From 91784425ec37cc5a8859ad73c0b1c9d1628fcec2 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 19 Sep 2019 22:54:07 -0500 Subject: [PATCH] wiphy: Remove wiphy_parse_id_and_name in favor of using nl80211_parse_attrs --- src/manager.c | 10 ++--- src/nl80211util.c | 1 + src/wiphy.c | 97 +++++++---------------------------------------- src/wiphy.h | 6 +-- 4 files changed, 21 insertions(+), 93 deletions(-) diff --git a/src/manager.c b/src/manager.c index 3c700373..1a04b071 100644 --- a/src/manager.c +++ b/src/manager.c @@ -330,17 +330,15 @@ static struct wiphy_setup_state *manager_rx_cmd_new_wiphy( { struct wiphy_setup_state *state = NULL; struct wiphy *wiphy; - struct l_genl_attr attr; uint32_t id; const char *name; const char *driver, **driver_bad; bool use_default; const struct l_settings *settings = iwd_get_config(); - if (!l_genl_attr_init(&attr, msg)) - return NULL; - - if (!wiphy_parse_id_and_name(&attr, &id, &name)) + if (nl80211_parse_attrs(msg, NL80211_ATTR_WIPHY, &id, + NL80211_ATTR_WIPHY_NAME, &name, + NL80211_ATTR_UNSPEC) < 0) return NULL; /* @@ -386,7 +384,7 @@ static struct wiphy_setup_state *manager_rx_cmd_new_wiphy( l_info("Wiphy %s will only use the default interface", name); done: - wiphy_update_from_genl(wiphy, msg); + wiphy_update_from_genl(wiphy, name, msg); return state; } diff --git a/src/nl80211util.c b/src/nl80211util.c index 243ddf08..7a036af7 100644 --- a/src/nl80211util.c +++ b/src/nl80211util.c @@ -96,6 +96,7 @@ static attr_handler handler_for_type(enum nl80211_attrs type) case NL80211_ATTR_WDEV: return extract_uint64; case NL80211_ATTR_IFNAME: + case NL80211_ATTR_WIPHY_NAME: return extract_name; default: break; diff --git a/src/wiphy.c b/src/wiphy.c index 007d58fd..b672afd4 100644 --- a/src/wiphy.c +++ b/src/wiphy.c @@ -49,6 +49,7 @@ #include "src/util.h" #include "src/common.h" #include "src/watchlist.h" +#include "src/nl80211util.h" #define EXT_CAP_LEN 10 @@ -703,13 +704,17 @@ static void parse_iftype_extended_capabilities(struct wiphy *wiphy, } static void wiphy_parse_attributes(struct wiphy *wiphy, - struct l_genl_attr *attr) + struct l_genl_msg *msg) { + struct l_genl_attr attr; struct l_genl_attr nested; uint16_t type, len; const void *data; - while (l_genl_attr_next(attr, &type, &len, &data)) { + if (!l_genl_attr_init(&attr, msg)) + return; + + while (l_genl_attr_next(&attr, &type, &len, &data)) { switch (type) { case NL80211_ATTR_FEATURE_FLAGS: if (len != sizeof(uint32_t)) @@ -725,7 +730,7 @@ static void wiphy_parse_attributes(struct wiphy *wiphy, memcpy(wiphy->ext_features, data, len); break; case NL80211_ATTR_SUPPORTED_COMMANDS: - if (l_genl_attr_recurse(attr, &nested)) + if (l_genl_attr_recurse(&attr, &nested)) parse_supported_commands(wiphy, &nested); break; @@ -733,7 +738,7 @@ static void wiphy_parse_attributes(struct wiphy *wiphy, parse_supported_ciphers(wiphy, data, len); break; case NL80211_ATTR_WIPHY_BANDS: - if (l_genl_attr_recurse(attr, &nested)) + if (l_genl_attr_recurse(&attr, &nested)) parse_supported_bands(wiphy, &nested); break; @@ -748,7 +753,7 @@ static void wiphy_parse_attributes(struct wiphy *wiphy, wiphy->support_adhoc_rsn = true; break; case NL80211_ATTR_SUPPORTED_IFTYPES: - if (l_genl_attr_recurse(attr, &nested)) + if (l_genl_attr_recurse(&attr, &nested)) parse_supported_iftypes(wiphy, &nested); break; case NL80211_ATTR_OFFCHANNEL_TX_OK: @@ -759,7 +764,7 @@ static void wiphy_parse_attributes(struct wiphy *wiphy, data, minsize(EXT_CAP_LEN, len)); break; case NL80211_ATTR_IFTYPE_EXT_CAPA: - if (!l_genl_attr_recurse(attr, &nested)) + if (!l_genl_attr_recurse(&attr, &nested)) break; parse_iftype_extended_capabilities(wiphy, &nested); @@ -768,68 +773,6 @@ static void wiphy_parse_attributes(struct wiphy *wiphy, } } -bool wiphy_parse_id_and_name(struct l_genl_attr *attr, uint32_t *out_id, - const char **out_name) -{ - uint16_t type, len; - const void *data; - uint32_t id; - const char *name; - - /* - * The wiphy attribute, name and generation are always the first - * three attributes (in that order) in every NEW_WIPHY & DEL_WIPHY - * message. If not, then error out with a warning and ignore the - * whole message. - */ - if (!l_genl_attr_next(attr, &type, &len, &data)) - return false; - - if (type != NL80211_ATTR_WIPHY) - return false; - - if (len != sizeof(uint32_t)) - return false; - - id = *((uint32_t *) data); - - if (!l_genl_attr_next(attr, &type, &len, &data)) - return false; - - if (type != NL80211_ATTR_WIPHY_NAME) - return false; - - if (len > sizeof(((struct wiphy *) 0)->name)) - return false; - - name = data; - - if (len < 1 || !memchr(name + 1, 0, len - 1)) - return false; - - if (!l_genl_attr_next(attr, &type, &len, &data)) - return false; - - if (type != NL80211_ATTR_GENERATION) - return false; - - if (len != sizeof(uint32_t)) - return false; - - /* - * TODO: Handle GENERATION. In theory if we detect a changed generation - * number during a dump, it means that our dump needs to be re-started - */ - - if (out_id) - *out_id = id; - - if (out_name) - *out_name = name; - - return true; -} - static bool wiphy_get_driver_name(struct wiphy *wiphy) { L_AUTO_FREE_VAR(char *, driver_link) = NULL; @@ -942,23 +885,11 @@ struct wiphy *wiphy_create(uint32_t wiphy_id, const char *name) return wiphy; } -void wiphy_update_from_genl(struct wiphy *wiphy, struct l_genl_msg *msg) +void wiphy_update_from_genl(struct wiphy *wiphy, const char *name, + struct l_genl_msg *msg) { - struct l_genl_attr attr; - const char *name; - l_debug(""); - if (!l_genl_attr_init(&attr, msg)) - return; - - if (!wiphy_parse_id_and_name(&attr, NULL, &name)) - return; - - /* - * WIPHY_NAME is a NLA_NUL_STRING, so the kernel - * enforces the data to be null terminated. - */ if (strncmp(wiphy->name, name, sizeof(wiphy->name))) { struct l_dbus *dbus = dbus_get_bus(); @@ -967,7 +898,7 @@ void wiphy_update_from_genl(struct wiphy *wiphy, struct l_genl_msg *msg) IWD_WIPHY_INTERFACE, "Name"); } - wiphy_parse_attributes(wiphy, &attr); + wiphy_parse_attributes(wiphy, msg); } static void wiphy_set_station_capability_bits(struct wiphy *wiphy) diff --git a/src/wiphy.h b/src/wiphy.h index d3dc0f04..10cf5373 100644 --- a/src/wiphy.h +++ b/src/wiphy.h @@ -43,15 +43,13 @@ enum ie_rsn_akm_suite wiphy_select_akm(struct wiphy *wiphy, struct scan_bss *bss, bool fils_capable_hint); -bool wiphy_parse_id_and_name(struct l_genl_attr *attr, uint32_t *out_id, - const char **out_name); - struct wiphy *wiphy_find(int wiphy_id); struct wiphy *wiphy_create(uint32_t wiphy_id, const char *name); void wiphy_create_complete(struct wiphy *wiphy); bool wiphy_destroy(struct wiphy *wiphy); -void wiphy_update_from_genl(struct wiphy *wiphy, struct l_genl_msg *msg); +void wiphy_update_from_genl(struct wiphy *wiphy, const char *name, + struct l_genl_msg *msg); bool wiphy_constrain_freq_set(const struct wiphy *wiphy, struct scan_freq_set *set);