MCPcopy Create free account
hub / github.com/FastLED/FastLED / handleFirmwareUpload

Method handleFirmwareUpload

src/platforms/esp/32/ota/ota_impl.cpp.hpp:995–1208  ·  view source on GitHub ↗

@brief Handle TCP firmware upload after successful invitation/auth @param client_addr UDP client address @param port TCP port where client is listening @param expected_size Expected firmware size in bytes @param expected_md5 Expected MD5 hash (32-char hex string) @param cmd OTA command (0=FLASH, 100=SPIFFS, etc.)

Source from the content-addressed store, hash-verified

993 /// @param expected_md5 Expected MD5 hash (32-char hex string)
994 /// @param cmd OTA command (0=FLASH, 100=SPIFFS, etc.)
995 void handleFirmwareUpload(struct sockaddr_in* client_addr, int port,
996 int expected_size, const char* expected_md5, int cmd) {
997 // Only handle FLASH command (0) for now
998 if (cmd != 0) {
999 FL_WARN("OTA: Unsupported command " << cmd << " (only FLASH supported)");
1000 if (mErrorCb) {
1001 mErrorCb("Unsupported OTA command");
1002 }
1003 return;
1004 }
1005
1006 // Call start state callback
1007 if (mStateCb) {
1008 mStateCb(1); // OTA_START
1009 }
1010
1011 // Create TCP socket to connect to client
1012 int tcp_socket = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
1013 if (tcp_socket < 0) {
1014 FL_WARN("OTA: Failed to create TCP socket");
1015 if (mErrorCb) {
1016 mErrorCb("TCP socket creation failed");
1017 }
1018 if (mStateCb) {
1019 mStateCb(3); // OTA_ERROR
1020 }
1021 return;
1022 }
1023
1024 // Set socket timeout to 10 seconds
1025 struct timeval timeout;
1026 timeout.tv_sec = 10;
1027 timeout.tv_usec = 0;
1028 lwip_setsockopt(tcp_socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
1029
1030 // Connect to client's TCP server
1031 struct sockaddr_in tcp_addr;
1032 fl::memcpy(&tcp_addr, client_addr, sizeof(struct sockaddr_in));
1033 tcp_addr.sin_port = lwip_htons(port);
1034
1035 FL_DBG("OTA: Connecting to client TCP server on port " << port);
1036 if (lwip_connect(tcp_socket, (struct sockaddr*)&tcp_addr, sizeof(tcp_addr)) < 0) {
1037 FL_WARN("OTA: Failed to connect to client TCP server");
1038 if (mErrorCb) {
1039 mErrorCb("TCP connection failed");
1040 }
1041 lwip_close(tcp_socket);
1042 if (mStateCb) {
1043 mStateCb(3); // OTA_ERROR
1044 }
1045 return;
1046 }
1047
1048 FL_DBG("OTA: TCP connected, receiving firmware (" << expected_size << " bytes)");
1049
1050 // Get OTA partition
1051 const esp_partition_t* update_partition = esp_ota_get_next_update_partition(nullptr);
1052 if (!update_partition) {

Callers 1

otaServerTaskMethod · 0.95

Calls 4

esp_err_to_nameFunction · 0.85
snprintfFunction · 0.85
strcmpFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected