pev_cm_slac_param.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. * signed pev_cm_slac_param (struct session * session, struct channel * channel, struct message * message);
  11. *
  12. * slac.h
  13. *
  14. * PEV-HLE broadcasts cm_slac_param requests until at least one
  15. * matching cm_slac_param confirm is received; matching confirm
  16. * has the same run identifier; EVSE-HLE returns information to
  17. * the PEV-HLE;
  18. *
  19. * return 0 on success, -1 on error and 1 on timeout;
  20. *
  21. * this interaction effectivey synchronizes the PEV-HLE and one
  22. * or more EVSE-HLEs by initiating the SLAC protocol sequence;
  23. *
  24. * MSOUND-TARGET will be FF:FF:FF:FF:FF:FF for SLAC;
  25. * NUM_SOUNDS will be 8 for SLAC;
  26. * TIME_OUT will be 10 for SLAC;
  27. * RESP_TYPE will be 00 for SLAC (???);
  28. * FORWARDING_STA will be 00:00:00:00:00:00 for SLAC when RESP_TYPE=0;
  29. * APPLICATION_TYPE will be 0 for SLAC;
  30. * SECUTITY_TYPE will be 0 for this application;
  31. * RunID will be that defined by PEV-HLE;
  32. *
  33. * send cm_slac_param request then wait up to channel.timeout
  34. * milliseconds for a cm_slac_param confirm having the same
  35. * RunID as the request; the application type and security
  36. * type should be the same as in the request;
  37. *
  38. * save the msound target, forwarding station, number of sounds,
  39. * sounding timeout and response type for use later in the session;
  40. *
  41. * the forwarding stations is a vague concept; the specification
  42. * authors say it should be FF:FF:FF:FF:FF:FF but here, the EVSE-HLE
  43. * will set it to the PEV MAC;
  44. *
  45. *--------------------------------------------------------------------*/
  46. #ifndef PEV_CM_SLAC_PARAM_SOURCE
  47. #define PEV_CM_SLAC_PARAM_SOURCE
  48. #include <string.h>
  49. #include <errno.h>
  50. #include "../ether/channel.h"
  51. #include "../tools/memory.h"
  52. #include "../tools/error.h"
  53. #include "../tools/flags.h"
  54. #include "../slac/slac.h"
  55. signed pev_cm_slac_param (struct session * session, struct channel * channel, struct message * message)
  56. {
  57. extern byte const broadcast [ETHER_ADDR_LEN];
  58. struct cm_slac_param_request * request = (struct cm_slac_param_request *) (message);
  59. struct cm_slac_param_confirm * confirm = (struct cm_slac_param_confirm *) (message);
  60. debug (0, __func__, "--> CM_SLAC_PARAM.REQ");
  61. memset (message, 0, sizeof (* message));
  62. EthernetHeader (& request->ethernet, broadcast, channel->host, channel->type);
  63. HomePlugHeader1 (& request->homeplug, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_REQ));
  64. request->APPLICATION_TYPE = session->APPLICATION_TYPE;
  65. request->SECURITY_TYPE = session->SECURITY_TYPE;
  66. memcpy (request->RunID, session->RunID, sizeof (request->RunID));
  67. request->CipherSuite [0] = HTOLE16 ((uint16_t) (session->counter));
  68. if (sendmessage (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0)
  69. {
  70. return (debug (1, __func__, CHANNEL_CANTSEND));
  71. }
  72. while (readmessage (channel, message, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_CNF)) > 0)
  73. {
  74. if (! memcmp (session->RunID, confirm->RunID, sizeof (session->RunID)))
  75. {
  76. debug (0, __func__, "<-- CM_SLAC_PARAM.CNF");
  77. if (confirm->APPLICATION_TYPE != session->APPLICATION_TYPE)
  78. {
  79. debug (session->exit, __func__, "Unexpected APPLICATION_TYPE");
  80. }
  81. if (confirm->SECURITY_TYPE != session->SECURITY_TYPE)
  82. {
  83. debug (session->exit, __func__, "Unexpected SECURITY_TYPE");
  84. }
  85. if (_anyset (session->flags, SLAC_COMPARE))
  86. {
  87. if (LE16TOH (confirm->CipherSuite) != (uint16_t) (session->counter))
  88. {
  89. debug (session->exit, __func__, "session->counter mismatch! PEV=(%d) EVSE=(%d)", LE16TOH (confirm->CipherSuite), session->counter);
  90. }
  91. }
  92. #if SLAC_DEBUG
  93. if (_anyset (session->flags, SLAC_VERBOSE))
  94. {
  95. char string [256];
  96. debug (0, __func__, "CM_SLAC_PARAM.CNF.MSOUND_TARGET %s", HEXSTRING (string, confirm->MSOUND_TARGET));
  97. debug (0, __func__, "CM_SLAC_PARAM.CNF.NUM_SOUNDS %d", confirm->NUM_SOUNDS);
  98. debug (0, __func__, "CM_SLAC_PARAM.CNF.TIME_OUT %d", confirm->TIME_OUT);
  99. debug (0, __func__, "CM_SLAC_PARAM.CNF.RESP_TYPE %d", confirm->RESP_TYPE);
  100. debug (0, __func__, "CM_SLAC_PARAM.CNF.FORWARDING_STA %s", HEXSTRING (string, confirm->FORWARDING_STA));
  101. debug (0, __func__, "CM_SLAC_PARAM.CNF.APPLICATION_TYPE %d", confirm->APPLICATION_TYPE);
  102. debug (0, __func__, "CM_SLAC_PARAM.CNF.SECURITY_TYPE %d", confirm->SECURITY_TYPE);
  103. debug (0, __func__, "CM_SLAC_PARAM.CNF.RunID %s", HEXSTRING (string, confirm->RunID));
  104. debug (0, __func__, "CM_SLAC_PARAM.CNF.CipherSuite %d", confirm->CipherSuite);
  105. }
  106. #endif
  107. memcpy (session->FORWARDING_STA, confirm->FORWARDING_STA, sizeof (session->FORWARDING_STA));
  108. memcpy (session->MSOUND_TARGET, confirm->MSOUND_TARGET, sizeof (session->MSOUND_TARGET));
  109. session->NUM_SOUNDS = confirm->NUM_SOUNDS;
  110. session->TIME_OUT = confirm->TIME_OUT;
  111. session->RESP_TYPE = confirm->RESP_TYPE;
  112. return (0);
  113. }
  114. }
  115. return (debug (0, __func__, "<-- CM_SLAC_PARAM.CNF ?"));
  116. }
  117. signed pev_cm_slac_param_req(struct session* session, struct channel* channel, struct message* message)
  118. {
  119. extern byte const broadcast[ETHER_ADDR_LEN];
  120. struct cm_slac_param_request* request = (struct cm_slac_param_request*)(message);
  121. debug(0, __func__, "--> CM_SLAC_PARAM.REQ");
  122. memset(message, 0, sizeof(*message));
  123. EthernetHeader(&request->ethernet, broadcast, channel->host, channel->type);
  124. HomePlugHeader1(&request->homeplug, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_REQ));
  125. request->APPLICATION_TYPE = session->APPLICATION_TYPE;
  126. request->SECURITY_TYPE = session->SECURITY_TYPE;
  127. memcpy(request->RunID, session->RunID, sizeof(request->RunID));
  128. request->CipherSuite[0] = HTOLE16((uint16_t)(session->counter));
  129. if (sendmessage(channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0)
  130. {
  131. return (debug(1, __func__, CHANNEL_CANTSEND));
  132. }
  133. return 0;
  134. }
  135. signed pev_cm_slac_param_cnf(struct session* session, struct channel* channel, struct message* message)
  136. {
  137. struct cm_slac_param_confirm* confirm = (struct cm_slac_param_confirm*)(message);
  138. if (!memcmp(session->RunID, confirm->RunID, sizeof(session->RunID)))
  139. {
  140. debug(0, __func__, "<-- CM_SLAC_PARAM.CNF");
  141. if (confirm->APPLICATION_TYPE != session->APPLICATION_TYPE)
  142. {
  143. debug(session->exit, __func__, "Unexpected APPLICATION_TYPE");
  144. }
  145. if (confirm->SECURITY_TYPE != session->SECURITY_TYPE)
  146. {
  147. debug(session->exit, __func__, "Unexpected SECURITY_TYPE");
  148. }
  149. if (_anyset(session->flags, SLAC_COMPARE))
  150. {
  151. if (LE16TOH(confirm->CipherSuite) != (uint16_t)(session->counter))
  152. {
  153. debug(session->exit, __func__, "session->counter mismatch! PEV=(%d) EVSE=(%d)", LE16TOH(confirm->CipherSuite), session->counter);
  154. }
  155. }
  156. #if SLAC_DEBUG
  157. if (_anyset(session->flags, SLAC_VERBOSE))
  158. {
  159. char string[256];
  160. debug(0, __func__, "CM_SLAC_PARAM.CNF.MSOUND_TARGET %s", HEXSTRING(string, confirm->MSOUND_TARGET));
  161. debug(0, __func__, "CM_SLAC_PARAM.CNF.NUM_SOUNDS %d", confirm->NUM_SOUNDS);
  162. debug(0, __func__, "CM_SLAC_PARAM.CNF.TIME_OUT %d", confirm->TIME_OUT);
  163. debug(0, __func__, "CM_SLAC_PARAM.CNF.RESP_TYPE %d", confirm->RESP_TYPE);
  164. debug(0, __func__, "CM_SLAC_PARAM.CNF.FORWARDING_STA %s", HEXSTRING(string, confirm->FORWARDING_STA));
  165. debug(0, __func__, "CM_SLAC_PARAM.CNF.APPLICATION_TYPE %d", confirm->APPLICATION_TYPE);
  166. debug(0, __func__, "CM_SLAC_PARAM.CNF.SECURITY_TYPE %d", confirm->SECURITY_TYPE);
  167. debug(0, __func__, "CM_SLAC_PARAM.CNF.RunID %s", HEXSTRING(string, confirm->RunID));
  168. debug(0, __func__, "CM_SLAC_PARAM.CNF.CipherSuite %d", confirm->CipherSuite);
  169. }
  170. #endif
  171. memcpy(session->FORWARDING_STA, confirm->FORWARDING_STA, sizeof(session->FORWARDING_STA));
  172. memcpy(session->MSOUND_TARGET, confirm->MSOUND_TARGET, sizeof(session->MSOUND_TARGET));
  173. session->NUM_SOUNDS = confirm->NUM_SOUNDS;
  174. session->TIME_OUT = confirm->TIME_OUT;
  175. session->RESP_TYPE = confirm->RESP_TYPE;
  176. return (0);
  177. }
  178. return (debug(0, __func__, "<-- CM_SLAC_PARAM.CNF ?"));
  179. }
  180. #endif