Просмотр исходного кода

Merge branch 'new_mbed_tls' of https://192.168.14.200:3000/dtelenkov/bt-670x into new_mbed_tls

Avetisyan Karen 7 лет назад
Родитель
Сommit
339b88c718
4 измененных файлов с 36 добавлено и 10 удалено
  1. 1 1
      modules/Ethernet/snmp_api.c
  2. 28 5
      modules/HTTP_Server/http_server.c
  3. 3 0
      modules/parameters.c
  4. 4 4
      modules/settings_api.c

+ 1 - 1
modules/Ethernet/snmp_api.c

@@ -137,7 +137,7 @@ void SNMP_AgentInit(void)
   SNMP_SetSysContact(sSettings.sSnmp.sysContact);
   SNMP_SetSysName(sSettings.sSnmp.sysName);
   SNMP_SetSysLocation(sSettings.sSnmp.sysLocation);
-  SNMP_SetManagerIP("192.168.14.37");  //SNMP_SetManagerIP(sSettings.sSnmp.managerIP);
+  SNMP_SetManagerIP(sSettings.sSnmp.managerIP);  //SNMP_SetManagerIP("192.168.14.37");
   SNMP_SetObjID();
   SNMP_SetTrapOnOff(1);
   

+ 28 - 5
modules/HTTP_Server/http_server.c

@@ -48,7 +48,7 @@ static void HTTP_ForceUserLogout(uint8_t user_id);
 void LogoutTimerCallback(TimerHandle_t pxTimer);
 void LoginTimerCallback(TimerHandle_t pxTimer);
 int HTTP_ChangeUserPwd(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut);
-void send_file(char *filename, char *pnonmatch,  struct fs_file *file);
+char* send_file(char *filename, char *pnonmatch,  struct fs_file *file, uint16_t *Len);
 static uint32_t Parse_Header(char *data, uint32_t len, const char *field, uint32_t flen, char *value);
 bool GetFileName(char *inStr, char *fileName, uint8_t *fileNameLen);
 
@@ -1607,7 +1607,7 @@ void ssl_server(void *pvParameters)
    
   // 1. Load the certificates and private RSA key
   mbedtls_printf( "\r\n  . Loading the server cert. and key..." );
-  ret = mbedtls_x509_crt_parse( &srvcert, (const unsigned char *) mbedtls_test_srv_crt, mbedtls_test_srv_crt_len );
+  ret = mbedtls_x509_crt_parse( &srvcert, (const unsigned char *) sSettings.our_srv_crt, (strlen(sSettings.our_srv_crt) + 1) );//mbedtls_test_srv_crtmbedtls_test_srv_crt_len
   if( ret != 0 )
   {
     mbedtls_printf( " failed\r\n  !  mbedtls_x509_crt_parse returned %d\r\n", ret );
@@ -1988,7 +1988,7 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen)
     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);
         *sendLen = file.len;
@@ -2050,7 +2050,7 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen)
         *sendLen = file.len;
         return file.data;
     }
-    else if (strncmp(receiveBuf, "GET /getJson.cgi", 16) == 0) // +
+    else*/ if (strncmp(receiveBuf, "GET /getJson.cgi", 16) == 0) // +
     {
         HTTP_GetParamsPage1(sendBuf);
         *sendLen = strlen(sendBuf);
@@ -2361,6 +2361,25 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen)
         HTTP_Prodate(receiveBuf, sendBuf, receivedBufLen, sendLen);
         return sendBuf;
     }
+    /* Check common GET request */
+	  else if (strncmp(receiveBuf, "GET", 3) == 0) {
+		  char filename[MAX_FILENAME_LEN];
+		  char nonmatch[MAX_ETAG_LEN];
+		  char *pnonmatch = NULL;
+		  uint8_t len;
+
+		  if (GetFileName(receiveBuf, filename, &len)) {
+			  HTTP_UpdateUserLoginTime(user_id);
+
+			  /* Parce If-Non_Match value */
+			  uint8_t nonmatch_len = Parse_Header(receiveBuf, receivedBufLen, If_None_Match, 15, nonmatch);
+			  if (nonmatch_len < MAX_ETAG_LEN && nonmatch_len > 0) {
+				  DBG printf("If_None_Match: %s\r\n", nonmatch);
+				  pnonmatch = nonmatch;
+			  }
+			  return send_file(filename, pnonmatch, &file, sendLen);
+		  }
+	  }
     else
     {
         HTTP_UpdateUserLoginTime(user_id);
@@ -2507,7 +2526,7 @@ void HTTP_SendLog(void)
   * @param  file: pointer to a fs_file struct
   * @retval
   */
-void send_file(char *filename, char *pnonmatch,  struct fs_file *file)
+char* send_file(char *filename, char *pnonmatch,  struct fs_file *file, uint16_t *Len)
 {
     int res = 0;
     char etag[MAX_ETAG_LEN];
@@ -2533,6 +2552,8 @@ void send_file(char *filename, char *pnonmatch,  struct fs_file *file)
         /* Send 304 code */
         sprintf(sendBuf, HTTP_304_NOT_MODIFIED);
         DBG printf(sendBuf);
+        *Len = strlen(sendBuf);
+        return sendBuf;
         //hs->file = sendBuf;
         //hs->left = strlen(sendBuf);
     }
@@ -2541,6 +2562,8 @@ void send_file(char *filename, char *pnonmatch,  struct fs_file *file)
         //DBG printf("%s\r\n\r\n", filename);
         //hs->file = file->data;
         //hs->left = file->len;
+    	*Len = file->len;
+    	return file->data;
     }
 
     //send_data(pcb, hs);

+ 3 - 0
modules/parameters.c

@@ -21,6 +21,8 @@
 #include "megatec.h"
 #endif
 #include "sntp.h"
+#include "lwip/snmp.h"
+#include "lwip/sys.h"
 #include "common_config.h"
 #include "settings_api.h"
 //#include "d_inouts.h"
@@ -339,6 +341,7 @@ void GetWorkTimeStr(char *str, uint8_t *len)
 
   // TODO открыть с новым api для snmp
   //snmp_get_sysuptime(&tick);
+  MIB2_COPY_SYSUPTIME_TO(&tick);
 
   day = tick/8640000;
   

+ 4 - 4
modules/settings_api.c

@@ -195,8 +195,8 @@ void SETTINGS_SetRADIUSDef(void)
   //sSettings.sRADIUS.RDSEnable = false;
   // todo вернуть на значение false
   sSettings.sRADIUS.RDSEnable = false;
-  //strcpy(sSettings.sRADIUS.ServerIP, "0.0.0.0");
-  strcpy(sSettings.sRADIUS.ServerIP, "192.168.14.234");
+  strcpy(sSettings.sRADIUS.ServerIP, "0.0.0.0");
+  //strcpy(sSettings.sRADIUS.ServerIP, "192.168.14.234");
   sSettings.sRADIUS.port = 1812;
   sSettings.sRADIUS.key_access = 123;
   strcpy(sSettings.sRADIUS.rds_password, "R02ekR4MP2");
@@ -208,8 +208,8 @@ void SETTINGS_SetRADIUSDef(void)
 void SETTINGS_SetSSLcrtDef(void){
  
 	memset(sSettings.our_srv_crt, 0, sizeof(sSettings.our_srv_crt));
-	//memcpy(sSettings.our_srv_crt, (unsigned char *) test_srv_crt, strlen(test_srv_crt));
-	//memcpy(sSettings.our_srv_key, (unsigned char *) test_srv_key, strlen(test_srv_key));
+	memcpy(sSettings.our_srv_crt, (unsigned char *) mbedtls_test_srv_crt, mbedtls_test_srv_crt_len);
+	//memcpy(sSettings.our_srv_key, (unsigned char *) mbedtls_test_srv_key, mbedtls_test_srv_key_len);
   
 }