飞凌2440开发板制作路由器
原文链接:http://www.cnblogs.com/NickQ/p/8976054.html
环境:Linux3.0内核 RT3070(无线) + DM9000(有线)
在s3c2440上实现SoftAP模式
-
配置内核
- 配置完内核开始编译后,报如下错误。
解决方法:make clean后重新编译。
参考:https://blog.csdn.net/tonkeytong/article/details/52672782
[nick@XQLY linux-3.0]$ make
CHK include/linux/version.h
CHK include/generated/utsrelease.h
make[1]: “include/generated/mach-types.h”是最新的。
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
LD fs/nfs/nfs.o
fs/nfs/client.o: file not recognized: File truncated
make[2]: *** [fs/nfs/nfs.o] 错误 1
make[1]: *** [fs/nfs] 错误 2
make: *** [fs] 错误 2
-
libnl 移植
Hostapd依赖于openssl与libnl两个库。
下载解压
wget
tar zvxf libnl-3.2.25.tar.gz
cd ./libnl-3.2.25
mkdir install
配置并编译
./configure --prefix=`pwd`/install --build=i686-pc-linux --host=arm-linux CC=/opt/xtools/arm920t/bin/arm-linux-gcc AS=/opt/xtools/arm920t/bin/arm-linux-as AR=/opt/xtools/arm920t/bin/arm-linux-ar LD=/opt/xtools/arm920t/bin/arm-linux-ld NM=/opt/xtools/arm920t/bin/arm-linux-nm RANLIB=/opt/xtools/arm920t/bin/arm-linux-ranlib OBJDUMP=/opt/xtools/arm920t/bin/arm-linux-objdump STRIP=/opt/xtools/arm920t/bin/arm-linux-strip
make && make install
-
openssl 移植
下载解压
wget
tar zxvf openssl-0.9.8zf.tar.gz
cd ./openssl-0.9.8zf
patch -p1 < ../patch/openssl-0.9.8zf-tls-extensions.patch
mkdir install
修改Makefile
将
OPTIONS= no-camellia no-capieng no-cms no-gmp no-jpake no-krb5 no-mdc2 no-montasm no-rc5 no-rfc3779 no-seed no-shared no-zlib no-zlib-dynamic
CONFIGURE_ARGS=dist
改为
#OPTIONS= no-camellia no-capieng no-cms no-gmp no-jpake no-krb5 no-mdc2 no-montasm no-rc5 no-rfc3779 no-seed no-shared no-zlib no-zlib-dynamic
CC=/opt/xtools/arm920t/bin/arm-linux-gcc
CONFIGURE_ARGS=dist
修改以下变量
INSTALLTOP= /home/nick/fl2440/3rdparty/wireless/openssl/openssl-0.9.8zf/install
OPENSSLDIR= /home/nick/fl2440/3rdparty/wireless/openssl/openssl-0.9.8zf/install
CC= /opt/xtools/arm920t/bin/arm-linux-cc
AR= /opt/xtools/arm920t/bin/arm-linux-ar $(ARFLAGS) r
ARD= /opt/xtools/arm920t/bin/arm-linux-ar $(ARFLAGS) d
RANLIB= /opt/xtools/arm920t/bin/arm-linux-ranlib
编译安装
sudo make
sudo make install
-
Hostapd 移植
hostapd 是一个用户态用于AP和认证服务器的守护进程。它实现了IEEE 802.11相关的接入管理,IEEE 802.1X/WPA/WPA2/EAP 认证, RADIUS客户端,EAP服务器和RADIUS 认证服务器。Linux下支持的驱动有:Host AP,madwifi,基于mac80211的驱动。
采用脚本,编译安装
#!/bin/bash
# Description:
# This shell script used download and compile hostapd for ARM
PROJ_PATH=`pwd`
OPENSSL_PATH=`pwd`/../openssl/
LIBNL_PATH=`pwd`/../libnl/
if [ -z $CROSSTOOL ] ; then
CROSSTOOL=/opt/xtools/arm920t/bin/arm-linux-
fi
function msg_banner()
{
echo ""
echo "+-----------------------------------------------------------------------"
echo "| $1 "
echo "+-----------------------------------------------------------------------"
echo ""
}
function check_result()
{
if [ $? != 0 ] ; then
echo ""
echo "+-----------------------------------------------------------------------"
echo "| $1 "
echo "+-----------------------------------------------------------------------"
echo ""
exit ;
fi
}
function export_cross()
{
# export cross toolchain
export CC=${CROSSTOOL}gcc
export AS=${CROSSTOOL}as
export AR=${CROSSTOOL}ar
export LD=${CROSSTOOL}ld
export NM=${CROSSTOOL}nm
export RANLIB=${CROSSTOOL}ranlib
export OBJDUMP=${CROSSTOOL}objdump
export STRIP=${CROSSTOOL}strip
# export cross configure
export CONFIG_CROSS=" --build=i686-pc-linux --host=arm-linux "
# Clear LDFLAGS and CFLAGS
export LDFLAGS=
export CFLAGS=
}
function compile_hostapd()
{
SRC_NAME=hostapd-2.5
PACK_SUFIX=tar.gz
if [ -f ${PREFIX_PATH}/${IMG_NAME} ] ; then
return 0;
fi
msg_banner "Start cross compile $SRC_NAME "
if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
wget https://w1.fi/releases/${SRC_NAME}.${PACK_SUFIX}
check_result "ERROR: download ${SRC_NAME} failure"
fi
tar -xzf ${SRC_NAME}.${PACK_SUFIX}
cd ${SRC_NAME}/hostapd
cp defconfig .config
#sed -i -e "s|^.*openssl/include.*|CFLAGS += -I${OPENSSL_PATH}/install/include|g" .config
#sed -i -e "s|^.*openssl/lib.*|LIBS += -L${OPENSSL_PATH}/install/lib|g" .config
sed -i -e "s|^.*libnl include files.*|CFLAGS += -I${LIBNL_PATH}/install/include/libnl3|g" .config
sed -i -e "s|^.*libnl library files.*|LIBS += -L${LIBNL_PATH}/install/lib|g" .config
sed -i -e "s|^.*CONFIG_LIBNL32=.*|CONFIG_LIBNL32=y|g" .config
export PKG_CONFIG_PATH=${LIBNL_PATH}/install/lib/pkgconfig/:$PKG_CONFIG_PATH
export CFLAGS="-I${OPENSSL_PATH}/install/include"
export LIBS="-L${OPENSSL_PATH}/install/lib"
make
cp hostapd ${PROJ_PATH}/
cp $LIBNL_PATH/install/lib/libnl-3.so.200.20.0 ${PROJ_PATH}/libnl-3.so.200
cp $LIBNL_PATH/install/lib/libnl-genl-3.so.200.20.0 ${PROJ_PATH}/libnl-genl-3.so.200
cd -
}
export_cross
if [ ! -d $OPENSSL_PATH/install/lib ] ; then
cd $OPENSSL_PATH
./build.sh
cd -
else
msg_banner "openssl already cross compiled!"
fi
if [ ! -d $LIBNL_PATH/install/lib ] ; then
cd $LIBNL_PATH
./build.sh
cd -
else
msg_banner "libnl already cross compiled!"
fi
compile_hostapd
将生成的hostapd,和库拷到开发板/bin与/lib目录下,并给予可执行权限。这里采用lszrz+tftp方式
[nick@XQLY hostapd]$ sz hostapd
rz
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring hostapd...
100% 1768 KB 1768 KB/sec 00:00:01 0 Errors
[nick@NickQ_fl2440 bin]# tftp -gr hostapd 192.168.110.1
hostapd 100% |*******************************| 1768k 0:00:00 ETA
[nick@NickQ_fl2440 bin]# chmod a+x hostapd
可以将hostapd目录下的hostapd.conf修改后拷贝到开发板/etc下,也可以直接新建一个,这里选择直接新建。
在开发板/etc目录下创建这个文件hostapd.conf。
interface=wlan0 //网络接口名称
ssid=nick666 //热点名称
driver=nl80211 //默认使用nl80211无线驱动
channel=3 //设定无线频道
hw_mode=g //使用80211g协议标准 , 有效的值取决于硬件,通常:a, b, g
ignore_broadcast_ssid=0 //开启或禁用广播ssid
auth_algs=1 /*指定OSA认证算法, auth_algs=1 只支持 WPA2 身份验证算法。*/
/*auth_algs=2 表示支持 WEP。永远不要使用有线等效加密 (wired equivalent privacy, WEP),因为它非常容易破解,并且多年前就已经被完全破解了。*/
/*auth_algs=3 表示支持这两种方式。*/
wpa=3 /*指定WPA/WPA2类型, wpa=2 仅支持 WPA2。wpa=1 表示支持 WPA1,而 wpa=3 表示二者都支持。*/
wpa_key_mgmt=WPA-PSK //指定您想支持的加密密钥算法
wpa_passphrase=12345678 //指定认证密钥
wpa_pairwise=TKIP /*启用了WPA或WPA2则需要指定wpa_pairwise或rsn_pairwise。*/
rsn_pairwise=CCMP /*wpa_pairwise 和 rsn_pairwise控制支持加密数据的密钥,您可以使用 CCMP、TKIP 或两者均使用*/
启用hostapd
hostapd -B /etc/hostapd.conf
ifconfig观察发现,多了网卡
mon.wlan0 Link encap:UNSPEC HWaddr 00-A1-B0-40-6F-1E-00-00-00-00-00-00-00-00-00-00
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
udhcpd启用DHCP分配IP
[nick@NickQ_fl2440 ~]# udhcpd -f /etc/udhcpd.conf
udhcpd: started, v1.27.1
phy0 -> rt2800_txdone_entry_check: Warning - TX status report missed for queue 2 entry 0
udhcpd: sending OFFER of 192.168.10.20
udhcpd: sending OFFER of 192.168.10.20
udhcpd: sending ACK to 192.168.10.20
udhcpd: sending ACK to 192.168.10.20
udhcpd -f
选项是保持在前台运行。去掉-f
则转为后台。
iptables移植
使用脚本编译安装
#!/bin/bash
# Description:
# This shell script used download and compile iptables for ARM
PREFIX_PATH=`pwd`/
if [ -z $CROSSTOOL ] ; then
CROSSTOOL=/opt/xtools/arm920t/bin/arm-linux-
fi
function msg_banner()
{
echo ""
echo "+-----------------------------------------------------------------------"
echo "| $1 "
echo "+-----------------------------------------------------------------------"
echo ""
}
function check_result()
{
if [ $? != 0 ] ; then
echo ""
echo "+-----------------------------------------------------------------------"
echo "| $1 "
echo "+-----------------------------------------------------------------------"
echo ""
exit ;
fi
}
function export_cross()
{
# export cross toolchain
export CC=${CROSSTOOL}gcc
export AS=${CROSSTOOL}as
export AR=${CROSSTOOL}ar
export LD=${CROSSTOOL}ld
export NM=${CROSSTOOL}nm
export RANLIB=${CROSSTOOL}ranlib
export OBJDUMP=${CROSSTOOL}objdump
export STRIP=${CROSSTOOL}strip
# export cross configure
export CONFIG_CROSS=" --build=i686-pc-linux --host=arm-linux "
# Clear LDFLAGS and CFLAGS
export LDFLAGS=
export CFLAGS=
}
function compile_iptables()
{
SRC_NAME=iptables-1.4.21
PACK_SUFIX=tar.bz2
IMG_NAME=iptables
if [ -f ${PREFIX_PATH}/${IMG_NAME} ] ; then
return 0;
fi
msg_banner "Start cross compile $SRC_NAME "
if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
wget http://www.netfilter.org/projects/iptables/files/${SRC_NAME}.${PACK_SUFIX}
check_result "ERROR: download ${SRC_NAME} failure"
fi
tar -xjf ${SRC_NAME}.${PACK_SUFIX}
cd ${SRC_NAME}
./configure --prefix=${PREFIX_PATH} ${CONFIG_CROSS} --enable-static --disable-shared --disable-ipv6 --disable-largefile
check_result "ERROR: configure ${SRC_NAME} failure"
make
check_result "ERROR: compile ${SRC_NAME} failure"
${STRIP} iptables/xtables-multi
cp iptables/xtables-multi ${PREFIX_PATH}/${IMG_NAME}
cd -
}
export_cross
compile_iptables
再理解一次CFLAGS和LDFLAGS:一般我们通过CFLAGS的 -I 选项告诉编译器所依赖的第三方的库的头文件在哪里,通过LDFLAGS的-L选项告诉链接器这些库的库文件在哪里;还有LIBS是告诉链接器要链接哪些库文件。简单地说,LDFLAGS是告诉链接器从哪里寻找库文件,而LIBS是告诉链接器要链接哪些库文件。有时候LIBS指定了却找不到库时可以试试LDFLAGS。
[nick@NickQ_fl2440 ~]# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
[nick@NickQ_fl2440 ~]# iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISH -j ACCEPT
[nick@NickQ_fl2440 ~]# iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
自动启动
在开发板/etc/init.d/中,创建启动脚本.以S??
,如开头S30_wifiAP
#!/bin/sh
ifconfig wlan0 192.168.10.1 netmask 255.255.255.0 up
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISH -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
hostapd -B /etc/hostapd.conf
udhcpd /etc/udhcpd.conf
作者:NickQ
出处:http://www.cnblogs.com/NickQ/
版权声明:
本文版权归原创作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。