diff mbox series

[2/3] hwsim: move frame processing into a separate function

Message ID 20230628202033.2320994-3-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series Handle DEL/ADD_MAC_ADDR events | expand

Commit Message

James Prestwood June 28, 2023, 8:20 p.m. UTC
The ADD/DEL_MAC_ADDR events come through the unicast handler so
move the frame processing to a separate function so these other
events can be handled.
---
 tools/hwsim.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/tools/hwsim.c b/tools/hwsim.c
index ecee0a0a..2fee9b19 100644
--- a/tools/hwsim.c
+++ b/tools/hwsim.c
@@ -1572,7 +1572,9 @@  static void process_frame(struct hwsim_frame *frame)
 	hwsim_frame_unref(frame);
 }
 
-static void unicast_handler(struct l_genl_msg *msg, void *user_data)
+
+
+static void hwsim_frame_event(struct l_genl_msg *msg)
 {
 	struct hwsim_frame *frame;
 	const struct mmpdu_header *mpdu;
@@ -1581,9 +1583,6 @@  static void unicast_handler(struct l_genl_msg *msg, void *user_data)
 	const void *data;
 	const uint8_t *transmitter = NULL, *freq = NULL, *flags = NULL;
 
-	if (l_genl_msg_get_command(msg) != HWSIM_CMD_FRAME)
-		return;
-
 	if (!l_genl_attr_init(&attr, msg))
 		return;
 
@@ -1683,6 +1682,24 @@  static void unicast_handler(struct l_genl_msg *msg, void *user_data)
 	process_frame(frame);
 }
 
+static void hwsim_unicast_handler(struct l_genl_msg *msg, void *user_data)
+{
+	uint8_t cmd;
+
+	if (l_genl_msg_get_error(msg) < 0)
+		return;
+
+	cmd = l_genl_msg_get_command(msg);
+
+	switch (cmd) {
+	case HWSIM_CMD_FRAME:
+		hwsim_frame_event(msg);
+		break;
+	default:
+		break;
+	}
+}
+
 static void radio_manager_create_callback(struct l_genl_msg *msg,
 						void *user_data)
 {
@@ -2939,8 +2956,9 @@  static void hwsim_ready(void)
 		}
 
 		if (!l_genl_add_unicast_watch(genl, "MAC80211_HWSIM",
-						unicast_handler, NULL, NULL)) {
-			l_error("Failed to set unicast handler");
+						hwsim_unicast_handler,
+						NULL, NULL)) {
+			l_error("Failed to set hwsim unicast handler");
 			goto error;
 		}