rt3070芯片动态获取IP地址———station模式

上一篇介绍到rt3070芯片station模式手动设置IP地址ping外网,这样显得有些麻烦,如果我们能自动获取IP地址去ping外网不是会更加智能化么?

1.要支持动态获取ip的话,你需要在linux内核中和制作文件系统的busybox的menuconfig选中必要的选项

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

          [ * ] Network packet filtering (replaces ipchains)

二: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

三:从Busybox的examples/udhcp/下将  simple.script文件tftp到开发板/usr/share/udhcpc/下,并重命名为default.script,然后更改文件default.script的权限

chmod a+x default.script

2.接着,连接WiFi:

>: wpa_supplicant -Dwext -iwlan0 -c wpa_supplicant.conf &
>: phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 2, TXop: 47.
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 2 - CWmin: 4, CWmax: 10, Aifs: 3, TXop: 0.
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7, TXop: 0.
Trying to associate with d4:ee:07:22:6b:5c (SSID='HiWiFi_LingYun' freq=2417 MHz)
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 7, 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:

3.动态获取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.15c completed (auth) [id=0 id_str=]

>: 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=41 time=485.113 ms
64 bytes from 4.2.2.2: seq=1 ttl=41 time=405.201 ms

--- 4.2.2.2 ping statistics ---

>: 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=39 time=93.176 ms
64 bytes from 8.8.8.8: seq=1 ttl=39 time=95.413 ms

--- 8.8.8.8 ping statistics ---

4.查看相关网关信息

>: route
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


现在,让来说说可能会遇到的错误:

 1.在执行udhcpc命令时

# udhcpc -f 
   udhcpc (v1.13.2) started
   eth0: link up, 100Mbps, full-duplex, lpa 0x41E1
   udhcpc: socket: Address family not supported by protocol

其原因可能是因为在内核 make menuconfig选项设置没选 Packet socket, [ * ] Network packet filtering (replaces ipchains) --->选项

 2.在接连你的wifi主机后执行

>: udhcpc -i wlan0
udhcpc (v1.20.2) started
Sending discover...
Sending select for 192.168.199.245...
Lease of 192.168.199.245 obtained, lease time 43200

其原因可能是没有在开发板上修改 default.script 的权限,或者没有将 default.script 放到你的开发板 /usr/share/udhcpc/ 路径下。



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值