]> granicus.if.org Git - esp-idf/commitdiff
esp32/tcpip_adapter: refractor for some wifi APIs
authorliuzhifu <liuzhifu@espressif.com>
Wed, 26 Oct 2016 10:16:40 +0000 (18:16 +0800)
committerliuzhifu <liuzhifu@espressif.com>
Wed, 26 Oct 2016 10:16:40 +0000 (18:16 +0800)
1. Modify esp_wifi_get_station_list to esp_wifi_ap_get_sta_list
2. Modify tcpip_adapter_get_station_list to tcpip_adapter_get_sta_list
3. Remove esp_wifi_free_station_list
4. Remove tcpip_adapter_free_station_list
5. Modify related data struct accordingly

components/esp32/include/esp_wifi.h
components/esp32/include/esp_wifi_types.h
components/tcpip_adapter/include/tcpip_adapter.h
components/tcpip_adapter/tcpip_adapter_lwip.c

index 12378f33467044b5546ff2cdca1a19f6cf66e37f..3898bfec7996c22f49979571e7718b0c0f6a9d30 100644 (file)
@@ -198,7 +198,7 @@ esp_err_t esp_wifi_clear_fast_connect(void);
   * @return    ESP_OK : succeed
   * @return    others : fail
   */
-esp_err_t esp_wifi_kick_station(uint16_t aid);
+esp_err_t esp_wifi_kick_sta(uint16_t aid);
 
 /**
   * @brief     Scan all available APs.
@@ -471,14 +471,13 @@ esp_err_t esp_wifi_get_config(wifi_interface_t ifx, wifi_config_t *conf);
   *
   * @attention SSC only API
   *
-  * @param     struct station_info **station :  station list
+  * @param     wifi_sta_list_t *sta:  sta list
   *
   * @return    ESP_OK : succeed
   * @return    others : fail
   */
-esp_err_t esp_wifi_get_station_list(struct station_info **station);
+esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta);
 
-esp_err_t esp_wifi_free_station_list(void);
 
 /**
   * @brief     Set the WiFi API configuration storage type
index b3474769e80ee602a4f91956aae23bdfafed01c8..a607ad9e9482cec0919c73134cecd04fbf282ec7 100644 (file)
@@ -150,10 +150,15 @@ typedef union {
     wifi_sta_config_t sta; /**< configuration of STA */
 } wifi_config_t;
 
-struct station_info {
-    STAILQ_ENTRY(station_info) next;
-    uint8_t bssid[6];
-};
+typedef struct {
+    uint8_t mac[6];  /**< mac address of sta that associated with ESP32 soft-AP */
+}wifi_sta_info_t;
+
+#define ESP_WIFI_MAX_CONN_NUM  8  /**< max number of sta the eSP32 soft-AP can connect */
+typedef struct {
+    wifi_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM+2]; /**< sta list */
+    uint8_t         num; /**< number of sta that associated with ESP32 soft-AP */
+}wifi_sta_list_t;
 
 typedef enum {
     WIFI_STORAGE_FLASH,  /**< all configuration will strore in both memory and flash */
index 5b0fc4c627d1b02e0f27473a7c3e0a02e7322c53..bbcf33727d0e5ab9413ce459d87be4e8a31ed889 100644 (file)
@@ -67,11 +67,15 @@ typedef struct {
 typedef dhcps_lease_t tcpip_adapter_dhcps_lease_t;
 
 #if CONFIG_DHCP_STA_LIST 
-struct station_list {
-    STAILQ_ENTRY(station_list) next;
+typedef struct {
     uint8_t mac[6];
     ip4_addr_t ip;
-};
+}tcpip_adapter_sta_info_t;
+
+typedef struct {
+    tcpip_adapter_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM+2];
+    uint8_t num;
+}tcpip_adapter_sta_list_t;
 #endif
 
 #endif
@@ -359,26 +363,14 @@ wifi_interface_t tcpip_adapter_get_wifi_if(void *dev);
 /**
  * @brief  Get the station information list
  *
- * @note   This function should be called in AP mode and dhcp server started, and the list should
- *         be by using tcpip_adapter_free_sta_list.
- *
- * @param[in]   sta_info: station information
- * @param[out]  sta_list: station information list
+ * @param[in]   wifi_sta_list_t *wifi_sta_list: sta list info
+ * @param[out]  tcpip_adapter_sta_list_t *tcpip_sta_list: sta list info
  *
  * @return ESP_OK
  *         ESP_ERR_TCPIP_ADAPTER_NO_MEM
  *         ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
  */
-esp_err_t tcpip_adapter_get_sta_list(struct station_info *sta_info, struct station_list **sta_list);
-
-/**
- * @brief Free the station information list's memory
- *
- * @param  sta_list: station information list
- *
- * @return ESP_OK
- */
-esp_err_t tcpip_adapter_free_sta_list(struct station_list *sta_list);
+esp_err_t tcpip_adapter_get_sta_list(wifi_sta_list_t *wifi_sta_list, tcpip_adapter_sta_list_t *tcpip_sta_list);
 
 #ifdef __cplusplus
 }
index 12cf05f95f7d7886c7440be068b50df1b5cfc4bb..677368008dff14887844077e2c6db32cbf9dc3ed 100644 (file)
@@ -590,45 +590,17 @@ wifi_interface_t tcpip_adapter_get_wifi_if(void *dev)
     return WIFI_IF_MAX;
 }
 
-esp_err_t tcpip_adapter_get_sta_list(struct station_info *sta_info, struct station_list **sta_list)
+esp_err_t tcpip_adapter_get_sta_list(wifi_sta_list_t *wifi_sta_list, tcpip_adapter_sta_list_t *tcpip_sta_list)
 {
-    struct station_info *info = sta_info;
-    struct station_list *list;
-    STAILQ_HEAD(, station_list) list_head;
+    int i;
 
-    if (sta_list == NULL)
+    if ((wifi_sta_list == NULL) || (tcpip_sta_list == NULL))
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
 
-    STAILQ_INIT(&list_head);
-
-    while (info != NULL) {
-        list = (struct station_list *)malloc(sizeof(struct station_list));
-        memset(list, 0, sizeof (struct station_list));
-
-        if (list == NULL) {
-            return ESP_ERR_TCPIP_ADAPTER_NO_MEM;
-        }
-
-        memcpy(list->mac, info->bssid, 6);
-        dhcp_search_ip_on_mac(list->mac, &list->ip);
-        STAILQ_INSERT_TAIL(&list_head, list, next);
-      
-        info = STAILQ_NEXT(info, next);
-    }
-
-    *sta_list = STAILQ_FIRST(&list_head);
-
-    return ESP_OK;
-}
-
-esp_err_t tcpip_adapter_free_sta_list(struct station_list *sta_list)
-{
-    struct station_list *list = sta_list;
-
-    while (sta_list != NULL) {
-        list = sta_list;
-        sta_list = STAILQ_NEXT(sta_list, next);
-        free(list);
+    memset(tcpip_sta_list, 0, sizeof(tcpip_adapter_sta_list_t));
+    for (i=0; i<wifi_sta_list->num; i++){
+        memcpy(tcpip_sta_list->sta[i].mac, wifi_sta_list->sta[i].mac, 6);
+        dhcp_search_ip_on_mac(tcpip_sta_list->sta[i].mac, &tcpip_sta_list->sta[i].ip);
     }
 
     return ESP_OK;