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