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