From b3bd49f3c0e3335b96c7c3f8f65e8dbe867fbf28 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 14 Sep 2024 12:54:04 +0300 Subject: [PATCH] NAN: Handle A3 copying internally to simplify control interface There is no need to copy the A3 value for follow-up frames through the control interface events and commands since it can be handled internally in the service with sufficient accuracy. More parallel operations with multiple peers might need per-peer information, but that can be extended in the future, if that level of complexity is really needed in practice. Signed-off-by: Jouni Malinen --- hostapd/ctrl_iface.c | 13 ++----------- src/ap/nan_usd_ap.c | 11 +++++------ src/ap/nan_usd_ap.h | 3 +-- src/common/nan_de.c | 16 ++++++++++++---- src/common/nan_de.h | 4 ++-- wpa_supplicant/ctrl_iface.c | 13 ++----------- wpa_supplicant/nan_usd.c | 8 ++++---- wpa_supplicant/nan_usd.h | 3 +-- wpa_supplicant/notify.c | 6 ++---- wpa_supplicant/notify.h | 1 - 10 files changed, 31 insertions(+), 47 deletions(-) diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index d5a906691..1fcefb355 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -3976,12 +3976,10 @@ static int hostapd_ctrl_nan_transmit(struct hostapd_data *hapd, char *cmd) int handle = 0; int req_instance_id = 0; struct wpabuf *ssi = NULL; - u8 peer_addr[ETH_ALEN], a3[ETH_ALEN]; + u8 peer_addr[ETH_ALEN]; int ret = -1; - bool a3_set = false; os_memset(peer_addr, 0, ETH_ALEN); - os_memset(a3, 0, ETH_ALEN); while ((token = str_token(cmd, " ", &context))) { if (sscanf(token, "handle=%i", &handle) == 1) @@ -3996,13 +3994,6 @@ static int hostapd_ctrl_nan_transmit(struct hostapd_data *hapd, char *cmd) continue; } - if (os_strncmp(token, "a3=", 3) == 0) { - if (hwaddr_aton(token + 3, a3) < 0) - return -1; - a3_set = true; - continue; - } - if (os_strncmp(token, "ssi=", 4) == 0) { if (ssi) goto fail; @@ -4031,7 +4022,7 @@ static int hostapd_ctrl_nan_transmit(struct hostapd_data *hapd, char *cmd) } ret = hostapd_nan_usd_transmit(hapd, handle, ssi, NULL, peer_addr, - a3_set ? a3 : NULL, req_instance_id); + req_instance_id); fail: wpabuf_free(ssi); return ret; diff --git a/src/ap/nan_usd_ap.c b/src/ap/nan_usd_ap.c index c908d6da8..56ef6a4d8 100644 --- a/src/ap/nan_usd_ap.c +++ b/src/ap/nan_usd_ap.c @@ -129,7 +129,7 @@ static void hostapd_nan_de_subscribe_terminated(void *ctx, int subscribe_id, static void hostapd_nan_de_receive(void *ctx, int id, int peer_instance_id, const u8 *ssi, size_t ssi_len, - const u8 *peer_addr, const u8 *a3) + const u8 *peer_addr) { struct hostapd_data *hapd = ctx; char *ssi_hex; @@ -140,9 +140,8 @@ static void hostapd_nan_de_receive(void *ctx, int id, int peer_instance_id, if (ssi) wpa_snprintf_hex(ssi_hex, 2 * ssi_len + 1, ssi, ssi_len); wpa_msg(hapd->msg_ctx, MSG_INFO, NAN_RECEIVE - "id=%d peer_instance_id=%d address=" MACSTR " a3=" MACSTR - " ssi=%s", - id, peer_instance_id, MAC2STR(peer_addr), MAC2STR(a3), ssi_hex); + "id=%d peer_instance_id=%d address=" MACSTR " ssi=%s", + id, peer_instance_id, MAC2STR(peer_addr), ssi_hex); os_free(ssi_hex); } @@ -262,11 +261,11 @@ void hostapd_nan_usd_cancel_subscribe(struct hostapd_data *hapd, int hostapd_nan_usd_transmit(struct hostapd_data *hapd, int handle, const struct wpabuf *ssi, const struct wpabuf *elems, - const u8 *peer_addr, const u8 *a3, + const u8 *peer_addr, u8 req_instance_id) { if (!hapd->nan_de) return -1; - return nan_de_transmit(hapd->nan_de, handle, ssi, elems, peer_addr, a3, + return nan_de_transmit(hapd->nan_de, handle, ssi, elems, peer_addr, req_instance_id); } diff --git a/src/ap/nan_usd_ap.h b/src/ap/nan_usd_ap.h index 59a164aa5..b7e8b76ce 100644 --- a/src/ap/nan_usd_ap.h +++ b/src/ap/nan_usd_ap.h @@ -36,8 +36,7 @@ void hostapd_nan_usd_cancel_subscribe(struct hostapd_data *hapd, int hostapd_nan_usd_transmit(struct hostapd_data *hapd, int handle, const struct wpabuf *ssi, const struct wpabuf *elems, - const u8 *peer_addr, const u8 *a3, - u8 req_instance_id); + const u8 *peer_addr, u8 req_instance_id); void hostapd_nan_usd_remain_on_channel_cb(struct hostapd_data *hapd, unsigned int freq, unsigned int duration); diff --git a/src/common/nan_de.c b/src/common/nan_de.c index 7f2a79680..fb6f84d2a 100644 --- a/src/common/nan_de.c +++ b/src/common/nan_de.c @@ -43,6 +43,8 @@ struct nan_de_service { unsigned int freq; unsigned int default_freq; int *freq_list; + u8 a3[ETH_ALEN]; + bool a3_set; /* pauseState information for Publish function */ struct os_reltime pause_state_end; @@ -829,7 +831,7 @@ static void nan_de_rx_publish(struct nan_de *de, struct nan_de_service *srv, /* Passive subscriber replies with a Follow-up message without * Service Specific Info field if it received a matching * unsolicited Publish message. */ - nan_de_transmit(de, srv->id, NULL, NULL, peer_addr, a3, + nan_de_transmit(de, srv->id, NULL, NULL, peer_addr, instance_id); } @@ -1004,9 +1006,12 @@ static void nan_de_rx_follow_up(struct nan_de *de, struct nan_de_service *srv, if (srv->type == NAN_DE_PUBLISH && !ssi) nan_de_pause_state(srv, peer_addr, instance_id); + os_memcpy(srv->a3, a3, ETH_ALEN); + srv->a3_set = true; + if (de->cb.receive) de->cb.receive(de->cb.ctx, srv->id, instance_id, ssi, ssi_len, - peer_addr, a3); + peer_addr); } @@ -1441,9 +1446,10 @@ void nan_de_cancel_subscribe(struct nan_de *de, int subscribe_id) int nan_de_transmit(struct nan_de *de, int handle, const struct wpabuf *ssi, const struct wpabuf *elems, - const u8 *peer_addr, const u8 *a3, u8 req_instance_id) + const u8 *peer_addr, u8 req_instance_id) { struct nan_de_service *srv; + const u8 *a3; if (handle < 1 || handle > NAN_DE_MAX_SERVICE) return -1; @@ -1452,7 +1458,9 @@ int nan_de_transmit(struct nan_de *de, int handle, if (!srv) return -1; - if (!a3) + if (srv->a3_set) + a3 = srv->a3; + else a3 = nan_network_id; nan_de_tx_sdf(de, srv, 100, NAN_SRV_CTRL_FOLLOW_UP, peer_addr, a3, req_instance_id, ssi); diff --git a/src/common/nan_de.h b/src/common/nan_de.h index 5d803ef59..3f9670a47 100644 --- a/src/common/nan_de.h +++ b/src/common/nan_de.h @@ -52,7 +52,7 @@ struct nan_callbacks { void (*receive)(void *ctx, int id, int peer_instance_id, const u8 *ssi, size_t ssi_len, - const u8 *peer_addr, const u8 *a3); + const u8 *peer_addr); void (*process_p2p_usd_elems)(void *ctx, const u8 *buf, u16 buf_len, const u8 *peer_addr, @@ -149,6 +149,6 @@ void nan_de_cancel_subscribe(struct nan_de *de, int subscribe_id); * req_instance_id = peer publish_id or subscribe_id */ int nan_de_transmit(struct nan_de *de, int handle, const struct wpabuf *ssi, const struct wpabuf *elems, - const u8 *peer_addr, const u8 *a3, u8 req_instance_id); + const u8 *peer_addr, u8 req_instance_id); #endif /* NAN_DE_H */ diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 4b49b72cd..6dba46898 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -12514,12 +12514,10 @@ static int wpas_ctrl_nan_transmit(struct wpa_supplicant *wpa_s, char *cmd) int handle = 0; int req_instance_id = 0; struct wpabuf *ssi = NULL; - u8 peer_addr[ETH_ALEN], a3[ETH_ALEN]; + u8 peer_addr[ETH_ALEN]; int ret = -1; - bool a3_set = false; os_memset(peer_addr, 0, ETH_ALEN); - os_memset(a3, 0, ETH_ALEN); while ((token = str_token(cmd, " ", &context))) { if (sscanf(token, "handle=%i", &handle) == 1) @@ -12534,13 +12532,6 @@ static int wpas_ctrl_nan_transmit(struct wpa_supplicant *wpa_s, char *cmd) continue; } - if (os_strncmp(token, "a3=", 3) == 0) { - if (hwaddr_aton(token + 3, a3) < 0) - return -1; - a3_set = true; - continue; - } - if (os_strncmp(token, "ssi=", 4) == 0) { if (ssi) goto fail; @@ -12569,7 +12560,7 @@ static int wpas_ctrl_nan_transmit(struct wpa_supplicant *wpa_s, char *cmd) } ret = wpas_nan_usd_transmit(wpa_s, handle, ssi, NULL, peer_addr, - a3_set ? a3 : NULL, req_instance_id); + req_instance_id); fail: wpabuf_free(ssi); return ret; diff --git a/wpa_supplicant/nan_usd.c b/wpa_supplicant/nan_usd.c index 7faa2e508..ae152356d 100644 --- a/wpa_supplicant/nan_usd.c +++ b/wpa_supplicant/nan_usd.c @@ -282,11 +282,11 @@ static void wpas_nan_de_subscribe_terminated(void *ctx, int subscribe_id, static void wpas_nan_de_receive(void *ctx, int id, int peer_instance_id, const u8 *ssi, size_t ssi_len, - const u8 *peer_addr, const u8 *a3) + const u8 *peer_addr) { struct wpa_supplicant *wpa_s = ctx; - wpas_notify_nan_receive(wpa_s, id, peer_instance_id, peer_addr, a3, + wpas_notify_nan_receive(wpa_s, id, peer_instance_id, peer_addr, ssi, ssi_len); } @@ -467,11 +467,11 @@ void wpas_nan_usd_cancel_subscribe(struct wpa_supplicant *wpa_s, int wpas_nan_usd_transmit(struct wpa_supplicant *wpa_s, int handle, const struct wpabuf *ssi, const struct wpabuf *elems, - const u8 *peer_addr, const u8 *a3, u8 req_instance_id) + const u8 *peer_addr, u8 req_instance_id) { if (!wpa_s->nan_de) return -1; - return nan_de_transmit(wpa_s->nan_de, handle, ssi, elems, peer_addr, a3, + return nan_de_transmit(wpa_s->nan_de, handle, ssi, elems, peer_addr, req_instance_id); } diff --git a/wpa_supplicant/nan_usd.h b/wpa_supplicant/nan_usd.h index 7ff7eaa50..59c09896a 100644 --- a/wpa_supplicant/nan_usd.h +++ b/wpa_supplicant/nan_usd.h @@ -35,8 +35,7 @@ void wpas_nan_usd_cancel_subscribe(struct wpa_supplicant *wpa_s, int subscribe_id); int wpas_nan_usd_transmit(struct wpa_supplicant *wpa_s, int handle, const struct wpabuf *ssi, const struct wpabuf *elems, - const u8 *peer_addr, const u8 *a3, - u8 req_instance_id); + const u8 *peer_addr, u8 req_instance_id); void wpas_nan_usd_remain_on_channel_cb(struct wpa_supplicant *wpa_s, unsigned int freq, unsigned int duration); diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c index cdde7fd6c..8c1a817f9 100644 --- a/wpa_supplicant/notify.c +++ b/wpa_supplicant/notify.c @@ -1121,7 +1121,6 @@ void wpas_notify_nan_replied(struct wpa_supplicant *wpa_s, void wpas_notify_nan_receive(struct wpa_supplicant *wpa_s, int id, int peer_instance_id, const u8 *peer_addr, - const u8 *a3, const u8 *ssi, size_t ssi_len) { char *ssi_hex; @@ -1132,9 +1131,8 @@ void wpas_notify_nan_receive(struct wpa_supplicant *wpa_s, int id, if (ssi) wpa_snprintf_hex(ssi_hex, 2 * ssi_len + 1, ssi, ssi_len); wpa_msg(wpa_s, MSG_INFO, NAN_RECEIVE - "id=%d peer_instance_id=%d address=" MACSTR " a3=" MACSTR - " ssi=%s", - id, peer_instance_id, MAC2STR(peer_addr), MAC2STR(a3), ssi_hex); + "id=%d peer_instance_id=%d address=" MACSTR " ssi=%s", + id, peer_instance_id, MAC2STR(peer_addr), ssi_hex); os_free(ssi_hex); } diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h index 728952bfa..56fe7c58e 100644 --- a/wpa_supplicant/notify.h +++ b/wpa_supplicant/notify.h @@ -192,7 +192,6 @@ void wpas_notify_nan_replied(struct wpa_supplicant *wpa_s, const u8 *ssi, size_t ssi_len); void wpas_notify_nan_receive(struct wpa_supplicant *wpa_s, int id, int peer_instance_id, const u8 *peer_addr, - const u8 *a3, const u8 *ssi, size_t ssi_len); void wpas_notify_nan_publish_terminated(struct wpa_supplicant *wpa_s, int publish_id,