diff mbox series

[v2,11/22] cfg80211: parse S1G Operation element for BSS channel

Message ID 20200831205600.21058-12-thomas@adapt-ip.com (mailing list archive)
State Superseded
Delegated to: Johannes Berg
Headers show
Series add support for S1G association | expand

Commit Message

Thomas Pedersen Aug. 31, 2020, 8:55 p.m. UTC
Extract the BSS primary channel from the S1G Operation
element.

Signed-off-by: Thomas Pedersen <thomas@adapt-ip.com>
---
 net/wireless/scan.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

Comments

Johannes Berg Sept. 18, 2020, 10:45 a.m. UTC | #1
On Mon, 2020-08-31 at 13:55 -0700, Thomas Pedersen wrote:
> Extract the BSS primary channel from the S1G Operation
> element.

Out of curiosity, do you even need to?

I mean ... you know what channel you received it on, surely?

> @@ -1318,15 +1318,26 @@ cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen,
>  	tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen);
>  	if (tmp && tmp[1] == 1) {
>  		channel_number = tmp[2];
> -	} else {
> -		tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
> -		if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
> -			struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
> +		goto found_channel;
> +	}
>  
> -			channel_number = htop->primary_chan;
> -		}
> +	tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
> +	if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
> +		struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
> +
> +		channel_number = htop->primary_chan;
> +		goto found_channel;
> +	}
> +
> +	tmp = cfg80211_find_ie(WLAN_EID_S1G_OPERATION, ie, ielen);
> +	if (tmp && tmp[1] >= sizeof(struct ieee80211_s1g_oper_ie)) {
> +		struct ieee80211_s1g_oper_ie *s1gop = (void *)(tmp + 2);
> +
> +		channel_number = s1gop->primary_ch;
> +		goto found_channel;
>  	}

I *am* a bit worried about this though - do you really want to try to
parse DS elements on S1G, or S1G elements on other bands? Seems like
there ought to be a band check here?

johannes
Thomas Pedersen Sept. 21, 2020, 5:12 a.m. UTC | #2
On 2020-09-18 03:45, Johannes Berg wrote:
> On Mon, 2020-08-31 at 13:55 -0700, Thomas Pedersen wrote:
>> Extract the BSS primary channel from the S1G Operation
>> element.
> 
> Out of curiosity, do you even need to?
> 
> I mean ... you know what channel you received it on, surely?

Consider the case where the BSS is operating @ 2Mhz, but primary is one 
of
the 1Mhz channels. The hardware (or driver) may not be able to tell you
exactly which primary channel (upper or lower) the packet came in on.

>> @@ -1318,15 +1318,26 @@ cfg80211_get_bss_channel(struct wiphy *wiphy, 
>> const u8 *ie, size_t ielen,
>>  	tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen);
>>  	if (tmp && tmp[1] == 1) {
>>  		channel_number = tmp[2];
>> -	} else {
>> -		tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
>> -		if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
>> -			struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
>> +		goto found_channel;
>> +	}
>> 
>> -			channel_number = htop->primary_chan;
>> -		}
>> +	tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
>> +	if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
>> +		struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
>> +
>> +		channel_number = htop->primary_chan;
>> +		goto found_channel;
>> +	}
>> +
>> +	tmp = cfg80211_find_ie(WLAN_EID_S1G_OPERATION, ie, ielen);
>> +	if (tmp && tmp[1] >= sizeof(struct ieee80211_s1g_oper_ie)) {
>> +		struct ieee80211_s1g_oper_ie *s1gop = (void *)(tmp + 2);
>> +
>> +		channel_number = s1gop->primary_ch;
>> +		goto found_channel;
>>  	}
> 
> I *am* a bit worried about this though - do you really want to try to
> parse DS elements on S1G, or S1G elements on other bands? Seems like
> there ought to be a band check here?

OK. I'll rework this to handle garbage input a little better.
Johannes Berg Sept. 21, 2020, 6:54 a.m. UTC | #3
On Sun, 2020-09-20 at 22:12 -0700, Thomas Pedersen wrote:
> On 2020-09-18 03:45, Johannes Berg wrote:
> > On Mon, 2020-08-31 at 13:55 -0700, Thomas Pedersen wrote:
> > > Extract the BSS primary channel from the S1G Operation
> > > element.
> > 
> > Out of curiosity, do you even need to?
> > 
> > I mean ... you know what channel you received it on, surely?
> 
> Consider the case where the BSS is operating @ 2Mhz, but primary is one 
> of
> the 1Mhz channels. The hardware (or driver) may not be able to tell you
> exactly which primary channel (upper or lower) the packet came in on.

Ah, OK, makes sense. Somehow based on a comment somewhere else I thought
you were saying that the channels are basically all unique in their
(center frequency, bandwidth) tuple, and was assuming you'd actually
have to scan them that way.

johannes
diff mbox series

Patch

diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index b4c85e8f2107..c2dcb9092257 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -1318,15 +1318,26 @@  cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen,
 	tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen);
 	if (tmp && tmp[1] == 1) {
 		channel_number = tmp[2];
-	} else {
-		tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
-		if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
-			struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
+		goto found_channel;
+	}
 
-			channel_number = htop->primary_chan;
-		}
+	tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
+	if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
+		struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
+
+		channel_number = htop->primary_chan;
+		goto found_channel;
+	}
+
+	tmp = cfg80211_find_ie(WLAN_EID_S1G_OPERATION, ie, ielen);
+	if (tmp && tmp[1] >= sizeof(struct ieee80211_s1g_oper_ie)) {
+		struct ieee80211_s1g_oper_ie *s1gop = (void *)(tmp + 2);
+
+		channel_number = s1gop->primary_ch;
+		goto found_channel;
 	}
 
+found_channel:
 	if (channel_number < 0) {
 		/* No channel information in frame payload */
 		return channel;