[PATCH 1/2] hostapd: allow using driver-generated iface addresses

Eliad Peller eliad at wizery.com
Sun Mar 6 01:42:37 PST 2016


Add a new 'use_driver_iface_addr' configuration parameter
to allow using the default interface address generated
by the driver on interface creation.

This can be useful when specific mac addresses were allocated
to the device and we want to use them for multi-bss operation.

Signed-off-by: Eliad Peller <eliad at wizery.com>
---
 hostapd/config_file.c |  2 ++
 hostapd/hostapd.conf  |  4 ++++
 src/ap/ap_config.h    |  3 +++
 src/ap/hostapd.c      | 25 ++++++++++++++++++-------
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index a157a74..6f525d9 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -2826,6 +2826,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
 				   line);
 			return 1;
 		}
+	} else if (os_strcmp(buf, "use_driver_iface_addr") == 0) {
+		conf->use_driver_iface_addr = atoi(pos);
 #ifdef CONFIG_IEEE80211W
 	} else if (os_strcmp(buf, "ieee80211w") == 0) {
 		bss->ieee80211w = atoi(pos);
diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
index 3d5c5e2..bcc7552 100644
--- a/hostapd/hostapd.conf
+++ b/hostapd/hostapd.conf
@@ -1926,6 +1926,10 @@ own_ip_addr=127.0.0.1
 # - is not the same as the MAC address of the radio
 # - is not the same as any other explicitly specified BSSID
 #
+# Alternatively, the 'use_driver_iface_addr' param can be used in order
+# to ask hostapd to use the driver auto-generated interface address (e.g. in
+# order to use the exact mac addresses allocated to the device).
+#
 # Not all drivers support multiple BSSes. The exact mechanism for determining
 # the driver capabilities is driver specific. With the current (i.e., a recent
 # kernel) drivers using nl80211, this information can be checked with "iw list"
diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
index f19cac6..6aeed7e 100644
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
@@ -665,6 +665,9 @@ struct hostapd_config {
 	u8 vht_oper_centr_freq_seg0_idx;
 	u8 vht_oper_centr_freq_seg1_idx;
 
+	/* use driver-generated iface addresses when adding multiple BSSIDs */
+	u8 use_driver_iface_addr;
+
 #ifdef CONFIG_FST
 	struct fst_iface_cfg fst_cfg;
 #endif /* CONFIG_FST */
diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
index 9aaa9a6..7c3fcd5 100644
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -512,6 +512,9 @@ static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
 	if (hostapd_drv_none(hapd))
 		return 0;
 
+	if (iface->conf->use_driver_iface_addr)
+		return 0;
+
 	/* Generate BSSID mask that is large enough to cover the BSSIDs. */
 
 	/* Determine the bits necessary to cover the number of BSSIDs. */
@@ -905,12 +908,9 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
 	hapd->started = 1;
 
 	if (!first || first == -1) {
-		if (is_zero_ether_addr(conf->bssid)) {
-			/* Allocate the next available BSSID. */
-			do {
-				inc_byte_array(hapd->own_addr, ETH_ALEN);
-			} while (mac_in_conf(hapd->iconf, hapd->own_addr));
-		} else {
+		u8 *addr = hapd->own_addr;
+
+		if (!is_zero_ether_addr(conf->bssid)) {
 			/* Allocate the configured BSSID. */
 			os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
 
@@ -922,11 +922,18 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
 					   "the radio", conf->iface);
 				return -1;
 			}
+		} else if (hapd->iconf->use_driver_iface_addr) {
+			addr = NULL;
+		} else {
+			/* Allocate the next available BSSID. */
+			do {
+				inc_byte_array(hapd->own_addr, ETH_ALEN);
+			} while (mac_in_conf(hapd->iconf, hapd->own_addr));
 		}
 
 		hapd->interface_added = 1;
 		if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
-				   conf->iface, hapd->own_addr, hapd,
+				   conf->iface, addr, hapd,
 				   &hapd->drv_priv, force_ifname, if_addr,
 				   conf->bridge[0] ? conf->bridge : NULL,
 				   first == -1)) {
@@ -935,6 +942,10 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
 			hapd->interface_added = 0;
 			return -1;
 		}
+
+		if (!addr) {
+			os_memcpy(hapd->own_addr, if_addr, ETH_ALEN);
+		}
 	}
 
 	if (conf->wmm_enabled < 0)
-- 
2.6.3




More information about the Hostap mailing list