]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
NAN: Handle A3 copying internally to simplify control interface
authorJouni Malinen <quic_jouni@quicinc.com>
Sat, 14 Sep 2024 09:54:04 +0000 (12:54 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 14 Sep 2024 10:06:03 +0000 (13:06 +0300)
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 <quic_jouni@quicinc.com>
hostapd/ctrl_iface.c
src/ap/nan_usd_ap.c
src/ap/nan_usd_ap.h
src/common/nan_de.c
src/common/nan_de.h
wpa_supplicant/ctrl_iface.c
wpa_supplicant/nan_usd.c
wpa_supplicant/nan_usd.h
wpa_supplicant/notify.c
wpa_supplicant/notify.h

index d5a906691c7eef24c6dd793f839f6e1488be25de..1fcefb3550b663cad107f060cb8a018db41edca5 100644 (file)
@@ -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;
index c908d6da8661937f38e4bcbd60e13b306ae5aee0..56ef6a4d8ff7e932c6f7603f1240a04730f200ea 100644 (file)
@@ -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);
 }
index 59a164aa596c95f69a4282bf6731b1e468641322..b7e8b76ce24ea8327ba65f4fd8fe2527e47774ad 100644 (file)
@@ -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);
index 7f2a796801e9a34b1e6e0f87bcca425be44c67eb..fb6f84d2a8c03d47f1c49345de61ab52e87a8ad6 100644 (file)
@@ -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);
index 5d803ef59e30e66d5ed75c34c1286889331788c8..3f9670a47881ed5a0578a9be830880b96401fa57 100644 (file)
@@ -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 */
index 4b49b72cd04f8f6fbf39f6455a68967219966901..6dba46898d505f04e232f8eadf790235d907622b 100644 (file)
@@ -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;
index 7faa2e508a886d0cc6b68ddfc4f180f6eebae67d..ae152356d2224462ff312419d27a648eb9a54453 100644 (file)
@@ -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);
 }
 
index 7ff7eaa5018ace2f2eeab28ff96744229cc21508..59c09896a08f598e0d0bbe9302e43ca50d2d500d 100644 (file)
@@ -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);
index cdde7fd6ca498bd91be95f758643b5ae4a94ccc7..8c1a817f9f899b447ac82c272c1e20fb2fc891eb 100644 (file)
@@ -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);
 }
 
index 728952bfac9e59b3c2d2c24b5acd58bc03486335..56fe7c58e2fd90d114e0fb4af20082be711d058a 100644 (file)
@@ -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,