You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/01/22 13:50:07 UTC

[incubator-nuttx-apps] branch pr28 updated: wapi/scan: add frequency/rssi printf

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr28
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git


The following commit(s) were added to refs/heads/pr28 by this push:
     new 7f8547f  wapi/scan: add frequency/rssi printf
7f8547f is described below

commit 7f8547f4d70901df1253af6aed9d93b405ec150e
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu Dec 26 17:37:12 2019 +0800

    wapi/scan: add frequency/rssi printf
    
    Scan print layout:
    
    nsh> wapi scan wlan0
    bssid / frequency / signal level / ssid
    **:**:**:**:**:**       2437    -38     <ssid>
    **:**:**:**:**:**       2427    -36     <ssid>
    ...
    
    Change-Id: I8201d89e3263262c41e2334e9a772ae6eb177bf6
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 include/wireless/wapi.h      |  2 ++
 wireless/wapi/src/wapi.c     |  5 +--
 wireless/wapi/src/wireless.c | 74 +++++++++++++++++++++++++++++++++++---------
 3 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/include/wireless/wapi.h b/include/wireless/wapi.h
index 6630905..ac0bce2 100644
--- a/include/wireless/wapi.h
+++ b/include/wireless/wapi.h
@@ -181,6 +181,8 @@ struct wapi_scan_info_s
   enum wapi_mode_e mode;
   int has_bitrate;
   int bitrate;
+  int has_rssi;
+  int rssi;
 };
 
 /* Linked list container for routing table rows. */
diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c
index a498f8f..0d656ba 100644
--- a/wireless/wapi/src/wapi.c
+++ b/wireless/wapi/src/wapi.c
@@ -747,13 +747,14 @@ static void wapi_scan_cmd(int sock, FAR const char *ifname)
 
   /* Print found aps */
 
+  printf("bssid / frequency / signal level / ssid\n");
   for (info = list.head.scan; info; info = info->next)
     {
-      printf("    %02x:%02x:%02x:%02x:%02x:%02x %s\n",
+      printf("%02x:%02x:%02x:%02x:%02x:%02x\t%g\t%d\t%s\n",
              info->ap.ether_addr_octet[0], info->ap.ether_addr_octet[1],
              info->ap.ether_addr_octet[2], info->ap.ether_addr_octet[3],
              info->ap.ether_addr_octet[4],  info->ap.ether_addr_octet[5],
-             (info->has_essid ? info->essid : ""));
+             info->freq, info->rssi, info->essid);
     }
 
   /* Free ap list */
diff --git a/wireless/wapi/src/wireless.c b/wireless/wapi/src/wireless.c
index f58b4dd..293c7fa 100644
--- a/wireless/wapi/src/wireless.c
+++ b/wireless/wapi/src/wireless.c
@@ -342,9 +342,35 @@ static int wapi_scan_event(FAR struct iw_event *event,
       }
 
     case SIOCGIWFREQ:
-      info->has_freq = 1;
-      info->freq = wapi_freq2float(&(event->u.freq));
-      break;
+      {
+        info->has_freq = 1;
+
+        if (event->u.freq.e == 0)
+          {
+            /* Some drivers do not report frequency, but a channel.
+             * Try to map this to frequency by assuming they are using
+             * IEEE 802.11b/g.  But don't overwrite a previously parsed
+             * frequency if the driver sends both frequency and channel,
+             * since the driver may be sending an A-band channel that we
+             * don't handle here.
+             */
+
+            if (event->u.freq.m >= 1 && event->u.freq.m <= 13)
+              {
+                info->freq = 2407 + 5 * event->u.freq.m;
+              }
+            else if (event->u.freq.m == 14)
+              {
+                info->freq = 2484;
+              }
+          }
+        else
+          {
+            info->freq = wapi_freq2float(&(event->u.freq));
+          }
+
+        break;
+      }
 
     case SIOCGIWMODE:
       {
@@ -361,16 +387,19 @@ static int wapi_scan_event(FAR struct iw_event *event,
       }
 
     case SIOCGIWESSID:
-      info->has_essid = 1;
-      info->essid_flag = (event->u.data.flags) ? WAPI_ESSID_ON
-                                               : WAPI_ESSID_OFF;
-      memset(info->essid, 0, (WAPI_ESSID_MAX_SIZE + 1));
-      if ((event->u.essid.pointer) && (event->u.essid.length))
-        {
-          memcpy(info->essid, event->u.essid.pointer, event->u.essid.length);
-        }
+      {
+        info->has_essid = 1;
+        info->essid_flag = (event->u.data.flags) ? WAPI_ESSID_ON
+                                                 : WAPI_ESSID_OFF;
+        memset(info->essid, 0, (WAPI_ESSID_MAX_SIZE + 1));
+        if ((event->u.essid.pointer) && (event->u.essid.length))
+          {
+            memcpy(info->essid, event->u.essid.pointer,
+                   event->u.essid.length);
+          }
 
-      break;
+        break;
+      }
 
     case SIOCGIWRATE:
 
@@ -383,7 +412,26 @@ static int wapi_scan_event(FAR struct iw_event *event,
           info->has_bitrate = 1;
           info->bitrate = event->u.bitrate.value;
         }
+
       break;
+
+    case IWEVQUAL:
+      {
+        if (event->u.qual.updated & IW_QUAL_DBM)
+          {
+            info->has_rssi = 1;
+            info->rssi = event->u.qual.level;
+
+            /* Report signal levels in dBm */
+
+            if (info->rssi >= 0x40)
+              {
+                info->rssi -= 0x100;
+              }
+          }
+
+        break;
+      }
     }
 
   return 0;
@@ -1237,8 +1285,6 @@ alloc:
       return -errcode;
     }
 
-  printf("got %d bytes\n", wrq.u.data.length);
-
   /* We have the results, process them. */
 
   if (wrq.u.data.length)