slac.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * slac.h -
  44. *
  45. * this file contains defintions for the HomePlug Green PHY SLAC
  46. * protocol;
  47. *
  48. *--------------------------------------------------------------------*/
  49. #ifndef SLAC_HEADER
  50. #define SLAC_HEADER
  51. /*====================================================================*
  52. * system header files;
  53. *--------------------------------------------------------------------*/
  54. #include <stdint.h>
  55. /*====================================================================*
  56. * custom header files;
  57. *--------------------------------------------------------------------*/
  58. #include "../tools/types.h"
  59. #include "../tools/endian.h"
  60. #include "../ether/ether.h"
  61. #include "../mme/mme.h"
  62. /*====================================================================*
  63. * constants;
  64. *--------------------------------------------------------------------*/
  65. #define SLAC_DEBUG 1
  66. /*
  67. * The following two constants control whether or not the PEV or EVSE
  68. * change AVLN on SLAC protocol cycle; The recommended setting is PEV
  69. * changes with each pass and the EVSE does not;
  70. */
  71. #define SLAC_AVLN_PEV 1
  72. #define SLAC_AVLN_EVSE 0
  73. #define SLAC_APPLICATION_PEV_EVSE 0x00
  74. #define SLAC_SECURITY_NONE 0x00
  75. #define SLAC_SECURITY_PUBLIC_KEY 0x01
  76. #define SLAC_RUNID_LEN 8
  77. #define SLAC_UNIQUE_ID_LEN 17
  78. #define SLAC_RND_LEN 16
  79. #define SLAC_NID_LEN 7
  80. #define SLAC_NMK_LEN 16
  81. #define SLAC_MSOUNDS 10
  82. #define SLAC_TIMETOSOUND 6
  83. #define SLAC_TIMEOUT 1000
  84. #define SLAC_APPLICATION_TYPE 0
  85. #define SLAC_SECURITY_TYPE 0
  86. #define SLAC_RESPONSE_TYPE 0
  87. #define SLAC_MSOUND_TARGET "FF:FF:FF:FF:FF:FF"
  88. #define SLAC_FORWARD_STATION "00:00:00:00:00:00"
  89. #define SLAC_GROUPS 58
  90. #define SLAC_LIMIT 40
  91. #define SLAC_PAUSE 20
  92. #define SLAC_SETTLETIME 10
  93. #define SLAC_CHARGETIME 2
  94. #define SLAC_FLAGS 0
  95. #define SLAC_SILENCE (1 << 0)
  96. #define SLAC_VERBOSE (1 << 1)
  97. #define SLAC_SESSION (1 << 2)
  98. #define SLAC_COMPARE (1 << 3)
  99. #define SLAC_SOUNDONLY (1 << 4)
  100. #define SLAC_CM_SETKEY_KEYTYPE 0x01
  101. #define SLAC_CM_SETKEY_PID 0x04
  102. #define SLAC_CM_SETKEY_PRN 0x00
  103. #define SLAC_CM_SETKEY_PMN 0x00
  104. #define SLAC_CM_SETKEY_CCO 0x00
  105. #define SLAC_CM_SETKEY_EKS 0x01
  106. /*====================================================================*
  107. * messages;
  108. *--------------------------------------------------------------------*/
  109. #ifndef __GNUC__
  110. #pragma pack (push,1)
  111. #endif
  112. typedef struct __packed session
  113. {
  114. struct session * next;
  115. struct session * prev;
  116. byte RunID [SLAC_RUNID_LEN];
  117. byte APPLICATION_TYPE;
  118. byte SECURITY_TYPE;
  119. byte RESP_TYPE;
  120. byte NUM_SOUNDS;
  121. byte TIME_OUT;
  122. byte AAG [SLAC_GROUPS];
  123. byte NumGroups;
  124. byte MSOUND_TARGET [ETHER_ADDR_LEN];
  125. byte FORWARDING_STA [ETHER_ADDR_LEN];
  126. byte PEV_ID [SLAC_UNIQUE_ID_LEN];
  127. byte PEV_MAC [ETHER_ADDR_LEN];
  128. byte EVSE_ID [SLAC_UNIQUE_ID_LEN];
  129. byte EVSE_MAC [ETHER_ADDR_LEN];
  130. byte RND [SLAC_UNIQUE_ID_LEN];
  131. byte NMK [SLAC_NMK_LEN];
  132. byte NID [SLAC_NID_LEN];
  133. byte original_nmk [SLAC_NMK_LEN];
  134. byte original_nid [SLAC_NID_LEN];
  135. unsigned state;
  136. unsigned sounds;
  137. unsigned limit;
  138. unsigned pause;
  139. unsigned chargetime;
  140. unsigned settletime;
  141. unsigned counter;
  142. unsigned flags;
  143. signed exit;
  144. }
  145. session;
  146. typedef struct __packed cm_sta_identity_request
  147. {
  148. struct ethernet_hdr ethernet;
  149. struct homeplug_fmi homeplug;
  150. }
  151. cm_sta_identity_request;
  152. typedef struct __packed cm_sta_identity_confirm
  153. {
  154. struct ethernet_hdr ethernet;
  155. struct homeplug_fmi homeplug;
  156. uint8_t GREEN_PHY_CAPABILITY;
  157. uint8_t POWER_SAVE_CAPABILITY;
  158. uint8_t GREEN_PHY_PREFERRED_ALLOCATION_CAPABILITY;
  159. uint8_t REPEATING_AND_ROUTING_CAPABILITY;
  160. uint8_t HOMEPLUG_AV_VERSION;
  161. uint8_t EFL;
  162. uint8_t EF [1];
  163. }
  164. cm_sta_identity_confirm;
  165. typedef struct __packed cm_slac_param_request
  166. {
  167. struct ethernet_hdr ethernet;
  168. struct homeplug_fmi homeplug;
  169. uint8_t APPLICATION_TYPE;
  170. uint8_t SECURITY_TYPE;
  171. uint8_t RunID [SLAC_RUNID_LEN];
  172. uint8_t CipherSuiteSetSize;
  173. uint16_t CipherSuite [1];
  174. }
  175. cm_slac_param_request;
  176. typedef struct __packed cm_slac_param_confirm
  177. {
  178. struct ethernet_hdr ethernet;
  179. struct homeplug_fmi homeplug;
  180. uint8_t MSOUND_TARGET [ETHER_ADDR_LEN];
  181. uint8_t NUM_SOUNDS;
  182. uint8_t TIME_OUT;
  183. uint8_t RESP_TYPE;
  184. uint8_t FORWARDING_STA [ETHER_ADDR_LEN];
  185. uint8_t APPLICATION_TYPE;
  186. uint8_t SECURITY_TYPE;
  187. uint8_t RunID [SLAC_RUNID_LEN];
  188. uint16_t CipherSuite;
  189. }
  190. cm_slac_param_confirm;
  191. typedef struct __packed cm_start_atten_char_indicate
  192. {
  193. struct ethernet_hdr ethernet;
  194. struct homeplug_fmi homeplug;
  195. uint8_t APPLICATION_TYPE;
  196. uint8_t SECURITY_TYPE;
  197. struct __packed
  198. {
  199. uint8_t NUM_SOUNDS;
  200. uint8_t TIME_OUT;
  201. uint8_t RESP_TYPE;
  202. uint8_t FORWARDING_STA [ETHER_ADDR_LEN];
  203. uint8_t RunID [SLAC_RUNID_LEN];
  204. }
  205. ACVarField;
  206. }
  207. cm_start_atten_char_indicate;
  208. typedef struct __packed cm_start_atten_char_response
  209. {
  210. struct ethernet_hdr ethernet;
  211. struct homeplug_fmi homeplug;
  212. }
  213. cm_start_atten_char_response;
  214. typedef struct __packed cm_atten_char_indicate
  215. {
  216. struct ethernet_hdr ethernet;
  217. struct homeplug_fmi homeplug;
  218. uint8_t APPLICATION_TYPE;
  219. uint8_t SECURITY_TYPE;
  220. struct __packed
  221. {
  222. uint8_t SOURCE_ADDRESS [ETHER_ADDR_LEN];
  223. uint8_t RunID [SLAC_RUNID_LEN];
  224. uint8_t SOURCE_ID [SLAC_UNIQUE_ID_LEN];
  225. uint8_t RESP_ID [SLAC_UNIQUE_ID_LEN];
  226. uint8_t NUM_SOUNDS;
  227. struct __packed
  228. {
  229. uint8_t NumGroups;
  230. uint8_t AAG [255];
  231. }
  232. ATTEN_PROFILE;
  233. }
  234. ACVarField;
  235. }
  236. cm_atten_char_indicate;
  237. typedef struct __packed cm_atten_char_response
  238. {
  239. struct ethernet_hdr ethernet;
  240. struct homeplug_fmi homeplug;
  241. uint8_t APPLICATION_TYPE;
  242. uint8_t SECURITY_TYPE;
  243. struct __packed
  244. {
  245. uint8_t SOURCE_ADDRESS [ETHER_ADDR_LEN];
  246. uint8_t RunID [SLAC_RUNID_LEN];
  247. uint8_t SOURCE_ID [SLAC_UNIQUE_ID_LEN];
  248. uint8_t RESP_ID [SLAC_UNIQUE_ID_LEN];
  249. uint8_t Result;
  250. }
  251. ACVarField;
  252. }
  253. cm_atten_char_response;
  254. typedef struct __packed cm_mnbc_sound_indicate
  255. {
  256. struct ethernet_hdr ethernet;
  257. struct homeplug_fmi homeplug;
  258. uint8_t APPLICATION_TYPE;
  259. uint8_t SECURITY_TYPE;
  260. struct __packed
  261. {
  262. uint8_t SenderID [SLAC_UNIQUE_ID_LEN];
  263. uint8_t CNT;
  264. uint8_t RunID [SLAC_RUNID_LEN];
  265. uint8_t RND [SLAC_UNIQUE_ID_LEN];
  266. }
  267. MSVarField;
  268. }
  269. cm_mnbc_sound_indcate;
  270. typedef struct __packed cm_validate_request
  271. {
  272. struct ethernet_hdr ethernet;
  273. struct homeplug_fmi homeplug;
  274. uint8_t SignalType;
  275. struct __packed
  276. {
  277. uint8_t Timer;
  278. uint8_t Result;
  279. }
  280. VRVarField;
  281. }
  282. cm_validate_request;
  283. typedef struct __packed cm_validate_confirm
  284. {
  285. struct ethernet_hdr ethernet;
  286. struct homeplug_fmi homeplug;
  287. uint8_t SignalType;
  288. struct __packed
  289. {
  290. uint8_t ToggleNum;
  291. uint8_t Result;
  292. }
  293. VCVarField;
  294. }
  295. cm_validate_confirm;
  296. typedef struct __packed cm_slac_match_request
  297. {
  298. struct ethernet_hdr ethernet;
  299. struct homeplug_fmi homeplug;
  300. uint8_t APPLICATION_TYPE;
  301. uint8_t SECURITY_TYPE;
  302. uint16_t MVFLength;
  303. struct __packed
  304. {
  305. uint8_t PEV_ID [SLAC_UNIQUE_ID_LEN];
  306. uint8_t PEV_MAC [ETHER_ADDR_LEN];
  307. uint8_t EVSE_ID [SLAC_UNIQUE_ID_LEN];
  308. uint8_t EVSE_MAC [ETHER_ADDR_LEN];
  309. uint8_t RunID [SLAC_RUNID_LEN];
  310. uint8_t RSVD [8];
  311. }
  312. MatchVarField;
  313. }
  314. cm_slac_match_request;
  315. typedef struct __packed cm_slac_match_confirm
  316. {
  317. struct ethernet_hdr ethernet;
  318. struct homeplug_fmi homeplug;
  319. uint8_t APPLICATION_TYPE;
  320. uint8_t SECURITY_TYPE;
  321. uint16_t MVFLength;
  322. struct __packed
  323. {
  324. uint8_t PEV_ID [SLAC_UNIQUE_ID_LEN];
  325. uint8_t PEV_MAC [ETHER_ADDR_LEN];
  326. uint8_t EVSE_ID [SLAC_UNIQUE_ID_LEN];
  327. uint8_t EVSE_MAC [ETHER_ADDR_LEN];
  328. uint8_t RunID [SLAC_RUNID_LEN];
  329. uint8_t RSVD1 [8];
  330. uint8_t NID [SLAC_NID_LEN];
  331. uint8_t RSVD2;
  332. uint8_t NMK [SLAC_NMK_LEN];
  333. }
  334. MatchVarField;
  335. }
  336. cm_slac_match_confirm;
  337. typedef struct __packed cm_atten_profile_indicate
  338. {
  339. struct ethernet_hdr ethernet;
  340. struct homeplug_fmi homeplug;
  341. uint8_t PEV_MAC [ETHER_ADDR_LEN];
  342. uint8_t NumGroups;
  343. uint8_t RSVD;
  344. uint8_t AAG [255];
  345. }
  346. cm_atten_profile_indicate;
  347. #ifndef __GNUC__
  348. #pragma pack (pop)
  349. #endif
  350. /*====================================================================*
  351. * functions;
  352. *--------------------------------------------------------------------*/
  353. signed pev_cm_slac_param (struct session *, struct channel *, struct message *);
  354. signed pev_cm_start_atten_char (struct session *, struct channel *, struct message *);
  355. signed pev_cm_atten_char (struct session *, struct channel *, struct message *);
  356. signed pev_cm_mnbc_sound (struct session *, struct channel *, struct message *);
  357. signed pev_cm_slac_match (struct session *, struct channel *, struct message *);
  358. signed pev_cm_set_key (struct session *, struct channel *, struct message *);
  359. signed evse_cm_slac_param (struct session *, struct channel *, struct message *);
  360. signed evse_cm_start_atten_char (struct session *, struct channel *, struct message *);
  361. signed evse_cm_atten_char (struct session *, struct channel *, struct message *);
  362. signed evse_cm_mnbc_sound (struct session *, struct channel *, struct message *);
  363. signed evse_cm_slac_match (struct session *, struct channel *, struct message *);
  364. signed evse_cm_set_key (struct session *, struct channel *, struct message *);
  365. signed slac_connect (struct session *);
  366. void slac_session (struct session *);
  367. void slac_structs ();
  368. signed slac_debug (struct session * session, signed status, char const * string, char const * format, ...);
  369. /*====================================================================*
  370. *
  371. *--------------------------------------------------------------------*/
  372. #endif