Merge wifi commit '87977b92f3e12cfca74cf2e4dea87dc8d60b26fc' into feature/wifi-stage-two

This commit is contained in:
Angus Gratton 2016-09-05 10:42:17 +10:00
commit cb6bd109f2
14 changed files with 1202 additions and 2624 deletions

View File

@ -54,6 +54,7 @@ static esp_err_t system_event_sta_start_handle_default(system_event_t *event);
static esp_err_t system_event_sta_stop_handle_default(system_event_t *event);
static esp_err_t system_event_sta_connected_handle_default(system_event_t *event);
static esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event);
static esp_err_t system_event_sta_gotip_default(system_event_t *event);
static system_event_handle_t g_system_event_handle_table[] = {
{SYSTEM_EVENT_WIFI_READY, NULL},
@ -63,7 +64,7 @@ static system_event_handle_t g_system_event_handle_table[] = {
{SYSTEM_EVENT_STA_CONNECTED, system_event_sta_connected_handle_default},
{SYSTEM_EVENT_STA_DISCONNECTED, system_event_sta_disconnected_handle_default},
{SYSTEM_EVENT_STA_AUTHMODE_CHANGE, NULL},
{SYSTEM_EVENT_STA_GOTIP, NULL},
{SYSTEM_EVENT_STA_GOTIP, system_event_sta_gotip_default},
{SYSTEM_EVENT_AP_START, system_event_ap_start_handle_default},
{SYSTEM_EVENT_AP_STOP, system_event_ap_stop_handle_default},
{SYSTEM_EVENT_AP_STACONNECTED, NULL},
@ -72,6 +73,13 @@ static system_event_handle_t g_system_event_handle_table[] = {
{SYSTEM_EVENT_MAX, NULL},
};
static esp_err_t system_event_sta_gotip_default(system_event_t *event)
{
extern esp_err_t esp_wifi_set_sta_ip(void);
WIFI_API_CALL_CHECK("esp_wifi_set_sta_ip", esp_wifi_set_sta_ip(), ESP_OK);
return ESP_OK;
}
esp_err_t system_event_ap_start_handle_default(system_event_t *event)
{
struct ip_info ap_ip;

View File

@ -48,6 +48,7 @@ typedef struct {
typedef struct {
uint32_t status; /**< status of scanning APs*/
uint8_t number;
uint8_t scan_id;
} system_event_sta_scan_done_t;
typedef struct {

View File

@ -122,6 +122,10 @@ esp_err_t esp_wifi_connect(void);
esp_err_t esp_wifi_disconnect(void);
esp_err_t esp_wifi_clear_fast_connect(void);
esp_err_t esp_wifi_kick_station(uint16_t aid);
typedef struct {
char *ssid; /**< SSID of AP */
uint8_t *bssid; /**< MAC address of AP */
@ -129,7 +133,7 @@ typedef struct {
bool show_hidden; /**< enable to scan AP whose SSID is hidden */
} wifi_scan_config_t;
esp_err_t esp_wifi_scan_start(wifi_scan_config_t *conf);
esp_err_t esp_wifi_scan_start(wifi_scan_config_t *conf, bool block);
esp_err_t esp_wifi_scan_stop(void);
@ -140,7 +144,7 @@ typedef struct {
uint8_t ssid[32]; /**< SSID of AP */
uint8_t primary; /**< channel of AP */
wifi_second_chan_t second; /**< second channel of AP */
char rssi; /**< single strength of AP */
signed char rssi; /**< single strength of AP */
wifi_auth_mode_t authmode; /**< authmode of AP */
}wifi_ap_list_t;
@ -188,7 +192,7 @@ esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]);
typedef void (* wifi_promiscuous_cb_t)(void *buf, uint16_t len);
wifi_promiscuous_cb_t wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
esp_err_t esp_wifi_set_promiscuous(uint8_t enable);
@ -230,10 +234,21 @@ esp_err_t esp_wifi_get_station_list(struct station_info **station);
esp_err_t esp_wifi_free_station_list(void);
typedef enum {
WIFI_STORAGE_RAM,
WIFI_STORAGE_FLASH,
} wifi_storage_t;
esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
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);
esp_err_t esp_wifi_set_auto_connect(bool en);
esp_err_t esp_wifi_get_auto_connect(bool *en);
#ifdef __cplusplus
}
#endif

@ -1 +1 @@
Subproject commit 468c510da96fd7176788fec75fa9ac37bf37ef34
Subproject commit fbb084dacc51f9c02889acb9bd3b4a0a68144fc4

View File

@ -69,12 +69,14 @@ static void esp_wifi_task(void *pvParameters)
#if CONFIG_WIFI_AUTO_CONNECT
wifi_mode_t mode;
bool auto_connect;
err = esp_wifi_get_mode(&mode);
if (err != ESP_OK){
WIFI_DEBUG("esp_wifi_get_mode fail, ret=%d\n", err);
}
if (mode == WIFI_MODE_STA || mode == WIFI_MODE_APSTA) {
err = esp_wifi_get_auto_connect(&auto_connect);
if ((mode == WIFI_MODE_STA || mode == WIFI_MODE_APSTA) && auto_connect) {
err = esp_wifi_connect();
if (err != ESP_OK) {
WIFI_DEBUG("esp_wifi_connect fail, ret=%d\n", err);

View File

@ -62,7 +62,7 @@ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__;
/* global variables */
#ifdef PERF
uint32 g_rx_post_mbox_fail_cnt = 0;
uint32_t g_rx_post_mbox_fail_cnt = 0;
#endif
static tcpip_init_done_fn tcpip_init_done;
static void *tcpip_init_done_arg;

File diff suppressed because it is too large Load Diff

View File

@ -47,221 +47,6 @@ typedef struct dhcps_msg {
u8_t options[312];
}dhcps_msg;
struct dhcps_lease {
bool enable;
ip4_addr_t start_ip;
ip4_addr_t end_ip;
};
enum dhcps_offer_option{
OFFER_START = 0x00,
OFFER_ROUTER = 0x01,
OFFER_END
};
struct dhcps_pool{
ip4_addr_t ip;
u8_t mac[6];
u32_t lease_timer;
};
typedef struct _list_node{
void *pnode;
struct _list_node *pnext;
}list_node;
extern u32_t dhcps_lease_time;
#define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0
#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)
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"
#include "lwip/netif.h"
#include "lwip/udp.h"
/** DHCP DEBUG INFO **/
#define DHCPS_DEBUG 1
#if DHCPS_DEBUG
#define log_info(message, ...) do { \
printf((message), ##__VA_ARGS__); \
printf("\n"); \
} while(0);
#else
#define log_info(message, ...)
#endif
#if (!defined(unlikely))
#define unlikely(Expression) !!(Expression)
#endif
#define REQUIRE_ASSERT(Expression) do{if (!(Expression)) log_info("%d\n", __LINE__);}while(0)
#define REQUIRE_ACTION(Expression,Label,Action) \
do{\
if (unlikely(!(Expression))) \
{\
log_info("%d\n", __LINE__);\
{Action;}\
goto Label;\
}\
}while(0)
#define REQUIRE_NOERROR(Expression,Label) \
do{\
int LocalError;\
LocalError = (int)Expression;\
if (unlikely(LocalError != 0)) \
{\
log_info("%d 0x%x\n", __LINE__, LocalError);\
goto Label;\
}\
}while(0)
#define REQUIRE_NOERROR_ACTION(Expression,Label,Action) \
do{\
int LocalError;\
LocalError = (int)Expression;\
if (unlikely(LocalError != 0)) \
{\
log_info("%d\n", __LINE__);\
{Action;}\
goto Label;\
}\
}while(0)
#define DHCP_OK 0
#define DHCP_FAIL -1
#define DHCP_SERVER_OPENDNS 0xd043dede /* OpenDNS DNS server 208.67.222.222 */
/* DHCP message */
/*
* Code ID of DHCP and BOOTP options
* as defined in RFC 2132
*/
typedef enum
{
DHCP_NONE = 0,
DHCPS_DISCOVER = 1,
DHCPS_OFFER = 2,
DHCPS_REQUEST = 3,
DHCPS_DECLINE = 4,
DHCPS_ACK = 5,
DHCPS_NAK = 6,
DHCPS_RELEASE = 7,
DHCPS_INFORM = 8,
DHCP_FORCE_RENEW = 9,
DHCP_LEASE_QUERY = 10,
DHCP_LEASE_UNASSIGNED = 11,
DHCP_LEASE_UNKNOWN = 12,
DHCP_LEASE_ACTIVE = 13,
} dhcp_msg_type;
typedef enum
{
BOOTPS = 67,
BOOTPC = 68
} ports;
typedef enum
{
BOOTREQUEST = 1,
BOOTREPLY = 2,
} op_types;
typedef enum
{
ETHERNET = 0x01,
ETHERNET_LAN = 0x06,
ETHEFDDI = 0x08,
ETHEIEEE1394 = 0x18
} hardware_types;
typedef enum
{
DHCPS_CHADDR_LEN = 16U,
DHCPS_SNAME_LEN = 64U,
DHCPS_FILE_LEN = 128U,
DHCP_HEADER_SIZE = 236U // without size of options
} head_size;
typedef struct dhcps
{
/** transaction identifier of last sent request */
u32_t xid;
/** incoming msg */
struct dhcps_msg *msg_in;
/** track PCB allocation state */
u8_t pcb_allocated;
/** current DHCP state machine state */
u8_t state;
/** retries of current request */
u8_t tries;
#if LWIP_DHCP_AUTOIP_COOP
u8_t autoip_coop_state;
#endif
u8_t subnet_mask_given;
struct pbuf *p_out; /* pbuf of outcoming msg */
struct dhcp_msg *msg_out; /* outgoing msg */
u16_t options_out_len; /* outgoing msg options length */
u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
u16_t t1_renew_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next renew try */
u16_t t2_rebind_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next rebind try */
u16_t lease_used; /* #ticks with period DHCP_COARSE_TIMER_SECS since last received DHCP ack */
u16_t t0_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for lease time */
ip_addr_t server_ip_addr; /* dhcp server address that offered this lease (ip_addr_t because passed to UDP) */
ip4_addr_t offered_ip_addr;
ip4_addr_t offered_sn_mask;
ip4_addr_t offered_gw_addr;
u32_t offered_t0_lease; /* lease period (in seconds) */
u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
u32_t offered_t2_rebind; /* recommended rebind time (usually 87.5 of lease period) */
#if LWIP_DHCP_BOOTP_FILE
ip_addr_t offered_si_addr;
char boot_file_name[DHCP_FILE_LEN];
#endif /* LWIP_DHCP_BOOTPFILE */
} dhcps;
typedef struct dhcp_message
{
PACK_STRUCT_FLD_8(u8_t op);
PACK_STRUCT_FLD_8(u8_t htype);
PACK_STRUCT_FLD_8(u8_t hlen);
PACK_STRUCT_FLD_8(u8_t hops);
PACK_STRUCT_FIELD(u32_t xid);
PACK_STRUCT_FIELD(u16_t secs);
PACK_STRUCT_FIELD(u16_t flags);
PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr);
PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr);
PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr);
PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr);
PACK_STRUCT_FLD_8(u8_t chaddr[DHCPS_CHADDR_LEN]);
PACK_STRUCT_FLD_8(u8_t sname[DHCPS_SNAME_LEN]);
PACK_STRUCT_FLD_8(u8_t file[DHCPS_FILE_LEN]);
// PACK_STRUCT_FIELD(u32_t cookie);
#define DHCPS_MIN_OPTIONS_LEN 312U
/** make sure user does not configure this too small */
#if ((defined(DHCPS_OPTIONS_LEN)) && (DHCPS_OPTIONS_LEN < DHCPS_MIN_OPTIONS_LEN))
#undef DHCPS_OPTIONS_LEN
#endif
/** allow this to be configured in lwipopts.h, but not too small */
#if (!defined(DHCPS_OPTIONS_LEN))
/** set this to be sufficient for your options in outgoing DHCP msgs */
#define DHCPS_OPTIONS_LEN DHCPS_MIN_OPTIONS_LEN
#endif
PACK_STRUCT_FLD_8(u8_t options[DHCPS_OPTIONS_LEN]);
} dhcp_message;
/** DHCP OPTIONS CODE **/
typedef enum
{
@ -379,117 +164,51 @@ typedef enum
CLASSLESS_ROUTE = 121,
} dhcp_msg_option;
typedef struct dhcp_option
{
uint8_t id; // option id
uint8_t len; // option length
uint8_t data[256]; // option data
STAILQ_ENTRY(dhcp_option) pointers; // pointers, see queue(3)
} dhcp_option;
/* Defined in esp_misc.h */
//struct dhcps_lease {
// bool enable;
// ip4_addr_t start_ip;
// ip4_addr_t end_ip;
//};
typedef STAILQ_HEAD(dhcp_option_list_, dhcp_option) DHCP_OPTION_LIST;
typedef struct dhcp_option_list_ dhcp_option_list;
/*
* Header to manage the database of address bindings.
*/
// static association or dynamic
enum
{
DYNAMIC = 0,
STATIC = 1,
STATIC_OR_DYNAMIC = 2
enum dhcps_offer_option{
OFFER_START = 0x00,
OFFER_ROUTER = 0x01,
OFFER_END
};
// binding status
enum
{
EMPTY = 0,
ASSOCIATED,
PENDINGD,
EXPIRED,
RELEASED
#define DHCPS_MAX_LEASE 0x64
#define DHCPS_LEASE_TIME_DEF (120)
struct dhcps_pool{
ip4_addr_t ip;
u8_t mac[6];
u32_t lease_timer;
};
/*
* IP address used to delimitate an address pool.
*/
typedef struct pool_indexes
{
uint32_t first; // first address of the pool
uint32_t last; // last address of the pool
uint32_t current; // current available address
}pool_indexes;
typedef struct _list_node{
void *pnode;
struct _list_node *pnext;
}list_node;
/*
* The bindings are organized as a double linked list
* using the standard queue(3) library
*/
typedef struct address_binding
{
uint32_t address; // address
uint8_t cident_len; // client identifier len
uint8_t cident[256]; // client identifier
typedef u32_t dhcps_time_t;
typedef u8_t dhcps_offer_t;
typedef struct dhcps_lease dhcps_lease_t;
time_t binding_time; // time of binding
time_t lease_time; // duration of lease
typedef struct _dhcps_options{
dhcps_offer_t dhcps_offer;
dhcps_time_t dhcps_time;
dhcps_lease_t dhcps_poll;
}dhcps_options_t;
int status; // binding status
int is_static; // check if it is a static binding
STAILQ_ENTRY(address_binding) pointers; // list pointers, see queue(3)
}address_binding;
typedef STAILQ_HEAD(binding_list_, address_binding) BINDING_LIST_HEAD;
typedef struct binding_list_ binding_list;
/*
* Global association pool.
*
* The (static or dynamic) associations tables of the DHCP server,
* are maintained in this global structure.
*
* Note: all the IP addresses are in host order,
* to allow an easy manipulation.
*/
typedef struct address_pool
{
uint32_t server_id; // this server id (IP address)
uint32_t netmask; // network mask
uint32_t gateway; // network gateway
char device[16]; // network device to use
pool_indexes indexes; // used to delimitate a pool of available addresses
time_t lease_time; // default lease time
time_t pending_time; // duration of a binding in the pending state
struct udp_pcb *socket; //
bool flags;
dhcp_option_list options; // options for this pool, see queue
binding_list bindings; // associated addresses, see queue(3)
}address_pool;
/*
* Internal representation of a DHCP message,
* with options parsed into a list...
*/
typedef struct dhcps_msg
{
dhcp_message hdr;
dhcp_option_list opts;
} dhcps_msg;
bool dhcps_option_set(u8_t opt_id, void* optarg);
void dhcps_start(struct netif *netif, struct dhcps_lease *lease_pool);
#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)
void dhcps_start(struct netif *netif, struct ip_info *info);
void dhcps_stop(struct netif *netif);
bool dhcps_lease_set(struct dhcps_lease *please);
bool dhcps_lease_get(struct dhcps_lease *please);
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);
#endif
#endif

View File

@ -35,6 +35,7 @@
#define __ARCH_CC_H__
#include <stdint.h>
#include <errno.h>
#include "arch/sys_arch.h"
@ -72,6 +73,4 @@ typedef int sys_prot_t;
#define LWIP_NOASSERT
//#define LWIP_ERROR
#define LWIP_PROVIDE_ERRNO
#endif /* __ARCH_CC_H__ */

View File

@ -221,6 +221,7 @@ extern unsigned long os_random(void);
* TCP_WND: The size of a TCP window. This must be at least
* (2 * TCP_MSS) for things to work well
*/
#define PERF 1
#ifdef PERF
extern unsigned char misc_prof_get_tcpw(void);
extern unsigned char misc_prof_get_tcp_snd_buf(void);
@ -469,7 +470,7 @@ extern unsigned char misc_prof_get_tcp_snd_buf(void);
/**
* SOCKETS_DEBUG: Enable debugging in sockets.c.
*/
#define SOCKETS_DEBUG LWIP_DBG_ON
#define SOCKETS_DEBUG LWIP_DBG_OFF
/**
* ICMP_DEBUG: Enable debugging in icmp.c.
@ -505,15 +506,15 @@ extern unsigned char misc_prof_get_tcp_snd_buf(void);
* DHCP_DEBUG: Enable debugging in dhcp.c.
*/
#define DHCP_DEBUG LWIP_DBG_OFF
#define LWIP_DEBUG 1
#define TCP_DEBUG LWIP_DBG_ON
#define THREAD_SAFE_DEBUG LWIP_DBG_ON
#define LWIP_DEBUG 0
#define TCP_DEBUG LWIP_DBG_OFF
#define THREAD_SAFE_DEBUG LWIP_DBG_OFF
#define LWIP_THREAD_SAFE 1
#define CHECKSUM_CHECK_UDP 0
#define CHECKSUM_CHECK_IP 0
#define HEAP_HIGHWAT 6*1024
#define HEAP_HIGHWAT 20*1024
#define LWIP_NETCONN_FULLDUPLEX 1
#define LWIP_NETCONN_SEM_PER_THREAD 1

View File

@ -501,13 +501,11 @@ static void sys_thread_tls_free(int index, void* data)
if (sem && *sem){
LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem del, i=%d sem=%p\n", index, *sem));
ets_printf("sem del:%p\n", *sem);
vSemaphoreDelete(*sem);
}
if (sem){
LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem pointer del, i=%d sem_p=%p\n", index, sem));
ets_printf("sem pointer del:%p\n", sem);
free(sem);
}
}

View File

@ -66,7 +66,7 @@ static char hostname[16];
static char hostname[16];
#endif
#ifdef PERF
uint32 g_rx_alloc_pbuf_fail_cnt = 0;
uint32_t g_rx_alloc_pbuf_fail_cnt = 0;
#endif
/**

View File

@ -32,6 +32,15 @@ struct ip_info {
ip4_addr_t gw;
};
/* Defined in esp_misc.h */
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
@ -50,6 +59,7 @@ struct station_list {
#define ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED ESP_ERR_TCPIP_ADAPTER_BASE + 0x03
#define ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED ESP_ERR_TCPIP_ADAPTER_BASE + 0x04
#define ESP_ERR_TCPIP_ADAPTER_NO_MEM ESP_ERR_TCPIP_ADAPTER_BASE + 0x05
#define ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPPED ESP_ERR_TCPIP_ADAPTER_BASE + 0x06
/* will add ethernet interface */
typedef enum {
@ -65,6 +75,21 @@ typedef enum {
TCPIP_ADAPTER_DHCP_STATUS_MAX
} tcpip_adapter_dhcp_status_t;
/*op*/
typedef enum{
TCPIP_ADAPTER_OP_START = 0,
TCPIP_ADAPTER_OP_SET,
TCPIP_ADAPTER_OP_GET,
TCPIP_ADAPTER_OP_MAX
} tcpip_adapter_option_mode;
typedef enum{
TCPIP_ADAPTER_ROUTER_SOLICITATION_ADDRESS = 32,
TCPIP_ADAPTER_REQUESTED_IP_ADDRESS = 50,
TCPIP_ADAPTER_IP_ADDRESS_LEASE_TIME = 51,
TCPIP_ADAPTER_IP_REQUEST_RETRY_TIME = 52,
} tcpip_adapter_option_id;
void tcpip_adapter_init(void);
esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct ip_info *info);
@ -86,15 +111,13 @@ esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
#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_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_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_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_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_sta_input(void *buffer, uint16_t len, void* eb);

View File

@ -38,7 +38,7 @@ static tcpip_adapter_dhcp_status_t dhcpc_status = TCPIP_ADAPTER_DHCP_INIT;
static esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif);
#define TCPIP_ADAPTER_DEBUG printf
#define TCPIP_ADAPTER_DEBUG(...)
void tcpip_adapter_init(void)
{
@ -76,8 +76,12 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct
netif_set_up(esp_netif[tcpip_if]);
if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) {
dhcps_start(esp_netif[tcpip_if]);
printf("dhcp server start:(ip: %s, mask: %s, gw: %s)\n", inet_ntoa(info->ip), inet_ntoa(info->netmask), inet_ntoa(info->gw));
dhcps_start(esp_netif[tcpip_if], info);
printf("dhcp server start:(ip: %s, ", inet_ntoa(info->ip));
printf("mask: %s, ", inet_ntoa(info->netmask));
printf("gw: %s)\n", inet_ntoa(info->gw));
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
}
}
@ -130,6 +134,8 @@ esp_err_t tcpip_adapter_up(tcpip_adapter_if_t tcpip_if)
return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
}
/* use last obtained ip, or static ip */
netif_set_addr(esp_netif[tcpip_if], &esp_ip[tcpip_if].ip, &esp_ip[tcpip_if].netmask, &esp_ip[tcpip_if].gw);
netif_set_up(esp_netif[tcpip_if]);
}
@ -151,44 +157,14 @@ esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if)
if (dhcpc_status != TCPIP_ADAPTER_DHCP_STOPPED) {
dhcpc_status = TCPIP_ADAPTER_DHCP_INIT;
}
} else {
netif_set_down(esp_netif[tcpip_if]);
netif_set_addr(esp_netif[tcpip_if], IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY);
}
ip4_addr_set_zero(&esp_ip[tcpip_if].ip);
ip4_addr_set_zero(&esp_ip[tcpip_if].gw);
ip4_addr_set_zero(&esp_ip[tcpip_if].netmask);
netif_set_down(esp_netif[tcpip_if]);
}
return ESP_OK;
}
esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip)
{
struct netif *p_netif;
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || if_ip == NULL) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
p_netif = esp_netif[tcpip_if];
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(&if_ip->netmask, ip_2_ip4(&p_netif->netmask));
ip4_addr_set(&if_ip->gw, ip_2_ip4(&p_netif->gw));
return ESP_OK;
}
ip4_addr_copy(if_ip->ip, esp_ip[tcpip_if].ip);
ip4_addr_copy(if_ip->gw, esp_ip[tcpip_if].gw);
ip4_addr_copy(if_ip->netmask, esp_ip[tcpip_if].netmask);
return ESP_OK;
}
esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif)
{
tcpip_adapter_if_t tcpip_if;
@ -223,6 +199,7 @@ esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif)
memcpy(&evt.event_info.got_ip.ip, &esp_ip[tcpip_if].ip, sizeof(evt.event_info.got_ip.ip));
memcpy(&evt.event_info.got_ip.netmask, &esp_ip[tcpip_if].netmask, sizeof(evt.event_info.got_ip.netmask));
memcpy(&evt.event_info.got_ip.gw, &esp_ip[tcpip_if].gw, sizeof(evt.event_info.got_ip.gw));
esp_event_send(&evt);
printf("ip: %s, ", inet_ntoa(esp_ip[tcpip_if].ip));
@ -236,7 +213,7 @@ esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif)
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_get_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip)
{
struct netif *p_netif;
@ -244,6 +221,46 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
p_netif = esp_netif[tcpip_if];
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(&if_ip->netmask, ip_2_ip4(&p_netif->netmask));
ip4_addr_set(&if_ip->gw, ip_2_ip4(&p_netif->gw));
return ESP_OK;
}
ip4_addr_copy(if_ip->ip, esp_ip[tcpip_if].ip);
ip4_addr_copy(if_ip->gw, esp_ip[tcpip_if].gw);
ip4_addr_copy(if_ip->netmask, esp_ip[tcpip_if].netmask);
return ESP_OK;
}
esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip)
{
struct netif *p_netif;
tcpip_adapter_dhcp_status_t status;
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || if_ip == NULL) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
if (tcpip_if == TCPIP_ADAPTER_IF_AP) {
tcpip_adapter_dhcps_get_status(tcpip_if, &status);
if (status != TCPIP_ADAPTER_DHCP_STOPPED) {
return ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPPED;
}
} else if (tcpip_if == TCPIP_ADAPTER_IF_STA) {
tcpip_adapter_dhcpc_get_status(tcpip_if, &status);
if (status != TCPIP_ADAPTER_DHCP_STOPPED) {
return ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPPED;
}
}
ip4_addr_copy(esp_ip[tcpip_if].ip, if_ip->ip);
ip4_addr_copy(esp_ip[tcpip_if].gw, if_ip->gw);
ip4_addr_copy(esp_ip[tcpip_if].netmask, if_ip->netmask);
@ -297,6 +314,99 @@ esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t mac[6])
}
#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)
{
void *opt_info = dhcps_option_info(opt_id, opt_len);
if (opt_info == NULL || opt_val == NULL) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
if (opt_op == TCPIP_ADAPTER_OP_GET) {
if (dhcps_status == TCPIP_ADAPTER_DHCP_STOPPED) {
return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED;
}
switch (opt_id) {
case IP_ADDRESS_LEASE_TIME:
{
*(uint32_t*)opt_val = *(uint32_t*)opt_info;
break;
}
case REQUESTED_IP_ADDRESS:
{
memcpy(opt_val, opt_info, opt_len);
break;
}
case ROUTER_SOLICITATION_ADDRESS:
{
*(uint8_t *)opt_val = (*(uint8_t *)opt_info) & OFFER_ROUTER;
break;
}
default:
break;
}
} else if (opt_op == TCPIP_ADAPTER_OP_SET) {
if (dhcps_status == TCPIP_ADAPTER_DHCP_STARTED) {
return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED;
}
switch (opt_id) {
case IP_ADDRESS_LEASE_TIME:
{
if (*(uint32_t*)opt_val != 0)
*(uint32_t*)opt_info = *(uint32_t*)opt_val;
else
*(uint32_t*)opt_info = DHCPS_LEASE_TIME_DEF;
break;
}
case REQUESTED_IP_ADDRESS:
{
struct ip_info info;
uint32_t softap_ip = 0;
uint32_t start_ip = 0;
uint32_t end_ip = 0;
struct dhcps_lease *poll = opt_val;
memset(&info, 0x00, sizeof(struct ip_info));
tcpip_adapter_get_ip_info(WIFI_IF_AP, &info);
softap_ip = htonl(info.ip.addr);
start_ip = htonl(poll->start_ip.addr);
end_ip = htonl(poll->end_ip.addr);
/*config ip information can't contain local ip*/
if ((start_ip <= softap_ip) && (softap_ip <= end_ip))
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
/*config ip information must be in the same segment as the local ip*/
softap_ip >>= 8;
if ((start_ip >> 8 != softap_ip)
|| (end_ip >> 8 != softap_ip)) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
if (end_ip - start_ip > DHCPS_MAX_LEASE) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
memcpy(opt_info, opt_val, opt_len);
break;
}
case ROUTER_SOLICITATION_ADDRESS:
{
*(uint8_t *)opt_info = (*(uint8_t *)opt_val) & OFFER_ROUTER;
break;
}
default:
break;
}
} else {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
return ESP_OK;
}
esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status)
{
*status = dhcps_status;
@ -316,7 +426,9 @@ esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if)
struct netif *p_netif = esp_netif[tcpip_if];
if (p_netif != NULL && netif_is_up(p_netif)) {
dhcps_start(p_netif);
struct ip_info default_ip;
tcpip_adapter_get_ip_info(WIFI_IF_AP, &default_ip);
dhcps_start(p_netif, &default_ip);
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
TCPIP_ADAPTER_DEBUG("dhcp server start successfully\n");
return ESP_OK;
@ -358,6 +470,12 @@ esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if)
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)
{
// TODO: when dhcp request timeout,change the retry count
return ESP_OK;
}
esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status)
{
*status = dhcpc_status;
@ -379,9 +497,13 @@ esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if)
if (p_netif != NULL) {
if (netif_is_up(p_netif)) {
TCPIP_ADAPTER_DEBUG("dhcp client init ip/mask/gw to all-0\n");
ip_addr_set_zero(&p_netif->ip_addr);;
ip_addr_set_zero(&p_netif->ip_addr);
ip_addr_set_zero(&p_netif->netmask);
ip_addr_set_zero(&p_netif->gw);
} else {
TCPIP_ADAPTER_DEBUG("dhcp client re init\n");
dhcpc_status = TCPIP_ADAPTER_DHCP_INIT;
return ESP_OK;
}
if (dhcp_start(p_netif) != ERR_OK) {
@ -420,7 +542,7 @@ esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if)
TCPIP_ADAPTER_DEBUG("dhcp client if not ready\n");
return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
}
} else if (dhcps_status == TCPIP_ADAPTER_DHCP_STOPPED) {
} else if (dhcpc_status == TCPIP_ADAPTER_DHCP_STOPPED) {
TCPIP_ADAPTER_DEBUG("dhcp client already stoped\n");
return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED;
}