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