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