p2p: support random interface address
To enhance privacy, generate a ramdom interface for each group.
This need additional qcom driver fix because MAC changing function of
P2P_GO won't work properly.
There are two configurations are introduced:
* p2p_interface_random_mac_addr
enable interface random MAC address feature, default disable.
Bug: 118904478
Test: manual test
* enable WiFi Direct in Settings.
* establish fresh connection between two peers.
* establish reinvoke connection between two peers.
* check interface addresses are random generated.
Test: CtsVerifier - WiFi Direct
* Two random device address enabled device.
* One random device address enabled device and
One random device address disabled device.
Change-Id: I519629eb8520a15e6f2d158cf3b9a4058f66e124
diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
index 970e0fa..a8987a6 100644
--- a/wpa_supplicant/config.c
+++ b/wpa_supplicant/config.c
@@ -4756,6 +4756,7 @@
{ INT_RANGE(dpp_config_processing, 0, 2), 0 },
{ INT(p2p_device_random_mac_addr), 0 },
{ STR(p2p_device_persistent_mac_addr), 0 },
+ { INT(p2p_interface_random_mac_addr), 0 },
};
#undef FUNC
diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h
index 4677d48..ee20a93 100644
--- a/wpa_supplicant/config.h
+++ b/wpa_supplicant/config.h
@@ -1489,6 +1489,16 @@
*/
char *p2p_device_persistent_mac_addr;
+ /**
+ * p2p_interface_random_mac_addr - P2P Interface MAC address policy default
+ *
+ * 0 = use permanent MAC address
+ * 1 = use random MAC address on creating the interface.
+ *
+ * By default, permanent MAC address is used.
+ */
+ int p2p_interface_random_mac_addr;
+
};
diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c
index cab4244..3a6dae5 100644
--- a/wpa_supplicant/config_file.c
+++ b/wpa_supplicant/config_file.c
@@ -1517,6 +1517,9 @@
if (config->p2p_device_persistent_mac_addr)
fprintf(f, "p2p_device_persistent_mac_addr=%s\n",
config->p2p_device_persistent_mac_addr);
+ if (config->p2p_interface_random_mac_addr)
+ fprintf(f, "p2p_interface_random_mac_addr=%d\n",
+ config->p2p_interface_random_mac_addr);
}
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 346326f..3d3296f 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -2075,6 +2075,17 @@
return -1;
}
+ if (wpa_s->conf->p2p_interface_random_mac_addr) {
+ if (random_mac_addr(wpa_s->pending_interface_addr) < 0) {
+ wpa_printf(MSG_ERROR, "P2P: Failed to generate random MAC address "
+ "for the group interface");
+ return -1;
+ }
+ wpa_printf(MSG_DEBUG, "P2P: Generate random MAC address " MACSTR " for the group",
+ MAC2STR(wpa_s->pending_interface_addr));
+ }
+
+
if (force_ifname[0]) {
wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s",
force_ifname);
@@ -2153,6 +2164,25 @@
wpas_p2p_clone_config(group_wpa_s, wpa_s);
+ if (wpa_s->conf->p2p_interface_random_mac_addr) {
+ if (wpa_drv_set_mac_addr(group_wpa_s, wpa_s->pending_interface_addr) < 0) {
+ wpa_msg(group_wpa_s, MSG_INFO,
+ "Failed to set random MAC address");
+ wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, 0);
+ return NULL;
+ }
+
+ if (wpa_supplicant_update_mac_addr(group_wpa_s) < 0) {
+ wpa_msg(group_wpa_s, MSG_INFO,
+ "Could not update MAC address information");
+ wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, 0);
+ return NULL;
+ }
+
+ wpa_printf(MSG_DEBUG, "P2P: Using random MAC address " MACSTR " for the group",
+ MAC2STR(wpa_s->pending_interface_addr));
+ }
+
return group_wpa_s;
}