wpa_supplicant工具主要用于连接WiFi
一、获取wpa_supplicant和openssl-0.9.8za源码
从下载wpa_supplicant-2.5.tar.gz
从下载
二、编译wpa_supplicant和openssl-0.9.8za
2.1、解压wpa_supplicant和openssl-0.9.8za
tar zxvf openssl-0.9.8za.tar.gz
tar zxvf wpa_supplicant-2.5.tar.gz
2.2、拷贝wpa_supplicant-2.5/patches目录下openssl-0.9.8za-tls-extensions.patch补丁文件到openssl目录
cp wpa_supplicant-2.5/patches/openssl-0.9.8za-tls-extensions.patch ../openssl-0.9.8za
用patch命令打上补丁
patch -p1 < openssl-0.9.8za-tls-extensions.patch
2.3、编译openssl-0.9.8za
在openssl-0.9.8za目录下建立bin目录,存在openssl编译后库文件
mkdir -p /project/tool/wpa_supplicant/openssl-0.9.8za/bin
修改openssl-0.9.8za目录下Makefile
CC=arm-hisiv300-linux-gcc
AR=arm-hisiv300-linux-ar$(ARFLAGS) r
RANLIB=arm-hisiv300-linux-ranlib
INSTALLTOP=/project/tool/wpa_supplicant/openssl-0.9.8za/bin #刚才你建立的安装目录,要使用绝对路径,不然在make install的时候会出错
OPENSSLDIR=/project/tool/wpa_supplicant/openssl-0.9.8za/bin #刚才你建立的安装目录,要使用绝对路径,不然在make install的时候会出错
make && make install。
2.4、配置wpa_supplicant编译选项
cd wpa_supplicant-2.5/wpa_supplicant
cp defconfig .config
修改.config,增加以下内容:
CC=arm-hisiv300-linux-gcc -L/project/tool/wpa_supplicant/openssl-0.9.8za/bin/lib
CFLAGS+=-I/project/tool/wpa_supplicant/openssl-0.9.8za/bin/include
LIBS+=-L/project/tool/wpa_supplicant/openssl-0.9.8za/bin/lib
使用默认的.config配置编译出的wpa_supplicant可执行文件较大,通过配置.config文件中选项,可以减小wpa_supplicant可执行文件大小
编辑.config
注释掉CONFIG_DRIVER_HOSTAP=y
注释掉CONFIG_DRIVER_ATMEL=y
注释掉CONFIG_DRIVER_NL80211=y
反注释CONFIG_NO_STDOUT_DEBUG=y
反注释CONFIG_NO_CONFIG_WRITE=y
修改wpa_supplicant的Makefile将:
CFLAGS += -I$(abspath ../src)
CFLAGS += -I$(abspath ../src/utils)
修改为:
CFLAGS += -I../src
CFLAGS += -I../src/utils
2.5、编译wpa_supplicant
make
三、wpa_supplicant、wpa_cli测试
3.1、加载RT7601驱动
insmod /usr/local/ko/mtutil7601Usta.ko
insmod /usr/local/ko/mt7601Usta.ko
insmod /usr/local/ko/mtnet7601Usta.ko
3.2、启动无线网卡
ifconfig ra0 up
3.3、修改/usr/local/config/network/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant # ..........................
ctrl_interface_group=0 # ......
ap_scan=1
network={
ssid="KangNianYiHua"
scan_ssid=1
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
psk="knyh6688"
}
3.4、运行wpa_supplicant
wpa_supplicant -B -ira0 -c /usr/local/config/network/wpa_supplicant.conf -Dwext
-B: 后台运行wpa_supplicant
-ira0: 网络设备ra0
-c: 配置文件路径
-Dwext: 驱动类型
3.5、查看WIFI链接状态
iwpriv ra0 connStatus
ra0 connStatus:Connected(AP: KangNianYiHua[8C:A6:DF:B2:B1:DC])
3.6、设置IP地址和网关
ifconfig ra0 192.168.0.166
route add default gw 192.168.0.1
3.7、修改/etc/resolv.conf
nameserver 202.96.134.133
3.8、ping外网
# ping
PING (14.215.177.38): 56 data bytes
64 bytes from 14.215.177.38: seq=0 ttl=54 time=55.148 ms
64 bytes from 14.215.177.38: seq=1 ttl=54 time=81.010 ms
64 bytes from 14.215.177.38: seq=2 ttl=54 time=7.634 ms
64 bytes from 14.215.177.38: seq=3 ttl=54 time=81.256 ms
64 bytes from 14.215.177.38: seq=4 ttl=54 time=46.885 ms
64 bytes from 14.215.177.38: seq=5 ttl=54 time=8.008 ms
64 bytes from 14.215.177.38: seq=6 ttl=54 time=49.751 ms
四、wpa_cli使用方法
Run the command line tool wpa_cli to connect wifi
wpa_cli -p/data/system/wpa_supplicant -iwlan0
Then , it will let you set network interactively
some common command:
>scan = to scan the neighboring AP
>scan_results = show the scan results
>status = check out the current connection information
>terminate = terminate wpa_supplicant
>quit = exit wpa_cli
>add_network = it will return a network id to you
>set_network = set network variables (shows list of variables when run without arguments), success will return OK, or will return Fail
>select_network = select a network (disable others)
>disable_network = disable a network
>enable_network = enable a network
3: example
for AP that doesn`t have encryption
>add_network (It will display a network id for you, assume it returns 0)
>set_network 0 ssid “666”
>set_network 0 key_mgmt NONE
>enable_network 0
>quit
if normal, we have connectted to the AP “666”, now you need a IP to access internet, for example:
dhcpcd wlan0
if everything is ok, it will get an IP & can access internet
for AP that has WEP
>add_network (assume returns 1)
>set_network 1 ssid “666”
>set_network 1 key_mgmt NONE
>set_network 1 wep_key0 “your ap passwork”(if usting ASCII, it need double quotation marks, if using hex, then don`t need the double quotation marks)
>set_network 1 wep_tx_keyidx 0
>select_network 1 (optional, remember, if you are connecting with another AP, you should select it to disable the another)
>enable_network 1
and then ,get an IP to access internet
for AP that has WPA-PSK/WPA2-PSK
>add_network (assume returns 2)
>set_network 2 ssid “666”
>set_network 2 psk “your pre-shared key”
>select_network 2 (optional, remember, if you are connecting with another AP, you should select it to disable the another)
>enable_network 2
there is still some others options to be set, but wpa_supplicant will choose the default for you, the default will include all we need to set
and then ,get an IP to access internet
使用示例:
# wpa_cli -ira0
> scan
OK
> scan_r
bssid / frequency / signal level / flags / ssid
8c:a6:df:b2:b1:dc 2462 211 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] KangNianYiHua
00:87:36:3e:8b:2d 2412 195 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] 360123
24:05:0f:4d:34:48 2412 187 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] T8 wi-fi
78:d3:8d:ea:d9:6c 2442 189 [WPA2-PSK-CCMP][ESS]
58:6d:8f:23:71:95 2412 185 [WPA2-PSK-CCMP][ESS] mopon-jszc
88:25:93:c8:5a:1e 2437 179 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] mopon-test
b0:d5:9d:89:ba:5b 2412 177 [WPA2-PSK-CCMP][ESS] ____________
f0:b4:29:38:c9:f2 2412 175 [WPA2-PSK-CCMP][ESS]
78:d3:8d:12:ee:50 2462 177 [WPA2-PSK-CCMP][ESS]
80:56:f2:d5:9c:c5 2462 175 [WPA2-PSK-CCMP][ESS] minePC
70:77:81:32:78:6c 2437 173 [WPA2-PSK-CCMP][ESS] HP-Print-6c-LaserJet Pro MFP
88:25:93:a5:15:53 2422 179 [ESS] mopon-dev
> add_network
0
> set_network 0 ssid "KangNianYiHua"
OK
> set_network 0 psk "knyh6688"
OK
> enable_network 0
OK
> status
bssid=8c:a6:df:b2:b1:dc
ssid=KangNianYiHua
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
阅读(4357) | 评论(0) | 转发(0) |