evse_cm_slac_param.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 evse_cm_slac_param (struct session * session, struct channel * channel, struct message * message);
  44. *
  45. * slac.h
  46. *
  47. * EVSE-HLE listens indefinitely for a cm_slac_param request and
  48. * responds with a cm_slac_param confirm; this function should not
  49. * exit untile a cm_slac_param request so that SLAC sessions will
  50. * properly synchronize;
  51. *
  52. * unlike some other EVSE-HLE functions, this one does not check
  53. * the run identifier because this is the first point at which a
  54. * new run identifier is received; it should, however, store the
  55. * run identifier to verify future messages from the PEV;
  56. *
  57. * EVSE-HLE should copy the message OSA to the session variable PEV
  58. * MAC address; the PEV MAC address can then be used to respond in
  59. * unicast to the right PEVHLE;
  60. *
  61. * EVSE-HLE should copy the run identifier to the session variable
  62. * for use later in the session; this will be used to distinguish
  63. * one PEV-EVSE session from another;
  64. *
  65. * EVSE-HLE should copy the application type and security type to
  66. * the session variable unless it wants to operate in a mode that
  67. * is different from the PEV;
  68. *
  69. * at this point, the EVSE-HLE dictates the number of msounds and
  70. * the msound timeout;
  71. *
  72. * EVSE-HLE should set the msound target to the broadcast address;
  73. *
  74. * EVSE-HLE should set the number of sounds to 8 and the timeout
  75. * to 10 intervals of 100ms.
  76. *
  77. * EVSE-HLE may send zeros for the forwarding station since it is
  78. * not used here;
  79. *
  80. *--------------------------------------------------------------------*/
  81. #ifndef EVSE_CM_SLAC_PARAM_SOURCE
  82. #define EVSE_CM_SLAC_PARAM_SOURCE
  83. #include <stdio.h>
  84. #include <string.h>
  85. #include "../ether/channel.h"
  86. #include "../tools/types.h"
  87. #include "../tools/flags.h"
  88. #include "../tools/error.h"
  89. #include "../tools/memory.h"
  90. #include "../slac/slac.h"
  91. signed evse_cm_slac_param (struct session * session, struct channel * channel, struct message * message)
  92. {
  93. extern byte const broadcast [ETHER_ADDR_LEN];
  94. struct cm_slac_param_request * request = (struct cm_slac_param_request *) (message);
  95. struct cm_slac_param_confirm * confirm = (struct cm_slac_param_confirm *) (message);
  96. while (readmessage (channel, message, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_REQ)) > 0)
  97. {
  98. slac_debug (session, 0, __func__, "<-- CM_SLAC_PARAM.REQ");
  99. session->APPLICATION_TYPE = request->APPLICATION_TYPE;
  100. session->SECURITY_TYPE = request->SECURITY_TYPE;
  101. memcpy (session->PEV_MAC, request->ethernet.OSA, sizeof (session->PEV_MAC));
  102. memcpy (session->RunID, request->RunID, sizeof (session->RunID));
  103. #if SLAC_DEBUG
  104. if (_anyset (session->flags, SLAC_VERBOSE))
  105. {
  106. char string [256];
  107. slac_debug (session, 0, __func__, "CM_SLAC_PARAM.REQ.APPLICATION_TYPE %d", request->APPLICATION_TYPE);
  108. slac_debug (session, 0, __func__, "CM_SLAC_PARAM.REQ.SECURITY_TYPE %d", request->SECURITY_TYPE);
  109. slac_debug (session, 0, __func__, "CM_SLAC_PARAM.REQ.RunID %s", HEXSTRING (string, request->RunID));
  110. slac_debug (session, 0, __func__, "CM_SLAC_PARAM.REQ.CipherSuiteSetSize %d", request->CipherSuiteSetSize);
  111. slac_debug (session, 0, __func__, "CM_SLAC_PARAM.REQ.CipherSuite [0] %d", request->CipherSuite [0]);
  112. slac_debug (session, 0, __func__, "CM_SLAC_PARAM.REQ.CipherSuite [1] %d", request->CipherSuite [1]);
  113. }
  114. #endif
  115. if (_anyset (session->flags, SLAC_COMPARE))
  116. {
  117. if (LE16TOH (request->CipherSuite [0]) != (uint16_t) (session->counter))
  118. {
  119. slac_debug (session, session->exit, __func__, "session->counter mismatch! PEV=(%d) EVSE=(%d)", LE16TOH (request->CipherSuite [0]), session->counter);
  120. }
  121. }
  122. slac_debug (session, 0, __func__, "--> CM_SLAC_PARAM.CNF");
  123. memset (message, 0, sizeof (* message));
  124. EthernetHeader (& confirm->ethernet, session->PEV_MAC, channel->host, channel->type);
  125. HomePlugHeader1 (& confirm->homeplug, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_CNF));
  126. memcpy (confirm->MSOUND_TARGET, broadcast, sizeof (confirm->MSOUND_TARGET));
  127. confirm->NUM_SOUNDS = session->NUM_SOUNDS;
  128. confirm->TIME_OUT = session->TIME_OUT;
  129. confirm->RESP_TYPE = session->RESP_TYPE;
  130. memcpy (confirm->FORWARDING_STA, session->FORWARDING_STA, sizeof (confirm->FORWARDING_STA));
  131. confirm->APPLICATION_TYPE = session->APPLICATION_TYPE;
  132. confirm->SECURITY_TYPE = session->SECURITY_TYPE;
  133. memcpy (confirm->RunID, session->RunID, sizeof (confirm->RunID));
  134. confirm->CipherSuite = HTOLE16 ((uint16_t) (session->counter));
  135. if (sendmessage (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0)
  136. {
  137. return (slac_debug (session, 1, __func__, CHANNEL_CANTSEND));
  138. }
  139. return (0);
  140. }
  141. return (slac_debug (session, 0, __func__, "<-- CM_SLAC_PARAM.REQ ?"));
  142. }
  143. #endif