evse_cm_slac_match.c 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed evse_cm_slac_match (struct session * session, struct channel * channel, struct message * message);
  11. *
  12. * slac.h
  13. *
  14. * receive CM_SLAC_MATCH.REQ and send CM_SLAC_MATCH.CNF containing
  15. * random NMK/NID that EVSE-HLE will use to configure EVSE-PLC for
  16. * charging;
  17. *
  18. * users must develop their own means of generating random NMK/NID
  19. * pairs because it is not part of the standard; this example does
  20. * not attempt to randomize NMK/NID;
  21. *
  22. *--------------------------------------------------------------------*/
  23. #ifndef EVSE_CM_SLAC_MATCH_SOURCE
  24. #define EVSE_CM_SLAC_MATCH_SOURCE
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "../ether/channel.h"
  28. #include "../tools/memory.h"
  29. #include "../tools/error.h"
  30. #include "../tools/flags.h"
  31. #include "../slac/slac.h"
  32. signed evse_cm_slac_match (struct session * session, struct channel * channel, struct message * message)
  33. {
  34. struct cm_slac_match_request * request = (struct cm_slac_match_request *) (message);
  35. struct cm_slac_match_confirm * confirm = (struct cm_slac_match_confirm *) (message);
  36. while (readmessage (channel, message, HOMEPLUG_MMV, (CM_SLAC_MATCH | MMTYPE_REQ)) > 0)
  37. {
  38. if (! memcmp (session->RunID, request->MatchVarField.RunID, sizeof (session->RunID)))
  39. {
  40. debug (0, __func__, "<-- CM_SLAC_MATCH.REQ");
  41. memcpy (session->PEV_ID, request->MatchVarField.PEV_ID, sizeof (session->PEV_ID));
  42. memcpy (session->PEV_MAC, request->MatchVarField.PEV_MAC, sizeof (session->PEV_MAC));
  43. memcpy (session->RunID, request->MatchVarField.RunID, sizeof (session->RunID));
  44. #if SLAC_DEBUG
  45. if (_anyset (session->flags, SLAC_VERBOSE))
  46. {
  47. char string [256];
  48. debug (0, __func__, "CM_SLAC_MATCH.REQ.APPLICATION_TYPE %d", request->APPLICATION_TYPE);
  49. debug (0, __func__, "CM_SLAC_MATCH.REQ.SECURITY_TYPE %d", request->SECURITY_TYPE);
  50. debug (0, __func__, "CM_SLAC_MATCH.REQ.MVFLength %d", LE16TOH (request->MVFLength));
  51. debug (0, __func__, "CM_SLAC_MATCH.REQ.PEV_ID %s", HEXSTRING (string, request->MatchVarField.PEV_ID));
  52. debug (0, __func__, "CM_SLAC_MATCH.REQ.PEV_MAC %s", HEXSTRING (string, request->MatchVarField.PEV_MAC));
  53. debug (0, __func__, "CM_SLAC_MATCH.REQ.EVSE_ID %s", HEXSTRING (string, request->MatchVarField.EVSE_ID));
  54. debug (0, __func__, "CM_SLAC_MATCH.REQ.EVSE_MAC %s", HEXSTRING (string, request->MatchVarField.EVSE_MAC));
  55. debug (0, __func__, "CM_SLAC_MATCH.REQ.RunID %s", HEXSTRING (string, request->MatchVarField.RunID));
  56. }
  57. #endif
  58. debug (0, __func__, "--> CM_SLAC_MATCH.CNF");
  59. memset (message, 0, sizeof (* message));
  60. EthernetHeader (& confirm->ethernet, session->PEV_MAC, channel->host, channel->type);
  61. HomePlugHeader1 (& confirm->homeplug, HOMEPLUG_MMV, (CM_SLAC_MATCH | MMTYPE_CNF));
  62. confirm->APPLICATION_TYPE = session->APPLICATION_TYPE;
  63. confirm->SECURITY_TYPE = session->SECURITY_TYPE;
  64. confirm->MVFLength = HTOLE16 (sizeof (confirm->MatchVarField));
  65. memcpy (confirm->MatchVarField.PEV_ID, session->PEV_ID, sizeof (confirm->MatchVarField.PEV_ID));
  66. memcpy (confirm->MatchVarField.PEV_MAC, session->PEV_MAC, sizeof (confirm->MatchVarField.PEV_MAC));
  67. memcpy (confirm->MatchVarField.EVSE_ID, session->EVSE_ID, sizeof (confirm->MatchVarField.EVSE_ID));
  68. memcpy (confirm->MatchVarField.EVSE_MAC, session->EVSE_MAC, sizeof (confirm->MatchVarField.EVSE_MAC));
  69. memcpy (confirm->MatchVarField.RunID, session->RunID, sizeof (confirm->MatchVarField.RunID));
  70. memcpy (confirm->MatchVarField.NID, session->NID, sizeof (confirm->MatchVarField.NID));
  71. memcpy (confirm->MatchVarField.NMK, session->NMK, sizeof (confirm->MatchVarField.NMK));
  72. if (sendmessage (channel, message, sizeof (* confirm)) <= 0)
  73. {
  74. return (debug (1, __func__, CHANNEL_CANTSEND));
  75. }
  76. return (0);
  77. }
  78. }
  79. return (debug (session->exit, __func__, "<-- CM_SLAC_MATCH.REQ ?"));
  80. }
  81. #endif