NetworkTraffic1.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed NetworkTraffic1 (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 NETWORKTRAFFIC1_SOURCE
  23. #define NETWORKTRAFFIC1_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 "../plc/plc.h"
  31. signed NetworkTraffic1 (struct plc * plc)
  32. {
  33. struct channel * channel = (struct channel *) (plc->channel);
  34. struct message * message = (struct message *) (plc->message);
  35. #ifndef __GNUC__
  36. #pragma pack (push,1)
  37. #endif
  38. struct __packed vs_nw_info_request
  39. {
  40. struct ethernet_hdr ethernet;
  41. struct qualcomm_hdr qualcomm;
  42. }
  43. * request = (struct vs_nw_info_request *) (message);
  44. struct __packed vs_nw_info_confirm
  45. {
  46. struct ethernet_hdr ethernet;
  47. struct qualcomm_hdr qualcomm;
  48. uint8_t DATA [1];
  49. }
  50. * confirm = (struct vs_nw_info_confirm *) (message);
  51. struct __packed station
  52. {
  53. uint8_t MAC [ETHER_ADDR_LEN];
  54. uint8_t TEI;
  55. uint8_t BDA [ETHER_ADDR_LEN];
  56. uint8_t AVGTX;
  57. uint8_t AVGRX;
  58. }
  59. * station;
  60. struct __packed network
  61. {
  62. uint8_t NID [7];
  63. uint8_t SNID;
  64. uint8_t TEI;
  65. uint8_t ROLE;
  66. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  67. uint8_t CCO_TEI;
  68. uint8_t NUMSTAS;
  69. struct station stations [1];
  70. }
  71. * network;
  72. struct __packed networks
  73. {
  74. uint8_t NUMAVLNS;
  75. struct network networks [1];
  76. }
  77. * networks = (struct networks *) (confirm->DATA);
  78. #ifndef __GNUC__
  79. #pragma pack (pop)
  80. #endif
  81. byte bridgelist [255] [ETHER_ADDR_LEN];
  82. unsigned bridges = LocalDevices (channel, message, bridgelist, sizeof (bridgelist));
  83. while (bridges--)
  84. {
  85. byte devicelist [255] [ETHER_ADDR_LEN];
  86. unsigned devices = 0;
  87. unsigned device;
  88. unsigned remote;
  89. memset (message, 0, sizeof (* message));
  90. EthernetHeader (& request->ethernet, bridgelist [bridges], channel->host, channel->type);
  91. QualcommHeader (& request->qualcomm, 0, (VS_NW_INFO | MMTYPE_REQ));
  92. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  93. if (SendMME (plc) <= 0)
  94. {
  95. error (0, errno, CHANNEL_CANTSEND);
  96. continue;
  97. }
  98. if (ReadMME (plc, 0, (VS_NW_INFO | MMTYPE_CNF)) <= 0)
  99. {
  100. error (0, errno, CHANNEL_CANTREAD);
  101. continue;
  102. }
  103. memcpy (devicelist [devices++], request->ethernet.OSA, sizeof (devicelist [0]));
  104. network = (struct network *) (& networks->networks);
  105. while (networks->NUMAVLNS--)
  106. {
  107. station = (struct station *) (& network->stations);
  108. while (network->NUMSTAS--)
  109. {
  110. memcpy (devicelist [devices++], station->MAC, sizeof (devicelist [0]));
  111. station++;
  112. }
  113. network = (struct network *) (station);
  114. }
  115. for (device = 1; device < devices; device++)
  116. {
  117. Transmit (plc, devicelist [0], devicelist [device]);
  118. Antiphon (plc, devicelist [device], devicelist [0]);
  119. }
  120. for (device = 1; device < devices; device++)
  121. {
  122. for (remote = 1; remote < devices; remote++)
  123. {
  124. if (remote != device)
  125. {
  126. Antiphon (plc, devicelist [device], devicelist [remote]);
  127. }
  128. }
  129. }
  130. }
  131. return (0);
  132. }
  133. #endif