2 * WPA Supplicant - driver interaction with BSD net80211 layer
3 * Copyright (c) 2004, Sam Leffler <sam@errno.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
21 #include <sys/ioctl.h>
27 #include "wpa_supplicant.h"
28 #include "l2_packet.h"
29 #include "wpa.h" /* XXX for RSN_INFO_ELEM */
31 #include <sys/socket.h>
33 #include <net/ethernet.h>
35 #include <net80211/ieee80211.h>
36 #include <net80211/ieee80211_crypto.h>
37 #include <net80211/ieee80211_ioctl.h>
39 struct wpa_driver_bsd_data {
40 int sock; /* open socket for 802.11 ioctls */
41 int route; /* routing socket for events */
42 char ifname[IFNAMSIZ+1]; /* interface name */
43 unsigned int ifindex; /* interface index */
45 int prev_roaming; /* roaming state to restore on deinit */
46 int prev_privacy; /* privacy state to restore on deinit */
47 int prev_wpa; /* wpa state to restore on deinit */
51 set80211var(struct wpa_driver_bsd_data *drv, int op, const void *arg, int arg_len)
53 struct ieee80211req ireq;
55 memset(&ireq, 0, sizeof(ireq));
56 strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
59 ireq.i_data = (void *) arg;
61 if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) {
62 fprintf(stderr, "ioctl[SIOCS80211, op %u, len %u]: %s\n",
63 op, arg_len, strerror(errno));
70 get80211var(struct wpa_driver_bsd_data *drv, int op, void *arg, int arg_len)
72 struct ieee80211req ireq;
74 memset(&ireq, 0, sizeof(ireq));
75 strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
80 if (ioctl(drv->sock, SIOCG80211, &ireq) < 0) {
81 fprintf(stderr, "ioctl[SIOCG80211, op %u, len %u]: %s\n",
82 op, arg_len, strerror(errno));
89 set80211param(struct wpa_driver_bsd_data *drv, int op, int arg)
91 struct ieee80211req ireq;
93 memset(&ireq, 0, sizeof(ireq));
94 strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
98 if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) {
99 fprintf(stderr, "ioctl[SIOCS80211, op %u, arg 0x%x]: %s\n",
100 op, arg, strerror(errno));
107 get80211param(struct wpa_driver_bsd_data *drv, int op)
109 struct ieee80211req ireq;
111 memset(&ireq, 0, sizeof(ireq));
112 strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
115 if (ioctl(drv->sock, SIOCG80211, &ireq) < 0) {
116 fprintf(stderr, "ioctl[SIOCG80211, op %u]: %s\n",
117 op, strerror(errno));
124 getifflags(struct wpa_driver_bsd_data *drv, int *flags)
128 memset(&ifr, 0, sizeof(ifr));
129 strncpy(ifr.ifr_name, drv->ifname, sizeof (ifr.ifr_name));
130 if (ioctl(drv->sock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
131 perror("SIOCGIFFLAGS");
134 *flags = ifr.ifr_flags & 0xffff;
139 setifflags(struct wpa_driver_bsd_data *drv, int flags)
143 memset(&ifr, 0, sizeof(ifr));
144 strncpy(ifr.ifr_name, drv->ifname, sizeof (ifr.ifr_name));
145 ifr.ifr_flags = flags & 0xffff;
146 if (ioctl(drv->sock, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) {
147 perror("SIOCSIFFLAGS");
154 wpa_driver_bsd_get_bssid(void *priv, u8 *bssid)
156 struct wpa_driver_bsd_data *drv = priv;
158 return get80211var(drv, IEEE80211_IOC_BSSID,
159 bssid, IEEE80211_ADDR_LEN) < 0 ? -1 : 0;
164 wpa_driver_bsd_set_bssid(void *priv, const char *bssid)
166 struct wpa_driver_bsd_data *drv = priv;
168 return set80211var(drv, IEEE80211_IOC_BSSID,
169 bssid, IEEE80211_ADDR_LEN);
174 wpa_driver_bsd_get_ssid(void *priv, u8 *ssid)
176 struct wpa_driver_bsd_data *drv = priv;
178 return get80211var(drv, IEEE80211_IOC_SSID,
179 ssid, IEEE80211_NWID_LEN);
183 wpa_driver_bsd_set_ssid(void *priv, const char *ssid,
186 struct wpa_driver_bsd_data *drv = priv;
188 return set80211var(drv, IEEE80211_IOC_SSID, ssid, ssid_len);
192 wpa_driver_bsd_set_wpa_ie(struct wpa_driver_bsd_data *drv,
193 const char *wpa_ie, size_t wpa_ie_len)
195 return set80211var(drv, IEEE80211_IOC_OPTIE, wpa_ie, wpa_ie_len);
199 wpa_driver_bsd_set_wpa_internal(void *priv, int wpa, int privacy)
201 struct wpa_driver_bsd_data *drv = priv;
204 wpa_printf(MSG_DEBUG, "%s: wpa=%d privacy=%d",
205 __FUNCTION__, wpa, privacy);
207 if (!wpa && wpa_driver_bsd_set_wpa_ie(drv, NULL, 0) < 0)
209 if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0)
211 if (set80211param(drv, IEEE80211_IOC_WPA, wpa) < 0)
218 wpa_driver_bsd_set_wpa(void *priv, int enabled)
220 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
222 return wpa_driver_bsd_set_wpa_internal(priv, enabled ? 3 : 0, enabled);
226 wpa_driver_bsd_del_key(struct wpa_driver_bsd_data *drv, int key_idx,
227 const unsigned char *addr)
229 struct ieee80211req_del_key wk;
231 memset(&wk, 0, sizeof(wk));
233 bcmp(addr, "\xff\xff\xff\xff\xff\xff", IEEE80211_ADDR_LEN) != 0) {
234 struct ether_addr ea;
236 memcpy(&ea, addr, IEEE80211_ADDR_LEN);
237 wpa_printf(MSG_DEBUG, "%s: addr=%s keyidx=%d",
238 __func__, ether_ntoa(&ea), key_idx);
239 memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
240 wk.idk_keyix = (uint8_t) IEEE80211_KEYIX_NONE;
242 wpa_printf(MSG_DEBUG, "%s: keyidx=%d", __func__, key_idx);
243 wk.idk_keyix = key_idx;
245 return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
249 wpa_driver_bsd_set_key(void *priv, wpa_alg alg,
250 const unsigned char *addr, int key_idx, int set_tx,
251 const u8 *seq, size_t seq_len,
252 const u8 *key, size_t key_len)
254 struct wpa_driver_bsd_data *drv = priv;
255 struct ieee80211req_key wk;
256 struct ether_addr ea;
260 if (alg == WPA_ALG_NONE)
261 return wpa_driver_bsd_del_key(drv, key_idx, addr);
266 cipher = IEEE80211_CIPHER_WEP;
270 cipher = IEEE80211_CIPHER_TKIP;
274 cipher = IEEE80211_CIPHER_AES_CCM;
277 wpa_printf(MSG_DEBUG, "%s: unknown/unsupported algorithm %d",
282 memcpy(&ea, addr, IEEE80211_ADDR_LEN);
283 wpa_printf(MSG_DEBUG,
284 "%s: alg=%s addr=%s key_idx=%d set_tx=%d seq_len=%zu key_len=%zu",
285 __func__, alg_name, ether_ntoa(&ea), key_idx, set_tx,
288 if (seq_len > sizeof(u_int64_t)) {
289 wpa_printf(MSG_DEBUG, "%s: seq_len %zu too big",
293 if (key_len > sizeof(wk.ik_keydata)) {
294 wpa_printf(MSG_DEBUG, "%s: key length %zu too big",
299 memset(&wk, 0, sizeof(wk));
301 wk.ik_flags = IEEE80211_KEY_RECV;
303 wk.ik_flags |= IEEE80211_KEY_XMIT;
304 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
306 * Deduce whether group/global or unicast key by checking
307 * the address (yech). Note also that we can only mark global
308 * keys default; doing this for a unicast key is an error.
310 if (bcmp(addr, "\xff\xff\xff\xff\xff\xff", IEEE80211_ADDR_LEN) == 0) {
311 wk.ik_flags |= IEEE80211_KEY_GROUP;
312 wk.ik_keyix = key_idx;
314 wk.ik_keyix = (key_idx == 0 ? IEEE80211_KEYIX_NONE : key_idx);
316 if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx)
317 wk.ik_flags |= IEEE80211_KEY_DEFAULT;
318 wk.ik_keylen = key_len;
319 memcpy(&wk.ik_keyrsc, seq, seq_len);
320 memcpy(wk.ik_keydata, key, key_len);
322 return set80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
326 wpa_driver_bsd_set_countermeasures(void *priv, int enabled)
328 struct wpa_driver_bsd_data *drv = priv;
330 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
331 return set80211param(drv, IEEE80211_IOC_COUNTERMEASURES, enabled);
336 wpa_driver_bsd_set_drop_unencrypted(void *priv, int enabled)
338 struct wpa_driver_bsd_data *drv = priv;
340 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
341 return set80211param(drv, IEEE80211_IOC_DROPUNENCRYPTED, enabled);
345 wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code)
347 struct wpa_driver_bsd_data *drv = priv;
348 struct ieee80211req_mlme mlme;
350 wpa_printf(MSG_DEBUG, "%s", __func__);
351 memset(&mlme, 0, sizeof(mlme));
352 mlme.im_op = IEEE80211_MLME_DEAUTH;
353 mlme.im_reason = reason_code;
354 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
355 return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
359 wpa_driver_bsd_disassociate(void *priv, const u8 *addr, int reason_code)
361 struct wpa_driver_bsd_data *drv = priv;
362 struct ieee80211req_mlme mlme;
364 wpa_printf(MSG_DEBUG, "%s", __func__);
365 memset(&mlme, 0, sizeof(mlme));
366 mlme.im_op = IEEE80211_MLME_DISASSOC;
367 mlme.im_reason = reason_code;
368 memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
369 return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
373 wpa_driver_bsd_associate(void *priv, struct wpa_driver_associate_params *params)
375 struct wpa_driver_bsd_data *drv = priv;
376 struct ieee80211req_mlme mlme;
379 wpa_printf(MSG_DEBUG,
380 "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u"
382 , params->ssid_len, params->ssid
384 , params->pairwise_suite
385 , params->group_suite
386 , params->key_mgmt_suite
389 /* XXX error handling is wrong but unclear what to do... */
390 if (wpa_driver_bsd_set_wpa_ie(drv, params->wpa_ie, params->wpa_ie_len) < 0)
393 privacy = !(params->pairwise_suite == CIPHER_NONE &&
394 params->group_suite == CIPHER_NONE &&
395 params->key_mgmt_suite == KEY_MGMT_NONE &&
396 params->wpa_ie_len == 0);
397 wpa_printf(MSG_DEBUG, "%s: set PRIVACY %u", __func__, privacy);
399 if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0)
402 if (params->wpa_ie_len &&
403 set80211param(drv, IEEE80211_IOC_WPA,
404 params->wpa_ie[0] == RSN_INFO_ELEM ? 2 : 1) < 0)
407 memset(&mlme, 0, sizeof(mlme));
408 mlme.im_op = IEEE80211_MLME_ASSOC;
409 if (params->ssid != NULL)
410 memcpy(mlme.im_ssid, params->ssid, params->ssid_len);
411 mlme.im_ssid_len = params->ssid_len;
412 if (params->bssid != NULL)
413 memcpy(mlme.im_macaddr, params->bssid, IEEE80211_ADDR_LEN);
414 if (set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)) < 0)
420 wpa_driver_bsd_set_auth_alg(void *priv, int auth_alg)
422 struct wpa_driver_bsd_data *drv = priv;
425 if ((auth_alg & AUTH_ALG_OPEN_SYSTEM) &&
426 (auth_alg & AUTH_ALG_SHARED_KEY))
427 authmode = IEEE80211_AUTH_AUTO;
428 else if (auth_alg & AUTH_ALG_SHARED_KEY)
429 authmode = IEEE80211_AUTH_SHARED;
431 authmode = IEEE80211_AUTH_OPEN;
433 wpa_printf(MSG_DEBUG, "%s alg 0x%x authmode %u",
434 __func__, auth_alg, authmode);
436 return set80211param(drv, IEEE80211_IOC_AUTHMODE, authmode);
440 wpa_driver_bsd_scan(void *priv, const u8 *ssid, size_t ssid_len)
442 struct wpa_driver_bsd_data *drv = priv;
445 /* NB: interface must be marked UP to do a scan */
446 if (getifflags(drv, &flags) != 0 || setifflags(drv, flags | IFF_UP) != 0)
449 /* set desired ssid before scan */
450 if (wpa_driver_bsd_set_ssid(drv, ssid, ssid_len) < 0)
453 /* NB: net80211 delivers a scan complete event so no need to poll */
454 return set80211param(drv, IEEE80211_IOC_SCAN_REQ, 0);
457 #include <net/route.h>
458 #include <net80211/ieee80211_freebsd.h>
461 wpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx)
463 struct wpa_driver_bsd_data *drv = sock_ctx;
465 struct if_announcemsghdr *ifan;
466 struct if_msghdr *ifm;
467 struct rt_msghdr *rtm;
468 union wpa_event_data event;
469 struct ieee80211_michael_event *mic;
472 n = read(sock, buf, sizeof(buf));
474 if (errno != EINTR && errno != EAGAIN)
475 perror("read(PF_ROUTE)");
479 rtm = (struct rt_msghdr *) buf;
480 if (rtm->rtm_version != RTM_VERSION) {
481 wpa_printf(MSG_DEBUG, "Routing message version %d not "
482 "understood\n", rtm->rtm_version);
485 memset(&event, 0, sizeof(event));
486 switch (rtm->rtm_type) {
488 ifan = (struct if_announcemsghdr *) rtm;
489 if (ifan->ifan_index != drv->ifindex)
491 strlcpy(event.interface_status.ifname, drv->ifname,
492 sizeof(event.interface_status.ifname));
493 switch (ifan->ifan_what) {
495 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
499 wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: Interface '%s' %s",
500 event.interface_status.ifname,
501 ifan->ifan_what == IFAN_DEPARTURE ?
502 "removed" : "added");
503 wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event);
506 ifan = (struct if_announcemsghdr *) rtm;
507 if (ifan->ifan_index != drv->ifindex)
509 switch (ifan->ifan_what) {
510 case RTM_IEEE80211_ASSOC:
511 case RTM_IEEE80211_REASSOC:
512 wpa_supplicant_event(ctx, EVENT_ASSOC, NULL);
514 case RTM_IEEE80211_DISASSOC:
515 wpa_supplicant_event(ctx, EVENT_DISASSOC, NULL);
517 case RTM_IEEE80211_SCAN:
518 wpa_supplicant_event(ctx, EVENT_SCAN_RESULTS, NULL);
520 case RTM_IEEE80211_REPLAY:
523 case RTM_IEEE80211_MICHAEL:
524 mic = (struct ieee80211_michael_event *) &ifan[1];
525 wpa_printf(MSG_DEBUG,
526 "Michael MIC failure wireless event: "
527 "keyix=%u src_addr=" MACSTR, mic->iev_keyix,
528 MAC2STR(mic->iev_src));
530 memset(&event, 0, sizeof(event));
531 event.michael_mic_failure.unicast =
532 !IEEE80211_IS_MULTICAST(mic->iev_dst);
533 wpa_supplicant_event(ctx, EVENT_MICHAEL_MIC_FAILURE,
539 ifm = (struct if_msghdr *) rtm;
540 if (ifm->ifm_index != drv->ifindex)
542 if ((rtm->rtm_flags & RTF_UP) == 0) {
543 strlcpy(event.interface_status.ifname, drv->ifname,
544 sizeof(event.interface_status.ifname));
545 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
546 wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' DOWN",
547 event.interface_status.ifname);
548 wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event);
554 /* Compare function for sorting scan results. Return >0 if @b is consider
557 wpa_scan_result_compar(const void *a, const void *b)
559 const struct wpa_scan_result *wa = a;
560 const struct wpa_scan_result *wb = b;
562 /* WPA/WPA2 support preferred */
563 if ((wb->wpa_ie_len || wb->rsn_ie_len) &&
564 !(wa->wpa_ie_len || wa->rsn_ie_len))
566 if (!(wb->wpa_ie_len || wb->rsn_ie_len) &&
567 (wa->wpa_ie_len || wa->rsn_ie_len))
570 /* privacy support preferred */
571 if ((wa->caps & IEEE80211_CAPINFO_PRIVACY) &&
572 (wb->caps & IEEE80211_CAPINFO_PRIVACY) == 0)
574 if ((wa->caps & IEEE80211_CAPINFO_PRIVACY) == 0 &&
575 (wb->caps & IEEE80211_CAPINFO_PRIVACY))
578 /* best/max rate preferred if signal level close enough XXX */
579 if (wa->maxrate != wb->maxrate && abs(wb->level - wa->level) < 5)
580 return wb->maxrate - wa->maxrate;
582 /* use freq for channel preference */
584 /* all things being equal, use signal level */
585 return wb->level - wa->level;
589 getmaxrate(uint8_t rates[15], uint8_t nrates)
593 for (i = 0; i < nrates; i++) {
594 int rate = rates[i] & IEEE80211_RATE_VAL;
601 /* unalligned little endian access */
602 #define LE_READ_4(p) \
604 ((((const u_int8_t *)(p))[0] ) | \
605 (((const u_int8_t *)(p))[1] << 8) | \
606 (((const u_int8_t *)(p))[2] << 16) | \
607 (((const u_int8_t *)(p))[3] << 24)))
610 iswpaoui(const u_int8_t *frm)
612 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
616 wpa_driver_bsd_get_scan_results(void *priv,
617 struct wpa_scan_result *results,
620 #define min(a,b) ((a)>(b)?(b):(a))
621 struct wpa_driver_bsd_data *drv = priv;
622 uint8_t buf[24*1024];
624 struct ieee80211req_scan_result *sr;
625 struct wpa_scan_result *wsr;
628 memset(results, 0, max_size * sizeof(struct wpa_scan_result));
630 len = get80211var(drv, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf));
635 while (len >= sizeof(struct ieee80211req_scan_result)) {
636 sr = (struct ieee80211req_scan_result *) cp;
637 memcpy(wsr->bssid, sr->isr_bssid, IEEE80211_ADDR_LEN);
638 wsr->ssid_len = sr->isr_ssid_len;
639 wsr->freq = sr->isr_freq;
640 wsr->noise = sr->isr_noise;
641 wsr->qual = sr->isr_rssi;
642 wsr->level = 0; /* XXX? */
643 wsr->caps = sr->isr_capinfo;
644 wsr->maxrate = getmaxrate(sr->isr_rates, sr->isr_nrates);
645 vp = (u_int8_t *)(sr+1);
646 memcpy(wsr->ssid, vp, sr->isr_ssid_len);
647 if (sr->isr_ie_len > 0) {
648 vp += sr->isr_ssid_len;
649 ielen = sr->isr_ie_len;
652 case IEEE80211_ELEMID_VENDOR:
656 min(2+vp[1], SSID_MAX_WPA_IE_LEN);
657 memcpy(wsr->wpa_ie, vp, wsr->wpa_ie_len);
659 case IEEE80211_ELEMID_RSN:
661 min(2+vp[1], SSID_MAX_WPA_IE_LEN);
662 memcpy(wsr->rsn_ie, vp, wsr->rsn_ie_len);
670 cp += sr->isr_len, len -= sr->isr_len;
673 qsort(results, wsr - results, sizeof(struct wpa_scan_result),
674 wpa_scan_result_compar);
676 wpa_printf(MSG_DEBUG, "Received %d bytes of scan results (%d BSSes)",
679 return wsr - results;
684 wpa_driver_bsd_init(void *ctx, const char *ifname)
686 #define GETPARAM(drv, param, v) \
687 (((v) = get80211param(drv, param)) != -1)
688 struct wpa_driver_bsd_data *drv;
690 drv = malloc(sizeof(*drv));
693 memset(drv, 0, sizeof(*drv));
695 * NB: We require the interface name be mappable to an index.
696 * This implies we do not support having wpa_supplicant
697 * wait for an interface to appear. This seems ok; that
698 * doesn't belong here; it's really the job of devd.
700 drv->ifindex = if_nametoindex(ifname);
701 if (drv->ifindex == 0) {
702 wpa_printf(MSG_DEBUG, "%s: interface %s does not exist",
706 drv->sock = socket(PF_INET, SOCK_DGRAM, 0);
709 drv->route = socket(PF_ROUTE, SOCK_RAW, 0);
712 eloop_register_read_sock(drv->route,
713 wpa_driver_bsd_event_receive, ctx, drv);
716 strncpy(drv->ifname, ifname, sizeof(drv->ifname));
718 if (!GETPARAM(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming)) {
719 wpa_printf(MSG_DEBUG, "%s: failed to get roaming state: %s",
720 __func__, strerror(errno));
723 if (!GETPARAM(drv, IEEE80211_IOC_PRIVACY, drv->prev_privacy)) {
724 wpa_printf(MSG_DEBUG, "%s: failed to get privacy state: %s",
725 __func__, strerror(errno));
728 if (!GETPARAM(drv, IEEE80211_IOC_WPA, drv->prev_wpa)) {
729 wpa_printf(MSG_DEBUG, "%s: failed to get wpa state: %s",
730 __func__, strerror(errno));
733 if (set80211param(drv, IEEE80211_IOC_ROAMING, IEEE80211_ROAMING_MANUAL) < 0) {
734 wpa_printf(MSG_DEBUG, "%s: failed to set wpa_supplicant-based "
735 "roaming: %s", __func__, strerror(errno));
739 if (set80211param(drv, IEEE80211_IOC_WPA, 1+2) < 0) {
740 wpa_printf(MSG_DEBUG, "%s: failed to enable WPA support %s",
741 __func__, strerror(errno));
755 wpa_driver_bsd_deinit(void *priv)
757 struct wpa_driver_bsd_data *drv = priv;
760 /* NB: mark interface down */
761 if (getifflags(drv, &flags) == 0)
762 (void) setifflags(drv, flags &~ IFF_UP);
764 wpa_driver_bsd_set_wpa_internal(drv, drv->prev_wpa, drv->prev_privacy);
765 if (set80211param(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming) < 0)
766 wpa_printf(MSG_DEBUG, "%s: failed to restore roaming state",
769 (void) close(drv->route); /* ioctl socket */
770 (void) close(drv->sock); /* event socket */
775 struct wpa_driver_ops wpa_driver_bsd_ops = {
777 .desc = "BSD 802.11 support (Atheros, etc.)",
778 .init = wpa_driver_bsd_init,
779 .deinit = wpa_driver_bsd_deinit,
780 .get_bssid = wpa_driver_bsd_get_bssid,
781 .get_ssid = wpa_driver_bsd_get_ssid,
782 .set_wpa = wpa_driver_bsd_set_wpa,
783 .set_key = wpa_driver_bsd_set_key,
784 .set_countermeasures = wpa_driver_bsd_set_countermeasures,
785 .set_drop_unencrypted = wpa_driver_bsd_set_drop_unencrypted,
786 .scan = wpa_driver_bsd_scan,
787 .get_scan_results = wpa_driver_bsd_get_scan_results,
788 .deauthenticate = wpa_driver_bsd_deauthenticate,
789 .disassociate = wpa_driver_bsd_disassociate,
790 .associate = wpa_driver_bsd_associate,
791 .set_auth_alg = wpa_driver_bsd_set_auth_alg,