pev_cm_slac_param.c 6.9 KB

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