From a03839f8efa080ec13e0eca5b0c6f142984deb45 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Sat, 21 Oct 2017 01:27:20 +0200 Subject: [PATCH] netdev: Send SET STATION in pairwise key callback When the 4-Way Handshake is done eapol.c calls netdev_set_tk, then optionally netdev_set_gtk and netdev_set_igtk. To support the no group key option send the final SET STATION enabling the controlled port inside the callback for the netdev_set_tk operation which always means the end of a 4-Way Handshake rather than in the netdev_set_gtk callback. The spec says exactly that the controlled port is enabled at the end of the 4-Way Handshake. The netlink operations will still be queued in the same order because the netdev_set_tk/netdev_set_gtk/netdev_set_igtk calls happen in one main loop iteration but even if the order changed it wouldn't matter. On failure of any of the three operations netdev_setting_keys_failed gets called and the remaining operations are cancelled. --- src/netdev.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/netdev.c b/src/netdev.c index 9e6496a3..fd9d57bc 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -949,19 +949,10 @@ static void netdev_new_group_key_cb(struct l_genl_msg *msg, void *data) netdev->group_new_key_cmd_id = 0; - if (l_genl_msg_get_error(msg) < 0) { - l_error("New Key for Group Key failed for ifindex: %d", - netdev->index); - goto error; - } - - msg = netdev_build_cmd_set_station(netdev); - - if (l_genl_family_send(nl80211, msg, netdev_set_station_cb, - netdev, NULL) > 0) + if (l_genl_msg_get_error(msg) >= 0) return; -error: + l_error("New Key for Group Key failed for ifindex: %d", netdev->index); netdev_setting_keys_failed(netdev, MMPDU_REASON_CODE_UNSPECIFIED); } @@ -1125,11 +1116,21 @@ static void netdev_set_pairwise_key_cb(struct l_genl_msg *msg, void *data) netdev->pairwise_set_key_cmd_id = 0; - if (l_genl_msg_get_error(msg) >= 0) + if (l_genl_msg_get_error(msg) < 0) { + l_error("Set Key for Pairwise Key failed for ifindex: %d", + netdev->index); + goto error; + } + + if (netdev->operational) return; - l_error("Set Key for Pairwise Key failed for ifindex: %d", - netdev->index); + msg = netdev_build_cmd_set_station(netdev); + + l_genl_family_send(nl80211, msg, netdev_set_station_cb, netdev, NULL); + return; + +error: netdev_setting_keys_failed(netdev, MMPDU_REASON_CODE_UNSPECIFIED); }