交叉编译通过,实测可用。在此记录一下,备忘。
hostapd v2.6依赖libnl和openssl,因此,需要先交叉编译它俩。需要注意,openssl不同版本API不同,如果不能匹配hostapd v2.6会导致编译报错。libnl我用的是libnl-3.2.23,可以用,因此没有尝试其他版本。
源码下载地址:点此下载
1、交叉编译libnl
解压后进入libnl根目录
执行:./configure --host=mips-linux-gnu --prefix=/home/beihj/mips-gcc472-glibc216-32bit/mips-linux-gnu/libc/uclibc/usr PKG_CONFIG_PATH=/home/beihj/mips-gcc472-glibc216-32bit/mips-linux-gnu/libc/uclibc/usr/lib/pkgconfig CC=/home/beihj/mips-gcc472-glibc216-32bit/bin/mips-linux-uclibc-gnu-gcc
其中,--prefix是源码编译完成后的安装路径,最好安装在交叉编译链中,这样编译其他源代码对libnl有依赖时,可不必特别指明libnl库的路径。在交叉编译链中库安装多了以后,你会发现你的交叉编译链越来越好用了。
PKG_CONFIG_PATH是.pc文件的搜索路径
CC是交叉编译工具的路径
--prefix、PKG_CONFIG_PATH、CC都需要换成自己相应的路径
接下来,make ,这时会报错:
addr.c:1027: error: 'AF_RDS' undeclared here (not in a function)
addr.c:1033: error: 'AF_CAN' undeclared here (not in a function)
addr.c:1034: error: 'AF_TIPC' undeclared here (not in a function)
addr.c:1038: error: 'AF_ISDN' undeclared here (not in a function)
addr.c:1039: error: 'AF_PHONET' undeclared here (not in a function)
make[2]: *** [addr.lo] Error 1
make[2]: Leaving directory `/work/projects/libnl-3.2.23/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/work/projects/libnl-3.2.23/lib'
make: *** [all-recursive] Error 1
解决方法:在libnl-3.2.23/lib/addr.c 中增加下面这些宏
/* Supported address families. */
#define AF_RDS 21 /* RDS sockets */
#define AF_CAN 29 /* Controller Area Network */
#define AF_ISDN 34 /* mISDN sockets */
#define AF_PHONET 35 /* Phonet sockets */
再次 make,编译完成后,执行 make install安装libnl库
2、交叉编译openssl
解压后进入openssl根目录,执行./config no-asm shared --prefix=/home/beihj/mips-gcc472-glibc216-32bit/mips-linux-gnu/libc/uclibc/usr/usr
然后修改Makefile文件:将CC、AR、RANLIB、MAKEDEPPROG改为自己相应的交叉编译工具
CC= mips-linux-uclibc-gnu-gcc
AR= mips-linux-uclibc-gnu-ar $(ARFLAGS) r
RANLIB= mips-linux-uclibc-gnu-ranlib
MAKEDEPPROG= mips-linux-uclibc-gnu-gcc
然后,执行make;make install
3、交叉编译hostapd
解压后进入hosdtapd-2.6/hostapd
cp defconfig .config
打开 .config 将CONFIG_LIBNL32前面的注释去掉,这样编译的时候就会去找libnl3.2的库
修改Makefile
CC=arm-linux-gcc /* 去掉前面的宏定义 */
make
编译完成后会在hostapd根目录下生成hostapd和hostapd_cli
4、测试
将hostapd和hostapd_cli放到开发板上 usr/bin目录下
ifconfig eth0 down
ifconfig wlan0 up
ifconfig wlan0 192.168.0.10 netmask 255.255.255.0
udhcpd /etc/udhcpd.conf &
hostapd -d /etc/hostapd.conf &
/etc/udhcpd.conf文件内容修改如下:
# The start and end of the IP lease block
start 192.168.0.10 #default: 192.168.0.20
end 192.168.0.100 #default: 192.168.0.254
# The interface that udhcpd will use
interface wlan0 #default: eth0
分配的IP要与wlan0设置的IP处于同一网段,interface设置为wlan0。
/etc/hostapd.conf文件内容如下:
interface=wlan0
ssid=XXX /* 自己任意设定 */
channel=9
hw_mode=g
ignore_broadcast_ssid=0
auth_algs=1
wpa=3
wpa_passphrase=******** /* 密码自己任意设定 */
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCM