P2P: Add P2P configuration and callbacks in hostapd code
[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 #endif /* CONFIG_WPS */
164
165 #ifdef CONFIG_P2P
166         if (wpa_s->conf->device_name) {
167                 bss->device_name = os_strdup(wpa_s->conf->device_name);
168                 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
169         }
170 #endif /* CONFIG_P2P */
171
172         return 0;
173 }
174
175
176 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
177 {
178 #ifdef CONFIG_P2P
179         struct wpa_supplicant *wpa_s = ctx;
180         const struct ieee80211_mgmt *mgmt;
181         size_t hdr_len;
182
183         mgmt = (const struct ieee80211_mgmt *) buf;
184         hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
185         if (hdr_len > len)
186                 return;
187         wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
188                            mgmt->u.action.category,
189                            &mgmt->u.action.u.vs_public_action.action,
190                            len - hdr_len, freq);
191 #endif /* CONFIG_P2P */
192 }
193
194
195 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
196 {
197 #ifdef CONFIG_P2P
198         struct wpa_supplicant *wpa_s = ctx;
199         const struct ieee80211_mgmt *mgmt;
200         size_t hdr_len;
201
202         mgmt = (const struct ieee80211_mgmt *) buf;
203         hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
204         if (hdr_len > len)
205                 return -1;
206         wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
207                            mgmt->u.action.category,
208                            &mgmt->u.action.u.vs_public_action.action,
209                            len - hdr_len, freq);
210 #endif /* CONFIG_P2P */
211         return 0;
212 }
213
214
215 static int ap_probe_req_rx(void *ctx, const u8 *addr, const u8 *ie,
216                            size_t ie_len)
217 {
218 #ifdef CONFIG_P2P
219         struct wpa_supplicant *wpa_s = ctx;
220         return wpas_p2p_probe_req_rx(wpa_s, addr, ie, ie_len);
221 #else /* CONFIG_P2P */
222         return 0;
223 #endif /* CONFIG_P2P */
224 }
225
226
227 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
228                                   const u8 *uuid_e)
229 {
230 #ifdef CONFIG_P2P
231         struct wpa_supplicant *wpa_s = ctx;
232         wpas_p2p_wps_success(wpa_s, mac_addr, 1);
233 #endif /* CONFIG_P2P */
234 }
235
236
237 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
238                              struct wpa_ssid *ssid)
239 {
240         struct wpa_driver_associate_params params;
241         struct hostapd_iface *hapd_iface;
242         struct hostapd_config *conf;
243         size_t i;
244
245         if (ssid->ssid == NULL || ssid->ssid_len == 0) {
246                 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
247                 return -1;
248         }
249
250         wpa_supplicant_ap_deinit(wpa_s);
251
252         wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
253                    wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
254
255         os_memset(&params, 0, sizeof(params));
256         params.ssid = ssid->ssid;
257         params.ssid_len = ssid->ssid_len;
258         switch (ssid->mode) {
259         case WPAS_MODE_INFRA:
260                 params.mode = IEEE80211_MODE_INFRA;
261                 break;
262         case WPAS_MODE_IBSS:
263                 params.mode = IEEE80211_MODE_IBSS;
264                 break;
265         case WPAS_MODE_AP:
266         case WPAS_MODE_P2P_GO:
267         case WPAS_MODE_P2P_GROUP_FORMATION:
268                 params.mode = IEEE80211_MODE_AP;
269                 break;
270         }
271         params.freq = ssid->frequency;
272
273         if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
274                 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
275         else
276                 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
277         params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
278
279         if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
280                 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
281         else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
282                 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
283         else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
284                 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
285         else {
286                 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
287                            "cipher.");
288                 return -1;
289         }
290         params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
291         params.group_suite = params.pairwise_suite;
292
293         if (wpa_drv_associate(wpa_s, &params) < 0) {
294                 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
295                 return -1;
296         }
297
298         wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
299         if (hapd_iface == NULL)
300                 return -1;
301         hapd_iface->owner = wpa_s;
302
303         wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
304         if (conf == NULL) {
305                 wpa_supplicant_ap_deinit(wpa_s);
306                 return -1;
307         }
308
309         if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
310                 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
311                 wpa_supplicant_ap_deinit(wpa_s);
312                 return -1;
313         }
314
315 #ifdef CONFIG_P2P
316         if (ssid->mode == WPAS_MODE_P2P_GO)
317                 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
318         else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
319                 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
320                         P2P_GROUP_FORMATION;
321 #endif /* CONFIG_P2P */
322
323         hapd_iface->num_bss = conf->num_bss;
324         hapd_iface->bss = os_zalloc(conf->num_bss *
325                                     sizeof(struct hostapd_data *));
326         if (hapd_iface->bss == NULL) {
327                 wpa_supplicant_ap_deinit(wpa_s);
328                 return -1;
329         }
330
331         for (i = 0; i < conf->num_bss; i++) {
332                 hapd_iface->bss[i] =
333                         hostapd_alloc_bss_data(hapd_iface, conf,
334                                                &conf->bss[i]);
335                 if (hapd_iface->bss[i] == NULL) {
336                         wpa_supplicant_ap_deinit(wpa_s);
337                         return -1;
338                 }
339
340                 hapd_iface->bss[i]->msg_ctx = wpa_s;
341                 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
342                 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
343                 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
344                 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
345                 hostapd_register_probereq_cb(hapd_iface->bss[i],
346                                              ap_probe_req_rx, wpa_s);
347                 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
348                 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
349 #ifdef CONFIG_P2P
350                 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
351                 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
352                         wpa_s, ssid->p2p_persistent_group,
353                         ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
354 #endif /* CONFIG_P2P */
355         }
356
357         os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
358         hapd_iface->bss[0]->driver = wpa_s->driver;
359         hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
360
361         if (hostapd_setup_interface(wpa_s->ap_iface)) {
362                 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
363                 wpa_supplicant_ap_deinit(wpa_s);
364                 return -1;
365         }
366
367         wpa_s->current_ssid = ssid;
368         os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
369         wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
370
371         if (wpa_s->ap_configured_cb)
372                 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
373                                         wpa_s->ap_configured_cb_data);
374
375         return 0;
376 }
377
378
379 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
380 {
381         if (wpa_s->ap_iface == NULL)
382                 return;
383
384         wpa_s->current_ssid = NULL;
385 #ifdef CONFIG_P2P
386         wpa_s->ap_iface->bss[0]->p2p_group = NULL;
387         wpas_p2p_group_deinit(wpa_s);
388 #endif /* CONFIG_P2P */
389         hostapd_interface_deinit(wpa_s->ap_iface);
390         hostapd_interface_free(wpa_s->ap_iface);
391         wpa_s->ap_iface = NULL;
392         wpa_drv_deinit_ap(wpa_s);
393 }
394
395
396 void ap_tx_status(void *ctx, const u8 *addr,
397                   const u8 *buf, size_t len, int ack)
398 {
399 #ifdef NEED_AP_MLME
400         struct wpa_supplicant *wpa_s = ctx;
401         hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
402 #endif /* NEED_AP_MLME */
403 }
404
405
406 void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
407 {
408 #ifdef NEED_AP_MLME
409         struct wpa_supplicant *wpa_s = ctx;
410         const struct ieee80211_hdr *hdr =
411                 (const struct ieee80211_hdr *) frame;
412         u16 fc = le_to_host16(hdr->frame_control);
413         ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
414                                    (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
415                                    (WLAN_FC_TODS | WLAN_FC_FROMDS));
416 #endif /* NEED_AP_MLME */
417 }
418
419
420 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
421 {
422 #ifdef NEED_AP_MLME
423         struct wpa_supplicant *wpa_s = ctx;
424         struct hostapd_frame_info fi;
425         os_memset(&fi, 0, sizeof(fi));
426         fi.datarate = rx_mgmt->datarate;
427         fi.ssi_signal = rx_mgmt->ssi_signal;
428         ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
429                         rx_mgmt->frame_len, &fi);
430 #endif /* NEED_AP_MLME */
431 }
432
433
434 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
435 {
436 #ifdef NEED_AP_MLME
437         struct wpa_supplicant *wpa_s = ctx;
438         ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
439 #endif /* NEED_AP_MLME */
440 }
441
442
443 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
444                                 const u8 *src_addr, const u8 *buf, size_t len)
445 {
446         ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
447 }
448
449
450 #ifdef CONFIG_WPS
451
452 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
453 {
454         if (!wpa_s->ap_iface)
455                 return -1;
456         return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]);
457 }
458
459
460 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
461                               const char *pin, char *buf, size_t buflen)
462 {
463         int ret, ret_len = 0;
464
465         if (!wpa_s->ap_iface)
466                 return -1;
467
468         if (pin == NULL) {
469                 unsigned int rpin = wps_generate_pin();
470                 ret_len = os_snprintf(buf, buflen, "%d", rpin);
471                 pin = buf;
472         }
473
474         ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
475                                   0);
476         if (ret)
477                 return -1;
478         return ret_len;
479 }
480
481 #endif /* CONFIG_WPS */
482
483
484 #ifdef CONFIG_CTRL_IFACE
485
486 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
487                             char *buf, size_t buflen)
488 {
489         if (wpa_s->ap_iface == NULL)
490                 return -1;
491         return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
492                                             buf, buflen);
493 }
494
495
496 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
497                       char *buf, size_t buflen)
498 {
499         if (wpa_s->ap_iface == NULL)
500                 return -1;
501         return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
502                                       buf, buflen);
503 }
504
505
506 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
507                            char *buf, size_t buflen)
508 {
509         if (wpa_s->ap_iface == NULL)
510                 return -1;
511         return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
512                                            buf, buflen);
513 }
514
515
516 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
517                                  size_t buflen, int verbose)
518 {
519         char *pos = buf, *end = buf + buflen;
520         int ret;
521         struct hostapd_bss_config *conf;
522
523         if (wpa_s->ap_iface == NULL)
524                 return -1;
525
526         conf = wpa_s->ap_iface->bss[0]->conf;
527         if (conf->wpa == 0)
528                 return 0;
529
530         ret = os_snprintf(pos, end - pos,
531                           "pairwise_cipher=%s\n"
532                           "group_cipher=%s\n"
533                           "key_mgmt=%s\n",
534                           wpa_cipher_txt(conf->rsn_pairwise),
535                           wpa_cipher_txt(conf->wpa_group),
536                           wpa_key_mgmt_txt(conf->wpa_key_mgmt,
537                                            conf->wpa));
538         if (ret < 0 || ret >= end - pos)
539                 return pos - buf;
540         pos += ret;
541         return pos - buf;
542 }
543
544 #endif /* CONFIG_CTRL_IFACE */
545
546
547 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
548 {
549         struct hostapd_iface *iface = wpa_s->ap_iface;
550         struct wpa_ssid *ssid = wpa_s->current_ssid;
551         struct hostapd_data *hapd;
552
553         if (ssid == NULL || wpa_s->ap_iface == NULL)
554                 return -1;
555
556 #ifdef CONFIG_P2P
557         if (ssid->mode == WPAS_MODE_P2P_GO)
558                 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
559         else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
560                 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
561                         P2P_GROUP_FORMATION;
562 #endif /* CONFIG_P2P */
563
564         ieee802_11_set_beacons(iface);
565         hapd = iface->bss[0];
566         hapd->drv.set_ap_wps_ie(hapd);
567
568         return 0;
569 }
570
571
572 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
573                                       const u8 *addr)
574 {
575         struct hostapd_data *hapd;
576         struct hostapd_bss_config *conf;
577
578         if (!wpa_s->ap_iface)
579                 return -1;
580
581         if (addr)
582                 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
583                            MAC2STR(addr));
584         else
585                 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
586
587         hapd = wpa_s->ap_iface->bss[0];
588         conf = hapd->conf;
589
590         os_free(conf->accept_mac);
591         conf->accept_mac = NULL;
592         conf->num_accept_mac = 0;
593         os_free(conf->deny_mac);
594         conf->deny_mac = NULL;
595         conf->num_deny_mac = 0;
596
597         if (addr == NULL) {
598                 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
599                 return 0;
600         }
601
602         conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
603         conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
604         if (conf->accept_mac == NULL)
605                 return -1;
606         os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
607         conf->num_accept_mac = 1;
608
609         return 0;
610 }