#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 */
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;
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]);
uint8_t mac[6];
struct lws_esp32_image i;
char img_factory[512], img_ota[512];
+ int grt;
case SCAN_STATE_INITIAL:
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\" }");
" \"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,