wifi连接及启动热点

连接wifi

现在wpa_supplicant、hostapd、rt8821驱动都编译完了,还需要在busybox添加udhcp支持:

make menuconfig
make
make insall
#install在_install目录下

make menuconfig配置:
wifi连接及启动热点_第1张图片
然后将_install目录与osdrv/pub/rootfs_glibc合并,重新制作文件系统,使用yaffs2、2KB pagesize、4bit ecc:

cd osdrv/pub
./bin/pc/mkyaffs2image100 rootfs_glibc rootfs_hi3519av100_2k_24bit.yaffs2 1 4

制作完成后将rootfs_hi3519av100_2k_24bit.yaffs2重新烧写。
烧写完成后udhcpc就能找到了,再将ko、wpa_supplicant、config等文件拷贝过来,加载驱动,启动wpa_supplicant,扫描连接wifi,启动udhcpc,就可以用iperf测速了:

insmod rtl8192eu.ko
export LD_LIBRARY_PATH=/mnt/usr/lib:$LD_LIBRARY_PATH
udhcpc -i wlan0 -s /etc/udhcpc/wifi.script &
/mnt/usr/bin/wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf -B

simple.script内容如下:

#!/bin/sh
# udhcpc script edited by Tim Riker 
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

wpa_supplicant.conf 从源码包 wpa_0_8.conf修改,wpa_cli,iperf使用就参考 “wpa_cli、wpa_supplicant连接热点”、“iperf交叉编译及使用”了。

启动热点

启动热点前需要将wpa_supplicant、dhcpc关掉,然后设置wlan0 ip,启动dhcpd,启动hostapd:

ifconfig wlan0 192.168.44.203 netmask 255.255.255.0 up
udhcpd /etc/udhcpd.conf
route add default gw 192.168.0.1
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
#设置路由
/mnt/usr/bin/iptables -t nat -A POSTROUTING -s 192.168.44.204/24 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
/mnt/usr/bin/hostapd /etc/rtl_hostapd_5G.conf &

udhcpd.conf:

start 192.168.44.204 #default: 192.168.0.20
end 192.168.44.254 #default: 192.168.0.254
# The interface that udhcpd will use
interface wlan0 #default: eth0
max_leases 234
option subnet 255.255.255.0
option router 192.168.44.203
option dns 114.114.114.114

rtl_hostapd_5G.conf则直接从源码包里边来,稍作修改即可使用。
启动时可能遇到报错:rfkill: Cannot open RFKILL control device,找不到 /dev/rfkill ,需要配置内核加上RFKILL支持:
wifi连接及启动热点_第2张图片
内核重新编译之后,重新执行上述命令。

注意:有可能热点开启了,但是手机还是无法连上,可能是5Gwifi有的手机不支持,无法扫描到热点,换个手机扫描试试。

热点开启后,为让连接到吃热点的设备能够上网,需要设置路由,使用iptables设置。

/mnt/usr/bin/iptables -t nat -A POSTROUTING -s 192.168.44.204/24 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

关闭热点时:

killall udhcpd
killall hostapd
/mnt/usr/bin/iptables -t nat -D POSTROUTING 1
route del default gw 192.168.43.1
echo 0 > /proc/sys/net/ipv4/ip_forward

你可能感兴趣的:(linux,linux驱动及海思)