NetworkInfoStats.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * signed NetworkInfoStats (struct plc * plc);
  44. *
  45. * plc.h
  46. *
  47. * Request network membership information from the peer device using
  48. * the VS_NW_INFO_STATS message;
  49. *
  50. * This function is similar to function NetworkInformation() but the
  51. * output format is different;
  52. *
  53. *
  54. * Contributor(s):
  55. * Charles Maier
  56. *
  57. *--------------------------------------------------------------------*/
  58. #ifndef NETWORKINFOSTATS_SOURCE
  59. #define NETWORKINFOSTATS_SOURCE
  60. #include <stdint.h>
  61. #include <memory.h>
  62. #include "../plc/plc.h"
  63. #include "../tools/memory.h"
  64. #include "../tools/number.h"
  65. #include "../tools/error.h"
  66. signed NetworkInfoStats (struct plc * plc)
  67. {
  68. extern char const * StationRole [STATIONROLES];
  69. struct channel * channel = (struct channel *)(plc->channel);
  70. struct message * message = (struct message *)(plc->message);
  71. #ifndef __GNUC__
  72. #pragma pack (push,1)
  73. #endif
  74. #if defined(INT6x00)
  75. struct __packed vs_ns_info_stats_request
  76. {
  77. struct ethernet_hdr ethernet;
  78. struct qualcomm_hdr qualcomm;
  79. uint8_t FIRST_TEI;
  80. }
  81. * request = (struct vs_ns_info_stats_request *)(message);
  82. struct __packed station
  83. {
  84. uint8_t MAC [ETHER_ADDR_LEN];
  85. uint8_t TEI;
  86. uint8_t BDA [ETHER_ADDR_LEN];
  87. uint8_t AVGTX;
  88. uint8_t AVGRX;
  89. }
  90. * station;
  91. struct __packed network
  92. {
  93. uint8_t NID [7];
  94. uint8_t SNID;
  95. uint8_t TEI;
  96. uint8_t ROLE;
  97. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  98. uint8_t ACCESS uint8_t NEIGHBOR_NETWORKS;
  99. uint8_t CCO_TEI;
  100. uint8_t NUMSTAS;
  101. struct station stations [1];
  102. }
  103. * network;
  104. struct __packed vs_ns_info_stats_confirm
  105. {
  106. struct ethernet_hdr ethernet;
  107. struct qualcomm_hdr qualcomm;
  108. uint8_t FIRST_TEI;
  109. uint8_t IN_AVLN;
  110. struct network network;
  111. }
  112. * confirm = (struct vs_ns_info_stats_confirm *)(message);
  113. #elif defined (AR7x00)
  114. struct __packed vs_ns_info_stats_request
  115. {
  116. struct ethernet_hdr ethernet;
  117. struct qualcomm_fmi qualcomm;
  118. uint8_t MME_SUBVER;
  119. uint8_t RESERVED [3];
  120. uint8_t FIRST_TEI;
  121. UINT8_6 NUM_STAS;
  122. }
  123. * request = (struct vs_ns_info_stats_request *)(message);
  124. struct __packed station
  125. {
  126. uint8_t MAC [ETHER_ADDR_LEN];
  127. uint8_t TEI;
  128. uint8_t Reserved [3];
  129. uint8_t BDA [ETHER_ADDR_LEN];
  130. uint16_t AVGTX;
  131. uint8_t COUPLING;
  132. uint8_t Reserved3;
  133. uint16_t AVGRX;
  134. uint16_t Reserved4;
  135. }
  136. * station;
  137. struct __packed network
  138. {
  139. uint8_t NID [7];
  140. uint8_t Reserved1;
  141. uint8_t SNID;
  142. uint8_t TEI;
  143. uint8_t Reserved2 [2];
  144. uint8_t ROLE;
  145. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  146. uint8_t ACCESS;
  147. uint8_t NEIGHBOR_NETWORKS;
  148. uint8_t CCO_TEI;
  149. uint8_t Reserved3 [7];
  150. uint8_t NUMSTAS;
  151. uint8_t Reserved4 [5];
  152. struct station stations [1];
  153. }
  154. * network;
  155. struct __packed vs_ns_info_stats_confirm
  156. {
  157. struct ethernet_hdr ethernet;
  158. struct qualcomm_fmi qualcomm;
  159. uint8_t SUB_VERSION;
  160. uint8_t Reserved;
  161. uint16_t DATA_LEN;
  162. uint8_t FIRST_TEI;
  163. uint8_t NUM_STAS;
  164. uin16_t Reserved;
  165. uint8_t IN_AVLN;
  166. struct network network;
  167. }
  168. * confirm = (struct vs_ns_info_stats_confirm *)(message);
  169. #else
  170. #error "Unspecified Atheros chipset"
  171. #endif
  172. #ifndef __GNUC__
  173. #pragma pack (pop)
  174. #endif
  175. Request (plc, "Fetch Network Information");
  176. memset (message, 0, sizeof (* message));
  177. #if defined (INT6x00)
  178. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  179. QualcommHeader (&request->qualcomm, 0, (VS_NW_INFO_STATS | MMTYPE_REQ));
  180. #elif defined (AR7x00)
  181. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  182. QualcommHeader1 (&request->qualcomm, 1, (VS_NW_INFO_STATS | MMTYPE_REQ));
  183. #else
  184. #error "Unspecified Atheros chipset"
  185. #endif
  186. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  187. if (SendMME (plc) <= 0)
  188. {
  189. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  190. return (-1);
  191. }
  192. #if defined (INT6x00)
  193. while (ReadMME (plc, 0, (VS_NW_INFO_STATS | MMTYPE_CNF)) > 0)
  194. #elif defined (AR7x00)
  195. while (ReadMME (plc, 1, (VS_NW_INFO_STATS | MMTYPE_CNF)) > 0)
  196. #else
  197. #error "Unspecified Atheros chipset"
  198. #endif
  199. {
  200. char string [24];
  201. Confirm (plc, "Found %d Network(s)\n", networks->NUMAVLNS);
  202. network = (struct network *)(&networks->networks);
  203. while (networks->NUMAVLNS--)
  204. {
  205. printf ("\tnetwork->NID = %s\n", hexstring (string, sizeof (string), network->NID, sizeof (network->NID)));
  206. printf ("\tnetwork->SNID = %d\n", network->SNID);
  207. printf ("\tnetwork->TEI = %d\n", network->TEI);
  208. printf ("\tnetwork->ROLE = 0x%02X (%s)\n", network->ROLE, StationRole [network->ROLE]);
  209. printf ("\tnetwork->CCO_DA = %s\n", hexstring (string, sizeof (string), network->CCO_MAC, sizeof (network->CCO_MAC)));
  210. printf ("\tnetwork->CCO_TEI = %d\n", network->CCO_TEI);
  211. printf ("\tnetwork->STATIONS = %d\n", network->NUMSTAS);
  212. printf ("\n");
  213. station = (struct station *)(&network->stations);
  214. while (network->NUMSTAS--)
  215. {
  216. char * TX = "";
  217. char * RX = "";
  218. printf ("\t\tstation->MAC = %s\n", hexstring (string, sizeof (string), station->MAC, sizeof (station->MAC)));
  219. printf ("\t\tstation->TEI = %d\n", station->TEI);
  220. printf ("\t\tstation->BDA = %s\n", hexstring (string, sizeof (string), station->BDA, sizeof (station->BDA)));
  221. #if defined (AR7x00)
  222. station->AVGTX = LE16TOH (station->AVGTX);
  223. station->AVGRX = LE16TOH (station->AVGRX);
  224. TX = ((station->COUPLING >> 4) & 0x0F)? "Alternate": "Primary";
  225. RX = ((station->COUPLING >> 0) & 0x0F)? "Alternate": "Primary";
  226. #endif
  227. printf ("\t\tstation->AvgPHYDR_TX = %03d mbps %s\n", station->AVGTX, TX);
  228. printf ("\t\tstation->AvgPHYDR_RX = %03d mbps %s\n", station->AVGRX, RX);
  229. printf ("\n");
  230. station++;
  231. }
  232. network = (struct network *)(station);
  233. }
  234. }
  235. return (0);
  236. }
  237. #endif