Traffic1.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed Traffic1 (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 INT6x00 chipsets only due to changes in chip
  21. * design; use Traffic2 for AR7x00 chipsets;
  22. *
  23. * Contributor(s):
  24. * Charles Maier <cmaier@qca.qualcomm.com>
  25. * Matthieu Poullet <m.poullet@avm.de>
  26. *
  27. *--------------------------------------------------------------------*/
  28. #ifndef TRAFFIC1_SOURCE
  29. #define TRAFFIC1_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 "../mme/mme.h"
  36. #include "../plc/plc.h"
  37. signed Traffic1 (struct plc * plc)
  38. {
  39. struct channel * channel = (struct channel *) (plc->channel);
  40. struct message * message = (struct message *) (plc->message);
  41. #ifndef __GNUC__
  42. #pragma pack (push,1)
  43. #endif
  44. struct __packed vs_nw_info_request
  45. {
  46. struct ethernet_hdr ethernet;
  47. struct qualcomm_hdr qualcomm;
  48. }
  49. * request = (struct vs_nw_info_request *) (message);
  50. struct __packed vs_nw_info_confirm
  51. {
  52. struct ethernet_hdr ethernet;
  53. struct qualcomm_hdr qualcomm;
  54. uint8_t DATA [1];
  55. }
  56. * confirm = (struct vs_nw_info_confirm *) (message);
  57. struct __packed station
  58. {
  59. uint8_t MAC [ETHER_ADDR_LEN];
  60. uint8_t TEI;
  61. uint8_t BDA [ETHER_ADDR_LEN];
  62. uint8_t AVGTX;
  63. uint8_t AVGRX;
  64. }
  65. * station;
  66. struct __packed network
  67. {
  68. uint8_t NID [7];
  69. uint8_t SNID;
  70. uint8_t TEI;
  71. uint8_t ROLE;
  72. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  73. uint8_t CCO_TEI;
  74. uint8_t NUMSTAS;
  75. struct station stations [1];
  76. }
  77. * network;
  78. struct __packed networks
  79. {
  80. uint8_t NUMAVLNS;
  81. struct network networks [1];
  82. }
  83. * networks = (struct networks *) (confirm->DATA);
  84. #ifndef __GNUC__
  85. #pragma pack (pop)
  86. #endif
  87. byte bridgelist [255] [ETHER_ADDR_LEN];
  88. unsigned bridges = LocalDevices (channel, message, bridgelist, sizeof (bridgelist));
  89. while (bridges--)
  90. {
  91. byte devicelist [255] [ETHER_ADDR_LEN];
  92. unsigned devices = 0;
  93. memset (message, 0, sizeof (* message));
  94. EthernetHeader (& request->ethernet, bridgelist [bridges], channel->host, channel->type);
  95. QualcommHeader (& request->qualcomm, 0, (VS_NW_INFO | MMTYPE_REQ));
  96. plc->packetsize = ETHER_MIN_LEN - ETHER_CRC_LEN;
  97. if (SendMME (plc) <= 0)
  98. {
  99. error (0, errno, CHANNEL_CANTSEND);
  100. continue;
  101. }
  102. if (ReadMME (plc, 0, (VS_NW_INFO | MMTYPE_CNF)) <= 0)
  103. {
  104. error (0, errno, CHANNEL_CANTREAD);
  105. continue;
  106. }
  107. memcpy (devicelist [devices++], request->ethernet.OSA, sizeof (devicelist [0]));
  108. network = (struct network *) (& networks->networks);
  109. while (networks->NUMAVLNS--)
  110. {
  111. station = (struct station *) (& network->stations);
  112. while (network->NUMSTAS--)
  113. {
  114. memcpy (devicelist [devices++], station->MAC, sizeof (devicelist [0]));
  115. station++;
  116. }
  117. network = (struct network *) (station);
  118. }
  119. while (devices-- > 1)
  120. {
  121. Transmit (plc, devicelist [0], devicelist [devices]);
  122. Antiphon (plc, devicelist [devices], devicelist [0]);
  123. sleep (1);
  124. }
  125. }
  126. return (0);
  127. }
  128. #endif