3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 09:39:25 +01:00

hwsim: Use nl80211_parse_attrs

Simplify the code by using nl80211_parse_attrs utility instead of open
coding the attribute parsing.
This commit is contained in:
Denis Kenzior 2021-12-27 10:32:30 -06:00
parent 5333207207
commit ea3fd01ebb

View File

@ -778,42 +778,25 @@ err_free_radio:
static void get_wiphy_callback(struct l_genl_msg *msg, void *user_data) static void get_wiphy_callback(struct l_genl_msg *msg, void *user_data)
{ {
struct l_genl_attr attr; const char *name;
uint16_t type, len; uint32_t id;
const void *data;
const char *name = NULL;
uint16_t name_len = 0;
const uint32_t *id = NULL;
struct radio_info_rec *rec; struct radio_info_rec *rec;
if (!l_genl_attr_init(&attr, msg)) if (nl80211_parse_attrs(msg, NL80211_ATTR_WIPHY, &id,
return; NL80211_ATTR_WIPHY_NAME, &name,
NL80211_ATTR_UNSPEC) < 0)
while (l_genl_attr_next(&attr, &type, &len, &data)) {
switch (type) {
case NL80211_ATTR_WIPHY:
id = data;
break;
case NL80211_ATTR_WIPHY_NAME:
name = data;
name_len = len;
break;
}
}
if (!name || !id)
return; return;
rec = l_queue_find(radio_info, radio_info_match_wiphy_id, rec = l_queue_find(radio_info, radio_info_match_wiphy_id,
L_UINT_TO_PTR(*id)); L_UINT_TO_PTR(id));
if (!rec) if (!rec)
return; return;
if (strlen(rec->name) == name_len && !memcmp(rec->name, name, name_len)) if (!strcmp(rec->name, name))
return; return;
l_free(rec->name); l_free(rec->name);
rec->name = l_strndup(name, name_len); rec->name = l_strdup(name);
l_dbus_property_changed(dbus, radio_get_path(rec), l_dbus_property_changed(dbus, radio_get_path(rec),
HWSIM_RADIO_INTERFACE, "Name"); HWSIM_RADIO_INTERFACE, "Name");
@ -986,30 +969,14 @@ static void set_interface_event(struct l_genl_msg *msg)
static void del_interface_event(struct l_genl_msg *msg) static void del_interface_event(struct l_genl_msg *msg)
{ {
struct interface_info_rec *interface; struct interface_info_rec *interface;
struct l_genl_attr attr; uint32_t ifindex;
uint16_t type, len;
const void *data;
const uint32_t *ifindex = NULL;
if (!l_genl_attr_init(&attr, msg)) if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
return; NL80211_ATTR_UNSPEC) < 0)
while (l_genl_attr_next(&attr, &type, &len, &data)) {
switch (type) {
case NL80211_ATTR_IFINDEX:
if (len != 4)
break;
ifindex = data;
break;
}
}
if (!ifindex)
return; return;
interface = l_queue_find(interface_info, interface_info_match_id, interface = l_queue_find(interface_info, interface_info_match_id,
L_UINT_TO_PTR(*ifindex)); L_UINT_TO_PTR(ifindex));
if (!interface) if (!interface)
return; return;