Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1683063
  • 博文数量: 311
  • 博客积分: 7778
  • 博客等级: 少将
  • 技术积分: 4186
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-09 19:59
个人简介

蓝点工坊(http://www.bluedrum.cn) 创始人,App和嵌入式产品开发。同时也做相应培训和外包工作。 详细介绍 http://pan.baidu.com/s/1y2g88

文章存档

2012年(3)

2011年(115)

2010年(170)

2009年(23)

分类: 嵌入式

2010-08-31 17:19:19

 
Andrew Huang
 
 
 
  在S3C2440开发上增加 USB WiFi 网卡,就可以通过无线上网。手头正好有一块现成的Zydas的WiFi网卡。试试无线通讯.
 
 

一.增加USB网卡驱动

 
 
 

Linux 2.6.29 加入Zydas 的驱动支持.动态模块形式.

一般采用WiFi Zyda 2611的网卡,注意在内核中有一个ZB1201的无法驱动比较新的网卡,

 

,

 

 

 

make modules  编译动态模块

 

 

最终的zd1201.ko即是所需的动态模块.将其拷出来

 

insmod zd1201.ko 安装,(注意ko所在路径,最好是绝对路径)

insmod zd1211rw.ko,(注意ko所在路径,最好是绝对路径)

 

 

USB WIFI网卡插入,如果成功,应该能看到提示

cat /proc/bus/usb/devices能看到如下信息

 

 

至此,USB网卡安装装成功

 

如果网卡安装成功,应该能在 cat /proc/net/wireless 目录下看到网卡,( 注意,2.6.21以前,要配置CONFIG_NET_RADIO才会显示这个文件系统.更高的版本是自动支持的.)

 

 

 

 

 

 

Wifi应用层工具的使用

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

 

此时应该在,安装应用层的工具.以便在Linux ifconfig 下能使用网络结点操作.

 

一般使用wireless_tools.29.tar.gz这一工具配置结点.

 

1.解压

tar xvzf wireless_tools.29.tar.gz

 

2.移植

这个项目已经预先写好了Makefile,因此不需要configure 重新生成,把所用的gcc 工具的地方用上arm-linux的版本.

prefix 改为相应的路径

 

 

 

 

执行 ifconfig wlan0 up 激活网卡 (注意是 ifconfig,不是iwconfig )

在大约一段时间后提示

 

 

表示需要一些固件,从网上查找的的文档来看是,是需要

zd1211-firmware-1.4.tar.bz2

 

里面有如下内容

 

 

[root@TecherHost libs]# tar xvjf zd1211-firmware-1.4.tar.bz2

zd1211-firmware/

zd1211-firmware/zd1211b_uphm

zd1211-firmware/zd1211_uphr

zd1211-firmware/WS11UPh.h

zd1211-firmware/WS11UPhm.h

zd1211-firmware/README

zd1211-firmware/zd1211b_uph

zd1211-firmware/zd1211b_ub

zd1211-firmware/WS11UPhR.h

zd1211-firmware/WS11UPhR_Turbo.h

zd1211-firmware/zd1211b_uphr

zd1211-firmware/zd1211_ub

zd1211-firmware/WS11Ub.h

zd1211-firmware/zd1211_ur

zd1211-firmware/zd1211_uph

zd1211-firmware/WS11Ur.h

zd1211-firmware/zd1211b_ur

zd1211-firmware/zd1211_uphm

zd1211-firmware/COPYING

 

根据firmware的说明,将其中的zd1211b_*文件拷贝到根文件系统/lib/firmware/zd1211目录中。

 

在开发板上执行:

mkdir -p /lib/firmware/zd1211/

cp zd1211_* /lib/firmware/zd1211/

再次执行 Ifconfig wlan0

 

有如下提示

 

[root@FriendlyARM zd1211-firmware]# ifconfig wlan0 up

usb 1-1: firmware: requesting zd1211/zd1211b_ub

usb 1-1: firmware: requesting zd1211/zd1211b_uphr

zd1211rw 1-1:1.0: firmware version 4725

zd1211rw 1-1:1.0: zd1211b chip 0ace:1215 v4810 full 00-e0-4c UW2453_RF pa0 g7---

 

cfg80211: Calling CRDA for country: US

 

运行ifconfig 的结果

 

[root@FriendlyARM zd1211-firmware]# ifconfig

eth0      Link encap:Ethernet  HWaddr 08:00:3E:26:0A:5B

          inet addr:192.168.1.230  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:505 errors:0 dropped:0 overruns:0 frame:0

          TX packets:233 errors:0 dropped:0 overruns:0 carrier:0

          collisions:12 txqueuelen:1000

          RX bytes:218025 (212.9 KiB)  TX bytes:31950 (31.2 KiB)

          Interrupt:53 Base address:0x300

 

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:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

 

wlan0     Link encap:Ethernet  HWaddr 00:E0:4C:18:74:B5

          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)

 

wmaster0  Link encap:UNSPEC  HWaddr 00-E0-4C-18-74-B5-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)

 

 

 

 

 

 

3.使用无线网络

 

执行iwlist scanning 扫描AP设备

 

 

[root@FriendlyARM sbin]#

[root@FriendlyARM sbin]# ./scan.sh[J

lo        Interface doesn't support scanning.

 

eth0      Interface doesn't support scanning.

 

wmaster0  Interface doesn't support scanning.

 

wlan0     Scan completed :

          Cell 01 - Address: 00:14:78:B3:66:56

                    ESSID:"AndrewHome"

                    Mode:Master

                    Channel:10

                    Frequency:2.457 GHz (Channel 10)

                    Quality=11/100  Signal level:72/100 

                    Encryption key:off

                    IE: Unknown: 000A416E64726577486F6D65

                    IE: Unknown: 010882848B960C183048

                    IE: Unknown: 03010A

                    IE: Unknown: 0706434E20010D14

                    IE: Unknown: 2A0100

                    IE: Unknown: 32041224606C

                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s

                              12 Mb/s; 24 Mb/s; 36 Mb/s; 9 Mb/s; 18 Mb/s

                              48 Mb/s; 54 Mb/s

                    Extra:tsf=00000000ff931aa7

                    Extra: Last beacon: 95ms ago

          Cell 02 - Address: 00:90:4C:C1:03:E9

                    ESSID:"3G-Router"

                    Mode:Master

                    Channel:11

                    Frequency:2.462 GHz (Channel 11)

                    Quality=23/100  Signal level:14/100 

                    Encryption key:on

                    IE: Unknown: 000933472D526F75746572

                    IE: Unknown: 010882848B962430486C

                    IE: Unknown: 03010B

                    IE: Unknown: 2A0100

                    IE: Unknown: 2F0100

                    IE: Unknown: 32040C121860

                    IE: Unknown: DD090010180200F0040000

                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s

                              24 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 9 Mb/s

                              12 Mb/s; 48 Mb/s

                    Extra:tsf=00000014c2eb155b

                    Extra: Last beacon: 90ms ago

          Cell 03 - Address: 00:21:27:3A:3A:F0

                    ESSID:"TP-LINK-316"

                    Mode:Master

                    Channel:11

                    Frequency:2.462 GHz (Channel 11)

                    Quality=17/100  Signal level:11/100 

                    Encryption key:on

                    IE: Unknown: 000B54502D4C494E4B2D333136

                    IE: Unknown: 010882848B960C183048

                    IE: Unknown: 03010B

                    IE: Unknown: 2A0100

                    IE: Unknown: 32041224606C

                    IE: Unknown: DD0900037F01010008FF7F

                    IE: Unknown: DD1A00037F03010000000021273A3AF00221273A3AF064002C010808

                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s

                              12 Mb/s; 24 Mb/s; 36 Mb/s; 9 Mb/s; 18 Mb/s

                              48 Mb/s; 54 Mb/s

                    Extra:tsf=0000000cffa98c87

                    Extra: Last beacon: 90ms ago

 

[root@FriendlyARM sbin]#

 

其中的ESSID:"AndrewHome"就是我自己无线路由器的名字,没有密码。就登录这个无线路由器

,因此登录上去。

iwconfig wlan0 key 123456 #设置登录命令为 123456,这里暂时不需要

iwconfig wlan0 essid " AndrewHome" #设置ESSID”AndrewHome”

 

[root@FriendlyARM sbin]# ./wup.sh wlan0 essid "AndrewHome"

[root@FriendlyARM sbin]# cfg80211: Calling CRDA for country: CN

 

其余采用自动参数

iwconfig wlan0 ap auto

再次执行iwconfig wlan0 ,这时发现已经上去了。

 

[root@FriendlyARM sbin]# ./wup.sh wlan0

wlan0     IEEE 802.11bg  ESSID:"AndrewHome"

          Mode:Managed  Frequency:2.457 GHz  Access Point: 00:14:78:B3:66:56

          Bit Rate=1 Mb/s   Tx-Power=27 dBm

          Retry min limit:7   RTS thr:off   Fragment thr=2352 B

          Encryption key:off

          Power Management:off

          Link Quality=100/100  Signal level:75/100

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

 

到这个阶段,就象普通的有线网卡一样,用ifconfig操作就行,设置IP

 ifconfig wlan0 192.168.1.231 netmask 255.255.255.0

 

然后可以写一个脚本。

#! /bin/sh
ifconfig wlan0 up
#iwconfig wlan0 key 123456
iwconfig wlan0 essid "AndrewHome"
iwconfig wlan0 ap auto
ifconfig wlan0 192.168.1.30 netmask 255.255.255.0

 

4.增加DHCP支持

 

从使用的角度来说,无线网卡最好用DHCP动态获取IP地址,LINUX下使用DHCP获取地址有几种方法,

在桌面机LINUX一种是配置网卡的启动脚本。

  即修改/etc/sysconfig/networks-scripts/ifg-XXXX(后面是设备名)

wlan0的设备就是 ifconfig-wlan0.第一块网卡就是 ifg-eth0,

静态IP的配置文件如下

 

DEVICE=eth0

BOOTPROTO=none

BROADCAST=192.168.0.255

IPADDR=192.168.0.146

NETMASK=255.255.255.0

NETWORK=192.168.0.0

ONBOOT=yes

USERCTL=no

PEERDNS=no

TYPE=Ethernet

 

如果用动态IP则修改成

 

DEVICE=eth0

BOOTPROTO=dhcp #以后的配置均失效。

BROADCAST=192.168.0.255

IPADDR=192.168.0.146

NETMASK=255.255.255.0

NETWORK=192.168.0.0

ONBOOT=yes

USERCTL=no

PEERDNS=no

TYPE=Ethernet

 

然后ifconfig eth0 down ,再打开ifconfig eth0 up即可申请IP

 

 

在嵌入式LINUX好象这个没有生效,可以用udhcpc这个busybox 的应用程序来手动申请。(在桌面版,这个程序是dhclient)

第一次运行,提示

 

[root@FriendlyARM init.d]# udhcpc wlan0

udhcpc (v1.13.3) started

udhcpc: exec /usr/share/udhcpc/default.script: No such file or directory

udhcpc: socket: Address family not supported by protocol

 

这里提示需要一些配置文件,查询资料是,

/usr/share/udhcpc/default.script

 

在在/busyboxexamples/udhcpc配置的模板,simple.scritp拷贝成default.script

 

/usr/share/udhcpc/sample.script

/usr/share/udhcpc/sample.deconfig

/usr/share/udhcpc/sample.nak

/usr/share/udhcpc/sample.renew

 

他们目录下面有一些模板,我们把拷到指定目录。进行配置

 

 

[root@FriendlyARM udhcp]# udhcpc -d -i wlan0

udhcpc (v1.13.3) started

udhcpc: socket: Address family not supported by protocol

 

查询原因,是可能内核没有打开相关选项.于是将DHCP选加入

 

 

 

 

 

 

 

6.增加对互联网的支持

增加域名服务器配置

   /etc/resolv.conf是保存DNS服务器地址的配置文件.

内容是

nameserver 202.102.224.68

nameserver 202.96.134.133

  
阅读(2928) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-12-21 19:15:51

你好,我想wifi模块,不知道买哪种,能否指点一下