mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-19 00:07:38 +00:00
Meshtastic OTA (moar) (#9327)
* Initial commit of combined BLE and WiFi OTA * Incorporate ota_hash in AdminMessage protobuf * OTA protobuf changes * Trunk fmt * Partition header check for OTA type * Guards * Guards * Derp * Missed one --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
This commit is contained in:
@@ -235,22 +235,46 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
|
||||
}
|
||||
case meshtastic_AdminMessage_ota_request_tag: {
|
||||
#if defined(ARCH_ESP32)
|
||||
LOG_INFO("OTA Requested");
|
||||
|
||||
if (r->ota_request.ota_hash.size != 32) {
|
||||
suppressRebootBanner = true;
|
||||
LOG_INFO("OTA Failed: Invalid `ota_hash` provided");
|
||||
sendWarningAndLog("Cannot start OTA: Invalid `ota_hash` provided.");
|
||||
break;
|
||||
}
|
||||
|
||||
meshtastic_OTAMode mode = r->ota_request.reboot_ota_mode;
|
||||
const char *mode_name = (mode == METHOD_OTA_BLE ? "BLE" : "WiFi");
|
||||
|
||||
// Check that we have an OTA partition
|
||||
const esp_partition_t *part = MeshtasticOTA::getAppPartition();
|
||||
if (part == NULL) {
|
||||
suppressRebootBanner = true;
|
||||
sendWarningAndLog("Cannot start OTA: Cannot find OTA Loader partition.");
|
||||
break;
|
||||
}
|
||||
|
||||
static esp_app_desc_t app_desc;
|
||||
if (!MeshtasticOTA::getAppDesc(part, &app_desc)) {
|
||||
suppressRebootBanner = true;
|
||||
sendWarningAndLog("Cannot start OTA: Device does have a valid OTA Loader.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!MeshtasticOTA::checkOTACapability(&app_desc, mode)) {
|
||||
suppressRebootBanner = true;
|
||||
sendWarningAndLog("OTA Loader does not support %s", mode_name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (MeshtasticOTA::trySwitchToOTA()) {
|
||||
LOG_INFO("OTA Requested");
|
||||
suppressRebootBanner = true;
|
||||
if (screen)
|
||||
screen->startFirmwareUpdateScreen();
|
||||
MeshtasticOTA::saveConfig(&config.network, mode, r->ota_request.ota_hash.bytes);
|
||||
LOG_INFO("Rebooting to WiFi OTA");
|
||||
sendWarningAndLog("Rebooting to %s OTA", mode_name);
|
||||
} else {
|
||||
LOG_INFO("WIFI OTA Failed");
|
||||
sendWarningAndLog("Unable to switch to the OTA partition.");
|
||||
}
|
||||
#endif
|
||||
int s = 1; // Reboot in 1 second, hard coded
|
||||
@@ -1472,15 +1496,43 @@ void AdminModule::handleSendInputEvent(const meshtastic_AdminMessage_InputEvent
|
||||
#endif
|
||||
}
|
||||
|
||||
void AdminModule::sendWarning(const char *message)
|
||||
void AdminModule::sendWarning(const char *format, ...)
|
||||
{
|
||||
meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed();
|
||||
if (!cn)
|
||||
return;
|
||||
|
||||
cn->level = meshtastic_LogRecord_Level_WARNING;
|
||||
cn->time = getValidTime(RTCQualityFromNet);
|
||||
strncpy(cn->message, message, sizeof(cn->message));
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
// Format the arguments directly into the notification object
|
||||
vsnprintf(cn->message, sizeof(cn->message), format, args);
|
||||
va_end(args);
|
||||
|
||||
service->sendClientNotification(cn);
|
||||
}
|
||||
|
||||
void AdminModule::sendWarningAndLog(const char *format, ...)
|
||||
{
|
||||
// We need a temporary buffer to hold the formatted text so we can log it
|
||||
// Using 250 bytes as a safe upper limit for typical text notifications
|
||||
char buf[250];
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buf, sizeof(buf), format, args);
|
||||
va_end(args);
|
||||
|
||||
LOG_WARN(buf);
|
||||
// 2. Call sendWarning
|
||||
// SECURITY NOTE: We pass "%s", buf instead of just 'buf'.
|
||||
// If 'buf' contained a % symbol (e.g. "Battery 50%"), passing it directly
|
||||
// would crash sendWarning. "%s" treats it purely as text.
|
||||
sendWarning("%s", buf);
|
||||
}
|
||||
|
||||
void disableBluetooth()
|
||||
{
|
||||
#if HAS_BLUETOOTH
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#pragma once
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <esp_ota_ops.h>
|
||||
#endif
|
||||
#include "ProtobufModule.h"
|
||||
#include <sys/types.h>
|
||||
#if HAS_WIFI
|
||||
#include "mesh/wifi/WiFiAPClient.h"
|
||||
#endif
|
||||
@@ -71,7 +73,8 @@ class AdminModule : public ProtobufModule<meshtastic_AdminMessage>, public Obser
|
||||
|
||||
bool messageIsResponse(const meshtastic_AdminMessage *r);
|
||||
bool messageIsRequest(const meshtastic_AdminMessage *r);
|
||||
void sendWarning(const char *message);
|
||||
void sendWarning(const char *format, ...) __attribute__((format(printf, 2, 3)));
|
||||
void sendWarningAndLog(const char *format, ...) __attribute__((format(printf, 2, 3)));
|
||||
};
|
||||
|
||||
static constexpr const char *licensedModeMessage =
|
||||
|
||||
Reference in New Issue
Block a user