From 98f217240eb38735c0b6eeef611daa1cd7acc732 Mon Sep 17 00:00:00 2001
From: Jimmy Chen <jimmycmchen@google.com>
Date: Thu, 29 Nov 2018 16:46:43 +0800
Subject: [PATCH 2/2] p2p: support random interface address
To enhance privacy, generate a ramdom interface for each group.
There are two configurations are introduced:
* p2p_interface_random_mac_addr
enable interface random MAC address feature, default disable.
Change-Id: I519629eb8520a15e6f2d158cf3b9a4058f66e124
Signed-off-by: Jimmy Chen <jimmycmchen@google.com>
---
wpa_supplicant/config.c | 1 +
wpa_supplicant/config.h | 10 ++++++++++
wpa_supplicant/config_file.c | 3 +++
wpa_supplicant/p2p_supplicant.c | 26 ++++++++++++++++++++++++++
4 files changed, 40 insertions(+)
@@ -4847,6 +4847,7 @@ static const struct global_parse_data global_fields[] = {
{ INT_RANGE(coloc_intf_reporting, 0, 1), 0 },
{ INT(p2p_device_random_mac_addr), 0 },
{ STR(p2p_device_persistent_mac_addr), 0 },
+ { INT(p2p_interface_random_mac_addr), 0 },
};
#undef FUNC
@@ -1498,6 +1498,16 @@ struct wpa_config {
*/
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;
+
};
@@ -1533,6 +1533,9 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
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);
}
#endif /* CONFIG_NO_CONFIG_WRITE */
@@ -2075,6 +2075,13 @@ static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s,
return -1;
}
+ if (wpa_s->conf->p2p_interface_random_mac_addr) {
+ random_mac_addr(wpa_s->pending_interface_addr);
+ 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 +2160,25 @@ wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go)
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;
}
--
2.20.1.97.g81188d93c3-goog