slac.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*====================================================================*
  2. Copyright (c) 2013,2021 Qualcomm Technologies, Inc.
  3. All Rights Reserved.
  4. Confidential and Proprietary - Qualcomm Technologies, Inc.
  5. ******************************************************************
  6. 2013 Qualcomm Atheros, Inc.
  7. *--------------------------------------------------------------------*/
  8. /*====================================================================*
  9. *
  10. * slac.h -
  11. *
  12. * this file contains defintions for the HomePlug Green PHY SLAC
  13. * protocol;
  14. *
  15. *--------------------------------------------------------------------*/
  16. #ifndef SLAC_HEADER
  17. #define SLAC_HEADER
  18. /*====================================================================*
  19. * system header files;
  20. *--------------------------------------------------------------------*/
  21. #include <stdint.h>
  22. /*====================================================================*
  23. * custom header files;
  24. *--------------------------------------------------------------------*/
  25. #include "../tools/types.h"
  26. #include "../tools/endian.h"
  27. #include "../ether/ether.h"
  28. #include "../mme/mme.h"
  29. #include "../plc/plc.h"
  30. /*====================================================================*
  31. * constants;
  32. *--------------------------------------------------------------------*/
  33. #define SLAC_DEBUG 1
  34. /*
  35. * The following two constants control whether or not the PEV or EVSE
  36. * change AVLN on SLAC protocol cycle; The recommended setting is PEV
  37. * changes with each pass and the EVSE does not;
  38. */
  39. #define SLAC_AVLN_PEV 1
  40. #define SLAC_AVLN_EVSE 0
  41. #define SLAC_APPLICATION_PEV_EVSE 0x00
  42. #define SLAC_SECURITY_NONE 0x00
  43. #define SLAC_SECURITY_PUBLIC_KEY 0x01
  44. #define SLAC_RUNID_LEN 8
  45. #define SLAC_UNIQUE_ID_LEN 17
  46. #define SLAC_RND_LEN 16
  47. #define SLAC_NID_LEN 7
  48. #define SLAC_NMK_LEN 16
  49. #define SLAC_LOOP 1
  50. #define SLAC_MSOUNDS 10
  51. #define SLAC_TIMETOSOUND 6
  52. #define SLAC_TIMEOUT 1000
  53. #define SLAC_APPLICATION_TYPE 0
  54. #define SLAC_SECURITY_TYPE 0
  55. #define SLAC_RESPONSE_TYPE 1
  56. #define SLAC_MSOUND_TARGET "00:00:00:00:00:00"
  57. #define SLAC_FORWARD_STATION "00:00:00:00:00:00"
  58. #define SLAC_GROUPS 58
  59. #define SLAC_LIMIT 201
  60. #define SLAC_PAUSE 20
  61. #define SLAC_SETTLETIME 10
  62. #define SLAC_CHARGETIME 3
  63. #define SLAC_FLAGS 0
  64. #define SLAC_SILENCE (1 << 0)
  65. #define SLAC_VERBOSE (1 << 1)
  66. #define SLAC_SESSION (1 << 2)
  67. #define SLAC_COMPARE (1 << 3)
  68. #define SLAC_CM_SETKEY_KEYTYPE 0x01
  69. #define SLAC_CM_SETKEY_PID 0x04
  70. #define SLAC_CM_SETKEY_PRN 0x00
  71. #define SLAC_CM_SETKEY_PMN 0x00
  72. #define SLAC_CM_SETKEY_CCO 0x00
  73. #define SLAC_CM_SETKEY_EKS 0x01
  74. /*====================================================================*
  75. * messages;
  76. *--------------------------------------------------------------------*/
  77. #ifndef __GNUC__
  78. #pragma pack (push,1)
  79. #endif
  80. typedef struct __packed session
  81. {
  82. struct session * next;
  83. struct session * prev;
  84. byte RunID [SLAC_RUNID_LEN];
  85. byte APPLICATION_TYPE;
  86. byte SECURITY_TYPE;
  87. byte RESP_TYPE;
  88. byte NUM_SOUNDS;
  89. byte TIME_OUT;
  90. byte AAG [SLAC_GROUPS];
  91. byte NumGroups;
  92. byte MSOUND_TARGET [ETHER_ADDR_LEN];
  93. byte FORWARDING_STA [ETHER_ADDR_LEN];
  94. byte PEV_ID [SLAC_UNIQUE_ID_LEN];
  95. byte PEV_MAC [ETHER_ADDR_LEN];
  96. byte EVSE_ID [SLAC_UNIQUE_ID_LEN];
  97. byte EVSE_MAC [ETHER_ADDR_LEN];
  98. byte RND [SLAC_UNIQUE_ID_LEN];
  99. byte NMK [SLAC_NMK_LEN];
  100. byte NID [SLAC_NID_LEN];
  101. byte original_nmk [SLAC_NMK_LEN];
  102. byte original_nid [SLAC_NID_LEN];
  103. unsigned state;
  104. unsigned sounds;
  105. unsigned limit;
  106. unsigned pause;
  107. unsigned chargetime;
  108. unsigned settletime;
  109. unsigned counter;
  110. unsigned flags;
  111. signed exit;
  112. }
  113. session;
  114. typedef struct __packed cm_sta_identity_request
  115. {
  116. struct ethernet_hdr ethernet;
  117. struct homeplug_fmi homeplug;
  118. }
  119. cm_sta_identity_request;
  120. typedef struct __packed cm_sta_identity_confirm
  121. {
  122. struct ethernet_hdr ethernet;
  123. struct homeplug_fmi homeplug;
  124. uint8_t GREEN_PHY_CAPABILITY;
  125. uint8_t POWER_SAVE_CAPABILITY;
  126. uint8_t GREEN_PHY_PREFERRED_ALLOCATION_CAPABILITY;
  127. uint8_t REPEATING_AND_ROUTING_CAPABILITY;
  128. uint8_t HOMEPLUG_AV_VERSION;
  129. uint8_t EFL;
  130. uint8_t EF [1];
  131. }
  132. cm_sta_identity_confirm;
  133. typedef struct __packed cm_slac_param_request
  134. {
  135. struct ethernet_hdr ethernet;
  136. struct homeplug_fmi homeplug;
  137. uint8_t APPLICATION_TYPE;
  138. uint8_t SECURITY_TYPE;
  139. uint8_t RunID [SLAC_RUNID_LEN];
  140. uint8_t CipherSuiteSetSize;
  141. uint16_t CipherSuite [1];
  142. }
  143. cm_slac_param_request;
  144. typedef struct __packed cm_slac_param_confirm
  145. {
  146. struct ethernet_hdr ethernet;
  147. struct homeplug_fmi homeplug;
  148. uint8_t MSOUND_TARGET [ETHER_ADDR_LEN];
  149. uint8_t NUM_SOUNDS;
  150. uint8_t TIME_OUT;
  151. uint8_t RESP_TYPE;
  152. uint8_t FORWARDING_STA [ETHER_ADDR_LEN];
  153. uint8_t APPLICATION_TYPE;
  154. uint8_t SECURITY_TYPE;
  155. uint8_t RunID [SLAC_RUNID_LEN];
  156. uint16_t CipherSuite;
  157. }
  158. cm_slac_param_confirm;
  159. typedef struct __packed cm_start_atten_char_indicate
  160. {
  161. struct ethernet_hdr ethernet;
  162. struct homeplug_fmi homeplug;
  163. uint8_t APPLICATION_TYPE;
  164. uint8_t SECURITY_TYPE;
  165. struct __packed
  166. {
  167. uint8_t NUM_SOUNDS;
  168. uint8_t TIME_OUT;
  169. uint8_t RESP_TYPE;
  170. uint8_t FORWARDING_STA [ETHER_ADDR_LEN];
  171. uint8_t RunID [SLAC_RUNID_LEN];
  172. }
  173. ACVarField;
  174. }
  175. cm_start_atten_char_indicate;
  176. typedef struct __packed cm_start_atten_char_response
  177. {
  178. struct ethernet_hdr ethernet;
  179. struct homeplug_fmi homeplug;
  180. }
  181. cm_start_atten_char_response;
  182. typedef struct __packed cm_atten_char_indicate
  183. {
  184. struct ethernet_hdr ethernet;
  185. struct homeplug_fmi homeplug;
  186. uint8_t APPLICATION_TYPE;
  187. uint8_t SECURITY_TYPE;
  188. struct __packed
  189. {
  190. uint8_t SOURCE_ADDRESS [ETHER_ADDR_LEN];
  191. uint8_t RunID [SLAC_RUNID_LEN];
  192. uint8_t SOURCE_ID [SLAC_UNIQUE_ID_LEN];
  193. uint8_t RESP_ID [SLAC_UNIQUE_ID_LEN];
  194. uint8_t NUM_SOUNDS;
  195. struct __packed
  196. {
  197. uint8_t NumGroups;
  198. uint8_t AAG [255];
  199. }
  200. ATTEN_PROFILE;
  201. }
  202. ACVarField;
  203. }
  204. cm_atten_char_indicate;
  205. typedef struct __packed cm_atten_char_response
  206. {
  207. struct ethernet_hdr ethernet;
  208. struct homeplug_fmi homeplug;
  209. uint8_t APPLICATION_TYPE;
  210. uint8_t SECURITY_TYPE;
  211. struct __packed
  212. {
  213. uint8_t SOURCE_ADDRESS [ETHER_ADDR_LEN];
  214. uint8_t RunID [SLAC_RUNID_LEN];
  215. uint8_t SOURCE_ID [SLAC_UNIQUE_ID_LEN];
  216. uint8_t RESP_ID [SLAC_UNIQUE_ID_LEN];
  217. uint8_t Result;
  218. }
  219. ACVarField;
  220. }
  221. cm_atten_char_response;
  222. typedef struct __packed cm_mnbc_sound_indicate
  223. {
  224. struct ethernet_hdr ethernet;
  225. struct homeplug_fmi homeplug;
  226. uint8_t APPLICATION_TYPE;
  227. uint8_t SECURITY_TYPE;
  228. struct __packed
  229. {
  230. uint8_t SenderID [SLAC_UNIQUE_ID_LEN];
  231. uint8_t CNT;
  232. uint8_t RunID [SLAC_RUNID_LEN];
  233. uint8_t RND [SLAC_UNIQUE_ID_LEN];
  234. }
  235. MSVarField;
  236. }
  237. cm_mnbc_sound_indcate;
  238. typedef struct __packed cm_validate_request
  239. {
  240. struct ethernet_hdr ethernet;
  241. struct homeplug_fmi homeplug;
  242. uint8_t SignalType;
  243. struct __packed
  244. {
  245. uint8_t Timer;
  246. uint8_t Result;
  247. }
  248. VRVarField;
  249. }
  250. cm_validate_request;
  251. typedef struct __packed cm_validate_confirm
  252. {
  253. struct ethernet_hdr ethernet;
  254. struct homeplug_fmi homeplug;
  255. uint8_t SignalType;
  256. struct __packed
  257. {
  258. uint8_t ToggleNum;
  259. uint8_t Result;
  260. }
  261. VCVarField;
  262. }
  263. cm_validate_confirm;
  264. typedef struct __packed cm_slac_match_request
  265. {
  266. struct ethernet_hdr ethernet;
  267. struct homeplug_fmi homeplug;
  268. uint8_t APPLICATION_TYPE;
  269. uint8_t SECURITY_TYPE;
  270. uint16_t MVFLength;
  271. struct __packed
  272. {
  273. uint8_t PEV_ID [SLAC_UNIQUE_ID_LEN];
  274. uint8_t PEV_MAC [ETHER_ADDR_LEN];
  275. uint8_t EVSE_ID [SLAC_UNIQUE_ID_LEN];
  276. uint8_t EVSE_MAC [ETHER_ADDR_LEN];
  277. uint8_t RunID [SLAC_RUNID_LEN];
  278. uint8_t RSVD [8];
  279. }
  280. MatchVarField;
  281. }
  282. cm_slac_match_request;
  283. typedef struct __packed cm_slac_match_confirm
  284. {
  285. struct ethernet_hdr ethernet;
  286. struct homeplug_fmi homeplug;
  287. uint8_t APPLICATION_TYPE;
  288. uint8_t SECURITY_TYPE;
  289. uint16_t MVFLength;
  290. struct __packed
  291. {
  292. uint8_t PEV_ID [SLAC_UNIQUE_ID_LEN];
  293. uint8_t PEV_MAC [ETHER_ADDR_LEN];
  294. uint8_t EVSE_ID [SLAC_UNIQUE_ID_LEN];
  295. uint8_t EVSE_MAC [ETHER_ADDR_LEN];
  296. uint8_t RunID [SLAC_RUNID_LEN];
  297. uint8_t RSVD1 [8];
  298. uint8_t NID [SLAC_NID_LEN];
  299. uint8_t RSVD2;
  300. uint8_t NMK [SLAC_NMK_LEN];
  301. }
  302. MatchVarField;
  303. }
  304. cm_slac_match_confirm;
  305. typedef struct __packed cm_atten_profile_indicate
  306. {
  307. struct ethernet_hdr ethernet;
  308. struct homeplug_fmi homeplug;
  309. uint8_t PEV_MAC [ETHER_ADDR_LEN];
  310. uint8_t NumGroups;
  311. uint8_t RSVD;
  312. uint8_t AAG [255];
  313. }
  314. cm_atten_profile_indicate;
  315. #ifndef __GNUC__
  316. #pragma pack (pop)
  317. #endif
  318. /*====================================================================*
  319. * functions;
  320. *--------------------------------------------------------------------*/
  321. signed pev_cm_slac_param (struct session *, struct channel *, struct message *);
  322. signed pev_cm_start_atten_char (struct session *, struct channel *, struct message *);
  323. signed pev_cm_atten_char (struct session *, struct channel *, struct message *);
  324. signed pev_cm_mnbc_sound (struct session *, struct channel *, struct message *);
  325. signed pev_cm_slac_match (struct session *, struct channel *, struct message *);
  326. signed pev_cm_set_key (struct session *, struct channel *, struct message *);
  327. signed pev_cm_slac_param_req (struct session *, struct channel *, struct message *);
  328. signed pev_cm_slac_param_cnf (struct session *, struct channel *, struct message *);
  329. signed pev_cm_atten_char_process (struct session *, struct channel *, struct message *);
  330. signed pev_cm_slac_match_req (struct session *, struct channel *, struct message *);
  331. signed pev_cm_slac_match_cnf (struct session *, struct channel *, struct message *);
  332. signed pev_cm_set_key_req (struct session *, struct channel *, struct message *);
  333. signed pev_cm_set_key_cnf (struct session *, struct channel *, struct message *);
  334. signed pev_cm_get_key_req (struct plc *, void *);
  335. signed process_pev_cm_get_key_cnf (struct plc *, uint8_t *, uint8_t *);
  336. signed evse_cm_slac_param (struct session *, struct channel *, struct message *);
  337. signed evse_cm_start_atten_char (struct session *, struct channel *, struct message *);
  338. signed evse_cm_atten_char (struct session *, struct channel *, struct message *);
  339. signed evse_cm_mnbc_sound (struct session *, struct channel *, struct message *);
  340. signed evse_cm_slac_match (struct session *, struct channel *, struct message *);
  341. signed evse_cm_set_key (struct session *, struct channel *, struct message *);
  342. signed slac_connect (struct session *);
  343. void slac_session (struct session *);
  344. void slac_structs ();
  345. /*====================================================================*
  346. *
  347. *--------------------------------------------------------------------*/
  348. #endif