pev_cm_slac_match.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_match (struct session * session, struct channel * channel, struct message * message);
  44. *
  45. * slac.h
  46. *
  47. * send CM_SLAC_MATCH.REQ and receive CM_SLAC_MATCH.CNF; store NMK
  48. * and NID in the session variable so that PEV-HLE can configure
  49. * PEV-PLC to form a network with EVSE-PLC;
  50. *
  51. *--------------------------------------------------------------------*/
  52. #ifndef PEV_CM_SLAC_MATCH_SOURCE
  53. #define PEV_CM_SLAC_MATCH_SOURCE
  54. #include <string.h>
  55. #include <errno.h>
  56. #include "../ether/channel.h"
  57. #include "../tools/memory.h"
  58. #include "../tools/error.h"
  59. #include "../tools/flags.h"
  60. #include "../slac/slac.h"
  61. signed pev_cm_slac_match (struct session * session, struct channel * channel, struct message * message)
  62. {
  63. struct cm_slac_match_request * request = (struct cm_slac_match_request *) (message);
  64. struct cm_slac_match_confirm * confirm = (struct cm_slac_match_confirm *) (message);
  65. slac_debug (session, 0, __func__, "--> CM_SLAC_MATCH.REQ");
  66. memset (message, 0, sizeof (* message));
  67. EthernetHeader (& request->ethernet, session->EVSE_MAC, channel->host, channel->type);
  68. HomePlugHeader1 (& request->homeplug, HOMEPLUG_MMV, (CM_SLAC_MATCH | MMTYPE_REQ));
  69. request->APPLICATION_TYPE = session->APPLICATION_TYPE;
  70. request->SECURITY_TYPE = session->SECURITY_TYPE;
  71. request->MVFLength = HTOLE16 (sizeof (request->MatchVarField));
  72. memcpy (request->MatchVarField.PEV_ID, session->PEV_ID, sizeof (request->MatchVarField.PEV_ID));
  73. memcpy (request->MatchVarField.PEV_MAC, session->PEV_MAC, sizeof (request->MatchVarField.PEV_MAC));
  74. memcpy (request->MatchVarField.EVSE_MAC, session->EVSE_MAC, sizeof (request->MatchVarField.EVSE_MAC));
  75. memcpy (request->MatchVarField.RunID, session->RunID, sizeof (request->MatchVarField.RunID));
  76. if (sendmessage (channel, message, sizeof (* request)) <= 0)
  77. {
  78. return (slac_debug (session, 1, __func__, CHANNEL_CANTSEND));
  79. }
  80. if (readmessage (channel, message, HOMEPLUG_MMV, (CM_SLAC_MATCH | MMTYPE_CNF)) > 0)
  81. {
  82. if (! memcmp (session->RunID, confirm->MatchVarField.RunID, sizeof (session->RunID)))
  83. {
  84. slac_debug (session, 0, __func__, "<-- CM_SLAC_MATCH.CNF");
  85. #if SLAC_DEBUG
  86. if (_anyset (session->flags, SLAC_VERBOSE))
  87. {
  88. char string [256];
  89. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.APPLICATION_TYPE %d", confirm->APPLICATION_TYPE);
  90. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.SECURITY_TYPE %d", confirm->SECURITY_TYPE);
  91. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.MVFLength %d", LE16TOH (confirm->MVFLength));
  92. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.MatchVarField.PEV_ID %s", HEXSTRING (string, confirm->MatchVarField.PEV_ID));
  93. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.MatchVarField.PEV_MAC %s", HEXSTRING (string, confirm->MatchVarField.PEV_MAC));
  94. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.MatchVarField.EVSE_ID %s", HEXSTRING (string, confirm->MatchVarField.EVSE_ID));
  95. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.MatchVarField.EVSE_MAC %s", HEXSTRING (string, confirm->MatchVarField.EVSE_MAC));
  96. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.MatchVarField.RunID %s", HEXSTRING (string, confirm->MatchVarField.RunID));
  97. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.MatchVarField.NID %s", HEXSTRING (string, confirm->MatchVarField.NID));
  98. slac_debug (session, 0, __func__, "CM_SLAC_MATCH.CNF.MatchVarField.NMK %s", HEXSTRING (string, confirm->MatchVarField.NMK));
  99. }
  100. #endif
  101. memcpy (session->EVSE_ID, confirm->MatchVarField.EVSE_ID, sizeof (session->EVSE_ID));
  102. memcpy (session->NMK, confirm->MatchVarField.NMK, sizeof (session->NMK));
  103. memcpy (session->NID, confirm->MatchVarField.NID, sizeof (session->NID));
  104. return (0);
  105. }
  106. }
  107. return (slac_debug (session, session->exit, __func__, "<-- CM_SLAC_MATCH.CNF ?"));
  108. }
  109. #endif