Date: Tue, 4 Dec 2007 05:38:43 GMT From: Sam Leffler <sam@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 130143 for review Message-ID: <200712040538.lB45chPO060154@repoman.freebsd.org>
index | next in thread | raw e-mail
http://perforce.freebsd.org/chv.cgi?CH=130143 Change 130143 by sam@sam_ebb on 2007/12/04 05:37:46 sync w/ vap code Affected files ... .. //depot/projects/vap/usr.sbin/wpa/hostapd/driver_freebsd.c#3 edit Differences ... ==== //depot/projects/vap/usr.sbin/wpa/hostapd/driver_freebsd.c#3 (text+ko) ==== @@ -25,8 +25,6 @@ #include <net/if.h> #include <netinet/in.h> -#include <net80211/ieee80211.h> -#include <net80211/ieee80211_crypto.h> #include <net80211/ieee80211_ioctl.h> #include "hostapd.h" @@ -48,6 +46,7 @@ struct hostapd_data *hapd; /* back pointer */ char iface[IFNAMSIZ + 1]; + unsigned int ifindex; /* interface index */ struct l2_packet_data *sock_xmit; /* raw packet xmit socket */ int ioctl_sock; /* socket for ioctl() use */ int wext_sock; /* socket for wireless events */ @@ -122,98 +121,6 @@ return buf; } -/* - * Configure WPA parameters. - */ -static int -bsd_configure_wpa(struct bsd_driver_data *drv) -{ - static const char *ciphernames[] = - { "WEP", "TKIP", "AES-OCB", "AES-CCM", "*BAD*", "CKIP", "NONE" }; - struct hostapd_data *hapd = drv->hapd; - struct hostapd_bss_config *conf = hapd->conf; - int v; - - switch (conf->wpa_group) { - case WPA_CIPHER_CCMP: - v = IEEE80211_CIPHER_AES_CCM; - break; - case WPA_CIPHER_TKIP: - v = IEEE80211_CIPHER_TKIP; - break; - case WPA_CIPHER_WEP104: - v = IEEE80211_CIPHER_WEP; - break; - case WPA_CIPHER_WEP40: - v = IEEE80211_CIPHER_WEP; - break; - case WPA_CIPHER_NONE: - v = IEEE80211_CIPHER_NONE; - break; - default: - printf("Unknown group key cipher %u\n", - conf->wpa_group); - return -1; - } - HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, - "%s: group key cipher=%s (%u)\n", __func__, ciphernames[v], v); - if (set80211param(drv, IEEE80211_IOC_MCASTCIPHER, v)) { - printf("Unable to set group key cipher to %u (%s)\n", - v, ciphernames[v]); - return -1; - } - if (v == IEEE80211_CIPHER_WEP) { - /* key length is done only for specific ciphers */ - v = (conf->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5); - if (set80211param(drv, IEEE80211_IOC_MCASTKEYLEN, v)) { - printf("Unable to set group key length to %u\n", v); - return -1; - } - } - - v = 0; - if (conf->wpa_pairwise & WPA_CIPHER_CCMP) - v |= 1<<IEEE80211_CIPHER_AES_CCM; - if (conf->wpa_pairwise & WPA_CIPHER_TKIP) - v |= 1<<IEEE80211_CIPHER_TKIP; - if (conf->wpa_pairwise & WPA_CIPHER_NONE) - v |= 1<<IEEE80211_CIPHER_NONE; - HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, - "%s: pairwise key ciphers=0x%x\n", __func__, v); - if (set80211param(drv, IEEE80211_IOC_UCASTCIPHERS, v)) { - printf("Unable to set pairwise key ciphers to 0x%x\n", v); - return -1; - } - - HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, - "%s: key management algorithms=0x%x\n", - __func__, conf->wpa_key_mgmt); - if (set80211param(drv, IEEE80211_IOC_KEYMGTALGS, conf->wpa_key_mgmt)) { - printf("Unable to set key management algorithms to 0x%x\n", - conf->wpa_key_mgmt); - return -1; - } - - v = 0; - if (conf->rsn_preauth) - v |= BIT(0); - HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, - "%s: rsn capabilities=0x%x\n", __func__, conf->rsn_preauth); - if (set80211param(drv, IEEE80211_IOC_RSNCAPS, v)) { - printf("Unable to set RSN capabilities to 0x%x\n", v); - return -1; - } - - HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, - "%s: enable WPA= 0x%x\n", __func__, conf->wpa); - if (set80211param(drv, IEEE80211_IOC_WPA, conf->wpa)) { - printf("Unable to set WPA to %u\n", conf->wpa); - return -1; - } - return 0; -} - - static int bsd_set_iface_flags(void *priv, int dev_up) { @@ -279,7 +186,7 @@ HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!"); return -1; } - if (conf->wpa && bsd_configure_wpa(drv) != 0) { + if (conf->wpa && set80211param(drv, IEEE80211_IOC_WPA, conf->wpa)) { hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER, HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!"); return -1; @@ -394,14 +301,16 @@ memset(&wk, 0, sizeof(wk)); wk.ik_type = cipher; - wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT; if (addr == NULL) { memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN); wk.ik_keyix = key_idx; - wk.ik_flags |= IEEE80211_KEY_DEFAULT | IEEE80211_KEY_GROUP; + wk.ik_flags = IEEE80211_KEY_XMIT + | IEEE80211_KEY_GROUP + | IEEE80211_KEY_DEFAULT; } else { memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN); wk.ik_keyix = IEEE80211_KEYIX_NONE; + wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT; } wk.ik_keylen = key_len; memcpy(wk.ik_keydata, key, key_len); @@ -487,10 +396,23 @@ static int bsd_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len) { - /* - * Do nothing; we setup parameters at startup that define the - * contents of the beacon information element. - */ + struct bsd_driver_data *drv = priv; + struct hostapd_data *hapd = drv->hapd; + struct ieee80211req ireq; + + memset(&ireq, 0, sizeof(ireq)); + strncpy(ireq.i_name, drv->iface, IFNAMSIZ); + ireq.i_type = IEEE80211_IOC_APPIE; + ireq.i_val = IEEE80211_APPIE_WPA; + ireq.i_data = (void *) ie; + ireq.i_len = ie_len; + + HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "%s: set WPA+RSN ie (len %d)\n", + __func__, ie_len); + if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) { + printf("Unable to set WPA+RSN ie\n"); + return -1; + } return 0; } @@ -638,6 +560,12 @@ return; } ifan = (struct if_announcemsghdr *) rtm; + if (ifan->ifan_index != drv->ifindex) { + wpa_printf(MSG_DEBUG, "Discard routing message to if#%d " + "(not for us %d)\n", + ifan->ifan_index, drv->ifindex); + return; + } switch (rtm->rtm_type) { case RTM_IEEE80211: switch (ifan->ifan_what) { @@ -820,6 +748,18 @@ goto bad; } memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface)); + /* + * NB: We require the interface name be mappable to an index. + * This implies we do not support having wpa_supplicant + * wait for an interface to appear. This seems ok; that + * doesn't belong here; it's really the job of devd. + * XXXSCW: devd is FreeBSD-specific. + */ + drv->ifindex = if_nametoindex(drv->iface); + if (drv->ifindex == 0) { + printf("%s: interface %s does not exist", __func__, drv->iface); + goto bad; + } drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL, handle_read, drv, 1);help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200712040538.lB45chPO060154>
