]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mac80211: choose first enabled channel for monitor
authorKarthikeyan Kathirvel <kathirve@codeaurora.org>
Thu, 11 Mar 2021 05:29:07 +0000 (10:59 +0530)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 16 Mar 2021 20:20:47 +0000 (21:20 +0100)
Even if the first channel from sband channel list is invalid
or disabled mac80211 ends up choosing it as the default channel
for monitor interfaces, making them not usable.

Fix this by assigning the first available valid or enabled
channel instead.

Signed-off-by: Karthikeyan Kathirvel <kathirve@codeaurora.org>
Link: https://lore.kernel.org/r/1615440547-7661-1-git-send-email-kathirve@codeaurora.org
[reword commit message, comment, code cleanups]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/main.c

index 4f3f8bb58e76cfa44d8545ac0e004c5e60af96cd..1b9c82616606b8851b2da8a43b4f2c6ec0c5b49d 100644 (file)
@@ -973,8 +973,19 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
                        continue;
 
                if (!dflt_chandef.chan) {
+                       /*
+                        * Assign the first enabled channel to dflt_chandef
+                        * from the list of channels
+                        */
+                       for (i = 0; i < sband->n_channels; i++)
+                               if (!(sband->channels[i].flags &
+                                               IEEE80211_CHAN_DISABLED))
+                                       break;
+                       /* if none found then use the first anyway */
+                       if (i == sband->n_channels)
+                               i = 0;
                        cfg80211_chandef_create(&dflt_chandef,
-                                               &sband->channels[0],
+                                               &sband->channels[i],
                                                NL80211_CHAN_NO_HT);
                        /* init channel we're on */
                        if (!local->use_chanctx && !local->_oper_chandef.chan) {