fuchch 发表于 2016-10-13 18:06:09

嵌入式Linux使用USB无线网卡 ——一种解决方案

一种解决方案就是不使用Linux自带的,使用网上的驱动编译得到rtl8188eu.ko,加载,同
时使用wpa_supplicant-0.6.9版本,编译wext驱动方式,这样就可以了,不会提示什么
/sys/class/net/wlan0/phy80211/name的问题了。
这样可以使用了,再编译busybox,选中udhcpc。
执行udhcpc -i wlan0获取到了可用ip,但是ifconfig没有设置,很奇怪。
网上一搜才知道,http://bbs.csdn.net/topics/390713401
udhcpc无法自动设置IP的问题
回复于: 2015-12-15 09:16:38
udhcpc是一个面向嵌入式系统的非常小的DHCP客户端,字母的缩写微- DHCP -客户端
(μDHCPc)。
udhcpc -i eth0
udhcpc只是获取一个IP,我们需要把\busybox-1.1.2\examples\udhcp下的脚本simple.script改名为
default.script,放在开发板上的/usr/share/dhcpc/目录下,才能将获取的IP写到指定的网卡中。
simple.script需要拷贝过来:
# cat udhcp.script
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
RESOLV_CONF="/etc/resolv.conf"
[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
NETMASK=""
[ -n "$subnet" ] && NETMASK="netmask $subnet"
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
case "$1" in
deconfig)
echo "Setting IP address 0.0.0.0 on $interface"
ifconfig $interface 0.0.0.0
;;
renew|bound)
echo "Setting IP address $ip on $interface"
ifconfig $interface $ip $NETMASK $BROADCAST
if [ -n "$router" ] ; then
echo "Deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
metric=0
for i in $router ; do
echo "Adding router $i"
route add default gw $i dev $interface metric $((metric++))
done
fi
echo "Recreating $RESOLV_CONF"
echo -n > $RESOLV_CONF-$$
[ -n "$domain" ] && echo "search $domain" >> $RESOLV_CONF-$$
for i in $dns ; do
echo " Adding DNS server $i"
echo "nameserver $i" >> $RESOLV_CONF-$$
done
mv $RESOLV_CONF-$$ $RESOLV_CONF
;;
esac
exit 0
然后使用udhcpc -i wlan0 -s /mnt/sdcard/udhcp.script,这样就可以自动获取IP并设置使用了

我这里跟文件系统是不可写的,所以提示了
can't create /etc/resolv.conf-389: Read-only file system
这样的话,dns不能正确使用了。所以还得修改这个东西。脚本中有
RESOLV_CONF="/etc/resolv.conf",修改一下就可以了。
<pre name="code" class="html">Adding DNS server xxxx,dns
ping www.baidu.com
ping: bad address 'www.baidu.com'
DNS
后来发现,系统使用的是/etc/resolv.conf,但我已经把RESOLV_CONF修改到其他地方了
,而根文件系统不能直接修改为可写,需要mount -t jffs去挂载。
所以,我选择了链接,使用ln -s xxxx/resolv.conf /etc/resolv.conf,这样只要存在
xxxx/resolv.conf,然后udhcpc去修改这个文件就可以了,系统使用/etc/resolv.conf链接到
xxxx/resolv.conf,再ping
www.baidu.com,OK,解决了。
# ping www.baidu.com
rtw_set_ps_mode(): Busy Traffic , Leave 802.11 power save..
rtl8192c_set_FwPwrMode_cmd(): Mode = 0, SmartPS = 0
PING www.baidu.com (115.239.211.112): 56 data bytes
64 bytes from 115.239.211.112: seq=0 ttl=56 time=8.102 ms
64 bytes from 115.239.211.112: seq=1 ttl=56 time=10.396 ms
64 bytes from 115.239.211.112: seq=2 ttl=56 time=8.082 ms

cdl511 发表于 2016-10-14 08:31:47

谢谢分享这

尛智 发表于 2016-10-14 08:54:36

谢谢分享

cityhu 发表于 2017-9-4 08:53:32

谢谢分享

twang0x80 发表于 2017-9-4 09:14:18

谢谢分享。。。。

cityhu 发表于 2017-9-28 08:56:26

页: [1]
查看完整版本: 嵌入式Linux使用USB无线网卡 ——一种解决方案