pib2xml.c.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. pib2xml.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='PhyRates.c.html' title=' PhyRates.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='pibcomp.c.html' title=' pibcomp.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. * pib2xml.c
  64. *
  65. *
  66. *--------------------------------------------------------------------*/
  67. /*====================================================================*
  68. * system header files;
  69. *--------------------------------------------------------------------*/
  70. #include &lt;stdio.h&gt;
  71. #include &lt;stdlib.h&gt;
  72. #include &lt;unistd.h&gt;
  73. #include &lt;ctype.h&gt;
  74. #include &lt;errno.h&gt;
  75. /*====================================================================*
  76. * custom header files;
  77. *--------------------------------------------------------------------*/
  78. #include &quot;../tools/getoptv.h&quot;
  79. #include &quot;../tools/putoptv.h&quot;
  80. #include &quot;../tools/version.h&quot;
  81. #include &quot;../tools/endian.h&quot;
  82. #include &quot;../tools/format.h&quot;
  83. #include &quot;../tools/files.h&quot;
  84. #include &quot;../tools/chars.h&quot;
  85. #include &quot;../tools/error.h&quot;
  86. #include &quot;../tools/flags.h&quot;
  87. #include &quot;../nodes/node.h&quot;
  88. #include &quot;../nvm/nvm.h&quot;
  89. #include &quot;../pib/pib.h&quot;
  90. /*====================================================================*
  91. * custom source files;
  92. *--------------------------------------------------------------------*/
  93. #ifndef MAKEFILE
  94. #include &quot;../tools/getoptv.c&quot;
  95. #include &quot;../tools/putoptv.c&quot;
  96. #include &quot;../tools/version.c&quot;
  97. #include &quot;../tools/hexview.c&quot;
  98. #include &quot;../tools/output.c&quot;
  99. #include &quot;../tools/error.c&quot;
  100. #include &quot;../tools/checksum32.c&quot;
  101. #include &quot;../tools/fdchecksum32.c&quot;
  102. #endif
  103. #ifndef MAKEFILE
  104. #include &quot;../nvm/nvmseek2.c&quot;
  105. #endif
  106. #ifndef MAKEFILE
  107. #include &quot;../nodes/xmlschema.c&quot;
  108. #endif
  109. /*====================================================================*
  110. *
  111. * void pibdump (signed fd, char const * filename, char const * schema, unsigned extent, flag_t flags);
  112. *
  113. *
  114. *
  115. *--------------------------------------------------------------------*/
  116. static void pibdump (signed fd, char const * filename, char const * schema, unsigned extent, flag_t flags)
  117. {
  118. unsigned offset = 0;
  119. signed indent = 0;
  120. signed length = 0;
  121. unsigned lineno = 1;
  122. char symbol [0x0100];
  123. char string [0x0400];
  124. char * sp;
  125. signed c;
  126. output (indent++, &quot;&lt;%s xmlns:xsi='%s' xsi:noNamespaceSchemaLocation='%s'&gt;&quot;, DATA_OBJECT, XML_NAMESPACE, schema);
  127. while ((c = getc (stdin)) != EOF)
  128. {
  129. if ((c == '#') || (c == ';'))
  130. {
  131. do
  132. {
  133. c = getc (stdin);
  134. }
  135. while (nobreak (c));
  136. }
  137. if (isspace (c))
  138. {
  139. if (c == '\n')
  140. {
  141. lineno++;
  142. }
  143. continue;
  144. }
  145. if (c == '+')
  146. {
  147. do { c = getc (stdin); } while (isblank (c));
  148. }
  149. length = 0;
  150. while (isdigit (c))
  151. {
  152. length *= 10;
  153. length += c - '0';
  154. c = getc (stdin);
  155. }
  156. while (isblank (c))
  157. {
  158. c = getc (stdin);
  159. }
  160. sp = symbol;
  161. if (isalpha (c) || (c == '_'))
  162. {
  163. do
  164. {
  165. *sp++ = (char)(c);
  166. c = getc (stdin);
  167. }
  168. while (isident (c));
  169. }
  170. *sp = (char)(0);
  171. while (isblank (c))
  172. {
  173. c = getc (stdin);
  174. }
  175. if (c == '[')
  176. {
  177. #if 0
  178. *sp++ = (char)(c);
  179. #endif
  180. c = getc (stdin);
  181. while (isblank (c))
  182. {
  183. c = getc (stdin);
  184. }
  185. while (isdigit (c))
  186. {
  187. #if 0
  188. *sp++ = (char)(c);
  189. #endif
  190. c = getc (stdin);
  191. }
  192. while (isblank (c))
  193. {
  194. c = getc (stdin);
  195. }
  196. if (c != ']')
  197. {
  198. error (1, EINVAL, &quot;Have '%c' but need ']'&quot;, c);
  199. }
  200. #if 0
  201. *sp++ = (char)(c);
  202. #endif
  203. c = getc (stdin);
  204. }
  205. *sp = (char)(0);
  206. while (isblank (c))
  207. {
  208. c = getc (stdin);
  209. }
  210. sp = string;
  211. while (nobreak (c))
  212. {
  213. *sp++ = (char)(c);
  214. c = getc (stdin);
  215. }
  216. *sp = (char)(0);
  217. if (length &gt; 0)
  218. {
  219. #if defined (WIN32)
  220. byte * buffer = (byte *)(emalloc (length));
  221. #else
  222. byte buffer [length];
  223. #endif
  224. if (read (fd, buffer, length) == length)
  225. {
  226. output (indent++, &quot;&lt;%s name='%s'&gt;&quot;, DATA_MEMBER, symbol);
  227. #if 0
  228. if (*string)
  229. {
  230. output (indent++, &quot;&lt;text&gt;&quot;);
  231. output (indent, &quot;%s&quot;, string);
  232. output (indent--, &quot;&lt;/text&gt;&quot;);
  233. }
  234. #endif
  235. output (indent++, &quot;&lt;%s&gt;&quot;, DATA_OFFSET);
  236. output (indent, &quot;%04X&quot;, offset);
  237. output (indent--, &quot;&lt;/%s&gt;&quot;, DATA_OFFSET);
  238. output (indent++, &quot;&lt;%s&gt;&quot;, DATA_LENGTH);
  239. output (indent, &quot;%d&quot;, length);
  240. output (indent--, &quot;&lt;/%s&gt;&quot;, DATA_LENGTH);
  241. output (indent++, &quot;&lt;%s&gt;&quot;, DATA_MEMORY);
  242. for (c = 0; c &lt; indent; c++)
  243. {
  244. printf (&quot;\t&quot;);
  245. }
  246. for (c = 0; c &lt; length; c++)
  247. {
  248. printf (&quot;%02X&quot;, buffer [c]);
  249. }
  250. printf (&quot;\n&quot;);
  251. output (indent--, &quot;&lt;/%s&gt;&quot;, DATA_MEMORY);
  252. output (indent--, &quot;&lt;/%s&gt;&quot;, DATA_MEMBER);
  253. }
  254. #if defined (WIN32)
  255. free (buffer);
  256. #endif
  257. }
  258. offset += length;
  259. }
  260. output (indent--, &quot;&lt;/%s&gt;&quot;, DATA_OBJECT);
  261. if (_allclr (flags, PIB_SILENCE))
  262. {
  263. if (offset != extent)
  264. {
  265. error (0, 0, &quot;file %s is %d not %d bytes&quot;, filename, extent, offset);
  266. }
  267. }
  268. return;
  269. }
  270. /*====================================================================*
  271. *
  272. * int main (int argc, char const * argv []);
  273. *
  274. *
  275. *
  276. *--------------------------------------------------------------------*/
  277. int main (int argc, char const * argv [])
  278. {
  279. static char const * optv [] =
  280. {
  281. &quot;f:x&quot;,
  282. &quot;file [file] [...]&quot;,
  283. &quot;Qualcomm Atheros Parameter File XML Dump Utility&quot;,
  284. &quot;f f\tobject definition file&quot;,
  285. &quot;x\tprint XML schema on stdout and exit&quot;,
  286. (char const *)(0)
  287. };
  288. char const * schema = DATA_SCHEMA;
  289. flag_t flags = (flag_t)(0);
  290. signed c;
  291. optind = 1;
  292. while ((c = getoptv (argc, argv, optv)) != -1)
  293. {
  294. switch (c)
  295. {
  296. case 'f':
  297. if (!freopen (optarg, &quot;rb&quot;, stdin))
  298. {
  299. error (1, errno, &quot;Can't open %s&quot;, optarg);
  300. }
  301. break;
  302. case 'x':
  303. xmlschema ();
  304. return (0);
  305. case 'q':
  306. _setbits (flags, PIB_SILENCE);
  307. break;
  308. case 'v':
  309. _setbits (flags, PIB_VERBOSE);
  310. break;
  311. default:
  312. break;
  313. }
  314. }
  315. argc -= optind;
  316. argv += optind;
  317. if (argc &gt; 1)
  318. {
  319. error (1, ENOTSUP, ERROR_TOOMANY);
  320. }
  321. #if defined (WIN32)
  322. setmode (STDOUT_FILENO, O_BINARY);
  323. #endif
  324. if ((argc) &amp;&amp; (* argv))
  325. {
  326. signed fd;
  327. uint32_t version;
  328. if ((fd = open (*argv, O_BINARY | O_RDONLY)) == -1)
  329. {
  330. error (1, errno, &quot;%s&quot;, *argv);
  331. }
  332. else if (read (fd, &amp;version, sizeof (version)) != sizeof (version))
  333. {
  334. error (1, errno, &quot;Can't read %s&quot;, *argv);
  335. }
  336. else if (lseek (fd, 0, SEEK_SET))
  337. {
  338. error (1, errno, &quot;Can't home %s&quot;, *argv);
  339. }
  340. else if (LE32TOH (version) == 0x60000000)
  341. {
  342. error (1, errno, &quot;Won't read %s&quot;, *argv);
  343. }
  344. else if (LE32TOH (version) == 0x00010001)
  345. {
  346. struct nvm_header2 nvm_header;
  347. if (!nvmseek2 (fd, *argv, &amp;nvm_header, NVM_IMAGE_PIB))
  348. {
  349. pibdump (fd, *argv, schema, LE32TOH (nvm_header.ImageLength), flags);
  350. }
  351. }
  352. else
  353. {
  354. struct simple_pib pib_header;
  355. if (read (fd, &amp;pib_header, sizeof (pib_header)) != sizeof (pib_header))
  356. {
  357. error (1, errno, &quot;Can't read %s&quot;, *argv);
  358. }
  359. if (lseek (fd, 0, SEEK_SET))
  360. {
  361. error (1, errno, &quot;Can't home %s&quot;, *argv);
  362. }
  363. pibdump (fd, *argv, schema, LE16TOH (pib_header.PIBLENGTH), flags);
  364. }
  365. close (fd);
  366. }
  367. return (0);
  368. }
  369. </pre>
  370. <div class='footerlink'>
  371. [<a href='PhyRates.c.html' title=' PhyRates.c '>PREV</a>]
  372. [<a href='toolkit.html' title=' Index '>HOME</a>]
  373. [<a href='pibcomp.c.html' title=' pibcomp.c '>NEXT</a>]
  374. </div>
  375. </body>
  376. </html>