2 * WPA Supplicant - 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.
17 #include <sys/ioctl.h>
22 #include "common/ieee802_11_defs.h"
25 #include <net/if_media.h>
28 #include <net/if_ether.h>
30 #include <net/ethernet.h>
32 #include <net/route.h>
35 #include <netproto/802_11/ieee80211_ioctl.h>
36 #include <netproto/802_11/ieee80211_dragonfly.h>
37 #else /* __DragonFly__ */
39 #include <netinet/ether.h>
40 #endif /* __GLIBC__ */
41 #include <net80211/ieee80211.h>
42 #include <net80211/ieee80211_ioctl.h>
43 #include <net80211/ieee80211_crypto.h>
44 #endif /* __DragonFly__ || __GLIBC__ */
45 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
46 #include <net80211/ieee80211_freebsd.h>
49 #include <net80211/ieee80211_netbsd.h>
52 #include "l2_packet/l2_packet.h"
54 struct bsd_driver_data
{
55 struct hostapd_data
*hapd
; /* back pointer */
57 int sock
; /* open socket for 802.11 ioctls */
58 struct l2_packet_data
*sock_xmit
;/* raw packet xmit socket */
59 int route
; /* routing socket for events */
60 char ifname
[IFNAMSIZ
+1]; /* interface name */
61 unsigned int ifindex
; /* interface index */
63 struct wpa_driver_capa capa
; /* driver capability */
64 int is_ap
; /* Access point mode */
65 int prev_roaming
; /* roaming state to restore on deinit */
66 int prev_privacy
; /* privacy state to restore on deinit */
67 int prev_wpa
; /* wpa state to restore on deinit */
70 /* Generic functions for hostapd and wpa_supplicant */
73 bsd_set80211(void *priv
, int op
, int val
, const void *arg
, int arg_len
)
75 struct bsd_driver_data
*drv
= priv
;
76 struct ieee80211req ireq
;
78 os_memset(&ireq
, 0, sizeof(ireq
));
79 os_strlcpy(ireq
.i_name
, drv
->ifname
, sizeof(ireq
.i_name
));
82 ireq
.i_data
= (void *) arg
;
85 if (ioctl(drv
->sock
, SIOCS80211
, &ireq
) < 0) {
86 wpa_printf(MSG_ERROR
, "ioctl[SIOCS80211, op=%u, val=%u, "
87 "arg_len=%u]: %s", op
, val
, arg_len
,
95 bsd_get80211(void *priv
, struct ieee80211req
*ireq
, int op
, void *arg
,
98 struct bsd_driver_data
*drv
= priv
;
100 os_memset(ireq
, 0, sizeof(*ireq
));
101 os_strlcpy(ireq
->i_name
, drv
->ifname
, sizeof(ireq
->i_name
));
103 ireq
->i_len
= arg_len
;
106 if (ioctl(drv
->sock
, SIOCG80211
, ireq
) < 0) {
107 wpa_printf(MSG_ERROR
, "ioctl[SIOCS80211, op=%u, "
108 "arg_len=%u]: %s", op
, arg_len
, strerror(errno
));
115 get80211var(struct bsd_driver_data
*drv
, int op
, void *arg
, int arg_len
)
117 struct ieee80211req ireq
;
119 if (bsd_get80211(drv
, &ireq
, op
, arg
, arg_len
) < 0)
125 set80211var(struct bsd_driver_data
*drv
, int op
, const void *arg
, int arg_len
)
127 return bsd_set80211(drv
, op
, 0, arg
, arg_len
);
131 set80211param(struct bsd_driver_data
*drv
, int op
, int arg
)
133 return bsd_set80211(drv
, op
, arg
, NULL
, 0);
137 bsd_get_ssid(void *priv
, u8
*ssid
, int len
)
139 struct bsd_driver_data
*drv
= priv
;
140 #ifdef SIOCG80211NWID
141 struct ieee80211_nwid nwid
;
144 os_memset(&ifr
, 0, sizeof(ifr
));
145 os_strlcpy(ifr
.ifr_name
, drv
->ifname
, sizeof(ifr
.ifr_name
));
146 ifr
.ifr_data
= (void *)&nwid
;
147 if (ioctl(drv
->sock
, SIOCG80211NWID
, &ifr
) < 0 ||
148 nwid
.i_len
> IEEE80211_NWID_LEN
)
150 os_memcpy(ssid
, nwid
.i_nwid
, nwid
.i_len
);
153 return get80211var(drv
, IEEE80211_IOC_SSID
, ssid
, IEEE80211_NWID_LEN
);
158 bsd_set_ssid(void *priv
, const u8
*ssid
, int ssid_len
)
160 struct bsd_driver_data
*drv
= priv
;
161 #ifdef SIOCS80211NWID
162 struct ieee80211_nwid nwid
;
165 os_memcpy(nwid
.i_nwid
, ssid
, ssid_len
);
166 nwid
.i_len
= ssid_len
;
167 os_memset(&ifr
, 0, sizeof(ifr
));
168 os_strlcpy(ifr
.ifr_name
, drv
->ifname
, sizeof(ifr
.ifr_name
));
169 ifr
.ifr_data
= (void *)&nwid
;
170 return ioctl(drv
->sock
, SIOCS80211NWID
, &ifr
);
172 return set80211var(drv
, IEEE80211_IOC_SSID
, ssid
, ssid_len
);
177 bsd_get_if_media(void *priv
)
179 struct bsd_driver_data
*drv
= priv
;
180 struct ifmediareq ifmr
;
182 os_memset(&ifmr
, 0, sizeof(ifmr
));
183 os_strlcpy(ifmr
.ifm_name
, drv
->ifname
, sizeof(ifmr
.ifm_name
));
185 if (ioctl(drv
->sock
, SIOCGIFMEDIA
, &ifmr
) < 0) {
186 wpa_printf(MSG_ERROR
, "%s: SIOCGIFMEDIA %s", __func__
,
191 return ifmr
.ifm_current
;
195 bsd_set_if_media(void *priv
, int media
)
197 struct bsd_driver_data
*drv
= priv
;
200 os_memset(&ifr
, 0, sizeof(ifr
));
201 os_strlcpy(ifr
.ifr_name
, drv
->ifname
, sizeof(ifr
.ifr_name
));
202 ifr
.ifr_media
= media
;
204 if (ioctl(drv
->sock
, SIOCSIFMEDIA
, &ifr
) < 0) {
205 wpa_printf(MSG_ERROR
, "%s: SIOCSIFMEDIA %s", __func__
,
214 bsd_set_mediaopt(void *priv
, uint32_t mask
, uint32_t mode
)
216 int media
= bsd_get_if_media(priv
);
222 if (bsd_set_if_media(priv
, media
) < 0)
228 bsd_del_key(void *priv
, const u8
*addr
, int key_idx
)
230 struct ieee80211req_del_key wk
;
232 os_memset(&wk
, 0, sizeof(wk
));
234 wpa_printf(MSG_DEBUG
, "%s: key_idx=%d", __func__
, key_idx
);
235 wk
.idk_keyix
= key_idx
;
237 wpa_printf(MSG_DEBUG
, "%s: addr=" MACSTR
, __func__
,
239 os_memcpy(wk
.idk_macaddr
, addr
, IEEE80211_ADDR_LEN
);
240 wk
.idk_keyix
= (u_int8_t
) IEEE80211_KEYIX_NONE
; /* XXX */
243 return set80211var(priv
, IEEE80211_IOC_DELKEY
, &wk
, sizeof(wk
));
247 bsd_send_mlme_param(void *priv
, const u8 op
, const u16 reason
, const u8
*addr
)
249 struct ieee80211req_mlme mlme
;
251 os_memset(&mlme
, 0, sizeof(mlme
));
253 mlme
.im_reason
= reason
;
254 os_memcpy(mlme
.im_macaddr
, addr
, IEEE80211_ADDR_LEN
);
255 return set80211var(priv
, IEEE80211_IOC_MLME
, &mlme
, sizeof(mlme
));
259 bsd_ctrl_iface(void *priv
, int enable
)
261 struct bsd_driver_data
*drv
= priv
;
264 os_memset(&ifr
, 0, sizeof(ifr
));
265 os_strlcpy(ifr
.ifr_name
, drv
->ifname
, sizeof(ifr
.ifr_name
));
267 if (ioctl(drv
->sock
, SIOCGIFFLAGS
, &ifr
) < 0) {
268 perror("ioctl[SIOCGIFFLAGS]");
273 ifr
.ifr_flags
|= IFF_UP
;
275 ifr
.ifr_flags
&= ~IFF_UP
;
277 if (ioctl(drv
->sock
, SIOCSIFFLAGS
, &ifr
) < 0) {
278 perror("ioctl[SIOCSIFFLAGS]");
286 bsd_set_key(const char *ifname
, void *priv
, enum wpa_alg alg
,
287 const unsigned char *addr
, int key_idx
, int set_tx
, const u8
*seq
,
288 size_t seq_len
, const u8
*key
, size_t key_len
)
290 struct ieee80211req_key wk
;
292 wpa_printf(MSG_DEBUG
, "%s: alg=%d addr=%p key_idx=%d set_tx=%d "
293 "seq_len=%zu key_len=%zu", __func__
, alg
, addr
, key_idx
,
294 set_tx
, seq_len
, key_len
);
296 if (alg
== WPA_ALG_NONE
) {
299 os_memcmp(addr
, "\xff\xff\xff\xff\xff\xff",
300 IEEE80211_ADDR_LEN
) == 0)
301 return bsd_del_key(priv
, NULL
, key_idx
);
304 return bsd_del_key(priv
, addr
, key_idx
);
307 os_memset(&wk
, 0, sizeof(wk
));
310 wk
.ik_type
= IEEE80211_CIPHER_WEP
;
313 wk
.ik_type
= IEEE80211_CIPHER_TKIP
;
316 wk
.ik_type
= IEEE80211_CIPHER_AES_CCM
;
319 wpa_printf(MSG_ERROR
, "%s: unknown alg=%d", __func__
, alg
);
323 wk
.ik_flags
= IEEE80211_KEY_RECV
;
325 wk
.ik_flags
|= IEEE80211_KEY_XMIT
;
328 os_memset(wk
.ik_macaddr
, 0xff, IEEE80211_ADDR_LEN
);
329 wk
.ik_keyix
= key_idx
;
331 os_memcpy(wk
.ik_macaddr
, addr
, IEEE80211_ADDR_LEN
);
333 * Deduce whether group/global or unicast key by checking
334 * the address (yech). Note also that we can only mark global
335 * keys default; doing this for a unicast key is an error.
337 if (os_memcmp(addr
, "\xff\xff\xff\xff\xff\xff",
338 IEEE80211_ADDR_LEN
) == 0) {
339 wk
.ik_flags
|= IEEE80211_KEY_GROUP
;
340 wk
.ik_keyix
= key_idx
;
342 wk
.ik_keyix
= key_idx
== 0 ? IEEE80211_KEYIX_NONE
:
346 if (wk
.ik_keyix
!= IEEE80211_KEYIX_NONE
&& set_tx
)
347 wk
.ik_flags
|= IEEE80211_KEY_DEFAULT
;
348 wk
.ik_keylen
= key_len
;
349 os_memcpy(&wk
.ik_keyrsc
, seq
, seq_len
);
350 os_memcpy(wk
.ik_keydata
, key
, key_len
);
352 return set80211var(priv
, IEEE80211_IOC_WPAKEY
, &wk
, sizeof(wk
));
356 bsd_configure_wpa(void *priv
, struct wpa_bss_params
*params
)
358 #ifndef IEEE80211_IOC_APPIE
359 static const char *ciphernames
[] =
360 { "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" };
363 switch (params
->wpa_group
) {
364 case WPA_CIPHER_CCMP
:
365 v
= IEEE80211_CIPHER_AES_CCM
;
367 case WPA_CIPHER_TKIP
:
368 v
= IEEE80211_CIPHER_TKIP
;
370 case WPA_CIPHER_WEP104
:
371 v
= IEEE80211_CIPHER_WEP
;
373 case WPA_CIPHER_WEP40
:
374 v
= IEEE80211_CIPHER_WEP
;
376 case WPA_CIPHER_NONE
:
377 v
= IEEE80211_CIPHER_NONE
;
380 printf("Unknown group key cipher %u\n",
384 wpa_printf(MSG_DEBUG
, "%s: group key cipher=%s (%u)",
385 __func__
, ciphernames
[v
], v
);
386 if (set80211param(priv
, IEEE80211_IOC_MCASTCIPHER
, v
)) {
387 printf("Unable to set group key cipher to %u (%s)\n",
391 if (v
== IEEE80211_CIPHER_WEP
) {
392 /* key length is done only for specific ciphers */
393 v
= (params
->wpa_group
== WPA_CIPHER_WEP104
? 13 : 5);
394 if (set80211param(priv
, IEEE80211_IOC_MCASTKEYLEN
, v
)) {
395 printf("Unable to set group key length to %u\n", v
);
401 if (params
->wpa_pairwise
& WPA_CIPHER_CCMP
)
402 v
|= 1<<IEEE80211_CIPHER_AES_CCM
;
403 if (params
->wpa_pairwise
& WPA_CIPHER_TKIP
)
404 v
|= 1<<IEEE80211_CIPHER_TKIP
;
405 if (params
->wpa_pairwise
& WPA_CIPHER_NONE
)
406 v
|= 1<<IEEE80211_CIPHER_NONE
;
407 wpa_printf(MSG_DEBUG
, "%s: pairwise key ciphers=0x%x", __func__
, v
);
408 if (set80211param(priv
, IEEE80211_IOC_UCASTCIPHERS
, v
)) {
409 printf("Unable to set pairwise key ciphers to 0x%x\n", v
);
413 wpa_printf(MSG_DEBUG
, "%s: key management algorithms=0x%x",
414 __func__
, params
->wpa_key_mgmt
);
415 if (set80211param(priv
, IEEE80211_IOC_KEYMGTALGS
,
416 params
->wpa_key_mgmt
)) {
417 printf("Unable to set key management algorithms to 0x%x\n",
418 params
->wpa_key_mgmt
);
423 if (params
->rsn_preauth
)
425 wpa_printf(MSG_DEBUG
, "%s: rsn capabilities=0x%x",
426 __func__
, params
->rsn_preauth
);
427 if (set80211param(priv
, IEEE80211_IOC_RSNCAPS
, v
)) {
428 printf("Unable to set RSN capabilities to 0x%x\n", v
);
431 #endif /* IEEE80211_IOC_APPIE */
433 wpa_printf(MSG_DEBUG
, "%s: enable WPA= 0x%x", __func__
, params
->wpa
);
434 if (set80211param(priv
, IEEE80211_IOC_WPA
, params
->wpa
)) {
435 printf("Unable to set WPA to %u\n", params
->wpa
);
442 bsd_set_ieee8021x(void *priv
, struct wpa_bss_params
*params
)
444 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __func__
, params
->enabled
);
446 if (!params
->enabled
) {
447 /* XXX restore state */
448 return set80211param(priv
, IEEE80211_IOC_AUTHMODE
,
449 IEEE80211_AUTH_AUTO
);
451 if (!params
->wpa
&& !params
->ieee802_1x
) {
452 wpa_printf(MSG_ERROR
, "%s: No 802.1X or WPA enabled",
456 if (params
->wpa
&& bsd_configure_wpa(priv
, params
) != 0) {
457 wpa_printf(MSG_ERROR
, "%s: Failed to configure WPA state",
461 if (set80211param(priv
, IEEE80211_IOC_AUTHMODE
,
462 (params
->wpa
? IEEE80211_AUTH_WPA
: IEEE80211_AUTH_8021X
))) {
463 wpa_printf(MSG_ERROR
, "%s: Failed to enable WPA/802.1X",
467 return bsd_ctrl_iface(priv
, 1);
471 bsd_set_sta_authorized(void *priv
, const u8
*addr
,
472 int total_flags
, int flags_or
, int flags_and
)
476 /* For now, only support setting Authorized flag */
477 if (flags_or
& WPA_STA_AUTHORIZED
)
479 if (!(flags_and
& WPA_STA_AUTHORIZED
))
485 return bsd_send_mlme_param(priv
, authorized
?
486 IEEE80211_MLME_AUTHORIZE
:
487 IEEE80211_MLME_UNAUTHORIZE
, 0, addr
);
491 bsd_new_sta(void *priv
, void *ctx
, u8 addr
[IEEE80211_ADDR_LEN
])
493 struct ieee80211req_wpaie ie
;
498 * Fetch and validate any negotiated WPA/RSN parameters.
500 memset(&ie
, 0, sizeof(ie
));
501 memcpy(ie
.wpa_macaddr
, addr
, IEEE80211_ADDR_LEN
);
502 if (get80211var(priv
, IEEE80211_IOC_WPAIE
, &ie
, sizeof(ie
)) < 0) {
503 printf("Failed to get WPA/RSN information element.\n");
507 ielen
= ie
.wpa_ie
[1];
514 drv_event_assoc(ctx
, addr
, iebuf
, ielen
);
518 bsd_send_eapol(void *priv
, const u8
*addr
, const u8
*data
, size_t data_len
,
519 int encrypt
, const u8
*own_addr
)
521 struct bsd_driver_data
*drv
= priv
;
523 wpa_hexdump(MSG_MSGDUMP
, "TX EAPOL", data
, data_len
);
525 return l2_packet_send(drv
->sock_xmit
, addr
, ETH_P_EAPOL
, data
,
530 bsd_set_freq(void *priv
, u16 channel
)
532 struct bsd_driver_data
*drv
= priv
;
533 #ifdef SIOCS80211CHANNEL
534 struct ieee80211chanreq creq
;
535 #endif /* SIOCS80211CHANNEL */
539 mode
= IFM_IEEE80211_11G
;
540 else if (channel
== 14)
541 mode
= IFM_IEEE80211_11B
;
543 mode
= IFM_IEEE80211_11A
;
544 if (bsd_set_mediaopt(drv
, IFM_MMASK
, mode
) < 0) {
545 wpa_printf(MSG_ERROR
, "%s: failed to set modulation mode",
550 #ifdef SIOCS80211CHANNEL
551 os_memset(&creq
, 0, sizeof(creq
));
552 os_strlcpy(creq
.i_name
, drv
->ifname
, sizeof(creq
.i_name
));
553 creq
.i_channel
= channel
;
554 return ioctl(drv
->sock
, SIOCS80211CHANNEL
, &creq
);
555 #else /* SIOCS80211CHANNEL */
556 return set80211param(priv
, IEEE80211_IOC_CHANNEL
, channel
);
557 #endif /* SIOCS80211CHANNEL */
561 bsd_set_opt_ie(void *priv
, const u8
*ie
, size_t ie_len
)
563 #ifdef IEEE80211_IOC_APPIE
564 wpa_printf(MSG_DEBUG
, "%s: set WPA+RSN ie (len %lu)", __func__
,
565 (unsigned long)ie_len
);
566 return bsd_set80211(priv
, IEEE80211_IOC_APPIE
, IEEE80211_APPIE_WPA
,
568 #endif /* IEEE80211_IOC_APPIE */
576 * Avoid conflicts with hostapd definitions by undefining couple of defines
577 * from net80211 header files.
583 static int bsd_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
587 ether_sprintf(const u8
*addr
)
589 static char buf
[sizeof(MACSTR
)];
592 snprintf(buf
, sizeof(buf
), MACSTR
, MAC2STR(addr
));
594 snprintf(buf
, sizeof(buf
), MACSTR
, 0,0,0,0,0,0);
599 bsd_set_privacy(void *priv
, int enabled
)
601 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __func__
, enabled
);
603 return set80211param(priv
, IEEE80211_IOC_PRIVACY
, enabled
);
607 bsd_get_seqnum(const char *ifname
, void *priv
, const u8
*addr
, int idx
,
610 struct ieee80211req_key wk
;
612 wpa_printf(MSG_DEBUG
, "%s: addr=%s idx=%d",
613 __func__
, ether_sprintf(addr
), idx
);
615 memset(&wk
, 0, sizeof(wk
));
617 memset(wk
.ik_macaddr
, 0xff, IEEE80211_ADDR_LEN
);
619 memcpy(wk
.ik_macaddr
, addr
, IEEE80211_ADDR_LEN
);
622 if (get80211var(priv
, IEEE80211_IOC_WPAKEY
, &wk
, sizeof(wk
)) < 0) {
623 printf("Failed to get encryption.\n");
627 #ifdef WORDS_BIGENDIAN
630 * wk.ik_keytsc is in host byte order (big endian), need to
631 * swap it to match with the byte order used in WPA.
634 u8 tmp
[WPA_KEY_RSC_LEN
];
635 memcpy(tmp
, &wk
.ik_keytsc
, sizeof(wk
.ik_keytsc
));
636 for (i
= 0; i
< WPA_KEY_RSC_LEN
; i
++) {
637 seq
[i
] = tmp
[WPA_KEY_RSC_LEN
- i
- 1];
640 #else /* WORDS_BIGENDIAN */
641 memcpy(seq
, &wk
.ik_keytsc
, sizeof(wk
.ik_keytsc
));
642 #endif /* WORDS_BIGENDIAN */
648 bsd_flush(void *priv
)
650 u8 allsta
[IEEE80211_ADDR_LEN
];
652 memset(allsta
, 0xff, IEEE80211_ADDR_LEN
);
653 return bsd_sta_deauth(priv
, NULL
, allsta
, IEEE80211_REASON_AUTH_LEAVE
);
658 bsd_read_sta_driver_data(void *priv
, struct hostap_sta_driver_data
*data
,
661 struct ieee80211req_sta_stats stats
;
663 memcpy(stats
.is_u
.macaddr
, addr
, IEEE80211_ADDR_LEN
);
664 if (get80211var(priv
, IEEE80211_IOC_STA_STATS
, &stats
, sizeof(stats
))
666 /* XXX? do packets counts include non-data frames? */
667 data
->rx_packets
= stats
.is_stats
.ns_rx_data
;
668 data
->rx_bytes
= stats
.is_stats
.ns_rx_bytes
;
669 data
->tx_packets
= stats
.is_stats
.ns_tx_data
;
670 data
->tx_bytes
= stats
.is_stats
.ns_tx_bytes
;
676 bsd_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
, int reason_code
)
678 return bsd_send_mlme_param(priv
, IEEE80211_MLME_DEAUTH
, reason_code
,
683 bsd_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
686 return bsd_send_mlme_param(priv
, IEEE80211_MLME_DISASSOC
, reason_code
,
691 bsd_wireless_event_receive(int sock
, void *ctx
, void *sock_ctx
)
693 struct bsd_driver_data
*drv
= ctx
;
695 struct if_announcemsghdr
*ifan
;
696 struct rt_msghdr
*rtm
;
697 struct ieee80211_michael_event
*mic
;
698 struct ieee80211_join_event
*join
;
699 struct ieee80211_leave_event
*leave
;
701 union wpa_event_data data
;
703 n
= read(sock
, buf
, sizeof(buf
));
705 if (errno
!= EINTR
&& errno
!= EAGAIN
)
706 perror("read(PF_ROUTE)");
710 rtm
= (struct rt_msghdr
*) buf
;
711 if (rtm
->rtm_version
!= RTM_VERSION
) {
712 wpa_printf(MSG_DEBUG
, "Routing message version %d not "
713 "understood\n", rtm
->rtm_version
);
716 ifan
= (struct if_announcemsghdr
*) rtm
;
717 switch (rtm
->rtm_type
) {
719 switch (ifan
->ifan_what
) {
720 case RTM_IEEE80211_ASSOC
:
721 case RTM_IEEE80211_REASSOC
:
722 case RTM_IEEE80211_DISASSOC
:
723 case RTM_IEEE80211_SCAN
:
725 case RTM_IEEE80211_LEAVE
:
726 leave
= (struct ieee80211_leave_event
*) &ifan
[1];
727 drv_event_disassoc(drv
->hapd
, leave
->iev_addr
);
729 case RTM_IEEE80211_JOIN
:
730 #ifdef RTM_IEEE80211_REJOIN
731 case RTM_IEEE80211_REJOIN
:
733 join
= (struct ieee80211_join_event
*) &ifan
[1];
734 bsd_new_sta(drv
, drv
->hapd
, join
->iev_addr
);
736 case RTM_IEEE80211_REPLAY
:
739 case RTM_IEEE80211_MICHAEL
:
740 mic
= (struct ieee80211_michael_event
*) &ifan
[1];
741 wpa_printf(MSG_DEBUG
,
742 "Michael MIC failure wireless event: "
743 "keyix=%u src_addr=" MACSTR
, mic
->iev_keyix
,
744 MAC2STR(mic
->iev_src
));
745 os_memset(&data
, 0, sizeof(data
));
746 data
.michael_mic_failure
.unicast
= 1;
747 data
.michael_mic_failure
.src
= mic
->iev_src
;
748 wpa_supplicant_event(drv
->hapd
,
749 EVENT_MICHAEL_MIC_FAILURE
, &data
);
757 handle_read(void *ctx
, const u8
*src_addr
, const u8
*buf
, size_t len
)
759 struct bsd_driver_data
*drv
= ctx
;
760 drv_event_eapol_rx(drv
->hapd
, src_addr
, buf
, len
);
764 hostapd_bsd_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
766 return bsd_set_freq(priv
, freq
->channel
);
770 bsd_init(struct hostapd_data
*hapd
, struct wpa_init_params
*params
)
772 struct bsd_driver_data
*drv
;
774 drv
= os_zalloc(sizeof(struct bsd_driver_data
));
776 printf("Could not allocate memory for bsd driver data\n");
781 drv
->sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
783 perror("socket[PF_INET,SOCK_DGRAM]");
786 os_strlcpy(drv
->ifname
, params
->ifname
, sizeof(drv
->ifname
));
788 drv
->sock_xmit
= l2_packet_init(drv
->ifname
, NULL
, ETH_P_EAPOL
,
789 handle_read
, drv
, 0);
790 if (drv
->sock_xmit
== NULL
)
792 if (l2_packet_get_own_addr(drv
->sock_xmit
, params
->own_addr
))
795 /* mark down during setup */
796 if (bsd_ctrl_iface(drv
, 0) < 0)
799 drv
->route
= socket(PF_ROUTE
, SOCK_RAW
, 0);
800 if (drv
->route
< 0) {
801 perror("socket(PF_ROUTE,SOCK_RAW)");
804 eloop_register_read_sock(drv
->route
, bsd_wireless_event_receive
, drv
,
807 if (bsd_set_mediaopt(drv
, IFM_OMASK
, IFM_IEEE80211_HOSTAP
) < 0) {
808 wpa_printf(MSG_ERROR
, "%s: failed to set operation mode",
815 if (drv
->sock_xmit
!= NULL
)
816 l2_packet_deinit(drv
->sock_xmit
);
826 bsd_deinit(void *priv
)
828 struct bsd_driver_data
*drv
= priv
;
830 if (drv
->route
>= 0) {
831 eloop_unregister_read_sock(drv
->route
);
834 bsd_ctrl_iface(drv
, 0);
837 if (drv
->sock_xmit
!= NULL
)
838 l2_packet_deinit(drv
->sock_xmit
);
845 get80211param(struct bsd_driver_data
*drv
, int op
)
847 struct ieee80211req ireq
;
849 if (bsd_get80211(drv
, &ireq
, op
, NULL
, 0) < 0)
855 wpa_driver_bsd_get_bssid(void *priv
, u8
*bssid
)
857 struct bsd_driver_data
*drv
= priv
;
858 #ifdef SIOCG80211BSSID
859 struct ieee80211_bssid bs
;
861 os_strlcpy(bs
.i_name
, drv
->ifname
, sizeof(bs
.i_name
));
862 if (ioctl(drv
->sock
, SIOCG80211BSSID
, &bs
) < 0)
864 os_memcpy(bssid
, bs
.i_bssid
, sizeof(bs
.i_bssid
));
867 return get80211var(drv
, IEEE80211_IOC_BSSID
,
868 bssid
, IEEE80211_ADDR_LEN
) < 0 ? -1 : 0;
873 wpa_driver_bsd_get_ssid(void *priv
, u8
*ssid
)
875 struct bsd_driver_data
*drv
= priv
;
876 return bsd_get_ssid(drv
, ssid
, 0);
880 wpa_driver_bsd_set_wpa_ie(struct bsd_driver_data
*drv
, const u8
*wpa_ie
,
883 #ifdef IEEE80211_IOC_APPIE
884 return bsd_set_opt_ie(drv
, wpa_ie
, wpa_ie_len
);
885 #else /* IEEE80211_IOC_APPIE */
886 return set80211var(drv
, IEEE80211_IOC_OPTIE
, wpa_ie
, wpa_ie_len
);
887 #endif /* IEEE80211_IOC_APPIE */
891 wpa_driver_bsd_set_wpa_internal(void *priv
, int wpa
, int privacy
)
895 wpa_printf(MSG_DEBUG
, "%s: wpa=%d privacy=%d",
896 __FUNCTION__
, wpa
, privacy
);
898 if (!wpa
&& wpa_driver_bsd_set_wpa_ie(priv
, NULL
, 0) < 0)
900 if (set80211param(priv
, IEEE80211_IOC_PRIVACY
, privacy
) < 0)
902 if (set80211param(priv
, IEEE80211_IOC_WPA
, wpa
) < 0)
909 wpa_driver_bsd_set_wpa(void *priv
, int enabled
)
911 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __FUNCTION__
, enabled
);
913 return wpa_driver_bsd_set_wpa_internal(priv
, enabled
? 3 : 0, enabled
);
917 wpa_driver_bsd_set_countermeasures(void *priv
, int enabled
)
919 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __func__
, enabled
);
920 return set80211param(priv
, IEEE80211_IOC_COUNTERMEASURES
, enabled
);
925 wpa_driver_bsd_set_drop_unencrypted(void *priv
, int enabled
)
927 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __func__
, enabled
);
928 return set80211param(priv
, IEEE80211_IOC_DROPUNENCRYPTED
, enabled
);
932 wpa_driver_bsd_deauthenticate(void *priv
, const u8
*addr
, int reason_code
)
934 return bsd_send_mlme_param(priv
, IEEE80211_MLME_DEAUTH
, reason_code
,
939 wpa_driver_bsd_disassociate(void *priv
, const u8
*addr
, int reason_code
)
941 return bsd_send_mlme_param(priv
, IEEE80211_MLME_DISASSOC
, reason_code
,
946 wpa_driver_bsd_set_auth_alg(void *priv
, int auth_alg
)
950 if ((auth_alg
& WPA_AUTH_ALG_OPEN
) &&
951 (auth_alg
& WPA_AUTH_ALG_SHARED
))
952 authmode
= IEEE80211_AUTH_AUTO
;
953 else if (auth_alg
& WPA_AUTH_ALG_SHARED
)
954 authmode
= IEEE80211_AUTH_SHARED
;
956 authmode
= IEEE80211_AUTH_OPEN
;
958 return set80211param(priv
, IEEE80211_IOC_AUTHMODE
, authmode
);
962 handle_read(void *ctx
, const u8
*src_addr
, const u8
*buf
, size_t len
)
964 struct bsd_driver_data
*drv
= ctx
;
966 drv_event_eapol_rx(drv
->ctx
, src_addr
, buf
, len
);
970 wpa_driver_bsd_associate(void *priv
, struct wpa_driver_associate_params
*params
)
972 struct bsd_driver_data
*drv
= priv
;
973 struct ieee80211req_mlme mlme
;
979 wpa_printf(MSG_DEBUG
,
980 "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u"
982 , (unsigned int) params
->ssid_len
, params
->ssid
983 , (unsigned int) params
->wpa_ie_len
984 , params
->pairwise_suite
985 , params
->group_suite
986 , params
->key_mgmt_suite
989 switch (params
->mode
) {
990 case IEEE80211_MODE_INFRA
:
993 case IEEE80211_MODE_IBSS
:
994 mode
= IFM_IEEE80211_IBSS
;
996 case IEEE80211_MODE_AP
:
997 mode
= IFM_IEEE80211_HOSTAP
;
1000 wpa_printf(MSG_ERROR
, "%s: unknown operation mode", __func__
);
1003 if (bsd_set_mediaopt(drv
, IFM_OMASK
, mode
) < 0) {
1004 wpa_printf(MSG_ERROR
, "%s: failed to set operation mode",
1009 if (params
->mode
== IEEE80211_MODE_AP
) {
1010 if (params
->freq
>= 2412 && params
->freq
<= 2472)
1011 channel
= (params
->freq
- 2407) / 5;
1012 else if (params
->freq
== 2484)
1014 else if ((params
->freq
>= 5180 && params
->freq
<= 5240) ||
1015 (params
->freq
>= 5745 && params
->freq
<= 5825))
1016 channel
= (params
->freq
- 5000) / 5;
1019 if (bsd_set_freq(drv
, channel
) < 0)
1022 drv
->sock_xmit
= l2_packet_init(drv
->ifname
, NULL
, ETH_P_EAPOL
,
1023 handle_read
, drv
, 0);
1024 if (drv
->sock_xmit
== NULL
)
1030 if (wpa_driver_bsd_set_drop_unencrypted(drv
, params
->drop_unencrypted
)
1033 if (wpa_driver_bsd_set_auth_alg(drv
, params
->auth_alg
) < 0)
1035 /* XXX error handling is wrong but unclear what to do... */
1036 if (wpa_driver_bsd_set_wpa_ie(drv
, params
->wpa_ie
, params
->wpa_ie_len
) < 0)
1039 privacy
= !(params
->pairwise_suite
== CIPHER_NONE
&&
1040 params
->group_suite
== CIPHER_NONE
&&
1041 params
->key_mgmt_suite
== KEY_MGMT_NONE
&&
1042 params
->wpa_ie_len
== 0);
1043 wpa_printf(MSG_DEBUG
, "%s: set PRIVACY %u", __func__
, privacy
);
1045 if (set80211param(drv
, IEEE80211_IOC_PRIVACY
, privacy
) < 0)
1048 if (params
->wpa_ie_len
&&
1049 set80211param(drv
, IEEE80211_IOC_WPA
,
1050 params
->wpa_ie
[0] == WLAN_EID_RSN
? 2 : 1) < 0)
1053 os_memset(&mlme
, 0, sizeof(mlme
));
1054 mlme
.im_op
= IEEE80211_MLME_ASSOC
;
1055 if (params
->ssid
!= NULL
)
1056 os_memcpy(mlme
.im_ssid
, params
->ssid
, params
->ssid_len
);
1057 mlme
.im_ssid_len
= params
->ssid_len
;
1058 if (params
->bssid
!= NULL
)
1059 os_memcpy(mlme
.im_macaddr
, params
->bssid
, IEEE80211_ADDR_LEN
);
1060 if (set80211var(drv
, IEEE80211_IOC_MLME
, &mlme
, sizeof(mlme
)) < 0)
1066 wpa_driver_bsd_scan(void *priv
, struct wpa_driver_scan_params
*params
)
1068 struct bsd_driver_data
*drv
= priv
;
1069 #ifdef IEEE80211_IOC_SCAN_MAX_SSID
1070 struct ieee80211_scan_req sr
;
1072 #endif /* IEEE80211_IOC_SCAN_MAX_SSID */
1074 if (bsd_set_mediaopt(drv
, IFM_OMASK
, 0 /* STA */) < 0) {
1075 wpa_printf(MSG_ERROR
, "%s: failed to set operation mode",
1080 if (set80211param(drv
, IEEE80211_IOC_ROAMING
,
1081 IEEE80211_ROAMING_MANUAL
) < 0) {
1082 wpa_printf(MSG_ERROR
, "%s: failed to set "
1083 "wpa_supplicant-based roaming: %s", __func__
,
1088 if (wpa_driver_bsd_set_wpa(drv
, 1) < 0) {
1089 wpa_printf(MSG_ERROR
, "%s: failed to set wpa: %s", __func__
,
1094 /* NB: interface must be marked UP to do a scan */
1095 if (bsd_ctrl_iface(drv
, 1) < 0)
1098 #ifdef IEEE80211_IOC_SCAN_MAX_SSID
1099 os_memset(&sr
, 0, sizeof(sr
));
1100 sr
.sr_flags
= IEEE80211_IOC_SCAN_ACTIVE
| IEEE80211_IOC_SCAN_ONCE
|
1101 IEEE80211_IOC_SCAN_NOJOIN
;
1102 sr
.sr_duration
= IEEE80211_IOC_SCAN_FOREVER
;
1103 if (params
->num_ssids
> 0) {
1104 sr
.sr_nssid
= params
->num_ssids
;
1106 /* Boundary check is done by upper layer */
1107 if (sr
.sr_nssid
> IEEE80211_IOC_SCAN_MAX_SSID
)
1108 sr
.sr_nssid
= IEEE80211_IOC_SCAN_MAX_SSID
;
1111 /* NB: check scan cache first */
1112 sr
.sr_flags
|= IEEE80211_IOC_SCAN_CHECK
;
1114 for (i
= 0; i
< sr
.sr_nssid
; i
++) {
1115 sr
.sr_ssid
[i
].len
= params
->ssids
[i
].ssid_len
;
1116 os_memcpy(sr
.sr_ssid
[i
].ssid
, params
->ssids
[i
].ssid
,
1120 /* NB: net80211 delivers a scan complete event so no need to poll */
1121 return set80211var(drv
, IEEE80211_IOC_SCAN_REQ
, &sr
, sizeof(sr
));
1122 #else /* IEEE80211_IOC_SCAN_MAX_SSID */
1123 /* set desired ssid before scan */
1124 if (bsd_set_ssid(drv
, params
->ssids
[0].ssid
,
1125 params
->ssids
[0].ssid_len
) < 0)
1128 /* NB: net80211 delivers a scan complete event so no need to poll */
1129 return set80211param(drv
, IEEE80211_IOC_SCAN_REQ
, 0);
1130 #endif /* IEEE80211_IOC_SCAN_MAX_SSID */
1134 wpa_driver_bsd_event_receive(int sock
, void *ctx
, void *sock_ctx
)
1136 struct bsd_driver_data
*drv
= sock_ctx
;
1138 struct if_announcemsghdr
*ifan
;
1139 struct if_msghdr
*ifm
;
1140 struct rt_msghdr
*rtm
;
1141 union wpa_event_data event
;
1142 struct ieee80211_michael_event
*mic
;
1143 struct ieee80211_leave_event
*leave
;
1144 struct ieee80211_join_event
*join
;
1147 n
= read(sock
, buf
, sizeof(buf
));
1149 if (errno
!= EINTR
&& errno
!= EAGAIN
)
1150 perror("read(PF_ROUTE)");
1154 rtm
= (struct rt_msghdr
*) buf
;
1155 if (rtm
->rtm_version
!= RTM_VERSION
) {
1156 wpa_printf(MSG_DEBUG
, "Routing message version %d not "
1157 "understood\n", rtm
->rtm_version
);
1160 os_memset(&event
, 0, sizeof(event
));
1161 switch (rtm
->rtm_type
) {
1162 case RTM_IFANNOUNCE
:
1163 ifan
= (struct if_announcemsghdr
*) rtm
;
1164 if (ifan
->ifan_index
!= drv
->ifindex
)
1166 os_strlcpy(event
.interface_status
.ifname
, drv
->ifname
,
1167 sizeof(event
.interface_status
.ifname
));
1168 switch (ifan
->ifan_what
) {
1169 case IFAN_DEPARTURE
:
1170 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
1174 wpa_printf(MSG_DEBUG
, "RTM_IFANNOUNCE: Interface '%s' %s",
1175 event
.interface_status
.ifname
,
1176 ifan
->ifan_what
== IFAN_DEPARTURE
?
1177 "removed" : "added");
1178 wpa_supplicant_event(ctx
, EVENT_INTERFACE_STATUS
, &event
);
1181 ifan
= (struct if_announcemsghdr
*) rtm
;
1182 if (ifan
->ifan_index
!= drv
->ifindex
)
1184 switch (ifan
->ifan_what
) {
1185 case RTM_IEEE80211_ASSOC
:
1186 case RTM_IEEE80211_REASSOC
:
1189 wpa_supplicant_event(ctx
, EVENT_ASSOC
, NULL
);
1191 case RTM_IEEE80211_DISASSOC
:
1194 wpa_supplicant_event(ctx
, EVENT_DISASSOC
, NULL
);
1196 case RTM_IEEE80211_SCAN
:
1199 wpa_supplicant_event(ctx
, EVENT_SCAN_RESULTS
, NULL
);
1201 case RTM_IEEE80211_LEAVE
:
1202 leave
= (struct ieee80211_leave_event
*) &ifan
[1];
1203 drv_event_disassoc(ctx
, leave
->iev_addr
);
1205 case RTM_IEEE80211_JOIN
:
1206 #ifdef RTM_IEEE80211_REJOIN
1207 case RTM_IEEE80211_REJOIN
:
1209 join
= (struct ieee80211_join_event
*) &ifan
[1];
1210 bsd_new_sta(drv
, ctx
, join
->iev_addr
);
1212 case RTM_IEEE80211_REPLAY
:
1215 case RTM_IEEE80211_MICHAEL
:
1216 mic
= (struct ieee80211_michael_event
*) &ifan
[1];
1217 wpa_printf(MSG_DEBUG
,
1218 "Michael MIC failure wireless event: "
1219 "keyix=%u src_addr=" MACSTR
, mic
->iev_keyix
,
1220 MAC2STR(mic
->iev_src
));
1222 os_memset(&event
, 0, sizeof(event
));
1223 event
.michael_mic_failure
.unicast
=
1224 !IEEE80211_IS_MULTICAST(mic
->iev_dst
);
1225 wpa_supplicant_event(ctx
, EVENT_MICHAEL_MIC_FAILURE
,
1231 ifm
= (struct if_msghdr
*) rtm
;
1232 if (ifm
->ifm_index
!= drv
->ifindex
)
1234 if ((rtm
->rtm_flags
& RTF_UP
) == 0) {
1235 os_strlcpy(event
.interface_status
.ifname
, drv
->ifname
,
1236 sizeof(event
.interface_status
.ifname
));
1237 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
1238 wpa_printf(MSG_DEBUG
, "RTM_IFINFO: Interface '%s' DOWN",
1239 event
.interface_status
.ifname
);
1240 wpa_supplicant_event(ctx
, EVENT_INTERFACE_STATUS
, &event
);
1247 wpa_driver_bsd_add_scan_entry(struct wpa_scan_results
*res
,
1248 struct ieee80211req_scan_result
*sr
)
1250 struct wpa_scan_res
*result
, **tmp
;
1254 extra_len
= 2 + sr
->isr_ssid_len
;
1255 extra_len
+= 2 + sr
->isr_nrates
;
1256 extra_len
+= 3; /* ERP IE */
1257 extra_len
+= sr
->isr_ie_len
;
1259 result
= os_zalloc(sizeof(*result
) + extra_len
);
1262 os_memcpy(result
->bssid
, sr
->isr_bssid
, ETH_ALEN
);
1263 result
->freq
= sr
->isr_freq
;
1264 result
->beacon_int
= sr
->isr_intval
;
1265 result
->caps
= sr
->isr_capinfo
;
1266 result
->qual
= sr
->isr_rssi
;
1267 result
->noise
= sr
->isr_noise
;
1269 pos
= (u8
*)(result
+ 1);
1271 *pos
++ = WLAN_EID_SSID
;
1272 *pos
++ = sr
->isr_ssid_len
;
1273 os_memcpy(pos
, sr
+ 1, sr
->isr_ssid_len
);
1274 pos
+= sr
->isr_ssid_len
;
1277 * Deal all rates as supported rate.
1278 * Because net80211 doesn't report extended supported rate or not.
1280 *pos
++ = WLAN_EID_SUPP_RATES
;
1281 *pos
++ = sr
->isr_nrates
;
1282 os_memcpy(pos
, sr
->isr_rates
, sr
->isr_nrates
);
1283 pos
+= sr
->isr_nrates
;
1285 *pos
++ = WLAN_EID_ERP_INFO
;
1287 *pos
++ = sr
->isr_erp
;
1289 os_memcpy(pos
, (u8
*)(sr
+ 1) + sr
->isr_ssid_len
, sr
->isr_ie_len
);
1290 pos
+= sr
->isr_ie_len
;
1292 result
->ie_len
= pos
- (u8
*)(result
+ 1);
1294 tmp
= os_realloc(res
->res
,
1295 (res
->num
+ 1) * sizeof(struct wpa_scan_res
*));
1300 tmp
[res
->num
++] = result
;
1304 struct wpa_scan_results
*
1305 wpa_driver_bsd_get_scan_results2(void *priv
)
1307 struct ieee80211req_scan_result
*sr
;
1308 struct wpa_scan_results
*res
;
1310 uint8_t buf
[24*1024], *pos
;
1312 len
= get80211var(priv
, IEEE80211_IOC_SCAN_RESULTS
, buf
, 24*1024);
1316 res
= os_zalloc(sizeof(*res
));
1322 while (rest
>= sizeof(struct ieee80211req_scan_result
)) {
1323 sr
= (struct ieee80211req_scan_result
*)pos
;
1324 wpa_driver_bsd_add_scan_entry(res
, sr
);
1326 rest
-= sr
->isr_len
;
1329 wpa_printf(MSG_DEBUG
, "Received %d bytes of scan results (%lu BSSes)",
1330 len
, (unsigned long)res
->num
);
1335 static int wpa_driver_bsd_capa(struct bsd_driver_data
*drv
)
1337 #ifdef IEEE80211_IOC_DEVCAPS
1338 /* kernel definitions copied from net80211/ieee80211_var.h */
1339 #define IEEE80211_CIPHER_WEP 0
1340 #define IEEE80211_CIPHER_TKIP 1
1341 #define IEEE80211_CIPHER_AES_CCM 3
1342 #define IEEE80211_CRYPTO_WEP (1<<IEEE80211_CIPHER_WEP)
1343 #define IEEE80211_CRYPTO_TKIP (1<<IEEE80211_CIPHER_TKIP)
1344 #define IEEE80211_CRYPTO_AES_CCM (1<<IEEE80211_CIPHER_AES_CCM)
1345 #define IEEE80211_C_HOSTAP 0x00000400 /* CAPABILITY: HOSTAP avail */
1346 #define IEEE80211_C_WPA1 0x00800000 /* CAPABILITY: WPA1 avail */
1347 #define IEEE80211_C_WPA2 0x01000000 /* CAPABILITY: WPA2 avail */
1348 struct ieee80211_devcaps_req devcaps
;
1350 if (get80211var(drv
, IEEE80211_IOC_DEVCAPS
, &devcaps
,
1351 sizeof(devcaps
)) < 0) {
1352 wpa_printf(MSG_ERROR
, "failed to IEEE80211_IOC_DEVCAPS: %s",
1357 wpa_printf(MSG_DEBUG
, "%s: drivercaps=0x%08x,cryptocaps=0x%08x",
1358 __func__
, devcaps
.dc_drivercaps
, devcaps
.dc_cryptocaps
);
1360 if (devcaps
.dc_drivercaps
& IEEE80211_C_WPA1
)
1361 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1362 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
;
1363 if (devcaps
.dc_drivercaps
& IEEE80211_C_WPA2
)
1364 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
1365 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
1367 if (devcaps
.dc_cryptocaps
& IEEE80211_CRYPTO_WEP
)
1368 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_WEP40
|
1369 WPA_DRIVER_CAPA_ENC_WEP104
;
1370 if (devcaps
.dc_cryptocaps
& IEEE80211_CRYPTO_TKIP
)
1371 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_TKIP
;
1372 if (devcaps
.dc_cryptocaps
& IEEE80211_CRYPTO_AES_CCM
)
1373 drv
->capa
.enc
|= WPA_DRIVER_CAPA_ENC_CCMP
;
1375 if (devcaps
.dc_drivercaps
& IEEE80211_C_HOSTAP
)
1376 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP
;
1377 #undef IEEE80211_CIPHER_WEP
1378 #undef IEEE80211_CIPHER_TKIP
1379 #undef IEEE80211_CIPHER_AES_CCM
1380 #undef IEEE80211_CRYPTO_WEP
1381 #undef IEEE80211_CRYPTO_TKIP
1382 #undef IEEE80211_CRYPTO_AES_CCM
1383 #undef IEEE80211_C_HOSTAP
1384 #undef IEEE80211_C_WPA1
1385 #undef IEEE80211_C_WPA2
1386 #else /* IEEE80211_IOC_DEVCAPS */
1387 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
1388 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1389 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
1390 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
1391 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
1392 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
1393 WPA_DRIVER_CAPA_ENC_WEP104
|
1394 WPA_DRIVER_CAPA_ENC_TKIP
|
1395 WPA_DRIVER_CAPA_ENC_CCMP
;
1396 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP
;
1397 #endif /* IEEE80211_IOC_DEVCAPS */
1398 #ifdef IEEE80211_IOC_SCAN_MAX_SSID
1399 drv
->capa
.max_scan_ssids
= IEEE80211_IOC_SCAN_MAX_SSID
;
1400 #else /* IEEE80211_IOC_SCAN_MAX_SSID */
1401 drv
->capa
.max_scan_ssids
= 1;
1402 #endif /* IEEE80211_IOC_SCAN_MAX_SSID */
1403 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
1404 WPA_DRIVER_AUTH_SHARED
|
1405 WPA_DRIVER_AUTH_LEAP
;
1410 wpa_driver_bsd_init(void *ctx
, const char *ifname
)
1412 #define GETPARAM(drv, param, v) \
1413 (((v) = get80211param(drv, param)) != -1)
1414 struct bsd_driver_data
*drv
;
1416 drv
= os_zalloc(sizeof(*drv
));
1420 * NB: We require the interface name be mappable to an index.
1421 * This implies we do not support having wpa_supplicant
1422 * wait for an interface to appear. This seems ok; that
1423 * doesn't belong here; it's really the job of devd.
1425 drv
->ifindex
= if_nametoindex(ifname
);
1426 if (drv
->ifindex
== 0) {
1427 wpa_printf(MSG_DEBUG
, "%s: interface %s does not exist",
1431 drv
->sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
1434 drv
->route
= socket(PF_ROUTE
, SOCK_RAW
, 0);
1437 eloop_register_read_sock(drv
->route
,
1438 wpa_driver_bsd_event_receive
, ctx
, drv
);
1441 os_strlcpy(drv
->ifname
, ifname
, sizeof(drv
->ifname
));
1443 /* Down interface during setup. */
1444 if (bsd_ctrl_iface(drv
, 0) < 0)
1447 if (!GETPARAM(drv
, IEEE80211_IOC_ROAMING
, drv
->prev_roaming
)) {
1448 wpa_printf(MSG_DEBUG
, "%s: failed to get roaming state: %s",
1449 __func__
, strerror(errno
));
1452 if (!GETPARAM(drv
, IEEE80211_IOC_PRIVACY
, drv
->prev_privacy
)) {
1453 wpa_printf(MSG_DEBUG
, "%s: failed to get privacy state: %s",
1454 __func__
, strerror(errno
));
1457 if (!GETPARAM(drv
, IEEE80211_IOC_WPA
, drv
->prev_wpa
)) {
1458 wpa_printf(MSG_DEBUG
, "%s: failed to get wpa state: %s",
1459 __func__
, strerror(errno
));
1463 if (wpa_driver_bsd_capa(drv
))
1476 wpa_driver_bsd_deinit(void *priv
)
1478 struct bsd_driver_data
*drv
= priv
;
1480 wpa_driver_bsd_set_wpa(drv
, 0);
1481 eloop_unregister_read_sock(drv
->route
);
1483 /* NB: mark interface down */
1484 bsd_ctrl_iface(drv
, 0);
1486 wpa_driver_bsd_set_wpa_internal(drv
, drv
->prev_wpa
, drv
->prev_privacy
);
1487 if (set80211param(drv
, IEEE80211_IOC_ROAMING
, drv
->prev_roaming
) < 0)
1488 wpa_printf(MSG_DEBUG
, "%s: failed to restore roaming state",
1491 if (drv
->sock_xmit
!= NULL
)
1492 l2_packet_deinit(drv
->sock_xmit
);
1493 (void) close(drv
->route
); /* ioctl socket */
1494 (void) close(drv
->sock
); /* event socket */
1499 wpa_driver_bsd_get_capa(void *priv
, struct wpa_driver_capa
*capa
)
1501 struct bsd_driver_data
*drv
= priv
;
1503 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
1506 #endif /* HOSTAPD */
1509 const struct wpa_driver_ops wpa_driver_bsd_ops
= {
1511 .desc
= "BSD 802.11 support",
1513 .hapd_init
= bsd_init
,
1514 .hapd_deinit
= bsd_deinit
,
1515 .set_privacy
= bsd_set_privacy
,
1516 .get_seqnum
= bsd_get_seqnum
,
1518 .read_sta_data
= bsd_read_sta_driver_data
,
1519 .sta_disassoc
= bsd_sta_disassoc
,
1520 .sta_deauth
= bsd_sta_deauth
,
1521 .set_freq
= hostapd_bsd_set_freq
,
1523 .init
= wpa_driver_bsd_init
,
1524 .deinit
= wpa_driver_bsd_deinit
,
1525 .get_bssid
= wpa_driver_bsd_get_bssid
,
1526 .get_ssid
= wpa_driver_bsd_get_ssid
,
1527 .set_countermeasures
= wpa_driver_bsd_set_countermeasures
,
1528 .scan2
= wpa_driver_bsd_scan
,
1529 .get_scan_results2
= wpa_driver_bsd_get_scan_results2
,
1530 .deauthenticate
= wpa_driver_bsd_deauthenticate
,
1531 .disassociate
= wpa_driver_bsd_disassociate
,
1532 .associate
= wpa_driver_bsd_associate
,
1533 .get_capa
= wpa_driver_bsd_get_capa
,
1534 #endif /* HOSTAPD */
1535 .set_key
= bsd_set_key
,
1536 .set_ieee8021x
= bsd_set_ieee8021x
,
1537 .hapd_set_ssid
= bsd_set_ssid
,
1538 .hapd_get_ssid
= bsd_get_ssid
,
1539 .hapd_send_eapol
= bsd_send_eapol
,
1540 .sta_set_flags
= bsd_set_sta_authorized
,
1541 .set_generic_elem
= bsd_set_opt_ie
,