tcpip_adapter: typedef clean up
This commit is contained in:
parent
1588d1aa6e
commit
df53d1588a
6 changed files with 81 additions and 112 deletions
|
@ -80,16 +80,16 @@ static esp_err_t system_event_sta_gotip_default(system_event_t *event)
|
||||||
WIFI_API_CALL_CHECK("esp_wifi_set_sta_ip", esp_wifi_set_sta_ip(), ESP_OK);
|
WIFI_API_CALL_CHECK("esp_wifi_set_sta_ip", esp_wifi_set_sta_ip(), ESP_OK);
|
||||||
|
|
||||||
printf("ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR "\n",
|
printf("ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR "\n",
|
||||||
IP2STR(&event->event_info.got_ip.ip),
|
IP2STR(&event->event_info.got_ip.ip_info.ip),
|
||||||
IP2STR(&event->event_info.got_ip.netmask),
|
IP2STR(&event->event_info.got_ip.ip_info.netmask),
|
||||||
IP2STR(&event->event_info.got_ip.gw));
|
IP2STR(&event->event_info.got_ip.ip_info.gw));
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t system_event_ap_start_handle_default(system_event_t *event)
|
esp_err_t system_event_ap_start_handle_default(system_event_t *event)
|
||||||
{
|
{
|
||||||
struct ip_info ap_ip;
|
tcpip_adapter_ip_info_t ap_ip;
|
||||||
uint8_t ap_mac[6];
|
uint8_t ap_mac[6];
|
||||||
|
|
||||||
WIFI_API_CALL_CHECK("esp_wifi_reg_rxcb", esp_wifi_reg_rxcb(WIFI_IF_AP, (wifi_rxcb_t)tcpip_adapter_ap_input), ESP_OK);
|
WIFI_API_CALL_CHECK("esp_wifi_reg_rxcb", esp_wifi_reg_rxcb(WIFI_IF_AP, (wifi_rxcb_t)tcpip_adapter_ap_input), ESP_OK);
|
||||||
|
@ -112,7 +112,7 @@ esp_err_t system_event_ap_stop_handle_default(system_event_t *event)
|
||||||
|
|
||||||
esp_err_t system_event_sta_start_handle_default(system_event_t *event)
|
esp_err_t system_event_sta_start_handle_default(system_event_t *event)
|
||||||
{
|
{
|
||||||
struct ip_info sta_ip;
|
tcpip_adapter_ip_info_t sta_ip;
|
||||||
uint8_t sta_mac[6];
|
uint8_t sta_mac[6];
|
||||||
|
|
||||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(WIFI_IF_STA, sta_mac), ESP_OK);
|
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(WIFI_IF_STA, sta_mac), ESP_OK);
|
||||||
|
@ -142,16 +142,14 @@ esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
|
||||||
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||||
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
|
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
|
||||||
} else if (status == TCPIP_ADAPTER_DHCP_STOPPED) {
|
} else if (status == TCPIP_ADAPTER_DHCP_STOPPED) {
|
||||||
struct ip_info ip_info;
|
tcpip_adapter_ip_info_t sta_ip;
|
||||||
system_event_t evt;
|
system_event_t evt;
|
||||||
|
|
||||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
|
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||||
|
|
||||||
//notify event
|
//notify event
|
||||||
evt.event_id = SYSTEM_EVENT_STA_GOTIP;
|
evt.event_id = SYSTEM_EVENT_STA_GOTIP;
|
||||||
memcpy(&evt.event_info.got_ip.ip, &ip_info.ip, sizeof(evt.event_info.got_ip.ip));
|
memcpy(&evt.event_info.got_ip.ip_info, &sta_ip, sizeof(tcpip_adapter_ip_info_t));
|
||||||
memcpy(&evt.event_info.got_ip.netmask, &ip_info.netmask, sizeof(evt.event_info.got_ip.netmask));
|
|
||||||
memcpy(&evt.event_info.got_ip.gw, &ip_info.gw, sizeof(evt.event_info.got_ip.gw));
|
|
||||||
|
|
||||||
esp_event_send(&evt);
|
esp_event_send(&evt);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +231,7 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
|
||||||
}
|
}
|
||||||
case SYSTEM_EVENT_STA_GOTIP:
|
case SYSTEM_EVENT_STA_GOTIP:
|
||||||
{
|
{
|
||||||
system_event_sta_gotip_t *got_ip;
|
system_event_sta_got_ip_t *got_ip;
|
||||||
got_ip = &event->event_info.got_ip;
|
got_ip = &event->event_info.got_ip;
|
||||||
WIFI_DEBUG("SYSTEM_EVENT_STA_GOTIP\n");
|
WIFI_DEBUG("SYSTEM_EVENT_STA_GOTIP\n");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
|
|
||||||
|
#include "tcpip_adapter.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,10 +44,6 @@ typedef enum {
|
||||||
SYSTEM_EVENT_MAX
|
SYSTEM_EVENT_MAX
|
||||||
} system_event_id_t;
|
} system_event_id_t;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t addr;
|
|
||||||
} esp_ip_addr_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t status; /**< status of scanning APs*/
|
uint32_t status; /**< status of scanning APs*/
|
||||||
uint8_t number;
|
uint8_t number;
|
||||||
|
@ -73,10 +71,8 @@ typedef struct {
|
||||||
} system_event_sta_authmode_change_t;
|
} system_event_sta_authmode_change_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
esp_ip_addr_t ip;
|
tcpip_adapter_ip_info_t ip_info;
|
||||||
esp_ip_addr_t netmask;
|
} system_event_sta_got_ip_t;
|
||||||
esp_ip_addr_t gw;
|
|
||||||
} system_event_sta_gotip_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */
|
uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */
|
||||||
|
@ -98,7 +94,7 @@ typedef union {
|
||||||
system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */
|
system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */
|
||||||
system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */
|
system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */
|
||||||
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
|
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
|
||||||
system_event_sta_gotip_t got_ip;
|
system_event_sta_got_ip_t got_ip;
|
||||||
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
|
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
|
||||||
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
|
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
|
||||||
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 softAP receive probe request packet */
|
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 softAP receive probe request packet */
|
||||||
|
|
|
@ -266,9 +266,9 @@ static u8_t *add_offer_options(u8_t *optptr)
|
||||||
*optptr++ = ip4_addr4(&ipadd);
|
*optptr++ = ip4_addr4(&ipadd);
|
||||||
|
|
||||||
if (dhcps_router_enabled(dhcps_offer)) {
|
if (dhcps_router_enabled(dhcps_offer)) {
|
||||||
struct ip_info if_ip;
|
tcpip_adapter_ip_info_t if_ip;
|
||||||
//bzero(&if_ip, sizeof(struct ip_info));
|
//bzero(&if_ip, sizeof(struct ip_info));
|
||||||
memset(&if_ip , 0x00, sizeof(struct ip_info));
|
memset(&if_ip , 0x00, sizeof(tcpip_adapter_ip_info_t));
|
||||||
|
|
||||||
tcpip_adapter_get_ip_info(WIFI_IF_AP, &if_ip);
|
tcpip_adapter_get_ip_info(WIFI_IF_AP, &if_ip);
|
||||||
|
|
||||||
|
@ -1024,18 +1024,17 @@ static void dhcps_poll_set(u32_t ip)
|
||||||
* : info -- The current ip info
|
* : info -- The current ip info
|
||||||
* Returns : none
|
* Returns : none
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void dhcps_start(struct netif *netif, struct ip_info *info)
|
void dhcps_start(struct netif *netif, ip4_addr_t ip)
|
||||||
{
|
{
|
||||||
struct netif *apnetif = netif;
|
struct netif *apnetif = netif;
|
||||||
|
|
||||||
|
|
||||||
if (apnetif->dhcps_pcb != NULL) {
|
if (apnetif->dhcps_pcb != NULL) {
|
||||||
udp_remove(apnetif->dhcps_pcb);
|
udp_remove(apnetif->dhcps_pcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
pcb_dhcps = udp_new();
|
pcb_dhcps = udp_new();
|
||||||
|
|
||||||
if (pcb_dhcps == NULL || info == NULL) {
|
if (pcb_dhcps == NULL || ip4_addr_isany_val(ip)) {
|
||||||
printf("dhcps_start(): could not obtain pcb\n");
|
printf("dhcps_start(): could not obtain pcb\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,7 +1042,7 @@ void dhcps_start(struct netif *netif, struct ip_info *info)
|
||||||
|
|
||||||
IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255);
|
IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255);
|
||||||
|
|
||||||
server_address = info->ip;
|
server_address.addr = ip.addr;
|
||||||
dhcps_poll_set(server_address.addr);
|
dhcps_poll_set(server_address.addr);
|
||||||
|
|
||||||
client_address_plus.addr = dhcps_poll.start_ip.addr;
|
client_address_plus.addr = dhcps_poll.start_ip.addr;
|
||||||
|
|
|
@ -17,17 +17,6 @@
|
||||||
#include "lwip/ip_addr.h"
|
#include "lwip/ip_addr.h"
|
||||||
//#include "esp_common.h"
|
//#include "esp_common.h"
|
||||||
#define USE_DNS
|
#define USE_DNS
|
||||||
/* Here for now until needed in other places in lwIP */
|
|
||||||
#ifndef isprint
|
|
||||||
#define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up)
|
|
||||||
#define isprint(c) in_range(c, 0x20, 0x7f)
|
|
||||||
#define isdigit(c) in_range(c, '0', '9')
|
|
||||||
#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
|
|
||||||
#define islower(c) in_range(c, 'a', 'z')
|
|
||||||
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LWIP_ESP8266
|
|
||||||
|
|
||||||
typedef struct dhcps_state{
|
typedef struct dhcps_state{
|
||||||
s16_t state;
|
s16_t state;
|
||||||
|
@ -164,6 +153,12 @@ typedef enum
|
||||||
CLASSLESS_ROUTE = 121,
|
CLASSLESS_ROUTE = 121,
|
||||||
} dhcp_msg_option;
|
} dhcp_msg_option;
|
||||||
|
|
||||||
|
/* Defined in esp_misc.h */
|
||||||
|
typedef struct {
|
||||||
|
bool enable;
|
||||||
|
ip4_addr_t start_ip;
|
||||||
|
ip4_addr_t end_ip;
|
||||||
|
} dhcps_lease_t;
|
||||||
|
|
||||||
enum dhcps_offer_option{
|
enum dhcps_offer_option{
|
||||||
OFFER_START = 0x00,
|
OFFER_START = 0x00,
|
||||||
|
@ -188,22 +183,18 @@ typedef struct _list_node{
|
||||||
typedef u32_t dhcps_time_t;
|
typedef u32_t dhcps_time_t;
|
||||||
typedef u8_t dhcps_offer_t;
|
typedef u8_t dhcps_offer_t;
|
||||||
|
|
||||||
/* struct dhcps_lease defined in tcpip_adapter.h */
|
typedef struct {
|
||||||
typedef struct dhcps_lease dhcps_lease_t;
|
|
||||||
|
|
||||||
typedef struct _dhcps_options{
|
|
||||||
dhcps_offer_t dhcps_offer;
|
dhcps_offer_t dhcps_offer;
|
||||||
dhcps_time_t dhcps_time;
|
dhcps_time_t dhcps_time;
|
||||||
dhcps_lease_t dhcps_poll;
|
dhcps_lease_t dhcps_poll;
|
||||||
}dhcps_options_t;
|
} dhcps_options_t;
|
||||||
|
|
||||||
#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)
|
#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)
|
||||||
void dhcps_start(struct netif *netif, struct ip_info *info);
|
|
||||||
|
void dhcps_start(struct netif *netif, ip4_addr_t ip);
|
||||||
void dhcps_stop(struct netif *netif);
|
void dhcps_stop(struct netif *netif);
|
||||||
void *dhcps_option_info(u8_t op_id, u32_t opt_len);
|
void *dhcps_option_info(u8_t op_id, u32_t opt_len);
|
||||||
bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
|
bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#if CONFIG_TCPIP_LWIP
|
#if CONFIG_TCPIP_LWIP
|
||||||
#include "lwip/ip_addr.h"
|
#include "lwip/ip_addr.h"
|
||||||
|
#include "apps/dhcpserver.h"
|
||||||
|
|
||||||
#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
|
#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
|
||||||
ip4_addr2_16(ipaddr), \
|
ip4_addr2_16(ipaddr), \
|
||||||
|
@ -34,22 +35,13 @@
|
||||||
|
|
||||||
#define IPSTR "%d.%d.%d.%d"
|
#define IPSTR "%d.%d.%d.%d"
|
||||||
|
|
||||||
struct ip_info {
|
typedef struct {
|
||||||
ip4_addr_t ip;
|
ip4_addr_t ip;
|
||||||
ip4_addr_t netmask;
|
ip4_addr_t netmask;
|
||||||
ip4_addr_t gw;
|
ip4_addr_t gw;
|
||||||
};
|
} tcpip_adapter_ip_info_t;
|
||||||
|
|
||||||
/* Also used by dhcpserver.h */
|
typedef dhcps_lease_t tcpip_adapter_dhcps_lease_t;
|
||||||
struct dhcps_lease {
|
|
||||||
bool enable;
|
|
||||||
ip4_addr_t start_ip;
|
|
||||||
ip4_addr_t end_ip;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct dhcps_lease tcpip_adapter_dhcps_lease;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if CONFIG_DHCP_STA_LIST
|
#if CONFIG_DHCP_STA_LIST
|
||||||
struct station_list {
|
struct station_list {
|
||||||
|
@ -59,6 +51,8 @@ struct station_list {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ESP_ERR_TCPIP_ADAPTER_BASE 0x5000 // base should be moved to esp_err.h
|
#define ESP_ERR_TCPIP_ADAPTER_BASE 0x5000 // base should be moved to esp_err.h
|
||||||
|
|
||||||
#define ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS ESP_ERR_TCPIP_ADAPTER_BASE + 0x00
|
#define ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS ESP_ERR_TCPIP_ADAPTER_BASE + 0x00
|
||||||
|
@ -83,24 +77,23 @@ typedef enum {
|
||||||
TCPIP_ADAPTER_DHCP_STATUS_MAX
|
TCPIP_ADAPTER_DHCP_STATUS_MAX
|
||||||
} tcpip_adapter_dhcp_status_t;
|
} tcpip_adapter_dhcp_status_t;
|
||||||
|
|
||||||
/*op*/
|
|
||||||
typedef enum{
|
typedef enum{
|
||||||
TCPIP_ADAPTER_OP_START = 0,
|
TCPIP_ADAPTER_OP_START = 0,
|
||||||
TCPIP_ADAPTER_OP_SET,
|
TCPIP_ADAPTER_OP_SET,
|
||||||
TCPIP_ADAPTER_OP_GET,
|
TCPIP_ADAPTER_OP_GET,
|
||||||
TCPIP_ADAPTER_OP_MAX
|
TCPIP_ADAPTER_OP_MAX
|
||||||
} tcpip_adapter_option_mode;
|
} tcpip_adapter_option_mode_t;
|
||||||
|
|
||||||
typedef enum{
|
typedef enum{
|
||||||
TCPIP_ADAPTER_ROUTER_SOLICITATION_ADDRESS = 32,
|
TCPIP_ADAPTER_ROUTER_SOLICITATION_ADDRESS = 32,
|
||||||
TCPIP_ADAPTER_REQUESTED_IP_ADDRESS = 50,
|
TCPIP_ADAPTER_REQUESTED_IP_ADDRESS = 50,
|
||||||
TCPIP_ADAPTER_IP_ADDRESS_LEASE_TIME = 51,
|
TCPIP_ADAPTER_IP_ADDRESS_LEASE_TIME = 51,
|
||||||
TCPIP_ADAPTER_IP_REQUEST_RETRY_TIME = 52,
|
TCPIP_ADAPTER_IP_REQUEST_RETRY_TIME = 52,
|
||||||
} tcpip_adapter_option_id;
|
} tcpip_adapter_option_id_t;
|
||||||
|
|
||||||
void tcpip_adapter_init(void);
|
void tcpip_adapter_init(void);
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct ip_info *info);
|
esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_stop(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_stop(tcpip_adapter_if_t tcpip_if);
|
||||||
|
|
||||||
|
@ -108,9 +101,9 @@ esp_err_t tcpip_adapter_up(tcpip_adapter_if_t tcpip_if);
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if);
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip);
|
esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info);
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip);
|
esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
esp_err_t tcpip_adapter_get_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
|
esp_err_t tcpip_adapter_get_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
|
||||||
|
@ -119,23 +112,17 @@ esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
|
esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
|
||||||
esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_option_mode opt_op, tcpip_adapter_option_id opt_id, void *opt_val, uint32_t opt_len);
|
esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_option_mode_t opt_op, tcpip_adapter_option_id_t opt_id, void *opt_val, uint32_t opt_len);
|
||||||
esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if);
|
||||||
esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if);
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
|
esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
|
||||||
esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode opt_op, tcpip_adapter_option_id opt_id, void *opt_val, uint32_t opt_len);
|
esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode_t opt_op, tcpip_adapter_option_id_t opt_id, void *opt_val, uint32_t opt_len);
|
||||||
esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if);
|
||||||
esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if);
|
esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if);
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void* eb);
|
esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void *eb);
|
||||||
esp_err_t tcpip_adapter_ap_input(void *buffer, uint16_t len, void* eb);
|
esp_err_t tcpip_adapter_ap_input(void *buffer, uint16_t len, void *eb);
|
||||||
|
|
||||||
#if 0
|
|
||||||
//esp_err_t tcpip_dep_input(wifi_interface_t wifi_if, void *buffer, uint16 len);
|
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_output(tcpip_adapter_if_t tcpip_if, void *buffer, uint16_t len);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
wifi_interface_t tcpip_adapter_get_wifi_if(void *dev);
|
wifi_interface_t tcpip_adapter_get_wifi_if(void *dev);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
|
|
||||||
static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX];
|
static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX];
|
||||||
static struct ip_info esp_ip[TCPIP_ADAPTER_IF_MAX];
|
static tcpip_adapter_ip_info_t esp_ip[TCPIP_ADAPTER_IF_MAX];
|
||||||
|
|
||||||
static tcpip_adapter_dhcp_status_t dhcps_status = TCPIP_ADAPTER_DHCP_INIT;
|
static tcpip_adapter_dhcp_status_t dhcps_status = TCPIP_ADAPTER_DHCP_INIT;
|
||||||
static tcpip_adapter_dhcp_status_t dhcpc_status = TCPIP_ADAPTER_DHCP_INIT;
|
static tcpip_adapter_dhcp_status_t dhcpc_status = TCPIP_ADAPTER_DHCP_INIT;
|
||||||
|
@ -53,9 +53,9 @@ void tcpip_adapter_init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct ip_info *info)
|
esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_adapter_ip_info_t *ip_info)
|
||||||
{
|
{
|
||||||
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || mac == NULL || info == NULL) {
|
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || mac == NULL || ip_info == NULL) {
|
||||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,17 +65,17 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
memcpy(esp_netif[tcpip_if]->hwaddr, mac, NETIF_MAX_HWADDR_LEN);
|
memcpy(esp_netif[tcpip_if]->hwaddr, mac, NETIF_MAX_HWADDR_LEN);
|
||||||
netif_add(esp_netif[tcpip_if], &info->ip, &info->netmask, &info->gw, NULL, wlanif_init, tcpip_input);
|
netif_add(esp_netif[tcpip_if], &ip_info->ip, &ip_info->netmask, &ip_info->gw, NULL, wlanif_init, tcpip_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tcpip_if == TCPIP_ADAPTER_IF_AP) {
|
if (tcpip_if == TCPIP_ADAPTER_IF_AP) {
|
||||||
netif_set_up(esp_netif[tcpip_if]);
|
netif_set_up(esp_netif[tcpip_if]);
|
||||||
|
|
||||||
if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) {
|
if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||||
dhcps_start(esp_netif[tcpip_if], info);
|
dhcps_start(esp_netif[tcpip_if], ip_info->ip);
|
||||||
|
|
||||||
printf("dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n",
|
printf("dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n",
|
||||||
IP2STR(&info->ip), IP2STR(&info->netmask), IP2STR(&info->gw));
|
IP2STR(&ip_info->ip), IP2STR(&ip_info->netmask), IP2STR(&ip_info->gw));
|
||||||
|
|
||||||
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
|
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
|
||||||
}
|
}
|
||||||
|
@ -164,37 +164,37 @@ esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if)
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip)
|
esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info)
|
||||||
{
|
{
|
||||||
struct netif *p_netif;
|
struct netif *p_netif;
|
||||||
|
|
||||||
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || if_ip == NULL) {
|
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || ip_info == NULL) {
|
||||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_netif = esp_netif[tcpip_if];
|
p_netif = esp_netif[tcpip_if];
|
||||||
|
|
||||||
if (p_netif != NULL && netif_is_up(p_netif)) {
|
if (p_netif != NULL && netif_is_up(p_netif)) {
|
||||||
ip4_addr_set(&if_ip->ip, ip_2_ip4(&p_netif->ip_addr));
|
ip4_addr_set(&ip_info->ip, ip_2_ip4(&p_netif->ip_addr));
|
||||||
ip4_addr_set(&if_ip->netmask, ip_2_ip4(&p_netif->netmask));
|
ip4_addr_set(&ip_info->netmask, ip_2_ip4(&p_netif->netmask));
|
||||||
ip4_addr_set(&if_ip->gw, ip_2_ip4(&p_netif->gw));
|
ip4_addr_set(&ip_info->gw, ip_2_ip4(&p_netif->gw));
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip4_addr_copy(if_ip->ip, esp_ip[tcpip_if].ip);
|
ip4_addr_copy(ip_info->ip, esp_ip[tcpip_if].ip);
|
||||||
ip4_addr_copy(if_ip->gw, esp_ip[tcpip_if].gw);
|
ip4_addr_copy(ip_info->gw, esp_ip[tcpip_if].gw);
|
||||||
ip4_addr_copy(if_ip->netmask, esp_ip[tcpip_if].netmask);
|
ip4_addr_copy(ip_info->netmask, esp_ip[tcpip_if].netmask);
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip)
|
esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info)
|
||||||
{
|
{
|
||||||
struct netif *p_netif;
|
struct netif *p_netif;
|
||||||
tcpip_adapter_dhcp_status_t status;
|
tcpip_adapter_dhcp_status_t status;
|
||||||
|
|
||||||
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || if_ip == NULL) {
|
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || ip_info == NULL) {
|
||||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,14 +212,14 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ip4_addr_copy(esp_ip[tcpip_if].ip, if_ip->ip);
|
ip4_addr_copy(esp_ip[tcpip_if].ip, ip_info->ip);
|
||||||
ip4_addr_copy(esp_ip[tcpip_if].gw, if_ip->gw);
|
ip4_addr_copy(esp_ip[tcpip_if].gw, ip_info->gw);
|
||||||
ip4_addr_copy(esp_ip[tcpip_if].netmask, if_ip->netmask);
|
ip4_addr_copy(esp_ip[tcpip_if].netmask, ip_info->netmask);
|
||||||
|
|
||||||
p_netif = esp_netif[tcpip_if];
|
p_netif = esp_netif[tcpip_if];
|
||||||
|
|
||||||
if (p_netif != NULL && netif_is_up(p_netif)) {
|
if (p_netif != NULL && netif_is_up(p_netif)) {
|
||||||
netif_set_addr(p_netif, &if_ip->ip, &if_ip->netmask, &if_ip->gw);
|
netif_set_addr(p_netif, &ip_info->ip, &ip_info->netmask, &ip_info->gw);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
@ -265,7 +265,7 @@ esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t mac[6])
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_option_mode opt_op, tcpip_adapter_option_id opt_id, void *opt_val, uint32_t opt_len)
|
esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_option_mode_t opt_op, tcpip_adapter_option_id_t opt_id, void *opt_val, uint32_t opt_len)
|
||||||
{
|
{
|
||||||
void *opt_info = dhcps_option_info(opt_id, opt_len);
|
void *opt_info = dhcps_option_info(opt_id, opt_len);
|
||||||
|
|
||||||
|
@ -313,13 +313,13 @@ esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_option_mode opt_op, tcpip_ada
|
||||||
}
|
}
|
||||||
case REQUESTED_IP_ADDRESS:
|
case REQUESTED_IP_ADDRESS:
|
||||||
{
|
{
|
||||||
struct ip_info info;
|
tcpip_adapter_ip_info_t info;
|
||||||
uint32_t softap_ip = 0;
|
uint32_t softap_ip = 0;
|
||||||
uint32_t start_ip = 0;
|
uint32_t start_ip = 0;
|
||||||
uint32_t end_ip = 0;
|
uint32_t end_ip = 0;
|
||||||
struct dhcps_lease *poll = opt_val;
|
dhcps_lease_t *poll = opt_val;
|
||||||
|
|
||||||
memset(&info, 0x00, sizeof(struct ip_info));
|
memset(&info, 0x00, sizeof(tcpip_adapter_ip_info_t));
|
||||||
tcpip_adapter_get_ip_info(WIFI_IF_AP, &info);
|
tcpip_adapter_get_ip_info(WIFI_IF_AP, &info);
|
||||||
softap_ip = htonl(info.ip.addr);
|
softap_ip = htonl(info.ip.addr);
|
||||||
start_ip = htonl(poll->start_ip.addr);
|
start_ip = htonl(poll->start_ip.addr);
|
||||||
|
@ -377,9 +377,9 @@ esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if)
|
||||||
struct netif *p_netif = esp_netif[tcpip_if];
|
struct netif *p_netif = esp_netif[tcpip_if];
|
||||||
|
|
||||||
if (p_netif != NULL && netif_is_up(p_netif)) {
|
if (p_netif != NULL && netif_is_up(p_netif)) {
|
||||||
struct ip_info default_ip;
|
tcpip_adapter_ip_info_t default_ip;
|
||||||
tcpip_adapter_get_ip_info(WIFI_IF_AP, &default_ip);
|
tcpip_adapter_get_ip_info(WIFI_IF_AP, &default_ip);
|
||||||
dhcps_start(p_netif, &default_ip);
|
dhcps_start(p_netif, default_ip.ip);
|
||||||
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
|
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
|
||||||
TCPIP_ADAPTER_DEBUG("dhcp server start successfully\n");
|
TCPIP_ADAPTER_DEBUG("dhcp server start successfully\n");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
@ -421,7 +421,7 @@ esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if)
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode opt_op, tcpip_adapter_option_id opt_id, void *opt_val, uint32_t opt_len)
|
esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode_t opt_op, tcpip_adapter_option_id_t opt_id, void *opt_val, uint32_t opt_len)
|
||||||
{
|
{
|
||||||
// TODO: when dhcp request timeout,change the retry count
|
// TODO: when dhcp request timeout,change the retry count
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
@ -430,7 +430,7 @@ esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode opt_op, tcpip_ada
|
||||||
static void tcpip_adapter_dhcpc_cb(void)
|
static void tcpip_adapter_dhcpc_cb(void)
|
||||||
{
|
{
|
||||||
struct netif *netif = esp_netif[TCPIP_ADAPTER_IF_STA];
|
struct netif *netif = esp_netif[TCPIP_ADAPTER_IF_STA];
|
||||||
struct ip_info *ip_info = &esp_ip[TCPIP_ADAPTER_IF_STA];
|
tcpip_adapter_ip_info_t *ip_info = &esp_ip[TCPIP_ADAPTER_IF_STA];
|
||||||
system_event_t evt;
|
system_event_t evt;
|
||||||
|
|
||||||
if (!netif) {
|
if (!netif) {
|
||||||
|
@ -450,9 +450,7 @@ static void tcpip_adapter_dhcpc_cb(void)
|
||||||
|
|
||||||
//notify event
|
//notify event
|
||||||
evt.event_id = SYSTEM_EVENT_STA_GOTIP;
|
evt.event_id = SYSTEM_EVENT_STA_GOTIP;
|
||||||
memcpy(&evt.event_info.got_ip.ip, &ip_info->ip, sizeof(evt.event_info.got_ip.ip));
|
memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
|
||||||
memcpy(&evt.event_info.got_ip.netmask, &ip_info->netmask, sizeof(evt.event_info.got_ip.netmask));
|
|
||||||
memcpy(&evt.event_info.got_ip.gw, &ip_info->gw, sizeof(evt.event_info.got_ip.gw));
|
|
||||||
|
|
||||||
esp_event_send(&evt);
|
esp_event_send(&evt);
|
||||||
} else {
|
} else {
|
||||||
|
@ -541,13 +539,13 @@ esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if)
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void* eb)
|
esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void *eb)
|
||||||
{
|
{
|
||||||
wlanif_input(esp_netif[TCPIP_ADAPTER_IF_STA], buffer, len, eb);
|
wlanif_input(esp_netif[TCPIP_ADAPTER_IF_STA], buffer, len, eb);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t tcpip_adapter_ap_input(void *buffer, uint16_t len, void* eb)
|
esp_err_t tcpip_adapter_ap_input(void *buffer, uint16_t len, void *eb)
|
||||||
{
|
{
|
||||||
wlanif_input(esp_netif[TCPIP_ADAPTER_IF_AP], buffer, len, eb);
|
wlanif_input(esp_netif[TCPIP_ADAPTER_IF_AP], buffer, len, eb);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
|
Loading…
Reference in a new issue