wifi(implementation): Set randomized MAC address for AP
Add the plumbing required for setting a random MAC address on AP
startup. The random MAC address is created once for the lifetime of
the daemon and then reused for any further AP creation. This would
ensure that the MAC address is changed on every reboot.
The feature is turned on by default, devices will need to set the
|WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION| in their .mk file to
disable the feature at compile time.
Bug: 78353419
Test: ./hardware/interfaces/wifi/1.3/default/tests/runtests.sh
Change-Id: I054d5249c20cc582b76966313135295873cd0b61
diff --git a/wifi/1.3/default/wifi_ap_iface.cpp b/wifi/1.3/default/wifi_ap_iface.cpp
index 025ece3..9a8681a 100644
--- a/wifi/1.3/default/wifi_ap_iface.cpp
+++ b/wifi/1.3/default/wifi_ap_iface.cpp
@@ -31,11 +31,26 @@
WifiApIface::WifiApIface(
const std::string& ifname,
const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
- const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)
+ const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util,
+ const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags)
: ifname_(ifname),
legacy_hal_(legacy_hal),
iface_util_(iface_util),
- is_valid_(true) {}
+ feature_flags_(feature_flags),
+ is_valid_(true) {
+ if (feature_flags_.lock()->isApMacRandomizationDisabled()) {
+ LOG(INFO) << "AP MAC randomization disabled";
+ return;
+ }
+ LOG(INFO) << "AP MAC randomization enabled";
+ // Set random MAC address
+ std::array<uint8_t, 6> randomized_mac =
+ iface_util_.lock()->getOrCreateRandomMacAddress();
+ bool status = iface_util_.lock()->setMacAddress(ifname_, randomized_mac);
+ if (!status) {
+ LOG(ERROR) << "Failed to set random mac address";
+ }
+}
void WifiApIface::invalidate() {
legacy_hal_.reset();