Module_CCS.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Module_CCS.h
  3. *
  4. * Created on: 2020¦~3¤ë16¤é
  5. * Author: foluswen
  6. */
  7. #ifndef MODULE_CCS_H_
  8. #define MODULE_CCS_H_
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/time.h>
  12. #include <sys/timeb.h>
  13. #include <sys/ipc.h>
  14. #include <sys/shm.h>
  15. #include <sys/mman.h>
  16. #include <sys/socket.h>
  17. #include <netinet/in.h>
  18. #include <net/if.h>
  19. #include <net/ethernet.h>
  20. #include <linux/if_packet.h>
  21. #include <unistd.h>
  22. #include <stdarg.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <unistd.h>
  26. #include <fcntl.h>
  27. #include <errno.h>
  28. #include <errno.h>
  29. #include <string.h>
  30. #include <time.h>
  31. #include <ctype.h>
  32. #include "SystemLogMessage.h"
  33. #include "NidNmk.h"
  34. #include "v2g/api/api.h"
  35. #include "v2g/transport/v2gtp.h"
  36. //#define TEST_WITH_ETH0
  37. #define QcaInterface "eth1"
  38. #define SupportBcbToggle
  39. #define SdpUdpServerPort 15118
  40. #define SdpTcpServerPort 55000 //49152-65535
  41. #define IPV6_LINK_LOCAL_PREFIX 0xFE80
  42. #define V2GTP_MSG_RX_BUFFER_SIZE (64*1024) //65,536 = 65.5KB
  43. #define V2GTP_MSG_TX_BUFFER_SIZE (64*1024) //65,536 = 65.5KB
  44. #define V2GTP_MSG_HEADER_LENGTH 8 //8 Bytes
  45. /***********************************************/
  46. /*********** Ethernet Type ********************/
  47. /**********************************************/
  48. #define EtherType_HomePlug 0x88E1
  49. /***********************************************/
  50. /*** MMTYPE (Management Message Type) **/
  51. /**********************************************/
  52. #define MMTYPE_CM_SET_KEY_REQ 0x6008
  53. #define MMTYPE_CM_SET_KEY_CNF 0x6009
  54. #define MMTYPE_CM_SLAC_PARM_REQ 0x6064
  55. #define MMTYPE_CM_SLAC_PARM_CNF 0x6065
  56. #define MMTYPE_CM_START_ATTEN_CHAR_IND 0x606A
  57. #define MMTYPE_CM_MNBC_SOUND_IND 0x6076
  58. #define MMTYPE_CM_ATTEN_CHAR_IND 0x606E
  59. #define MMTYPE_CM_ATTEN_CHAR_RSP 0x606F
  60. #define MMTYPE_CM_VALIDATE_REQ 0x6078
  61. #define MMTYPE_CM_VALIDATE_CNF 0x6079
  62. #define MMTYPE_CM_SLAC_MATCH_REQ 0x607C
  63. #define MMTYPE_CM_SLAC_MATCH_CNF 0x607D
  64. #define MMTYPE_CM_ATTEN_PROFILE_IND 0x6086
  65. //following are the vendor specific type
  66. #define MMTYPE_VENDOR_VS_HOST_ACTION 0xA062 //Embedded Host Action Requested Indication MME
  67. #define MMTYPE_VENDOR_ATTEN_CHAR 0xA14E //Attenuation Characteristics MME (VS_ATTEN_CHAR)
  68. #define MMTYPE_VENDOR_VS_NW_INFO 0xA038 //Network Info MME
  69. #define MMTYPE_VENDOR_VS_NW_INFO_CNF 0xA039 //Network Info MME
  70. #define MMTYPE_VENDOR_VS_PL_LNK_STATUS 0xA0B8 //Powerline Link Status /*+++ 20200808, vern, for PLC connection monitoring ---*/
  71. #define MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF 0xA0B9 //Powerline Link Status /*+++ 20200808, vern, for PLC connection monitoring ---*/
  72. /***********************************************/
  73. /************** V2GTP Payload Type ************/
  74. /**********************************************/
  75. #define V2GTP_PAYLOAD_TYPE_SDP_REQUEST 0x9000 //SDP request message
  76. #define V2GTP_PAYLOAD_TYPE_SDP_RESPONSE 0x9001 //SDP response message
  77. #define V2GTP_PAYLOAD_TYPE_EXI_MSG 0x8001 //EXI encoded V2G Message
  78. //Payload
  79. #define SDP_PAYLOAD_SECURITY_TLS 0x00 //0x00 = secured with TLS
  80. #define SDP_PAYLOAD_SECURITY_NONE 0x10 //0x10 = No transport layer security
  81. #define SDP_PAYLOAD_TRANS_PROTOCOL_TCP 0x00 //0x00= TCP
  82. #define SDP_PAYLOAD_TRANS_PROTOCOL_UDP 0x10 //0x10 = reserved for UDP
  83. /***********************************************/
  84. /****** Timing and constant values **********/
  85. /*********** [2015] ISO 15118_3 ***************/
  86. /**********************************************/
  87. #define TT_EVSE_match_MNBC (600+400) //unit: 1ms (default: 600ms)
  88. #define C_EV_match_MNBC 0x0A
  89. #define TT_EVSE_SLAC_init 50 //unit: sec.
  90. #define TT_match_sequence 400 //unit: ms
  91. #define TP_match_response 100 //unit: ms, General performance time for a response to a request
  92. #define TT_match_response (200*3) //unit: ms, Time that the EV/EVSE shall wait for a response from the EVSE/EV
  93. #define TP_EV_batch_msg_interval (50*3) //unit: ms
  94. #define TT_EVSE_match_session 10000 //unit: ms
  95. #define TT_match_join (12000*2) //unit: ms
  96. #define V2G_SECC_ReadyToCharge_Performance_Time 148000 //unit: ms (148 sec)
  97. #define V2G_SECC_CommunicationSetup_Performance_Time 18000 //unit: ms (18 sec)
  98. #define V2G_SECC_ChargingParameter_Performance_Time 60000 //unit: ms (60 sec)
  99. //#define V2G_SECC_ChargingParameter_Performance_Time 120000 //unit: ms (120 sec)
  100. #define V2G_SECC_CableCheck_Performance_Time 38000 //unit: ms (38 sec)
  101. //#define V2G_SECC_CableCheck_Performance_Time 60000 //unit: ms (extend to 60 sec)
  102. //#define V2G_SECC_PreCharge_Performance_Time 5000 //unit: ms (5 sec)
  103. #define V2G_SECC_PreCharge_Performance_Time 10000 //unit: ms (extend to 10 sec)
  104. #define V2G_SECC_WeldingDetection_Performance_Time 20000 //unit: ms (20 sec)
  105. #define V2G_SECC_CPState_Detection_Timeout 1500 //unit: ms (1.5 sec)
  106. #define V2G_SECC_CPOscillator_Retain_Timeout 1500 //unit: ms (1.5 sec)
  107. #define V2G_EVCC_Msg_Timeout_SupportedAppProtocolReq 2000 //unit: ms (1.5 sec)
  108. #define V2G_EVCC_Msg_Timeout_SessionSetupReq 2000 //unit: ms (1.5 sec)
  109. #define V2G_EVCC_Msg_Timeout_ServiceDiscoveryReq 2000
  110. #define V2G_EVCC_Msg_Timeout_ServicePaymentSelectionReq 2000
  111. #define V2G_EVCC_Msg_Timeout_ContractAuthenticationReq 2000
  112. #define V2G_EVCC_Msg_Timeout_ChargeParameterDiscoveryReq 2000
  113. #define V2G_EVCC_Msg_Timeout_PowerDeliveryReq 2000
  114. #define V2G_EVCC_Msg_Timeout_CableCheckReq 2000
  115. #define V2G_EVCC_Msg_Timeout_PreChargeReq 2000
  116. #define V2G_EVCC_Msg_Timeout_CurrentDemandReq 25
  117. #define V2G_EVCC_Msg_Timeout_WeldingDetectionReq 2000
  118. #define V2G_EVCC_Msg_Timeout_SessionStopReq 2000
  119. #define V2G_SECC_Sequence_Timeout 60000 //unit: ms (default: 60000, i.e. 60 sec)
  120. #define V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD 3000 //unit: ms (default: 3000, i.e. 3 sec)
  121. #define V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD 2000 //unit: ms (default: 2000, i.e. 2 sec)
  122. #define V2G_SECC_QCA7000_COMM_TIMEOUT 10000 //unit: ms (default: 10000, i.e. 20 sec)
  123. //[To-Do] to be continued. (DIN 70121, Table 75)
  124. #define V2G_SECC_CP_Timeout_CableCheck 2000 //unit: ms (default: 2 sec)
  125. #define DIN_SPEC_70121_2012_VersionNumberMajor 2
  126. #define DIN_SPEC_70121_2012_VersionNumberMinor 0
  127. #define ISO1_15118_2013_VersionNumberMajor 2
  128. #define ISO1_15118_2013_VersionNumberMinor 0
  129. #define ISO2_15118_2018_VersionNumberMajor 2
  130. #define ISO2_15118_2018_VersionNumberMinor 0
  131. //Protocol format : Message ID
  132. #define CAN_CMD_ADDRESS_REQUEST 0x00000100
  133. #define CAN_CMD_ADDRESS_ASSIGN 0x00000200
  134. #define CAN_CMD_EV_BOARD_STATUS 0x00000300
  135. #define CAN_CMD_GET_FW_VERSION 0x00000400
  136. #define CAN_CMD_GET_HW_VERSION 0x00000500
  137. #define CAN_CMD_CHARGING_PERMISSION 0x00000600
  138. #define CAN_CMD_EVSE_OUTPUT_STATUS_ANNOUNCEMENT 0x00000700
  139. #define CAN_CMD_EVSE_CAPACITY_ANNOUNCEMENT 0x00000800
  140. #define CAN_CMD_GET_EV_TARGET_INFO 0x00000900
  141. #define CAN_CMD_GET_EV_BATTERY_INFO 0x00000A00
  142. #define CAN_CMD_EV_STOP_EVENT 0x00000B00
  143. #define CAN_CMD_EVSE_STOP_EVENT 0x00000C00
  144. #define CAN_CMD_GET_MISC_INFO 0x00000D00
  145. #define CAN_CMD_DOWNLOAD_REQUEST 0x00000E00
  146. #define CAN_CMD_START_BLOCK_TRANSFER 0x00000F00
  147. #define CAN_CMD_DATA_TRANSFER 0x00001000
  148. #define CAN_CMD_DOWNLOAD_FINISH 0x00001100
  149. #define CAN_CMD_ISOLATION_STATUS 0x00001200
  150. #define CAN_CMD_CCS_CONNECTOR_INFO 0x00001300
  151. #define CAN_CMD_RTC_INFO 0x00001400
  152. #define CAN_CMD_EVSE_PRECHARGE_INFO 0x00001500
  153. #define CAN_CMD_EVCCID_REQUEST 0x00001600
  154. #define CAN_CMD_PCBA_TEST 0x0000AA00
  155. /***********************************************/
  156. /*************** Structure *********************/
  157. /**********************************************/
  158. struct MmeHeader
  159. {
  160. unsigned char ODA[6]; //Original Destination Address
  161. unsigned char OSA[6]; //Original source Address
  162. //unsigned int VLAN Tag; //IEEE802.1Q VLAN Tag (optional)
  163. unsigned short MTYPE; //Ethernet Type for HomePlug, should be 0x88E1
  164. unsigned char MMV; //Management Message Version
  165. unsigned short MMTYPE; //Management Message Type
  166. unsigned char FMI[2]; //Fragmentation Management Information, Fragmentation Message Sequence Number
  167. unsigned char MMENTRY[256]; //Management Message Entry Data
  168. } __attribute__((packed));
  169. //Qualcomm Atheros Vendor Specific MME Format
  170. struct QcaVendorMmeHeader
  171. {
  172. unsigned char ODA[6]; //Original Destination Address
  173. unsigned char OSA[6]; //Original source Address
  174. //unsigned int VLAN Tag; //IEEE802.1Q VLAN Tag (optional)
  175. unsigned short MTYPE; //Ethernet Type for HomePlug, should be 0x88E1
  176. unsigned char MMV; //Management Message Version
  177. unsigned short MMTYPE; //Management Message Type
  178. unsigned char OUI[3]; //Fragmentation Management Information, Fragmentation Message Sequence Number
  179. unsigned char MBODY[1024]; //Management Message Entry Data
  180. } __attribute__((packed));
  181. struct V2gtpHeader //8 Bytes (see Figure 25 in DIN 70121)
  182. {
  183. unsigned char ProtocolVersion; //0x01: V2GTP version 1, 0x00, 0x02-0xFF reserved
  184. unsigned char InverseProtocolVersion; //Equals the <Protocol_Version> XOR 0xFF, 0xFE: V2GTP Version 1
  185. unsigned short PayloadType; //0x8001: EXI encoded V2G Message,
  186. //0x9000: SDP request message,
  187. //0x9001: SDP response message,
  188. //0xA000 - 0xFFFF: Manufacturer specific use
  189. unsigned int PayloadLength; //excluding the generic V2GTP header byte
  190. } __attribute__((packed));
  191. typedef struct MODULE_INFO
  192. {
  193. struct timeb startTime[10];
  194. uint8_t QCA7K_SetKey_status;
  195. }Module_Info;
  196. int Proc_din_supportedAppProtocolRes(int AcceptFd);
  197. void SHM_Init_din_ChargeParameterDiscoveryRes(struct CcsData *shm_ccs);
  198. void SHM_Init_din_CableCheckRes(struct CcsData *shm_ccs);
  199. void SHM_Init_din_PreChargeRes(struct CcsData *shm_ccs);
  200. void SHM_Init_din_PowerDeliveryRes(struct CcsData *shm_ccs);
  201. void SHM_Init_din_CurrentDemandRes(struct CcsData *shm_ccs);
  202. void SHM_Init_din_WeldingDetectionRes(struct CcsData *shm_ccs);
  203. void SHM_Init_din_SessionStopRes(struct CcsData *shm_ccs);
  204. int OutputCpPwmDuty(unsigned char Duty);
  205. void Check_EVErrorCode(int code);
  206. unsigned char Check_V2G_Flow_Status_pre();
  207. int End_Process();
  208. int SdpUdpConnected();
  209. int V2gTcpConnected();
  210. #endif /* MODULE_CCS_H_ */