主机操作系统:Centos 6.7
交叉编译器版本:buildroot-2012.08
开发板平台: FL2440
Linux内核版本: linux-3.0
开发模块:rt3070无线网卡动态获取IP上网
之前我们需要自己手动设置IP来上网,现在让它动态获取IP自己上网。
一、修改内核
Networking --->
Networking support
Networking options --->
Packet socket //添加.配置CONFIG_PACKET
[ * ] IP: DHCP support //DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)
[ * ] Network packet filtering (replaces ipchains)
make,将生成的内核文件装到开发板上
[*]udhcp server(udhcpd)
[*]udhcp client(udhcpc)都选上
udhcpd就是终端设备作为DHCP服务器 ;udhcpc就是终端设备作为DHCP客户端
Networking Utilities --->
[*] udhcp client for DHCPv6 (udhcpc6)
[*] udhcp server (udhcpd) //生成udhcpc命令
make编译后把Busybox的examples/udhcp/simple.script 拷贝到开发板/usr/share/udhcpc/下,并重命名为default.script,然后更改文件default.script的权限为777
>: chmod 777 /usr/share/udhcpc/default.script
>: ll /usr/share/udhcpc/default.script
-rwxrwxrwx 1 root root
三、连接路由器
>: wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf &
>: Trying to associate with c0:61:18:f5:3e:62 (SSID='Router_LingYun' freq=2462 MHz)
Associated with c0:61:18:f5:3e:62
WPA: Key negotiation completed with c0:61:18:f5:3e:62 [PTK=CCMP GTK=TKIP]
CTRL-EVENT-CONNECTED - Connection to c0:61:18:f5:3e:62 completed (auth) [id=0 id_str=]
WPA: Group rekeying completed with c0:61:18:f5:3e:62 [GTK=TKIP]
>:
>: udhcpc -i wlan0udhcp会以守护进程方式在后台运行
udhcpc (v1.20.2) started
Sending discover...
Sending select for 192.168.2.112...
Lease of 192.168.2.112 obtained, lease time 7200
deleting routers
route: SIOCDELRT: No such process
adding dns 114.114.114.114
adding dns 202.103.24.68
五、测试
>: ping www.baidu.com
PING www.baidu.com (180.97.33.108): 56 data bytes
64 bytes from 180.97.33.108: seq=0 ttl=54 time=21.746 ms
64 bytes from 180.97.33.108: seq=1 ttl=54 time=62.449 ms
64 bytes from 180.97.33.108: seq=2 ttl=54 time=65.329 ms
64 bytes from 180.97.33.108: seq=3 ttl=54 time=64.575 ms
64 bytes from 180.97.33.108: seq=4 ttl=54 time=61.608 ms
64 bytes from 180.97.33.108: seq=5 ttl=54 time=62.624 ms
^C
--- www.baidu.com ping statistics ---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 21.746/56.388/65.329 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=38 time=416.030 ms
64 bytes from 8.8.8.8: seq=1 ttl=38 time=433.437 ms
64 bytes from 8.8.8.8: seq=2 ttl=38 time=452.338 ms
64 bytes from 8.8.8.8: seq=3 ttl=38 time=472.499 ms
^C
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 4 packets received, 20% packet loss
round-trip min/avg/max = 416.030/443.576/472.499 ms
查看ip信息
>: ifconfig
eth0 Link encap:Ethernet HWaddr 82:D2:A6:D4:EF:3E
inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:213 errors:0 dropped:0 overruns:0 frame:0
TX packets:140 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:18995 (18.5 KiB) TX bytes:16569 (16.1 KiB)
Interrupt:51 Base address:0x4300
wlan0 Link encap:Ethernet HWaddr 00:A1:B0:40:6E:F7
inet addr:192.168.2.112 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:126 errors:0 dropped:89 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21718 (21.2 KiB) TX bytes:3114 (3.0 KiB)
>: route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.2.1 0.0.0.0 UG 0 0 0 wlan0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 wlan0
Ok
问题总结:
1、busybox 配置及make menuconfig 无法删除标识的问题
点击secureCRT的选项—>会话选项—>终端—>映射键,在右边的菜单框中,把其他映射选项下的“Backspace 发送delete(B)”选项勾上就可以解决问题了
参考:http://www.th7.cn/system/lin/201508/124552.shtml
2、无法自动获取IP
>: udhcpc -i wlan0
udhcpc (v1.20.2) started
/usr/share/udhcpc/default.script: exec: line 7: /usr/share/udhcpc/sample.deconfig: not found
Sending discover...
Sending select for 192.168.199.223...
Lease of 192.168.199.223 obtained, lease time 43200
/usr/share/udhcpc/default.script: exec: line 7: /usr/share/udhcpc/sample.bound: not found
sample.bound: not found
Busybox的examples/udhcp/下有sample.bound,放到开发板/usr/share/udhcpc/下给777权限。
>: udhcpc -i wlan0去到etc目录下,mkdir udhcpc文件夹,将之前做好的resolv.conf放到这个路径下 参考:http://blog.csdn.net/hshl1214/article/details/8684740 解决Ok
udhcpc (v1.20.2) started
Sending discover...
Sending select for 192.168.199.223...
Lease of 192.168.199.223 obtained, lease time 43200
deleting routers
route: SIOCDELRT: No such process
/usr/share/udhcpc/sample.bound: line 25: can't create /etc/udhcpc/resolv.conf: nonexistent directory
上面的IP设置有问题,无法上网,后面我改了。就是上面做的正确方法,这里记录问题是提供解决思路和方法参考。