aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2023-11-14 10:03:58 -0600
committerDenis Kenzior <denkenz@gmail.com>2023-11-14 10:03:58 -0600
commit05c1d34c6ebf7c35df72e202e10e50c76aa6e83a (patch)
tree101072b5fcd45874c523c74f6217ecded649f1b7
parent708a8feaba60b09e1d989ed874104267b5c43be3 (diff)
netdev: Move CMD_NEW_KEY RX-only builder to nl80211util
-rw-r--r--src/netdev.c36
-rw-r--r--src/nl80211util.c29
-rw-r--r--src/nl80211util.h6
3 files changed, 38 insertions, 33 deletions
diff --git a/src/netdev.c b/src/netdev.c
index 64d16d6dc..086c3b9d1 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -1898,36 +1898,6 @@ error:
netdev_setting_keys_failed(nhs, err);
}
-static struct l_genl_msg *netdev_build_cmd_new_rx_key_pairwise(
- struct netdev *netdev,
- uint32_t cipher,
- const uint8_t *aa,
- const uint8_t *tk,
- size_t tk_len,
- uint8_t key_id)
-{
- uint8_t key_mode = NL80211_KEY_NO_TX;
- uint32_t key_type = NL80211_KEYTYPE_PAIRWISE;
- struct l_genl_msg *msg;
-
- msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512);
-
- l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, aa);
- l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
-
- l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY);
-
- l_genl_msg_append_attr(msg, NL80211_KEY_DATA, tk_len, tk);
- l_genl_msg_append_attr(msg, NL80211_KEY_CIPHER, 4, &cipher);
- l_genl_msg_append_attr(msg, NL80211_KEY_IDX, 1, &key_id);
- l_genl_msg_append_attr(msg, NL80211_KEY_MODE, 1, &key_mode);
- l_genl_msg_append_attr(msg, NL80211_KEY_TYPE, 4, &key_type);
-
- l_genl_msg_leave_nested(msg);
-
- return msg;
-}
-
static void netdev_group_timeout_cb(struct l_timeout *timeout, void *user_data)
{
struct netdev_handshake_state *nhs = user_data;
@@ -2037,9 +2007,9 @@ static void netdev_set_ext_tk(struct handshake_state *hs, uint8_t key_idx,
if (!netdev_copy_tk(tk_buf, tk, cipher, hs->authenticator))
goto error;
- msg = netdev_build_cmd_new_rx_key_pairwise(netdev, cipher, addr, tk_buf,
- crypto_cipher_key_len(cipher),
- hs->active_tk_index);
+ msg = nl80211_build_new_rx_key_pairwise(netdev->index, cipher, addr,
+ tk_buf, crypto_cipher_key_len(cipher),
+ hs->active_tk_index);
nhs->pairwise_new_key_cmd_id =
l_genl_family_send(nl80211, msg, netdev_new_rx_pairwise_key_cb,
nhs, NULL);
diff --git a/src/nl80211util.c b/src/nl80211util.c
index 437a52d55..87e859c96 100644
--- a/src/nl80211util.c
+++ b/src/nl80211util.c
@@ -379,6 +379,35 @@ struct l_genl_msg *nl80211_build_new_key_pairwise(uint32_t ifindex,
return msg;
}
+struct l_genl_msg *nl80211_build_new_rx_key_pairwise(uint32_t ifindex,
+ uint32_t cipher,
+ const uint8_t addr[static 6],
+ const uint8_t *tk,
+ size_t tk_len,
+ uint8_t key_id)
+{
+ uint8_t key_mode = NL80211_KEY_NO_TX;
+ uint32_t key_type = NL80211_KEYTYPE_PAIRWISE;
+ struct l_genl_msg *msg;
+
+ msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512);
+
+ l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
+ l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
+
+ l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY);
+
+ l_genl_msg_append_attr(msg, NL80211_KEY_DATA, tk_len, tk);
+ l_genl_msg_append_attr(msg, NL80211_KEY_CIPHER, 4, &cipher);
+ l_genl_msg_append_attr(msg, NL80211_KEY_IDX, 1, &key_id);
+ l_genl_msg_append_attr(msg, NL80211_KEY_MODE, 1, &key_mode);
+ l_genl_msg_append_attr(msg, NL80211_KEY_TYPE, 4, &key_type);
+
+ l_genl_msg_leave_nested(msg);
+
+ return msg;
+}
+
static struct l_genl_msg *nl80211_build_set_station(uint32_t ifindex,
const uint8_t *addr,
struct nl80211_sta_flag_update *flags)
diff --git a/src/nl80211util.h b/src/nl80211util.h
index 00d1ea852..d8026a8eb 100644
--- a/src/nl80211util.h
+++ b/src/nl80211util.h
@@ -50,6 +50,12 @@ struct l_genl_msg *nl80211_build_new_key_pairwise(uint32_t ifindex,
const uint8_t *tk,
size_t tk_len,
uint8_t key_id);
+struct l_genl_msg *nl80211_build_new_rx_key_pairwise(uint32_t ifindex,
+ uint32_t cipher,
+ const uint8_t addr[static 6],
+ const uint8_t *tk,
+ size_t tk_len,
+ uint8_t key_id);
struct l_genl_msg *nl80211_build_set_station_authorized(uint32_t ifindex,
const uint8_t *addr);