26a1d11fb84dc3beea5f72ab245d9625d016a26d
[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         wpa_drv_set_intra_bss(wpa_s, wpa_s->conf->p2p_intra_bss);
306 #endif /* CONFIG_P2P */
307
308         if (wpa_s->parent->set_ap_uapsd)
309                 params.uapsd = wpa_s->parent->ap_uapsd;
310         else
311                 params.uapsd = -1;
312
313         if (wpa_drv_associate(wpa_s, &params) < 0) {
314                 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
315                 return -1;
316         }
317
318         wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
319         if (hapd_iface == NULL)
320                 return -1;
321         hapd_iface->owner = wpa_s;
322
323         wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
324         if (conf == NULL) {
325                 wpa_supplicant_ap_deinit(wpa_s);
326                 return -1;
327         }
328
329         if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
330                 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
331                 wpa_supplicant_ap_deinit(wpa_s);
332                 return -1;
333         }
334
335 #ifdef CONFIG_P2P
336         if (ssid->mode == WPAS_MODE_P2P_GO)
337                 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
338         else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
339                 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
340                         P2P_GROUP_FORMATION;
341 #endif /* CONFIG_P2P */
342
343         hapd_iface->num_bss = conf->num_bss;
344         hapd_iface->bss = os_zalloc(conf->num_bss *
345                                     sizeof(struct hostapd_data *));
346         if (hapd_iface->bss == NULL) {
347                 wpa_supplicant_ap_deinit(wpa_s);
348                 return -1;
349         }
350
351         for (i = 0; i < conf->num_bss; i++) {
352                 hapd_iface->bss[i] =
353                         hostapd_alloc_bss_data(hapd_iface, conf,
354                                                &conf->bss[i]);
355                 if (hapd_iface->bss[i] == NULL) {
356                         wpa_supplicant_ap_deinit(wpa_s);
357                         return -1;
358                 }
359
360                 hapd_iface->bss[i]->msg_ctx = wpa_s;
361                 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
362                 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
363                 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
364                 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
365                 hostapd_register_probereq_cb(hapd_iface->bss[i],
366                                              ap_probe_req_rx, wpa_s);
367                 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
368                 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
369 #ifdef CONFIG_P2P
370                 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
371                 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
372                         wpa_s, ssid->p2p_persistent_group,
373                         ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
374 #endif /* CONFIG_P2P */
375         }
376
377         os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
378         hapd_iface->bss[0]->driver = wpa_s->driver;
379         hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
380
381         if (hostapd_setup_interface(wpa_s->ap_iface)) {
382                 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
383                 wpa_supplicant_ap_deinit(wpa_s);
384                 return -1;
385         }
386
387         wpa_s->current_ssid = ssid;
388         os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
389         wpa_s->assoc_freq = ssid->frequency;
390         wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
391
392         if (wpa_s->ap_configured_cb)
393                 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
394                                         wpa_s->ap_configured_cb_data);
395
396         return 0;
397 }
398
399
400 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
401 {
402         if (wpa_s->ap_iface == NULL)
403                 return;
404
405         wpa_s->current_ssid = NULL;
406 #ifdef CONFIG_P2P
407         if (wpa_s->ap_iface->bss)
408                 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
409         wpas_p2p_group_deinit(wpa_s);
410 #endif /* CONFIG_P2P */
411         hostapd_interface_deinit(wpa_s->ap_iface);
412         hostapd_interface_free(wpa_s->ap_iface);
413         wpa_s->ap_iface = NULL;
414         wpa_drv_deinit_ap(wpa_s);
415 }
416
417
418 void ap_tx_status(void *ctx, const u8 *addr,
419                   const u8 *buf, size_t len, int ack)
420 {
421 #ifdef NEED_AP_MLME
422         struct wpa_supplicant *wpa_s = ctx;
423         hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
424 #endif /* NEED_AP_MLME */
425 }
426
427
428 void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
429 {
430 #ifdef NEED_AP_MLME
431         struct wpa_supplicant *wpa_s = ctx;
432         const struct ieee80211_hdr *hdr =
433                 (const struct ieee80211_hdr *) frame;
434         u16 fc = le_to_host16(hdr->frame_control);
435         ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
436                                    (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
437                                    (WLAN_FC_TODS | WLAN_FC_FROMDS));
438 #endif /* NEED_AP_MLME */
439 }
440
441
442 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
443 {
444 #ifdef NEED_AP_MLME
445         struct wpa_supplicant *wpa_s = ctx;
446         struct hostapd_frame_info fi;
447         os_memset(&fi, 0, sizeof(fi));
448         fi.datarate = rx_mgmt->datarate;
449         fi.ssi_signal = rx_mgmt->ssi_signal;
450         ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
451                         rx_mgmt->frame_len, &fi);
452 #endif /* NEED_AP_MLME */
453 }
454
455
456 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
457 {
458 #ifdef NEED_AP_MLME
459         struct wpa_supplicant *wpa_s = ctx;
460         ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
461 #endif /* NEED_AP_MLME */
462 }
463
464
465 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
466                                 const u8 *src_addr, const u8 *buf, size_t len)
467 {
468         ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
469 }
470
471
472 #ifdef CONFIG_WPS
473
474 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
475 {
476         if (!wpa_s->ap_iface)
477                 return -1;
478         return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]);
479 }
480
481
482 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data *hapd,
483                                             struct sta_info *sta, void *ctx)
484 {
485         if (sta && (sta->flags & WLAN_STA_WPS)) {
486                 ap_sta_deauthenticate(hapd, sta,
487                                       WLAN_REASON_PREV_AUTH_NOT_VALID);
488                 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
489                            __func__, MAC2STR(sta->addr));
490                 return 1;
491         }
492
493         return 0;
494 }
495
496
497 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
498 {
499         struct wps_registrar *reg;
500         int reg_sel = 0, wps_sta = 0;
501
502         if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
503                 return -1;
504
505         reg = wpa_s->ap_iface->bss[0]->wps->registrar;
506         reg_sel = wps_registrar_wps_cancel(reg);
507         wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
508                                   wpa_supplicant_ap_wps_sta_cancel, NULL);
509
510         if (!reg_sel && !wps_sta) {
511                 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
512                            "time");
513                 return -1;
514         }
515
516         /*
517          * There are 2 cases to return wps cancel as success:
518          * 1. When wps cancel was initiated but no connection has been
519          *    established with client yet.
520          * 2. Client is in the middle of exchanging WPS messages.
521          */
522
523         return 0;
524 }
525
526
527 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
528                               const char *pin, char *buf, size_t buflen)
529 {
530         int ret, ret_len = 0;
531
532         if (!wpa_s->ap_iface)
533                 return -1;
534
535         if (pin == NULL) {
536                 unsigned int rpin = wps_generate_pin();
537                 ret_len = os_snprintf(buf, buflen, "%d", rpin);
538                 pin = buf;
539         } else
540                 ret_len = os_snprintf(buf, buflen, "%s", pin);
541
542         ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
543                                   0);
544         if (ret)
545                 return -1;
546         return ret_len;
547 }
548
549 #endif /* CONFIG_WPS */
550
551
552 #ifdef CONFIG_CTRL_IFACE
553
554 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
555                             char *buf, size_t buflen)
556 {
557         if (wpa_s->ap_iface == NULL)
558                 return -1;
559         return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
560                                             buf, buflen);
561 }
562
563
564 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
565                       char *buf, size_t buflen)
566 {
567         if (wpa_s->ap_iface == NULL)
568                 return -1;
569         return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
570                                       buf, buflen);
571 }
572
573
574 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
575                            char *buf, size_t buflen)
576 {
577         if (wpa_s->ap_iface == NULL)
578                 return -1;
579         return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
580                                            buf, buflen);
581 }
582
583
584 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
585                                  size_t buflen, int verbose)
586 {
587         char *pos = buf, *end = buf + buflen;
588         int ret;
589         struct hostapd_bss_config *conf;
590
591         if (wpa_s->ap_iface == NULL)
592                 return -1;
593
594         conf = wpa_s->ap_iface->bss[0]->conf;
595         if (conf->wpa == 0)
596                 return 0;
597
598         ret = os_snprintf(pos, end - pos,
599                           "pairwise_cipher=%s\n"
600                           "group_cipher=%s\n"
601                           "key_mgmt=%s\n",
602                           wpa_cipher_txt(conf->rsn_pairwise),
603                           wpa_cipher_txt(conf->wpa_group),
604                           wpa_key_mgmt_txt(conf->wpa_key_mgmt,
605                                            conf->wpa));
606         if (ret < 0 || ret >= end - pos)
607                 return pos - buf;
608         pos += ret;
609         return pos - buf;
610 }
611
612 #endif /* CONFIG_CTRL_IFACE */
613
614
615 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
616 {
617         struct hostapd_iface *iface = wpa_s->ap_iface;
618         struct wpa_ssid *ssid = wpa_s->current_ssid;
619         struct hostapd_data *hapd;
620
621         if (ssid == NULL || wpa_s->ap_iface == NULL)
622                 return -1;
623
624 #ifdef CONFIG_P2P
625         if (ssid->mode == WPAS_MODE_P2P_GO)
626                 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
627         else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
628                 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
629                         P2P_GROUP_FORMATION;
630 #endif /* CONFIG_P2P */
631
632         ieee802_11_set_beacons(iface);
633         hapd = iface->bss[0];
634         hapd->drv.set_ap_wps_ie(hapd);
635
636         return 0;
637 }
638
639
640 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
641                                       const u8 *addr)
642 {
643         struct hostapd_data *hapd;
644         struct hostapd_bss_config *conf;
645
646         if (!wpa_s->ap_iface)
647                 return -1;
648
649         if (addr)
650                 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
651                            MAC2STR(addr));
652         else
653                 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
654
655         hapd = wpa_s->ap_iface->bss[0];
656         conf = hapd->conf;
657
658         os_free(conf->accept_mac);
659         conf->accept_mac = NULL;
660         conf->num_accept_mac = 0;
661         os_free(conf->deny_mac);
662         conf->deny_mac = NULL;
663         conf->num_deny_mac = 0;
664
665         if (addr == NULL) {
666                 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
667                 return 0;
668         }
669
670         conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
671         conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
672         if (conf->accept_mac == NULL)
673                 return -1;
674         os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
675         conf->num_accept_mac = 1;
676
677         return 0;
678 }