Skip to content

Commit 2d68ae0

Browse files
committed
OTA project name check, url, and static user agent
1 parent 76b1dfe commit 2d68ae0

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ set(OTA_UPDATES ON)
2020
set(PROJECT_VER "2.4.0.2")
2121

2222
if(HOME_AUTOMATION STREQUAL "HOMEKIT")
23-
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../esp-apple-homekit-adk/)
23+
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/../esp-apple-homekit-adk/)
2424
elseif(HOME_AUTOMATION STREQUAL "NEST")
25-
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../esp-google-iot/)
25+
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/../esp-google-iot/)
2626
elseif(HOME_AUTOMATION STREQUAL "ALEXA")
27-
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../esp-aws-iot/)
27+
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/../esp-aws-iot/)
2828
endif()
2929

3030
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

main/ota.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ const char *LETS_ENCRYPT_X1_ROOT_CA = "-----BEGIN CERTIFICATE-----\n"
7070
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n"
7171
"-----END CERTIFICATE-----";
7272

73-
char *ota_user_agent;
74-
7573
void print_app_desc(esp_app_desc_t app_desc, char *app, esp_log_level_t log_level) {
7674
ESP_LOG_LEVEL(log_level, OTA_TAG, "%s firmware project: %s", app, app_desc.project_name);
7775
ESP_LOG_LEVEL(log_level, OTA_TAG, "%s firmware version: %s", app, app_desc.version);
@@ -83,7 +81,7 @@ esp_err_t validate_image_header(esp_https_ota_handle_t *https_ota_handle) {
8381
esp_http_client_config_t config = {
8482
.url = OTA_UPDATE_URL,
8583
.cert_pem = LETS_ENCRYPT_X1_ROOT_CA,
86-
.user_agent = ota_user_agent
84+
.user_agent = OTA_UPDATE_USER_AGENT
8785
};
8886

8987
esp_https_ota_config_t ota_config = {
@@ -114,6 +112,11 @@ esp_err_t validate_image_header(esp_https_ota_handle_t *https_ota_handle) {
114112

115113
print_app_desc(update_app_info, "Update", ESP_LOG_WARN);
116114

115+
if(memcmp(update_app_info.project_name, running_app_info.project_name, sizeof(update_app_info.project_name)) != 0) {
116+
ESP_LOGE(OTA_TAG, "Invalid project name!");
117+
return ESP_FAIL;
118+
}
119+
117120
if(memcmp(update_app_info.version, running_app_info.version, sizeof(update_app_info.version)) <= 0) {
118121
ESP_LOGI(OTA_TAG, "Running firmware version is up to date!");
119122
return ESP_ERR_INVALID_VERSION;
@@ -128,7 +131,6 @@ esp_err_t validate_image_header(esp_https_ota_handle_t *https_ota_handle) {
128131
}
129132

130133
void ota_task(void *arg) {
131-
asprintf(&ota_user_agent, "%s - %s v%s", OTA_UPDATE_USER_AGENT, OTA_PROJECT_NAME, OTA_PROJECT_VER);
132134
vTaskDelay(SLEEP_INTERVAL_10_SEC / portTICK_PERIOD_MS);
133135

134136
for(;;) {

main/ota.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
#include "esp_ota_ops.h"
2727
#include "esp_https_ota.h"
2828

29-
#define OTA_PROJECT_NAME (PROJECT_NAME)
30-
#define OTA_PROJECT_VER (PROJECT_VER)
31-
#define OTA_UPDATE_URL ("https://ma.lwa.re/ota/Dreamdesk.bin")
32-
#define OTA_UPDATE_USER_AGENT ("ESP32 HTTP Client/1.0")
29+
#define OTA_UPDATE_URL ("https://ma.lwa.re/ota/" PROJECT_NAME ".bin")
30+
#define OTA_UPDATE_USER_AGENT ("ESP32 HTTP Client/1.0 - " PROJECT_NAME " v" PROJECT_VER)
3331
#define SLEEP_INTERVAL_10_SEC (1000 * 10)
3432
#define SLEEP_INTERVAL_12_HOURS (1000 * 60 * 60 * 12)
3533

0 commit comments

Comments
 (0)