{{{#!html
See also:
Android uses the standard hostapd and wpa_supplicant users-space daemons for Access Point and authentication management. These are fairly close forks of the upstream projects with some changes specifically for Android. Source for both is currently in the external/wpa_supplicent_8 directory. Currently this relates most closely to the version 2.1-devel branch.
The Android network daemon netd (source in /system/netd) manages the overall Linux based network configuration listening for commands over a socket interface. There is a Network Daemon Command shell application, ndc that can be used to send/receive commands via command-line.
The wifi legacy module in hardware/hardware_liblegacy/wifi.c implements the API defined in hardware/libhardware_legacy/include/hardware_legacy/wifi.h
The BoardConfig.mk file for your build target defines the details of the configuration of hostapd and wpa_supplicant used in the build process.
The Gateworks Android BSP defines the following:
# wireless device (used by various modules to include per-device support) BOARD_WLAN_DEVICE := wl12xx_mac80211 # Supplicant WPA_SUPPLICANT_VERSION := VER_0_8_X BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_wl12xx # skip populating rtl/conf files SKIP_WPA_SUPPLICANT_RTL := y SKIP_WPA_SUPPLICANT_CONF := y # AP HOSTAPD_VERSION := VER_0_8_x BOARD_HOSTAPD_DRIVER := NL80211 BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_wl12xx
Additional defines can be used for drivers that require specific kernel modules to be loaded or firmware to be loaded for various operation modes. The actual loading of the modules and firmware is done by wifi.c:
# kernel modules WIFI_DRIVER_MODULE_PATH - full path of kernel module(s) WIFI_DRIVER_MODULE_NAME - kernel module name (w/o the ko) WIFI_DRIVER_MODULE_ARG - kernel module params WIFI_DRIVER_P2P_MODULE_ARG # firmware WIFI_FIRMWARE_LOADER - firmware loader WIFI_DRIVER_FW_PATH_PARAM - params to pass to fw loader WIFI_DRIVER_FW_PATH_AP - full path to AP firmware WIFI_DRIVER_FW_PATH_STA - full path to STA firmware WIFI_DRIVER_FW_PATH_P2P - full path to P2P firmware
The Android framework talks to {{{netd}} via the NetworkManagementService class
The WifiManager class provides the primary API for managing al aspects of Wi-Fi connectivity. To perform operations that pertain to network connectivity at an abstract level use ConnectivityManager which answers queries about the state of network connectivity and notifies applications when network connectivity changes.
The WifiConfiguration class reprsents a configured Wi-Fi network, including the security configuration. Android is not intended to provide a build that is suitable for all wireless devices and you may find that customization via the above is necessary.
The Android modules/packages required for wireless are:
The libhardware_legacy module provides an API used by the Android framework that facilitates kernel module loading, firmware loading, wpa_supplicant service management, and dhcp service management. The module is heavily configurable for specific wireless devices at build-time through:
# kernel Module WIFI_DRIVER_MODULE_NAME WIFI_DRIVER_MODULE_PATH WIFI_DRIVER_MODULE_ARG # Firmware WIFI_FIRMWARE_LOADER WIFI_DRIVER_FW_PATH_STA WIFI_DRIVER_FW_PATH_AP WIFI_DRIVER_FW_PATH_P2P WIFI_DRIVER_FW_PATH_PARAM
Android uses the standard wpa_supplicant users-space daemon for Access Point and authentication management on the client-side.
The wpa_supplicant.conf file is stored in /data/misc/wifi/wpa_supplicant.conf and used by the WifiConfigStore class and the SettingsBackupAgent class
The wpa_supplicant application runs as a backgaround daemon launched by the Android init process. It is communicated with via a socket.
You can use Wireless Networking Client support via the Settings App: Settings -> Wi-Fi. You must enable Wi-Fi and configure one or more Wi-Fi networks at which point the NetworkManagementService? will handle the associations.
An Application can use Wireless Client mode via the WifiConfiguration class (representing a configured Wi-Fi network including security) and the WifiManager class functions:
From a command-line perspective you can manually configure and launch wpa_supplicant if you wish:
# restore default wpa_supplicant.conf and start wpa_supplicant service
cp /system/etc/wifi/wpa_supplicant.conf /data/misc/wifi/wpa_supplicant
chmod 660 /data/misc/wifi/wpa_supplicant.conf
chwon system.wifi /data/misc/wifi/wpa_supplicant.conf
start wpa_supplicant
Android uses the hostapd users-space daemon for Access Point and authentication management on the AP side. For a DHCP server it uses the typical dnsmasq server.
The hostapd application provides the Access Point management and is managed by the netd SoftapController class which accepts the following commands:
The dnsmasq application provides a DHCP server and is managed by the netd TetherController class which also manages iptables.
The netd TetherController class accepts the following commands:
which accesps the following commands.
Network Address Translation (NAT) is provided by the netd NatController class which uses the iptables shell command and accepts the following commands:
The hostapd.conf file is stored in /data/misc/wifi/hostapd.conf and used by the SoftapController class.
The dnsmasq application is launched by netd with all configuration available on the cmdline. It will store lease information in /data/misc/dhcp/dnsmasq.leases
When configuration through the Android UI, the Settings application (Settings -> Wireless & Networks -> More... -> Tethering & portable hotspot -> Set up Wi-Fi hotspot) will store the SSID and Passkey settings in the /data/misc/wifi/softap.conf file which are used to dynamically create /data/misc/wifi/hostapd.conf.
Unlike other system services that are started from Android's init process, hostapd is started on-demand by the Network Daemon netd via it's !SoftapController class when it receives the softap startap command.
This command is sent to netd when the NetworkManagementService startAccessPoint function is called.
From an Android UI perspective, you can enable an Access Point (aka Hotspot) and NAT routing (aka Tethering) via the Settings Application:
Note that enabling the Wi-Fi hotspot via the Settings GUI will not 'stick' and again be enabled on re-boot by design.
An application can use the WifiManager class to manage an Access Point:
If your wireless device requires module or firmware loading, netd will do this as well by calling fwreload <STA|AP|P2P> using the API defined in hardware/libhardware_legacy/include/wifi.h however note that the firmware load command and patches for each option are a build-time option using paths and arguments defined in BoardConfig.mk. By default these are all blank meaning no firmware or modules will be loaded.
While you can manage hostapd and dnsmasq IP forwarding, and Network Address Translation manually it is likely much easier to use the API that the Network Daemon netd provides either through the Android java framework via the NetworkManagementService class or via command-line with its command-line interface app netd.
For example, you can use netd to manage an Access Point with Linux NAT Routine (aka a 'Tethered Hotspot') using ncd:
ndc softap set wlan0 testssid broadcast 11 wpa-psk testpass # config hostapd
interface=<iface> driver=nl80211 ctrl_interface=/data/misc/wifi/hostapd ssid=testssid channel=<channel> ieee80211n=1 hw_mode=g
ndc softap startap # start hostapd
ndc interface setcfg wlan0 192.168.43.1 24 up
ndc tether interface add wlan0 # add wlan0 to tether ndc tether dns set 8.8.4.4 8.8.8.8 # add DNS servers ndc ipfwd enable # enable IP forwarding
ndc tether start 192.168.43.10 192.168.43.99
ndc nat enable wlan0 eth0 0
Note that when using Access Point mode, you must not enable Wireless from the Settings Application as this puts the radio in Client mode.
}}}