]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/ap.c
Add max_num_sta config option for wpa_supplicant AP mode
[thirdparty/hostap.git] / wpa_supplicant / ap.c
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
16 #include "utils/includes.h"
17
18 #include "utils/common.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/wpa_ctrl.h"
21 #include "ap/hostapd.h"
22 #include "ap/ap_config.h"
23 #ifdef NEED_AP_MLME
24 #include "ap/ieee802_11.h"
25 #endif /* NEED_AP_MLME */
26 #include "ap/beacon.h"
27 #include "ap/ieee802_1x.h"
28 #include "ap/wps_hostapd.h"
29 #include "ap/ctrl_iface_ap.h"
30 #include "eap_common/eap_defs.h"
31 #include "eap_server/eap_methods.h"
32 #include "eap_common/eap_wsc_common.h"
33 #include "wps/wps.h"
34 #include "common/ieee802_11_defs.h"
35 #include "config_ssid.h"
36 #include "config.h"
37 #include "wpa_supplicant_i.h"
38 #include "driver_i.h"
39 #include "p2p_supplicant.h"
40 #include "ap.h"
41 #include "ap/sta_info.h"
42
43
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];
49 int pairwise;
50
51 conf->driver = wpa_s->driver;
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)) {
64 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
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
72 /* TODO: enable HT if driver supports it;
73 * drop to 11b if driver does not support 11g */
74
75 #ifdef CONFIG_P2P
76 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
77 /* Remove 802.11b rates from supported and basic rate sets */
78 int *list = os_malloc(4 * sizeof(int));
79 if (list) {
80 list[0] = 60;
81 list[1] = 120;
82 list[2] = 240;
83 list[3] = -1;
84 }
85 conf->basic_rates = list;
86
87 list = os_malloc(9 * sizeof(int));
88 if (list) {
89 list[0] = 60;
90 list[1] = 90;
91 list[2] = 120;
92 list[3] = 180;
93 list[4] = 240;
94 list[5] = 360;
95 list[6] = 480;
96 list[7] = 540;
97 list[8] = -1;
98 }
99 conf->supported_rates = list;
100 }
101 #endif /* CONFIG_P2P */
102
103 if (ssid->ssid_len == 0) {
104 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
105 return -1;
106 }
107 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
108 bss->ssid.ssid[ssid->ssid_len] = '\0';
109 bss->ssid.ssid_len = ssid->ssid_len;
110 bss->ssid.ssid_set = 1;
111
112 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
113 bss->wpa = ssid->proto;
114 bss->wpa_key_mgmt = ssid->key_mgmt;
115 bss->wpa_pairwise = ssid->pairwise_cipher;
116 if (ssid->passphrase) {
117 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
118 } else if (ssid->psk_set) {
119 os_free(bss->ssid.wpa_psk);
120 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
121 if (bss->ssid.wpa_psk == NULL)
122 return -1;
123 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
124 bss->ssid.wpa_psk->group = 1;
125 }
126
127 /* Select group cipher based on the enabled pairwise cipher suites */
128 pairwise = 0;
129 if (bss->wpa & 1)
130 pairwise |= bss->wpa_pairwise;
131 if (bss->wpa & 2) {
132 if (bss->rsn_pairwise == 0)
133 bss->rsn_pairwise = bss->wpa_pairwise;
134 pairwise |= bss->rsn_pairwise;
135 }
136 if (pairwise & WPA_CIPHER_TKIP)
137 bss->wpa_group = WPA_CIPHER_TKIP;
138 else
139 bss->wpa_group = WPA_CIPHER_CCMP;
140
141 if (bss->wpa && bss->ieee802_1x)
142 bss->ssid.security_policy = SECURITY_WPA;
143 else if (bss->wpa)
144 bss->ssid.security_policy = SECURITY_WPA_PSK;
145 else if (bss->ieee802_1x) {
146 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
147 bss->ssid.wep.default_len = bss->default_wep_key_len;
148 } else if (bss->ssid.wep.keys_set)
149 bss->ssid.security_policy = SECURITY_STATIC_WEP;
150 else
151 bss->ssid.security_policy = SECURITY_PLAINTEXT;
152
153 #ifdef CONFIG_WPS
154 /*
155 * Enable WPS by default, but require user interaction to actually use
156 * it. Only the internal Registrar is supported.
157 */
158 bss->eap_server = 1;
159 bss->wps_state = 2;
160 bss->ap_setup_locked = 1;
161 if (wpa_s->conf->config_methods)
162 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
163 if (wpa_s->conf->device_type)
164 bss->device_type = os_strdup(wpa_s->conf->device_type);
165 if (wpa_s->conf->device_name) {
166 bss->device_name = os_strdup(wpa_s->conf->device_name);
167 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
168 }
169 if (wpa_s->conf->manufacturer)
170 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
171 if (wpa_s->conf->model_name)
172 bss->model_name = os_strdup(wpa_s->conf->model_name);
173 if (wpa_s->conf->model_number)
174 bss->model_number = os_strdup(wpa_s->conf->model_number);
175 if (wpa_s->conf->serial_number)
176 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
177 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
178 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
179 #endif /* CONFIG_WPS */
180
181 bss->max_num_sta = wpa_s->conf->max_num_sta;
182
183 return 0;
184 }
185
186
187 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
188 {
189 #ifdef CONFIG_P2P
190 struct wpa_supplicant *wpa_s = ctx;
191 const struct ieee80211_mgmt *mgmt;
192 size_t hdr_len;
193
194 mgmt = (const struct ieee80211_mgmt *) buf;
195 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
196 if (hdr_len > len)
197 return;
198 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
199 mgmt->u.action.category,
200 &mgmt->u.action.u.vs_public_action.action,
201 len - hdr_len, freq);
202 #endif /* CONFIG_P2P */
203 }
204
205
206 static void ap_wps_event_cb(void *ctx, enum wps_event event,
207 union wps_event_data *data)
208 {
209 struct wpa_supplicant *wpa_s = ctx;
210
211 if (event == WPS_EV_FAIL && wpa_s->parent && wpa_s->parent != wpa_s) {
212 struct wps_event_fail *fail = &data->fail;
213
214 /*
215 * src/ap/wps_hostapd.c has already sent this on the main
216 * interface, so only send on the parent interface here if
217 * needed.
218 */
219 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
220 "msg=%d config_error=%d",
221 fail->msg, fail->config_error);
222 }
223 }
224
225
226 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
227 {
228 #ifdef CONFIG_P2P
229 struct wpa_supplicant *wpa_s = ctx;
230 const struct ieee80211_mgmt *mgmt;
231 size_t hdr_len;
232
233 mgmt = (const struct ieee80211_mgmt *) buf;
234 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
235 if (hdr_len > len)
236 return -1;
237 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
238 mgmt->u.action.category,
239 &mgmt->u.action.u.vs_public_action.action,
240 len - hdr_len, freq);
241 #endif /* CONFIG_P2P */
242 return 0;
243 }
244
245
246 static int ap_probe_req_rx(void *ctx, const u8 *addr, const u8 *ie,
247 size_t ie_len)
248 {
249 #ifdef CONFIG_P2P
250 struct wpa_supplicant *wpa_s = ctx;
251 return wpas_p2p_probe_req_rx(wpa_s, addr, ie, ie_len);
252 #else /* CONFIG_P2P */
253 return 0;
254 #endif /* CONFIG_P2P */
255 }
256
257
258 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
259 const u8 *uuid_e)
260 {
261 #ifdef CONFIG_P2P
262 struct wpa_supplicant *wpa_s = ctx;
263 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
264 #endif /* CONFIG_P2P */
265 }
266
267
268 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
269 struct wpa_ssid *ssid)
270 {
271 struct wpa_driver_associate_params params;
272 struct hostapd_iface *hapd_iface;
273 struct hostapd_config *conf;
274 size_t i;
275
276 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
277 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
278 return -1;
279 }
280
281 wpa_supplicant_ap_deinit(wpa_s);
282
283 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
284 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
285
286 os_memset(&params, 0, sizeof(params));
287 params.ssid = ssid->ssid;
288 params.ssid_len = ssid->ssid_len;
289 switch (ssid->mode) {
290 case WPAS_MODE_INFRA:
291 params.mode = IEEE80211_MODE_INFRA;
292 break;
293 case WPAS_MODE_IBSS:
294 params.mode = IEEE80211_MODE_IBSS;
295 break;
296 case WPAS_MODE_AP:
297 case WPAS_MODE_P2P_GO:
298 case WPAS_MODE_P2P_GROUP_FORMATION:
299 params.mode = IEEE80211_MODE_AP;
300 break;
301 }
302 params.freq = ssid->frequency;
303
304 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
305 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
306 else
307 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
308 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
309
310 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
311 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
312 else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
313 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
314 else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
315 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
316 else {
317 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
318 "cipher.");
319 return -1;
320 }
321 params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
322 params.group_suite = params.pairwise_suite;
323
324 #ifdef CONFIG_P2P
325 if (ssid->mode == WPAS_MODE_P2P_GO ||
326 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
327 params.p2p = 1;
328 wpa_drv_set_intra_bss(wpa_s, wpa_s->conf->p2p_intra_bss);
329 #endif /* CONFIG_P2P */
330
331 if (wpa_s->parent->set_ap_uapsd)
332 params.uapsd = wpa_s->parent->ap_uapsd;
333 else
334 params.uapsd = -1;
335
336 if (wpa_drv_associate(wpa_s, &params) < 0) {
337 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
338 return -1;
339 }
340
341 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
342 if (hapd_iface == NULL)
343 return -1;
344 hapd_iface->owner = wpa_s;
345
346 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
347 if (conf == NULL) {
348 wpa_supplicant_ap_deinit(wpa_s);
349 return -1;
350 }
351
352 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
353 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
354 wpa_supplicant_ap_deinit(wpa_s);
355 return -1;
356 }
357
358 #ifdef CONFIG_P2P
359 if (ssid->mode == WPAS_MODE_P2P_GO)
360 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
361 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
362 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
363 P2P_GROUP_FORMATION;
364 #endif /* CONFIG_P2P */
365
366 hapd_iface->num_bss = conf->num_bss;
367 hapd_iface->bss = os_zalloc(conf->num_bss *
368 sizeof(struct hostapd_data *));
369 if (hapd_iface->bss == NULL) {
370 wpa_supplicant_ap_deinit(wpa_s);
371 return -1;
372 }
373
374 for (i = 0; i < conf->num_bss; i++) {
375 hapd_iface->bss[i] =
376 hostapd_alloc_bss_data(hapd_iface, conf,
377 &conf->bss[i]);
378 if (hapd_iface->bss[i] == NULL) {
379 wpa_supplicant_ap_deinit(wpa_s);
380 return -1;
381 }
382
383 hapd_iface->bss[i]->msg_ctx = wpa_s;
384 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
385 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
386 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
387 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
388 hostapd_register_probereq_cb(hapd_iface->bss[i],
389 ap_probe_req_rx, wpa_s);
390 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
391 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
392 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
393 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
394 #ifdef CONFIG_P2P
395 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
396 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
397 wpa_s, ssid->p2p_persistent_group,
398 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
399 #endif /* CONFIG_P2P */
400 }
401
402 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
403 hapd_iface->bss[0]->driver = wpa_s->driver;
404 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
405
406 if (hostapd_setup_interface(wpa_s->ap_iface)) {
407 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
408 wpa_supplicant_ap_deinit(wpa_s);
409 return -1;
410 }
411
412 wpa_s->current_ssid = ssid;
413 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
414 wpa_s->assoc_freq = ssid->frequency;
415 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
416
417 if (wpa_s->ap_configured_cb)
418 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
419 wpa_s->ap_configured_cb_data);
420
421 return 0;
422 }
423
424
425 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
426 {
427 if (wpa_s->ap_iface == NULL)
428 return;
429
430 wpa_s->current_ssid = NULL;
431 #ifdef CONFIG_P2P
432 if (wpa_s->ap_iface->bss)
433 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
434 wpas_p2p_group_deinit(wpa_s);
435 #endif /* CONFIG_P2P */
436 hostapd_interface_deinit(wpa_s->ap_iface);
437 hostapd_interface_free(wpa_s->ap_iface);
438 wpa_s->ap_iface = NULL;
439 wpa_drv_deinit_ap(wpa_s);
440 }
441
442
443 void ap_tx_status(void *ctx, const u8 *addr,
444 const u8 *buf, size_t len, int ack)
445 {
446 #ifdef NEED_AP_MLME
447 struct wpa_supplicant *wpa_s = ctx;
448 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
449 #endif /* NEED_AP_MLME */
450 }
451
452
453 void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
454 {
455 #ifdef NEED_AP_MLME
456 struct wpa_supplicant *wpa_s = ctx;
457 const struct ieee80211_hdr *hdr =
458 (const struct ieee80211_hdr *) frame;
459 u16 fc = le_to_host16(hdr->frame_control);
460 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
461 (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
462 (WLAN_FC_TODS | WLAN_FC_FROMDS));
463 #endif /* NEED_AP_MLME */
464 }
465
466
467 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
468 {
469 #ifdef NEED_AP_MLME
470 struct wpa_supplicant *wpa_s = ctx;
471 struct hostapd_frame_info fi;
472 os_memset(&fi, 0, sizeof(fi));
473 fi.datarate = rx_mgmt->datarate;
474 fi.ssi_signal = rx_mgmt->ssi_signal;
475 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
476 rx_mgmt->frame_len, &fi);
477 #endif /* NEED_AP_MLME */
478 }
479
480
481 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
482 {
483 #ifdef NEED_AP_MLME
484 struct wpa_supplicant *wpa_s = ctx;
485 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
486 #endif /* NEED_AP_MLME */
487 }
488
489
490 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
491 const u8 *src_addr, const u8 *buf, size_t len)
492 {
493 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
494 }
495
496
497 #ifdef CONFIG_WPS
498
499 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
500 {
501 if (!wpa_s->ap_iface)
502 return -1;
503 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]);
504 }
505
506
507 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data *hapd,
508 struct sta_info *sta, void *ctx)
509 {
510 if (sta && (sta->flags & WLAN_STA_WPS)) {
511 ap_sta_deauthenticate(hapd, sta,
512 WLAN_REASON_PREV_AUTH_NOT_VALID);
513 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
514 __func__, MAC2STR(sta->addr));
515 return 1;
516 }
517
518 return 0;
519 }
520
521
522 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
523 {
524 struct wps_registrar *reg;
525 int reg_sel = 0, wps_sta = 0;
526
527 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
528 return -1;
529
530 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
531 reg_sel = wps_registrar_wps_cancel(reg);
532 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
533 wpa_supplicant_ap_wps_sta_cancel, NULL);
534
535 if (!reg_sel && !wps_sta) {
536 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
537 "time");
538 return -1;
539 }
540
541 /*
542 * There are 2 cases to return wps cancel as success:
543 * 1. When wps cancel was initiated but no connection has been
544 * established with client yet.
545 * 2. Client is in the middle of exchanging WPS messages.
546 */
547
548 return 0;
549 }
550
551
552 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
553 const char *pin, char *buf, size_t buflen)
554 {
555 int ret, ret_len = 0;
556
557 if (!wpa_s->ap_iface)
558 return -1;
559
560 if (pin == NULL) {
561 unsigned int rpin = wps_generate_pin();
562 ret_len = os_snprintf(buf, buflen, "%d", rpin);
563 pin = buf;
564 } else
565 ret_len = os_snprintf(buf, buflen, "%s", pin);
566
567 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
568 0);
569 if (ret)
570 return -1;
571 return ret_len;
572 }
573
574 #endif /* CONFIG_WPS */
575
576
577 #ifdef CONFIG_CTRL_IFACE
578
579 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
580 char *buf, size_t buflen)
581 {
582 if (wpa_s->ap_iface == NULL)
583 return -1;
584 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
585 buf, buflen);
586 }
587
588
589 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
590 char *buf, size_t buflen)
591 {
592 if (wpa_s->ap_iface == NULL)
593 return -1;
594 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
595 buf, buflen);
596 }
597
598
599 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
600 char *buf, size_t buflen)
601 {
602 if (wpa_s->ap_iface == NULL)
603 return -1;
604 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
605 buf, buflen);
606 }
607
608
609 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
610 size_t buflen, int verbose)
611 {
612 char *pos = buf, *end = buf + buflen;
613 int ret;
614 struct hostapd_bss_config *conf;
615
616 if (wpa_s->ap_iface == NULL)
617 return -1;
618
619 conf = wpa_s->ap_iface->bss[0]->conf;
620 if (conf->wpa == 0)
621 return 0;
622
623 ret = os_snprintf(pos, end - pos,
624 "pairwise_cipher=%s\n"
625 "group_cipher=%s\n"
626 "key_mgmt=%s\n",
627 wpa_cipher_txt(conf->rsn_pairwise),
628 wpa_cipher_txt(conf->wpa_group),
629 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
630 conf->wpa));
631 if (ret < 0 || ret >= end - pos)
632 return pos - buf;
633 pos += ret;
634 return pos - buf;
635 }
636
637 #endif /* CONFIG_CTRL_IFACE */
638
639
640 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
641 {
642 struct hostapd_iface *iface = wpa_s->ap_iface;
643 struct wpa_ssid *ssid = wpa_s->current_ssid;
644 struct hostapd_data *hapd;
645
646 if (ssid == NULL || wpa_s->ap_iface == NULL)
647 return -1;
648
649 #ifdef CONFIG_P2P
650 if (ssid->mode == WPAS_MODE_P2P_GO)
651 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
652 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
653 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
654 P2P_GROUP_FORMATION;
655 #endif /* CONFIG_P2P */
656
657 ieee802_11_set_beacons(iface);
658 hapd = iface->bss[0];
659 hapd->drv.set_ap_wps_ie(hapd);
660
661 return 0;
662 }
663
664
665 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
666 const u8 *addr)
667 {
668 struct hostapd_data *hapd;
669 struct hostapd_bss_config *conf;
670
671 if (!wpa_s->ap_iface)
672 return -1;
673
674 if (addr)
675 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
676 MAC2STR(addr));
677 else
678 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
679
680 hapd = wpa_s->ap_iface->bss[0];
681 conf = hapd->conf;
682
683 os_free(conf->accept_mac);
684 conf->accept_mac = NULL;
685 conf->num_accept_mac = 0;
686 os_free(conf->deny_mac);
687 conf->deny_mac = NULL;
688 conf->num_deny_mac = 0;
689
690 if (addr == NULL) {
691 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
692 return 0;
693 }
694
695 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
696 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
697 if (conf->accept_mac == NULL)
698 return -1;
699 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
700 conf->num_accept_mac = 1;
701
702 return 0;
703 }