3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00

wiphy: Refactor get_scan

This commit is contained in:
Denis Kenzior 2014-10-28 11:14:40 -05:00
parent 6917824be9
commit 39fde81dba

View File

@ -420,12 +420,13 @@ fail:
static void get_scan_callback(struct l_genl_msg *msg, void *user_data) static void get_scan_callback(struct l_genl_msg *msg, void *user_data)
{ {
struct wiphy *wiphy = user_data; struct netdev *netdev = user_data;
struct netdev *netdev = NULL;
struct l_genl_attr attr, nested; struct l_genl_attr attr, nested;
uint16_t type, len; uint16_t type, len;
const void *data; const void *data;
l_debug("get_scan_callback");
if (!l_genl_attr_init(&attr, msg)) if (!l_genl_attr_init(&attr, msg))
return; return;
@ -437,14 +438,12 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data)
return; return;
} }
netdev = l_queue_find(wiphy->netdev_list, netdev_match, if (netdev->index != *((uint32_t *) data)) {
L_UINT_TO_PTR(*((uint32_t *) data))); l_warn("ifindex mismatch");
if (!netdev) {
l_warn("No interface structure found");
return; return;
} }
break;
break;
case NL80211_ATTR_BSS: case NL80211_ATTR_BSS:
if (!netdev) { if (!netdev) {
l_warn("No interface structure found"); l_warn("No interface structure found");
@ -460,21 +459,21 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data)
} }
} }
static void get_scan(struct wiphy *wiphy) static void get_scan_done(void *user)
{
struct netdev *netdev = user;
l_debug("get_scan_done for netdev: %p", netdev);
}
static void get_scan(struct netdev *netdev)
{ {
struct netdev *netdev;
struct l_genl_msg *msg; struct l_genl_msg *msg;
if (!network_ssid)
return;
netdev = l_queue_peek_head(wiphy->netdev_list);
if (!netdev)
return;
msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8); msg = l_genl_msg_new_sized(NL80211_CMD_GET_SCAN, 8);
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index); l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
l_genl_family_dump(nl80211, msg, get_scan_callback, wiphy, NULL); l_genl_family_dump(nl80211, msg, get_scan_callback, netdev,
get_scan_done);
l_genl_msg_unref(msg); l_genl_msg_unref(msg);
} }
@ -689,10 +688,15 @@ static void wiphy_config_notify(struct l_genl_msg *msg, void *user_data)
static void wiphy_scan_notify(struct l_genl_msg *msg, void *user_data) static void wiphy_scan_notify(struct l_genl_msg *msg, void *user_data)
{ {
struct wiphy *wiphy = NULL; struct wiphy *wiphy = NULL;
struct netdev *netdev = NULL;
struct l_genl_attr attr; struct l_genl_attr attr;
uint16_t type, len; uint16_t type, len;
const void *data; const void *data;
uint8_t cmd; uint8_t cmd;
uint32_t attr_ifindex;
bool have_ifindex;
uint32_t attr_wiphy;
bool have_wiphy;
cmd = l_genl_msg_get_command(msg); cmd = l_genl_msg_get_command(msg);
@ -709,23 +713,47 @@ static void wiphy_scan_notify(struct l_genl_msg *msg, void *user_data)
return; return;
} }
wiphy = l_queue_find(wiphy_list, wiphy_match, have_wiphy = true;
L_UINT_TO_PTR(*((uint32_t *) data))); attr_wiphy = *((uint32_t *) data);
if (!wiphy) { break;
l_warn("No wiphy structure found"); case NL80211_ATTR_IFINDEX:
if (len != sizeof(uint32_t)) {
l_warn("Invalid interface index attribute");
return; return;
} }
have_ifindex = true;
attr_ifindex = *((uint32_t *) data);
break; break;
} }
} }
if (!have_wiphy) {
l_warn("Scan results do not contain wiphy attribute");
return;
}
if (!have_ifindex) {
l_warn("Scan results do not contain ifindex attribute");
return;
}
wiphy = l_queue_find(wiphy_list, wiphy_match,
L_UINT_TO_PTR(attr_wiphy));
if (!wiphy) { if (!wiphy) {
l_warn("Scan notification is missing wiphy attribute"); l_warn("Scan notification for unknown wiphy");
return;
}
netdev = l_queue_find(wiphy->netdev_list, netdev_match,
L_UINT_TO_PTR(attr_ifindex));
if (!netdev) {
l_warn("Scan notification for unknown ifindex");
return; return;
} }
if (cmd == NL80211_CMD_NEW_SCAN_RESULTS) { if (cmd == NL80211_CMD_NEW_SCAN_RESULTS) {
get_scan(wiphy); get_scan(netdev);
return; return;
} }
} }