]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
PR: Fetch Device Identity Key from configuration file
authorPeddolla Harshavardhan Reddy <peddolla@qti.qualcomm.com>
Sat, 26 Apr 2025 19:14:49 +0000 (00:44 +0530)
committerJouni Malinen <j@w1.fi>
Fri, 17 Oct 2025 10:22:51 +0000 (13:22 +0300)
Get Device Identity Key from wpa_supplicant configuration file. Generate
a new DIK if it is not present in the configuration file.

Signed-off-by: Peddolla Harshavardhan Reddy <peddolla@qti.qualcomm.com>
src/common/proximity_ranging.h
wpa_supplicant/pr_supplicant.c

index 830ac5f8b4c4445e7a4dd55883a235137023b6d9..45ae998fc723eb6d4bd3077a28a3fb6ffdc2701a 100644 (file)
@@ -12,6 +12,8 @@
 #include "utils/list.h"
 #include "wps/wps_defs.h"
 
+#define DEVICE_IDENTITY_KEY_LEN 16
+
 /**
  * PR_MAX_OP_CLASSES - Maximum number of operating classes
  */
@@ -285,6 +287,18 @@ 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
         */
index f32d9a45ed90e1f72a400ea889512e64cf493dc1..961d5711ee30f58163b80a725068a1c6f8c539da 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "utils/common.h"
 #include "common/proximity_ranging.h"
+#include "p2p/p2p.h"
 #include "wpa_supplicant_i.h"
 #include "config.h"
 #include "pr_supplicant.h"
@@ -312,6 +313,35 @@ int wpas_pr_init(struct wpa_global *global, struct wpa_supplicant *wpa_s,
                os_memcpy(pr.country, "XX\x04", 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");