1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

esp32: dont require factory button if no ssl certs yet

This commit is contained in:
Andy Green 2017-04-03 11:56:33 +08:00
parent 7faa71637f
commit 30195eb79d
3 changed files with 35 additions and 2 deletions

View file

@ -537,7 +537,6 @@ static inline void uv_close(uv_handle_t *h, void *v)
#define LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY 0xfaceb00b
#define LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON 0xf0cedfac
static inline uint32_t lws_esp32_get_reboot_type(void) { uint32_t *p = (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS; return *p; }
/* user code provides these */
@ -592,6 +591,7 @@ extern const esp_partition_t *
lws_esp_ota_get_boot_partition(void);
extern int
lws_esp32_get_image_info(const esp_partition_t *part, struct lws_esp32_image *i, char *json, int json_len);
extern uint32_t lws_esp32_get_reboot_type(void);
#else
typedef int lws_sockfd_type;
typedef int lws_filefd_type;

View file

@ -585,6 +585,30 @@ struct esp32_file {
const struct inode *i;
};
uint32_t lws_esp32_get_reboot_type(void)
{
uint32_t *p = (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS, val = *p;
nvs_handle nvh;
size_t s = 0;
int n = 0;
ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh));
if (nvs_get_blob(nvh, "ssl-pub.der", NULL, &s) == ESP_OK)
n = 1;
if (nvs_get_blob(nvh, "ssl-pri.der", NULL, &s) == ESP_OK)
n |= 2;
nvs_close(nvh);
/*
* in the case the SSL certs are not there, don't require
* the button to be down to access all features.
*/
if (n != 3)
val = LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON;
return val;
}
static void render_ip(char *dest, int len, uint8_t *ip)
{
snprintf(dest, len, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);

View file

@ -363,6 +363,7 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,
uint8_t mac[6];
struct lws_esp32_image i;
char img_factory[512], img_ota[512];
int grt;
case SCAN_STATE_INITIAL:
@ -378,6 +379,14 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,
nvs_close(nvh);
/*
* this value in the JSON is just
* used for UI indication. Each conditional feature confirms
* it itself before it allows itself to be used.
*/
grt = lws_esp32_get_reboot_type();
esp_efuse_read_mac(mac);
strcpy(img_factory, " { \"date\": \"Empty\" }");
strcpy(img_ota, " { \"date\": \"Empty\" }");
@ -406,7 +415,7 @@ callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason,
" \"img_factory\": %s,\n"
" \"img_ota\": %s,\n",
lws_esp32.model,
lws_esp32_get_reboot_type() == LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON,
grt == LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON,
lws_esp32.serial,
lws_esp32.opts,
lws_esp32.model, lws_esp32.serial,