NetworkInfoStats.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed NetworkInfoStats (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * Request network membership information from the peer device using
  15. * the VS_NW_INFO_STATS message;
  16. *
  17. * This function is similar to function NetworkInformation() but the
  18. * output format is different;
  19. *
  20. * Contributor(s):
  21. * Charles Maier <cmaier@qca.qualcomm.com>
  22. *
  23. *--------------------------------------------------------------------*/
  24. #ifndef NETWORKINFOSTATS_SOURCE
  25. #define NETWORKINFOSTATS_SOURCE
  26. #include <stdint.h>
  27. #include <memory.h>
  28. #include "../plc/plc.h"
  29. #include "../tools/memory.h"
  30. #include "../tools/number.h"
  31. #include "../tools/error.h"
  32. signed NetworkInfoStats (struct plc * plc)
  33. {
  34. extern char const * StationRole [STATIONROLES];
  35. struct channel * channel = (struct channel *) (plc->channel);
  36. struct message * message = (struct message *) (plc->message);
  37. #ifndef __GNUC__
  38. #pragma pack (push,1)
  39. #endif
  40. #if defined (INT6x00)
  41. struct __packed vs_ns_info_stats_request
  42. {
  43. struct ethernet_hdr ethernet;
  44. struct qualcomm_hdr qualcomm;
  45. uint8_t FIRST_TEI;
  46. }
  47. * request = (struct vs_ns_info_stats_request *) (message);
  48. struct __packed station
  49. {
  50. uint8_t MAC [ETHER_ADDR_LEN];
  51. uint8_t TEI;
  52. uint8_t BDA [ETHER_ADDR_LEN];
  53. uint8_t AVGTX;
  54. uint8_t AVGRX;
  55. }
  56. * station;
  57. struct __packed network
  58. {
  59. uint8_t NID [7];
  60. uint8_t SNID;
  61. uint8_t TEI;
  62. uint8_t ROLE;
  63. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  64. uint8_t ACCESS uint8_t NEIGHBOR_NETWORKS;
  65. uint8_t CCO_TEI;
  66. uint8_t NUMSTAS;
  67. struct station stations [1];
  68. }
  69. * network;
  70. struct __packed vs_ns_info_stats_confirm
  71. {
  72. struct ethernet_hdr ethernet;
  73. struct qualcomm_hdr qualcomm;
  74. uint8_t FIRST_TEI;
  75. uint8_t IN_AVLN;
  76. struct network network;
  77. }
  78. * confirm = (struct vs_ns_info_stats_confirm *) (message);
  79. #elif defined (AR7x00)
  80. struct __packed vs_ns_info_stats_request
  81. {
  82. struct ethernet_hdr ethernet;
  83. struct qualcomm_fmi qualcomm;
  84. uint8_t MME_SUBVER;
  85. uint8_t RESERVED [3];
  86. uint8_t FIRST_TEI;
  87. UINT8_6 NUM_STAS;
  88. }
  89. * request = (struct vs_ns_info_stats_request *) (message);
  90. struct __packed station
  91. {
  92. uint8_t MAC [ETHER_ADDR_LEN];
  93. uint8_t TEI;
  94. uint8_t Reserved [3];
  95. uint8_t BDA [ETHER_ADDR_LEN];
  96. uint16_t AVGTX;
  97. uint8_t COUPLING;
  98. uint8_t Reserved3;
  99. uint16_t AVGRX;
  100. uint16_t Reserved4;
  101. }
  102. * station;
  103. struct __packed network
  104. {
  105. uint8_t NID [7];
  106. uint8_t Reserved1;
  107. uint8_t SNID;
  108. uint8_t TEI;
  109. uint8_t Reserved2 [2];
  110. uint8_t ROLE;
  111. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  112. uint8_t ACCESS;
  113. uint8_t NEIGHBOR_NETWORKS;
  114. uint8_t CCO_TEI;
  115. uint8_t Reserved3 [7];
  116. uint8_t NUMSTAS;
  117. uint8_t Reserved4 [5];
  118. struct station stations [1];
  119. }
  120. * network;
  121. struct __packed vs_ns_info_stats_confirm
  122. {
  123. struct ethernet_hdr ethernet;
  124. struct qualcomm_fmi qualcomm;
  125. uint8_t SUB_VERSION;
  126. uint8_t Reserved;
  127. uint16_t DATA_LEN;
  128. uint8_t FIRST_TEI;
  129. uint8_t NUM_STAS;
  130. uin16_t Reserved;
  131. uint8_t IN_AVLN;
  132. struct network network;
  133. }
  134. * confirm = (struct vs_ns_info_stats_confirm *) (message);
  135. #else
  136. #error "Unspecified chipset"
  137. #endif
  138. #ifndef __GNUC__
  139. #pragma pack (pop)
  140. #endif
  141. Request (plc, "Fetch Network Information");
  142. memset (message, 0, sizeof (* message));
  143. #if defined (INT6x00)
  144. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  145. QualcommHeader (& request->qualcomm, 0, (VS_NW_INFO_STATS | MMTYPE_REQ));
  146. #elif defined (AR7x00)
  147. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  148. QualcommHeader1 (& request->qualcomm, 1, (VS_NW_INFO_STATS | MMTYPE_REQ));
  149. #else
  150. #error "Unspecified chipset"
  151. #endif
  152. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  153. if (SendMME (plc) <= 0)
  154. {
  155. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  156. return (-1);
  157. }
  158. #if defined (INT6x00)
  159. while (ReadMME (plc, 0, (VS_NW_INFO_STATS | MMTYPE_CNF)) > 0)
  160. #elif defined (AR7x00)
  161. while (ReadMME (plc, 1, (VS_NW_INFO_STATS | MMTYPE_CNF)) > 0)
  162. #else
  163. #error "Unspecified chipset"
  164. #endif
  165. {
  166. char string [24];
  167. Confirm (plc, "Found %d Network(s)\n", networks->NUMAVLNS);
  168. network = (struct network *) (& networks->networks);
  169. while (networks->NUMAVLNS--)
  170. {
  171. printf ("\tnetwork->NID = %s\n", hexstring (string, sizeof (string), network->NID, sizeof (network->NID)));
  172. printf ("\tnetwork->SNID = %d\n", network->SNID);
  173. printf ("\tnetwork->TEI = %d\n", network->TEI);
  174. printf ("\tnetwork->ROLE = 0x%02X (%s)\n", network->ROLE, StationRole [network->ROLE]);
  175. printf ("\tnetwork->CCO_DA = %s\n", hexstring (string, sizeof (string), network->CCO_MAC, sizeof (network->CCO_MAC)));
  176. printf ("\tnetwork->CCO_TEI = %d\n", network->CCO_TEI);
  177. printf ("\tnetwork->STATIONS = %d\n", network->NUMSTAS);
  178. printf ("\n");
  179. station = (struct station *) (& network->stations);
  180. while (network->NUMSTAS--)
  181. {
  182. static char const * coupling [] =
  183. {
  184. "Primary",
  185. "Alternate",
  186. "MIMO",
  187. ""
  188. };
  189. printf ("\t\tstation->MAC = %s\n", hexstring (string, sizeof (string), station->MAC, sizeof (station->MAC)));
  190. printf ("\t\tstation->TEI = %d\n", station->TEI);
  191. printf ("\t\tstation->BDA = %s\n", hexstring (string, sizeof (string), station->BDA, sizeof (station->BDA)));
  192. #if defined (AR7x00)
  193. station->AVGTX = LE16TOH (station->AVGTX);
  194. station->AVGRX = LE16TOH (station->AVGRX);
  195. printf ("\t\tstation->AvgPHYDR_RX = %03d mbps %s\n", station->AVGRX, coupling [(station->COUPLING >> 4) & 0x03]);
  196. printf ("\t\tstation->AvgPHYDR_TX = %03d mbps %s\n", station->AVGTX, coupling [(station->COUPLING >> 0) & 0x03]);
  197. #endif
  198. printf ("\t\tstation->AvgPHYDR_TX = %03d mbps\n");
  199. printf ("\t\tstation->AvgPHYDR_RX = %03d mbps\n");
  200. printf ("\n");
  201. station++;
  202. }
  203. network = (struct network *) (station);
  204. }
  205. }
  206. return (0);
  207. }
  208. #endif