evse_cm_slac_param.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed evse_cm_slac_param (struct session * session, struct channel * channel, struct message * message);
  11. *
  12. * slac.h
  13. *
  14. * EVSE-HLE listens indefinitely for a cm_slac_param request and
  15. * responds with a cm_slac_param confirm; this function should not
  16. * exit untile a cm_slac_param request so that SLAC sessions will
  17. * properly synchronize;
  18. *
  19. * unlike some other EVSE-HLE functions, this one does not check
  20. * the run identifier because this is the first point at which a
  21. * new run identifier is received; it should, however, store the
  22. * run identifier to verify future messages from the PEV;
  23. *
  24. * EVSE-HLE should copy the message OSA to the session variable PEV
  25. * MAC address; the PEV MAC address can then be used to respond in
  26. * unicast to the right PEVHLE;
  27. *
  28. * EVSE-HLE should copy the run identifier to the session variable
  29. * for use later in the session; this will be used to distinguish
  30. * one PEV-EVSE session from another;
  31. *
  32. * EVSE-HLE should copy the application type and security type to
  33. * the session variable unless it wants to operate in a mode that
  34. * is different from the PEV;
  35. *
  36. * at this point, the EVSE-HLE dictates the number of msounds and
  37. * the msound timeout;
  38. *
  39. * EVSE-HLE should set the msound target to the broadcast address;
  40. *
  41. * EVSE-HLE should set the number of sounds to 8 and the timeout
  42. * to 10 intervals of 100ms.
  43. *
  44. * EVSE-HLE may send zeros for the forwarding station since it is
  45. * not used here;
  46. *
  47. *--------------------------------------------------------------------*/
  48. #ifndef EVSE_CM_SLAC_PARAM_SOURCE
  49. #define EVSE_CM_SLAC_PARAM_SOURCE
  50. #include <stdio.h>
  51. #include <string.h>
  52. #include "../ether/channel.h"
  53. #include "../tools/types.h"
  54. #include "../tools/flags.h"
  55. #include "../tools/error.h"
  56. #include "../tools/memory.h"
  57. #include "../slac/slac.h"
  58. signed evse_cm_slac_param (struct session * session, struct channel * channel, struct message * message)
  59. {
  60. extern byte const broadcast [ETHER_ADDR_LEN];
  61. struct cm_slac_param_request * request = (struct cm_slac_param_request *) (message);
  62. struct cm_slac_param_confirm * confirm = (struct cm_slac_param_confirm *) (message);
  63. while (readmessage (channel, message, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_REQ)) > 0)
  64. {
  65. debug (0, __func__, "<-- CM_SLAC_PARAM.REQ");
  66. session->APPLICATION_TYPE = request->APPLICATION_TYPE;
  67. session->SECURITY_TYPE = request->SECURITY_TYPE;
  68. memcpy (session->PEV_MAC, request->ethernet.OSA, sizeof (session->PEV_MAC));
  69. memcpy (session->RunID, request->RunID, sizeof (session->RunID));
  70. #if SLAC_DEBUG
  71. if (_anyset (session->flags, SLAC_VERBOSE))
  72. {
  73. char string [256];
  74. debug (0, __func__, "CM_SLAC_PARAM.REQ.APPLICATION_TYPE %d", request->APPLICATION_TYPE);
  75. debug (0, __func__, "CM_SLAC_PARAM.REQ.SECURITY_TYPE %d", request->SECURITY_TYPE);
  76. debug (0, __func__, "CM_SLAC_PARAM.REQ.RunID %s", HEXSTRING (string, request->RunID));
  77. debug (0, __func__, "CM_SLAC_PARAM.REQ.CipherSuiteSetSize %d", request->CipherSuiteSetSize);
  78. debug (0, __func__, "CM_SLAC_PARAM.REQ.CipherSuite [0] %d", request->CipherSuite [0]);
  79. debug (0, __func__, "CM_SLAC_PARAM.REQ.CipherSuite [1] %d", request->CipherSuite [1]);
  80. }
  81. #endif
  82. if (_anyset (session->flags, SLAC_COMPARE))
  83. {
  84. if (LE16TOH (request->CipherSuite [0]) != (uint16_t) (session->counter))
  85. {
  86. debug (session->exit, __func__, "session->counter mismatch! PEV=(%d) EVSE=(%d)", LE16TOH (request->CipherSuite [0]), session->counter);
  87. }
  88. }
  89. debug (0, __func__, "--> CM_SLAC_PARAM.CNF");
  90. memset (message, 0, sizeof (* message));
  91. EthernetHeader (& confirm->ethernet, session->PEV_MAC, channel->host, channel->type);
  92. HomePlugHeader1 (& confirm->homeplug, HOMEPLUG_MMV, (CM_SLAC_PARAM | MMTYPE_CNF));
  93. memcpy (confirm->MSOUND_TARGET, broadcast, sizeof (confirm->MSOUND_TARGET));
  94. confirm->NUM_SOUNDS = session->NUM_SOUNDS;
  95. confirm->TIME_OUT = session->TIME_OUT;
  96. confirm->RESP_TYPE = session->RESP_TYPE;
  97. memcpy (confirm->FORWARDING_STA, session->FORWARDING_STA, sizeof (confirm->FORWARDING_STA));
  98. confirm->APPLICATION_TYPE = session->APPLICATION_TYPE;
  99. confirm->SECURITY_TYPE = session->SECURITY_TYPE;
  100. memcpy (confirm->RunID, session->RunID, sizeof (confirm->RunID));
  101. confirm->CipherSuite = HTOLE16 ((uint16_t) (session->counter));
  102. if (sendmessage (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0)
  103. {
  104. return (debug (1, __func__, CHANNEL_CANTSEND));
  105. }
  106. return (0);
  107. }
  108. return (debug (0, __func__, "<-- CM_SLAC_PARAM.REQ ?"));
  109. }
  110. #endif