mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 23:09:34 +01:00
netdev: fixed key setting failure
If netdev fails to set the keys, there was no way for device/ap to know. A new handshake event was added for this. The key setting failure function was also fixed to support both AP/station iftypes. It will now automatically send either a disconnect or del_station depending on the interface type. In similar manner, netdev_handshake_failed was also modified to support both AP/station iftypes. Now, any handshake event listeners should call netdev_handshake_failed upon a handshake failure event, including AP.
This commit is contained in:
parent
d4e521027b
commit
b2f27f3abe
16
src/ap.c
16
src/ap.c
@ -151,6 +151,16 @@ static bool ap_sta_match_addr(const void *a, const void *b)
|
|||||||
return !memcmp(sta->addr, b, 6);
|
return !memcmp(sta->addr, b, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ap_remove_sta(struct sta_state *sta)
|
||||||
|
{
|
||||||
|
if (!l_queue_remove(sta->ap->sta_states, sta)) {
|
||||||
|
l_error("tried to remove station that doesnt exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ap_sta_free(sta);
|
||||||
|
}
|
||||||
|
|
||||||
static void ap_set_sta_cb(struct l_genl_msg *msg, void *user_data)
|
static void ap_set_sta_cb(struct l_genl_msg *msg, void *user_data)
|
||||||
{
|
{
|
||||||
if (l_genl_msg_get_error(msg) < 0)
|
if (l_genl_msg_get_error(msg) < 0)
|
||||||
@ -398,8 +408,10 @@ static void ap_handshake_event(struct handshake_state *hs,
|
|||||||
ap_new_rsna(sta);
|
ap_new_rsna(sta);
|
||||||
break;
|
break;
|
||||||
case HANDSHAKE_EVENT_FAILED:
|
case HANDSHAKE_EVENT_FAILED:
|
||||||
ap_deauthenticate_sta(sta, l_get_u16(event_data));
|
netdev_handshake_failed(hs, l_get_u16(event_data));
|
||||||
break;
|
/* fall through */
|
||||||
|
case HANDSHAKE_EVENT_SETTING_KEYS_FAILED:
|
||||||
|
ap_remove_sta(sta);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -670,9 +670,9 @@ static void device_handshake_event(struct handshake_state *hs,
|
|||||||
network_sync_psk(network);
|
network_sync_psk(network);
|
||||||
break;
|
break;
|
||||||
case HANDSHAKE_EVENT_FAILED:
|
case HANDSHAKE_EVENT_FAILED:
|
||||||
netdev_handshake_failed(device_get_netdev(device),
|
netdev_handshake_failed(hs, l_get_u16(event_data));
|
||||||
l_get_u16(event_data));
|
|
||||||
break;
|
break;
|
||||||
|
case HANDSHAKE_EVENT_SETTING_KEYS_FAILED:
|
||||||
case HANDSHAKE_EVENT_COMPLETE:
|
case HANDSHAKE_EVENT_COMPLETE:
|
||||||
/*
|
/*
|
||||||
* currently we dont care about any other events. The
|
* currently we dont care about any other events. The
|
||||||
|
@ -45,6 +45,7 @@ enum handshake_kde {
|
|||||||
enum handshake_event {
|
enum handshake_event {
|
||||||
HANDSHAKE_EVENT_STARTED,
|
HANDSHAKE_EVENT_STARTED,
|
||||||
HANDSHAKE_EVENT_SETTING_KEYS,
|
HANDSHAKE_EVENT_SETTING_KEYS,
|
||||||
|
HANDSHAKE_EVENT_SETTING_KEYS_FAILED,
|
||||||
HANDSHAKE_EVENT_COMPLETE,
|
HANDSHAKE_EVENT_COMPLETE,
|
||||||
HANDSHAKE_EVENT_FAILED
|
HANDSHAKE_EVENT_FAILED
|
||||||
};
|
};
|
||||||
|
61
src/netdev.c
61
src/netdev.c
@ -893,6 +893,25 @@ static struct l_genl_msg *netdev_build_cmd_deauthenticate(struct netdev *netdev,
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct l_genl_msg *netdev_build_cmd_del_station(struct netdev *netdev,
|
||||||
|
const uint8_t *sta,
|
||||||
|
uint16_t reason_code,
|
||||||
|
bool disassociate)
|
||||||
|
{
|
||||||
|
struct l_genl_msg *msg;
|
||||||
|
uint8_t subtype = disassociate ?
|
||||||
|
MPDU_MANAGEMENT_SUBTYPE_DISASSOCIATION :
|
||||||
|
MPDU_MANAGEMENT_SUBTYPE_DEAUTHENTICATION;
|
||||||
|
|
||||||
|
msg = l_genl_msg_new_sized(NL80211_CMD_DEL_STATION, 64);
|
||||||
|
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
||||||
|
l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, 6, sta);
|
||||||
|
l_genl_msg_append_attr(msg, NL80211_ATTR_MGMT_SUBTYPE, 1, &subtype);
|
||||||
|
l_genl_msg_append_attr(msg, NL80211_ATTR_REASON_CODE, 2, &reason_code);
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
static void netdev_operstate_cb(bool success, void *user_data)
|
static void netdev_operstate_cb(bool success, void *user_data)
|
||||||
{
|
{
|
||||||
struct netdev *netdev = user_data;
|
struct netdev *netdev = user_data;
|
||||||
@ -945,14 +964,21 @@ static void netdev_setting_keys_failed(struct netdev_handshake_state *nhs,
|
|||||||
|
|
||||||
netdev->result = NETDEV_RESULT_KEY_SETTING_FAILED;
|
netdev->result = NETDEV_RESULT_KEY_SETTING_FAILED;
|
||||||
|
|
||||||
if (netdev->type != NL80211_IFTYPE_STATION)
|
handshake_event(&nhs->super, HANDSHAKE_EVENT_SETTING_KEYS_FAILED, NULL);
|
||||||
return;
|
|
||||||
|
|
||||||
msg = netdev_build_cmd_disconnect(netdev,
|
switch (netdev->type) {
|
||||||
MMPDU_REASON_CODE_UNSPECIFIED);
|
case NL80211_IFTYPE_STATION:
|
||||||
netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
|
msg = netdev_build_cmd_disconnect(netdev, reason_code);
|
||||||
|
netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
|
||||||
netdev_connect_failed,
|
netdev_connect_failed,
|
||||||
netdev, NULL);
|
netdev, NULL);
|
||||||
|
break;
|
||||||
|
case NL80211_IFTYPE_AP:
|
||||||
|
msg = netdev_build_cmd_del_station(netdev, nhs->super.spa,
|
||||||
|
reason_code, false);
|
||||||
|
if (!l_genl_family_send(nl80211, msg, NULL, NULL, NULL))
|
||||||
|
l_error("error sending DEL_STATION");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void netdev_set_station_cb(struct l_genl_msg *msg, void *user_data)
|
static void netdev_set_station_cb(struct l_genl_msg *msg, void *user_data)
|
||||||
@ -1277,8 +1303,11 @@ invalid_key:
|
|||||||
netdev_setting_keys_failed(nhs, rc);
|
netdev_setting_keys_failed(nhs, rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void netdev_handshake_failed(struct netdev *netdev, uint16_t reason_code)
|
void netdev_handshake_failed(struct handshake_state *hs, uint16_t reason_code)
|
||||||
{
|
{
|
||||||
|
struct netdev_handshake_state *nhs =
|
||||||
|
container_of(hs, struct netdev_handshake_state, super);
|
||||||
|
struct netdev *netdev = nhs->netdev;
|
||||||
struct l_genl_msg *msg;
|
struct l_genl_msg *msg;
|
||||||
|
|
||||||
l_error("4-Way handshake failed for ifindex: %d, reason: %u",
|
l_error("4-Way handshake failed for ifindex: %d, reason: %u",
|
||||||
@ -1288,13 +1317,19 @@ void netdev_handshake_failed(struct netdev *netdev, uint16_t reason_code)
|
|||||||
|
|
||||||
netdev->result = NETDEV_RESULT_HANDSHAKE_FAILED;
|
netdev->result = NETDEV_RESULT_HANDSHAKE_FAILED;
|
||||||
|
|
||||||
if (netdev->type != NL80211_IFTYPE_STATION)
|
switch (netdev->type) {
|
||||||
return;
|
case NL80211_IFTYPE_STATION:
|
||||||
|
msg = netdev_build_cmd_disconnect(netdev, reason_code);
|
||||||
msg = netdev_build_cmd_disconnect(netdev, reason_code);
|
netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
|
||||||
netdev->disconnect_cmd_id = l_genl_family_send(nl80211, msg,
|
netdev_connect_failed,
|
||||||
netdev_connect_failed,
|
netdev, NULL);
|
||||||
netdev, NULL);
|
break;
|
||||||
|
case NL80211_IFTYPE_AP:
|
||||||
|
msg = netdev_build_cmd_del_station(netdev, nhs->super.spa,
|
||||||
|
reason_code, false);
|
||||||
|
if (!l_genl_family_send(nl80211, msg, NULL, NULL, NULL))
|
||||||
|
l_error("error sending DEL_STATION");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hardware_rekey_cb(struct l_genl_msg *msg, void *data)
|
static void hardware_rekey_cb(struct l_genl_msg *msg, void *data)
|
||||||
|
@ -145,7 +145,7 @@ uint32_t netdev_frame_watch_add(struct netdev *netdev, uint16_t frame_type,
|
|||||||
void *user_data);
|
void *user_data);
|
||||||
bool netdev_frame_watch_remove(struct netdev *netdev, uint32_t id);
|
bool netdev_frame_watch_remove(struct netdev *netdev, uint32_t id);
|
||||||
|
|
||||||
void netdev_handshake_failed(struct netdev *netdev, uint16_t reason_code);
|
void netdev_handshake_failed(struct handshake_state *hs, uint16_t reason_code);
|
||||||
|
|
||||||
struct netdev *netdev_find(int ifindex);
|
struct netdev *netdev_find(int ifindex);
|
||||||
|
|
||||||
|
@ -387,12 +387,9 @@ static void wsc_netdev_event(struct netdev *netdev, enum netdev_event event,
|
|||||||
static void wsc_handshake_event(struct handshake_state *hs,
|
static void wsc_handshake_event(struct handshake_state *hs,
|
||||||
enum handshake_event event, void *event_data, void *user_data)
|
enum handshake_event event, void *event_data, void *user_data)
|
||||||
{
|
{
|
||||||
struct wsc *wsc = user_data;
|
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case HANDSHAKE_EVENT_FAILED:
|
case HANDSHAKE_EVENT_FAILED:
|
||||||
netdev_handshake_failed(device_get_netdev(wsc->device),
|
netdev_handshake_failed(hs, l_get_u16(event_data));
|
||||||
l_get_u16(event_data));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user