lightning_pib_peek.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed lightning_pib_peek (void const * memory);
  11. *
  12. * pib.h
  13. *
  14. * print PIB identity information on stdout;
  15. *
  16. * Contributor(s):
  17. * Charles Maier <cmaier@qca.qualcomm.com>
  18. *
  19. *--------------------------------------------------------------------*/
  20. #ifndef LIGHTNING_PIB_PEEK_SOURCE
  21. #define LIGHTNING_PIB_PEEK_SOURCE
  22. #include <stdio.h>
  23. #include <memory.h>
  24. #include "../tools/memory.h"
  25. #include "../tools/number.h"
  26. #include "../key/HPAVKey.h"
  27. #include "../key/keys.h"
  28. #include "../pib/pib.h"
  29. static char const * CCoMode [] =
  30. {
  31. "Auto",
  32. "Never",
  33. "Always",
  34. "User",
  35. "Covert",
  36. "Unknown"
  37. };
  38. static char const * MDURole [] =
  39. {
  40. "Slave",
  41. "Master"
  42. };
  43. signed lightning_pib_peek (void const * memory)
  44. {
  45. extern const struct key keys [KEYS];
  46. struct PIB1 * PIB = (struct PIB1 *) (memory);
  47. char buffer [HPAVKEY_SHA_LEN * 3];
  48. size_t key;
  49. if (PIB->FWVersion == 1)
  50. {
  51. if (PIB->PIBVersion == 2)
  52. {
  53. struct PIB1_2 * PIB = (struct PIB1_2 *) (memory);
  54. printf ("\tPIB %d-%d\n", PIB->FWVersion, PIB->PIBVersion);
  55. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->MAC, sizeof (PIB->MAC)));
  56. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->DAK, sizeof (PIB->DAK)));
  57. for (key = 0; key < KEYS; key++)
  58. {
  59. if (! memcmp (keys [key].DAK, PIB->DAK, HPAVKEY_DAK_LEN))
  60. {
  61. printf (" (%s)", keys [key].phrase);
  62. break;
  63. }
  64. }
  65. printf ("\n");
  66. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->NMK, sizeof (PIB->NMK)));
  67. for (key = 0; key < KEYS; key++)
  68. {
  69. if (! memcmp (keys [key].NMK, PIB->NMK, HPAVKEY_NMK_LEN))
  70. {
  71. printf (" (%s)", keys [key].phrase);
  72. break;
  73. }
  74. }
  75. printf ("\n");
  76. printf ("\tFLG %s\n", hexstring (buffer, sizeof (buffer), (uint8_t *) (& PIB->FLG), sizeof (PIB->FLG)));
  77. return (0);
  78. }
  79. else if (PIB->PIBVersion == 3)
  80. {
  81. struct PIB1_3 * PIB = (struct PIB1_3 *) (memory);
  82. printf ("\tPIB %d-%d\n", PIB->FWVersion, PIB->PIBVersion);
  83. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->MAC, sizeof (PIB->MAC)));
  84. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->DAK, sizeof (PIB->DAK)));
  85. for (key = 0; key < KEYS; key++)
  86. {
  87. if (! memcmp (keys [key].DAK, PIB->DAK, HPAVKEY_DAK_LEN))
  88. {
  89. printf (" (%s)", keys [key].phrase);
  90. break;
  91. }
  92. }
  93. printf ("\n");
  94. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->NMK, sizeof (PIB->NMK)));
  95. for (key = 0; key < KEYS; key++)
  96. {
  97. if (! memcmp (keys [key].NMK, PIB->NMK, HPAVKEY_NMK_LEN))
  98. {
  99. printf (" (%s)", keys [key].phrase);
  100. break;
  101. }
  102. }
  103. printf ("\n");
  104. printf ("\tNET \"%s\"\n", PIB->NET);
  105. printf ("\tMFG \"%s\"\n", PIB->MFG);
  106. printf ("\tUSR \"%s\"\n", PIB->USR);
  107. return (0);
  108. }
  109. else if (PIB->PIBVersion >= 4)
  110. {
  111. struct PIB1_4 * PIB = (struct PIB1_4 *) (memory);
  112. printf ("\tPIB %d-%d %d bytes\n", PIB->VersionHeader.FWVersion, PIB->VersionHeader.PIBVersion, LE16TOH (PIB->VersionHeader.PIBLength));
  113. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.MAC, sizeof (PIB->LocalDeviceConfig.MAC)));
  114. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.DAK, sizeof (PIB->LocalDeviceConfig.DAK)));
  115. for (key = 0; key < KEYS; key++)
  116. {
  117. if (! memcmp (keys [key].DAK, PIB->LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  118. {
  119. printf (" (%s)", keys [key].phrase);
  120. break;
  121. }
  122. }
  123. printf ("\n");
  124. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.NMK, sizeof (PIB->LocalDeviceConfig.NMK)));
  125. for (key = 0; key < KEYS; key++)
  126. {
  127. if (! memcmp (keys [key].NMK, PIB->LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  128. {
  129. printf (" (%s)", keys [key].phrase);
  130. break;
  131. }
  132. }
  133. printf ("\n");
  134. printf ("\tNET %s\n", PIB->LocalDeviceConfig.NET);
  135. printf ("\tMFG %s\n", PIB->LocalDeviceConfig.MFG);
  136. printf ("\tUSR %s\n", PIB->LocalDeviceConfig.USR);
  137. return (0);
  138. }
  139. }
  140. else if (PIB->FWVersion == 2)
  141. {
  142. struct PIB2_0 * PIB = (struct PIB2_0 *) (memory);
  143. printf ("\tPIB %d-%d %d bytes\n", PIB->VersionHeader.FWVersion, PIB->VersionHeader.PIBVersion, LE16TOH (PIB->VersionHeader.PIBLength));
  144. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.MAC, sizeof (PIB->LocalDeviceConfig.MAC)));
  145. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.DAK, sizeof (PIB->LocalDeviceConfig.DAK)));
  146. for (key = 0; key < KEYS; key++)
  147. {
  148. if (! memcmp (keys [key].DAK, PIB->LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  149. {
  150. printf (" (%s)", keys [key].phrase);
  151. break;
  152. }
  153. }
  154. printf ("\n");
  155. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.NMK, sizeof (PIB->LocalDeviceConfig.NMK)));
  156. for (key = 0; key < KEYS; key++)
  157. {
  158. if (! memcmp (keys [key].NMK, PIB->LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  159. {
  160. printf (" (%s)", keys [key].phrase);
  161. break;
  162. }
  163. }
  164. printf ("\n");
  165. printf ("\tNID %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.PreferredNID, sizeof (PIB->LocalDeviceConfig.PreferredNID)));
  166. printf ("\tNET %s\n", PIB->LocalDeviceConfig.NET);
  167. printf ("\tMFG %s\n", PIB->LocalDeviceConfig.MFG);
  168. printf ("\tUSR %s\n", PIB->LocalDeviceConfig.USR);
  169. return (0);
  170. }
  171. else if (PIB->FWVersion < 8)
  172. {
  173. struct PIB3_0 * PIB = (struct PIB3_0 *) (memory);
  174. printf ("\tPIB %d-%d %d bytes\n", PIB->VersionHeader.FWVersion, PIB->VersionHeader.PIBVersion, LE16TOH (PIB->VersionHeader.PIBLength));
  175. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.MAC, sizeof (PIB->LocalDeviceConfig.MAC)));
  176. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.DAK, sizeof (PIB->LocalDeviceConfig.DAK)));
  177. for (key = 0; key < KEYS; key++)
  178. {
  179. if (! memcmp (keys [key].DAK, PIB->LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  180. {
  181. printf (" (%s)", keys [key].phrase);
  182. break;
  183. }
  184. }
  185. printf ("\n");
  186. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.NMK, sizeof (PIB->LocalDeviceConfig.NMK)));
  187. for (key = 0; key < KEYS; key++)
  188. {
  189. if (! memcmp (keys [key].NMK, PIB->LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  190. {
  191. printf (" (%s)", keys [key].phrase);
  192. break;
  193. }
  194. }
  195. printf ("\n");
  196. printf ("\tNID %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.PreferredNID, sizeof (PIB->LocalDeviceConfig.PreferredNID)));
  197. printf ("\tNET %s\n", PIB->LocalDeviceConfig.NET);
  198. printf ("\tMFG %s\n", PIB->LocalDeviceConfig.MFG);
  199. printf ("\tUSR %s\n", PIB->LocalDeviceConfig.USR);
  200. printf ("\tCCo %s\n", CCoMode [PIB->LocalDeviceConfig.CCoSelection > SIZEOF (CCoMode) - 1? SIZEOF (CCoMode) - 1: PIB->LocalDeviceConfig.CCoSelection]);
  201. printf ("\tMDU %s\n", PIB->LocalDeviceConfig.MDUConfiguration? MDURole [PIB->LocalDeviceConfig.MDURole & 1]: "N/A");
  202. return (0);
  203. }
  204. printf ("\tPIB %d-%d %d (unsupported)\n", PIB->FWVersion, PIB->PIBVersion, LE16TOH (PIB->PIBLength));
  205. return (1);
  206. }
  207. #endif