linux下WIFI模塊使用:IW工具交叉編譯以及配置


iw是Linux下的一種wifi配置工具,它替代了Wireless tools中的iwconfig,支持最近已添加到內核所有新的驅動程序,有兩種加密認證加密方式:open(開放系統認證+有效等線加密)、wep方式(共享秘鑰認證+有效等線加密)。

iw工具的交叉編譯

1. iw依賴libnl庫,首先得先安裝下載安裝libnl:http://www.infradead.org/~tgr/libnl/files/

cd /root/wifi
tar -xvf libnl-3.2.23.tar.gz
cd libnl-3.2.23
mkdir build
./configure --host=arm-linux --prefix=/root/wifi/libnl-3.2.23/build
make

make時報如下錯誤:

make[2]: Entering directory '/root/wifi/libnl-3.2.23/lib'
  CC       addr.lo
addr.c:1082: error: 'AF_RDS' undeclared here (not in a function)
addr.c:1088: error: 'AF_CAN' undeclared here (not in a function)
addr.c:1089: error: 'AF_TIPC' undeclared here (not in a function)
addr.c:1093: error: 'AF_ISDN' undeclared here (not in a function)
addr.c:1094: error: 'AF_PHONET' undeclared here (not in a function)
Makefile:1077: recipe for target 'addr.lo' failed
make[2]: *** [addr.lo] Error 1

解決方法:

在kernel源碼里搜索AF_RDS

grep "AF_RDS" * -nR /root/linux-3.4.2

 依次把上述幾個宏拷貝到lib/addr.c文件里。

make
make install

編譯並安裝完成后,在build目錄里有如下內容:

 

交叉編譯及移植

下載路徑:https://mirrors.edge.kernel.org/pub/software/network/iw/

cd /root/wifi
tar -xvf iw-4.0.tar.gz 
cd iw-4.0/
export PKG_CONFIG_PATH=/root/wifi/libnl-3.2.23/build/lib/pkgconfig:$PKG_CONFIG_PATH
make CC=arm-linux-gcc

這時會遇到如下錯誤:

 CC   info.o
info.c: In function 'print_phy_handler':
info.c:522: error: implicit declaration of function 'htole16'
Makefile:101: recipe for target 'info.o' failed
make: *** [info.o] Error 1

解決辦法:

在info.c里面添加如下宏:

#define htole16(X)  (((((uint16_t)(X)) << 8) | ((uint16_t)(X) >> 8)) & 0xffff)

然后再執行make CC=arm-linux-gcc,編譯通過。

把生成的iw文件復制到開發板的/usr/bin/目錄下。

測試IW工具

啟動開發板,接上wifi模塊,依次加載以下驅動模塊:

insmod rt2x00lib.ko
insmod rt2x00usb.ko
insmod rt2800lib.ko 
insmod  rt2800usb.ko 

打開wifi模塊:

ifconfig wlan0 up

 

列出WIFI網卡的性能:

/ # iw list
iw: error while loading shared libraries: libnl-genl-3.so.200: cannot open shared object file: No such file or directory

把libnl-3.2.23/build/lib/libnl-genl-3.so.200拷貝到開發板的/usr/lib目錄下,這里需要注意的是libnl-genl-3.so.200是一個軟鏈接,拷貝的真實動態庫應為軟鏈接指向的libnl-genl-3.so.200.18.0。

 再次執行iw時出現以下錯誤:

/ # iw list
iw: error while loading shared libraries: libnl-3.so.200: cannot open shared object file: No such file or directory

同理,把libnl-3.2.23/build/lib/libnl-3.so.200拷貝到開發板的/usr/lib目錄下,libnl-3.so.200 同樣也為指向libnl-3.so.200.18.0的一個軟鏈接。

幾個iw工具常用命令:

iw list // 列出WIFI網卡的性能
ifconfig wlan0 up //啟用wifi模塊
iw dev wlan0 scan // 掃描可連接WIFI AP
iw wlan0 connect dswei // 連接到不加密的WIFI,WIFI名字為dswei
iw wlan0 connect dswei keys d:0:baiwenwang123 // 連接到WEP加密的WIFI,WIFI名為dswei,d: default, 0: 第0個密碼
連接成功以后可以在手機上看到有設備連接

 這里需要注意的是路由器的無線加密方式要設置為WEP,否則網絡不通。本人使用的TL-WDR7620千兆版路由器不能設置加密方式,默認是WPA2-PSK/WPA-PSK加密方式,修改不了加密方式,坑!! 換了一個百兆路由器TL-WR842N,也是不可以設置無線加密方式,再見!來不及握手~~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM