diff --git a/components/esp_netif/CMakeLists.txt b/components/esp_netif/CMakeLists.txt index a47bcd65d..6155f9579 100644 --- a/components/esp_netif/CMakeLists.txt +++ b/components/esp_netif/CMakeLists.txt @@ -4,6 +4,7 @@ idf_component_register(SRCS "esp_netif_handlers.c" "lwip/esp_netif_lwip.c" "loopback/esp_netif_loopback.c" "lwip/esp_netif_lwip_defaults.c" + "lwip/esp_netif_sta_list.c" INCLUDE_DIRS include PRIV_INCLUDE_DIRS lwip private_include REQUIRES lwip esp_eth tcpip_adapter) diff --git a/components/esp_netif/esp_netif_defaults.c b/components/esp_netif/esp_netif_defaults.c index 67d2410b9..c1e20e201 100644 --- a/components/esp_netif/esp_netif_defaults.c +++ b/components/esp_netif/esp_netif_defaults.c @@ -65,30 +65,3 @@ const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config = { .if_type = ESP_NETIF_TYPE_ETH, .route_prio = 50 }; - -esp_netif_t* esp_netif_create_default_wifi_ap(void) -{ - esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_AP(); - esp_netif_t *netif = esp_netif_new(&cfg); - assert(netif); - esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_AP, netif); - return netif; -} - -esp_netif_t* esp_netif_create_default_wifi_sta(void) -{ - esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_STA(); - esp_netif_t *netif = esp_netif_new(&cfg); - assert(netif); - esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_STA, netif); - return netif; -} - -esp_netif_t* esp_netif_create_default_eth(void * eth_driver) -{ - esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); - esp_netif_t* eth_netif = esp_netif_new(&cfg); - assert(eth_netif); - ESP_ERROR_CHECK(esp_netif_attach(eth_netif, eth_driver)); - return eth_netif; -} \ No newline at end of file diff --git a/components/esp_netif/include/esp_netif.h b/components/esp_netif/include/esp_netif.h index e06a3f583..d2ec9dd50 100644 --- a/components/esp_netif/include/esp_netif.h +++ b/components/esp_netif/include/esp_netif.h @@ -670,7 +670,7 @@ esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif); * * @return Textual description of related interface */ -char *esp_netif_get_ifkey(esp_netif_t *esp_netif); +const char *esp_netif_get_ifkey(esp_netif_t *esp_netif); /** * @brief Returns configured interface type for this esp-netif instance @@ -721,22 +721,8 @@ esp_netif_t* esp_netif_next(esp_netif_t* esp_netif); */ size_t esp_netif_get_nr_of_ifs(void); -// -// 8) MISC: List of STAs -// - /** - * @brief Get IP information for stations connected to the Wi-Fi AP interface - * - * @param[in] wifi_sta_list Wi-Fi station info list, returned from esp_wifi_ap_get_sta_list() - * @param[out] tcpip_sta_list IP layer station info list, corresponding to MAC addresses provided in wifi_sta_list - * - * @return - * - ESP_OK - * - ESP_ERR_ESP_NETIF_NO_MEM - * - ESP_ERR_ESP_NETIF_INVALID_PARAMS + * @} */ -esp_err_t esp_netif_get_sta_list(const wifi_sta_list_t *wifi_sta_list, esp_netif_sta_list_t *tcpip_sta_list); - #endif /* _ESP_NETIF_H_ */ diff --git a/components/esp_netif/include/esp_netif_defaults.h b/components/esp_netif/include/esp_netif_defaults.h index c8b817b1f..c1bc5d1e6 100644 --- a/components/esp_netif/include/esp_netif_defaults.h +++ b/components/esp_netif/include/esp_netif_defaults.h @@ -85,30 +85,4 @@ extern const esp_netif_inherent_config_t _g_esp_netif_inherent_sta_config; extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config; extern const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config; -// -// API for creating default interfaces -// - -/** - * @brief Creates default WIFI AP. In case of any init error this API aborts. - * - * @return pointer to esp-netif instance - */ -esp_netif_t* esp_netif_create_default_wifi_ap(void); - -/** - * @brief Creates default WIFI STA. In case of any init error this API aborts. - * - * @return pointer to esp-netif instance - */ -esp_netif_t* esp_netif_create_default_wifi_sta(void); - -/** - * @brief Creates default ethernet interface. In case of any init error this API aborts. - * - * @return pointer to esp-netif instance - */ -esp_netif_t* esp_netif_create_default_eth(void * eth_driver); - - #endif //_ESP_NETIF_DEFAULTS_H diff --git a/components/esp_netif/include/esp_netif_sta_list.h b/components/esp_netif/include/esp_netif_sta_list.h new file mode 100644 index 000000000..3f672ec6e --- /dev/null +++ b/components/esp_netif/include/esp_netif_sta_list.h @@ -0,0 +1,62 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _ESP_NETIF_STA_LIST_H_ +#define _ESP_NETIF_STA_LIST_H_ + +#include "esp_netif_types.h" + +/** + * @brief station list info element + */ +typedef struct { + uint8_t mac[6]; /**< Station MAC address */ + esp_ip4_addr_t ip; /**< Station assigned IP address */ +} esp_netif_sta_info_t; + +/** + * @brief station list structure + */ +typedef struct { + esp_netif_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]; /**< Connected stations */ + int num; /**< Number of connected stations */ +} esp_netif_sta_list_t; + +/** + * @defgroup ESP_NETIF_STA_LIST ESP-NETIF STA list api + * @brief List of stations for Wi-Fi AP interface + * + */ + +/** @addtogroup ESP_NETIF_STA_LIST + * @{ + */ + +/** + * @brief Get IP information for stations connected to the Wi-Fi AP interface + * + * @param[in] wifi_sta_list Wi-Fi station info list, returned from esp_wifi_ap_get_sta_list() + * @param[out] tcpip_sta_list IP layer station info list, corresponding to MAC addresses provided in wifi_sta_list + * + * @return + * - ESP_OK + * - ESP_ERR_ESP_NETIF_NO_MEM + * - ESP_ERR_ESP_NETIF_INVALID_PARAMS + */ +esp_err_t esp_netif_get_sta_list(const wifi_sta_list_t *wifi_sta_list, esp_netif_sta_list_t *tcpip_sta_list); + +/** + * @} + */ +#endif //_ESP_NETIF_STA_LIST_H_ diff --git a/components/esp_netif/include/esp_netif_types.h b/components/esp_netif/include/esp_netif_types.h index 960df2d88..364b498c5 100644 --- a/components/esp_netif/include/esp_netif_types.h +++ b/components/esp_netif/include/esp_netif_types.h @@ -120,17 +120,8 @@ typedef struct { } ip_event_ap_staipassigned_t; -typedef struct { - uint8_t mac[6]; /**< Station MAC address */ - esp_ip4_addr_t ip; /**< Station assigned IP address */ -} esp_netif_sta_info_t; -typedef struct { - esp_netif_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]; /**< Connected stations */ - int num; /**< Number of connected stations */ -} esp_netif_sta_list_t; - typedef enum esp_netif_flags { ESP_NETIF_DHCPC = 1 << 0, ESP_NETIF_DHCPS = 1 << 1, diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 751b00653..ef22c888b 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -1275,25 +1275,6 @@ esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t ty return esp_netif_lwip_ipc_call(esp_netif_get_dns_info_api, esp_netif, (void *)&dns_param); } -esp_err_t esp_netif_get_sta_list(const wifi_sta_list_t *wifi_sta_list, esp_netif_sta_list_t *netif_sta_list) -{ - ESP_LOGD(TAG, "%s entered", __func__); - - if ((wifi_sta_list == NULL) || (netif_sta_list == NULL)) { - return ESP_ERR_ESP_NETIF_INVALID_PARAMS; - } - - memset(netif_sta_list, 0, sizeof(esp_netif_sta_list_t)); - netif_sta_list->num = wifi_sta_list->num; - for (int i = 0; i < wifi_sta_list->num; i++) { - memcpy(netif_sta_list->sta[i].mac, wifi_sta_list->sta[i].mac, 6); - dhcp_search_ip_on_mac(netif_sta_list->sta[i].mac, (ip4_addr_t*)&netif_sta_list->sta[i].ip); - } - - return ESP_OK; -} - - static void esp_netif_nd6_cb(struct netif *p_netif, uint8_t ip_idex) { ESP_LOGD(TAG, "%s lwip-netif:%p", __func__, p_netif); @@ -1362,7 +1343,7 @@ esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif) return esp_netif->flags; } -char *esp_netif_get_ifkey(esp_netif_t *esp_netif) +const char *esp_netif_get_ifkey(esp_netif_t *esp_netif) { return esp_netif->if_key; } diff --git a/components/esp_netif/lwip/esp_netif_sta_list.c b/components/esp_netif/lwip/esp_netif_sta_list.c new file mode 100644 index 000000000..0bbdcaada --- /dev/null +++ b/components/esp_netif/lwip/esp_netif_sta_list.c @@ -0,0 +1,43 @@ +// Copyright 2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "esp_netif.h" +#include "esp_netif_sta_list.h" +#include "dhcpserver/dhcpserver.h" +#include "esp_log.h" + +#if CONFIG_ESP_NETIF_TCPIP_LWIP + +static const char *TAG = "esp_netif_sta_list"; + +esp_err_t esp_netif_get_sta_list(const wifi_sta_list_t *wifi_sta_list, esp_netif_sta_list_t *netif_sta_list) +{ + ESP_LOGD(TAG, "%s entered", __func__); + + if ((wifi_sta_list == NULL) || (netif_sta_list == NULL)) { + return ESP_ERR_ESP_NETIF_INVALID_PARAMS; + } + + memset(netif_sta_list, 0, sizeof(esp_netif_sta_list_t)); + netif_sta_list->num = wifi_sta_list->num; + for (int i = 0; i < wifi_sta_list->num; i++) { + memcpy(netif_sta_list->sta[i].mac, wifi_sta_list->sta[i].mac, 6); + dhcp_search_ip_on_mac(netif_sta_list->sta[i].mac, (ip4_addr_t*)&netif_sta_list->sta[i].ip); + } + + return ESP_OK; +} + +#endif // CONFIG_ESP_NETIF_TCPIP_LWIP diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index 6566abee7..d638c9b3a 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -63,6 +63,7 @@ #include "esp_wifi_types.h" #include "esp_event.h" #include "esp_private/esp_wifi_private.h" +#include "esp_wifi_default.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_wifi/include/esp_wifi_default.h b/components/esp_wifi/include/esp_wifi_default.h index e6cd40cff..3dfc5a4b5 100644 --- a/components/esp_wifi/include/esp_wifi_default.h +++ b/components/esp_wifi/include/esp_wifi_default.h @@ -47,5 +47,18 @@ esp_err_t esp_wifi_set_default_wifi_ap_handlers(void *esp_netif); */ esp_err_t esp_wifi_clear_default_wifi_driver_and_handlers(void *esp_netif); +/** + * @brief Creates default WIFI AP. In case of any init error this API aborts. + * + * @return pointer to esp-netif instance + */ +esp_netif_t* esp_netif_create_default_wifi_ap(void); + +/** + * @brief Creates default WIFI STA. In case of any init error this API aborts. + * + * @return pointer to esp-netif instance + */ +esp_netif_t* esp_netif_create_default_wifi_sta(void); #endif //_ESP_WIFI_DEFAULT_H diff --git a/components/esp_wifi/src/wifi_default.c b/components/esp_wifi/src/wifi_default.c index 9351172d6..251f12d64 100644 --- a/components/esp_wifi/src/wifi_default.c +++ b/components/esp_wifi/src/wifi_default.c @@ -277,3 +277,21 @@ esp_err_t esp_wifi_clear_default_wifi_driver_and_handlers(void *esp_netif) } return disconnect_and_destroy(esp_netif); } + +esp_netif_t* esp_netif_create_default_wifi_ap(void) +{ + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_AP(); + esp_netif_t *netif = esp_netif_new(&cfg); + assert(netif); + esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_AP, netif); + return netif; +} + +esp_netif_t* esp_netif_create_default_wifi_sta(void) +{ + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_STA(); + esp_netif_t *netif = esp_netif_new(&cfg); + assert(netif); + esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_STA, netif); + return netif; +} \ No newline at end of file diff --git a/components/tcpip_adapter/include/tcpip_adapter_types.h b/components/tcpip_adapter/include/tcpip_adapter_types.h index c2fe0b4c1..e8346125b 100644 --- a/components/tcpip_adapter/include/tcpip_adapter_types.h +++ b/components/tcpip_adapter/include/tcpip_adapter_types.h @@ -17,6 +17,7 @@ #include "lwip/ip_addr.h" #include "dhcpserver/dhcpserver.h" +#include "esp_netif_sta_list.h" // // Define compatible types if tcpip_adapter interface used //