]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P2: Allow P2P-PMK to be extracted for testing purposes
authorShivani Baranwal <quic_shivbara@quicinc.com>
Tue, 13 Aug 2024 10:29:08 +0000 (15:59 +0530)
committerJouni Malinen <j@w1.fi>
Tue, 19 Nov 2024 22:28:00 +0000 (00:28 +0200)
Add support to fetch a recent PASN-PMK that is derived during a P2P2
connection. This is needed for testing purposes.

Signed-off-by: Shivani Baranwal <quic_shivbara@quicinc.com>
wpa_supplicant/ctrl_iface.c

index 2ac34df7e47c94ae611465d7370ac32582f79efb..0a8246c5e6a1bd1b89992a840a1deaadf59009ee 100644 (file)
@@ -7859,6 +7859,26 @@ static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
        return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
 }
 
+
+#ifdef CONFIG_TESTING_OPTIONS
+static int p2p_ctrl_pmk_get(struct wpa_supplicant *wpa_s, char *buf,
+                           size_t buflen)
+{
+       const u8 *pmk;
+       size_t pmk_len;
+
+       /* Return the PMK from the first identity entry. This assumes test
+        * cases to remove all indentities at the beginning so that only one
+        * entry is available. */
+       if (!wpa_s->conf->identity || !wpa_s->conf->identity->pmk)
+               return -1;
+
+       pmk_len = wpabuf_len(wpa_s->conf->identity->pmk);
+       pmk = wpabuf_head(wpa_s->conf->identity->pmk);
+
+       return wpa_snprintf_hex(buf, buflen, pmk, pmk_len);
+}
+#endif /* CONFIG_TESTING_OPTIONS */
 #endif /* CONFIG_P2P */
 
 
@@ -13017,6 +13037,10 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strcmp(buf, "P2P_REMOVE_IDENTITY") == 0) {
                if (wpas_p2p_remove_all_identity(wpa_s))
                        reply_len = -1;
+#ifdef CONFIG_TESTING_OPTIONS
+       } else if (os_strncmp(buf, "P2P_PMK_GET", 12) == 0) {
+               reply_len = p2p_ctrl_pmk_get(wpa_s, reply, reply_size);
+#endif /* CONFIG_TESTING_OPTIONS */
 #endif /* CONFIG_P2P */
 #ifdef CONFIG_WIFI_DISPLAY
        } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {