{"id":323,"date":"2025-11-02T20:31:46","date_gmt":"2025-11-02T12:31:46","guid":{"rendered":"https:\/\/www.garfield-blog.top\/?p=323"},"modified":"2025-12-13T11:01:20","modified_gmt":"2025-12-13T03:01:20","slug":"mac80211%e7%9b%91%e7%ae%a1%e5%9f%9f%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.garfield-blog.top\/?p=323","title":{"rendered":"\u3010\u6e90\u7801\u89e3\u6790\u3011MAC80211\u76d1\u7ba1\u57df\u7ba1\u7406"},"content":{"rendered":"\n<p>\u8fd9\u91cc\u5217\u51fa<code>backports<\/code>\u4e0b\u56fd\u5bb6\u7801\u7684\u4fee\u6539\u7684\u5927\u81f4\u6d41\u7a0b\uff0c\u4ee5<code>openwrt<\/code>\u7cfb\u7edf\u4e3a\u4f8b\u5b50<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e0a\u5c42\u6a21\u5757\u914d\u7f6e\u56fd\u5bb6\u7801<\/h2>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u5bf9\u5e94\u56fd\u5bb6\u7801\u7684\u4fee\u6539\u5b9e\u9645\u662f\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u4e2a\u63a5\u53e3\uff0c\u5404\u79cd\u4e0a\u5c42\u5e94\u7528\u90fd\u662f\u4f7f\u7528\u8fd9\u4e2a\u63a5\u53e3\uff0c\u90a3\u4e48\u53ea\u8981\u5728\u5408\u9002\u7684\u4f4d\u7f6e\u53bb\u6dfb\u52a0\u5904\u7406\u903b\u8f91\u5373\u53ef<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/11\/\u56fd\u5bb6\u7801\u4fee\u6539\u6d41\u7a0b.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"447\" height=\"338\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/11\/\u56fd\u5bb6\u7801\u4fee\u6539\u6d41\u7a0b.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-325\"  sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u56fd\u5bb6\u7801\u7684\u751f\u6548<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u539f\u751fopenwrt<\/strong> \u8fc7<code>wireless-regdb<\/code>\u5c06<code>db.txt<\/code>\u8f6c\u6362\u4e3a<code>regulatory.db<\/code>\u6587\u4ef6\u6765\u67e5\u627e\u56fd\u5bb6\u7801\uff1b\u4fee\u6539<code>build_dir\/target-mipsel_mips-interAptiv_musl\/wireless-regdb-2017-10-20-4343d359<\/code>\u76ee\u5f55\u4e0b<code>db.txt<\/code> <strong>\u8fd9\u91cc\u8d34\u51fa\u4e00\u5c0f\u6bb5<code>db.txt<\/code>\u6587\u4ef6\u7684\u5185\u5bb9<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  # This is the world regulatory domain\n  country 00:\n    (2402 - 2472 @ 40), (20)\n    # Channel 12 - 13.\n    (2457 - 2482 @ 20), (20), NO-IR, AUTO-BW\n    # Channel 14. Only JP enables this and for 802.11b only\n    (2474 - 2494 @ 20), (20), NO-IR, NO-OFDM\n    # Channel 36 - 48\n    (5170 - 5250 @ 80), (20), AUTO-BW\n    # Channel 52 - 64\n    (5250 - 5330 @ 80), (20), NO-IR, DFS, AUTO-BW\n    # Channel 100 - 144\n    (5490 - 5730 @ 160), (20), NO-IR, DFS\n    # Channel 149 - 165\n    (5735 - 5835 @ 80), (20), NO-IR\n    # IEEE 802.11ad (60GHz), channels 1..3\n    (57240 - 63720 @ 2160), (0)\n\n  country AD:\n    (2402 - 2482 @ 40), (20)\n    (5170 - 5250 @ 80), (20)\n    (5250 - 5330 @ 80), (20), DFS\n    (5490 - 5710 @ 80), (27), DFS\n    # 60 GHz band channels 1-4, ref: Etsi En 302 567\n    (57000 - 66000 @ 2160), (40)\n\n  country AE: DFS-FCC\n    (2402 - 2482 @ 40), (20)\n    (5170 - 5250 @ 80), (17), AUTO-BW\n    (5250 - 5330 @ 80), (24), DFS, AUTO-BW\n    (5490 - 5730 @ 160), (24), DFS\n    (5735 - 5835 @ 80), (30)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u539f\u751f linux\u7684cfg80211<\/strong> \u8981<code>make menuconfig<\/code>\u4f7f\u80fd<code>CONFIG_CFG80211_INTERNAL_REGDB<\/code>\u5b8f\uff0c\u5e76\u4fee\u6539<code>net\/wireless\/db.txt<\/code>\u91cc\u7684\u56fd\u5bb6\u4fe1\u9053\u8868\uff0c\u91cd\u65b0\u7f16\u8bd1\uff0c\u7f16\u8bd1\u540e\u4f1a\u751f\u6210<code>regdb.c<\/code>\u6587\u4ef6 \u67e5\u8be2<code>Linux<\/code>\u6e90\u7801\u540e\u53d1\u73b0\uff0c\u5728<code>linux-4.14.90-dev\/linux-4.14.90\/net\/wireless\/db.txt<\/code>\u4e2d\u63d0\u5230\u4e86\uff0c<code>CONFIG_CFG80211_INTERNAL_REGDB<\/code>\u8fd9\u4e2a\u5b8f\u662f\u51e0\u4e4e\u4e0d\u4f1a\u88ab\u4f7f\u7528\u7684<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>#<\/p>\n\n\n\n<p># This file is a placeholder to prevent accidental build breakage if someone enables CONFIG_CFG80211_INTERNAL_REGDB. Almost no one actually needs to enable that build option.<\/p>\n\n\n\n<p>#<\/p>\n\n\n\n<p># You should be using CRDA instead. It is even better if you use the CRDA package provided by your distribution, since they will probably keep it up-to-date on your behalf.<\/p>\n\n\n\n<p>#<\/p>\n\n\n\n<p># If you <em>really<\/em> intend to use CONFIG_CFG80211_INTERNAL_REGDB then you will need to replace this file with one containing appropriately formatted regulatory rules that cover the regulatory domains you will be using. Your best option is to extract the db.txt file from the wireless-regdb git<\/p>\n\n\n\n<p># repository:<\/p>\n\n\n\n<p># git:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/linville\/wireless-regdb.git<\/p>\n\n\n\n<p>#<\/p>\n\n\n\n<p>\u8bd1\u6587\uff1a\u6b64\u6587\u4ef6\u662f\u4e00\u4e2a\u5360\u4f4d\u7b26\uff0c\u4ee5\u9632\u6b62\u610f\u5916\u6784\u5efa\u7834\u574f\uff0c\u5982\u679c\u6709\u4eba\u542f\u7528CONFIG_CFG80211_INTERNAL_REGDB\u3002<strong>\u5b9e\u9645\u4e0a\u51e0\u4e4e\u6ca1\u6709\u4eba\u9700\u8981\u542f\u7528\u8be5\u6784\u5efa\u9009\u9879<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u4f60\u5e94\u8be5\u4f7f\u7528CRDA<\/strong>\u3002\u5982\u679c\u60a8\u4f7f\u7528\u60a8\u7684\u53d1\u884c\u7248\u63d0\u4f9b\u7684CRDA\u5305\u5c31\u66f4\u597d\u4e86\uff0c\u56e0\u4e3a\u4ed6\u4eec\u53ef\u80fd\u4f1a\u4ee3\u8868\u60a8\u4fdd\u6301\u6700\u65b0<\/p>\n\n\n\n<p>\u5982\u679c\u60a8\u771f\u7684\u6253\u7b97\u4f7f\u7528CONFIG_CFG80211_INTERNAL_REGDB\uff0c\u90a3\u4e48\u60a8\u5c06\u9700\u8981\u7528\u4e00\u4e2a\u5305\u542b\u9002\u5f53\u683c\u5f0f\u7684\u76d1\u7ba1\u89c4\u5219\u7684\u6587\u4ef6\u6765\u66ff\u6362\u8be5\u6587\u4ef6\uff0c\u8be5\u89c4\u5219\u6db5\u76d6\u60a8\u5c06\u4f7f\u7528\u7684\u76d1\u7ba1\u57df\u3002<strong>\u6700\u597d\u7684\u9009\u62e9\u662f\u4ecewireless-regdb git\u4e2d\u63d0\u53d6db.txt\u6587\u4ef6<\/strong><\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u5982backports\u7684linux<\/strong> \u5728\u5bf9\u5e94\u7684\u4ee3\u7801(<code>openwrt<\/code>)\u4e0a\u6839\u636e\u9700\u6c42\u505a\u4fee\u6539\u540e\uff0c\u5c06\u751f\u6210\u7684\u5bf9\u5e94\u7684<code>build_dir\/target-mipsel_mips-interAptiv_musl\/wirelessregdb-2017-10-20-4343d359<\/code>\u76ee\u5f55\u4e0b\u7684\u76ee<code>regulatory.db<\/code>\u6587\u4ef6\u7f16\u8bd1\u5230\u955c\u50cf\u4e2d<\/li>\n<\/ul>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p>\u56fd\u5bb6\u7801\u7684\u914d\u7f6e\u8fd8\u662f\u4f9d\u8d56\u4e8e<code>regulatory.db<\/code>\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u5728\u5355\u677f\u4e2d\u88ab\u5b58\u50a8\u5728<code>\/lib\/firmware\/regulatory.db<\/code>\uff0c\u7531\u5185\u6838\u7684<code>cfg80211<\/code>\u6a21\u5757\u8fdb\u884c\u52a0\u8f7d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56fd\u5bb6\u7801\u751f\u6548\u6d41\u7a0b<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e0a\u5c42\u5e94\u7528<\/h3>\n\n\n\n<p>\u9996\u5148\u662f\u4e0a\u5c42\u5e94\u7528\u901a\u8fc7<code>network<\/code>\u53d1\u9001<code>NL80211_CMD_REQ_SET_REG<\/code>:\u7ed9\u5185\u6838\uff0c\u5df2<code>hostapd<\/code>\u4e3e\u4f8b\uff0c\u8fd9\u91cc\u5217\u51fa\u5bf9\u5e94\u6ce8\u91ca<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>* @NL80211_CMD_REQ_SET_REG: ask the wireless core to set the regulatory domain to the specified ISO\/IEC 3166-1 alpha2 country code. The core will store this as a valid request and then query userspace for it.<\/p>\n\n\n\n<p>\u8bd1\u6587\uff1a\u8981\u6c42\u65e0\u7ebf\u6838\u5fc3\u5c06\u76d1\u7ba1\u57df\u8bbe\u7f6e\u4e3a\u6307\u5b9a\u7684ISO\/IEC 3166-1 alpha2\u56fd\u5bb6\u4ee3\u7801\u3002\u5185\u6838\u5c06\u628a\u5b83\u5b58\u50a8\u4e3a\u4e00\u4e2a\u6709\u6548\u7684\u8bf7\u6c42\uff0c\u7136\u540e\u67e5\u8be2\u7528\u6237\u7a7a\u95f4\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u91cc\u5217\u51fa\u5bf9\u5e94\u4ee3\u7801<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7b14\u8005\u6ce8\uff1a\u4e3a\u4fdd\u8bc1\u9605\u8bfb\u5220\u9664\u90e8\u5206\u5197\u4f59\u903b\u8f91<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)\n{\n    struct i802_bss *bss = priv;\n    struct wpa_driver_nl80211_data *drv = bss-&gt;drv;\n    char alpha2&#91;3];\n    struct nl_msg *msg;\n\n    msg = nlmsg_alloc();\n\n    alpha2&#91;0] = alpha2_arg&#91;0];\n    alpha2&#91;1] = alpha2_arg&#91;1];\n    alpha2&#91;2] = '\\0';\n\n    if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||\n        nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2) ||\n            ((alpha2_arg&#91;3] == 'T') &amp;&amp; nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, 0))) {\n        nlmsg_free(msg);\n        return -EINVAL;\n    }\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5185\u6838\u90e8\u5206<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">cfg80211\u4e2d\u5927\u81f4\u6d41\u7a0b<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5185\u6838\u90e8\u5206\u4e3b\u8981\u5206\u6790<code>backports-4.19.7-1<\/code>\u6a21\u5757<\/p>\n<\/blockquote>\n\n\n\n<p><code>backports<\/code>\u4e2d\u4f1a\u6ce8\u518c\u4e00\u4e2a\u5de5\u4f5c\u961f\u5217<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/net\/wireless\/reg.c\n\/\/\u8fd9\u91cc\u901a\u8fc7DECLARE_WORK\u6ce8\u518c\u4e86\u4e00\u4e2areg_work\u5de5\u4f5c\u961f\u5217\u548c\u5bf9\u5e94\u56de\u8c03\nstatic DECLARE_WORK(reg_work, reg_todo);<\/code><\/pre>\n\n\n\n<p>\u5728\u7528\u6237\u7a7a\u95f4\u7684<code>NL80211_CMD_REQ_SET_REG<\/code>\u8bf7\u6c42\u6765\u5230\u540e\u5148\u4f7f\u7528\u5bf9\u5e94\u56de\u8c03<code>nl80211_req_set_reg<\/code>\u6ce8\u518c\u5728\u8fd9\u4e2a\u5de5\u4f5c\u961f\u5217\u4e2d\uff0c\u7136\u540e\u4f7f\u7528\u5de5\u4f5c\u961f\u5217\u7684\u5904\u7406\u51fd\u6570\u53bb\u5904\u7406<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7b80\u5355\u5217\u51fa\u51fd\u6570\u8c03\u7528\u6808<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nl80211_req_set_reg\n    \/\/\u63a5\u6536\u7528\u6237\u7a7a\u95f4\u4f20\u5165\u7684\u56fd\u5bb6\u7801\uff0c\u5f62\u5f0f\u662f\u4e24\u4e2a\u5927\u5199\u5b57\u6bcd\n    -&gt;regulatory_hint_user\n      -&gt;queue_regulatory_request\n          \/\/\u8fd9\u91cc\u7684\u5904\u7406\u662f\uff0c\u5c06\u4f20\u5165\u7684\u56fd\u5bb6\u7801\u8f6c\u5316\u4e3a\u5927\u5199\u5f62\u5f0f\uff0c\u7136\u540e\u52a0\u5165\u4e00\u4e2a\u5de5\u4f5c\u961f\u5217\u4e2d\uff0c\u7136\u540e\u8c03\u7528\u8fd9\u4e2a\u961f\u5217\u53bb\u5904\u7406\n          -&gt;list_add_tail(&amp;request-&gt;list, &amp;reg_requests_list);\n              schedule_work(&amp;reg_work);\n                -&gt;reg_todo<\/code><\/pre>\n\n\n\n<p>\u5728\u8c03\u7528\u5de5\u4f5c\u961f\u5217\u540e\u5e94\u8be5\u662f\uff0c\u901a\u8fc7<code>reg_process_hint_user<\/code>\u51fd\u6570\u5904\u7406\u7528\u6237\u7a7a\u95f4\u8bf7\u6c42\uff0c\u8fd9\u91cc\u4f1a\u8bfb\u53d6<code>reg_requests_list<\/code>\u961f\u5217\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u8bf7\u6c42\uff0c\u7136\u540e\u5904\u7406<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5217\u51fa\u51fd\u6570\u8c03\u7528\u6808<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>reg_todo\n    -&gt;reg_process_pending_hints\n      -&gt;reg_process_hint\n          -&gt;reg_process_hint_user\n              -&gt;reg_query_database\n                  \/\/\u8bfb\u53d6\u6570\u636e\u5e93\u6587\u4ef6\n                     -&gt;query_regdb_file\n                      \/\/\u6b64\u65f6\u5982\u679cregulatory.db\u5df2\u7ecf\u88ab\u52a0\u8f7d\u5230\u5168\u5c40\u53d8\u91cf\u4e2d\u90a3\u4e48\u8d70\u8fd9\u4e2a\u903b\u8f91\n                      -&gt;query_regdb\n                          \/\/\u8fd9\u91cc\u8bfb\u53d6DB\u4e2d\u7684\u6570\u636e\uff0c\u5305\u62ec\u4fe1\u9053\uff0c\u529f\u7387\u7684\u7b49\u4fe1\u606f\n                          -&gt;regdb_query_country\n                              \/\/\u8bfb\u53d6DB\u4e2d\u7684\u6570\u636e\u540e\uff0c\u5c06\u5176\u653e\u5165reg_regdb_work\u5de5\u4f5c\u961f\u5217\u4e2d\uff0c\u7136\u540e\u5524\u9192\n                              -&gt;reg_schedule_apply\n                                  -&gt;schedule_work(&amp;reg_regdb_work)\n                                      -&gt;reg_regdb_apply\n                      \/\/\u5982\u679cregulatory.db\u8fd8\u6ca1\u6709\u88ab\u52a0\u8f7d\uff0c\u5c06regulatory.db\u52a0\u8f7d\u5230\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u4e2d\n                      -&gt;request_firmware_nowait(\"..\", \"regulatory.db\", \"..\")\n                          -&gt;regdb_fw_cb<\/code><\/pre>\n\n\n\n<p><code>reg_regdb_work<\/code>\u5de5\u4f5c\u961f\u5217\u7684\u56de\u8c03<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u8fd9\u91cc\u8bfb\u53d6\u4e86\u521a\u624d\u88ab\u5b58\u653e\u5230\u5de5\u4f5c\u961f\u5217\u4e2d\u7684\u529f\u7387\u4fe1\u606f\nreg_regdb_apply\n    -&gt;set_regdom\n      -&gt;reg_set_rd_user\n          \/\/\u8fd9\u8fd9\u91cc\u66f4\u65b0\u4e86\u4e00\u4e2a\u5f53\u524d\u76d1\u7ba1\u57df\u5168\u5c40\u53d8\u91cfcfg80211_regdomain\uff0c\u8fd9\u4e2a\u76d1\u7ba1\u57df\u53d8\u91cf\u4e2d\u5c31\u5b58\u653e\u7740\u529f\u7387\u76f8\u5173\u7684\u4fe1\u606f\n          -&gt;reset_regdomains\n              -&gt;reg_update_last_request\n        \/\/\u66f4\u65b0\u76d1\u7ba1\u57df\u4fe1\u606f\n        -&gt;update_all_wiphy_regulatory\n            -&gt;wiphy_update_regulatory<\/code><\/pre>\n\n\n\n<p><strong>backports\u4e2d\u7684\u5927\u81f4\u6d41\u7a0b<\/strong><\/p>\n\n\n\n<p>\u6574\u4f53\u7684\u7f16\u7801\u662f\u4f9d\u8d56\u5185\u6838\u7684\u5de5\u4f5c\u961f\u5217\u5b9e\u73b0\u6a21\u5757\u7684\u89e3\u8026\u5408\uff0c\u4e3b\u8981\u4f7f\u7528<code>reg_work<\/code>\u548c<code>reg_regdb_work<\/code>\u4e24\u4e2a\u5de5\u4f5c\u961f\u5217\uff0c\u9996\u5148\u7528\u6237\u7a7a\u95f4\u901a\u8fc7<code>netlink<\/code>\u53d1\u9001\u56fd\u5bb6\u7801\u4fe1\u606f\u5230\u5185\u6838\u540e\u5148\u4f1a\u88ab\u6dfb\u52a0\u5230<code>reg_work<\/code>\u4e2d\u53bb\uff0c\u7136\u540e\u8bfb\u53d6<code>regulatory.db<\/code>\u4e2d\u7684\u6570\u636e\uff0c\u5c06\u5176\u4e2d\u7684\u6570\u636e\u4fdd\u5b58\u5728\u4e00\u4e2a\u5168\u5c40\u94fe\u8868\u4e2d\u3002\u7136\u540e\u8c03\u7528<code>reg_regdb_work<\/code>\u5de5\u4f5c\u961f\u5217\uff0c\u5904\u7406\u8fd9\u4e2a\u94fe\u8868\u4e2d\u7684\u6570\u636e\uff0c\u4f7f\u7528\u94fe\u8868\u4e2d\u7684\u6700\u540e\u7684\u4e00\u4e2a\u7684\u76d1\u7ba1\u57df\u6765\u66f4\u65b0<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u76d1\u7ba1\u57df\u7ba1\u7406\u53ef\u4ee5\u63a5\u6536\u9a71\u52a8\u6216\u662f\u7528\u6237\u6001\u7684\u7ba1\u7406\u8bf7\u6c42\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6bd4\u8f83\u7edf\u4e00\u7684<code>API<\/code>\u63a5\u53e3\uff0c\u8fd9\u4e00\u70b9\u5728<code>reg_process_hint<\/code>\uff08<code>reg_work<\/code>\u5de5\u4f5c\u961f\u5217\u56de\u8c03\uff09\u548c<code>set_regdom<\/code>\uff08<code>reg_regdb_work<\/code>\u5de5\u4f5c\u961f\u5217\u56de\u8c03\uff09\u51fd\u6570\u4e2d\u90fd\u53ef\u4ee5\u7aa5\u89c1<\/p>\n\n\n\n<p>\u5176\u4e2d\u5173\u4e8e\u529f\u7387\u7b49\u4fe1\u606f\u7684\u8bfb\u53d6\u662f\u5728<code>regdb_query_country<\/code>\u51fd\u6570\u4e2d<code>reg_schedule_apply<\/code>\u8bfb\u53d6<code>DB<\/code>\u4e2d\u7684\u6570\u636e\uff0c\u7136\u540e\u52a0\u5165<code>reg_regdb_work<\/code>\u5de5\u4f5c\u961f\u5217\u4e2d<\/p>\n\n\n\n<p>\u6700\u540e\u5728<code>reset_regdomains<\/code>\u51fd\u6570\u4e2d\u66f4\u65b0\u4e86\u4e00\u4e2a\u5168\u5c40\u7684\u5f53\u524d\u76d1\u7ba1\u57df\u53d8\u91cf<code>cfg80211_regdomain<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rcu_assign_pointer(cfg80211_regdomain, new_regdom);<\/code><\/pre>\n\n\n\n<p><strong>\u5728\u540e\u7eed\u7684\u6d41\u7a0b\u4e2d\u5982\u679c\u9700\u8981\u8c03\u7528\u9a71\u52a8\u63a5\u53e3\u66f4\u65b0\u76d1\u7ba1\u57df\u4fe1\u606f\u53ef\u4ee5\u5728<code>wiphy_update_regulatory<\/code>\u51fd\u6570\u5c3e\u90e8\u901a\u8fc7\u8bfb\u53d6<code>cfg80211_regdomain<\/code>\u8fd9\u4e2a\u5168\u5c40\u53d8\u91cf\u6765\u5b9e\u73b0<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56fd\u5bb6\u7801\u7684\u8bfb\u53d6<\/h2>\n\n\n\n<p>\u56fd\u5bb6\u7801\u7684\u8bfb\u53d6\u9760<code>iw reg get<\/code>\u547d\u4ee4\u5b9e\u73b0\uff0c\u8fd9\u91cc\u8981\u5206\u6790<code>iw reg get<\/code>\u7684\u5177\u4f53\u6d41\u7a0b\uff0c<code>iw<\/code>\u4e2d\u662f\u4f7f\u7528\u4e86\u4e00\u4e2a<code>NL80211_CMD_GET_REG<\/code>\u7684<code>netlink<\/code>\u6d88\u606f\uff0c\u53d1\u9001\u540e\u67e5\u770b\u6d88\u606f\u8fd4\u56de\u503c<\/p>\n\n\n\n<p>\u5e95\u5c42\u8fd8\u662f\u4ece\u7ba1\u7406\u57df\u4e2d\u53bb\u8bfb\u53d6<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7b80\u5355\u5217\u51fa\u51fd\u6570\u8c03\u7528\u6808<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nl80211_get_reg_do\n    -&gt;cfg80211_get_dev_from_info\n      -&gt;__cfg80211_rdev_from_attrs<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">cfg80211\u4e0e\u9a71\u52a8\u7684\u4ea4\u4e92<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4ecechannel\u4fee\u6539\u770bcfg80211\u5230\u9a71\u52a8\u7684\u6d41\u7a0b<\/strong><\/h3>\n\n\n\n<p>\u5f00\u53d1\u8005\u901a\u5e38\u4f1a\u5728\u9a71\u52a8\u4e2d\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4fee\u6539\u4fe1\u9053\u7684\u63a5\u53e3\u4f8b\u5982<code>demo_cfg80211_channel_switch<\/code><\/p>\n\n\n\n<p>\u8fd9\u91cc\u5217\u51fa\u51fd\u6570\u8c03\u7528\u6808\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static struct cfg80211_ops demo_cfg80211_ops = {\n    .channel_switch = demo_cfg80211_channel_switch,\n}\n\ncfg80211_init\n    -&gt;wiphy_new(&amp;demo_cfg80211_ops, sizeof(struct demo_hw))\n    wiphy_register(wiphy)<\/code><\/pre>\n\n\n\n<p><code>static struct cfg80211_ops demo_cfg80211_ops<\/code>\u4e2d\u7684<code>demo_cfg80211_channel_switch<\/code>\u51fd\u6570\uff0c\u901a\u8fc7<code>wiphy_priv(wiphy)<\/code>\u548c<code>wiphy_register(wiphy)<\/code>\u88ab\u6ce8\u518c\u5728\u5185\u6838\u4e2d\uff0c\u6700\u7ec8\u5728<code>cfg80211<\/code>\u6a21\u5757\u4e2d\u901a\u8fc7<code>rdev-&gt;ops-&gt;channel_switch<\/code>\u88ab\u8c03\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static inline int rdev_channel_switch(struct cfg80211_registered_device *rdev,\n                      struct net_device *dev,\n                      struct cfg80211_csa_settings *params)\n{\n    int ret;\n    trace_rdev_channel_switch(&amp;rdev-&gt;wiphy, dev, params);\n    ret = rdev-&gt;ops-&gt;channel_switch(&amp;rdev-&gt;wiphy, dev, params);\n    trace_rdev_return_int(&amp;rdev-&gt;wiphy, ret);\n    return ret;\n}\n\nstatic int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)\n{\n    if (!rdev-&gt;ops-&gt;channel_switch ||\n        !(rdev-&gt;wiphy.flags &amp; WIPHY_FLAG_HAS_CHANNEL_SWITCH))\n        return -EOPNOTSUPP;\n\n    ......\n\n    wdev_lock(wdev);\n    err = rdev_channel_switch(rdev, dev, &amp;params);\n    wdev_unlock(wdev);\n}<\/code><\/pre>\n\n\n\n<p>\u5176\u5b9e\u5230\u8fd9\u91cc\u4ece\u7528\u6237\u7a7a\u95f4\u5230<code>cfg80211<\/code>\uff0c\u518d\u5230\u9a71\u52a8\u7684\u6574\u4e2a\u6d41\u7a0b\u5c31\u5df2\u7ecf\u6e05\u6670\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u91cc\u5217\u51fabackports\u4e0b\u56fd\u5bb6\u7801\u7684\u4fee\u6539\u7684\u5927\u81f4\u6d41\u7a0b\uff0c\u4ee5openwrt\u7cfb\u7edf\u4e3a\u4f8b\u5b50 \u4e0a\u5c42\u6a21\u5757\u914d\u7f6e\u56fd\u5bb6\u7801 \u53ef\u4ee5\u770b\u5230\u5bf9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-323","post","type-post","status-publish","format-standard","hentry","category-source-code-analysis"],"_links":{"self":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=323"}],"version-history":[{"count":4,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/323\/revisions"}],"predecessor-version":[{"id":357,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/323\/revisions\/357"}],"wp:attachment":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}