Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Dec 2010 20:00:28 +0000 (UTC)
From:      Bernhard Schmidt <bschmidt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r216529 - head/usr.sbin/wpa/hostapd
Message-ID:  <201012182000.oBIK0S1t027027@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bschmidt
Date: Sat Dec 18 20:00:28 2010
New Revision: 216529
URL: http://svn.freebsd.org/changeset/base/216529

Log:
  Move some functions around to match the upstream order.

Modified:
  head/usr.sbin/wpa/hostapd/driver_freebsd.c

Modified: head/usr.sbin/wpa/hostapd/driver_freebsd.c
==============================================================================
--- head/usr.sbin/wpa/hostapd/driver_freebsd.c	Sat Dec 18 19:58:23 2010	(r216528)
+++ head/usr.sbin/wpa/hostapd/driver_freebsd.c	Sat Dec 18 20:00:28 2010	(r216529)
@@ -24,14 +24,11 @@
 
 #include <sys/socket.h>
 #include <net/if.h>
+#include <net/route.h>
 #include <netinet/in.h>
 
 #include <net80211/ieee80211_ioctl.h>
-
-#undef RSN_VERSION
-#undef WPA_VERSION
-#undef WPA_OUI_TYPE
-#undef WME_OUI_TYPE
+#include <net80211/ieee80211_freebsd.h>
 
 #include "l2_packet/l2_packet.h"
 
@@ -54,9 +51,6 @@ struct bsd_driver_data {
 
 static const struct wpa_driver_ops bsd_driver_ops;
 
-static int bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
-    int reason_code);
-
 static int
 bsd_set80211(void *priv, int op, int val, const void *arg, int arg_len)
 {
@@ -121,16 +115,58 @@ set80211param(struct bsd_driver_data *dr
 	return bsd_set80211(drv, op, arg, NULL, 0);
 }
 
-static const char *
-ether_sprintf(const u8 *addr)
+static int
+bsd_get_ssid(void *priv, u8 *buf, int len)
 {
-	static char buf[sizeof(MACSTR)];
+	struct bsd_driver_data *drv = priv;
 
-	if (addr != NULL)
-		snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
-	else
-		snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
-	return buf;
+	int ssid_len = get80211var(priv, IEEE80211_IOC_SSID, buf, len);
+
+	wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"\n", __func__, ssid_len, buf);
+
+	return ssid_len;
+}
+
+static int
+bsd_set_ssid(void *priv, const u8 *buf, int len)
+{
+	struct bsd_driver_data *drv = priv;
+	struct hostapd_data *hapd = drv->hapd;
+
+	wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"\n", __func__, len, buf);
+
+	return set80211var(priv, IEEE80211_IOC_SSID, buf, len);
+}
+
+static int
+bsd_del_key(void *priv, const u8 *addr, int key_idx)
+{
+	struct ieee80211req_del_key wk;
+
+	os_memset(&wk, 0, sizeof(wk));
+	if (addr == NULL) {
+		wpa_printf(MSG_DEBUG, "%s: key_idx=%d", __func__, key_idx);
+		wk.idk_keyix = key_idx;
+	} else {
+		wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__,
+			   MAC2STR(addr));
+		os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
+		wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE;	/* XXX */
+	}
+
+	return set80211var(priv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
+}
+
+static int
+bsd_send_mlme_param(void *priv, const u8 op, const u16 reason, const u8 *addr)
+{
+	struct ieee80211req_mlme mlme;
+
+	os_memset(&mlme, 0, sizeof(mlme));
+	mlme.im_op = op;
+	mlme.im_reason = reason;
+	os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+	return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
 }
 
 static int
@@ -178,6 +214,69 @@ bsd_commit(void *priv)
 }
 
 static int
+bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg,
+	    const unsigned char *addr, int key_idx, int set_tx, const u8 *seq,
+	    size_t seq_len, const u8 *key, size_t key_len)
+{
+	struct ieee80211req_key wk;
+
+	wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%p key_idx=%d set_tx=%d "
+		  "seq_len=%zu key_len=%zu", __func__, alg, addr, key_idx,
+		  set_tx, seq_len, key_len);
+
+	if (alg == WPA_ALG_NONE) {
+		return bsd_del_key(priv, addr, key_idx);
+	}
+
+	os_memset(&wk, 0, sizeof(wk));
+	switch (alg) {
+	case WPA_ALG_WEP:
+		wk.ik_type = IEEE80211_CIPHER_WEP;
+		break;
+	case WPA_ALG_TKIP:
+		wk.ik_type = IEEE80211_CIPHER_TKIP;
+		break;
+	case WPA_ALG_CCMP:
+		wk.ik_type = IEEE80211_CIPHER_AES_CCM;
+		break;
+	default:
+		wpa_printf(MSG_ERROR, "%s: unknown alg=%d", __func__, alg);
+		return -1;
+	}
+
+	wk.ik_flags = IEEE80211_KEY_RECV;
+	if (set_tx)
+		wk.ik_flags |= IEEE80211_KEY_XMIT;
+
+	if (addr == NULL) {
+		os_memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
+		wk.ik_keyix = key_idx;
+	} else {
+		os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
+		/*
+		 * Deduce whether group/global or unicast key by checking
+		 * the address (yech).  Note also that we can only mark global
+		 * keys default; doing this for a unicast key is an error.
+		 */
+		if (os_memcmp(addr, "\xff\xff\xff\xff\xff\xff",
+			      IEEE80211_ADDR_LEN) == 0) {
+			wk.ik_flags |= IEEE80211_KEY_GROUP;
+			wk.ik_keyix = key_idx;
+		} else {
+			wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE :
+				key_idx;
+		}
+	}
+	if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx)
+		wk.ik_flags |= IEEE80211_KEY_DEFAULT;
+	wk.ik_keylen = key_len;
+	os_memcpy(&wk.ik_keyrsc, seq, seq_len);
+	os_memcpy(wk.ik_keydata, key, key_len);
+
+	return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
+}
+
+static int
 bsd_set_ieee8021x(void *priv, struct wpa_bss_params *params)
 {
 	wpa_printf(MSG_DEBUG, "%s: enabled=%d\n", __func__, params->enabled);
@@ -207,26 +306,6 @@ bsd_set_ieee8021x(void *priv, struct wpa
 }
 
 static int
-bsd_set_privacy(void *priv, int enabled)
-{
-	wpa_printf(MSG_DEBUG, "%s: enabled=%d\n", __func__, enabled);
-
-	return set80211param(priv, IEEE80211_IOC_PRIVACY, enabled);
-}
-
-static int
-bsd_send_mlme_param(void *priv, const u8 op, const u16 reason, const u8 *addr)
-{
-	struct ieee80211req_mlme mlme;
-
-	os_memset(&mlme, 0, sizeof(mlme));
-	mlme.im_op = op;
-	mlme.im_reason = reason;
-	os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
 bsd_set_sta_authorized(void *priv, const u8 *addr,
 		       int total_flags, int flags_or, int flags_and)
 {
@@ -246,88 +325,113 @@ bsd_set_sta_authorized(void *priv, const
 				   IEEE80211_MLME_UNAUTHORIZE, 0, addr);
 }
 
-static int
-bsd_del_key(void *priv, const u8 *addr, int key_idx)
+static void
+bsd_new_sta(void *priv, void *ctx, u8 addr[IEEE80211_ADDR_LEN])
 {
-	struct ieee80211req_del_key wk;
+	struct ieee80211req_wpaie ie;
+	int ielen = 0;
+	u8 *iebuf = NULL;
 
-	os_memset(&wk, 0, sizeof(wk));
-	if (addr == NULL) {
-		wpa_printf(MSG_DEBUG, "%s: key_idx=%d", __func__, key_idx);
-		wk.idk_keyix = key_idx;
-	} else {
-		wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__,
-			   MAC2STR(addr));
-		os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
-		wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE;	/* XXX */
+	/*
+	 * Fetch and validate any negotiated WPA/RSN parameters.
+	 */
+	memset(&ie, 0, sizeof(ie));
+	memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
+	if (get80211var(priv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) {
+		printf("Failed to get WPA/RSN information element.\n");
+		goto no_ie;
 	}
+	iebuf = ie.wpa_ie;
+	ielen = ie.wpa_ie[1];
+	if (ielen == 0)
+		iebuf = NULL;
+	else
+		ielen += 2;
+
+no_ie:
+        drv_event_assoc(ctx, addr, iebuf, ielen);
 
-	return set80211var(priv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
 }
 
 static int
-bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg,
-	    const unsigned char *addr, int key_idx, int set_tx, const u8 *seq,
-	    size_t seq_len, const u8 *key, size_t key_len)
+bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
+	       int encrypt, const u8 *own_addr)
+	      
 {
-	struct ieee80211req_key wk;
-
-	wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%p key_idx=%d set_tx=%d "
-		  "seq_len=%zu key_len=%zu", __func__, alg, addr, key_idx,
-		  set_tx, seq_len, key_len);
+	struct bsd_driver_data *drv = priv;
+	struct hostapd_data *hapd = drv->hapd;
+	unsigned char buf[3000];
+	unsigned char *bp = buf;
+	struct l2_ethhdr *eth;
+	size_t len;
+	int status;
 
-	if (alg == WPA_ALG_NONE) {
-		return bsd_del_key(priv, addr, key_idx);
+	/*
+	 * Prepend the Etherent header.  If the caller left us
+	 * space at the front we could just insert it but since
+	 * we don't know we copy to a local buffer.  Given the frequency
+	 * and size of frames this probably doesn't matter.
+	 */
+	len = data_len + sizeof(struct l2_ethhdr);
+	if (len > sizeof(buf)) {
+		bp = malloc(len);
+		if (bp == NULL) {
+			printf("EAPOL frame discarded, cannot malloc temp "
+				"buffer of size %u!\n", len);
+			return -1;
+		}
 	}
+	eth = (struct l2_ethhdr *) bp;
+	memcpy(eth->h_dest, addr, ETH_ALEN);
+	memcpy(eth->h_source, own_addr, ETH_ALEN);
+	eth->h_proto = htons(ETH_P_EAPOL);
+	memcpy(eth+1, data, data_len);
 
-	os_memset(&wk, 0, sizeof(wk));
-	switch (alg) {
-	case WPA_ALG_WEP:
-		wk.ik_type = IEEE80211_CIPHER_WEP;
-		break;
-	case WPA_ALG_TKIP:
-		wk.ik_type = IEEE80211_CIPHER_TKIP;
-		break;
-	case WPA_ALG_CCMP:
-		wk.ik_type = IEEE80211_CIPHER_AES_CCM;
-		break;
-	default:
-		wpa_printf(MSG_ERROR, "%s: unknown alg=%d", __func__, alg);
-		return -1;
-	}
+	wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
 
-	wk.ik_flags = IEEE80211_KEY_RECV;
-	if (set_tx)
-		wk.ik_flags |= IEEE80211_KEY_XMIT;
+	status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
 
-	if (addr == NULL) {
-		os_memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
-		wk.ik_keyix = key_idx;
-	} else {
-		os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
-		/*
-		 * Deduce whether group/global or unicast key by checking
-		 * the address (yech).  Note also that we can only mark global
-		 * keys default; doing this for a unicast key is an error.
-		 */
-		if (os_memcmp(addr, "\xff\xff\xff\xff\xff\xff",
-			      IEEE80211_ADDR_LEN) == 0) {
-			wk.ik_flags |= IEEE80211_KEY_GROUP;
-			wk.ik_keyix = key_idx;
-		} else {
-			wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE :
-				key_idx;
-		}
-	}
-	if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx)
-		wk.ik_flags |= IEEE80211_KEY_DEFAULT;
-	wk.ik_keylen = key_len;
-	os_memcpy(&wk.ik_keyrsc, seq, seq_len);
-	os_memcpy(wk.ik_keydata, key, key_len);
+	if (bp != buf)
+		free(bp);
+	return status;
+}
 
-	return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
+static int
+bsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
+{
+	wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__,
+		   (unsigned long)ie_len);
+	return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA,
+			    ie, ie_len);
+}
+
+#undef RSN_VERSION
+#undef WPA_VERSION
+#undef WPA_OUI_TYPE
+#undef WME_OUI_TYPE
+
+static int bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
+    int reason_code);
+
+static const char *
+ether_sprintf(const u8 *addr)
+{
+	static char buf[sizeof(MACSTR)];
+
+	if (addr != NULL)
+		snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
+	else
+		snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
+	return buf;
 }
 
+static int
+bsd_set_privacy(void *priv, int enabled)
+{
+	wpa_printf(MSG_DEBUG, "%s: enabled=%d\n", __func__, enabled);
+
+	return set80211param(priv, IEEE80211_IOC_PRIVACY, enabled);
+}
 
 static int
 bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
@@ -403,15 +507,6 @@ bsd_sta_clear_stats(void *priv, const u8
 }
 
 static int
-bsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
-{
-	wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__,
-		   (unsigned long)ie_len);
-	return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA,
-			    ie, ie_len);
-}
-
-static int
 bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code)
 {
 	return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code,
@@ -427,37 +522,6 @@ bsd_sta_disassoc(void *priv, const u8 *o
 }
 
 static void
-bsd_new_sta(void *priv, void *ctx, u8 addr[IEEE80211_ADDR_LEN])
-{
-	struct ieee80211req_wpaie ie;
-	int ielen = 0;
-	u8 *iebuf = NULL;
-
-	/*
-	 * Fetch and validate any negotiated WPA/RSN parameters.
-	 */
-	memset(&ie, 0, sizeof(ie));
-	memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
-	if (get80211var(priv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) {
-		printf("Failed to get WPA/RSN information element.\n");
-		goto no_ie;
-	}
-	iebuf = ie.wpa_ie;
-	ielen = ie.wpa_ie[1];
-	if (ielen == 0)
-		iebuf = NULL;
-	else
-		ielen += 2;
-
-no_ie:
-        drv_event_assoc(ctx, addr, iebuf, ielen);
-
-}
-
-#include <net/route.h>
-#include <net80211/ieee80211_freebsd.h>
-
-static void
 bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
 {
 	struct bsd_driver_data *drv = ctx;
@@ -559,49 +623,6 @@ bsd_wireless_event_receive(int sock, voi
 	}
 }
 
-static int
-bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
-	       int encrypt, const u8 *own_addr)
-	      
-{
-	struct bsd_driver_data *drv = priv;
-	struct hostapd_data *hapd = drv->hapd;
-	unsigned char buf[3000];
-	unsigned char *bp = buf;
-	struct l2_ethhdr *eth;
-	size_t len;
-	int status;
-
-	/*
-	 * Prepend the Etherent header.  If the caller left us
-	 * space at the front we could just insert it but since
-	 * we don't know we copy to a local buffer.  Given the frequency
-	 * and size of frames this probably doesn't matter.
-	 */
-	len = data_len + sizeof(struct l2_ethhdr);
-	if (len > sizeof(buf)) {
-		bp = malloc(len);
-		if (bp == NULL) {
-			printf("EAPOL frame discarded, cannot malloc temp "
-				"buffer of size %u!\n", len);
-			return -1;
-		}
-	}
-	eth = (struct l2_ethhdr *) bp;
-	memcpy(eth->h_dest, addr, ETH_ALEN);
-	memcpy(eth->h_source, own_addr, ETH_ALEN);
-	eth->h_proto = htons(ETH_P_EAPOL);
-	memcpy(eth+1, data, data_len);
-
-	wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
-
-	status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
-
-	if (bp != buf)
-		free(bp);
-	return status;
-}
-
 static void
 handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
 {
@@ -610,29 +631,6 @@ handle_read(void *ctx, const u8 *src_add
 }
 
 static int
-bsd_get_ssid(void *priv, u8 *buf, int len)
-{
-	struct bsd_driver_data *drv = priv;
-
-	int ssid_len = get80211var(priv, IEEE80211_IOC_SSID, buf, len);
-
-	wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"\n", __func__, ssid_len, buf);
-
-	return ssid_len;
-}
-
-static int
-bsd_set_ssid(void *priv, const u8 *buf, int len)
-{
-	struct bsd_driver_data *drv = priv;
-	struct hostapd_data *hapd = drv->hapd;
-
-	wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"\n", __func__, len, buf);
-
-	return set80211var(priv, IEEE80211_IOC_SSID, buf, len);
-}
-
-static int
 bsd_set_countermeasures(void *priv, int enabled)
 {
 	struct bsd_driver_data *drv = priv;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201012182000.oBIK0S1t027027>