Re: [PATCH] cfg80211: Allow cfg80211_connect_result() errors to be distinguished

2016-05-31 Thread Johannes Berg
On Tue, 2016-05-31 at 00:16 +0300, Jouni Malinen wrote:
> Previously, the status parameter to cfg80211_connect_result() was
> documented as using WLAN_STATUS_UNSPECIFIED_FAILURE (1) when the real
> status code for the failure is not known. This value can be used by
> an
> AP (and often is) and as such, user space cannot distinguish between
> explicitly rejected authentication/association and not being able to
> even try to associate or not receiving a response from the AP.
> 
> Add a new inline function, cfg80211_connect_timeout(), to be used
> when
> the driver knows that the connection attempt failed due to a reason
> where connection could not be attempt or no response was received
> from
> the AP. The internal functions now allow a negative status value (-1) 
> to
> be used as an indication of this special case. This results in the
> NL80211_ATTR_TIMED_OUT to be added to the NL80211_CMD_CONNECT event
> to
> allow user space to determine this case was hit. For backwards
> compatibility, NL80211_STATUS_CODE with the value
> WLAN_STATUS_UNSPECIFIED_FAILURE is still indicated in the event in
> such
> a case.
> 
Applied, with a fix to the cfg80211_connect_bss() prototype.

I also added cfg80211_connect_timeout to the docbook.

johannes
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cfg80211: Allow cfg80211_connect_result() errors to be distinguished

2016-05-30 Thread Jouni Malinen
Previously, the status parameter to cfg80211_connect_result() was
documented as using WLAN_STATUS_UNSPECIFIED_FAILURE (1) when the real
status code for the failure is not known. This value can be used by an
AP (and often is) and as such, user space cannot distinguish between
explicitly rejected authentication/association and not being able to
even try to associate or not receiving a response from the AP.

Add a new inline function, cfg80211_connect_timeout(), to be used when
the driver knows that the connection attempt failed due to a reason
where connection could not be attempt or no response was received from
the AP. The internal functions now allow a negative status value (-1) to
be used as an indication of this special case. This results in the
NL80211_ATTR_TIMED_OUT to be added to the NL80211_CMD_CONNECT event to
allow user space to determine this case was hit. For backwards
compatibility, NL80211_STATUS_CODE with the value
WLAN_STATUS_UNSPECIFIED_FAILURE is still indicated in the event in such
a case.

Signed-off-by: Jouni Malinen 
---
 include/net/cfg80211.h   | 54 ++--
 include/uapi/linux/nl80211.h |  7 +-
 net/wireless/core.h  |  4 ++--
 net/wireless/nl80211.c   |  7 --
 net/wireless/nl80211.h   |  2 +-
 net/wireless/sme.c   |  6 ++---
 6 files changed, 58 insertions(+), 22 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 58cdd42..b60c244 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2367,19 +2367,26 @@ struct cfg80211_qos_map {
  * (invoked with the wireless_dev mutex held)
  *
  * @connect: Connect to the ESS with the specified parameters. When connected,
- * call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
- * If the connection fails for some reason, call cfg80211_connect_result()
- * with the status from the AP. The driver is allowed to roam to other
- * BSSes within the ESS when the other BSS matches the connect parameters.
- * When such roaming is initiated by the driver, the driver is expected to
- * verify that the target matches the configured security parameters and
- * to use Reassociation Request frame instead of Association Request frame.
- * The connect function can also be used to request the driver to perform
- * a specific roam when connected to an ESS. In that case, the prev_bssid
+ * call cfg80211_connect_result()/cfg80211_connect_bss() with status code
+ * %WLAN_STATUS_SUCCESS. If the connection fails for some reason, call
+ * cfg80211_connect_result()/cfg80211_connect_bss() with the status code
+ * from the AP or cfg80211_connect_timeout() if no frame with status code
+ * was received.
+ *
+ * The driver is allowed to roam to other BSSes within the ESS when the
+ * other BSS matches the connect parameters. When such roaming is initiated
+ * by the driver, the driver is expected to verify that the target matches
+ * the configured security parameters and to use Reassociation Request
+ * frame instead of Association Request frame.
+ *
+ * The connect function can also be used to request the driver to perform a
+ * specific roam when connected to an ESS. In that case, the prev_bssid
  * parameter is set to the BSSID of the currently associated BSS as an
- * indication of requesting reassociation. In both the driver-initiated and
- * new connect() call initiated roaming cases, the result of roaming is
- * indicated with a call to cfg80211_roamed() or cfg80211_roamed_bss().
+ * indication of requesting reassociation.
+ *
+ * In both the driver-initiated and new connect() call initiated roaming
+ * cases, the result of roaming is indicated with a call to
+ * cfg80211_roamed() or cfg80211_roamed_bss().
  * (invoked with the wireless_dev mutex held)
  * @disconnect: Disconnect from the BSS/ESS.
  * (invoked with the wireless_dev mutex held)
@@ -4736,6 +4743,29 @@ cfg80211_connect_result(struct net_device *dev, const u8 
*bssid,
 }
 
 /**
+ * cfg80211_connect_timeout - notify cfg80211 of connection timeout
+ *
+ * @dev: network device
+ * @bssid: the BSSID of the AP
+ * @req_ie: association request IEs (maybe be %NULL)
+ * @req_ie_len: association request IEs length
+ * @gfp: allocation flags
+ *
+ * It should be called by the underlying driver whenever connect() has failed
+ * in a sequence where no explicit authentication/association rejection was
+ * received from the AP. This could happen, e.g., due to not being able to send
+ * out the Authentication or Association Request frame or timing out while
+ * waiting for the response.
+ */
+static inline void
+cfg80211_connect_timeout(struct net_device *dev, const u8 *bssid,
+const u8 *req_ie, size_t req_ie_len, gfp_t gfp)
+{
+   cfg80211_connect_bss(dev, bssid, NULL, req_ie, req_ie_len, NULL, 0, -1,
+gfp);