Android教程:wifi热点问题


现在很多移动设备都提供wifi hostpot功能,使用方便,也省下了原来无线路由器的成本。wifi和wifi hotspot功能是互斥的,即在同一时间里,你只能用其中一种功能。在Android较新版本(2.2之后)中已经实现,本文实现在命令行模式下完成wifi hotspot功能的启动,并简单介绍其中涉及到的相关工具。
0、确保eth0可以访问网络
1、修改framework/base/core/res/res/values/config.xml

  1. <!-- List of regexpressions describing the interface (if any) that represent tetherable 
    Wifi interfaces. If the device doesn't want to support tethering over Wifi this 
    should be empty. An example would be "softap.*" --> 
    <string-array translatable="false" name="config_tether_wifi_regexs"> 
    <item>"wlap0"</item> 
    </string-array> 
    <!-- Dhcp range (min, max) to use for tethering purposes --> 
    <string-array translatable="false" name="config_tether_dhcp_range"> 
    </string-array> 
    <!-- Regex array of allowable upstream ifaces for tethering - for example if you want 
    tethering on a new interface called "foo2" add <item>"foo\\d"</item> to the array --> 
    <string-array translatable="false" name="config_tether_upstream_regexs"> 
    <item>"eth0"</item> 
    <item>"ppp0"</item> 
    <item>"wlan0"</item> 
    </string-array> 
2、加载wifi驱动(我这使用的是atheros)
insmod /system/wifi/ar6000.ko ifname=wlap0 若成功的话,则第3、4、5步自动执行。
3、设置IP地址 /system/bin/ifconfig wlap0 192.168.100.1 netmask 255.255.255.0
4、iptables设置 echo 1 > /proc/sys/net/ipv4/ip_forward /system/bin/iptables -A FORWARD -i wlap0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT  /system/bin/iptables -A FORWARD -i wlap0 -o eth0 -j ACCEPT  /system/bin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
5、dnsmasq设置 /system/bin/dnsmasq --no-daemon --no-resolv --no-poll --dhcp-range=192.168.100.100,192.168.100.200,100h 当然也可以把相关配置写成文件再执行dnsmasq --conf-file=/*/dnsmasq.conf
6、启动hostapd /system/bin/hostapd_wps -dd /data/misc/wifi/hostapd.conf
出现的问题 1、执行上述命令后,客户端去连接的时候获取不到IP地址,重新启动hostapd就OK? 可以采用如下方法修正 /sytem/bin/ndc softap set eth0 wlap0 djstava open /system/bin/ndc softap start /system/bin/ndc/softap startap  

更多Android相关信息见Android 专题页面 http://www.bkjia.com/topicnews.aspx?tid=11

相关内容