{"id":367,"date":"2014-03-11T11:20:58","date_gmt":"2014-03-11T03:20:58","guid":{"rendered":"http:\/\/www.freezhongzi.info\/?p=367"},"modified":"2014-03-11T11:20:58","modified_gmt":"2014-03-11T03:20:58","slug":"%e4%bf%ae%e5%a4%8drg100a%e7%9a%84%e6%8c%89%e9%94%ae","status":"publish","type":"post","link":"https:\/\/bl4kraven.com\/index.php\/2014\/03\/11\/%e4%bf%ae%e5%a4%8drg100a%e7%9a%84%e6%8c%89%e9%94%ae\/","title":{"rendered":"\u4fee\u590dRG100A\u7684\u6309\u952e"},"content":{"rendered":"<p>\u6211\u4e70RG100A\u8def\u7531\u5668\u5f88\u4e45\u4e86\uff0c\u5237\u4e86OpenWRT\u540e\u4f5c\u4e3a\u516c\u53f8\u5de5\u4f5c\u7684\u4e3b\u529b\u8def\u7531\u5668\u81f3\u4eca\u3002\u56e0\u4e3a\u6211\u5e73\u65f6\u8981\u8c03\u8bd5\u5f88\u591a\u4e0d\u540c\u7f51\u6bb5\u7684\u8bbe\u5907\uff0c\u5168\u9760\u4e86OpenWRT\u7684VLAN\u529f\u80fd\u4ece\u800c\u8f7b\u677e\u89e3\u51b3\u3002\u4e3a\u4e86\u6d88\u9664\u8bb0\u5fc6IP\u5730\u5740\u9ebb\u70e6\u5c31\u4f7f\u7528\u4e86mDNS\uff0c\u4e3a\u4e86\u80fd\u628amDNS\u5e7f\u64ad\u5230\u5404\u4e2a\u5b50\u7f51\uff0c\u4e13\u95e8\u5728OpenWRT\u4e0a\u8dd1\u4e86\u4e2a\u7a0b\u5e8f\u8fdb\u884c\u76d1\u542c\u548c\u8f6c\u53d1mDNS\uff08\u4e0d\u8fc7\u540e\u6765\u53d1\u73b0\u592a\u5360\u8d44\u6e90\u5c31\u53bb\u6389\u4e86\uff0c\u6700\u4e3b\u8981\u662f\u8bbe\u5907\u4e0d\u591a\uff0cWindows\u5b89\u88c5mDNS\u4e00\u76f4\u6709\u95ee\u9898\uff0c\u5269\u4e0b\u7684\u53ea\u6709Ubuntu\u7b14\u8bb0\u672c\u548c\u865a\u62df\u673a\u4e0a\u8dd1\u7684Ubuntu\u4e86\uff09\u3002\u4f46\u6211\u4e00\u76f4\u4e0d\u592a\u6ee1\u610f\u7684\u662fRG100A\u540e\u9762\u7684\u6309\u952e\uff0c\u4e09\u4e2a\u6309\u952e\uff08WPS\u3001Wifi\u3001Reset)OpenWRT\u4e0d\u77e5\u4e3a\u4f55\u4e0d\u652f\u6301\u3002\u6700\u8fd1\u51e0\u5929\u95f2\u6765\u65e0\u4e8b\u5c31\u60f3\u5f7b\u5e95\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u9996\u5148\u5c31\u662f\u627e\u95ee\u9898\u7684\u6839\u6e90\u4e86\uff0c\u8fd9\u4e2a\u9664\u4e86\u770b\u4ee3\u7801\u5916\u522b\u65e0\u4ed6\u9014\u4e86\u3002\u4ece<a href=\"https:\/\/dev.openwrt.org\/wiki\/GetSource\">OpenWRT\u5b98\u7f51<\/a>\u4e0b\u8f7d\u4ee3\u7801\uff0c\u6211\u88c5\u7684\u662f\u8001\u7248\u7684Backfire 10.03\uff0c\u5185\u6838\u662flinux-2.6.32.27\uff08\u4e4b\u524d\u8bd5\u8fc7\u7f16\u8bd1\u6700\u65b0\u7684\u7248\u672c\uff0c\u4f46\u4e00\u70e7\u8fdb\u53bb\u8981\u4e48\u7f51\u7edc\u6709\u95ee\u9898\uff0c\u8981\u4e48\u5c31\u76f4\u63a5\u5d29\u6e83-_-!!!)\uff0c\u7f16\u8bd1\u4e86\u5927\u534a\u5929\uff0c\u4e3b\u8981\u662f\u4e0b\u8f7d\u5404\u79cd\u8f6f\u4ef6\u5305\uff0c\u5e78\u4e8f\u7f51\u7edc\u7ed9\u529b\uff08\u7535\u4fe1\u5bbd\u5e26\u9a6c\u4e0a\u8981\u5347\u523012M\u4e86:))\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u627e\u76f8\u5173\u7684\u9a71\u52a8\u4ee3\u7801\uff0c\u8fd9\u91cc\u4e3b\u8981\u662f\u4e09\u4e2a\u9a71\u52a8\uff1ainput_gpio_button\u3001input_polldev\u3001button-hotplug\u3002<\/p>\n<ol>\n<li>\n<p>input_gpio_button\u8d1f\u8d23\u4f4e\u5c42\u8bfb\u53d6\u6309\u952e\u7684GPIO\u53e3\u72b6\u6001\u8f6c\u6362\u6210input event\uff08\u6211\u8fd9\u91cc\u628a\u628aWifi\u952e\u6620\u5c04\u6210BTN_0, WPS\u952e\u6620\u5c04\u6210BTN_1\uff0c\u6ca1\u7528Reset\u952e\uff09\u3002\u8fd9\u4e2a\u4ee3\u7801\u5728build_dir\/linux-brcm63xx\/linux-2.6.32.27\/drivers\/input\/misc\/gpio_buttons.c\u4e0a\u3002<\/p>\n<\/li>\n<li>\n<p>input_polldev\u662finput system\u7684input_dev,\u56e0\u4e3a\u8fd9\u4e09\u4e2a\u6309\u952e\u7684GPIO\u90fd\u4e0d\u652f\u6301\u4e2d\u65ad\uff0c\u6240\u4ee5\u53ea\u80fd\u91c7\u53d6\u8f6e\u8be2\u65b9\u5f0f\uff0c\u8fd9\u4e2ainput_polldev\u5c31\u662f\u5e72\u8fd9\u4e2a\u4e8b\u7684\u3002\u5b83\u4e0d\u65ad\u901a\u8fc7input_gpio_button\u67e5\u8be2GPIO\u72b6\u6001,\u7136\u540e\u53d1\u9001input event\u3002\u6e90\u7801\u5728build_dir\/linux-brcm63xx\/linux-2.6.32.27\/drivers\/input\/input-polldev.c\u3002<\/p>\n<\/li>\n<li>\n<p>button-hotplug\u662f\u9762\u5411\u5e94\u7528\u5c42\u63a5\u53e3\u7684\uff0c\u628ainput_event\u8f6c\u6362\u6210hotplug\u6d88\u606f\u3002\u8fd9\u4e2a\u4e3b\u8981\u662f\u5185\u6838\u7684hotplug\u673a\u5236\uff08\u901a\u8fc7\u5185\u6838netlink\u6280\u672f\u5e7f\u64ad\u5bf9\u8c61\u6d88\u606f\uff0c\u4ece\u800c\u652f\u6301\u70ed\u63d2\u62d4\u4e4b\u7c7b\u7684)\u3002OpenWRT\u7528\u7684\u662fhotplug2\uff0c\u5177\u4f53\u914d\u7f6e\u5728\/etc\/hotplug.d\u4e0b\u3002\u5982\u679c\u8981\u5728\u5e94\u7528\u5c42\u5904\u7406\u6309\u952e\u4e8b\u4ef6\uff0c\u5c31\u65b0\u5efa\/etc\/hotplug.d\/button\u76ee\u5f55\uff0c\u5199\u4e2a\u6d4b\u8bd5\u811a\u672c\uff0c\u7528\u6309\u952e\u70b9\u4eae\u524d\u9762\u677f\u7684WPS LED\u706f\uff0c\u53c2\u8003<a href=\"http:\/\/wiki.openwrt.org\/doc\/howto\/hardware.button\">\u8fd9\u91cc<\/a>\u3002\u6e90\u7801\u5728build_dir\/linux-brcm63xx\/button-hotplug\/button-hotplug.c\u3002<\/p>\n<pre><code>#!\/bin\/sh\nLED_NUM=24\n[ -e \"\/sys\/class\/gpio\/gpio${LED_NUM}\/value\" ] || echo $LED_NUM &gt; \/sys\/class\/gpio\/export\n[ -e \"\/sys\/class\/gpio\/gpio${LED_NUM}\/direction\" ] &amp;&amp; echo out &gt; \/sys\/class\/gpio\/gpio${LED_NUM}\/direction\n\nturn_on()\n{\n    echo 0 &gt; \/sys\/class\/gpio\/gpio${LED_NUM}\/value\n}\n\nturn_off()\n{\n    echo 1 &gt; \/sys\/class\/gpio\/gpio${LED_NUM}\/value\n}\n\nif [ \"$ACTION\" = \"pressed\" ]; then\n    turn_on\nelse\n    turn_off\nfi\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u800c\u51fa\u95ee\u9898\u7684\u9a71\u52a8\u662finput_gpio_button\uff0c\u5b83\u4f9d\u8d56\u5e73\u53f0board\u7684GPIO\u6309\u952e\u914d\u7f6e\uff0c\u800c\u6211\u8c03\u8bd5\u540e\u53d1\u73b0board\u521d\u59cb\u5316\u7ed9\u7684button GPIO\u53c2\u6570\u4e0d\u5bf9\u3002\u8fd9\u6837\u8981\u4e48\u6539board\u521d\u59cb\u5316\u4ee3\u7801\uff0c\u8981\u4e48\u5728input_gpio_button \u4ee3\u7801\u91cc\u624b\u52a8\u6307\u5b9aGPIO\u53c2\u6570\u3002\u6211\u4e0d\u60f3\u91cd\u65b0\u7f16\u8bd1\u6574\u4e2a\u5185\u6838\uff0c\u6240\u4ee5\u9009\u62e9\u540e\u8005\uff0c\u4e0b\u9762\u662f\u8865\u4e01\uff1a<\/p>\n<pre><code>--- ..\/linux-brcm63xx\/linux-2.6.32.27\/drivers\/input\/misc\/gpio_buttons.c 2014-02-27 16:58:19.502642430 +0800\n+++ gpio_buttons.c  2014-03-06 11:05:50.939708245 +0800\n@@ -29,6 +29,31 @@\n\n #define DRV_NAME   \"gpio-buttons\"\n\n+static struct gpio_button my_all_buttons[] = {\n+        {\n+            .gpio = 34,\n+            .active_low = 1,\n+            .desc = \"wifi\",\n+            .type = EV_KEY,\n+            .code = BTN_0,\n+            .threshold = 3,\n+        },\n+        {\n+            .gpio = 37,\n+            .active_low = 1,\n+            .desc = \"wps\",\n+            .type = EV_KEY,\n+            .code = BTN_1,\n+            .threshold = 3,\n+        },\n+};\n+\n+static struct gpio_buttons_platform_data my_buttons_datas = {\n+    .buttons = my_all_buttons,\n+    .nbuttons = 2,\n+    .poll_interval = 100,\n+};\n+\n struct gpio_button_data {\n    int last_state;\n    int count;\n@@ -55,6 +80,9 @@\n    if (state != bdata-&gt;last_state) {\n        unsigned int type = button-&gt;type ?: EV_KEY;\n\n+        \/\/ I add\n+        printk(KERN_DEBUG \"type %d, code %d, active %d\", type, button-&gt;code, state ^ button-&gt;active_low);\n+\n        input_event(input, type, button-&gt;code,\n                !!(state ^ button-&gt;active_low));\n        input_sync(input);\n@@ -84,7 +112,8 @@\n\n static int __devinit gpio_buttons_probe(struct platform_device *pdev)\n {\n-   struct gpio_buttons_platform_data *pdata = pdev-&gt;dev.platform_data;\n+   \/\/struct gpio_buttons_platform_data *pdata = pdev-&gt;dev.platform_data;\n+   struct gpio_buttons_platform_data *pdata = &amp;my_buttons_datas;\n    struct device *dev = &amp;pdev-&gt;dev;\n    struct gpio_buttons_dev *bdev;\n    struct input_polled_dev *poll_dev;\n@@ -95,6 +124,15 @@\n    if (!pdata)\n        return -ENXIO;\n\n+    \/\/ I add\n+    printk(KERN_DEBUG \"platform_data buttons: %d poll_interval: %d \", pdata-&gt;nbuttons, pdata-&gt;poll_interval);\n+   for (i = 0; i &lt; pdata-&gt;nbuttons; i++) {\n+        printk(KERN_DEBUG \"button gpio %d %s type:%d code:%d\", pdata-&gt;buttons[i].gpio, pdata-&gt;buttons[i].desc, \n+                                                               pdata-&gt;buttons[i].type, pdata-&gt;buttons[i].code);\n+    }\n+\n+    printk(KERN_DEBUG \"platform_device name %s\", pdev-&gt;name);\n+\n    bdev = kzalloc(sizeof(struct gpio_buttons_dev) +\n               pdata-&gt;nbuttons * sizeof(struct gpio_button_data),\n               GFP_KERNEL);\n@@ -189,7 +227,8 @@\n static int __devexit gpio_buttons_remove(struct platform_device *pdev)\n {\n    struct gpio_buttons_dev *bdev = platform_get_drvdata(pdev);\n-   struct gpio_buttons_platform_data *pdata = bdev-&gt;pdata;\n+   \/\/struct gpio_buttons_platform_data *pdata = bdev-&gt;pdata;\n+   struct gpio_buttons_platform_data *pdata = &amp;my_buttons_datas;\n    int i;\n\ninput_unregister_polled_device(bdev-&gt;poll_dev);\n<\/code><\/pre>\n<p>\u4e2d\u95f4\u52a0\u4e86\u4e9b\u8c03\u8bd5\u4fe1\u606f\uff0c\u4e3b\u8981\u662f\u90a3\u4e2agpio_buttons_platform_data my_buttons_datas\uff0c\u9ed8\u8ba4\u662fplatform_device *pdev\u6307\u5b9a\u7684\u3002\u8fd9\u4e2a\u5728board init\u91cc\u6307\u5b9a\uff0c\u6709\u5174\u8da3\u7684\u53ef\u4ee5\u770b\u770barch\/mips\/bcm63xx\/board_bcm963xx.c\uff0c\u91cc\u9762\u6709\u5f88\u591a\u677f\u5b50\uff0cRG100A\u5bf9\u5e94\u7684\u677f\u5b50\u662f96358VW2\uff0c\u8fd9\u4e2a\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884cdmesg | grep board\u770b\u51fa\u6765\u3002<\/p>\n<p>\u6709\u5173RG100A\u7684GPIO\u53c2\u6570\uff0c\u7f51\u4e0a\u6709\u516c\u5e03\uff0c\u6211\u53ea\u6458\u6284\u4e00\u4e9b\uff1a<\/p>\n<pre><code>button gpio:\n    gpio34 wifi\n    gpio36 reset\n    gpio37 wps\n\nled gpio:\n    gpio0 usb\n    gpio4 power\n    gpio8 net\n    gpio22 dsl\n    gpio24 wps\n<\/code><\/pre>\n<p>\u8fd9\u6837\u4fee\u6539\u597d\u540e\uff0c\u8f7d\u5165\u9a71\u52a8\u5c31\u53ef\u4ee5\u901a\u8fc7\u6309\u952e\u63a7\u5236RG100A\u524d\u9762\u677fWPS\u706f\u4e86\uff0c\u4e0d\u8fc7\u6682\u65f6\u8fd8\u60f3\u4e0d\u51fa\u6765\u53ef\u4ee5\u7528\u6765\u5e72\u4ec0\u4e48\u3002\u6211\u73b0\u5728\u7528RG100A\u7684USB\u53e3\u53ef\u4ee5\u9a71\u52a8\u6444\u50cf\u5934\u4e86\uff0c\u5c31\u641e\u4e86\u4e2a\u8fdc\u7a0b\u62cd\u7167\u7684\u4e1c\u897f\uff0c\u8fd8\u4e0d\u9519\uff0c\u5c31\u662f\u4e0d\u592a\u7a33\u5b9a-_-!!!\u3002\u4e0b\u4e00\u6b65\u7ec6\u770blinux\u7684 input system\uff0c\u4e4b\u524d\u5927\u6982\u770b\u4e86\u4e00\u4e9b\uff0c\u4e86\u89e3\u4e86\u4e9b\u539f\u7406\uff0c\u7406\u89e3\u6709\u8bef\u4e5f\u8bf4\u4e0d\u5b9a\u3002\u8981\u5199\u7684\u592a\u591a\u4e86\u5199\u4e0d\u8fc7\u6765\u4e86\uff0c\u5c31\u5199\u8fd9\u4e9b\u5427\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4e70RG100A\u8def\u7531\u5668\u5f88\u4e45\u4e86\uff0c\u5237\u4e86OpenWRT\u540e\u4f5c\u4e3a\u516c\u53f8\u5de5\u4f5c\u7684\u4e3b\u529b\u8def\u7531\u5668\u81f3\u4eca\u3002 &hellip; <a href=\"https:\/\/bl4kraven.com\/index.php\/2014\/03\/11\/%e4%bf%ae%e5%a4%8drg100a%e7%9a%84%e6%8c%89%e9%94%ae\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a> <a href=\"https:\/\/bl4kraven.com\/index.php\/2014\/03\/11\/%e4%bf%ae%e5%a4%8drg100a%e7%9a%84%e6%8c%89%e9%94%ae\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[],"class_list":["post-367","post","type-post","status-publish","format-standard","hentry","category-openwrt","category-program"],"_links":{"self":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/comments?post=367"}],"version-history":[{"count":0,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"wp:attachment":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}