devices: add device id for Realtek RTL8188CU and RTL8188FTV
[project/iwinfo.git] / iwinfo_cli.c
index c8436a47f1802981a2c9b4ec714ff98662406abd..5dcee9ad023f4311fe75a7283d7c0bb788b6f976 100644 (file)
@@ -44,6 +44,17 @@ static char * format_ssid(char *ssid)
        return buf;
 }
 
+static const char *format_band(int band)
+{
+       const char *name;
+
+       name = iwinfo_band_name(band);
+       if (name)
+               return name;
+
+       return "unknown";
+}
+
 static char * format_channel(int ch)
 {
        static char buf[16];
@@ -68,6 +79,25 @@ static char * format_frequency(int freq)
        return buf;
 }
 
+static char * format_freqflags(uint32_t flags)
+{
+       static char str[512] = "[";
+       char *pos = str + 1;
+       int i;
+
+       if (!flags)
+               return "";
+
+       for (i = 0; i < IWINFO_FREQ_FLAG_COUNT; i++)
+               if (flags & (1 << i))
+                       pos += sprintf(pos, "%s, ", IWINFO_FREQ_FLAG_NAMES[i]);
+
+       *(pos - 2) = ']';
+       *(pos - 1) = 0;
+
+       return str;
+}
+
 static char * format_txpower(int pwr)
 {
        static char buf[16];
@@ -145,39 +175,11 @@ static char * format_enc_ciphers(int ciphers)
 {
        static char str[128] = { 0 };
        char *pos = str;
+       int i;
 
-       if (ciphers & IWINFO_CIPHER_WEP40)
-               pos += sprintf(pos, "WEP-40, ");
-
-       if (ciphers & IWINFO_CIPHER_WEP104)
-               pos += sprintf(pos, "WEP-104, ");
-
-       if (ciphers & IWINFO_CIPHER_TKIP)
-               pos += sprintf(pos, "TKIP, ");
-
-       if (ciphers & IWINFO_CIPHER_CCMP)
-               pos += sprintf(pos, "CCMP, ");
-
-       if (ciphers & IWINFO_CIPHER_CCMP256)
-               pos += sprintf(pos, "CCMP-256, ");
-
-       if (ciphers & IWINFO_CIPHER_GCMP)
-               pos += sprintf(pos, "GCMP, ");
-
-       if (ciphers & IWINFO_CIPHER_GCMP256)
-               pos += sprintf(pos, "GCMP-256, ");
-
-       if (ciphers & IWINFO_CIPHER_WRAP)
-               pos += sprintf(pos, "WRAP, ");
-
-       if (ciphers & IWINFO_CIPHER_AESOCB)
-               pos += sprintf(pos, "AES-OCB, ");
-
-       if (ciphers & IWINFO_CIPHER_CKIP)
-               pos += sprintf(pos, "CKIP, ");
-
-       if (!ciphers || (ciphers & IWINFO_CIPHER_NONE))
-               pos += sprintf(pos, "NONE, ");
+       for (i = 0; i < IWINFO_CIPHER_COUNT; i++)
+               if (ciphers & (1 << i))
+                       pos += sprintf(pos, "%s, ", IWINFO_CIPHER_NAMES[i]);
 
        *(pos - 2) = 0;
 
@@ -188,21 +190,11 @@ static char * format_enc_suites(int suites)
 {
        static char str[64] = { 0 };
        char *pos = str;
+       int i;
 
-       if (suites & IWINFO_KMGMT_PSK)
-               pos += sprintf(pos, "PSK/");
-
-       if (suites & IWINFO_KMGMT_8021x)
-               pos += sprintf(pos, "802.1X/");
-
-       if (suites & IWINFO_KMGMT_SAE)
-               pos += sprintf(pos, "SAE/");
-
-       if (suites & IWINFO_KMGMT_OWE)
-               pos += sprintf(pos, "OWE/");
-
-       if (!suites || (suites & IWINFO_KMGMT_NONE))
-               pos += sprintf(pos, "NONE/");
+       for (i = 0; i < IWINFO_KMGMT_COUNT; i++)
+               if (suites & (1 << i))
+                       pos += sprintf(pos, "%s/", IWINFO_KMGMT_NAMES[i]);
 
        *(pos - 1) = 0;
 
@@ -373,9 +365,16 @@ static char * print_hardware_id(const struct iwinfo_ops *iw, const char *ifname)
 
        if (!iw->hardware_id(ifname, (char *)&ids))
        {
-               snprintf(buf, sizeof(buf), "%04X:%04X %04X:%04X",
-                       ids.vendor_id, ids.device_id,
-                       ids.subsystem_vendor_id, ids.subsystem_device_id);
+               if (strlen(ids.compatible) > 0)
+                       snprintf(buf, sizeof(buf), "embedded");
+               else if (ids.vendor_id == 0 && ids.device_id == 0 &&
+                        ids.subsystem_vendor_id != 0 && ids.subsystem_device_id != 0)
+                       snprintf(buf, sizeof(buf), "USB %04X:%04X",
+                               ids.subsystem_vendor_id, ids.subsystem_device_id);
+               else
+                       snprintf(buf, sizeof(buf), "%04X:%04X %04X:%04X",
+                               ids.vendor_id, ids.device_id,
+                               ids.subsystem_vendor_id, ids.subsystem_device_id);
        }
        else
        {
@@ -571,6 +570,20 @@ static char * print_hwmodes(const struct iwinfo_ops *iw, const char *ifname)
        return format_hwmodes(modes);
 }
 
+static const char *print_htmode(const struct iwinfo_ops *iw, const char *ifname)
+{
+       int mode;
+       const char *name;
+       if (iw->htmode(ifname, &mode))
+               mode = -1;
+
+       name = iwinfo_htmode_name(mode);
+       if (name)
+               return name;
+
+       return "unknown";
+}
+
 static char * print_mbssid_supp(const struct iwinfo_ops *iw, const char *ifname)
 {
        int supp;
@@ -602,10 +615,11 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname)
                print_ssid(iw, ifname));
        printf("          Access Point: %s\n",
                print_bssid(iw, ifname));
-       printf("          Mode: %s  Channel: %s (%s)\n",
+       printf("          Mode: %s  Channel: %s (%s)  HT Mode: %s\n",
                print_mode(iw, ifname),
                print_channel(iw, ifname),
-               print_frequency(iw, ifname));
+               print_frequency(iw, ifname),
+               print_htmode(iw, ifname));
        if (iw->center_chan1 != NULL) {
                printf("          Center Channel 1: %s",
                        print_center_chan1(iw, ifname));
@@ -664,8 +678,10 @@ static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname)
                        format_bssid(e->mac));
                printf("          ESSID: %s\n",
                        format_ssid(e->ssid));
-               printf("          Mode: %s  Channel: %s\n",
+               printf("          Mode: %s  Frequency: %s  Band: %s  Channel: %s\n",
                        IWINFO_OPMODE_NAMES[e->mode],
+                       format_frequency(e->mhz),
+                       format_band(e->band),
                        format_channel(e->channel));
                printf("          Signal: %s  Quality: %s/%s\n",
                        format_signal(e->signal - 0x100),
@@ -745,11 +761,12 @@ static void print_freqlist(const struct iwinfo_ops *iw, const char *ifname)
        {
                e = (struct iwinfo_freqlist_entry *) &buf[i];
 
-               printf("%s %s (Channel %s)%s\n",
+               printf("%s %s (Band: %s, Channel %s) %s\n",
                        (freq == e->mhz) ? "*" : " ",
                        format_frequency(e->mhz),
+                       format_band(e->band),
                        format_channel(e->channel),
-                       e->restricted ? " [restricted]" : "");
+                       format_freqflags(e->flags));
        }
 }
 
@@ -852,7 +869,7 @@ static void print_htmodelist(const struct iwinfo_ops *iw, const char *ifname)
                return;
        }
 
-       for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
+       for (i = 0; i < IWINFO_HTMODE_COUNT; i++)
                if (htmodes & (1 << i))
                        printf("%s ", IWINFO_HTMODE_NAMES[i]);