pibpeek1.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 pibpeek1 (void const * memory);
  44. *
  45. * pib.h
  46. *
  47. * print PIB identity information on stdout;
  48. *
  49. *
  50. * Contributor(s):
  51. * Charles Maier
  52. *
  53. *--------------------------------------------------------------------*/
  54. #ifndef PIBPEEK1_SOURCE
  55. #define PIBPEEK1_SOURCE
  56. #include <stdio.h>
  57. #include <memory.h>
  58. #include "../tools/memory.h"
  59. #include "../tools/number.h"
  60. #include "../key/HPAVKey.h"
  61. #include "../key/keys.h"
  62. #include "../pib/pib.h"
  63. static char const * CCoMode [] =
  64. {
  65. "Auto",
  66. "Never",
  67. "Always",
  68. "User",
  69. "Covert",
  70. "Unknown"
  71. };
  72. static char const * MDURole [] =
  73. {
  74. "Slave",
  75. "Master"
  76. };
  77. signed pibpeek1 (void const * memory)
  78. {
  79. extern const struct key keys [KEYS];
  80. extern char const * CCoMode [];
  81. extern char const * MDURole [];
  82. struct PIB1 * PIB = (struct PIB1 *)(memory);
  83. char buffer [HPAVKEY_SHA_LEN * 3];
  84. size_t key;
  85. if (PIB->FWVersion == 1)
  86. {
  87. if (PIB->PIBVersion == 2)
  88. {
  89. struct PIB1_2 * PIB = (struct PIB1_2 *)(memory);
  90. printf ("\tPIB %d-%d\n", PIB->FWVersion, PIB->PIBVersion);
  91. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->MAC, sizeof (PIB->MAC)));
  92. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->DAK, sizeof (PIB->DAK)));
  93. for (key = 0; key < KEYS; key++)
  94. {
  95. if (!memcmp (keys [key].DAK, PIB->DAK, HPAVKEY_DAK_LEN))
  96. {
  97. printf (" (%s)", keys [key].phrase);
  98. break;
  99. }
  100. }
  101. printf ("\n");
  102. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->NMK, sizeof (PIB->NMK)));
  103. for (key = 0; key < KEYS; key++)
  104. {
  105. if (!memcmp (keys [key].NMK, PIB->NMK, HPAVKEY_NMK_LEN))
  106. {
  107. printf (" (%s)", keys [key].phrase);
  108. break;
  109. }
  110. }
  111. printf ("\n");
  112. printf ("\tFLG %s\n", hexstring (buffer, sizeof (buffer), (uint8_t *)(&PIB->FLG), sizeof (PIB->FLG)));
  113. return (0);
  114. }
  115. else if (PIB->PIBVersion == 3)
  116. {
  117. struct PIB1_3 * PIB = (struct PIB1_3 *)(memory);
  118. printf ("\tPIB %d-%d\n", PIB->FWVersion, PIB->PIBVersion);
  119. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->MAC, sizeof (PIB->MAC)));
  120. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->DAK, sizeof (PIB->DAK)));
  121. for (key = 0; key < KEYS; key++)
  122. {
  123. if (!memcmp (keys [key].DAK, PIB->DAK, HPAVKEY_DAK_LEN))
  124. {
  125. printf (" (%s)", keys [key].phrase);
  126. break;
  127. }
  128. }
  129. printf ("\n");
  130. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->NMK, sizeof (PIB->NMK)));
  131. for (key = 0; key < KEYS; key++)
  132. {
  133. if (!memcmp (keys [key].NMK, PIB->NMK, HPAVKEY_NMK_LEN))
  134. {
  135. printf (" (%s)", keys [key].phrase);
  136. break;
  137. }
  138. }
  139. printf ("\n");
  140. printf ("\tNET \"%s\"\n", PIB->NET);
  141. printf ("\tMFG \"%s\"\n", PIB->MFG);
  142. printf ("\tUSR \"%s\"\n", PIB->USR);
  143. return (0);
  144. }
  145. else if (PIB->PIBVersion >= 4)
  146. {
  147. struct PIB1_4 * PIB = (struct PIB1_4 *)(memory);
  148. printf ("\tPIB %d-%d %d bytes\n", PIB->VersionHeader.FWVersion, PIB->VersionHeader.PIBVersion, LE16TOH (PIB->VersionHeader.PIBLength));
  149. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.MAC, sizeof (PIB->LocalDeviceConfig.MAC)));
  150. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.DAK, sizeof (PIB->LocalDeviceConfig.DAK)));
  151. for (key = 0; key < KEYS; key++)
  152. {
  153. if (!memcmp (keys [key].DAK, PIB->LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  154. {
  155. printf (" (%s)", keys [key].phrase);
  156. break;
  157. }
  158. }
  159. printf ("\n");
  160. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.NMK, sizeof (PIB->LocalDeviceConfig.NMK)));
  161. for (key = 0; key < KEYS; key++)
  162. {
  163. if (!memcmp (keys [key].NMK, PIB->LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  164. {
  165. printf (" (%s)", keys [key].phrase);
  166. break;
  167. }
  168. }
  169. printf ("\n");
  170. printf ("\tNET %s\n", PIB->LocalDeviceConfig.NET);
  171. printf ("\tMFG %s\n", PIB->LocalDeviceConfig.MFG);
  172. printf ("\tUSR %s\n", PIB->LocalDeviceConfig.USR);
  173. return (0);
  174. }
  175. }
  176. else if (PIB->FWVersion == 2)
  177. {
  178. struct PIB2_0 * PIB = (struct PIB2_0 *)(memory);
  179. printf ("\tPIB %d-%d %d bytes\n", PIB->VersionHeader.FWVersion, PIB->VersionHeader.PIBVersion, LE16TOH (PIB->VersionHeader.PIBLength));
  180. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.MAC, sizeof (PIB->LocalDeviceConfig.MAC)));
  181. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.DAK, sizeof (PIB->LocalDeviceConfig.DAK)));
  182. for (key = 0; key < KEYS; key++)
  183. {
  184. if (!memcmp (keys [key].DAK, PIB->LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  185. {
  186. printf (" (%s)", keys [key].phrase);
  187. break;
  188. }
  189. }
  190. printf ("\n");
  191. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.NMK, sizeof (PIB->LocalDeviceConfig.NMK)));
  192. for (key = 0; key < KEYS; key++)
  193. {
  194. if (!memcmp (keys [key].NMK, PIB->LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  195. {
  196. printf (" (%s)", keys [key].phrase);
  197. break;
  198. }
  199. }
  200. printf ("\n");
  201. printf ("\tNID %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.PreferredNID, sizeof (PIB->LocalDeviceConfig.PreferredNID)));
  202. printf ("\tSecurity level %u\n", (PIB->LocalDeviceConfig.PreferredNID[HPAVKEY_NID_LEN-1] >> 4) & 3);
  203. printf ("\tNET %s\n", PIB->LocalDeviceConfig.NET);
  204. printf ("\tMFG %s\n", PIB->LocalDeviceConfig.MFG);
  205. printf ("\tUSR %s\n", PIB->LocalDeviceConfig.USR);
  206. return (0);
  207. }
  208. else if (PIB->FWVersion < 8)
  209. {
  210. struct PIB3_0 * PIB = (struct PIB3_0 *)(memory);
  211. printf ("\tPIB %d-%d %d bytes\n", PIB->VersionHeader.FWVersion, PIB->VersionHeader.PIBVersion, LE16TOH (PIB->VersionHeader.PIBLength));
  212. printf ("\tMAC %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.MAC, sizeof (PIB->LocalDeviceConfig.MAC)));
  213. printf ("\tDAK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.DAK, sizeof (PIB->LocalDeviceConfig.DAK)));
  214. for (key = 0; key < KEYS; key++)
  215. {
  216. if (!memcmp (keys [key].DAK, PIB->LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  217. {
  218. printf (" (%s)", keys [key].phrase);
  219. break;
  220. }
  221. }
  222. printf ("\n");
  223. printf ("\tNMK %s", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.NMK, sizeof (PIB->LocalDeviceConfig.NMK)));
  224. for (key = 0; key < KEYS; key++)
  225. {
  226. if (!memcmp (keys [key].NMK, PIB->LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  227. {
  228. printf (" (%s)", keys [key].phrase);
  229. break;
  230. }
  231. }
  232. printf ("\n");
  233. printf ("\tNID %s\n", hexstring (buffer, sizeof (buffer), PIB->LocalDeviceConfig.PreferredNID, sizeof (PIB->LocalDeviceConfig.PreferredNID)));
  234. printf ("\tSecurity level %u\n", (PIB->LocalDeviceConfig.PreferredNID[HPAVKEY_NID_LEN-1] >> 4) & 3);
  235. printf ("\tNET %s\n", PIB->LocalDeviceConfig.NET);
  236. printf ("\tMFG %s\n", PIB->LocalDeviceConfig.MFG);
  237. printf ("\tUSR %s\n", PIB->LocalDeviceConfig.USR);
  238. printf ("\tCCo %s\n", CCoMode [PIB->LocalDeviceConfig.CCoSelection > SIZEOF (CCoMode)-1?SIZEOF (CCoMode)-1:PIB->LocalDeviceConfig.CCoSelection]);
  239. printf ("\tMDU %s\n", PIB->LocalDeviceConfig.MDUConfiguration? MDURole [PIB->LocalDeviceConfig.MDURole & 1]: "N/A");
  240. return (0);
  241. }
  242. printf ("\tPIB %d-%d %d (unsupported)\n", PIB->FWVersion, PIB->PIBVersion, LE16TOH (PIB->PIBLength));
  243. return (1);
  244. }
  245. #endif