{"id":208,"date":"2025-10-18T18:15:47","date_gmt":"2025-10-18T10:15:47","guid":{"rendered":"http:\/\/47.99.178.170\/?p=208"},"modified":"2025-10-18T18:25:07","modified_gmt":"2025-10-18T10:25:07","slug":"%e3%80%90wifi%e3%80%91%e3%80%90linux%e3%80%9180211%e6%a8%a1%e5%9d%97%e4%b8%8e%e9%a9%b1%e5%8a%a8%e4%ba%a4%e4%ba%92api","status":"publish","type":"post","link":"https:\/\/www.garfield-blog.top\/?p=208","title":{"rendered":"\u3010wifi\u3011\u3010Linux\u301180211\u6a21\u5757\u4e0e\u9a71\u52a8\u4ea4\u4e92API"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u53c2\u8003\u6587\u6863<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/torvalds\/linux\/releases\/tag\/v5.4\">Release v5.4 \u00b7 torvalds\/linux<\/a><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u6982\u8ff0<\/h2>\n\n\n\n<p><code>cfg80211<\/code>\u6a21\u5757\u4e0e\u9a71\u52a8\u6a21\u5757\u7684\u4ea4\u4e92\u662f\u901a\u8fc7\u4e00\u7cfb\u5217<code>API<\/code>\u6765\u8fdb\u884c\u4ea4\u4e92\u7684\uff0c\u8fd9\u4e9b<code>API<\/code>\u662f\u7531\u5185\u6838\u5b9a\u4e49\u5728<code>include\/net\/cfg80211.h<\/code>\u4e2d\u7684<code>struct cfg80211_ops<\/code>\u7ed3\u6784\u4f53\u4e2d<\/p>\n\n\n\n<p>\u8fd9\u4e9b\u63a5\u53e3\u7531\u9a71\u52a8\u6a21\u5757\u5b9a\u4e49\u5e76\u5728\u9a71\u52a8\u521d\u59cb\u5316\u9636\u6bb5\u6ce8\u518c\u5728\u5185\u6838\u4e2d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6574\u4f53\u6d41\u7a0b<\/h2>\n\n\n\n<p>\u8fd9\u4e2a\u51fd\u6570\u901a\u8fc7\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\u5c06\u9a71\u52a8\u81ea\u5b9a\u4e49\u7684\u63a5\u53e3\u6ce8\u518c\u5230<code>cfg80211<\/code>\u6a21\u5757\u4e2d\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u521b\u5efawiphy\u8bbe\u5907\u5e76\u6ce8\u518c\u64cd\u4f5c\u96c6<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">\/* create a new wiphy for use with cfg80211 *\/<br>wiphy = wiphy_new(&amp;demo_cfg80211_ops, sizeof(struct demo_softc));<\/pre>\n\n\n\n<p>\u8fd9\u662f\u6700\u6838\u5fc3\u7684\u6ce8\u518c\u6b65\u9aa4\u3002<code>demo_cfg80211_ops<\/code> \u662f\u4e00\u4e2a <code>cfg80211_ops<\/code> \u7ed3\u6784\u4f53\uff0c\u5305\u542b\u4e86\u9a71\u52a8\u7a0b\u5e8f\u5b9e\u73b0\u7684\u6240\u6709<code>cfg80211<\/code>\u56de\u8c03\u51fd\u6570\u3002\u8fd9\u4e9b\u56de\u8c03\u51fd\u6570\u5b9a\u4e49\u4e86\u9a71\u52a8\u5982\u4f55\u54cd\u5e94\u7528\u6237\u7a7a\u95f4\u7684WiFi\u64cd\u4f5c\u8bf7\u6c42<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u8bbe\u7f6ewiphy\u8bbe\u5907\u5c5e\u6027<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sc = wiphy_priv(wiphy);<br>sc-&gt;wiphy = wiphy;<br>set_wiphy_dev(wiphy, sc-&gt;dev);<br>wiphy-&gt;privid = sc;<\/code><\/pre>\n\n\n\n<p>\u5c06\u9a71\u52a8\u7684\u79c1\u6709\u6570\u636e\u7ed3\u6784\u4e0e<code>wiphy<\/code>\u8bbe\u5907\u5173\u8054\uff0c\u5efa\u7acb\u53cc\u5411\u5f15\u7528\u5173\u7cfb<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u521d\u59cb\u5316wiphy\u529f\u80fd\u7279\u6027<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>demo_init_wiphy(sc);<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u51fd\u6570\u4f1a\u8bbe\u7f6e<code>wiphy<\/code>\u652f\u6301\u7684\u529f\u80fd\u7279\u6027\uff0c\u5982\u652f\u6301\u7684\u9891\u6bb5\u3001\u52a0\u5bc6\u65b9\u5f0f\u3001\u63a5\u53e3\u7c7b\u578b\u7b49\uff0c\u544a\u8bc9<code>cfg80211<\/code>\u8fd9\u4e2a\u9a71\u52a8\u80fd\u63d0\u4f9b\u54ea\u4e9b<code>WiFi<\/code>\u529f\u80fd<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u5411\u5185\u6838\u6ce8\u518cwiphy\u8bbe\u5907<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>if ((ret = wiphy_register(wiphy))) {<br> &nbsp;SSV_LOG_DBG(\"Could not register wiphy device\\n\");<br> &nbsp;ret = -ENODEV;<br> &nbsp;goto err_register_wiphy;<br>}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e00\u6b65\u5c06<code>wiphy<\/code>\u8bbe\u5907\u6b63\u5f0f\u6ce8\u518c\u5230<code>Linux<\/code>\u5185\u6838\u7684<code>cfg80211<\/code>\u5b50\u7cfb\u7edf\u4e2d\uff0c\u4f7f\u5176\u5bf9\u7528\u6237\u7a7a\u95f4\u53ef\u89c1<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u521b\u5efa\u7f51\u7edc\u63a5\u53e3<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#ifndef DIS_NETDEV_INIT<br>rtnl_lock();<br>wdev = demo_interface_add(sc, \"wlan%d\", NL80211_IFTYPE_STATION, NULL);<br>rtnl_unlock();<br>rtnl_lock();<br>wdev = demo_interface_add(sc, \"p2p0\", NL80211_IFTYPE_STATION, NULL);<br>rtnl_unlock();<br>#endif<\/code><\/pre>\n\n\n\n<p>\u521b\u5efa\u5177\u4f53\u7684\u7f51\u7edc\u63a5\u53e3\uff08\u5982<code>wlan0<\/code>\u3001<code>p2p0<\/code>\uff09\uff0c\u8fd9\u4e9b\u63a5\u53e3\u4f1a\u51fa\u73b0\u5728\u7cfb\u7edf\u7684\u7f51\u7edc\u63a5\u53e3\u5217\u8868\u4e2d\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e9b\u63a5\u53e3\u8fdb\u884c<code>WiFi<\/code>\u64cd\u4f5c<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6ce8\u518c\u673a\u5236\u7684\u5de5\u4f5c\u539f\u7406<\/h3>\n\n\n\n<p>\u5f53\u7528\u6237\u7a7a\u95f4\u7a0b\u5e8f\uff08\u5982<code>wpa_supplicant<\/code>\u3001<code>iw<\/code>\u547d\u4ee4\uff09\u901a\u8fc7<code>netlink<\/code>\u53d1\u9001<code>WiFi<\/code>\u914d\u7f6e\u8bf7\u6c42\u65f6\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>cfg80211\u5b50\u7cfb\u7edf<\/strong>\u63a5\u6536\u8bf7\u6c42<\/li>\n\n\n\n<li><strong>\u6839\u636ewiphy\u8bbe\u5907\u627e\u5230\u5bf9\u5e94\u7684\u9a71\u52a8<\/strong><\/li>\n\n\n\n<li><strong>\u8c03\u7528<code>demo_cfg80211_ops<\/code>\u4e2d\u76f8\u5e94\u7684\u56de\u8c03\u51fd\u6570<\/strong><\/li>\n\n\n\n<li><strong>\u9a71\u52a8\u6267\u884c\u5177\u4f53\u7684\u786c\u4ef6\u64cd\u4f5c<\/strong><\/li>\n<\/ol>\n\n\n\n<p>\u4f8b\u5982\uff0c\u5f53\u7528\u6237\u6267\u884c <code>iw wlan0 scan<\/code> \u65f6\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cfg80211<\/code>\u4f1a\u8c03\u7528 <code>demo_cfg80211_ops.scan<\/code> \u56de\u8c03\u51fd\u6570<\/li>\n\n\n\n<li>\u9a71\u52a8\u6536\u5230\u8c03\u7528\u540e\u63a7\u5236<code>WiFi<\/code>\u786c\u4ef6\u6267\u884c\u626b\u63cf\u64cd\u4f5c<\/li>\n\n\n\n<li>\u626b\u63cf\u7ed3\u679c\u901a\u8fc7<code>cfg80211<\/code>\u63a5\u53e3\u8fd4\u56de\u7ed9\u7528\u6237\u7a7a\u95f4<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u6837\uff0c\u9a71\u52a8\u5c31\u6210\u529f\u5730\u5c06\u81ea\u5df1\u7684<code>WiFi<\/code>\u529f\u80fd&#8221;\u63d2\u5165&#8221;\u5230\u4e86<code>Linux<\/code>\u6807\u51c6\u7684\u65e0\u7ebf\u7f51\u7edc\u7ba1\u7406\u6846\u67b6\u4e2d\uff0c\u5b9e\u73b0\u4e86\u786c\u4ef6\u62bd\u8c61\u548c\u6807\u51c6\u5316\u63a5\u53e3\u7684\u7edf\u4e00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\u6587\u6863 Release v5.4 \u00b7 torvalds\/linux \u6982\u8ff0 cfg80211\u6a21\u5757\u4e0e\u9a71\u52a8\u6a21\u5757\u7684\u4ea4 [&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":[6,9],"tags":[],"class_list":["post-208","post","type-post","status-publish","format-standard","hentry","category-linux-knowledge","category-wifi"],"_links":{"self":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/208","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=208"}],"version-history":[{"count":2,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/208\/revisions"}],"predecessor-version":[{"id":210,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/208\/revisions\/210"}],"wp:attachment":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}