WIFI工具移植之WAP_SUPPLICANT

欢迎转载~~~~~~

http://www.linuxfromscratch.org/blfs/view/svn/basicnet/wpa_supplicant.html可以参照这个文档

注:不同的opensll和libnl和wpa_supplicant可能会导致一些问题)
问题集合:
第一种错误:这里选择的wpa_supplicant为最新版本4.0
/ #  wpa_supplicant -B -c/etc/wpa_wpa2.conf  -iwlan0
Successfully initialized wpa_supplicant
nl80211: deinit ifname=wlan0 disabled_11b_rates=0
wlan0: Failed to initialize driver interface
第二种错误:
/ #  wpa_supplicant -B -c/etc/wpa_wpa2.conf  -iwlan0  //可以正常的连接到网上去
/ # wpa_cli -iwlan0 status  //而这里一直产生此类错误
Failed to connect to non-global ctrl_ifname: wlan0  error: Connection refused
上面的两种错误,在这几天的折磨中,对于内核的配置和wifi的驱动反复修改依然没有效果。
最后通过不断的移植opensll和libnlwap_supplicant的不同版本,此问题得以解决。(具体原因不清楚)
有知道具体问题的如何去修改的,请您一定要留言发表!!


这里建议大家使用:
第一种:libnl-3.2.23 openssl-1.0.1d wpa_supplicant-2.0
第二种:libnl-3.2.25 openssl-1.0.2c wpa_supplicant-2.0 

1wap_supplicant简介

在Linux移植iw工具的时候,我们讲过iw支持两种“认证/加密”的方式,这两种方式分别为:open与wep。但是现在很多的无线加密方法都是以wpa与wpa2(AES)方式加密的。那么这里就出现了iw工具不能再wpa与wpa2的无线加密上使用。

因此接下来移植一个wpa_supplicant的工具:这个工具支持上面介绍到的四种方式:

1.1、open

1.2、WEP

1.3、WPA(TKJP)

1.4、WAP2(AES)

 

2、移植wpa_supplicant工具

2.1、在移植之前,我们先要移植libopenssl的库

2.1、在ftp://ftp.openssl.org/snapshot/下载

openssl-1.0.2-stable-SNAP-20150630.tar.gz

2.2、解压openssl

#tar xzf openssl-1.0.2-stable-SNAP-20150630.tar.gz

#cd openssl-1.0.2-stable-SNAP-20150630/

#./config shared no-asm --prefix=$PWD/tmp

2.3、修改Makefile使其使用交叉编译器

修改Makefile:

CC= arm-linux-gcc

AR= arm-linux-ar $(ARFLAGS) r

RANLIB= arm-linux-ranlib

NM= arm-linux-nm

MAKEDEPPROG= arm-linux-gcc

2.4、重新编译openssl

[root@localhost openssl-1.0.2-stable-SNAP-20150630]# make
making all in crypto...
make[1]: Entering directory `/work/a9_board/WifiTools/STA/tools/openssl-1.0.2-stable-SNAP-20150630/crypto'
/usr/bin/perl ../util/mkbuildinf.pl "arm-linux-gcc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -march=pentium -DL_ENDIAN -O3 -fomit-frame-pointer -Wall" "linux-elf" >buildinf.h
arm-linux-gcc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -march=pentium -DL_ENDIAN -O3 -fomit-frame-pointer -Wall   -c -o cversion.o cversion.c
cversion.c:1:0: error: bad value (pentium) for -march= switch
make[1]: *** [cversion.o] 错误 1
make[1]: Leaving directory `/work/a9_board/WifiTools/STA/tools/openssl-1.0.2-stable-SNAP-20150630/crypto'
make: *** [build_crypto] 错误 1

[root@localhost openssl-1.0.2-stable-SNAP-20150630]#    

解决方法:去掉makefile中的 CFLAG= 中的 “-march=pentium”

3、移植wpa_supplicant 

3.1、下载wpa_supplicant-2.0.tar.gz

3.2、解压

#tar xzf wpa_supplicant-2.0.tar.gz 

3.3、配置

#cd wpa_supplicant-2.0/wpa_supplicant/

#cp defconfig .config

3.3.1、修改.config文件,指定交叉编译器与openssl和libn的库与头文件路径

 45 CC=arm-linux-gcc
 46 ## add libnl include
 47 CFLAGS += -I/work/a9_board/WifiTools/STA/tools/libnl-3.2.24/tmp/include/libnl3
 48 ## add libnl lib
 49 LIB += -L/work/a9_board/WifiTools/STA/tools/libnl-3.2.24/tmp/lib  -lnl-3 -lnl-genl-3
 50 # add openssl include
 51 CFLAGS += -I/work/a9_board/WifiTools/STA/tools/openssl-1.0.2-stable-SNAP-20150630/tmp/in    clude
 52 # add openssl lib
 53 LIB += -L/work/a9_board/WifiTools/STA/tools/openssl-1.0.2-stable-SNAP-20150630/tmp/lib -    lssl -lcrypto

[root@localhost wpa_supplicant]# make

3.3.2、编译与安装

[root@localhost wpa_supplicant]# make DESTDIR=$PWD/tmp install

3.4、wpa_supplicant在arm上的使用(wpa2方式)

3.4.1、wpa_supplicant包含两个主要的可执行工具:

wpa_supplicant与wpa_cli。wpa_supplicant与wpa_cli关系就是服务器和客户端的关系。使用时:在后台运行wpa_supplicant,使用wpa_cli来搜索、设置和链接网络。

3.4.2、构造配置wpa2方式的配置文件

在开发板文件系统的/etc/wpa_wpa2.conf

ctrl_interface=/var/run/wpa_supplicant

network={

    ssid="zxl407"

    psk=" 1 2 3 4a"

}

3.4.3、开启wpa_supplicant使其链接上路由器,配置,ping

Myroot /# wpa_supplicant -B -c/etc/wpa_wpa2.conf  -iwlan0

Myroot /# wpa_cli -iwlan0 status

Myroot /# ifconfig wlan0 192.168.1.234

Myroot /# ping 192.168.1.1

PING 192.168.1.1 (192.168.1.1): 56 data bytes

64 bytes from 192.168.1.1: seq=0 ttl=64 time=5593.111 ms

64 bytes from 192.168.1.1: seq=2 ttl=64 time=3592.853 ms

64 bytes from 192.168.1.1: seq=3 ttl=64 time=2592.651 ms

64 bytes from 192.168.1.1: seq=4 ttl=64 time=2614.203 ms

64 bytes from 192.168.1.1: seq=5 ttl=64 time=1614.140 ms

^C

--- 192.168.1.1 ping statistics ---

12 packets transmitted, 5 packets received, 58% packet loss

round-trip min/avg/max = 1614.140/3201.391/5593.111 ms

3.4.4、测试是否能访问外网

Myroot /# ping www.baidu.com

ping: bad address 'www.baidu.com'

Ping百度,出现错误的地址。需要添加/etc/resolv.conf添加DNS

Myroot # vi /etc/resolv.conf

Nameserver 192.168.1.1

其次还得配置网关,先使用route来查看

Myroot /# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

default         192.168.1.1     0.0.0.0         UG    0      0        0 wlan0

default         192.168.18.1    0.0.0.0         UG    0      0        0 eth0

192.168.1.0     *               255.255.255.0   U     0      0        0 wlan0

192.168.18.0    *               255.255.255.0   U     0      0        0 eth0

从上面看,wlan0的网关已经设置了,如果没有设置可以使用下面的命令来添加网关:

Myroot /# route add default gw 192.168.1.1 dev wlan0

Myroot /# ping www.baidu.com

PING www.baidu.com (180.97.33.107): 56 data bytes

64 bytes from 180.97.33.107: seq=0 ttl=54 time=897.973 ms

64 bytes from 180.97.33.107: seq=1 ttl=54 time=888.785 ms

64 bytes from 180.97.33.107: seq=2 ttl=54 time=253.869 ms

64 bytes from 180.97.33.107: seq=3 ttl=54 time=966.799 ms

64 bytes from 180.97.33.107: seq=4 ttl=54 time=182.072 ms

至此USBWIFI就能够去连接外网。










你可能感兴趣的:(WIFI工具移植之WAP_SUPPLICANT)