[PATCH] hostapd: nl80211 adaptation for Red Hat 2.6.18 kernel

Christian Lestrade christian.lestrade at free.fr
Mon Jul 18 11:10:39 EDT 2011


I wrote the following code in order to let hostapd work with Red Hat's
customized 2.6.18 Linux kernel.

It is a matter of using the old nl80211 kernel API for multicast subscription
instead of the new and providing definitions which are not exported by the RHEL
kernel.

Tested OK on a Slackware 11 system with RHEL 2.6.18 kernel compiled from the
sources and with a SMC SMCWCBT-G Cardbus adapter PCI ID 168c:0013

04:00.0 Ethernet controller: Atheros Communications, Inc. AR5212 802.11abg NIC
(rev 01)

--- hostapd-0.7.3/src/drivers/driver_nl80211.c	2010-09-07 17:43:39.000000000
+0200
+++ hostapd-0.7.3-fixed/src/drivers/driver_nl80211.c	2011-07-12
13:00:29.000000000 +0200
@@ -42,6 +42,33 @@
 #define nl_handle_destroy nl_socket_free
 #endif /* CONFIG_LIBNL20 */

+enum {
+	CTRL_ATTR_MCAST_GRP_UNSPEC,
+	CTRL_ATTR_MCAST_GRP_NAME,
+	CTRL_ATTR_MCAST_GRP_ID,
+	__CTRL_ATTR_MCAST_GRP_MAX,
+};
+
+#define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
+#define CTRL_ATTR_MCAST_GROUPS 7
+
+enum nl80211_multicast_groups {
+	/* be notified of configuration changes like wiphy renames */
+	NL80211_GROUP_CONFIG,
+	/* be notified of scan results */
+	NL80211_GROUP_SCAN,
+	/* be notified of regulatory changes */
+	NL80211_GROUP_REGULATORY,
+	/* be notified of MLME events */
+	NL80211_GROUP_MLME,
+
+	/* add groups here */
+
+	/* keep last */
+	__NL80211_GROUP_AFTER_LAST
+};
+#define NL80211_GROUP_MAX (__NL80211_GROUP_AFTER_LAST - 1)
+

 #ifndef IFF_LOWER_UP
 #define IFF_LOWER_UP   0x10000         /* driver signals L1 up         */
@@ -1251,6 +1278,10 @@
 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data *drv,
 				      void *ctx)
 {
+#ifdef DEPRECATED_MEMBERSHIP
+	struct sockaddr_nl mcsa;
+	socklen_t mcsa_size;
+#endif
 	int ret;

 	/* Initialize generic netlink and nl80211 */
@@ -1322,6 +1353,29 @@
 		goto err4;
 	}

+#ifdef DEPRECATED_MEMBERSHIP
+	memset(&mcsa, 0, sizeof(mcsa));
+	mcsa_size = sizeof(mcsa);
+	/* Retrieve socket nl_pid */
+	ret = getsockname(nl_socket_get_fd(drv->nl_handle_event),
+			  (struct sockaddr*)&mcsa, &mcsa_size);
+	if (ret < 0) {
+		wpa_printf(MSG_ERROR, "nl80211: Could not fetch netlink "
+			   "socket PID for musticast events: %d (%s)",
+			   ret, strerror(-ret));
+		goto err4;
+	}
+	mcsa.nl_family = AF_NETLINK;
+	mcsa.nl_groups |= NL80211_GROUP_SCAN | NL80211_GROUP_MLME;
+	ret = bind(nl_socket_get_fd(drv->nl_handle_event),
+		   (struct sockaddr*)&mcsa, sizeof(mcsa));
+	if (ret < 0) {
+		wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
+			   "membership for scan events: %d (%s)",
+			   ret, strerror(-ret));
+		goto err4;
+	}
+#else
 	ret = nl_get_multicast_id(drv, "nl80211", "scan");
 	if (ret >= 0)
 		ret = nl_socket_add_membership(drv->nl_handle_event, ret);
@@ -1341,6 +1395,7 @@
 			   ret, strerror(-ret));
 		goto err4;
 	}
+#endif

 	eloop_register_read_sock(nl_socket_get_fd(drv->nl_handle_event),
 				 wpa_driver_nl80211_event_receive, drv, ctx);
--- hostapd-0.7.3/hostapd/defconfig	2010-09-07 17:43:39.000000000 +0200
+++ hostapd-0.7.3-fixed/hostapd/defconfig	2011-07-12 13:01:36.000000000 +0200
@@ -20,13 +20,14 @@
 #CFLAGS += -I../../madwifi # change to the madwifi source directory

 # Driver interface for drivers using the nl80211 kernel interface
-#CONFIG_DRIVER_NL80211=y
+CONFIG_DRIVER_NL80211=y
 # driver_nl80211.c requires a rather new libnl (version 1.1) which may not be
 # shipped with your distribution yet. If that is the case, you need to build
 # newer libnl version and point the hostapd build to use it.
-#LIBNL=/usr/src/libnl
-#CFLAGS += -I$(LIBNL)/include
-#LIBS += -L$(LIBNL)/lib
+LIBNL=/usr/src/wireless/libnl-2.0
+CFLAGS += -DDEPRECATED_MEMBERSHIP -DCONFIG_LIBNL20 -I$(LIBNL)/include
+CFLAGS += -I/usr/src/linux-2.6.18rh-mki/include
+LIBS += -L$(LIBNL)/lib -lnl-genl -lm

 # Driver interface for FreeBSD net80211 layer (e.g., Atheros driver)
 #CONFIG_DRIVER_BSD=y


Christian Lestrade


More information about the HostAP mailing list