SeccComm.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*===========================================================================
  2. Combined Charging System (CCS): SECC
  3. EVComm.h
  4. initiated by Vern, Joseph
  5. (since 2019/07/19)
  6. =============================================================================*/
  7. #ifndef EVCOMM_H_
  8. #define EVCOMM_H_
  9. #if FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == ENABLE
  10. //Saving System Log
  11. #define SAVE_SYS_LOG_MSG_EVCOMM_SWITCH ENABLE //ENABLE, DISABLE
  12. //Configuration for Debug Print Messages
  13. #define DEBUG_PRINTF_EVCOMM_SHOW DISABLE //DISABLE, ENABLE
  14. #define DEBUG_PRINTF_EVCOMM_BRIEF_SHOW DISABLE //DISABLE, ENABLE
  15. #define DEBUG_PRINTF_EVCOMM_DETAIL_SHOW DISABLE //DISABLE, ENABLE
  16. #define DEBUG_PRINTF_EVCOMM_SYSTEM_LOG_SHOW DISABLE //ENABLE, DISABLE
  17. #else //debug mode
  18. //Saving System Log
  19. #define SAVE_SYS_LOG_MSG_EVCOMM_SWITCH ENABLE //ENABLE, DISABLE
  20. //Configuration for Debug Print Messages
  21. #define DEBUG_PRINTF_EVCOMM_SHOW ENABLE //DISABLE, ENABLE
  22. #define DEBUG_PRINTF_EVCOMM_BRIEF_SHOW DISABLE //DISABLE, ENABLE
  23. #define DEBUG_PRINTF_EVCOMM_DETAIL_SHOW DISABLE //DISABLE, ENABLE
  24. #define DEBUG_PRINTF_EVCOMM_SYSTEM_LOG_SHOW ENABLE //ENABLE, DISABLE
  25. #endif
  26. //ADC Channels (0, 1, 2, 3)
  27. #define ADC_CHANNEL_AIN0_NTC1 0
  28. #define ADC_CHANNEL_AIN1_NTC2 1
  29. #define ADC_CHANNEL_AIN2_PP 2
  30. #define ADC_CHANNEL_AIN3_CP 3
  31. #define QcaInterface "eth1"
  32. #define SUPPORT_BCB_TOGGLE_FUNCTION ENABLE //BCB
  33. #define SdpUdpServerPort 15118
  34. //#define SdpTcpServerPort 59438 //49152-65535 (default:59438)
  35. #define SdpTcpServerPort 50000 //49152-65535 (base: 50000)
  36. #define IPV6_LINK_LOCAL_PREFIX 0xFE80
  37. //[Joseph] These Tx/Rx buffer size should owns 8 + 4294967295 = 4,294,967,303 Bytes = 4.GB as maximum.
  38. //(according to Figure 24 in DIN 70121)
  39. #define V2GTP_MSG_RX_BUFFER_SIZE (64*1024) //65,536 = 65.5KB
  40. #define V2GTP_MSG_TX_BUFFER_SIZE (64*1024) //65,536 = 65.5KB
  41. #define V2GTP_MSG_HEADER_LENGTH 8 //8 Bytes
  42. /***********************************************/
  43. /*********** Ethernet Type ********************/
  44. /**********************************************/
  45. #define EtherType_HomePlug 0x88E1
  46. /***********************************************/
  47. /*** MMTYPE (Management Message Type) **/
  48. /**********************************************/
  49. #define MMTYPE_CM_SET_KEY_REQ 0x6008
  50. #define MMTYPE_CM_SET_KEY_CNF 0x6009
  51. #define MMTYPE_CM_AMP_MAP_REQ 0x601C
  52. #define MMTYPE_CM_AMP_MAP_CNF 0x601D
  53. #define MMTYPE_CM_SLAC_PARM_REQ 0x6064
  54. #define MMTYPE_CM_SLAC_PARM_CNF 0x6065
  55. #define MMTYPE_CM_START_ATTEN_CHAR_IND 0x606A
  56. #define MMTYPE_CM_MNBC_SOUND_IND 0x6076
  57. #define MMTYPE_CM_ATTEN_CHAR_IND 0x606E
  58. #define MMTYPE_CM_ATTEN_CHAR_RSP 0x606F
  59. #define MMTYPE_CM_VALIDATE_REQ 0x6078
  60. #define MMTYPE_CM_VALIDATE_CNF 0x6079
  61. #define MMTYPE_CM_SLAC_MATCH_REQ 0x607C
  62. #define MMTYPE_CM_SLAC_MATCH_CNF 0x607D
  63. #define MMTYPE_CM_ATTEN_PROFILE_IND 0x6086
  64. //following are the vendor specific type
  65. #define MMTYPE_VENDOR_VS_HOST_ACTION 0xA062 //Embedded Host Action Requested Indication MME
  66. #define MMTYPE_VENDOR_ATTEN_CHAR 0xA14E //Attenuation Characteristics MME (VS_ATTEN_CHAR)
  67. #define MMTYPE_VENDOR_VS_NW_INFO 0xA038 //Network Info MME
  68. #define MMTYPE_VENDOR_VS_NW_INFO_CNF 0xA039 //Network Info MME
  69. #define MMTYPE_VENDOR_VS_PL_LNK_STATUS 0xA0B8 //Powerline Link Status /*+++ 20200808, vern, for PLC connection monitoring ---*/
  70. #define MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF 0xA0B9 //Powerline Link Status /*+++ 20200808, vern, for PLC connection monitoring ---*/
  71. /***********************************************/
  72. /************** V2GTP Payload Type ************/
  73. /**********************************************/
  74. //Reference:
  75. //Table 16 ??"Overview on V2GTP payload types," page 79, DIN SPEC 70121:2014-12
  76. #define V2GTP_PAYLOAD_TYPE_SDP_REQUEST 0x9000 //SDP request message
  77. #define V2GTP_PAYLOAD_TYPE_SDP_RESPONSE 0x9001 //SDP response message
  78. #define V2GTP_PAYLOAD_TYPE_EXI_MSG 0x8001 //EXI encoded V2G Message
  79. //Payload
  80. #define SDP_PAYLOAD_SECURITY_TLS 0x00 //0x00 = secured with TLS
  81. #define SDP_PAYLOAD_SECURITY_NONE 0x10 //0x10 = No transport layer security
  82. #define SDP_PAYLOAD_TRANS_PROTOCOL_TCP 0x00 //0x00= TCP
  83. #define SDP_PAYLOAD_TRANS_PROTOCOL_UDP 0x10 //0x10 = reserved for UDP
  84. /***********************************************/
  85. /****** Timing and constant values **********/
  86. /*********** [2015] ISO 15118_3 ***************/
  87. /**********************************************/
  88. //#define TT_EVSE_match_MNBC 600 //unit: 1ms (default: 600ms)
  89. #define TT_EVSE_match_MNBC (600+400) //unit: 1ms (default: 600ms)
  90. #define C_EV_match_MNBC 0x0A
  91. #define TT_EVSE_SLAC_init 50 //unit: sec.
  92. #define TT_match_sequence 400 //unit: ms
  93. #define TP_match_response 100 //unit: ms, General performance time for a response to a request
  94. // Alston 20220723
  95. //#define TT_EVSE_RESET_STATE 3 //unit: sec.
  96. // Alston 20220723 end
  97. #ifdef DIN70122_ISO15118_VERIFICATION
  98. #define TT_match_response (200) //unit: ms, Time that the EV/EVSE shall wait for a response from the EVSE/EV
  99. #else
  100. #define TT_match_response (200) //unit: ms, Time that the EV/EVSE shall wait for a response from the EVSE/EV
  101. #endif
  102. #define TP_EV_batch_msg_interval (50*3) //unit: ms
  103. #define TT_EVSE_match_session 10000 //unit: ms
  104. #define TT_match_join (12000*2) //unit: ms
  105. #define V2G_SECC_ReadyToCharge_Performance_Time 148000 //unit: ms (148 sec)
  106. #define V2G_SECC_CommunicationSetup_Performance_Time 18000 //unit: ms (18 sec)
  107. #define V2G_SECC_ChargingParameter_Performance_Time 60000 //unit: ms (60 sec)
  108. //#define V2G_SECC_ChargingParameter_Performance_Time 120000 //unit: ms (120 sec)
  109. #define V2G_SECC_CableCheck_Performance_Time 38000 //unit: ms (38 sec)
  110. //#define V2G_SECC_CableCheck_Performance_Time 60000 //unit: ms (extend to 60 sec)
  111. //#define V2G_SECC_PreCharge_Performance_Time 5000 //unit: ms (5 sec)
  112. #define V2G_SECC_PreCharge_Performance_Time 10000 //unit: ms (extend to 10 sec)
  113. #define V2G_SECC_WeldingDetection_Performance_Time 20000 //unit: ms (20 sec)
  114. #define V2G_SECC_CPState_Detection_Timeout 1500 //unit: ms (1.5 sec)
  115. #define V2G_SECC_CPOscillator_Retain_Timeout 1500 //unit: ms (1.5 sec)
  116. #define V2G_EVCC_Msg_Timeout_SupportedAppProtocolReq 2000 //unit: ms (1.5 sec)
  117. #define V2G_EVCC_Msg_Timeout_SessionSetupReq 2000 //unit: ms (1.5 sec)
  118. #define V2G_EVCC_Msg_Timeout_ServiceDiscoveryReq 2000
  119. #define V2G_EVCC_Msg_Timeout_ServicePaymentSelectionReq 2000
  120. #define V2G_EVCC_Msg_Timeout_ContractAuthenticationReq 2000
  121. #define V2G_EVCC_Msg_Timeout_ChargeParameterDiscoveryReq 2000
  122. #define V2G_EVCC_Msg_Timeout_PowerDeliveryReq 2000
  123. #define V2G_EVCC_Msg_Timeout_CableCheckReq 2000
  124. #define V2G_EVCC_Msg_Timeout_PreChargeReq 2000
  125. #define V2G_EVCC_Msg_Timeout_CurrentDemandReq 25
  126. #define V2G_EVCC_Msg_Timeout_WeldingDetectionReq 2000
  127. #define V2G_EVCC_Msg_Timeout_SessionStopReq 2000
  128. #define V2G_SECC_Sequence_Timeout 60000 //unit: ms (default: 60000, i.e. 60 sec)
  129. #define V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD 3000 //unit: ms (default: 3000, i.e. 3 sec)
  130. #define V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD 2000 //unit: ms (default: 2000, i.e. 2 sec)
  131. #define V2G_SECC_QCA7000_COMM_TIMEOUT 10000 //unit: ms (default: 10000, i.e. 20 sec)
  132. //[To-Do] to be continued. (DIN 70121, Table 75)
  133. #define V2G_SECC_CP_Timeout_CableCheck 2000 //unit: ms (default: 2 sec)
  134. #define DIN_SPEC_70121_2012_VersionNumberMajor 2
  135. #define DIN_SPEC_70121_2012_VersionNumberMinor 0
  136. #define ISO1_15118_2013_VersionNumberMajor 2
  137. #define ISO1_15118_2013_VersionNumberMinor 0
  138. #define ISO2_15118_2018_VersionNumberMajor 3
  139. #define ISO2_15118_2018_VersionNumberMinor 0
  140. /***********************************************/
  141. /*************** Structure *********************/
  142. /**********************************************/
  143. struct MmeHeader
  144. {
  145. unsigned char ODA[6]; //Original Destination Address
  146. unsigned char OSA[6]; //Original source Address
  147. //unsigned int VLAN Tag; //IEEE802.1Q VLAN Tag (optional)
  148. unsigned short MTYPE; //Ethernet Type for HomePlug, should be 0x88E1
  149. unsigned char MMV; //Management Message Version
  150. unsigned short MMTYPE; //Management Message Type
  151. unsigned char FMI[2]; //Fragmentation Management Information, Fragmentation Message Sequence Number
  152. unsigned char MMENTRY[256]; //Management Message Entry Data
  153. } __attribute__((packed));
  154. //Qualcomm Atheros Vendor Specific MME Format
  155. struct QcaVendorMmeHeader
  156. {
  157. unsigned char ODA[6]; //Original Destination Address
  158. unsigned char OSA[6]; //Original source Address
  159. //unsigned int VLAN Tag; //IEEE802.1Q VLAN Tag (optional)
  160. unsigned short MTYPE; //Ethernet Type for HomePlug, should be 0x88E1
  161. unsigned char MMV; //Management Message Version
  162. unsigned short MMTYPE; //Management Message Type
  163. unsigned char OUI[3]; //Fragmentation Management Information, Fragmentation Message Sequence Number
  164. unsigned char MBODY[1024]; //Management Message Entry Data
  165. } __attribute__((packed));
  166. struct V2gtpHeader //8 Bytes (see Figure 25 in DIN 70121)
  167. {
  168. unsigned char ProtocolVersion; //0x01: V2GTP version 1, 0x00, 0x02-0xFF reserved
  169. unsigned char InverseProtocolVersion; //Equals the <Protocol_Version> XOR 0xFF, 0xFE: V2GTP Version 1
  170. unsigned short PayloadType; //0x8001: EXI encoded V2G Message,
  171. //0x9000: SDP request message,
  172. //0x9001: SDP response message,
  173. //0xA000 - 0xFFFF: Manufacturer specific use
  174. unsigned int PayloadLength; //excluding the generic V2GTP header byte
  175. } __attribute__((packed));
  176. int Proc_din_supportedAppProtocolRes(int AcceptFd);
  177. void SHM_Init_din_ChargeParameterDiscoveryRes(struct CcsData *shm_ccs);
  178. void SHM_Init_din_CableCheckRes(struct CcsData *shm_ccs);
  179. void SHM_Init_din_PreChargeRes(struct CcsData *shm_ccs);
  180. void SHM_Init_din_PowerDeliveryRes(struct CcsData *shm_ccs);
  181. void SHM_Init_din_CurrentDemandRes(struct CcsData *shm_ccs);
  182. void SHM_Init_din_WeldingDetectionRes(struct CcsData *shm_ccs);
  183. void SHM_Init_din_SessionStopRes(struct CcsData *shm_ccs);
  184. int OutputCpPwmDuty(unsigned char Duty);
  185. void Check_EVErrorCode(int code);
  186. unsigned char Check_V2G_Flow_Status_pre();
  187. int End_Process();
  188. int SdpUdpConnected();
  189. int V2gTcpConnected();
  190. //System Log
  191. #if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  192. #define SAVE_SYS_LOG_MSG_EVCOMM StoreLogMsg2
  193. #else
  194. #define SAVE_SYS_LOG_MSG_EVCOMM(...)
  195. #endif
  196. //Debug Message
  197. #if DEBUG_PRINTF_EVCOMM_SHOW == ENABLE
  198. //Brief Messages
  199. #if DEBUG_PRINTF_EVCOMM_BRIEF_SHOW == ENABLE
  200. #define DEBUG_PRINTF_EVCOMM_BRIEF printf
  201. #else
  202. #define DEBUG_PRINTF_EVCOMM_BRIEF(...)
  203. #endif
  204. //Detail Messages
  205. #if DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE
  206. #define DEBUG_PRINTF_EVCOMM_DETAIL printf
  207. #else
  208. #define DEBUG_PRINTF_EVCOMM_DETAIL(...)
  209. #endif
  210. //System Log Messages
  211. #if DEBUG_PRINTF_EVCOMM_SYSTEM_LOG_SHOW == ENABLE
  212. #define DEBUG_PRINTF_EVCOMM_SYSTEM_LOG printf
  213. #else
  214. #define DEBUG_PRINTF_EVCOMM_SYSTEM_LOG(...)
  215. #endif
  216. #else
  217. #define DEBUG_PRINTF_EVCOMM_BRIEF(...)
  218. #define DEBUG_PRINTF_EVCOMM_DETAIL(...)
  219. #define DEBUG_PRINTF_EVCOMM_SYSTEM_LOG(...)
  220. #endif
  221. #endif