18d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt/* 28d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * WPA Supplicant - driver interaction with BSD net80211 layer 38d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Copyright (c) 2004, Sam Leffler <sam@errno.com> 48d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Copyright (c) 2004, 2Wire, Inc 58d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * 604949598a23f501be6eec21697465fd46a28840aDmitry Shmidt * This software may be distributed under the terms of the BSD license. 704949598a23f501be6eec21697465fd46a28840aDmitry Shmidt * See README for more details. 88d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 98d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "includes.h" 118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <sys/ioctl.h> 128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <sys/sysctl.h> 138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "common.h" 158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "driver.h" 168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "eloop.h" 178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "common/ieee802_11_defs.h" 188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "common/wpa_common.h" 198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net/if.h> 218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net/if_media.h> 228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef __NetBSD__ 248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net/if_ether.h> 258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else 268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net/ethernet.h> 278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net/route.h> 298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef __DragonFly__ 318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <netproto/802_11/ieee80211_ioctl.h> 328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <netproto/802_11/ieee80211_dragonfly.h> 338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* __DragonFly__ */ 348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef __GLIBC__ 358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <netinet/ether.h> 368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* __GLIBC__ */ 378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net80211/ieee80211.h> 388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net80211/ieee80211_ioctl.h> 398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net80211/ieee80211_crypto.h> 408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* __DragonFly__ || __GLIBC__ */ 418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net80211/ieee80211_freebsd.h> 438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#if __NetBSD__ 458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include <net80211/ieee80211_netbsd.h> 468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "l2_packet/l2_packet.h" 498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstruct bsd_driver_data { 518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct hostapd_data *hapd; /* back pointer */ 528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int sock; /* open socket for 802.11 ioctls */ 548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct l2_packet_data *sock_xmit;/* raw packet xmit socket */ 558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int route; /* routing socket for events */ 568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt char ifname[IFNAMSIZ+1]; /* interface name */ 578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt unsigned int ifindex; /* interface index */ 588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt void *ctx; 598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpa_driver_capa capa; /* driver capability */ 608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int is_ap; /* Access point mode */ 618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int prev_roaming; /* roaming state to restore on deinit */ 628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int prev_privacy; /* privacy state to restore on deinit */ 638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int prev_wpa; /* wpa state to restore on deinit */ 645393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt enum ieee80211_opmode opmode; /* operation mode */ 658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt}; 668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt/* Generic functions for hostapd and wpa_supplicant */ 688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 695393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidtstatic enum ieee80211_opmode 705393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidtget80211opmode(struct bsd_driver_data *drv) 715393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt{ 725393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt struct ifmediareq ifmr; 735393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt 745393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt (void) memset(&ifmr, 0, sizeof(ifmr)); 755393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt (void) strncpy(ifmr.ifm_name, drv->ifname, sizeof(ifmr.ifm_name)); 765393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt 775393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (ioctl(drv->sock, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) { 785393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) { 795393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (ifmr.ifm_current & IFM_FLAG0) 805393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return IEEE80211_M_AHDEMO; 815393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt else 825393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return IEEE80211_M_IBSS; 835393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt } 845393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP) 855393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return IEEE80211_M_HOSTAP; 865393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (ifmr.ifm_current & IFM_IEEE80211_MONITOR) 875393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return IEEE80211_M_MONITOR; 885393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (ifmr.ifm_current & IFM_IEEE80211_MBSS) 895393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return IEEE80211_M_MBSS; 905393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt } 915393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return IEEE80211_M_STA; 925393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt} 935393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt 945393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt 958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set80211(void *priv, int op, int val, const void *arg, int arg_len) 978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req ireq; 1008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&ireq, 0, sizeof(ireq)); 1028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(ireq.i_name, drv->ifname, sizeof(ireq.i_name)); 1038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ireq.i_type = op; 1048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ireq.i_val = val; 1058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ireq.i_data = (void *) arg; 1068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ireq.i_len = arg_len; 1078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) { 1098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, val=%u, " 1108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "arg_len=%u]: %s", op, val, arg_len, 1118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt strerror(errno)); 1128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 1138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 1148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 1158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 1188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_get80211(void *priv, struct ieee80211req *ireq, int op, void *arg, 1198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int arg_len) 1208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 1228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(ireq, 0, sizeof(*ireq)); 1248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(ireq->i_name, drv->ifname, sizeof(ireq->i_name)); 1258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ireq->i_type = op; 1268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ireq->i_len = arg_len; 1278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ireq->i_data = arg; 1288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ioctl(drv->sock, SIOCG80211, ireq) < 0) { 1308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, " 1318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "arg_len=%u]: %s", op, arg_len, strerror(errno)); 1328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 1338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 1348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 1358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 1388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtget80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len) 1398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req ireq; 1418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_get80211(drv, &ireq, op, arg, arg_len) < 0) 1438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 1448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return ireq.i_len; 1458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 1488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtset80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len) 1498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_set80211(drv, op, 0, arg, arg_len); 1518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 1548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtset80211param(struct bsd_driver_data *drv, int op, int arg) 1558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_set80211(drv, op, arg, NULL, 0); 1578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 1608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_get_ssid(void *priv, u8 *ssid, int len) 1618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 1638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef SIOCG80211NWID 1648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_nwid nwid; 1658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ifreq ifr; 1668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&ifr, 0, sizeof(ifr)); 1688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); 1698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifr.ifr_data = (void *)&nwid; 1708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ioctl(drv->sock, SIOCG80211NWID, &ifr) < 0 || 1718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt nwid.i_len > IEEE80211_NWID_LEN) 1728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 1738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(ssid, nwid.i_nwid, nwid.i_len); 1748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return nwid.i_len; 1758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else 1768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return get80211var(drv, IEEE80211_IOC_SSID, ssid, IEEE80211_NWID_LEN); 1778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 1788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 1818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_ssid(void *priv, const u8 *ssid, int ssid_len) 1828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 1838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 1848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef SIOCS80211NWID 1858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_nwid nwid; 1868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ifreq ifr; 1878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(nwid.i_nwid, ssid, ssid_len); 1898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt nwid.i_len = ssid_len; 1908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&ifr, 0, sizeof(ifr)); 1918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); 1928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifr.ifr_data = (void *)&nwid; 1938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return ioctl(drv->sock, SIOCS80211NWID, &ifr); 1948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else 1958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211var(drv, IEEE80211_IOC_SSID, ssid, ssid_len); 1968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 1978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 1988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 1998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 2008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_get_if_media(void *priv) 2018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 2028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 2038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ifmediareq ifmr; 2048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&ifmr, 0, sizeof(ifmr)); 2068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(ifmr.ifm_name, drv->ifname, sizeof(ifmr.ifm_name)); 2078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ioctl(drv->sock, SIOCGIFMEDIA, &ifmr) < 0) { 2098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: SIOCGIFMEDIA %s", __func__, 2108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt strerror(errno)); 2118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 2128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return ifmr.ifm_current; 2158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 2168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 2188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_if_media(void *priv, int media) 2198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 2208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 2218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ifreq ifr; 2228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&ifr, 0, sizeof(ifr)); 2248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); 2258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifr.ifr_media = media; 2268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ioctl(drv->sock, SIOCSIFMEDIA, &ifr) < 0) { 2288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: SIOCSIFMEDIA %s", __func__, 2298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt strerror(errno)); 2308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 2318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 2348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 2358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 2378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_mediaopt(void *priv, uint32_t mask, uint32_t mode) 2388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 2398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int media = bsd_get_if_media(priv); 2408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (media < 0) 2428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 2438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt media &= ~mask; 2448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt media |= mode; 2458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_set_if_media(priv, media) < 0) 2468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 2478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 2488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 2498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 2518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_del_key(void *priv, const u8 *addr, int key_idx) 2528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 2538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_del_key wk; 2548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&wk, 0, sizeof(wk)); 2568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (addr == NULL) { 2578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: key_idx=%d", __func__, key_idx); 2588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.idk_keyix = key_idx; 2598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 2608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__, 2618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt MAC2STR(addr)); 2628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN); 2638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */ 2648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211var(priv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk)); 2678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 2688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 2708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_send_mlme_param(void *priv, const u8 op, const u16 reason, const u8 *addr) 2718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 2728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_mlme mlme; 2738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&mlme, 0, sizeof(mlme)); 2758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mlme.im_op = op; 2768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mlme.im_reason = reason; 2778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN); 2788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)); 2798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 2808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 2828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_ctrl_iface(void *priv, int enable) 2838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 2848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 2858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ifreq ifr; 2868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&ifr, 0, sizeof(ifr)); 2888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name)); 2898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ioctl(drv->sock, SIOCGIFFLAGS, &ifr) < 0) { 2918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt perror("ioctl[SIOCGIFFLAGS]"); 2928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 2938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 2948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 2955393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (enable) { 2965393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (ifr.ifr_flags & IFF_UP) 2975393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return 0; 2988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifr.ifr_flags |= IFF_UP; 2995393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt } else { 3005393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (!(ifr.ifr_flags & IFF_UP)) 3015393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return 0; 3028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifr.ifr_flags &= ~IFF_UP; 3035393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt } 3048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ioctl(drv->sock, SIOCSIFFLAGS, &ifr) < 0) { 3068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt perror("ioctl[SIOCSIFFLAGS]"); 3078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 3088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 3098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 3118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 3128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3135393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt#ifdef HOSTAPD 3145393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidtstatic int 3155393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidtbsd_commit(void *priv) 3165393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt{ 3175393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt return bsd_ctrl_iface(priv, 1); 3185393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt} 3195393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt#endif /* HOSTAPD */ 3205393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt 3218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 3228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_key(const char *ifname, void *priv, enum wpa_alg alg, 3238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const unsigned char *addr, int key_idx, int set_tx, const u8 *seq, 3248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t seq_len, const u8 *key, size_t key_len) 3258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 3268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_key wk; 3275393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt struct bsd_driver_data *drv = priv; 3288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%p key_idx=%d set_tx=%d " 3308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "seq_len=%zu key_len=%zu", __func__, alg, addr, key_idx, 3318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt set_tx, seq_len, key_len); 3328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (alg == WPA_ALG_NONE) { 3348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifndef HOSTAPD 3358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (addr == NULL || is_broadcast_ether_addr(addr)) 3368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_del_key(priv, NULL, key_idx); 3378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt else 3388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* HOSTAPD */ 3398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_del_key(priv, addr, key_idx); 3408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 3418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&wk, 0, sizeof(wk)); 3438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (alg) { 3448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case WPA_ALG_WEP: 3458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_type = IEEE80211_CIPHER_WEP; 3468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 3478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case WPA_ALG_TKIP: 3488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_type = IEEE80211_CIPHER_TKIP; 3498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 3508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case WPA_ALG_CCMP: 3518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_type = IEEE80211_CIPHER_AES_CCM; 3528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 3538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 3548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: unknown alg=%d", __func__, alg); 3558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 3568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 3578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_flags = IEEE80211_KEY_RECV; 3598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set_tx) 3608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_flags |= IEEE80211_KEY_XMIT; 3618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 3628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (addr == NULL) { 3638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); 3648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_keyix = key_idx; 3658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 3668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); 3678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 3688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Deduce whether group/global or unicast key by checking 3698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * the address (yech). Note also that we can only mark global 3708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * keys default; doing this for a unicast key is an error. 3718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 3728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (is_broadcast_ether_addr(addr)) { 3738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_flags |= IEEE80211_KEY_GROUP; 3748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_keyix = key_idx; 3758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 3768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE : 3778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt key_idx; 3788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 3798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 3808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx) 3818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_flags |= IEEE80211_KEY_DEFAULT; 3825393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt#ifndef HOSTAPD 3835393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt /* 3845393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt * Ignore replay failures in IBSS and AHDEMO mode. 3855393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt */ 3865393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (drv->opmode == IEEE80211_M_IBSS || 3875393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt drv->opmode == IEEE80211_M_AHDEMO) 3885393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt wk.ik_flags |= IEEE80211_KEY_NOREPLAY; 3895393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt#endif /* HOSTAPD */ 3908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_keylen = key_len; 39175ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen if (seq) { 39275ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen#ifdef WORDS_BIGENDIAN 39375ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen /* 39475ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen * wk.ik_keyrsc is in host byte order (big endian), need to 39575ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen * swap it to match with the byte order used in WPA. 39675ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen */ 39775ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen int i; 39875ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen u8 *keyrsc = (u8 *) &wk.ik_keyrsc; 39975ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen for (i = 0; i < seq_len; i++) 40075ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen keyrsc[WPA_KEY_RSC_LEN - i - 1] = seq[i]; 40175ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen#else /* WORDS_BIGENDIAN */ 4028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(&wk.ik_keyrsc, seq, seq_len); 40375ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen#endif /* WORDS_BIGENDIAN */ 40475ecf5267604f166b85a7ee2cf0d9cb682966680Jouni Malinen } 4058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(wk.ik_keydata, key, key_len); 4068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)); 4088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 4098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 4118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_configure_wpa(void *priv, struct wpa_bss_params *params) 4128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 4138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifndef IEEE80211_IOC_APPIE 4148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt static const char *ciphernames[] = 4158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt { "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" }; 4168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int v; 4178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (params->wpa_group) { 4198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case WPA_CIPHER_CCMP: 4208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v = IEEE80211_CIPHER_AES_CCM; 4218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 4228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case WPA_CIPHER_TKIP: 4238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v = IEEE80211_CIPHER_TKIP; 4248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 4258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case WPA_CIPHER_WEP104: 4268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v = IEEE80211_CIPHER_WEP; 4278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 4288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case WPA_CIPHER_WEP40: 4298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v = IEEE80211_CIPHER_WEP; 4308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 4318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case WPA_CIPHER_NONE: 4328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v = IEEE80211_CIPHER_NONE; 4338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 4348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 4358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Unknown group key cipher %u\n", 4368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt params->wpa_group); 4378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 4388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: group key cipher=%s (%u)", 4408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, ciphernames[v], v); 4418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_MCASTCIPHER, v)) { 4428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Unable to set group key cipher to %u (%s)\n", 4438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v, ciphernames[v]); 4448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 4458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (v == IEEE80211_CIPHER_WEP) { 4478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* key length is done only for specific ciphers */ 4488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v = (params->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5); 4498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_MCASTKEYLEN, v)) { 4508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Unable to set group key length to %u\n", v); 4518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 4528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v = 0; 4568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->wpa_pairwise & WPA_CIPHER_CCMP) 4578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v |= 1<<IEEE80211_CIPHER_AES_CCM; 4588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->wpa_pairwise & WPA_CIPHER_TKIP) 4598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v |= 1<<IEEE80211_CIPHER_TKIP; 4608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->wpa_pairwise & WPA_CIPHER_NONE) 4618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v |= 1<<IEEE80211_CIPHER_NONE; 4628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v); 4638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_UCASTCIPHERS, v)) { 4648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Unable to set pairwise key ciphers to 0x%x\n", v); 4658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 4668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x", 4698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, params->wpa_key_mgmt); 4708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_KEYMGTALGS, 4718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt params->wpa_key_mgmt)) { 4728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Unable to set key management algorithms to 0x%x\n", 4738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt params->wpa_key_mgmt); 4748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 4758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v = 0; 4788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->rsn_preauth) 4798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt v |= BIT(0); 4808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x", 4818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, params->rsn_preauth); 4828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_RSNCAPS, v)) { 4838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Unable to set RSN capabilities to 0x%x\n", v); 4848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 4858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* IEEE80211_IOC_APPIE */ 4878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: enable WPA= 0x%x", __func__, params->wpa); 4898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_WPA, params->wpa)) { 4908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Unable to set WPA to %u\n", params->wpa); 4918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 4928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 4938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 4948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 4958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 4968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 4978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_ieee8021x(void *priv, struct wpa_bss_params *params) 4988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 4998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled); 5008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!params->enabled) { 5028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* XXX restore state */ 5038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211param(priv, IEEE80211_IOC_AUTHMODE, 5048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt IEEE80211_AUTH_AUTO); 5058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 5068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!params->wpa && !params->ieee802_1x) { 5078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: No 802.1X or WPA enabled", 5088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__); 5098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 5108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 5118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->wpa && bsd_configure_wpa(priv, params) != 0) { 5128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: Failed to configure WPA state", 5138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__); 5148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 5158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 5168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_AUTHMODE, 5178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) { 5188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: Failed to enable WPA/802.1X", 5198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__); 5208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 5218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 5228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_ctrl_iface(priv, 1); 5238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5255393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt#ifdef HOSTAPD 5268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 5278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_sta_authorized(void *priv, const u8 *addr, 5288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int total_flags, int flags_or, int flags_and) 5298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 5308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int authorized = -1; 5318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* For now, only support setting Authorized flag */ 5338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (flags_or & WPA_STA_AUTHORIZED) 5348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt authorized = 1; 5358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!(flags_and & WPA_STA_AUTHORIZED)) 5368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt authorized = 0; 5378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (authorized < 0) 5398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 5408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_send_mlme_param(priv, authorized ? 5428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt IEEE80211_MLME_AUTHORIZE : 5438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt IEEE80211_MLME_UNAUTHORIZE, 0, addr); 5448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5455393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt#endif /* HOSTAPD */ 5468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void 5488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_new_sta(void *priv, void *ctx, u8 addr[IEEE80211_ADDR_LEN]) 5498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 5508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_wpaie ie; 5518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int ielen = 0; 5528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *iebuf = NULL; 5538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 5558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Fetch and validate any negotiated WPA/RSN parameters. 5568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 5578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memset(&ie, 0, sizeof(ie)); 5588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN); 5598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (get80211var(priv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) { 5608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Failed to get WPA/RSN information element.\n"); 5618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto no_ie; 5628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 5638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt iebuf = ie.wpa_ie; 5648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ielen = ie.wpa_ie[1]; 5658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ielen == 0) 5668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt iebuf = NULL; 5678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt else 5688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ielen += 2; 5698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtno_ie: 5718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv_event_assoc(ctx, addr, iebuf, ielen, 0); 5728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 5758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len, 5768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int encrypt, const u8 *own_addr, u32 flags) 5778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 5788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 5798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", data, data_len); 5818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, data, 5838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data_len); 5848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 5858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 5878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_freq(void *priv, struct hostapd_freq_params *freq) 5888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 5898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 5908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef SIOCS80211CHANNEL 5918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211chanreq creq; 5928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* SIOCS80211CHANNEL */ 5938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u32 mode; 5948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int channel = freq->channel; 5958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 5968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (channel < 14) { 5978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mode = 5988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef CONFIG_IEEE80211N 5998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt freq->ht_enabled ? IFM_IEEE80211_11NG : 6008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* CONFIG_IEEE80211N */ 6018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt IFM_IEEE80211_11G; 6028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else if (channel == 14) { 6038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mode = IFM_IEEE80211_11B; 6048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } else { 6058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mode = 6068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef CONFIG_IEEE80211N 6078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt freq->ht_enabled ? IFM_IEEE80211_11NA : 6088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* CONFIG_IEEE80211N */ 6098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt IFM_IEEE80211_11A; 6108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 6118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_set_mediaopt(drv, IFM_MMASK, mode) < 0) { 6128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: failed to set modulation mode", 6138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__); 6148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 6158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 6168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef SIOCS80211CHANNEL 6188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&creq, 0, sizeof(creq)); 6198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(creq.i_name, drv->ifname, sizeof(creq.i_name)); 6208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt creq.i_channel = (u_int16_t)channel; 6218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return ioctl(drv->sock, SIOCS80211CHANNEL, &creq); 6228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* SIOCS80211CHANNEL */ 6238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211param(priv, IEEE80211_IOC_CHANNEL, channel); 6248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* SIOCS80211CHANNEL */ 6258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 6268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 6288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len) 6298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 6308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef IEEE80211_IOC_APPIE 6318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__, 6328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (unsigned long)ie_len); 6338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA, 6348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ie, ie_len); 6358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* IEEE80211_IOC_APPIE */ 6368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 6378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 6388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 6408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtrtbuf_len(void) 6418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 6428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t len; 6438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int mib[6] = {CTL_NET, AF_ROUTE, 0, AF_INET, NET_RT_DUMP, 0}; 6458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { 6478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_WARNING, "%s failed: %s\n", __func__, 6488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt strerror(errno)); 6498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt len = 2048; 6508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 6518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return len; 6538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 6548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef HOSTAPD 6568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt/* 6588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Avoid conflicts with hostapd definitions by undefining couple of defines 6598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * from net80211 header files. 6608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 6618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef RSN_VERSION 6628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef WPA_VERSION 6638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef WPA_OUI_TYPE 6648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, 6668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int reason_code); 6678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic const char * 6698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtether_sprintf(const u8 *addr) 6708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 6718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt static char buf[sizeof(MACSTR)]; 6728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (addr != NULL) 6748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr)); 6758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt else 6768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0); 6778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return buf; 6788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 6798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 6818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_set_privacy(void *priv, int enabled) 6828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 6838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); 6848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211param(priv, IEEE80211_IOC_PRIVACY, enabled); 6868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 6878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 6898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx, 6908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *seq) 6918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 6928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_key wk; 6938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d", 6958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, ether_sprintf(addr), idx); 6968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 6978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memset(&wk, 0, sizeof(wk)); 6988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (addr == NULL) 6998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); 7008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt else 7018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); 7028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wk.ik_keyix = idx; 7038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (get80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) { 7058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Failed to get encryption.\n"); 7068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 7078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef WORDS_BIGENDIAN 7108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt { 7118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 7128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * wk.ik_keytsc is in host byte order (big endian), need to 7138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * swap it to match with the byte order used in WPA. 7148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 7158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int i; 7168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 tmp[WPA_KEY_RSC_LEN]; 7178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc)); 7188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt for (i = 0; i < WPA_KEY_RSC_LEN; i++) { 7198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1]; 7208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* WORDS_BIGENDIAN */ 7238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc)); 7248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* WORDS_BIGENDIAN */ 7258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 7268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 7278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 7308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_flush(void *priv) 7318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 7328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 allsta[IEEE80211_ADDR_LEN]; 7338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memset(allsta, 0xff, IEEE80211_ADDR_LEN); 7358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_sta_deauth(priv, NULL, allsta, IEEE80211_REASON_AUTH_LEAVE); 7368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 7378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 7408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data, 7418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt const u8 *addr) 7428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 7438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_sta_stats stats; 7448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN); 7468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (get80211var(priv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) 7478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt > 0) { 7488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* XXX? do packets counts include non-data frames? */ 7498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->rx_packets = stats.is_stats.ns_rx_data; 7508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->rx_bytes = stats.is_stats.ns_rx_bytes; 7518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->tx_packets = stats.is_stats.ns_tx_data; 7528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data->tx_bytes = stats.is_stats.ns_tx_bytes; 7538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 7558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 7568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 7588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code) 7598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 7608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code, 7618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt addr); 7628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 7638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 7658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, 7668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int reason_code) 7678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 7688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_send_mlme_param(priv, IEEE80211_MLME_DISASSOC, reason_code, 7698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt addr); 7708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 7718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void 7738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx) 7748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 7758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = ctx; 7768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt char *buf; 7778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct if_announcemsghdr *ifan; 7788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct rt_msghdr *rtm; 7798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_michael_event *mic; 7808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_join_event *join; 7818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_leave_event *leave; 7828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int n, len; 7838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt union wpa_event_data data; 7848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt len = rtbuf_len(); 7868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt buf = os_malloc(len); 7888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (buf == NULL) { 7898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s os_malloc() failed\n", __func__); 7908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 7918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 7928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 7938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt n = read(sock, buf, len); 7948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (n < 0) { 7958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (errno != EINTR && errno != EAGAIN) 7968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s read() failed: %s\n", 7978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, strerror(errno)); 7988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 7998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 8008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt rtm = (struct rt_msghdr *) buf; 8038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (rtm->rtm_version != RTM_VERSION) { 8048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "Invalid routing message version=%d", 8058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt rtm->rtm_version); 8068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 8078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 8088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifan = (struct if_announcemsghdr *) rtm; 8108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (rtm->rtm_type) { 8118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211: 8128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (ifan->ifan_what) { 8138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_ASSOC: 8148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_REASSOC: 8158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_DISASSOC: 8168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_SCAN: 8178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_LEAVE: 8198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt leave = (struct ieee80211_leave_event *) &ifan[1]; 8208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv_event_disassoc(drv->hapd, leave->iev_addr); 8218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_JOIN: 8238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef RTM_IEEE80211_REJOIN 8248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_REJOIN: 8258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 8268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt join = (struct ieee80211_join_event *) &ifan[1]; 8278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt bsd_new_sta(drv, drv->hapd, join->iev_addr); 8288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_REPLAY: 8308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* ignore */ 8318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_MICHAEL: 8338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mic = (struct ieee80211_michael_event *) &ifan[1]; 8348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, 8358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Michael MIC failure wireless event: " 8368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "keyix=%u src_addr=" MACSTR, mic->iev_keyix, 8378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt MAC2STR(mic->iev_src)); 8388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&data, 0, sizeof(data)); 8398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data.michael_mic_failure.unicast = 1; 8408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt data.michael_mic_failure.src = mic->iev_src; 8418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_supplicant_event(drv->hapd, 8428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt EVENT_MICHAEL_MIC_FAILURE, &data); 8438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 8468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 8488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 8498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void 8518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidthandle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) 8528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 8538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = ctx; 8548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv_event_eapol_rx(drv->hapd, src_addr, buf, len); 8558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 8568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void * 8588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_init(struct hostapd_data *hapd, struct wpa_init_params *params) 8598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 8608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv; 8618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv = os_zalloc(sizeof(struct bsd_driver_data)); 8638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv == NULL) { 8648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt printf("Could not allocate memory for bsd driver data\n"); 8658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto bad; 8668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->hapd = hapd; 8698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->sock = socket(PF_INET, SOCK_DGRAM, 0); 8708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock < 0) { 8718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt perror("socket[PF_INET,SOCK_DGRAM]"); 8728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto bad; 8738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(drv->ifname, params->ifname, sizeof(drv->ifname)); 8758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL, 8778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt handle_read, drv, 0); 8788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock_xmit == NULL) 8798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto bad; 8808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr)) 8818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto bad; 8828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* mark down during setup */ 8848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_ctrl_iface(drv, 0) < 0) 8858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto bad; 8868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->route = socket(PF_ROUTE, SOCK_RAW, 0); 8888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->route < 0) { 8898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt perror("socket(PF_ROUTE,SOCK_RAW)"); 8908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto bad; 8918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 8928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eloop_register_read_sock(drv->route, bsd_wireless_event_receive, drv, 8938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt NULL); 8948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 8958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_set_mediaopt(drv, IFM_OMASK, IFM_IEEE80211_HOSTAP) < 0) { 8968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: failed to set operation mode", 8978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__); 8988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto bad; 8998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 9008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return drv; 9028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbad: 9038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock_xmit != NULL) 9048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt l2_packet_deinit(drv->sock_xmit); 9058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock >= 0) 9068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt close(drv->sock); 9078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv != NULL) 9088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(drv); 9098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 9108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void 9148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtbsd_deinit(void *priv) 9158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 9178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->route >= 0) { 9198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eloop_unregister_read_sock(drv->route); 9208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt close(drv->route); 9218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 9228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt bsd_ctrl_iface(drv, 0); 9238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock >= 0) 9248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt close(drv->sock); 9258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock_xmit != NULL) 9268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt l2_packet_deinit(drv->sock_xmit); 9278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(drv); 9288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* HOSTAPD */ 9318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 9338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtget80211param(struct bsd_driver_data *drv, int op) 9348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req ireq; 9368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_get80211(drv, &ireq, op, NULL, 0) < 0) 9388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 9398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return ireq.i_val; 9408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 9438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_get_bssid(void *priv, u8 *bssid) 9448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 9468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef SIOCG80211BSSID 9478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_bssid bs; 9488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(bs.i_name, drv->ifname, sizeof(bs.i_name)); 9508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ioctl(drv->sock, SIOCG80211BSSID, &bs) < 0) 9518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 9528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(bssid, bs.i_bssid, sizeof(bs.i_bssid)); 9538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 9548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else 9558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return get80211var(drv, IEEE80211_IOC_BSSID, 9568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt bssid, IEEE80211_ADDR_LEN) < 0 ? -1 : 0; 9578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 9588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 9618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_get_ssid(void *priv, u8 *ssid) 9628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 9648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_get_ssid(drv, ssid, 0); 9658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 9688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_set_wpa_ie(struct bsd_driver_data *drv, const u8 *wpa_ie, 9698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t wpa_ie_len) 9708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef IEEE80211_IOC_APPIE 9728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_set_opt_ie(drv, wpa_ie, wpa_ie_len); 9738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* IEEE80211_IOC_APPIE */ 9748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211var(drv, IEEE80211_IOC_OPTIE, wpa_ie, wpa_ie_len); 9758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* IEEE80211_IOC_APPIE */ 9768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 9798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_set_wpa_internal(void *priv, int wpa, int privacy) 9808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int ret = 0; 9828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: wpa=%d privacy=%d", 9848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __FUNCTION__, wpa, privacy); 9858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!wpa && wpa_driver_bsd_set_wpa_ie(priv, NULL, 0) < 0) 9878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ret = -1; 9888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_PRIVACY, privacy) < 0) 9898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ret = -1; 9908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(priv, IEEE80211_IOC_WPA, wpa) < 0) 9918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ret = -1; 9928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return ret; 9948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 9958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 9968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 9978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_set_wpa(void *priv, int enabled) 9988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 9998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled); 10008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return wpa_driver_bsd_set_wpa_internal(priv, enabled ? 3 : 0, enabled); 10028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 10038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 10058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_set_countermeasures(void *priv, int enabled) 10068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 10078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); 10088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211param(priv, IEEE80211_IOC_COUNTERMEASURES, enabled); 10098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 10108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 10138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_set_drop_unencrypted(void *priv, int enabled) 10148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 10158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled); 10168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211param(priv, IEEE80211_IOC_DROPUNENCRYPTED, enabled); 10178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 10188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 10208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code) 10218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 10228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code, 10238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt addr); 10248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 10258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 10278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_set_auth_alg(void *priv, int auth_alg) 10288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 10298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int authmode; 10308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if ((auth_alg & WPA_AUTH_ALG_OPEN) && 10328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (auth_alg & WPA_AUTH_ALG_SHARED)) 10338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt authmode = IEEE80211_AUTH_AUTO; 10348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt else if (auth_alg & WPA_AUTH_ALG_SHARED) 10358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt authmode = IEEE80211_AUTH_SHARED; 10368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt else 10378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt authmode = IEEE80211_AUTH_OPEN; 10388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211param(priv, IEEE80211_IOC_AUTHMODE, authmode); 10408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 10418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void 10438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidthandle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) 10448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 10458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = ctx; 10468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv_event_eapol_rx(drv->ctx, src_addr, buf, len); 10488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 10498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 10518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_associate(void *priv, struct wpa_driver_associate_params *params) 10528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 10538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 10548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_mlme mlme; 10558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u32 mode; 10568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int privacy; 10578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int ret = 0; 10588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, 10608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u" 10618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt , __func__ 10628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt , (unsigned int) params->ssid_len, params->ssid 10638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt , (unsigned int) params->wpa_ie_len 10648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt , params->pairwise_suite 10658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt , params->group_suite 10668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt , params->key_mgmt_suite 10678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ); 10688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (params->mode) { 10708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case IEEE80211_MODE_INFRA: 10718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mode = 0 /* STA */; 10728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 10738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case IEEE80211_MODE_IBSS: 10748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mode = IFM_IEEE80211_IBSS; 10758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 10768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case IEEE80211_MODE_AP: 10778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mode = IFM_IEEE80211_HOSTAP; 10788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 10798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 10808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: unknown operation mode", __func__); 10818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 10828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_set_mediaopt(drv, IFM_OMASK, mode) < 0) { 10848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: failed to set operation mode", 10858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__); 10868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 10878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->mode == IEEE80211_MODE_AP) { 10908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL, 10918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt handle_read, drv, 0); 10928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock_xmit == NULL) 10938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 10948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->is_ap = 1; 10958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 10968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 10978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 10988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (wpa_driver_bsd_set_drop_unencrypted(drv, params->drop_unencrypted) 10998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt < 0) 11008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ret = -1; 11018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (wpa_driver_bsd_set_auth_alg(drv, params->auth_alg) < 0) 11028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ret = -1; 11038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* XXX error handling is wrong but unclear what to do... */ 11048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (wpa_driver_bsd_set_wpa_ie(drv, params->wpa_ie, params->wpa_ie_len) < 0) 11058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt privacy = !(params->pairwise_suite == CIPHER_NONE && 11088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt params->group_suite == CIPHER_NONE && 11098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt params->key_mgmt_suite == KEY_MGMT_NONE && 11108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt params->wpa_ie_len == 0); 11118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: set PRIVACY %u", __func__, privacy); 11128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0) 11148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->wpa_ie_len && 11178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt set80211param(drv, IEEE80211_IOC_WPA, 11188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt params->wpa_ie[0] == WLAN_EID_RSN ? 2 : 1) < 0) 11198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&mlme, 0, sizeof(mlme)); 11228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mlme.im_op = IEEE80211_MLME_ASSOC; 11238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->ssid != NULL) 11248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(mlme.im_ssid, params->ssid, params->ssid_len); 11258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mlme.im_ssid_len = params->ssid_len; 11268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->bssid != NULL) 11278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(mlme.im_macaddr, params->bssid, IEEE80211_ADDR_LEN); 11288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)) < 0) 11298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return ret; 11318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 11328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 11348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_scan(void *priv, struct wpa_driver_scan_params *params) 11358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 11368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 11378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef IEEE80211_IOC_SCAN_MAX_SSID 11388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_scan_req sr; 11398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int i; 11408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* IEEE80211_IOC_SCAN_MAX_SSID */ 11418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_set_mediaopt(drv, IFM_OMASK, 0 /* STA */) < 0) { 11438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: failed to set operation mode", 11448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__); 11458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(drv, IEEE80211_IOC_ROAMING, 11498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt IEEE80211_ROAMING_MANUAL) < 0) { 11508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: failed to set " 11518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "wpa_supplicant-based roaming: %s", __func__, 11528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt strerror(errno)); 11538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (wpa_driver_bsd_set_wpa(drv, 1) < 0) { 11578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s: failed to set wpa: %s", __func__, 11588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt strerror(errno)); 11598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* NB: interface must be marked UP to do a scan */ 11638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_ctrl_iface(drv, 1) < 0) 11648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef IEEE80211_IOC_SCAN_MAX_SSID 11678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&sr, 0, sizeof(sr)); 11688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE | IEEE80211_IOC_SCAN_ONCE | 11698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt IEEE80211_IOC_SCAN_NOJOIN; 11708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER; 11718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (params->num_ssids > 0) { 11728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sr.sr_nssid = params->num_ssids; 11738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#if 0 11748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* Boundary check is done by upper layer */ 11758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (sr.sr_nssid > IEEE80211_IOC_SCAN_MAX_SSID) 11768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sr.sr_nssid = IEEE80211_IOC_SCAN_MAX_SSID; 11778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 11788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* NB: check scan cache first */ 11808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sr.sr_flags |= IEEE80211_IOC_SCAN_CHECK; 11818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt for (i = 0; i < sr.sr_nssid; i++) { 11838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sr.sr_ssid[i].len = params->ssids[i].ssid_len; 11848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(sr.sr_ssid[i].ssid, params->ssids[i].ssid, 11858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sr.sr_ssid[i].len); 11868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 11878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* NB: net80211 delivers a scan complete event so no need to poll */ 11898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211var(drv, IEEE80211_IOC_SCAN_REQ, &sr, sizeof(sr)); 11908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* IEEE80211_IOC_SCAN_MAX_SSID */ 11918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* set desired ssid before scan */ 11928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (bsd_set_ssid(drv, params->ssids[0].ssid, 11938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt params->ssids[0].ssid_len) < 0) 11948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 11958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 11968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* NB: net80211 delivers a scan complete event so no need to poll */ 11978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return set80211param(drv, IEEE80211_IOC_SCAN_REQ, 0); 11988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* IEEE80211_IOC_SCAN_MAX_SSID */ 11998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 12008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void 12028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx) 12038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 12048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = sock_ctx; 12058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt char *buf; 12068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct if_announcemsghdr *ifan; 12078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct if_msghdr *ifm; 12088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct rt_msghdr *rtm; 12098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt union wpa_event_data event; 12108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_michael_event *mic; 12118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_leave_event *leave; 12128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_join_event *join; 12138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int n, len; 12148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt len = rtbuf_len(); 12168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt buf = os_malloc(len); 12188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (buf == NULL) { 12198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s os_malloc() failed\n", __func__); 12208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt n = read(sock, buf, len); 12248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (n < 0) { 12258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (errno != EINTR && errno != EAGAIN) 12268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "%s read() failed: %s\n", 12278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, strerror(errno)); 12288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 12298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 12328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt rtm = (struct rt_msghdr *) buf; 12338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (rtm->rtm_version != RTM_VERSION) { 12348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "Invalid routing message version=%d", 12358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt rtm->rtm_version); 12368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 12378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&event, 0, sizeof(event)); 12408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (rtm->rtm_type) { 12418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IFANNOUNCE: 12428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifan = (struct if_announcemsghdr *) rtm; 12438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ifan->ifan_index != drv->ifindex) 12448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(event.interface_status.ifname, drv->ifname, 12468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(event.interface_status.ifname)); 12478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (ifan->ifan_what) { 12488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case IFAN_DEPARTURE: 12498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt event.interface_status.ievent = EVENT_INTERFACE_REMOVED; 12508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt default: 12518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 12528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 12538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 12548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: Interface '%s' %s", 12558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt event.interface_status.ifname, 12568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifan->ifan_what == IFAN_DEPARTURE ? 12578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "removed" : "added"); 12588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event); 12598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211: 12618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifan = (struct if_announcemsghdr *) rtm; 12628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ifan->ifan_index != drv->ifindex) 12638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt switch (ifan->ifan_what) { 12658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_ASSOC: 12668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_REASSOC: 12678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->is_ap) 12688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_supplicant_event(ctx, EVENT_ASSOC, NULL); 12708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_DISASSOC: 12728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->is_ap) 12738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_supplicant_event(ctx, EVENT_DISASSOC, NULL); 12758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_SCAN: 12778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->is_ap) 12788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_supplicant_event(ctx, EVENT_SCAN_RESULTS, NULL); 12808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_LEAVE: 12828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt leave = (struct ieee80211_leave_event *) &ifan[1]; 12838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv_event_disassoc(ctx, leave->iev_addr); 12848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_JOIN: 12868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef RTM_IEEE80211_REJOIN 12878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_REJOIN: 12888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif 12898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt join = (struct ieee80211_join_event *) &ifan[1]; 12908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt bsd_new_sta(drv, ctx, join->iev_addr); 12918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_REPLAY: 12938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* ignore */ 12948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 12958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IEEE80211_MICHAEL: 12968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt mic = (struct ieee80211_michael_event *) &ifan[1]; 12978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, 12988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "Michael MIC failure wireless event: " 12998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt "keyix=%u src_addr=" MACSTR, mic->iev_keyix, 13008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt MAC2STR(mic->iev_src)); 13018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memset(&event, 0, sizeof(event)); 13038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt event.michael_mic_failure.unicast = 13048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt !IEEE80211_IS_MULTICAST(mic->iev_dst); 13058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_supplicant_event(ctx, EVENT_MICHAEL_MIC_FAILURE, 13068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt &event); 13078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 13088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 13108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt case RTM_IFINFO: 13118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt ifm = (struct if_msghdr *) rtm; 13128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (ifm->ifm_index != drv->ifindex) 13138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 13148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if ((rtm->rtm_flags & RTF_UP) == 0) { 13158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_strlcpy(event.interface_status.ifname, drv->ifname, 13168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(event.interface_status.ifname)); 13178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt event.interface_status.ievent = EVENT_INTERFACE_REMOVED; 13188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' DOWN", 13198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt event.interface_status.ifname); 13208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event); 13218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt break; 13238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(buf); 13258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 13268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void 13288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_add_scan_entry(struct wpa_scan_results *res, 13298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_scan_result *sr) 13308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 13318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpa_scan_res *result, **tmp; 13328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt size_t extra_len; 13338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt u8 *pos; 13348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt extra_len = 2 + sr->isr_ssid_len; 13368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt extra_len += 2 + sr->isr_nrates; 13378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt extra_len += 3; /* ERP IE */ 13388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt extra_len += sr->isr_ie_len; 13398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result = os_zalloc(sizeof(*result) + extra_len); 13418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (result == NULL) 13428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(result->bssid, sr->isr_bssid, ETH_ALEN); 13448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->freq = sr->isr_freq; 13458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->beacon_int = sr->isr_intval; 13468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->caps = sr->isr_capinfo; 13478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->qual = sr->isr_rssi; 13488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->noise = sr->isr_noise; 13495393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt /* 13505393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt * the rssi value reported by the kernel is in 0.5dB steps relative to 13515393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt * the reported noise floor. see ieee80211_node.h for details. 13525393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt */ 13535393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt result->level = sr->isr_rssi / 2 + sr->isr_noise; 13548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = (u8 *)(result + 1); 13568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = WLAN_EID_SSID; 13588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = sr->isr_ssid_len; 13598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(pos, sr + 1, sr->isr_ssid_len); 13608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += sr->isr_ssid_len; 13618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 13638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Deal all rates as supported rate. 13648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Because net80211 doesn't report extended supported rate or not. 13658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 13668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = WLAN_EID_SUPP_RATES; 13678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = sr->isr_nrates; 13688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(pos, sr->isr_rates, sr->isr_nrates); 13698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += sr->isr_nrates; 13708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = WLAN_EID_ERP_INFO; 13728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = 1; 13738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *pos++ = sr->isr_erp; 13748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len, sr->isr_ie_len); 13768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += sr->isr_ie_len; 13778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt result->ie_len = pos - (u8 *)(result + 1); 13798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 138061d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt tmp = os_realloc_array(res->res, res->num + 1, 138161d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt sizeof(struct wpa_scan_res *)); 13828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (tmp == NULL) { 13838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(result); 13848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return; 13858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 13868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt tmp[res->num++] = result; 13878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt res->res = tmp; 13888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 13898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstruct wpa_scan_results * 13918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_get_scan_results2(void *priv) 13928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 13938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211req_scan_result *sr; 13948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct wpa_scan_results *res; 13958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt int len, rest; 13968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt uint8_t buf[24*1024], *pos; 13978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 13988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt len = get80211var(priv, IEEE80211_IOC_SCAN_RESULTS, buf, 24*1024); 13998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (len < 0) 14008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 14018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt res = os_zalloc(sizeof(*res)); 14038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (res == NULL) 14048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 14058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos = buf; 14078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt rest = len; 14088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt while (rest >= sizeof(struct ieee80211req_scan_result)) { 14098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sr = (struct ieee80211req_scan_result *)pos; 14108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_driver_bsd_add_scan_entry(res, sr); 14118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt pos += sr->isr_len; 14128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt rest -= sr->isr_len; 14138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 14148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "Received %d bytes of scan results (%lu BSSes)", 14168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt len, (unsigned long)res->num); 14178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return res; 14198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 14208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int wpa_driver_bsd_capa(struct bsd_driver_data *drv) 14228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 14238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef IEEE80211_IOC_DEVCAPS 14248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt/* kernel definitions copied from net80211/ieee80211_var.h */ 14258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_CIPHER_WEP 0 14268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_CIPHER_TKIP 1 14278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_CIPHER_AES_CCM 3 14288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_CRYPTO_WEP (1<<IEEE80211_CIPHER_WEP) 14298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_CRYPTO_TKIP (1<<IEEE80211_CIPHER_TKIP) 14308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_CRYPTO_AES_CCM (1<<IEEE80211_CIPHER_AES_CCM) 14318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_C_HOSTAP 0x00000400 /* CAPABILITY: HOSTAP avail */ 14328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_C_WPA1 0x00800000 /* CAPABILITY: WPA1 avail */ 14338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define IEEE80211_C_WPA2 0x01000000 /* CAPABILITY: WPA2 avail */ 14348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct ieee80211_devcaps_req devcaps; 14358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (get80211var(drv, IEEE80211_IOC_DEVCAPS, &devcaps, 14378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt sizeof(devcaps)) < 0) { 14388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_ERROR, "failed to IEEE80211_IOC_DEVCAPS: %s", 14398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt strerror(errno)); 14408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return -1; 14418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 14428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: drivercaps=0x%08x,cryptocaps=0x%08x", 14448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, devcaps.dc_drivercaps, devcaps.dc_cryptocaps); 14458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (devcaps.dc_drivercaps & IEEE80211_C_WPA1) 14478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | 14488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK; 14498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (devcaps.dc_drivercaps & IEEE80211_C_WPA2) 14508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | 14518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; 14528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_WEP) 14548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP40 | 14558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_ENC_WEP104; 14568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_TKIP) 14578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.enc |= WPA_DRIVER_CAPA_ENC_TKIP; 14588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (devcaps.dc_cryptocaps & IEEE80211_CRYPTO_AES_CCM) 14598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.enc |= WPA_DRIVER_CAPA_ENC_CCMP; 14608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (devcaps.dc_drivercaps & IEEE80211_C_HOSTAP) 14628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.flags |= WPA_DRIVER_FLAGS_AP; 14638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_CIPHER_WEP 14648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_CIPHER_TKIP 14658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_CIPHER_AES_CCM 14668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_CRYPTO_WEP 14678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_CRYPTO_TKIP 14688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_CRYPTO_AES_CCM 14698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_C_HOSTAP 14708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_C_WPA1 14718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef IEEE80211_C_WPA2 14728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* IEEE80211_IOC_DEVCAPS */ 14738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */ 14748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | 14758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | 14768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | 14778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; 14788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.enc = WPA_DRIVER_CAPA_ENC_WEP40 | 14798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_ENC_WEP104 | 14808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_ENC_TKIP | 14818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_CAPA_ENC_CCMP; 14828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.flags |= WPA_DRIVER_FLAGS_AP; 14838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* IEEE80211_IOC_DEVCAPS */ 14848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef IEEE80211_IOC_SCAN_MAX_SSID 14858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.max_scan_ssids = IEEE80211_IOC_SCAN_MAX_SSID; 14868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* IEEE80211_IOC_SCAN_MAX_SSID */ 14878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.max_scan_ssids = 1; 14888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* IEEE80211_IOC_SCAN_MAX_SSID */ 14898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->capa.auth = WPA_DRIVER_AUTH_OPEN | 14908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_AUTH_SHARED | 14918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt WPA_DRIVER_AUTH_LEAP; 14928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 14938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 14948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 14958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void * 14968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_init(void *ctx, const char *ifname) 14978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 14988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#define GETPARAM(drv, param, v) \ 14998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (((v) = get80211param(drv, param)) != -1) 15008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv; 15018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv = os_zalloc(sizeof(*drv)); 15038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv == NULL) 15048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 15058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* 15068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * NB: We require the interface name be mappable to an index. 15078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * This implies we do not support having wpa_supplicant 15088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * wait for an interface to appear. This seems ok; that 15098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * doesn't belong here; it's really the job of devd. 15108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */ 15118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->ifindex = if_nametoindex(ifname); 15128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->ifindex == 0) { 15138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: interface %s does not exist", 15148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, ifname); 15158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto fail1; 15168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 15178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->sock = socket(PF_INET, SOCK_DGRAM, 0); 15188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock < 0) 15198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto fail1; 15205393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt 15215393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname)); 15225393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt /* Down interface during setup. */ 15235393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt if (bsd_ctrl_iface(drv, 0) < 0) 15245393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt goto fail; 15255393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt 15268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->route = socket(PF_ROUTE, SOCK_RAW, 0); 15278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->route < 0) 15288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto fail; 15298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eloop_register_read_sock(drv->route, 15308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_driver_bsd_event_receive, ctx, drv); 15318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt drv->ctx = ctx; 15338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!GETPARAM(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming)) { 15358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: failed to get roaming state: %s", 15368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, strerror(errno)); 15378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto fail; 15388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 15398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!GETPARAM(drv, IEEE80211_IOC_PRIVACY, drv->prev_privacy)) { 15408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: failed to get privacy state: %s", 15418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, strerror(errno)); 15428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto fail; 15438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 15448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (!GETPARAM(drv, IEEE80211_IOC_WPA, drv->prev_wpa)) { 15458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: failed to get wpa state: %s", 15468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__, strerror(errno)); 15478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto fail; 15488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt } 15498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15508d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (wpa_driver_bsd_capa(drv)) 15518d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt goto fail; 15528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15535393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt drv->opmode = get80211opmode(drv); 15545393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt 15558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return drv; 15568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtfail: 15578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt close(drv->sock); 15588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtfail1: 15598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(drv); 15608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return NULL; 15618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#undef GETPARAM 15628d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void 15658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_deinit(void *priv) 15668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 15688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_driver_bsd_set_wpa(drv, 0); 15708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt eloop_unregister_read_sock(drv->route); 15718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt /* NB: mark interface down */ 15738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt bsd_ctrl_iface(drv, 0); 15748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_driver_bsd_set_wpa_internal(drv, drv->prev_wpa, drv->prev_privacy); 15768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (set80211param(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming) < 0) 15778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt wpa_printf(MSG_DEBUG, "%s: failed to restore roaming state", 15788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt __func__); 15798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt if (drv->sock_xmit != NULL) 15818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt l2_packet_deinit(drv->sock_xmit); 15828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (void) close(drv->route); /* ioctl socket */ 15838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt (void) close(drv->sock); /* event socket */ 15848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_free(drv); 15858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int 15888d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtwpa_driver_bsd_get_capa(void *priv, struct wpa_driver_capa *capa) 15898d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{ 15908d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt struct bsd_driver_data *drv = priv; 15918d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt os_memcpy(capa, &drv->capa, sizeof(*capa)); 15938d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt return 0; 15948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt} 15958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* HOSTAPD */ 15968d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt 15988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtconst struct wpa_driver_ops wpa_driver_bsd_ops = { 15998d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .name = "bsd", 16008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .desc = "BSD 802.11 support", 16018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef HOSTAPD 16028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .hapd_init = bsd_init, 16038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .hapd_deinit = bsd_deinit, 16048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .set_privacy = bsd_set_privacy, 16058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .get_seqnum = bsd_get_seqnum, 16068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .flush = bsd_flush, 16078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .read_sta_data = bsd_read_sta_driver_data, 16088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .sta_disassoc = bsd_sta_disassoc, 16098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .sta_deauth = bsd_sta_deauth, 16105393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt .sta_set_flags = bsd_set_sta_authorized, 16115393a0f77c5281735888bd9dcf8d8abeb5961461Dmitry Shmidt .commit = bsd_commit, 16128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#else /* HOSTAPD */ 16138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .init = wpa_driver_bsd_init, 16148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .deinit = wpa_driver_bsd_deinit, 16158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .get_bssid = wpa_driver_bsd_get_bssid, 16168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .get_ssid = wpa_driver_bsd_get_ssid, 16178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .set_countermeasures = wpa_driver_bsd_set_countermeasures, 16188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .scan2 = wpa_driver_bsd_scan, 16198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .get_scan_results2 = wpa_driver_bsd_get_scan_results2, 16208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .deauthenticate = wpa_driver_bsd_deauthenticate, 16218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .associate = wpa_driver_bsd_associate, 16228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .get_capa = wpa_driver_bsd_get_capa, 16238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* HOSTAPD */ 16248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .set_freq = bsd_set_freq, 16258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .set_key = bsd_set_key, 16268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .set_ieee8021x = bsd_set_ieee8021x, 16278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .hapd_set_ssid = bsd_set_ssid, 16288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .hapd_get_ssid = bsd_get_ssid, 16298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .hapd_send_eapol = bsd_send_eapol, 16308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt .set_generic_elem = bsd_set_opt_ie, 16318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt}; 1632