From 0eeb71e4ebe670d82b87cf44af5a6a9ca21e1681 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 16 Jun 2016 11:06:17 -0500 Subject: [PATCH] netdev: Move CQM event handling out of wiphy.c --- src/device.c | 15 ++++++++++++++- src/netdev.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/wiphy.c | 43 ------------------------------------------- 3 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/device.c b/src/device.c index 23c8a703..53e85171 100644 --- a/src/device.c +++ b/src/device.c @@ -181,6 +181,17 @@ void device_disassociated(struct device *device) IWD_NETWORK_INTERFACE, "Connected"); } +static void device_lost_beacon(struct device *device) +{ + l_debug("%d", device->index); + + if (device->connect_pending) + dbus_pending_reply(&device->connect_pending, + dbus_error_failed(device->connect_pending)); + + device_disassociated(device); +} + static void device_connect_cb(struct netdev *netdev, enum netdev_result result, void *user_data) { @@ -211,6 +222,8 @@ static void device_connect_cb(struct netdev *netdev, enum netdev_result result, static void device_netdev_event(struct netdev *netdev, enum netdev_event event, void *user_data) { + struct device *device = user_data; + switch (event) { case NETDEV_EVENT_AUTHENTICATING: l_debug("Authenticating"); @@ -225,7 +238,7 @@ static void device_netdev_event(struct netdev *netdev, enum netdev_event event, l_debug("Setting keys"); break; case NETDEV_EVENT_LOST_BEACON: - l_debug("Beacon lost"); + device_lost_beacon(device); break; }; } diff --git a/src/netdev.c b/src/netdev.c index 1229dab5..e49de535 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -187,6 +187,44 @@ struct netdev *netdev_find(int ifindex) return l_queue_find(netdev_list, netdev_match, L_UINT_TO_PTR(ifindex)); } +static void netdev_lost_beacon(struct netdev *netdev) +{ + if (!netdev->event_filter) + return; + + netdev->event_filter(netdev, NETDEV_EVENT_LOST_BEACON, + netdev->user_data); +} + +static void netdev_cqm_event(struct l_genl_msg *msg, struct netdev *netdev) +{ + struct l_genl_attr attr; + struct l_genl_attr nested; + uint16_t type, len; + const void *data; + + if (!l_genl_attr_init(&attr, msg)) + return; + + while (l_genl_attr_next(&attr, &type, &len, &data)) { + switch (type) { + case NL80211_ATTR_CQM: + if (!l_genl_attr_recurse(&attr, &nested)) + return; + + while (l_genl_attr_next(&nested, &type, &len, &data)) { + switch (type) { + case NL80211_ATTR_CQM_BEACON_LOSS_EVENT: + netdev_lost_beacon(netdev); + break; + } + } + + break; + } + } +} + static void netdev_deauthenticate_event(struct l_genl_msg *msg, struct netdev *netdev) { @@ -498,6 +536,9 @@ static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data) case NL80211_CMD_ASSOCIATE: netdev_associate_event(msg, netdev); break; + case NL80211_CMD_NOTIFY_CQM: + netdev_cqm_event(msg, netdev); + break; } } diff --git a/src/wiphy.c b/src/wiphy.c index 11779ea8..10007ce5 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -165,15 +165,6 @@ void device_enter_state(struct device *device, enum device_state state) device->state = state; } -static void device_lost_beacon(struct device *device) -{ - if (device->connect_pending) - dbus_pending_reply(&device->connect_pending, - dbus_error_failed(device->connect_pending)); - - device_disassociated(device); -} - enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy, uint16_t mask) { mask &= wiphy->pairwise_ciphers; @@ -864,37 +855,6 @@ static void mlme_disconnect_event(struct l_genl_msg *msg, device_disassociated(device); } -static void mlme_cqm_event(struct l_genl_msg *msg, struct device *device) -{ - struct l_genl_attr attr; - struct l_genl_attr nested; - uint16_t type, len; - const void *data; - - l_debug(""); - - if (!l_genl_attr_init(&attr, msg)) - return; - - while (l_genl_attr_next(&attr, &type, &len, &data)) { - switch (type) { - case NL80211_ATTR_CQM: - if (!l_genl_attr_recurse(&attr, &nested)) - return; - - while (l_genl_attr_next(&nested, &type, &len, &data)) { - switch (type) { - case NL80211_ATTR_CQM_BEACON_LOSS_EVENT: - device_lost_beacon(device); - break; - } - } - - break; - } - } -} - static bool process_network(const void *key, void *data, void *user_data) { struct network *network = data; @@ -1512,9 +1472,6 @@ static void wiphy_mlme_notify(struct l_genl_msg *msg, void *user_data) case NL80211_CMD_DISCONNECT: mlme_disconnect_event(msg, device); break; - case NL80211_CMD_NOTIFY_CQM: - mlme_cqm_event(msg, device); - break; } }