nl80211: request split information about frequencies
authorRafał Miłecki <rafal@milecki.pl>
Wed, 23 Aug 2017 09:00:00 +0000 (11:00 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Wed, 23 Aug 2017 09:00:00 +0000 (11:00 +0200)
This allows kernel send more details including all the
NL80211_FREQUENCY_ATTR_NO_* flags.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
iwinfo_nl80211.c

index 6bc131819adf89211a1fb08f18f0049a7df5f515..27765317d071dc2e9173a4fa4e2f2da4782fdaca 100644 (file)
@@ -425,6 +425,30 @@ static struct nlattr ** nl80211_parse(struct nl_msg *msg)
        return attr;
 }
 
+static int nl80211_get_protocol_features_cb(struct nl_msg *msg, void *arg)
+{
+       uint32_t *features = arg;
+       struct nlattr **attr = nl80211_parse(msg);
+
+       if (attr[NL80211_ATTR_PROTOCOL_FEATURES])
+               *features = nla_get_u32(attr[NL80211_ATTR_PROTOCOL_FEATURES]);
+
+       return NL_SKIP;
+}
+
+static int nl80211_get_protocol_features(const char *ifname)
+{
+       struct nl80211_msg_conveyor *req;
+       uint32_t features = 0;
+
+       req = nl80211_msg(ifname, NL80211_CMD_GET_PROTOCOL_FEATURES, 0);
+       if (req) {
+               nl80211_send(req, nl80211_get_protocol_features_cb, &features);
+               nl80211_free(req);
+       }
+
+       return features;
+}
 
 static int nl80211_subscribe_cb(struct nl_msg *msg, void *arg)
 {
@@ -2426,15 +2450,25 @@ static int nl80211_get_freqlist_cb(struct nl_msg *msg, void *arg)
 
 static int nl80211_get_freqlist(const char *ifname, char *buf, int *len)
 {
+       struct nl80211_msg_conveyor *cv;
        struct nl80211_array_buf arr = { .buf = buf, .count = 0 };
+       uint32_t features = nl80211_get_protocol_features(ifname);
+       int flags;
 
-       if (nl80211_request(ifname, NL80211_CMD_GET_WIPHY, 0,
-                           nl80211_get_freqlist_cb, &arr))
+       flags = features & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP ? NLM_F_DUMP : 0;
+       cv = nl80211_msg(ifname, NL80211_CMD_GET_WIPHY, flags);
+       if (!cv)
+               goto out;
+
+       NLA_PUT_FLAG(cv->msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
+       if (nl80211_send(cv, nl80211_get_freqlist_cb, &arr))
                goto out;
 
        *len = arr.count * sizeof(struct iwinfo_freqlist_entry);
        return 0;
 
+nla_put_failure:
+       nl80211_free(cv);
 out:
        *len = 0;
        return -1;