[PATCH] driver_bsd.c: Aggregate ioctl routines

Masashi Honma honma
Thu Feb 11 21:43:42 PST 2010


Hello.

This patch aggregates ioctls.

First is SIOCS80211. The SIOCS80211's arguments has 3 couples.
	1-1. i_len, i_data
	1-2. i_val
	1-3. i_len, i_data, i_val (currently only IEEE80211_IOC_APPIE)
There were 3 routines for each cases. This patch aggregates these to
one.

Second is SIOCG80211. The SIOCG80211 returns 2 type of value.
	2-1. i_len
	2-2. i_val
There were 2 routines for each cases. This patch aggregates these to
one.

This is a patch to
http://lists.shmoo.com/pipermail/hostap/2010-February/021089.html

I have tested on both FreeBSD 8.0 and NetBSD 5.0.1 with these cases.

[hostapd]
RSN-PSK(CCMP)/WPA-PSK(TKIP)

[wpa_supplicant(STA)]
RSN-PSK(CCMP)/WPA-PSK(TKIP)

[wpa_supplicant(AP)]
RSN-PSK(CCMP)/WPA-PSK(TKIP)


--- driver_bsd.c.bak	2010-02-12 05:31:59.000000000 +0900
+++ driver_bsd.c	2010-02-12 05:37:38.000000000 +0900
@@ -67,77 +67,67 @@
 /* Generic functions for hostapd and wpa_supplicant */
 
 static int
-bsd_set80211var(int s, const char *ifname, int op, const void *arg, int arg_len)
+bsd_set80211(void *priv, int op, int val, const void *arg, int arg_len)
 {
+	struct bsd_driver_data *drv = priv;
 	struct ieee80211req ireq;
 
 	os_memset(&ireq, 0, sizeof(ireq));
-	os_strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name));
+	os_strlcpy(ireq.i_name, drv->ifname, sizeof(ireq.i_name));
 	ireq.i_type = op;
+	ireq.i_val = val;
+	ireq.i_data = (void *)arg;
 	ireq.i_len = arg_len;
-	ireq.i_data = (void *) arg;
 
-	if (ioctl(s, SIOCS80211, &ireq) < 0) {
-		fprintf(stderr, "ioctl[SIOCS80211, op %u, len %u]: %s\n",
-			op, arg_len, strerror(errno));
+	if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) {
+		wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, val=%u, "
+			   "arg_len=%u]: %s", op, val, arg_len,
+			   strerror(errno));
 		return -1;
 	}
 	return 0;
 }
 
 static int
-bsd_get80211var(int s, const char *ifname, int op, void *arg, int arg_len)
+bsd_get80211(void *priv, struct ieee80211req *ireq, int op, void *arg,
+	     int arg_len)
 {
-	struct ieee80211req ireq;
-
-	os_memset(&ireq, 0, sizeof(ireq));
-	os_strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name));
-	ireq.i_type = op;
-	ireq.i_len = arg_len;
-	ireq.i_data = arg;
+	struct bsd_driver_data *drv = priv;
 
-	if (ioctl(s, SIOCG80211, &ireq) < 0) {
-		fprintf(stderr, "ioctl[SIOCG80211, op %u, len %u]: %s\n",
-			op, arg_len, strerror(errno));
+	os_memset(ireq, 0, sizeof(*ireq));
+	os_strlcpy(ireq->i_name, drv->ifname, sizeof(ireq->i_name));
+	ireq->i_type = op;
+	ireq->i_len = arg_len;
+	ireq->i_data = arg;
+
+	if (ioctl(drv->sock, SIOCG80211, ireq) < 0) {
+		wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, "
+			   "arg_len=%u]: %s", op, arg_len, strerror(errno));
 		return -1;
 	}
-	return ireq.i_len;
+	return 0;
 }
 
 static int
-bsd_set80211param(int s, const char *ifname, int op, int arg)
+get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len)
 {
 	struct ieee80211req ireq;
 
-	os_memset(&ireq, 0, sizeof(ireq));
-	os_strlcpy(ireq.i_name, ifname, sizeof(ireq.i_name));
-	ireq.i_type = op;
-	ireq.i_val = arg;
-
-	if (ioctl(s, SIOCS80211, &ireq) < 0) {
-		fprintf(stderr, "ioctl[SIOCS80211, op %u, arg 0x%x]: %s\n",
-			op, arg, strerror(errno));
+	if (bsd_get80211(drv, &ireq, op, arg, arg_len) < 0)
 		return -1;
-	}
-	return 0;
-}
-
-static int
-get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len)
-{
-	return bsd_get80211var(drv->sock, drv->ifname, op, arg, arg_len);
+	return ireq.i_len;
 }
 
 static int
 set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len)
 {
-	return bsd_set80211var(drv->sock, drv->ifname, op, arg, arg_len);
+	return bsd_set80211(drv, op, 0, arg, arg_len);
 }
 
 static int
 set80211param(struct bsd_driver_data *drv, int op, int arg)
 {
-	return bsd_set80211param(drv->sock, drv->ifname, op, arg);
+	return bsd_set80211(drv, op, arg, NULL, 0);
 }
 
 static int
@@ -568,22 +558,10 @@
 bsd_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len)
 {
 #ifdef IEEE80211_IOC_APPIE
-	struct bsd_driver_data *drv = priv;
-	struct ieee80211req ireq;
-
-	os_memset(&ireq, 0, sizeof(ireq));
-	os_strlcpy(ireq.i_name, drv->ifname, sizeof(ireq.i_name));
-	ireq.i_type = IEEE80211_IOC_APPIE;
-	ireq.i_val = IEEE80211_APPIE_WPA;
-	ireq.i_data = (void *) ie;
-	ireq.i_len = ie_len;
-
 	wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__,
 		   (unsigned long)ie_len);
-	if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) {
-		perror("Unable to set WPA+RSN ie");
-		return -1;
-	}
+	return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA,
+			    ie, ie_len);
 #endif /* IEEE80211_IOC_APPIE */
 	return 0;
 }
@@ -865,15 +843,8 @@
 {
 	struct ieee80211req ireq;
 
-	os_memset(&ireq, 0, sizeof(ireq));
-	os_strlcpy(ireq.i_name, drv->ifname, sizeof(ireq.i_name));
-	ireq.i_type = op;
-
-	if (ioctl(drv->sock, SIOCG80211, &ireq) < 0) {
-		fprintf(stderr, "ioctl[SIOCG80211, op %u]: %s\n",
-			op, strerror(errno));
+	if (bsd_get80211(drv, &ireq, op, NULL, 0) < 0)
 		return -1;
-	}
 	return ireq.i_val;
 }
 


Regards,
Masashi Honma.



More information about the Hostap mailing list