int6ktest.c.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. int6ktest.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='int6kstat.c.html' title=' int6kstat.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='int6ktone.c.html' title=' int6ktone.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. * int6ktest.c - Atheros Test Applet Loader;
  64. *
  65. *
  66. * Contributor(s):
  67. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  68. * Matthieu Poullet &lt;m.poullet@avm.de&gt;
  69. *
  70. *--------------------------------------------------------------------*/
  71. /*====================================================================*&quot;
  72. * system header files;
  73. *--------------------------------------------------------------------*/
  74. #include &lt;unistd.h&gt;
  75. #include &lt;stdlib.h&gt;
  76. #include &lt;stdint.h&gt;
  77. #include &lt;limits.h&gt;
  78. #include &lt;errno.h&gt;
  79. /*====================================================================*
  80. * custom header files;
  81. *--------------------------------------------------------------------*/
  82. #include &quot;../tools/getoptv.h&quot;
  83. #include &quot;../tools/putoptv.h&quot;
  84. #include &quot;../tools/memory.h&quot;
  85. #include &quot;../tools/number.h&quot;
  86. #include &quot;../tools/types.h&quot;
  87. #include &quot;../tools/flags.h&quot;
  88. #include &quot;../tools/files.h&quot;
  89. #include &quot;../tools/error.h&quot;
  90. #include &quot;../ether/channel.h&quot;
  91. #include &quot;../ram/nvram.h&quot;
  92. #include &quot;../ram/sdram.h&quot;
  93. #include &quot;../nvm/nvm.h&quot;
  94. #include &quot;../pib/pib.h&quot;
  95. #include &quot;../plc/plc.h&quot;
  96. /*====================================================================*
  97. * custom source files;
  98. *--------------------------------------------------------------------*/
  99. #ifndef MAKEFILE
  100. #include &quot;../plc/chipset.c&quot;
  101. #include &quot;../plc/Confirm.c&quot;
  102. #include &quot;../plc/Devices.c&quot;
  103. #include &quot;../plc/Display.c&quot;
  104. #include &quot;../plc/Failure.c&quot;
  105. #include &quot;../plc/Request.c&quot;
  106. #include &quot;../plc/SendMME.c&quot;
  107. #include &quot;../plc/WriteFirmware1.c&quot;
  108. #include &quot;../plc/StartFirmware1.c&quot;
  109. #include &quot;../plc/WaitForStart.c&quot;
  110. #endif
  111. #ifndef MAKEFILE
  112. #include &quot;../tools/getoptv.c&quot;
  113. #include &quot;../tools/putoptv.c&quot;
  114. #include &quot;../tools/version.c&quot;
  115. #include &quot;../tools/uintspec.c&quot;
  116. #include &quot;../tools/checkfilename.c&quot;
  117. #include &quot;../tools/hexdecode.c&quot;
  118. #include &quot;../tools/todigit.c&quot;
  119. #include &quot;../tools/hexdump.c&quot;
  120. #include &quot;../tools/checksum32.c&quot;
  121. #include &quot;../tools/fdchecksum32.c&quot;
  122. #include &quot;../tools/error.c&quot;
  123. #include &quot;../tools/strfbits.c&quot;
  124. #include &quot;../tools/typename.c&quot;
  125. #endif
  126. #ifndef MAKEFILE
  127. #include &quot;../ether/openchannel.c&quot;
  128. #include &quot;../ether/closechannel.c&quot;
  129. #include &quot;../ether/readpacket.c&quot;
  130. #include &quot;../ether/sendpacket.c&quot;
  131. #include &quot;../ether/channel.c&quot;
  132. #endif
  133. #ifndef MAKEFILE
  134. #include &quot;../nvm/nvmfile1.c&quot;
  135. #endif
  136. #ifndef MAKEFILE
  137. #include &quot;../mme/MMECode.c&quot;
  138. #include &quot;../mme/EthernetHeader.c&quot;
  139. #include &quot;../mme/QualcommHeader.c&quot;
  140. #include &quot;../mme/UnwantedMessage.c&quot;
  141. #endif
  142. /*====================================================================*
  143. *
  144. * signed ReadMME (struct plc * plc, uint8_t MMV, uint16_t MMTYPE);
  145. *
  146. * plc.h
  147. *
  148. * this is a custom version of ReadMME that intercepts VS_ARPC
  149. * messages and print them on the console in human readable format;
  150. *
  151. * this implementation was an early attempt the does not take full
  152. * advantage of the VS_ARPC structure and so messages are printed
  153. * in a format that is incompatible with the Windows Device Manager;
  154. * program amptest corrects this problem by calling ARPCPrint;
  155. *
  156. * this function is maintained for legacy purposes only and will be
  157. * deleted at some point in the future;
  158. *
  159. *
  160. * Contributor(s):
  161. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  162. *
  163. *--------------------------------------------------------------------*/
  164. signed ReadMME (struct plc * plc, uint8_t MMV, uint16_t MMTYPE)
  165. {
  166. struct channel * channel = (struct channel *)(plc-&gt;channel);
  167. struct message * message = (struct message *)(plc-&gt;message);
  168. #ifndef __GNUC__
  169. #pragma pack (push,1)
  170. #endif
  171. static qualcomm_hdr header_arpc =
  172. {
  173. 0,
  174. VS_ARPC | MMTYPE_IND,
  175. {
  176. 0x00,
  177. 0xB0,
  178. 0x52
  179. }
  180. };
  181. struct __packed vs_arpc_ind
  182. {
  183. struct ethernet_hdr ethernet;
  184. struct qualcomm_hdr qualcomm;
  185. uint16_t RDATALENGTH;
  186. uint8_t RDATAOFFSET;
  187. uint8_t RDATA [1];
  188. }
  189. * indicate = (struct vs_arpc_ind *)(plc-&gt;message);
  190. #ifndef __GNUC__
  191. #pragma pack (pop)
  192. #endif
  193. while ((plc-&gt;packetsize = readpacket (channel, message, sizeof (* message))) &gt; 0)
  194. {
  195. #if 1
  196. /*
  197. * Normally this block of code would be replaced by function FirmwareMessage () but due to an
  198. * ARPC implmenetation error on early diagnostic applets we need to use this code instead;
  199. */
  200. header_arpc.MMTYPE = HTOLE16 (header_arpc.MMTYPE);
  201. if (!memcmp (&amp;indicate-&gt;qualcomm, &amp;header_arpc, sizeof (header_arpc)))
  202. {
  203. indicate-&gt;RDATA [indicate-&gt;RDATALENGTH - indicate-&gt;RDATAOFFSET] = (char)(0);
  204. Display (plc, &quot;0x%02X %s&quot;, indicate-&gt;RDATA [0], &amp;indicate-&gt;RDATA [5]);
  205. continue;
  206. }
  207. #endif
  208. if (UnwantedMessage (message, plc-&gt;packetsize, 0, MMTYPE))
  209. {
  210. continue;
  211. }
  212. break;
  213. }
  214. return (plc-&gt;packetsize);
  215. }
  216. /*====================================================================*
  217. *
  218. * signed sequence (struct plc * plc);
  219. *
  220. * plc.h
  221. *
  222. * sequentially download and execute all modules found in a .nvm
  223. * file regardless of module type; users must ensure that modules
  224. * are executable or results may be unpredictable;
  225. *
  226. * DO NOT USE THIS FUNCTION TO DOWNBOOT AND EXECUTE RUNTIME FIRMWARE;
  227. *
  228. *
  229. * Contributor(s):
  230. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  231. *
  232. *--------------------------------------------------------------------*/
  233. static signed sequence (struct plc * plc)
  234. {
  235. struct nvm_header1 nvm_header;
  236. unsigned module = 0;
  237. do
  238. {
  239. if (read (plc-&gt;NVM.file, &amp;nvm_header, sizeof (nvm_header)) != sizeof (nvm_header))
  240. {
  241. if (_allclr (plc-&gt;flags, PLC_SILENCE))
  242. {
  243. error (0, errno, NVM_HDR_CANTREAD, plc-&gt;NVM.name, module);
  244. }
  245. return (-1);
  246. }
  247. if (LE32TOH (nvm_header.HEADERVERSION) != 0x60000000)
  248. {
  249. if (_allclr (plc-&gt;flags, PLC_SILENCE))
  250. {
  251. error (0, 0, NVM_HDR_VERSION, plc-&gt;NVM.name, module);
  252. }
  253. return (-1);
  254. }
  255. if (checksum32 (&amp;nvm_header, sizeof (nvm_header), 0))
  256. {
  257. if (_allclr (plc-&gt;flags, PLC_SILENCE))
  258. {
  259. error (0, 0, NVM_HDR_CHECKSUM, plc-&gt;NVM.name, module);
  260. }
  261. return (-1);
  262. }
  263. if (WriteFirmware1 (plc, module, &amp;nvm_header))
  264. {
  265. return (-1);
  266. }
  267. if (StartFirmware1 (plc, module, &amp;nvm_header))
  268. {
  269. return (-1);
  270. }
  271. if (_anyset (plc-&gt;flags, PLC_QUICK_FLASH))
  272. {
  273. break;
  274. }
  275. while (!ReadMME (plc, 0, (VS_HOST_ACTION | MMTYPE_IND)));
  276. module++;
  277. }
  278. while (nvm_header.NEXTHEADER);
  279. return (0);
  280. }
  281. /*====================================================================*
  282. *
  283. * void function (struct plc * plc, int argc, char const * argv);
  284. *
  285. * execute all applets in each file on the command line; return no
  286. * value; this function may be called repeatedly;
  287. *
  288. *
  289. *--------------------------------------------------------------------*/
  290. static void function (struct plc * plc, int argc, char const * argv [])
  291. {
  292. while ((argc) &amp;&amp; (* argv))
  293. {
  294. if ((plc-&gt;NVM.file = open (plc-&gt;NVM.name = * argv, O_BINARY|O_RDONLY)) == -1)
  295. {
  296. error (0, errno, &quot;%s&quot;, plc-&gt;NVM.name);
  297. }
  298. else if (nvmfile1 (&amp;plc-&gt;NVM))
  299. {
  300. error (0, errno, &quot;Won't load %s&quot;, plc-&gt;NVM.name);
  301. }
  302. else if (sequence (plc))
  303. {
  304. error (0, errno, &quot;Abandoning %s&quot;, plc-&gt;NVM.name);
  305. }
  306. close (plc-&gt;NVM.file);
  307. argc--;
  308. argv++;
  309. }
  310. return;
  311. }
  312. /*====================================================================*
  313. *
  314. * int main (int argc, char const * argv[]);
  315. *
  316. * parse command line, populate plc structure and perform selected
  317. * operations; show help summary when asked; see getoptv and putoptv
  318. * to understand command line parsing and help summary display; see
  319. * plc.h for the definition of struct plc;
  320. *
  321. * the default interface is eth1 because most people use eth0 as
  322. * their principle network connection; you can specify another
  323. * interface with -i or define environment string PLC to make
  324. * that the default interface and save typing;
  325. *
  326. *
  327. *--------------------------------------------------------------------*/
  328. int main (int argc, char const * argv [])
  329. {
  330. extern struct channel channel;
  331. char firmware [PLC_VERSION_STRING];
  332. static char const * optv [] =
  333. {
  334. &quot;c:ei:lp:qt:vx&quot;,
  335. &quot;file [file] [...]&quot;,
  336. &quot;Qualcomm Atheros Test Applet Loader&quot;,
  337. &quot;e\tredirect stderr to stdout&quot;,
  338. #if defined (WINPCAP) || defined (LIBPCAP)
  339. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  340. #else
  341. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  342. #endif
  343. &quot;l\tloop until program is terminated&quot;,
  344. &quot;q\tquiet mode&quot;,
  345. &quot;t n\tread timeout is (n) milliseconds [&quot; LITERAL (CHANNEL_TIMEOUT) &quot;]&quot;,
  346. &quot;v\tverbose mode&quot;,
  347. &quot;x\texit on error&quot;,
  348. (char const *) (0)
  349. };
  350. #include &quot;../plc/plc.c&quot;
  351. signed c;
  352. if (getenv (PLCDEVICE))
  353. {
  354. #if defined (WINPCAP) || defined (LIBPCAP)
  355. channel.ifindex = atoi (getenv (PLCDEVICE));
  356. #else
  357. channel.ifname = strdup (getenv (PLCDEVICE));
  358. #endif
  359. }
  360. optind = 1;
  361. while ((c = getoptv (argc, argv, optv)) != -1)
  362. {
  363. switch (c)
  364. {
  365. case 'e':
  366. dup2 (STDOUT_FILENO, STDERR_FILENO);
  367. break;
  368. case 'i':
  369. #if defined (WINPCAP) || defined (LIBPCAP)
  370. channel.ifindex = atoi (optarg);
  371. #else
  372. channel.ifname = optarg;
  373. #endif
  374. break;
  375. case 'l':
  376. _setbits (plc.flags, PLC_FOREVER);
  377. break;
  378. case 'q':
  379. _setbits (channel.flags, CHANNEL_SILENCE);
  380. _setbits (plc.flags, PLC_SILENCE);
  381. break;
  382. case 't':
  383. channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
  384. break;
  385. case 'v':
  386. _setbits (channel.flags, CHANNEL_VERBOSE);
  387. _setbits (plc.flags, PLC_VERBOSE);
  388. break;
  389. case 'x':
  390. _setbits (plc.flags, PLC_BAILOUT);
  391. break;
  392. default:
  393. break;
  394. }
  395. }
  396. argc -= optind;
  397. argv += optind;
  398. openchannel (&amp;channel);
  399. if (!(plc.message = malloc (sizeof (* plc.message))))
  400. {
  401. error (1, errno, PLC_NOMEMORY);
  402. }
  403. if (WaitForStart (&amp;plc, firmware, sizeof (firmware)))
  404. {
  405. error (1, ECANCELED, PLC_NODETECT);
  406. }
  407. if (strcmp (firmware, &quot;BootLoader&quot;))
  408. {
  409. error (1, ECANCELED, &quot;BootLoader must be running&quot;);
  410. }
  411. do
  412. {
  413. function (&amp;plc, argc, argv);
  414. }
  415. while (_anyset (plc.flags, PLC_FOREVER));
  416. free (plc.message);
  417. closechannel (&amp;channel);
  418. return (plc.state);
  419. }
  420. </pre>
  421. <div class='footerlink'>
  422. [<a href='int6kstat.c.html' title=' int6kstat.c '>PREV</a>]
  423. [<a href='toolkit.html' title=' Index '>HOME</a>]
  424. [<a href='int6ktone.c.html' title=' int6ktone.c '>NEXT</a>]
  425. </div>
  426. </body>
  427. </html>