]>
Commit | Line | Data |
---|---|---|
f1a48710 JM |
1 | /* |
2 | * WPA Supplicant - Basic AP mode support routines | |
3 | * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi> | |
4 | * Copyright (c) 2009, Atheros Communications | |
5 | * | |
0f3d578e JM |
6 | * This software may be distributed under the terms of the BSD license. |
7 | * See README for more details. | |
f1a48710 JM |
8 | */ |
9 | ||
6226e38d | 10 | #include "utils/includes.h" |
f1a48710 | 11 | |
6226e38d | 12 | #include "utils/common.h" |
70d84f11 | 13 | #include "utils/eloop.h" |
ab45223b | 14 | #include "utils/uuid.h" |
58c26600 | 15 | #include "common/ieee802_11_defs.h" |
a0dee797 | 16 | #include "common/wpa_ctrl.h" |
1057d78e | 17 | #include "ap/hostapd.h" |
6226e38d | 18 | #include "ap/ap_config.h" |
fe99fb74 | 19 | #include "ap/ap_drv_ops.h" |
fe6bdb77 | 20 | #ifdef NEED_AP_MLME |
1057d78e | 21 | #include "ap/ieee802_11.h" |
fe6bdb77 | 22 | #endif /* NEED_AP_MLME */ |
b22128ef | 23 | #include "ap/beacon.h" |
a8e0505b | 24 | #include "ap/ieee802_1x.h" |
363b9e60 | 25 | #include "ap/wps_hostapd.h" |
0e2d35c6 | 26 | #include "ap/ctrl_iface_ap.h" |
3ec97afe | 27 | #include "wps/wps.h" |
e44f8bf2 | 28 | #include "common/ieee802_11_defs.h" |
1f1b62a0 | 29 | #include "config_ssid.h" |
094393b1 | 30 | #include "config.h" |
1f1b62a0 | 31 | #include "wpa_supplicant_i.h" |
2d5b792d | 32 | #include "driver_i.h" |
e44f8bf2 | 33 | #include "p2p_supplicant.h" |
2d5b792d | 34 | #include "ap.h" |
2f9929ff | 35 | #include "ap/sta_info.h" |
d8a43924 | 36 | #include "notify.h" |
f1a48710 JM |
37 | |
38 | ||
0fe620de | 39 | #ifdef CONFIG_WPS |
70d84f11 | 40 | static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx); |
0fe620de | 41 | #endif /* CONFIG_WPS */ |
70d84f11 JM |
42 | |
43 | ||
07f117ed JM |
44 | static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s, |
45 | struct wpa_ssid *ssid, | |
46 | struct hostapd_config *conf) | |
47 | { | |
48 | struct hostapd_bss_config *bss = &conf->bss[0]; | |
a911a6e6 | 49 | int pairwise; |
c5121837 | 50 | |
a911a6e6 | 51 | conf->driver = wpa_s->driver; |
07f117ed JM |
52 | |
53 | os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface)); | |
54 | ||
55 | if (ssid->frequency == 0) { | |
56 | /* default channel 11 */ | |
57 | conf->hw_mode = HOSTAPD_MODE_IEEE80211G; | |
58 | conf->channel = 11; | |
59 | } else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) { | |
60 | conf->hw_mode = HOSTAPD_MODE_IEEE80211G; | |
61 | conf->channel = (ssid->frequency - 2407) / 5; | |
62 | } else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) || | |
63 | (ssid->frequency >= 5745 && ssid->frequency <= 5825)) { | |
b615a25e | 64 | conf->hw_mode = HOSTAPD_MODE_IEEE80211A; |
07f117ed JM |
65 | conf->channel = (ssid->frequency - 5000) / 5; |
66 | } else { | |
67 | wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz", | |
68 | ssid->frequency); | |
69 | return -1; | |
70 | } | |
71 | ||
2db91745 | 72 | /* TODO: enable HT40 if driver supports it; |
07f117ed JM |
73 | * drop to 11b if driver does not support 11g */ |
74 | ||
2db91745 AC |
75 | #ifdef CONFIG_IEEE80211N |
76 | /* | |
79b8c60f AN |
77 | * Enable HT20 if the driver supports it, by setting conf->ieee80211n |
78 | * and a mask of allowed capabilities within conf->ht_capab. | |
2db91745 | 79 | * Using default config settings for: conf->ht_op_mode_fixed, |
79b8c60f | 80 | * conf->secondary_channel, conf->require_ht |
2db91745 | 81 | */ |
6bf731e8 | 82 | if (wpa_s->hw.modes) { |
2db91745 AC |
83 | struct hostapd_hw_modes *mode = NULL; |
84 | int i; | |
6bf731e8 CL |
85 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
86 | if (wpa_s->hw.modes[i].mode == conf->hw_mode) { | |
87 | mode = &wpa_s->hw.modes[i]; | |
2db91745 AC |
88 | break; |
89 | } | |
90 | } | |
79b8c60f | 91 | if (mode && mode->ht_capab) { |
2db91745 | 92 | conf->ieee80211n = 1; |
79b8c60f AN |
93 | |
94 | /* | |
95 | * white-list capabilities that won't cause issues | |
96 | * to connecting stations, while leaving the current | |
97 | * capabilities intact (currently disabled SMPS). | |
98 | */ | |
99 | conf->ht_capab |= mode->ht_capab & | |
100 | (HT_CAP_INFO_GREEN_FIELD | | |
101 | HT_CAP_INFO_SHORT_GI20MHZ | | |
102 | HT_CAP_INFO_SHORT_GI40MHZ | | |
103 | HT_CAP_INFO_RX_STBC_MASK | | |
104 | HT_CAP_INFO_MAX_AMSDU_SIZE); | |
105 | } | |
2db91745 AC |
106 | } |
107 | #endif /* CONFIG_IEEE80211N */ | |
108 | ||
4c2c3028 JM |
109 | #ifdef CONFIG_P2P |
110 | if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) { | |
111 | /* Remove 802.11b rates from supported and basic rate sets */ | |
112 | int *list = os_malloc(4 * sizeof(int)); | |
113 | if (list) { | |
114 | list[0] = 60; | |
115 | list[1] = 120; | |
116 | list[2] = 240; | |
117 | list[3] = -1; | |
118 | } | |
119 | conf->basic_rates = list; | |
120 | ||
121 | list = os_malloc(9 * sizeof(int)); | |
122 | if (list) { | |
123 | list[0] = 60; | |
124 | list[1] = 90; | |
125 | list[2] = 120; | |
126 | list[3] = 180; | |
127 | list[4] = 240; | |
128 | list[5] = 360; | |
129 | list[6] = 480; | |
130 | list[7] = 540; | |
131 | list[8] = -1; | |
132 | } | |
133 | conf->supported_rates = list; | |
134 | } | |
6cd930cb JB |
135 | |
136 | bss->isolate = !wpa_s->conf->p2p_intra_bss; | |
4c2c3028 JM |
137 | #endif /* CONFIG_P2P */ |
138 | ||
07f117ed JM |
139 | if (ssid->ssid_len == 0) { |
140 | wpa_printf(MSG_ERROR, "No SSID configured for AP mode"); | |
141 | return -1; | |
142 | } | |
143 | os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len); | |
144 | bss->ssid.ssid[ssid->ssid_len] = '\0'; | |
145 | bss->ssid.ssid_len = ssid->ssid_len; | |
146 | bss->ssid.ssid_set = 1; | |
147 | ||
0399f2e4 VT |
148 | if (ssid->auth_alg) |
149 | bss->auth_algs = ssid->auth_alg; | |
150 | ||
07f117ed JM |
151 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) |
152 | bss->wpa = ssid->proto; | |
153 | bss->wpa_key_mgmt = ssid->key_mgmt; | |
154 | bss->wpa_pairwise = ssid->pairwise_cipher; | |
155 | if (ssid->passphrase) { | |
156 | bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase); | |
07f117ed JM |
157 | } else if (ssid->psk_set) { |
158 | os_free(bss->ssid.wpa_psk); | |
159 | bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); | |
160 | if (bss->ssid.wpa_psk == NULL) | |
161 | return -1; | |
162 | os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN); | |
163 | bss->ssid.wpa_psk->group = 1; | |
6bcb1c2b JM |
164 | } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] || |
165 | ssid->wep_key_len[2] || ssid->wep_key_len[3]) { | |
166 | struct hostapd_wep_keys *wep = &bss->ssid.wep; | |
167 | int i; | |
168 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
169 | if (ssid->wep_key_len[i] == 0) | |
170 | continue; | |
171 | wep->key[i] = os_malloc(ssid->wep_key_len[i]); | |
172 | if (wep->key[i] == NULL) | |
173 | return -1; | |
174 | os_memcpy(wep->key[i], ssid->wep_key[i], | |
175 | ssid->wep_key_len[i]); | |
176 | wep->len[i] = ssid->wep_key_len[i]; | |
177 | } | |
178 | wep->idx = ssid->wep_tx_keyidx; | |
179 | wep->keys_set = 1; | |
07f117ed JM |
180 | } |
181 | ||
07d9a552 JM |
182 | /* Select group cipher based on the enabled pairwise cipher suites */ |
183 | pairwise = 0; | |
184 | if (bss->wpa & 1) | |
185 | pairwise |= bss->wpa_pairwise; | |
186 | if (bss->wpa & 2) { | |
187 | if (bss->rsn_pairwise == 0) | |
188 | bss->rsn_pairwise = bss->wpa_pairwise; | |
189 | pairwise |= bss->rsn_pairwise; | |
190 | } | |
191 | if (pairwise & WPA_CIPHER_TKIP) | |
192 | bss->wpa_group = WPA_CIPHER_TKIP; | |
193 | else | |
194 | bss->wpa_group = WPA_CIPHER_CCMP; | |
195 | ||
196 | if (bss->wpa && bss->ieee802_1x) | |
197 | bss->ssid.security_policy = SECURITY_WPA; | |
198 | else if (bss->wpa) | |
199 | bss->ssid.security_policy = SECURITY_WPA_PSK; | |
200 | else if (bss->ieee802_1x) { | |
697cd03f | 201 | int cipher = WPA_CIPHER_NONE; |
07d9a552 JM |
202 | bss->ssid.security_policy = SECURITY_IEEE_802_1X; |
203 | bss->ssid.wep.default_len = bss->default_wep_key_len; | |
697cd03f JM |
204 | if (bss->default_wep_key_len) |
205 | cipher = bss->default_wep_key_len >= 13 ? | |
206 | WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40; | |
207 | bss->wpa_group = cipher; | |
208 | bss->wpa_pairwise = cipher; | |
209 | bss->rsn_pairwise = cipher; | |
210 | } else if (bss->ssid.wep.keys_set) { | |
211 | int cipher = WPA_CIPHER_WEP40; | |
212 | if (bss->ssid.wep.len[0] >= 13) | |
213 | cipher = WPA_CIPHER_WEP104; | |
07d9a552 | 214 | bss->ssid.security_policy = SECURITY_STATIC_WEP; |
697cd03f JM |
215 | bss->wpa_group = cipher; |
216 | bss->wpa_pairwise = cipher; | |
217 | bss->rsn_pairwise = cipher; | |
218 | } else { | |
07d9a552 | 219 | bss->ssid.security_policy = SECURITY_PLAINTEXT; |
697cd03f JM |
220 | bss->wpa_group = WPA_CIPHER_NONE; |
221 | bss->wpa_pairwise = WPA_CIPHER_NONE; | |
222 | bss->rsn_pairwise = WPA_CIPHER_NONE; | |
223 | } | |
07d9a552 | 224 | |
3ec97afe JM |
225 | #ifdef CONFIG_WPS |
226 | /* | |
04ed4e98 JM |
227 | * Enable WPS by default for open and WPA/WPA2-Personal network, but |
228 | * require user interaction to actually use it. Only the internal | |
229 | * Registrar is supported. | |
3ec97afe | 230 | */ |
04ed4e98 JM |
231 | if (bss->ssid.security_policy != SECURITY_WPA_PSK && |
232 | bss->ssid.security_policy != SECURITY_PLAINTEXT) | |
233 | goto no_wps; | |
c0f83f31 JM |
234 | #ifdef CONFIG_WPS2 |
235 | if (bss->ssid.security_policy == SECURITY_WPA_PSK && | |
236 | (!(pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2))) | |
237 | goto no_wps; /* WPS2 does not allow WPA/TKIP-only | |
238 | * configuration */ | |
239 | #endif /* CONFIG_WPS2 */ | |
3ec97afe JM |
240 | bss->eap_server = 1; |
241 | bss->wps_state = 2; | |
9dd7d6b0 | 242 | bss->ap_setup_locked = 2; |
094393b1 JM |
243 | if (wpa_s->conf->config_methods) |
244 | bss->config_methods = os_strdup(wpa_s->conf->config_methods); | |
2f646b6e JB |
245 | os_memcpy(bss->device_type, wpa_s->conf->device_type, |
246 | WPS_DEV_TYPE_LEN); | |
e44f8bf2 JM |
247 | if (wpa_s->conf->device_name) { |
248 | bss->device_name = os_strdup(wpa_s->conf->device_name); | |
249 | bss->friendly_name = os_strdup(wpa_s->conf->device_name); | |
250 | } | |
56815b2b JM |
251 | if (wpa_s->conf->manufacturer) |
252 | bss->manufacturer = os_strdup(wpa_s->conf->manufacturer); | |
253 | if (wpa_s->conf->model_name) | |
254 | bss->model_name = os_strdup(wpa_s->conf->model_name); | |
255 | if (wpa_s->conf->model_number) | |
256 | bss->model_number = os_strdup(wpa_s->conf->model_number); | |
257 | if (wpa_s->conf->serial_number) | |
258 | bss->serial_number = os_strdup(wpa_s->conf->serial_number); | |
ab45223b JM |
259 | if (is_nil_uuid(wpa_s->conf->uuid)) |
260 | os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN); | |
261 | else | |
262 | os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN); | |
56815b2b | 263 | os_memcpy(bss->os_version, wpa_s->conf->os_version, 4); |
04ed4e98 | 264 | no_wps: |
56815b2b | 265 | #endif /* CONFIG_WPS */ |
e44f8bf2 | 266 | |
de979d8f JM |
267 | if (wpa_s->max_stations && |
268 | wpa_s->max_stations < wpa_s->conf->max_num_sta) | |
269 | bss->max_num_sta = wpa_s->max_stations; | |
270 | else | |
271 | bss->max_num_sta = wpa_s->conf->max_num_sta; | |
dae608d5 | 272 | |
0d7e5a3a JB |
273 | bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack; |
274 | ||
07f117ed JM |
275 | return 0; |
276 | } | |
277 | ||
278 | ||
c706d5aa JM |
279 | static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq) |
280 | { | |
e44f8bf2 JM |
281 | #ifdef CONFIG_P2P |
282 | struct wpa_supplicant *wpa_s = ctx; | |
283 | const struct ieee80211_mgmt *mgmt; | |
284 | size_t hdr_len; | |
285 | ||
286 | mgmt = (const struct ieee80211_mgmt *) buf; | |
287 | hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf; | |
288 | if (hdr_len > len) | |
289 | return; | |
290 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, | |
291 | mgmt->u.action.category, | |
292 | &mgmt->u.action.u.vs_public_action.action, | |
293 | len - hdr_len, freq); | |
294 | #endif /* CONFIG_P2P */ | |
295 | } | |
296 | ||
297 | ||
a0dee797 AGS |
298 | static void ap_wps_event_cb(void *ctx, enum wps_event event, |
299 | union wps_event_data *data) | |
300 | { | |
ca806fb5 | 301 | #ifdef CONFIG_P2P |
a0dee797 | 302 | struct wpa_supplicant *wpa_s = ctx; |
8be6450c JMB |
303 | |
304 | if (event == WPS_EV_FAIL) { | |
305 | struct wps_event_fail *fail = &data->fail; | |
306 | ||
307 | if (wpa_s->parent && wpa_s->parent != wpa_s && | |
308 | wpa_s == wpa_s->global->p2p_group_formation) { | |
309 | /* | |
310 | * src/ap/wps_hostapd.c has already sent this on the | |
311 | * main interface, so only send on the parent interface | |
312 | * here if needed. | |
313 | */ | |
314 | wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL | |
315 | "msg=%d config_error=%d", | |
316 | fail->msg, fail->config_error); | |
317 | } | |
318 | wpas_p2p_wps_failed(wpa_s, fail); | |
a0dee797 | 319 | } |
ca806fb5 | 320 | #endif /* CONFIG_P2P */ |
a0dee797 AGS |
321 | } |
322 | ||
323 | ||
d8a43924 | 324 | static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr, |
fbdcfd57 | 325 | int authorized, const u8 *p2p_dev_addr) |
d8a43924 | 326 | { |
fbdcfd57 | 327 | wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr); |
d8a43924 JB |
328 | } |
329 | ||
330 | ||
e44f8bf2 JM |
331 | static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq) |
332 | { | |
333 | #ifdef CONFIG_P2P | |
334 | struct wpa_supplicant *wpa_s = ctx; | |
335 | const struct ieee80211_mgmt *mgmt; | |
336 | size_t hdr_len; | |
337 | ||
338 | mgmt = (const struct ieee80211_mgmt *) buf; | |
339 | hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf; | |
340 | if (hdr_len > len) | |
341 | return -1; | |
342 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, | |
343 | mgmt->u.action.category, | |
344 | &mgmt->u.action.u.vs_public_action.action, | |
345 | len - hdr_len, freq); | |
346 | #endif /* CONFIG_P2P */ | |
347 | return 0; | |
c706d5aa JM |
348 | } |
349 | ||
350 | ||
04a85e44 JM |
351 | static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da, |
352 | const u8 *bssid, const u8 *ie, size_t ie_len) | |
c706d5aa | 353 | { |
e44f8bf2 JM |
354 | #ifdef CONFIG_P2P |
355 | struct wpa_supplicant *wpa_s = ctx; | |
04a85e44 | 356 | return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len); |
e44f8bf2 | 357 | #else /* CONFIG_P2P */ |
c706d5aa | 358 | return 0; |
e44f8bf2 | 359 | #endif /* CONFIG_P2P */ |
c706d5aa JM |
360 | } |
361 | ||
362 | ||
363 | static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr, | |
364 | const u8 *uuid_e) | |
365 | { | |
e44f8bf2 JM |
366 | #ifdef CONFIG_P2P |
367 | struct wpa_supplicant *wpa_s = ctx; | |
368 | wpas_p2p_wps_success(wpa_s, mac_addr, 1); | |
369 | #endif /* CONFIG_P2P */ | |
c706d5aa JM |
370 | } |
371 | ||
372 | ||
c76e5d7f JB |
373 | static void wpas_ap_configured_cb(void *ctx) |
374 | { | |
375 | struct wpa_supplicant *wpa_s = ctx; | |
376 | ||
377 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
378 | ||
379 | if (wpa_s->ap_configured_cb) | |
380 | wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx, | |
381 | wpa_s->ap_configured_cb_data); | |
382 | } | |
383 | ||
384 | ||
2d5b792d JM |
385 | int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s, |
386 | struct wpa_ssid *ssid) | |
387 | { | |
388 | struct wpa_driver_associate_params params; | |
389 | struct hostapd_iface *hapd_iface; | |
390 | struct hostapd_config *conf; | |
391 | size_t i; | |
f1a48710 | 392 | |
2d5b792d JM |
393 | if (ssid->ssid == NULL || ssid->ssid_len == 0) { |
394 | wpa_printf(MSG_ERROR, "No SSID configured for AP mode"); | |
395 | return -1; | |
f1a48710 JM |
396 | } |
397 | ||
2d5b792d | 398 | wpa_supplicant_ap_deinit(wpa_s); |
d2440ba0 JM |
399 | |
400 | wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')", | |
401 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
402 | ||
403 | os_memset(¶ms, 0, sizeof(params)); | |
404 | params.ssid = ssid->ssid; | |
405 | params.ssid_len = ssid->ssid_len; | |
d7dcba70 JM |
406 | switch (ssid->mode) { |
407 | case WPAS_MODE_INFRA: | |
408 | params.mode = IEEE80211_MODE_INFRA; | |
409 | break; | |
410 | case WPAS_MODE_IBSS: | |
411 | params.mode = IEEE80211_MODE_IBSS; | |
412 | break; | |
413 | case WPAS_MODE_AP: | |
2c5d725c JM |
414 | case WPAS_MODE_P2P_GO: |
415 | case WPAS_MODE_P2P_GROUP_FORMATION: | |
d7dcba70 JM |
416 | params.mode = IEEE80211_MODE_AP; |
417 | break; | |
418 | } | |
d2440ba0 JM |
419 | params.freq = ssid->frequency; |
420 | ||
64fa840a | 421 | params.wpa_proto = ssid->proto; |
508545f3 JM |
422 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) |
423 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK; | |
424 | else | |
425 | wpa_s->key_mgmt = WPA_KEY_MGMT_NONE; | |
426 | params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt); | |
427 | ||
428 | if (ssid->pairwise_cipher & WPA_CIPHER_CCMP) | |
429 | wpa_s->pairwise_cipher = WPA_CIPHER_CCMP; | |
430 | else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP) | |
431 | wpa_s->pairwise_cipher = WPA_CIPHER_TKIP; | |
432 | else if (ssid->pairwise_cipher & WPA_CIPHER_NONE) | |
433 | wpa_s->pairwise_cipher = WPA_CIPHER_NONE; | |
434 | else { | |
435 | wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise " | |
436 | "cipher."); | |
437 | return -1; | |
438 | } | |
439 | params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher); | |
440 | params.group_suite = params.pairwise_suite; | |
441 | ||
6e3f4b89 JM |
442 | #ifdef CONFIG_P2P |
443 | if (ssid->mode == WPAS_MODE_P2P_GO || | |
444 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) | |
445 | params.p2p = 1; | |
446 | #endif /* CONFIG_P2P */ | |
447 | ||
eea2fd9e JM |
448 | if (wpa_s->parent->set_ap_uapsd) |
449 | params.uapsd = wpa_s->parent->ap_uapsd; | |
450 | else | |
451 | params.uapsd = -1; | |
452 | ||
d2440ba0 JM |
453 | if (wpa_drv_associate(wpa_s, ¶ms) < 0) { |
454 | wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality"); | |
455 | return -1; | |
456 | } | |
457 | ||
2d5b792d JM |
458 | wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface)); |
459 | if (hapd_iface == NULL) | |
460 | return -1; | |
0f2b2c19 | 461 | hapd_iface->owner = wpa_s; |
a57db49c | 462 | hapd_iface->drv_flags = wpa_s->drv_flags; |
4f73d88a | 463 | hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads; |
1f1b62a0 | 464 | |
2d5b792d JM |
465 | wpa_s->ap_iface->conf = conf = hostapd_config_defaults(); |
466 | if (conf == NULL) { | |
467 | wpa_supplicant_ap_deinit(wpa_s); | |
468 | return -1; | |
469 | } | |
1f1b62a0 | 470 | |
d26e45a4 EP |
471 | if (params.uapsd > 0) { |
472 | conf->bss->wmm_enabled = 1; | |
473 | conf->bss->wmm_uapsd = 1; | |
474 | } | |
475 | ||
07f117ed JM |
476 | if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) { |
477 | wpa_printf(MSG_ERROR, "Failed to create AP configuration"); | |
478 | wpa_supplicant_ap_deinit(wpa_s); | |
479 | return -1; | |
480 | } | |
481 | ||
e44f8bf2 JM |
482 | #ifdef CONFIG_P2P |
483 | if (ssid->mode == WPAS_MODE_P2P_GO) | |
484 | conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER; | |
485 | else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) | |
486 | conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER | | |
487 | P2P_GROUP_FORMATION; | |
488 | #endif /* CONFIG_P2P */ | |
489 | ||
2d5b792d JM |
490 | hapd_iface->num_bss = conf->num_bss; |
491 | hapd_iface->bss = os_zalloc(conf->num_bss * | |
492 | sizeof(struct hostapd_data *)); | |
493 | if (hapd_iface->bss == NULL) { | |
494 | wpa_supplicant_ap_deinit(wpa_s); | |
495 | return -1; | |
496 | } | |
1f1b62a0 | 497 | |
2d5b792d JM |
498 | for (i = 0; i < conf->num_bss; i++) { |
499 | hapd_iface->bss[i] = | |
500 | hostapd_alloc_bss_data(hapd_iface, conf, | |
501 | &conf->bss[i]); | |
502 | if (hapd_iface->bss[i] == NULL) { | |
503 | wpa_supplicant_ap_deinit(wpa_s); | |
504 | return -1; | |
505 | } | |
4f760fcc JM |
506 | |
507 | hapd_iface->bss[i]->msg_ctx = wpa_s; | |
8a5e75f6 | 508 | hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent; |
c706d5aa JM |
509 | hapd_iface->bss[i]->public_action_cb = ap_public_action_rx; |
510 | hapd_iface->bss[i]->public_action_cb_ctx = wpa_s; | |
e44f8bf2 JM |
511 | hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx; |
512 | hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s; | |
c706d5aa JM |
513 | hostapd_register_probereq_cb(hapd_iface->bss[i], |
514 | ap_probe_req_rx, wpa_s); | |
515 | hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb; | |
516 | hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s; | |
a0dee797 AGS |
517 | hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb; |
518 | hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s; | |
d8a43924 JB |
519 | hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb; |
520 | hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s; | |
e44f8bf2 JM |
521 | #ifdef CONFIG_P2P |
522 | hapd_iface->bss[i]->p2p = wpa_s->global->p2p; | |
523 | hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init( | |
524 | wpa_s, ssid->p2p_persistent_group, | |
525 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION); | |
526 | #endif /* CONFIG_P2P */ | |
c76e5d7f JB |
527 | hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb; |
528 | hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s; | |
2d5b792d JM |
529 | } |
530 | ||
a911a6e6 JM |
531 | os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN); |
532 | hapd_iface->bss[0]->driver = wpa_s->driver; | |
533 | hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv; | |
534 | ||
e73edcaa JM |
535 | wpa_s->current_ssid = ssid; |
536 | os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN); | |
537 | wpa_s->assoc_freq = ssid->frequency; | |
538 | ||
a911a6e6 | 539 | if (hostapd_setup_interface(wpa_s->ap_iface)) { |
2d5b792d JM |
540 | wpa_printf(MSG_ERROR, "Failed to initialize AP interface"); |
541 | wpa_supplicant_ap_deinit(wpa_s); | |
542 | return -1; | |
1f1b62a0 JM |
543 | } |
544 | ||
2d5b792d JM |
545 | return 0; |
546 | } | |
547 | ||
548 | ||
549 | void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s) | |
550 | { | |
0fe620de | 551 | #ifdef CONFIG_WPS |
70d84f11 | 552 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); |
0fe620de | 553 | #endif /* CONFIG_WPS */ |
70d84f11 | 554 | |
2d5b792d JM |
555 | if (wpa_s->ap_iface == NULL) |
556 | return; | |
557 | ||
7a649c7d | 558 | wpa_s->current_ssid = NULL; |
3c85f144 | 559 | wpa_s->assoc_freq = 0; |
ca62e114 | 560 | wpa_s->reassociated_connection = 0; |
e44f8bf2 | 561 | #ifdef CONFIG_P2P |
0e14267a JM |
562 | if (wpa_s->ap_iface->bss) |
563 | wpa_s->ap_iface->bss[0]->p2p_group = NULL; | |
e44f8bf2 JM |
564 | wpas_p2p_group_deinit(wpa_s); |
565 | #endif /* CONFIG_P2P */ | |
2d5b792d | 566 | hostapd_interface_deinit(wpa_s->ap_iface); |
f7c47833 | 567 | hostapd_interface_free(wpa_s->ap_iface); |
2d5b792d | 568 | wpa_s->ap_iface = NULL; |
7a649c7d | 569 | wpa_drv_deinit_ap(wpa_s); |
1f1b62a0 | 570 | } |
0915d02c JM |
571 | |
572 | ||
573 | void ap_tx_status(void *ctx, const u8 *addr, | |
574 | const u8 *buf, size_t len, int ack) | |
575 | { | |
f8b1f695 | 576 | #ifdef NEED_AP_MLME |
0915d02c JM |
577 | struct wpa_supplicant *wpa_s = ctx; |
578 | hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack); | |
f8b1f695 | 579 | #endif /* NEED_AP_MLME */ |
0915d02c JM |
580 | } |
581 | ||
582 | ||
dd840f79 JB |
583 | void ap_eapol_tx_status(void *ctx, const u8 *dst, |
584 | const u8 *data, size_t len, int ack) | |
585 | { | |
586 | #ifdef NEED_AP_MLME | |
587 | struct wpa_supplicant *wpa_s = ctx; | |
588 | hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack); | |
589 | #endif /* NEED_AP_MLME */ | |
590 | } | |
591 | ||
592 | ||
bcf24348 JB |
593 | void ap_client_poll_ok(void *ctx, const u8 *addr) |
594 | { | |
595 | #ifdef NEED_AP_MLME | |
596 | struct wpa_supplicant *wpa_s = ctx; | |
597 | if (wpa_s->ap_iface) | |
598 | hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr); | |
599 | #endif /* NEED_AP_MLME */ | |
600 | } | |
601 | ||
602 | ||
9b90955e | 603 | void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds) |
0915d02c | 604 | { |
f8b1f695 | 605 | #ifdef NEED_AP_MLME |
0915d02c | 606 | struct wpa_supplicant *wpa_s = ctx; |
9b90955e | 607 | ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds); |
f8b1f695 | 608 | #endif /* NEED_AP_MLME */ |
0915d02c JM |
609 | } |
610 | ||
611 | ||
2a8b7416 | 612 | void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt) |
0915d02c | 613 | { |
f8b1f695 | 614 | #ifdef NEED_AP_MLME |
0915d02c | 615 | struct wpa_supplicant *wpa_s = ctx; |
2a8b7416 JM |
616 | struct hostapd_frame_info fi; |
617 | os_memset(&fi, 0, sizeof(fi)); | |
618 | fi.datarate = rx_mgmt->datarate; | |
619 | fi.ssi_signal = rx_mgmt->ssi_signal; | |
620 | ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame, | |
621 | rx_mgmt->frame_len, &fi); | |
f8b1f695 | 622 | #endif /* NEED_AP_MLME */ |
0915d02c JM |
623 | } |
624 | ||
625 | ||
f8b1f695 | 626 | void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok) |
0915d02c | 627 | { |
f8b1f695 | 628 | #ifdef NEED_AP_MLME |
0915d02c JM |
629 | struct wpa_supplicant *wpa_s = ctx; |
630 | ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok); | |
fe6bdb77 | 631 | #endif /* NEED_AP_MLME */ |
f8b1f695 | 632 | } |
db149ac9 JM |
633 | |
634 | ||
635 | void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s, | |
636 | const u8 *src_addr, const u8 *buf, size_t len) | |
637 | { | |
a8e0505b | 638 | ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len); |
db149ac9 | 639 | } |
3ec97afe JM |
640 | |
641 | ||
642 | #ifdef CONFIG_WPS | |
643 | ||
d601247c JM |
644 | int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid, |
645 | const u8 *p2p_dev_addr) | |
3ec97afe | 646 | { |
48b357a9 JM |
647 | if (!wpa_s->ap_iface) |
648 | return -1; | |
d601247c JM |
649 | return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0], |
650 | p2p_dev_addr); | |
3ec97afe JM |
651 | } |
652 | ||
653 | ||
2f9929ff AC |
654 | static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data *hapd, |
655 | struct sta_info *sta, void *ctx) | |
656 | { | |
657 | if (sta && (sta->flags & WLAN_STA_WPS)) { | |
658 | ap_sta_deauthenticate(hapd, sta, | |
659 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
660 | wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR, | |
661 | __func__, MAC2STR(sta->addr)); | |
662 | return 1; | |
663 | } | |
664 | ||
665 | return 0; | |
666 | } | |
667 | ||
668 | ||
669 | int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s) | |
670 | { | |
671 | struct wps_registrar *reg; | |
672 | int reg_sel = 0, wps_sta = 0; | |
673 | ||
674 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps) | |
675 | return -1; | |
676 | ||
677 | reg = wpa_s->ap_iface->bss[0]->wps->registrar; | |
678 | reg_sel = wps_registrar_wps_cancel(reg); | |
679 | wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0], | |
680 | wpa_supplicant_ap_wps_sta_cancel, NULL); | |
681 | ||
682 | if (!reg_sel && !wps_sta) { | |
683 | wpa_printf(MSG_DEBUG, "No WPS operation in progress at this " | |
684 | "time"); | |
685 | return -1; | |
686 | } | |
687 | ||
688 | /* | |
689 | * There are 2 cases to return wps cancel as success: | |
690 | * 1. When wps cancel was initiated but no connection has been | |
691 | * established with client yet. | |
692 | * 2. Client is in the middle of exchanging WPS messages. | |
693 | */ | |
694 | ||
695 | return 0; | |
696 | } | |
697 | ||
698 | ||
3ec97afe JM |
699 | int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, |
700 | const char *pin, char *buf, size_t buflen) | |
701 | { | |
702 | int ret, ret_len = 0; | |
703 | ||
48b357a9 JM |
704 | if (!wpa_s->ap_iface) |
705 | return -1; | |
706 | ||
3ec97afe JM |
707 | if (pin == NULL) { |
708 | unsigned int rpin = wps_generate_pin(); | |
9337e876 | 709 | ret_len = os_snprintf(buf, buflen, "%08d", rpin); |
3ec97afe | 710 | pin = buf; |
f80a2237 JM |
711 | } else |
712 | ret_len = os_snprintf(buf, buflen, "%s", pin); | |
3ec97afe | 713 | |
31fcea93 JM |
714 | ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin, |
715 | 0); | |
3ec97afe JM |
716 | if (ret) |
717 | return -1; | |
718 | return ret_len; | |
719 | } | |
720 | ||
70d84f11 JM |
721 | |
722 | static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx) | |
723 | { | |
724 | struct wpa_supplicant *wpa_s = eloop_data; | |
725 | wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out"); | |
726 | wpas_wps_ap_pin_disable(wpa_s); | |
727 | } | |
728 | ||
729 | ||
730 | static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout) | |
731 | { | |
732 | struct hostapd_data *hapd; | |
733 | ||
734 | if (wpa_s->ap_iface == NULL) | |
735 | return; | |
736 | hapd = wpa_s->ap_iface->bss[0]; | |
737 | wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout); | |
738 | hapd->ap_pin_failures = 0; | |
739 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); | |
740 | if (timeout > 0) | |
741 | eloop_register_timeout(timeout, 0, | |
742 | wpas_wps_ap_pin_timeout, wpa_s, NULL); | |
743 | } | |
744 | ||
745 | ||
746 | void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s) | |
747 | { | |
748 | struct hostapd_data *hapd; | |
749 | ||
750 | if (wpa_s->ap_iface == NULL) | |
751 | return; | |
752 | wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN"); | |
753 | hapd = wpa_s->ap_iface->bss[0]; | |
754 | os_free(hapd->conf->ap_pin); | |
755 | hapd->conf->ap_pin = NULL; | |
756 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); | |
757 | } | |
758 | ||
759 | ||
760 | const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout) | |
761 | { | |
762 | struct hostapd_data *hapd; | |
763 | unsigned int pin; | |
764 | char pin_txt[9]; | |
765 | ||
766 | if (wpa_s->ap_iface == NULL) | |
767 | return NULL; | |
768 | hapd = wpa_s->ap_iface->bss[0]; | |
769 | pin = wps_generate_pin(); | |
9337e876 | 770 | os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin); |
70d84f11 JM |
771 | os_free(hapd->conf->ap_pin); |
772 | hapd->conf->ap_pin = os_strdup(pin_txt); | |
773 | if (hapd->conf->ap_pin == NULL) | |
774 | return NULL; | |
775 | wpas_wps_ap_pin_enable(wpa_s, timeout); | |
776 | ||
777 | return hapd->conf->ap_pin; | |
778 | } | |
779 | ||
780 | ||
781 | const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s) | |
782 | { | |
783 | struct hostapd_data *hapd; | |
784 | if (wpa_s->ap_iface == NULL) | |
785 | return NULL; | |
786 | hapd = wpa_s->ap_iface->bss[0]; | |
787 | return hapd->conf->ap_pin; | |
788 | } | |
789 | ||
790 | ||
791 | int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin, | |
792 | int timeout) | |
793 | { | |
794 | struct hostapd_data *hapd; | |
795 | char pin_txt[9]; | |
796 | int ret; | |
797 | ||
798 | if (wpa_s->ap_iface == NULL) | |
799 | return -1; | |
800 | hapd = wpa_s->ap_iface->bss[0]; | |
801 | ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin); | |
802 | if (ret < 0 || ret >= (int) sizeof(pin_txt)) | |
803 | return -1; | |
804 | os_free(hapd->conf->ap_pin); | |
805 | hapd->conf->ap_pin = os_strdup(pin_txt); | |
806 | if (hapd->conf->ap_pin == NULL) | |
807 | return -1; | |
808 | wpas_wps_ap_pin_enable(wpa_s, timeout); | |
809 | ||
810 | return 0; | |
811 | } | |
812 | ||
813 | ||
814 | void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s) | |
815 | { | |
816 | struct hostapd_data *hapd; | |
817 | ||
818 | if (wpa_s->ap_iface == NULL) | |
819 | return; | |
820 | hapd = wpa_s->ap_iface->bss[0]; | |
821 | ||
822 | /* | |
823 | * Registrar failed to prove its knowledge of the AP PIN. Disable AP | |
824 | * PIN if this happens multiple times to slow down brute force attacks. | |
825 | */ | |
826 | hapd->ap_pin_failures++; | |
827 | wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u", | |
828 | hapd->ap_pin_failures); | |
829 | if (hapd->ap_pin_failures < 3) | |
830 | return; | |
831 | ||
832 | wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN"); | |
833 | hapd->ap_pin_failures = 0; | |
834 | os_free(hapd->conf->ap_pin); | |
835 | hapd->conf->ap_pin = NULL; | |
836 | } | |
837 | ||
3ec97afe | 838 | #endif /* CONFIG_WPS */ |
e653b622 JM |
839 | |
840 | ||
35deb646 JM |
841 | #ifdef CONFIG_CTRL_IFACE |
842 | ||
e653b622 JM |
843 | int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s, |
844 | char *buf, size_t buflen) | |
845 | { | |
846 | if (wpa_s->ap_iface == NULL) | |
847 | return -1; | |
848 | return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0], | |
849 | buf, buflen); | |
850 | } | |
851 | ||
852 | ||
853 | int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr, | |
854 | char *buf, size_t buflen) | |
855 | { | |
856 | if (wpa_s->ap_iface == NULL) | |
857 | return -1; | |
858 | return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr, | |
859 | buf, buflen); | |
860 | } | |
861 | ||
862 | ||
863 | int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr, | |
864 | char *buf, size_t buflen) | |
865 | { | |
866 | if (wpa_s->ap_iface == NULL) | |
867 | return -1; | |
868 | return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr, | |
869 | buf, buflen); | |
870 | } | |
35deb646 | 871 | |
43fb5297 | 872 | |
e60b2951 JJ |
873 | int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s, |
874 | const char *txtaddr) | |
875 | { | |
876 | if (wpa_s->ap_iface == NULL) | |
877 | return -1; | |
878 | return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0], | |
879 | txtaddr); | |
880 | } | |
881 | ||
882 | ||
883 | int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s, | |
884 | const char *txtaddr) | |
885 | { | |
886 | if (wpa_s->ap_iface == NULL) | |
887 | return -1; | |
888 | return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0], | |
889 | txtaddr); | |
890 | } | |
891 | ||
892 | ||
43fb5297 JM |
893 | int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf, |
894 | size_t buflen, int verbose) | |
895 | { | |
896 | char *pos = buf, *end = buf + buflen; | |
897 | int ret; | |
898 | struct hostapd_bss_config *conf; | |
899 | ||
900 | if (wpa_s->ap_iface == NULL) | |
901 | return -1; | |
902 | ||
903 | conf = wpa_s->ap_iface->bss[0]->conf; | |
904 | if (conf->wpa == 0) | |
905 | return 0; | |
906 | ||
907 | ret = os_snprintf(pos, end - pos, | |
908 | "pairwise_cipher=%s\n" | |
909 | "group_cipher=%s\n" | |
910 | "key_mgmt=%s\n", | |
911 | wpa_cipher_txt(conf->rsn_pairwise), | |
912 | wpa_cipher_txt(conf->wpa_group), | |
913 | wpa_key_mgmt_txt(conf->wpa_key_mgmt, | |
914 | conf->wpa)); | |
915 | if (ret < 0 || ret >= end - pos) | |
916 | return pos - buf; | |
917 | pos += ret; | |
918 | return pos - buf; | |
919 | } | |
920 | ||
35deb646 | 921 | #endif /* CONFIG_CTRL_IFACE */ |
f90ceeaa JM |
922 | |
923 | ||
b22128ef JM |
924 | int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s) |
925 | { | |
926 | struct hostapd_iface *iface = wpa_s->ap_iface; | |
927 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
928 | struct hostapd_data *hapd; | |
929 | ||
72d48a80 JM |
930 | if (ssid == NULL || wpa_s->ap_iface == NULL || |
931 | ssid->mode == WPAS_MODE_INFRA || | |
932 | ssid->mode == WPAS_MODE_IBSS) | |
b22128ef JM |
933 | return -1; |
934 | ||
e44f8bf2 JM |
935 | #ifdef CONFIG_P2P |
936 | if (ssid->mode == WPAS_MODE_P2P_GO) | |
937 | iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER; | |
938 | else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) | |
939 | iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER | | |
940 | P2P_GROUP_FORMATION; | |
941 | #endif /* CONFIG_P2P */ | |
942 | ||
b22128ef | 943 | hapd = iface->bss[0]; |
72d48a80 JM |
944 | if (hapd->drv_priv == NULL) |
945 | return -1; | |
946 | ieee802_11_set_beacons(iface); | |
fe99fb74 | 947 | hostapd_set_ap_wps_ie(hapd); |
b22128ef JM |
948 | |
949 | return 0; | |
950 | } | |
951 | ||
952 | ||
f90ceeaa JM |
953 | int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s, |
954 | const u8 *addr) | |
955 | { | |
956 | struct hostapd_data *hapd; | |
957 | struct hostapd_bss_config *conf; | |
958 | ||
959 | if (!wpa_s->ap_iface) | |
960 | return -1; | |
961 | ||
962 | if (addr) | |
963 | wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR, | |
964 | MAC2STR(addr)); | |
965 | else | |
966 | wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter"); | |
967 | ||
968 | hapd = wpa_s->ap_iface->bss[0]; | |
969 | conf = hapd->conf; | |
970 | ||
971 | os_free(conf->accept_mac); | |
972 | conf->accept_mac = NULL; | |
973 | conf->num_accept_mac = 0; | |
974 | os_free(conf->deny_mac); | |
975 | conf->deny_mac = NULL; | |
976 | conf->num_deny_mac = 0; | |
977 | ||
978 | if (addr == NULL) { | |
979 | conf->macaddr_acl = ACCEPT_UNLESS_DENIED; | |
980 | return 0; | |
981 | } | |
982 | ||
983 | conf->macaddr_acl = DENY_UNLESS_ACCEPTED; | |
984 | conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry)); | |
985 | if (conf->accept_mac == NULL) | |
986 | return -1; | |
987 | os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN); | |
988 | conf->num_accept_mac = 1; | |
989 | ||
990 | return 0; | |
991 | } |