Skip to contentSkip to conversation

cfg80211: connect/disconnect API

RFC PATCH In review Samuel Ortiz 2 participants 12 messages Jun 22, 2009 – Jun 23, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 cfg80211: connect/disconnect API

This patch introduces the cfg80211 connect/disconnect API. The goal here is to run the AUTH and ASSOC steps in one call. This is needed for some fullmac cards that run both steps directly from the target, after the host driver sends a connect command.
The connect/disconnect API is emulated through the auth/assoc/deauth hooks for the cfg80211 devices that can only provide those.
This API also allows us to move some of the wext calls (ESSID, FREQ and AP) from mac80211 or driver specific wext implementations to the cfg80211 layer.

---
 include/linux/nl80211.h |   11 ++
 include/net/cfg80211.h  |   96 ++++++++++++++++++-
 net/wireless/Makefile   |    4 
 net/wireless/core.c     |   58 ++++++++---
 net/wireless/core.h     |   11 ++
 net/wireless/mlme.c     |   65 ++++++++++++
 net/wireless/nl80211.c  |  217 +++++++++++++++++++++++++++++++++++++++++++
 net/wireless/nl80211.h  |    7 +
 net/wireless/sme.c      |  241 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/wireless/wext-sme.c |  238 +++++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 925 insertions(+), 23 deletions(-)
include/linux/nl80211.h +11 -0
Index: iwm-2.6/include/linux/nl80211.h
===================================================================
@@ -242,6 +242,14 @@
  * @NL80211_CMD_LEAVE_IBSS: Leave the IBSS -- no special arguments, the IBSS is
  *	determined by the network interface.
  *
+ * @NL80211_CMD_CONNECT: connection request and notification; this command
+ *	requests to connect to a specified network but without separating
+ *	auth and assoc steps. It is also sent when the connection is
+ *	established and possibly when the card roamed.
+ * @NL80211_CMD_DISCONNECT: drop a given connection; also used to notify
+ *	userspace that a connection was dropped by the AP or due to other
+ *	reasons.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -310,6 +318,9 @@ enum nl80211_commands {
 	NL80211_CMD_JOIN_IBSS,
 	NL80211_CMD_LEAVE_IBSS,
 
+	NL80211_CMD_CONNECT,
+	NL80211_CMD_DISCONNECT,
+
 	/* add new commands above here */
 
 	/* used to define NL80211_CMD_MAX below */
include/net/cfg80211.h +95 -1

139 lines not on this page · raw message

net/wireless/Makefile +2 -2
Index: iwm-2.6/net/wireless/Makefile
===================================================================
@@ -5,8 +5,8 @@ obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib8
 obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o
 obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o
 
-cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o ibss.o
+cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o ibss.o sme.o
 cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o
-cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o
+cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o wext-sme.o
 
 ccflags-y += -D__CHECK_ENDIAN__
net/wireless/core.h +11 -0
Index: iwm-2.6/net/wireless/core.h
===================================================================
@@ -58,6 +58,8 @@ struct cfg80211_registered_device {
 	struct cfg80211_scan_request *scan_req; /* protected by RTNL */
 	unsigned long suspend_at;
 
+	struct work_struct sme_sm;
+
 #ifdef CONFIG_CFG80211_DEBUGFS
 	/* Debugfs entries */
 	struct wiphy_debugfsdentries {
@@ -170,6 +172,15 @@ void cfg80211_clear_ibss(struct net_devi
 int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
 			struct net_device *dev, bool nowext);
 
+/* SME */
+void cfg80211_sme_work(struct work_struct *work);
+
+int cfg80211_connect(struct cfg80211_registered_device *rdev,
+		     struct net_device *dev,
+		     struct cfg80211_connect_params *connect);
+int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
+			struct net_device *dev, u16 reason);
+
 /* internal helpers */
 int cfg80211_validate_key_settings(struct key_params *params, int key_idx,
 				   const u8 *mac_addr);
net/wireless/nl80211.c +217 -0

241 lines not on this page · raw message

net/wireless/sme.c new file +241 -0

241 lines not on this page · raw message

net/wireless/wext-sme.c new file +238 -0

238 lines not on this page · raw message

net/wireless/mlme.c +61 -4

94 lines not on this page · raw message

net/wireless/core.c +42 -16

108 lines not on this page · raw message

net/wireless/nl80211.h +7 -0
Index: iwm-2.6/net/wireless/nl80211.h
===================================================================
@@ -31,6 +31,13 @@ extern void nl80211_send_auth_timeout(st
 extern void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
 				       struct net_device *netdev,
 				       const u8 *addr);
+void nl80211_send_connected(struct cfg80211_registered_device *rdev,
+			    struct net_device *netdev, const u8 *bssid,
+			    const u8 *ie, size_t ie_len, gfp_t gfp);
+void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
+			       struct net_device *netdev, gfp_t gfp,
+			       u16 reason);
+
 extern void
 nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
 			    struct net_device *netdev, const u8 *addr,
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#1 lore raw

RFC PATCH 2/2 mac80211: connect API port

With the connect()/disconnect() API, some of the mac80211 STA wext hooks can now move to cfg80211.

---
 net/mac80211/cfg.c  |   40 +++++++++++++++++----------
 net/mac80211/mlme.c |   15 ----------
 net/mac80211/wext.c |   76 +++++++++-------------------------------------------
 3 files changed, 39 insertions(+), 92 deletions(-)
net/mac80211/cfg.c +25 -15
Index: iwm-2.6/net/mac80211/cfg.c
===================================================================
@@ -1173,6 +1173,7 @@ static int ieee80211_auth(struct wiphy *
 			  struct cfg80211_auth_request *req)
 {
 	struct ieee80211_sub_if_data *sdata;
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
 
 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 
@@ -1193,12 +1194,20 @@ static int ieee80211_auth(struct wiphy *
 		return -EOPNOTSUPP;
 	}
 
-	memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
-	sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
-	sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
+	if (req->peer_addr) {
+		memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
+		sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
+		sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
+	} else {
+		memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
+		sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
+		sdata->u.mgd.flags &= ~IEEE80211_STA_BSSID_SET;
+	}
 
-	/* TODO: req->chan */
-	sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
+	if (!wdev->channel)
+		sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
+	else
+		sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
 
 	if (req->ssid) {
 		sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
@@ -1220,6 +1229,7 @@ static int ieee80211_auth(struct wiphy *
 
 	sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
 	sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
+
 	ieee80211_sta_req_auth(sdata);
 	return 0;
 }
@@ -1232,27 +1242,26 @@ static int ieee80211_assoc(struct wiphy 
 
 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 
-	if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
-	    !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
+	if ((req->peer_addr &&
+	     memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0) ||
+	     !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
 		return -ENOLINK; /* not authenticated */
 
 	sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
 	sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
 
-	/* TODO: req->chan */
-	sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
-
 	if (req->ssid) {
 		sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
 		memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
 		sdata->u.mgd.ssid_len = req->ssid_len;
 		sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
-	} else
-		sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
+	}
 
-	ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
-	if (ret && ret != -EALREADY)
-		return ret;
+	if (req->ie) {
+		ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
+		if (ret && ret != -EALREADY)
+			return ret;
+	}
 
 	if (req->use_mfp) {
 		sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
@@ -1269,6 +1278,7 @@ static int ieee80211_assoc(struct wiphy 
 
 	sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
 	sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
+
 	ieee80211_sta_req_auth(sdata);
 	return 0;
 }
net/mac80211/wext.c +14 -62

128 lines not on this page · raw message

net/mac80211/mlme.c +0 -15
Index: iwm-2.6/net/mac80211/mlme.c
===================================================================
@@ -868,17 +868,6 @@ static u32 ieee80211_handle_bss_capabili
 	return changed;
 }
 
-static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
-{
-	union iwreq_data wrqu;
-
-	memset(&wrqu, 0, sizeof(wrqu));
-	if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
-		memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
-	wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-	wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
-}
-
 static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
 {
 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
@@ -991,8 +980,6 @@ static void ieee80211_set_associated(str
 
 	netif_tx_start_all_queues(sdata->dev);
 	netif_carrier_on(sdata->dev);
-
-	ieee80211_sta_send_apinfo(sdata);
 }
 
 static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
@@ -1143,8 +1130,6 @@ static void ieee80211_set_disassoc(struc
 	changed |= BSS_CHANGED_ASSOC;
 	sdata->vif.bss_conf.assoc = false;
 
-	ieee80211_sta_send_apinfo(sdata);
-
 	if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
 		ifmgd->state = IEEE80211_STA_MLME_DISABLED;
 		ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
maintainer
#2 lore raw

Re: [PATCH 2/2 RFC] mac80211: connect API port

Quoted 7 lines · Samuel Ortiz

With the connect()/disconnect() API, some of the mac80211 STA wext hooks can now move to cfg80211.

---
 net/mac80211/cfg.c  |   40 +++++++++++++++++----------
 net/mac80211/mlme.c |   15 ----------
---
 net/mac80211/mlme.c |   54 ----------------------------------------------------
 1 file changed, 54 deletions(-)
net/mac80211/mlme.c +0 -54
@@ -868,59 +868,6 @@ static u32 ieee80211_handle_bss_capabili
 	return changed;
 }
 
-static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
-{
-	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
-	char *buf;
-	size_t len;
-	int i;
-	union iwreq_data wrqu;
-
-	if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
-		return;
-
-	buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
-				ifmgd->assocresp_ies_len), GFP_KERNEL);
-	if (!buf)
-		return;
-
-	len = sprintf(buf, "ASSOCINFO(");
-	if (ifmgd->assocreq_ies) {
-		len += sprintf(buf + len, "ReqIEs=");
-		for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
-			len += sprintf(buf + len, "%02x",
-				       ifmgd->assocreq_ies[i]);
-		}
-	}
-	if (ifmgd->assocresp_ies) {
-		if (ifmgd->assocreq_ies)
-			len += sprintf(buf + len, " ");
-		len += sprintf(buf + len, "RespIEs=");
-		for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
-			len += sprintf(buf + len, "%02x",
-				       ifmgd->assocresp_ies[i]);
-		}
-	}
-	len += sprintf(buf + len, ")");
-
-	if (len > IW_CUSTOM_MAX) {
-		len = sprintf(buf, "ASSOCRESPIE=");
-		for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
-			len += sprintf(buf + len, "%02x",
-				       ifmgd->assocresp_ies[i]);
-		}
-	}
-
-	if (len <= IW_CUSTOM_MAX) {
-		memset(&wrqu, 0, sizeof(wrqu));
-		wrqu.data.length = len;
-		wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
-	}
-
-	kfree(buf);
-}
-
-
 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
 				     u32 bss_info_changed)
 {
@@ -953,7 +900,6 @@ static void ieee80211_set_associated(str
 
 	ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
 	memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
-	ieee80211_sta_send_associnfo(sdata);
 
 	ifmgd->last_probe = jiffies;
 	ieee80211_led_assoc(local, 1);
#3 lore raw

Re: [PATCH 2/2 RFC] mac80211: connect API port

Hi Johannes,

Quoted 4 lines · Johannes Berg
Quoted 3 lines · Samuel Ortiz

With the connect()/disconnect() API, some of the mac80211 STA wext hooks can now move to cfg80211.

Quoted 8 lines
Quoted 4 lines
---
 net/mac80211/cfg.c  |   40 +++++++++++++++++----------
 net/mac80211/mlme.c |   15 ----------
---
 net/mac80211/mlme.c |   54 ----------------------------------------------------
 1 file changed, 54 deletions(-)

I thought about this one, but wasnt sure since we're now sending an IWEVASSOCRESPIE event while the current code is sending a custom one. I guess it's fine, just wanted to know if Jouni is fine with it.

Cheers,
Samuel.

Quoted 72 lines
net/mac80211/mlme.c +0 -54
@@ -868,59 +868,6 @@ static u32 ieee80211_handle_bss_capabili
 	return changed;
 }
 
-static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
-{
-	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
-	char *buf;
-	size_t len;
-	int i;
-	union iwreq_data wrqu;
-
-	if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
-		return;
-
-	buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
-				ifmgd->assocresp_ies_len), GFP_KERNEL);
-	if (!buf)
-		return;
-
-	len = sprintf(buf, "ASSOCINFO(");
-	if (ifmgd->assocreq_ies) {
-		len += sprintf(buf + len, "ReqIEs=");
-		for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
-			len += sprintf(buf + len, "%02x",
-				       ifmgd->assocreq_ies[i]);
-		}
-	}
-	if (ifmgd->assocresp_ies) {
-		if (ifmgd->assocreq_ies)
-			len += sprintf(buf + len, " ");
-		len += sprintf(buf + len, "RespIEs=");
-		for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
-			len += sprintf(buf + len, "%02x",
-				       ifmgd->assocresp_ies[i]);
-		}
-	}
-	len += sprintf(buf + len, ")");
-
-	if (len > IW_CUSTOM_MAX) {
-		len = sprintf(buf, "ASSOCRESPIE=");
-		for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
-			len += sprintf(buf + len, "%02x",
-				       ifmgd->assocresp_ies[i]);
-		}
-	}
-
-	if (len <= IW_CUSTOM_MAX) {
-		memset(&wrqu, 0, sizeof(wrqu));
-		wrqu.data.length = len;
-		wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
-	}
-
-	kfree(buf);
-}
-
-
 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
 				     u32 bss_info_changed)
 {
@@ -953,7 +900,6 @@ static void ieee80211_set_associated(str
 
 	ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
 	memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
-	ieee80211_sta_send_associnfo(sdata);
 
 	ifmgd->last_probe = jiffies;
 	ieee80211_led_assoc(local, 1);
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
maintainer
#4 lore raw

Re: [PATCH 2/2 RFC] mac80211: connect API port

Quoted 7 lines · Samuel Ortiz

Hi Johannes,

Quoted 2 lines
 net/mac80211/mlme.c |   54 ----------------------------------------------------
 1 file changed, 54 deletions(-)

I thought about this one, but wasnt sure since we're now sending an IWEVASSOCRESPIE event while the current code is sending a custom one. I guess it's fine, just wanted to know if Jouni is fine with it.

Complicated story, but it boils down to this being ok if (and only if!) we put in the wext compat event patch. If not, we need to send the custom event in cfg80211. Maybe that's safer for now.

johannes

maintainer
#5 lore raw
In reply to Samuel Ortiz
Quoted 11 lines · Samuel Ortiz

/**
+ * struct cfg80211_connect_params - Connection parameters
+ *
+ * This structure provides information needed to complete IEEE 802.11
+ * authentication and association.
+ *
+ * @channel: The channel to use or %NULL if not specified (auto-select based
+ * on scan results)
+ * @bssid: The AP BSSID or %NULL if not specified (auto-select based on scan
+ * results)
+ * @ssid: SSID

Quoted 8 lines

+ * @ssid_len: Length of ssid in octets
+ * @auth_type: Authentication type (algorithm)
+ * @assoc_ie: IEs for association request
+ * @assoc_ie_len: Length of assoc_ie in octets
+ * @control_port: Whether user space controls IEEE 802.1X port, i.e.,
+ * sets/clears %NL80211_STA_FLAG_AUTHORIZED. If true, the driver is
+ * required to assume that the port is unauthorized until authorized by
+ * user space. Otherwise, port is marked authorized by default.

One question I just had -- if bssid is NULL, and the card selects the BSSID, I suppose it will also roam by itself if it can [1]. Don't we need a "roamed" event for that then, even if we're not yet adding a ->roam() call?

johannes

[1] yes, we need to have a way to export roaming capabilities of the card to user space

#6 lore raw
Quoted 22 lines · Johannes Berg
Quoted 11 lines · Samuel Ortiz

/**
+ * struct cfg80211_connect_params - Connection parameters
+ *
+ * This structure provides information needed to complete IEEE 802.11
+ * authentication and association.
+ *
+ * @channel: The channel to use or %NULL if not specified (auto-select based
+ * on scan results)
+ * @bssid: The AP BSSID or %NULL if not specified (auto-select based on scan
+ * results)
+ * @ssid: SSID

Quoted 8 lines

+ * @ssid_len: Length of ssid in octets
+ * @auth_type: Authentication type (algorithm)
+ * @assoc_ie: IEs for association request
+ * @assoc_ie_len: Length of assoc_ie in octets
+ * @control_port: Whether user space controls IEEE 802.1X port, i.e.,
+ * sets/clears %NL80211_STA_FLAG_AUTHORIZED. If true, the driver is
+ * required to assume that the port is unauthorized until authorized by
+ * user space. Otherwise, port is marked authorized by default.

Quoted 4 lines

One question I just had -- if bssid is NULL, and the card selects the BSSID, I suppose it will also roam by itself if it can [1]. Don't we need a "roamed" event for that then, even if we're not yet adding a ->roam() call?

I guess userspace will get 2 events: a disconnect one and then a connect one. Not exactly a "roamed" event though, I agree.

Cheers,
Samuel.

Quoted 4 lines

johannes

[1] yes, we need to have a way to export roaming capabilities of the card to user space

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
maintainer
#7 lore raw
Quoted 6 lines · Samuel Ortiz
Quoted 4 lines

One question I just had -- if bssid is NULL, and the card selects the BSSID, I suppose it will also roam by itself if it can [1]. Don't we need a "roamed" event for that then, even if we're not yet adding a ->roam() call?

I guess userspace will get 2 events: a disconnect one and then a connect one. Not exactly a "roamed" event though, I agree.

Ok, I guess then it needs to distinguish between a disconnect that it caused locally (or some other userspace tool), and a disconnect that the AP caused.

OTOH, I don't think this is appropriate. I think after a disconnect event, the kernel/device should stop doing _anything_. Otherwise we'll, on a smaller scale, repeat the wext problem where you don't know whether the device is currently doing something or not.

johannes

maintainer
#8 lore raw
In reply to Samuel Ortiz

include/net/cfg80211.h void wiphy_rfkill_start_polling(struct w · line 1793

Quoted 9 lines · Samuel Ortiz
include/net/cfg80211.h +9 -0
+/**
+ * cfg80211_connected - notify cfg80211 that connection was dropped
+ *
+ * @dev: network device
+ * @gfp: allocation flags
+ * @reason: reason code for the disconnection, set it to 0 when invalid.
+ *
+ */
+void cfg80211_disconnected(struct net_device *dev, gfp_t gfp, u16 reason);

Shouldn't this also be called, with reason == 0, when a ->disconnect() call has succeeded? Not sure why it can ever fail, but we have to give userspace an event somehow.

net/wireless/sme.c line 161

Quoted 11 lines
net/wireless/sme.c new file +11 -0
+		/*
+		 * Here we cache the assoc request. It will be used
+		 * when the cfg80211 user will call cfg80211_authenticated()
+		 * letting us know that we can move forward and call the
+		 * assoc hook.
+		 */
+		memset(&wdev->assoc_req, 0, sizeof(wdev->assoc_req));
+		if (connect->channel)
+			wdev->assoc_req.chan = kmemdup(connect->channel,
+					       sizeof(struct ieee80211_channel),
+						       GFP_ATOMIC);

??
->channel always points into the registered channels, that can't go stale until the wiphy is killed.

net/wireless/sme.c line 165

Quoted 4 lines
net/wireless/sme.c new file +4 -0
+		if (connect->bssid)
+			wdev->assoc_req.peer_addr = kmemdup(connect->bssid,
+							    ETH_ALEN,
+							    GFP_ATOMIC);

just point it to wdev->bssid?

net/wireless/sme.c line 169

Quoted 4 lines
net/wireless/sme.c new file +4 -0
+		wdev->assoc_req.ssid = kmemdup(connect->ssid,
+					       connect->ssid_len,
+					       GFP_ATOMIC);
+		wdev->assoc_req.ssid_len = connect->ssid_len;

wdev->ssid?

net/wireless/sme.c line 173

Quoted 4 lines
net/wireless/sme.c new file +4 -0
+		if (connect->ie)
+			wdev->assoc_req.ie = kmemdup(connect->ie,
+						     connect->ie_len,
+						     GFP_ATOMIC);

Yes, this needs to be kmemdup'ed :) I don't think it needs GFP_ATOMIC though? This should only be called from nl80211 or wext, i.e. in process context.

net/wireless/sme.c line 238

Quoted 7 lines
net/wireless/sme.c new file +7 -0
+	wdev->current_bss = NULL;
+	wdev->ssid_len = 0;
+	memset(wdev->bssid, 0, ETH_ALEN);
+	kfree(wdev->assoc_req.chan);
+	kfree(wdev->assoc_req.peer_addr);
+	kfree(wdev->assoc_req.ssid);
+	kfree(wdev->assoc_req.ie);

Better set = NULL too, since you don't set = NULL in _connect() if the parameter isn't present.

Quoted 8 lines

void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len) {

net/wireless/mlme.c +4 -1
-	struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
+	u16 status_code;
+	struct ieee80211_mgmt *mgmt;
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct wiphy *wiphy = wdev->wiphy;
 	struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);

net/wireless/mlme.c line 53

Quoted 10 lines
net/wireless/mlme.c +9 -0
+
+	mgmt = (struct ieee80211_mgmt *)buf;
+	status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
+
 	nl80211_send_rx_assoc(rdev, dev, buf, len);
+
+	if (status_code != WLAN_STATUS_SUCCESS)
+		wdev->sme_state = CFG80211_SME_AUTH;
+	else {
+		u8 *ie = mgmt->u.assoc_resp.variable;

I wonder if we should give up, if non-successful auth? Wouldn't this retry again and again? Well I guess you don't queue the work, but if another interface causes it to be queued... so I guess we need to retry, or something, but only a limited number of times? Not sure really.

Quoted 9 lines

void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len) {

net/wireless/mlme.c +4 -1
-	struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct wiphy *wiphy = wdev->wiphy;
 	struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
+
 	nl80211_send_deauth(rdev, dev, buf, len);
+

net/wireless/mlme.c line 80

Quoted 10 lines
net/wireless/mlme.c +10 -0
+	if (wdev->sme_state == CFG80211_SME_CONNECTED ||
+	    wdev->sme_state == CFG80211_SME_ASSOC) {
+		u16 reason_code;
+		struct ieee80211_mgmt *mgmt;
+
+		mgmt = (struct ieee80211_mgmt *)buf;
+		reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
+
+		cfg80211_disconnected(dev, GFP_ATOMIC, reason_code);
+	}

This might be interesting -- you could get a disconnected event without ever asking for connected. But that indicates we need yet another event:
"I've given up on connect"?

Quoted 10 lines

EXPORT_SYMBOL(cfg80211_send_deauth);

void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len) {

net/wireless/mlme.c +3 -1
-	struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
+	struct wiphy *wiphy = wdev->wiphy;
 	struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
+
 	nl80211_send_disassoc(rdev, dev, buf, len);

net/wireless/mlme.c line 100

Quoted 10 lines
net/wireless/mlme.c +10 -0
+
+	if (wdev->sme_state == CFG80211_SME_CONNECTED) {
+		u16 reason_code;
+		struct ieee80211_mgmt *mgmt;
+
+		mgmt = (struct ieee80211_mgmt *)buf;
+		reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
+
+		cfg80211_disconnected(dev, GFP_ATOMIC, reason_code);
+	}

I suspect it needs to be valid to call this without a frame, if you just get that indication from firmware somehow. However, then there's no reason code to pass. Maybe we just need a second exported symbol in that case and not worry about it now. Doesn't need to be perfect, after all :)

Quoted 94 lines

EXPORT_SYMBOL(cfg80211_send_disassoc);

Index: iwm-2.6/net/wireless/core.c
===================================================================

net/wireless/core.c +33 -12
@@ -321,6 +321,7 @@ struct wiphy *wiphy_new(const struct cfg
 	}
 
 	INIT_WORK(&drv->rfkill_sync, cfg80211_rfkill_sync_work);
+	INIT_WORK(&drv->sme_sm, cfg80211_sme_work);
 
 	/*
 	 * Initialize wiphy parameters to IEEE 802.11 MIB default values.
@@ -481,6 +482,8 @@ void wiphy_unregister(struct wiphy *wiph
 	/* unlock again before freeing */
 	mutex_unlock(&drv->mtx);
 
+	cancel_work_sync(&drv->sme_sm);
+
 	cfg80211_debugfs_drv_del(drv);
 
 	/* If this device got a regulatory hint tell core its
@@ -526,54 +529,77 @@ static int cfg80211_netdev_notifier_call
 					 void *ndev)
 {
 	struct net_device *dev = ndev;
+	struct wireless_dev *wdev = dev->ieee80211_ptr;
 	struct cfg80211_registered_device *rdev;
 
-	if (!dev->ieee80211_ptr)
+	if (!wdev)
 		return NOTIFY_DONE;
 
-	rdev = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
+	rdev = wiphy_to_dev(wdev->wiphy);
 
-	WARN_ON(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_UNSPECIFIED);
+	WARN_ON(wdev->iftype == NL80211_IFTYPE_UNSPECIFIED);
 
 	switch (state) {
 	case NETDEV_REGISTER:
 		mutex_lock(&rdev->devlist_mtx);
-		list_add(&dev->ieee80211_ptr->list, &rdev->netdev_list);
+		list_add(&wdev->list, &rdev->netdev_list);
 		if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
 				      "phy80211")) {
 			printk(KERN_ERR "wireless: failed to add phy80211 "
 				"symlink to netdev!\n");
 		}
-		dev->ieee80211_ptr->netdev = dev;
+		wdev->netdev = dev;
+		wdev->sme_state = CFG80211_SME_IDLE;
+
 #ifdef CONFIG_WIRELESS_EXT
-		dev->ieee80211_ptr->wext.default_key = -1;
-		dev->ieee80211_ptr->wext.default_mgmt_key = -1;
+		wdev->wext.default_key = -1;
+		wdev->wext.default_mgmt_key = -1;
 #endif
 		mutex_unlock(&rdev->devlist_mtx);
 		break;
 	case NETDEV_GOING_DOWN:
-		if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
+		if (!wdev->ssid_len)
+			break;
+
+		switch (wdev->iftype) {
+		case NL80211_IFTYPE_ADHOC:
+			cfg80211_leave_ibss(rdev, dev, true);
+			break;
+		case NL80211_IFTYPE_STATION:
+			cfg80211_disconnect(rdev, dev,
+					    WLAN_REASON_DEAUTH_LEAVING);
 			break;
-		if (!dev->ieee80211_ptr->ssid_len)
+		default:
 			break;
-		cfg80211_leave_ibss(rdev, dev, true);
+		}
+
 		break;
 	case NETDEV_UP:
 #ifdef CONFIG_WIRELESS_EXT
-		if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
+		switch (wdev->iftype) {
+		case NL80211_IFTYPE_ADHOC:
+			if (wdev->wext.ibss.ssid_len &&
+			    cfg80211_join_ibss(rdev, dev, &wdev->wext.ibss))
+				return NOTIFY_STOP;
 			break;
-		if (!dev->ieee80211_ptr->wext.ibss.ssid_len)
+		case NL80211_IFTYPE_STATION:
+			if (wdev->wext.connect.ssid_len &&

net/wireless/core.c static int cfg80211_netdev_notifier_call · line 594

Quoted 10 lines
net/wireless/core.c +6 -2
+			    cfg80211_connect(rdev, dev, &wdev->wext.connect))
+				return NOTIFY_STOP;
 			break;
-		cfg80211_join_ibss(rdev, dev, &dev->ieee80211_ptr->wext.ibss);
-		break;
+		default:
+			break;
+		}
 #endif
+		break;

Wow, that fixes a bad bug if you don't have wext configured. Good thing that's currently pretty much impossible.

Thanks!

johannes

maintainer
#9 lore raw
In reply to Samuel Ortiz
[  176.185771] WARNING: at /home/johannes/sys/wireless-testing/net/wireless/sme.c:46 cfg80211_connected+0x149/0x150()
[  176.197900] Hardware name: 
[  176.202752] Pid: 468, comm: phy1 Tainted: G        W  2.6.30-wl #71
[  176.209012] Call Trace:
[  176.218526]  [<ffffffff8024ae93>] warn_slowpath_common+0x73/0xc0
[  176.219258]  [<ffffffff8024aeef>] warn_slowpath_null+0xf/0x20
[  176.219966]  [<ffffffff805a58f9>] cfg80211_connected+0x149/0x150
[  176.221854]  [<ffffffff805a5136>] cfg80211_send_rx_assoc+0x96/0xa0
[  176.226272]  [<ffffffff805b28ec>] ieee80211_rx_mgmt_assoc_resp+0x71c/0x8a0

johannes

maintainer
#10 lore raw
In reply to Samuel Ortiz

And this, symmetric to the first one:

[  302.975063] WARNING: at /home/johannes/sys/wireless-testing/net/wireless/sme.c:95 cfg80211_disconnected+0x9d/0xc0()
[  302.976435] Hardware name: 
[  302.976869] Pid: 1321, comm: wpa_supplicant Tainted: G        W  2.6.30-wl #71
[  302.977819] Call Trace:
[  302.980113]  [<ffffffff8024ae93>] warn_slowpath_common+0x73/0xc0
[  302.981529]  [<ffffffff8024aeef>] warn_slowpath_null+0xf/0x20
[  302.982356]  [<ffffffff805a578d>] cfg80211_disconnected+0x9d/0xc0
[  302.983205]  [<ffffffff805a5092>] cfg80211_send_deauth+0x72/0x80
[  302.995239]  [<ffffffff805af634>] ieee80211_send_deauth_disassoc+0x144/0x160
[  303.005284]  [<ffffffff805af7e5>] ieee80211_set_disassoc+0x195/0x3d0
[  303.023982]  [<ffffffff805afac2>] ieee80211_sta_deauthenticate+0x42/0x50
[  303.027995]  [<ffffffff805b6ef7>] ieee80211_deauth+0x17/0x20
[  303.028830]  [<ffffffff8059dd7b>] nl80211_deauthenticate+0x14b/0x160

johannes

maintainer
#11 lore raw
In reply to Samuel Ortiz

Also, something seems to be wrong with the IEs:

hostapd says:
STA 02:00:00:00:01:00: No WPA/RSN IE in association request

and the client gets:

[  469.426983] wlan1: RX AssocResp from 00:11:24:91:07:4d (capab=0x411 status=40 aid=0)
[  469.428119] wlan1: AP denied association (code=40)

johannes