3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-10-04 18:38:48 +02:00

wiphy: Rework wiphy dump parser

This commit is contained in:
Denis Kenzior 2016-06-24 19:20:35 -05:00
parent 0d9ec3b5ed
commit ed18ab4fc0

View File

@ -232,20 +232,60 @@ static void parse_supported_bands(struct wiphy *wiphy,
} }
} }
#define FAIL_NO_WIPHY() \ static void wiphy_parse_attributes(struct wiphy *wiphy,
if (!wiphy) { \ struct l_genl_attr *attr)
l_warn("No wiphy structure found"); \ {
return; \ struct l_genl_attr nested;
} \ uint16_t type, len;
const void *data;
while (l_genl_attr_next(attr, &type, &len, &data)) {
switch (type) {
case NL80211_ATTR_WIPHY:
l_warn("Duplicate wiphy attribute");
break;
case NL80211_ATTR_WIPHY_NAME:
if (len > sizeof(wiphy->name))
l_warn("Invalid wiphy name attribute");
else
memcpy(wiphy->name, data, len);
break;
case NL80211_ATTR_FEATURE_FLAGS:
if (len != sizeof(uint32_t))
l_warn("Invalid feature flags attribute");
else
wiphy->feature_flags = *((uint32_t *) data);
break;
case NL80211_ATTR_SUPPORTED_COMMANDS:
if (l_genl_attr_recurse(attr, &nested))
parse_supported_commands(wiphy, &nested);
break;
case NL80211_ATTR_CIPHER_SUITES:
parse_supported_ciphers(wiphy, data, len);
break;
case NL80211_ATTR_WIPHY_BANDS:
if (l_genl_attr_recurse(attr, &nested))
parse_supported_bands(wiphy, &nested);
break;
}
}
}
static void wiphy_dump_callback(struct l_genl_msg *msg, void *user_data) static void wiphy_dump_callback(struct l_genl_msg *msg, void *user_data)
{ {
struct wiphy *wiphy = NULL; struct wiphy *wiphy;
struct l_genl_attr attr, nested; struct l_genl_attr attr;
uint16_t type, len; uint16_t type, len;
const void *data; const void *data;
uint32_t id; uint32_t id;
l_debug("");
if (!l_genl_attr_init(&attr, msg)) if (!l_genl_attr_init(&attr, msg))
return; return;
@ -258,13 +298,12 @@ static void wiphy_dump_callback(struct l_genl_msg *msg, void *user_data)
* since the information included can not fit into a single * since the information included can not fit into a single
* message. * message.
*/ */
while (l_genl_attr_next(&attr, &type, &len, &data)) { if (!l_genl_attr_next(&attr, &type, &len, &data))
switch (type) {
case NL80211_ATTR_WIPHY:
if (wiphy) {
l_warn("Duplicate wiphy attribute");
return; return;
}
if (type != NL80211_ATTR_WIPHY)
return;
if (len != sizeof(uint32_t)) { if (len != sizeof(uint32_t)) {
l_warn("Invalid wiphy attribute"); l_warn("Invalid wiphy attribute");
@ -273,60 +312,15 @@ static void wiphy_dump_callback(struct l_genl_msg *msg, void *user_data)
id = *((uint32_t *) data); id = *((uint32_t *) data);
wiphy = l_queue_find(wiphy_list, wiphy_match, wiphy = l_queue_find(wiphy_list, wiphy_match, L_UINT_TO_PTR(id));
L_UINT_TO_PTR(id));
if (!wiphy) { if (!wiphy) {
wiphy = l_new(struct wiphy, 1); wiphy = l_new(struct wiphy, 1);
wiphy->id = id; wiphy->id = id;
wiphy->supported_freqs = scan_freq_set_new(); wiphy->supported_freqs = scan_freq_set_new();
l_queue_push_head(wiphy_list, wiphy); l_queue_push_head(wiphy_list, wiphy);
} }
break;
case NL80211_ATTR_WIPHY_NAME: wiphy_parse_attributes(wiphy, &attr);
FAIL_NO_WIPHY();
if (len > sizeof(wiphy->name)) {
l_warn("Invalid wiphy name attribute");
return;
}
memcpy(wiphy->name, data, len);
break;
case NL80211_ATTR_FEATURE_FLAGS:
FAIL_NO_WIPHY();
if (len != sizeof(uint32_t)) {
l_warn("Invalid feature flags attribute");
return;
}
wiphy->feature_flags = *((uint32_t *) data);
break;
case NL80211_ATTR_SUPPORTED_COMMANDS:
FAIL_NO_WIPHY();
if (!l_genl_attr_recurse(&attr, &nested))
return;
parse_supported_commands(wiphy, &nested);
break;
case NL80211_ATTR_CIPHER_SUITES:
FAIL_NO_WIPHY();
parse_supported_ciphers(wiphy, data, len);
break;
case NL80211_ATTR_WIPHY_BANDS:
FAIL_NO_WIPHY();
if (!l_genl_attr_recurse(&attr, &nested))
return;
parse_supported_bands(wiphy, &nested);
break;
}
}
} }
static void wiphy_dump_done(void *user) static void wiphy_dump_done(void *user)