return gain / 100;
}
+size_t iwinfo_format_hwmodes(int modes, char *buf, size_t len);
+
int iwinfo_ifup(const char *ifname);
int iwinfo_ifdown(const char *ifname);
int iwinfo_ifmac(const char *ifname);
static char * format_hwmodes(int modes)
{
- static char buf[17];
+ static char buf[32] = "802.11";
- if (modes <= 0)
+ if (iwinfo_format_hwmodes(modes, buf + 6, sizeof(buf) - 6) < 1)
snprintf(buf, sizeof(buf), "unknown");
- else
- snprintf(buf, sizeof(buf), "802.11%s%s%s%s%s%s%s",
- (modes & IWINFO_80211_A) ? "a" : "",
- (modes & IWINFO_80211_B) ? "b" : "",
- (modes & IWINFO_80211_G) ? "g" : "",
- (modes & IWINFO_80211_N) ? "n" : "",
- (modes & IWINFO_80211_AC) ? "ac" : "",
- (modes & IWINFO_80211_AD) ? "ad" : "",
- (modes & IWINFO_80211_AX) ? "ax" : "");
return buf;
}
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_ifup(const char *ifname)
{
struct ifreq ifr;