原文連接:http://www.cnblogs.com/NickQ/p/8976054.html 環境:Linux3.0內核 RT3070(無線) + DM9000(有線)html
在s3c2440上實現SoftAP模式
-
配置內核
- 配置完內核開始編譯後,報以下錯誤。
解決方法:make clean後從新編譯。 參考:https://blog.csdn.net/tonkeytong/article/details/52672782linux
[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
配置並編譯shell
./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 移植
下載解壓api
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
修改Makefilebash
將 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方式less
[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。ui
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