ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
ota_esphome.cpp
Go to the documentation of this file.
1#include "ota_esphome.h"
2#ifdef USE_OTA
3#ifdef USE_OTA_PASSWORD
5#endif
13#include "esphome/core/hal.h"
15#include "esphome/core/log.h"
16#include "esphome/core/util.h"
17
18#include <cerrno>
19#include <cstdio>
20
21namespace esphome {
22
23static const char *const TAG = "esphome.ota";
24static constexpr uint16_t OTA_BLOCK_SIZE = 8192;
25static constexpr size_t OTA_BUFFER_SIZE = 1024; // buffer size for OTA data transfer
26static constexpr uint32_t OTA_SOCKET_TIMEOUT_HANDSHAKE = 20000; // milliseconds for initial handshake
27static constexpr uint32_t OTA_SOCKET_TIMEOUT_DATA = 90000; // milliseconds for data transfer
28
30 this->server_ = socket::socket_ip_loop_monitored(SOCK_STREAM, 0); // monitored for incoming connections
31 if (this->server_ == nullptr) {
32 this->log_socket_error_(LOG_STR("creation"));
33 this->mark_failed();
34 return;
35 }
36 int enable = 1;
37 int err = this->server_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int));
38 if (err != 0) {
39 this->log_socket_error_(LOG_STR("reuseaddr"));
40 // we can still continue
41 }
42 err = this->server_->setblocking(false);
43 if (err != 0) {
44 this->log_socket_error_(LOG_STR("non-blocking"));
45 this->mark_failed();
46 return;
47 }
48
49 struct sockaddr_storage server;
50
51 socklen_t sl = socket::set_sockaddr_any((struct sockaddr *) &server, sizeof(server), this->port_);
52 if (sl == 0) {
53 this->log_socket_error_(LOG_STR("set sockaddr"));
54 this->mark_failed();
55 return;
56 }
57
58 err = this->server_->bind((struct sockaddr *) &server, sizeof(server));
59 if (err != 0) {
60 this->log_socket_error_(LOG_STR("bind"));
61 this->mark_failed();
62 return;
63 }
64
65 err = this->server_->listen(1); // Only one client at a time
66 if (err != 0) {
67 this->log_socket_error_(LOG_STR("listen"));
68 this->mark_failed();
69 return;
70 }
71}
72
74 ESP_LOGCONFIG(TAG,
75 "Over-The-Air updates:\n"
76 " Address: %s:%u\n"
77 " Version: %d",
78 network::get_use_address(), this->port_, USE_OTA_VERSION);
79#ifdef USE_OTA_PASSWORD
80 if (!this->password_.empty()) {
81 ESP_LOGCONFIG(TAG, " Password configured");
82 }
83#endif
84}
85
87 // Skip handle_handshake_() call if no client connected and no incoming connections
88 // This optimization reduces idle loop overhead when OTA is not active
89 // Note: No need to check server_ for null as the component is marked failed in setup()
90 // if server_ creation fails
91 if (this->client_ != nullptr || this->server_->ready()) {
92 this->handle_handshake_();
93 }
94}
95
96static const uint8_t FEATURE_SUPPORTS_COMPRESSION = 0x01;
97static const uint8_t FEATURE_SUPPORTS_SHA256_AUTH = 0x02;
98
105
106 if (this->client_ == nullptr) {
107 // We already checked server_->ready() in loop(), so we can accept directly
108 struct sockaddr_storage source_addr;
109 socklen_t addr_len = sizeof(source_addr);
110 int enable = 1;
111
112 this->client_ = this->server_->accept_loop_monitored((struct sockaddr *) &source_addr, &addr_len);
113 if (this->client_ == nullptr)
114 return;
115 int err = this->client_->setsockopt(IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(int));
116 if (err != 0) {
117 this->log_socket_error_(LOG_STR("nodelay"));
118 this->cleanup_connection_();
119 return;
120 }
121 err = this->client_->setblocking(false);
122 if (err != 0) {
123 this->log_socket_error_(LOG_STR("non-blocking"));
124 this->cleanup_connection_();
125 return;
126 }
127 this->log_start_(LOG_STR("handshake"));
129 this->handshake_buf_pos_ = 0; // Reset handshake buffer position
131 }
132
133 // Check for handshake timeout
134 uint32_t now = App.get_loop_component_start_time();
135 if (now - this->client_connect_time_ > OTA_SOCKET_TIMEOUT_HANDSHAKE) {
136 ESP_LOGW(TAG, "Handshake timeout");
137 this->cleanup_connection_();
138 return;
139 }
140
141 switch (this->ota_state_) {
143 // Try to read remaining magic bytes (5 total)
144 if (!this->try_read_(5, LOG_STR("read magic"))) {
145 return;
146 }
147
148 // Validate magic bytes
149 static const uint8_t MAGIC_BYTES[5] = {0x6C, 0x26, 0xF7, 0x5C, 0x45};
150 if (memcmp(this->handshake_buf_, MAGIC_BYTES, 5) != 0) {
151 ESP_LOGW(TAG, "Magic bytes mismatch! 0x%02X-0x%02X-0x%02X-0x%02X-0x%02X", this->handshake_buf_[0],
152 this->handshake_buf_[1], this->handshake_buf_[2], this->handshake_buf_[3], this->handshake_buf_[4]);
154 return;
155 }
156
157 // Magic bytes valid, move to next state
160 this->handshake_buf_[1] = USE_OTA_VERSION;
161 [[fallthrough]];
162 }
163
164 case OTAState::MAGIC_ACK: {
165 // Send OK and version - 2 bytes
166 if (!this->try_write_(2, LOG_STR("ack magic"))) {
167 return;
168 }
169 // All bytes sent, create backend and move to next state
172 [[fallthrough]];
173 }
174
176 // Read features - 1 byte
177 if (!this->try_read_(1, LOG_STR("read feature"))) {
178 return;
179 }
180 this->ota_features_ = this->handshake_buf_[0];
181 ESP_LOGV(TAG, "Features: 0x%02X", this->ota_features_);
183 this->handshake_buf_[0] =
184 ((this->ota_features_ & FEATURE_SUPPORTS_COMPRESSION) != 0 && this->backend_->supports_compression())
187 [[fallthrough]];
188 }
189
191 // Acknowledge header - 1 byte
192 if (!this->try_write_(1, LOG_STR("ack feature"))) {
193 return;
194 }
195#ifdef USE_OTA_PASSWORD
196 // If password is set, move to auth phase
197 if (!this->password_.empty()) {
199 } else
200#endif
201 {
202 // No password, move directly to data phase
204 }
205 [[fallthrough]];
206 }
207
208#ifdef USE_OTA_PASSWORD
209 case OTAState::AUTH_SEND: {
210 // Non-blocking authentication send
211 if (!this->handle_auth_send_()) {
212 return;
213 }
215 [[fallthrough]];
216 }
217
218 case OTAState::AUTH_READ: {
219 // Non-blocking authentication read & verify
220 if (!this->handle_auth_read_()) {
221 return;
222 }
224 [[fallthrough]];
225 }
226#endif
227
228 case OTAState::DATA:
229 this->handle_data_();
230 return;
231
232 default:
233 break;
234 }
235}
236
246 bool update_started = false;
247 size_t total = 0;
248 uint32_t last_progress = 0;
249 uint8_t buf[OTA_BUFFER_SIZE];
250 char *sbuf = reinterpret_cast<char *>(buf);
251 size_t ota_size;
252#if USE_OTA_VERSION == 2
253 size_t size_acknowledged = 0;
254#endif
255
256 // Acknowledge auth OK - 1 byte
258
259 // Read size, 4 bytes MSB first
260 if (!this->readall_(buf, 4)) {
261 this->log_read_error_(LOG_STR("size"));
262 goto error; // NOLINT(cppcoreguidelines-avoid-goto)
263 }
264 ota_size = (static_cast<size_t>(buf[0]) << 24) | (static_cast<size_t>(buf[1]) << 16) |
265 (static_cast<size_t>(buf[2]) << 8) | buf[3];
266 ESP_LOGV(TAG, "Size is %u bytes", ota_size);
267
268 // Now that we've passed authentication and are actually
269 // starting the update, set the warning status and notify
270 // listeners. This ensures that port scanners do not
271 // accidentally trigger the update process.
272 this->log_start_(LOG_STR("update"));
273 this->status_set_warning();
274#ifdef USE_OTA_STATE_LISTENER
275 this->notify_state_(ota::OTA_STARTED, 0.0f, 0);
276#endif
277
278 // This will block for a few seconds as it locks flash
279 error_code = this->backend_->begin(ota_size);
280 if (error_code != ota::OTA_RESPONSE_OK)
281 goto error; // NOLINT(cppcoreguidelines-avoid-goto)
282 update_started = true;
283
284 // Acknowledge prepare OK - 1 byte
286
287 // Read binary MD5, 32 bytes
288 if (!this->readall_(buf, 32)) {
289 this->log_read_error_(LOG_STR("MD5 checksum"));
290 goto error; // NOLINT(cppcoreguidelines-avoid-goto)
291 }
292 sbuf[32] = '\0';
293 ESP_LOGV(TAG, "Update: Binary MD5 is %s", sbuf);
294 this->backend_->set_update_md5(sbuf);
295
296 // Acknowledge MD5 OK - 1 byte
298
299 while (total < ota_size) {
300 // TODO: timeout check
301 size_t remaining = ota_size - total;
302 size_t requested = remaining < OTA_BUFFER_SIZE ? remaining : OTA_BUFFER_SIZE;
303 ssize_t read = this->client_->read(buf, requested);
304 if (read == -1) {
305 if (this->would_block_(errno)) {
307 continue;
308 }
309 ESP_LOGW(TAG, "Read err %d", errno);
310 goto error; // NOLINT(cppcoreguidelines-avoid-goto)
311 } else if (read == 0) {
312 ESP_LOGW(TAG, "Remote closed");
313 goto error; // NOLINT(cppcoreguidelines-avoid-goto)
314 }
315
316 error_code = this->backend_->write(buf, read);
317 if (error_code != ota::OTA_RESPONSE_OK) {
318 ESP_LOGW(TAG, "Flash write err %d", error_code);
319 goto error; // NOLINT(cppcoreguidelines-avoid-goto)
320 }
321 total += read;
322#if USE_OTA_VERSION == 2
323 while (size_acknowledged + OTA_BLOCK_SIZE <= total || (total == ota_size && size_acknowledged < ota_size)) {
325 size_acknowledged += OTA_BLOCK_SIZE;
326 }
327#endif
328
329 uint32_t now = millis();
330 if (now - last_progress > 1000) {
331 last_progress = now;
332 float percentage = (total * 100.0f) / ota_size;
333 ESP_LOGD(TAG, "Progress: %0.1f%%", percentage);
334#ifdef USE_OTA_STATE_LISTENER
335 this->notify_state_(ota::OTA_IN_PROGRESS, percentage, 0);
336#endif
337 // feed watchdog and give other tasks a chance to run
339 }
340 }
341
342 // Acknowledge receive OK - 1 byte
344
345 error_code = this->backend_->end();
346 if (error_code != ota::OTA_RESPONSE_OK) {
347 ESP_LOGW(TAG, "End update err %d", error_code);
348 goto error; // NOLINT(cppcoreguidelines-avoid-goto)
349 }
350
351 // Acknowledge Update end OK - 1 byte
353
354 // Read ACK
355 if (!this->readall_(buf, 1) || buf[0] != ota::OTA_RESPONSE_OK) {
356 this->log_read_error_(LOG_STR("ack"));
357 // do not go to error, this is not fatal
358 }
359
360 this->cleanup_connection_();
361 delay(10);
362 ESP_LOGI(TAG, "Update complete");
363 this->status_clear_warning();
364#ifdef USE_OTA_STATE_LISTENER
365 this->notify_state_(ota::OTA_COMPLETED, 100.0f, 0);
366#endif
367 delay(100); // NOLINT
369
370error:
371 this->write_byte_(static_cast<uint8_t>(error_code));
372 this->cleanup_connection_();
373
374 if (this->backend_ != nullptr && update_started) {
375 this->backend_->abort();
376 }
377
378 this->status_momentary_error("err", 5000);
379#ifdef USE_OTA_STATE_LISTENER
380 this->notify_state_(ota::OTA_ERROR, 0.0f, static_cast<uint8_t>(error_code));
381#endif
382}
383
384bool ESPHomeOTAComponent::readall_(uint8_t *buf, size_t len) {
385 uint32_t start = millis();
386 uint32_t at = 0;
387 while (len - at > 0) {
388 uint32_t now = millis();
389 if (now - start > OTA_SOCKET_TIMEOUT_DATA) {
390 ESP_LOGW(TAG, "Timeout reading %d bytes", len);
391 return false;
392 }
393
394 ssize_t read = this->client_->read(buf + at, len - at);
395 if (read == -1) {
396 if (!this->would_block_(errno)) {
397 ESP_LOGW(TAG, "Read err %d bytes, errno %d", len, errno);
398 return false;
399 }
400 } else if (read == 0) {
401 ESP_LOGW(TAG, "Remote closed");
402 return false;
403 } else {
404 at += read;
405 }
407 }
408
409 return true;
410}
411bool ESPHomeOTAComponent::writeall_(const uint8_t *buf, size_t len) {
412 uint32_t start = millis();
413 uint32_t at = 0;
414 while (len - at > 0) {
415 uint32_t now = millis();
416 if (now - start > OTA_SOCKET_TIMEOUT_DATA) {
417 ESP_LOGW(TAG, "Timeout writing %d bytes", len);
418 return false;
419 }
420
421 ssize_t written = this->client_->write(buf + at, len - at);
422 if (written == -1) {
423 if (!this->would_block_(errno)) {
424 ESP_LOGW(TAG, "Write err %d bytes, errno %d", len, errno);
425 return false;
426 }
427 } else {
428 at += written;
429 }
431 }
432 return true;
433}
434
436uint16_t ESPHomeOTAComponent::get_port() const { return this->port_; }
437void ESPHomeOTAComponent::set_port(uint16_t port) { this->port_ = port; }
438
439void ESPHomeOTAComponent::log_socket_error_(const LogString *msg) {
440 ESP_LOGW(TAG, "Socket %s: errno %d", LOG_STR_ARG(msg), errno);
441}
442
443void ESPHomeOTAComponent::log_read_error_(const LogString *what) { ESP_LOGW(TAG, "Read %s failed", LOG_STR_ARG(what)); }
444
445void ESPHomeOTAComponent::log_start_(const LogString *phase) {
446 ESP_LOGD(TAG, "Starting %s from %s", LOG_STR_ARG(phase), this->client_->getpeername().c_str());
447}
448
449void ESPHomeOTAComponent::log_remote_closed_(const LogString *during) {
450 ESP_LOGW(TAG, "Remote closed at %s", LOG_STR_ARG(during));
451}
452
453bool ESPHomeOTAComponent::handle_read_error_(ssize_t read, const LogString *desc) {
454 if (read == -1 && this->would_block_(errno)) {
455 return false; // No data yet, try again next loop
456 }
457
458 if (read <= 0) {
459 read == 0 ? this->log_remote_closed_(desc) : this->log_socket_error_(desc);
460 this->cleanup_connection_();
461 return false;
462 }
463 return true;
464}
465
466bool ESPHomeOTAComponent::handle_write_error_(ssize_t written, const LogString *desc) {
467 if (written == -1) {
468 if (this->would_block_(errno)) {
469 return false; // Try again next loop
470 }
471 this->log_socket_error_(desc);
472 this->cleanup_connection_();
473 return false;
474 }
475 return true;
476}
477
478bool ESPHomeOTAComponent::try_read_(size_t to_read, const LogString *desc) {
479 // Read bytes into handshake buffer, starting at handshake_buf_pos_
480 size_t bytes_to_read = to_read - this->handshake_buf_pos_;
481 ssize_t read = this->client_->read(this->handshake_buf_ + this->handshake_buf_pos_, bytes_to_read);
482
483 if (!this->handle_read_error_(read, desc)) {
484 return false;
485 }
486
487 this->handshake_buf_pos_ += read;
488 // Return true only if we have all the requested bytes
489 return this->handshake_buf_pos_ >= to_read;
490}
491
492bool ESPHomeOTAComponent::try_write_(size_t to_write, const LogString *desc) {
493 // Write bytes from handshake buffer, starting at handshake_buf_pos_
494 size_t bytes_to_write = to_write - this->handshake_buf_pos_;
495 ssize_t written = this->client_->write(this->handshake_buf_ + this->handshake_buf_pos_, bytes_to_write);
496
497 if (!this->handle_write_error_(written, desc)) {
498 return false;
499 }
500
501 this->handshake_buf_pos_ += written;
502 // Return true only if we have written all the requested bytes
503 return this->handshake_buf_pos_ >= to_write;
504}
505
507 this->client_->close();
508 this->client_ = nullptr;
509 this->client_connect_time_ = 0;
510 this->handshake_buf_pos_ = 0;
512 this->ota_features_ = 0;
513 this->backend_ = nullptr;
514#ifdef USE_OTA_PASSWORD
515 this->cleanup_auth_();
516#endif
517}
518
523
524#ifdef USE_OTA_PASSWORD
525void ESPHomeOTAComponent::log_auth_warning_(const LogString *msg) { ESP_LOGW(TAG, "Auth: %s", LOG_STR_ARG(msg)); }
526
528 bool client_supports_sha256 = (this->ota_features_ & FEATURE_SUPPORTS_SHA256_AUTH) != 0;
529
530 // Require SHA256
531 if (!client_supports_sha256) {
532 this->log_auth_warning_(LOG_STR("SHA256 required"));
534 return false;
535 }
537 return true;
538}
539
541 // Initialize auth buffer if not already done
542 if (!this->auth_buf_) {
543 // Select auth type based on client capabilities and configuration
544 if (!this->select_auth_type_()) {
545 return false;
546 }
547
548 // Generate nonce - hasher must be created and used in same stack frame
549 // CRITICAL ESP32-S3 HARDWARE SHA ACCELERATION REQUIREMENTS:
550 // 1. Hash objects must NEVER be passed to another function (different stack frame)
551 // 2. NO Variable Length Arrays (VLAs) - they corrupt the stack with hardware DMA
552 // 3. All hash operations (init/add/calculate) must happen in the SAME function where object is created
553 // Violating these causes truncated hash output (20 bytes instead of 32) or memory corruption.
554 //
555 // Buffer layout after AUTH_READ completes:
556 // [0]: auth_type (1 byte)
557 // [1...hex_size]: nonce (hex_size bytes) - our random nonce sent in AUTH_SEND
558 // [1+hex_size...1+2*hex_size-1]: cnonce (hex_size bytes) - client's nonce
559 // [1+2*hex_size...1+3*hex_size-1]: response (hex_size bytes) - client's hash
560
561 // CRITICAL ESP32-S3 HARDWARE SHA ACCELERATION: Hash object must stay in same stack frame
562 // (no passing to other functions). All hash operations must happen in this function.
563 sha256::SHA256 hasher;
564
565 const size_t hex_size = hasher.get_size() * 2;
566 const size_t nonce_len = hasher.get_size() / 4;
567 const size_t auth_buf_size = 1 + 3 * hex_size;
568 this->auth_buf_ = std::make_unique<uint8_t[]>(auth_buf_size);
569 this->auth_buf_pos_ = 0;
570
571 char *buf = reinterpret_cast<char *>(this->auth_buf_.get() + 1);
572 if (!random_bytes(reinterpret_cast<uint8_t *>(buf), nonce_len)) {
573 this->log_auth_warning_(LOG_STR("Random failed"));
575 return false;
576 }
577
578 hasher.init();
579 hasher.add(buf, nonce_len);
580 hasher.calculate();
581 this->auth_buf_[0] = this->auth_type_;
582 hasher.get_hex(buf);
583
584 ESP_LOGV(TAG, "Auth: Nonce is %.*s", hex_size, buf);
585 }
586
587 // Try to write auth_type + nonce
588 constexpr size_t hex_size = SHA256_HEX_SIZE;
589 const size_t to_write = 1 + hex_size;
590 size_t remaining = to_write - this->auth_buf_pos_;
591
592 ssize_t written = this->client_->write(this->auth_buf_.get() + this->auth_buf_pos_, remaining);
593 if (!this->handle_write_error_(written, LOG_STR("ack auth"))) {
594 return false;
595 }
596
597 this->auth_buf_pos_ += written;
598
599 // Check if we still have more to write
600 if (this->auth_buf_pos_ < to_write) {
601 return false; // More to write, try again next loop
602 }
603
604 // All written, prepare for reading phase
605 this->auth_buf_pos_ = 0;
606 return true;
607}
608
610 constexpr size_t hex_size = SHA256_HEX_SIZE;
611 const size_t to_read = hex_size * 2; // CNonce + Response
612
613 // Try to read remaining bytes (CNonce + Response)
614 // We read cnonce+response starting at offset 1+hex_size (after auth_type and our nonce)
615 size_t cnonce_offset = 1 + hex_size; // Offset where cnonce should be stored in buffer
616 size_t remaining = to_read - this->auth_buf_pos_;
617 ssize_t read = this->client_->read(this->auth_buf_.get() + cnonce_offset + this->auth_buf_pos_, remaining);
618
619 if (!this->handle_read_error_(read, LOG_STR("read auth"))) {
620 return false;
621 }
622
623 this->auth_buf_pos_ += read;
624
625 // Check if we still need more data
626 if (this->auth_buf_pos_ < to_read) {
627 return false; // More to read, try again next loop
628 }
629
630 // We have all the data, verify it
631 const char *nonce = reinterpret_cast<char *>(this->auth_buf_.get() + 1);
632 const char *cnonce = nonce + hex_size;
633 const char *response = cnonce + hex_size;
634
635 // CRITICAL ESP32-S3 HARDWARE SHA ACCELERATION: Hash object must stay in same stack frame
636 // (no passing to other functions). All hash operations must happen in this function.
637 sha256::SHA256 hasher;
638
639 hasher.init();
640 hasher.add(this->password_.c_str(), this->password_.length());
641 hasher.add(nonce, hex_size * 2); // Add both nonce and cnonce (contiguous in buffer)
642 hasher.calculate();
643
644 ESP_LOGV(TAG, "Auth: CNonce is %.*s", hex_size, cnonce);
645#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
646 char computed_hash[SHA256_HEX_SIZE + 1]; // Buffer for hex-encoded hash (max expected length + null terminator)
647 hasher.get_hex(computed_hash);
648 ESP_LOGV(TAG, "Auth: Result is %.*s", hex_size, computed_hash);
649#endif
650 ESP_LOGV(TAG, "Auth: Response is %.*s", hex_size, response);
651
652 // Compare response
653 bool matches = hasher.equals_hex(response);
654
655 if (!matches) {
656 this->log_auth_warning_(LOG_STR("Password mismatch"));
658 return false;
659 }
660
661 // Authentication successful - clean up auth state
662 this->cleanup_auth_();
663
664 return true;
665}
666
668 this->auth_buf_ = nullptr;
669 this->auth_buf_pos_ = 0;
670 this->auth_type_ = 0;
671}
672#endif // USE_OTA_PASSWORD
673
674} // namespace esphome
675#endif
void feed_wdt(uint32_t time=0)
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
virtual void mark_failed()
Mark this component as failed.
void status_momentary_error(const char *name, uint32_t length=5000)
Set error status flag and automatically clear it after a timeout.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
bool would_block_(int error_code) const
Definition ota_esphome.h:61
std::unique_ptr< ota::OTABackend > backend_
Definition ota_esphome.h:88
static constexpr size_t SHA256_HEX_SIZE
Definition ota_esphome.h:47
bool writeall_(const uint8_t *buf, size_t len)
bool try_read_(size_t to_read, const LogString *desc)
bool try_write_(size_t to_write, const LogString *desc)
std::unique_ptr< uint8_t[]> auth_buf_
Definition ota_esphome.h:83
bool handle_write_error_(ssize_t written, const LogString *desc)
void log_auth_warning_(const LogString *msg)
float get_setup_priority() const override
void send_error_and_cleanup_(ota::OTAResponseTypes error)
Definition ota_esphome.h:74
bool handle_read_error_(ssize_t read, const LogString *desc)
void log_read_error_(const LogString *what)
bool readall_(uint8_t *buf, size_t len)
void set_port(uint16_t port)
Manually set the port OTA should listen on.
bool write_byte_(uint8_t byte)
Definition ota_esphome.h:56
std::unique_ptr< socket::Socket > server_
Definition ota_esphome.h:86
void transition_ota_state_(OTAState next_state)
Definition ota_esphome.h:64
void log_remote_closed_(const LogString *during)
std::unique_ptr< socket::Socket > client_
Definition ota_esphome.h:87
void log_start_(const LogString *phase)
void log_socket_error_(const LogString *msg)
void get_hex(char *output)
Retrieve the hash as hex characters. Output buffer must hold get_size() * 2 + 1 bytes.
Definition hash_base.h:29
bool equals_hex(const char *expected)
Compare the hash against a provided hex-encoded hash.
Definition hash_base.h:35
void notify_state_(OTAState state, float progress, uint8_t error)
void calculate() override
Definition sha256.cpp:55
size_t get_size() const override
Get the size of the hash in bytes (32 for SHA256)
Definition sha256.h:38
void add(const uint8_t *data, size_t len) override
Definition sha256.cpp:53
void init() override
Definition sha256.cpp:48
uint16_t addr_len
uint32_t socklen_t
Definition headers.h:97
__int64 ssize_t
Definition httplib.h:178
const char * get_use_address()
Get the active network hostname.
Definition util.cpp:88
std::unique_ptr< ota::OTABackend > make_ota_backend()
@ OTA_RESPONSE_UPDATE_PREPARE_OK
Definition ota_backend.h:21
@ OTA_RESPONSE_SUPPORTS_COMPRESSION
Definition ota_backend.h:25
@ OTA_RESPONSE_BIN_MD5_OK
Definition ota_backend.h:22
@ OTA_RESPONSE_UPDATE_END_OK
Definition ota_backend.h:24
@ OTA_RESPONSE_RECEIVE_OK
Definition ota_backend.h:23
@ OTA_RESPONSE_CHUNK_OK
Definition ota_backend.h:26
@ OTA_RESPONSE_ERROR_AUTH_INVALID
Definition ota_backend.h:30
@ OTA_RESPONSE_ERROR_UNKNOWN
Definition ota_backend.h:41
@ OTA_RESPONSE_REQUEST_SHA256_AUTH
Definition ota_backend.h:17
@ OTA_RESPONSE_ERROR_MAGIC
Definition ota_backend.h:28
@ OTA_RESPONSE_HEADER_OK
Definition ota_backend.h:19
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
Definition component.cpp:88
std::unique_ptr< Socket > socket_ip_loop_monitored(int type, int protocol)
Definition socket.cpp:21
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port)
Set a sockaddr to the any address and specified port for the IP version used by socket_ip().
Definition socket.cpp:68
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
bool random_bytes(uint8_t *data, size_t len)
Generate len number of random bytes.
Definition helpers.cpp:18
std::string size_t len
Definition helpers.h:533
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:26
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:25
Application App
Global storage of Application pointer - only one Application can exist.