NetworkProbe.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed NetworkProbe (struct plc * plc);
  11. *
  12. * nda.h
  13. *
  14. * detect and report neighbor networks using the VS_DIAG_PROBE
  15. * message;
  16. *
  17. * Contributor(s):
  18. * Charles Maier <cmaier@qca.qualcomm.com>
  19. *
  20. *--------------------------------------------------------------------*/
  21. #ifndef NETWORKPROBE_SOURCE
  22. #define NETWORKPROBE_SOURCE
  23. #include <stdint.h>
  24. #include <memory.h>
  25. #include "../plc/plc.h"
  26. #include "../tools/memory.h"
  27. #include "../tools/number.h"
  28. #include "../tools/error.h"
  29. #define STAMODE_MAX 3
  30. #define NETMODE_MAX 4
  31. static char const * StationMode [STAMODE_MAX] =
  32. {
  33. "Unassociated Station",
  34. "Associated not Authenticated",
  35. "Associated and Authenticated"
  36. };
  37. static char const * NetworkMode [NETMODE_MAX] =
  38. {
  39. "AVLN Only",
  40. "Shared CSMA Hybrid",
  41. "Full Hybrid",
  42. "Hybrid Delimiters"
  43. };
  44. signed NetworkProbe (struct plc * plc)
  45. {
  46. struct channel * channel = (struct channel *) (plc->channel);
  47. struct message * message = (struct message *) (plc->message);
  48. #ifndef __GNUC__
  49. #pragma pack (push,1)
  50. #endif
  51. struct __packed network
  52. {
  53. uint8_t NID [7];
  54. uint8_t SNID;
  55. uint8_t HybridMode;
  56. uint8_t NumSlots;
  57. uint8_t CoordinatingStatus;
  58. uint16_t Offset;
  59. uint8_t CCoMAC [ETHER_ADDR_LEN];
  60. uint16_t AvgPhyRate;
  61. uint8_t NumGood_Assoc_Auth;
  62. uint8_t NumBad_CouldNotAssoc;
  63. uint8_t NumBad_Assoc_Failure;
  64. uint8_t NumBad_CouldNotAuth;
  65. uint8_t NumLeave;
  66. uint8_t NumLeave_SameMaster;
  67. uint8_t NumLeave_NextMaster;
  68. uint8_t NumLeave_NeverReturn;
  69. }
  70. * network;
  71. struct __packed vs_diag_network_probe_request
  72. {
  73. struct ethernet_hdr ethernet;
  74. struct qualcomm_hdr qualcomm;
  75. uint8_t MCONTROL;
  76. }
  77. * request = (struct vs_diag_network_probe_request *) (message);
  78. struct __packed vs_diag_network_probe_confirm
  79. {
  80. struct ethernet_hdr ethernet;
  81. struct qualcomm_hdr qualcomm;
  82. uint8_t MCONTROL;
  83. uint8_t ASSOC_STATE;
  84. uint8_t SNID;
  85. uint8_t NUM_NETWORKS;
  86. struct network networks [1];
  87. }
  88. * confirm = (struct vs_diag_network_probe_confirm *) (message);
  89. #ifndef __GNUC__
  90. #pragma pack (pop)
  91. #endif
  92. Request (plc, "Network Probe");
  93. memset (message, 0, sizeof (* message));
  94. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  95. QualcommHeader (& request->qualcomm, 0, (VS_DIAG_NETWORK_PROBE | MMTYPE_REQ));
  96. request->MCONTROL = plc->action;
  97. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  98. if (SendMME (plc) <= 0)
  99. {
  100. error (PLC_EXIT (plc), ECANCELED, CHANNEL_CANTSEND);
  101. return (-1);
  102. }
  103. while (ReadMME (plc, 0, (VS_DIAG_NETWORK_PROBE | MMTYPE_CNF)) > 0)
  104. {
  105. Confirm (plc, "Found %d Network(s)\n", confirm->NUM_NETWORKS);
  106. printf ("\tstation->MODE = %s\n", StationMode [confirm->ASSOC_STATE]);
  107. printf ("\tstation->SNID = 0x%02X\n", confirm->SNID);
  108. printf ("\n");
  109. network = (struct network *) (confirm->networks);
  110. while (confirm->NUM_NETWORKS-- > 0)
  111. {
  112. char string [24];
  113. printf ("\t\tnetwork->NID = %s\n", hexstring (string, sizeof (string), network->NID, sizeof (network->NID)));
  114. printf ("\t\tnetwork->SNID = 0x%02X\n", network->SNID);
  115. printf ("\t\tnetwork->MODE = %s\n", NetworkMode [network->HybridMode]);
  116. printf ("\t\tnetwork->SLOTS = %d\n", network->NumSlots);
  117. printf ("\t\tnetwork->CCO = %s\n", hexstring (string, sizeof (string), network->CCoMAC, sizeof (network->CCoMAC)));
  118. printf ("\t\tnetwork->PHYRate = %d mbps\n", network->AvgPhyRate);
  119. printf ("\n");
  120. network++;
  121. }
  122. }
  123. return (0);
  124. }
  125. #endif