• FL2440 rt3070模块ap模式移植


    ------------------------------------------------------------------------------------------------------------------------------

    交叉编译器:arm-linux-gcc-4.5.4

    Linux内核版本:Linux-3.0

    主机操作系统:Centos 6.5

    开发板:FL2440

    本文章的内核已经已经添加了DM9000的网卡,USB驱动,使用的是initramfs的文件系统。

    ------------------------------------------------------------------------------------------------------------------------------

    大体移植过程:添加内核支持-->编译Openssl生成一些库函数,用作后面hostapd的编译-->编译libnl生成一些库函数,用作后面hostapd的编译-->编译hostapd生成开发板所需的命令文件hostapd以及配置文件hostapd.conf-->配置udhcpd的配置文件udhcpd.conf到开发板,完成dhcp服务器功能-->开发板上运行配置文件初次尝试连接wifi-->移植iptables命令完成上网功能。

    一、内核移植

    make menuconfig

    [*] Networking support --->
      Networking options --->
        <*> Packet socket
        <*> Unix domain sockets
        [*] TCP/IP networking
        [*] TCP/IP networking
        [*] IP: kernel level autoconfiguration
        [*] IP: multicast routing
        [*] IP: DHCP support
        [*] IP: BOOTP support
        [*] IP: RARP support
        [*] IP: multicast routing
        [*] Network packet filtering framework (Netfilter) --->
          [*] Advanced netfilter configuration
            Core Netfilter Configuration ---> //除了下面的其余的全选
              < > Transparent proxying support (EXPERIMENTAL)
              < > set target and match support
              < > CHECKSUM target support
              < > "CT" target support
              < > "DSCP" and "TOS" target support
              < > "NOTRACK" target support
              < > "TRACE" target support
          <*> IP set support --->
            (256) Maximum number of IP sets
            <*> bitmap:ip set support
            <*> bitmap:ip,mac set support
            <*> bitmap:port set support
            <*> list:set set support
          <*> IP virtual server support --->
            (12) IPVS connection table size (the Nth power of 2)
              *** IPVS transport protocol load balancing support ***
            [*] TCP load balancing support
            [*] UDP load balancing support
            [*] ESP load balancing support
            [*] AH load balancing support
            <*> round-robin scheduling
            <*> weighted round-robin scheduling
            <*> least-connection scheduling
            <*> weighted least-connection scheduling
            <*> locality-based least-connection scheduling
            <*> locality-based least-connection with replication scheduling
            <*> destination hashing scheduling
            <*> source hashing scheduling
            <*> shortest expected delay scheduling
            <*> never queue scheduling
              *** IPVS application helper ***
            [*] Netfilter connection tracking
            IP: Netfilter Configuration ---> //此下的全选
      <*> RF switch subsystem support --->

    二、网络配置工具移植

    所需文件:

    openssl-0.9.8e.tar.gz    下载地址 http://www.openssl.org/source/old/0.9.x/

    libnl-1.1.4.tar.gz    下载地址 http://www.infradead.org/~tgr/libnl/

    hostapd-1.0.tar.gz    下载地址 http://download.chinaunix.net/download.php?id=40061&ResourceID=4450

    (1)移植openssl-0.9.8e

    [xiaohexiansheng@centos6 openssl-0.9.8e]$ mkdir install

    [xiaohexiansheng@centos6 openssl-0.9.8e]$ vim Makefile

    修改编译生成文件所放的位置和编译器的位置

    INSTALLTOP=/home/xiaohexiansheng/fl2440/3rdparty/apwifi/openssl-0.9.8e/install

    CC= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc

    AR=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar $(ARFLAGS) r
    RANLIB= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib

    [xiaohexiansheng@centos6 openssl-0.9.8e]$ sudo make
    [xiaohexiansheng@centos6 openssl-0.9.8e]$ sudo make install

    (2)移植libnl-1.1.4

    在这里不需要修改Makefile文件,用 configure命令来指定安装路径和软件运行的系统平台

    [xiaohexiansheng@centos6 libnl-1.1.4]$ mkdir install

    [xiaohexiansheng@centos6 libnl-1.1.4]$ ./configure --prefix=/home/xiaohexiansheng/fl2440/3rdparty/apwifi/openssl-0.9.8e/install --host=arm-linux

    [xiaohexiansheng@centos6 libnl-1.1.4]$ sudo make CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc

    [xiaohexiansheng@centos6 libnl-1.1.4]$ sudo make install

    将install/lib/目录下的libnl.so.1文件发送到开发板的/lib/目录下

    (3)移植hostapd-1.0

    修改.config文件和Makefile文件

    [xiaohexiansheng@centos6 hostapd]$ cp defconfig .config
    [xiaohexiansheng@centos6 hostapd]$ vim .config

    添加:

    CONFIG_DRICER_NL80211=y

    [xiaohexiansheng@centos6 hostapd]$ vim Makefile

    添加:

    CFLAGS +=-I/home/xiaohexiansheng/fl2440/3rdparty/apwifi/libnl-1.1.4/install/include
    CFLAGS +=-I/home/xiaohexiansheng/fl2440/3rdparty/apwifi/openssl-0.9.8e/install/include
    LIBS +=-L/home/xiaohexiansheng/fl2440/3rdparty/apwifi/libnl-1.1.4/install/lib
    LDFLAGS +=-L/home/xiaohexiansheng/fl2440/3rdparty/apwifi/libnl-1.1.4/install/lib
    LIBS +=-L/home/xiaohexiansheng/fl2440/3rdparty/apwifi/openssl-0.9.8e/install/lib
    LDFLAGS +=-L/home/xiaohexiansheng/fl2440/3rdparty/apwifi/openssl-0.9.8e/install/lib

    [xiaohexiansheng@centos6 hostapd]$ make CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
    [xiaohexiansheng@centos6 hostapd]$ sudo make install

    参考网上的资料修改hostapd.conf配置文件

    [xiaohexiansheng@centos6 hostapd]$ vim hostapd.conf

    配置文件修改如下:

    nterface=wlan0   
    driver=nl80211
    ssid=guanlei
    channel=3
    hw_mode=g
    ignore_broadcast_ssid=0
    auth_algs=1
    wpa=3
    wpa_passphrase=12345678   
    wpa_key_mgmt=WPA-PSK WPA-EAP
    wpa_pairwise=TKIP CCMP

    拷贝当前目录下生成的hostapd与hostapd.conf文件到开发板上,给hostapd可执行权限。

    (4)配置udhcpd

    参考网上的资料配置udhcpd.conf文件

    udhcpd.conf在busybox下的/examples/udhcpd/目录下

    修改如下:

    start 192.168.2.20     //修改IP池,起始IP的后两位可以随意,但必须在一个网段。

    end 192.168.2.254    

    interface       wlan0    //修改执行dhcp功能的接口

    opt dns 8.8.8.8       //修改DNS、网关、netmask

    option subnet 255.255.255.0
    opt router 192.168.2.1

    三、开发板上运行配置文件

    理一下所需的文件和文件要放的位置:

     /lib/:libnl.so.1

    hostapd(执行命令)、hostapd.conf(配置文件)、udhcpd(执行命令)、udhcpd.conf(配置文件)

    如果想要启动wlan0还需要一个rt2870的固件。下载地址:

    git clone git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git

    在开发板下创建/lib/firmware文件夹,将下载下来的linux-firmware/rt2870.bin拷贝到开发板的firmware文件夹下。

    接下来开始配置开发板

    (1)配置hostapd

    >:./hostapd -B hostapd.conf

    Configuration file: hostapd.conf
    phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 102.
    phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 4, CWmax: 5, Aifs: 2, TXop: 188.
    phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 5, CWmax: 10, Aifs: 3, TXop: 0.
    phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 5, CWmax: 10, Aifs: 7, TXop: 0.
    Using interface wlan0 with hwaddr 00:a1:b0:40:6f:9a and ssid 'xiaohexiansheng'
    phy0 -> rt2x00usb_watchdog_tx_status: Warning - TX queue 0 status timed out, invoke forced tx handler
    phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 1, TXop: 47.
    phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 1, TXop: 94.
    phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 4, CWmax: 6, Aifs: 3, TXop: 0.
    phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7, TXop: 0.

    若出现读取random随机数错误,可采用符号链接的方法解决:

    # mv /dev/random /dev/random.org
    # ln -s /dev/urandom /dev/random

    若出现如下错误:

    Failed to create interface mon.wlan0: -23 (Too many open files in system)

    ctrl_iface exists and seems to be in use - cannot override it
    Delete '/var/run/hostapd/wlan0' manually if it is not used anymore
    Failed to setup control interface
    wlan0: Unable to setup interface.

    解决方案:删除./hostapd的进程,删除/var/run下面的hostapd   messages这两个文件

    >: ifconfig wlan0 192.168.2.1 netmask 255.255.255.0   (先把要接入点设备设置好)

     

    (2)配置udhcpd

    执行udhcpd命令之前需要一个udhcpd.release的租赁文件,在相应的文件夹下创建即可。

    >:mkdir -p /var/lib/misc/

    >:touch /var/lib/misc/udhcpd.leases

    >:udhcpd  -f /etc/udhcpd.conf 
    udhcpd (v1.20.2) started
    Sending OFFER of 192.168.2.20
    Sending ACK to 192.168.2.20

    OK,手机可以连上自己的开发板了。

    四、定义防火墙策略实现开发板上网功能

    iptables-1.4.12.tar.bz2    下载地址:http://www.netfilter.org/projects/iptables/downloads.html

    [xiaohexiansheng@centos6 iptables-1.4.12]$ mkdir install

    [xiaohexiansheng@centos6 iptables-1.4.12]$ ./configure --host=/arm-linux --enable-static --disable-shared --prefix=/home/xiaohexiansheng/fl2440/3rdparty/apwifi/iptables-1.4.12/install --disable-ipv6 --disable-largefile

    [xiaohexiansheng@centos6 iptables-1.4.12]$ make CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc CFALGS=--static LDFLAGS=-static

    [xiaohexiansheng@centos6 iptables-1.4.12]$ sudo make install

    [xiaohexiansheng@centos6 iptables]$ sudo /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-strip xtables-multi    //strip 减少大小用的

    将/install/lib文件夹和xtables-multi打包放到开发板/lib/bin目录下,赋予可执行权限后将xtables-multi改名为iptables

    在开发板上配置nat表。

     //将局域网内地址通过eth0接口伪装后转发出去

    >:iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE   

    //开启转发功能,允许已建立连接及相关连接对内转发   

    >: iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISH -j ACCEPT  

    //对外转发,数据包从wlan0流向eth0    

    >: iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT      

    /*开启linux 的转发功能! Linux系统是默认进制数据包转发的,所谓的转发就是当主机拥有多块网卡的时候,其中一块收到数据包,根据数据包的目的ip转发到本机的另一张网卡上,该网卡根据路由表继续发送数据包首先保证硬件连通,然后打开系统的转发功能

    less /proc/sys/net/ipv4/ip_forward,该文件内容为0,表示禁止数据包转发,1表示允许,将其修改为1。可使用命令echo "1" > /proc/sys/net/ipv4/ip_forward 修改文件内容,重启网络服务或主机后效果不再*/

    >:echo "1" >/proc/sys/net/ipv4/ip_forward

    到此,手机连上wifi模块就可以上网了。

  • 相关阅读:
    c# gdi设置画刷透明
    char,varchar,nvarchar,text区别与联系
    banner无缝轮播【小封装】
    div中的内容垂直居中的五种方法
    jQuery hover() 方法
    年过三十,我为什么要学习ios 与安卓App 移动端技术
    CentOS 中用 Split 命令分割文件的方法
    centos E440 安装无线网卡
    CentOS7修改默认运行级别
    iwconfig: command not found 解决方案
  • 原文地址:https://www.cnblogs.com/xiaohexiansheng/p/5679309.html
Copyright © 2020-2023  润新知