NetworkTraffic2.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed NetworkTraffic2 (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * generate full mesh network traffic between powerline devices on
  15. * all accessible powerline networks;
  16. *
  17. * Contributor(s):
  18. * Charles Maier <cmaier@qca.qualcomm.com>
  19. * Matthieu Poullet <m.poullet@avm.de>
  20. *
  21. *--------------------------------------------------------------------*/
  22. #ifndef NETWORKTRAFFIC2_SOURCE
  23. #define NETWORKTRAFFIC2_SOURCE
  24. #include <memory.h>
  25. #include <errno.h>
  26. #include "../tools/memory.h"
  27. #include "../tools/number.h"
  28. #include "../tools/error.h"
  29. #include "../tools/flags.h"
  30. #include "../tools/timer.h"
  31. #include "../plc/plc.h"
  32. signed NetworkTraffic2 (struct plc * plc)
  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_nw_info_request
  40. {
  41. struct ethernet_hdr ethernet;
  42. struct qualcomm_fmi qualcomm;
  43. }
  44. * request = (struct vs_nw_info_request *) (message);
  45. struct __packed vs_nw_info_confirm
  46. {
  47. struct ethernet_hdr ethernet;
  48. struct qualcomm_fmi qualcomm;
  49. uint8_t SUB_VERSION;
  50. uint8_t RESERVED;
  51. uint16_t DATA_LEN;
  52. uint8_t DATA [1];
  53. }
  54. * confirm = (struct vs_nw_info_confirm *) (message);
  55. struct __packed station
  56. {
  57. uint8_t MAC [ETHER_ADDR_LEN];
  58. uint8_t TEI;
  59. uint8_t Reserved1;
  60. uint16_t Reserved2;
  61. uint8_t BDA [ETHER_ADDR_LEN];
  62. uint16_t AVGTX;
  63. uint8_t COUPLING;
  64. uint8_t Reserved3;
  65. uint16_t AVGRX;
  66. uint16_t Reserved4;
  67. }
  68. * station;
  69. struct __packed network
  70. {
  71. uint8_t NID [7];
  72. uint8_t Reserved1 [2];
  73. uint8_t SNID;
  74. uint8_t TEI;
  75. uint8_t Reserved2 [4];
  76. uint8_t ROLE;
  77. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  78. uint8_t CCO_TEI;
  79. uint8_t Reserved3 [3];
  80. uint8_t NUMSTAS;
  81. uint8_t Reserved4 [5];
  82. struct station stations [1];
  83. }
  84. * network;
  85. struct __packed networks
  86. {
  87. uint8_t Reserved;
  88. uint8_t NUMAVLNS;
  89. struct network networks [1];
  90. }
  91. * networks = (struct networks *) (confirm->DATA);
  92. #ifndef __GNUC__
  93. #pragma pack (pop)
  94. #endif
  95. byte bridgelist [255] [ETHER_ADDR_LEN];
  96. unsigned bridges = LocalDevices (channel, message, bridgelist, sizeof (bridgelist));
  97. while (bridges--)
  98. {
  99. byte devicelist [255] [ETHER_ADDR_LEN];
  100. unsigned devices = 0;
  101. unsigned device;
  102. unsigned remote;
  103. memset (message, 0, sizeof (* message));
  104. EthernetHeader (& request->ethernet, bridgelist [bridges], channel->host, channel->type);
  105. QualcommHeader1 (& request->qualcomm, 1, (VS_NW_INFO | MMTYPE_REQ));
  106. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  107. if (SendMME (plc) <= 0)
  108. {
  109. error (0, errno, CHANNEL_CANTSEND);
  110. continue;
  111. }
  112. if (ReadMME (plc, 1, (VS_NW_INFO | MMTYPE_CNF)) <= 0)
  113. {
  114. error (0, errno, CHANNEL_CANTREAD);
  115. continue;
  116. }
  117. memcpy (devicelist [devices++], request->ethernet.OSA, sizeof (devicelist [0]));
  118. network = (struct network *) (& networks->networks);
  119. while (networks->NUMAVLNS--)
  120. {
  121. station = (struct station *) (& network->stations);
  122. while (network->NUMSTAS--)
  123. {
  124. memcpy (devicelist [devices++], station->MAC, sizeof (devicelist [0]));
  125. station++;
  126. }
  127. network = (struct network *) (station);
  128. }
  129. for (device = 1; device < devices; device++)
  130. {
  131. Transmit (plc, devicelist [0], devicelist [device]);
  132. Antiphon (plc, devicelist [device], devicelist [0]);
  133. }
  134. for (device = 1; device < devices; device++)
  135. {
  136. for (remote = 1; remote < devices; remote++)
  137. {
  138. if (remote != device)
  139. {
  140. Antiphon (plc, devicelist [device], devicelist [remote]);
  141. }
  142. }
  143. }
  144. }
  145. return (0);
  146. }
  147. #endif