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