devices: add device id for Realtek RTL8188CU and RTL8188FTV
[project/iwinfo.git] / iwinfo_wl.c
index 57e4acf00292b4e534886f3b4a511619a5485143..9ec78cd2119f48934493610c50691401fc55bfef 100644 (file)
@@ -18,6 +18,9 @@
  * This code is based on the wlc.c utility published by OpenWrt.org .
  */
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include "iwinfo.h"
 #include "api/broadcom.h"
 
@@ -141,6 +144,18 @@ static int wl_get_channel(const char *ifname, int *buf)
        return wl_ioctl(ifname, WLC_GET_CHANNEL, buf, sizeof(buf));
 }
 
+static int wl_get_center_chan1(const char *ifname, int *buf)
+{
+       /* Not Supported */
+       return -1;
+}
+
+static int wl_get_center_chan2(const char *ifname, int *buf)
+{
+       /* Not Supported */
+       return -1;
+}
+
 static int wl_get_frequency(const char *ifname, int *buf)
 {
        return wext_ops.frequency(ifname, buf);
@@ -601,6 +616,8 @@ static int wl_get_hwmodelist(const char *ifname, int *buf)
                        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;
@@ -628,6 +645,29 @@ static int wl_get_hwmodelist(const char *ifname, int *buf)
        return -1;
 }
 
+static int wl_get_htmodelist(const char *ifname, int *buf)
+{
+       int modes;
+
+       if (!wl_get_hwmodelist(ifname, &modes))
+       {
+               *buf = 0;
+
+               /* FIXME: determine real capabilities */
+
+               if (modes & IWINFO_80211_N)
+                       *buf |= IWINFO_HTMODE_HT20 | IWINFO_HTMODE_HT40;
+
+               if (modes & IWINFO_80211_AC)
+                       *buf |= IWINFO_HTMODE_VHT20 | IWINFO_HTMODE_VHT40 |
+                               IWINFO_HTMODE_VHT80;
+
+               return 0;
+       }
+
+       return -1;
+}
+
 static int wl_get_mbssid_support(const char *ifname, int *buf)
 {
        wlc_rev_info_t revinfo;
@@ -677,15 +717,19 @@ static int wl_get_txpower_offset(const char *ifname, int *buf)
 {
        FILE *p;
        char off[8];
+       struct stat s;
 
        *buf = 0;
 
-       if ((p = popen("/usr/sbin/nvram get opo", "r")) != NULL)
+       if (!stat("/usr/sbin/nvram", &s) && (s.st_mode & S_IXUSR))
        {
-               if (fread(off, 1, sizeof(off), p))
-                       *buf = strtoul(off, NULL, 16);
+               if ((p = popen("/usr/sbin/nvram get opo", "r")) != NULL)
+               {
+                       if (fread(off, 1, sizeof(off), p))
+                               *buf = strtoul(off, NULL, 16);
 
-               pclose(p);
+                       pclose(p);
+               }
        }
 
        return 0;
@@ -702,6 +746,8 @@ const struct iwinfo_ops wl_ops = {
        .name             = "wl",
        .probe            = wl_probe,
        .channel          = wl_get_channel,
+       .center_chan1     = wl_get_center_chan1,
+       .center_chan2     = wl_get_center_chan2,
        .frequency        = wl_get_frequency,
        .frequency_offset = wl_get_frequency_offset,
        .txpower          = wl_get_txpower,
@@ -713,6 +759,7 @@ const struct iwinfo_ops wl_ops = {
        .quality_max      = wl_get_quality_max,
        .mbssid_support   = wl_get_mbssid_support,
        .hwmodelist       = wl_get_hwmodelist,
+       .htmodelist       = wl_get_htmodelist,
        .mode             = wl_get_mode,
        .ssid             = wl_get_ssid,
        .bssid            = wl_get_bssid,