From a95906f9381ee8aa4ccb66e1c99952658d8e3369 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 29 Nov 2018 16:46:43 +0800 Subject: [PATCH] P2P: support random interface address To enhance privacy, generate a random interface for each group. There are two configurations are introduced: * p2p_interface_random_mac_addr enable interface random MAC address feature, default disable. Signed-off-by: Jimmy Chen --- wpa_supplicant/config.c | 1 + wpa_supplicant/config.h | 10 ++++++++++ wpa_supplicant/config_file.c | 3 +++ wpa_supplicant/p2p_supplicant.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index d4570d6af..b4e9952fe 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -4787,6 +4787,7 @@ static const struct global_parse_data global_fields[] = { { INT_RANGE(p2p_cli_probe, 0, 1), 0 }, { INT(p2p_device_random_mac_addr), 0 }, { FUNC(p2p_device_persistent_mac_addr), 0 }, + { INT(p2p_interface_random_mac_addr), 0 }, #endif /* CONFIG_P2P */ { FUNC(country), CFG_CHANGED_COUNTRY }, { INT(bss_max_count), 0 }, diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index 0d0282755..15d8c4830 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -1507,6 +1507,16 @@ struct wpa_config { * random MAC address, and need to restore to last used MAC address. */ u8 p2p_device_persistent_mac_addr[ETH_ALEN]; + + /** + * 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 57d8afcf0..85a393725 100644 --- a/wpa_supplicant/config_file.c +++ b/wpa_supplicant/config_file.c @@ -1535,6 +1535,9 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config) if (!is_zero_ether_addr(config->p2p_device_persistent_mac_addr)) fprintf(f, "p2p_device_persistent_mac_addr=" MACSTR "\n", MAC2STR(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 6df4f763d..848299d54 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -2076,6 +2076,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); @@ -2154,6 +2161,29 @@ 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; }