Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1754122021, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"2c495f747defd0cf2dc9a6296a1b5718", "commit": {"type":"commit", "time": 1594826280, "time_ofs": 60, "oid_tree": { "oid": "f3eda977242a4680b09291aaab61c9f5dd8a8be3", "alias": []}, "oid":{ "oid": "6762c7367f507dda477332eb403ed154a7848b01", "alias": []}, "msg": "remove: old esp32 helper pieces", "sig_commit": { "git_time": { "time": 1594826280, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1594644297, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "remove: old esp32 helper pieces\n\nThe old esp32 -factory stuff along with the lws support doesn't have a\nfuture in its old form. It has users but the ratio of effort to\ncontribution is really especially bad. I haven't updated it for more\nthan a year since esp-idf changes broke the original stuff.\n\nFreertos plat is alive and well and getting a lot of new use, ESP-32 is\nsupported both there and by modern lws_drivers pieces, including in CI\non real hardware, any further effort will be invested in that direction\ninstead of more vendor api-specific code (outside of wrapper\nimplementation).\n\nlws_drivers wraps any SDK apis in generic lws apis such that your code\njust uses those, enabling it to become SDK / SoC / vendor independent.\nIts first implementation is on esp-idf, the low and mid-level features\nthat were in the old -factory are already available using that and\nnew technologies like lws_struct and Secure Streams." , "diff": "diff --git a/CMakeLists.txt b/CMakeLists.txt\nindex f5b5500..d9e4cb4 100644\n--- a/CMakeLists.txt\n+++ b/CMakeLists.txt\n@@ -170,7 +170,6 @@ option(LWS_STATIC_PIC \u0022Build the static version of the library with position-ind\n # Specific platforms\n #\n option(LWS_WITH_ESP32 \u0022Build for ESP32\u0022 OFF)\n-option(LWS_WITH_ESP32_HELPER \u0022Build ESP32 helper\u0022 OFF)\n option(LWS_PLAT_OPTEE \u0022Build for OPTEE\u0022 OFF)\n option(LWS_PLAT_FREERTOS \u0022Build for FreeRTOS\u0022 OFF)\n option(LWS_PLAT_ANDROID \u0022Android flavour of unix platform\u0022 OFF)\ndiff --git a/include/libwebsockets.h b/include/libwebsockets.h\nindex b015aa1..c60b87d 100644\n--- a/include/libwebsockets.h\n+++ b/include/libwebsockets.h\n@@ -353,9 +353,6 @@ struct lws_pollfd {\n \n #if defined(LWS_PLAT_FREERTOS)\n #include \u003clibwebsockets/lws-freertos.h\u003e\n-#if defined(LWS_WITH_ESP32)\n-#include \u003clibwebsockets/lws-esp32.h\u003e\n-#endif\n #else\n typedef int lws_sockfd_type;\n typedef int lws_filefd_type;\ndiff --git a/include/libwebsockets/lws-esp32.h b/include/libwebsockets/lws-esp32.h\ndeleted file mode 100644\nindex 5105b3b..0000000\n--- a/include/libwebsockets/lws-esp32.h\n+++ /dev/null\n@@ -1,156 +0,0 @@\n-/*\n- * libwebsockets - small server side websockets and web server implementation\n- *\n- * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n- *\n- * Permission is hereby granted, free of charge, to any person obtaining a copy\n- * of this software and associated documentation files (the \u0022Software\u0022), to\n- * deal in the Software without restriction, including without limitation the\n- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n- * sell copies of the Software, and to permit persons to whom the Software is\n- * furnished to do so, subject to the following conditions:\n- *\n- * The above copyright notice and this permission notice shall be included in\n- * all copies or substantial portions of the Software.\n- *\n- * THE SOFTWARE IS PROVIDED \u0022AS IS\u0022, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n- * IN THE SOFTWARE.\n- *\n- * This is only included from libwebsockets.h if LWS_WITH_ESP32\n- */\n-\n-/* ESP32 helper declarations */\n-\n-#include \u003cmdns.h\u003e\n-#include \u003cesp_partition.h\u003e\n-\n-#define LWS_PLUGIN_STATIC\n-#define LWS_MAGIC_REBOOT_TYPE_ADS 0x50001ffc\n-#define LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY 0xb00bcafe\n-#define LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY 0xfaceb00b\n-#define LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON 0xf0cedfac\n-#define LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY_ERASE_OTA 0xfac0eeee\n-\n-/* user code provides these */\n-\n-extern void\n-lws_esp32_identify_physical_device(void);\n-\n-/* lws-plat-esp32 provides these */\n-\n-typedef void (*lws_cb_scan_done)(uint16_t count, wifi_ap_record_t *recs, void *arg);\n-\n-enum genled_state {\n-\tLWSESP32_GENLED__INIT,\n-\tLWSESP32_GENLED__LOST_NETWORK,\n-\tLWSESP32_GENLED__NO_NETWORK,\n-\tLWSESP32_GENLED__CONN_AP,\n-\tLWSESP32_GENLED__GOT_IP,\n-\tLWSESP32_GENLED__OK,\n-};\n-\n-struct lws_group_member {\n-\tstruct lws_group_member *next;\n-\tuint64_t last_seen;\n-\tchar model[16];\n-\tchar role[16];\n-\tchar host[32];\n-\tchar mac[20];\n-\tint width, height;\n-\tstruct ip4_addr addr;\n-\tstruct ip6_addr addrv6;\n-\tuint8_t\tflags;\n-};\n-\n-#define LWS_SYSTEM_GROUP_MEMBER_ADD\t\t1\n-#define LWS_SYSTEM_GROUP_MEMBER_CHANGE\t\t2\n-#define LWS_SYSTEM_GROUP_MEMBER_REMOVE\t\t3\n-\n-#define LWS_GROUP_FLAG_SELF 1\n-\n-struct lws_esp32 {\n-\tchar sta_ip[16];\n-\tchar sta_mask[16];\n-\tchar sta_gw[16];\n-\tchar serial[16];\n-\tchar opts[16];\n-\tchar model[16];\n-\tchar group[16];\n-\tchar role[16];\n-\tchar ssid[4][64];\n-\tchar password[4][64];\n-\tchar active_ssid[64];\n-\tchar access_pw[16];\n-\tchar hostname[32];\n-\tchar mac[20];\n-\tchar le_dns[64];\n-\tchar le_email[64];\n- \tchar region;\n- \tchar inet;\n-\tchar conn_ap;\n-\n-\tenum genled_state genled;\n-\tuint64_t genled_t;\n-\n-\tlws_cb_scan_done scan_consumer;\n-\tvoid *scan_consumer_arg;\n-\tstruct lws_group_member *first;\n-\tint extant_group_members;\n-\n-\tchar acme;\n-\tchar upload;\n-\n-\tvolatile char button_is_down;\n-};\n-\n-struct lws_esp32_image {\n-\tuint32_t romfs;\n-\tuint32_t romfs_len;\n-\tuint32_t json;\n-\tuint32_t json_len;\n-};\n-\n-extern struct lws_esp32 lws_esp32;\n-struct lws_vhost;\n-\n-extern esp_err_t\n-lws_esp32_event_passthru(void *ctx, system_event_t *event);\n-extern void\n-lws_esp32_wlan_config(void);\n-extern void\n-lws_esp32_wlan_start_ap(void);\n-extern void\n-lws_esp32_wlan_start_station(void);\n-struct lws_context_creation_info;\n-extern void\n-lws_esp32_set_creation_defaults(struct lws_context_creation_info *info);\n-extern struct lws_context *\n-lws_esp32_init(struct lws_context_creation_info *, struct lws_vhost **pvh);\n-extern int\n-lws_esp32_wlan_nvs_get(int retry);\n-extern esp_err_t\n-lws_nvs_set_str(nvs_handle handle, const char* key, const char* value);\n-extern void\n-lws_esp32_restart_guided(uint32_t type);\n-extern const esp_partition_t *\n-lws_esp_ota_get_boot_partition(void);\n-extern int\n-lws_esp32_get_image_info(const esp_partition_t *part, struct lws_esp32_image *i, char *json, int json_len);\n-extern int\n-lws_esp32_leds_network_indication(void);\n-\n-extern uint32_t lws_esp32_get_reboot_type(void);\n-extern uint16_t lws_esp32_sine_interp(int n);\n-\n-/* required in external code by esp32 plat (may just return if no leds) */\n-extern void lws_esp32_leds_timer_cb(TimerHandle_t th);\n-\n-\n-#include \u0022libwebsockets/lws-gpio.h\u0022\n-extern const lws_gpio_ops_t lws_gpio_plat;\n-\ndiff --git a/include/libwebsockets/lws-freertos.h b/include/libwebsockets/lws-freertos.h\nindex 2dd7ff4..a787229 100644\n--- a/include/libwebsockets/lws-freertos.h\n+++ b/include/libwebsockets/lws-freertos.h\n@@ -74,6 +74,10 @@ struct pollfd {\n #if defined(LWS_ESP_PLATFORM)\n #include \u0022lwip/sockets.h\u0022\n #include \u0022lwip/netdb.h\u0022\n+#if defined(LWS_WITH_DRIVERS)\n+#include \u0022libwebsockets/lws-gpio.h\u0022\n+extern const lws_gpio_ops_t lws_gpio_plat;\n+#endif\n #endif\n \n #endif /* LWS_AMAZON_RTOS */\ndiff --git a/lib/plat/freertos/CMakeLists.txt b/lib/plat/freertos/CMakeLists.txt\nindex 1953ac2..c0d92e9 100644\n--- a/lib/plat/freertos/CMakeLists.txt\n+++ b/lib/plat/freertos/CMakeLists.txt\n@@ -46,9 +46,6 @@ if (LWS_ESP_PLATFORM AND LWS_WITH_DRIVERS)\n \t\tlist(APPEND SOURCES plat/freertos/esp32/drivers/netdev/wifi-esp32.c)\n \tendif()\n endif()\n-if (LWS_WITH_ESP32_HELPER)\n-\tlist(APPEND SOURCES plat/freertos/esp32/esp32-helpers.c)\n-endif()\n if (LWS_WITH_FILE_OPS)\n \tlist(APPEND SOURCES plat/freertos/freertos-file.c)\n endif()\ndiff --git a/lib/plat/freertos/esp32/esp32-helpers.c b/lib/plat/freertos/esp32/esp32-helpers.c\ndeleted file mode 100644\nindex f646354..0000000\n--- a/lib/plat/freertos/esp32/esp32-helpers.c\n+++ /dev/null\n@@ -1,1373 +0,0 @@\n-/*\n- * libwebsockets - small server side websockets and web server implementation\n- *\n- * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n- *\n- * Permission is hereby granted, free of charge, to any person obtaining a copy\n- * of this software and associated documentation files (the \u0022Software\u0022), to\n- * deal in the Software without restriction, including without limitation the\n- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n- * sell copies of the Software, and to permit persons to whom the Software is\n- * furnished to do so, subject to the following conditions:\n- *\n- * The above copyright notice and this permission notice shall be included in\n- * all copies or substantial portions of the Software.\n- *\n- * THE SOFTWARE IS PROVIDED \u0022AS IS\u0022, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n- * IN THE SOFTWARE.\n- */\n-\n-#include \u0022private-lib-core.h\u0022\n-\n-#include \u0022romfs.h\u0022\n-#include \u003cesp_ota_ops.h\u003e\n-#include \u003ctcpip_adapter.h\u003e\n-#include \u003cesp_image_format.h\u003e\n-#include \u003cesp_task_wdt.h\u003e\n-#include \u0022soc/ledc_reg.h\u0022\n-#include \u0022driver/ledc.h\u0022\n-\n-struct lws_esp32 lws_esp32 \u003d {\n-\t.model \u003d CONFIG_LWS_MODEL_NAME,\n-\t.serial \u003d \u0022unknown\u0022,\n-};\n-\n-/*\n- * Group AP / Station State\n- */\n-\n-enum lws_gapss {\n-\tLWS_GAPSS_INITIAL,\t/* just started up, init and move to\n-\t\t\t\t * LWS_GAPSS_SCAN */\n-\tLWS_GAPSS_SCAN,\t\t/*\n-\t\t\t\t * Unconnected, scanning: AP known in one of the\n-\t\t\t\t * config slots -\u003e configure it, start timeout +\n-\t\t\t\t * LWS_GAPSS_STAT, if no AP already up in same\n-\t\t\t\t * group with lower MAC, after a random period\n-\t\t\t\t * start up our AP (LWS_GAPSS_AP)\n-\t\t\t\t */\n-\tLWS_GAPSS_AP,\t\t/*\n-\t\t\t\t * Trying to be the group AP... periodically do\n-\t\t\t\t * a scan LWS_GAPSS_AP_SCAN, faster and then\n-\t\t\t\t * slower\n- \t\t\t\t */\n-\tLWS_GAPSS_AP_SCAN,\t/*\n-\t\t\t\t * doing a scan while trying to be the group\n-\t\t\t\t * AP... if we see a lower MAC being the AP for\n-\t\t\t\t * the same group AP, abandon being an AP and\n-\t\t\t\t * join that AP as a station\n-\t\t\t\t */\n-\tLWS_GAPSS_STAT_GRP_AP,\t/*\n-\t\t\t\t * We have decided to join another group member\n-\t\t\t\t * who is being the AP, as its MAC is lower than\n-\t\t\t\t * ours. This is a stable state, but we still\n-\t\t\t\t * do periodic scans LWS_GAPSS_STAT_GRP_AP_SCAN\n-\t\t\t\t * and will always prefer an AP configured in a\n-\t\t\t\t * slot.\n-\t\t\t\t */\n-\tLWS_GAPSS_STAT_GRP_AP_SCAN,\n-\t\t\t\t/*\n-\t\t\t\t * We have joined a group member who is doing\n-\t\t\t\t * the AP job... we want to check every now and\n-\t\t\t\t * then if a configured AP has appeared that we\n-\t\t\t\t * should better use instead. Otherwise stay in\n-\t\t\t\t * LWS_GAPSS_STAT_GRP_AP\n-\t\t\t\t */\n-\tLWS_GAPSS_STAT,\t\t/*\n-\t\t\t\t * trying to connect to another non-group AP.\n-\t\t\t\t * If we don't get an IP within a timeout and\n-\t\t\t\t * retries, blacklist it and go back\n-\t\t\t\t */\n-\tLWS_GAPSS_STAT_HAPPY,\n-};\n-\n-static const char *gapss_str[] \u003d {\n-\t\u0022LWS_GAPSS_INITIAL\u0022,\n- \u0022LWS_GAPSS_SCAN\u0022,\n- \u0022LWS_GAPSS_AP\u0022,\n- \u0022LWS_GAPSS_AP_SCAN\u0022,\n- \u0022LWS_GAPSS_STAT_GRP_AP\u0022,\n- \u0022LWS_GAPSS_STAT_GRP_AP_SCAN\u0022,\n- \u0022LWS_GAPSS_STAT\u0022,\n-\t\u0022LWS_GAPSS_STAT_HAPPY\u0022,\n-};\n-\n-static romfs_t lws_esp32_romfs;\n-static TimerHandle_t leds_timer, scan_timer, debounce_timer, association_timer\n-#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION)\n-, mdns_timer\n-#endif\n-;\n-static enum lws_gapss gapss \u003d LWS_GAPSS_INITIAL;\n-#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION)\n-static mdns_result_t *mdns_results_head;\n-#endif\n-\n-#define GPIO_SW 14\n-\n-struct esp32_file {\n-\tconst struct inode *i;\n-};\n-\n-static void lws_gapss_to(enum lws_gapss to)\n-{\n-\tlwsl_notice(\u0022gapss from %s to %s\u005cn\u0022, gapss_str[gapss], gapss_str[to]);\n-\tgapss \u003d to;\n-}\n-\n-uint32_t lws_esp32_get_reboot_type(void)\n-{\n-\tuint32_t *p \u003d (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS, val \u003d *p;\n-\tnvs_handle nvh;\n-\tsize_t s \u003d 0;\n-\tint n \u003d 0;\n-\n-\tESP_ERROR_CHECK(nvs_open(\u0022lws-station\u0022, NVS_READWRITE, \u0026nvh));\n-\tif (nvs_get_blob(nvh, \u0022ssl-pub.pem\u0022, NULL, \u0026s) \u003d\u003d ESP_OK)\n-\t\tn \u003d 1;\n-\tif (nvs_get_blob(nvh, \u0022ssl-pri.pem\u0022, NULL, \u0026s) \u003d\u003d ESP_OK)\n-\t\tn |\u003d 2;\n-\tnvs_close(nvh);\n-\n-\t/*\n-\t * in the case the SSL certs are not there, don't require\n-\t * the button to be down to access all features.\n-\t */\n-\tif (n !\u003d 3)\n-\t\tval \u003d LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON;\n-\n-\treturn val;\n-}\n-\n-static void render_ip(char *dest, int len, uint8_t *ip)\n-{\n-\tsnprintf(dest, len, \u0022%u.%u.%u.%u\u0022, ip[0], ip[1], ip[2], ip[3]);\n-}\n-\n-void lws_esp32_restart_guided(uint32_t type)\n-{\n- uint32_t *p_force_factory_magic \u003d (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS;\n-\n-\tlwsl_notice(\u0022%s: %x\u005cn\u0022, __func__, type);\n- *p_force_factory_magic \u003d type;\n-\n-\tesp_restart();\n-}\n-\n-/*\n- * esp-idf goes crazy with zero length str nvs. Use this as a workaround\n- * to delete the key in that case.\n- */\n-\n-esp_err_t lws_nvs_set_str(nvs_handle handle, const char* key, const char* value)\n-{\n-\tif (*value)\n-\t\treturn nvs_set_str(handle, key, value);\n-\n-\treturn nvs_erase_key(handle, key);\n-}\n-\n-static wifi_scan_config_t scan_config \u003d {\n- .ssid \u003d 0,\n- .bssid \u003d 0,\n- .channel \u003d 0,\n- .show_hidden \u003d true\n-};\n-\n-static char scan_ongoing \u003d 0, scan_timer_exists \u003d 0;\n-static int try_slot \u003d -1;\n-\n-static wifi_config_t config \u003d {\n-\t.ap \u003d {\n-\t .channel \u003d 6,\n-\t .authmode \u003d WIFI_AUTH_OPEN,\n-\t .max_connection \u003d 1,\n-\t} }, sta_config \u003d {\n-\t.sta \u003d {\n-\t\t.bssid_set \u003d 0,\n-\t} };\n-\n-static void lws_esp32_scan_timer_cb(TimerHandle_t th)\n-{\n-\tint n;\n-\n-\tlwsl_notice(\u0022%s\u005cn\u0022, __func__);\n-\tscan_ongoing \u003d 0;\n-\tn \u003d esp_wifi_scan_start(\u0026scan_config, false);\n-\tif (n !\u003d ESP_OK)\n-\t\tlwsl_err(\u0022scan start failed %d\u005cn\u0022, n);\n-}\n-\n-static void lws_esp32_assoc_timer_cb(TimerHandle_t th)\n-{\n-\tint n;\n-\n-\txTimerStop(association_timer, 0);\n-\n-\tif (gapss \u003d\u003d LWS_GAPSS_STAT_HAPPY) {\n-\t\tlwsl_debug(\u0022%s: saw we were happy\u005cn\u0022, __func__);\n-\n-\t\treturn;\n-\t}\n-\n-\tlwsl_notice(\u0022%s: forcing rescan\u005cn\u0022, __func__);\n-\n-\tlws_gapss_to(LWS_GAPSS_SCAN);\n-\tscan_ongoing \u003d 0;\n-\tn \u003d esp_wifi_scan_start(\u0026scan_config, false);\n-\tif (n !\u003d ESP_OK)\n-\t\tlwsl_err(\u0022scan start failed %d\u005cn\u0022, n);\n-}\n-\n-\n-#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION)\n-\n-void __attribute__(( weak ))\n-lws_group_member_event(int e, void *p)\n-{\n-}\n-\n-void __attribute__(( weak ))\n-lws_get_iframe_size(int *w, int *h)\n-{\n-\t*w \u003d 320;\n-\t*h \u003d 160;\n-}\n-\n-void lws_group_member_event_call(int e, void *p)\n-{\n-\tlws_group_member_event(e, p);\n-}\n-\n-static int\n-get_txt_param(const mdns_result_t *mr, const char *param, char *result, int len)\n-{\n-\tconst char *p;\n-\n-\t*result \u003d '\u005c0';\n-\n-\tp \u003d strstr(mr-\u003etxt-\u003ekey, param);\n-\tif (!p) {\n-\t\t*result \u003d '\u005c0';\n-\t\treturn 1;\n-\t}\n-\n-\tlws_strncpy(result, mr-\u003etxt-\u003evalue, len);\n-\n-\treturn 0;\n-}\n-\n-static void lws_esp32_mdns_timer_cb(TimerHandle_t th)\n-{\n-\tuint64_t now \u003d lws_now_usecs();\n-\tstruct lws_group_member *p, **p1;\n-\tconst mdns_result_t *r \u003d mdns_results_head;\n-\n-\twhile (r) {\n-\t\tchar ch \u003d 0, group[16];\n-\n-\t\tget_txt_param(r, \u0022group\u0022, group, sizeof(group));\n-\t\tif (strcmp(group, lws_esp32.group)) /* not our group */ {\n-\t\t\tlwsl_notice(\u0022group %s vs %s %s\u005cn\u0022,\n-\t\t\t\t\tgroup, lws_esp32.group, r-\u003etxt-\u003evalue);\n-\t\t\tcontinue;\n-\t\t}\n-\n-\t\tp \u003d lws_esp32.first;\n-\t\twhile (p) {\n-\t\t\tif (strcmp(r-\u003ehostname, p-\u003ehost))\n-\t\t\t\tgoto next;\n-\t\t\tif (memcmp(\u0026r-\u003eaddr, \u0026p-\u003eaddr, sizeof(r-\u003eaddr)))\n-\t\t\t\tgoto next;\n-\n-\t\t\tp-\u003elast_seen \u003d now;\n-\t\t\tbreak;\n-next:\n-\t\t\tp \u003d p-\u003enext;\n-\t\t}\n-\t\tif (!p) { /* did not find */\n-\t\t\tchar temp[8];\n-\n-\t\t\tp \u003d lws_malloc(sizeof(*p), \u0022group\u0022);\n-\t\t\tif (!p)\n-\t\t\t\tcontinue;\n-\t\t\tlws_strncpy(p-\u003ehost, r-\u003ehostname, sizeof(p-\u003ehost));\n-\n-\t\t\tget_txt_param(r, \u0022model\u0022, p-\u003emodel, sizeof(p-\u003emodel));\n-\t\t\tget_txt_param(r, \u0022role\u0022, p-\u003erole, sizeof(p-\u003erole));\n-\t\t\tget_txt_param(r, \u0022mac\u0022, p-\u003emac, sizeof(p-\u003emac));\n-\t\t\tget_txt_param(r, \u0022width\u0022, temp, sizeof(temp));\n-\t\t\tp-\u003ewidth \u003d atoi(temp);\n-\t\t\tget_txt_param(r, \u0022height\u0022, temp, sizeof(temp));\n-\t\t\tp-\u003eheight \u003d atoi(temp);\n-\n-\t\t\tmemcpy(\u0026p-\u003eaddr, \u0026r-\u003eaddr, sizeof(p-\u003eaddr));\n-//\t\t\tmemcpy(\u0026p-\u003eaddrv6, \u0026r-\u003eaddrv6, sizeof(p-\u003eaddrv6));\n-\t\t\tp-\u003elast_seen \u003d now;\n-\t\t\tp-\u003eflags \u003d 0;\n-\t\t\tp-\u003enext \u003d lws_esp32.first;\n-\t\t\tlws_esp32.first \u003d p;\n-\t\t\tlws_esp32.extant_group_members++;\n-\n-\t\t\tlws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_ADD, p);\n-\t\t} else {\n-\t\t\tif (memcmp(\u0026p-\u003eaddr, \u0026r-\u003eaddr, sizeof(p-\u003eaddr))) {\n-\t\t\t\tmemcpy(\u0026p-\u003eaddr, \u0026r-\u003eaddr, sizeof(p-\u003eaddr));\n-\t\t\t\tch \u003d 1;\n-\t\t\t}\n-/*\t\t\tif (memcmp(\u0026p-\u003eaddrv6, \u0026r-\u003eaddrv6, sizeof(p-\u003eaddrv6))) {\n-\t\t\t\tmemcpy(\u0026p-\u003eaddrv6, \u0026r-\u003eaddrv6, sizeof(p-\u003eaddrv6));\n-\t\t\t\tch \u003d 1;\n-\t\t\t} */\n-\t\t\tif (ch)\n-\t\t\t\tlws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_CHANGE, p);\n-\t\t}\n-\t}\n-\n-\tmdns_query_results_free(mdns_results_head);\n-\n-\t/* garbage-collect group members not seen for too long */\n-\tp1 \u003d \u0026lws_esp32.first;\n-\twhile (*p1) {\n-\t\tp \u003d *p1;\n-\t\tif (!(p-\u003eflags \u0026 LWS_GROUP_FLAG_SELF) \u0026\u0026\n-\t\t\t\tnow - p-\u003elast_seen \u003e 60000000) {\n-\t\t\tlws_esp32.extant_group_members--;\n-\t\t\t*p1 \u003d p-\u003enext;\n-\n-\t\t\tlws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_REMOVE, p);\n-\t\t\tlws_free(p);\n-\t\t\tcontinue;\n-\t\t}\n-\t\tp1 \u003d \u0026(*p1)-\u003enext;\n-\t}\n-\n-\tmdns_query_txt(lws_esp32.group, \u0022_lwsgrmem\u0022, \u0022_tcp\u0022, 0,\n-\t\t\t \u0026mdns_results_head);\n-\txTimerStart(mdns_timer, 0);\n-}\n-#endif\n-\n-void __attribute__(( weak ))\n-lws_esp32_button(int down)\n-{\n-}\n-\n-void IRAM_ATTR\n-gpio_irq(void *arg)\n-{\n-\tgpio_set_intr_type(GPIO_SW, GPIO_INTR_DISABLE);\n-\txTimerStart(debounce_timer, 0);\n-}\n-\n-static void lws_esp32_debounce_timer_cb(TimerHandle_t th)\n-{\n-\tif (lws_esp32.button_is_down)\n-\t\tgpio_set_intr_type(GPIO_SW, GPIO_INTR_POSEDGE);\n-\telse\n-\t\tgpio_set_intr_type(GPIO_SW, GPIO_INTR_NEGEDGE);\n-\n-\tlws_esp32.button_is_down \u003d gpio_get_level(GPIO_SW);\n-\n-\tlws_esp32_button(lws_esp32.button_is_down);\n-}\n-\n-\n-static int\n-start_scan()\n-{\n-\t/* if no APs configured, no point... */\n-\n-\tif (!lws_esp32.ssid[0][0] \u0026\u0026\n-\t !lws_esp32.ssid[1][0] \u0026\u0026\n-\t !lws_esp32.ssid[2][0] \u0026\u0026\n-\t !lws_esp32.ssid[3][0])\n-\t\treturn 0;\n-\n-\tif (scan_timer_exists \u0026\u0026 !scan_ongoing) {\n-\t\t// lwsl_notice(\u0022Starting scan timer...\u005cn\u0022);\n-\t\tscan_ongoing \u003d 1;\n-\t\txTimerStart(scan_timer, 0);\n-\t}\n-\n-\treturn 0;\n-}\n-\n-\n-\n-static void\n-end_scan()\n-{\n-\twifi_ap_record_t ap_records[10];\n-\tuint16_t count_ap_records;\n-\tint n, m;\n-\n-\tcount_ap_records \u003d LWS_ARRAY_SIZE(ap_records);\n-\tif (esp_wifi_scan_get_ap_records(\u0026count_ap_records, ap_records)) {\n-\t\tlwsl_err(\u0022%s: failed\u005cn\u0022, __func__);\n-\t\treturn;\n-\t}\n-\n-\tif (!count_ap_records)\n-\t\tgoto passthru;\n-\n-\tif (gapss !\u003d LWS_GAPSS_SCAN) {\n-\t\tlwsl_info(\u0022ignoring scan as gapss %s\u005cn\u0022, gapss_str[gapss]);\n-\t\tgoto passthru;\n-\t}\n-\n-\t/* no point if no APs set up */\n-\tif (!lws_esp32.ssid[0][0] \u0026\u0026\n-\t !lws_esp32.ssid[1][0] \u0026\u0026\n-\t !lws_esp32.ssid[2][0] \u0026\u0026\n-\t !lws_esp32.ssid[3][0])\n-\t\tgoto passthru;\n-\n-\tlwsl_info(\u0022checking %d scan records\u005cn\u0022, count_ap_records);\n-\n-\tfor (n \u003d 0; n \u003c 4; n++) {\n-\n-\t\tif (!lws_esp32.ssid[(n + try_slot + 1) \u0026 3][0])\n-\t\t\tcontinue;\n-\n-\t\tlwsl_debug(\u0022looking for %s\u005cn\u0022,\n-\t\t\t lws_esp32.ssid[(n + try_slot + 1) \u0026 3]);\n-\n-\t\t/* this ssid appears in scan results? */\n-\n-\t\tfor (m \u003d 0; m \u003c count_ap_records; m++) {\n-\t\t\t// lwsl_notice(\u0022 %s\u005cn\u0022, ap_records[m].ssid);\n-\t\t\tif (!strcmp((char *)ap_records[m].ssid,\n-\t\t\t\t lws_esp32.ssid[(n + try_slot + 1) \u0026 3]))\n-\t\t\t\tgoto hit;\n-\t\t}\n-\n-\t\tcontinue;\n-\n-hit:\n-\t\tm \u003d (n + try_slot + 1) \u0026 3;\n-\t\ttry_slot \u003d m;\n-\t\tlwsl_info(\u0022Attempting connection with slot %d: %s:\u005cn\u0022, m,\n-\t\t\t\tlws_esp32.ssid[m]);\n-\t\t/* set the ssid we last tried to connect to */\n-\t\tlws_strncpy(lws_esp32.active_ssid, lws_esp32.ssid[m],\n-\t\t\t\tsizeof(lws_esp32.active_ssid));\n-\n-\t\tlws_strncpy((char *)sta_config.sta.ssid, lws_esp32.ssid[m],\n-\t\t\tsizeof(sta_config.sta.ssid));\n-\t\tlws_strncpy((char *)sta_config.sta.password, lws_esp32.password[m],\n-\t\t\tsizeof(sta_config.sta.password));\n-\n-\t\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA,\n-\t\t\t\t\t (const char *)\u0026config.ap.ssid[7]);\n-\t\tlws_gapss_to(LWS_GAPSS_STAT);\n-\t\txTimerStop(association_timer, 0);\n-\t\txTimerStart(association_timer, 0);\n-\n-\t\tesp_wifi_set_config(WIFI_IF_STA, \u0026sta_config);\n-\t\tesp_wifi_connect();\n-\t\tbreak;\n-\t}\n-\n-\tif (n \u003d\u003d 4)\n-\t\tstart_scan();\n-\n-passthru:\n-\tif (lws_esp32.scan_consumer)\n-\t\tlws_esp32.scan_consumer(count_ap_records, ap_records,\n-\t\t\t\t\tlws_esp32.scan_consumer_arg);\n-\n-}\n-\n-static void\n-lws_set_genled(int n)\n-{\n-\tlws_esp32.genled_t \u003d lws_now_usecs();\n-\tlws_esp32.genled \u003d n;\n-}\n-\n-int\n-lws_esp32_leds_network_indication(void)\n-{\n-\tuint64_t us, r;\n-\tint n, fadein \u003d 100, speed \u003d 1199, div \u003d 1, base \u003d 0;\n-\n-\tr \u003d lws_now_usecs();\n-\tus \u003d r - lws_esp32.genled_t;\n-\n-\tswitch (lws_esp32.genled) {\n-\tcase LWSESP32_GENLED__INIT:\n-\t\tlws_esp32.genled \u003d LWSESP32_GENLED__LOST_NETWORK;\n-\t\t/* fallthru */\n-\tcase LWSESP32_GENLED__LOST_NETWORK:\n-\t\tfadein \u003d us / 10000; /* 100 steps in 1s */\n-\t\tif (fadein \u003e 100) {\n-\t\t\tfadein \u003d 100;\n-\t\t\tlws_esp32.genled \u003d LWSESP32_GENLED__NO_NETWORK;\n-\t\t}\n-\t\t/* fallthru */\n-\tcase LWSESP32_GENLED__NO_NETWORK:\n-\t\tbreak;\n-\tcase LWSESP32_GENLED__CONN_AP:\n-\t\tbase \u003d 4096;\n-\t\tspeed \u003d 933;\n-\t\tdiv \u003d 2;\n-\t\tbreak;\n-\tcase LWSESP32_GENLED__GOT_IP:\n-\t\tfadein \u003d us / 10000; /* 100 steps in 1s */\n-\t\tif (fadein \u003e 100) {\n-\t\t\tfadein \u003d 100;\n-\t\t\tlws_esp32.genled \u003d LWSESP32_GENLED__OK;\n-\t\t}\n-\t\tfadein \u003d 100 - fadein; /* we are fading out */\n-\t\t/* fallthru */\n-\tcase LWSESP32_GENLED__OK:\n-\t\tif (lws_esp32.genled \u003d\u003d LWSESP32_GENLED__OK)\n-\t\t\treturn 0;\n-\n-\t\tbase \u003d 4096;\n-\t\tspeed \u003d 766;\n-\t\tdiv \u003d 3;\n-\t\tbreak;\n-\t}\n-\n-\tn \u003d base + (lws_esp32_sine_interp(r / speed) / div);\n-\treturn (n * fadein) / 100;\n-}\n-\n-esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)\n-{\n-#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION)\n-\tstruct lws_group_member *mem;\n-\tint n;\n-#endif\n-\tnvs_handle nvh;\n-\tuint32_t use;\n-\n-\tswitch((int)event-\u003eevent_id) {\n-\tcase SYSTEM_EVENT_STA_START:\n-\t\t//esp_wifi_connect();\n-//\t\tbreak;\n-\t\t/* fallthru */\n-\tcase SYSTEM_EVENT_STA_DISCONNECTED:\n-\t\tlwsl_notice(\u0022SYSTEM_EVENT_STA_DISCONNECTED\u005cn\u0022);\n-\t\tif (sntp_enabled())\n-\t\t\tsntp_stop();\n-\t\tlws_esp32.conn_ap \u003d 0;\n-\t\tlws_esp32.inet \u003d 0;\n-\t\tlws_esp32.sta_ip[0] \u003d '\u005c0';\n-\t\tlws_esp32.sta_mask[0] \u003d '\u005c0';\n-\t\tlws_esp32.sta_gw[0] \u003d '\u005c0';\n-\t\tlws_gapss_to(LWS_GAPSS_SCAN);\n-\t\tmdns_free();\n-\t\tlws_set_genled(LWSESP32_GENLED__LOST_NETWORK);\n-\t\tstart_scan();\n-\t\tesp_wifi_connect();\n-\t\tbreak;\n-\n-\tcase SYSTEM_EVENT_STA_CONNECTED:\n-\t\tlws_esp32.conn_ap \u003d 1;\n-\t\tlws_set_genled(LWSESP32_GENLED__CONN_AP);\n-\t\tbreak;\n-\n-\tcase SYSTEM_EVENT_STA_GOT_IP:\n-\t\tlwsl_notice(\u0022SYSTEM_EVENT_STA_GOT_IP\u005cn\u0022);\n-\n-\t\tlws_esp32.inet \u003d 1;\n-\t\tlws_set_genled(LWSESP32_GENLED__GOT_IP);\n-\n-\t\trender_ip(lws_esp32.sta_ip, sizeof(lws_esp32.sta_ip) - 1,\n-\t\t\t\t(uint8_t *)\u0026event-\u003eevent_info.got_ip.ip_info.ip);\n-\t\trender_ip(lws_esp32.sta_mask, sizeof(lws_esp32.sta_mask) - 1,\n-\t\t\t\t(uint8_t *)\u0026event-\u003eevent_info.got_ip.ip_info.netmask);\n-\t\trender_ip(lws_esp32.sta_gw, sizeof(lws_esp32.sta_gw) - 1,\n-\t\t\t\t(uint8_t *)\u0026event-\u003eevent_info.got_ip.ip_info.gw);\n-\n-\t\tif (!nvs_open(\u0022lws-station\u0022, NVS_READWRITE, \u0026nvh)) {\n-\t\t\tchar slot[8];\n-\n-\t\t\tlws_snprintf(slot, sizeof(slot) - 1, \u0022%duse\u0022, try_slot);\n-\t\t\tuse \u003d 0;\n-\t\t\tnvs_get_u32(nvh, slot, \u0026use);\n-\t\t\tnvs_set_u32(nvh, slot, use + 1);\n-\t\t\tnvs_commit(nvh);\n-\t\t\tnvs_close(nvh);\n-\t\t}\n-\n-\t\tlws_gapss_to(LWS_GAPSS_STAT_HAPPY);\n-\n-#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION)\n-\t\tn \u003d mdns_init();\n-\t\tif (!n) {\n-\t\t\tstatic mdns_txt_item_t txta[6];\n-\t\t\tstatic char wh[2][6];\n-\t\t\tint w, h;\n-\n-\t\t\tmdns_hostname_set(lws_esp32.hostname);\n-\t\t\tmdns_instance_name_set(lws_esp32.group);\n-\n-\t\t\tlws_get_iframe_size(\u0026w, \u0026h);\n-\n-\t\t\ttxta[0].key \u003d \u0022model\u0022;\n-\t\t\ttxta[1].key \u003d \u0022group\u0022;\n-\t\t\ttxta[2].key \u003d \u0022role\u0022;\n-\t\t\ttxta[3].key \u003d \u0022mac\u0022;\n-\t\t\ttxta[4].key \u003d \u0022width\u0022;\n-\t\t\ttxta[5].key \u003d \u0022height\u0022;\n-\n-\t\t\ttxta[0].value \u003d lws_esp32.model;\n-\t\t\ttxta[1].value \u003d lws_esp32.group;\n-\t\t\ttxta[2].value \u003d lws_esp32.role;\n-\t\t\ttxta[3].value \u003d lws_esp32.mac;\n-\t\t\ttxta[4].value \u003d wh[0];\n-\t\t\ttxta[5].value \u003d wh[1];\n-\n-\t\t\tlws_snprintf(wh[0], 6, \u0022%d\u0022, w);\n-\t\t\tlws_snprintf(wh[1], 6, \u0022%d\u0022, h);\n-\n-\t\t\tmdns_service_add(lws_esp32.group,\n-\t\t\t\t\t \u0022_lwsgrmem\u0022, \u0022_tcp\u0022, 443, txta,\n-\t\t\t\t\t LWS_ARRAY_SIZE(txta));\n-\n-\t\t\tmem \u003d lws_esp32.first;\n-\t\t\twhile (mem) {\n-\t\t\t\tif (mem-\u003eflags \u0026 1)\n-\t\t\t\t\tbreak;\n-\t\t\t\tmem \u003d mem-\u003enext;\n-\t\t\t}\n-\n-\t\t\tif (!mem) {\n-\t\t\t\tstruct lws_group_member *mem \u003d\n-\t\t\t\t\t lws_malloc(sizeof(*mem), \u0022group\u0022);\n-\t\t\t\tif (mem) {\n-\t\t\t\t\tmem-\u003elast_seen \u003d ~(uint64_t)0;\n-\t\t\t\t\tstrcpy(mem-\u003emodel, lws_esp32.model);\n-\t\t\t\t\tstrcpy(mem-\u003erole, lws_esp32.role);\n-\t\t\t\t\tstrcpy(mem-\u003ehost, lws_esp32.hostname);\n-\t\t\t\t\tstrcpy(mem-\u003emac, lws_esp32.mac);\n-\t\t\t\t\tmem-\u003eflags \u003d LWS_GROUP_FLAG_SELF;\n-\t\t\t\t\tlws_get_iframe_size(\u0026mem-\u003ewidth,\n-\t\t\t\t\t\t\t \u0026mem-\u003eheight);\n-\t\t\t\t\tmemcpy(\u0026mem-\u003eaddr,\n-\t\t\t\t\t \u0026event-\u003eevent_info.got_ip.ip_info.ip,\n-\t\t\t\t\t sizeof(mem-\u003eaddr));\n-\t\t\t\t\tmemcpy(\u0026mem-\u003eaddrv6,\n-\t\t\t\t\t \u0026event-\u003eevent_info.got_ip6.ip6_info.ip,\n-\t\t\t\t\t sizeof(mem-\u003eaddrv6));\n-\t\t\t\t\tmem-\u003enext \u003d lws_esp32.first;\n-\t\t\t\t\tlws_esp32.first \u003d mem;\n-\t\t\t\t\tlws_esp32.extant_group_members++;\n-\n-\t\t\t\t\tlws_group_member_event_call(\n-\t\t\t\t\t LWS_SYSTEM_GROUP_MEMBER_ADD, mem);\n-\t\t\t\t}\n-\t\t\t} else { /* update our IP */\n-\t\t\t\tmemcpy(\u0026mem-\u003eaddr,\n-\t\t\t\t \u0026event-\u003eevent_info.got_ip.ip_info.ip,\n-\t\t\t\t sizeof(mem-\u003eaddr));\n-\t\t\t\tmemcpy(\u0026mem-\u003eaddrv6,\n-\t\t\t\t \u0026event-\u003eevent_info.got_ip6.ip6_info.ip,\n-\t\t\t\t sizeof(mem-\u003eaddrv6));\n-\t\t\t\tlws_group_member_event_call(\n-\t\t\t\t\t LWS_SYSTEM_GROUP_MEMBER_CHANGE, mem);\n-\t\t\t}\n-\n-\t\t} else\n-\t\t\tlwsl_err(\u0022unable to init mdns on STA: %d\u005cn\u0022, n);\n-\n-\t\tmdns_query_txt(lws_esp32.group, \u0022_lwsgrmem\u0022, \u0022_tcp\u0022, 0,\n-\t\t\t \u0026mdns_results_head);\n-\t\txTimerStart(mdns_timer, 0);\n-#endif\n-\n-\t\tlwsl_notice(\u0022 --- Got IP %s\u005cn\u0022, lws_esp32.sta_ip);\n-\t\tif (!sntp_enabled()) {\n-\t\t\tsntp_setoperatingmode(SNTP_OPMODE_POLL);\n-\t\t\tsntp_setservername(0, \u0022pool.ntp.org\u0022);\n-\t\t\tsntp_init();\n-\t\t}\n-\t\tbreak;\n-\n-\tcase SYSTEM_EVENT_SCAN_DONE:\n-\t\tlwsl_notice(\u0022SYSTEM_EVENT_SCAN_DONE\u005cn\u0022);\n-\t\tend_scan();\n-\t\tbreak;\n-\n-\tdefault:\n-\t\tbreak;\n-\t}\n-\n-\treturn ESP_OK;\n-}\n-\n-#if defined(LWS_WITH_FILE_OPS)\n-static lws_fop_fd_t IRAM_ATTR\n-esp32_lws_fops_open(const struct lws_plat_file_ops *fops, const char *filename,\n- const char *vfs_path, lws_fop_flags_t *flags)\n-{\n-\tstruct esp32_file *f \u003d malloc(sizeof(*f));\n-\tlws_fop_fd_t fop_fd;\n-\tsize_t len, csum;\n-\n-\tlwsl_notice(\u0022%s: %s\u005cn\u0022, __func__, filename);\n-\n-\tif (!f)\n-\t\treturn NULL;\n-\tf-\u003ei \u003d romfs_get_info(lws_esp32_romfs, filename, \u0026len, \u0026csum);\n-\tif (!f-\u003ei)\n-\t\tgoto bail;\n-\n- fop_fd \u003d malloc(sizeof(*fop_fd));\n- if (!fop_fd)\n- goto bail;\n-\n- fop_fd-\u003efops \u003d fops;\n- fop_fd-\u003efilesystem_priv \u003d f;\n-\tfop_fd-\u003emod_time \u003d csum;\n-\t*flags |\u003d LWS_FOP_FLAG_MOD_TIME_VALID;\n-\tfop_fd-\u003eflags \u003d *flags;\n-\n-\tfop_fd-\u003elen \u003d len;\n-\tfop_fd-\u003epos \u003d 0;\n-\n-\treturn fop_fd;\n-\n-bail:\n-\tfree(f);\n-\n-\treturn NULL;\n-}\n-\n-static int IRAM_ATTR\n-esp32_lws_fops_close(lws_fop_fd_t *fop_fd)\n-{\n-\tfree((*fop_fd)-\u003efilesystem_priv);\n-\tfree(*fop_fd);\n-\n-\t*fop_fd \u003d NULL;\n-\n-\treturn 0;\n-}\n-static lws_fileofs_t IRAM_ATTR\n-esp32_lws_fops_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset_from_cur_pos)\n-{\n-\tfop_fd-\u003epos +\u003d offset_from_cur_pos;\n-\n-\tif (fop_fd-\u003epos \u003e fop_fd-\u003elen)\n-\t\tfop_fd-\u003epos \u003d fop_fd-\u003elen;\n-\n- return 0;\n-}\n-\n-static int IRAM_ATTR\n-esp32_lws_fops_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount, uint8_t *buf,\n- lws_filepos_t len)\n-{\n- struct esp32_file *f \u003d fop_fd-\u003efilesystem_priv;\n-#if 0\n- if ((long)buf \u0026 3) {\n- lwsl_err(\u0022misaligned buf\u005cn\u0022);\n-\n- return -1;\n- }\n-#endif\n- if (fop_fd-\u003epos \u003e\u003d fop_fd-\u003elen)\n- return 0;\n-\n- if (len \u003e fop_fd-\u003elen - fop_fd-\u003epos)\n- len \u003d fop_fd-\u003elen - fop_fd-\u003epos;\n-\n- spi_flash_read((uint32_t)(char *)f-\u003ei + fop_fd-\u003epos, buf, len);\n-\n- *amount \u003d len;\n- fop_fd-\u003epos +\u003d len;\n-\n- return 0;\n-}\n-\n-static const struct lws_plat_file_ops fops \u003d {\n-\t.next \u003d \u0026fops_zip,\n-\t.LWS_FOP_OPEN \u003d esp32_lws_fops_open,\n-\t.LWS_FOP_CLOSE \u003d esp32_lws_fops_close,\n-\t.LWS_FOP_READ \u003d esp32_lws_fops_read,\n-\t.LWS_FOP_SEEK_CUR \u003d esp32_lws_fops_seek_cur,\n-};\n-#endif\n-\n-int\n-lws_esp32_wlan_nvs_get(int retry)\n-{\n-\tnvs_handle nvh;\n-\tchar lws_esp32_force_ap \u003d 0, slot[12];\n-\tsize_t s;\n-\tuint8_t mac[6];\n-\tint n;\n-\n-\tesp_efuse_mac_get_default(mac);\n-\tmac[5] |\u003d 1; /* match the AP MAC */\n-\tsnprintf(lws_esp32.serial, sizeof(lws_esp32.serial) - 1,\n-\t\t \u0022%02X%02X%02X\u0022, mac[3], mac[4], mac[5]);\n-\tsnprintf(lws_esp32.mac, sizeof(lws_esp32.mac) - 1,\n-\t\t \u0022%02X%02X%02X%02X%02X%02X\u0022, mac[0], mac[1], mac[2], mac[3],\n-\t\t mac[4], mac[5]);\n-\n-\tESP_ERROR_CHECK(nvs_open(\u0022lws-station\u0022, NVS_READWRITE, \u0026nvh));\n-\n-\tconfig.sta.ssid[0] \u003d '\u005c0';\n-\tconfig.sta.password[0] \u003d '\u005c0';\n-\n-\tfor (n \u003d 0; n \u003c 4; n++) {\n-\t\tlws_snprintf(slot, sizeof(slot) - 1, \u0022%dssid\u0022, n);\n-\t\ts \u003d sizeof(lws_esp32.ssid[0]) - 1;\n-\t\tlws_esp32.ssid[n][0] \u003d '\u005c0';\n-\t\tnvs_get_str(nvh, slot, lws_esp32.ssid[n], \u0026s);\n-\n-\t\tlws_snprintf(slot, sizeof(slot) - 1, \u0022%dpassword\u0022, n);\n-\t\ts \u003d sizeof(lws_esp32.password[0]) - 1;\n-\t\tlws_esp32.password[n][0] \u003d '\u005c0';\n-\t\tnvs_get_str(nvh, slot, lws_esp32.password[n], \u0026s);\n-\t}\n-\n-\ts \u003d sizeof(lws_esp32.serial) - 1;\n-\tif (nvs_get_str(nvh, \u0022serial\u0022, lws_esp32.serial, \u0026s) !\u003d ESP_OK)\n-\t\tlws_esp32_force_ap \u003d 1;\n-\telse\n-\t\tsnprintf((char *)config.ap.ssid, sizeof(config.ap.ssid) - 1,\n-\t\t\t \u0022config-%s-%s\u0022, lws_esp32.model, lws_esp32.serial);\n-\ts \u003d sizeof(lws_esp32.opts) - 1;\n-\tif (nvs_get_str(nvh, \u0022opts\u0022, lws_esp32.opts, \u0026s) !\u003d ESP_OK)\n-\t\tlws_esp32_force_ap \u003d 1;\n-\n-\tlws_esp32.access_pw[0] \u003d '\u005c0';\n-\tnvs_get_str(nvh, \u0022access_pw\u0022, lws_esp32.access_pw, \u0026s);\n-\n-\tlws_esp32.group[0] \u003d '\u005c0';\n-\ts \u003d sizeof(lws_esp32.group);\n-\tnvs_get_str(nvh, \u0022group\u0022, lws_esp32.group, \u0026s);\n-\n-\tlws_esp32.role[0] \u003d '\u005c0';\n-\ts \u003d sizeof(lws_esp32.role);\n-\tnvs_get_str(nvh, \u0022role\u0022, lws_esp32.role, \u0026s);\n-\n-\t/* if group and role defined: group-role */\n-\tif (lws_esp32.group[0] \u0026\u0026 lws_esp32.role[0])\n-\t\tlws_snprintf(lws_esp32.hostname, sizeof(lws_esp32.hostname) - 1,\n-\t\t\t\t\u0022%s-%s\u0022, lws_esp32.group, lws_esp32.role);\n-\telse /* otherwise model-serial */\n-\t\tlws_snprintf(lws_esp32.hostname, sizeof(lws_esp32.hostname) - 1,\n-\t\t\t\t\u0022%s-%s\u0022, lws_esp32.model, lws_esp32.serial);\n-\n-\tnvs_close(nvh);\n-\n-\tlws_gapss_to(LWS_GAPSS_SCAN);\n-\tstart_scan();\n-\n-\treturn lws_esp32_force_ap;\n-}\n-\n-\n-void\n-lws_esp32_wlan_config(void)\n-{\n-\tledc_timer_config_t ledc_timer \u003d {\n-\t .bit_num \u003d LEDC_TIMER_13_BIT,\n-\t .freq_hz \u003d 5000,\n-\t .speed_mode \u003d LEDC_HIGH_SPEED_MODE,\n-\t .timer_num \u003d LEDC_TIMER_0\n-\t};\n-\tint n;\n-\n-\tlwsl_debug(\u0022%s\u005cn\u0022, __func__);\n-\n-\tledc_timer_config(\u0026ledc_timer);\n-\n-\tlws_set_genled(LWSESP32_GENLED__INIT);\n-\n-\t/* user code needs to provide lws_esp32_leds_timer_cb */\n-\n- leds_timer \u003d xTimerCreate(\u0022lws_leds\u0022, pdMS_TO_TICKS(25), 1, NULL,\n- (TimerCallbackFunction_t)lws_esp32_leds_timer_cb);\n- scan_timer \u003d xTimerCreate(\u0022lws_scan\u0022, pdMS_TO_TICKS(10000), 0, NULL,\n- (TimerCallbackFunction_t)lws_esp32_scan_timer_cb);\n- debounce_timer \u003d xTimerCreate(\u0022lws_db\u0022, pdMS_TO_TICKS(100), 0, NULL,\n- (TimerCallbackFunction_t)lws_esp32_debounce_timer_cb);\n- association_timer \u003d xTimerCreate(\u0022lws_assoc\u0022, pdMS_TO_TICKS(10000), 0, NULL,\n- (TimerCallbackFunction_t)lws_esp32_assoc_timer_cb);\n-\n-#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION)\n- mdns_timer \u003d xTimerCreate(\u0022lws_mdns\u0022, pdMS_TO_TICKS(5000), 0, NULL,\n- (TimerCallbackFunction_t)lws_esp32_mdns_timer_cb);\n-#endif\n-\tscan_timer_exists \u003d 1;\n- xTimerStart(leds_timer, 0);\n-\n-\t*(volatile uint32_t *)PERIPHS_IO_MUX_MTMS_U \u003d FUNC_MTMS_GPIO14;\n-\n-\tgpio_output_set(0, 0, 0, (1 \u003c\u003c GPIO_SW));\n-\n-\tn \u003d gpio_install_isr_service(0);\n-\tif (!n) {\n-\t\tgpio_config_t c;\n-\n-\t\tc.intr_type \u003d GPIO_INTR_NEGEDGE;\n-\t\tc.mode \u003d GPIO_MODE_INPUT;\n-\t\tc.pin_bit_mask \u003d 1 \u003c\u003c GPIO_SW;\n-\t\tc.pull_down_en \u003d 0;\n-\t\tc.pull_up_en \u003d 0;\n-\t\tgpio_config(\u0026c);\n-\n-\t\tif (gpio_isr_handler_add(GPIO_SW, gpio_irq, NULL))\n-\t\t\tlwsl_notice(\u0022isr handler add for 14 failed\u005cn\u0022);\n-\t} else\n-\t\tlwsl_notice(\u0022failed to install gpio isr service: %d\u005cn\u0022, n);\n-\n-\tlws_esp32_wlan_nvs_get(0);\n-\ttcpip_adapter_init();\n-}\n-\n-void\n-lws_esp32_wlan_start_ap(void)\n-{\n-\twifi_init_config_t cfg \u003d WIFI_INIT_CONFIG_DEFAULT();\n-\n-\tESP_ERROR_CHECK( esp_wifi_init(\u0026cfg));\n-\tESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM));\n-\n-\tESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_APSTA) );\n-\tESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, \u0026config) );\n-\tESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, \u0026sta_config));\n-\tESP_ERROR_CHECK( esp_wifi_start());\n-\n-\tesp_wifi_scan_start(\u0026scan_config, false);\n-\n-\tif (sta_config.sta.ssid[0]) {\n-\t\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA,\n-\t\t\t\t\t (const char *)\u0026config.ap.ssid[7]);\n-\t\t// esp_wifi_set_auto_connect(1);\n-\t\tESP_ERROR_CHECK( esp_wifi_connect());\n-\t\tESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, \u0026sta_config));\n-\t\tESP_ERROR_CHECK( esp_wifi_connect());\n-\t}\n-}\n-\n-void\n-lws_esp32_wlan_start_station(void)\n-{\n-\twifi_init_config_t cfg \u003d WIFI_INIT_CONFIG_DEFAULT();\n-\n-\tESP_ERROR_CHECK( esp_wifi_init(\u0026cfg));\n-\tESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM));\n-\n-\tESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA));\n-\tESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, \u0026sta_config));\n-\n-\tESP_ERROR_CHECK( esp_wifi_start());\n-\n-\ttcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA,\n-\t\t\t\t (const char *)\u0026config.ap.ssid[7]);\n-\t//esp_wifi_set_auto_connect(1);\n-\t//ESP_ERROR_CHECK( esp_wifi_connect());\n-\n-\tlws_esp32_scan_timer_cb(NULL);\n-}\n-\n-const esp_partition_t *\n-lws_esp_ota_get_boot_partition(void)\n-{\n-\tconst esp_partition_t *part \u003d esp_ota_get_boot_partition(),\n-\t\t\t *factory_part, *ota;\n-\tesp_image_header_t eih, ota_eih;\n-\tuint32_t *p_force_factory_magic \u003d (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS;\n-\n-\t/* confirm what we are told is the boot part is sane */\n-\tspi_flash_read(part-\u003eaddress , \u0026eih, sizeof(eih));\n-\tfactory_part \u003d esp_partition_find_first(ESP_PARTITION_TYPE_APP,\n-\t\t\tESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);\n- \tota \u003d esp_partition_find_first(ESP_PARTITION_TYPE_APP,\n-\t\t\tESP_PARTITION_SUBTYPE_APP_OTA_0, NULL);\n-\tspi_flash_read(ota-\u003eaddress , \u0026ota_eih, sizeof(ota_eih));\n-\n-\tif (eih.spi_mode \u003d\u003d 0xff ||\n-\t *p_force_factory_magic \u003d\u003d LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY ||\n-\t *p_force_factory_magic \u003d\u003d LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON\n-\t) {\n-\t\t/*\n-\t\t * we believed we were going to boot OTA, but we fell\n-\t\t * back to FACTORY in the bootloader when we saw it\n-\t\t * had been erased. esp_ota_get_boot_partition() still\n-\t\t * says the OTA partition then even if we are in the\n-\t\t * factory partition right now.\n-\t\t */\n-\t\tpart \u003d factory_part;\n-\t}\n-\n-#ifdef CONFIG_LWS_IS_FACTORY_APPLICATION\n-\telse\n-\t\tif (ota_eih.spi_mode !\u003d 0xff \u0026\u0026\n-\t\t part-\u003eaddress !\u003d factory_part-\u003eaddress) {\n-\t\t\tuint8_t buf[4096];\n-\t\t\tuint32_t n;\n-\t\t\t/*\n-\t\t\t * we are a FACTORY image running in an OTA slot...\n-\t\t\t * it means we were just written and need to copy\n-\t\t\t * ourselves into the FACTORY slot.\n-\t\t\t */\n-\t\t\tlwsl_notice(\u0022Copying FACTORY update into place \u0022\n-\t\t\t\t \u00220x%x len 0x%x\u005cn\u0022, factory_part-\u003eaddress,\n-\t\t\t\t factory_part-\u003esize);\n-\t\t\tesp_task_wdt_reset();\n-\t\t\tif (spi_flash_erase_range(factory_part-\u003eaddress,\n-\t\t\t\t\t\t factory_part-\u003esize)) {\n-\t \t lwsl_err(\u0022spi: Failed to erase\u005cn\u0022);\n-\t \t goto retry;\n-\t \t}\n-\n-\t\t\tfor (n \u003d 0; n \u003c factory_part-\u003esize; n +\u003d sizeof(buf)) {\n-\t\t\t\tesp_task_wdt_reset();\n-\t\t\t\tspi_flash_read(part-\u003eaddress + n , buf,\n-\t\t\t\t\t sizeof(buf));\n-\t\t\t\tif (spi_flash_write(factory_part-\u003eaddress + n,\n-\t\t\t\t\t\t buf, sizeof(buf))) {\n-\t \t lwsl_err(\u0022spi: Failed to write\u005cn\u0022);\n-\t \t goto retry;\n-\t \t}\n-\t\t\t}\n-\n-\t\t\t/*\n-\t\t\t * We send a message to the bootloader to erase the OTA header, we will come back up in\n-\t\t\t * factory where the user can reload the OTA image\n-\t\t\t */\n-\t\t\tlwsl_notice(\u0022 FACTORY copy successful, rebooting\u005cn\u0022);\n-\t\t\tlws_esp32_restart_guided(LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY_ERASE_OTA);\n-retry:\n-\t\t\tesp_restart();\n-\t\t}\n-#endif\n-\n-\treturn part;\n-}\n-\n-\n-void\n-lws_esp32_set_creation_defaults(struct lws_context_creation_info *info)\n-{\n-\tconst esp_partition_t *part;\n-\n-\tmemset(info, 0, sizeof(*info));\n-\n-\tlws_set_log_level(63, lwsl_emit_syslog);\n-\n-\tpart \u003d lws_esp_ota_get_boot_partition();\n-\t(void)part;\n-\n-\tinfo-\u003evhost_name \u003d \u0022default\u0022;\n-\tinfo-\u003eport \u003d 443;\n-\tinfo-\u003efd_limit_per_thread \u003d 16;\n-\tinfo-\u003emax_http_header_pool \u003d 5;\n-\tinfo-\u003emax_http_header_data \u003d 1024;\n-\tinfo-\u003ept_serv_buf_size \u003d 4096;\n-\tinfo-\u003ekeepalive_timeout \u003d 30;\n-\tinfo-\u003etimeout_secs \u003d 30;\n-\tinfo-\u003esimultaneous_ssl_restriction \u003d 2;\n-\tinfo-\u003eoptions \u003d LWS_SERVER_OPTION_EXPLICIT_VHOSTS |\n-\t\t LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;\n-}\n-\n-int\n-lws_esp32_get_image_info(const esp_partition_t *part, struct lws_esp32_image *i,\n-\t\t\t char *json, int json_len)\n-{\n-\tesp_image_segment_header_t eis;\n-\tesp_image_header_t eih;\n-\tuint32_t hdr;\n-\n-\tspi_flash_read(part-\u003eaddress , \u0026eih, sizeof(eih));\n-\thdr \u003d part-\u003eaddress + sizeof(eih);\n-\n-\tif (eih.magic !\u003d ESP_IMAGE_HEADER_MAGIC) {\n-\t\tlwsl_notice(\u0022%s: bad image header magic\u005cn\u0022, __func__);\n-\t\treturn 1;\n-\t}\n-\n-\teis.data_len \u003d 0;\n-\twhile (eih.segment_count-- \u0026\u0026 eis.data_len !\u003d 0xffffffff) {\n-\t\tspi_flash_read(hdr, \u0026eis, sizeof(eis));\n-\t\thdr +\u003d sizeof(eis) + eis.data_len;\n-\t}\n-\thdr +\u003d (~hdr \u0026 15) + 1;\n-\n-\tif (eih.hash_appended)\n-\t\thdr +\u003d 0x20;\n-\n-//\tlwsl_notice(\u0022romfs estimated at 0x%x\u005cn\u0022, hdr);\n-\n-\ti-\u003eromfs \u003d hdr + 0x4;\n-\tspi_flash_read(hdr, \u0026i-\u003eromfs_len, sizeof(i-\u003eromfs_len));\n-\ti-\u003ejson \u003d i-\u003eromfs + i-\u003eromfs_len + 4;\n-\tspi_flash_read(i-\u003ejson - 4, \u0026i-\u003ejson_len, sizeof(i-\u003ejson_len));\n-\n-\tif (i-\u003ejson_len \u003c json_len - 1)\n-\t\tjson_len \u003d i-\u003ejson_len;\n-\tspi_flash_read(i-\u003ejson, json, json_len);\n-\tjson[json_len] \u003d '\u005c0';\n-\n-\treturn 0;\n-}\n-\n-static int\n-_rngf(void *context, unsigned char *buf, size_t len)\n-{\n-\tif (lws_get_random(context, buf, len) \u003d\u003d len)\n-\t\treturn 0;\n-\n-\treturn -1;\n-}\n-\n-int\n-lws_esp32_selfsigned(struct lws_vhost *vhost)\n-{\n-\tmbedtls_x509write_cert crt;\n-\tchar subject[200];\n-\tmbedtls_pk_context mpk;\n-\tint buf_size \u003d 4096, n;\n-\tuint8_t *buf \u003d malloc(buf_size); /* malloc because given to user code */\n-\tmbedtls_mpi mpi;\n-\tnvs_handle nvh;\n-\tsize_t s;\n-\n-\tlwsl_notice(\u0022%s: %s\u005cn\u0022, __func__, vhost-\u003ename);\n-\n-\tif (!buf)\n-\t\treturn -1;\n-\n-\tif (nvs_open(\u0022lws-station\u0022, NVS_READWRITE, \u0026nvh)) {\n-\t\tlwsl_notice(\u0022%s: can't open nvs\u005cn\u0022, __func__);\n-\t\tfree(buf);\n-\t\treturn 1;\n-\t}\n-\n-\tn \u003d 0;\n-\tif (!nvs_get_blob(nvh, vhost-\u003etls.alloc_cert_path, NULL, \u0026s))\n-\t\tn |\u003d 1;\n-\tif (!nvs_get_blob(nvh, vhost-\u003etls.key_path, NULL, \u0026s))\n-\t\tn |\u003d 2;\n-\n-\tnvs_close(nvh);\n-\tif (n \u003d\u003d 3) {\n-\t\tlwsl_notice(\u0022%s: certs exist\u005cn\u0022, __func__);\n-\t\tfree(buf);\n-\t\treturn 0; /* certs already exist */\n-\t}\n-\n-\tlwsl_notice(\u0022%s: creating selfsigned initial certs\u005cn\u0022, __func__);\n-\n-\tmbedtls_x509write_crt_init(\u0026crt);\n-\n-\tmbedtls_pk_init(\u0026mpk);\n-\tif (mbedtls_pk_setup(\u0026mpk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA))) {\n-\t\tlwsl_notice(\u0022%s: pk_setup failed\u005cn\u0022, __func__);\n-\t\tgoto fail;\n-\t}\n-\tlwsl_notice(\u0022%s: generating 2048-bit RSA keypair... \u0022\n-\t\t \u0022this may take a minute or so...\u005cn\u0022, __func__);\n-\tn \u003d mbedtls_rsa_gen_key(mbedtls_pk_rsa(mpk), _rngf, vhost-\u003econtext,\n-\t\t\t\t2048, 65537);\n-\tif (n) {\n-\t\tlwsl_notice(\u0022%s: failed to generate keys\u005cn\u0022, __func__);\n-\t\tgoto fail1;\n-\t}\n-\tlwsl_notice(\u0022%s: keys done\u005cn\u0022, __func__);\n-\n-\t/* subject must be formatted like \u0022C\u003dTW,O\u003dwarmcat,CN\u003dmyserver\u0022 */\n-\n-\tlws_snprintf(subject, sizeof(subject) - 1,\n-\t\t \u0022C\u003dTW,ST\u003dNew Taipei City,L\u003dTaipei,O\u003dwarmcat,CN\u003d%s\u0022,\n-\t\t lws_esp32.hostname);\n-\n-\tif (mbedtls_x509write_crt_set_subject_name(\u0026crt, subject)) {\n-\t\tlwsl_notice(\u0022set SN failed\u005cn\u0022);\n-\t\tgoto fail1;\n-\t}\n-\tmbedtls_x509write_crt_set_subject_key(\u0026crt, \u0026mpk);\n-\tif (mbedtls_x509write_crt_set_issuer_name(\u0026crt, subject)) {\n-\t\tlwsl_notice(\u0022set IN failed\u005cn\u0022);\n-\t\tgoto fail1;\n-\t}\n-\tmbedtls_x509write_crt_set_issuer_key(\u0026crt, \u0026mpk);\n-\n-\tlws_get_random(vhost-\u003econtext, \u0026n, sizeof(n));\n-\tlws_snprintf(subject, sizeof(subject), \u0022%d\u0022, n);\n-\n-\tmbedtls_mpi_init(\u0026mpi);\n-\tmbedtls_mpi_read_string(\u0026mpi, 10, subject);\n-\tmbedtls_x509write_crt_set_serial(\u0026crt, \u0026mpi);\n-\tmbedtls_mpi_free(\u0026mpi);\n-\n-\tmbedtls_x509write_crt_set_validity(\u0026crt, \u002220171105235959\u0022,\n-\t\t\t\t\t \u002220491231235959\u0022);\n-\n-\tmbedtls_x509write_crt_set_key_usage(\u0026crt,\n-\t\t\t\t\t MBEDTLS_X509_KU_DIGITAL_SIGNATURE |\n-\t\t\t\t\t MBEDTLS_X509_KU_KEY_ENCIPHERMENT);\n-\n-\n-\tmbedtls_x509write_crt_set_md_alg(\u0026crt, MBEDTLS_MD_SHA256);\n-\n-\tn \u003d mbedtls_x509write_crt_pem(\u0026crt, buf, buf_size, _rngf,\n-\t\t\t\t vhost-\u003econtext);\n-\tif (n \u003c 0) {\n-\t\tlwsl_notice(\u0022%s: write crt der failed\u005cn\u0022, __func__);\n-\t\tgoto fail1;\n-\t}\n-\n-\tlws_plat_write_cert(vhost, 0, 0, buf, strlen((const char *)buf));\n-\n-\tif (mbedtls_pk_write_key_pem(\u0026mpk, buf, buf_size)) {\n-\t\tlwsl_notice(\u0022write key pem failed\u005cn\u0022);\n-\t\tgoto fail1;\n-\t}\n-\n-\tlws_plat_write_cert(vhost, 1, 0, buf, strlen((const char *)buf));\n-\n-\tmbedtls_pk_free(\u0026mpk);\n-\tmbedtls_x509write_crt_free(\u0026crt);\n-\n-\tlwsl_notice(\u0022%s: cert creation complete\u005cn\u0022, __func__);\n-\n-\treturn n;\n-\n-fail1:\n-\tmbedtls_pk_free(\u0026mpk);\n-fail:\n-\tmbedtls_x509write_crt_free(\u0026crt);\n-\tfree(buf);\n-\n-\tnvs_close(nvh);\n-\n-\treturn -1;\n-}\n-\n-void\n-lws_esp32_update_acme_info(void)\n-{\n- int n;\n-\n-\tn \u003d lws_plat_read_file(\u0022acme-email\u0022, lws_esp32.le_email,\n-\t\t\t sizeof(lws_esp32.le_email) - 1);\n-\tif (n \u003e\u003d 0)\n-\t\tlws_esp32.le_email[n] \u003d '\u005c0';\n-\n-\tn \u003d lws_plat_read_file(\u0022acme-cn\u0022, lws_esp32.le_dns,\n-\t\t\t sizeof(lws_esp32.le_dns) - 1);\n-\tif (n \u003e\u003d 0)\n-\t\tlws_esp32.le_dns[n] \u003d '\u005c0';\n-}\n-\n-struct lws_context *\n-lws_esp32_init(struct lws_context_creation_info *info, struct lws_vhost **pvh)\n-{\n-\tconst esp_partition_t *part \u003d lws_esp_ota_get_boot_partition();\n-\tstruct lws_context *context;\n-\tstruct lws_esp32_image i;\n-\tstruct lws_vhost *vhost;\n-\tstruct lws wsi;\n-\tchar buf[512];\n-\n-\tcontext \u003d lws_create_context(info);\n-\tif (context \u003d\u003d NULL) {\n-\t\tlwsl_err(\u0022Failed to create context\u005cn\u0022);\n-\t\treturn NULL;\n-\t}\n-\n-\tlws_esp32_get_image_info(part, \u0026i, buf, sizeof(buf) - 1);\n-\n-\tlws_esp32_romfs \u003d (romfs_t)i.romfs;\n-\tif (!romfs_mount_check(lws_esp32_romfs)) {\n-\t\tlwsl_err(\u0022mount error on ROMFS at %p 0x%x\u005cn\u0022, lws_esp32_romfs,\n-\t\t\t i.romfs);\n-\t\treturn NULL;\n-\t}\n-\n-\tlwsl_notice(\u0022ROMFS length %uKiB\u005cn\u0022, i.romfs_len \u003e\u003e 10);\n-\n-\tputs(buf);\n-\n-\t/* set the lws vfs to use our romfs */\n-#if defined(LWS_WITH_FILE_OPS)\n-\tlws_set_fops(context, \u0026fops);\n-#endif\n-\n-\tinfo-\u003eoptions |\u003d LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX |\n-\t\t\t LWS_SERVER_OPTION_IGNORE_MISSING_CERT;\n-\n-\tvhost \u003d lws_create_vhost(context, info);\n-\tif (!vhost) {\n-\t\tlwsl_err(\u0022Failed to create vhost\u005cn\u0022);\n-\t\treturn NULL;\n-\t}\n-\n-\tlws_esp32_update_acme_info();\n-\n-\tlws_esp32_selfsigned(vhost);\n-\twsi.context \u003d vhost-\u003econtext;\n-\twsi.vhost \u003d vhost;\n-\n-\tlws_tls_server_certs_load(vhost, \u0026wsi, info-\u003essl_cert_filepath,\n-\t\t\tinfo-\u003essl_private_key_filepath, NULL, 0, NULL, 0);\n-\n-\tlws_init_vhost_client_ssl(info, vhost);\n-\n-\tif (pvh)\n-\t\t*pvh \u003d vhost;\n-\n-\tif (lws_protocol_init(context))\n-\t\treturn NULL;\n-\n-\treturn context;\n-}\n-\n-static const uint16_t sineq16[] \u003d {\n- 0x0000, 0x0191, 0x031e, 0x04a4, 0x061e, 0x0789, 0x08e2, 0x0a24,\n- 0x0b4e, 0x0c5c, 0x0d4b, 0x0e1a, 0x0ec6, 0x0f4d, 0x0faf, 0x0fea,\n-};\n-\n-static uint16_t sine_lu(int n)\n-{\n- switch ((n \u003e\u003e 4) \u0026 3) {\n- case 1:\n- return 4096 + sineq16[n \u0026 15];\n- case 2:\n- return 4096 + sineq16[15 - (n \u0026 15)];\n- case 3:\n- return 4096 - sineq16[n \u0026 15];\n- default:\n- return 4096 - sineq16[15 - (n \u0026 15)];\n- }\n-}\n-\n-/* useful for sine led fade patterns */\n-\n-uint16_t lws_esp32_sine_interp(int n)\n-{\n- /*\n- * 2: quadrant\n- * 4: table entry in quadrant\n- * 4: interp (LSB)\n- *\n- * total 10 bits / 1024 steps per cycle\n-\t *\n-\t * + 0: 0\n-\t * + 256: 4096\n-\t * + 512: 8192\n-\t * + 768: 4096\n-\t * +1023: 0\n- */\n-\n- return (sine_lu(n \u003e\u003e 4) * (15 - (n \u0026 15)) +\n- sine_lu((n \u003e\u003e 4) + 1) * (n \u0026 15)) / 15;\n-}\n","s":{"c":1754122021,"u": 4803}} ],"g": 9900,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}