NetworkInformation1.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed NetworkInformation1 (struct channel * channel);
  11. *
  12. * plc.h
  13. *
  14. * Request network membership information for the peer device using
  15. * a VS_NW_INFO message;
  16. *
  17. * This function is similar to function NetworkInfo() but the output
  18. * format is different;
  19. *
  20. * See the Atheros HomePlug AV Firmware Technical Reference Manual
  21. * for more information;
  22. *
  23. * Contributor(s):
  24. * Charles Maier <cmaier@qca.qualcomm.com>
  25. *
  26. *--------------------------------------------------------------------*/
  27. #ifndef NETWORKINFORMATION1_SOURCE
  28. #define NETWORKINFORMATION1_SOURCE
  29. #include <stdint.h>
  30. #include <memory.h>
  31. #include "../plc/plc.h"
  32. #include "../tools/memory.h"
  33. #include "../tools/number.h"
  34. #include "../tools/error.h"
  35. signed NetworkInformation1 (struct plc * plc)
  36. {
  37. struct channel * channel = (struct channel *) (plc->channel);
  38. struct message * message = (struct message *) (plc->message);
  39. #ifndef __GNUC__
  40. #pragma pack (push,1)
  41. #endif
  42. struct __packed vs_nw_info_request
  43. {
  44. struct ethernet_hdr ethernet;
  45. struct qualcomm_hdr qualcomm;
  46. }
  47. * request = (struct vs_nw_info_request *) (message);
  48. struct __packed vs_nw_info_confirm
  49. {
  50. struct ethernet_hdr ethernet;
  51. struct qualcomm_hdr qualcomm;
  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 BDA [ETHER_ADDR_LEN];
  60. uint8_t AVGTX;
  61. uint8_t AVGRX;
  62. }
  63. * station;
  64. struct __packed network
  65. {
  66. uint8_t NID [7];
  67. uint8_t SNID;
  68. uint8_t TEI;
  69. uint8_t ROLE;
  70. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  71. uint8_t CCO_TEI;
  72. uint8_t NUMSTAS;
  73. struct station stations [1];
  74. }
  75. * network;
  76. struct __packed networks
  77. {
  78. uint8_t NUMAVLNS;
  79. struct network networks [1];
  80. }
  81. * networks = (struct networks *) (confirm->data);
  82. #ifndef __GNUC__
  83. #pragma pack (pop)
  84. #endif
  85. memset (message, 0, sizeof (* message));
  86. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  87. QualcommHeader (& request->qualcomm, 0, (VS_NW_INFO | MMTYPE_REQ));
  88. if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0)
  89. {
  90. error (1, errno, CHANNEL_CANTSEND);
  91. }
  92. if (readpacket (channel, message, sizeof (* message)) <= 0)
  93. {
  94. error (1, errno, CHANNEL_CANTREAD);
  95. }
  96. network = (struct network *) (& networks->networks);
  97. while (networks->NUMAVLNS--)
  98. {
  99. char string [24];
  100. printf (" NID %20s", hexstring (string, sizeof (string), network->NID, sizeof (network->NID)));
  101. printf (" SNID %03d", network->SNID);
  102. printf ("\n");
  103. printf (" %s", (network->TEI == network->CCO_TEI)? "CCO": "STA");
  104. printf (" TEI %03d", network->TEI);
  105. printf (" MAC %17s", hexstring (string, sizeof (string), request->ethernet.OSA, sizeof (request->ethernet.OSA)));
  106. printf (" BDA %17s", hexstring (string, sizeof (string), request->ethernet.ODA, sizeof (request->ethernet.ODA)));
  107. printf ("\n");
  108. station = (struct station *) (& network->stations);
  109. while (network->NUMSTAS--)
  110. {
  111. printf (" %s", (station->TEI == network->CCO_TEI)? "CCO": "STA");
  112. printf (" TEI %03d", station->TEI);
  113. printf (" MAC %17s", hexstring (string, sizeof (string), station->MAC, sizeof (station->MAC)));
  114. printf (" BDA %17s", hexstring (string, sizeof (string), station->BDA, sizeof (station->BDA)));
  115. printf (" TX %03d", station->AVGTX);
  116. printf (" RX %03d", station->AVGRX);
  117. printf ("\n");
  118. station++;
  119. }
  120. network = (struct network *) (station);
  121. }
  122. return (0);
  123. }
  124. #endif