mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-26 10:39:23 +01:00
wiphy: refactor parse_bss
This commit is contained in:
parent
0a71163c3f
commit
6917824be9
60
src/wiphy.c
60
src/wiphy.c
@ -352,74 +352,70 @@ static void mlme_associate(struct netdev *netdev, struct bss *bss)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool parse_ie(const void *data, uint16_t len)
|
static bool parse_ie(struct bss *bss, const void *data, uint16_t len)
|
||||||
{
|
{
|
||||||
struct ie_tlv_iter iter;
|
struct ie_tlv_iter iter;
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
ie_tlv_iter_init(&iter, data, len);
|
ie_tlv_iter_init(&iter, data, len);
|
||||||
|
|
||||||
while (ie_tlv_iter_next(&iter)) {
|
while (ie_tlv_iter_next(&iter)) {
|
||||||
uint8_t tag = ie_tlv_iter_get_tag(&iter);
|
uint8_t tag = ie_tlv_iter_get_tag(&iter);
|
||||||
|
|
||||||
if (tag == 0) {
|
switch (tag) {
|
||||||
char *str;
|
case 0:
|
||||||
|
bss->ssid = l_strndup((const char *) iter.data,
|
||||||
str = l_strndup((const char *) iter.data, iter.len);
|
iter.len);
|
||||||
if (!strcmp(str, network_ssid)) {
|
break;
|
||||||
l_debug("Found network SSID=%s", str);
|
default:
|
||||||
result = true;
|
break;
|
||||||
}
|
|
||||||
l_free(str);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_bss(struct netdev *netdev, struct l_genl_attr *attr)
|
static void parse_bss(struct netdev *netdev, struct l_genl_attr *attr)
|
||||||
{
|
{
|
||||||
uint16_t type, len;
|
uint16_t type, len;
|
||||||
const void *data;
|
const void *data;
|
||||||
uint8_t bssid[ETH_ALEN];
|
struct bss *bss;
|
||||||
uint32_t frequency;
|
|
||||||
bool found = false;
|
bss = l_new(struct bss, 1);
|
||||||
|
|
||||||
while (l_genl_attr_next(attr, &type, &len, &data)) {
|
while (l_genl_attr_next(attr, &type, &len, &data)) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NL80211_BSS_BSSID:
|
case NL80211_BSS_BSSID:
|
||||||
if (len != sizeof(bssid)) {
|
if (len != sizeof(bss->addr)) {
|
||||||
l_warn("Invalid BSSID attribute");
|
l_warn("Invalid BSSID attribute");
|
||||||
return;
|
goto fail;
|
||||||
}
|
}
|
||||||
memcpy(bssid, data, len);
|
|
||||||
|
memcpy(bss->addr, data, len);
|
||||||
break;
|
break;
|
||||||
case NL80211_BSS_FREQUENCY:
|
case NL80211_BSS_FREQUENCY:
|
||||||
if (len != sizeof(uint32_t)) {
|
if (len != sizeof(uint32_t)) {
|
||||||
l_warn("Invalid frequency attribute");
|
l_warn("Invalid frequency attribute");
|
||||||
return;
|
goto fail;
|
||||||
}
|
}
|
||||||
frequency = *((uint32_t *) data);
|
|
||||||
|
bss->frequency = *((uint32_t *) data);
|
||||||
break;
|
break;
|
||||||
case NL80211_BSS_INFORMATION_ELEMENTS:
|
case NL80211_BSS_INFORMATION_ELEMENTS:
|
||||||
found = parse_ie(data, len);
|
if (!parse_ie(bss, data, len)) {
|
||||||
|
l_warn("Could not parse BSS IEs");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
l_debug("Frequency for %s is %u", bss->ssid, bss->frequency);
|
||||||
struct bss *bss;
|
|
||||||
|
|
||||||
l_debug("Frequency %u", frequency);
|
|
||||||
|
|
||||||
bss = l_new(struct bss, 1);
|
|
||||||
memcpy(bss->addr, bssid, sizeof(bss->addr));
|
|
||||||
bss->frequency = frequency;
|
|
||||||
bss->ssid = l_strdup(network_ssid);
|
|
||||||
l_queue_push_head(netdev->bss_list, bss);
|
l_queue_push_head(netdev->bss_list, bss);
|
||||||
|
return;
|
||||||
|
|
||||||
mlme_authenticate(netdev, bss);
|
fail:
|
||||||
}
|
bss_free(bss);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user