WIFI模块工作模式浅析

一.我的工作平台:

 FL2440开发板(移植了linux3.0的内核和ubifs的文件系统),RT3070的WIFI模块,无线路由器(联网)。

 

二. 你要用WIFI模块做事:

1.首先要了解你使用的wifi模块是要工作在哪种模式下。
 
当你要用你的wifi模块组成一个基础网,应该使wifi工作在AP模式下。(AP称为无线接入点,是一个无线网络的创建着,是网络的中心节点。一般的家庭或办公室使用的无线路由器就是一个AP。)简单的解释是,就像你的WIFI模块作为无线路由器,别人的WIFI(做为STA)连到你上面来。

当你要用你的wifi模块组成自组网,应该使wifi工作在sta模式下。(STA站点,每个连接到无线网络中的终端都可以称为一个站点)简单的解释是,就像你手机的WIFI连接无线网一样,你手机就是个STA。

 

2.我的开发板移植了linux-3.0内核版本,已经支持RT3070的驱动,所以我就没自己移植驱动。内核的配置如下:

[*] Networking support  --->

         -*-   Wireless  --->

              <*>   cfg80211 - wireless configuration API

              [ ]     nl80211 testmode command

              [ ]     enable developer warnings

              [ ]     cfg80211 regulatory debugging

              [*]     enable powersave by default

              [ ]     use statically compiled regulatory rules database

              [ ]     cfg80211 wireless extensions compatibility

              <*>   Common routines for IEEE802.11 drivers

              [ ]   lib80211 debugging messages

              <*>   Generic IEEE 802.11 Networking Stack (mac80211)

              [ ]   PID controller based rate control algorithm

              [*]   Minstrel

              [*]     Minstrel 802.11n support

                    Default rate control algorithm (Minstrel)  --->

              [ ]   Enable mac80211 mesh networking (pre-802.11s) support

              [ ]   Select mac80211 debugging features  --->

Device Drivers  --->

       Generic Driver Options  --->

              (/sbin/hotplug) path to uevent helper

              [ ] Maintain a devtmpfs filesystem to mount at /dev

              [ ] Select only drivers that don't need compile-time external firmware

              [ ] Prevent firmware from being built

              -*- Userspace firmware loading support

              [*]   Include in-kernel firmware blobs in kernel binary

              ()    External firmware blobs to build into the kernel binary

[*] Network device support  --->

          [*]   Wireless LAN  --->

             <*>   Ralink driver support  --->

                   --- Ralink driver support

                   < >   Ralink rt2500 (USB) support

                   < >   Ralink rt2501/rt73 (USB) support

                   <*>   Ralink rt27xx/rt28xx/rt30xx (USB) support

                   [ ]    rt2800usb - Include support for rt33xx devices

                   [ ]    rt2800usb - Include support for rt35xx devices (EXPERIMENTAL)

                   [ ]    rt2800usb - Include support for rt53xx devices (EXPERIMENTAL)

                   [ ]    rt2800usb - Include support for unknown (USB) devices

                   [*]   Ralink debug output

 

准备工作基本都做好了,现在我们wifi模块查到开发板上看看。

~ >: usb 1-1.1: USB disconnect, device number 3
usb 1-1.1: new full speed USB device number 4 using s3c2410-ohci
usb 1-1.1: New USB device found, idVendor=148f, idProduct=3070
usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.1: Product: 802.11 n WLAN
usb 1-1.1: Manufacturer: Ralink
usb 1-1.1: SerialNumber: 1.0

这是内核打印的一些WIFI模块的信息,比较有用就是idVendor(厂商ID)idProduct(设备ID)。

 

三.我们先研究下STA模式:

~ >: ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:E5:49:83:76:1A 
          inet addr:192.168.1.168  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:0x4300

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:45 errors:0 dropped:0 overruns:0 frame:0
          TX packets:45 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2700 (2.6 KiB)  TX bytes:2700 (2.6 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:0C:43:30:72:81 
          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)

这里我们可以看到我们开发板所有的网络接口的信息,wlan0就是我们WIFI设备的网络接口。

 ~ >:ifconfig wlan0 up

    phy0 -> rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'.

    phy0 -> rt2x00lib_request_firmware: Error - Failed to request Firmware.

    ifconfig: SIOCSIFFLAGS: No such file or directory

这里我们可以看到我们的wlan0并不能起来,还需要一个系统固件'rt2870.bin'.

我们先在自己linux服务器下下载这个固件:

 [lingyun@localhost linux-firmware]$  git clone git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git

你会在里面找到你所需要的系统固件,并把它下载到开发板的固件目录/lib/linux-firmware/下来(没有的话自己创建)。

~ >:ifconfig wlan0 up

phy1 -> rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'.

phy1 -> rt2x00lib_request_firmware: Info - Firmware detected - version: 0.29.

phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 102.

phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 4, CWmax: 5, Aifs: 2, TXop: 188.

phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 5, CWmax: 10, Aifs: 3, TXop: 0.

phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 5, CWmax: 10, Aifs: 7, TXop: 0.

 

要使开发板工作在STA模式,我们会用到wpa_supplicant工具,具体移植我就不写了,网上很多资料。

最主要的是他的配置文件wpa_supplicant.conf(虽然每个无线网的配置信息不一样,但是基本可以包括这些):

这里是我用的配置:

# wpa_supplicant WPA-PSK/TKIP,AES configure file
# FILE:/apps/etc/network/
# Copyright (C) 2012 GuoWenxue <
guowenxue@gmail.com QQ:281143292>
#
# WPA-PSK/TKIP
# wpa_supplicant -B -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant

network={
        ssid="Router_LingYun" /你的无线网的id/
        key_mgmt=WPA-PSK /如果你的是WPA2-PSK加密,请不要修改为这个,因为现在好像还不支持,直接使用WPA-PSK是可以用的/
        proto=WPA
        #proto=WPA2
        pairwise=TKIP CCMP
        group=TKIP CCMP
        psk="lingyun-emb" /你的无线密码/
        #psk=be266b7cea70a09b47da452311cd4660b304a24b1131228e501d8da775928271
}

密码这里我没有使用暗文,如果你需要你可以这样做:

在制作wpa_supplicant工具时也会生成一个wpa_passphrase的工具。

wpa_passphrase 无线名字 密码 >> wpa_supplicant.conf(其中的无线名字就是你的无线ssID ,密码就是你自己无线网的密码,它会帮你转换为暗文写入到配置文件中)

现在我们敲命令:

wpa_supplicant -Dwext -iwlan0 -c /apps/etc/wireless/wpa_supplicant.conf(具体参数你可以自己网上查)

如果你想看网卡的这些配置信息一般我们会移植wireless_tools里面的工具,具体移植自己百度吧,就是把编译生成的工具:iwconfig, iwlist, iwpriv下载到开发板上。

~ >:iwconfig(iwconfig是LWE最主要的工具,可以对无线网卡的大部分参数进行配置)

lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     IEEE 802.11bgn  Mode:Master  Frequency:2.457 GHz  Tx-Power=20 dBm  
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:on

~>:iwlist(用于对/proc/net/wireless文件进行分析,得出无线网卡相关信息)

~ >: iwlist wlan0 scanning(搜索热点)

它会列出当前工作环境下所有能接收到的无线网络的信息。

现在我们要给我们wlan0配置IP,网关,dns服务器,这些一个一个配置太麻烦,而udhcpc(busybox中的命令)可以帮我们很容易解决这个问题,他帮我们动态从我们无线路由器申请ip,网关,dns服务器,前提是你的无线路由开启了DHCP的服务,现在基本都会开启这个服务吧。

~ >: udhcpc -i wlan0

udhcpc (v1.19.3) started

Sending discover...

Sending select for 192.168.1.100...

Lease of 192.168.1.100 obtained, lease time 7200

deleting routers

route: SIOCDELRT: No such process

adding dns 4.2.2.2

adding dns 8.8.8.8

现在我们配置基本完成了。

 

在敲下iwconfig命令看下:

lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     IEEE 802.11bgn  ESSID:"Router_LingYun" 
          Mode:Managed  Frequency:2.437 GHz  Access Point: D8:5D:4C:18:04:7A  
          Bit Rate=48 Mb/s   Tx-Power=20 dBm  
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
          Link Quality=70/70  Signal level=-35 dBm 
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:23  Invalid misc:3   Missed beacon:0

我们开始测试:

首先我们先关掉eth0的网卡,因为我们开发板是默认使用eth0。

~ >:ifconfig eth0 down

~ >: ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2): 56 data bytes
64 bytes from 192.168.1.2: seq=0 ttl=64 time=82.530 ms
64 bytes from 192.168.1.2: seq=1 ttl=64 time=54.166 ms
64 bytes from 192.168.1.2: seq=2 ttl=64 time=45.515 ms
64 bytes from 192.168.1.2: seq=3 ttl=64 time=45.559 ms
64 bytes from 192.168.1.2: seq=4 ttl=64 time=64.387 ms

--- 192.168.1.2 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 45.515/58.431/82.530 ms

~ >: pingwww.baidu.com
PING www.baidu.com (115.239.210.27): 56 data bytes
64 bytes from 115.239.210.27: seq=0 ttl=55 time=54.049 ms
64 bytes from 115.239.210.27: seq=1 ttl=55 time=94.991 ms
64 bytes from 115.239.210.27: seq=2 ttl=55 time=99.909 ms
64 bytes from 115.239.210.27: seq=3 ttl=55 time=875.014 ms
64 bytes from 115.239.210.27: seq=4 ttl=55 time=95.107 ms
64 bytes from 115.239.210.27: seq=5 ttl=55 time=95.025 ms

---
www.baidu.com ping statistics ---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 54.049/219.015/875.014 ms

到这里我们的STA模式就调试结束了。

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值