]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: support random interface address
authorJimmy Chen <jimmycmchen@google.com>
Thu, 29 Nov 2018 08:46:43 +0000 (16:46 +0800)
committerJouni Malinen <j@w1.fi>
Sat, 12 Jan 2019 15:58:30 +0000 (17:58 +0200)
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 <jimmycmchen@google.com>
wpa_supplicant/config.c
wpa_supplicant/config.h
wpa_supplicant/config_file.c
wpa_supplicant/p2p_supplicant.c

index d4570d6afe061be9b2d56bfb7f907b52e690210c..b4e9952feee2e837ae9a2bca7dd1384a78d102e2 100644 (file)
@@ -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 },
index 0d02827551b34012190253008529ff9bd12a4d37..15d8c48300a2b6b70ccce70e6a1c0be6146dde71 100644 (file)
@@ -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;
 };
 
 
index 57d8afcf0251376803ad0c2c60ac739e5cf68c95..85a3937252ce5cc96ba822df4b455deb40052c09 100644 (file)
@@ -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 */
index 6df4f763d44b0efd45929574b3bceb24b8fc45c9..848299d541a753a8db8d3bd9fc068c6ddc16a500 100644 (file)
@@ -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;
 }