|
@@ -77,6 +77,17 @@
|
|
|
SET_FWINVALID_FLAG();\
|
|
|
} while(0)
|
|
|
|
|
|
+#define HTTP_RET_UPLOAD_ERROR_NO_FLASH_ERASE() do {\
|
|
|
+ memset(sendBuf, 0, 32);\
|
|
|
+ strcpy(sendBuf, HTTP_200_OK);\
|
|
|
+ strcat(sendBuf, "0");\
|
|
|
+ hs->file = sendBuf;\
|
|
|
+ hs->left = strlen(sendBuf);\
|
|
|
+ send_data(pcb, hs);\
|
|
|
+ tcp_sent(pcb, http_sent);\
|
|
|
+ htmlpage = UploadErrorPage;\
|
|
|
+ } while(0)
|
|
|
+
|
|
|
static char sendBuf[512];
|
|
|
static char tempBuf[HW_REV_OFFSET + HW_REV_LEN];
|
|
|
|
|
@@ -163,7 +174,7 @@ bool CookieIsSet(char *inStr, uint16_t inLen, char *paramName);
|
|
|
|
|
|
|
|
|
// Implements the GNU function memmem much faster (2x) than the standard memmem
|
|
|
-char *memmem(char *haystack, int hlen, char *needle, int nlen)
|
|
|
+char *memmemory(char *haystack, int hlen, char *needle, int nlen)
|
|
|
{
|
|
|
if (nlen > hlen) return 0;
|
|
|
int i = 0, j = 0;
|
|
@@ -648,7 +659,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
|
|
|
TotalData = TotalData - len;
|
|
|
len = 0;
|
|
|
} else {
|
|
|
- char *bptr = memmem(data, p->tot_len, boundary, strlen(boundary));
|
|
|
+ char *bptr = memmemory(data, p->tot_len, boundary, strlen(boundary));
|
|
|
// DBG printf("boundary: %s\r\n", boundary);
|
|
|
|
|
|
if (bptr != NULL) {
|
|
@@ -672,7 +683,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
|
|
|
|
|
|
/* Find "\r\n" or "\r" depending on a current packet length */
|
|
|
uint8_t marker_len = (tail_len - boundary_len >= 2) ? 2 : 1;
|
|
|
- char *ptr = memmem(data + p->tot_len - boundary_len, boundary_len,
|
|
|
+ char *ptr = memmemory(data + p->tot_len - boundary_len, boundary_len,
|
|
|
marker_len == 2 ? "\r\n" : "\r", marker_len);
|
|
|
|
|
|
if (ptr != NULL) {
|
|
@@ -726,7 +737,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
|
|
|
DataFlag = 0;
|
|
|
upload_pcb = NULL;
|
|
|
|
|
|
- HTTP_RET_UPLOAD_ERROR();
|
|
|
+ HTTP_RET_UPLOAD_ERROR_NO_FLASH_ERASE();
|
|
|
pbuf_free(p);
|
|
|
|
|
|
return ERR_OK;
|
|
@@ -811,7 +822,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
|
|
|
printf("FW binary size mismatch. Aborting update..\r\n");
|
|
|
printf("FW dest size %u was %u\r\n", (unsigned int)FwDestSize, (unsigned int)TotalData);
|
|
|
|
|
|
- HTTP_RET_UPLOAD_ERROR();
|
|
|
+ HTTP_RET_UPLOAD_ERROR_NO_FLASH_ERASE();
|
|
|
} else {
|
|
|
static uint8_t progress = 0;
|
|
|
if (progress != TotalReceived * 100 / size) {
|
|
@@ -1128,7 +1139,16 @@ void send_index_page(struct tcp_pcb *pcb, struct http_state *hs, struct pbuf *p,
|
|
|
#endif
|
|
|
|
|
|
strcat(sendBuf, "\r\nSet-Cookie: file2=");
|
|
|
- strcat(sendBuf, MAIN_FW_NAME);
|
|
|
+
|
|
|
+ char file_name_buf[40];
|
|
|
+ memset(file_name_buf, 0, sizeof(file_name_buf));
|
|
|
+ strcpy(file_name_buf, MAIN_FW_NAME);
|
|
|
+
|
|
|
+ if(strcmp(file_name_buf, "NONE") != 0){
|
|
|
+ strcat(sendBuf, MAIN_FW_NAME);
|
|
|
+ } else {
|
|
|
+ strcat(sendBuf, " ");
|
|
|
+ }
|
|
|
|
|
|
strcat(sendBuf,
|
|
|
"\r\n\r\n<!DOCTYPE html><html lang="
|
|
@@ -1262,6 +1282,16 @@ static bool Parse_Filename(const char *data, uint32_t len, fw_type_t *fw_type, u
|
|
|
uint32_t FilenameOffset = 0;
|
|
|
char filename[FILENAME_MAX_LEN];
|
|
|
|
|
|
+ char file_name_buf[40];
|
|
|
+ memset(file_name_buf, 0, sizeof(file_name_buf));
|
|
|
+ strcpy(file_name_buf, MAIN_FW_NAME);
|
|
|
+
|
|
|
+ if(strcmp(file_name_buf, "NONE") == 0){
|
|
|
+ *fw_type = fw_main_board;
|
|
|
+ *fw_size = MAIN_FW_SIZE;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
if (strncmp((char *)(data + i), "filename=", 9) == 0) {
|
|
|
FilenameOffset = i + 10;
|