我们都知道在高一点版本的PC的Linux中,一般都带有wpa_supplicant,校内网一般用这个登录,并且使用802.1x协议,今天就讲802.1x如何在mini2440中移植。
另外,这篇文章的很多部分借鉴了 http://blog.chinaunix.net/space.php?uid=12873540&do=blog&id=2912747这篇文章,并在这篇文章的基础上更新了详细的步骤,并且解决了这篇文章中没有提到的很多问题
1下载wpa_supplicant,在 http://hostap.epitest.fi/wpa_supplicant/
下载后解压
2修改Makefile
将wpa_supplicant-0.7.3/wpa_supplicant下的Makefile中
ifndef CC
CC=gcc
Endif
改为arm-linux-gcc
3再修改同一目录下defconfig文件.
山东大学的认证是用md5方式,将defconfig中除CONFIG_EAP_MD5=y外的其他CONFIG_EAP_xx去掉,因为,其他方式可能需要有相关的库,如tls就需要libtls.so库,为了编译方便,将用不到的尽量不要,免得编译时出错
# EAP-MD5
CONFIG_EAP_MD5=y //只保留这个,别的都注释掉
# EAP-MSCHAPv2
CONFIG_EAP_MSCHAPV2=y
# EAP-TLS
CONFIG_EAP_TLS=y
# EAL-PEAP
CONFIG_EAP_PEAP=y
# EAP-TTLS
CONFIG_EAP_TTLS=y
# EAP-GTC
CONFIG_EAP_GTC=y
# EAP-OTP
CONFIG_EAP_OTP=y
# EAP-SIM (enable CONFIG_PCSC, if EAP-SIM is used)
#CONFIG_EAP_SIM=y
# EAP-PSK (experimental; this is _not_ needed for WPA-PSK)
#CONFIG_EAP_PSK=y
# EAP-PAX
#CONFIG_EAP_PAX=y
# LEAP
CONFIG_EAP_LEAP=y
# EAP-AKA (enable CONFIG_PCSC, if EAP-AKA is used)
#CONFIG_EAP_AKA=y
# EAP-SAKE
#CONFIG_EAP_SAKE=y
# EAP-GPSK
#CONFIG_EAP_GPSK=y
# Include support for optional SHA256 cipher suite in EAP-GPSK
#CONFIG_EAP_GPSK_SHA256=y
然后执make就ok了,这时候我出现了错误:
../src/crypto/crypto_openssl.c:16:30: warning: openssl/opensslv.h: No such file or directory
../src/crypto/crypto_openssl.c:17:25: warning: openssl/err.h: No such file or directory
../src/crypto/crypto_openssl.c:18:25: warning: openssl/des.h: No such file or directory
../src/crypto/crypto_openssl.c:19:25: warning: openssl/aes.h: No such file or directory
../src/crypto/crypto_openssl.c:20:24: warning: openssl/bn.h: No such file or directory
../src/crypto/crypto_openssl.c:21:25: warning: openssl/evp.h: No such file or directory
在 www.openssl.org/source/下载openssl源码
进入openssl的源码目录,执行命令
./Configurelinux-elf-arm -DB_ENDIAN linux:'arm-linux-uclibc-gcc -mbig-endian'--prefix=/你要安装的目录
然后
make&& makeinstall
然后进入安装目录顺利找到所需的头文件和库文件。分别为:
/安装目录/include/openssl/*.h
/安装目录/lib/*.a
回到wpa_supplicant中:因为我们编译出的是静态库,那么需要修改相应的Makefile。
首先将刚才编译出的openssl的库文件(*.a)拷贝到wpa_supplicant源代码下。
修改Makefile中:
LIBS+= -lcrypto
LIBS_p+= -lcrypto
注释掉,改为
LIBS+= libcrypto.a
LIBS_p+= libcrypto.a
就是采用静态库文件。
然后make就可以了。
将编译出的wpa_supplicant下到开发板运行(注意,这里千万不要使用NFS来启动板子,因为后来还要用dhcp来改ip,这时候就连接不上了)
运行前要添加wpa_supplicant配置文件:在/etc/中建立lan.conf文件,内容如下:
[root@FriendlyARM /]# cat /etc/lan.conf
ctrl_interface=/var/run/wpa_supplicant
# ctrl_interface_group=wheel
ap_scan=0
network={
key_mgmt=IEEE8021X
eap=MD5
identity="028xxxxxx@local"//改为你自己的号,上外网去掉@local
password="2475xxxx" //改为你自己的密码
eapol_flags=0
}
创建wpa_supplicant执行目录:
mkdir-p /var/run/wpa_supplicant//这个很重要,要不然会提示Failedto initialize control interface '/var/run/wpa_supplicant'.
然后执行
[root@FriendlyARM /]# wpa_supplicant -B -ieth0 -c /etc/lan.conf -Dwired
如果提示“socket(PF_PACKET):Address family not supported by protocol”错误,需要重新配置并且编译内核:
Networkingsupport中Networkingoptions:
将PF_KEYsockets选中
IP:DHCP support 选中
然后重新编译内核,将内核下载到mini2440中运行
如果提示Unsupporteddriver 'wired',按照如下步骤:
(fromhttp://www.stevens.edu/itwiki/files/802.1x%20wired%20linux.doc)
-
Execute:ifconfig eth0 up
-
Execute:ifconfig eth0 promisc
-
Execute:wpa_supplicant -i eth0 -d -Dwired -c /etc/wpa_supplicant.conf
-
Execute:dhcpcd -o eth0
我的开发板是可以了。
但是这是认证,我们还要获得Ip等相关信息,所以要动刀dhcp软件,
幸好mini2440带有udhcpc嵌入式动态ip客户端。
所以我们执行
[root@FriendlyARM /]#udhcpc eth0
Sending select for 10.20.29.40...
udhcpc[321]: Sending select for 10.20.29.40...
Waiting on select...
udhcpc[321]: Waiting on select...
oooooh!!! got some!
udhcpc[321]: oooooh!!! got some!
Lease of 10.20.29.40 obtained, lease time 14400
udhcpc[321]: Lease of 10.20.29.40 obtained, lease time 14400
vforking and execle'ing /usr/share/udhcpc/default.script
udhcpc[321]: vforking and execle'ing /usr/share/udhcpc/default.script
script /usr/share/udhcpc/default.script failed: No such file or directory
udhcpc[323]: script /usr/share/udhcpc/default.script failed: No such file or dir
ectory
entering none listen mode
从上面我们可以看出有错误,明显可以看出是红色的地方的错误,原来是这个文件不存在,
到baidu,google搜索一下发现,用busybox下sample文件夹下的simple.script代替即可。
root@FriendlyARM /bin]#mkdir /usr/share/udhcpc
root@FriendlyARM /bin]# mv /mnt/simple.script /usr/share/udhcpc/default.script
下面再试下udhcpc看行不行
[root@FriendlyARM /bin]# udhcpc eht0
v dhcpc (v1.2.0) started
adapter index 3
adapter hardware address 00:13:f6:6c:87:89
vforking and execle'ing /usr/share/udhcpc/default.script
entering raw listen mode
Opening raw socket on ifindex 3
adding option 0x35
adding option 0x3d
adding option 0x3c
Sending discover...
Waiting on select...
oooooh!!! got some!
adding option 0x35
adding option 0x3d
adding option 0x3c
adding option 0x32
adding option 0x36
Sending select for 10.20.29.40...
Waiting on select...
oooooh!!! got some!
adding option 0x35
adding option 0x3d
adding option 0x3c
adding option 0x32
adding option 0x36
Sending select for 10.20.29.40...
Waiting on select...
oooooh!!! got some!
Lease of 10.20.29.40 obtained, lease time 14400
vforking and execle'ing /usr/share/udhcpc/default.script
deleting routers
adding dns 202.112.14.151
adding dns 202.112.14.161
entering none listen mode
基本就成功了,会一直有信息提示:
Initializing interface 'eth0' conf '/etc/lan.conf' driver'
Configuration file '/etc/lan.conf' -> '/etc/lan.conf'
Reading configuration file '/etc/lan.conf'
ctrl_interface='/var/run/wpa_supplicant'
ap_scan=0
Priority group 0
id=0 ssid=''
wpa_driver_wired_init: Added multicast membership with packet socket
Own MAC address: 08:90:90:90:90:90
RSN: flushing PMKID list in the driver
Setting scan request: 0 sec 100000 usec
EAPOL: SUPP_PAE entering state DISCONNECTED
EAPOL: Supplicant port status: Unauthorized
EAPOL: KEY_RX entering state NO_KEY_RECEIVE
EAPOL: SUPP_BE entering state INITIALIZE
EAP: EAP entering state DISABLED
EAPOL: Supplicant port status: Unauthorized
EAPOL: Supplicant port status: Unauthorized
Added interface eth0
EAPOL: External notification - EAP success=0
EAPOL: Supplicant port status: Unauthorized
EAPOL: External notification - EAP fail=0
EAPOL: Supplicant port status: Unauthorized
EAPOL: External notification - portControl=Auto
EAPOL: Supplicant port status: Unauthorized
Already associated with a configured network - generating associated event
Association info event
State: DISCONNECTED -> ASSOCIATED
Associated to a new BSS: BSSID=01:80:c2:00:00:03
No keys have been configured - skip key clearing
Select network based on association information
Network configuration found for the current AP
WPA: clearing AP WPA IE
WPA: clearing AP RSN IE
WPA: clearing own WPA/RSN IE
EAPOL: External notification - EAP success=0
EAPOL: Supplicant port status: Unauthorized
EAPOL: External notification - EAP fail=0
EAPOL: Supplicant port status: Unauthorized
EAPOL: External notification - portControl=Auto
EAPOL: Supplicant port status: Unauthorized
Associated with 01:80:c2:00:00:03
WPA: Association event - clear replay counter
WPA: Clear old PTK
EAPOL: External notification - portEnabled=0
EAPOL: Supplicant port status: Unauthorized
EAPOL: External notification - portValid=0
EAPOL: Supplicant port status: Unauthorized
EAPOL: External notification - portEnabled=1
EAPOL: SUPP_PAE entering state CONNECTING
EAPOL: SUPP_BE entering state IDLE
EAP: EAP entering state INITIALIZE
EAP: EAP entering state IDLE
下面测试下
root@FriendlyARM /bin]# ping www.baidu.com
PING www.baidu.com (119.75.218.70): 56 data bytes
64 bytes from 119.75.218.70: seq=0 ttl=52 time=8.422 ms
64 bytes from 119.75.218.70: seq=1 ttl=52 time=9.869 ms
64 bytes from 119.75.218.70: seq=2 ttl=52 time=10.525 ms
64 bytes from 119.75.218.70: seq=3 ttl=52 time=8.336 ms
64 bytes from 119.75.218.70: seq=4 ttl=52 time=8.180 ms