diff mbox series

[06/11] netdev: Move CMD_DEAUTHENTICATE builder to nl80211util

Message ID 20231114171455.1108856-6-denkenz@gmail.com (mailing list archive)
State New
Headers show
Series [01/11] netdev: Fix obtaining reason code from deauth frames | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

Denis Kenzior Nov. 14, 2023, 5:14 p.m. UTC
---
 src/netdev.c      | 20 ++++----------------
 src/nl80211util.c | 14 ++++++++++++++
 src/nl80211util.h |  3 +++
 3 files changed, 21 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/src/netdev.c b/src/netdev.c
index 1f6920028a03..6c35cd1b75e7 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -1298,20 +1298,6 @@  static void netdev_deauthenticate_event(struct l_genl_msg *msg,
 					MMPDU_STATUS_CODE_UNSPECIFIED);
 }
 
-static struct l_genl_msg *netdev_build_cmd_deauthenticate(struct netdev *netdev,
-							uint16_t reason_code)
-{
-	struct l_genl_msg *msg;
-
-	msg = l_genl_msg_new_sized(NL80211_CMD_DEAUTHENTICATE, 128);
-	l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
-	l_genl_msg_append_attr(msg, NL80211_ATTR_REASON_CODE, 2, &reason_code);
-	l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN,
-							netdev->handshake->aa);
-
-	return msg;
-}
-
 static struct l_genl_msg *netdev_build_cmd_del_station(struct netdev *netdev,
 							const uint8_t *sta,
 							uint16_t reason_code,
@@ -3028,7 +3014,8 @@  static void netdev_cmd_ft_reassociate_cb(struct l_genl_msg *msg,
 
 		netdev->result = NETDEV_RESULT_ASSOCIATION_FAILED;
 		netdev->last_code = MMPDU_STATUS_CODE_UNSPECIFIED;
-		cmd_deauth = netdev_build_cmd_deauthenticate(netdev,
+		cmd_deauth = nl80211_build_deauthenticate(netdev->index,
+						netdev->handshake->aa,
 						MMPDU_REASON_CODE_UNSPECIFIED);
 		netdev->disconnect_cmd_id = l_genl_family_send(nl80211,
 							cmd_deauth,
@@ -3163,7 +3150,8 @@  static void netdev_authenticate_event(struct l_genl_msg *msg,
 
 			netdev->result = NETDEV_RESULT_ASSOCIATION_FAILED;
 			netdev->last_code = MMPDU_STATUS_CODE_UNSPECIFIED;
-			cmd_deauth = netdev_build_cmd_deauthenticate(netdev,
+			cmd_deauth = nl80211_build_deauthenticate(netdev->index,
+						netdev->handshake->aa,
 						MMPDU_REASON_CODE_UNSPECIFIED);
 			netdev->disconnect_cmd_id = l_genl_family_send(nl80211,
 							cmd_deauth,
diff --git a/src/nl80211util.c b/src/nl80211util.c
index 44a8ebe50300..8ed260ad6f13 100644
--- a/src/nl80211util.c
+++ b/src/nl80211util.c
@@ -284,6 +284,20 @@  done:
 	return ret;
 }
 
+struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex,
+						const uint8_t addr[static 6],
+						uint16_t reason_code)
+{
+	struct l_genl_msg *msg;
+
+	msg = l_genl_msg_new_sized(NL80211_CMD_DEAUTHENTICATE, 128);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_REASON_CODE, 2, &reason_code);
+	l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
+
+	return msg;
+}
+
 struct l_genl_msg *nl80211_build_disconnect(uint32_t ifindex,
 							uint16_t reason_code)
 {
diff --git a/src/nl80211util.h b/src/nl80211util.h
index 9eb8681900b8..1553047d1b8a 100644
--- a/src/nl80211util.h
+++ b/src/nl80211util.h
@@ -28,6 +28,9 @@  struct band_freq_attrs;
 
 int nl80211_parse_attrs(struct l_genl_msg *msg, int tag, ...);
 
+struct l_genl_msg *nl80211_build_deauthenticate(uint32_t ifindex,
+						const uint8_t addr[static 6],
+						uint16_t reason_code);
 struct l_genl_msg *nl80211_build_disconnect(uint32_t ifindex,
 							uint16_t reason_code);