| 
														
															@@ -2877,9 +2877,7 @@ void ssl_server(void *pvParameters) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 {
 
														 | 
														
														 | 
														
															 {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   SSL_SERVER_STATE ssl_state = SSL_ACCEPT;
 
														 | 
														
														 | 
														
															   SSL_SERVER_STATE ssl_state = SSL_ACCEPT;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   char* sendPtr;
 
														 | 
														
														 | 
														
															   char* sendPtr;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  uint32_t sendBufSize;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  int ret, len;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  struct fs_file file = {0, 0};
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  int ret;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   
 
														 | 
														
														 | 
														
															   
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 #ifdef MBEDTLS_MEMORY_BUFFER_ALLOC_C
 
														 | 
														
														 | 
														
															 #ifdef MBEDTLS_MEMORY_BUFFER_ALLOC_C
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   mbedtls_memory_buffer_alloc_init(malloc_buf, sizeof(malloc_buf));
 
														 | 
														
														 | 
														
															   mbedtls_memory_buffer_alloc_init(malloc_buf, sizeof(malloc_buf));
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3122,25 +3120,20 @@ char* SSL_ProcessingRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 {  
 
														 | 
														
														 | 
														
															 {  
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   Cockie();
 
														 | 
														
														 | 
														
															   Cockie();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   getAuthenticatedState();
 
														 | 
														
														 | 
														
															   getAuthenticatedState();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-/*  
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  fs_open("/main.css", &file);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  *sendLen = file.len;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  return file.data;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-*/  
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-#if 1
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   if ( Authenticated == false && sSettings.sRADIUS.Auth_enable == false)
 
														 | 
														
														 | 
														
															   if ( Authenticated == false && sSettings.sRADIUS.Auth_enable == false)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   { 	
 
														 | 
														
														 | 
														
															   { 	
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     HTTP_LOGIN(sendBuf, sendLen);  
 
														 | 
														
														 | 
														
															     HTTP_LOGIN(sendBuf, sendLen);  
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return sendBuf;
 
														 | 
														
														 | 
														
															     return sendBuf;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  else if ( Authenticated == false )//&& sSettings.sRADIUS.Auth_enable == true
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  else if (!Authenticated)//&& sSettings.sRADIUS.Auth_enable == true
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   {
 
														 | 
														
														 | 
														
															   {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     return AuthenticatedFalseRoutine(sendLen);
 
														 | 
														
														 | 
														
															     return AuthenticatedFalseRoutine(sendLen);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-#endif  
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  else 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    return AuthenticatedTrueRoutine(sendLen);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  }  
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }
 
														 | 
														
														 | 
														
															 }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 //
 
														 | 
														
														 | 
														
															 //
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3210,7 +3203,7 @@ char* AuthenticatedFalseRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                         //ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
 
														 | 
														
														 | 
														
															                         //ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                         return sendBuf;
 
														 | 
														
														 | 
														
															                         return sendBuf;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     } 
 
														 | 
														
														 | 
														
															                     } 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                        post_data_count = 0;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    post_data_count = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 }
 
														 | 
														
														 | 
														
															                 }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 else
 
														 | 
														
														 | 
														
															                 else
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 {
 
														 | 
														
														 | 
														
															                 {
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3287,7 +3280,8 @@ char* AuthenticatedFalseRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 char* AuthenticatedTrueRoutine(uint16_t* sendLen)
 
														 | 
														
														 | 
														
															 char* AuthenticatedTrueRoutine(uint16_t* sendLen)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 {
 
														 | 
														
														 | 
														
															 {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     char *DataOffset;
 
														 | 
														
														 | 
														
															     char *DataOffset;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-  
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    char *ptr;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (strncmp(receiveBuf, "GET /main.css", 13) == 0) // +
 
														 | 
														
														 | 
														
															     if (strncmp(receiveBuf, "GET /main.css", 13) == 0) // +
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     {
 
														 | 
														
														 | 
														
															     {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         fs_open("/main.css", &file);
 
														 | 
														
														 | 
														
															         fs_open("/main.css", &file);
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3366,6 +3360,7 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 return sendBuf;
 
														 | 
														
														 | 
														
															                 return sendBuf;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             }
 
														 | 
														
														 | 
														
															             }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }
 
														 | 
														
														 | 
														
															         }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     else if (strncmp(receiveBuf, "POST /settings.cgi", 18) == 0)
 
														 | 
														
														 | 
														
															     else if (strncmp(receiveBuf, "POST /settings.cgi", 18) == 0)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     {
 
														 | 
														
														 | 
														
															     {
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3414,9 +3409,9 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 sendBufLoadLen = strlen(sendBuf);
 
														 | 
														
														 | 
														
															                 sendBufLoadLen = strlen(sendBuf);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 *sendLen = sendBufLoadLen;
 
														 | 
														
														 | 
														
															                 *sendLen = sendBufLoadLen;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 return sendBuf;
 
														 | 
														
														 | 
														
															                 return sendBuf;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             }
 
														 | 
														
														 | 
														
															             }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }  
 
														 | 
														
														 | 
														
															         }  
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
 
														 | 
														
														 | 
														
															     } 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     else if (strncmp(receiveBuf, "POST /srv_crt_upload.cgi", 24) == 0)
 
														 | 
														
														 | 
														
															     else if (strncmp(receiveBuf, "POST /srv_crt_upload.cgi", 24) == 0)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     {
 
														 | 
														
														 | 
														
															     {
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3461,7 +3456,7 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         while(TotalData < size)
 
														 | 
														
														 | 
														
															         while(TotalData < size)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         {
 
														 | 
														
														 | 
														
															         {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            ssl_server_read();
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            SSL_ReadRoutine(&ssl, (unsigned char*)receiveBuf);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             receiveBuf[receivedBufLen] = '\0';
 
														 | 
														
														 | 
														
															             receiveBuf[receivedBufLen] = '\0';
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             //printf("receive3 %s \r\n", receiveBuf);
 
														 | 
														
														 | 
														
															             //printf("receive3 %s \r\n", receiveBuf);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             strncat(sendBuf,  receiveBuf, receivedBufLen);
 
														 | 
														
														 | 
														
															             strncat(sendBuf,  receiveBuf, receivedBufLen);
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3565,11 +3560,11 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     
 
														 | 
														
														 | 
														
															     
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         if (res == SEND_REQUIRED_FILE)
 
														 | 
														
														 | 
														
															         if (res == SEND_REQUIRED_FILE)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         {
 
														 | 
														
														 | 
														
															         {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            //send_data(pcb, hs);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            //tcp_sent(pcb, http_sent_history);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (SSL_SendFrames(&ssl, sendBuf, sendBufLoadLen) == SSL_ERROR)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                return 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             HTTP_SendHistory();
 
														 | 
														
														 | 
														
															             HTTP_SendHistory();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            //tcp_err(pcb, http_sent_log_err);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            return 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }
 
														 | 
														
														 | 
														
															         }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         else if (res == SEND_REQUIRED_YES) 
 
														 | 
														
														 | 
														
															         else if (res == SEND_REQUIRED_YES) 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         {
 
														 | 
														
														 | 
														
															         {
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3584,12 +3579,11 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     
 
														 | 
														
														 | 
														
															     
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         if (res == SEND_REQUIRED_FILE)
 
														 | 
														
														 | 
														
															         if (res == SEND_REQUIRED_FILE)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         {
 
														 | 
														
														 | 
														
															         {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            //send_data(pcb, hs);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            //tcp_sent(pcb, http_sent_log);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (SSL_SendFrames(&ssl, sendBuf, sendBufLoadLen) == SSL_ERROR)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                return 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             HTTP_SendLog();
 
														 | 
														
														 | 
														
															             HTTP_SendLog();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            //tcp_err(pcb, http_sent_log_err);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            return 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }
 
														 | 
														
														 | 
														
															         }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         else if (res == SEND_REQUIRED_YES) 
 
														 | 
														
														 | 
														
															         else if (res == SEND_REQUIRED_YES) 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         {
 
														 | 
														
														 | 
														
															         {
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3637,19 +3631,19 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     else if (strncmp(receiveBuf, "GET /fw_update.cgi", 18) == 0)
 
														 | 
														
														 | 
														
															     else if (strncmp(receiveBuf, "GET /fw_update.cgi", 18) == 0)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     {
 
														 | 
														
														 | 
														
															     {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         HTTP_ConfirmBootPwd(receiveBuf, sendBuf, receivedBufLen, sendLen);
 
														 | 
														
														 | 
														
															         HTTP_ConfirmBootPwd(receiveBuf, sendBuf, receivedBufLen, sendLen);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return sendBuf;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     /* Смена пароля пользователя */
 
														 | 
														
														 | 
														
															     /* Смена пароля пользователя */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     else if (strncmp(receiveBuf, "GET /changepwd.cgi", 18) == 0)
 
														 | 
														
														 | 
														
															     else if (strncmp(receiveBuf, "GET /changepwd.cgi", 18) == 0)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     {
 
														 | 
														
														 | 
														
															     {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        HTTP_ChangeUserPwd(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        HTTP_ChangeUserPwd(receiveBuf, sendBuf, receivedBufLen, sendLen);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return sendBuf;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     // На производстве
 
														 | 
														
														 | 
														
															     // На производстве
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     else if (strncmp(receiveBuf, "GET /setProdate.cgi", 19) == 0)
 
														 | 
														
														 | 
														
															     else if (strncmp(receiveBuf, "GET /setProdate.cgi", 19) == 0)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     {
 
														 | 
														
														 | 
														
															     {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        HTTP_Prodate(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-        ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        HTTP_Prodate(receiveBuf, sendBuf, receivedBufLen, sendLen);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return sendBuf;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     else
 
														 | 
														
														 | 
														
															     else
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     {
 
														 | 
														
														 | 
														
															     {
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3658,6 +3652,8 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         *sendLen = file.len;
 
														 | 
														
														 | 
														
															         *sendLen = file.len;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         return file.data;
 
														 | 
														
														 | 
														
															         return file.data;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    return 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }
 
														 | 
														
														 | 
														
															 }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3695,8 +3691,7 @@ SSL_SERVER_STATE SSL_SendFrames(mbedtls_ssl_context *ssl, char *data, int datale 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if( retClose != MBEDTLS_ERR_SSL_WANT_READ && retClose != MBEDTLS_ERR_SSL_WANT_WRITE )
 
														 | 
														
														 | 
														
															     if( retClose != MBEDTLS_ERR_SSL_WANT_READ && retClose != MBEDTLS_ERR_SSL_WANT_WRITE )
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     {
 
														 | 
														
														 | 
														
															     {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       mbedtls_printf( " failed\r\n  ! mbedtls_ssl_close_notify returned %d\r\n", ret );
 
														 | 
														
														 | 
														
															       mbedtls_printf( " failed\r\n  ! mbedtls_ssl_close_notify returned %d\r\n", ret );
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      // TODO вернуть другой статус
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-      return SSL_ACCEPT;
 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      return SSL_ERROR;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     }
 
														 | 
														
														 | 
														
															     }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   }
 
														 | 
														
														 | 
														
															   }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
 
														 | 
														
														 | 
														
															 
 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3746,3 +3741,73 @@ SSL_SERVER_STATE SSL_Write(mbedtls_ssl_context *ssl, char *data, int datalen) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   ret = 0;
 
														 | 
														
														 | 
														
															   ret = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   return SSL_ACCEPT;
 
														 | 
														
														 | 
														
															   return SSL_ACCEPT;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }
 
														 | 
														
														 | 
														
															 }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+/**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  * @brief Send callback for log file transfer (messages as is, not ordered)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+void HTTP_SendHistory(void)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+{
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    uint32_t nbytes = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    static bool start = true;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    memset(logFileBuf, 0, FILE_BUF_MAX_LEN);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (log_ptr + FILE_BUF_MAX_LEN <= log_size) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        nbytes = History_GetData(log_ptr, logFileBuf, FILE_BUF_MAX_LEN, start);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    else if (log_ptr < log_size) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        nbytes = History_GetData(log_ptr, logFileBuf, (log_size - log_ptr), start);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    else {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        nbytes = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    log_ptr += nbytes;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    start = false;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (nbytes == 0) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        // File transfer finished. 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        start = true;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        // Clear file transfer in progress flag 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        fLogTransInprog = false;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    SSL_SendFrames(&ssl, logFileBuf, nbytes);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    HTTP_SendHistory();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+}
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+/**
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  * @brief Sent callback for log file transfer (messages as is, not ordered)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  */
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+void HTTP_SendLog(void)
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+{
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    uint32_t nbytes = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    static bool start = true;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	memset(logFileBuf, 0, FILE_BUF_MAX_LEN);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (log_ptr + FILE_BUF_MAX_LEN_LOG <= log_size) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        nbytes = LOG_GetData(log_ptr, logFileBuf, FILE_BUF_MAX_LEN_LOG, start);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    else if (log_ptr < log_size) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        nbytes = LOG_GetData(log_ptr, logFileBuf, (log_size - log_ptr), start);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    else {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        nbytes = 0;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    log_ptr += nbytes;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    start = false;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    if (nbytes == 0) {
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        // File transfer finished. 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        start = true;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        // Clear file transfer in progress flag 
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        fLogTransInprog = false;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        return;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    }
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    SSL_SendFrames(&ssl, logFileBuf, nbytes);
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    HTTP_SendLog();
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    return;
 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+} 
														 |