Skip to content

Commit

Permalink
Make magic number configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Nov 22, 2023
1 parent bdfbe40 commit e121cb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/Arduino_ESP32_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Arduino_ESP32_OTA::Arduino_ESP32_OTA()
,_crc32(0)
,_ca_cert{amazon_root_ca}
,_ca_cert_bundle{nullptr}
,_magic(0)
{

}
Expand All @@ -45,14 +46,17 @@ Arduino_ESP32_OTA::Arduino_ESP32_OTA()
PUBLIC MEMBER FUNCTIONS
******************************************************************************/

Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin()
Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin(uint32_t magic)
{
/* initialize private variables */
otaInit();

/* ... initialize CRC ... */
crc32Init();

/* ... configure board Magic number */
setMagic(magic);

if(!isCapable()) {
DEBUG_ERROR("%s: board is not capable to perform OTA", __FUNCTION__);
return Error::NoOtaStorage;
Expand Down Expand Up @@ -84,6 +88,11 @@ void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle)
}
}

void Arduino_ESP32_OTA::setMagic(uint32_t magic)
{
_magic = magic;
}

uint8_t Arduino_ESP32_OTA::read_byte_from_network()
{
bool is_http_data_timeout = false;
Expand Down Expand Up @@ -229,7 +238,7 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
}

/* ... and OTA magic number */
if (_ota_header.header.magic_number != ARDUINO_ESP32_OTA_MAGIC)
if (_ota_header.header.magic_number != _magic)
{
return static_cast<int>(Error::OtaHeaterMagicNumber);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Arduino_ESP32_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ class Arduino_ESP32_OTA
Arduino_ESP32_OTA();
virtual ~Arduino_ESP32_OTA() { }

Arduino_ESP32_OTA::Error begin();
void setCACert (const char *rootCA);
Arduino_ESP32_OTA::Error begin(uint32_t magic = ARDUINO_ESP32_OTA_MAGIC);
void setMagic(uint32_t magic);
void setCACert(const char *rootCA);
void setCACertBundle(const uint8_t * bundle);
int download(const char * ota_url);
uint8_t read_byte_from_network();
Expand All @@ -97,6 +98,8 @@ class Arduino_ESP32_OTA
uint32_t _crc32;
const char * _ca_cert;
const uint8_t * _ca_cert_bundle;
uint32_t _magic;

};

#endif /* ARDUINO_ESP32_OTA_H_ */

0 comments on commit e121cb7

Please sign in to comment.