You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/06/18 06:53:39 UTC

[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6466: wireless/bcm43xxx: sort scan result by rssi

anchao commented on code in PR #6466:
URL: https://github.com/apache/incubator-nuttx/pull/6466#discussion_r900707373


##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c:
##########
@@ -666,300 +669,235 @@ void bcmf_wl_scan_event_handler(FAR struct bcmf_dev_s *priv,
 
   /* Process escan result payload */
 
-  result = (struct wl_escan_result *)&event[1];
+  result = (FAR struct wl_escan_result *)&event[1];
 
   if (len < result->buflen ||
       result->buflen < sizeof(struct wl_escan_result))
     {
       goto exit_invalid_frame;
     }
 
-  /* wl_escan_result structure contains a wl_bss_info field */
-
-  len = result->buflen - sizeof(struct wl_escan_result)
-                       + sizeof(struct wl_bss_info);
+  bss = result->bss_info;
 
   /* Process bss_infos */
 
-  bss = result->bss_info;
-
-  while (len > 0 && bss_count < result->bss_count)
+  for (i = 0; i < result->bss_count; i++)
     {
-      struct iw_event *iwe;
-      unsigned int result_size;
-      size_t essid_len;
-      size_t essid_len_aligned;
-      uint8_t *ie_buffer;
-      unsigned int ie_offset;
-      unsigned int check_offset;
+      worst_entries = -1;
+      worst_rssi = 0;
 
-      result_size = BCMF_SCAN_RESULT_SIZE - priv->scan_result_size;
-      bss_info_len = bss->length;
-
-      if (len < bss_info_len)
+      for (j = 0; j < priv->scan_result_entries; j++)
         {
-          wlerr("bss_len error %d %d\n", len, bss_info_len);
-          goto exit_invalid_frame;
-        }
+          curr = &priv->scan_result[j];
 
-      /* Append current bss_info to priv->scan_results
-       * FIXME protect this against race conditions
-       */
+          /* Find worst rssi and mark the entries */
 
-      /* Check if current bss AP is not already detected */
+          if (curr->RSSI < worst_rssi)
+            {
+              worst_entries = j;
+              worst_rssi = curr->RSSI;
+            }
 
-      check_offset = 0;
+          /* Check if current bss AP is not already detected */
 
-      while (priv->scan_result_size - check_offset
-                                     >= offsetof(struct iw_event, u))
-        {
-          iwe = (struct iw_event *)&priv->scan_result[check_offset];
-
-          if (iwe->cmd == SIOCGIWAP)
+          if (memcmp(&curr->BSSID, &bss[i].BSSID,
+                     sizeof(curr->BSSID)) == 0)
             {
-              if (memcmp(&iwe->u.ap_addr.sa_data,
-                         bss->BSSID.ether_addr_octet,
-                         sizeof(bss->BSSID.ether_addr_octet)) == 0)
+              /* Replace the duplicate entries if rssi is
+               * better than before
+               */
+
+              if (curr->RSSI < bss[i].RSSI)
                 {
-                  goto process_next_bss;
+                  memcpy(curr, bss, sizeof(*curr));
                 }
-            }
 
-          check_offset += iwe->len;
+              goto process_next_bss;
+            }
         }
 
-      wlinfo("Scan result: <%.32s> %02x:%02x:%02x:%02x:%02x:%02x\n",
-               bss->SSID,
-               bss->BSSID.ether_addr_octet[0],
-               bss->BSSID.ether_addr_octet[1],
-               bss->BSSID.ether_addr_octet[2],
-               bss->BSSID.ether_addr_octet[3],
-               bss->BSSID.ether_addr_octet[4],
-               bss->BSSID.ether_addr_octet[5]);
-
-      /* Copy BSSID */
-
-      if (result_size < BCMF_IW_EVENT_SIZE(ap_addr))
+      if (priv->scan_result_entries == BCMF_SCAN_RESULT_ENTRIES)
         {
-          goto scan_result_full;
-        }
-
-      iwe = (struct iw_event *)&priv->scan_result[priv->scan_result_size];
-      iwe->len = BCMF_IW_EVENT_SIZE(ap_addr);
-      iwe->cmd = SIOCGIWAP;
-      memcpy(&iwe->u.ap_addr.sa_data, bss->BSSID.ether_addr_octet,
-             sizeof(bss->BSSID.ether_addr_octet));
-      iwe->u.ap_addr.sa_family = ARPHRD_ETHER;
-
-      priv->scan_result_size += BCMF_IW_EVENT_SIZE(ap_addr);
-      result_size -= BCMF_IW_EVENT_SIZE(ap_addr);
+          /* Entries full and replace the worst entries */
 
-      /* Copy ESSID */
-
-      essid_len = min(strlen((const char *)bss->SSID), 32);
-      essid_len_aligned = (essid_len + 3) & -4;
+          if (worst_entries >= 0)
+            {
+              curr = &priv->scan_result[worst_entries];
+              if (curr->RSSI < bss->RSSI)
+                {
+                  memcpy(curr, bss, sizeof(*curr));
+                }
+            }
 
-      if (result_size < BCMF_IW_EVENT_SIZE(essid)+essid_len_aligned)
-        {
-          goto scan_result_full;
+process_next_bss:
+          continue;
         }
 
-      iwe = (struct iw_event *)&priv->scan_result[priv->scan_result_size];
-      iwe->len = BCMF_IW_EVENT_SIZE(essid)+essid_len_aligned;
-      iwe->cmd = SIOCGIWESSID;
-      iwe->u.essid.flags = 0;
-      iwe->u.essid.length = essid_len;
-
-      /* Special processing for iw_point, set offset in pointer field */
-
-      iwe->u.essid.pointer = (FAR void *)sizeof(iwe->u.essid);
-      memcpy(&iwe->u.essid + 1, bss->SSID, essid_len);
-
-      priv->scan_result_size += BCMF_IW_EVENT_SIZE(essid)+essid_len_aligned;
-      result_size -= BCMF_IW_EVENT_SIZE(essid)+essid_len_aligned;
+      curr = &priv->scan_result[priv->scan_result_entries];
+      memcpy(curr, bss, sizeof(wl_bss_info_t));

Review Comment:
   done



##########
drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c:
##########
@@ -56,7 +56,7 @@
 #define DOT11_BSSTYPE_ANY      2
 #define BCMF_SCAN_TIMEOUT_TICK (5*CLOCKS_PER_SEC)
 #define BCMF_AUTH_TIMEOUT_MS   20000  /* was 10000 */

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org