diff mbox series

PATCH: P2P randomized MAC address support

Message ID CALoVRkOyQkCT_GW_fkxSjTnopzMCTyhFSF7hM2CmPRCw_df7kg@mail.gmail.com
State Accepted
Headers show
Series PATCH: P2P randomized MAC address support | expand

Commit Message

Jimmy Chen Jan. 10, 2019, 7:11 a.m. UTC
Hi,

To enhance privacy, we try to hide the real MAC address of P2P interface.
These two patches would provide P2P randomized MAC address support.

Best regards,
Jimmy

Comments

Jouni Malinen Jan. 12, 2019, 5:48 p.m. UTC | #1
On Thu, Jan 10, 2019 at 03:11:01PM +0800, Jimmy Chen wrote:
> To enhance privacy, we try to hide the real MAC address of P2P interface.
> These two patches would provide P2P randomized MAC address support.

Thanks, applied with some clean up.
diff mbox series

Patch

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(+)

diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
index caecfd15b..f5c606703 100644
--- a/wpa_supplicant/config.c
+++ b/wpa_supplicant/config.c
@@ -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
diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h
index 6e009e836..f735671a6 100644
--- a/wpa_supplicant/config.h
+++ b/wpa_supplicant/config.h
@@ -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;
+
 };
 
 
diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c
index ea45ed398..1e1c53085 100644
--- a/wpa_supplicant/config_file.c
+++ b/wpa_supplicant/config_file.c
@@ -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 */
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 8d0d1ad5a..836673463 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -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