Wifi Nic status 1. WIFI_STATE_DISABLED: WIFI Nic unavailable 2. WIFI_STATE_DISABLING: WIFI is being disabled 3. WIFI_STATE_ENABLED: WIFI Nic available 4. WIFI_STATE_ENABLING: the WIFI Nic is on. 5. WIFI_STATE_UNKNOWN: Unknown Nic status required for WIFI access to the network <uses-permission android: name = "android. permission. CHANGE_NETWORK_STATE "> </uses-permission> permission for modifying the network status <uses-permission android: name =" android. permission. CHANGE_WIFI_STATE "> </uses-permission> permission for modifying the WIFI status <uses-permiss Ion android: name = "android. permission. ACCESS_NETWORK_STATE "> </uses-permission> network access permission <uses-permission android: name =" android. permission. ACCESS_WIFI_STATE "> </uses-permission> access WIFI permission. the Wi-Fi Core Module n is created by ConnecttivityService generated when the SystemServer starts WifiService. It is responsible for starting and disabling wpa_supplicant and the WifiMonitor threads, send the command to wpa_supplicant and the status with the new WIFI. n WifiMonitor is responsible for receiving Event Notifications from wpa_supplicant. n Wpa_supplicant. 1. Read the configuration file. 2. initialize configuration parameters and drive functions. 3. enable the driver to scan all bssid values. 4. Check whether the scan parameters are consistent with those set by the user. 5. If yes, notify the driver to perform permission authentication 6. Connect to the source provided by the AP n Wifi driver module vendor, the module is mainly used to load firmware and kernel wireless for communication. n Wifi power management module mainly controls hardware GPIO and power-on and power-off, enable the CPU and Wifi modules to communicate with each other through the sdio interface Wifi work step n initial Wifi module n Wifi start n find hotspot (AP) n configure AP parameters n Wifi connection n IP address configure Wifi module code summary n Wifi Application code packages/apps/Settings/src/com/android/settings/wifi n Wifi Framework frameworks /base/wifi/java/android/net/wi Fi frameworks/base/services/java/com/android/server n Wifi JNI frameworks/base/core/jni/android_net_wifi_Wifi.cpp n Wifi Hardware hardware/libhardware_legacy/wifi. c n Wifi tool external/wpa_supplicant n Wifi kernel net/wireless drivers/wlan_sd8688 arch/arm/mach-pxa/wlan_pm.c Wifi module initialization: When SystemServer is started, A ConnectivityService instance is generated. The ConnectivityService constructor creates WifiService and WifiStateTracker. WifiMonitor is created to receive events from the underlying layer. WifiService and WifiMonitor are the core of the entire module. WifiService is responsible for starting and disabling wpa_supplicant, starting and disabling the WifiMonitor monitoring thread, and issuing the command to wpa_supplicant, while WifiMonitor is responsible for receiving Event Notifications from wpa_supplicant. Start of the Wifi module: WirelessSettings configures the WifiEnabler to process the Wifi button during initialization. When the user presses the Wifi button, Android will call the onPreferenceChange of the WifiEnabler, then, WifiEnabler calls the setWifiEnabled interface function of WifiManager. Through AIDL, The setWifiEnabled function of WifiService is actually called, and WifiService then sends a MESSAGE_ENABLE_WIFI message to itself, perform real enabling in the code that processes the message: First load the WIFI kernel module (the location of the module is hard-coded as "/system/lib/modules/wlan. ko "), and then start wpa_supplicant (the configuration file is hard-coded as"/data/misc/wifi/wpa_supplicant.conf "), Then, WifiStateTracker is used to start the monitoring thread in the WifiMonitor. Find hotspot (AP): After the Wifi module is enabled, WIFI_STATE_CHANGED_ACTION is sent to the outside world. WifiLayer registers the operator of Action. After WifiLayer receives this Action, it starts the scan process. The following figure shows how wpa_supplicant sends an event notification to the control channel after processing the SCAN command, this event is received from the wifi_wait_for_event function. Therefore, the MonitorThread in the WifiMonitor will be executed for this event: configure the AP parameter: After you select an AP on the WifiSettings interface, A dialog box for configuring AP parameters is displayed: Wifi connection: IP Address Configuration: