[RFC PATCH 08/34] Fetch Device Identity Key from configuration file

Peddolla Harshavardhan Reddy peddolla at qti.qualcomm.com
Thu May 15 00:17:31 PDT 2025


Add support to get Device Identity Key from configuration file.
Generate a new DIK if it is not present in conf file.

Signed-off-by: Peddolla Harshavardhan Reddy <peddolla at qti.qualcomm.com>
---
 src/common/proximity_ranging.h | 13 +++++++++++++
 wpa_supplicant/pr_supplicant.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/common/proximity_ranging.h b/src/common/proximity_ranging.h
index df4a898b8..d2847b62e 100644
--- a/src/common/proximity_ranging.h
+++ b/src/common/proximity_ranging.h
@@ -13,6 +13,8 @@
 #include "utils/list.h"
 #include "drivers/driver.h"
 
+#define DEVICE_IDENTITY_KEY_LEN 16
+
 /**
  * P2P_MAX_REG_CLASSES - Maximum number of regulatory classes
  */
@@ -229,6 +231,17 @@ struct pr_config {
 
 	bool support_6ghz;
 
+	/* Cipher version type */
+	int dik_cipher;
+
+	/* Buffer to hold the DevIK */
+	u8 dik_data[DEVICE_IDENTITY_KEY_LEN];
+
+	/* Length of DevIK in octets */
+	size_t dik_len;
+
+	/* DevIK expiration */
+	int expiration;
 
 	/**
 	 * cb_ctx - Context to use with callback functions
diff --git a/wpa_supplicant/pr_supplicant.c b/wpa_supplicant/pr_supplicant.c
index 1e151581a..65af512c7 100644
--- a/wpa_supplicant/pr_supplicant.c
+++ b/wpa_supplicant/pr_supplicant.c
@@ -142,6 +142,35 @@ int wpas_pr_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
 		os_memcpy(pr.country, "XX\x00", 3);
 	}
 
+	if (wpa_s->conf->dik &&
+	    wpabuf_len(wpa_s->conf->dik) <= DEVICE_IDENTITY_KEY_LEN) {
+		pr.dik_cipher = wpa_s->conf->dik_cipher;
+		pr.dik_len = wpabuf_len(wpa_s->conf->dik);
+		os_memcpy(pr.dik_data, wpabuf_head(wpa_s->conf->dik),
+			  pr.dik_len);
+		pr.expiration = 24; /* hours */
+	} else {
+		pr.dik_cipher = DIRA_CIPHER_VERSION_128;
+		pr.dik_len = DEVICE_IDENTITY_KEY_LEN;
+		pr.expiration = 24; /* hours */
+		if (os_get_random(pr.dik_data, pr.dik_len) < 0)
+			return -1;
+
+		wpa_s->conf->dik =
+			wpabuf_alloc_copy(pr.dik_data, pr.dik_len);
+		if (!wpa_s->conf->dik)
+			return -1;
+
+		wpa_s->conf->dik_cipher = pr.dik_cipher;
+
+		wpa_printf(MSG_DEBUG, "PR: PR init new DIRA set");
+
+		if (wpa_s->conf->update_config &&
+		    wpa_config_write(wpa_s->confname, wpa_s->conf))
+			wpa_printf(MSG_DEBUG,
+				   "PR: Failed to update configuration");
+	}
+
 	global->pr = pr_init(&pr);
 	if (!global->pr) {
 		wpa_printf(MSG_DEBUG, "PR: Failed to init PR");
-- 
2.34.1




More information about the Hostap mailing list