config: use PARTUUID by default on x86_64
[openwrt/openwrt.git] / package / network / utils / iwinfo / src / iwinfo_wl.c
index 3d15fc9ca7518b76c1ee6b3ede2d5536c4a212b2..7cbda9679e566456988466d9c73d74d3e75b125d 100644 (file)
@@ -18,8 +18,8 @@
  * This code is based on the wlc.c utility published by OpenWrt.org .
  */
 
-#include "iwinfo/wl.h"
-#include "iwinfo/wext.h"
+#include "iwinfo.h"
+#include "api/broadcom.h"
 
 static int wl_ioctl(const char *name, int cmd, void *buf, int len)
 {
@@ -55,6 +55,9 @@ static struct wl_maclist * wl_read_assoclist(const char *ifname)
        struct wl_maclist *macs;
        int maclen = 4 + WL_MAX_STA_COUNT * 6;
 
+       if (strstr(ifname, "wds"))
+               return NULL;
+
        if ((macs = (struct wl_maclist *) malloc(maclen)) != NULL)
        {
                memset(macs, 0, maclen);
@@ -70,19 +73,19 @@ static struct wl_maclist * wl_read_assoclist(const char *ifname)
 }
 
 
-int wl_probe(const char *ifname)
+static int wl_probe(const char *ifname)
 {
        int magic;
        return (!wl_ioctl(ifname, WLC_GET_MAGIC, &magic, sizeof(magic)) &&
                        (magic == WLC_IOCTL_MAGIC));
 }
 
-void wl_close(void)
+static void wl_close(void)
 {
        /* Nop */
 }
 
-int wl_get_mode(const char *ifname, int *buf)
+static int wl_get_mode(const char *ifname, int *buf)
 {
        int ret = -1;
        int ap, infra, passive;
@@ -108,7 +111,7 @@ int wl_get_mode(const char *ifname, int *buf)
        return 0;
 }
 
-int wl_get_ssid(const char *ifname, char *buf)
+static int wl_get_ssid(const char *ifname, char *buf)
 {
        int ret = -1;
        wlc_ssid_t ssid;
@@ -119,7 +122,7 @@ int wl_get_ssid(const char *ifname, char *buf)
        return ret;
 }
 
-int wl_get_bssid(const char *ifname, char *buf)
+static int wl_get_bssid(const char *ifname, char *buf)
 {
        int ret = -1;
        char bssid[6];
@@ -133,23 +136,23 @@ int wl_get_bssid(const char *ifname, char *buf)
        return ret;
 }
 
-int wl_get_channel(const char *ifname, int *buf)
+static int wl_get_channel(const char *ifname, int *buf)
 {
        return wl_ioctl(ifname, WLC_GET_CHANNEL, buf, sizeof(buf));
 }
 
-int wl_get_frequency(const char *ifname, int *buf)
+static int wl_get_frequency(const char *ifname, int *buf)
 {
-       return wext_get_frequency(ifname, buf);
+       return wext_ops.frequency(ifname, buf);
 }
 
-int wl_get_txpower(const char *ifname, int *buf)
+static int wl_get_txpower(const char *ifname, int *buf)
 {
        /* WLC_GET_VAR "qtxpower" */
-       return wext_get_txpower(ifname, buf);
+       return wext_ops.txpower(ifname, buf);
 }
 
-int wl_get_bitrate(const char *ifname, int *buf)
+static int wl_get_bitrate(const char *ifname, int *buf)
 {
        int ret = -1;
        int rate = 0;
@@ -160,7 +163,7 @@ int wl_get_bitrate(const char *ifname, int *buf)
        return ret;
 }
 
-int wl_get_signal(const char *ifname, int *buf)
+static int wl_get_signal(const char *ifname, int *buf)
 {
        unsigned int ap, rssi, i, rssi_count;
        int ioctl_req_version = 0x2000;
@@ -204,7 +207,7 @@ int wl_get_signal(const char *ifname, int *buf)
        return 0;
 }
 
-int wl_get_noise(const char *ifname, int *buf)
+static int wl_get_noise(const char *ifname, int *buf)
 {
        unsigned int ap, noise;
        int ioctl_req_version = 0x2000;
@@ -230,17 +233,17 @@ int wl_get_noise(const char *ifname, int *buf)
        return 0;
 }
 
-int wl_get_quality(const char *ifname, int *buf)
+static int wl_get_quality(const char *ifname, int *buf)
 {
-       return wext_get_quality(ifname, buf);
+       return wext_ops.quality(ifname, buf);
 }
 
-int wl_get_quality_max(const char *ifname, int *buf)
+static int wl_get_quality_max(const char *ifname, int *buf)
 {
-       return wext_get_quality_max(ifname, buf);
+       return wext_ops.quality_max(ifname, buf);
 }
 
-int wl_get_encryption(const char *ifname, char *buf)
+static int wl_get_encryption(const char *ifname, char *buf)
 {
        uint32_t wsec, wauth, wpa;
        struct iwinfo_crypto_entry *c = (struct iwinfo_crypto_entry *)buf;
@@ -321,7 +324,19 @@ int wl_get_encryption(const char *ifname, char *buf)
        return 0;
 }
 
-int wl_get_enctype(const char *ifname, char *buf)
+static int wl_get_phyname(const char *ifname, char *buf)
+{
+       char *p;
+
+       strcpy(buf, ifname);
+
+       if ((p = strchr(buf, '.')) != NULL)
+               *p = 0;
+
+       return 0;
+}
+
+static int wl_get_enctype(const char *ifname, char *buf)
 {
        uint32_t wsec, wpa;
        char algo[11];
@@ -406,7 +421,7 @@ static void wl_get_assoclist_cb(const char *ifname,
        }
 }
 
-int wl_get_assoclist(const char *ifname, char *buf, int *len)
+static int wl_get_assoclist(const char *ifname, char *buf, int *len)
 {
        int i, j, noise;
        int ap, infra, passive;
@@ -486,7 +501,7 @@ int wl_get_assoclist(const char *ifname, char *buf, int *len)
        return -1;
 }
 
-int wl_get_txpwrlist(const char *ifname, char *buf, int *len)
+static int wl_get_txpwrlist(const char *ifname, char *buf, int *len)
 {
        struct iwinfo_txpwrlist_entry entry;
        uint8_t dbm[11] = { 0, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 };
@@ -504,17 +519,17 @@ int wl_get_txpwrlist(const char *ifname, char *buf, int *len)
        return 0;
 }
 
-int wl_get_scanlist(const char *ifname, char *buf, int *len)
+static int wl_get_scanlist(const char *ifname, char *buf, int *len)
 {
-       return wext_get_scanlist(ifname, buf, len);
+       return wext_ops.scanlist(ifname, buf, len);
 }
 
-int wl_get_freqlist(const char *ifname, char *buf, int *len)
+static int wl_get_freqlist(const char *ifname, char *buf, int *len)
 {
-       return wext_get_freqlist(ifname, buf, len);
+       return wext_ops.freqlist(ifname, buf, len);
 }
 
-int wl_get_country(const char *ifname, char *buf)
+static int wl_get_country(const char *ifname, char *buf)
 {
        char ccode[WLC_CNTRY_BUF_SZ];
 
@@ -537,7 +552,7 @@ int wl_get_country(const char *ifname, char *buf)
        return -1;
 }
 
-int wl_get_countrylist(const char *ifname, char *buf, int *len)
+static int wl_get_countrylist(const char *ifname, char *buf, int *len)
 {
        int i, count;
        char cdata[WLC_IOCTL_MAXLEN];
@@ -550,7 +565,7 @@ int wl_get_countrylist(const char *ifname, char *buf, int *len)
        {
                for (i = 0, count = 0; i < cl->count; i++, c++)
                {
-                       sprintf(c->ccode, &cl->country_abbrev[i * WLC_CNTRY_BUF_SZ]);
+                       snprintf(c->ccode, sizeof(c->ccode), "%s", &cl->country_abbrev[i * WLC_CNTRY_BUF_SZ]);
                        c->iso3166 = c->ccode[0] * 256 + c->ccode[1];
 
                        /* IL0 -> World */
@@ -569,12 +584,53 @@ int wl_get_countrylist(const char *ifname, char *buf, int *len)
        return -1;
 }
 
-int wl_get_hwmodelist(const char *ifname, int *buf)
+static int wl_get_hwmodelist(const char *ifname, int *buf)
 {
-       return wext_get_hwmodelist(ifname, buf);
+       int phytype;
+       uint i, band[WLC_BAND_ALL], bands;
+
+       if (!wl_ioctl(ifname, WLC_GET_PHYTYPE, &phytype, sizeof(phytype)) &&
+               !wl_ioctl(ifname, WLC_GET_BANDLIST, band, sizeof(band)))
+       {
+               *buf = 0;
+               switch (phytype)
+               {
+                       case WLC_PHY_TYPE_A:
+                               *buf = IWINFO_80211_A;
+                               break;
+                       case WLC_PHY_TYPE_B:
+                               *buf = IWINFO_80211_B;
+                               break;
+                       case WLC_PHY_TYPE_AC:
+                               *buf |= IWINFO_80211_AC;
+                       case WLC_PHY_TYPE_HT:
+                       case WLC_PHY_TYPE_N:
+                               *buf |= IWINFO_80211_N;
+                       case WLC_PHY_TYPE_LP:
+                       case WLC_PHY_TYPE_G:
+                               bands = 0;
+                               for (i = 1; i <= band[0]; i++)
+                               {
+                                       bands |= band[i];
+                               }
+                               if (bands & WLC_BAND_5G)
+                                       *buf |= IWINFO_80211_A;
+                               if (bands & WLC_BAND_2G)
+                               {
+                                       *buf |= IWINFO_80211_B;
+                                       *buf |= IWINFO_80211_G;
+                               }
+                               break;
+                       default:
+                               return -1;
+                               break;
+               }
+                       return 0;
+       }
+       return -1;
 }
 
-int wl_get_mbssid_support(const char *ifname, int *buf)
+static int wl_get_mbssid_support(const char *ifname, int *buf)
 {
        wlc_rev_info_t revinfo;
 
@@ -591,7 +647,7 @@ int wl_get_mbssid_support(const char *ifname, int *buf)
        return -1;
 }
 
-int wl_get_hardware_id(const char *ifname, char *buf)
+static int wl_get_hardware_id(const char *ifname, char *buf)
 {
        wlc_rev_info_t revinfo;
        struct iwinfo_hardware_id *ids = (struct iwinfo_hardware_id *)buf;
@@ -607,7 +663,7 @@ int wl_get_hardware_id(const char *ifname, char *buf)
        return 0;
 }
 
-int wl_get_hardware_name(const char *ifname, char *buf)
+static int wl_get_hardware_name(const char *ifname, char *buf)
 {
        struct iwinfo_hardware_id ids;
 
@@ -619,7 +675,7 @@ int wl_get_hardware_name(const char *ifname, char *buf)
        return 0;
 }
 
-int wl_get_txpower_offset(const char *ifname, int *buf)
+static int wl_get_txpower_offset(const char *ifname, int *buf)
 {
        FILE *p;
        char off[8];
@@ -637,9 +693,40 @@ int wl_get_txpower_offset(const char *ifname, int *buf)
        return 0;
 }
 
-int wl_get_frequency_offset(const char *ifname, int *buf)
+static int wl_get_frequency_offset(const char *ifname, int *buf)
 {
        /* Stub */
        *buf = 0;
        return -1;
 }
+
+const struct iwinfo_ops wl_ops = {
+       .name             = "wl",
+       .probe            = wl_probe,
+       .channel          = wl_get_channel,
+       .frequency        = wl_get_frequency,
+       .frequency_offset = wl_get_frequency_offset,
+       .txpower          = wl_get_txpower,
+       .txpower_offset   = wl_get_txpower_offset,
+       .bitrate          = wl_get_bitrate,
+       .signal           = wl_get_signal,
+       .noise            = wl_get_noise,
+       .quality          = wl_get_quality,
+       .quality_max      = wl_get_quality_max,
+       .mbssid_support   = wl_get_mbssid_support,
+       .hwmodelist       = wl_get_hwmodelist,
+       .mode             = wl_get_mode,
+       .ssid             = wl_get_ssid,
+       .bssid            = wl_get_bssid,
+       .country          = wl_get_country,
+       .hardware_id      = wl_get_hardware_id,
+       .hardware_name    = wl_get_hardware_name,
+       .encryption       = wl_get_encryption,
+       .phyname          = wl_get_phyname,
+       .assoclist        = wl_get_assoclist,
+       .txpwrlist        = wl_get_txpwrlist,
+       .scanlist         = wl_get_scanlist,
+       .freqlist         = wl_get_freqlist,
+       .countrylist      = wl_get_countrylist,
+       .close            = wl_close
+};