Loopback.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed Loopback (struct plc * plc, void * memory, size_t extent);
  11. *
  12. * plc.h
  13. *
  14. * instruct one powerline device to transmit the given Etherenet
  15. * frame to another for a fixed period of time using VS_FR_LNK
  16. * message;
  17. *
  18. * See the Atheros HomePlug AV Firmware Technical Reference Manual
  19. * for more information;
  20. *
  21. * Contributor(s):
  22. * Charles Maier <cmaier@qca.qualcomm.com>
  23. *
  24. *--------------------------------------------------------------------*/
  25. #ifndef LOOPBACK_SOURCE
  26. #define LOOPBACK_SOURCE
  27. #include <stdint.h>
  28. #include <memory.h>
  29. #include "../plc/plc.h"
  30. #include "../tools/error.h"
  31. #include "../tools/memory.h"
  32. signed Loopback (struct plc * plc, void * memory, size_t extent)
  33. {
  34. struct channel * channel = (struct channel *) (plc->channel);
  35. struct message * message = (struct message *) (plc->message);
  36. #ifndef __GNUC__
  37. #pragma pack (push,1)
  38. #endif
  39. struct __packed vs_fr_lbk_request
  40. {
  41. struct ethernet_hdr ethernet;
  42. struct qualcomm_hdr qualcomm;
  43. uint8_t DURATION;
  44. uint8_t RESERVED;
  45. uint16_t LENGTH;
  46. uint8_t PACKET [1038];
  47. }
  48. * request = (struct vs_fr_lbk_request *) (message);
  49. struct __packed vs_fr_lbk_confirm
  50. {
  51. struct ethernet_hdr ethernet;
  52. struct qualcomm_hdr qualcomm;
  53. uint8_t MSTATUS;
  54. uint8_t DURATION;
  55. uint16_t LENGTH;
  56. }
  57. * confirm = (struct vs_fr_lbk_confirm *) (message);
  58. #ifndef __GNUC__
  59. #pragma pack (pop)
  60. #endif
  61. memset (message, 0, sizeof (* message));
  62. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  63. QualcommHeader (& request->qualcomm, 0, (VS_FR_LBK | MMTYPE_REQ));
  64. if (extent > sizeof (request->PACKET))
  65. {
  66. extent = sizeof (request->PACKET);
  67. }
  68. memcpy (request->PACKET, memory, extent);
  69. if (extent < (ETHER_MIN_LEN - ETHER_CRC_LEN))
  70. {
  71. extent = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  72. }
  73. request->DURATION = plc->timer;
  74. request->LENGTH = HTOLE16 ((uint16_t) (extent));
  75. extent += sizeof (struct ethernet_hdr);
  76. extent += sizeof (struct qualcomm_hdr);
  77. extent += 4;
  78. plc->packetsize = (uint16_t) (extent);
  79. if (SendMME (plc) <= 0)
  80. {
  81. error (1, ECANCELED, CHANNEL_CANTSEND);
  82. }
  83. while (ReadMME (plc, 0, (VS_FR_LBK | MMTYPE_CNF)) > 0)
  84. {
  85. if (confirm->MSTATUS)
  86. {
  87. Failure (plc, PLC_WONTDOIT);
  88. continue;
  89. }
  90. }
  91. return (0);
  92. }
  93. #endif