0
0
Fork 0

Compare commits

...

11 Commits

32 changed files with 1427 additions and 332 deletions

View File

@ -0,0 +1,8 @@
file(GLOB SOURCES ssdp.c
)
idf_component_register(
SRCS ${SOURCES}
INCLUDE_DIRS "."
PRIV_REQUIRES esp_netif memory_pool wt_storage
)

372
components/SSDP/ssdp.c Normal file
View File

@ -0,0 +1,372 @@
#include "ssdp.h"
#include <stdio.h>
#include "esp_log.h"
#include "esp_mac.h"
#include "esp_netif.h"
#include "lwip/err.h"
#include "lwip/sockets.h"
#include "memory_pool.h"
#include "wt_nvs.h"
#define TAG "SSDP"
#define SSDP_PORT 1900
#define SSDP_MULTICAST_TTL 4
#define SSDP_UUID_BASE "9079d7e9-92c6-45b3-aa28-77cdcc"
#define SSDP_MULTICAST_ADDR "239.255.255.250"
#define HEADER_SEARCH "M-SEARCH"
#define SSDP_DEVICE_TYPE "urn:schemas-upnp-org:device:Basic:1"
#define SSDP_MODEL_NAME "wireless-proxy"
#define SSDP_DEFAULT_FRIENDLY_NAME "允斯调试器"
#define SSDP_MANUFACTURER "允斯工作室"
#ifndef SSDP_MODEL_URL
#define SSDP_MODEL_URL "https://yunsi.studio/"
#endif
static struct ssdp_ctx_t {
TaskHandle_t ssdp_service_task;
ip4_addr_t ip;
ip4_addr_t gw;
uint8_t uuid_end[3]; /* actually use MAC[3:5] */
char friendly_name[32];
} ssdp_ctx;
static volatile uint8_t ssdp_running = false;
static int ssdp_socket = -1;
static void ssdp_service_task(void *pvParameters);
static int ssdp_handle_data(int sock, in_addr_t remote_addr, uint16_t remote_port,
char *buf, int len);
static int ssdp_get_friendly_name();
static int create_ssdp_socket(int *sock)
{
int err;
*sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
if (*sock < 0) {
ESP_LOGE(TAG, "Failed to create socket. Error %d", errno);
return -1;
}
int opt = 1;
if (setsockopt(*sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) != 0) {
ESP_LOGE(TAG, "setsockopt SO_REUSEADDR failed %d\n", errno);
goto err;
}
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = htons(SSDP_PORT),
.sin_addr.s_addr = htonl(INADDR_ANY)
};
err = bind(*sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
if (err < 0) {
ESP_LOGE(TAG, "Failed to bind socket. Error %d", errno);
goto err;
}
/* Multicast TTL (independent to normal interface TTL)
* should be set to small value like 2~4 */
opt = SSDP_MULTICAST_TTL;
if (setsockopt(*sock, IPPROTO_IP, IP_MULTICAST_TTL, &opt, sizeof(opt)) < 0) {
ESP_LOGE(TAG, "Failed to set IP_MULTICAST_TTL. Error %d", errno);
err = errno;
goto err;
}
/* Receive multicast packet sent from this device,
* useful when other service need to be aware of multicast notification */
opt = 0;
if (setsockopt(*sock, IPPROTO_IP, IP_MULTICAST_LOOP, &opt, sizeof(opt)) < 0) {
ESP_LOGE(TAG, "Failed to unset IP_MULTICAST_LOOP. Error %d", errno);
err = errno;
goto err;
}
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr(SSDP_MULTICAST_ADDR);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(*sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
perror("Adding to multicast group failed");
goto err;
}
return 0;
err:
close(*sock);
return -1;
}
static int ssdp_send_notify(int sock, char *buf, int buf_len)
{
int msg_len = snprintf(
buf, buf_len,
"NOTIFY * HTTP/1.1\r\n"
"HOST: 239.255.255.250:1900\r\n"
"NTS: ssdp:alive\r\n"
"NT: upnp:rootdevice\r\n"
"CACHE-CONTROL: max-age=3600\r\n"
"SERVER: FreeRTOS/v10 UPnP/1.1 product/version\r\n"
"USN: uuid:"SSDP_UUID_BASE"%02x%02x%02x::upnp:rootdevice\r\n"
"LOCATION: http://%s:%u/SSDP.xml\r\n",
ssdp_ctx.uuid_end[0], ssdp_ctx.uuid_end[1], ssdp_ctx.uuid_end[2],
ip4addr_ntoa((const ip4_addr_t *)&ssdp_ctx.ip), 80
);
buf[msg_len] = '\0';
struct sockaddr_in dest_addr;
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(SSDP_PORT);
dest_addr.sin_addr.s_addr = inet_addr(SSDP_MULTICAST_ADDR);
int err = sendto(sock, buf, msg_len, 0,
(struct sockaddr *)&dest_addr, sizeof(dest_addr));
if (err < 0) {
ESP_LOGE(TAG, "IPV4 sendto failed. errno: %d", errno);
return errno;
}
return 0;
}
static int ssdp_send_response(int sock, in_addr_t remote_addr, uint16_t remote_port, char *buf, int buf_len)
{
int msg_len = snprintf(
buf, buf_len,
"HTTP/1.1 200 OK\r\n"
"EXT:\r\n"
"ST: ""upnp:rootdevice""\r\n"
"CACHE-CONTROL: max-age=3600\r\n"
"SERVER: FreeRTOS/v10 UPnP/1.1 product/version\r\n"
"USN: uuid:"SSDP_UUID_BASE"%02x%02x%02x" /* MAC=UUID */
"::""upnp:rootdevice""\r\n"
"LOCATION: http://%s:%u/SSDP.xml\r\n" /* ip:port */
"\r\n",
ssdp_ctx.uuid_end[0], ssdp_ctx.uuid_end[1], ssdp_ctx.uuid_end[2], /* MAC=UUID */
ip4addr_ntoa((const ip4_addr_t *)&ssdp_ctx.ip), 80 /* ip:port */
);
buf[msg_len] = '\0';
struct sockaddr_in dest_addr;
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = remote_port;
dest_addr.sin_addr.s_addr = remote_addr;
int err = sendto(sock, buf, msg_len, 0,
(struct sockaddr *)&dest_addr, sizeof(dest_addr));
if (err < 0) {
ESP_LOGE(TAG, "IPV4 sendto failed. errno: %d", errno);
return errno;
}
return 0;
}
static int ssdp_handle_data(int sock, in_addr_t remote_addr, uint16_t remote_port,
char *buf, int len)
{
/* on M-SEARCH: send RESPONSE anyway (even if this device doesn't match search type)
* on NOTIFY : ignore
* on RESPONSE: HTTP/1.1 200 OK : ignore
* */
if (memcmp(buf, HEADER_SEARCH, strlen(HEADER_SEARCH)) != 0) {
return 0;
}
return ssdp_send_response(sock, remote_addr, remote_port, buf, len);
}
static void ssdp_service_handle_socket()
{
char *buf = memory_pool_get(portMAX_DELAY);
while (1) {
struct sockaddr_storage remote_addr;
socklen_t socklen = sizeof(remote_addr);
int len = recvfrom(ssdp_socket, buf, memory_pool_get_buf_size(), 0,
(struct sockaddr *)&remote_addr, &socklen);
if (len < 0) {
ESP_LOGE(TAG, "multicast recvfrom failed: errno %d", errno);
break;
} else if (len == 0) {
continue;
}
buf[len] = '\0';
uint16_t remote_port = ((struct sockaddr_in *)&remote_addr)->sin_port;
in_addr_t remote_ip = ((struct sockaddr_in *)&remote_addr)->sin_addr.s_addr;
ssdp_handle_data(ssdp_socket, remote_ip, remote_port,
buf, memory_pool_get_buf_size());
}
memory_pool_put(buf);
}
static void ssdp_service_task(void *pvParameters)
{
ESP_LOGD(TAG, "ssdp_service_task()");
ssdp_running = true;
int err;
while (ssdp_running) {
err = create_ssdp_socket(&ssdp_socket);
if (err) {
ssdp_socket = -1;
ESP_LOGE(TAG, "Failed to create multicast socket");
vTaskDelay(pdMS_TO_TICKS(1000));
continue;
}
ssdp_service_handle_socket();
ESP_LOGE(TAG, "Shutting down socket and restarting...");
shutdown(ssdp_socket, 0);
close(ssdp_socket);
ssdp_socket = -1;
}
vTaskDelete(NULL);
}
/*
* Global Functions
*/
esp_err_t ssdp_init()
{
ssdp_ctx.ssdp_service_task = NULL;
ssdp_socket = -1;
ssdp_running = false;
ssdp_ctx.ip.addr = 0;
ssdp_ctx.gw.addr = 0;
uint8_t mac[6];
esp_base_mac_addr_get(mac);
for (int i = 0; i < 3; ++i) {
/* use MAC last 3 bytes, as the first 3 bytes do not change */
ssdp_ctx.uuid_end[i] = mac[i + 3];
}
/* get name from nvs, if failed: use default */
if (ssdp_get_friendly_name())
ssdp_set_friendly_name(SSDP_DEFAULT_FRIENDLY_NAME);
return ESP_OK;
}
esp_err_t ssdp_start()
{
if (ssdp_socket != -1 || ssdp_ctx.ssdp_service_task) {
ESP_LOGE(TAG, "SSDP already started");
return ESP_ERR_INVALID_STATE;
}
/* get a default ip from available netif */
esp_err_t err;
esp_netif_ip_info_t ip_info = {0};
esp_netif_t *netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
if (netif == NULL) {
netif = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF");
}
if (netif == NULL) {
netif = esp_netif_get_handle_from_ifkey("ETH_DEF");
}
err = esp_netif_get_ip_info(netif, &ip_info);
if (err != ESP_OK) {
/* fallback to 0.0.0.0 default IP */
ssdp_ctx.ip.addr = 0;
ssdp_ctx.gw.addr = 0;
} else {
ssdp_ctx.ip.addr = ip_info.ip.addr;
ssdp_ctx.gw.addr = ip_info.gw.addr;
}
BaseType_t res = xTaskCreatePinnedToCore(
ssdp_service_task, "ssdp task", 4096, NULL,
tskIDLE_PRIORITY + 1, &ssdp_ctx.ssdp_service_task,
0);
if (res != pdPASS || ssdp_ctx.ssdp_service_task == NULL) {
ESP_LOGE(TAG, "Failed to create task");
err = ESP_FAIL;
}
return err;
}
void ssdp_stop()
{
ESP_LOGD(TAG, "Stopping SSDP");
if (ssdp_socket != -1) {
shutdown(ssdp_socket, 0);
close(ssdp_socket);
ssdp_socket = -1;
}
ssdp_running = false;
ssdp_ctx.ssdp_service_task = NULL;
}
#define WT_NVS_KEY_SSDP_FRIENDLY_NAME 0x80
#define WT_NVS_NS_NETWORK "net"
int ssdp_get_friendly_name()
{
return wt_nvs_get_once(WT_NVS_NS_NETWORK, WT_NVS_KEY_SSDP_FRIENDLY_NAME,
ssdp_ctx.friendly_name, sizeof(ssdp_ctx.friendly_name));
}
int ssdp_set_friendly_name(const char *name)
{
snprintf(ssdp_ctx.friendly_name, sizeof(ssdp_ctx.friendly_name),
"%s-%02X-%02X", name, ssdp_ctx.uuid_end[1], ssdp_ctx.uuid_end[2]);
ssdp_ctx.friendly_name[sizeof(ssdp_ctx.friendly_name) - 1] = '\0';
return 0;
}
int ssdp_set_ip_gw(const uint32_t *ip, const uint32_t *gw)
{
ssdp_ctx.ip.addr = *ip;
ssdp_ctx.gw.addr = *gw;
char *buf = memory_pool_get(portMAX_DELAY);
/* send a ssdp notification to the new connected network */
ssdp_send_notify(ssdp_socket, buf, memory_pool_get_buf_size());
memory_pool_put(buf);
return 0;
}
int ssdp_get_schema_str(char *buf, uint32_t buf_len)
{
int write_size = snprintf(
buf, buf_len - 1,
"<?xml version=\"1.0\"?>"
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\">"
"<specVersion>"
"<major>1</major>"
"<minor>0</minor>"
"</specVersion>"
"<URLBase>http://%s:%u</URLBase>" /* ip, port */
"<device>"
"<friendlyName>%s</friendlyName>" /* friendly_name */
"<deviceType>"SSDP_DEVICE_TYPE"</deviceType>"
"<presentationURL>/</presentationURL>"
"<serialNumber>0000</serialNumber>"
"<modelName>"SSDP_MODEL_NAME"</modelName>"
"<modelNumber>0000</modelNumber>"
"<modelURL>"SSDP_MODEL_URL"</modelURL>"
"<manufacturer>"SSDP_MANUFACTURER"</manufacturer>"
"<manufacturerURL>https://yunsi.studio</manufacturerURL>"
"</device>"
"</root>\r\n"
"\r\n",
ip4addr_ntoa((const ip4_addr_t *)&ssdp_ctx.ip), 80, /* ip, port */
ssdp_ctx.friendly_name /* friendly_name */
);
buf[write_size] = '\0';
return write_size < buf_len - 1;
}

15
components/SSDP/ssdp.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef SSDP_HEADER_GUARD
#define SSDP_HEADER_GUARD
#include <esp_err.h>
#include <stdint.h>
esp_err_t ssdp_init();
esp_err_t ssdp_start();
void ssdp_stop();
int ssdp_set_friendly_name(const char *name);
int ssdp_set_ip_gw(const uint32_t *ip, const uint32_t *gw);
int ssdp_get_schema_str(char *buf, uint32_t buf_len);
#endif /* SSDP_HEADER_GUARD */

View File

@ -20,6 +20,7 @@
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/sockets.h" #include "lwip/sockets.h"
#include "websocket_server.h"
extern TaskHandle_t kDAPTaskHandle; extern TaskHandle_t kDAPTaskHandle;
extern int kRestartDAPHandle; extern int kRestartDAPHandle;
@ -128,9 +129,7 @@ void tcp_server_task(void *pvParameters)
usbip_state = WAIT_IMPORT; usbip_state = WAIT_IMPORT;
usbip_worker(tcp_rx_buffer, sizeof(tcp_rx_buffer), &usbip_state); usbip_worker(tcp_rx_buffer, sizeof(tcp_rx_buffer), &usbip_state);
} else if (header == 0x47455420) { // string "GET " } else if (header == 0x47455420) { // string "GET "
#ifdef CONFIG_USE_WEBSOCKET_DAP
websocket_worker(kSock, tcp_rx_buffer, sizeof(tcp_rx_buffer)); websocket_worker(kSock, tcp_rx_buffer, sizeof(tcp_rx_buffer));
#endif
} else { } else {
printf("Unknown protocol\n"); printf("Unknown protocol\n");
} }

View File

@ -8,7 +8,7 @@
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/queue.h> #include <freertos/queue.h>
#define BUFFER_NR 8 #define BUFFER_NR 7
#define BUFFER_SZ 2048 #define BUFFER_SZ 2048
static uint8_t buf[BUFFER_NR][BUFFER_SZ]; static uint8_t buf[BUFFER_NR][BUFFER_SZ];

View File

@ -8,3 +8,4 @@ phy_init,data,phy , ,4K ,
none0 ,0x40,0x00 , ,0k , none0 ,0x40,0x00 , ,0k ,
ota_0 ,app ,ota_0 ,0x20000 ,0x1B0000, ota_0 ,app ,ota_0 ,0x20000 ,0x1B0000,
wt_nvs ,data,nvs , ,64K , wt_nvs ,data,nvs , ,64K ,
coredump,data,coredump,0x390000,64K ,
1 # Name , Type , SubType , Offset , Size , Flags
8 none0 ,0x40,0x00 , ,0k , none0 ,0x40,0x00 , ,0k ,
9 ota_0 ,app ,ota_0,0x20000 ,0x1B0000, ota_0 ,app ,ota_0 ,0x20000 ,0x1B0000,
10 wt_nvs ,data,nvs , ,64K , wt_nvs ,data,nvs , ,64K ,
11 coredump,data,coredump,0x390000,64K ,

View File

@ -0,0 +1 @@
v0.1.3

View File

@ -10,7 +10,7 @@ idf_component_register(
SRCS ${SOURCES} SRCS ${SOURCES}
INCLUDE_DIRS "." INCLUDE_DIRS "."
REQUIRES esp_http_server REQUIRES esp_http_server
PRIV_REQUIRES request_runner api_router json memory_pool utils html PRIV_REQUIRES request_runner api_router json memory_pool utils html SSDP
) )
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON) idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)

View File

@ -1,12 +1,16 @@
#include "web_uri_module.h" #include "web_uri_module.h"
#include "ssdp.h"
#include <esp_http_server.h> #include <esp_http_server.h>
#include <esp_log.h> #include <esp_log.h>
#include "memory_pool.h"
#define TAG __FILE_NAME__ #define TAG __FILE_NAME__
#define URI_ROOT 0x0000002F /* / */ #define MAKE_U32(b0, b1, b2, b3) ((b0) | (b1) << 8 | (b2) << 16 | (b3) << 24)
#define URI_WS_DOT 0x2E73772F /* /ws. */ #define URI_ROOT MAKE_U32 ('/', '\0', '\0', '\0')/* / */
#define URI_WS_DOT MAKE_U32('/', 'w', 's', '.') /* /ws. */
#define URI_SSDP MAKE_U32 ('/', 'S', 'S', 'D') /* /SSD */
#define HTML_INDEX "index_html_gz" #define HTML_INDEX "index_html_gz"
#define JS_WS_SHARED "ws_sharedworker_js_gz" #define JS_WS_SHARED "ws_sharedworker_js_gz"
@ -29,6 +33,11 @@ static esp_err_t html_base_get_handler(httpd_req_t *req)
httpd_resp_set_type(req, "text/javascript"); httpd_resp_set_type(req, "text/javascript");
httpd_resp_set_hdr(req, "Content-encoding", "gzip"); httpd_resp_set_hdr(req, "Content-encoding", "gzip");
SEND_FILE(req, JS_WS_SHARED); SEND_FILE(req, JS_WS_SHARED);
} else if (*URI_HASH == URI_SSDP) {
httpd_resp_set_type(req, "text/xml");
char *buf = memory_pool_get(portMAX_DELAY);
ssdp_get_schema_str(buf, memory_pool_get_buf_size());
httpd_resp_send(req, buf, strlen(buf));
} else { } else {
httpd_resp_set_type(req, "text/html"); httpd_resp_set_type(req, "text/html");
httpd_resp_set_hdr(req, "Content-encoding", "gzip"); httpd_resp_set_hdr(req, "Content-encoding", "gzip");

View File

@ -1,5 +1,6 @@
#include "web_server.h" #include "web_server.h"
#include "web_uri_module.h" #include "web_uri_module.h"
#include "ssdp.h"
#include <esp_http_server.h> #include <esp_http_server.h>
#include <esp_event.h> #include <esp_event.h>

View File

@ -11,7 +11,7 @@ file(GLOB SOURCES
idf_component_register( idf_component_register(
SRCS ${SOURCES} SRCS ${SOURCES}
INCLUDE_DIRS "." INCLUDE_DIRS "."
PRIV_REQUIRES mdns esp_wifi esp_event api_router wt_storage driver PRIV_REQUIRES mdns esp_wifi esp_event api_router wt_storage driver SSDP
) )
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON) idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)

View File

@ -1,15 +1,18 @@
#include "wifi_api.h" #include "wifi_api.h"
#include "wifi_manager.h" #include "wifi_manager.h"
#include "wifi_configuration.h" #include "wifi_configuration.h"
#include "wifi_storage.h"
#include <esp_wifi.h> #include <esp_wifi.h>
void wifi_api_sta_get_ap_info(wifi_api_ap_info_t *ap_info) void wifi_api_sta_get_ap_info(wifi_api_ap_info_t *ap_info)
{ {
wifi_ap_record_t ap_record; wifi_ap_record_t ap_record = {0};
int err;
esp_wifi_sta_get_ap_info(&ap_record); esp_wifi_sta_get_ap_info(&ap_record);
strncpy(ap_info->ssid, (char *)ap_record.ssid, sizeof(ap_info->ssid)); strncpy(ap_info->ssid, (char *)ap_record.ssid, sizeof(ap_info->ssid));
strncpy(ap_info->mac, (char *)ap_record.bssid, sizeof(ap_info->mac)); strncpy(ap_info->mac, (char *)ap_record.bssid, sizeof(ap_info->mac));
ap_info->rssi = ap_record.rssi; ap_info->rssi = ap_record.rssi;
ap_info->password[0] = '\0';
esp_netif_t *sta_netif = wifi_manager_get_sta_netif(); esp_netif_t *sta_netif = wifi_manager_get_sta_netif();
esp_netif_ip_info_t ip_info; esp_netif_ip_info_t ip_info;
@ -17,29 +20,71 @@ void wifi_api_sta_get_ap_info(wifi_api_ap_info_t *ap_info)
ip4_addr_set(&ap_info->ip, &ip_info.ip); ip4_addr_set(&ap_info->ip, &ip_info.ip);
ip4_addr_set(&ap_info->gateway, &ip_info.gw); ip4_addr_set(&ap_info->gateway, &ip_info.gw);
ip4_addr_set(&ap_info->netmask, &ip_info.netmask); ip4_addr_set(&ap_info->netmask, &ip_info.netmask);
esp_netif_dns_info_t dns_info;
err = esp_netif_get_dns_info(wifi_manager_get_sta_netif(),
ESP_NETIF_DNS_MAIN, &dns_info);
if (err) {
ap_info->dns_main.addr = ap_info->gateway.addr;
} else {
ap_info->dns_main.addr = dns_info.ip.u_addr.ip4.addr;
}
err = esp_netif_get_dns_info(wifi_manager_get_sta_netif(),
ESP_NETIF_DNS_BACKUP, &dns_info);
if (err) {
ap_info->dns_backup.addr = ap_info->gateway.addr;
} else {
ap_info->dns_backup.addr = dns_info.ip.u_addr.ip4.addr;
}
} }
void wifi_api_ap_get_info(wifi_api_ap_info_t *ap_info) void wifi_api_ap_get_info(wifi_api_ap_info_t *ap_info)
{ {
wifi_credential_t credential;
int err = wifi_data_get_ap_credential(&credential);
if (err) {
strncpy(ap_info->ssid, WIFI_DEFAULT_AP_SSID, strlen(WIFI_DEFAULT_AP_SSID)+1); strncpy(ap_info->ssid, WIFI_DEFAULT_AP_SSID, strlen(WIFI_DEFAULT_AP_SSID)+1);
strncpy(ap_info->password, WIFI_DEFAULT_AP_PASS, strlen(WIFI_DEFAULT_AP_PASS)+1);
} else {
strncpy(ap_info->ssid, credential.ssid, sizeof(ap_info->ssid));
strncpy(ap_info->password, credential.password, sizeof(ap_info->password));
}
esp_wifi_get_mac(WIFI_IF_AP, (uint8_t *) &ap_info->mac); esp_wifi_get_mac(WIFI_IF_AP, (uint8_t *) &ap_info->mac);
IP4_ADDR_EXPAND(&ap_info->ip, WIFI_DEFAULT_AP_IP); IP4_ADDR_EXPAND(&ap_info->ip, WIFI_DEFAULT_AP_IP);
IP4_ADDR_EXPAND(&ap_info->gateway, WIFI_DEFAULT_AP_GATEWAY); IP4_ADDR_EXPAND(&ap_info->gateway, WIFI_DEFAULT_AP_GATEWAY);
IP4_ADDR_EXPAND(&ap_info->netmask, WIFI_DEFAULT_AP_NETMASK); IP4_ADDR_EXPAND(&ap_info->netmask, WIFI_DEFAULT_AP_NETMASK);
ap_info->rssi = 0; ap_info->rssi = 0;
esp_netif_dns_info_t dns_info;
err = esp_netif_get_dns_info(wifi_manager_get_ap_netif(),
ESP_NETIF_DNS_MAIN, &dns_info);
if (err) {
ap_info->dns_main.addr = ap_info->gateway.addr;
} else {
ap_info->dns_main.addr = dns_info.ip.u_addr.ip4.addr;
}
err = esp_netif_get_dns_info(wifi_manager_get_ap_netif(),
ESP_NETIF_DNS_BACKUP, &dns_info);
if (err) {
ap_info->dns_backup.addr = ap_info->gateway.addr;
} else {
ap_info->dns_backup.addr = dns_info.ip.u_addr.ip4.addr;
}
} }
static int rssi_comp(const void *a, const void *b) static int rssi_comp(const void *a, const void *b)
{ {
const wifi_api_ap_info_t *r1 = a; const wifi_api_ap_scan_info_t *r1 = a;
const wifi_api_ap_info_t *r2 = b; const wifi_api_ap_scan_info_t *r2 = b;
return r2->rssi - r1->rssi; return r2->rssi - r1->rssi;
} }
/** /**
* @brief blocking function * @brief blocking function
*/ */
int wifi_api_get_scan_list(uint16_t *number, wifi_api_ap_info_t *ap_info) int wifi_api_get_scan_list(uint16_t *number, wifi_api_ap_scan_info_t *ap_info)
{ {
wifi_ap_record_t *records; wifi_ap_record_t *records;
int err; int err;
@ -64,7 +109,7 @@ int wifi_api_get_scan_list(uint16_t *number, wifi_api_ap_info_t *ap_info)
} }
free(records); free(records);
qsort(ap_info, *number, sizeof(wifi_api_ap_info_t), rssi_comp); qsort(ap_info, *number, sizeof(wifi_api_ap_scan_info_t), rssi_comp);
return 0; return 0;
} }
@ -72,9 +117,9 @@ static wifi_api_scan_done_cb scan_done_cb;
static void wifi_manager_scan_done(uint16_t ap_found, wifi_ap_record_t *records, void *arg) static void wifi_manager_scan_done(uint16_t ap_found, wifi_ap_record_t *records, void *arg)
{ {
wifi_api_ap_info_t *ap_info; wifi_api_ap_scan_info_t *ap_info;
ap_info = malloc(ap_found * sizeof(wifi_api_ap_info_t)); ap_info = malloc(ap_found * sizeof(wifi_api_ap_scan_info_t));
for (int i = 0; i < ap_found; ++i) { for (int i = 0; i < ap_found; ++i) {
strncpy(ap_info[i].ssid, (char *) records[i].ssid, sizeof(ap_info[i].ssid)); strncpy(ap_info[i].ssid, (char *) records[i].ssid, sizeof(ap_info[i].ssid));
strncpy(ap_info[i].mac, (char *) records[i].bssid, sizeof(ap_info[i].mac)); strncpy(ap_info[i].mac, (char *) records[i].bssid, sizeof(ap_info[i].mac));
@ -93,3 +138,13 @@ int wifi_api_disconnect(void)
{ {
return wifi_manager_disconnect(); return wifi_manager_disconnect();
} }
int wifi_api_sta_set_static_conf(wifi_api_sta_ap_static_info_t *static_info)
{
int err = wifi_manager_sta_set_static_conf(static_info);
if (err) {
return err;
}
return wifi_data_save_static(static_info);
}

View File

@ -7,35 +7,80 @@
typedef enum wifi_api_json_cmd_t { typedef enum wifi_api_json_cmd_t {
UNKNOWN = 0, UNKNOWN = 0,
WIFI_API_JSON_STA_GET_AP_INFO, WIFI_API_JSON_STA_GET_AP_INFO = 1,
WIFI_API_JSON_CONNECT, WIFI_API_JSON_CONNECT = 2,
WIFI_API_JSON_GET_SCAN, WIFI_API_JSON_GET_SCAN = 3,
WIFI_API_JSON_DISCONNECT, WIFI_API_JSON_DISCONNECT = 4,
WIFI_API_JSON_AP_GET_INFO, WIFI_API_JSON_AP_GET_INFO = 5,
WIFI_API_JSON_GET_MODE = 6, /* req:{ }, ret:{mode, [delay_off], [delay_on]} */
WIFI_API_JSON_SET_MODE = 7, /* req:{mode, [delay_off], [delay_on]} */
WIFI_API_JSON_SET_AP_CRED = 8, /* ssid[32] + password[64] */
WIFI_API_JSON_STA_GET_STATIC_INFO = 9,
WIFI_API_JSON_STA_SET_STATIC_CONF = 10, /* static_ip_en: 0/1, static_dns_en: 0/1 */
} wifi_api_json_cmd_t; } wifi_api_json_cmd_t;
typedef struct wifi_api_ap_info_t { typedef struct wifi_api_ap_info_t {
ip4_addr_t ip; ip4_addr_t ip;
ip4_addr_t gateway; ip4_addr_t gateway;
ip4_addr_t netmask; ip4_addr_t netmask;
char ssid[33]; char ssid[32+1];
char password[64+1];
char mac[6]; char mac[6];
signed char rssi; signed char rssi;
ip4_addr_t dns_main;
ip4_addr_t dns_backup;
} wifi_api_ap_info_t; } wifi_api_ap_info_t;
typedef struct wifi_api_ap_scan_info_t {
ip4_addr_t ip;
ip4_addr_t gateway;
ip4_addr_t netmask;
char ssid[32+1];
char mac[6];
signed char rssi;
} wifi_api_ap_scan_info_t;
typedef struct wifi_api_sta_ap_static_info_t {
ip4_addr_t ip;
ip4_addr_t gateway;
ip4_addr_t netmask;
ip4_addr_t dns_main;
ip4_addr_t dns_backup;
uint8_t static_ip_en;
uint8_t static_dns_en;
} wifi_api_sta_ap_static_info_t;
typedef enum wifi_apsta_mode_e {
/* permanent */
WIFI_AP_AUTO_STA_ON = 0,
WIFI_AP_STA_OFF = 4, /* 100 */
WIFI_AP_OFF_STA_ON = 5, /* 101 */
WIFI_AP_ON_STA_OFF = 6, /* 110 */
WIFI_AP_STA_ON = 7, /* 111 */
/* temporary */
WIFI_AP_STOP = 8,
WIFI_AP_START = 9,
WIFI_STA_STOP = 10,
WIFI_STA_START = 11,
} wifi_apsta_mode_e;
void wifi_api_sta_get_ap_info(wifi_api_ap_info_t *ap_info); void wifi_api_sta_get_ap_info(wifi_api_ap_info_t *ap_info);
void wifi_api_ap_get_info(wifi_api_ap_info_t *ap_info); void wifi_api_ap_get_info(wifi_api_ap_info_t *ap_info);
typedef void (*wifi_api_scan_done_cb)(uint16_t found, wifi_api_ap_info_t *aps, void *arg); typedef void (*wifi_api_scan_done_cb)(uint16_t found, wifi_api_ap_scan_info_t *aps, void *arg);
int wifi_api_trigger_scan(uint16_t *max_ap_count, wifi_api_scan_done_cb cb, void *cb_arg); int wifi_api_trigger_scan(uint16_t *max_ap_count, wifi_api_scan_done_cb cb, void *cb_arg);
int wifi_api_get_scan_list(uint16_t *number, wifi_api_ap_info_t *ap_info); int wifi_api_get_scan_list(uint16_t *number, wifi_api_ap_scan_info_t *ap_info);
int wifi_api_connect(const char *ssid, const char *password); int wifi_api_connect(const char *ssid, const char *password);
int wifi_api_disconnect(void); int wifi_api_disconnect(void);
int wifi_api_sta_set_static_conf(wifi_api_sta_ap_static_info_t *static_info);
#endif //WIFI_API_H_GUARD #endif //WIFI_API_H_GUARD

View File

@ -1,10 +1,13 @@
#include "api_json_module.h" #include "api_json_module.h"
#include "wifi_api.h" #include "wifi_api.h"
#include "wifi_json_utils.h" #include "wifi_json_utils.h"
#include "wifi_manager.h"
#include <stdio.h> #include <stdio.h>
#include <esp_log.h> #include <esp_log.h>
#include "wifi_storage.h"
#define TAG __FILENAME__ #define TAG __FILENAME__
static int wifi_api_json_sta_get_ap_info(api_json_req_t *req); static int wifi_api_json_sta_get_ap_info(api_json_req_t *req);
@ -17,6 +20,13 @@ static int wifi_api_json_disconnect(api_json_req_t *req);
static int wifi_api_json_ap_get_info(api_json_req_t *req); static int wifi_api_json_ap_get_info(api_json_req_t *req);
static int wifi_api_json_set_mode(api_json_req_t *req);
static int wifi_api_json_get_mode(api_json_req_t *req);
static int wifi_api_json_set_ap_cred(api_json_req_t *req);
static int wifi_api_json_sta_get_static_info(api_json_req_t *req);
static int wifi_api_json_sta_set_static_conf(api_json_req_t *req);
/* the upper caller call cb() with void *, this let us use custom function arg */ /* the upper caller call cb() with void *, this let us use custom function arg */
static int async_helper_cb(void *arg) static int async_helper_cb(void *arg)
{ {
@ -50,12 +60,35 @@ static int on_json_req(uint16_t cmd, api_json_req_t *req, api_json_module_async_
return wifi_api_json_disconnect(req); return wifi_api_json_disconnect(req);
case WIFI_API_JSON_AP_GET_INFO: case WIFI_API_JSON_AP_GET_INFO:
return wifi_api_json_ap_get_info(req); return wifi_api_json_ap_get_info(req);
case WIFI_API_JSON_GET_MODE:
return wifi_api_json_get_mode(req);
case WIFI_API_JSON_SET_MODE:
return wifi_api_json_set_mode(req);
case WIFI_API_JSON_SET_AP_CRED:
return wifi_api_json_set_ap_cred(req);
case WIFI_API_JSON_STA_GET_STATIC_INFO:
return wifi_api_json_sta_get_static_info(req);
case WIFI_API_JSON_STA_SET_STATIC_CONF:
return wifi_api_json_sta_set_static_conf(req);
} }
ESP_LOGI(TAG, "cmd %d not executed\n", cmd); ESP_LOGI(TAG, "cmd %d not executed\n", cmd);
return API_JSON_UNSUPPORTED_CMD; return API_JSON_UNSUPPORTED_CMD;
} }
/* ****
* register module
* */
static int wifi_api_json_init(api_json_module_cfg_t *cfg)
{
cfg->on_req = on_json_req;
cfg->module_id = WIFI_MODULE_ID;
return 0;
}
API_JSON_MODULE_REGISTER(wifi_api_json_init)
static int wifi_api_json_sta_get_ap_info(api_json_req_t *req) static int wifi_api_json_sta_get_ap_info(api_json_req_t *req)
{ {
wifi_api_ap_info_t ap_info; wifi_api_ap_info_t ap_info;
@ -74,7 +107,7 @@ static int wifi_api_json_ap_get_info(api_json_req_t *req)
static int wifi_api_json_get_scan(api_json_req_t *req) static int wifi_api_json_get_scan(api_json_req_t *req)
{ {
wifi_api_ap_info_t ap_info[20]; wifi_api_ap_scan_info_t ap_info[20];
uint16_t max_count = 20; uint16_t max_count = 20;
int err; int err;
@ -112,20 +145,113 @@ int wifi_api_json_connect(api_json_req_t *req)
return wifi_api_json_sta_get_ap_info(req); return wifi_api_json_sta_get_ap_info(req);
}; };
int wifi_api_json_set_mode(api_json_req_t *req)
{
int value;
int err;
err = wifi_api_json_utils_get_int(req->in, "mode", &value);
if (err) {
req->out = wifi_api_json_create_err_rsp(req->in, "'mode' attribute missing");
ESP_LOGE(TAG, "ap stop: %s", esp_err_to_name(err));
return API_JSON_OK;
}
wifi_apsta_mode_e mode = value;
err = wifi_manager_change_mode(mode);
if (err) {
req->out = wifi_api_json_create_err_rsp(req->in, "Change mode Failed");
ESP_LOGE(TAG, "ap stop: %s", esp_err_to_name(err));
return API_JSON_OK;
}
if (mode == WIFI_AP_AUTO_STA_ON) {
int ap_on_delay;
int ap_off_delay;
err = wifi_api_json_utils_get_int(req->in, "ap_on_delay", &ap_on_delay);
err |= wifi_api_json_utils_get_int(req->in, "ap_off_delay", &ap_off_delay);
if (err == 0) {
wifi_manager_set_ap_auto_delay(&ap_on_delay, &ap_off_delay);
req->out = wifi_api_json_serialize_ap_auto(mode, ap_on_delay, ap_off_delay);
return API_JSON_OK;
}
}
return API_JSON_OK;
}
int wifi_api_json_get_mode(api_json_req_t *req)
{
wifi_apsta_mode_e mode;
wifi_mode_t status;
int ap_on_delay, ap_off_delay;
wifi_manager_get_mode(&mode, &status);
if (mode == WIFI_AP_AUTO_STA_ON) {
wifi_manager_get_ap_auto_delay(&ap_on_delay, &ap_off_delay);
} else {
ap_on_delay = -1;
ap_off_delay = -1;
}
req->out = wifi_api_json_serialize_get_mode(mode, status, ap_on_delay, ap_off_delay);
return API_JSON_OK;
}
int wifi_api_json_disconnect(api_json_req_t *req) int wifi_api_json_disconnect(api_json_req_t *req)
{ {
return wifi_api_disconnect(); return wifi_api_disconnect();
} }
/* ****
* register module
* */
static int wifi_api_json_init(api_json_module_cfg_t *cfg) int wifi_api_json_set_ap_cred(api_json_req_t *req)
{ {
cfg->on_req = on_json_req; wifi_credential_t credential;
cfg->module_id = WIFI_MODULE_ID; int err;
err = wifi_api_json_get_credential(req->in, (char *)&credential.ssid, (char *)&credential.password);
if (err) {
return API_JSON_PROPERTY_ERR;
}
if (strlen(credential.password) < 8) {
req->out = wifi_api_json_create_err_rsp(req->in, "password < 8");
return API_JSON_OK;
}
err = wifi_data_save_ap_credential(&credential);
if (err) {
return API_JSON_INTERNAL_ERR;
}
wifi_manager_set_ap_credential(&credential);
return 0; return 0;
} }
API_JSON_MODULE_REGISTER(wifi_api_json_init) int wifi_api_json_sta_get_static_info(api_json_req_t *req)
{
wifi_api_sta_ap_static_info_t static_info = {0};
int err = wifi_data_get_static(&static_info);
if (err) {
return API_JSON_INTERNAL_ERR;
}
req->out = wifi_api_json_ser_static_info(&static_info);
return API_JSON_OK;
}
int wifi_api_json_sta_set_static_conf(api_json_req_t *req)
{
wifi_api_sta_ap_static_info_t static_info = {0};
int err;
wifi_data_get_static(&static_info);
err = wifi_api_json_deser_static_conf(req->in, &static_info);
if (err) {
return API_JSON_PROPERTY_ERR;
}
wifi_api_sta_set_static_conf(&static_info);
return API_JSON_OK;
}

View File

@ -7,6 +7,9 @@
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/semphr.h> #include <freertos/semphr.h>
#include "ssdp.h"
#include "wifi_configuration.h"
#define TAG __FILE_NAME__ #define TAG __FILE_NAME__
void event_on_connected(ip_event_got_ip_t *event); void event_on_connected(ip_event_got_ip_t *event);
@ -22,11 +25,18 @@ void ip_event_handler(void *handler_arg __attribute__((unused)),
printf("STA GOT IP : %s\n", printf("STA GOT IP : %s\n",
ip4addr_ntoa((const ip4_addr_t *) &event->ip_info.ip)); ip4addr_ntoa((const ip4_addr_t *) &event->ip_info.ip));
event_on_connected(event); event_on_connected(event);
ssdp_set_ip_gw(&event->ip_info.ip.addr, &event->ip_info.gw.addr);
break; break;
} }
case IP_EVENT_STA_LOST_IP: case IP_EVENT_STA_LOST_IP: {
printf("sta lost ip\n"); printf("sta lost ip\n");
ip4_addr_t ip;
ip4_addr_t gw;
IP4_ADDR_EXPAND(&ip, WIFI_DEFAULT_AP_IP);
IP4_ADDR_EXPAND(&gw, WIFI_DEFAULT_AP_GATEWAY);
ssdp_set_ip_gw(&ip.addr, &gw.addr);
break; break;
}
case IP_EVENT_AP_STAIPASSIGNED: case IP_EVENT_AP_STAIPASSIGNED:
printf("event STAIPASSIGNED\n"); printf("event STAIPASSIGNED\n");
break; break;

View File

@ -19,8 +19,13 @@ cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info, wifi_api_jso
cJSON_AddStringToObject(root, "ip", ip4addr_ntoa(&ap_info->ip)); cJSON_AddStringToObject(root, "ip", ip4addr_ntoa(&ap_info->ip));
cJSON_AddStringToObject(root, "gateway", ip4addr_ntoa(&ap_info->gateway)); cJSON_AddStringToObject(root, "gateway", ip4addr_ntoa(&ap_info->gateway));
cJSON_AddStringToObject(root, "netmask", ip4addr_ntoa(&ap_info->netmask)); cJSON_AddStringToObject(root, "netmask", ip4addr_ntoa(&ap_info->netmask));
cJSON_AddStringToObject(root, "dns_main", ip4addr_ntoa(&ap_info->dns_main));
cJSON_AddStringToObject(root, "dns_backup", ip4addr_ntoa(&ap_info->dns_backup));
cJSON_AddNumberToObject(root, "rssi", ap_info->rssi); cJSON_AddNumberToObject(root, "rssi", ap_info->rssi);
cJSON_AddStringToObject(root, "ssid", ap_info->ssid); cJSON_AddStringToObject(root, "ssid", ap_info->ssid);
if (ap_info->password[0]) {
cJSON_AddStringToObject(root, "password", ap_info->password);
}
char mac_str[18]; char mac_str[18];
char *m = ap_info->mac; char *m = ap_info->mac;
@ -31,7 +36,7 @@ cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info, wifi_api_jso
return root; return root;
} }
cJSON *wifi_api_json_serialize_scan_list(wifi_api_ap_info_t *aps_info, uint16_t count) cJSON *wifi_api_json_serialize_scan_list(wifi_api_ap_scan_info_t *aps_info, uint16_t count)
{ {
cJSON *root; cJSON *root;
char mac_str[18]; char mac_str[18];
@ -54,12 +59,131 @@ cJSON *wifi_api_json_serialize_scan_list(wifi_api_ap_info_t *aps_info, uint16_t
return root; return root;
} }
cJSON *wifi_api_json_serialize_ap_auto(wifi_apsta_mode_e mode, int ap_on_delay, int ap_off_delay)
{
cJSON *root;
root = cJSON_CreateObject();
wifi_api_json_set_header(root, WIFI_API_JSON_GET_SCAN);
cJSON_AddNumberToObject(root, "mode", mode);
cJSON_AddNumberToObject(root, "ap_on_delay", ap_on_delay);
cJSON_AddNumberToObject(root, "ap_off_delay", ap_off_delay);
return root;
}
cJSON *wifi_api_json_create_err_rsp(cJSON *req, const char *msg) cJSON *wifi_api_json_create_err_rsp(cJSON *req, const char *msg)
{ {
cJSON *root; cJSON *root;
root = cJSON_Duplicate(req, 1); root = cJSON_Duplicate(req, 1);
cJSON_AddStringToObject(root, "msg", msg); cJSON_AddStringToObject(root, "err", msg);
return root; return root;
} }
int wifi_api_json_utils_get_int(cJSON *req, const char *name, int *out_value)
{
cJSON *item = cJSON_GetObjectItemCaseSensitive(req, name);
if (!cJSON_IsNumber(item)) {
return 1;
}
*out_value = item->valueint;
return 0;
}
cJSON *wifi_api_json_serialize_get_mode(wifi_apsta_mode_e mode, int status, int ap_on_delay, int ap_off_delay)
{
cJSON *root;
root = cJSON_CreateObject();
wifi_api_json_set_header(root, WIFI_API_JSON_GET_MODE);
cJSON_AddNumberToObject(root, "mode", mode);
cJSON_AddNumberToObject(root, "status", status);
if (ap_on_delay >= 0 && ap_off_delay >= 0) {
cJSON_AddNumberToObject(root, "ap_on_delay", ap_on_delay);
cJSON_AddNumberToObject(root, "ap_off_delay", ap_off_delay);
}
return root;
}
cJSON *wifi_api_json_add_int_item(cJSON *root, const char *name, int item)
{
cJSON_AddNumberToObject(root, name, item);
return root;
}
int wifi_api_json_get_credential(cJSON *root, char *ssid, char *password)
{
cJSON *json_ssid = cJSON_GetObjectItem(root, "ssid");
cJSON *json_password = cJSON_GetObjectItem(root, "password");
if (!cJSON_IsString(json_ssid) || !cJSON_IsString(json_password)) {
return 1;
}
strncpy(ssid, cJSON_GetStringValue(json_ssid), 31);
strncpy(password, cJSON_GetStringValue(json_password), 63);
ssid[31] = '\0';
password[64] = '\0';
return 0;
}
cJSON *wifi_api_json_ser_static_info(wifi_api_sta_ap_static_info_t *info)
{
cJSON *root;
root = cJSON_CreateObject();
wifi_api_json_set_header(root, WIFI_API_JSON_STA_GET_STATIC_INFO);
cJSON_AddNumberToObject(root, "static_ip_en", info->static_ip_en);
cJSON_AddNumberToObject(root, "static_dns_en", info->static_dns_en);
cJSON_AddStringToObject(root, "ip", ip4addr_ntoa(&info->ip));
cJSON_AddStringToObject(root, "gateway", ip4addr_ntoa(&info->gateway));
cJSON_AddStringToObject(root, "netmask", ip4addr_ntoa(&info->netmask));
cJSON_AddStringToObject(root, "dns_main", ip4addr_ntoa(&info->dns_main));
cJSON_AddStringToObject(root, "dns_backup", ip4addr_ntoa(&info->dns_backup));
return root;
}
int wifi_api_json_deser_static_conf(cJSON *root, wifi_api_sta_ap_static_info_t *static_info)
{
cJSON *static_ip_en = cJSON_GetObjectItemCaseSensitive(root, "static_ip_en");
cJSON *static_dns_en = cJSON_GetObjectItemCaseSensitive(root, "static_dns_en");
if (!cJSON_IsNumber(static_ip_en) || !cJSON_IsNumber(static_dns_en)) {
printf("en error\n");
return 1;
}
static_info->static_dns_en = static_dns_en->valueint;
static_info->static_ip_en = static_ip_en->valueint;
cJSON *ip = cJSON_GetObjectItemCaseSensitive(root, "ip");
cJSON *gateway = cJSON_GetObjectItemCaseSensitive(root, "gateway");
cJSON *netmask = cJSON_GetObjectItemCaseSensitive(root, "netmask");
cJSON *dns_main = cJSON_GetObjectItemCaseSensitive(root, "dns_main");
cJSON *dns_backup = cJSON_GetObjectItemCaseSensitive(root, "dns_backup");
if (cJSON_IsString(ip)) {
ip4addr_aton(ip->valuestring, &static_info->ip);
}
if (cJSON_IsString(gateway)) {
ip4addr_aton(gateway->valuestring, &static_info->gateway);
}
if (cJSON_IsString(netmask)) {
ip4addr_aton(netmask->valuestring, &static_info->netmask);
}
if (cJSON_IsString(dns_main)) {
ip4addr_aton(dns_main->valuestring, &static_info->dns_main);
}
if (cJSON_IsString(dns_backup)) {
ip4addr_aton(dns_backup->valuestring, &static_info->dns_backup);
}
return 0;
}

View File

@ -4,9 +4,18 @@
#include "wifi_api.h" #include "wifi_api.h"
cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info, wifi_api_json_cmd_t cmd); cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info, wifi_api_json_cmd_t cmd);
cJSON *wifi_api_json_serialize_scan_list(wifi_api_ap_info_t *aps_info, uint16_t count); cJSON *wifi_api_json_serialize_scan_list(wifi_api_ap_scan_info_t *aps_info, uint16_t count);
cJSON *wifi_api_json_serialize_ap_auto(wifi_apsta_mode_e mode, int ap_on_delay, int ap_off_delay);
cJSON *wifi_api_json_serialize_get_mode(wifi_apsta_mode_e mode, int status, int ap_on_delay, int ap_off_delay);
cJSON *wifi_api_json_create_err_rsp(cJSON *req, const char *msg); cJSON *wifi_api_json_create_err_rsp(cJSON *req, const char *msg);
cJSON *wifi_api_json_add_int_item(cJSON *root, const char *name, int item);
int wifi_api_json_utils_get_int(cJSON *req, const char *name, int *out_value);
int wifi_api_json_get_credential(cJSON *root, char *ssid, char *password);
cJSON *wifi_api_json_ser_static_info(wifi_api_sta_ap_static_info_t *info);
int wifi_api_json_deser_static_conf(cJSON *root, wifi_api_sta_ap_static_info_t *static_info);
#endif //WIFI_JSON_UTILS_H_GUARD #endif //WIFI_JSON_UTILS_H_GUARD

View File

@ -19,6 +19,9 @@
#include <hal/gpio_hal.h> #include <hal/gpio_hal.h>
#include <soc/ledc_periph.h> #include <soc/ledc_periph.h>
#include "ssdp.h"
#include "wifi_api.h"
#define TAG __FILENAME__ #define TAG __FILENAME__
typedef struct wifi_ctx_t { typedef struct wifi_ctx_t {
@ -38,10 +41,20 @@ typedef struct wifi_ctx_t {
uint8_t need_unlock; /* used when trigger connection from wifi_manager instead of wifi_api */ uint8_t need_unlock; /* used when trigger connection from wifi_manager instead of wifi_api */
} conn; } conn;
}; };
struct {
uint8_t is_endless_connect: 1; uint8_t is_endless_connect: 1;
uint8_t auto_reconnect: 1; uint8_t auto_reconnect: 1;
uint8_t do_fast_connect: 1; /* 0 delay connect on boot or just disconnected, else 5 seconds delay from each connection try */ uint8_t do_fast_connect: 1; /* 0 delay connect on boot or just disconnected, else 5 seconds delay from each connection try */
uint8_t reserved:5; uint8_t is_sta_connected: 1;
uint8_t reserved: 4;
};
TaskHandle_t delayed_stopAP_task;
TaskHandle_t delayed_startAP_task;
uint32_t try_connect_count;
wifi_apsta_mode_e permanent_mode;
wifi_mode_t mode;
int ap_on_delay_tick;
int ap_off_delay_tick;
} wifi_ctx_t; } wifi_ctx_t;
static esp_netif_t *ap_netif; static esp_netif_t *ap_netif;
@ -52,6 +65,8 @@ static wifi_ctx_t ctx;
static void set_sta_cred(const char *ssid, const char *password); static void set_sta_cred(const char *ssid, const char *password);
static void disconn_handler(void); static void disconn_handler(void);
static int set_default_sta_cred(void); static int set_default_sta_cred(void);
static int set_wifi_mode(wifi_apsta_mode_e mode);
static void handle_wifi_connected(); /* got IP */
static void wifi_led_init(); static void wifi_led_init();
static void wifi_led_set_blink(); static void wifi_led_set_blink();
@ -77,21 +92,39 @@ void wifi_manager_init(void)
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, NULL)); ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, NULL));
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL, NULL)); ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL, NULL));
ctx.is_sta_connected = false;
ctx.ap_on_delay_tick = pdMS_TO_TICKS(5000);
ctx.ap_off_delay_tick = pdMS_TO_TICKS(10000);
ctx.delayed_stopAP_task = NULL;
ctx.delayed_startAP_task = NULL;
ctx.try_connect_count = 0;
err = wifi_data_get_wifi_mode(&ctx.permanent_mode);
ESP_LOGI(TAG, "use wifi mode: %d", ctx.permanent_mode);
if (err) {
ctx.permanent_mode = WIFI_AP_AUTO_STA_ON;
ctx.mode = WIFI_MODE_APSTA;
} else {
ctx.mode = ctx.permanent_mode & 0x3; /* 0b1XX */
if (ctx.mode == WIFI_MODE_STA || ctx.mode == WIFI_MODE_NULL) {
ctx.mode = WIFI_MODE_APSTA;
}
}
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA)); ESP_ERROR_CHECK(esp_wifi_set_mode(ctx.mode));
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
{ wifi_credential_t cred;
wifi_config_t ap_config = {0}; err = wifi_data_get_ap_credential(&cred);
if (err || strlen(cred.password) < 8) {
strncpy((char *) ap_config.ap.ssid, WIFI_DEFAULT_AP_SSID, 32); ESP_LOGI(TAG, "use default AP credential");
strncpy((char *) ap_config.ap.password, WIFI_DEFAULT_AP_PASS, 64); strncpy((char *)cred.ssid, WIFI_DEFAULT_AP_SSID, 32);
ap_config.ap.authmode = WIFI_AUTH_WPA2_WPA3_PSK; strncpy((char *)cred.password, WIFI_DEFAULT_AP_PASS, 64);
ap_config.ap.max_connection = 4; } else {
ap_config.ap.channel = 6; ESP_LOGI(TAG, "use AP credential %s, %s", cred.ssid, cred.password);
ap_config.ap.ssid_hidden = 0;
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_config));
} }
wifi_manager_set_ap_credential(&cred);
if (set_default_sta_cred() == 0) { if (set_default_sta_cred() == 0) {
ESP_LOGI(TAG, "STA connect to saved cred"); ESP_LOGI(TAG, "STA connect to saved cred");
@ -99,6 +132,12 @@ void wifi_manager_init(void)
ctx.do_fast_connect = 1; ctx.do_fast_connect = 1;
} }
wifi_api_sta_ap_static_info_t static_info;
err = wifi_data_get_static(&static_info);
if (err == ESP_OK) {
wifi_manager_sta_set_static_conf(&static_info);
}
/* TODO: Read from nvs */ /* TODO: Read from nvs */
esp_netif_ip_info_t ip_info; esp_netif_ip_info_t ip_info;
IP4_ADDR_EXPAND(&ip_info.ip, WIFI_DEFAULT_AP_IP); IP4_ADDR_EXPAND(&ip_info.ip, WIFI_DEFAULT_AP_IP);
@ -131,6 +170,9 @@ void wifi_manager_init(void)
if (do_connect) { if (do_connect) {
disconn_handler(); disconn_handler();
} }
ssdp_init();
ssdp_start();
} }
void wifi_led_init() void wifi_led_init()
@ -290,7 +332,7 @@ int set_default_sta_cred()
{ {
int err; int err;
wifi_credential_t credential; wifi_credential_t credential;
err = wifi_data_get_last_conn_cred(&credential); err = wifi_data_get_sta_last_conn_cred(&credential);
if (err) { if (err) {
return err; return err;
} }
@ -330,16 +372,105 @@ int wifi_manager_connect(const char *ssid, const char *password)
/* connection success: overwrite last connected credential */ /* connection success: overwrite last connected credential */
wifi_led_set_on(); wifi_led_set_on();
handle_wifi_connected();
wifi_credential_t credential; wifi_credential_t credential;
memcpy(credential.ssid, ssid, 32); memcpy(credential.ssid, ssid, 32);
memcpy(credential.password, password, 64); memcpy(credential.password, password, 64);
ret = wifi_save_ap_credential(&credential); ret = wifi_data_save_sta_ap_credential(&credential);
if (ret) { if (ret) {
ESP_LOGE(TAG, "nvs save error: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "nvs save error: %s", esp_err_to_name(ret));
} }
return 0; return 0;
} }
int wifi_manager_change_mode(wifi_apsta_mode_e mode)
{
int err;
if (ctx.permanent_mode == mode) {
return 0;
}
err = xSemaphoreTake(ctx.lock, pdMS_TO_TICKS(2000));
if (err != pdTRUE) {
ESP_LOGE(TAG, "set mode take lock");
return 1;
}
if (ctx.delayed_stopAP_task) {
xTaskNotifyGive(ctx.delayed_stopAP_task);
}
if (ctx.delayed_startAP_task) {
xTaskNotifyGive(ctx.delayed_startAP_task);
}
err = set_wifi_mode(mode);
xSemaphoreGive(ctx.lock);
if (err)
return err;
if (mode >= WIFI_AP_STOP){
return ESP_OK;
}
return wifi_data_save_wifi_mode(mode);
}
int set_wifi_mode(wifi_apsta_mode_e mode)
{
uint32_t new_mode = ctx.mode;
printf("change mode: %d\n", mode);
switch (mode) {
default:
return 1;
case WIFI_AP_AUTO_STA_ON:
if (ctx.is_sta_connected) {
new_mode = WIFI_MODE_STA;
} else {
new_mode = WIFI_MODE_APSTA;
}
ctx.permanent_mode = mode;
break;
case WIFI_AP_STA_OFF:
case WIFI_AP_ON_STA_OFF:
case WIFI_AP_OFF_STA_ON:
case WIFI_AP_STA_ON:
ctx.permanent_mode = mode;
new_mode = mode & (~WIFI_AP_STA_OFF);
break;
case WIFI_AP_STOP:
new_mode &= ~WIFI_MODE_AP;
break;
case WIFI_AP_START:
new_mode |= WIFI_MODE_AP;
break;
case WIFI_STA_STOP:
new_mode &= ~WIFI_MODE_STA;
break;
case WIFI_STA_START:
new_mode |= WIFI_MODE_STA;
break;
}
printf("set mode to %lx\n", new_mode);
if (new_mode == ctx.mode) {
return 0;
}
int err = esp_wifi_set_mode(new_mode);
if (err) {
printf("set mode ret err %x\n", err);
return err;
}
/* AP -> APSTA */
if (!(ctx.mode & WIFI_MODE_STA) && (new_mode & WIFI_MODE_STA)) {
printf("set mode reco\n");
xSemaphoreGive(ctx.lock);
disconn_handler();
}
ctx.mode = new_mode;
printf("set mode ret %x\n", err);
return err;
}
static void set_sta_cred(const char *ssid, const char *password) static void set_sta_cred(const char *ssid, const char *password)
{ {
wifi_config_t wifi_config = { wifi_config_t wifi_config = {
@ -351,7 +482,76 @@ static void set_sta_cred(const char *ssid, const char *password)
memcpy((char *)wifi_config.sta.ssid, ssid, 32); memcpy((char *)wifi_config.sta.ssid, ssid, 32);
memcpy((char *)wifi_config.sta.password, password, 64); memcpy((char *)wifi_config.sta.password, password, 64);
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); int err = esp_wifi_set_config(WIFI_IF_STA, &wifi_config);
if (err) {
ESP_LOGE(TAG, "%s", esp_err_to_name(err));
}
}
static void delayed_set_ap_stop(void *arg)
{
uint32_t ret = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(30000));
xSemaphoreTake(ctx.lock, pdMS_TO_TICKS(10000));
/* timeout: connected to STA without disconnection: close AP */
if (ret == 0) {
set_wifi_mode(WIFI_AP_STOP);
ctx.try_connect_count = 0;
}
ctx.delayed_stopAP_task = NULL;
xSemaphoreGive(ctx.lock);
vTaskDelete(NULL);
}
static void delayed_set_ap_start(void *arg)
{
uint32_t ret = 0;
if (!(ctx.try_connect_count > 5)) {
ret = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(10000));
}
xSemaphoreTake(ctx.lock, pdMS_TO_TICKS(10000));
/* timeout: connected to STA without disconnection for 10 sec: close AP */
/* or consecutive connect/disconnect */
if (ret == 0 && ctx.permanent_mode == WIFI_AP_AUTO_STA_ON) {
set_wifi_mode(WIFI_AP_START);
ctx.try_connect_count = 0;
}
ctx.delayed_startAP_task = NULL;
xSemaphoreGive(ctx.lock);
vTaskDelete(NULL);
}
static void handle_wifi_connected()
{
ctx.is_sta_connected = true;
if (ctx.delayed_startAP_task) {
printf("clear start ap task");
xTaskNotifyGive(ctx.delayed_startAP_task);
}
if (ctx.permanent_mode != WIFI_AP_AUTO_STA_ON) {
return;
}
printf("stop ap task");
xTaskCreate(delayed_set_ap_stop, "stop ap", 4096,
NULL, tskIDLE_PRIORITY + 1, &ctx.delayed_stopAP_task);
}
static void handle_wifi_disconnected()
{
ctx.is_sta_connected = false;
if (ctx.delayed_stopAP_task) {
printf("clear stop ap task");
xTaskNotifyGive(ctx.delayed_stopAP_task);
}
if (ctx.permanent_mode != WIFI_AP_AUTO_STA_ON) {
return;
}
printf("start ap task");
ctx.try_connect_count++;
xTaskCreate(delayed_set_ap_start, "start ap", 4096,
NULL, tskIDLE_PRIORITY + 1, &ctx.delayed_startAP_task);
} }
static void reconnection_task(void *arg) static void reconnection_task(void *arg)
@ -378,7 +578,9 @@ static void reconnection_task(void *arg)
if (ctx.conn.event || ctx.auto_reconnect == 0) { if (ctx.conn.event || ctx.auto_reconnect == 0) {
/* reconnection successful or stop reconnect */ /* reconnection successful or stop reconnect */
if (ctx.conn.event) { if (ctx.conn.event) {
/* sta connected */
wifi_led_set_on(); wifi_led_set_on();
handle_wifi_connected();
} }
break; break;
} }
@ -406,6 +608,7 @@ static void disconn_handler(void)
* 3. this device is ejected by AP * 3. this device is ejected by AP
* */ * */
wifi_led_set_blink(); wifi_led_set_blink();
handle_wifi_disconnected();
if (ctx.auto_reconnect == 0) { if (ctx.auto_reconnect == 0) {
return; return;
} }
@ -429,3 +632,80 @@ int wifi_manager_disconnect(void)
ctx.auto_reconnect = 0; ctx.auto_reconnect = 0;
return esp_wifi_disconnect(); return esp_wifi_disconnect();
} }
int wifi_manager_get_ap_auto_delay(int *ap_on_delay, int *ap_off_delay)
{
*ap_on_delay = pdTICKS_TO_MS(ctx.ap_on_delay_tick);
*ap_off_delay = pdTICKS_TO_MS(ctx.ap_off_delay_tick);
return 0;
}
int wifi_manager_set_ap_auto_delay(int *ap_on_delay, int *ap_off_delay)
{
ctx.ap_on_delay_tick = pdMS_TO_TICKS(*ap_on_delay);
ctx.ap_on_delay_tick = pdMS_TO_TICKS(*ap_off_delay);
return wifi_manager_get_ap_auto_delay(ap_on_delay, ap_off_delay);
}
int wifi_manager_get_mode(wifi_apsta_mode_e *mode, wifi_mode_t *status)
{
*mode = ctx.permanent_mode;
*status = ctx.mode;
return 0;
}
int wifi_manager_set_ap_credential(wifi_credential_t *cred)
{
wifi_config_t ap_config = {0};
wifi_mode_t mode;
strncpy((char *)ap_config.ap.ssid, cred->ssid, 32);
strncpy((char *)ap_config.ap.password, cred->password, 64);
ap_config.ap.authmode = WIFI_AUTH_WPA2_WPA3_PSK;
ap_config.ap.max_connection = 4;
ap_config.ap.channel = 6;
ap_config.ap.ssid_hidden = 0;
if (esp_wifi_get_mode(&mode)) {
return 1;
}
if (mode & WIFI_MODE_AP) {
int err = esp_wifi_set_config(WIFI_IF_AP, &ap_config);
if (err) {
ESP_LOGE(TAG, "ap conf %s", esp_err_to_name(err));
}
}
return 0;
}
int wifi_manager_sta_set_static_conf(wifi_api_sta_ap_static_info_t *static_info)
{
if (static_info->static_ip_en) {
esp_netif_ip_info_t ip_info;
ip_info.ip.addr = static_info->ip.addr;
ip_info.gw.addr = static_info->gateway.addr;
ip_info.netmask.addr = static_info->netmask.addr;
esp_netif_dhcpc_stop(wifi_manager_get_sta_netif());
esp_netif_set_ip_info(wifi_manager_get_sta_netif(), &ip_info);
} else {
esp_netif_dhcpc_start(wifi_manager_get_sta_netif());
}
if (static_info->static_dns_en) {
esp_netif_dns_info_t dns_info;
dns_info.ip.type = ESP_IPADDR_TYPE_V4;
dns_info.ip.u_addr.ip4.addr = static_info->dns_main.addr;
esp_netif_set_dns_info(wifi_manager_get_sta_netif(), ESP_NETIF_DNS_MAIN, &dns_info);
dns_info.ip.u_addr.ip4.addr = static_info->dns_backup.addr;
esp_netif_set_dns_info(wifi_manager_get_sta_netif(), ESP_NETIF_DNS_BACKUP, &dns_info);
} else {
esp_netif_ip_info_t ip_info;
esp_netif_dns_info_t dns_info;
dns_info.ip.type = ESP_IPADDR_TYPE_V4;
esp_netif_get_ip_info(wifi_manager_get_sta_netif(), &ip_info);
dns_info.ip.u_addr.ip4.addr = ip_info.gw.addr;
dns_info.ip.type = ESP_NETIF_DNS_MAIN;
esp_netif_set_dns_info(wifi_manager_get_sta_netif(), ESP_NETIF_DNS_MAIN, &dns_info);
}
return 0;
}

View File

@ -2,6 +2,8 @@
#define WIFI_MANAGER_H_GUARD #define WIFI_MANAGER_H_GUARD
#include <esp_wifi_types.h> #include <esp_wifi_types.h>
#include "wifi_api.h"
#include "wifi_storage.h"
void wifi_manager_init(); void wifi_manager_init();
@ -13,7 +15,12 @@ typedef void (*wifi_manager_scan_done_cb)(uint16_t ap_found, wifi_ap_record_t *r
int wifi_manager_get_scan_list(uint16_t *number, wifi_ap_record_t *aps); int wifi_manager_get_scan_list(uint16_t *number, wifi_ap_record_t *aps);
int wifi_manager_connect(const char *ssid, const char *password); int wifi_manager_connect(const char *ssid, const char *password);
int wifi_manager_disconnect(void); int wifi_manager_disconnect(void);
int wifi_manager_change_mode(wifi_apsta_mode_e mode);
int wifi_manager_get_mode(wifi_apsta_mode_e *mode, wifi_mode_t *status);
int wifi_manager_get_ap_auto_delay(int *ap_on_delay, int *ap_off_delay);
int wifi_manager_set_ap_auto_delay(int *ap_on_delay, int *ap_off_delay);
int wifi_manager_set_ap_credential(wifi_credential_t *cred);
int wifi_manager_sta_set_static_conf(wifi_api_sta_ap_static_info_t *static_info);
#endif //WIFI_MANAGER_H_GUARD #endif //WIFI_MANAGER_H_GUARD

View File

@ -1,12 +1,13 @@
#include "wifi_storage.h" #include "wifi_storage.h"
#include "wifi_storage_priv.h" #include "wifi_storage_priv.h"
#include "wt_nvs.h" #include "wt_nvs.h"
#include "wifi_api.h"
#include <stdio.h> #include <stdio.h>
#define WIFI_NVS_NAMESPACE "wt_wifi" #define WIFI_NVS_NAMESPACE "wt_wifi"
int wifi_data_get_last_conn_cred(wifi_credential_t *ap_credential) int wifi_data_get_sta_last_conn_cred(wifi_credential_t *ap_credential)
{ {
uint32_t ap_bitmap = 0; uint32_t ap_bitmap = 0;
nvs_handle_t handle; nvs_handle_t handle;
@ -14,28 +15,33 @@ int wifi_data_get_last_conn_cred(wifi_credential_t *ap_credential)
err = wt_nvs_open(WIFI_NVS_NAMESPACE, &handle); err = wt_nvs_open(WIFI_NVS_NAMESPACE, &handle);
if (err) { if (err) {
return WT_NVS_ERR; return err;
} }
err = wt_nvs_get(handle, KEY_WIFI_STA_AP_BITMAP, &ap_bitmap, sizeof(ap_bitmap)); err = wt_nvs_get(handle, KEY_WIFI_STA_AP_BITMAP, &ap_bitmap, sizeof(ap_bitmap));
if (err || ap_bitmap == 0) { if (err) {
return WT_NVS_ERR_NOT_FOUND; goto end;
}
if (ap_bitmap == 0) {
err = WT_NVS_ERR_NOT_FOUND;
goto end;
} }
err = wt_nvs_get(handle, KEY_WIFI_STA_LAST_AP_CRED, err = wt_nvs_get(handle, KEY_WIFI_STA_LAST_AP_CRED,
ap_credential, sizeof(wifi_credential_t)); ap_credential, sizeof(wifi_credential_t));
if (err) { if (err) {
return WT_NVS_ERR; goto end;
} }
end:
wt_nvs_close(handle); wt_nvs_close(handle);
return WT_NVS_OK; return err;
} }
/* /*
* Called when connect to an AP, * Called when connect to an AP,
*/ */
int wifi_save_ap_credential(wifi_credential_t *ap_credential) int wifi_data_save_sta_ap_credential(wifi_credential_t *ap_credential)
{ {
uint32_t ap_bitmap; uint32_t ap_bitmap;
int err; int err;
@ -49,7 +55,7 @@ int wifi_save_ap_credential(wifi_credential_t *ap_credential)
err = wt_nvs_get(handle, KEY_WIFI_STA_AP_BITMAP, &ap_bitmap, sizeof(ap_bitmap)); err = wt_nvs_get(handle, KEY_WIFI_STA_AP_BITMAP, &ap_bitmap, sizeof(ap_bitmap));
if (err) { if (err) {
if (err != ESP_ERR_NVS_NOT_FOUND) { if (err != ESP_ERR_NVS_NOT_FOUND) {
return err; goto end;
} }
ap_bitmap = 0; ap_bitmap = 0;
} }
@ -63,15 +69,141 @@ int wifi_save_ap_credential(wifi_credential_t *ap_credential)
err = wt_nvs_get(handle, KEY_WIFI_STA_LAST_AP_CRED, &credential, sizeof(ap_bitmap)); err = wt_nvs_get(handle, KEY_WIFI_STA_LAST_AP_CRED, &credential, sizeof(ap_bitmap));
if (err) { if (err) {
if (err != ESP_ERR_NVS_NOT_FOUND) { if (err != ESP_ERR_NVS_NOT_FOUND) {
return err; goto end;
} }
} }
err = wt_nvs_set(handle, KEY_WIFI_STA_LAST_AP_CRED, ap_credential, sizeof(wifi_credential_t)); err = wt_nvs_set(handle, KEY_WIFI_STA_LAST_AP_CRED, ap_credential, sizeof(wifi_credential_t));
if (err) { if (err) {
goto end;
}
end:
wt_nvs_close(handle);
return err; return err;
} }
wt_nvs_close(handle); int wifi_data_save_wifi_mode(wifi_apsta_mode_e mode)
return WT_NVS_OK; {
nvs_handle_t handle;
int err;
uint8_t mode_u8 = mode;
err = wt_nvs_open(WIFI_NVS_NAMESPACE, &handle);
if (err) {
return err;
}
err = wt_nvs_set(handle, KEY_WIFI_APSTA_MODE, &mode_u8, sizeof(mode_u8));
wt_nvs_close(handle);
return err;
}
int wifi_data_get_wifi_mode(wifi_apsta_mode_e *mode)
{
nvs_handle_t handle;
int err;
uint8_t mode_u8;
err = wt_nvs_open(WIFI_NVS_NAMESPACE, &handle);
if (err) {
return err;
}
err = wt_nvs_get(handle, KEY_WIFI_APSTA_MODE, &mode_u8, sizeof(mode_u8));
*mode = mode_u8;
wt_nvs_close(handle);
return err;
}
int wifi_data_save_ap_credential(wifi_credential_t *ap_credential)
{
nvs_handle_t handle;
int err;
err = wt_nvs_open(WIFI_NVS_NAMESPACE, &handle);
if (err) {
return err;
}
err = wt_nvs_set(handle, KEY_WIFI_AP_CRED, ap_credential, sizeof(wifi_credential_t));
wt_nvs_close(handle);
return err;
}
int wifi_data_get_ap_credential(wifi_credential_t *ap_credential)
{
nvs_handle_t handle;
int err;
err = wt_nvs_open(WIFI_NVS_NAMESPACE, &handle);
if (err) {
return err;
}
err = wt_nvs_get(handle, KEY_WIFI_AP_CRED, ap_credential, sizeof(wifi_credential_t));
wt_nvs_close(handle);
return err;
}
int wifi_data_get_static(wifi_api_sta_ap_static_info_t *static_info)
{
nvs_handle_t handle;
int err;
err = wt_nvs_open(WIFI_NVS_NAMESPACE, &handle);
if (err) {
return err;
}
err = wt_nvs_get(handle, KEY_WIFI_STA_STATIC_BASE,
static_info, sizeof(wifi_api_sta_ap_static_info_t));
if (err == ESP_ERR_NVS_NOT_FOUND) {
static_info->static_ip_en = 0;
static_info->static_dns_en = 0;
err = ESP_OK;
} else if (err) {
printf("err %d\n", err);
goto end;
}
if (static_info->static_ip_en > 1) {
static_info->static_ip_en = 0;
}
if (static_info->static_dns_en > 1) {
static_info->static_dns_en = 0;
}
end:
wt_nvs_close(handle);
return err;
}
int wifi_data_save_static(wifi_api_sta_ap_static_info_t *static_info)
{
nvs_handle_t handle;
int err;
err = wt_nvs_open(WIFI_NVS_NAMESPACE, &handle);
if (err) {
return err;
}
err = wt_nvs_set(handle, KEY_WIFI_STA_STATIC_BASE,
static_info, sizeof(wifi_api_sta_ap_static_info_t));
if (err) {
goto end;
}
printf("static info saved\n");
end:
wt_nvs_close(handle);
return err;
} }

View File

@ -2,14 +2,28 @@
#define WIFI_STORAGE_H_GUARD #define WIFI_STORAGE_H_GUARD
#include <stdint-gcc.h> #include <stdint-gcc.h>
#include "wifi_api.h"
typedef struct nvs_wifi_credential_t { typedef struct nvs_wifi_credential_t {
char ssid[32]; char ssid[32];
char password[64]; char password[64];
} wifi_credential_t; } wifi_credential_t;
int wifi_data_get_last_conn_cred(wifi_credential_t *ap_credential); int wifi_data_get_sta_last_conn_cred(wifi_credential_t *ap_credential);
int wifi_data_save_sta_ap_credential(wifi_credential_t *ap_credential);
int wifi_data_save_wifi_mode(wifi_apsta_mode_e mode);
int wifi_data_get_wifi_mode(wifi_apsta_mode_e *mode);
int wifi_data_get_ap_credential(wifi_credential_t *ap_credential);
int wifi_data_save_ap_credential(wifi_credential_t *ap_credential);
int wifi_data_get_static(wifi_api_sta_ap_static_info_t *static_info);
int wifi_data_save_static(wifi_api_sta_ap_static_info_t *static_info);
int wifi_save_ap_credential(wifi_credential_t *ap_credential);
#endif //WIFI_STORAGE_H_GUARD #endif //WIFI_STORAGE_H_GUARD

View File

@ -11,19 +11,21 @@ typedef struct w_cache_t {
typedef enum wt_wifi_key_enum { typedef enum wt_wifi_key_enum {
KEY_WIFI_RESERVED = 0x000, KEY_WIFI_RESERVED = 0x000,
/* WIFI */ /* WIFI */
KEY_WIFI_AP_SSID, KEY_WIFI_AP_CRED = 0x1,
KEY_WIFI_AP_PASSWORD,
/* TODO: should have 1 for each AP */ /* TODO: should have 1 for each AP */
KEY_WIFI_STA_USE_STATIC, /* bit[0:31]=[IP, MASK, GATEWAY, DNS] */ KEY_WIFI_STA_USE_STATIC = 0x03, /* bit[0:31]=[IP, MASK, GATEWAY, DNS_MAIN, DNS_BACK] */
KEY_WIFI_STA_STATIC_IP, /* 4B */
KEY_WIFI_STA_STATIC_MASK, /* 4B */
KEY_WIFI_STA_STATIC_GATEWAY, /* 4B */
KEY_WIFI_STA_STATIC_DNS, /* 4B */
/* AP's information */ /* STA information */
KEY_WIFI_STA_LAST_AP_CRED, /*!< ssid[32] + password[64] */ KEY_WIFI_STA_LAST_AP_CRED = 0x08, /*!< ssid[32] + password[64] */
KEY_WIFI_STA_AP_BITMAP, KEY_WIFI_STA_AP_BITMAP = 0x09, /* 32 bit */
KEY_WIFI_STA_STATIC_BASE = 0x10, /* [IP:4B, MASK:4B, GW:4B, DNS1:4B, DNS2:4B] = 20B */
KEY_WIFI_STA_STATIC_LAST = 0x1F, /* [IP:4B, MASK:4B, GW:4B, DNS1:4B, DNS2:4B] */
KEY_WIFI_APSTA_MODE = 0xFF, /* 1B */
KEY_UNUSED_100 = 0x0100, /* avoid: same as 0x1 */
} wt_wifi_key; } wt_wifi_key;
#endif //WIFI_STORAGE_PRIV_H_GUARD #endif //WIFI_STORAGE_PRIV_H_GUARD

View File

@ -15,15 +15,16 @@ void wt_mdns_init()
/* TODO: read instance description from NVS */ /* TODO: read instance description from NVS */
ESP_ERROR_CHECK(mdns_instance_name_set(MDSN_INSTANCE_DESC)); ESP_ERROR_CHECK(mdns_instance_name_set(MDSN_INSTANCE_DESC));
uint8_t mac[6];
esp_netif_get_mac(esp_netif_get_default_netif(), mac);
char value[64];
snprintf(value, 63, "允斯调试器-%02X-%02X", mac[4], mac[5]);
value[63] = '\0';
//structure with TXT records //structure with TXT records
mdns_txt_item_t serviceTxtData[] = { mdns_txt_item_t serviceTxtData[] = {
#if defined CONFIG_IDF_TARGET_ESP32S3 {"name", value},
{"board", "esp32S3"},
#elif defined CONFIG_IDF_TARGET_ESP32C3
{"board", "esp32c3"},
#elif defined CONFIG_IDF_TARGET_ESP32
{"board", "esp32"},
#endif
}; };
//initialize service //initialize service

View File

@ -95,3 +95,21 @@ int wt_nvs_get_once(const char* namespace, const uint32_t key, void *data, uint3
wt_nvs_close(handle); wt_nvs_close(handle);
return 0; return 0;
} }
int wt_nvs_set_once(const char* namespace, const uint32_t key, void *data, uint32_t data_size)
{
nvs_handle_t handle;
int err;
err = wt_nvs_open(namespace, &handle);
if (err) {
return err;
}
err = wt_nvs_set(handle, key, data, data_size);
if (err) {
return err;
}
wt_nvs_close(handle);
return 0;
}

View File

@ -20,6 +20,9 @@ int wt_nvs_get(nvs_handle_t handle, uint32_t key, void *data, uint32_t data_size
int wt_nvs_set(nvs_handle_t handle, uint32_t key, void *data, uint32_t data_size); int wt_nvs_set(nvs_handle_t handle, uint32_t key, void *data, uint32_t data_size);
int wt_nvs_get_once(const char* namespace, const uint32_t key, void *data, uint32_t data_size);
int wt_nvs_set_once(const char* namespace, const uint32_t key, void *data, uint32_t data_size);
int wt_nvs_flush(nvs_handle_t handle); int wt_nvs_flush(nvs_handle_t handle);
void wt_nvs_init(); void wt_nvs_init();

View File

@ -12,6 +12,8 @@
typedef enum wt_system_cmd_t { typedef enum wt_system_cmd_t {
WT_SYS_GET_FM_INFO = 1, WT_SYS_GET_FM_INFO = 1,
WT_SYS_REBOOT = 2, WT_SYS_REBOOT = 2,
WT_SYS_DO_CRASH = 200,
} wt_system_cmd_t; } wt_system_cmd_t;

View File

@ -28,6 +28,11 @@ static int on_json_req(uint16_t cmd, api_json_req_t *req, api_json_module_async_
case WT_SYS_REBOOT: case WT_SYS_REBOOT:
wt_system_reboot(); wt_system_reboot();
return API_JSON_OK; return API_JSON_OK;
case WT_SYS_DO_CRASH: {
int *ptr = NULL;
*ptr = 66;
break;
}
} }
return API_JSON_UNSUPPORTED_CMD; return API_JSON_UNSUPPORTED_CMD;
} }

View File

@ -9,6 +9,8 @@ CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y
CONFIG_APP_BUILD_GENERATE_BINARIES=y CONFIG_APP_BUILD_GENERATE_BINARIES=y
CONFIG_APP_BUILD_BOOTLOADER=y CONFIG_APP_BUILD_BOOTLOADER=y
CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y
# CONFIG_APP_REPRODUCIBLE_BUILD is not set
# CONFIG_APP_NO_BLOBS is not set
# end of Build type # end of Build type
# #
@ -30,11 +32,15 @@ CONFIG_BOOTLOADER_SPI_WP_PIN=7
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
# CONFIG_BOOTLOADER_FACTORY_RESET is not set # CONFIG_BOOTLOADER_FACTORY_RESET is not set
# CONFIG_BOOTLOADER_APP_TEST is not set # CONFIG_BOOTLOADER_APP_TEST is not set
CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE=y
CONFIG_BOOTLOADER_WDT_ENABLE=y CONFIG_BOOTLOADER_WDT_ENABLE=y
# CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set # CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set
CONFIG_BOOTLOADER_WDT_TIME_MS=9000 CONFIG_BOOTLOADER_WDT_TIME_MS=9000
# CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE is not set CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
# CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK is not set
# CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is not set # CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is not set
# CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON is not set
# CONFIG_BOOTLOADER_SKIP_VALIDATE_ALWAYS is not set
CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0 CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0
# CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set # CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set
# end of Bootloader config # end of Bootloader config
@ -144,9 +150,6 @@ CONFIG_APPTRACE_LOCK_ENABLE=y
# #
# Legacy ADC Calibration Configuration # Legacy ADC Calibration Configuration
# #
CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y
CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y
CONFIG_ADC_CAL_LUT_ENABLE=y
# CONFIG_ADC_CALI_SUPPRESS_DEPRECATE_WARN is not set # CONFIG_ADC_CALI_SUPPRESS_DEPRECATE_WARN is not set
# end of Legacy ADC Calibration Configuration # end of Legacy ADC Calibration Configuration
# end of Legacy ADC Configuration # end of Legacy ADC Configuration
@ -305,8 +308,13 @@ CONFIG_ESP_CONSOLE_UART_DEFAULT=y
CONFIG_ESP_CONSOLE_UART=y CONFIG_ESP_CONSOLE_UART=y
CONFIG_ESP_CONSOLE_UART_NUM=0 CONFIG_ESP_CONSOLE_UART_NUM=0
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
# CONFIG_ESP_INT_WDT is not set CONFIG_ESP_INT_WDT=y
# CONFIG_ESP_TASK_WDT_INIT is not set CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
CONFIG_ESP_TASK_WDT_EN=y
CONFIG_ESP_TASK_WDT_INIT=y
# CONFIG_ESP_TASK_WDT_PANIC is not set
CONFIG_ESP_TASK_WDT_TIMEOUT_S=5
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y
# CONFIG_ESP_PANIC_HANDLER_IRAM is not set # CONFIG_ESP_PANIC_HANDLER_IRAM is not set
CONFIG_ESP_BROWNOUT_DET=y CONFIG_ESP_BROWNOUT_DET=y
@ -358,17 +366,53 @@ CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0=y
CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=752 CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=752
CONFIG_ESP_WIFI_MGMT_SBUF_NUM=32 CONFIG_ESP_WIFI_MGMT_SBUF_NUM=32
CONFIG_ESP_WIFI_IRAM_OPT=y CONFIG_ESP_WIFI_IRAM_OPT=y
CONFIG_ESP_WIFI_EXTRA_IRAM_OPT=y
CONFIG_ESP_WIFI_RX_IRAM_OPT=y CONFIG_ESP_WIFI_RX_IRAM_OPT=y
CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y
# CONFIG_ESP_WIFI_FTM_ENABLE is not set
# CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is not set
# CONFIG_ESP_WIFI_GCMP_SUPPORT is not set
# CONFIG_ESP_WIFI_GMAC_SUPPORT is not set
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y
# CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT is not set
CONFIG_ESP_WIFI_MBEDTLS_CRYPTO=y CONFIG_ESP_WIFI_MBEDTLS_CRYPTO=y
CONFIG_ESP_WIFI_MBEDTLS_TLS_CLIENT=y
# CONFIG_ESP_WIFI_WAPI_PSK is not set
# CONFIG_ESP_WIFI_SUITE_B_192 is not set
# CONFIG_ESP_WIFI_11KV_SUPPORT is not set
# CONFIG_ESP_WIFI_MBO_SUPPORT is not set
# CONFIG_ESP_WIFI_DPP_SUPPORT is not set
# CONFIG_ESP_WIFI_11R_SUPPORT is not set
# CONFIG_ESP_WIFI_WPS_SOFTAP_REGISTRAR is not set
#
# WPS Configuration Options
#
# CONFIG_ESP_WIFI_WPS_STRICT is not set
# CONFIG_ESP_WIFI_WPS_PASSPHRASE is not set
# end of WPS Configuration Options
# CONFIG_ESP_WIFI_DEBUG_PRINT is not set
# CONFIG_ESP_WIFI_TESTING_OPTIONS is not set
CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=y
# CONFIG_ESP_WIFI_ENT_FREE_DYNAMIC_BUFFER is not set
# end of Wi-Fi # end of Wi-Fi
# #
# Core dump # Core dump
# #
# CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH is not set CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y
# CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set # CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set
CONFIG_ESP_COREDUMP_ENABLE_TO_NONE=y # CONFIG_ESP_COREDUMP_ENABLE_TO_NONE is not set
# CONFIG_ESP_COREDUMP_DATA_FORMAT_BIN is not set
CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y
CONFIG_ESP_COREDUMP_CHECKSUM_CRC32=y
# CONFIG_ESP_COREDUMP_CHECK_BOOT is not set
CONFIG_ESP_COREDUMP_ENABLE=y
CONFIG_ESP_COREDUMP_LOGS=y
CONFIG_ESP_COREDUMP_MAX_TASKS_NUM=40
CONFIG_ESP_COREDUMP_STACK_SIZE=0
CONFIG_ESP_COREDUMP_SUMMARY_STACKDUMP_SIZE=1024
# end of Core dump # end of Core dump
# #
@ -460,9 +504,9 @@ CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
# CONFIG_LWIP_L2_TO_L3_COPY is not set # CONFIG_LWIP_L2_TO_L3_COPY is not set
CONFIG_LWIP_IRAM_OPTIMIZATION=y CONFIG_LWIP_IRAM_OPTIMIZATION=y
CONFIG_LWIP_TIMERS_ONDEMAND=y CONFIG_LWIP_TIMERS_ONDEMAND=y
CONFIG_LWIP_MAX_SOCKETS=10 CONFIG_LWIP_MAX_SOCKETS=16
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set # CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
# CONFIG_LWIP_SO_LINGER is not set CONFIG_LWIP_SO_LINGER=y
CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE=y
CONFIG_LWIP_SO_REUSE_RXTOALL=y CONFIG_LWIP_SO_REUSE_RXTOALL=y
# CONFIG_LWIP_SO_RCVBUF is not set # CONFIG_LWIP_SO_RCVBUF is not set
@ -783,7 +827,8 @@ CONFIG_SPIFFS_USE_MTIME=y
# #
# Websocket # Websocket
# #
# CONFIG_WS_TRANSPORT is not set CONFIG_WS_TRANSPORT=y
CONFIG_WS_BUFFER_SIZE=2048
# end of Websocket # end of Websocket
# end of TCP Transport # end of TCP Transport

View File

@ -19,7 +19,6 @@ CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y
# #
# Bootloader config # Bootloader config
# #
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x0
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set # CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set # CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set
@ -57,8 +56,6 @@ CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0
# #
# Security features # Security features
# #
CONFIG_SECURE_BOOT_V2_RSA_SUPPORTED=y
CONFIG_SECURE_BOOT_V2_PREFERRED=y
# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set # CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set
# CONFIG_SECURE_BOOT is not set # CONFIG_SECURE_BOOT is not set
# CONFIG_SECURE_FLASH_ENC_ENABLED is not set # CONFIG_SECURE_FLASH_ENC_ENABLED is not set
@ -73,15 +70,6 @@ CONFIG_APP_COMPILE_TIME_DATE=y
# CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set # CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set
CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16
# end of Application manager # end of Application manager
#
# Boot ROM Behavior
#
CONFIG_BOOT_ROM_LOG_ALWAYS_ON=y
# CONFIG_BOOT_ROM_LOG_ALWAYS_OFF is not set
# CONFIG_BOOT_ROM_LOG_ON_GPIO_HIGH is not set
# CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW is not set
# end of Boot ROM Behavior
# #
# Serial flasher config # Serial flasher config
# #
@ -192,91 +180,11 @@ CONFIG_APPTRACE_LOCK_ENABLE=y
# #
# SPI Configuration # SPI Configuration
# #
# CONFIG_SPI_MASTER_IN_IRAM is not set CONFIG_SPI_MASTER_IN_IRAM=y
CONFIG_SPI_MASTER_ISR_IN_IRAM=y CONFIG_SPI_MASTER_ISR_IN_IRAM=y
# CONFIG_SPI_SLAVE_IN_IRAM is not set # CONFIG_SPI_SLAVE_IN_IRAM is not set
CONFIG_SPI_SLAVE_ISR_IN_IRAM=y CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
# end of SPI Configuration
#
# TWAI Configuration
#
# CONFIG_TWAI_ISR_IN_IRAM is not set
CONFIG_TWAI_ERRATA_FIX_LISTEN_ONLY_DOM=y
# end of TWAI Configuration
#
# Temperature sensor Configuration
#
# CONFIG_TEMP_SENSOR_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_TEMP_SENSOR_ENABLE_DEBUG_LOG is not set
# end of Temperature sensor Configuration
#
# UART Configuration
#
CONFIG_UART_ISR_IN_IRAM=y
# end of UART Configuration
#
# GPIO Configuration
#
# CONFIG_GPIO_CTRL_FUNC_IN_IRAM is not set
# end of GPIO Configuration
#
# Sigma Delta Modulator Configuration
#
# CONFIG_SDM_CTRL_FUNC_IN_IRAM is not set
# CONFIG_SDM_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_SDM_ENABLE_DEBUG_LOG is not set
# end of Sigma Delta Modulator Configuration
#
# GPTimer Configuration
#
CONFIG_GPTIMER_ISR_HANDLER_IN_IRAM=y
# CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is not set
# CONFIG_GPTIMER_ISR_IRAM_SAFE is not set
# CONFIG_GPTIMER_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_GPTIMER_ENABLE_DEBUG_LOG is not set
# end of GPTimer Configuration
#
# RMT Configuration
#
# CONFIG_RMT_ISR_IRAM_SAFE is not set
# CONFIG_RMT_RECV_FUNC_IN_IRAM is not set
# CONFIG_RMT_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_RMT_ENABLE_DEBUG_LOG is not set
# end of RMT Configuration
#
# I2S Configuration
#
# CONFIG_I2S_ISR_IRAM_SAFE is not set
# CONFIG_I2S_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_I2S_ENABLE_DEBUG_LOG is not set
# end of I2S Configuration
#
# USB Serial/JTAG Configuration
#
# end of USB Serial/JTAG Configuration
#
# LEDC Configuration
#
# CONFIG_LEDC_CTRL_FUNC_IN_IRAM is not set
# end of LEDC Configuration
#
# I2C Configuration
#
# CONFIG_I2C_ISR_IRAM_SAFE is not set
# CONFIG_I2C_ENABLE_DEBUG_LOG is not set
# end of I2C Configuration
# end of Driver Configurations
# #
# eFuse Bit Manager # eFuse Bit Manager
@ -609,7 +517,7 @@ CONFIG_ESP_WIFI_EXTRA_IRAM_OPT=y
CONFIG_ESP_WIFI_RX_IRAM_OPT=y CONFIG_ESP_WIFI_RX_IRAM_OPT=y
CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y
# CONFIG_ESP_WIFI_FTM_ENABLE is not set # CONFIG_ESP_WIFI_FTM_ENABLE is not set
# CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is not set CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=y
# CONFIG_ESP_WIFI_GCMP_SUPPORT is not set # CONFIG_ESP_WIFI_GCMP_SUPPORT is not set
# CONFIG_ESP_WIFI_GMAC_SUPPORT is not set # CONFIG_ESP_WIFI_GMAC_SUPPORT is not set
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y
@ -640,9 +548,18 @@ CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=y
# #
# Core dump # Core dump
# #
# CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH is not set CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y
# CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set # CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set
CONFIG_ESP_COREDUMP_ENABLE_TO_NONE=y # CONFIG_ESP_COREDUMP_ENABLE_TO_NONE is not set
# CONFIG_ESP_COREDUMP_DATA_FORMAT_BIN is not set
CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y
CONFIG_ESP_COREDUMP_CHECKSUM_CRC32=y
# CONFIG_ESP_COREDUMP_CHECK_BOOT is not set
CONFIG_ESP_COREDUMP_ENABLE=y
CONFIG_ESP_COREDUMP_LOGS=y
CONFIG_ESP_COREDUMP_MAX_TASKS_NUM=40
CONFIG_ESP_COREDUMP_STACK_SIZE=0
CONFIG_ESP_COREDUMP_SUMMARY_STACKDUMP_SIZE=1024
# end of Core dump # end of Core dump
# #
@ -802,7 +719,7 @@ CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=50
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set # CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set CONFIG_LWIP_DHCP_RESTORE_LAST_IP=y
CONFIG_LWIP_DHCP_OPTIONS_LEN=68 CONFIG_LWIP_DHCP_OPTIONS_LEN=68
# #
@ -1049,7 +966,7 @@ CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
# CONFIG_MBEDTLS_CHACHA20_C is not set # CONFIG_MBEDTLS_CHACHA20_C is not set
# CONFIG_MBEDTLS_HKDF_C is not set # CONFIG_MBEDTLS_HKDF_C is not set
# CONFIG_MBEDTLS_THREADING_C is not set # CONFIG_MBEDTLS_THREADING_C is not set
CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI=y # CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI is not set
# end of mbedTLS # end of mbedTLS
# #
@ -1215,7 +1132,7 @@ CONFIG_SPIFFS_USE_MTIME=y
# Websocket # Websocket
# #
CONFIG_WS_TRANSPORT=y CONFIG_WS_TRANSPORT=y
CONFIG_WS_BUFFER_SIZE=1024 CONFIG_WS_BUFFER_SIZE=2048
# end of Websocket # end of Websocket
# end of TCP Transport # end of TCP Transport

View File

@ -20,7 +20,6 @@ CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y
# #
# Bootloader config # Bootloader config
# #
CONFIG_BOOTLOADER_OFFSET_IN_FLASH=0x0
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set # CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set # CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set
@ -46,7 +45,8 @@ CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE=y
CONFIG_BOOTLOADER_WDT_ENABLE=y CONFIG_BOOTLOADER_WDT_ENABLE=y
# CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set # CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set
CONFIG_BOOTLOADER_WDT_TIME_MS=9000 CONFIG_BOOTLOADER_WDT_TIME_MS=9000
# CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE is not set CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
# CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK is not set
# CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is not set # CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is not set
# CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON is not set # CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON is not set
# CONFIG_BOOTLOADER_SKIP_VALIDATE_ALWAYS is not set # CONFIG_BOOTLOADER_SKIP_VALIDATE_ALWAYS is not set
@ -57,8 +57,6 @@ CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0
# #
# Security features # Security features
# #
CONFIG_SECURE_BOOT_V2_RSA_SUPPORTED=y
CONFIG_SECURE_BOOT_V2_PREFERRED=y
# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set # CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set
# CONFIG_SECURE_BOOT is not set # CONFIG_SECURE_BOOT is not set
# CONFIG_SECURE_FLASH_ENC_ENABLED is not set # CONFIG_SECURE_FLASH_ENC_ENABLED is not set
@ -73,39 +71,6 @@ CONFIG_APP_COMPILE_TIME_DATE=y
# CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set # CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set
CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16
# end of Application manager # end of Application manager
CONFIG_ESP_ROM_HAS_CRC_LE=y
CONFIG_ESP_ROM_HAS_CRC_BE=y
CONFIG_ESP_ROM_HAS_MZ_CRC32=y
CONFIG_ESP_ROM_HAS_JPEG_DECODE=y
CONFIG_ESP_ROM_UART_CLK_IS_XTAL=y
CONFIG_ESP_ROM_HAS_RETARGETABLE_LOCKING=y
CONFIG_ESP_ROM_USB_OTG_NUM=3
CONFIG_ESP_ROM_USB_SERIAL_DEVICE_NUM=4
CONFIG_ESP_ROM_HAS_ERASE_0_REGION_BUG=y
CONFIG_ESP_ROM_GET_CLK_FREQ=y
CONFIG_ESP_ROM_HAS_HAL_WDT=y
CONFIG_ESP_ROM_NEEDS_SWSETUP_WORKAROUND=y
CONFIG_ESP_ROM_HAS_LAYOUT_TABLE=y
CONFIG_ESP_ROM_HAS_SPI_FLASH=y
CONFIG_ESP_ROM_HAS_ETS_PRINTF_BUG=y
CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT=y
CONFIG_ESP_ROM_NEEDS_SET_CACHE_MMU_SIZE=y
CONFIG_ESP_ROM_RAM_APP_NEEDS_MMU_INIT=y
CONFIG_ESP_ROM_HAS_FLASH_COUNT_PAGES_BUG=y
CONFIG_ESP_ROM_HAS_CACHE_SUSPEND_WAITI_BUG=y
CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG=y
CONFIG_ESP_ROM_HAS_SW_FLOAT=y
#
# Boot ROM Behavior
#
CONFIG_BOOT_ROM_LOG_ALWAYS_ON=y
# CONFIG_BOOT_ROM_LOG_ALWAYS_OFF is not set
# CONFIG_BOOT_ROM_LOG_ON_GPIO_HIGH is not set
# CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW is not set
# end of Boot ROM Behavior
# #
# Serial flasher config # Serial flasher config
# #
@ -118,6 +83,7 @@ CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y
CONFIG_ESPTOOLPY_FLASHMODE="dio" CONFIG_ESPTOOLPY_FLASHMODE="dio"
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set # CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set # CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
CONFIG_ESPTOOLPY_FLASHFREQ="80m" CONFIG_ESPTOOLPY_FLASHFREQ="80m"
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
@ -215,91 +181,11 @@ CONFIG_APPTRACE_LOCK_ENABLE=y
# #
# SPI Configuration # SPI Configuration
# #
# CONFIG_SPI_MASTER_IN_IRAM is not set CONFIG_SPI_MASTER_IN_IRAM=y
CONFIG_SPI_MASTER_ISR_IN_IRAM=y CONFIG_SPI_MASTER_ISR_IN_IRAM=y
# CONFIG_SPI_SLAVE_IN_IRAM is not set # CONFIG_SPI_SLAVE_IN_IRAM is not set
CONFIG_SPI_SLAVE_ISR_IN_IRAM=y CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
# end of SPI Configuration
#
# TWAI Configuration
#
# CONFIG_TWAI_ISR_IN_IRAM is not set
CONFIG_TWAI_ERRATA_FIX_LISTEN_ONLY_DOM=y
# end of TWAI Configuration
#
# Temperature sensor Configuration
#
# CONFIG_TEMP_SENSOR_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_TEMP_SENSOR_ENABLE_DEBUG_LOG is not set
# end of Temperature sensor Configuration
#
# UART Configuration
#
CONFIG_UART_ISR_IN_IRAM=y
# end of UART Configuration
#
# GPIO Configuration
#
# CONFIG_GPIO_CTRL_FUNC_IN_IRAM is not set
# end of GPIO Configuration
#
# Sigma Delta Modulator Configuration
#
# CONFIG_SDM_CTRL_FUNC_IN_IRAM is not set
# CONFIG_SDM_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_SDM_ENABLE_DEBUG_LOG is not set
# end of Sigma Delta Modulator Configuration
#
# GPTimer Configuration
#
CONFIG_GPTIMER_ISR_HANDLER_IN_IRAM=y
# CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is not set
# CONFIG_GPTIMER_ISR_IRAM_SAFE is not set
# CONFIG_GPTIMER_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_GPTIMER_ENABLE_DEBUG_LOG is not set
# end of GPTimer Configuration
#
# RMT Configuration
#
# CONFIG_RMT_ISR_IRAM_SAFE is not set
# CONFIG_RMT_RECV_FUNC_IN_IRAM is not set
# CONFIG_RMT_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_RMT_ENABLE_DEBUG_LOG is not set
# end of RMT Configuration
#
# I2S Configuration
#
# CONFIG_I2S_ISR_IRAM_SAFE is not set
# CONFIG_I2S_SUPPRESS_DEPRECATE_WARN is not set
# CONFIG_I2S_ENABLE_DEBUG_LOG is not set
# end of I2S Configuration
#
# USB Serial/JTAG Configuration
#
# end of USB Serial/JTAG Configuration
#
# LEDC Configuration
#
# CONFIG_LEDC_CTRL_FUNC_IN_IRAM is not set
# end of LEDC Configuration
#
# I2C Configuration
#
# CONFIG_I2C_ISR_IRAM_SAFE is not set
# CONFIG_I2C_ENABLE_DEBUG_LOG is not set
# end of I2C Configuration
# end of Driver Configurations
# #
# eFuse Bit Manager # eFuse Bit Manager
@ -641,7 +527,7 @@ CONFIG_ESP_WIFI_NVS_ENABLED=y
CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=752 CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=752
CONFIG_ESP_WIFI_MGMT_SBUF_NUM=32 CONFIG_ESP_WIFI_MGMT_SBUF_NUM=32
CONFIG_ESP_WIFI_IRAM_OPT=y CONFIG_ESP_WIFI_IRAM_OPT=y
# CONFIG_ESP_WIFI_EXTRA_IRAM_OPT is not set CONFIG_ESP_WIFI_EXTRA_IRAM_OPT=y
CONFIG_ESP_WIFI_RX_IRAM_OPT=y CONFIG_ESP_WIFI_RX_IRAM_OPT=y
CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=y
CONFIG_ESP_WIFI_ENABLE_SAE_PK=y CONFIG_ESP_WIFI_ENABLE_SAE_PK=y
@ -680,9 +566,18 @@ CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=y
# #
# Core dump # Core dump
# #
# CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH is not set CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y
# CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set # CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set
CONFIG_ESP_COREDUMP_ENABLE_TO_NONE=y # CONFIG_ESP_COREDUMP_ENABLE_TO_NONE is not set
# CONFIG_ESP_COREDUMP_DATA_FORMAT_BIN is not set
CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y
CONFIG_ESP_COREDUMP_CHECKSUM_CRC32=y
# CONFIG_ESP_COREDUMP_CHECK_BOOT is not set
CONFIG_ESP_COREDUMP_ENABLE=y
CONFIG_ESP_COREDUMP_LOGS=y
CONFIG_ESP_COREDUMP_MAX_TASKS_NUM=40
CONFIG_ESP_COREDUMP_STACK_SIZE=0
CONFIG_ESP_COREDUMP_SUMMARY_STACKDUMP_SIZE=1024
# end of Core dump # end of Core dump
# #
@ -843,7 +738,7 @@ CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set # CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set CONFIG_LWIP_DHCP_RESTORE_LAST_IP=y
CONFIG_LWIP_DHCP_OPTIONS_LEN=68 CONFIG_LWIP_DHCP_OPTIONS_LEN=68
CONFIG_LWIP_NUM_NETIF_CLIENT_DATA=0 CONFIG_LWIP_NUM_NETIF_CLIENT_DATA=0
CONFIG_LWIP_DHCP_COARSE_TIMER_SECS=1 CONFIG_LWIP_DHCP_COARSE_TIMER_SECS=1
@ -1098,11 +993,10 @@ CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
# #
# ESP-MQTT Configurations # ESP-MQTT Configurations
# #
CONFIG_MQTT_PROTOCOL_311=y # CONFIG_MQTT_PROTOCOL_311 is not set
# CONFIG_MQTT_PROTOCOL_5 is not set # CONFIG_MQTT_PROTOCOL_5 is not set
CONFIG_MQTT_TRANSPORT_SSL=y # CONFIG_MQTT_TRANSPORT_SSL is not set
CONFIG_MQTT_TRANSPORT_WEBSOCKET=y # CONFIG_MQTT_TRANSPORT_WEBSOCKET is not set
CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE=y
# CONFIG_MQTT_MSG_ID_INCREMENTAL is not set # CONFIG_MQTT_MSG_ID_INCREMENTAL is not set
# CONFIG_MQTT_SKIP_PUBLISH_IF_DISCONNECTED is not set # CONFIG_MQTT_SKIP_PUBLISH_IF_DISCONNECTED is not set
# CONFIG_MQTT_REPORT_DELETED_MESSAGES is not set # CONFIG_MQTT_REPORT_DELETED_MESSAGES is not set
@ -1259,7 +1153,7 @@ CONFIG_SPIFFS_USE_MTIME=y
# Websocket # Websocket
# #
CONFIG_WS_TRANSPORT=y CONFIG_WS_TRANSPORT=y
CONFIG_WS_BUFFER_SIZE=1024 CONFIG_WS_BUFFER_SIZE=2048
# end of Websocket # end of Websocket
# end of TCP Transport # end of TCP Transport