diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 5913fa5c2..f4a122415 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -31,7 +31,7 @@ extern "C" { #include "user_interface.h" #include "cont.h" } -#define LOOP_TASK_PRIORITY 0 +#define LOOP_TASK_PRIORITY 1 #define LOOP_QUEUE_SIZE 1 #define OPTIMISTIC_YIELD_TIME_US 16000 @@ -73,7 +73,7 @@ extern "C" void esp_yield() { } extern "C" void esp_schedule() { - system_os_post(LOOP_TASK_PRIORITY, 0, 0); + ets_post(LOOP_TASK_PRIORITY, 0, 0); } extern "C" void __yield() { @@ -144,7 +144,7 @@ extern "C" void user_init(void) { cont_init(&g_cont); - system_os_task(loop_task, + ets_task(loop_task, LOOP_TASK_PRIORITY, g_loop_queue, LOOP_QUEUE_SIZE); diff --git a/cores/esp8266/core_esp8266_phy.c b/cores/esp8266/core_esp8266_phy.c index ea0beefb1..df8da3ec4 100644 --- a/cores/esp8266/core_esp8266_phy.c +++ b/cores/esp8266/core_esp8266_phy.c @@ -231,6 +231,13 @@ static uint8_t phy_init_data[128] = // force_freq_offset // signed, unit is 8kHz [113] = 0, + + // rf_cal_use_flash + // 0: RF init no RF CAL, using all RF CAL data in flash, it takes about 2ms for RF init + // 1: RF init only do TX power control CAL, others using RF CAL data in flash , it takes about 20ms for RF init + // 2: RF init no RF CAL, using all RF CAL data in flash, it takes about 2ms for RF init (same as 0?!) + // 3: RF init do all RF CAL, it takes about 200ms for RF init + [114] = 2 }; extern int __real_register_chipv6_phy(uint8_t* init_data); diff --git a/libraries/ESP8266WiFi/src/lwip/mem.h b/libraries/ESP8266WiFi/src/lwip/mem.h index 7a4febccb..1d768856c 100644 --- a/libraries/ESP8266WiFi/src/lwip/mem.h +++ b/libraries/ESP8266WiFi/src/lwip/mem.h @@ -51,19 +51,19 @@ typedef size_t mem_size_t; * allow these defines to be overridden. */ #ifndef mem_free -#define mem_free vPortFree +#define mem_free(p) vPortFree(p, "", 0) #endif #ifndef mem_malloc -#define mem_malloc pvPortMalloc +#define mem_malloc(s) pvPortMalloc(s, "", 0) #endif #ifndef mem_calloc -#define mem_calloc pvPortCalloc +#define mem_calloc(s) pvPortCalloc(s, "", 0) #endif #ifndef mem_realloc -#define mem_realloc pvPortRealloc +#define mem_realloc(p, s) pvPortRealloc(p, s, "", 0) #endif #ifndef mem_zalloc -#define mem_zalloc pvPortZalloc +#define mem_zalloc(s) pvPortZalloc(s, "", 0) #endif #ifndef os_malloc diff --git a/platform.txt b/platform.txt index 1ab1d5772..5d335bdda 100644 --- a/platform.txt +++ b/platform.txt @@ -24,7 +24,7 @@ compiler.S.flags=-c -g -x assembler-with-cpp -MMD compiler.c.elf.flags=-g -Os -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy compiler.c.elf.cmd=xtensa-lx106-elf-gcc -compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig -lwps -lcrypto -laxtls +compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lpp -lnet80211 -llwip -lwpa -lcrypto -lmain -lwps -laxtls -lsmartconfig compiler.cpp.cmd=xtensa-lx106-elf-g++ compiler.cpp.flags=-c -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections diff --git a/tools/sdk/changelog.txt b/tools/sdk/changelog.txt index 7f7db13f7..e19249ecf 100644 --- a/tools/sdk/changelog.txt +++ b/tools/sdk/changelog.txt @@ -1,3 +1,83 @@ +esp_iot_sdk_v1.4.0_15_09_18 Release Note +---------------------------------------- +Resolved Issues(Bugs below are eligible for Bug Bounty Program): +1.Espconn may fail to download big chunk of data(FOTA). +2.Invalid TCP data sent issue. +3.Fatal exceptions occur when change WiFi mode in WiFi scan callback. +4.WiFi compatibility problem of special network card. +5.Deep sleep may appear high current under certain circumstances. + +Optimization: +1. Add a new method to check memory leaks (API : system_show_malloc). +2. Add print information when exception happens. +3. Resolve the problem of os_timer_disarm. +4. Optimize DHCP server, add API to set up the lease time of DHCP server. More details are in the “Added APIs”. +5. Add event “EVENT_STAMODE_DHCP_TIMEOUT” for the DHCP timeout handling mechanism. +6. Optimize handling of the reception of data and ZWP message. +7. Add new APIs to support SSL bidirectional authentication. More details are in the “Added APIs”. +8. Add new APIs to set up SSL certificates and encryption keys. API espconn_secure_set_default_certificate and espconn_secure_set_default_private_key should be called to set SSL certificate and secure key, if ESP8266 runs as SSL server. More details are in the “Added APIs”. +9. Optimize the process of FOTA (firmware upgrade through WiFi. +10. Optimize mDNS, and resolve the problem that in certain case the ESP8266 softAP can not work in the sta+AP mode. +11. Release mesh as a lib in the esp_iot_sdk, and do not provide SDK of the mesh version any more. +12. Optimize mesh’s handling of UDP packets. +13. Optimize checking of the validity of the mesh API’s parameters. +14. Add an API to set up the largest hop of mesh. For detailed information, go to mesh instructions. +15. Optimize the process of powering up and booting to shorten booting time by 20 ms. +16. Optimize the function of automatic frequency offset calibration. +17. Optimize the function of sniffer. +18. Strengthen reliability of the checking of beacon timeout. +19.Optimize Wi-Fi event mechanism, and add event “ EVENT_SOFTAPMODE_PROBEREQRECVED”, and reason for a failed connection. +20. Optimize Wi-Fi callback function and strengthen reliability of the software. +21. Add the function of data transferring between stations in the soft-AP mode. +22. Update SmartConfig to the version of 2.5.1. + +23.Update esp_init_data_default.bin. Please use the newest esp_init_data_default.bin when burning. + +24.Modify the espconn pointer in the receive callback of UDP. Parameters remote_ip and remote_port in it are the remote IP and port set by espconn_create. If users want to obtain IP and ports of the current sender, please call espconn_get_connection_info to get relevant information. + + +Added APIs: +1.System API +system_show_malloc : for checking memory leak, to print the memory usage. +2.DHCP server lease time related APIs +wifi_softap_set_dhcps_lease_time:set ESP8266 softAP DHCP server lease time. +wifi_softap_get_dhcps_lease_time:check ESP8266 softAP DHCP server lease time. +wifi_softap_reset_dhcps_lease_time:reset ESP8266 softAP DHCP server lease time which is 120 minutes by default. +3.wifi_station_dhcpc_set_maxtry:set the maximum number that ESP8266 station DHCP client will try to reconnect to the AP. +4.Force sleep APIs +wifi_fpm_open:enable force sleep function. +wifi_fpm_close:disable force sleep function. +wifi_fpm_do_sleep:force ESP8266 enter sleep mode. +wifi_fpm_do_wakeup:wake ESP8266 up from force sleep. +wifi_fpm_set_sleep_type:set sleep type of force sleep function. +wifi_fpm_get_sleep_type:get sleep type of force sleep function. +5.Send packet freedom APIs (to send user-define 802.11 packets) +wifi_register_send_pkt_freedom_cb:register a callback for sending user-define 802.11 packets. +wifi_unregister_send_pkt_freedom_cb:unregister the callback for sending user-define 802.11 packets. +wifi_send_pkt_freedom:send user-define 802.11 packet. +6.RFID LOCP APIs +wifi_rfid_locp_recv_open:enable RFID LOCP to receive WDS packets. +wifi_rfid_locp_recv_close:disable RFID LOCP. +wifi_register_rfid_locp_recv_cb:register a callback of receiving WDS packets. +wifi_unregister_rfid_locp_recv_cb:unregister the callback of receiving WDS packets. +7.Rate Control APIs +wifi_set_user_fixed_rate:set the fixed rate and mask of sending data from ESP8266 +wifi_get_user_fixed_rate:check the fixed rate and mask of ESP8266 +wifi_set_user_sup_rate:set the rate range supported by ESP8266 to limit the rate of sending packets from other devices. +wifi_set_user_rate_limit:limit the rate of sending data from ESP8266. +wifi_set_user_limit_rate_mask:set the interfaces of ESP8266 whose rate of sending packets is limited by wifi_set_user_rate_limit. +wifi_get_user_limit_rate_mask:get the interfaces of ESP8266 whose rate of sending packets is limited by wifi_set_user_rate_limit. +8.Espconn APIs +espconn_sendto:send UDP data. +espconn_secure_cert_req_enable:enable certificates verification function when ESP8266 runs as SSL client. +espconn_secure_cert_req_disable:disable certificates verification function when ESP8266 runs as SSL client. +espconn_secure_set_default_certificate:set the certificate when ESP8266 runs as SSL server. +espconn_secure_set_default_private_key:set the encryption key when ESP8266 runs as SSL server. +9.SmartConfig API +smartconfig_set_type: set the protocol type of SmartConfig. + + + esp_iot_sdk_v1.3.0_15_08_10_p1 Release Note ---------------------------------------- diff --git a/tools/sdk/include/at_custom.h b/tools/sdk/include/at_custom.h new file mode 100644 index 000000000..59f1a578d --- /dev/null +++ b/tools/sdk/include/at_custom.h @@ -0,0 +1,143 @@ + +/* + * custom_at.h + * + * This file is part of Espressif's AT+ command set program. + * Copyright (C) 2013 - 2016, Espressif Systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of version 3 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef CUSTOM_AT_H_ +#define CUSTOM_AT_H_ + +#include "c_types.h" + +typedef struct +{ + char *at_cmdName; + int8_t at_cmdLen; + void (*at_testCmd)(uint8_t id); + void (*at_queryCmd)(uint8_t id); + void (*at_setupCmd)(uint8_t id, char *pPara); + void (*at_exeCmd)(uint8_t id); +}at_funcationType; + +typedef void (*at_custom_uart_rx_intr)(uint8* data,int32 len); + +typedef void (*at_custom_response_func_type)(const char *str); + +extern uint8 at_customLinkMax; + +/** + * @brief Response "OK" to uart. + * @param None + * @retval None + */ +void at_response_ok(void); +/** + * @brief Response "ERROR" to uart. + * @param None + * @retval None + */ +void at_response_error(void); +/** + * @brief Response string. + * It is equivalent to at_port_print,if not call at_register_response_func or call at_register_response_func(NULL); + * It will run custom response function,if call at_register_response_func and parameter is not NULL. + * @param string + * @retval None + */ +void at_response(const char *str); +/** + * @brief register custom response function. + * @param response_func: the function that will run when call at_response + * @retval None + */ +void at_register_response_func(at_custom_response_func_type response_func); +/** + * @brief Task of process command or txdata. + * @param custom_at_cmd_array: the array of at cmd that custom defined + * cmd_num : the num of at cmd that custom defined + * @retval None + */ +void at_cmd_array_regist(at_funcationType *custom_at_cmd_array,uint32 cmd_num); +/** + * @brief get digit form at cmd line.the maybe alter pSrc + * @param p_src: at cmd line string + * result:the buffer to be placed result + * err : err num + * @retval TRUE: + * FALSE: + */ +bool at_get_next_int_dec(char **p_src,int*result,int* err); +/** + * @brief get string form at cmd line.the maybe alter pSrc + * @param p_dest: the buffer to be placed result + * p_src: at cmd line string + * max_len :max len of string excepted to get + * @retval None + */ +int32 at_data_str_copy(char *p_dest, char **p_src, int32 max_len); + +/** + * @brief initialize at module + * @param None + * @retval None + */ +void at_init(void); +/** + * @brief print string to at port + * @param string + * @retval None + */ +void at_port_print(const char *str); +/** + * @brief print custom information when AT+GMR + * @param string + * @retval None + */ +void at_set_custom_info(char* info); +/** + * @brief if current at command is processing,you can call at_enter_special_state, + * then if other comamnd coming,it will return busy. + * @param None + * @retval None + */ +void at_enter_special_state(void); +/** + * @brief + * @param None + * @retval None + */ +void at_leave_special_state(void); +/** + * @brief get at version + * @param None + * @retval at version + * bit24~31: at main version + * bit23~16: at sub version + * bit15~8 : at test version + * bit7~0 : customized version + */ +uint32 at_get_version(void); + +/** + * @brief register custom uart rx interrupt function + * @param rx_func: custom uart rx interrupt function. + * If rx_func is non-void,when rx interrupt comming,it will call rx_func(data,len), + * data is the buffer of data,len is the length of data.Otherwise,it will run AT rx function. + * @retval None + */ +void at_register_uart_rx_intr(at_custom_uart_rx_intr rx_func); +#endif diff --git a/tools/sdk/include/espconn.h b/tools/sdk/include/espconn.h index fc4be05c5..eeb603e99 100644 --- a/tools/sdk/include/espconn.h +++ b/tools/sdk/include/espconn.h @@ -14,6 +14,7 @@ typedef void (* espconn_reconnect_callback)(void *arg, sint8 err); #define ESPCONN_TIMEOUT -3 /* Timeout. */ #define ESPCONN_RTE -4 /* Routing problem. */ #define ESPCONN_INPROGRESS -5 /* Operation in progress */ +#define ESPCONN_MAXNUM -7 /* Total number exceeds the set maximum*/ #define ESPCONN_ABRT -8 /* Connection aborted. */ #define ESPCONN_RST -9 /* Connection reset. */ @@ -21,6 +22,7 @@ typedef void (* espconn_reconnect_callback)(void *arg, sint8 err); #define ESPCONN_CONN -11 /* Not connected. */ #define ESPCONN_ARG -12 /* Illegal argument. */ +#define ESPCONN_IF -14 /* UDP send error */ #define ESPCONN_ISCONN -15 /* Already connected. */ #define ESPCONN_HANDSHAKE -28 /* ssl handshake failed */ @@ -289,6 +291,17 @@ sint8 espconn_send(struct espconn *espconn, uint8 *psent, uint16 length); sint8 espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length); +/****************************************************************************** + * FunctionName : espconn_sendto + * Description : send data for UDP + * Parameters : espconn -- espconn to set for UDP + * psent -- data to send + * length -- length of data to send + * Returns : error +*******************************************************************************/ + +sint16 espconn_sendto(struct espconn *espconn, uint8 *psent, uint16 length); + /****************************************************************************** * FunctionName : espconn_regist_connectcb * Description : used to specify the function that should be called when @@ -419,6 +432,15 @@ typedef void (*dns_found_callback)(const char *name, ip_addr_t *ipaddr, void *ca err_t espconn_gethostbyname(struct espconn *pespconn, const char *hostname, ip_addr_t *addr, dns_found_callback found); +/****************************************************************************** + * FunctionName : espconn_abort + * Description : Forcely abort with host + * Parameters : espconn -- the espconn used to connect with the host + * Returns : result +*******************************************************************************/ + +sint8 espconn_abort(struct espconn *espconn); + /****************************************************************************** * FunctionName : espconn_encry_connect * Description : The function given as connection @@ -502,15 +524,69 @@ bool espconn_secure_ca_enable(uint8 level, uint8 flash_sector ); bool espconn_secure_ca_disable(uint8 level); + +/****************************************************************************** + * FunctionName : espconn_secure_cert_req_enable + * Description : enable the client certificate authenticate and set the flash sector + * as client or server + * Parameters : level -- set for client or server + * 1: client,2:server,3:client and server + * flash_sector -- flash sector for save certificate + * Returns : result true or false +*******************************************************************************/ + +bool espconn_secure_cert_req_enable(uint8 level, uint8 flash_sector ); + +/****************************************************************************** + * FunctionName : espconn_secure_ca_disable + * Description : disable the client certificate authenticate as client or server + * Parameters : level -- set for client or server + * 1: client,2:server,3:client and server + * Returns : result true or false +*******************************************************************************/ + +bool espconn_secure_cert_req_disable(uint8 level); + +/****************************************************************************** + * FunctionName : espconn_secure_set_default_certificate + * Description : Load the certificates in memory depending on compile-time + * and user options. + * Parameters : certificate -- Load the certificate + * length -- Load the certificate length + * Returns : result true or false +*******************************************************************************/ + +bool espconn_secure_set_default_certificate(const uint8* certificate, uint16 length); + +/****************************************************************************** + * FunctionName : espconn_secure_set_default_private_key + * Description : Load the key in memory depending on compile-time + * and user options. + * Parameters : private_key -- Load the key + * length -- Load the key length + * Returns : result true or false +*******************************************************************************/ + +bool espconn_secure_set_default_private_key(const uint8* private_key, uint16 length); + /****************************************************************************** * FunctionName : espconn_secure_accept * Description : The function given as the listen * Parameters : espconn -- the espconn used to listen the connection - * Returns : none + * Returns : result *******************************************************************************/ sint8 espconn_secure_accept(struct espconn *espconn); +/****************************************************************************** + * FunctionName : espconn_secure_accepts + * Description : delete the secure server host + * Parameters : espconn -- the espconn used to listen the connection + * Returns : result +*******************************************************************************/ + +sint8 espconn_secure_delete(struct espconn *espconn); + /****************************************************************************** * FunctionName : espconn_igmp_join * Description : join a multicast group diff --git a/tools/sdk/include/ets_sys.h b/tools/sdk/include/ets_sys.h index 526a24d40..b05533590 100644 --- a/tools/sdk/include/ets_sys.h +++ b/tools/sdk/include/ets_sys.h @@ -145,11 +145,9 @@ inline uint32_t ETS_INTR_PENDING(void) ETS_INTR_DISABLE(ETS_SLC_INUM) -void *pvPortMalloc(size_t xWantedSize) __attribute__((malloc, alloc_size(1))); -void *pvPortRealloc(void* ptr, size_t xWantedSize) __attribute__((alloc_size(2))); -void pvPortFree(void *ptr); -void *vPortMalloc(size_t xWantedSize) __attribute__((malloc, alloc_size(1))); -void vPortFree(void *ptr); +void *pvPortMalloc(size_t xWantedSize, const char* file, int line) __attribute__((malloc, alloc_size(1))); +void *pvPortRealloc(void* ptr, size_t xWantedSize, const char* file, int line) __attribute__((alloc_size(2))); +void vPortFree(void *ptr, const char* file, int line); void *ets_memcpy(void *dest, const void *src, size_t n); void *ets_memset(void *s, int c, size_t n); void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer); @@ -174,5 +172,8 @@ void ets_intr_lock(); void ets_intr_unlock(); int ets_vsnprintf(char * s, size_t n, const char * format, va_list arg) __attribute__ ((format (printf, 3, 0))); int ets_vprintf(const char * format, va_list arg) __attribute__ ((format (printf, 1, 0))); +bool ets_task(ETSTask task, uint8 prio, ETSEvent *queue, uint8 qlen); +bool ets_post(uint8 prio, ETSSignal sig, ETSParam par); + #endif /* _ETS_SYS_H */ diff --git a/tools/sdk/include/mem.h b/tools/sdk/include/mem.h index ac92e74d0..78388a366 100644 --- a/tools/sdk/include/mem.h +++ b/tools/sdk/include/mem.h @@ -1,13 +1,57 @@ #ifndef __MEM_H__ #define __MEM_H__ -//void *pvPortMalloc( size_t xWantedSize ); -//void vPortFree( void *pv ); -//void *pvPortZalloc(size_t size); +/* Note: check_memleak_debug_enable is a weak function inside SDK. + * please copy following codes to user_main.c. +#include "mem.h" -#define os_malloc pvPortMalloc -#define os_free vPortFree -#define os_zalloc pvPortZalloc -#define os_realloc pvPortRealloc +bool ICACHE_FLASH_ATTR check_memleak_debug_enable(void) +{ + return MEMLEAK_DEBUG_ENABLE; +} +*/ + +#ifndef MEMLEAK_DEBUG +#define MEMLEAK_DEBUG_ENABLE 0 +#define os_free(s) vPortFree(s, "", 0) +#define os_malloc(s) pvPortMalloc(s, "", 0) +#define os_calloc(s) pvPortCalloc(s, "", 0); +#define os_realloc(p, s) pvPortRealloc(p, s, "", 0) +#define os_zalloc(s) pvPortZalloc(s, "", 0) +#else +#define MEMLEAK_DEBUG_ENABLE 1 + +#define os_free(s) \ +do{\ + static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ + vPortFree(s, mem_debug_file, __LINE__);\ +}while(0) + +#define os_malloc(s) \ + ({ \ + static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ + pvPortMalloc(s, mem_debug_file, __LINE__); \ + }) + +#define os_calloc(s) \ + ({ \ + static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ + pvPortCalloc(s, mem_debug_file, __LINE__); \ + }) + +#define os_realloc(p, s) \ + ({ \ + static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ + pvPortRealloc(p, s, mem_debug_file, __LINE__); \ + }) + +#define os_zalloc(s) \ + ({ \ + static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \ + pvPortZalloc(s, mem_debug_file, __LINE__); \ + }) #endif + +#endif + diff --git a/tools/sdk/include/mesh.h b/tools/sdk/include/mesh.h new file mode 100644 index 000000000..d00a7c51e --- /dev/null +++ b/tools/sdk/include/mesh.h @@ -0,0 +1,341 @@ +/* + * ESPRSSIF MIT License + * + * Copyright (c) 2015 + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#ifndef __LWIP_API_MESH_H__ +#define __LWIP_API_MESH_H__ + +#include "ip_addr.h" +#include "user_interface.h" +#include "espconn.h" +#ifdef __cplusplus +extern "C" { +#endif + +#define ESP_MESH_GROUP_ID_LEN (6) + +typedef void (* espconn_mesh_callback)(); +typedef void (* espconn_mesh_scan_callback)(void *arg, int8_t status); + +enum mesh_type { + MESH_CLOSE = 0, + MESH_LOCAL, + MESH_ONLINE, + MESH_NONE = 0xFF +}; +/** \defgroup Mesh_APIs Mesh APIs + * @brief Mesh APIs + * + * + * + */ + +/** @addtogroup Mesh_APIs + * @{ + */ + +enum mesh_status { + MESH_DISABLE = 0, + MESH_WIFI_CONN, + MESH_NET_CONN, + MESH_LOCAL_AVAIL, + MESH_ONLINE_AVAIL +}; + +enum mesh_node_type { + MESH_NODE_PARENT = 0, + MESH_NODE_CHILD, + MESH_NODE_ALL +}; + +struct mesh_scan_para_type { + espconn_mesh_scan_callback usr_scan_cb; // scan done callback + uint8_t grp_id[ESP_MESH_GROUP_ID_LEN]; // group id + bool grp_set; // group set +}; + + +/** + * @brief Check whether the IP address is mesh local IP address or not. + * + * @attention 1. The range of mesh local IP address is 2.255.255.* ~ max_hop.255.255.*. + * @attention 2. IP pointer should not be NULL. If the IP pointer is NULL, it will return false. + * + * @param struct ip_addr *ip : IP address + * + * @return true : the IP address is mesh local IP address + * @return false : the IP address is not mesh local IP address + */ +bool espconn_mesh_local_addr(struct ip_addr *ip); + +/** + * @brief Get the information of router used by mesh network. + * + * @attention 1. The function should be called after mesh_enable_done + * + * @param struct station_config *router: router inforamtion + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_get_router(struct station_config *router); + +/** + * @brief Set the information of router used by mesh network. + * + * @attention The function must be called before espconn_mesh_enable. + * + * @param struct station_config *router: router information. + * user should initialize the ssid and password. + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_set_router(struct station_config *router); + +/** + * @brief Set server setup by user. + * + * @attention If users wants to use themself server, they use the function. + * but the function must be called before espconn_mesh_enable. + * at the same time, users need to implement the server. + * + * @param struct ip_addr *ip : ip address of server. + * @param uint16_t port : port used by server. + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_server_init(struct ip_addr *ip, uint16_t port); + +/** + * @brief Get the information of mesh node. + * + * @param enum mesh_node_type typ : mesh node type. + * @param uint8_t **info : the information will be saved in *info. + * @param uint8_t *count : the node count in *info. + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_get_node_info(enum mesh_node_type type, + uint8_t **info, uint8_t *count); + +/** + * @brief Set WiFi cryption algrithm and password for mesh node. + * + * @attention The function must be called before espconn_mesh_enable. + * + * @param AUTH_MODE mode : cryption algrithm (WPA/WAP2/WPA_WPA2). + * @param uint8_t *passwd : password of WiFi. + * @param uint8_t passwd_len : length of password (8 <= passwd_len <= 64). + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_encrypt_init(AUTH_MODE mode, uint8_t *passwd, uint8_t passwd_len); +/** + * @brief Set prefix of SSID for mesh node. + * + * @attention The function must be called before espconn_mesh_enable. + * + * @param uint8_t *prefix : prefix of SSID. + * @param uint8_t prefix_len : length of prefix (0 < passwd_len <= 22). + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_set_ssid_prefix(uint8_t *prefix, uint8_t prefix_len); + +/** + * @brief Set max hop for mesh network. + * + * @attention The function must be called before espconn_mesh_enable. + * + * @param uint8_t max_hops : max hop of mesh network (1 <= max_hops < 10, 4 is recommended). + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_set_max_hops(uint8_t max_hops); + +/** + * @brief Set group ID of mesh node. + * + * @attention The function must be called before espconn_mesh_enable. + * + * @param uint8_t *grp_id : group ID. + * @param uint16_t gid_len: length of group ID, now gid_len = 6. + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_group_id_init(uint8_t *grp_id, uint16_t gid_len); + +/** + * @brief Set the curent device type. + * + * @param uint8_t dev_type : device type of mesh node + * + * @return true : succeed + * @return false : fail + */ +bool espconn_mesh_set_dev_type(uint8_t dev_type); +/** + * @brief Get the curent device type. + * + * @param none + * + * @return device type + */ +uint8_t espconn_mesh_get_dev_type(); + +/** + * @brief Try to establish mesh connection to server. + * + * @attention If espconn_mesh_connect fail, returns non-0 value, there is no connection, so it + * won't enter any espconn callback. + * + * @param struct espconn *usr_esp : the network connection structure, the usr_esp to + * listen to the connection + * + * @return 0 : succeed + * @return Non-0 : error code + * - ESPCONN_RTE - Routing Problem + * - ESPCONN_MEM - Out of memory + * - ESPCONN_ISCONN - Already connected + * - ESPCONN_ARG - Illegal argument, can't find the corresponding connection + * according to structure espconn + */ +int8_t espconn_mesh_connect(struct espconn *usr_esp); + +/** + * @brief Disconnect a mesh connection. + * + * @attention Do not call this API in any espconn callback. If needed, please use system + * task to trigger espconn_mesh_disconnect. + * + * @param struct espconn *usr_esp : the network connection structure + * + * @return 0 : succeed + * @return Non-0 : error code + * - ESPCONN_ARG - illegal argument, can't find the corresponding TCP connection + * according to structure espconn + */ + +int8_t espconn_mesh_disconnect(struct espconn *usr_esp); + +/** + * @brief Get current mesh status. + * + * @param null + * + * @return the current mesh status, please refer to enum mesh_status. + */ +int8_t espconn_mesh_get_status(); + +/** + * @brief Send data through mesh network. + * + * @attention Please call espconn_mesh_sent after espconn_sent_callback of the pre-packet. + * + * @param struct espconn *usr_esp : the network connection structure + * @param uint8 *pdata : pointer of data + * @param uint16 len : data length + * + * @return 0 : succeed + * @return Non-0 : error code + * - ESPCONN_MEM - out of memory + * - ESPCONN_ARG - illegal argument, can't find the corresponding network transmission + * according to structure espconn + * - ESPCONN_MAXNUM - buffer of sending data is full + * - ESPCONN_IF - send UDP data fail + */ +int8_t espconn_mesh_sent(struct espconn *usr_esp, uint8 *pdata, uint16 len); + +/** + * @brief Get max hop of mesh network. + * + * @param null. + * + * @return the current max hop of mesh + */ +uint8_t espconn_mesh_get_max_hops(); + +/** + * @brief To enable mesh network. + * + * @attention 1. the function should be called in user_init. + * @attention 2. if mesh node can not scan the mesh AP, it will be isolate node without trigger enable_cb. + * user can use espconn_mesh_get_status to get current status of node. + * @attention 3. if user try to enable online mesh, but node fails to establish mesh connection + * the node will work with local mesh. + * + * @param espconn_mesh_callback enable_cb : callback function of mesh-enable + * @param enum mesh_type type : type of mesh, local or online. + * + * @return null + */ +void espconn_mesh_enable(espconn_mesh_callback enable_cb, enum mesh_type type); + +/** + * @brief To disable mesh network. + * + * @attention When mesh network is disabed, the system will trigger disable_cb. + * + * @param espconn_mesh_callback disable_cb : callback function of mesh-disable + * @param enum mesh_type type : type of mesh, local or online. + * + * @return null + */ +void espconn_mesh_disable(espconn_mesh_callback disable_cb); + +/** + * @brief To print version of mesh. + * + * @param null + * + * @return null + */ +void espconn_mesh_print_ver(); + +/** + * @brief To get AP around node. + * + * @attention User can get normal AP or mesh AP using the function. + * If user plans to get normal AP, he/she needs to clear grp_set flag in para. + * If user plans to get mesh AP, he/she needs to set grp_set and grp_id; + * + * @param struct mesh_scan_para_type *para : callback function of mesh-disable + * + * @return null + */ +void espconn_mesh_scan(struct mesh_scan_para_type *para); +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tools/sdk/include/smartconfig.h b/tools/sdk/include/smartconfig.h index 6fd86d611..adf91302a 100644 --- a/tools/sdk/include/smartconfig.h +++ b/tools/sdk/include/smartconfig.h @@ -17,6 +17,7 @@ typedef enum { typedef enum { SC_TYPE_ESPTOUCH = 0, SC_TYPE_AIRKISS, + SC_TYPE_ESPTOUCH_AIRKISS, } sc_type; typedef void (*sc_callback_t)(sc_status status, void *pdata); @@ -25,5 +26,6 @@ const char *smartconfig_get_version(void); bool smartconfig_start(sc_callback_t cb, ...); bool smartconfig_stop(void); bool esptouch_set_timeout(uint8 time_s); //15s~255s, offset:45s +bool smartconfig_set_type(sc_type type); #endif diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index 672ee7ad2..99bb01c71 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -132,6 +132,7 @@ enum flash_size_map system_get_flash_size_map(void); void system_phy_set_max_tpw(uint8 max_tpw); void system_phy_set_tpw_via_vdd33(uint16 vdd33); void system_phy_set_rfoption(uint8 option); +void system_phy_set_powerup_option(uint8 option); bool system_param_save_with_protect(uint16 start_sec, void *param, uint16 len); bool system_param_load(uint16 start_sec, uint16 offset, void *param, uint16 len); @@ -140,6 +141,8 @@ void system_soft_wdt_stop(void); void system_soft_wdt_restart(void); void system_soft_wdt_feed(void); +void system_show_malloc(void); + #define NULL_MODE 0x00 #define STATION_MODE 0x01 #define SOFTAP_MODE 0x02 @@ -166,11 +169,14 @@ struct bss_info { uint8 bssid[6]; uint8 ssid[32]; + uint8 ssid_len; uint8 channel; sint8 rssi; AUTH_MODE authmode; uint8 is_hidden; sint16 freq_offset; + sint16 freqcal_val; + uint8 *esp_mesh_ie; }; typedef struct _scaninfo { @@ -240,10 +246,16 @@ uint8 wifi_station_get_ap_info(struct station_config config[]); bool wifi_station_dhcpc_start(void); bool wifi_station_dhcpc_stop(void); enum dhcp_status wifi_station_dhcpc_status(void); +bool wifi_station_dhcpc_set_maxtry(uint8 num); char* wifi_station_get_hostname(void); bool wifi_station_set_hostname(char *name); +int wifi_station_set_cert_key(uint8 *client_cert, int client_cert_len, + uint8 *private_key, int private_key_len, + uint8 *private_key_passwd, int private_key_passwd_len); +void wifi_station_clear_cert_key(void); + struct softap_config { uint8 ssid[32]; uint8 password[64]; @@ -268,6 +280,7 @@ struct station_info { }; struct dhcps_lease { + bool enable; struct ip_addr start_ip; struct ip_addr end_ip; }; @@ -284,8 +297,13 @@ void wifi_softap_free_station_info(void); bool wifi_softap_dhcps_start(void); bool wifi_softap_dhcps_stop(void); + bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please); bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please); +uint32 wifi_softap_get_dhcps_lease_time(void); +bool wifi_softap_set_dhcps_lease_time(uint32 minute); +bool wifi_softap_reset_dhcps_lease_time(void); + enum dhcp_status wifi_softap_dhcps_status(void); bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg); @@ -333,13 +351,22 @@ enum sleep_type { bool wifi_set_sleep_type(enum sleep_type type); enum sleep_type wifi_get_sleep_type(void); +void wifi_fpm_open(void); +void wifi_fpm_close(void); +void wifi_fpm_do_wakeup(void); +sint8 wifi_fpm_do_sleep(uint32 sleep_time_in_us); +void wifi_fpm_set_sleep_type(enum sleep_type type); +enum sleep_type wifi_fpm_get_sleep_type(void); + enum { EVENT_STAMODE_CONNECTED = 0, EVENT_STAMODE_DISCONNECTED, EVENT_STAMODE_AUTHMODE_CHANGE, EVENT_STAMODE_GOT_IP, + EVENT_STAMODE_DHCP_TIMEOUT, EVENT_SOFTAPMODE_STACONNECTED, EVENT_SOFTAPMODE_STADISCONNECTED, + EVENT_SOFTAPMODE_PROBEREQRECVED, EVENT_MAX }; @@ -370,6 +397,9 @@ enum { REASON_BEACON_TIMEOUT = 200, REASON_NO_AP_FOUND = 201, + REASON_AUTH_FAIL = 202, + REASON_ASSOC_FAIL = 203, + REASON_HANDSHAKE_TIMEOUT = 204, }; typedef struct { @@ -407,6 +437,11 @@ typedef struct { uint8 aid; } Event_SoftAPMode_StaDisconnected_t; +typedef struct { + int rssi; + uint8 mac[6]; +} Event_SoftAPMode_ProbeReqRecved_t; + typedef union { Event_StaMode_Connected_t connected; Event_StaMode_Disconnected_t disconnected; @@ -414,6 +449,7 @@ typedef union { Event_StaMode_Got_IP_t got_ip; Event_SoftAPMode_StaConnected_t sta_connected; Event_SoftAPMode_StaDisconnected_t sta_disconnected; + Event_SoftAPMode_ProbeReqRecved_t ap_probereqrecved; } Event_Info_u; typedef struct _esp_event { @@ -430,7 +466,7 @@ typedef enum wps_type { WPS_TYPE_PBC, WPS_TYPE_PIN, WPS_TYPE_DISPLAY, - WPS_TYPE_MAX + WPS_TYPE_MAX, } WPS_TYPE_t; enum wps_cb_status { @@ -447,4 +483,119 @@ bool wifi_wps_start(void); typedef void (*wps_st_cb_t)(int status); bool wifi_set_wps_cb(wps_st_cb_t cb); +typedef void (*freedom_outside_cb_t)(uint8 status); +int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb); +void wifi_unregister_send_pkt_freedom_cb(void); +int wifi_send_pkt_freedom(uint8 *buf, int len, bool sys_seq); + +int wifi_rfid_locp_recv_open(void); +void wifi_rfid_locp_recv_close(void); + +typedef void (*rfid_locp_cb_t)(uint8 *frm, int len, int rssi); +int wifi_register_rfid_locp_recv_cb(rfid_locp_cb_t cb); +void wifi_unregister_rfid_locp_recv_cb(void); + +enum FIXED_RATE { + PHY_RATE_48 = 0x8, + PHY_RATE_24 = 0x9, + PHY_RATE_12 = 0xA, + PHY_RATE_6 = 0xB, + PHY_RATE_54 = 0xC, + PHY_RATE_36 = 0xD, + PHY_RATE_18 = 0xE, + PHY_RATE_9 = 0xF, +}; + +#define FIXED_RATE_MASK_NONE 0x00 +#define FIXED_RATE_MASK_STA 0x01 +#define FIXED_RATE_MASK_AP 0x02 +#define FIXED_RATE_MASK_ALL 0x03 + +int wifi_set_user_fixed_rate(uint8 enable_mask, uint8 rate); +int wifi_get_user_fixed_rate(uint8 *enable_mask, uint8 *rate); + +enum support_rate { + RATE_11B5M = 0, + RATE_11B11M = 1, + RATE_11B1M = 2, + RATE_11B2M = 3, + RATE_11G6M = 4, + RATE_11G12M = 5, + RATE_11G24M = 6, + RATE_11G48M = 7, + RATE_11G54M = 8, + RATE_11G9M = 9, + RATE_11G18M = 10, + RATE_11G36M = 11, +}; + +int wifi_set_user_sup_rate(uint8 min, uint8 max); + +enum RATE_11B_ID { + RATE_11B_B11M = 0, + RATE_11B_B5M = 1, + RATE_11B_B2M = 2, + RATE_11B_B1M = 3, +}; + +enum RATE_11G_ID { + RATE_11G_G54M = 0, + RATE_11G_G48M = 1, + RATE_11G_G36M = 2, + RATE_11G_G24M = 3, + RATE_11G_G18M = 4, + RATE_11G_G12M = 5, + RATE_11G_G9M = 6, + RATE_11G_G6M = 7, + RATE_11G_B5M = 8, + RATE_11G_B2M = 9, + RATE_11G_B1M = 10 +}; + +enum RATE_11N_ID { + RATE_11N_MCS7S = 0, + RATE_11N_MCS7 = 1, + RATE_11N_MCS6 = 2, + RATE_11N_MCS5 = 3, + RATE_11N_MCS4 = 4, + RATE_11N_MCS3 = 5, + RATE_11N_MCS2 = 6, + RATE_11N_MCS1 = 7, + RATE_11N_MCS0 = 8, + RATE_11N_B5M = 9, + RATE_11N_B2M = 10, + RATE_11N_B1M = 11 +}; + +#define RC_LIMIT_11B 0 +#define RC_LIMIT_11G 1 +#define RC_LIMIT_11N 2 +#define RC_LIMIT_P2P_11G 3 +#define RC_LIMIT_P2P_11N 4 +#define RC_LIMIT_NUM 5 + +#define LIMIT_RATE_MASK_NONE 0x00 +#define LIMIT_RATE_MASK_STA 0x01 +#define LIMIT_RATE_MASK_AP 0x02 +#define LIMIT_RATE_MASK_ALL 0x03 + +bool wifi_set_user_rate_limit(uint8 mode, uint8 ifidx, uint8 max, uint8 min); +uint8 wifi_get_user_limit_rate_mask(void); +bool wifi_set_user_limit_rate_mask(uint8 enable_mask); + +enum { + USER_IE_BEACON = 0, + USER_IE_PROBE_REQ, + USER_IE_PROBE_RESP, + USER_IE_ASSOC_REQ, + USER_IE_ASSOC_RESP, + USER_IE_MAX +}; + +typedef void (*user_ie_manufacturer_recv_cb_t)(uint8 type, const uint8 sa[6], const uint8 m_oui[3], uint8 *ie, uint8 ie_len, int rssi); + +bool wifi_set_user_ie(bool enable, uint8 *m_oui, uint8 type, uint8 *user_ie, uint8 len); +int wifi_register_user_ie_manufacturer_recv_cb(user_ie_manufacturer_recv_cb_t cb); +void wifi_unregister_user_ie_manufacturer_recv_cb(void); + #endif diff --git a/tools/sdk/lib/libat.a b/tools/sdk/lib/libat.a index eafb08de0..6ff14e748 100644 Binary files a/tools/sdk/lib/libat.a and b/tools/sdk/lib/libat.a differ diff --git a/tools/sdk/lib/libaxtls.a b/tools/sdk/lib/libaxtls.a index 9e29c802b..edf2b9043 100644 Binary files a/tools/sdk/lib/libaxtls.a and b/tools/sdk/lib/libaxtls.a differ diff --git a/tools/sdk/lib/libcrypto.a b/tools/sdk/lib/libcrypto.a index d24bf9f70..592eb30dc 100644 Binary files a/tools/sdk/lib/libcrypto.a and b/tools/sdk/lib/libcrypto.a differ diff --git a/tools/sdk/lib/libespnow.a b/tools/sdk/lib/libespnow.a index f6952d361..d99b7554f 100644 Binary files a/tools/sdk/lib/libespnow.a and b/tools/sdk/lib/libespnow.a differ diff --git a/tools/sdk/lib/libjson.a b/tools/sdk/lib/libjson.a index 99d4e33b9..ca7f92eee 100644 Binary files a/tools/sdk/lib/libjson.a and b/tools/sdk/lib/libjson.a differ diff --git a/tools/sdk/lib/liblwip.a b/tools/sdk/lib/liblwip.a index ed62c1ff8..d2983951a 100644 Binary files a/tools/sdk/lib/liblwip.a and b/tools/sdk/lib/liblwip.a differ diff --git a/tools/sdk/lib/liblwip_536.a b/tools/sdk/lib/liblwip_536.a deleted file mode 100644 index 46f08d599..000000000 Binary files a/tools/sdk/lib/liblwip_536.a and /dev/null differ diff --git a/tools/sdk/lib/libmain.a b/tools/sdk/lib/libmain.a index e5b1c202a..fa713fe10 100644 Binary files a/tools/sdk/lib/libmain.a and b/tools/sdk/lib/libmain.a differ diff --git a/tools/sdk/lib/libmesh.a b/tools/sdk/lib/libmesh.a new file mode 100644 index 000000000..945325abe Binary files /dev/null and b/tools/sdk/lib/libmesh.a differ diff --git a/tools/sdk/lib/libnet80211.a b/tools/sdk/lib/libnet80211.a index 2051f9471..9dde1dab7 100644 Binary files a/tools/sdk/lib/libnet80211.a and b/tools/sdk/lib/libnet80211.a differ diff --git a/tools/sdk/lib/libphy.a b/tools/sdk/lib/libphy.a index 0f2fdbdb1..5ba5d47d8 100644 Binary files a/tools/sdk/lib/libphy.a and b/tools/sdk/lib/libphy.a differ diff --git a/tools/sdk/lib/libpp.a b/tools/sdk/lib/libpp.a index 5d5b3b776..80d9c3267 100644 Binary files a/tools/sdk/lib/libpp.a and b/tools/sdk/lib/libpp.a differ diff --git a/tools/sdk/lib/libsmartconfig.a b/tools/sdk/lib/libsmartconfig.a index 7fc7b1cff..0c42ff7b3 100644 Binary files a/tools/sdk/lib/libsmartconfig.a and b/tools/sdk/lib/libsmartconfig.a differ diff --git a/tools/sdk/lib/libssl.a b/tools/sdk/lib/libssl.a index 5977a723b..173910c0f 100644 Binary files a/tools/sdk/lib/libssl.a and b/tools/sdk/lib/libssl.a differ diff --git a/tools/sdk/lib/libupgrade.a b/tools/sdk/lib/libupgrade.a index f8ca29228..0eb05af54 100644 Binary files a/tools/sdk/lib/libupgrade.a and b/tools/sdk/lib/libupgrade.a differ diff --git a/tools/sdk/lib/libwpa.a b/tools/sdk/lib/libwpa.a index d22039e98..f45b08de7 100644 Binary files a/tools/sdk/lib/libwpa.a and b/tools/sdk/lib/libwpa.a differ diff --git a/tools/sdk/lib/libwpa2.a b/tools/sdk/lib/libwpa2.a new file mode 100644 index 000000000..a9cc738ab Binary files /dev/null and b/tools/sdk/lib/libwpa2.a differ diff --git a/tools/sdk/lib/libwps.a b/tools/sdk/lib/libwps.a index ea1deebb6..1b36d150c 100644 Binary files a/tools/sdk/lib/libwps.a and b/tools/sdk/lib/libwps.a differ