eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit d400c7f303b571cf8432c2f04b08f939b990bc77
parent 2772845a7b02ceb45ab2baed79429e2e7b38682c
Author: Denis Kenzior <denkenz@gmail.com>
Date:   Thu, 19 Sep 2019 21:35:55 -0500

manager: Simplify manager_parse_wiphy_id

using nl80211_get_attrs

Diffstat:
Msrc/manager.c | 37+++++++++----------------------------
Msrc/nl80211util.c | 13+++++++++++++
2 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/src/manager.c b/src/manager.c @@ -462,35 +462,24 @@ static uint32_t manager_parse_ifindex(struct l_genl_msg *msg) return ifindex; } -static uint32_t manager_parse_wiphy_id(struct l_genl_attr *attr) +static uint32_t manager_parse_wiphy_id(struct l_genl_msg *msg) { - uint16_t type, len; - const void *data; - - while (l_genl_attr_next(attr, &type, &len, &data)) { - if (type != NL80211_ATTR_WIPHY) - continue; - - if (len != sizeof(uint32_t)) - break; + uint32_t wiphy; - return *((uint32_t *) data); - } + if (nl80211_parse_attrs(msg, NL80211_ATTR_WIPHY, &wiphy, + NL80211_ATTR_UNSPEC) < 0) + return -1; - return -1; + return wiphy; } static void manager_del_wiphy_event(struct l_genl_msg *msg) { struct wiphy_setup_state *state; struct wiphy *wiphy; - struct l_genl_attr attr; uint32_t id; - if (!l_genl_attr_init(&attr, msg)) - return; - - id = manager_parse_wiphy_id(&attr); + id = manager_parse_wiphy_id(msg); state = manager_find_pending(id); if (state) { @@ -509,14 +498,10 @@ static void manager_interface_dump_callback(struct l_genl_msg *msg, void *user_data) { struct wiphy_setup_state *state; - struct l_genl_attr attr; l_debug(""); - if (!l_genl_attr_init(&attr, msg)) - return; - - state = manager_find_pending(manager_parse_wiphy_id(&attr)); + state = manager_find_pending(manager_parse_wiphy_id(msg)); if (!state) return; @@ -557,7 +542,6 @@ static void manager_wiphy_dump_callback(struct l_genl_msg *msg, void *user_data) static void manager_new_wiphy_event(struct l_genl_msg *msg) { - struct l_genl_attr attr; unsigned int wiphy_cmd_id; unsigned int iface_cmd_id; uint32_t wiphy_id; @@ -565,10 +549,7 @@ static void manager_new_wiphy_event(struct l_genl_msg *msg) if (!pending_wiphys) return; - if (!l_genl_attr_init(&attr, msg)) - return; - - wiphy_id = manager_parse_wiphy_id(&attr); + wiphy_id = manager_parse_wiphy_id(msg); /* * Until fixed, a NEW_WIPHY event will not include all the information * that may be available, but a dump will. Because of this we do both diff --git a/src/nl80211util.c b/src/nl80211util.c @@ -49,11 +49,24 @@ static bool extract_ifindex(const void *data, uint16_t len, void *o) return true; } +static bool extract_uint32(const void *data, uint16_t len, void *o) +{ + uint32_t *out = o; + + if (len != 4) + return false; + + *out = l_get_u32(data); + return true; +} + static attr_handler handler_for_type(enum nl80211_attrs type) { switch (type) { case NL80211_ATTR_IFINDEX: return extract_ifindex; + case NL80211_ATTR_WIPHY: + return extract_uint32; default: break; }