int6kf.c.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. int6kf.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='int6keth.c.html' title=' int6keth.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='int6khost.c.html' title=' int6khost.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. * int6kf.c - Atheros Powerline Device Flash Utility;
  64. *
  65. * this program sends and receives raw ethernet frames and so needs
  66. * root priviledges; if you install it using &quot;chmod 555&quot; and &quot;chown
  67. * root:root&quot; then you must login as root to run it; otherwise, you
  68. * can install it using &quot;chmod 4555&quot; and &quot;chown root:root&quot; so that
  69. * anyone can run it; the program will refuse to run until you get
  70. * things right;
  71. *
  72. * Contributor(s):
  73. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  74. *
  75. *--------------------------------------------------------------------*/
  76. /*====================================================================*&quot;
  77. * system header files;
  78. *--------------------------------------------------------------------*/
  79. #include &lt;unistd.h&gt;
  80. #include &lt;stdlib.h&gt;
  81. #include &lt;limits.h&gt;
  82. #include &lt;string.h&gt;
  83. #include &lt;ctype.h&gt;
  84. /*====================================================================*
  85. * custom header files;
  86. *--------------------------------------------------------------------*/
  87. #include &quot;../tools/getoptv.h&quot;
  88. #include &quot;../tools/putoptv.h&quot;
  89. #include &quot;../tools/memory.h&quot;
  90. #include &quot;../tools/number.h&quot;
  91. #include &quot;../tools/types.h&quot;
  92. #include &quot;../tools/flags.h&quot;
  93. #include &quot;../tools/files.h&quot;
  94. #include &quot;../tools/error.h&quot;
  95. #include &quot;../ram/nvram.h&quot;
  96. #include &quot;../ram/sdram.h&quot;
  97. #include &quot;../nvm/nvm.h&quot;
  98. #include &quot;../plc/plc.h&quot;
  99. #include &quot;../pib/pib.h&quot;
  100. /*====================================================================*
  101. * custom source files;
  102. *--------------------------------------------------------------------*/
  103. #ifndef MAKEFILE
  104. #include &quot;../plc/chipset.c&quot;
  105. #include &quot;../plc/Confirm.c&quot;
  106. #include &quot;../plc/Devices.c&quot;
  107. #include &quot;../plc/Display.c&quot;
  108. #include &quot;../plc/Failure.c&quot;
  109. #include &quot;../plc/FlashNVM.c&quot;
  110. #include &quot;../plc/ReadMME.c&quot;
  111. #include &quot;../plc/Request.c&quot;
  112. #include &quot;../plc/SendMME.c&quot;
  113. #include &quot;../plc/StartDevice1.c&quot;
  114. #include &quot;../plc/FlashDevice1.c&quot;
  115. #include &quot;../plc/UpgradeDevice1.c&quot;
  116. #include &quot;../plc/StartFirmware1.c&quot;
  117. #include &quot;../plc/WriteFirmware1.c&quot;
  118. #include &quot;../plc/WriteCFG.c&quot;
  119. #include &quot;../plc/WriteMEM.c&quot;
  120. #include &quot;../plc/WriteNVM.c&quot;
  121. #include &quot;../plc/WritePIB.c&quot;
  122. #include &quot;../plc/WaitForReset.c&quot;
  123. #include &quot;../plc/WaitForStart.c&quot;
  124. #include &quot;../plc/WaitForRestart.c&quot;
  125. #endif
  126. #ifndef MAKEFILE
  127. #include &quot;../tools/getoptv.c&quot;
  128. #include &quot;../tools/putoptv.c&quot;
  129. #include &quot;../tools/version.c&quot;
  130. #include &quot;../tools/uintspec.c&quot;
  131. #include &quot;../tools/checkfilename.c&quot;
  132. #include &quot;../tools/hexdecode.c&quot;
  133. #include &quot;../tools/hexstring.c&quot;
  134. #include &quot;../tools/todigit.c&quot;
  135. #include &quot;../tools/hexdump.c&quot;
  136. #include &quot;../tools/checksum32.c&quot;
  137. #include &quot;../tools/fdchecksum32.c&quot;
  138. #include &quot;../tools/typename.c&quot;
  139. #include &quot;../tools/strfbits.c&quot;
  140. #include &quot;../tools/error.c&quot;
  141. #endif
  142. #ifndef MAKEFILE
  143. #include &quot;../ram/sdramfile.c&quot;
  144. #include &quot;../ram/sdrampeek.c&quot;
  145. #endif
  146. #ifndef MAKEFILE
  147. #include &quot;../nvm/nvm.c&quot;
  148. #include &quot;../nvm/nvmfile1.c&quot;
  149. #include &quot;../nvm/nvmpeek1.c&quot;
  150. #endif
  151. #ifndef MAKEFILE
  152. #include &quot;../pib/pibfile1.c&quot;
  153. #include &quot;../pib/pibpeek1.c&quot;
  154. #endif
  155. #ifndef MAKEFILE
  156. #include &quot;../ether/openchannel.c&quot;
  157. #include &quot;../ether/closechannel.c&quot;
  158. #include &quot;../ether/readpacket.c&quot;
  159. #include &quot;../ether/sendpacket.c&quot;
  160. #include &quot;../ether/channel.c&quot;
  161. #endif
  162. #ifndef MAKEFILE
  163. #include &quot;../mme/EthernetHeader.c&quot;
  164. #include &quot;../mme/HomePlugHeader.c&quot;
  165. #include &quot;../mme/QualcommHeader.c&quot;
  166. #include &quot;../mme/UnwantedMessage.c&quot;
  167. #include &quot;../mme/MMECode.c&quot;
  168. #endif
  169. #ifndef MAKEFILE
  170. #include &quot;../key/keys.c&quot;
  171. #endif
  172. /*====================================================================*
  173. *
  174. * int main (int argc, const char * argv[]);
  175. *
  176. * parse command line, populate int6k structure and perform selected
  177. * operations; show help summary when asked; see getoptv and putoptv
  178. * to understand command line parsing and help summary display; see
  179. * int6k.h for the definition of struct int6k;
  180. *
  181. * the default interface is eth1 because most people use eth0 as
  182. * their principle network connection; you can specify another
  183. * interface with -i or define environment string PLC to make
  184. * that the default interface and save typing;
  185. *
  186. *--------------------------------------------------------------------*/
  187. int main (int argc, const char * argv [])
  188. {
  189. extern struct channel channel;
  190. static const char *optv [] =
  191. {
  192. &quot;C:i:eFN:p:P:qt:vx&quot;,
  193. &quot;-C file -P file -N file&quot;,
  194. &quot;Atheros Powerline Device Flash Utility for INT6300&quot;,
  195. &quot;C f\twrite CFG file to device using VS_SET_SDRAM&quot;,
  196. &quot;e\tredirect stderr messages to stdout&quot;,
  197. #if defined (WINPCAP) || defined (LIBPCAP)
  198. &quot;i n\thost interface number [2]&quot;,
  199. #else
  200. &quot;i s\thost interface name [&quot; CHANNEL_ETHDEVICE &quot;]&quot;,
  201. #endif
  202. &quot;F[F]\tflash [force] NVRAM after firmware start using VS_MOD_NVM&quot;,
  203. &quot;N f\twrite NVM file to device using VS_WR_MEM&quot;,
  204. &quot;P f\twrite PIB file to device using VS_WR_MEM&quot;,
  205. &quot;q\tquiet mode&quot;,
  206. #if defined (WINPCAP) || defined (LIBPCAP)
  207. &quot;t n\tread capture time is (n) milliseconds [50]&quot;,
  208. #else
  209. &quot;t n\tread timeout is (n) milliseconds [50]&quot;,
  210. #endif
  211. &quot;v\tverbose mode&quot;,
  212. &quot;x\texit on error&quot;,
  213. (const char *) (0)
  214. };
  215. #include &quot;../plc/plc.c&quot;
  216. char firmware [PLC_VERSION_STRING];
  217. signed c;
  218. if (getenv (PLCDEVICE))
  219. {
  220. #if defined (WINPCAP) || defined (LIBPCAP)
  221. channel.ifindex = atoi (getenv (PLCDEVICE));
  222. #else
  223. channel.ifname = strdup (getenv (PLCDEVICE));
  224. #endif
  225. }
  226. optind = 1;
  227. opterr = 1;
  228. while ((c = getoptv (argc, argv, optv)) != -1)
  229. {
  230. switch ((char) (c))
  231. {
  232. case 'C':
  233. if (!checkfilename (optarg))
  234. {
  235. error (1, EINVAL, &quot;%s&quot;, optarg);
  236. }
  237. if ((plc.CFG.file = open (optarg, O_BINARY|O_RDONLY)) == -1)
  238. {
  239. error (1, errno, &quot;%s&quot;, optarg);
  240. }
  241. if (sdramfile (plc.CFG.file, optarg, plc.flags))
  242. {
  243. error (1, ECANCELED, &quot;CFG file %s is corrupt&quot;, optarg);
  244. }
  245. _setbits (plc.flags, PLC_SDRAM_CONFIG);
  246. plc.CFG.name = optarg;
  247. break;
  248. case 'e':
  249. dup2 (STDOUT_FILENO, STDERR_FILENO);
  250. break;
  251. case 'i':
  252. #if defined (WINPCAP) || defined (LIBPCAP)
  253. channel.ifindex = atoi (optarg);
  254. #else
  255. channel.ifname = optarg;
  256. #endif
  257. break;
  258. case 'F':
  259. _setbits (plc.module, PLC_MODULE_NVM_PIB);
  260. if (_anyset (plc.flags, PLC_FLASH_DEVICE))
  261. {
  262. _setbits (plc.module, VS_MODULE_FORCE);
  263. }
  264. _setbits (plc.flags, PLC_FLASH_DEVICE);
  265. break;
  266. case 'N':
  267. if (!checkfilename (optarg))
  268. {
  269. error (1, EINVAL, &quot;%s&quot;, optarg);
  270. }
  271. if ((plc.NVM.file = open (optarg, O_BINARY|O_RDONLY)) == -1)
  272. {
  273. error (1, errno, &quot;%s&quot;, optarg);
  274. }
  275. plc.NVM.name = optarg;
  276. if (nvmfile1 (&amp;plc.NVM))
  277. {
  278. error (1, errno, &quot;Bad firmware file: %s&quot;, plc.NVM.name);
  279. }
  280. _setbits (plc.flags, PLC_WRITE_MAC);
  281. break;
  282. case 'P':
  283. if (!checkfilename (optarg))
  284. {
  285. error (1, EINVAL, &quot;%s&quot;, optarg);
  286. }
  287. if ((plc.PIB.file = open (optarg, O_BINARY|O_RDONLY)) == -1)
  288. {
  289. error (1, errno, &quot;%s&quot;, optarg);
  290. }
  291. plc.PIB.name = optarg;
  292. if (pibfile1 (&amp;plc.PIB))
  293. {
  294. error (1, errno, &quot;Bad parameter file: %s&quot;, plc.PIB.name);
  295. }
  296. _setbits (plc.flags, PLC_WRITE_PIB);
  297. break;
  298. case 'q':
  299. _setbits (channel.flags, CHANNEL_SILENCE);
  300. _setbits (plc.flags, PLC_SILENCE);
  301. break;
  302. case 't':
  303. channel.timeout = (unsigned)(uintspec (optarg, 0, UINT_MAX));
  304. break;
  305. case 'v':
  306. _setbits (channel.flags, CHANNEL_VERBOSE);
  307. _setbits (plc.flags, PLC_VERBOSE);
  308. break;
  309. case 'x':
  310. _setbits (plc.flags, PLC_BAILOUT);
  311. break;
  312. default:
  313. break;
  314. }
  315. }
  316. argc -= optind;
  317. argv += optind;
  318. if (argc)
  319. {
  320. error (1, ECANCELED, &quot;Too many arguments&quot;);
  321. }
  322. if (plc.CFG.file == -1)
  323. {
  324. error (1, ECANCELED, &quot;No CFG file specified&quot;);
  325. }
  326. if (plc.PIB.file == -1)
  327. {
  328. error (1, ECANCELED, &quot;No PIB file specified&quot;);
  329. }
  330. if (plc.NVM.file == -1)
  331. {
  332. error (1, ECANCELED, &quot;No NVM file specified&quot;);
  333. }
  334. openchannel (&amp;channel);
  335. if (!(plc.message = malloc (sizeof (struct message))))
  336. {
  337. error (1, errno, PLC_NOMEMORY);
  338. }
  339. if (WaitForStart (&amp;plc, firmware, sizeof (firmware)))
  340. {
  341. Failure (&amp;plc, &quot;Device must be connected&quot;);
  342. return (-1);
  343. }
  344. if (plc.hardwareID &gt; CHIPSET_INT6300)
  345. {
  346. Failure (&amp;plc, &quot;Device must be %s or earlier; try using int6kboot.&quot;, chipsetname (CHIPSET_INT6300));
  347. return (-1);
  348. }
  349. if (strcmp (firmware, &quot;BootLoader&quot;))
  350. {
  351. Failure (&amp;plc, &quot;Bootloader must be running&quot;);
  352. return (-1);
  353. }
  354. if (!StartDevice1 (&amp;plc))
  355. {
  356. if (_anyset (plc.flags, PLC_FLASH_DEVICE))
  357. {
  358. UpgradeDevice1 (&amp;plc);
  359. }
  360. }
  361. free (plc.message);
  362. closechannel (&amp;channel);
  363. exit (0);
  364. }
  365. </pre>
  366. <div class='footerlink'>
  367. [<a href='int6keth.c.html' title=' int6keth.c '>PREV</a>]
  368. [<a href='toolkit.html' title=' Index '>HOME</a>]
  369. [<a href='int6khost.c.html' title=' int6khost.c '>NEXT</a>]
  370. </div>
  371. </body>
  372. </html>