From owner-p4-projects@FreeBSD.ORG Tue Dec 4 05:38:44 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id CF45216A421; Tue, 4 Dec 2007 05:38:43 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7C84116A418 for ; Tue, 4 Dec 2007 05:38:43 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 792D213C447 for ; Tue, 4 Dec 2007 05:38:43 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lB45chLk060157 for ; Tue, 4 Dec 2007 05:38:43 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lB45chPO060154 for perforce@freebsd.org; Tue, 4 Dec 2007 05:38:43 GMT (envelope-from sam@freebsd.org) Date: Tue, 4 Dec 2007 05:38:43 GMT Message-Id: <200712040538.lB45chPO060154@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Cc: Subject: PERFORCE change 130143 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Dec 2007 05:38:44 -0000 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 #include -#include -#include #include #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<wpa_pairwise & WPA_CIPHER_TKIP) - v |= 1<wpa_pairwise & WPA_CIPHER_NONE) - v |= 1<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);