歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android教程:wifi熱點問題

Android教程:wifi熱點問題

日期:2017/3/1 10:22:40   编辑:Linux編程

現在很多移動設備都提供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.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved