d80211: Don't discriminate against 802.11b drivers
Subsystems (2)
PATCH 1/1 d80211: Don't discriminate against 802.11b drivers
This makes the current hack used to prevent 802.11g cards from scanning with 802.11b channels not break scanning in 802.11b drivers.
net/d80211/ieee80211_sta.c +1 -1
@@ -2566,7 +2566,7 @@ int ieee80211_sta_req_scan(struct net_dememcpy (local->scan_ssid, ssid, ssid_len); }else local->scan_ssid_len =0 ; - local->scan_skip_11b =1 ;/* FIX: clear this is 11g is not supported */ + local->scan_skip_11b = local->hw->num_modes >1 ; local->scan_state =SCAN_SET_CHANNEL ; local->scan_hw_mode_idx =0 ; local->scan_channel_idx =0 ;
Quoted 2 lines · Michael Wu
This makes the current hack used to prevent 802.11g cards from scanning with 802.11b channels not break scanning in 802.11b drivers.
I think this should be better:
---
net/d80211/ieee80211.c | 14 ++++++++++++++ net/d80211/ieee80211_sta.c | 1 - 2 files changed, 14 insertions(+), 1 deletion(-)
net/d80211/ieee80211.c +14 -0
@@ -4014,6 +4014,19 @@ static void ieee80211_precalc_rates(stru } } +static inline void ieee80211_apply_modes (struct ieee80211_hw *hw, +struct ieee80211_local *local) +{ +struct ieee80211_hw_modes *mode; +int i; + + local->scan_skip_11b =0 ; +for (i =0 ; i < hw->num_modes; i++) { + mode = &hw->modes[i]; +if (mode->mode ==MODE_IEEE80211G ) + local->scan_skip_11b =1 ; + } +}struct net_device *ieee80211_alloc_hw (size_t priv_data_len,void (*setup)(struct net_device *))
@@ -4258,6 +4271,7 @@ int ieee80211_update_hw(struct net_devicreturn -1 ;ieee80211_precalc_rates (hw); +ieee80211_apply_modes (hw, local); local->conf.phymode = hw->modes[0 ].mode; local->curr_rates = hw->modes[0 ].rates; local->num_curr_rates = hw->modes[0 ].num_rates;
net/d80211/ieee80211_sta.c +0 -1
@@ -2566,7 +2566,6 @@ int ieee80211_sta_req_scan(struct net_dememcpy (local->scan_ssid, ssid, ssid_len); }else local->scan_ssid_len =0 ; - local->scan_skip_11b =1 ;/* FIX: clear this is 11g is not supported */ local->scan_state =SCAN_SET_CHANNEL ; local->scan_hw_mode_idx =0 ; local->scan_channel_idx =0 ;
Signature · 2 lines
Jiri Benc SUSE Labs
Quoted 17 lines · you
Quoted 2 lines · Michael Wu
This makes the current hack used to prevent 802.11g cards from scanning with 802.11b channels not break scanning in 802.11b drivers.
I think this should be better:
Signed-off-by Jiri Benc <[email protected]>---
net/d80211/ieee80211.c | 14 ++++++++++++++ net/d80211/ieee80211_sta.c | 1 - 2 files changed, 14 insertions(+), 1 deletion(-)
net/d80211/ieee80211.c static void ieee80211_precalc_rates(stru · line 4018
Quoted 5 lines
net/d80211/ieee80211.c +2
-0@@ -4014,6 +4014,19 @@ static void ieee80211_precalc_rates(stru } } +static inline void ieee80211_apply_modes (struct ieee80211_hw *hw, +struct ieee80211_local *local)
Just a minor nitpick, but please remove the "inline".
This is a candidate for binary bloat, if it is called later on another place, too, and modern compilers will inline it anyway, if only used once.
Additionally it is not a hotpath.
Quoted 34 lines
net/d80211/ieee80211.c +12
-0+{ +struct ieee80211_hw_modes *mode; +int i; + + local->scan_skip_11b =0 ; +for (i =0 ; i < hw->num_modes; i++) { + mode = &hw->modes[i]; +if (mode->mode ==MODE_IEEE80211G ) + local->scan_skip_11b =1 ; + } +}struct net_device *ieee80211_alloc_hw (size_t priv_data_len,void (*setup)(struct net_device *))@@ -4258,6 +4271,7 @@ int ieee80211_update_hw(struct net_devicreturn -1 ;ieee80211_precalc_rates (hw); +ieee80211_apply_modes (hw, local); local->conf.phymode = hw->modes[0 ].mode; local->curr_rates = hw->modes[0 ].rates; local->num_curr_rates = hw->modes[0 ].num_rates;net/d80211/ieee80211_sta.c +0
-1@@ -2566,7 +2566,6 @@ int ieee80211_sta_req_scan(struct net_dememcpy (local->scan_ssid, ssid, ssid_len); }else local->scan_ssid_len =0 ; - local->scan_skip_11b =1 ;/* FIX: clear this is 11g is not supported */ local->scan_state =SCAN_SET_CHANNEL ; local->scan_hw_mode_idx =0 ; local->scan_channel_idx =0 ;
Signature · 1 line
Greetings Michael.
Quoted 6 lines · Jiri Benc
Quoted 2 lines · Michael Wu
This makes the current hack used to prevent 802.11g cards from scanning with 802.11b channels not break scanning in 802.11b drivers.
I think this should be better:
I think this is overkill to fix a hack. IMHO, scan_skip_11b shouldn't exist in the first place. One alternative would be to modify 802.11g drivers to not set IEEE80211_CHAN_W_SCAN on 802.11b channels when there are equivalent 802.11g channels. Another would be to set the local->hw_modes bitfield correctly during driver initialization instead of relying on userspace to set it, so the existing logic for avoiding 802.11b channels when 802.11g is supported actually works.
Hmm... that ioctl for changing the hw_modes bitfield doesn't seem too good.. No validity checking at all .. but then again, the current value of hw_modes isn't valid to begin with. It seems like hw_modes is more useful for saying what modes shouldn't be used than saying what modes are supported by the hardware and should be used.
-Michael Wu
Quoted 4 lines · Michael Wu
I think this is overkill to fix a hack. IMHO,
scan_skip_11bshouldn't exist in the first place. One alternative would be to modify 802.11g drivers to not setIEEE80211_CHAN_W_SCANon 802.11b channels when there are equivalent 802.11g channels.
This won't work when 11g is administratively disabled. We can surely add another flags; but I'm not sure if it is really desirable to require drivers to be aware of this when it is easily determinable by the stack.
Quoted 3 lines
It seems like
hw_modesis more useful for saying
what modes shouldn't be used than saying what modes are supported by the hardware and should be used.
This is exactly the purpose of hw_modes. This also means you don't need any validation.
Jiri
Signature · 2 lines
Jiri Benc SUSE Labs
Quoted 7 lines · you
Quoted 3 lines
It seems like
hw_modesis more useful for saying
what modes shouldn't be used than saying what modes are supported by the hardware and should be used.This is exactly the purpose of
hw_modes. This also means you don't need any validation.
Hm, so why not add something that will tell you what modes are supported by the hardware?
Only problem with this patch is if the hardware adds any modes after registration, they will be disabled initially. Hopefully, no drivers will actually need to do that.
net/d80211/ieee80211.c +7 -2
@@ -3999,19 +3999,24 @@ void ieee80211_if_setup(struct net_devic } -static void ieee80211_precalc_rates (struct ieee80211_hw *hw) +static void ieee80211_precalc_modes (struct ieee80211_hw *hw, +struct ieee80211_local *local) {struct ieee80211_hw_modes *mode;struct ieee80211_rate *rate;int m, r; + local->valid_hw_modes =0 ;for (m =0 ; m < hw->num_modes; m++) { mode = &hw->modes[m]; + local->valid_hw_modes |=1 << mode->mode;for (r =0 ; r < mode->num_rates; r++) { rate = &mode->rates[r]; rate->rate_inv =CHAN_UTIL_RATE_LCM / rate->rate; } } + + local->hw_modes &= local->valid_hw_modes; }
@@ -4257,7 +4262,7 @@ int ieee80211_update_hw(struct net_devic !hw->modes->num_channels || !hw->modes->num_rates)return -1 ; -ieee80211_precalc_rates (hw); +ieee80211_precalc_modes (hw, local); local->conf.phymode = hw->modes[0 ].mode; local->curr_rates = hw->modes[0 ].rates; local->num_curr_rates = hw->modes[0 ].num_rates;
net/d80211/ieee80211_i.h +2 -1
@@ -409,7 +409,6 @@ #define IEEE80211_IRQSAFE_QUEUE_LIMIT 12int scan_oper_antenna_max;u8 scan_ssid[IEEE80211_MAX_SSID_LEN ];size_t scan_ssid_len; -int scan_skip_11b;struct list_head sta_bss_list;struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE ];spinlock_t sta_bss_lock;
@@ -500,6 +499,8 @@ #endif /* CONFIG_D80211_DEBUG_COUNTERS *int wifi_wme_noack_test;unsigned int wmm_acm;/* bit field of ACM bits (BIT(802.1D tag)) */ +unsigned int valid_hw_modes;/* bitfield of supported hardware modes; +* (1 << MODE_*) */ unsigned int hw_modes;/* bitfield of allowed hardware modes; * (1 << MODE_*) */ };
net/d80211/ieee80211_ioctl.c +1 -1
@@ -2447,7 +2447,7 @@ static int ieee80211_ioctl_prism2_param(break ;case PRISM2_PARAM_HW_MODES : - local->hw_modes = value; + local->hw_modes = value & local->valid_hw_modes;break ;case PRISM2_PARAM_CREATE_IBSS :
net/d80211/ieee80211_sta.c +1 -2
@@ -2468,7 +2468,7 @@ static void ieee80211_sta_scan_timer(uns (sdata->type ==IEEE80211_IF_TYPE_IBSS && !(chan->flag &IEEE80211_CHAN_W_IBSS )) || (local->hw_modes & (1 <<MODE_IEEE80211G ) && - mode->mode == MODE_IEEE80211B && local->scan_skip_11b)) + mode->mode == MODE_IEEE80211B)) skip = 1;if (!skip) {
@@ -2566,7 +2566,6 @@ int ieee80211_sta_req_scan(struct net_dememcpy (local->scan_ssid, ssid, ssid_len); }else local->scan_ssid_len =0 ; - local->scan_skip_11b =1 ;/* FIX: clear this is 11g is not supported */ local->scan_state =SCAN_SET_CHANNEL ; local->scan_hw_mode_idx =0 ; local->scan_channel_idx =0 ;
Quoted 2 lines · Michael Wu
Hm, so why not add something that will tell you what modes are supported by the hardware?
Sounds reasonable.
Quoted 3 lines
Only problem with this patch is if the hardware adds any modes after registration, they will be disabled initially. Hopefully, no drivers will actually need to do that.
bcm43xx does that. If I understand it correctly, bcm43xx driver doesn't know allowed modes until it loads firmware. And the firmware is not loaded until the device is opened (they probably have a reason for this).
This issue can be easily solved by not masking hw_modes by valid_hw_modes in ieee80211_ioctl_prism2_param and ieee80211_precalc_modes. Just check (hw_modes & valid_hw_modes) instead of hw_modes in ieee80211_sta_scan_timer.
And yes, hw_modes is a confusing name. It should be named hw_modes_mask_disabled_by_user or so. Maybe at least some better comment about this in ieee80211_i.h won't be a bad idea.
Thanks,
Jiri
Signature · 2 lines
Jiri Benc SUSE Labs
Quoted 5 lines · Jiri Benc
bcm43xx does that. If I understand it correctly, bcm43xx driver doesn't know allowed modes until it loads firmware. And the firmware is not loaded until the device is opened (they probably have a reason for this).
No, that's not right, the firmware has nothing to do with it. At least not that we know of, so we treat it as all doing the same :)
johannes
[removed some people from Cc: list as this is probably not much interesting for them]
Quoted 8 lines · Johannes Berg
Quoted 4 lines · Jiri Benc
bcm43xx does that. If I understand it correctly, bcm43xx driver doesn't know allowed modes until it loads firmware. And the firmware is not loaded until the device is opened (they probably have a reason for this).
No, that's not right, the firmware has nothing to do with it. At least not that we know of, so we treat it as all doing the same :)
Hm, so your calls to ieee80211_update_hw are probably unnecessary. Anyway, I'm still inclined towards not masking hw_modes by valid_hw_modes.
Jiri
Signature · 2 lines
Jiri Benc SUSE Labs
Quoted 10 lines · you
[removed some people from Cc: list as this is probably not much interesting for them]
Quoted 6 lines · Johannes Berg
Quoted 4 lines · Jiri Benc
bcm43xx does that. If I understand it correctly, bcm43xx driver doesn't know allowed modes until it loads firmware. And the firmware is not loaded until the device is opened (they probably have a reason for this).
Quoted 4 lines
Quoted 2 lines
No, that's not right, the firmware has nothing to do with it. At least not that we know of, so we treat it as all doing the same :)
Hm, so your calls to
ieee80211_update_hware probably unnecessary.
No, We must allocate the ieee80211_hw, before we can attach the board. But before we attached the board, we don't know what hardware it is. Sure, this can be worked around by some very ugly hack (It was done in an early version of the dscape port, because there was no ieee80211_update_hw), but I am not very happy to add the hack again. (I am not sure anymore _what_ we actually did to workaround it. I would have to look up the SVN repository ;) )
Quoted 7 lines · Michael Buesch
No, We must allocate the
ieee80211_hw, before we can attach the board. But before we attached the board, we don't know what hardware it is. Sure, this can be worked around by some very ugly hack (It was done in an early version of the dscape port, because there was noieee80211_update_hw), but I am not very happy to add the hack again. (I am not sure anymore _what_ we actually did to workaround it. I would have to look up the SVN repository ;) )
Isn't it possible to do attaching of the board between ieee80211_alloc_hw and ieee80211_register_hw calls? You don't need to call ieee80211_update_hw then.
Anyway, the ieee80211_update_hw function is here for a reason (solving issues with a firmware primarily, but not exclusively), so use it if it is easier for you.
Jiri
Signature · 2 lines
Jiri Benc SUSE Labs
Quoted 9 lines · Jiri Benc
This issue can be easily solved by not masking
hw_modesbyvalid_hw_modesinieee80211_ioctl_prism2_paramandieee80211_precalc_modes. Just check (hw_modes&valid_hw_modes) instead ofhw_modesinieee80211_sta_scan_timer.And yes,
hw_modesis a confusing name. It should be namedhw_modes_mask_disabled_by_useror so. Maybe at least some better comment about this inieee80211_i.hwon't be a bad idea.
Okay, how about this? Instead of adding valid_hw_modes, I added enabled_modes, and replaced all instances of local->hw_modes with local->enabled_modes. local->hw_modes now really means what modes are supported by the hardware.
net/d80211/ieee80211.c +6 -3
@@ -3999,14 +3999,17 @@ void ieee80211_if_setup(struct net_devic } -static void ieee80211_precalc_rates (struct ieee80211_hw *hw) +static void ieee80211_precalc_modes (struct ieee80211_hw *hw, +struct ieee80211_local *local) {struct ieee80211_hw_modes *mode;struct ieee80211_rate *rate;int m, r; + local->hw_modes =0 ;for (m =0 ; m < hw->num_modes; m++) { mode = &hw->modes[m]; + local->hw_modes |=1 << mode->mode;for (r =0 ; r < mode->num_rates; r++) { rate = &mode->rates[r]; rate->rate_inv =CHAN_UTIL_RATE_LCM / rate->rate;
@@ -4087,7 +4090,7 @@ struct net_device *ieee80211_alloc_hw(si local->rate_ctrl_num_down =RATE_CONTROL_NUM_DOWN ; local->scan.in_scan =0 ; - local->hw_modes = (unsigned int )-1 ; + local->enabled_modes = (unsigned int )-1 ;init_timer (&local->scan.timer);/* clear it out */
@@ -4257,7 +4260,7 @@ int ieee80211_update_hw(struct net_devic !hw->modes->num_channels || !hw->modes->num_rates)return -1 ; -ieee80211_precalc_rates (hw); +ieee80211_precalc_modes (hw, local); local->conf.phymode = hw->modes[0 ].mode; local->curr_rates = hw->modes[0 ].rates; local->num_curr_rates = hw->modes[0 ].num_rates;
net/d80211/ieee80211_i.h +3 -2
@@ -409,7 +409,6 @@ #define IEEE80211_IRQSAFE_QUEUE_LIMIT 12int scan_oper_antenna_max;u8 scan_ssid[IEEE80211_MAX_SSID_LEN ];size_t scan_ssid_len; -int scan_skip_11b;struct list_head sta_bss_list;struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE ];spinlock_t sta_bss_lock;
@@ -500,7 +499,9 @@ #endif /* CONFIG_D80211_DEBUG_COUNTERS *int wifi_wme_noack_test;unsigned int wmm_acm;/* bit field of ACM bits (BIT(802.1D tag)) */ -unsigned int hw_modes;/* bitfield of allowed hardware modes; +unsigned int enabled_modes;/* bitfield of allowed modes; +* (1 << MODE_*) */ +unsigned int hw_modes;/* bitfield of supported hardware modes; * (1 << MODE_*) */ };
net/d80211/ieee80211_ioctl.c +3 -3
@@ -1699,7 +1699,7 @@ int ieee80211_ioctl_siwfreq(struct net_dif (chan->flag &IEEE80211_CHAN_W_SCAN && ((freq->e ==0 && chan->chan == freq->m) || (freq->e >0 && nfreq == chan->freq)) && - (local->hw_modes & (1 << mode->mode))) { + (local->enabled_modes & (1 << mode->mode))) {/* Use next_mode as the mode preference to * resolve non-unique channel numbers. */ if (set && mode->mode != local->next_mode)
@@ -2447,7 +2447,7 @@ static int ieee80211_ioctl_prism2_param(break ;case PRISM2_PARAM_HW_MODES : - local->hw_modes = value; + local->enabled_modes = value;break ;case PRISM2_PARAM_CREATE_IBSS :
@@ -2620,7 +2620,7 @@ static int ieee80211_ioctl_get_prism2_pabreak ;case PRISM2_PARAM_HW_MODES : - *param = local->hw_modes; + *param = local->enabled_modes;break ;case PRISM2_PARAM_CREATE_IBSS :
net/d80211/ieee80211_sta.c +4 -5
@@ -2462,13 +2462,13 @@ static void ieee80211_sta_scan_timer(uns }return ; } - skip = !(local->hw_modes & (1 << mode->mode)); + skip = !(local->enabled_modes & (1 << mode->mode)); chan = &mode->channels[local->scan_channel_idx];if (!(chan->flag &IEEE80211_CHAN_W_SCAN ) || (sdata->type ==IEEE80211_IF_TYPE_IBSS && !(chan->flag &IEEE80211_CHAN_W_IBSS )) || - (local->hw_modes & (1 <<MODE_IEEE80211G ) && - mode->mode ==MODE_IEEE80211B && local->scan_skip_11b)) + (local->hw_modes & local->enabled_modes & + (1 <<MODE_IEEE80211G ) && mode->mode ==MODE_IEEE80211B )) skip =1 ;if (!skip) {
@@ -2566,7 +2566,6 @@ int ieee80211_sta_req_scan(struct net_dememcpy (local->scan_ssid, ssid, ssid_len); }else local->scan_ssid_len =0 ; - local->scan_skip_11b =1 ;/* FIX: clear this is 11g is not supported */ local->scan_state =SCAN_SET_CHANNEL ; local->scan_hw_mode_idx =0 ; local->scan_channel_idx =0 ;
@@ -2592,7 +2591,7 @@ ieee80211_sta_scan_result(struct net_dev bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))return current_ev; -if (!(local->hw_modes & (1 << bss->hw_mode))) +if (!(local->enabled_modes & (1 << bss->hw_mode)))return current_ev; if (local->scan_flags & IEEE80211_SCAN_WPA_ONLY &&
Quoted 6 lines · Michael Wu
Quoted 5 lines · Jiri Benc
This issue can be easily solved by not masking
hw_modesbyvalid_hw_modesinieee80211_ioctl_prism2_paramandieee80211_precalc_modes. Just check (hw_modes&valid_hw_modes) instead ofhw_modesinieee80211_sta_scan_timer.
Quoted 7 lines
Quoted 4 lines
And yes,
hw_modesis a confusing name. It should be namedhw_modes_mask_disabled_by_useror so. Maybe at least some better comment about this inieee80211_i.hwon't be a bad idea.Okay, how about this? Instead of adding
valid_hw_modes, I addedenabled_modes, and replaced all instances oflocal->hw_modeswithlocal->enabled_modes.local->hw_modesnow really means what modes are supported by the hardware.
Are we satisfied w/ this patch? If so, please repost the patch after cleaning-up the changelog according to the rules here:
http://linux.yyz.us/patch-format.html
Thanks,
John
Signature · 2 lines
John W. Linville [email protected]
Quoted 5 lines · John W. Linville
Are we satisfied w/ this patch? If so, please repost the patch after cleaning-up the changelog according to the rules here:
I was going to after getting a response, but Jiri Benc already pulled it into his dscape tree and cleaned up the changelog, so I assumed that was enough. I'll repost if needed.
-Michael Wu
Quoted 9 lines · Michael Wu
Quoted 5 lines · John W. Linville
Are we satisfied w/ this patch? If so, please repost the patch after cleaning-up the changelog according to the rules here:
I was going to after getting a response, but Jiri Benc already pulled it into his dscape tree and cleaned up the changelog, so I assumed that was enough. I'll repost if needed.
I'm happy to take patches from Jiri (or pull from Jiri's tree).
Jiri, I'll count on you to pass this on when you are ready.
John
Signature · 2 lines
John W. Linville [email protected]