]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P2: Control interface command to get DIRA info of a P2P device
authorVinay Gannevaram <quic_vganneva@quicinc.com>
Sun, 19 Jan 2025 17:22:27 +0000 (22:52 +0530)
committerJouni Malinen <j@w1.fi>
Fri, 24 Jan 2025 20:48:14 +0000 (22:48 +0200)
Add a control interface command P2P_GET_DIRA to get DIRA nonce and tag
of a P2P device when pairing support is enabled. Upper layer components
can fetch DIRA info of a device and populate it in BLE frames for
BLE-Assisted P2P R2 Discovery.

Signed-off-by: Vinay Gannevaram <quic_vganneva@quicinc.com>
src/p2p/p2p.c
src/p2p/p2p.h
wpa_supplicant/ctrl_iface.c
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/p2p_supplicant.h

index cd3563bf5d5a7d4f3d74e184316b5751424707cf..7775aa788d7ab47e3f25783c2e7073ba4e238b79 100644 (file)
@@ -7313,3 +7313,52 @@ int p2p_pasn_get_ptk(struct p2p_data *p2p, const u8 **buf, size_t *buf_len)
 #endif /* CONFIG_TESTING_OPTIONS */
 
 #endif /* CONFIG_PASN */
+
+
+int p2p_get_dira_info(struct p2p_data *p2p, char *buf, size_t buflen)
+{
+       int res;
+       char *pos, *end;
+       struct p2p_id_key *dev_ik;
+
+       if (!p2p->pairing_info ||
+           !p2p->cfg->pairing_config.pairing_capable ||
+           !p2p->cfg->pairing_config.enable_pairing_cache)
+               return 0;
+
+       if (p2p_derive_nonce_tag(p2p))
+               return 0;
+
+       pos = buf;
+       end = buf + buflen;
+       dev_ik = &p2p->pairing_info->dev_ik;
+
+       res = os_snprintf(pos, end - pos, MACSTR,
+                         MAC2STR(p2p->cfg->dev_addr));
+       if (os_snprintf_error(end - pos, res))
+               return pos - buf;
+       pos += res;
+
+       res = os_snprintf(pos, end - pos, " ");
+       if (os_snprintf_error(end - pos, res))
+               return pos - buf;
+       pos += res;
+
+       pos += wpa_snprintf_hex(pos, end - pos, dev_ik->dira_nonce,
+                               dev_ik->dira_nonce_len);
+
+       res = os_snprintf(pos, end - pos, " ");
+       if (os_snprintf_error(end - pos, res))
+               return pos - buf;
+       pos += res;
+
+       pos += wpa_snprintf_hex(pos, end - pos, dev_ik->dira_tag,
+                               dev_ik->dira_tag_len);
+
+       res = os_snprintf(pos, end - pos, "\n");
+       if (os_snprintf_error(end - pos, res))
+               return pos - buf;
+       pos += res;
+
+       return pos - buf;
+}
index 51eed59d29e5eaff5ae816b192a92c281ea28f44..066064e1389b6d2ea9fadf501b01383eb1c5a69a 100644 (file)
@@ -2790,5 +2790,6 @@ void p2p_set_store_pasn_ptk(struct p2p_data *p2p, u8 val);
 void p2p_pasn_store_ptk(struct p2p_data *p2p, struct wpa_ptk *ptk);
 int p2p_pasn_get_ptk(struct p2p_data *p2p, const u8 **buf, size_t *buf_len);
 void p2p_usd_service_hash(struct p2p_data *p2p, const char *service_name);
+int p2p_get_dira_info(struct p2p_data *p2p, char *buf, size_t buflen);
 
 #endif /* P2P_H */
index 0b29dc705cdbeba32bbb311da6a4dce574768ba1..90e98ce6ad37329ff3ee9e783701f001bcb5f466 100644 (file)
@@ -13034,6 +13034,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                        reply_len = -1;
        } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
                reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
+       } else if (os_strcmp(buf, "P2P_GET_DIRA") == 0) {
+               reply_len = wpas_p2p_get_dira(wpa_s, reply, reply_size);
 #ifdef CONFIG_PASN
 #ifdef CONFIG_TESTING_OPTIONS
        } else if (os_strcmp(buf, "P2P_GET_PASNPTK") == 0) {
@@ -14138,6 +14140,7 @@ static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
 #ifdef CONFIG_AP
                "STA-FIRST",
 #endif /* CONFIG_AP */
+               "P2P_GET_DIRA",
                NULL
        };
        static const char * prefix[] = {
index 8d472f0d605105dc760be220b95fcb5a13ffb4c4..ee12c8a6d89136495ddcde335f7ab36a8cae6b7f 100644 (file)
@@ -11432,6 +11432,16 @@ int wpas_p2p_get_pasn_ptk(struct wpa_supplicant *wpa_s, const u8 **ptk,
 #endif /* CONFIG_PASN */
 
 
+int wpas_p2p_get_dira(struct wpa_supplicant *wpa_s, char *buf, size_t buf_len)
+{
+       struct p2p_data *p2p = wpa_s->global->p2p;
+
+       if (wpa_s->global->p2p_disabled || !p2p)
+               return 0;
+       return p2p_get_dira_info(p2p, buf, buf_len);
+}
+
+
 void wpas_p2p_update_dev_addr(struct wpa_supplicant *wpa_s)
 {
        os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
index 89a3bf91746afb88a20c0b5a24733a2f9b80a5ff..32af1af03f25012faf5f1f53af7819b0c045b73e 100644 (file)
@@ -244,6 +244,7 @@ int wpas_p2p_pasn_auth_rx(struct wpa_supplicant *wpa_s,
                          int freq);
 int wpas_p2p_get_pasn_ptk(struct wpa_supplicant *wpa_s, const u8 **ptk,
                          size_t *ptk_len);
+int wpas_p2p_get_dira(struct wpa_supplicant *wpa_s, char *buf, size_t buf_len);
 
 #else /* CONFIG_P2P */