From 1df74c53dbdf6c48088ae214c0a9cbda1b542e6d Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 6 Dec 2023 01:31:20 +0530 Subject: [PATCH 1/4] [nrf noup] zephyr: Move payload to the end fixup! [nrf noup] Monitor supplicant state and inform applications Even though the payload is of fixed size, move it to the end for easier parsing. Signed-off-by: Chaitanya Tata --- wpa_supplicant/ctrl_iface_zephyr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpa_supplicant/ctrl_iface_zephyr.h b/wpa_supplicant/ctrl_iface_zephyr.h index ab547a2cc..290474514 100644 --- a/wpa_supplicant/ctrl_iface_zephyr.h +++ b/wpa_supplicant/ctrl_iface_zephyr.h @@ -47,6 +47,6 @@ struct ctrl_iface_global_priv { }; struct conn_msg { - char msg[MAX_CTRL_MSG_LEN]; int msg_len; + char msg[MAX_CTRL_MSG_LEN]; }; From 07f15375c0922a22f46a3b01b1eeaddf4c5c4972 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 6 Dec 2023 01:33:57 +0530 Subject: [PATCH 2/4] [nrf noup] zephyr: Fix message processing fixup! [nrf noup] Monitor supplicant state and inform applications Incoming message has a pre-defined structure and isn't a arbitrary blob, so, use the structure to parse properly. This was working earlier as the payload was in the beginning of the structure, but if we ever end up with a longer message then we would see issues. Signed-off-by: Chaitanya Tata --- wpa_supplicant/wpa_cli_zephyr.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wpa_supplicant/wpa_cli_zephyr.c b/wpa_supplicant/wpa_cli_zephyr.c index 72a3b9780..b26243c14 100644 --- a/wpa_supplicant/wpa_cli_zephyr.c +++ b/wpa_supplicant/wpa_cli_zephyr.c @@ -118,13 +118,21 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl) size_t len = sizeof(buf) - 1; if (wpa_ctrl_recv(ctrl, buf, &len) == 0) { - buf[len] = '\0'; - if (strlen(buf) > 0) { + struct conn_msg *msg = (struct conn_msg *)buf; + + msg->msg[msg->msg_len] = '\0'; + wpa_printf(MSG_DEBUG, "Received len: %d, msg_len:%d - %s->END\n", + len, msg->msg_len, msg->msg); + if (msg->msg_len >= MAX_CTRL_MSG_LEN) { + wpa_printf(MSG_INFO, "Too long message received.\n"); + continue; + } + + if (msg->msg_len > 0) { /* Only interested in CTRL-EVENTs */ - if (strncmp(buf, "CTRL-EVENT", 10) == 0) { - wpa_printf(MSG_DEBUG, "Received event: %s\n", buf); + if (strncmp(msg->msg, "CTRL-EVENT", 10) == 0) { send_wifi_mgmt_event("wlan0", NET_EVENT_WPA_SUPP_CMD_INT_EVENT, - (void *)&buf[0], strlen(buf)); + msg->msg, msg->msg_len); } } } else { From 163da14252aaea6888dc6c8782536f48cd3fd92b Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 6 Dec 2023 01:36:35 +0530 Subject: [PATCH 3/4] [nrf noup] zephyr: Fix message buffer length fixup! [nrf noup] Monitor supplicant state and inform applications The incoming message is payload + length, so, need to include size of the "length" field. Fixes SHEL-2250. Signed-off-by: Chaitanya Tata --- wpa_supplicant/wpa_cli_zephyr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpa_supplicant/wpa_cli_zephyr.c b/wpa_supplicant/wpa_cli_zephyr.c index b26243c14..8771ed420 100644 --- a/wpa_supplicant/wpa_cli_zephyr.c +++ b/wpa_supplicant/wpa_cli_zephyr.c @@ -114,7 +114,7 @@ static void wpa_cli_close_connection(struct wpa_supplicant *wpa_s) static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl) { while (wpa_ctrl_pending(ctrl) > 0) { - char buf[MAX_CTRL_MSG_LEN]; + char buf[sizeof(struct conn_msg)]; size_t len = sizeof(buf) - 1; if (wpa_ctrl_recv(ctrl, buf, &len) == 0) { From fac9222d3681044be5a4c3b6669cb324490ceed1 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 6 Dec 2023 01:38:27 +0530 Subject: [PATCH 4/4] [nrf noup] zephyr: Fix receive message length fixup! [nrf noup] Monitor supplicant state and inform applications Sender is sending the entire structure, and receiving one byte lesser results in two receive calls per-message, this screws up the message parsing. Fixes SHEL-2250. Signed-off-by: Chaitanya Tata --- wpa_supplicant/wpa_cli_zephyr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpa_supplicant/wpa_cli_zephyr.c b/wpa_supplicant/wpa_cli_zephyr.c index 8771ed420..91d22178a 100644 --- a/wpa_supplicant/wpa_cli_zephyr.c +++ b/wpa_supplicant/wpa_cli_zephyr.c @@ -115,7 +115,7 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl) { while (wpa_ctrl_pending(ctrl) > 0) { char buf[sizeof(struct conn_msg)]; - size_t len = sizeof(buf) - 1; + size_t len = sizeof(buf); if (wpa_ctrl_recv(ctrl, buf, &len) == 0) { struct conn_msg *msg = (struct conn_msg *)buf;