From: xiaxiaotian Date: Tue, 23 Aug 2016 03:22:58 +0000 (+0800) Subject: 1. Remove ip member of struct station_info X-Git-Tag: v0.9~70^2~4^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef0cd1cde38da2559839c5a1e53317f66393dbf0;p=esp-idf 1. Remove ip member of struct station_info 2. Add struct station_list into tcpip_adapter layer 3. When ap -L cmd is received, get mac address from mac layer first and then search ip address based on mac address on dhcp layer. --- diff --git a/components/esp32/include/esp_wifi.h b/components/esp32/include/esp_wifi.h index bdd125395f..3ad5fcdedf 100755 --- a/components/esp32/include/esp_wifi.h +++ b/components/esp32/include/esp_wifi.h @@ -19,6 +19,7 @@ #include #include "esp_err.h" +#include "rom/queue.h" #ifdef __cplusplus extern "C" { @@ -220,6 +221,15 @@ esp_err_t esp_wifi_set_config(wifi_interface_t ifx, wifi_config_t *conf); esp_err_t esp_wifi_get_config(wifi_interface_t ifx, wifi_config_t *conf); +struct station_info { + STAILQ_ENTRY(station_info) next; + uint8_t bssid[6]; +}; + +esp_err_t esp_wifi_get_station_list(struct station_info **station); + +esp_err_t esp_wifi_free_station_list(void); + typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void* eb); esp_err_t esp_wifi_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn); diff --git a/components/lwip/apps/dhcpserver.c b/components/lwip/apps/dhcpserver.c index 3b9795c5ad..5c4e429c9c 100644 --- a/components/lwip/apps/dhcpserver.c +++ b/components/lwip/apps/dhcpserver.c @@ -1211,6 +1211,25 @@ u32_t wifi_softap_get_dhcps_lease_time(void) // minute { return dhcps_lease_time; } + +/* Search ip address based on mac address */ +bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip) +{ + struct dhcps_pool *pdhcps_pool = NULL; + list_node *pback_node = NULL; + bool ret = false; + + for (pback_node = plist; pback_node != NULL;pback_node = pback_node->pnext) { + pdhcps_pool = pback_node->pnode; + if (memcmp(pdhcps_pool->mac, mac, sizeof(pdhcps_pool->mac)) == 0){ + memcpy(&ip->addr, &pdhcps_pool->ip.addr, sizeof(pdhcps_pool->ip.addr)); + ret = true; + break; + } + } + + return ret; +} #else #include #include @@ -2477,6 +2496,7 @@ bool wifi_softap_set_dhcps_lease_time(u32_t minute) return false; } + #endif /*ifdef LWIP_ESP8266*/ diff --git a/components/lwip/include/lwip/apps/dhcpserver.h b/components/lwip/include/lwip/apps/dhcpserver.h index a0099e32d8..6468109db4 100644 --- a/components/lwip/include/lwip/apps/dhcpserver.h +++ b/components/lwip/include/lwip/apps/dhcpserver.h @@ -77,6 +77,7 @@ extern u32_t dhcps_lease_time; void dhcps_start(struct netif *netif); void dhcps_stop(struct netif *netif); +bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip); #else #include "lwip/opt.h" diff --git a/components/tcpip_adapter/include/tcpip_adapter.h b/components/tcpip_adapter/include/tcpip_adapter.h index 7996632f3d..18622ee50e 100644 --- a/components/tcpip_adapter/include/tcpip_adapter.h +++ b/components/tcpip_adapter/include/tcpip_adapter.h @@ -20,15 +20,26 @@ #include "esp_wifi.h" #define CONFIG_TCPIP_LWIP 1 +#define CONFIG_DHCP_STA_LIST 1 #if CONFIG_TCPIP_LWIP #include "lwip/ip_addr.h" +#include "rom/queue.h" struct ip_info { ip4_addr_t ip; ip4_addr_t netmask; ip4_addr_t gw; }; + +#endif + +#if CONFIG_DHCP_STA_LIST +struct station_list { + STAILQ_ENTRY(station_list) next; + uint8_t mac[6]; + ip4_addr_t ip; +}; #endif #define ESP_ERR_TCPIP_ADAPTER_BASE 0x5000 // base should be moved to esp_err.h @@ -38,6 +49,7 @@ struct ip_info { #define ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED ESP_ERR_TCPIP_ADAPTER_BASE + 0x02 #define ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED ESP_ERR_TCPIP_ADAPTER_BASE + 0x03 #define ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPED ESP_ERR_TCPIP_ADAPTER_BASE + 0x04 +#define ESP_ERR_TCPIP_ADAPTER_NO_MEM ESP_ERR_TCPIP_ADAPTER_BASE + 0x05 /* will add ethernet interface */ typedef enum { @@ -96,5 +108,8 @@ esp_err_t tcpip_adapter_output(tcpip_adapter_if_t tcpip_if, void *buffer, uint16 wifi_interface_t tcpip_adapter_get_wifi_if(void *dev); +esp_err_t tcpip_adapter_get_sta_list(struct station_info *sta_info, struct station_list **sta_list); +esp_err_t tcpip_adapter_free_sta_list(struct station_list *sta_list); + #endif /* _TCPIP_ADAPTER_H_ */ diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index 9b50279c0c..bad5d44228 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -455,4 +455,49 @@ 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) +{ + struct station_info *info = sta_info; + struct station_list *list; + STAILQ_HEAD(, station_list) list_head; + + if (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); + } + + return ESP_OK; +} + #endif