1. System Architecture
The android WiFi system introduces wpa_supplicant. The entire WiFi system uses wpa_supplicant as the core to define upper-layer user interfaces and lower-layer driver interfaces. Shows the entire Wi-Fi system architecture:
Everything is in progress. Next we will analyze each part in detail.
1.1 wifiservice
The connecttivityservice created when systemserver is started is responsible for starting and disabling wpa_supplicant, starting and closing the wifimonitor thread, issuing the command to wpa_supplicant, and updating the WiFi status.
Handle remote Wi-Fi Operations sent by other modules through the iwifimanager interface.
1.2 wifimonitor
Receives Event Notifications from wpa_supplicant.
1.3 wpa_supplicant
1) read the configuration file
2) initialize configuration parameters and Drive Functions
3) Let the driver scan all current bssid
4) check whether the scan parameters are consistent with those set by the user.
5) if they match, the notification driver will perform permission and authentication operations.
6) connect to the AP
1.4 WiFi Driver Module
Source provided by the vendor, mainly for load firware and kernel Wireless Communication
1.5 WiFi Power Management Module
It mainly controls the hardware gpio and power-on and power-off, so that the CPU and WiFi modules can communicate with each other through the sdio interface or USB interface.
1.6 WiFi procedure
1) WiFi startup
2) Start scanning
3) display the scanned AP
4) configure the AP
5) connect to the AP
6) obtain the IP address
7) surfing the internet
1.7 WiFi module code
1) WiFi settings Application
Packages/apps/settings/src/COM/Android/settings/WiFi
2) WiFi framework
Frameworks/base/WiFi/Java/Android/NET/WiFi (the UI uses android.net. WiFi package
Send command to wifi. c)
Frameworks/base/CORE/Java/Android/net (higher-level network management)
Frameworks/base/services/Java/COM/Android/Server
3) WiFi JNI
Frameworks/base/CORE/JNI/android_net_wifi_wifi.cpp
4) WiFi hardware (WiFi Management Library)
Hardware/libhardware_legacy/WiFi/wifi. c
5) wpa_supplicant (WiFi tool)
External/wpa_supplicant8
(1) wpa_client (generate library libwpaclient. So)
External/wpa_supplicant_8/wpa_supplicant/src/common/wpa_ctrl.c
(2) wpa_server (generate the daemon wpa_supplicant)
External/wpa_supplicant_8/wpa_supplicant/Main. c
6) WiFi Kernel
Net/wireless Drivers/wlan_xxx ARCH/ARM/Mach-xxx/wlan_pm.c
2. wifiservice and wpa_supplicant Startup Process
Shows the wifiservice and wpa_supplicant startup processes:
2.1 status changes
• The status change process for loading the WiFi driver is as follows:
Initial State: minitialstate
|
Mdriverunloadedstate
|
Mwaitforp2pdisablestate
|
Mdriverloadingstate (its enter calls wifinative. loaddriver)
• The status of wpa_supplicant startup changes as follows:
Call wifinative. startsupplicant in processmessage of driverloadedstate.
3. automatically enable WiFi during production
In production, WiFi is disabled by default. To enable it by default, you can modify the following code in wifiservice. Java:
[CPP]View
Plaincopy
- /**
- * Check if Wi-Fi needs to be enabled and start
- * If needed
- *
- * This function is used only at boot time
- */
- Public void checkandstartwifi (){
- Mairplanemodeon. Set (isairplanemodeon ());
- Mpersistwifistate. Set (getpersistedwifistate ());
- /* Start If wi-fi shoshould be enabled or the saved State indicates Wi-Fi was on */
- Boolean wifienabled = shouldwifibeenabled () | testandclearwifisavedstate ();
- Slog. I (TAG, "wifiservice starting up with Wi-Fi" +
- (Wifienabled? "Enabled": "disabled "));
- Setwifienabled (wifienabled); // set it to true.
- Mwifiwatchdogstatemachine = wifiwatchdogstatemachine.
- Makewifiwatchdogstatemachine (mcontext );
- }