FL2440——RT3070 STA模式 实现无线上网功能

FL2440添加RT3070实现无线上网

rtl3070中文名称为雷凌3070,是台湾雷凌科技有限公司生产的一款专用于usb无线网卡的处理芯片。是一种低功耗高度集成的MAC / BBP和2.4G RF单一芯片,支持300Mbps的吞吐量。RT3070无线网卡有两种工作模式STA模式和softAP模式,分别由STA驱动和softAP驱动来实现,STA驱动支持无线网卡工作在STA模式下,可以连接到网络实现上网功能。而SoftAP的驱动支持无线网卡工作在softAP模式下,可以作为一个软的接入点,实现无线路由器功能。

前面的学习过程中,在FL2440上面已经使能了DM9000的有线网卡和USB驱动,可以使用DM9000网卡接入网线实现上网功能,现在对于FL2440基于RT3070添加STA驱动使其可以使用雷凌公司的RT3070芯片实现无线上网功能。

linux内核对于RT3070的驱动已经比较完善,我们只需稍微对于内核稍加修改就能使用RT3070实现无线上网。这里基于linux3.0内核实现。

添加make menuconfig选项

 [*] Networking support  --->  
    -*-   Wireless  --->  
         <*>   cfg80211 - wireless configuration API  
         [*]     enable powersave by default  
         [*]     cfg80211 wireless extensions compatibility 
         [*]   Wireless extensions sysfs files  
         {*}   Common routines for IEEE802.11 drivers 
         <*>   Generic IEEE 802.11 Networking Stack (mac80211)
     Device Drivers  --->
        Generic Driver Options  --->
            -*- Userspace firmware loading support    
            [*]   Include in-kernel firmware blobs in kernel binary 
        [*] Network device support  --->  
            [*]   Wireless LAN  --->  
                <*>   Ralink driver support  --->
                    <*>   Ralink rt27xx/rt28xx/rt30xx (USB) support
                    [*]     rt2800usb - Include support for rt33xx devices  
                    [*]   Ralink debug output

现在重新编译内核烧录到开发板,启动内核。
插入RT3070无线网卡后内核打印信息,不同配置打印的信息可能不一样。

>: usb 1-1.2: new full speed USB device number 3 using s3c2410-ohci

使用ifconfig -a命令查看网卡信息,可以看到wlan0已经添加成功。
这里写图片描述

使能网卡

现在只是添加了网卡驱动,还没有真正的使能网卡,要使能网卡还需要下载RT2870的固件。
在开发板下创建/lib/firmware文件夹,将下载下来的linux-firmware/rt2870.bin拷贝到开发板的firmware文件夹下。

虚拟机下:
>wget https://coding.net/u/sfantree/p/self_use_OSS/git/raw/master/source/rt2870.bin
开发板:
>: ls lib/firmware/
rt2870.bin

使能无线网卡

>: ifconfig wlan0 up
>ifconfig/*查看已经使能的网卡信息*/
eth0      Link encap:Ethernet  HWaddr 16:0D:AA:78:FB:A2  
          inet addr:192.168.1.22  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST 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)
          Interrupt:51 Base address:0x2300 

wlan0     Link encap:Ethernet  HWaddr 00:12:04:24:06:93  
          UP BROADCAST 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)

连接路由器

现在已经使能无线网卡,但是要连路由器上网还需要移植无线上网工具:openssl和wpa_supplicant

移植openss库l

下载解压openssl库

[lwn@localhost openssl]$ wget http://www.openssl.org/source/openssl-0.9.8i.tar.gz
[lwn@localhost openssl]$ tar -xzvf openssl-0.9.8i.tar.gz
[lwn@localhost openssl]$ cd openssl-0.9.8i/
[lwn@localhost openssl]$./config no-asm shared --prefix=`pwd`/_install

修改Makefile
修改Makefile编译生成相关工具库,下面是我修改Makefile后生成的补丁文件。课按照补丁文件对Makefile进行修改。

--- openssl-0.9.8i/Makefile 2008-09-15 23:27:21.000000000 +0800
+++ openssl-0.9.8i_lwn/Makefile 2017-05-13 21:45:05.174133646 +0800
 -11,11 +11,11 @@
 SHLIB_VERSION_HISTORY=
 SHLIB_MAJOR=0
 SHLIB_MINOR=9.8
-SHLIB_EXT=
+SHLIB_EXT=.so.$(SHLIB_MAJOR).$(SHLIB_MINOR)
 PLATFORM=dist
-OPTIONS= no-camellia no-capieng no-cms no-gmp no-krb5 no-mdc2 no-montasm no-rc5 no-rfc3779 no-seed no-shared no-tlsext no-zlib no-zlib-dynamic
+OPTIONS=enable-shared no-camellia no-capieng no-cms no-gmp no-krb5 no-mdc2 no-montasm no-rc5 no-rfc3779 no-seed no-tlsext no-zlib no-zlib-dynamic
 CONFIGURE_ARGS=dist
-SHLIB_TARGET=
+SHLIB_TARGET=linux-shared

 # HERE indicates where this Makefile lives.  This can be used to indicate
 # where sub-Makefiles are expected to be.  Currently has very limited usage,
@@ -26,10 +26,10 @@
 # for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/.
 # Normally it is left empty.
 INSTALL_PREFIX=
-INSTALLTOP=/usr/local/ssl
+INSTALLTOP = /home/lwn/myfl2440/driver/wlan/install

 # Do not edit this manually. Use Configure --openssldir=DIR do change this!
-OPENSSLDIR=/usr/local/ssl
+OPENSSLDIR = /home/lwn/myfl2440/driver/wlan/install

 # NO_IDEA - Define to build without the IDEA algorithm
 # NO_RC4  - Define to build without the RC4 algorithm
@@ -59,15 +59,15 @@
 # equal 4.
 # PKCS1_CHECK - pkcs1 tests.

-CC= cc
+CC = /opt/dl/buildroot-2012.08/ARM920t/usr/bin/arm-linux-gcc
 CFLAG= -O
 DEPFLAG= -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_CAPIENG -DOPENSSL_NO_CMS -DOPENSSL_NO_GMP -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SEED -DOPENSSL_NO_TLSEXT 
 PEX_LIBS= 
 EX_LIBS= 
 EXE_EXT= 
 ARFLAGS= 
-AR=ar $(ARFLAGS) r
-RANLIB= /usr/bin/ranlib
+AR = /opt/dl/buildroot-2012.08/ARM920t/usr/bin/arm-linux-ar $(ARFLAGS) r
+RANLIB = /opt/dl/buildroot-2012.08/ARM920t/usr/bin/arm-linux-ranlib
 PERL= /usr/bin/perl
 TAR= tar
 TARFLAGS= --no-recursion
@@ -225,7 +225,7 @@
    @[ -n "$(THIS)" ] && $(CLEARENV) && $(MAKE) $(THIS) -e $(BUILDENV)

 sub_all: build_all
-build_all: build_libs build_apps build_tests build_tools
+build_all: build_libs build_apps build_tests build_tools build-shared

 build_libs: build_crypto build_ssl build_engines

按照上面patch补丁包修改Makefile之后使用mkae命令编译,编译完成后将生成几个动态库,我们 libssl.solibcrypto.so 拷贝到开发板的/lib目录下
Alt text

移植wpa_supplicant

下载解压wpa_supplicant库

[lwn@localhost wpa_supplicant]wget https://coding.net/u/sfantree/p/self_use_OSS/git/raw/master/source/wpa_supplicant-0.7.3.tar.gz
[lwn@localhost wpa_supplicant]tar zxvf wpa_supplicant-0.7.3.tar.gz
[lwn@localhost wpa_supplicant]cd wpa_supplicant-0.7.3/wpa_supplicant
[lwn@localhost wpa_supplicant]cp defconfig .config

修改.config
修改.config相应字段,下面是我修改后生成的patch补丁文件。

--- defconfig   2010-09-07 23:43:39.000000000 +0800
   +++ .config 2017-05-14 18:45:09.257435666 +0800
   @@ -24,10 +24,10 @@

    #### sveasoft (e.g., for Linksys WRT54G) ######################################
    #CC=mipsel-uclibc-gcc
   -#CC=/opt/brcm/hndtools-mipsel-uclibc/bin/mipsel-uclibc-gcc
   -#CFLAGS += -Os
   +CC=/opt/dl/buildroot-2012.08/ARM920t/usr/bin/arm-linux-gcc -L/home/lwn/myfl2440/driver/openssl/install/lib
  +CFLAGS += -I/home/lwn/myfl2440/driver/openssl/install/include
   #CPPFLAGS += -I../src/include -I../../src/router/openssl/include
  -#LIBS += -L/opt/brcm/hndtools-mipsel-uclibc-0.9.19/lib -lss

修改.config配置文件之后,编译之后生成如下几个文件,将其拷贝到开发板的/user/bin目录下

  • wpa_cli
  • wpa_passphrase 生成配置文件
  • wpa_supplicant 连接wifi命令

查看相关依赖库,可见wpa_supplicant前置依赖属于openssl的libcrypto.so和libssl.so

> arm-linux-readelf -d ./wpa_supplicant
Dynamic section at offset 0x471e8 contains 24 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libssl.so.1.0.0]
 0x00000001 (NEEDED)                     Shared library: [libcrypto.so.1.0.0]
 0x00000001 (NEEDED)                     Shared library: [libdl.so.0]
 0x00000001 (NEEDED)                     Shared library: [libc.so.0]
...

生成配置文件
wpa_supplicant.conf配置文件保留着需要连接AP的SSID和key等信息,可以使用wpa_supplicant.conf一键生成

/*Router_LingYun_Master是我将要连接的路由器的SSID*/
/*ling_emb是SSID为Router_Lingyun的路由器认证密码*/
wpa_passphrase Router_LingYun_Master lingyun-emb>> /etc/wpa_supplicant.conf

修改wpa_supplicant.conf如下,Router_LingYun_Master为WiFi的名称,lingyun_emb为wifi密码。

ctrl_interface=/var/run/wpa_supplicant
#ctrl_interface_group=wheel

network={
        ssid="Router_LingYun_Master"
        key_mgmt=WPA-PSK
        proto=WPA2
        group=TKIP CCMP
        pairwise=TKIP CCMP
        psk="lingyun_emb"     #psk=56466f08ff364ccbbec3266aeda88cb69619a3914834966cc7e90098985d225c
}

启用wpa_supplicant

wpa_supplicant -B -d -Dwext -i wlan0 -c /etc/wpa_supplicant.conf

网络配置

由于还没有开启DHCP,所以需要手动分配IP等各种配置,这里配置由你的网络环境决定。

#配置IP地址
ifconfig wlan0 192.168.0.168 
#配置默认网关
route add default gw 192.168.0.1
#配置DNS
echo "nameserver 114.114.114.114" > /etc/resolv.conf

测试网络连通性
接下来进行ping测试

>: ping baidu.com
PING baidu.com (220.181.57.217): 56 data bytes
64 bytes from 220.181.57.217: seq=0 ttl=54 time=57.336 ms
64 bytes from 220.181.57.217: seq=1 ttl=54 time=70.318 ms
64 bytes from 220.181.57.217: seq=2 ttl=54 time=70.620 ms
64 bytes from 220.181.57.217: seq=4 ttl=54 time=71.594 ms
64 bytes from 220.181.57.217: seq=5 ttl=54 time=69.678 ms

可以ping通百度,说明已经将fl2440连上internet网了。

使能DHCP服务

上面只能手动配置ip,现在开启DHCP服务,使其自动获取IP地址
busybox已经集成了DHCP的客户端和服务端,源码编译过后的examples/udhcp/simple.script作为DHCP客户端的示例配置文件如下,将其重命名为/usr/share/udhcpc/default.script,特别注意必须给default.script可执行权限。

vim default.scrupt
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>

RESOLV_CONF="/etc/resolv.conf"

[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }

NETMASK=""
[ -n "$subnet" ] && NETMASK="netmask $subnet"
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"

case "$1" in
    deconfig)
        echo "Setting IP address 0.0.0.0 on $interface"
        ifconfig $interface 0.0.0.0
        ;;

    renew|bound)
        echo "Setting IP address $ip on $interface"
        ifconfig $interface $ip $NETMASK $BROADCAST

        if [ -n "$router" ] ; then
            echo "Deleting routers"
            while route del default gw 0.0.0.0 dev $interface ; do
                :
            done

            metric=0
            for i in $router ; do
                echo "Adding router $i"
                route add default gw $i dev $interface metric $((metric++))
            done
        fi

        echo "Recreating $RESOLV_CONF"
        echo -n > $RESOLV_CONF-$$
        [ -n "$domain" ] && echo "search $domain" >> $RESOLV_CONF-$$
        for i in $dns ; do
            echo " Adding DNS server $i"
            echo "nameserver $i" >> $RESOLV_CONF-$$
        done
        mv $RESOLV_CONF-$$ $RESOLV_CONF
        ;;
esac

exit 0

执行udhcpc -i wlan0之后即可自动获取IP,执行这个命令后udhcp会以守护进程方式在后台运行

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值