From fee68c2373f02baaf1462fedfa47623f93100b5a Mon Sep 17 00:00:00 2001 From: Vinay Gannevaram Date: Sun, 19 Jan 2025 22:52:27 +0530 Subject: [PATCH] P2P2: Control interface command to get DIRA info of a P2P device 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 --- src/p2p/p2p.c | 49 +++++++++++++++++++++++++++++++++ src/p2p/p2p.h | 1 + wpa_supplicant/ctrl_iface.c | 3 ++ wpa_supplicant/p2p_supplicant.c | 10 +++++++ wpa_supplicant/p2p_supplicant.h | 1 + 5 files changed, 64 insertions(+) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index cd3563bf5..7775aa788 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -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; +} diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 51eed59d2..066064e13 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -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 */ diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 0b29dc705..90e98ce6a 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -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[] = { diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 8d472f0d6..ee12c8a6d 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -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); diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h index 89a3bf917..32af1af03 100644 --- a/wpa_supplicant/p2p_supplicant.h +++ b/wpa_supplicant/p2p_supplicant.h @@ -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 */ -- 2.47.2