在mips平台移植hostapd库开启wifi的AP模式

一.主要内容:建立wifi模块的ap热点,使wifi模块工作在ap模式相当于路由器功能,手机等客户端可以连接该热点,并且借助4G网络可以访问到外网.

 

二.准备资料: hostapd-0.8.tar.bz2   hostapd-2.5.tar.bz2   openssl-1.0.2d.tar.bz2  libnl-3.2.27.tar.bz2

 

因为hostapd库编译需要依赖openssl,libnl库,hostapd有两个版本,0.8版本是USB的wifi模块源码资料中打包提供的,官网没找到该版本,看来是厂家对其做了修改,以适应自己的USB WiFi模块;2.5版本就是官网通用版本可以下载得到。

至于hostapd库执行之前必须要有相对应的wifi驱动,我们这里使用的是SDIO接口rtl8189es驱动,wifi驱动一般厂家会提供,我们只需要编译好后安装驱动:insmod  8189es.ko

注意:在不同平台使用需要选择对应的交叉编译工具:我这里使用的是联咏芯片mips平台,所以选择mips架构编译工具

mipsel-24kec-linux-uclibc-gcc

三:hostapd实现步骤:

  ---》1.编译openssl-1.0.2d:

            --->>1.将压缩包拷贝到当前用户环境解压

                              tar -xvf openssl-1.0.2d.tar.bz2

        --->>2.配置选择:

            cd    openssl-1.0.2d/

       ./config no-asm shared --prefix=/home/liucong/hostapd/openssl-1.0.2d/_install   --cross-compile-prefix=mipsel-24kec-linux-uclibc- 

注意:--prefix是指定编译后安装的路径 :根据你自己选择目录即可

         --cross-compile-prefix是指定交叉编译工具:根据你使用的选择

     修改当前Makefile    

     将   PLATFORM=linux-x86_64    修改为 PLATFORM=linux-mips32 

     将  CONFIGURE_ARGS=linux-x88_64   修改为linux-mips32 

在 CFLAG= -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 
  将  -m64 删除   我们是32位mips平台

在SHARED_LDFLAGS= -m64           将-m64删除

 

    -->> 3.编译:

              make     

            make install

注意:在/home/liucong/tool/hostapd/openssl-1.0.2d路径下可以看到生成的文件,为hostapd编译做准备

 

---》2.libnl交叉编译:

        ----->0.解压进入:
              tar -xvf libnl-3.2.27.tar.bz2
                 
       ---->1.  配置选择:

          cd  libnl-3.2.27

       ./configure  --prefix=/home/liucong/hostapd/libnl-3.2.27/_install --enable-shared --enable-static \
                 --host=mipsel-24kec-linux-uclibc 

       注意:--prefix指定编译后安装的路径: 根据自己实际目录指定就好

                  --host 指定运行的平台,选择交叉工具链前缀即可  这里是mips平台,根据交叉编译器选择


       ---->2.    make 

       ---->3.    make install

 

---》3.hosapd.0.8编译:

  

        ----> 0.解压:

               tar -xvf  hostapd-2.5.tar.bz2

              cd  hostapd-2.5    

       --->1.选择配置文件
             cp defconfig .config

    
    ---->2.修改.config文件:

            CONFIG_DRIVER_NL80211=y     解注释此选项,支持nl80211驱动  
            CONFIG_LIBNL32=y            解注释此选项,使用libnl3.2版本库

            CONFIG_TLS=openssl          解注释此选项

        添加如下内容:

        #libnl library
        CFLAGS += -I/home/liucong/hostapd/libnl-3.2.27/_install/include/libnl3
        LDFLAGS += -I/home/liucong/hostapd/libnl-3.2.27/_install/include/libnl3

        LIBS += -L/home/liucong/hostapd/libnl-3.2.27/_install/lib
        LIBS_p += -L/home/liucong/hostapd/libnl-3.2.27/_install/lib


        #opessl library
        CFLAGS += -I/home/liucong/hostapd/openssl-1.0.2d/_install/include
        LDFLAGS += -I/home/liucong/hostapd/openssl-1.0.2d/_install/include
        LIBS += -L/home/liucong/hostapd/openssl-1.0.2d/_install/lib
        LIBS_p += -L/home/liucong/hostapd/openssl-1.0.2d/_install/lib
        
        DESTDIR= $(shell pwd)/_install                                          #指定install安装的路径
        


        注意:CFLAGS和LDFLAGS  都必须指定链接库的头文件, 这里指定你自己前面选择的openssl和libnl安装的路径哦 

        LIBS和LIBS_p   同上根据自己情况指定


    ----->3.编译:
        make  

        最后在当前目录下产生: hostapd 和 hostapd_cli

      file  hostapd 查看可执行文件属性:显示mips  32位

      ----->4.安装:
            make  install

            在当前/_install/usr/bin目录下存在需要的文件:hostapd  hostapd_cli

 

---》4.使用hostapd命令启动ap热点配置流程:

           因为前面已经移植了需要的库,现在我们就是看在板子中如何使用.

     1.最重要一步:安装wifi驱动,我这里直接找到驱动文件安装:insmod  8189es.ko

     wifi驱动这里不多说,根据自己实际情况安装,安装成功ifconfig -a 可以看到wlan0网卡出现了.

       

 

  2.创建两个配置文件:udhcpd.conf和hostapd.conf: 

        udhcpd.conf配置如下:

           start 192.168.1.3
           end 192.168.2.100
            interface wlan0
           max_leases 20
           remaining yes
           auto_time 7200
            decline_time 3600
            conflict_time 3600
            offer_time 60
            min_lease 60
            lease_file /etc/udhcpd.leases
            opt dns 114.114.114.114                             
            option subnet 255.255.255.0                                            
            opt router 192.168.1.1                                                
            option domain local

还需要创建一个文件:touch  /etc/udhcpd.leases

 

hostapd.conf配置(AP热点):

         interface=wlan0

           #driver=nl80211                      我的这项屏蔽了可用

          ieee80211n=1
          max_num_sta=1                        最大的连接个数
           ssid=myapp                               ap模式下热点名称
           channel=3
           hw_mode=g
            ignore_broadcast_ssid=0
           auth_algs=3
            wpa=3                                        当然从此项开始需要wpa_suppliation支持,加密功能,无可以注释
            wpa_passphrase=lc123456
            wpa_key_mgmt=WPA-PSK
             wpa_pairwise=TKIP
             rsn_pairwise=CCMP

 

为了确保运行的正确,请确保内核中有如下配置:

     

 

执行命令开启热点:

      ifconfig wlan0 192.168.1.1 netmask 255.255.255.0 up

    udhcpd -fS  /etc/udhcpd.conf &

    hostapd -B  /etc/hostapd.conf

当然此时只是建立了AP热点,且可自动分配IP地址,但是还无法上外网,用手机我们可以搜索到myapp热点.

 

四.iptabels实现4G访问外网流程:

    iptabels工具具体作用不说自行百度,总之我们使用它可以实现两个网卡之间nat转发数据,wifi热点通过4G上网.


---》1.iptabels编译:
        
     --->1.解压源码:

           tar -xvf iptables-1.6.0.tar.bz2
    ---》2.设置configure配置项:

    cd  iptables-1.6.0

        mkdir  output      编译后文件存放目录

    ./configure  --disable-ipv6 --disable-nftables --disable-largefile --enable-libipq --disable-devel --host=mipsel-24kec-linux-uclibc  
         --with-xtlibdir=/lib/xtables


    ---》3.编译:
        make

    ---》4.安装:
      
          make install  DESTDIR=/home/liucong/tool/hostapd/iptables-1.6.0/output

        在output目录下有我们想要的iptables工具
    注意:DESTDIR 指定编译后安装的文件路径,根据自己情况修改即可.

 

---》2.内核配置iptables:

         

       如果不清楚打开所有相关的也没关系了.

 

---》3.iptables工具使用:

          iptables是一种防火墙工具,可以创建过滤表(filter)和NAT表等,主要由表,链,规则组成.

       iptabels  -L  查看默认设置的规则(默认filter表)

       iptables -A FORWARD -s 192.168.1.0/24 -o eth0 -j ACCEPT       允许192.168.1.0网络地址的主机发送消息到eth0网卡

       如果规则设置没有报任何错误,证明可用,如果报如下错误:

          /usr/local/bin/iptables: can't load library 'libip4tc.so.0'                 缺少一个库 iptables编译后会产生的

 

 

  iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 -o eth0 -j MASQUERADE

         iptables v1.6.0: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
         Perhaps iptables or your kernel needs to be upgraded          这个是有关nat的内核配置项没打开

 

完整的流程:

          4G自动拨号: ifconfig  查看是否有eth0 

       配置无限网卡ip:  ifconfig wlan0 192.168.1.1 netmask 255.255.255.0 up

 

        

         

     
              udhcpd -fS /etc/udhcpd.conf &                  //udhcpd服务启动 

             iptables -A FORWARD -s 192.168.1.0/24 -o eth0 -j ACCEPT           允许接收数据:注意ipd地址

             iptables -A FORWARD -d 192.168.1.0/24 -j ACCEPT       

             iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 -o eth0 -j MASQUERADE    

              echo 1 >/proc/sys/net/ipv4/ip_forward      这个必须打开否则无法使用iptabels转发

               hostapd -B /etc/hostapd.conf                    愉快的开启了ap热点模式了

 

              可以使用iwconfig wlan0   查看是否存在ap模式:具体iwconfig怎么用网上太多了

             

              当然我也写了几个脚本比较方便执行:下载既可以使用:

               https://download.csdn.net/download/delores_lc/11257265

         我移植使用的  hostapd  openssl  libnl  iptables 资源下载链接:

              https://download.csdn.net/download/delores_lc/11257285

 

 

 

  

 

 

 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值