pibpeek1.c.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. pibpeek1.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='piboffset.c.html' title=' piboffset.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='pibpeek2.c.html' title=' pibpeek2.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * signed pibpeek1 (void const * memory);
  64. *
  65. * pib.h
  66. *
  67. * print PIB identity information on stdout;
  68. *
  69. *
  70. * Contributor(s):
  71. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  72. *
  73. *--------------------------------------------------------------------*/
  74. #ifndef PIBPEEK1_SOURCE
  75. #define PIBPEEK1_SOURCE
  76. #include &lt;stdio.h&gt;
  77. #include &lt;memory.h&gt;
  78. #include &quot;../tools/memory.h&quot;
  79. #include &quot;../tools/number.h&quot;
  80. #include &quot;../key/HPAVKey.h&quot;
  81. #include &quot;../key/keys.h&quot;
  82. #include &quot;../pib/pib.h&quot;
  83. static char const * CCoMode [] =
  84. {
  85. &quot;Auto&quot;,
  86. &quot;Never&quot;,
  87. &quot;Always&quot;,
  88. &quot;User&quot;,
  89. &quot;Covert&quot;,
  90. &quot;Unknown&quot;
  91. };
  92. static char const * MDURole [] =
  93. {
  94. &quot;Slave&quot;,
  95. &quot;Master&quot;
  96. };
  97. signed pibpeek1 (void const * memory)
  98. {
  99. extern const struct key keys [KEYS];
  100. extern char const * CCoMode [];
  101. extern char const * MDURole [];
  102. struct PIB1 * PIB = (struct PIB1 *)(memory);
  103. char buffer [HPAVKEY_SHA_LEN * 3];
  104. size_t key;
  105. if (PIB-&gt;FWVersion == 1)
  106. {
  107. if (PIB-&gt;PIBVersion == 2)
  108. {
  109. struct PIB1_2 * PIB = (struct PIB1_2 *)(memory);
  110. printf (&quot;\tPIB %d-%d\n&quot;, PIB-&gt;FWVersion, PIB-&gt;PIBVersion);
  111. printf (&quot;\tMAC %s\n&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;MAC, sizeof (PIB-&gt;MAC)));
  112. printf (&quot;\tDAK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;DAK, sizeof (PIB-&gt;DAK)));
  113. for (key = 0; key &lt; KEYS; key++)
  114. {
  115. if (!memcmp (keys [key].DAK, PIB-&gt;DAK, HPAVKEY_DAK_LEN))
  116. {
  117. printf (&quot; (%s)&quot;, keys [key].phrase);
  118. break;
  119. }
  120. }
  121. printf (&quot;\n&quot;);
  122. printf (&quot;\tNMK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;NMK, sizeof (PIB-&gt;NMK)));
  123. for (key = 0; key &lt; KEYS; key++)
  124. {
  125. if (!memcmp (keys [key].NMK, PIB-&gt;NMK, HPAVKEY_NMK_LEN))
  126. {
  127. printf (&quot; (%s)&quot;, keys [key].phrase);
  128. break;
  129. }
  130. }
  131. printf (&quot;\n&quot;);
  132. printf (&quot;\tFLG %s\n&quot;, hexstring (buffer, sizeof (buffer), (uint8_t *)(&amp;PIB-&gt;FLG), sizeof (PIB-&gt;FLG)));
  133. return (0);
  134. }
  135. else if (PIB-&gt;PIBVersion == 3)
  136. {
  137. struct PIB1_3 * PIB = (struct PIB1_3 *)(memory);
  138. printf (&quot;\tPIB %d-%d\n&quot;, PIB-&gt;FWVersion, PIB-&gt;PIBVersion);
  139. printf (&quot;\tMAC %s\n&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;MAC, sizeof (PIB-&gt;MAC)));
  140. printf (&quot;\tDAK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;DAK, sizeof (PIB-&gt;DAK)));
  141. for (key = 0; key &lt; KEYS; key++)
  142. {
  143. if (!memcmp (keys [key].DAK, PIB-&gt;DAK, HPAVKEY_DAK_LEN))
  144. {
  145. printf (&quot; (%s)&quot;, keys [key].phrase);
  146. break;
  147. }
  148. }
  149. printf (&quot;\n&quot;);
  150. printf (&quot;\tNMK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;NMK, sizeof (PIB-&gt;NMK)));
  151. for (key = 0; key &lt; KEYS; key++)
  152. {
  153. if (!memcmp (keys [key].NMK, PIB-&gt;NMK, HPAVKEY_NMK_LEN))
  154. {
  155. printf (&quot; (%s)&quot;, keys [key].phrase);
  156. break;
  157. }
  158. }
  159. printf (&quot;\n&quot;);
  160. printf (&quot;\tNET \&quot;%s\&quot;\n&quot;, PIB-&gt;NET);
  161. printf (&quot;\tMFG \&quot;%s\&quot;\n&quot;, PIB-&gt;MFG);
  162. printf (&quot;\tUSR \&quot;%s\&quot;\n&quot;, PIB-&gt;USR);
  163. return (0);
  164. }
  165. else if (PIB-&gt;PIBVersion &gt;= 4)
  166. {
  167. struct PIB1_4 * PIB = (struct PIB1_4 *)(memory);
  168. printf (&quot;\tPIB %d-%d %d bytes\n&quot;, PIB-&gt;VersionHeader.FWVersion, PIB-&gt;VersionHeader.PIBVersion, LE16TOH (PIB-&gt;VersionHeader.PIBLength));
  169. printf (&quot;\tMAC %s\n&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.MAC, sizeof (PIB-&gt;LocalDeviceConfig.MAC)));
  170. printf (&quot;\tDAK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.DAK, sizeof (PIB-&gt;LocalDeviceConfig.DAK)));
  171. for (key = 0; key &lt; KEYS; key++)
  172. {
  173. if (!memcmp (keys [key].DAK, PIB-&gt;LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  174. {
  175. printf (&quot; (%s)&quot;, keys [key].phrase);
  176. break;
  177. }
  178. }
  179. printf (&quot;\n&quot;);
  180. printf (&quot;\tNMK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.NMK, sizeof (PIB-&gt;LocalDeviceConfig.NMK)));
  181. for (key = 0; key &lt; KEYS; key++)
  182. {
  183. if (!memcmp (keys [key].NMK, PIB-&gt;LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  184. {
  185. printf (&quot; (%s)&quot;, keys [key].phrase);
  186. break;
  187. }
  188. }
  189. printf (&quot;\n&quot;);
  190. printf (&quot;\tNET %s\n&quot;, PIB-&gt;LocalDeviceConfig.NET);
  191. printf (&quot;\tMFG %s\n&quot;, PIB-&gt;LocalDeviceConfig.MFG);
  192. printf (&quot;\tUSR %s\n&quot;, PIB-&gt;LocalDeviceConfig.USR);
  193. return (0);
  194. }
  195. }
  196. else if (PIB-&gt;FWVersion == 2)
  197. {
  198. struct PIB2_0 * PIB = (struct PIB2_0 *)(memory);
  199. printf (&quot;\tPIB %d-%d %d bytes\n&quot;, PIB-&gt;VersionHeader.FWVersion, PIB-&gt;VersionHeader.PIBVersion, LE16TOH (PIB-&gt;VersionHeader.PIBLength));
  200. printf (&quot;\tMAC %s\n&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.MAC, sizeof (PIB-&gt;LocalDeviceConfig.MAC)));
  201. printf (&quot;\tDAK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.DAK, sizeof (PIB-&gt;LocalDeviceConfig.DAK)));
  202. for (key = 0; key &lt; KEYS; key++)
  203. {
  204. if (!memcmp (keys [key].DAK, PIB-&gt;LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  205. {
  206. printf (&quot; (%s)&quot;, keys [key].phrase);
  207. break;
  208. }
  209. }
  210. printf (&quot;\n&quot;);
  211. printf (&quot;\tNMK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.NMK, sizeof (PIB-&gt;LocalDeviceConfig.NMK)));
  212. for (key = 0; key &lt; KEYS; key++)
  213. {
  214. if (!memcmp (keys [key].NMK, PIB-&gt;LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  215. {
  216. printf (&quot; (%s)&quot;, keys [key].phrase);
  217. break;
  218. }
  219. }
  220. printf (&quot;\n&quot;);
  221. printf (&quot;\tNID %s\n&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.PreferredNID, sizeof (PIB-&gt;LocalDeviceConfig.PreferredNID)));
  222. printf (&quot;\tNET %s\n&quot;, PIB-&gt;LocalDeviceConfig.NET);
  223. printf (&quot;\tMFG %s\n&quot;, PIB-&gt;LocalDeviceConfig.MFG);
  224. printf (&quot;\tUSR %s\n&quot;, PIB-&gt;LocalDeviceConfig.USR);
  225. return (0);
  226. }
  227. else if (PIB-&gt;FWVersion &lt; 8)
  228. {
  229. struct PIB3_0 * PIB = (struct PIB3_0 *)(memory);
  230. printf (&quot;\tPIB %d-%d %d bytes\n&quot;, PIB-&gt;VersionHeader.FWVersion, PIB-&gt;VersionHeader.PIBVersion, LE16TOH (PIB-&gt;VersionHeader.PIBLength));
  231. printf (&quot;\tMAC %s\n&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.MAC, sizeof (PIB-&gt;LocalDeviceConfig.MAC)));
  232. printf (&quot;\tDAK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.DAK, sizeof (PIB-&gt;LocalDeviceConfig.DAK)));
  233. for (key = 0; key &lt; KEYS; key++)
  234. {
  235. if (!memcmp (keys [key].DAK, PIB-&gt;LocalDeviceConfig.DAK, HPAVKEY_DAK_LEN))
  236. {
  237. printf (&quot; (%s)&quot;, keys [key].phrase);
  238. break;
  239. }
  240. }
  241. printf (&quot;\n&quot;);
  242. printf (&quot;\tNMK %s&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.NMK, sizeof (PIB-&gt;LocalDeviceConfig.NMK)));
  243. for (key = 0; key &lt; KEYS; key++)
  244. {
  245. if (!memcmp (keys [key].NMK, PIB-&gt;LocalDeviceConfig.NMK, HPAVKEY_NMK_LEN))
  246. {
  247. printf (&quot; (%s)&quot;, keys [key].phrase);
  248. break;
  249. }
  250. }
  251. printf (&quot;\n&quot;);
  252. printf (&quot;\tNID %s\n&quot;, hexstring (buffer, sizeof (buffer), PIB-&gt;LocalDeviceConfig.PreferredNID, sizeof (PIB-&gt;LocalDeviceConfig.PreferredNID)));
  253. printf (&quot;\tNET %s\n&quot;, PIB-&gt;LocalDeviceConfig.NET);
  254. printf (&quot;\tMFG %s\n&quot;, PIB-&gt;LocalDeviceConfig.MFG);
  255. printf (&quot;\tUSR %s\n&quot;, PIB-&gt;LocalDeviceConfig.USR);
  256. printf (&quot;\tCCo %s\n&quot;, CCoMode [PIB-&gt;LocalDeviceConfig.CCoSelection &gt; SIZEOF (CCoMode)-1?SIZEOF (CCoMode)-1:PIB-&gt;LocalDeviceConfig.CCoSelection]);
  257. printf (&quot;\tMDU %s\n&quot;, PIB-&gt;LocalDeviceConfig.MDUConfiguration? MDURole [PIB-&gt;LocalDeviceConfig.MDURole &amp; 1]: &quot;N/A&quot;);
  258. return (0);
  259. }
  260. printf (&quot;\tPIB %d-%d %d (unsupported)\n&quot;, PIB-&gt;FWVersion, PIB-&gt;PIBVersion, LE16TOH (PIB-&gt;PIBLength));
  261. return (1);
  262. }
  263. #endif
  264. </pre>
  265. <div class='footerlink'>
  266. [<a href='piboffset.c.html' title=' piboffset.c '>PREV</a>]
  267. [<a href='toolkit.html' title=' Index '>HOME</a>]
  268. [<a href='pibpeek2.c.html' title=' pibpeek2.c '>NEXT</a>]
  269. </div>
  270. </body>
  271. </html>