Lenovo ThinkPad T420 to enable wireless to AP mode
某次開會看到同樣是使用T420的同事可以在Win7下變更wireless adapeter為Access Point,想到如果wireless chip有支援那應該在Linux下也是啟動AP Mode的可能性。
連線方式
internet – eth0 – nat service – wireless (ap) – wireless client
又是拜G大神找到許多相關的資料,其中原始的來源有:
http://linuxwireless.org/en/users/Drivers/mac80211_hwsim
$lsmod | grep mac80211
mac80211 506816 1 iwlwifi
cfg80211 205544 2 iwlwifi,mac80211
確定系統自動load了mac80211,該網站寫到
mac80211_hwsim is a software simulator of 802.11 radio(s) for mac80211
系統不會自動load,必需手動load mac80211_hwsim來做為驅動的中介driver。
需要的軟體套件有
hostapd
dhcp3-server
wpasupplicant
如果是用Ubuntu
$sudo apt-get install hostapd dhcp3-server wpasupplicant
編輯檔案
$vi /etc/hostapd/hostapd.conf
# SSID to be used in IEEE 802.11 management frames
ssid=<ap ssid name>
# Operation mode (a = IEEE 802.11a, b = IEEE 802.11b, g = IEEE 802.11g,
# Default: IEEE 802.11b
hw_mode=g
# bit1 = IEEE 802.11i/RSN (WPA2) (dot11RSNAEnabled)
wpa=1
# $wpa_passphrase <ssid name> <passphrase> and copy&past to here
wpa_psk=<dot11RSNAConfigPSKValue> #要用指定加密出對應的字串
接下要設定ap client的dhcp ip range
$sudo vi /etc/dhcp3/dhcpd.conf # Adding lines
subnet 192.168.0.0 netmask 255.255.255.0
{
range 192.168.0.2 192.168.0.10;
option routers 192.168.0.1;
option domain-name-servers 168.95.192.1;
}
最後弄一個script把啟動必要的動作集合起來。
#!/bin/sh
nat()
{
iptables -A INPUT -i wlan0 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE
echo “1” > /proc/sys/net/ipv4/ip_forward
}
ap_mode()
{
hostapd -B /etc/hostapd/hostapd.conf
}
dhcpserver()
{
dhcpd wlan0
}
#MAIN
case $1 in
start)
modprobe mac80211_hwsim
ifconfig wlan0 192.168.0.1
nat
ap_mode
dhcpserver
;;
stop)
pkill -15 hostapd
pkill -15 dhcpd
iptables -X
echo “0” > /proc/sys/net/ipv4/ip_forward
;;
*)
echo “$0 start or $0 stop”
esac
如果執行完enable_ap.sh start後沒有出現錯誤情況,就可以開始拿出手機測試wifi上網。待使用完畢要停止ap mode服務,執行enable_ap.sh stop。
列出Linux下支援ap mode的chip list