The Wi-Fi Direct feature, also known as Wi-Fi P2P, allows supporting devices to discover and connect to one another directly using the Wi-Fi Direct protocol without internet or cellular network access. This feature, built upon the Wi-Fi Alliance (WFA) Wi-Fi Direct specification allows sharing of high-throughput data among trusted devices and apps that are otherwise off-network.
Examples and source
To use this feature, device manufacturers must implement the Wi-Fi Vendor and Supplicant HAL interfaces.
In Android 13, the Supplicant interface uses AIDL for the HAL definition. In Android 14 and higher, the Vendor HAL interface uses AIDL. In Android 12 and lower, the Supplicant and Vendor HAL interfaces are defined using HIDL.
The following Wi-Fi HAL surfaces are required to employ the Wi-Fi Direct feature:
hardware/interfaces/wifi/aidl
or,hardware/interfaces/wifi/1.3
or higherhardware/interfaces/wifi/supplicant/aidl
or,hardware/interfaces/wifi/supplicant/1.2
or higher
Implementation
Device manufacturers need to provide both framework and HAL/firmware support:
- Framework:
- AOSP code
- Enable Wi-Fi Direct: Requires a feature flag
- Wi-Fi Direct (P2P) HAL support (which implies firmware support)
To implement this feature, device manufacturers implement the Wi-Fi HIDL or AIDL
interfaces and enable the feature flag for Wi-Fi Direct. In device.mk
located
in device/<oem>/<device>
, modify the PRODUCT_COPY_FILES
environment variable
to include support for the Wi-Fi Direct feature:
```
PRODUCT_COPY_FILES +=
frameworks/native/data/etc/android.hardware.wifi.direct.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.direct.xml
```
All other requirements for supporting Wi-FI Direct are included in AOSP.
MAC randomization
Android requires that the Wi-Fi Direct device address and interface address are randomized. They must be different from the true MAC address of the device and must meet the following requirements:
- The Wi-Fi Direct device address must be randomized on interface creation if there is no persistent group saved; otherwise the device address must keep using the last generated MAC address.
- The Wi-Fi Direct interface address, also known as group address, must be randomized every time a connection is established.
Wi-Fi Direct MAC randomization is implemented in 'wpa_supplicant' and controlled
by two configurations, p2p_device_random_mac_addr
and
p2p_interface_random_mac_addr
.
To enable this feature, device manufacturers must:
- Implement the Wi-Fi Supplicant
ISupplicantP2pIface::setMacRandomization
API. Depending on the interface implemented, this is in:hardware/interface/wifi/supplicant/1.2
for HIDLhardware/interface/wifi/supplicant/aidl
for AIDL
- Set
config_wifi_p2p_mac_randomization_supported
to 'true' in a device custom overlay.
Validation
Android provides a set of unit tests, Compatibility Test Suite (CTS) tests, and CTS Verifier tests to validate the Wi-Fi Direct feature. Wi-Fi Direct can also be tested using the Vendor Test Suite (VTS).
Unit tests
Verify the Wi-Fi Direct package using the following tests.
Service tests:
atest com.android.server.wifi.p2p
Manager tests:
atest android.net.wifi.p2p
Compatibility Test Suite (CTS) tests
Use CTS tests to validate the Wi-Fi Direct feature. CTS detects when the feature is enabled and automatically includes the associated tests.
To trigger the CTS tests, run:
% atest android.net.wifi.p2p.cts
CTS Verifier tests
CTS Verifier tests validate Wi-Fi Direct behavior using two devices: a test device and a known good device. To run the tests, open CTS Verifier and navigate to the section titled Wi-Fi Direct Tests.