Rt3070芯片动态获取IP地址——station模式(WIFI模块)

Rt3070芯片动态获取IP地址——station模式(WIFI模块)

 

主机操作系统:Centos 6.7
交叉编译器环境:arm-linux-gcc-4.5.4 
开发板平台: FL2440 
Linux内核版本: linux-3.0 
开发模块: SIM900 WiFI-STA模式

=====================================================================

而我想要的是板子自己去动态随机获取IP联网,这样可以不用给wlan0指定IP。接下我们来完成这个功能。

=====================================================================

一.要支持动态获取的话,你需要在内核中和制作文件系统的内核部分bysybox部分选中必要的选项

1. 内核部分
Networking --->
    Networking support   
    Networking options ---> 
           Packet socket                 //添加.配置CONFIG_PACKET
          [ * ]     IP: DHCP support         //添加

          [ * ] Network packet filtering (replaces ipchains)

2.busybox部分
[*]udhcp server(udhcpd)
[*]udhcp client(udhcpc)都选上
udhcpd就是终端设备作为DHCP服务器 ;udhcpc就是终端设备作为DHCP客户端
Networking Utilities --->
 [*] udhcp client for DHCPv6 (udhcpc6)                                            
 [*] udhcp server (udhcpd)  //生成udhcpc命令 

make
sudo make install

 

二.从busyboxexamples/udhcp/copysimple.script文件到开发板/usr/share/udhcpc/下,并重命名为default.script.注意更改default.script的权限!!!

 

>: ls

apps     data     etc      init     linuxrc  proc     sbin     tmp      var

bin      dev      info     lib      mnt      root     sys      usr

>: cd usr/

>: ls

bin    lib    sbin   share

>: cd share/

>: ls

>: ls

>: mkdir udhcpc

>: ls

udhcpc

>: cd udhcpc/

>: tftp -gr simple.script 192.168.1.2

simple.script        100% |*******************************|  1074   0:00:00 ETA

>: ls

Simple.script

>: mv simple.script default.script

>: chmod a+x default.script

>: ls

Default.script

 

连接路由器:

>: wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf &

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

phy0 -> rt2x00lib_request_firmware: Info - Firmware detected - version: 0.36.

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.

Trying to associate with d4:ee:07:22:6b:5c (SSID='HiWiFi_LingYun' freq=2452 MHz)

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: 4, CWmax: 10, Aifs: 7, TXop: 0.

phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 94.

phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 2, TXop: 47.

Associated with d4:ee:07:22:6b:5c

WPA: Key negotiation completed with d4:ee:07:22:6b:5c [PTK=CCMP GTK=CCMP]

CTRL-EVENT-CONNECTED - Connection to d4:ee:07:22:6b:5c completed (auth) [id=0 id_str=]

动态获取IP地址:

>: udhcpc -i wlan0

udhcpc (v1.20.2) started

Setting IP address 0.0.0.0 on wlan0

Sending discover...

Sending discover...

Sending select for 192.168.199.245...

Lease of 192.168.199.245 obtained, lease time 43200

Setting IP address 192.168.199.245 on wlan0

Deleting routers

route: SIOCDELRT: No such process

Adding router 192.168.199.1

Recreating /etc/resolv.conf

 Adding DNS server 192.168.199.1

>: ping 4.2.2.2

PING 4.2.2.2 (4.2.2.2): 56 data bytes

64 bytes from 4.2.2.2: seq=0 ttl=47 time=433.416 ms

64 bytes from 4.2.2.2: seq=1 ttl=47 time=345.583 ms

64 bytes from 4.2.2.2: seq=2 ttl=47 time=365.502 ms

64 bytes from 4.2.2.2: seq=3 ttl=47 time=385.645 ms

64 bytes from 4.2.2.2: seq=4 ttl=47 time=403.668 ms

64 bytes from 4.2.2.2: seq=5 ttl=47 time=422.573 ms

64 bytes from 4.2.2.2: seq=6 ttl=47 time=339.577 ms

64 bytes from 4.2.2.2: seq=8 ttl=47 time=376.863 ms

64 bytes from 4.2.2.2: seq=9 ttl=47 time=294.990 ms

64 bytes from 4.2.2.2: seq=10 ttl=47 time=413.824 ms

64 bytes from 4.2.2.2: seq=11 ttl=47 time=332.572 ms

 

--- 4.2.2.2 ping statistics ---

12 packets transmitted, 11 packets received, 8% packet loss

round-trip min/avg/max = 294.990/374.019/433.416 ms

>: ping 8.8.8.8

PING 8.8.8.8 (8.8.8.8): 56 data bytes

64 bytes from 8.8.8.8: seq=0 ttl=45 time=419.097 ms

64 bytes from 8.8.8.8: seq=2 ttl=45 time=459.425 ms

64 bytes from 8.8.8.8: seq=3 ttl=45 time=476.569 ms

64 bytes from 8.8.8.8: seq=4 ttl=45 time=395.526 ms

64 bytes from 8.8.8.8: seq=5 ttl=45 time=414.304 ms

64 bytes from 8.8.8.8: seq=6 ttl=45 time=433.294 ms

64 bytes from 8.8.8.8: seq=7 ttl=45 time=453.372 ms

64 bytes from 8.8.8.8: seq=8 ttl=45 time=471.506 ms

 

--- 8.8.8.8 ping statistics ---

9 packets transmitted, 8 packets received, 11% packet loss

round-trip min/avg/max = 395.526/440.386/476.569 ms

>: ping www.baidu.com

PING www.baidu.com (119.75.218.70): 56 data bytes

64 bytes from 119.75.218.70: seq=0 ttl=53 time=24.745 ms

64 bytes from 119.75.218.70: seq=1 ttl=53 time=65.137 ms

64 bytes from 119.75.218.70: seq=2 ttl=53 time=66.086 ms

64 bytes from 119.75.218.70: seq=3 ttl=53 time=66.191 ms

64 bytes from 119.75.218.70: seq=4 ttl=53 time=65.276 ms

64 bytes from 119.75.218.70: seq=5 ttl=53 time=23.224 ms

64 bytes from 119.75.218.70: seq=6 ttl=53 time=66.509 ms

 

--- www.baidu.com ping statistics ---

7 packets transmitted, 7 packets received, 0% packet loss

round-trip min/avg/max = 23.224/53.881/66.509 ms

查看相关网关信息

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

default         Hiwifi.lan      0.0.0.0         UG    0      0        0 wlan0

192.168.1.0     *               255.255.255.0   U     0      0        0 eth0

192.168.199.0   *               255.255.255.0   U     0      0        0 wlan0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值