[RFC] hostapd: allow bssid config on default interface

Johannes Berg johannes
Tue Nov 27 13:12:11 PST 2007


This patch makes hostapd accept bssid= on the default interface for
those drivers that are changed to support it and changes
driver_devicescape to support it. In order to support such a setting the
driver must provide an init_bssid() rather than init() routine.

Signed-off-by: Johannes Berg <johannes at sipsolutions.net>
---
So the reason I want this is that I'm lazy and because the default MAC
address of my interface is odd (lowest bit set) hostapd rejects the
configuration if I don't clear that bit by hand... specifying it in the
config file makes it much easier.

Other drivers could easily support it too but again I'm too lazy...

 hostapd/config.c             |    6 ++++--
 hostapd/driver.h             |    9 +++++++++
 hostapd/driver_devicescape.c |   18 ++++++++++++++----
 hostapd/hostapd.c            |    8 +++++++-
 4 files changed, 34 insertions(+), 7 deletions(-)

--- hostap.orig/hostapd/driver.h	2007-11-27 22:05:48.000000000 +0100
+++ hostap/hostapd/driver.h	2007-11-27 22:07:08.000000000 +0100
@@ -23,6 +23,7 @@ struct wpa_driver_ops {
 	const char *name;		/* as appears in the config file */
 
 	void * (*init)(struct hostapd_data *hapd);
+	void * (*init_bssid)(struct hostapd_data *hapd, u8 *bssid);
 	void (*deinit)(void *priv);
 
 	int (*wireless_event_init)(void *priv);
@@ -168,6 +169,14 @@ hostapd_driver_init(struct hostapd_data 
 	return hapd->driver->init(hapd);
 }
 
+static inline void *
+hostapd_driver_init_bssid(struct hostapd_data *hapd, u8 *bssid)
+{
+	if (hapd->driver == NULL || hapd->driver->init_bssid == NULL)
+		return NULL;
+	return hapd->driver->init_bssid(hapd, bssid);
+}
+
 static inline void
 hostapd_driver_deinit(struct hostapd_data *hapd)
 {
--- hostap.orig/hostapd/config.c	2007-11-27 22:05:48.000000000 +0100
+++ hostap/hostapd/config.c	2007-11-27 22:08:51.000000000 +0100
@@ -1887,9 +1887,11 @@ struct hostapd_config * hostapd_config_r
 				errors++;
 			}
 		} else if (strcmp(buf, "bssid") == 0) {
-			if (bss == conf->bss) {
+			if (bss == conf->bss &&
+			    (!conf->driver || !conf->driver->init_bssid)) {
 				printf("Line %d: bssid item not allowed "
-				       "for the default interface\n", line);
+				       "for the default interface and this "
+				       "driver\n", line);
 				errors++;
 			} else if (hwaddr_aton(pos, bss->bssid)) {
 				printf("Line %d: invalid bssid item\n", line);
--- hostap.orig/hostapd/hostapd.c	2007-11-27 22:05:48.000000000 +0100
+++ hostap/hostapd/hostapd.c	2007-11-27 22:07:08.000000000 +0100
@@ -1468,12 +1468,18 @@ static int setup_interface1(struct hosta
 	struct hostapd_bss_config *conf = hapd->conf;
 	size_t i;
 	char country[4];
+	u8 *b = conf->bssid;
 
 	/*
 	 * Initialize the driver interface and make sure that all BSSes get
 	 * configured with a pointer to this driver interface.
 	 */
-	hapd->drv_priv = hostapd_driver_init(hapd);
+	if (b[0] | b[1] | b[2] | b[3] | b[4] | b[5]) {
+		hapd->drv_priv = hostapd_driver_init_bssid(hapd, b);
+	} else {
+		hapd->drv_priv = hostapd_driver_init(hapd);
+	}
+
 	if (hapd->drv_priv == NULL) {
 		printf("%s driver initialization failed.\n",
 			hapd->driver ? hapd->driver->name : "Unknown");
--- hostap.orig/hostapd/driver_devicescape.c	2007-11-27 22:06:17.000000000 +0100
+++ hostap/hostapd/driver_devicescape.c	2007-11-27 22:07:08.000000000 +0100
@@ -1498,7 +1498,7 @@ static void handle_read(int sock, void *
 }
 
 
-static int i802_init_sockets(struct i802_driver_data *drv)
+static int i802_init_sockets(struct i802_driver_data *drv, u8 *bssid)
 {
 	struct hostapd_data *hapd = drv->hapd;
 	struct hostapd_iface *iface = hapd->iface;
@@ -1514,6 +1514,16 @@ static int i802_init_sockets(struct i802
 		return -1;
 	}
 
+	if (hostapd_set_iface_flags(drv, drv->iface, 0))
+		return -1;
+
+	os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
+	memcpy(ifr.ifr_hwaddr.sa_data, bssid, ETH_ALEN);
+	ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+
+	if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifr))
+		return -1;
+
 	/*
 	 * initialise generic netlink and nl80211
 	 */
@@ -1928,7 +1938,7 @@ static int i802_sta_disassoc(void *priv,
 }
 
 
-static void * i802_init(struct hostapd_data *hapd)
+static void *i802_init(struct hostapd_data *hapd, u8 *bssid)
 {
 	struct i802_driver_data *drv;
 
@@ -1941,7 +1951,7 @@ static void * i802_init(struct hostapd_d
 	drv->hapd = hapd;
 	memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
 
-	if (i802_init_sockets(drv))
+	if (i802_init_sockets(drv, bssid))
 		goto failed;
 
 	return drv;
@@ -1978,7 +1988,7 @@ static void i802_deinit(void *priv)
 
 const struct wpa_driver_ops wpa_driver_devicescape_ops = {
 	.name = "devicescape",
-	.init = i802_init,
+	.init_bssid = i802_init,
 	.deinit = i802_deinit,
 	.wireless_event_init = i802_wireless_event_init,
 	.wireless_event_deinit = i802_wireless_event_deinit,






More information about the Hostap mailing list