Line data Source code
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 : *
6 : * This software may be distributed under the terms of the BSD license.
7 : * See README for more details.
8 : */
9 :
10 : #include "utils/includes.h"
11 :
12 : #include "utils/common.h"
13 : #include "utils/eloop.h"
14 : #include "utils/uuid.h"
15 : #include "common/ieee802_11_defs.h"
16 : #include "common/wpa_ctrl.h"
17 : #include "eapol_supp/eapol_supp_sm.h"
18 : #include "crypto/dh_group5.h"
19 : #include "ap/hostapd.h"
20 : #include "ap/ap_config.h"
21 : #include "ap/ap_drv_ops.h"
22 : #ifdef NEED_AP_MLME
23 : #include "ap/ieee802_11.h"
24 : #endif /* NEED_AP_MLME */
25 : #include "ap/beacon.h"
26 : #include "ap/ieee802_1x.h"
27 : #include "ap/wps_hostapd.h"
28 : #include "ap/ctrl_iface_ap.h"
29 : #include "ap/dfs.h"
30 : #include "wps/wps.h"
31 : #include "common/ieee802_11_defs.h"
32 : #include "config_ssid.h"
33 : #include "config.h"
34 : #include "wpa_supplicant_i.h"
35 : #include "driver_i.h"
36 : #include "p2p_supplicant.h"
37 : #include "ap.h"
38 : #include "ap/sta_info.h"
39 : #include "notify.h"
40 :
41 :
42 : #ifdef CONFIG_WPS
43 : static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
44 : #endif /* CONFIG_WPS */
45 :
46 :
47 : #ifdef CONFIG_IEEE80211N
48 9 : static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
49 : struct hostapd_config *conf,
50 : struct hostapd_hw_modes *mode)
51 : {
52 : #ifdef CONFIG_P2P
53 9 : u8 center_chan = 0;
54 9 : u8 channel = conf->channel;
55 :
56 9 : if (!conf->secondary_channel)
57 8 : goto no_vht;
58 :
59 1 : center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
60 1 : if (!center_chan)
61 0 : goto no_vht;
62 :
63 : /* Use 80 MHz channel */
64 1 : conf->vht_oper_chwidth = 1;
65 1 : conf->vht_oper_centr_freq_seg0_idx = center_chan;
66 10 : return;
67 :
68 : no_vht:
69 8 : conf->vht_oper_centr_freq_seg0_idx =
70 8 : channel + conf->secondary_channel * 2;
71 : #else /* CONFIG_P2P */
72 : conf->vht_oper_centr_freq_seg0_idx =
73 : conf->channel + conf->secondary_channel * 2;
74 : #endif /* CONFIG_P2P */
75 : }
76 : #endif /* CONFIG_IEEE80211N */
77 :
78 :
79 344 : void wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
80 : struct wpa_ssid *ssid,
81 : struct hostapd_config *conf)
82 : {
83 : /* TODO: enable HT40 if driver supports it;
84 : * drop to 11b if driver does not support 11g */
85 :
86 : #ifdef CONFIG_IEEE80211N
87 : /*
88 : * Enable HT20 if the driver supports it, by setting conf->ieee80211n
89 : * and a mask of allowed capabilities within conf->ht_capab.
90 : * Using default config settings for: conf->ht_op_mode_fixed,
91 : * conf->secondary_channel, conf->require_ht
92 : */
93 344 : if (wpa_s->hw.modes) {
94 344 : struct hostapd_hw_modes *mode = NULL;
95 344 : int i, no_ht = 0;
96 356 : for (i = 0; i < wpa_s->hw.num_modes; i++) {
97 356 : if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
98 344 : mode = &wpa_s->hw.modes[i];
99 344 : break;
100 : }
101 : }
102 :
103 : #ifdef CONFIG_HT_OVERRIDES
104 344 : if (ssid->disable_ht) {
105 0 : conf->ieee80211n = 0;
106 0 : conf->ht_capab = 0;
107 0 : no_ht = 1;
108 : }
109 : #endif /* CONFIG_HT_OVERRIDES */
110 :
111 344 : if (!no_ht && mode && mode->ht_capab) {
112 344 : conf->ieee80211n = 1;
113 : #ifdef CONFIG_P2P
114 356 : if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
115 12 : (mode->ht_capab &
116 12 : HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
117 12 : ssid->ht40)
118 1 : conf->secondary_channel =
119 1 : wpas_p2p_get_ht40_mode(wpa_s, mode,
120 1 : conf->channel);
121 344 : if (conf->secondary_channel)
122 1 : conf->ht_capab |=
123 : HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
124 : #endif /* CONFIG_P2P */
125 :
126 : /*
127 : * white-list capabilities that won't cause issues
128 : * to connecting stations, while leaving the current
129 : * capabilities intact (currently disabled SMPS).
130 : */
131 344 : conf->ht_capab |= mode->ht_capab &
132 : (HT_CAP_INFO_GREEN_FIELD |
133 : HT_CAP_INFO_SHORT_GI20MHZ |
134 : HT_CAP_INFO_SHORT_GI40MHZ |
135 : HT_CAP_INFO_RX_STBC_MASK |
136 : HT_CAP_INFO_TX_STBC |
137 : HT_CAP_INFO_MAX_AMSDU_SIZE);
138 :
139 344 : if (mode->vht_capab && ssid->vht) {
140 9 : conf->ieee80211ac = 1;
141 9 : wpas_conf_ap_vht(wpa_s, conf, mode);
142 : }
143 : }
144 : }
145 : #endif /* CONFIG_IEEE80211N */
146 344 : }
147 :
148 :
149 311 : static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
150 : struct wpa_ssid *ssid,
151 : struct hostapd_config *conf)
152 : {
153 311 : struct hostapd_bss_config *bss = conf->bss[0];
154 :
155 311 : conf->driver = wpa_s->driver;
156 :
157 311 : os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
158 :
159 311 : conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
160 : &conf->channel);
161 311 : if (conf->hw_mode == NUM_HOSTAPD_MODES) {
162 0 : wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
163 : ssid->frequency);
164 0 : return -1;
165 : }
166 :
167 311 : wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf);
168 :
169 311 : if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) {
170 1 : conf->ieee80211h = 1;
171 1 : conf->ieee80211d = 1;
172 1 : conf->country[0] = wpa_s->conf->country[0];
173 1 : conf->country[1] = wpa_s->conf->country[1];
174 : }
175 :
176 : #ifdef CONFIG_P2P
177 612 : if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
178 411 : (ssid->mode == WPAS_MODE_P2P_GO ||
179 110 : ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
180 : /* Remove 802.11b rates from supported and basic rate sets */
181 290 : int *list = os_malloc(4 * sizeof(int));
182 290 : if (list) {
183 290 : list[0] = 60;
184 290 : list[1] = 120;
185 290 : list[2] = 240;
186 290 : list[3] = -1;
187 : }
188 290 : conf->basic_rates = list;
189 :
190 290 : list = os_malloc(9 * sizeof(int));
191 290 : if (list) {
192 290 : list[0] = 60;
193 290 : list[1] = 90;
194 290 : list[2] = 120;
195 290 : list[3] = 180;
196 290 : list[4] = 240;
197 290 : list[5] = 360;
198 290 : list[6] = 480;
199 290 : list[7] = 540;
200 290 : list[8] = -1;
201 : }
202 290 : conf->supported_rates = list;
203 : }
204 :
205 311 : bss->isolate = !wpa_s->conf->p2p_intra_bss;
206 311 : bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
207 :
208 311 : if (ssid->p2p_group) {
209 298 : os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
210 298 : os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
211 : 4);
212 298 : os_memcpy(bss->ip_addr_start,
213 : wpa_s->parent->conf->ip_addr_start, 4);
214 298 : os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
215 : 4);
216 : }
217 : #endif /* CONFIG_P2P */
218 :
219 311 : if (ssid->ssid_len == 0) {
220 0 : wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
221 0 : return -1;
222 : }
223 311 : os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
224 311 : bss->ssid.ssid_len = ssid->ssid_len;
225 311 : bss->ssid.ssid_set = 1;
226 :
227 311 : bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
228 :
229 311 : if (ssid->auth_alg)
230 298 : bss->auth_algs = ssid->auth_alg;
231 :
232 311 : if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
233 304 : bss->wpa = ssid->proto;
234 311 : bss->wpa_key_mgmt = ssid->key_mgmt;
235 311 : bss->wpa_pairwise = ssid->pairwise_cipher;
236 311 : if (ssid->psk_set) {
237 304 : bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
238 304 : bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
239 304 : if (bss->ssid.wpa_psk == NULL)
240 0 : return -1;
241 304 : os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
242 304 : bss->ssid.wpa_psk->group = 1;
243 7 : } else if (ssid->passphrase) {
244 0 : bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
245 13 : } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
246 12 : ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
247 1 : struct hostapd_wep_keys *wep = &bss->ssid.wep;
248 : int i;
249 5 : for (i = 0; i < NUM_WEP_KEYS; i++) {
250 4 : if (ssid->wep_key_len[i] == 0)
251 3 : continue;
252 1 : wep->key[i] = os_malloc(ssid->wep_key_len[i]);
253 1 : if (wep->key[i] == NULL)
254 0 : return -1;
255 1 : os_memcpy(wep->key[i], ssid->wep_key[i],
256 : ssid->wep_key_len[i]);
257 1 : wep->len[i] = ssid->wep_key_len[i];
258 : }
259 1 : wep->idx = ssid->wep_tx_keyidx;
260 1 : wep->keys_set = 1;
261 : }
262 :
263 311 : if (ssid->ap_max_inactivity)
264 298 : bss->ap_max_inactivity = ssid->ap_max_inactivity;
265 :
266 311 : if (ssid->dtim_period)
267 0 : bss->dtim_period = ssid->dtim_period;
268 311 : else if (wpa_s->conf->dtim_period)
269 0 : bss->dtim_period = wpa_s->conf->dtim_period;
270 :
271 311 : if (ssid->beacon_int)
272 0 : conf->beacon_int = ssid->beacon_int;
273 311 : else if (wpa_s->conf->beacon_int)
274 0 : conf->beacon_int = wpa_s->conf->beacon_int;
275 :
276 : #ifdef CONFIG_P2P
277 311 : if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
278 0 : wpa_printf(MSG_INFO,
279 : "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
280 0 : wpa_s->conf->p2p_go_ctwindow, conf->beacon_int);
281 0 : conf->p2p_go_ctwindow = 0;
282 : } else {
283 311 : conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
284 : }
285 : #endif /* CONFIG_P2P */
286 :
287 311 : if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
288 304 : bss->rsn_pairwise = bss->wpa_pairwise;
289 311 : bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
290 : bss->rsn_pairwise);
291 :
292 311 : if (bss->wpa && bss->ieee802_1x)
293 0 : bss->ssid.security_policy = SECURITY_WPA;
294 311 : else if (bss->wpa)
295 304 : bss->ssid.security_policy = SECURITY_WPA_PSK;
296 7 : else if (bss->ieee802_1x) {
297 0 : int cipher = WPA_CIPHER_NONE;
298 0 : bss->ssid.security_policy = SECURITY_IEEE_802_1X;
299 0 : bss->ssid.wep.default_len = bss->default_wep_key_len;
300 0 : if (bss->default_wep_key_len)
301 0 : cipher = bss->default_wep_key_len >= 13 ?
302 0 : WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
303 0 : bss->wpa_group = cipher;
304 0 : bss->wpa_pairwise = cipher;
305 0 : bss->rsn_pairwise = cipher;
306 7 : } else if (bss->ssid.wep.keys_set) {
307 1 : int cipher = WPA_CIPHER_WEP40;
308 1 : if (bss->ssid.wep.len[0] >= 13)
309 0 : cipher = WPA_CIPHER_WEP104;
310 1 : bss->ssid.security_policy = SECURITY_STATIC_WEP;
311 1 : bss->wpa_group = cipher;
312 1 : bss->wpa_pairwise = cipher;
313 1 : bss->rsn_pairwise = cipher;
314 : } else {
315 6 : bss->ssid.security_policy = SECURITY_PLAINTEXT;
316 6 : bss->wpa_group = WPA_CIPHER_NONE;
317 6 : bss->wpa_pairwise = WPA_CIPHER_NONE;
318 6 : bss->rsn_pairwise = WPA_CIPHER_NONE;
319 : }
320 :
321 615 : if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
322 306 : (bss->wpa_group == WPA_CIPHER_CCMP ||
323 4 : bss->wpa_group == WPA_CIPHER_GCMP ||
324 4 : bss->wpa_group == WPA_CIPHER_CCMP_256 ||
325 2 : bss->wpa_group == WPA_CIPHER_GCMP_256)) {
326 : /*
327 : * Strong ciphers do not need frequent rekeying, so increase
328 : * the default GTK rekeying period to 24 hours.
329 : */
330 302 : bss->wpa_group_rekey = 86400;
331 : }
332 :
333 : #ifdef CONFIG_IEEE80211W
334 311 : if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
335 3 : bss->ieee80211w = ssid->ieee80211w;
336 : #endif /* CONFIG_IEEE80211W */
337 :
338 : #ifdef CONFIG_WPS
339 : /*
340 : * Enable WPS by default for open and WPA/WPA2-Personal network, but
341 : * require user interaction to actually use it. Only the internal
342 : * Registrar is supported.
343 : */
344 318 : if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
345 7 : bss->ssid.security_policy != SECURITY_PLAINTEXT)
346 1 : goto no_wps;
347 614 : if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
348 608 : (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
349 304 : !(bss->wpa & 2)))
350 : goto no_wps; /* WPS2 does not allow WPA/TKIP-only
351 : * configuration */
352 310 : bss->eap_server = 1;
353 :
354 310 : if (!ssid->ignore_broadcast_ssid)
355 310 : bss->wps_state = 2;
356 :
357 310 : bss->ap_setup_locked = 2;
358 310 : if (wpa_s->conf->config_methods)
359 8 : bss->config_methods = os_strdup(wpa_s->conf->config_methods);
360 310 : os_memcpy(bss->device_type, wpa_s->conf->device_type,
361 : WPS_DEV_TYPE_LEN);
362 310 : if (wpa_s->conf->device_name) {
363 292 : bss->device_name = os_strdup(wpa_s->conf->device_name);
364 292 : bss->friendly_name = os_strdup(wpa_s->conf->device_name);
365 : }
366 310 : if (wpa_s->conf->manufacturer)
367 0 : bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
368 310 : if (wpa_s->conf->model_name)
369 0 : bss->model_name = os_strdup(wpa_s->conf->model_name);
370 310 : if (wpa_s->conf->model_number)
371 0 : bss->model_number = os_strdup(wpa_s->conf->model_number);
372 310 : if (wpa_s->conf->serial_number)
373 0 : bss->serial_number = os_strdup(wpa_s->conf->serial_number);
374 310 : if (is_nil_uuid(wpa_s->conf->uuid))
375 310 : os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
376 : else
377 0 : os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
378 310 : os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
379 310 : bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
380 : no_wps:
381 : #endif /* CONFIG_WPS */
382 :
383 311 : if (wpa_s->max_stations &&
384 0 : wpa_s->max_stations < wpa_s->conf->max_num_sta)
385 0 : bss->max_num_sta = wpa_s->max_stations;
386 : else
387 311 : bss->max_num_sta = wpa_s->conf->max_num_sta;
388 :
389 311 : bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
390 :
391 311 : if (wpa_s->conf->ap_vendor_elements) {
392 0 : bss->vendor_elements =
393 0 : wpabuf_dup(wpa_s->conf->ap_vendor_elements);
394 : }
395 :
396 311 : return 0;
397 : }
398 :
399 :
400 75 : static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
401 : {
402 : #ifdef CONFIG_P2P
403 75 : struct wpa_supplicant *wpa_s = ctx;
404 : const struct ieee80211_mgmt *mgmt;
405 :
406 75 : mgmt = (const struct ieee80211_mgmt *) buf;
407 75 : if (len < IEEE80211_HDRLEN + 1)
408 0 : return;
409 75 : if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
410 0 : return;
411 150 : wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
412 75 : mgmt->u.action.category,
413 : buf + IEEE80211_HDRLEN + 1,
414 : len - IEEE80211_HDRLEN - 1, freq);
415 : #endif /* CONFIG_P2P */
416 : }
417 :
418 :
419 245 : static void ap_wps_event_cb(void *ctx, enum wps_event event,
420 : union wps_event_data *data)
421 : {
422 : #ifdef CONFIG_P2P
423 245 : struct wpa_supplicant *wpa_s = ctx;
424 :
425 245 : if (event == WPS_EV_FAIL) {
426 10 : struct wps_event_fail *fail = &data->fail;
427 :
428 10 : if (wpa_s->parent && wpa_s->parent != wpa_s &&
429 0 : wpa_s == wpa_s->global->p2p_group_formation) {
430 : /*
431 : * src/ap/wps_hostapd.c has already sent this on the
432 : * main interface, so only send on the parent interface
433 : * here if needed.
434 : */
435 0 : wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
436 : "msg=%d config_error=%d",
437 0 : fail->msg, fail->config_error);
438 : }
439 10 : wpas_p2p_wps_failed(wpa_s, fail);
440 : }
441 : #endif /* CONFIG_P2P */
442 245 : }
443 :
444 :
445 430 : static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
446 : int authorized, const u8 *p2p_dev_addr)
447 : {
448 430 : wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
449 430 : }
450 :
451 :
452 : #ifdef CONFIG_P2P
453 8 : static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
454 : const u8 *psk, size_t psk_len)
455 : {
456 :
457 8 : struct wpa_supplicant *wpa_s = ctx;
458 8 : if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
459 8 : return;
460 8 : wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
461 : }
462 : #endif /* CONFIG_P2P */
463 :
464 :
465 5 : static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
466 : {
467 : #ifdef CONFIG_P2P
468 5 : struct wpa_supplicant *wpa_s = ctx;
469 : const struct ieee80211_mgmt *mgmt;
470 :
471 5 : mgmt = (const struct ieee80211_mgmt *) buf;
472 5 : if (len < IEEE80211_HDRLEN + 1)
473 0 : return -1;
474 10 : wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
475 5 : mgmt->u.action.category,
476 : buf + IEEE80211_HDRLEN + 1,
477 : len - IEEE80211_HDRLEN - 1, freq);
478 : #endif /* CONFIG_P2P */
479 5 : return 0;
480 : }
481 :
482 :
483 400 : static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
484 : const u8 *bssid, const u8 *ie, size_t ie_len,
485 : int ssi_signal)
486 : {
487 400 : struct wpa_supplicant *wpa_s = ctx;
488 400 : return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
489 : ssi_signal);
490 : }
491 :
492 :
493 168 : static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
494 : const u8 *uuid_e)
495 : {
496 168 : struct wpa_supplicant *wpa_s = ctx;
497 168 : wpas_p2p_wps_success(wpa_s, mac_addr, 1);
498 168 : }
499 :
500 :
501 311 : static void wpas_ap_configured_cb(void *ctx)
502 : {
503 311 : struct wpa_supplicant *wpa_s = ctx;
504 :
505 311 : wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
506 :
507 311 : if (wpa_s->ap_configured_cb)
508 298 : wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
509 : wpa_s->ap_configured_cb_data);
510 311 : }
511 :
512 :
513 313 : int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
514 : struct wpa_ssid *ssid)
515 : {
516 : struct wpa_driver_associate_params params;
517 : struct hostapd_iface *hapd_iface;
518 : struct hostapd_config *conf;
519 : size_t i;
520 :
521 313 : if (ssid->ssid == NULL || ssid->ssid_len == 0) {
522 1 : wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
523 1 : return -1;
524 : }
525 :
526 312 : wpa_supplicant_ap_deinit(wpa_s);
527 :
528 624 : wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
529 312 : wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
530 :
531 312 : os_memset(¶ms, 0, sizeof(params));
532 312 : params.ssid = ssid->ssid;
533 312 : params.ssid_len = ssid->ssid_len;
534 312 : switch (ssid->mode) {
535 : case WPAS_MODE_AP:
536 : case WPAS_MODE_P2P_GO:
537 : case WPAS_MODE_P2P_GROUP_FORMATION:
538 312 : params.mode = IEEE80211_MODE_AP;
539 312 : break;
540 : default:
541 0 : return -1;
542 : }
543 312 : if (ssid->frequency == 0)
544 2 : ssid->frequency = 2462; /* default channel 11 */
545 312 : params.freq.freq = ssid->frequency;
546 :
547 312 : params.wpa_proto = ssid->proto;
548 312 : if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
549 301 : wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
550 : else
551 11 : wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
552 312 : params.key_mgmt_suite = wpa_s->key_mgmt;
553 :
554 312 : wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
555 : 1);
556 312 : if (wpa_s->pairwise_cipher < 0) {
557 0 : wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
558 : "cipher.");
559 0 : return -1;
560 : }
561 312 : params.pairwise_suite = wpa_s->pairwise_cipher;
562 312 : params.group_suite = params.pairwise_suite;
563 :
564 : #ifdef CONFIG_P2P
565 429 : if (ssid->mode == WPAS_MODE_P2P_GO ||
566 117 : ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
567 298 : params.p2p = 1;
568 : #endif /* CONFIG_P2P */
569 :
570 312 : if (wpa_s->parent->set_ap_uapsd)
571 0 : params.uapsd = wpa_s->parent->ap_uapsd;
572 312 : else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
573 298 : params.uapsd = 1; /* mandatory for P2P GO */
574 : else
575 14 : params.uapsd = -1;
576 :
577 312 : if (ieee80211_is_dfs(params.freq.freq))
578 1 : params.freq.freq = 0; /* set channel after CAC */
579 :
580 312 : if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
581 1 : wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
582 1 : return -1;
583 : }
584 :
585 311 : wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
586 311 : if (hapd_iface == NULL)
587 0 : return -1;
588 311 : hapd_iface->owner = wpa_s;
589 311 : hapd_iface->drv_flags = wpa_s->drv_flags;
590 311 : hapd_iface->smps_modes = wpa_s->drv_smps_modes;
591 311 : hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
592 311 : hapd_iface->extended_capa = wpa_s->extended_capa;
593 311 : hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
594 311 : hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
595 :
596 311 : wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
597 311 : if (conf == NULL) {
598 0 : wpa_supplicant_ap_deinit(wpa_s);
599 0 : return -1;
600 : }
601 :
602 311 : os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
603 : wpa_s->conf->wmm_ac_params,
604 : sizeof(wpa_s->conf->wmm_ac_params));
605 :
606 311 : if (params.uapsd > 0) {
607 298 : conf->bss[0]->wmm_enabled = 1;
608 298 : conf->bss[0]->wmm_uapsd = 1;
609 : }
610 :
611 311 : if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
612 0 : wpa_printf(MSG_ERROR, "Failed to create AP configuration");
613 0 : wpa_supplicant_ap_deinit(wpa_s);
614 0 : return -1;
615 : }
616 :
617 : #ifdef CONFIG_P2P
618 311 : if (ssid->mode == WPAS_MODE_P2P_GO)
619 195 : conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
620 116 : else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
621 103 : conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
622 : P2P_GROUP_FORMATION;
623 : #endif /* CONFIG_P2P */
624 :
625 311 : hapd_iface->num_bss = conf->num_bss;
626 311 : hapd_iface->bss = os_calloc(conf->num_bss,
627 : sizeof(struct hostapd_data *));
628 311 : if (hapd_iface->bss == NULL) {
629 0 : wpa_supplicant_ap_deinit(wpa_s);
630 0 : return -1;
631 : }
632 :
633 622 : for (i = 0; i < conf->num_bss; i++) {
634 622 : hapd_iface->bss[i] =
635 311 : hostapd_alloc_bss_data(hapd_iface, conf,
636 311 : conf->bss[i]);
637 311 : if (hapd_iface->bss[i] == NULL) {
638 0 : wpa_supplicant_ap_deinit(wpa_s);
639 0 : return -1;
640 : }
641 :
642 311 : hapd_iface->bss[i]->msg_ctx = wpa_s;
643 311 : hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
644 311 : hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
645 311 : hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
646 311 : hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
647 311 : hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
648 311 : hostapd_register_probereq_cb(hapd_iface->bss[i],
649 : ap_probe_req_rx, wpa_s);
650 311 : hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
651 311 : hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
652 311 : hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
653 311 : hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
654 311 : hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
655 311 : hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
656 : #ifdef CONFIG_P2P
657 311 : hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
658 311 : hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
659 311 : hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
660 311 : hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
661 : ssid);
662 : #endif /* CONFIG_P2P */
663 311 : hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
664 311 : hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
665 : #ifdef CONFIG_TESTING_OPTIONS
666 622 : hapd_iface->bss[i]->ext_eapol_frame_io =
667 311 : wpa_s->ext_eapol_frame_io;
668 : #endif /* CONFIG_TESTING_OPTIONS */
669 : }
670 :
671 311 : os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
672 311 : hapd_iface->bss[0]->driver = wpa_s->driver;
673 311 : hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
674 :
675 311 : wpa_s->current_ssid = ssid;
676 311 : eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
677 311 : os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
678 311 : wpa_s->assoc_freq = ssid->frequency;
679 :
680 311 : if (hostapd_setup_interface(wpa_s->ap_iface)) {
681 0 : wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
682 0 : wpa_supplicant_ap_deinit(wpa_s);
683 0 : return -1;
684 : }
685 :
686 311 : return 0;
687 : }
688 :
689 :
690 6017 : void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
691 : {
692 : #ifdef CONFIG_WPS
693 6017 : eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
694 : #endif /* CONFIG_WPS */
695 :
696 6017 : if (wpa_s->ap_iface == NULL)
697 11723 : return;
698 :
699 311 : wpa_s->current_ssid = NULL;
700 311 : eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
701 311 : wpa_s->assoc_freq = 0;
702 311 : wpas_p2p_ap_deinit(wpa_s);
703 622 : wpa_s->ap_iface->driver_ap_teardown =
704 311 : !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
705 :
706 311 : hostapd_interface_deinit(wpa_s->ap_iface);
707 311 : hostapd_interface_free(wpa_s->ap_iface);
708 311 : wpa_s->ap_iface = NULL;
709 311 : wpa_drv_deinit_ap(wpa_s);
710 1866 : wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
711 : " reason=%d locally_generated=1",
712 1866 : MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
713 : }
714 :
715 :
716 10 : void ap_tx_status(void *ctx, const u8 *addr,
717 : const u8 *buf, size_t len, int ack)
718 : {
719 : #ifdef NEED_AP_MLME
720 10 : struct wpa_supplicant *wpa_s = ctx;
721 10 : hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
722 : #endif /* NEED_AP_MLME */
723 10 : }
724 :
725 :
726 1650 : void ap_eapol_tx_status(void *ctx, const u8 *dst,
727 : const u8 *data, size_t len, int ack)
728 : {
729 : #ifdef NEED_AP_MLME
730 1650 : struct wpa_supplicant *wpa_s = ctx;
731 1650 : if (!wpa_s->ap_iface)
732 1651 : return;
733 1649 : hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
734 : #endif /* NEED_AP_MLME */
735 : }
736 :
737 :
738 0 : void ap_client_poll_ok(void *ctx, const u8 *addr)
739 : {
740 : #ifdef NEED_AP_MLME
741 0 : struct wpa_supplicant *wpa_s = ctx;
742 0 : if (wpa_s->ap_iface)
743 0 : hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
744 : #endif /* NEED_AP_MLME */
745 0 : }
746 :
747 :
748 0 : void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
749 : {
750 : #ifdef NEED_AP_MLME
751 0 : struct wpa_supplicant *wpa_s = ctx;
752 0 : ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
753 : #endif /* NEED_AP_MLME */
754 0 : }
755 :
756 :
757 1898 : void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
758 : {
759 : #ifdef NEED_AP_MLME
760 1898 : struct wpa_supplicant *wpa_s = ctx;
761 : struct hostapd_frame_info fi;
762 1898 : os_memset(&fi, 0, sizeof(fi));
763 1898 : fi.datarate = rx_mgmt->datarate;
764 1898 : fi.ssi_signal = rx_mgmt->ssi_signal;
765 1898 : ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
766 : rx_mgmt->frame_len, &fi);
767 : #endif /* NEED_AP_MLME */
768 1898 : }
769 :
770 :
771 1268 : void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
772 : {
773 : #ifdef NEED_AP_MLME
774 1268 : struct wpa_supplicant *wpa_s = ctx;
775 1268 : ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
776 : #endif /* NEED_AP_MLME */
777 1268 : }
778 :
779 :
780 1486 : void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
781 : const u8 *src_addr, const u8 *buf, size_t len)
782 : {
783 1486 : ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
784 1486 : }
785 :
786 :
787 : #ifdef CONFIG_WPS
788 :
789 31 : int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
790 : const u8 *p2p_dev_addr)
791 : {
792 31 : if (!wpa_s->ap_iface)
793 0 : return -1;
794 31 : return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
795 : p2p_dev_addr);
796 : }
797 :
798 :
799 9 : int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
800 : {
801 : struct wps_registrar *reg;
802 9 : int reg_sel = 0, wps_sta = 0;
803 :
804 9 : if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
805 1 : return -1;
806 :
807 8 : reg = wpa_s->ap_iface->bss[0]->wps->registrar;
808 8 : reg_sel = wps_registrar_wps_cancel(reg);
809 8 : wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
810 : ap_sta_wps_cancel, NULL);
811 :
812 8 : if (!reg_sel && !wps_sta) {
813 6 : wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
814 : "time");
815 6 : return -1;
816 : }
817 :
818 : /*
819 : * There are 2 cases to return wps cancel as success:
820 : * 1. When wps cancel was initiated but no connection has been
821 : * established with client yet.
822 : * 2. Client is in the middle of exchanging WPS messages.
823 : */
824 :
825 2 : return 0;
826 : }
827 :
828 :
829 134 : int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
830 : const char *pin, char *buf, size_t buflen,
831 : int timeout)
832 : {
833 134 : int ret, ret_len = 0;
834 :
835 134 : if (!wpa_s->ap_iface)
836 0 : return -1;
837 :
838 134 : if (pin == NULL) {
839 0 : unsigned int rpin = wps_generate_pin();
840 0 : ret_len = os_snprintf(buf, buflen, "%08d", rpin);
841 0 : if (os_snprintf_error(buflen, ret_len))
842 0 : return -1;
843 0 : pin = buf;
844 134 : } else if (buf) {
845 55 : ret_len = os_snprintf(buf, buflen, "%s", pin);
846 55 : if (os_snprintf_error(buflen, ret_len))
847 0 : return -1;
848 : }
849 :
850 134 : ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
851 : timeout);
852 134 : if (ret)
853 0 : return -1;
854 134 : return ret_len;
855 : }
856 :
857 :
858 2 : static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
859 : {
860 2 : struct wpa_supplicant *wpa_s = eloop_data;
861 2 : wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
862 2 : wpas_wps_ap_pin_disable(wpa_s);
863 2 : }
864 :
865 :
866 4 : static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
867 : {
868 : struct hostapd_data *hapd;
869 :
870 4 : if (wpa_s->ap_iface == NULL)
871 4 : return;
872 4 : hapd = wpa_s->ap_iface->bss[0];
873 4 : wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
874 4 : hapd->ap_pin_failures = 0;
875 4 : eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
876 4 : if (timeout > 0)
877 4 : eloop_register_timeout(timeout, 0,
878 : wpas_wps_ap_pin_timeout, wpa_s, NULL);
879 : }
880 :
881 :
882 3 : void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
883 : {
884 : struct hostapd_data *hapd;
885 :
886 3 : if (wpa_s->ap_iface == NULL)
887 3 : return;
888 3 : wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
889 3 : hapd = wpa_s->ap_iface->bss[0];
890 3 : os_free(hapd->conf->ap_pin);
891 3 : hapd->conf->ap_pin = NULL;
892 3 : eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
893 : }
894 :
895 :
896 2 : const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
897 : {
898 : struct hostapd_data *hapd;
899 : unsigned int pin;
900 : char pin_txt[9];
901 :
902 2 : if (wpa_s->ap_iface == NULL)
903 0 : return NULL;
904 2 : hapd = wpa_s->ap_iface->bss[0];
905 2 : pin = wps_generate_pin();
906 2 : os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
907 2 : os_free(hapd->conf->ap_pin);
908 2 : hapd->conf->ap_pin = os_strdup(pin_txt);
909 2 : if (hapd->conf->ap_pin == NULL)
910 0 : return NULL;
911 2 : wpas_wps_ap_pin_enable(wpa_s, timeout);
912 :
913 2 : return hapd->conf->ap_pin;
914 : }
915 :
916 :
917 8 : const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
918 : {
919 : struct hostapd_data *hapd;
920 8 : if (wpa_s->ap_iface == NULL)
921 0 : return NULL;
922 8 : hapd = wpa_s->ap_iface->bss[0];
923 8 : return hapd->conf->ap_pin;
924 : }
925 :
926 :
927 2 : int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
928 : int timeout)
929 : {
930 : struct hostapd_data *hapd;
931 : char pin_txt[9];
932 : int ret;
933 :
934 2 : if (wpa_s->ap_iface == NULL)
935 0 : return -1;
936 2 : hapd = wpa_s->ap_iface->bss[0];
937 2 : ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
938 2 : if (os_snprintf_error(sizeof(pin_txt), ret))
939 0 : return -1;
940 2 : os_free(hapd->conf->ap_pin);
941 2 : hapd->conf->ap_pin = os_strdup(pin_txt);
942 2 : if (hapd->conf->ap_pin == NULL)
943 0 : return -1;
944 2 : wpas_wps_ap_pin_enable(wpa_s, timeout);
945 :
946 2 : return 0;
947 : }
948 :
949 :
950 0 : void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
951 : {
952 : struct hostapd_data *hapd;
953 :
954 0 : if (wpa_s->ap_iface == NULL)
955 0 : return;
956 0 : hapd = wpa_s->ap_iface->bss[0];
957 :
958 : /*
959 : * Registrar failed to prove its knowledge of the AP PIN. Disable AP
960 : * PIN if this happens multiple times to slow down brute force attacks.
961 : */
962 0 : hapd->ap_pin_failures++;
963 0 : wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
964 : hapd->ap_pin_failures);
965 0 : if (hapd->ap_pin_failures < 3)
966 0 : return;
967 :
968 0 : wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
969 0 : hapd->ap_pin_failures = 0;
970 0 : os_free(hapd->conf->ap_pin);
971 0 : hapd->conf->ap_pin = NULL;
972 : }
973 :
974 :
975 : #ifdef CONFIG_WPS_NFC
976 :
977 1 : struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
978 : int ndef)
979 : {
980 : struct hostapd_data *hapd;
981 :
982 1 : if (wpa_s->ap_iface == NULL)
983 0 : return NULL;
984 1 : hapd = wpa_s->ap_iface->bss[0];
985 1 : return hostapd_wps_nfc_config_token(hapd, ndef);
986 : }
987 :
988 :
989 4 : struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
990 : int ndef)
991 : {
992 : struct hostapd_data *hapd;
993 :
994 4 : if (wpa_s->ap_iface == NULL)
995 3 : return NULL;
996 1 : hapd = wpa_s->ap_iface->bss[0];
997 1 : return hostapd_wps_nfc_hs_cr(hapd, ndef);
998 : }
999 :
1000 :
1001 4 : int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1002 : const struct wpabuf *req,
1003 : const struct wpabuf *sel)
1004 : {
1005 : struct hostapd_data *hapd;
1006 :
1007 4 : if (wpa_s->ap_iface == NULL)
1008 3 : return -1;
1009 1 : hapd = wpa_s->ap_iface->bss[0];
1010 1 : return hostapd_wps_nfc_report_handover(hapd, req, sel);
1011 : }
1012 :
1013 : #endif /* CONFIG_WPS_NFC */
1014 :
1015 : #endif /* CONFIG_WPS */
1016 :
1017 :
1018 : #ifdef CONFIG_CTRL_IFACE
1019 :
1020 1 : int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1021 : char *buf, size_t buflen)
1022 : {
1023 : struct hostapd_data *hapd;
1024 :
1025 1 : if (wpa_s->ap_iface)
1026 1 : hapd = wpa_s->ap_iface->bss[0];
1027 0 : else if (wpa_s->ifmsh)
1028 0 : hapd = wpa_s->ifmsh->bss[0];
1029 : else
1030 0 : return -1;
1031 1 : return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
1032 : }
1033 :
1034 :
1035 1 : int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1036 : char *buf, size_t buflen)
1037 : {
1038 : struct hostapd_data *hapd;
1039 :
1040 1 : if (wpa_s->ap_iface)
1041 1 : hapd = wpa_s->ap_iface->bss[0];
1042 0 : else if (wpa_s->ifmsh)
1043 0 : hapd = wpa_s->ifmsh->bss[0];
1044 : else
1045 0 : return -1;
1046 1 : return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
1047 : }
1048 :
1049 :
1050 2 : int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1051 : char *buf, size_t buflen)
1052 : {
1053 : struct hostapd_data *hapd;
1054 :
1055 2 : if (wpa_s->ap_iface)
1056 2 : hapd = wpa_s->ap_iface->bss[0];
1057 0 : else if (wpa_s->ifmsh)
1058 0 : hapd = wpa_s->ifmsh->bss[0];
1059 : else
1060 0 : return -1;
1061 2 : return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
1062 : }
1063 :
1064 :
1065 23 : int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1066 : const char *txtaddr)
1067 : {
1068 23 : if (wpa_s->ap_iface == NULL)
1069 1 : return -1;
1070 22 : return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1071 : txtaddr);
1072 : }
1073 :
1074 :
1075 22 : int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1076 : const char *txtaddr)
1077 : {
1078 22 : if (wpa_s->ap_iface == NULL)
1079 1 : return -1;
1080 21 : return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1081 : txtaddr);
1082 : }
1083 :
1084 :
1085 195 : int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1086 : size_t buflen, int verbose)
1087 : {
1088 195 : char *pos = buf, *end = buf + buflen;
1089 : int ret;
1090 : struct hostapd_bss_config *conf;
1091 :
1092 195 : if (wpa_s->ap_iface == NULL)
1093 0 : return -1;
1094 :
1095 195 : conf = wpa_s->ap_iface->bss[0]->conf;
1096 195 : if (conf->wpa == 0)
1097 3 : return 0;
1098 :
1099 192 : ret = os_snprintf(pos, end - pos,
1100 : "pairwise_cipher=%s\n"
1101 : "group_cipher=%s\n"
1102 : "key_mgmt=%s\n",
1103 : wpa_cipher_txt(conf->rsn_pairwise),
1104 : wpa_cipher_txt(conf->wpa_group),
1105 : wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1106 : conf->wpa));
1107 192 : if (os_snprintf_error(end - pos, ret))
1108 0 : return pos - buf;
1109 192 : pos += ret;
1110 192 : return pos - buf;
1111 : }
1112 :
1113 : #endif /* CONFIG_CTRL_IFACE */
1114 :
1115 :
1116 1206 : int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1117 : {
1118 1206 : struct hostapd_iface *iface = wpa_s->ap_iface;
1119 1206 : struct wpa_ssid *ssid = wpa_s->current_ssid;
1120 : struct hostapd_data *hapd;
1121 :
1122 1919 : if (ssid == NULL || wpa_s->ap_iface == NULL ||
1123 1426 : ssid->mode == WPAS_MODE_INFRA ||
1124 713 : ssid->mode == WPAS_MODE_IBSS)
1125 493 : return -1;
1126 :
1127 : #ifdef CONFIG_P2P
1128 713 : if (ssid->mode == WPAS_MODE_P2P_GO)
1129 606 : iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
1130 107 : else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1131 107 : iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
1132 : P2P_GROUP_FORMATION;
1133 : #endif /* CONFIG_P2P */
1134 :
1135 713 : hapd = iface->bss[0];
1136 713 : if (hapd->drv_priv == NULL)
1137 0 : return -1;
1138 713 : ieee802_11_set_beacons(iface);
1139 713 : hostapd_set_ap_wps_ie(hapd);
1140 :
1141 713 : return 0;
1142 : }
1143 :
1144 :
1145 2 : int ap_switch_channel(struct wpa_supplicant *wpa_s,
1146 : struct csa_settings *settings)
1147 : {
1148 : #ifdef NEED_AP_MLME
1149 2 : if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1150 1 : return -1;
1151 :
1152 1 : return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1153 : #else /* NEED_AP_MLME */
1154 : return -1;
1155 : #endif /* NEED_AP_MLME */
1156 : }
1157 :
1158 :
1159 2 : int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1160 : {
1161 : struct csa_settings settings;
1162 2 : int ret = hostapd_parse_csa_settings(pos, &settings);
1163 :
1164 2 : if (ret)
1165 0 : return ret;
1166 :
1167 2 : return ap_switch_channel(wpa_s, &settings);
1168 : }
1169 :
1170 :
1171 1 : void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
1172 : int offset, int width, int cf1, int cf2)
1173 : {
1174 1 : if (!wpa_s->ap_iface)
1175 1 : return;
1176 :
1177 1 : wpa_s->assoc_freq = freq;
1178 1 : hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
1179 : }
1180 :
1181 :
1182 202 : int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1183 : const u8 *addr)
1184 : {
1185 : struct hostapd_data *hapd;
1186 : struct hostapd_bss_config *conf;
1187 :
1188 202 : if (!wpa_s->ap_iface)
1189 0 : return -1;
1190 :
1191 202 : if (addr)
1192 618 : wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1193 618 : MAC2STR(addr));
1194 : else
1195 99 : wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1196 :
1197 202 : hapd = wpa_s->ap_iface->bss[0];
1198 202 : conf = hapd->conf;
1199 :
1200 202 : os_free(conf->accept_mac);
1201 202 : conf->accept_mac = NULL;
1202 202 : conf->num_accept_mac = 0;
1203 202 : os_free(conf->deny_mac);
1204 202 : conf->deny_mac = NULL;
1205 202 : conf->num_deny_mac = 0;
1206 :
1207 202 : if (addr == NULL) {
1208 99 : conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1209 99 : return 0;
1210 : }
1211 :
1212 103 : conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1213 103 : conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1214 103 : if (conf->accept_mac == NULL)
1215 0 : return -1;
1216 103 : os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1217 103 : conf->num_accept_mac = 1;
1218 :
1219 103 : return 0;
1220 : }
1221 :
1222 :
1223 : #ifdef CONFIG_WPS_NFC
1224 13 : int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1225 : const struct wpabuf *pw, const u8 *pubkey_hash)
1226 : {
1227 : struct hostapd_data *hapd;
1228 : struct wps_context *wps;
1229 :
1230 13 : if (!wpa_s->ap_iface)
1231 0 : return -1;
1232 13 : hapd = wpa_s->ap_iface->bss[0];
1233 13 : wps = hapd->wps;
1234 :
1235 26 : if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1236 13 : wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1237 0 : wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1238 0 : return -1;
1239 : }
1240 :
1241 13 : dh5_free(wps->dh_ctx);
1242 13 : wpabuf_free(wps->dh_pubkey);
1243 13 : wpabuf_free(wps->dh_privkey);
1244 13 : wps->dh_privkey = wpabuf_dup(
1245 13 : wpa_s->parent->conf->wps_nfc_dh_privkey);
1246 13 : wps->dh_pubkey = wpabuf_dup(
1247 13 : wpa_s->parent->conf->wps_nfc_dh_pubkey);
1248 13 : if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1249 0 : wps->dh_ctx = NULL;
1250 0 : wpabuf_free(wps->dh_pubkey);
1251 0 : wps->dh_pubkey = NULL;
1252 0 : wpabuf_free(wps->dh_privkey);
1253 0 : wps->dh_privkey = NULL;
1254 0 : return -1;
1255 : }
1256 13 : wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1257 13 : if (wps->dh_ctx == NULL)
1258 0 : return -1;
1259 :
1260 13 : return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1261 : pw_id,
1262 : pw ? wpabuf_head(pw) : NULL,
1263 : pw ? wpabuf_len(pw) : 0, 1);
1264 : }
1265 : #endif /* CONFIG_WPS_NFC */
1266 :
1267 :
1268 1 : int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1269 : {
1270 : struct hostapd_data *hapd;
1271 :
1272 1 : if (!wpa_s->ap_iface)
1273 0 : return -1;
1274 1 : hapd = wpa_s->ap_iface->bss[0];
1275 1 : return hostapd_ctrl_iface_stop_ap(hapd);
1276 : }
1277 :
1278 :
1279 : #ifdef NEED_AP_MLME
1280 21 : void wpas_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1281 : struct dfs_event *radar)
1282 : {
1283 21 : if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1284 42 : return;
1285 0 : wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
1286 0 : hostapd_dfs_radar_detected(wpa_s->ap_iface, radar->freq,
1287 : radar->ht_enabled, radar->chan_offset,
1288 0 : radar->chan_width,
1289 : radar->cf1, radar->cf2);
1290 : }
1291 :
1292 :
1293 0 : void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1294 : struct dfs_event *radar)
1295 : {
1296 0 : if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1297 0 : return;
1298 0 : wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
1299 0 : hostapd_dfs_start_cac(wpa_s->ap_iface, radar->freq,
1300 : radar->ht_enabled, radar->chan_offset,
1301 0 : radar->chan_width, radar->cf1, radar->cf2);
1302 : }
1303 :
1304 :
1305 1 : void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1306 : struct dfs_event *radar)
1307 : {
1308 1 : if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1309 1 : return;
1310 1 : wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
1311 2 : hostapd_dfs_complete_cac(wpa_s->ap_iface, 1, radar->freq,
1312 : radar->ht_enabled, radar->chan_offset,
1313 1 : radar->chan_width, radar->cf1, radar->cf2);
1314 : }
1315 :
1316 :
1317 0 : void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1318 : struct dfs_event *radar)
1319 : {
1320 0 : if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1321 0 : return;
1322 0 : wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
1323 0 : hostapd_dfs_complete_cac(wpa_s->ap_iface, 0, radar->freq,
1324 : radar->ht_enabled, radar->chan_offset,
1325 0 : radar->chan_width, radar->cf1, radar->cf2);
1326 : }
1327 :
1328 :
1329 0 : void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1330 : struct dfs_event *radar)
1331 : {
1332 0 : if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1333 0 : return;
1334 0 : wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
1335 0 : hostapd_dfs_nop_finished(wpa_s->ap_iface, radar->freq,
1336 : radar->ht_enabled, radar->chan_offset,
1337 0 : radar->chan_width, radar->cf1, radar->cf2);
1338 : }
1339 : #endif /* NEED_AP_MLME */
|