forked from espressif/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.
This commit is contained in:
committed by
Wu Jian Gang
parent
c35b57ac7b
commit
ef0cd1cde3
@@ -19,6 +19,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#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);
|
||||
|
@@ -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 <stdio.h>
|
||||
#include <sys/types.h>
|
||||
@@ -2477,6 +2496,7 @@ bool wifi_softap_set_dhcps_lease_time(u32_t minute)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#endif /*ifdef LWIP_ESP8266*/
|
||||
|
||||
|
||||
|
@@ -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"
|
||||
|
||||
|
@@ -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_ */
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user