一、WPA_SUPPLICANT簡介
1. 什么是wpa_supplicant
wpa_supplicant is a WPA Supplicant for Linux, BSD, Mac OS X, and Windows with support for WPA and WPA2 (IEEE 802.11i / RSN). It is suitable for both desktop/laptop computers and embedded systems. Supplicant is the IEEE 802.1X/WPA component that is used in the client stations. It implements key negotiation with a WPA Authenticator and it controls the roaming and IEEE 802.11 authentication/association of the wlan driver.
wpa_supplicant is designed to be a "daemon" program that runs in the background and acts as the backend component controlling the wireless connection. wpa_supplicant supports separate frontend programs and a text-based frontend (wpa_cli) and a GUI (wpa_gui) are included with wpa_supplicant.
wpa_supplicant uses a flexible build configuration that can be used to select which features are included. This allows minimal code size (from ca. 50 kB binary for WPA/WPA2-Personal and 130 kB binary for WPA/WPA2-Enterprise without debugging code to 450 kB with most features and full debugging support; these example sizes are from a build for x86 target).
2. 支持的WPA/IEEE 802.11i feature
WPA-PSK ("WPA-Personal")WPA with EAP (e.g., with RADIUS authentication server) ("WPA-Enterprise")key management for CCMP, TKIP, WEP104, WEP40WPA and full IEEE 802.11i/RSN/WPA2RSN: PMKSA caching, pre-authenticationIEEE 802.11rIEEE 802.11wWi-Fi Protected Setup (WPS)
3. 支持的無線無線網卡和驅動
Linux drivers that support nl80211/cfg80211 (most new drivers)Linux drivers that support Linux Wireless Extensions v19 or newer with WPA/WPA2 extensionsWired Ethernet driversBSD net80211 layer (e.g., Atheros driver) (FreeBSD 6-CURRENT and NetBSD current)Windows NDIS drivers (Windows; at least XP and 2000, others not tested)
4. WPA如何和AP建立聯系
wpa_supplicant requests the kernel driver to scan neighboring BSSeswpa_supplicant selects a BSS based on its configurationwpa_supplicant requests the kernel driver to associate with the chosen BSSif WPA-EAP: integrated IEEE 802.1X Supplicant completes EAP authentication with the authentication server (proxied by the Authenticator in the AP)If WPA-EAP: master key is received from the IEEE 802.1X SupplicantIf WPA-PSK: wpa_supplicant uses PSK as the master session keywpa_supplicant completes WPA 4-Way Handshake and Group Key Handshake with the Authenticator (AP). WPA2 has integrated the initial Group Key Handshake into the 4-Way Handshake.wpa_supplicant configures encryption keys for unicast and broadcastnormal data packets can be transmitted and received
二、移植wpa_supplicant和wifi驅動的步驟
1. 將廠商提供的HAL代碼復制到hardware目錄下,並修改Makefile
例如:realteck、broadcom、ti、qcomm等。
2. 修改ANDROID_SDK /device/<soc_vendor_name>/<board_name>/目錄下的BoardConfig.mk
例如:
BOARD_WIFI_VENDOR := realtek
ifeq ($(BOARD_WIFI_VENDOR), realtek)
WPA_SUPPLICANT_VERSION := VER_0_8_X
BOARD_WPA_SUPPLICANT_DRIVER := NL80211
CONFIG_DRIVER_WEXT :=y
BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_rtl
BOARD_HOSTAPD_DRIVER := NL80211
BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_rtl
BOARD_WLAN_DEVICE := rtl8192cu
#BOARD_WLAN_DEVICE := rtl8192du
#BOARD_WLAN_DEVICE := rtl8192ce
#BOARD_WLAN_DEVICE := rtl8192de
#BOARD_WLAN_DEVICE := rtl8723as
#BOARD_WLAN_DEVICE := rtl8723au
#BOARD_WLAN_DEVICE := rtl8189es
#BOARD_WLAN_DEVICE := rtl8723bs
#BOARD_WLAN_DEVICE := rtl8723bu
WIFI_DRIVER_MODULE_NAME := "wlan"
WIFI_DRIVER_MODULE_PATH := "/system/lib/modules/wlan.ko"
WIFI_DRIVER_MODULE_ARG := "ifname=wlan0 if2name=p2p0"
endif
3. 修改ANDROID_SDK/device/<soc_vendor_name>/<board_name>/目錄下的init.xxx.rc
例如:
service rtw_suppl_con /system/bin/wpa_supplicant \
-ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
-e/data/misc/wifi/entropy.bin -N \
-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
-O/data/misc/wifi/sockets \
-g@android:wpa_wlan0
class main
socket wpa_wlan0 dgram 660 wifi wifi
disabled
oneshot
service rtw_suppl /system/bin/wpa_supplicant \
-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
-O/data/misc/wifi/sockets \
-e/data/misc/wifi/entropy.bin
-g@android:wpa_wlan0
class main
socket wpa_wlan0 dgram 660 wifi wifi
disabled
service dhcpcd_wlan0 /system/bin/dhcpcd -aABDKL
class main
disabled
oneshot
service dhcpcd_p2p /system/bin/dhcpcd -aABKL
class main
disabled
oneshot
service iprenew_wlan0 /system/bin/dhcpcd -n
class main
disabled
oneshot
service iprenew_p2p /system/bin/dhcpcd -n
class main
disabled
oneshot
4. 修改ANDROID_SDK/device/<soc_vendor_name>/<board_name>/目錄下的device.mk
例如:
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.wifi.xml:system/etc/permissions/android.hardware.
wifi.xml
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.wifi.direct.xml:system/etc/permissions/android.hard
ware.wifi.direct.xml
PRODUCT_PROPERTY_OVERRIDES += \
wifi.interface=wlan0
5. 修改ANDROID_SDK/frameworks/base/core/res/res/values/config.xml,配置wifi網絡屬性
array translatable="false" name="networkAttributes"> "wifi,1,1,1,-1,true" "bluetooth,7,7,0,-1,true" "ethernet,9,9,2,-1,true"</STRING-array>
array translatable="false" name="radioAttributes"> "1,1" "7,1" "9,1" </STRING-array>
array translatable="false" name="config_tether_wifi_regexs"> "wlan0" </STRING-array>
array translatable="false" name="config_tether_upstream_types"> 1 9 </INTEGER-array>
6. 將廠商提供的WPA_SUPPLICANT替換到ANDROID_SDK/external/wpa_suppliant_8目錄下
7. 編譯wifi驅動,將驅動配置成模塊加載的方式,將生成的ko文件存放到BoardConfig.mk里面設置的ko文件路徑下,並確認驅動模塊名稱一致
三、常用調試命令和技巧
1. 調試命令
通過wpa_cli命令可以檢測wpa_supplicant的運行狀態
- PING:心跳檢測命令。客戶端用它判斷WPAS是否工作正常。WPAS收到”PING”命令后需要回復“PONG”。
- MIB:客戶端用該命令獲取設備的MIB信息。
- STATUS:客戶端用該命令來獲取WPAS的工作狀態。
- ADD_NETWORK:為WPAS添加一個新的無線網絡。它將返回此新無線網絡的id(從0開始)。注意:此network id非常重要,客戶端后續將通過它來指明自己想操作的無線網絡。
- SET_NETWORK <network id> <variable> <value>:network id是無線網絡的id。此命令用於設置指定無線網絡的信息。其中variable為參數名,value為參數的值。
- ENABLE_NETWORK <network id>:使能某個無線網絡。此命令最終將促使WPAS發起一系列操作以加入該無線網絡。
2. 調試技巧
可以在wpa_supplicant里面增加一些log來跟蹤指令的下發流程。
通過在命令行終端輸入getprop init.svc.wpa_servername 來檢查wpa_supplicant進程是否在運行。
wpa_supplicant起來后,可以通過查看wpa_cli ping或者wpa_cli status來檢測wpa_suppliant通道是否正常。
檢查/system/etc/wifi/wpa_supplicant.conf和/data/misc/wifi/wpa_supplicant.conf中ctrl_interface是否正確。
檢查/dev/socket/wpa_wlan0、/data/misc/wifi/sockets/wlan0、/data/misc/wifi/sockets/p2p、wpa_ctrl_*等節點是否成功創建。
通過lsmod檢查驅動模塊是否成功加載。
通過查看/sys/class/rfkill/目錄下是否生成rfkill*節點判斷驅動加載過程是否OK。