commit d99242846c19ba5a2648070578d9e8b3f2994484
parent 1b08602727a0d622fe6006a6141df1fea3e35cd7
Author: Denis Kenzior <denkenz@gmail.com>
Date: Tue, 16 Apr 2019 16:52:15 -0500
manager: Split up new_wiphy dumps & events
Separate out the two types of NEW_WIPHY handlers into separate paths and
factor out the common code into a utility function.
Dumps of CMD_NEW_WIPHY can be split up over several messages, while
CMD_NEW_WIPHY events (generated when a new card is plugged in) are
stuffed into a single message.
This also prepares ground for follow-on commits where we will handle the
two types of events differently.
Diffstat:
| M | src/manager.c | | | 49 | +++++++++++++++++++++++++++++++------------------ |
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/src/manager.c b/src/manager.c
@@ -381,30 +381,20 @@ static void manager_wiphy_dump_interfaces(struct wiphy_setup_state *state)
state->use_default = true;
}
-static void manager_wiphy_setup_timeout(struct l_timeout *timeout,
- void *user_data)
-{
- struct wiphy_setup_state *state = user_data;
-
- manager_wiphy_dump_interfaces(state);
-}
-
-static void manager_new_wiphy_event(struct l_genl_msg *msg)
+static struct wiphy_setup_state *manager_rx_cmd_new_wiphy(
+ struct l_genl_msg *msg)
{
- struct wiphy_setup_state *state;
+ struct wiphy_setup_state *state = NULL;
struct wiphy *wiphy;
struct l_genl_attr attr;
uint32_t id;
const char *name;
- if (!pending_wiphys)
- return;
-
if (!l_genl_attr_init(&attr, msg))
- return;
+ return NULL;
if (!wiphy_parse_id_and_name(&attr, &id, &name))
- return;
+ return NULL;
/*
* A Wiphy split dump can generate many (6+) NEW_WIPHY messages
@@ -417,7 +407,7 @@ static void manager_new_wiphy_event(struct l_genl_msg *msg)
wiphy = wiphy_create(id, name);
if (!wiphy)
- return;
+ return NULL;
/*
* We've got a new wiphy, flag it as new and wait for a
@@ -433,12 +423,35 @@ static void manager_new_wiphy_event(struct l_genl_msg *msg)
state = l_new(struct wiphy_setup_state, 1);
state->id = id;
state->wiphy = wiphy;
- state->setup_timeout = l_timeout_create(1, manager_wiphy_setup_timeout,
- state, NULL);
l_queue_push_tail(pending_wiphys, state);
done:
wiphy_update_from_genl(wiphy, msg);
+ return state;
+}
+
+static void manager_wiphy_setup_timeout(struct l_timeout *timeout,
+ void *user_data)
+{
+ struct wiphy_setup_state *state = user_data;
+
+ manager_wiphy_dump_interfaces(state);
+}
+
+static void manager_new_wiphy_event(struct l_genl_msg *msg)
+{
+ struct wiphy_setup_state *state;
+
+ if (!pending_wiphys)
+ return;
+
+ state = manager_rx_cmd_new_wiphy(msg);
+ if (!state)
+ return;
+
+ /* Setup a timer just in case a default interface is not created */
+ state->setup_timeout = l_timeout_create(1, manager_wiphy_setup_timeout,
+ state, NULL);
}
static bool manager_wiphy_state_match(const void *a, const void *b)