Traffic2.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed Traffic2 (struct plc * plc);
  11. *
  12. * generate bi-directional traffic between a local device and all
  13. * remote devices on a powerline network; remote devices need not
  14. * be connected; no traffic is generated between remote devices;
  15. *
  16. * this function is similar to NetworkTraffic but takes less time
  17. * since not all powerline paths are exercised and those that are
  18. * can be exercised in parallel;
  19. *
  20. * this function is for AR7x00 chipsets due to chipset design
  21. * changes; use Traffic1 for INT6x00 chipsets;
  22. *
  23. * Contributor(s):
  24. * Charles Maier <cmaier@qca.qualcomm.com>
  25. * Matthieu Poullet <m.poullet@avm.de>
  26. *
  27. *--------------------------------------------------------------------*/
  28. #ifndef TRAFFIC2_SOURCE
  29. #define TRAFFIC2_SOURCE
  30. #include <memory.h>
  31. #include <errno.h>
  32. #include "../tools/memory.h"
  33. #include "../tools/error.h"
  34. #include "../tools/flags.h"
  35. #include "../tools/timer.h"
  36. #include "../mme/mme.h"
  37. #include "../plc/plc.h"
  38. signed Traffic2 (struct plc * plc)
  39. {
  40. struct channel * channel = (struct channel *) (plc->channel);
  41. struct message * message = (struct message *) (plc->message);
  42. #ifndef __GNUC__
  43. #pragma pack (push,1)
  44. #endif
  45. struct __packed vs_nw_info_request
  46. {
  47. struct ethernet_hdr ethernet;
  48. struct qualcomm_fmi qualcomm;
  49. }
  50. * request = (struct vs_nw_info_request *) (message);
  51. struct __packed vs_nw_info_confirm
  52. {
  53. struct ethernet_hdr ethernet;
  54. struct qualcomm_fmi qualcomm;
  55. uint8_t SUB_VERSION;
  56. uint8_t Reserved;
  57. uint16_t DATA_LEN;
  58. uint8_t DATA [1];
  59. }
  60. * confirm = (struct vs_nw_info_confirm *) (message);
  61. struct __packed station
  62. {
  63. uint8_t MAC [ETHER_ADDR_LEN];
  64. uint8_t TEI;
  65. uint8_t Reserved [3];
  66. uint8_t BDA [ETHER_ADDR_LEN];
  67. uint16_t AVGTX;
  68. uint8_t COUPLING;
  69. uint8_t Reserved3;
  70. uint16_t AVGRX;
  71. uint16_t Reserved4;
  72. }
  73. * station;
  74. struct __packed network
  75. {
  76. uint8_t NID [7];
  77. uint8_t Reserved1 [2];
  78. uint8_t SNID;
  79. uint8_t TEI;
  80. uint8_t Reserved2 [4];
  81. uint8_t ROLE;
  82. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  83. uint8_t CCO_TEI;
  84. uint8_t Reserved3 [3];
  85. uint8_t NUMSTAS;
  86. uint8_t Reserved4 [5];
  87. struct station stations [1];
  88. }
  89. * network;
  90. struct __packed networks
  91. {
  92. uint8_t Reserved;
  93. uint8_t NUMAVLNS;
  94. struct network networks [1];
  95. }
  96. * networks = (struct networks *) (confirm->DATA);
  97. #ifndef __GNUC__
  98. #pragma pack (pop)
  99. #endif
  100. byte bridgelist [255] [ETHER_ADDR_LEN];
  101. unsigned bridges = LocalDevices (channel, message, bridgelist, sizeof (bridgelist));
  102. while (bridges--)
  103. {
  104. byte devicelist [255] [ETHER_ADDR_LEN];
  105. unsigned devices = 0;
  106. memset (message, 0, sizeof (* message));
  107. EthernetHeader (& request->ethernet, bridgelist [bridges], channel->host, channel->type);
  108. QualcommHeader1 (& request->qualcomm, 1, (VS_NW_INFO | MMTYPE_REQ));
  109. plc->packetsize = ETHER_MIN_LEN - ETHER_CRC_LEN;
  110. if (SendMME (plc) <= 0)
  111. {
  112. error (0, errno, CHANNEL_CANTSEND);
  113. continue;
  114. }
  115. if (ReadMME (plc, 1, (VS_NW_INFO | MMTYPE_CNF)) <= 0)
  116. {
  117. error (0, errno, CHANNEL_CANTREAD);
  118. continue;
  119. }
  120. memcpy (devicelist [devices++], request->ethernet.OSA, sizeof (devicelist [0]));
  121. network = (struct network *) (& networks->networks);
  122. while (networks->NUMAVLNS--)
  123. {
  124. station = (struct station *) (& network->stations);
  125. while (network->NUMSTAS--)
  126. {
  127. memcpy (devicelist [devices++], station->MAC, sizeof (devicelist [0]));
  128. station++;
  129. }
  130. network = (struct network *) (station);
  131. }
  132. while (devices-- > 1)
  133. {
  134. Transmit (plc, devicelist [0], devicelist [devices]);
  135. Antiphon (plc, devicelist [devices], devicelist [0]);
  136. sleep (1);
  137. }
  138. }
  139. return (0);
  140. }
  141. #endif