Jelajahi Sumber

2022-12-12/Jerry Wang
[OCPP 1.6] confVersion 23->24
Action:
1. Add logic of packaging Dispenser log file in GetDiagnostics function.
2. Increase buffer length for UpdateFirmware related functions.
3. Add logic of authorizing the certificate of download link with protocol 'https' or 'ftps' for UpdateFirmware function.
4. Add new Configuration Key 'AuthDownloadlinkCertificate'.

File:
1. EVSE/Modularization/ocppfiles/MessageHandler.c
--> Action 1-4
2. EVSE/Modularization/ocppfiles/MessageHandler.h
--> Action 4
3. EVSE/Projects/define.h
--> Action 4

Jerry Wang 2 tahun lalu
induk
melakukan
a5276b08c5

+ 110 - 25
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -12585,6 +12585,7 @@ void* GetDiagnosticsProcess(void* data)
 		sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
+		sprintf(cmdBuf, "%s /Storage/Dispenser*Log.zip", cmdBuf);
 		system(cmdBuf);
 
 		// Pack charging & event log
@@ -12766,6 +12767,7 @@ void* GetDiagnosticsProcess(void* data)
 
 end:
 	system("rm -f /mnt/*");
+	system("rm -f /Storage/Dispenser*Log.zip");
 	sleep(5);
 	sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
 	ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
@@ -15473,13 +15475,14 @@ void *UpdateFirmwareProcess(void *data)
 	pthread_detach(pthread_self());
 	mtrace();
 	int retriesInt =0, retryIntervalInt=0;
-	char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
+	char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
 	int port=0;
-	char locationstr[1024]={0}, retrieveDatestr[36]={0};
+	char locationstr[2048]={0}, retrieveDatestr[36]={0};
 	int isSuccess = 0;
-	char ftpbuf[1024];
-	char temp[1024];
+	char ftpbuf[2048];
+	char temp[2048];
 	char * pch;
+	char filenametemp[256];
 
 	json_object *UpdateFirmware;
 	UpdateFirmware = json_tokener_parse(data);
@@ -15532,7 +15535,7 @@ void *UpdateFirmwareProcess(void *data)
 
 		int ftppathlen=strlen(ftppath);
 		int i=1;
-		char filenametemp[50];
+
 		while(i < ftppathlen)
 		{
 		   int len=ftppathlen-i;
@@ -15581,7 +15584,7 @@ void *UpdateFirmwareProcess(void *data)
 		strcpy(ftpbuf, locationstr);
 		int ftppathlen=strlen(ftpbuf);
 		int i=1;
-		char filenametemp[50];
+
 		while(i < ftppathlen)
 		{
 			int len=ftppathlen-i;
@@ -15647,7 +15650,7 @@ void *UpdateFirmwareProcess(void *data)
 			retriesInt--;
 		}while((!isSuccess)&&(retriesInt >= 0));
 	}
-    else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
+    else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
 	{
     	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
     	memset(temp, 0, ARRAY_SIZE(temp));
@@ -15655,7 +15658,7 @@ void *UpdateFirmwareProcess(void *data)
     	strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
     	int ftppathlen=strlen(ftpbuf);
     	int i=1;
-    	char filenametemp[50];
+
     	while(i < ftppathlen)
     	{
     		int len=ftppathlen-i;
@@ -16251,6 +16254,7 @@ void* GetLogProcess(void* data)
 
 		sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
+		sprintf(cmdBuf, "%s /Storage/Dispenser*Log.zip", cmdBuf);
 		system(cmdBuf);
 
 		// Pack charging & event log
@@ -16440,6 +16444,7 @@ void* GetLogProcess(void* data)
 
 end:
 	system("rm -f /mnt/*");
+	system("rm -f /Storage/Dispenser*Log.zip");
 	sleep(5);
 	ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
 	sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
@@ -16666,13 +16671,13 @@ void *SignedUpdateFirmwareProcess(void *data)
 {
 	pthread_detach(pthread_self());
 	mtrace();
-	char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
+	char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
 	int port=0;
 	int isSuccess = 0;
-	char ftpbuf[1024];
-	char temp[1024];
+	char ftpbuf[2048];
+	char temp[2048];
 	char * pch;
-	char firmwareFileName[50];
+	char firmwareFileName[256];
 
 	DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
 
@@ -17517,7 +17522,7 @@ int initialConfigurationTable(void)
 	FILE *fp;
 	FILE *outfile;
 	char str[512]={0};
-	int	confVersion = 23;
+	int	confVersion = 24;
 
 	DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
 	//start_t = clock();
@@ -18003,6 +18008,13 @@ int initialConfigurationTable(void)
 
 		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
 
+		// Check certificate of download link
+		ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
+		strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
+		sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "FALSE");
+
+		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
+
 		//* Local Auth List Management Profile*/
 		#if 0
 			//For OCTT Test Case
@@ -18479,6 +18491,12 @@ int initialConfigurationTable(void)
 					sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
 				}
 
+				if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
+				{
+					ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
+					sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
+				}
+
 				if(strcmp(keystr, "LocalAuthListEnabled") == 0)
 				{
 					ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
@@ -19123,6 +19141,16 @@ void StoreConfigurationTable(void)
 
 	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
 
+
+	// AuthDownloadlinkCertificate
+	/*
+	ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
+	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
+	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE" );
+	*/
+
+	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
+
 	//* Local Auth List Management Profile*/
 	//LocalAuthListEnabled
 	/*
@@ -20300,6 +20328,25 @@ void getKeyValue(char *keyReq)
 			  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
 			  isKnowKey = TRUE;
 		  }
+
+		  if(isEmpty ||  strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
+		  {
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
+
+			  if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
+			  {
+				  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
+			  }
+			  else
+			  {
+				  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
+			  }
+
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
+			  isKnowKey = TRUE;
+		  }
+
 #if 1
 	      if(isEmpty ||  strcmp(keyReq, "LocalAuthListEnabled") == 0 )
 	      {
@@ -21710,6 +21757,34 @@ int setKeyValue(char *key, char *value)
 		}
 	}
 
+	if(strcmp(key, "OcppSoftwareVersion") == 0)
+	{
+		if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
+		{
+			strcpy(str, (const char*)value);
+			sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
+			isSuccess = ConfigurationStatus_Accepted;
+		}
+		else
+		{
+			isSuccess = ConfigurationStatus_Rejected;
+		}
+	}
+
+	if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
+	{
+		if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
+		{
+			strcpy(str, (const char*)value);
+			sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", str );
+			isSuccess = ConfigurationStatus_Accepted;
+		}
+		else
+		{
+			isSuccess = ConfigurationStatus_Rejected;
+		}
+	}
+
 #if 0
     //For OCPP Test Case
     if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
@@ -22002,9 +22077,9 @@ int ParseHeader(int sock)
 int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 {
 	int result = TRUE;
-	char rmFileCmd[100]={0};
-    char FilePath[100]={0};
-	char ftpbuf[200];
+	char rmFileCmd[300]={0};
+    char FilePath[256]={0};
+	char ftpbuf[2048];
 	int systemresult;
 
 	sprintf(FilePath,"/mnt/%s",filename);
@@ -22017,7 +22092,10 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 		system(rmFileCmd);
 	}
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
-	sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
+	if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
+		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
+	else
+		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
 	DEBUG_INFO("Download command: %s\n",ftpbuf);
 
 	systemresult = system(ftpbuf);
@@ -22034,9 +22112,9 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
 {
 	int result = TRUE;
-	char rmFileCmd[100]={0};
-	char FilePath[100]={0};
-	char ftpbuf[200];
+	char rmFileCmd[300]={0};
+	char FilePath[256]={0};
+	char ftpbuf[2048];
 	int systemresult;
 
 	sprintf(FilePath,"/mnt/%s",filename);
@@ -22067,9 +22145,9 @@ int sftpDownLoadFile(char *location, char *user, int port, char *path, char *fil
 int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
 {
 	int result = TRUE;
-	char rmFileCmd[100]={0};
-	char FilePath[100]={0};
-	char ftpbuf[200];
+	char rmFileCmd[300]={0};
+	char FilePath[256]={0};
+	char ftpbuf[2048];
 	int systemresult;
 
 	sprintf(FilePath,"/mnt/%s",filename);
@@ -22083,14 +22161,21 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 	}
 
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
+	if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
+		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
+	else
+		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
 
-	sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
 	DEBUG_INFO("Download command: %s\n",ftpbuf);
 
 	systemresult = system(ftpbuf);
 	if(systemresult != 0)
 	{
-		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
+		if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
+			sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
+		else
+			sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
+
 		DEBUG_INFO("Download command: %s\n",ftpbuf);
 
 		systemresult = system(ftpbuf);

+ 1 - 0
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -420,6 +420,7 @@ enum GetConfigurationKey {
 	GetConfiguration_CharingProfileRefreshInterval,
 	GetConfiguration_CpoName,
 	GetConfiguration_OcppSoftwareVersion,
+	GetConfiguration_AuthDownloadlinkCertificate,
 	_GetConfiguration_CNT
 };
 

+ 4 - 3
EVSE/Projects/define.h

@@ -347,6 +347,7 @@ enum CoreProfile {
 	 CharingProfileRefreshInterval,
 	 CpoName,
 	 OcppSoftwareVersion,
+	 AuthDownloadlinkCertificate,
 	 _CoreProfile_CNT
 };
 
@@ -612,9 +613,9 @@ struct SysConfigData
     unsigned int            PowerSharingCapacityPower;          // Local power sharing capacity power
     unsigned char           MaxChargingSoc;                     // 0: unlimit, 1 ~ 100 percent
     unsigned char			FanControlPolicy;					// 0: Auto mode		1: Quite mode
-	unsigned short			MaxChargingVoltage;					// 0: rating value, 1 ~ RATING_VOLTAGE	volt
-	unsigned char			isEnalbleFirewall;					// 0: Disable	1: Enable
-	unsigned char			FirewallAcceptAddr[10][128];		// Max accepted server address is 10
+    unsigned short			MaxChargingVoltage;					// 0: rating value, 1 ~ RATING_VOLTAGE	volt
+    unsigned char			isEnalbleFirewall;					// 0: Disable	1: Enable
+    unsigned char			FirewallAcceptAddr[10][128];		// Max accepted server address is 10
 };
 
 struct DERATING_BY_OTP