Patchwork nl80211: explicitly pass mode setting when initialising interface

login
register
mail settings
Submitter Johannes Berg
Date April 22, 2013, 2:06 p.m.
Message ID <1366639614-5466-1-git-send-email-johannes@sipsolutions.net>
Download mbox | patch
Permalink /patch/238542/
State Rejected
Headers show

Comments

Johannes Berg - April 22, 2013, 2:06 p.m.
From: Johannes Berg <johannes.berg@intel.com>

When wpa_driver_nl80211_finish_drv_init() is called, require the
caller to explicitly give the new nlmode, or NL80211_IFTYPE_UNSPECIFIED
if it shouldn't be changed.

Change-Id: Ifd46ae9c7e353d4d3e18988e4dd6cd267d647163
Signed-hostap: Johannes Berg <johannes.berg@intel.com>
---
 src/drivers/driver_nl80211.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
Johannes Berg - April 22, 2013, 2:07 p.m.
On Mon, 2013-04-22 at 16:06 +0200, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> When wpa_driver_nl80211_finish_drv_init() is called, require the
> caller to explicitly give the new nlmode, or NL80211_IFTYPE_UNSPECIFIED
> if it shouldn't be changed.
> 
> Change-Id: Ifd46ae9c7e353d4d3e18988e4dd6cd267d647163

Oops, can you edit that out please?

johannes
Johannes Berg - April 23, 2013, 12:08 p.m.
On Mon, 2013-04-22 at 16:06 +0200, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> When wpa_driver_nl80211_finish_drv_init() is called, require the
> caller to explicitly give the new nlmode, or NL80211_IFTYPE_UNSPECIFIED
> if it shouldn't be changed.

Oops, no, this doesn't work... the ifindex isn't assigned where I use
it!

johannes

Patch

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 3b0dba4..88956d9 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -299,7 +299,8 @@  static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx,
 static int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
 				       enum nl80211_iftype nlmode);
 static int
-wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv);
+wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
+				   enum nl80211_iftype nlmode);
 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
 				   const u8 *addr, int cmd, u16 reason_code,
 				   int local_state_change);
@@ -859,7 +860,10 @@  static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
 		drv->first_bss.ifindex = if_nametoindex(drv->first_bss.ifname);
 		wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
 			   "interface");
-		wpa_driver_nl80211_finish_drv_init(drv);
+		wpa_driver_nl80211_finish_drv_init(drv,
+			drv->ifindex != drv->global->if_add_ifindex ?
+				NL80211_IFTYPE_STATION :
+				NL80211_IFTYPE_UNSPECIFIED);
 		return 1;
 	}
 
@@ -3314,7 +3318,10 @@  static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
 		os_free(rcfg);
 	}
 
-	if (wpa_driver_nl80211_finish_drv_init(drv))
+	if (wpa_driver_nl80211_finish_drv_init(drv,
+			drv->ifindex != drv->global->if_add_ifindex ?
+				NL80211_IFTYPE_STATION :
+				NL80211_IFTYPE_UNSPECIFIED);
 		goto failed;
 
 	drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
@@ -3609,7 +3616,8 @@  static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
 
 
 static int
-wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
+wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
+				   enum nl80211_iftype nlmode)
 {
 	struct i802_bss *bss = &drv->first_bss;
 	int send_rfkill_event = 0;
@@ -3623,10 +3631,10 @@  wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
 	 * dynamically added interface (e.g., P2P) that was already configured
 	 * with proper iftype.
 	 */
-	if (drv->ifindex != drv->global->if_add_ifindex &&
-	    wpa_driver_nl80211_set_mode(bss, NL80211_IFTYPE_STATION) < 0) {
+	if (nlmode != NL80211_IFTYPE_UNSPECIFIED &&
+	    wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
 		wpa_printf(MSG_ERROR, "nl80211: Could not configure driver to "
-			   "use managed mode");
+			   "use mode %d", nlmode);
 		return -1;
 	}