From 99905ab4429f347a0593e86fc1dda030676adaf1 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 27 Dec 2024 19:37:30 +0530 Subject: [PATCH] P2P2: Return ID of identity block for p2p_validate_dira() Start the identity block ID from a non-zero value and return the ID on successful DIRA validation. This is used to process invitation request and handle random SSID by group owner which will be covered in separate commits. Signed-off-by: Vinay Gannevaram --- src/p2p/p2p.c | 11 ++++++----- src/p2p/p2p.h | 5 +++-- wpa_supplicant/config.c | 2 +- wpa_supplicant/config_file.c | 2 +- wpa_supplicant/p2p_supplicant.c | 14 ++++++++------ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 18c8b2eb5..74775d206 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -6041,13 +6041,14 @@ static int p2p_derive_nonce_tag(struct p2p_data *p2p) } -static void p2p_validate_dira(struct p2p_data *p2p, struct p2p_device *dev, - const u8 *dira, u16 dira_len) +static int p2p_validate_dira(struct p2p_data *p2p, struct p2p_device *dev, + const u8 *dira, u16 dira_len) { if (p2p->cfg->validate_dira) - p2p->cfg->validate_dira(p2p->cfg->cb_ctx, - dev->info.p2p_device_addr, - dira, dira_len); + return p2p->cfg->validate_dira(p2p->cfg->cb_ctx, + dev->info.p2p_device_addr, + dira, dira_len); + return 0; } diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 7724859ad..fc158db04 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1346,14 +1346,15 @@ struct p2p_config { * @peer_addr: P2P Device address of the peer * @dira: DIRA attribute present in the USD frames * @dira_len: Length of DIRA + * Returns: Identity block ID on success, 0 on failure * * This function can be used to validate DIRA and configure PMK of a * paired/persistent peer from configuration. The handler function is * expected to call p2p_pasn_pmksa_set_pmk() to set the PMK/PMKID in * case a matching entry is found. */ - void (*validate_dira)(void *ctx, const u8 *peer_addr, - const u8 *dira, size_t dira_len); + int (*validate_dira)(void *ctx, const u8 *peer_addr, + const u8 *dira, size_t dira_len); /** * pasn_send_mgmt - Function handler to transmit a Management frame diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 228b1b2c9..2413fd39e 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -5861,7 +5861,7 @@ struct wpa_dev_ik * wpa_config_add_identity(struct wpa_config *config) int id; struct wpa_dev_ik *identity, *last = NULL; - id = -1; + id = 0; identity = config->identity; while (identity) { if (identity->id > id) diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c index f0c3727dd..f96b225b8 100644 --- a/wpa_supplicant/config_file.c +++ b/wpa_supplicant/config_file.c @@ -367,7 +367,7 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp, struct wpa_config *config; static int id = 0; static int cred_id = 0; - static int identity_id = 0; + static int identity_id = 1; if (name == NULL) return NULL; diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 1d20ea3bc..0f82283d9 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -5344,8 +5344,8 @@ static void wpas_bootstrap_completed(void *ctx, const u8 *addr, } -static void wpas_validate_dira(void *ctx, const u8 *peer_addr, - const u8 *dira, size_t dira_len) +static int wpas_validate_dira(void *ctx, const u8 *peer_addr, + const u8 *dira, size_t dira_len) { struct wpa_supplicant *wpa_s = ctx; int ret; @@ -5358,14 +5358,14 @@ static void wpas_validate_dira(void *ctx, const u8 *peer_addr, if (dira_len < 1 || dira[0] != DIRA_CIPHER_VERSION_128) { wpa_printf(MSG_ERROR, "P2P2: Unsupported DIRA cipher version %d", dira[0]); - return; + return 0; } if (dira_len < 1 + DEVICE_IDENTITY_NONCE_LEN + DEVICE_IDENTITY_TAG_LEN) { wpa_printf(MSG_INFO, "P2P2: Truncated DIRA (length %zu)", dira_len); - return; + return 0; } addr[0] = (const u8 *) label; @@ -5386,7 +5386,7 @@ static void wpas_validate_dira(void *ctx, const u8 *peer_addr, if (ret < 0) { wpa_printf(MSG_ERROR, "P2P2: Failed to derive DIRA Tag"); - return; + return 0; } if (os_memcmp(tag, &dira[1 + DEVICE_IDENTITY_NONCE_LEN], @@ -5397,7 +5397,7 @@ static void wpas_validate_dira(void *ctx, const u8 *peer_addr, } if (!ik) - return; + return 0; #ifdef CONFIG_PASN p2p_pasn_pmksa_set_pmk(wpa_s->global->p2p, wpa_s->global->p2p_dev_addr, @@ -5405,6 +5405,8 @@ static void wpas_validate_dira(void *ctx, const u8 *peer_addr, wpabuf_head(ik->pmk), wpabuf_len(ik->pmk), wpabuf_head(ik->pmkid)); #endif /* CONFIG_PASN */ + + return ik->id; } -- 2.47.2