2023-04-10 WIFI countrycode国家码忽略NL80211_REGDOM_SET_BY_COUNTRY_IE

如果为了避免在连接router路由器后,出现TV 或手机设备的WIFI countrycode国家码随着Router 中Country IE信息变化,也就是Kernel 的NL80211_REGDOM_SET_BY_COUNTRY_IE信息设置国家码。

为了避免出现以上情况 ,需要设置REGULATORY_COUNTRY_IE_IGNORE到prWiphy->regulatory_flags,即:

    prWiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;


void  cfg80211_regd_set_wiphy(IN struct wiphy *prWiphy)

{

    /* * register callback*/

    prWiphy->reg_notifier = xxxx_reg_notify;

    /*  * clear REGULATORY_CUSTOM_REG flag*/

#if KERNEL_VERSION(3, 14, 0) > CFG80211_VERSION_CODE

    /*tells kernel that assign WW as default*/

    prWiphy->flags &= ~(WIPHY_FLAG_CUSTOM_REGULATORY);

#else

    prWiphy->regulatory_flags &= ~(REGULATORY_CUSTOM_REG);

    /*ignore the hint from IE*/

    prWiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;

#ifdef CFG_SUPPORT_DISABLE_BCN_HINTS

    /*disable beacon hint to avoid channel flag be changed*/

    prWiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS;

#endif

#endif

    /*

    * set REGULATORY_CUSTOM_REG flag

    */

#if KERNEL_VERSION(3, 14, 0) > CFG80211_VERSION_CODE

    /*tells kernel that assign WW as default*/

    prWiphy->flags |= (WIPHY_FLAG_CUSTOM_REGULATORY);

#else

    prWiphy->regulatory_flags |= (REGULATORY_CUSTOM_REG);

#endif

    /* assigned a defautl one */

    if (rlmDomainGetLocalDefaultRegd())

        wiphy_apply_custom_regulatory(prWiphy,

                          rlmDomainGetLocalDefaultRegd());

}



参考如下:

https://patchwork.kernel.org/project/linux-wireless/patch/1531228573-20734-1-git-send-email-rsirasan@codeaurora.org/

[v1] cfg80211: Avoid regulatory restore when COUNTRY_IE_IGNORE is set


When REGULATORY_COUNTRY_IE_IGNORE is set,  __reg_process_hint_country_ie()

ignores the country code change request from __cfg80211_connect_result()

via regulatory_hint_country_ie().

After Disconnect, similar to above, country code should not be reset to

world when country IE ignore is set. But this is violated and restore of

regulatory settings is invoked by cfg80211_disconnect_work via

regulatory_hint_disconnect().

To address this, avoid regulatory restore from regulatory_hint_disconnect()

when COUNTRY_IE_IGNORE is set.

Note: Currently, restore_regulatory_settings() takes care of clearing

beacon hints. But in the proposed change, regulatory restore is avoided.

Therefore, explicitly clear beacon hints when DISABLE_BEACON_HINTS

is not set.


---

net/wireless/reg.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++

1 file changed, 46 insertions(+)



Patch

diff --git a/net/wireless/reg.c b/net/wireless/reg.c

index bbe6298..9795e64 100644

--- a/net/wireless/reg.c

+++ b/net/wireless/reg.c

@@ -3271,8 +3271,54 @@  static void restore_regulatory_settings(bool reset_user)

    schedule_work(&reg_work);

}

+static bool is_wiphy_all_set_reg_flag(enum ieee80211_regulatory_flags flag)

+{

+    struct cfg80211_registered_device *rdev;

+    struct wireless_dev *wdev;

+

+    list_for_each_entry(rdev, &cfg80211_rdev_list, list) {

+        list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {

+            wdev_lock(wdev);

+            if (!(wdev->wiphy->regulatory_flags & flag)) {

+                wdev_unlock(wdev);

+                return false;

+            }

+            wdev_unlock(wdev);

+        }

+    }

+

+    return true;

+}

+

void regulatory_hint_disconnect(void)

{

+    /* Restore of regulatory settings is not required when wiphy(s)

+    * ignore IE from connected access point but clearance of beacon hints

+    * is required when wiphy(s) supports beacon hints.

+    */

+    if (is_wiphy_all_set_reg_flag(REGULATORY_COUNTRY_IE_IGNORE)) {

+        struct reg_beacon *reg_beacon, *btmp;

+

+        if (is_wiphy_all_set_reg_flag(REGULATORY_DISABLE_BEACON_HINTS))

+            return;

+

+        spin_lock_bh(&reg_pending_beacons_lock);

+        list_for_each_entry_safe(reg_beacon, btmp,

+                    &reg_pending_beacons, list) {

+            list_del(&reg_beacon->list);

+            kfree(reg_beacon);

+        }

+        spin_unlock_bh(&reg_pending_beacons_lock);

+

+        list_for_each_entry_safe(reg_beacon, btmp,

+                    &reg_beacon_list, list) {

+            list_del(&reg_beacon->list);

+            kfree(reg_beacon);

+        }

+

+        return;

+    }

+

    pr_debug("All devices are disconnected, going to restore regulatory settings\n");

    restore_regulatory_settings(false);

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容