Ver Fonte

2022-09-15/Jerry Wang
[OCPP 1.6]
Action:
1. Improve PnC Authorize function.
2. Improve DataTransfer hashmap logic.

File:
1. EVSE/Modularization/ocppfiles/MessageHandler.c
--> Action 1-2

Jerry Wang há 2 anos atrás
pai
commit
98a9415ce8
1 ficheiros alterados com 34 adições e 15 exclusões
  1. 34 15
      EVSE/Modularization/ocppfiles/MessageHandler.c

+ 34 - 15
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -58,7 +58,7 @@ static int authorizeRetryTimes 		= 0;  //number of  Retry times
 // OCPP other variables
 //===============================
 static int HeartBeatWaitTime 						= 10;
-static int FirstHeartBeat 							= 0;
+static int FirstHeartBeat 							= FALSE;
 static int FirmwareStatusNotificationStatus 		= FIRMWARE_STATUS_IDLE;  // Idle
 static int DiagnosticsStatusNotificationStatus 		= DIAGNOSTIC_STATUS_IDLE; // Idle
 static char CurrentChargingProfileScheduleStr[30]	= {0};
@@ -1454,7 +1454,7 @@ void reportReaderStatus(int gun_index)
 	json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
 	json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
 
-	sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
+	sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
 	json_object_put(dataBuf);
 
 	ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
@@ -1624,6 +1624,7 @@ int syncDateTimeRTC(uint8_t *data)
 int parseCertInfo(char *certPath, int parseType, char *data)
 {
 	int result = FAIL;
+	memset(data, 0, ARRAY_SIZE(data));
 	if(access(certPath,F_OK) != -1)
 	{
 		char temp[512] = {0};
@@ -1655,13 +1656,12 @@ int parseCertInfo(char *certPath, int parseType, char *data)
 					break;
 				}
 			}
-			sprintf((char*)data, hashType);
 		}
 
 		switch(parseType)
 		{
 		case CERT_PARSE_HashAlgorithm:
-			// Already parsed
+			sprintf((char*)data, hashType);
 			DEBUG_INFO("hashAlgorithm: %s\n", hashType);
 			break;
 
@@ -1725,15 +1725,19 @@ int parseCertInfo(char *certPath, int parseType, char *data)
 			break;
 
 		case CERT_PARSE_OcspUrl:
-			sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
+			//sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
+			sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
 			fp = popen(temp, "r");
 			if(fp)
 			{
 				while(fgets(temp, sizeof(temp), fp) != NULL)
 				{
-					if(strstr(temp, "://") != NULL)
+					if(strstr(temp, "OCSP - URI:") != NULL)
 					{
-						strcpy((char*)data, temp);
+						//strcpy((char*)data, temp);
+						sscanf(temp, "%*[^:]:%s", capturedData);
+						sprintf((char*)data, capturedData);
+						DEBUG_INFO("OCSP_URI: %s\n", data);
 						result = PASS;
 						break;
 					}
@@ -5893,10 +5897,27 @@ void CheckSystemValue(void)
 			json_object *idToken = json_object_new_object();
 			json_object *iso15118CertificateHashData = json_object_new_array();
 
+			// Read CERTIFICATE_PnCAuth file content
+			if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
+			{
+				memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
+				FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
+				char *line = NULL;
+				size_t len = 0;
+
+				while(getline(&line, &len, fp) != -1)
+				{
+					//memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
+
+					strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
+				}
+				fclose(fp);
+			}
+
 			if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
 				json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
 
-			strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
+			//strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
 			json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
 			json_object_object_add(data, "idToken", idToken);
 
@@ -5913,12 +5934,12 @@ void CheckSystemValue(void)
 			if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
 				sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
 
-			if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS)
+			if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
 				strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
 
 			for(int idx=0; idx < 4; idx++)
 			{
-				if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL) >= 7)
+				if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
 				{
 					json_object *OCSPRequestDataType = json_object_new_object();
 					json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
@@ -6163,7 +6184,7 @@ int sendDataTransferRequest(int gun_index)
 	json_object_put(DataTransfer);
 
 	LWS_Send(message);
-	sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
+	sprintf(tempdata, "DataTransfer,%d", gun_index);
 	if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
 	{
 		result = PASS;
@@ -6233,7 +6254,7 @@ int sendOcmfByDataTransferRequest(int gun_index)
 
 	json_object_put(DataTransfer);
 
-	sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
+	sprintf(tempdata, "DataTransfer,%d", gun_index );
 	if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
 	{
 		result = PASS;
@@ -17274,7 +17295,7 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 void handleDataTransferResponse(char *payload, int gun_index)
 {
 	json_object *DataTransfer = json_tokener_parse(payload);
-
+	DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
 	if(!is_error(DataTransfer))
 	{
 		// Required data
@@ -17304,7 +17325,6 @@ void handleDataTransferResponse(char *payload, int gun_index)
 							sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "certificateStatus"), "cacheExpiryDateTime")));
 						}
 					}
-
 					ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
 				}
 				else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
@@ -17491,7 +17511,6 @@ void handleStatusNotificationResponse(char *payload, int gun_index)
 	//cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
 	//cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
 	cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
-
 }
 
 void handleStopTransactionnResponse(char *payload, int gun_index)