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