2 * Host AP - driver interaction with BSD net80211 layer
3 * Copyright (c) 2004, Sam Leffler <sam@errno.com>
4 * Copyright (c) 2004, 2Wire, Inc
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.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
15 * $FreeBSD: head/usr.sbin/wpa/hostapd/driver_freebsd.c 193524 2009-06-05 17:19:55Z sam $
22 #include <sys/ioctl.h>
25 #include <sys/socket.h>
27 #include <netinet/in.h>
29 #include <netproto/802_11/ieee80211_ioctl.h>
36 #include "hostapd/hostapd.h"
37 #include "hostapd/driver.h"
38 #include "hostapd/ieee802_1x.h"
39 #include "hostapd/ieee802_11_auth.h"
41 #include "hostapd/sta_info.h"
42 #include "l2_packet/l2_packet.h"
44 #include "hostapd/eapol_sm.h"
45 #include "hostapd/wpa.h"
46 #include "radius/radius.h"
47 #include "hostapd/ieee802_11.h"
49 #include "hostapd/hostap_common.h"
51 struct bsd_driver_data {
52 struct hostapd_data *hapd; /* back pointer */
54 char iface[IFNAMSIZ + 1];
55 unsigned int ifindex; /* interface index */
56 struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
57 int ioctl_sock; /* socket for ioctl() use */
58 int wext_sock; /* socket for wireless events */
61 static const struct wpa_driver_ops bsd_driver_ops;
63 static int bsd_sta_deauth(void *priv, const u8 *addr, int reason_code);
66 set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len)
68 struct ieee80211req ireq;
70 memset(&ireq, 0, sizeof(ireq));
71 strncpy(ireq.i_name, drv->iface, IFNAMSIZ);
74 ireq.i_data = (void *) arg;
76 if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
77 perror("ioctl[SIOCS80211]");
84 get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len)
86 struct ieee80211req ireq;
88 memset(&ireq, 0, sizeof(ireq));
89 strncpy(ireq.i_name, drv->iface, IFNAMSIZ);
94 if (ioctl(drv->ioctl_sock, SIOCG80211, &ireq) < 0) {
95 perror("ioctl[SIOCG80211]");
102 set80211param(struct bsd_driver_data *drv, int op, int arg)
104 struct ieee80211req ireq;
106 memset(&ireq, 0, sizeof(ireq));
107 strncpy(ireq.i_name, drv->iface, IFNAMSIZ);
111 if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
112 perror("ioctl[SIOCS80211]");
119 ether_sprintf(const u8 *addr)
121 static char buf[sizeof(MACSTR)];
124 snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
126 snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
131 bsd_set_iface_flags(void *priv, int flags)
133 struct bsd_driver_data *drv = priv;
134 struct hostapd_data *hapd = drv->hapd;
137 wpa_printf(MSG_DEBUG, "%s: flags=0x%x\n", __func__, flags);
139 if (drv->ioctl_sock < 0)
142 memset(&ifr, 0, sizeof(ifr));
143 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", drv->iface);
145 if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
146 perror("ioctl[SIOCGIFFLAGS]");
152 if ((ifr.ifr_flags & flags) == 0)
154 ifr.ifr_flags &= ~flags;
156 if ((ifr.ifr_flags & flags) == flags)
158 ifr.ifr_flags |= flags;
161 if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
162 perror("ioctl[SIOCSIFFLAGS]");
169 bsd_commit(void *priv)
171 return bsd_set_iface_flags(priv, IFF_UP);
175 bsd_set_ieee8021x(const char *ifname, void *priv, int enabled)
177 struct bsd_driver_data *drv = priv;
178 struct hostapd_data *hapd = drv->hapd;
179 struct hostapd_bss_config *conf = hapd->conf;
181 wpa_printf(MSG_DEBUG, "%s: enabled=%d\n", __func__, enabled);
184 /* XXX restore state */
185 return set80211param(priv, IEEE80211_IOC_AUTHMODE,
186 IEEE80211_AUTH_AUTO);
188 if (!conf->wpa && !conf->ieee802_1x) {
189 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
190 HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
193 if (conf->wpa && set80211param(drv, IEEE80211_IOC_WPA, conf->wpa)) {
194 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
195 HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");
198 if (set80211param(priv, IEEE80211_IOC_AUTHMODE,
199 (conf->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
200 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
201 HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!");
208 bsd_set_privacy(const char *ifname, void *priv, int enabled)
210 struct bsd_driver_data *drv = priv;
211 struct hostapd_data *hapd = drv->hapd;
213 wpa_printf(MSG_DEBUG, "%s: enabled=%d\n", __func__, enabled);
215 return set80211param(priv, IEEE80211_IOC_PRIVACY, enabled);
219 bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized)
221 struct bsd_driver_data *drv = priv;
222 struct hostapd_data *hapd = drv->hapd;
223 struct ieee80211req_mlme mlme;
225 wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d\n",
226 __func__, ether_sprintf(addr), authorized);
229 mlme.im_op = IEEE80211_MLME_AUTHORIZE;
231 mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
233 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
234 return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
238 bsd_sta_set_flags(void *priv, const u8 *addr, int total_flags,
239 int flags_or, int flags_and)
241 /* For now, only support setting Authorized flag */
242 if (flags_or & WLAN_STA_AUTHORIZED)
243 return bsd_set_sta_authorized(priv, addr, 1);
244 if (!(flags_and & WLAN_STA_AUTHORIZED))
245 return bsd_set_sta_authorized(priv, addr, 0);
250 bsd_del_key(void *priv, const unsigned char *addr, int key_idx)
252 struct bsd_driver_data *drv = priv;
253 struct hostapd_data *hapd = drv->hapd;
254 struct ieee80211req_del_key wk;
256 wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d\n",
257 __func__, ether_sprintf(addr), key_idx);
259 memset(&wk, 0, sizeof(wk));
261 memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
262 wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */
264 wk.idk_keyix = key_idx;
267 return set80211var(priv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
271 bsd_set_key(const char *ifname, void *priv, const char *alg,
272 const u8 *addr, int key_idx,
273 const u8 *key, size_t key_len, int txkey)
275 struct bsd_driver_data *drv = priv;
276 struct hostapd_data *hapd = drv->hapd;
277 struct ieee80211req_key wk;
280 if (strcmp(alg, "none") == 0)
281 return bsd_del_key(priv, addr, key_idx);
283 wpa_printf(MSG_DEBUG, "%s: alg=%s addr=%s key_idx=%d\n",
284 __func__, alg, ether_sprintf(addr), key_idx);
286 if (strcmp(alg, "WEP") == 0)
287 cipher = IEEE80211_CIPHER_WEP;
288 else if (strcmp(alg, "TKIP") == 0)
289 cipher = IEEE80211_CIPHER_TKIP;
290 else if (strcmp(alg, "CCMP") == 0)
291 cipher = IEEE80211_CIPHER_AES_CCM;
293 printf("%s: unknown/unsupported algorithm %s\n",
298 if (key_len > sizeof(wk.ik_keydata)) {
299 printf("%s: key length %d too big\n", __func__, key_len);
303 memset(&wk, 0, sizeof(wk));
306 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
307 wk.ik_keyix = key_idx;
308 wk.ik_flags = IEEE80211_KEY_XMIT
309 | IEEE80211_KEY_GROUP
310 | IEEE80211_KEY_DEFAULT;
312 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
313 wk.ik_keyix = IEEE80211_KEYIX_NONE;
314 wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
316 wk.ik_keylen = key_len;
317 memcpy(wk.ik_keydata, key, key_len);
319 return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
324 bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
327 struct bsd_driver_data *drv = priv;
328 struct hostapd_data *hapd = drv->hapd;
329 struct ieee80211req_key wk;
331 wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d\n",
332 __func__, ether_sprintf(addr), idx);
334 memset(&wk, 0, sizeof(wk));
336 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
338 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
341 if (get80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) {
342 printf("Failed to get encryption.\n");
345 /* NB: upper layer expects tsc in network order */
346 wk.ik_keytsc = htole64(wk.ik_keytsc);
347 memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
354 bsd_flush(void *priv)
356 u8 allsta[IEEE80211_ADDR_LEN];
358 memset(allsta, 0xff, IEEE80211_ADDR_LEN);
359 return bsd_sta_deauth(priv, allsta, IEEE80211_REASON_AUTH_LEAVE);
364 bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
367 struct bsd_driver_data *drv = priv;
368 struct ieee80211req_sta_stats stats;
370 memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
371 if (get80211var(drv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) > 0) {
372 /* XXX? do packets counts include non-data frames? */
373 data->rx_packets = stats.is_stats.ns_rx_data;
374 data->rx_bytes = stats.is_stats.ns_rx_bytes;
375 data->tx_packets = stats.is_stats.ns_tx_data;
376 data->tx_bytes = stats.is_stats.ns_tx_bytes;
382 bsd_sta_clear_stats(void *priv, const u8 *addr)
384 struct bsd_driver_data *drv = priv;
385 struct hostapd_data *hapd = drv->hapd;
386 struct ieee80211req_sta_stats stats;
388 wpa_printf(MSG_DEBUG, "%s: addr=%s\n", __func__, ether_sprintf(addr));
390 /* zero station statistics */
391 memset(&stats, 0, sizeof(stats));
392 memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
393 return set80211var(drv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats));
397 bsd_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len)
399 struct bsd_driver_data *drv = priv;
400 struct hostapd_data *hapd = drv->hapd;
401 struct ieee80211req ireq;
403 memset(&ireq, 0, sizeof(ireq));
404 strncpy(ireq.i_name, drv->iface, IFNAMSIZ);
405 ireq.i_type = IEEE80211_IOC_APPIE;
406 ireq.i_val = IEEE80211_APPIE_WPA;
407 ireq.i_data = (void *) ie;
410 wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %d)\n",
412 if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
413 printf("Unable to set WPA+RSN ie\n");
420 bsd_sta_deauth(void *priv, const u8 *addr, int reason_code)
422 struct bsd_driver_data *drv = priv;
423 struct hostapd_data *hapd = drv->hapd;
424 struct ieee80211req_mlme mlme;
426 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d\n",
427 __func__, ether_sprintf(addr), reason_code);
429 mlme.im_op = IEEE80211_MLME_DEAUTH;
430 mlme.im_reason = reason_code;
431 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
432 return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
436 bsd_sta_disassoc(void *priv, const u8 *addr, int reason_code)
438 struct bsd_driver_data *drv = priv;
439 struct hostapd_data *hapd = drv->hapd;
440 struct ieee80211req_mlme mlme;
442 wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d\n",
443 __func__, ether_sprintf(addr), reason_code);
445 mlme.im_reason = reason_code;
446 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
447 return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
451 bsd_del_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
453 struct hostapd_data *hapd = drv->hapd;
454 struct hostapd_bss_config *conf = hapd->conf;
455 struct sta_info *sta;
457 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
458 HOSTAPD_LEVEL_INFO, "deassociated");
460 sta = ap_get_sta(hapd, addr);
462 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
464 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
465 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
466 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
467 ap_free_sta(hapd, sta);
473 bsd_new_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
475 struct hostapd_data *hapd = drv->hapd;
476 struct hostapd_bss_config *conf = hapd->conf;
477 struct sta_info *sta;
478 struct ieee80211req_wpaie ie;
479 int new_assoc, ielen, res;
481 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
482 HOSTAPD_LEVEL_INFO, "associated");
484 sta = ap_sta_add(hapd, addr);
488 * Fetch and validate any negotiated WPA/RSN parameters.
491 memset(&ie, 0, sizeof(ie));
492 memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
493 if (get80211var(drv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) {
494 printf("Failed to get WPA/RSN information element.\n");
495 return -1; /* XXX not right */
497 if (ie.wpa_ie[1] == 0) {
498 printf("No WPA/RSN information element for station!\n");
499 return -1; /* XXX not right */
501 if (sta->wpa_sm == NULL)
502 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
504 if (sta->wpa_sm == NULL) {
505 printf("Failed to initialize WPA state machine\n");
508 ielen = 2 + ie.wpa_ie[1];
509 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
510 ie.wpa_ie, ielen, NULL, 0);
511 if (res != WPA_IE_OK) {
512 printf("WPA/RSN information element rejected? "
519 * Now that the internal station state is setup
520 * kick the authenticator into action.
522 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
523 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
524 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
525 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
526 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
531 #include <net/route.h>
532 #include <netproto/802_11/ieee80211_dragonfly.h>
535 bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
537 struct bsd_driver_data *drv = ctx;
538 struct hostapd_data *hapd = drv->hapd;
540 struct if_announcemsghdr *ifan;
541 struct rt_msghdr *rtm;
542 struct ieee80211_michael_event *mic;
543 struct ieee80211_join_event *join;
544 struct ieee80211_leave_event *leave;
545 #ifdef CONFIG_DRIVER_RADIUS_ACL
546 struct ieee80211_auth_event *auth;
550 n = read(sock, buf, sizeof(buf));
552 if (errno != EINTR && errno != EAGAIN)
553 perror("read(PF_ROUTE)");
557 rtm = (struct rt_msghdr *) buf;
558 if (rtm->rtm_version != RTM_VERSION) {
559 wpa_printf(MSG_DEBUG, "Routing message version %d not "
560 "understood\n", rtm->rtm_version);
563 ifan = (struct if_announcemsghdr *) rtm;
564 if (ifan->ifan_index != drv->ifindex) {
565 wpa_printf(MSG_DEBUG, "Discard routing message to if#%d "
567 ifan->ifan_index, drv->ifindex);
570 switch (rtm->rtm_type) {
572 switch (ifan->ifan_what) {
573 case RTM_IEEE80211_ASSOC:
574 case RTM_IEEE80211_REASSOC:
575 case RTM_IEEE80211_DISASSOC:
576 case RTM_IEEE80211_SCAN:
578 case RTM_IEEE80211_LEAVE:
579 leave = (struct ieee80211_leave_event *) &ifan[1];
580 bsd_del_sta(drv, leave->iev_addr);
582 case RTM_IEEE80211_JOIN:
583 #ifdef RTM_IEEE80211_REJOIN
584 case RTM_IEEE80211_REJOIN:
586 join = (struct ieee80211_join_event *) &ifan[1];
587 bsd_new_sta(drv, join->iev_addr);
589 case RTM_IEEE80211_REPLAY:
592 case RTM_IEEE80211_MICHAEL:
593 mic = (struct ieee80211_michael_event *) &ifan[1];
594 wpa_printf(MSG_DEBUG,
595 "Michael MIC failure wireless event: "
596 "keyix=%u src_addr=" MACSTR, mic->iev_keyix,
597 MAC2STR(mic->iev_src));
598 ieee80211_michael_mic_failure(hapd, mic->iev_src, 1);
600 #ifdef CONFIG_DRIVER_RADIUS_ACL
601 case RTM_IEEE80211_AUTH:
602 auth = (struct ieee80211_auth_event *) &ifan[1];
603 wpa_printf(MSG_DEBUG, "802.11 AUTH, STA = " MACSTR,
604 MAC2STR(auth->iev_addr));
605 n = hostapd_allowed_address(hapd, auth->iev_addr,
606 NULL, 0, NULL, NULL, NULL);
608 case HOSTAPD_ACL_ACCEPT:
609 case HOSTAPD_ACL_REJECT:
610 hostapd_set_radius_acl_auth(hapd,
611 auth->iev_addr, n, 0);
612 wpa_printf(MSG_DEBUG,
613 "802.11 AUTH, STA = " MACSTR " hostapd says: %s",
614 MAC2STR(auth->iev_addr),
615 (n == HOSTAPD_ACL_ACCEPT ?
616 "ACCEPT" : "REJECT" ));
618 case HOSTAPD_ACL_PENDING:
619 wpa_printf(MSG_DEBUG,
620 "802.11 AUTH, STA = " MACSTR " pending",
621 MAC2STR(auth->iev_addr));
625 #endif /* CONFIG_DRIVER_RADIUS_ACL */
632 bsd_wireless_event_init(void *priv)
634 struct bsd_driver_data *drv = priv;
639 s = socket(PF_ROUTE, SOCK_RAW, 0);
641 perror("socket(PF_ROUTE,SOCK_RAW)");
644 eloop_register_read_sock(s, bsd_wireless_event_receive, drv, NULL);
651 bsd_wireless_event_deinit(void *priv)
653 struct bsd_driver_data *drv = priv;
656 if (drv->wext_sock < 0)
658 eloop_unregister_read_sock(drv->wext_sock);
659 close(drv->wext_sock);
665 bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
666 int encrypt, const u8 *own_addr)
668 struct bsd_driver_data *drv = priv;
669 struct hostapd_data *hapd = drv->hapd;
670 unsigned char buf[3000];
671 unsigned char *bp = buf;
672 struct l2_ethhdr *eth;
677 * Prepend the Etherent header. If the caller left us
678 * space at the front we could just insert it but since
679 * we don't know we copy to a local buffer. Given the frequency
680 * and size of frames this probably doesn't matter.
682 len = data_len + sizeof(struct l2_ethhdr);
683 if (len > sizeof(buf)) {
686 printf("EAPOL frame discarded, cannot malloc temp "
687 "buffer of size %u!\n", len);
691 eth = (struct l2_ethhdr *) bp;
692 memcpy(eth->h_dest, addr, ETH_ALEN);
693 memcpy(eth->h_source, own_addr, ETH_ALEN);
694 eth->h_proto = htons(ETH_P_EAPOL);
695 memcpy(eth+1, data, data_len);
697 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
699 status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
707 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
709 struct bsd_driver_data *drv = ctx;
710 struct hostapd_data *hapd = drv->hapd;
711 struct sta_info *sta;
713 sta = ap_get_sta(hapd, src_addr);
714 if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
715 printf("Data frame from not associated STA %s\n",
716 ether_sprintf(src_addr));
717 /* XXX cannot happen */
720 ieee802_1x_receive(hapd, src_addr, buf + sizeof(struct l2_ethhdr),
721 len - sizeof(struct l2_ethhdr));
725 bsd_get_ssid(const char *ifname, void *priv, u8 *buf, int len)
727 struct bsd_driver_data *drv = priv;
728 struct hostapd_data *hapd = drv->hapd;
729 int ssid_len = get80211var(priv, IEEE80211_IOC_SSID, buf, len);
731 wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"\n", __func__, ssid_len, buf);
737 bsd_set_ssid(const char *ifname, void *priv, const u8 *buf, int len)
739 struct bsd_driver_data *drv = priv;
740 struct hostapd_data *hapd = drv->hapd;
742 wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"\n", __func__, len, buf);
744 return set80211var(priv, IEEE80211_IOC_SSID, buf, len);
748 bsd_set_countermeasures(void *priv, int enabled)
750 struct bsd_driver_data *drv = priv;
752 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
753 return set80211param(drv, IEEE80211_IOC_COUNTERMEASURES, enabled);
756 #ifdef CONFIG_DRIVER_RADIUS_ACL
758 bsd_set_radius_acl_auth(void *priv, const u8 *mac, int accepted,
761 struct bsd_driver_data *drv = priv;
762 struct hostapd_data *hapd = drv->hapd;
763 struct ieee80211req_mlme mlme;
766 case HOSTAPD_ACL_ACCEPT_TIMEOUT:
767 wpa_printf(MSG_DEBUG, "[%s] STA " MACSTR
768 " has been accepted by RADIUS ACL with timeout "
769 "of %d.\n", hapd->conf->iface, MAC2STR(mac),
771 mlme.im_reason = IEEE80211_STATUS_SUCCESS;
773 case HOSTAPD_ACL_ACCEPT:
774 wpa_printf(MSG_DEBUG, "[%s] STA " MACSTR
775 " has been accepted by RADIUS ACL.\n",
776 hapd->conf->iface, MAC2STR(mac));
777 mlme.im_reason = IEEE80211_STATUS_SUCCESS;
779 case HOSTAPD_ACL_REJECT:
780 wpa_printf(MSG_DEBUG, "[%s] STA " MACSTR
781 " has been rejected by RADIUS ACL.\n",
782 hapd->conf->iface, MAC2STR(mac));
783 mlme.im_reason = IEEE80211_STATUS_UNSPECIFIED;
786 wpa_printf(MSG_ERROR, "[%s] STA " MACSTR
787 " has unknown status (%d) by RADIUS ACL. "
788 "Nothing to do...\n", hapd->conf->iface,
789 MAC2STR(mac), accepted);
792 memset(&mlme, 0, sizeof(mlme));
793 mlme.im_op = IEEE80211_MLME_AUTH;
794 memcpy(mlme.im_macaddr, mac, IEEE80211_ADDR_LEN);
795 return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
799 bsd_set_radius_acl_expire(void *priv, const u8 *mac)
801 struct bsd_driver_data *drv = priv;
802 struct hostapd_data *hapd = drv->hapd;
805 * The expiry of the MAC address from RADIUS ACL cache doesn't mean
806 * that we should kick off the client. Our current approach doesn't
807 * require adding/removing entries from an allow/deny list; so this
808 * function is likely unecessary
810 wpa_printf(MSG_DEBUG, "[%s] STA " MACSTR " radius acl cache "
811 "expired; nothing to do...", hapd->conf->iface,
815 #endif /* CONFIG_DRIVER_RADIUS_ACL */
818 bsd_init(struct hostapd_data *hapd)
820 struct bsd_driver_data *drv;
822 drv = malloc(sizeof(struct bsd_driver_data));
824 printf("Could not allocate memory for bsd driver data\n");
828 memset(drv, 0, sizeof(*drv));
830 drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
831 if (drv->ioctl_sock < 0) {
832 perror("socket[PF_INET,SOCK_DGRAM]");
835 memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
837 * NB: We require the interface name be mappable to an index.
838 * This implies we do not support having wpa_supplicant
839 * wait for an interface to appear. This seems ok; that
840 * doesn't belong here; it's really the job of devd.
841 * XXXSCW: devd is FreeBSD-specific.
843 drv->ifindex = if_nametoindex(drv->iface);
844 if (drv->ifindex == 0) {
845 printf("%s: interface %s does not exist", __func__, drv->iface);
849 drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
850 handle_read, drv, 1);
851 if (drv->sock_xmit == NULL)
853 if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
856 bsd_set_iface_flags(drv, -IFF_UP); /* mark down during setup */
861 if (drv->sock_xmit != NULL)
862 l2_packet_deinit(drv->sock_xmit);
863 if (drv->ioctl_sock >= 0)
864 close(drv->ioctl_sock);
872 bsd_deinit(void *priv)
874 struct bsd_driver_data *drv = priv;
876 (void) bsd_set_iface_flags(drv, -IFF_UP);
877 if (drv->ioctl_sock >= 0)
878 close(drv->ioctl_sock);
879 if (drv->sock_xmit != NULL)
880 l2_packet_deinit(drv->sock_xmit);
884 const struct wpa_driver_ops wpa_driver_bsd_ops = {
887 .deinit = bsd_deinit,
888 .set_ieee8021x = bsd_set_ieee8021x,
889 .set_privacy = bsd_set_privacy,
890 .set_encryption = bsd_set_key,
891 .get_seqnum = bsd_get_seqnum,
893 .set_generic_elem = bsd_set_opt_ie,
894 .wireless_event_init = bsd_wireless_event_init,
895 .wireless_event_deinit = bsd_wireless_event_deinit,
896 .sta_set_flags = bsd_sta_set_flags,
897 .read_sta_data = bsd_read_sta_driver_data,
898 .send_eapol = bsd_send_eapol,
899 .sta_disassoc = bsd_sta_disassoc,
900 .sta_deauth = bsd_sta_deauth,
901 .set_ssid = bsd_set_ssid,
902 .get_ssid = bsd_get_ssid,
903 .set_countermeasures = bsd_set_countermeasures,
904 .sta_clear_stats = bsd_sta_clear_stats,
905 .commit = bsd_commit,
906 #ifdef CONFIG_DRIVER_RADIUS_ACL
907 .set_radius_acl_auth = bsd_set_radius_acl_auth,
908 .set_radius_acl_expire = bsd_set_radius_acl_expire,