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