evse_cm_slac_match.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_match (struct session * session, struct channel * channel, struct message * message);
  44. *
  45. * slac.h
  46. *
  47. * receive CM_SLAC_MATCH.REQ and send CM_SLAC_MATCH.CNF containing
  48. * random NMK/NID that EVSE-HLE will use to configure EVSE-PLC for
  49. * charging;
  50. *
  51. * users must develop their own means of generating random NMK/NID
  52. * pairs because it is not part of the standard; this example does
  53. * not attempt to randomize NMK/NID;
  54. *
  55. *--------------------------------------------------------------------*/
  56. #ifndef EVSE_CM_SLAC_MATCH_SOURCE
  57. #define EVSE_CM_SLAC_MATCH_SOURCE
  58. #include <stdio.h>
  59. #include <string.h>
  60. #include "../ether/channel.h"
  61. #include "../tools/memory.h"
  62. #include "../tools/error.h"
  63. #include "../tools/flags.h"
  64. #include "../slac/slac.h"
  65. signed evse_cm_slac_match (struct session * session, struct channel * channel, struct message * message)
  66. {
  67. struct cm_slac_match_request * request = (struct cm_slac_match_request *) (message);
  68. struct cm_slac_match_confirm * confirm = (struct cm_slac_match_confirm *) (message);
  69. while (readmessage (channel, message, HOMEPLUG_MMV, (CM_SLAC_MATCH | MMTYPE_REQ)) > 0)
  70. {
  71. if (! memcmp (session->RunID, request->MatchVarField.RunID, sizeof (session->RunID)))
  72. {
  73. slac_debug (session, 0, __func__, "<-- CM_SLAC_MATCH.REQ");
  74. memcpy (session->PEV_ID, request->MatchVarField.PEV_ID, sizeof (session->PEV_ID));
  75. memcpy (session->PEV_MAC, request->MatchVarField.PEV_MAC, sizeof (session->PEV_MAC));
  76. memcpy (session->RunID, request->MatchVarField.RunID, sizeof (session->RunID));
  77. #if SLAC_DEBUG
  78. if (_anyset (session->flags, SLAC_VERBOSE))
  79. {
  80. char string [256];
  81. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.REQ.APPLICATION_TYPE %d", request->APPLICATION_TYPE);
  82. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.REQ.SECURITY_TYPE %d", request->SECURITY_TYPE);
  83. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.REQ.MVFLength %d", LE16TOH (request->MVFLength));
  84. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.REQ.PEV_ID %s", HEXSTRING (string, request->MatchVarField.PEV_ID));
  85. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.REQ.PEV_MAC %s", HEXSTRING (string, request->MatchVarField.PEV_MAC));
  86. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.REQ.EVSE_ID %s", HEXSTRING (string, request->MatchVarField.EVSE_ID));
  87. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.REQ.EVSE_MAC %s", HEXSTRING (string, request->MatchVarField.EVSE_MAC));
  88. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.REQ.RunID %s", HEXSTRING (string, request->MatchVarField.RunID));
  89. }
  90. #endif
  91. slac_debug (session, 0, __func__, "--> CM_SLAC_MATCH.CNF");
  92. memset (message, 0, sizeof (* message));
  93. EthernetHeader (& confirm->ethernet, session->PEV_MAC, channel->host, channel->type);
  94. HomePlugHeader1 (& confirm->homeplug, HOMEPLUG_MMV, (CM_SLAC_MATCH | MMTYPE_CNF));
  95. confirm->APPLICATION_TYPE = session->APPLICATION_TYPE;
  96. confirm->SECURITY_TYPE = session->SECURITY_TYPE;
  97. confirm->MVFLength = HTOLE16 (sizeof (confirm->MatchVarField));
  98. memcpy (confirm->MatchVarField.PEV_ID, session->PEV_ID, sizeof (confirm->MatchVarField.PEV_ID));
  99. memcpy (confirm->MatchVarField.PEV_MAC, session->PEV_MAC, sizeof (confirm->MatchVarField.PEV_MAC));
  100. memcpy (confirm->MatchVarField.EVSE_ID, session->EVSE_ID, sizeof (confirm->MatchVarField.EVSE_ID));
  101. memcpy (confirm->MatchVarField.EVSE_MAC, session->EVSE_MAC, sizeof (confirm->MatchVarField.EVSE_MAC));
  102. memcpy (confirm->MatchVarField.RunID, session->RunID, sizeof (confirm->MatchVarField.RunID));
  103. memcpy (confirm->MatchVarField.NID, session->NID, sizeof (confirm->MatchVarField.NID));
  104. memcpy (confirm->MatchVarField.NMK, session->NMK, sizeof (confirm->MatchVarField.NMK));
  105. if (sendmessage (channel, message, sizeof (* confirm)) <= 0)
  106. {
  107. return (slac_debug (session, 1, __func__, CHANNEL_CANTSEND));
  108. }
  109. return (0);
  110. }
  111. }
  112. return (slac_debug (session, session->exit, __func__, "<-- CM_SLAC_MATCH.REQ ?"));
  113. }
  114. #endif