utils: add iwinfo_htmode_is_{ht|vht|he} helpers
[project/iwinfo.git] / iwinfo_utils.c
index 425492ee9b19155a7d94ae3edb8ee0ab2bca57ef..c7713edb25715c8d6d5a65425c2d0bdedb2c7cef 100644 (file)
@@ -77,6 +77,73 @@ int iwinfo_mw2dbm(int in)
        return (int)res;
 }
 
+size_t iwinfo_format_hwmodes(int modes, char *buf, size_t len)
+{
+       // bit numbers as per IWINFO_80211_*:  ad ac ax  a  b  g  n
+       const int order[IWINFO_80211_COUNT] = { 5, 4, 6, 0, 1, 2, 3 };
+       size_t res = 0;
+       int i;
+
+       *buf = 0;
+
+       if (!(modes & ((1 << IWINFO_80211_COUNT) - 1)))
+               return 0;
+
+       for (i = 0; i < IWINFO_80211_COUNT; i++)
+               if (modes & 1 << order[i])
+                       res += snprintf(buf + res, len - res, "%s/", IWINFO_80211_NAMES[order[i]]);
+
+       if (res > 0)
+       {
+               res--;
+               buf[res] = 0;
+       }
+
+       return res;
+}
+
+int iwinfo_htmode_is_ht(int htmode)
+{
+       switch (htmode)
+       {
+       case IWINFO_HTMODE_HT20:
+       case IWINFO_HTMODE_HT40:
+               return 1;
+       }
+
+       return 0;
+}
+
+int iwinfo_htmode_is_vht(int htmode)
+{
+       switch (htmode)
+       {
+       case IWINFO_HTMODE_VHT20:
+       case IWINFO_HTMODE_VHT40:
+       case IWINFO_HTMODE_VHT80:
+       case IWINFO_HTMODE_VHT80_80:
+       case IWINFO_HTMODE_VHT160:
+               return 1;
+       }
+
+       return 0;
+}
+
+int iwinfo_htmode_is_he(int htmode)
+{
+       switch (htmode)
+       {
+       case IWINFO_HTMODE_HE20:
+       case IWINFO_HTMODE_HE40:
+       case IWINFO_HTMODE_HE80:
+       case IWINFO_HTMODE_HE80_80:
+       case IWINFO_HTMODE_HE160:
+               return 1;
+       }
+
+       return 0;
+}
+
 int iwinfo_ifup(const char *ifname)
 {
        struct ifreq ifr;
@@ -285,7 +352,7 @@ int iwinfo_hardware_id_from_mtd(struct iwinfo_hardware_id *id)
        return (id->vendor_id && id->device_id) ? 0 : -1;
 }
 
-static void iwinfo_parse_rsn_cipher(uint8_t idx, uint8_t *ciphers)
+static void iwinfo_parse_rsn_cipher(uint8_t idx, uint16_t *ciphers)
 {
        switch (idx)
        {
@@ -312,11 +379,20 @@ static void iwinfo_parse_rsn_cipher(uint8_t idx, uint8_t *ciphers)
                        *ciphers |= IWINFO_CIPHER_WEP104;
                        break;
 
+               case 8:
+                       *ciphers |= IWINFO_CIPHER_GCMP;
+                       break;
+
+               case 9:
+                       *ciphers |= IWINFO_CIPHER_GCMP256;
+                       break;
+
+               case 10:
+                       *ciphers |= IWINFO_CIPHER_CCMP256;
+                       break;
+
                case 6:  /* AES-128-CMAC */
                case 7:  /* No group addressed */
-               case 8:  /* GCMP */
-               case 9:  /* GCMP-256 */
-               case 10: /* CCMP-256 */
                case 11: /* BIP-GMAC-128 */
                case 12: /* BIP-GMAC-256 */
                case 13: /* BIP-CMAC-256 */
@@ -324,16 +400,8 @@ 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)
+                                         uint16_t defcipher, uint8_t defauth)
 {
        uint16_t i, count;
        uint8_t wpa_version = 0;
@@ -427,11 +495,11 @@ void iwinfo_parse_rsn(struct iwinfo_crypto_entry *c, uint8_t *data, uint8_t len,
 
                                case 11: /* 802.1x Suite-B */
                                case 12: /* 802.1x Suite-B-192 */
+                               case 13: /* FT/802.1x SHA-384 */
                                        c->wpa_version |= 4;
                                        c->auth_suites |= IWINFO_KMGMT_8021x;
                                        break;
 
-                               case 13: /* FT/802.1x SHA-384 */
                                case 14: /* FILS SHA-256 */
                                case 15: /* FILS SHA-384 */
                                case 16: /* FT/FILS SHA-256 */