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