diff mbox series

[v3,05/25] P2P: Add config support to fetch Device Identity key

Message ID 1722850403-8852-6-git-send-email-quic_shivbara@quicinc.com
State Accepted
Headers show
Series Add support for P2P2 | expand

Commit Message

Shivani Baranwal Aug. 5, 2024, 9:33 a.m. UTC
Generate a random device identity key and save it to the config file.
Use the same identity key from config to derive DIRA of NAN SDF frames.

Signed-off-by: Shivani Baranwal <quic_shivbara@quicinc.com>
---
 wpa_supplicant/config.c         |  4 ++++
 wpa_supplicant/config.h         |  9 +++++++++
 wpa_supplicant/config_file.c    |  8 +++++++-
 wpa_supplicant/p2p_supplicant.c | 29 +++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
index b02b694..d0957eb 100644
--- a/wpa_supplicant/config.c
+++ b/wpa_supplicant/config.c
@@ -3095,6 +3095,7 @@  void wpa_config_free(struct wpa_config *config)
 	os_free(config->dpp_mud_url);
 	os_free(config->dpp_extra_conf_req_name);
 	os_free(config->dpp_extra_conf_req_value);
+	os_free(config->dik_data);
 
 	os_free(config);
 }
@@ -5595,6 +5596,9 @@  static const struct global_parse_data global_fields[] = {
 	/* NOTE: When adding new parameters here, add_interface() in
 	 * wpa_supplicant/dbus_new_introspect.c may need to be modified to
 	 * increase the size of the iface->xml buffer. */
+	{ INT(dik_cipher), 0},
+	{ INT(dik_len), 0},
+	{ STR(dik_data), 0 },
 };
 
 #undef FUNC
diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h
index d74b5c4..6b8f0cb 100644
--- a/wpa_supplicant/config.h
+++ b/wpa_supplicant/config.h
@@ -1814,6 +1814,15 @@  struct wpa_config {
 
 	int mld_force_single_link;
 #endif /* CONFIG_TESTING_OPTIONS */
+
+	/* cipher version type */
+	int dik_cipher;
+
+	/* buffer to hold the DevIK */
+	char *dik_data;
+
+	/* length of DevIK */
+	size_t dik_len;
 };
 
 
diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c
index fd8eafe..68aed57 100644
--- a/wpa_supplicant/config_file.c
+++ b/wpa_supplicant/config_file.c
@@ -1628,7 +1628,13 @@  static void wpa_config_write_global(FILE *f, struct wpa_config *config)
 			MAC2STR(config->mld_connect_bssid_pref));
 #endif /* CONFIG_TESTING_OPTIONS */
 	if (config->ft_prepend_pmkid)
-		fprintf(f, "ft_prepend_pmkid=%d", config->ft_prepend_pmkid);
+		fprintf(f, "ft_prepend_pmkid=%d\n", config->ft_prepend_pmkid);
+	if (config->dik_len) {
+		fprintf(f, "dik_cipher=%d\n", config->dik_cipher);
+		fprintf(f, "dik_len=%ld\n", config->dik_len);
+		if (config->dik_data)
+			fprintf(f, "dik_data=%s\n", config->dik_data);
+	}
 }
 
 #endif /* CONFIG_NO_CONFIG_WRITE */
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 2df2d10..f92a608 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -37,6 +37,7 @@ 
 #include "wps_supplicant.h"
 #include "p2p_supplicant.h"
 #include "wifi_display.h"
+#include "crypto/random.h"
 
 
 /*
@@ -5057,6 +5058,34 @@  int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
 	else
 		p2p.passphrase_len = 8;
 
+	if (wpa_s->conf->dik_len && wpa_s->conf->dik_data) {
+		p2p.pairing_config.dik_cipher = wpa_s->conf->dik_cipher;
+		p2p.pairing_config.dik_len = wpa_s->conf->dik_len;
+		hexstr2bin(wpa_s->conf->dik_data, p2p.pairing_config.dik_data,
+			   p2p.pairing_config.dik_len);
+	} else {
+		p2p.pairing_config.dik_cipher = DIRA_CIPHER_VERSION_128;
+		p2p.pairing_config.dik_len = DEVICE_IDENTITY_KEY_LEN;
+		random_get_bytes(p2p.pairing_config.dik_data,
+				 p2p.pairing_config.dik_len);
+
+		wpa_s->conf->dik_data =
+				os_zalloc(p2p.pairing_config.dik_len * 2 + 1);
+		if (!wpa_s->conf->dik_data)
+			return -1;
+
+		wpa_snprintf_hex(wpa_s->conf->dik_data,
+				 p2p.pairing_config.dik_len * 2 + 1,
+				 p2p.pairing_config.dik_data,
+				 p2p.pairing_config.dik_len);
+		wpa_s->conf->dik_len = p2p.pairing_config.dik_len;
+		wpa_s->conf->dik_cipher = p2p.pairing_config.dik_cipher;
+
+		if (wpa_s->conf->update_config &&
+		    wpa_config_write(wpa_s->confname, wpa_s->conf))
+			wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
+	}
+
 	global->p2p = p2p_init(&p2p);
 	if (global->p2p == NULL)
 		return -1;