[PATCH] driver_bsd.c: Reduce code duplication (MLME)

Masashi Honma honma
Wed Jan 27 21:57:05 PST 2010


Hello.

This patch reduces code duplication between hostapd and wpa_supplicant
about IEEE80211_IOC_MLME. This is a preparation for AP mode
wpa_supplicant. This is a patch to
http://lists.shmoo.com/pipermail/hostap/2010-January/021036.html.


--- driver_bsd.c.bak	2010-01-28 14:53:45.000000000 +0900
+++ driver_bsd.c	2010-01-28 14:53:46.000000000 +0900
@@ -212,6 +212,20 @@
 			       sizeof(wk));
 }
 
+static int
+bsd_send_mlme_param(int s, const char *ifname, 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 bsd_set80211var(s, ifname, IEEE80211_IOC_MLME, &mlme,
+			       sizeof(mlme));
+}
+
 
 #ifdef HOSTAPD
 
@@ -432,18 +446,10 @@
 bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized)
 {
 	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
 
-	wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
-		   __func__, ether_sprintf(addr), authorized);
-
-	if (authorized)
-		mlme.im_op = IEEE80211_MLME_AUTHORIZE;
-	else
-		mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
-	mlme.im_reason = 0;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
+	return bsd_send_mlme_param(drv->ioctl_sock, drv->iface, authorized ?
+				   IEEE80211_MLME_AUTHORIZE :
+				   IEEE80211_MLME_UNAUTHORIZE, 0, addr);
 }
 
 static int
@@ -592,15 +598,9 @@
 bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code)
 {
 	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
-		   __func__, ether_sprintf(addr), reason_code);
 
-	mlme.im_op = IEEE80211_MLME_DEAUTH;
-	mlme.im_reason = reason_code;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
+	return bsd_send_mlme_param(drv->ioctl_sock, drv->iface,
+				   IEEE80211_MLME_DEAUTH, reason_code, addr);
 }
 
 static int
@@ -608,15 +608,9 @@
 		 int reason_code)
 {
 	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
 
-	wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
-		   __func__, ether_sprintf(addr), reason_code);
-
-	mlme.im_op = IEEE80211_MLME_DISASSOC;
-	mlme.im_reason = reason_code;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
+	return bsd_send_mlme_param(drv->ioctl_sock, drv->iface,
+				   IEEE80211_MLME_DISASSOC, reason_code, addr);
 }
 
 static void
@@ -1156,28 +1150,18 @@
 wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code)
 {
 	struct wpa_driver_bsd_data *drv = priv;
-	struct ieee80211req_mlme mlme;
 
-	wpa_printf(MSG_DEBUG, "%s", __func__);
-	os_memset(&mlme, 0, sizeof(mlme));
-	mlme.im_op = IEEE80211_MLME_DEAUTH;
-	mlme.im_reason = reason_code;
-	os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
+	return bsd_send_mlme_param(drv->sock, drv->ifname,
+				   IEEE80211_MLME_DEAUTH, reason_code, addr);
 }
 
 static int
 wpa_driver_bsd_disassociate(void *priv, const u8 *addr, int reason_code)
 {
 	struct wpa_driver_bsd_data *drv = priv;
-	struct ieee80211req_mlme mlme;
 
-	wpa_printf(MSG_DEBUG, "%s", __func__);
-	os_memset(&mlme, 0, sizeof(mlme));
-	mlme.im_op = IEEE80211_MLME_DISASSOC;
-	mlme.im_reason = reason_code;
-	os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
+	return bsd_send_mlme_param(drv->sock, drv->ifname,
+				   IEEE80211_MLME_DISASSOC, reason_code, addr);
 }
 
 static int


Regards,
Masashi Honma.



More information about the Hostap mailing list