utils: add iwinfo_band2ghz() and iwinfo_ghz2band() helpers
authorAndre Heider <a.heider@gmail.com>
Tue, 22 Nov 2022 08:39:12 +0000 (09:39 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 15 Dec 2022 23:09:07 +0000 (00:09 +0100)
To classify bands, to be used as ubus values.

Signed-off-by: Andre Heider <a.heider@gmail.com>
include/iwinfo/utils.h
iwinfo_utils.c

index a7645dea1d89001b02c3745fdf328906e107531d..7b8ceea12439b6652f0d311d280c8da7709976d1 100644 (file)
@@ -46,6 +46,9 @@ static inline int iwinfo_mbm2dbm(int gain)
 const char * const iwinfo_band_name(int mask);
 const char * const iwinfo_htmode_name(int mask);
 
+uint32_t iwinfo_band2ghz(uint8_t band);
+uint8_t iwinfo_ghz2band(uint32_t ghz);
+
 size_t iwinfo_format_hwmodes(int modes, char *buf, size_t len);
 int iwinfo_htmode_is_ht(int htmode);
 int iwinfo_htmode_is_vht(int htmode);
index 83f049a5a4b28a1995a8d1691b4a70cabe18dcaf..a342b6a19fa526d94aa90f9e24b604ce703878c1 100644 (file)
@@ -115,6 +115,40 @@ const char * const iwinfo_htmode_name(int mask)
        return iwinfo_name(mask, IWINFO_HTMODE_COUNT, IWINFO_HTMODE_NAMES);
 }
 
+uint32_t iwinfo_band2ghz(uint8_t band)
+{
+       switch (band)
+       {
+       case IWINFO_BAND_24:
+               return 2;
+       case IWINFO_BAND_5:
+               return 5;
+       case IWINFO_BAND_6:
+               return 6;
+       case IWINFO_BAND_60:
+               return 60;
+       }
+
+       return 0;
+}
+
+uint8_t iwinfo_ghz2band(uint32_t ghz)
+{
+       switch (ghz)
+       {
+       case 2:
+               return IWINFO_BAND_24;
+       case 5:
+               return IWINFO_BAND_5;
+       case 6:
+               return IWINFO_BAND_6;
+       case 60:
+               return IWINFO_BAND_60;
+       }
+
+       return 0;
+}
+
 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