iwinfo: add BSS load element to scan result
authorDavid Bauer <mail@david-bauer.net>
Fri, 31 Jan 2020 13:45:03 +0000 (14:45 +0100)
committerDavid Bauer <mail@david-bauer.net>
Tue, 4 Feb 2020 13:44:14 +0000 (14:44 +0100)
This adds support for the BSS load information element. With this patch,
the BSS load information is visible when using the CLI as well as when
accessing scan results using the LUA binding.

Signed-off-by: David Bauer <mail@david-bauer.net>
include/iwinfo.h
include/iwinfo/utils.h
iwinfo_cli.c
iwinfo_lua.c
iwinfo_nl80211.c
iwinfo_utils.c

index 5e64294392901308dcfa344197e67129fd326ef6..b07820d8e2a39d76a66937647ccd04424dced35b 100644 (file)
@@ -179,6 +179,12 @@ struct iwinfo_scanlist_entry {
        uint8_t quality;
        uint8_t quality_max;
        struct iwinfo_crypto_entry crypto;
+
+       /* BSS Load */
+       uint8_t has_bss_load;
+       uint8_t station_count;
+       uint8_t channel_utilization;
+       uint8_t admission_capacity;
 };
 
 struct iwinfo_country_entry {
index 98b9c890012ea80d1dd448238526a5366422b44b..a71bc9b5acb9102b6f5b24eaf5ebde82ffdb13d5 100644 (file)
@@ -53,6 +53,8 @@ struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id);
 
 int iwinfo_hardware_id_from_mtd(struct iwinfo_hardware_id *id);
 
+void iwinfo_parse_bss_load(struct iwinfo_scanlist_entry *e, uint8_t *data);
+
 void iwinfo_parse_rsn(struct iwinfo_crypto_entry *c, uint8_t *data, uint8_t len,
                                          uint8_t defcipher, uint8_t defauth);
 
index 0332bc2b90fd7821f7232bc2f00fdf5b5830916e..5949004965bbe4f0f622aa68766921c97f8aea71 100644 (file)
@@ -612,8 +612,17 @@ static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname)
                        format_signal(e->signal - 0x100),
                        format_quality(e->quality),
                        format_quality_max(e->quality_max));
-               printf("          Encryption: %s\n\n",
+               printf("          Encryption: %s\n",
                        format_encryption(&e->crypto));
+               if (e->has_bss_load) {
+                       printf("          Station count: %u\n",
+                               e->station_count);
+                       printf("          Channel utilization: %u/255\n",
+                               e->channel_utilization);
+                       printf("          Available admission capacity: %u (*32us)\n",
+                               e->admission_capacity);
+               }
+               printf("\n");
        }
 }
 
index 58a5537b638634a21298eeb706c3e080741e8e6e..76160b6812dc2dc5dd3aec24ca4e86000fdf4532 100644 (file)
@@ -434,6 +434,18 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int
                        lua_pushnumber(L, (e->signal - 0x100));
                        lua_setfield(L, -2, "signal");
 
+                       /* BSS load */
+                       if (e->has_bss_load) {
+                               lua_pushnumber(L, e->station_count);
+                               lua_setfield(L, -2, "station_count");
+
+                               lua_pushnumber(L, e->channel_utilization);
+                               lua_setfield(L, -2, "channel_utilization");
+
+                               lua_pushnumber(L, e->admission_capacity);
+                               lua_setfield(L, -2, "admission_capacity");
+                       }
+
                        /* Crypto */
                        iwinfo_L_cryptotable(L, &e->crypto);
                        lua_setfield(L, -2, "encryption");
index 2b2a04386ee5faf8a38f8601d991795f503597c5..7463fc7791be72740a76f2f67838a2b7240907ae 100644 (file)
@@ -2296,6 +2296,10 @@ static void nl80211_get_scanlist_ie(struct nlattr **bss,
                        }
                        break;
 
+               case 11: /* BSS Load */
+                       iwinfo_parse_bss_load(e, ie + 2);
+                       break;
+
                case 48: /* RSN */
                        iwinfo_parse_rsn(&e->crypto, ie + 2, ie[1],
                                         IWINFO_CIPHER_CCMP, IWINFO_KMGMT_8021x);
index b4f98a903a721e4395e2fe734524b16e23d2c0fe..425492ee9b19155a7d94ae3edb8ee0ab2bca57ef 100644 (file)
@@ -324,6 +324,14 @@ static void iwinfo_parse_rsn_cipher(uint8_t idx, uint8_t *ciphers)
        }
 }
 
+void iwinfo_parse_bss_load(struct iwinfo_scanlist_entry *e, uint8_t *data)
+{
+       e->has_bss_load = 1;
+       e->station_count = ((data[1] << 8) | data[0]);
+       e->channel_utilization = data[2];
+       e->admission_capacity = ((data[4] << 8) | data[3]);
+}
+
 void iwinfo_parse_rsn(struct iwinfo_crypto_entry *c, uint8_t *data, uint8_t len,
                                          uint8_t defcipher, uint8_t defauth)
 {