Technical Overview of Android Wi-Fi System

Android’s Wi-Fi subsystem is a comprehensive implementation that includes low-level drivers, user-space daemons, and APIs for developers to leverage connectivity features. This article delves into Android’s Wi-Fi architecture, capabilities, and the processes underpinning its operation, as well as the APIs available for development.


Wi-Fi Architecture in Android

The Android Wi-Fi stack consists of several key components:

  1. Kernel-Level Drivers:

    • The low-level drivers communicate directly with Wi-Fi hardware.
    • Android typically uses the mac80211 framework and cfg80211 for wireless networking, interfacing with hardware-specific drivers like ath10k or brcmfmac.
  2. HAL and WPA Supplicant:

    • The Hardware Abstraction Layer (HAL) provides a bridge between the Android framework and kernel drivers.
    • WPA Supplicant, a user-space daemon, manages Wi-Fi security and connectivity (e.g., WPA2/3 authentication). Recent Android versions use the Wi-Fi HAL as an abstraction layer for the supplicant.
  3. Framework Services:

    • Android frameworks handle Wi-Fi management and connectivity services (e.g., scanning, connecting, hotspot setup). These services interact with HAL and user-space components.
  4. Passpoint/Hotspot 2.0 Support:

    • Android supports Passpoint (802.11u) for seamless access to Wi-Fi networks. It uses features like Generic Advertisement Service (GAS) and Access Network Query Protocol (ANQP) to enable automatic network selection and authentication.

Wi-Fi Features Available to Users

Android’s Wi-Fi functionality includes:

  • Standard Connectivity:

    • Join networks with various security protocols (e.g., WPA, WPA2, WPA3).
    • Save and manage network credentials.
  • Hotspot & Tethering:

    • Turn devices into Wi-Fi hotspots.
    • Share data connections with other devices.
  • Advanced Features:

    • Wi-Fi Direct for peer-to-peer connectivity.
    • Support for Wi-Fi Aware (neighbor-aware networking).
    • Improved performance with WPA3 and Hotspot 2.0.

Wi-Fi Startup Process

  1. Driver Initialization:
    • On boot, kernel modules for Wi-Fi hardware are loaded.
  2. HAL and WPA Supplicant:
    • The HAL interacts with the supplicant to initialize configuration and manage hardware communication.
  3. Framework Initialization:
    • Android’s WifiManager and WifiService start and handle user-level interactions and APIs.

Low-Level Wi-Fi Driver Techniques

  • Android leverages Linux kernel features like Netlink sockets for communication between the user-space and kernel-space.
  • Wireless drivers use the cfg80211 subsystem for configuration, and the mac80211 stack handles packet processing.

Developer APIs

Developers can use the following key APIs in Android to manage Wi-Fi functionality:

  1. WifiManager:

    • Provides methods to scan for networks, connect, disconnect, and retrieve network information.
    • Example: startScan(), getConnectionInfo().
  2. WifiP2pManager:

    • Enables peer-to-peer connectivity using Wi-Fi Direct.
  3. WifiAwareManager:

    • Manages Wi-Fi Aware operations, enabling devices to discover and communicate directly without an access point.
  4. Network Connectivity APIs:

    • ConnectivityManager provides methods to monitor and manage active network connections.

WPA Supplicant and Protocols

  • WPA Supplicant plays a vital role in network authentication and supports protocols like EAP (Extensible Authentication Protocol) for secure access.
  • Android HAL uses HIDL or AIDL interfaces to interact with the supplicant based on Android versions.

Sample Code for Scanning Wi-Fi Networks

1
2
3
4
5
6
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
List<ScanResult> results = wifiManager.getScanResults();
for (ScanResult result : results) {
Log.d("WiFiScan", "SSID: " + result.SSID + ", RSSI: " + result.level);
}

Conclusion

The Android Wi-Fi subsystem is a robust platform for connectivity, offering a rich set of APIs and underlying mechanisms to ensure secure and seamless network management. By understanding its architecture and using the provided APIs, developers can build applications leveraging cutting-edge Wi-Fi capabilities.