Jelajahi Sumber

[New feature][Modularization][Module_OcppBackend]

2020.09.07 / Folus Wen

Actions:
1. EVSE/Projects/define.h add AuthorizationKey and SecurityProfile to enum CoreProfile.
2. EVSE/Modularization/Module_Upgrade.c add nand utils result to log file.
3. EVSE/Modularization/ocppfiles/Module_OcppBackend.c implement handshake security profile 0~2 logic.
4. EVSE/Modularization/ocppfiles/MessageHandler.c add AuthorizationKey and SecurityProfile key to changeConfiguration/getConfiguration function logic.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 4 tahun lalu
induk
melakukan
cdac5aa5d2

+ 54 - 24
EVSE/Modularization/Module_Upgrade.c

@@ -14,6 +14,8 @@
 #define DEBUG_WARN(format, args...) storeLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define DEBUG_ERROR(format, args...) storeLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
+#define SystemLogMessage
+//#define ConsloePrintLog
 #define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
 #define PASS                1
 #define FAIL                -1
@@ -41,11 +43,14 @@ int storeLogMsg(const char *fmt, ...)
             tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
             buffer,
             tm->tm_year+1900,tm->tm_mon+1);
+
 #ifdef SystemLogMessage
     system(Buf);
 #endif
 
+#ifdef ConsloePrintLog
     printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
 
     return rc;
 }
@@ -90,6 +95,27 @@ uint32_t crc32(uint8_t *data, unsigned int length)
     return ~crc;
 }
 
+int runShellCmd(const char*cmd)
+{
+	int result = FAIL;
+	char buf[256];
+	FILE *fp;
+
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			DEBUG_INFO("%s\n", buf);
+		}
+
+		result = PASS;
+	}
+	pclose(fp);
+
+	return result;
+}
+
 int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
 {
     int result = FAIL;
@@ -100,7 +126,6 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
     int wrd,fd;
 
     // space max size set
-
     switch(Type)
     {
         case CSU_BOOTLOADER:
@@ -196,9 +221,10 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 else
                                 {
                                 	DEBUG_INFO("Erase /dev/mtd0.\n");
-									system("flash_erase /dev/mtd0 0 1");
-									DEBUG_INFO("Write /dev/mtd0.\n");
-									system("nandwrite -p /dev/mtd0 /mnt/imgBuffer");
+                                	runShellCmd("flash_erase /dev/mtd0 0 1");
+
+                                	DEBUG_INFO("Write /dev/mtd0.\n");
+                                	runShellCmd("nandwrite -p /dev/mtd0 /mnt/imgBuffer");
 
 									system("rm -f /mnt/imgBuffer");
 									result = PASS;
@@ -226,14 +252,16 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 else
                                 {
                                 	DEBUG_INFO("Erase /dev/mtd1.\n");
-									system("flash_erase /dev/mtd1 0 2");
+                                	runShellCmd("flash_erase /dev/mtd1 0 2");
+
 									DEBUG_INFO("Write /dev/mtd1.\n");
-									system("nandwrite -p /dev/mtd1 /mnt/imgBuffer");
+									runShellCmd("nandwrite -p /dev/mtd1 /mnt/imgBuffer");
 
 									DEBUG_INFO("Erase /dev/mtd3.\n");
-									system("flash_erase /dev/mtd3 0 2");
+									runShellCmd("flash_erase /dev/mtd3 0 2");
+
 									DEBUG_INFO("Write /dev/mtd3.\n");
-									system("nandwrite -p /dev/mtd3 /mnt/imgBuffer");
+									runShellCmd("nandwrite -p /dev/mtd3 /mnt/imgBuffer");
 
 									system("rm -f /mnt/imgBuffer");
 									result = PASS;
@@ -261,14 +289,16 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 else
                                 {
                                     DEBUG_INFO("Erase /dev/mtd4.\n");
-									system("flash_erase /dev/mtd4 0 1");
+                                    runShellCmd("flash_erase /dev/mtd4 0 1");
+
 									DEBUG_INFO("Write /dev/mtd4.\n");
-									system("nandwrite -p /dev/mtd4 /mnt/imgBuffer");
+									runShellCmd("nandwrite -p /dev/mtd4 /mnt/imgBuffer");
 
 									DEBUG_INFO("Erase /dev/mtd5.\n");
-									system("flash_erase /dev/mtd5 0 1");
+									runShellCmd("flash_erase /dev/mtd5 0 1");
+
 									DEBUG_INFO("Write /dev/mtd5.\n");
-									system("nandwrite -p /dev/mtd5 /mnt/imgBuffer");
+									runShellCmd("nandwrite -p /dev/mtd5 /mnt/imgBuffer");
 
 									system("rm -f /mnt/imgBuffer");
 									result = PASS;
@@ -296,14 +326,14 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 else
                                 {
                                 	DEBUG_INFO("Erase /dev/mtd6.\n");
-									system("flash_erase /dev/mtd6 0 20");
+                                	runShellCmd("flash_erase /dev/mtd6 0 20");
 									DEBUG_INFO("Write /dev/mtd6.\n");
-									system("nandwrite -p /dev/mtd6 /mnt/imgBuffer");
+									runShellCmd("nandwrite -p /dev/mtd6 /mnt/imgBuffer");
 
 									DEBUG_INFO("Erase /dev/mtd7.\n");
-									system("flash_erase /dev/mtd7 0 20");
+									runShellCmd("flash_erase /dev/mtd7 0 20");
 									DEBUG_INFO("Write /dev/mtd7.\n");
-									system("nandwrite -p /dev/mtd7 /mnt/imgBuffer");
+									runShellCmd("nandwrite -p /dev/mtd7 /mnt/imgBuffer");
 
 									system("rm -f /mnt/imgBuffer");
 									result = PASS;
@@ -330,14 +360,14 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 else
                                 {
                                 	DEBUG_INFO("Erase /dev/mtd8.\n");
-                                	system("flash_erase /dev/mtd8 0 96");
+                                	runShellCmd("flash_erase /dev/mtd8 0 96");
                                 	DEBUG_INFO("Write /dev/mtd8.\n");
-                                	system("nandwrite -p /dev/mtd8 /mnt/imgBuffer");
+                                	runShellCmd("nandwrite -p /dev/mtd8 /mnt/imgBuffer");
 
                                 	DEBUG_INFO("Erase /dev/mtd9.\n");
-                                	system("flash_erase /dev/mtd9 0 96");
+                                	runShellCmd("flash_erase /dev/mtd9 0 96");
                                 	DEBUG_INFO("Write /dev/mtd9.\n");
-                                	system("nandwrite -p /dev/mtd9 /mnt/imgBuffer");
+                                	runShellCmd("nandwrite -p /dev/mtd9 /mnt/imgBuffer");
 
                                 	system("rm -f /mnt/imgBuffer");
                                     result = PASS;
@@ -365,14 +395,14 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 else
                                 {
                                 	DEBUG_INFO("Erase /dev/mtd10.\n");
-									system("flash_erase /dev/mtd10 0 12");
+                                	runShellCmd("flash_erase /dev/mtd10 0 12");
 									DEBUG_INFO("Write /dev/mtd10.\n");
-									system("nandwrite -p /dev/mtd10 /mnt/imgBuffer");
+									runShellCmd("nandwrite -p /dev/mtd10 /mnt/imgBuffer");
 
 									DEBUG_INFO("Erase /dev/mtd11.\n");
-									system("flash_erase /dev/mtd11 0 12");
+									runShellCmd("flash_erase /dev/mtd11 0 12");
 									DEBUG_INFO("Write /dev/mtd11.\n");
-									system("nandwrite -p /dev/mtd11 /mnt/imgBuffer");
+									runShellCmd("nandwrite -p /dev/mtd11 /mnt/imgBuffer");
 
 									system("rm -f /mnt/imgBuffer");
 									result = PASS;

+ 147 - 9
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -26,7 +26,7 @@ struct PsuData 						*ShmPsuData ;
 struct OCPP16Data 					*ShmOCPP16Data;
 
 //ConfigurationMaxKeys
-#define GetConfigurationMaxKeysNUM 	44
+#define GetConfigurationMaxKeysNUM 	_GetConfiguration_CNT
 
 pthread_mutex_t lock_send 			= PTHREAD_MUTEX_INITIALIZER;
 char queuedata[QUEUE_MESSAGE_LENGTH]				= {0};
@@ -6526,23 +6526,21 @@ int handleChangeConfigurationRequest(char *uuid, char *payload)
     			sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
     			ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
     			StoreConfigurationTable();
-    		break;
-
-    		case ConfigurationStatus_Rejected:
-    			sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
-    		break;
+    			break;
 
     		case RebootRequired:
     			sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
     			StoreConfigurationTable();
-    		break;
+    			break;
 
     		case NotSupported:
     			sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
     			break;
 
+    		case ConfigurationStatus_Rejected:
     		default:
-    		break;
+    			sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
+    			break;
     	}
     }
 
@@ -6553,6 +6551,11 @@ int handleChangeConfigurationRequest(char *uuid, char *payload)
 		ChageWebSocketPingInterval(atoi(valuestr));
 	}
 
+	if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
+	{
+		ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
+	}
+
 	return result;
 }
 
@@ -11640,6 +11643,19 @@ int initialConfigurationTable(void)
 
 		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
 
+		// AuthorizationKey
+		ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
+		strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
+		strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
+
+		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
+
+		// SecurityProfile
+		ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
+		strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
+		strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
+
+		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
 
 		//* Local Auth List Management Profile*/
 		#if 0
@@ -11998,6 +12014,18 @@ int initialConfigurationTable(void)
 				 sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
 			}
 
+			if(strcmp(keystr, "AuthorizationKey") == 0)
+			{
+				ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
+				sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
+			}
+
+			if(strcmp(keystr, "SecurityProfile") == 0)
+			{
+				ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
+				sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
+			}
+
 			if(strcmp(keystr, "LocalAuthListEnabled") == 0)
 			{
 				ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
@@ -12399,6 +12427,23 @@ void StoreConfigurationTable(void)
 
 	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
 
+	// AuthorizationKey
+	/*
+	ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
+	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
+	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
+	*/
+
+	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
+
+	// SecurityProfile
+	/*
+	ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
+	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
+	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
+	*/
+
+	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
 
 	//* Local Auth List Management Profile*/
 	//LocalAuthListEnabled
@@ -13134,7 +13179,42 @@ void getKeyValue(char *keyReq)
 			  isKnowKey = TRUE;
 		  }
 
+	      /*
+	      if(isEmpty ||  strcmp(keyReq, "AuthorizationKey") == 0 )
+		  {
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
+
+			  if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
+			  {
+				  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
+			  }
+			  else
+			  {
+				  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
+			  }
+
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
+			  isKnowKey = TRUE;
+		  }*/
+
+	      if(isEmpty ||  strcmp(keyReq, "SecurityProfile") == 0 )
+		  {
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
 
+			  if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
+			  {
+				  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
+			  }
+			  else
+			  {
+				  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
+			  }
+
+			  strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
+			  isKnowKey = TRUE;
+		  }
 #if 1
 	      if(isEmpty ||  strcmp(keyReq, "LocalAuthListEnabled") == 0 )
 	      {
@@ -14092,7 +14172,6 @@ int setKeyValue(char *key, char *value)
     		}
     		else
     		{
-
         		sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
         		isSuccess = ConfigurationStatus_Accepted;
     		}
@@ -14123,6 +14202,50 @@ int setKeyValue(char *key, char *value)
 
     }
 
+    if(strcmp(key, "AuthorizationKey") == 0)
+    {
+    	if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
+    	{
+    		strcpy(str, (const char*)value);
+    		sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
+    		isSuccess = ConfigurationStatus_Accepted;
+    	}
+    	else
+    	{
+    	    isSuccess = ConfigurationStatus_Rejected;
+    	}
+    }
+
+    if(strcmp(key, "SecurityProfile") == 0)
+    {
+    	if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
+    	{
+    		check_ascii = value[0];
+    		if( (check_ascii < 0x30) || (check_ascii > 0x33) )
+    		{
+    			isSuccess = ConfigurationStatus_Rejected;
+    		}
+    		else if(check_ascii == 0x33)
+    		{
+    			isSuccess = NotSupported;
+    		}
+    		else
+    		{
+    			if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
+    			{
+    				sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
+    				isSuccess = ConfigurationStatus_Accepted;
+    			}
+    			else
+    				isSuccess = ConfigurationStatus_Rejected;
+    		}
+    	}
+    	else
+    	{
+    	    isSuccess = ConfigurationStatus_Rejected;
+    	}
+    }
+
 #if 0
     //For OCPP Test Case
     if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
@@ -16061,6 +16184,21 @@ int GetServerSign(void)
 	return server_sign;
 }
 
+uint8_t GetOcppSecurityProfile()
+{
+	return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
+}
+
+void GetOcppChargerBoxId(uint8_t *data)
+{
+	sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
+}
+
+void GetOcppSecurityPassword(uint8_t *data)
+{
+	sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
+}
+
 void SetServerSign(int value)
 {
 	server_sign = value;

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

@@ -320,6 +320,7 @@ typedef enum {
 
 }  UnitOfMeasure;
 
+/*Configuration enum*/
 enum LocalAuthListManagementProfile{
 	LocalAuthListEnabled=0,
 	LocalAuthListMaxLength,
@@ -386,6 +387,8 @@ enum GetConfigurationKey {
 	GetConfiguration_UnlockConnectorOnEVSideDisconnect,
 	GetConfiguration_WebSocketPingInterval,
 	GetConfiguration_QueueOffLineStartTransactionMessage,
+	GetConfiguration_AuthorizationKey,
+	GetConfiguration_SecurityProfile,
 	GetConfiguration_LocalAuthListEnabled,
 	GetConfiguration_LocalAuthListMaxLength,
 	GetConfiguration_SendLocalListMaxLength,
@@ -395,6 +398,7 @@ enum GetConfigurationKey {
 	GetConfiguration_ChargingScheduleMaxPeriods,
 	GetConfiguration_ConnectorSwitch3to1PhaseSupported,
 	GetConfiguration_MaxChargingProfilesInstalled,
+	_GetConfiguration_CNT
 };
 
 enum FIRMWARE_NOTIFICATION_STATUS

+ 60 - 28
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -135,6 +135,12 @@ int SendData(struct lws *wsi)
 
 static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
 {
+	char 	buf[256]={0}, hash[20]={0}, key_b64[40]={0}, tempin[65536]={0}, sstr[65536]={0};
+	uint8_t auth_b64[256]={0}, boxId[128]={0}, password[64]={0};
+	int 	c = 0;
+	char 	*loc;
+
+
 	switch (reason)
 	{
 		case LWS_CALLBACK_PROTOCOL_INIT:
@@ -143,25 +149,25 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			break;
 		case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH:
 			DEBUG_INFO("LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH\n");
-
-			char buf[64];
-			char hash[20], key_b64[40];
-
-			lws_b64_encode_string(hash, 16, key_b64, ARRAY_SIZE(key_b64));// Sec-WebSocket-Key
-
 			DEBUG_OCPPMESSAGE_INFO("----- Handshake: Client Request START -----\n");
+
 			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, _WSI_TOKEN_CLIENT_URI);
 			DEBUG_OCPPMESSAGE_INFO("GET %s  HTTP/1.1 \n", buf);
 
 			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, _WSI_TOKEN_CLIENT_HOST);
 			DEBUG_OCPPMESSAGE_INFO("Host: %s\n", buf);
+
 			DEBUG_OCPPMESSAGE_INFO("Upgrade: websocket\n");
 			DEBUG_OCPPMESSAGE_INFO("Connection: Upgrade\n");
+
+			lws_b64_encode_string(hash, 16, key_b64, ARRAY_SIZE(key_b64));// Sec-WebSocket-Key
 			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Key: %s\n", key_b64);
 
 			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS);
 			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Protocol: %s\n", buf);
+
 			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Version: %d\n", SPEC_LATEST_SUPPORTED);
+
 			DEBUG_OCPPMESSAGE_INFO("----- Handshake: Client Request END -----\n");
 
 			DEBUG_OCPPMESSAGE_INFO("----- Handshake: Server response START -----\n");
@@ -210,6 +216,33 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			break;
 		case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
 			DEBUG_INFO("LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER\n");
+
+			unsigned char** pos = (unsigned char**)in;
+			unsigned char* end = (*pos) + len;
+
+			switch(GetOcppSecurityProfile())
+			{
+				case 1:
+				case 2:
+				case 3:
+					GetOcppChargerBoxId(boxId);
+					GetOcppSecurityPassword(password);
+					sprintf(buf, "%s:%s", boxId, password);
+					lws_b64_encode_string(buf, strlen(buf), (char*)auth_b64, ARRAY_SIZE(auth_b64));
+					sprintf(buf, "Basic %s", auth_b64);
+					if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_AUTHORIZATION, (uint8_t *)buf, strlen(buf), pos, end))
+					{
+						DEBUG_ERROR("lws_add_http_header_by_token : WSI_TOKEN_HTTP_AUTHORIZATION\n");
+						return -1;
+					}
+					DEBUG_OCPPMESSAGE_INFO("Authorization: %s\n", buf);
+
+					break;
+				case 0:
+				default:
+					break;
+			}
+
 			break;
 		case LWS_CALLBACK_CLIENT_ESTABLISHED: //3
 			DEBUG_INFO("LWS_CALLBACK_CLIENT_ESTABLISHED\n");
@@ -239,35 +272,40 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			//disconnected
 			ConnectionEstablished=0;
 
-			char buf1[64];
-			char hash1[20]={0}, key_b641[40]={0};
-
-			lws_b64_encode_string(hash1, 16, key_b641, ARRAY_SIZE(key_b641));// Sec-WebSocket-Key
-
 			DEBUG_OCPPMESSAGE_INFO("===== Handshake: Client  START =====\n");
 			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, _WSI_TOKEN_CLIENT_URI);
 			DEBUG_OCPPMESSAGE_INFO("GET %s  HTTP/1.1 \n", buf);
+
 			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, _WSI_TOKEN_CLIENT_HOST);
 			DEBUG_OCPPMESSAGE_INFO("Host: %s\n", buf);
+
 			DEBUG_OCPPMESSAGE_INFO("Upgrade: websocket\n");
 			DEBUG_OCPPMESSAGE_INFO("Connection: Upgrade\n");
-			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Key: %s\n", key_b641);
+
+			lws_b64_encode_string(hash, 16, key_b64, ARRAY_SIZE(key_b64));// Sec-WebSocket-Key
+			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Key: %s\n", key_b64);
+
 			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS);
 			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Protocol: %s\n", buf);
+
 			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Version: %d\n", SPEC_LATEST_SUPPORTED);
 			DEBUG_OCPPMESSAGE_INFO("===== Handshake: Client  END =====\n");
 
 			DEBUG_OCPPMESSAGE_INFO("===== Handshake: Server response START =====\n");
-			lws_hdr_copy(wsi, buf1, ARRAY_SIZE(buf1) - 1, WSI_TOKEN_HTTP);
-			DEBUG_OCPPMESSAGE_INFO("HTTP/1.1 %s\n", buf1);
-			lws_hdr_copy(wsi, buf1, ARRAY_SIZE(buf1) - 1, WSI_TOKEN_UPGRADE);
-			DEBUG_OCPPMESSAGE_INFO("Upgrade: %s\n", buf1);
-			lws_hdr_copy(wsi, buf1, ARRAY_SIZE(buf1) - 1, WSI_TOKEN_CONNECTION);
-			DEBUG_OCPPMESSAGE_INFO("Connection: %s\n", buf1);
-			lws_hdr_copy(wsi, buf1, ARRAY_SIZE(buf1) - 1, WSI_TOKEN_ACCEPT);
-			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Accept: %s\n", buf1);
-			lws_hdr_copy(wsi, buf1, ARRAY_SIZE(buf1) - 1, WSI_TOKEN_PROTOCOL);
-			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Protocol: %s\n", buf1);
+			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, WSI_TOKEN_HTTP);
+			DEBUG_OCPPMESSAGE_INFO("HTTP/1.1 %s\n", buf);
+
+			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, WSI_TOKEN_UPGRADE);
+			DEBUG_OCPPMESSAGE_INFO("Upgrade: %s\n", buf);
+
+			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, WSI_TOKEN_CONNECTION);
+			DEBUG_OCPPMESSAGE_INFO("Connection: %s\n", buf);
+
+			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, WSI_TOKEN_ACCEPT);
+			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Accept: %s\n", buf);
+
+			lws_hdr_copy(wsi, buf, ARRAY_SIZE(buf) - 1, WSI_TOKEN_PROTOCOL);
+			DEBUG_OCPPMESSAGE_INFO("Sec-WebSocket-Protocol: %s\n", buf);
 			DEBUG_OCPPMESSAGE_INFO("===== Handshake: Server response END =====\n");
 
 			break;
@@ -286,12 +324,6 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			((char *)in)[len] = '\0';
 			DEBUG_OCPPMESSAGE_INFO("<===== %s\n", (char *)in);
 
-			char tempin[65536]={0};
-
-			int c = 0;
-			char *loc;
-			char sstr[65536]={0};
-
 		 	//**********Receive Message**********/
 		  	c = 0;
 		  	loc = strstr((const char *)in, "][2,");

+ 3 - 1
EVSE/Modularization/ocppfiles/Module_OcppBackend.h

@@ -86,6 +86,9 @@ extern int GetOcppConnStatus(void);
 extern void SetOcppConnStatus(uint8_t status);
 extern int GetHeartBeatWithNOResponse(void);
 extern void SetHeartBeatWithNOResponse(void);
+extern uint8_t GetOcppSecurityProfile();
+extern void GetOcppChargerBoxId(uint8_t *data);
+extern void GetOcppSecurityPassword(uint8_t *data);
 
 extern int InitShareMemory();
 extern int ProcessShareMemory();
@@ -107,7 +110,6 @@ extern char* stringtrim( char * s );
 extern char* stringtrimspace( char * s );
 extern char * strtrim( char * s );
 
-
 extern struct lws 					*wsi_client;
 extern struct lws_context 			*context;
 extern unsigned char 				SendBuffer[4096];

+ 3 - 2
EVSE/Projects/define.h

@@ -260,10 +260,11 @@ enum CoreProfile {
 	 UnlockConnectorOnEVSideDisconnect,
 	 WebSocketPingInterval,
 	 QueueOffLineStartTransactionMessage,
+	 AuthorizationKey,
+	 SecurityProfile,
 	 _CoreProfile_CNT
 };
 
-
 /**************************************************************************************/
 /****structure SysConfigData => shall store the data to NAND flash****************/
 /****structure SysInfoData => shall NOT store the data to NAND flash***************/
@@ -3827,7 +3828,7 @@ struct OCPP16ConfigurationItem
 struct OCPP16ConfigurationTable
 {
 	//please refer to OCPP 1.6 chapter 9
-	struct OCPP16ConfigurationItem 			CoreProfile[35];
+	struct OCPP16ConfigurationItem 			CoreProfile[37];
 	struct OCPP16ConfigurationItem 			LocalAuthListManagementProfile[3];
 	struct OCPP16ConfigurationItem 			ReservationProfile[1];
 	struct OCPP16ConfigurationItem 			SmartChargingProfile[5];