3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 10:39:23 +01:00

nl80211: make SET_KEY/GET_KEY common

Moved AP helpers for building SET_KEY/GET_KEY commands into
nl80211_util.c
This commit is contained in:
James Prestwood 2018-10-08 13:44:10 -07:00 committed by Denis Kenzior
parent 04a9315a3c
commit 60aba7114e
3 changed files with 40 additions and 35 deletions

View File

@ -501,26 +501,6 @@ error:
ap_del_station(sta, MMPDU_REASON_CODE_UNSPECIFIED, true);
}
static struct l_genl_msg *ap_build_cmd_set_key(struct ap_state *ap)
{
uint32_t ifindex = netdev_get_ifindex(ap->netdev);
struct l_genl_msg *msg;
msg = l_genl_msg_new_sized(NL80211_CMD_SET_KEY, 128);
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_IDX, 1, &ap->gtk_index);
l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT, 0, NULL);
l_genl_msg_enter_nested(msg, NL80211_KEY_DEFAULT_TYPES);
l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST,
0, NULL);
l_genl_msg_leave_nested(msg);
l_genl_msg_leave_nested(msg);
return msg;
}
static struct l_genl_msg *ap_build_cmd_del_key(struct ap_state *ap)
{
uint32_t ifindex = netdev_get_ifindex(ap->netdev);
@ -536,19 +516,6 @@ static struct l_genl_msg *ap_build_cmd_del_key(struct ap_state *ap)
return msg;
}
static struct l_genl_msg *ap_build_cmd_get_key(struct ap_state *ap)
{
uint32_t ifindex = netdev_get_ifindex(ap->netdev);
struct l_genl_msg *msg;
msg = l_genl_msg_new_sized(NL80211_CMD_GET_KEY, 128);
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_IDX, 1, &ap->gtk_index);
return msg;
}
static struct l_genl_msg *ap_build_cmd_new_station(struct sta_state *sta)
{
struct l_genl_msg *msg;
@ -642,7 +609,8 @@ static void ap_associate_sta_cb(struct l_genl_msg *msg, void *user_data)
goto error;
}
msg = ap_build_cmd_set_key(ap);
msg = nl80211_build_set_key(netdev_get_ifindex(ap->netdev),
ap->gtk_index);
if (!l_genl_family_send(nl80211, msg, ap_gtk_op_cb, NULL,
NULL)) {
l_genl_msg_unref(msg);
@ -660,7 +628,8 @@ static void ap_associate_sta_cb(struct l_genl_msg *msg, void *user_data)
if (ap->group_cipher == IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC)
ap_start_rsna(sta, NULL);
else {
msg = ap_build_cmd_get_key(ap);
msg = nl80211_build_get_key(netdev_get_ifindex(ap->netdev),
ap->gtk_index);
sta->gtk_query_cmd_id = l_genl_family_send(nl80211, msg,
ap_gtk_query_cb,
sta, NULL);

View File

@ -101,3 +101,35 @@ struct l_genl_msg *nl80211_build_set_station_unauthorized(uint32_t ifindex,
return nl80211_build_set_station(ifindex, addr, &flags);
}
struct l_genl_msg *nl80211_build_set_key(uint32_t ifindex, uint8_t key_index)
{
struct l_genl_msg *msg;
msg = l_genl_msg_new_sized(NL80211_CMD_SET_KEY, 128);
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_IDX, 1, &key_index);
l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT, 0, NULL);
l_genl_msg_enter_nested(msg, NL80211_KEY_DEFAULT_TYPES);
l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST,
0, NULL);
l_genl_msg_leave_nested(msg);
l_genl_msg_leave_nested(msg);
return msg;
}
struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index)
{
struct l_genl_msg *msg;
msg = l_genl_msg_new_sized(NL80211_CMD_GET_KEY, 128);
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_IDX, 1, &key_index);
return msg;
}

View File

@ -35,3 +35,7 @@ struct l_genl_msg *nl80211_build_set_station_associated(uint32_t ifindex,
struct l_genl_msg *nl80211_build_set_station_unauthorized(uint32_t ifindex,
const uint8_t *addr);
struct l_genl_msg *nl80211_build_set_key(uint32_t ifindex, uint8_t key_index);
struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index);