Преглед на файлове

add support for data rate

Evlers преди 1 година
родител
ревизия
6b528f8a45

+ 46 - 8
common/esp_hosted_config.pb-c.c

@@ -2257,7 +2257,7 @@ void   ctrl_msg__free_unpacked
   assert(message->base.descriptor == &ctrl_msg__descriptor);
   protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
 }
-static const ProtobufCFieldDescriptor scan_result__field_descriptors[5] =
+static const ProtobufCFieldDescriptor scan_result__field_descriptors[7] =
 {
   {
     "ssid",
@@ -2319,6 +2319,30 @@ static const ProtobufCFieldDescriptor scan_result__field_descriptors[5] =
     0,             /* flags */
     0,NULL,NULL    /* reserved1,reserved2, etc */
   },
+  {
+    "bandwidth",
+    6,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_ENUM,
+    0,   /* quantifier_offset */
+    offsetof(ScanResult, bw),
+    &ctrl__wifi_bw__descriptor,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
+  {
+    "support",
+    7,
+    PROTOBUF_C_LABEL_NONE,
+    PROTOBUF_C_TYPE_UINT32,
+    0,   /* quantifier_offset */
+    offsetof(ScanResult, support),
+    NULL,
+    NULL,
+    0,             /* flags */
+    0,NULL,NULL    /* reserved1,reserved2, etc */
+  },
 };
 static const unsigned scan_result__field_indices_by_name[] = {
   3,   /* field[3] = bssid */
@@ -2326,11 +2350,13 @@ static const unsigned scan_result__field_indices_by_name[] = {
   2,   /* field[2] = rssi */
   4,   /* field[4] = sec_prot */
   0,   /* field[0] = ssid */
+  5,   /* field[5] = bandwidth */
+  6,   /* field[6] = support */
 };
 static const ProtobufCIntRange scan_result__number_ranges[1 + 1] =
 {
   { 1, 0 },
-  { 0, 5 }
+  { 0, 7 }
 };
 const ProtobufCMessageDescriptor scan_result__descriptor =
 {
@@ -2340,7 +2366,7 @@ const ProtobufCMessageDescriptor scan_result__descriptor =
   "ScanResult",
   "",
   sizeof(ScanResult),
-  5,
+  7,
   scan_result__field_descriptors,
   scan_result__field_indices_by_name,
   1,  scan_result__number_ranges,
@@ -5817,7 +5843,7 @@ const ProtobufCEnumDescriptor ctrl__wifi_power_save__descriptor =
   ctrl__wifi_power_save__value_ranges,
   NULL,NULL,NULL,NULL   /* reserved[1234] */
 };
-static const ProtobufCEnumValue ctrl__wifi_sec_prot__enum_values_by_number[8] =
+static const ProtobufCEnumValue ctrl__wifi_sec_prot__enum_values_by_number[14] =
 {
   { "Open", "CTRL__WIFI_SEC_PROT__Open", 0 },
   { "WEP", "CTRL__WIFI_SEC_PROT__WEP", 1 },
@@ -5827,11 +5853,17 @@ static const ProtobufCEnumValue ctrl__wifi_sec_prot__enum_values_by_number[8] =
   { "WPA2_ENTERPRISE", "CTRL__WIFI_SEC_PROT__WPA2_ENTERPRISE", 5 },
   { "WPA3_PSK", "CTRL__WIFI_SEC_PROT__WPA3_PSK", 6 },
   { "WPA2_WPA3_PSK", "CTRL__WIFI_SEC_PROT__WPA2_WPA3_PSK", 7 },
+  { "WIFI_AUTH_WAPI_PSK", "CTRL__WIFI_SEC_PROT__WAPI_PSK", 8 },
+  { "WIFI_AUTH_OWE", "CTRL__WIFI_SEC_PROT__OWE", 9 },
+  { "WIFI_AUTH_WPA3_ENT_192", "CTRL__WIFI_SEC_PROT__WPA3_ENT_192", 10 },
+  { "WIFI_AUTH_WPA3_EXT_PSK", "CTRL__WIFI_SEC_PROT__WPA3_EXT_PSK", 11 },
+  { "WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE", "CTRL__WIFI_SEC_PROT__WPA3_EXT_PSK_MIXED_MODE", 12 },
+  { "WIFI_AUTH_DPP", "CTRL__WIFI_SEC_PROT__DPP", 13 },
 };
 static const ProtobufCIntRange ctrl__wifi_sec_prot__value_ranges[] = {
-{0, 0},{0, 8}
+{0, 0},{0, 14}
 };
-static const ProtobufCEnumValueIndex ctrl__wifi_sec_prot__enum_values_by_name[8] =
+static const ProtobufCEnumValueIndex ctrl__wifi_sec_prot__enum_values_by_name[14] =
 {
   { "Open", 0 },
   { "WEP", 1 },
@@ -5841,6 +5873,12 @@ static const ProtobufCEnumValueIndex ctrl__wifi_sec_prot__enum_values_by_name[8]
   { "WPA3_PSK", 6 },
   { "WPA_PSK", 2 },
   { "WPA_WPA2_PSK", 4 },
+  { "WIFI_AUTH_WAPI_PSK", 8},
+  { "WIFI_AUTH_OWE", 9},
+  { "WIFI_AUTH_WPA3_ENT_192", 10},
+  { "WIFI_AUTH_WPA3_EXT_PSK", 11},
+  { "WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE", 12},
+  { "WIFI_AUTH_DPP", 13},
 };
 const ProtobufCEnumDescriptor ctrl__wifi_sec_prot__descriptor =
 {
@@ -5849,9 +5887,9 @@ const ProtobufCEnumDescriptor ctrl__wifi_sec_prot__descriptor =
   "Ctrl_WifiSecProt",
   "CtrlWifiSecProt",
   "",
-  8,
+  14,
   ctrl__wifi_sec_prot__enum_values_by_number,
-  8,
+  14,
   ctrl__wifi_sec_prot__enum_values_by_name,
   1,
   ctrl__wifi_sec_prot__value_ranges,

+ 22 - 2
common/include/esp_hosted_config.pb-c.h

@@ -112,7 +112,13 @@ typedef enum _CtrlWifiSecProt {
   CTRL__WIFI_SEC_PROT__WPA_WPA2_PSK = 4,
   CTRL__WIFI_SEC_PROT__WPA2_ENTERPRISE = 5,
   CTRL__WIFI_SEC_PROT__WPA3_PSK = 6,
-  CTRL__WIFI_SEC_PROT__WPA2_WPA3_PSK = 7
+  CTRL__WIFI_SEC_PROT__WPA2_WPA3_PSK = 7,
+  CTRL__WIFI_SEC_PROT__WAPI_PSK = 8,
+  CTRL__WIFI_SEC_PROT__OWE = 9,
+  CTRL__WIFI_SEC_PROT__WPA3_ENT_192 = 10,
+  CTRL__WIFI_SEC_PROT__WPA3_EXT_PSK = 11,
+  CTRL__WIFI_SEC_PROT__WPA3_EXT_PSK_MIXED_MODE = 12,
+  CTRL__WIFI_SEC_PROT__DPP = 13
     PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(CTRL__WIFI_SEC_PROT)
 } CtrlWifiSecProt;
 /*
@@ -238,10 +244,24 @@ struct  ScanResult
   int32_t rssi;
   ProtobufCBinaryData bssid;
   CtrlWifiSecProt sec_prot;
+  CtrlWifiBw bw;
+  struct {
+    uint32_t phy_11b: 1;                  /**< Bit: 0 flag to identify if 11b mode is enabled or not */
+    uint32_t phy_11g: 1;                  /**< Bit: 1 flag to identify if 11g mode is enabled or not */
+    uint32_t phy_11n: 1;                  /**< Bit: 2 flag to identify if 11n mode is enabled or not */
+    uint32_t phy_lr: 1;                   /**< Bit: 3 flag to identify if low rate is enabled or not */
+    uint32_t phy_11a: 1;                  /**< Bit: 4 flag to identify if 11ax mode is enabled or not */
+    uint32_t phy_11ac: 1;                 /**< Bit: 5 flag to identify if 11ax mode is enabled or not */
+    uint32_t phy_11ax: 1;                 /**< Bit: 6 flag to identify if 11ax mode is enabled or not */
+    uint32_t wps: 1;                      /**< Bit: 7 flag to identify if WPS is supported or not */
+    uint32_t ftm_responder: 1;            /**< Bit: 8 flag to identify if FTM is supported in responder mode */
+    uint32_t ftm_initiator: 1;            /**< Bit: 9 flag to identify if FTM is supported in initiator mode */
+    uint32_t reserved: 22;                /**< Bit: 10..31 reserved */
+  } support;
 };
 #define SCAN_RESULT__INIT \
  { PROTOBUF_C_MESSAGE_INIT (&scan_result__descriptor) \
-    , {0,NULL}, 0, 0, {0,NULL}, CTRL__WIFI_SEC_PROT__Open }
+    , {0,NULL}, 0, 0, {0,NULL}, CTRL__WIFI_SEC_PROT__Open, CTRL__WIFI_BW__BW_Invalid, {0} }
 
 
 struct  ConnectedSTAList

+ 40 - 3
esp/esp_driver/network_adapter/main/slave_control.c

@@ -1273,6 +1273,41 @@ static esp_err_t req_get_ap_scan_list_handler (CtrlMsg *req,
         credentials.rssi = ap_info[i].rssi;
         results[i]->rssi = credentials.rssi;
 
+        /* bandwidth */
+        {
+            /* Since esp32 does not provide an API to obtain AP MIMO information, 
+            * and esp32 only does not support MIMO,
+            * our evaluated rate is also based on 1x1.
+            */
+
+            /* HT20 */
+            if (ap_info[i].second == WIFI_SECOND_CHAN_NONE)
+            {
+                credentials.bw = CTRL__WIFI_BW__HT20;
+            }
+            /* HT40 */
+            else if (ap_info[i].second == WIFI_SECOND_CHAN_ABOVE || ap_info[i].second == WIFI_SECOND_CHAN_BELOW)
+            {
+                credentials.bw = CTRL__WIFI_BW__HT40;
+            }
+        }
+        results[i]->bw = credentials.bw;
+
+        /* supports */
+        {
+            results[i]->support.phy_11b = ap_info[i].phy_11b;
+            results[i]->support.phy_11g = ap_info[i].phy_11g;
+            results[i]->support.phy_11n = ap_info[i].phy_11n;
+            results[i]->support.phy_lr = ap_info[i].phy_lr;
+            results[i]->support.phy_11a = ap_info[i].phy_11a;
+            results[i]->support.phy_11ac = ap_info[i].phy_11ac;
+            results[i]->support.phy_11ax = ap_info[i].phy_11ax;
+            results[i]->support.wps = ap_info[i].wps;
+            results[i]->support.ftm_responder = ap_info[i].ftm_responder;
+            results[i]->support.ftm_initiator = ap_info[i].ftm_initiator;
+            results[i]->support.reserved = ap_info[i].reserved;
+        }
+
         snprintf((char *)credentials.bssid, BSSID_LENGTH,
                 MACSTR, MAC2STR(ap_info[i].bssid));
         results[i]->bssid.len = strnlen((char *)credentials.bssid, BSSID_LENGTH);
@@ -1291,13 +1326,15 @@ static esp_err_t req_get_ap_scan_list_handler (CtrlMsg *req,
 
         credentials.ecn = ap_info[i].authmode;
         results[i]->sec_prot = credentials.ecn;
+        uint32_t support;
+        memcpy(&support, &results[i]->support, sizeof(results[i]->support));
 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
-        ESP_LOGI(TAG, "SSID      \t\t%s\nRSSI      \t\t%ld\nChannel   \t\t%lu\nBSSID     \t\t%s\nAuth mode \t\t%d\n",
+        ESP_LOGI(TAG, "SSID      \t\t%s\nRSSI      \t\t%ld\nChannel   \t\t%lu\nBSSID     \t\t%s\nAuth mode \t\t%d\nbandwidth\t\t%d\nsupport\t\t\t%08lx\n",
 #else
-        ESP_LOGI(TAG,"\nSSID      \t\t%s\nRSSI      \t\t%d\nChannel   \t\t%d\nBSSID     \t\t%s\nAuth mode \t\t%d\n",
+        ESP_LOGI(TAG,"\nSSID      \t\t%s\nRSSI      \t\t%d\nChannel   \t\t%d\nBSSID     \t\t%s\nAuth mode \t\t%d\nbandwidth\t\t%d\nsupport\t\t\t%08lx\n",
 #endif
                 results[i]->ssid.data, results[i]->rssi, results[i]->chnl,
-                results[i]->bssid.data, results[i]->sec_prot);
+                results[i]->bssid.data, results[i]->sec_prot, results[i]->bw, support);
         vTaskDelay(1);
 
         resp_payload->n_entries++;

+ 20 - 0
host/control_lib/include/ctrl_api.h

@@ -196,6 +196,12 @@ typedef enum {
     WIFI_AUTH_WPA2_ENTERPRISE = CTRL__WIFI_SEC_PROT__WPA2_ENTERPRISE,
     WIFI_AUTH_WPA3_PSK = CTRL__WIFI_SEC_PROT__WPA3_PSK,
     WIFI_AUTH_WPA2_WPA3_PSK = CTRL__WIFI_SEC_PROT__WPA2_WPA3_PSK,
+    WIFI_AUTH_WAPI_PSK = CTRL__WIFI_SEC_PROT__WAPI_PSK,
+    WIFI_AUTH_OWE = CTRL__WIFI_SEC_PROT__OWE,
+    WIFI_AUTH_WPA3_ENT_192 = CTRL__WIFI_SEC_PROT__WPA3_ENT_192,
+    WIFI_AUTH_WPA3_EXT_PSK = CTRL__WIFI_SEC_PROT__WPA3_EXT_PSK,
+    WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE = CTRL__WIFI_SEC_PROT__WPA3_EXT_PSK_MIXED_MODE,
+    WIFI_AUTH_DPP = CTRL__WIFI_SEC_PROT__DPP,
     WIFI_AUTH_MAX,
 } wifi_auth_mode_e;
 
@@ -252,6 +258,20 @@ typedef struct {
     int rssi;
     int channel;
     int encryption_mode;
+    wifi_bandwidth_e bandwidth;
+    struct {
+    uint32_t phy_11b: 1;                  /**< Bit: 0 flag to identify if 11b mode is enabled or not */
+    uint32_t phy_11g: 1;                  /**< Bit: 1 flag to identify if 11g mode is enabled or not */
+    uint32_t phy_11n: 1;                  /**< Bit: 2 flag to identify if 11n mode is enabled or not */
+    uint32_t phy_lr: 1;                   /**< Bit: 3 flag to identify if low rate is enabled or not */
+    uint32_t phy_11a: 1;                  /**< Bit: 4 flag to identify if 11ax mode is enabled or not */
+    uint32_t phy_11ac: 1;                 /**< Bit: 5 flag to identify if 11ax mode is enabled or not */
+    uint32_t phy_11ax: 1;                 /**< Bit: 6 flag to identify if 11ax mode is enabled or not */
+    uint32_t wps: 1;                      /**< Bit: 7 flag to identify if WPS is supported or not */
+    uint32_t ftm_responder: 1;            /**< Bit: 8 flag to identify if FTM is supported in responder mode */
+    uint32_t ftm_initiator: 1;            /**< Bit: 9 flag to identify if FTM is supported in initiator mode */
+    uint32_t reserved: 22;                /**< Bit: 10..31 reserved */
+  } support;
 } wifi_scanlist_t;
 
 typedef struct {

+ 2 - 0
host/control_lib/src/ctrl_core.c

@@ -423,6 +423,8 @@ static int ctrl_app_parse_resp(CtrlMsg *ctrl_msg, ctrl_cmd_t *app_resp)
                 list[i].channel = rp->entries[i]->chnl;
                 list[i].rssi = rp->entries[i]->rssi;
                 list[i].encryption_mode = rp->entries[i]->sec_prot;
+                list[i].bandwidth = rp->entries[i]->bw;
+                memcpy(&list[i].support, &rp->entries[i]->support, sizeof(list[i].support));
             }
 
             ap->out_list = list;

+ 48 - 2
wlan/esp_wlan.c

@@ -257,6 +257,52 @@ static int security_wlan_to_esp (rt_wlan_security_t security)
     }
 }
 
+/* estimate the maximum rate for ap
+ *  MIMO    Channel Width   Protocol        rate
+ *  -           22MHz       802.11b         11Mbps
+ *  -           20MHz       802.11g         54 Mbps
+ *  1x1         20MHz       802.11n         72Mbps
+ *  1x1         40MHz       802.11n         150Mbps
+ *  2x2         20MHz       802.11n         144Mbps
+ *  2x2         40MHz       802.11n         300Mbps
+*/
+static int estimate_ap_max_rate(wifi_scanlist_t *ap_info)
+{
+    int max_rate = 0;
+
+    /* Check whether 802.11n (Wi-Fi 4) is supported */
+    if (ap_info->support.phy_11n)
+    {
+        /* Since esp32 does not provide an API to obtain AP MIMO information, 
+         * and esp32 only does not support MIMO,
+         * our evaluated rate is also based on 1x1.
+         */
+
+        /* 20 MHz */
+        if (ap_info->bandwidth == WIFI_BW_HT20)
+        {
+            max_rate = 72;
+        }
+        /* 40 MHz */
+        else if (ap_info->bandwidth == WIFI_BW_HT40)
+        {
+            max_rate = 150;
+        }
+    }
+    /* Check whether 802.11g is supported */
+    else if (ap_info->support.phy_11g)
+    {
+        max_rate = 54;
+    }
+    /* Check whether 802.11b is supported */
+    else if (ap_info->support.phy_11b)
+    {
+        max_rate = 11;
+    }
+
+    return max_rate;
+}
+
 static rt_err_t drv_wlan_init(struct rt_wlan_device *wlan)
 {
     return RT_EOK;
@@ -314,8 +360,8 @@ static int esp_scan_callback(ctrl_cmd_t * resp)
                 wlan_info.channel = (rt_int16_t)list[i].channel;
                 wlan_info.rssi = list[i].rssi;
 
-                wlan_info.datarate = 0;
-                wlan_info.band = RT_802_11_BAND_2_4GHZ;
+                wlan_info.datarate = estimate_ap_max_rate(&list[i]) * 1000000;
+                wlan_info.band = RT_802_11_BAND_UNKNOWN;
 
                 wlan_info.security = security_esp_to_wlan(list[i].encryption_mode);