fix: Fix-Runde 1 für Task 4 - Reset nur bei akzeptiertem OTA-Image, hängende Downloads/Sessions begrenzen

This commit is contained in:
Michael Sauer
2026-09-12 01:56:58 +02:00
parent aa8151c3d6
commit 37c05d2f90
7 changed files with 122 additions and 27 deletions
+25 -2
View File
@@ -16,9 +16,15 @@
enum ota_state {PREPARE_PACKET, SETUP_LINK_AND_REQ, RECV_RSP, HANDLE_HEADER, HANDLE_BODY, SHUTDOWN_LINK, QUIT_OTA};
/* ninlight: SHUTDOWN_LINK resumes an unfinished transfer via PREPARE_PACKET forever - a server
* that closes the connection early (or never sends the full body) used to hang this task, and
* with it the caller of t_http_fwup(), permanently (see sdk/PATCHES.md point 1). Cap the number
* of resume rounds generously so a slow-but-healthy download still completes. */
#define NL_OTA_MAX_RETRY_ROUNDS 200
int http_fwup(HTTPParameters ClientParams)
{
char* Buffer = NULL;
char* Buffer = NULL;
char token[32];
char headRange[32] = {0};
int nRetCode = 0;
@@ -26,6 +32,7 @@ int http_fwup(HTTPParameters ClientParams)
u32 partLen;
u32 totalLen = 0;
u32 recvLen = 0;
u32 retryRounds = 0;
T_BOOTER *booter;
#if USE_BREAK_POINT_RESUME == 0
u32 breakFlag = 0;
@@ -124,6 +131,13 @@ int http_fwup(HTTPParameters ClientParams)
}
else
{
/* ninlight: nRetCode is still HTTP_CLIENT_SUCCESS here (the read itself
* worked, only the image header is bad), so the "if(nRetCode)" cleanup
* at the end of this function used to be skipped entirely - leaving
* socket_fwup_err()/tls_fwup_exit() uncalled and the fwup session stuck
* busy for every later attempt. Force the cleanup path (see
* sdk/PATCHES.md point 1). */
nRetCode = HTTP_CLIENT_ERROR_BAD_HEADER;
now_state = QUIT_OTA;
break;
}
@@ -191,7 +205,16 @@ int http_fwup(HTTPParameters ClientParams)
{
if(pHTTP){
HTTPClientCloseRequest(&pHTTP);
(recvLen == totalLen)?(now_state = QUIT_OTA):(now_state = PREPARE_PACKET);
if (recvLen == totalLen) {
now_state = QUIT_OTA;
} else if (++retryRounds > NL_OTA_MAX_RETRY_ROUNDS) {
/* ninlight: give up instead of resuming forever, see the comment above
* NL_OTA_MAX_RETRY_ROUNDS. */
nRetCode = HTTP_CLIENT_ERROR_SOCKET_TIME_OUT;
now_state = QUIT_OTA;
} else {
now_state = PREPARE_PACKET;
}
}
}
break;