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