| 
					
				 | 
			
			
				@@ -33,6 +33,7 @@ static __IO u8 resetpage=0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 static uint32_t ContentLengthOffset =0,BrowserFlag=0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 static __IO uint32_t TotalData=0, checklogin=0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 static bool fEraseFlash = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+static bool hw_validated = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 static uint8_t reqCounter = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 static uint8_t reqTimer = 0; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -279,10 +280,10 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       /* process POST request for file upload and incoming data packets after POST request*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       else if ((strncmp(data, "POST /upload.cgi",16) == 0) || (DataFlag >= 1)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if (fEraseFlash) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		/*if (fEraseFlash) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		  FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		  fEraseFlash = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         DataOffset = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -362,6 +363,9 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              filename[i] = 0x0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+           /* Set HW revision validation marker */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+               hw_validated = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (i==0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              htmlpage = FileUploadPage; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -389,11 +393,11 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            TotalData =0 ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            /* init flash */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-           FLASH_If_Init(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         ///  FLASH_If_Init(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            /* erase user flash area */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-           FlashWriteAddress = USER_FLASH_FIRST_PAGE_ADDRESS; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         // / FlashWriteAddress = USER_FLASH_FIRST_PAGE_ADDRESS; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            /*indicate start of flash programming */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            PRINT_USART("\n\rState: Programming..\n\r"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -448,6 +452,8 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		   else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		   { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			 FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			 fEraseFlash = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		     fs_open("/error.html", &file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              hs->file = file.data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              hs->left = file.len; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -469,6 +475,41 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /* not last data packet */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        	if ((TotalData >= HW_REV_OFFSET + HW_REV_LEN) && (!hw_validated)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			  char rev[HW_REV_LEN]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			  strncpy(rev, HW_REV, HW_REV_LEN); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			  if (strcmp((char *)(ptr + HW_REV_OFFSET), rev) != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				  DataFlag = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 fs_open("/error.html", &file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 hs->file = file.data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 hs->left = file.len; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 send_data(pcb, hs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 tcp_sent(pcb, http_sent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 htmlpage = UploadErrorPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				// fErrorReset = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 pbuf_free(p); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				 //close_conn(pcb, hs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				  return ERR_OK; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			  else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				  hw_validated = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				   // Erase flash 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				   if (fEraseFlash) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					  FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					  fEraseFlash = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				  // Init flash 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				  FLASH_If_Init(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				  FlashWriteAddress = USER_FLASH_FIRST_PAGE_ADDRESS; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           /* write data in flash */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           if(len) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             IAP_HTTP_writedata(ptr,len); 
			 |