int6k.c.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. int6k.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='int6kboot.c.html' title=' int6kboot.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='int6kdetect.c.html' title=' int6kdetect.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. /*====================================================================*&quot;
  62. *
  63. * int6k.c -
  64. *
  65. *
  66. * Contributor(s):
  67. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  68. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&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. /*====================================================================*
  79. * custom header files;
  80. *--------------------------------------------------------------------*/
  81. #include &quot;../tools/getoptv.h&quot;
  82. #include &quot;../tools/putoptv.h&quot;
  83. #include &quot;../tools/memory.h&quot;
  84. #include &quot;../tools/number.h&quot;
  85. #include &quot;../tools/symbol.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;../plc/plc.h&quot;
  91. #include &quot;../ether/channel.h&quot;
  92. #include &quot;../key/HPAVKey.h&quot;
  93. #include &quot;../key/keys.h&quot;
  94. #include &quot;../ram/sdram.h&quot;
  95. #include &quot;../pib/pib.h&quot;
  96. #include &quot;../nvm/nvm.h&quot;
  97. /*====================================================================*
  98. * custom source files;
  99. *--------------------------------------------------------------------*/
  100. #ifndef MAKEFILE
  101. #include &quot;../plc/Attributes1.c&quot;
  102. #include &quot;../plc/chipset.c&quot;
  103. #include &quot;../plc/Devices.c&quot;
  104. #include &quot;../plc/Confirm.c&quot;
  105. #include &quot;../plc/Display.c&quot;
  106. #include &quot;../plc/Failure.c&quot;
  107. #include &quot;../plc/FlashNVM.c&quot;
  108. #include &quot;../plc/FactoryDefaults.c&quot;
  109. #include &quot;../plc/Identity1.c&quot;
  110. #include &quot;../plc/HostActionResponse.c&quot;
  111. #include &quot;../plc/NetInfo1.c&quot;
  112. #include &quot;../plc/NVRAMInfo.c&quot;
  113. #include &quot;../plc/PushButton.c&quot;
  114. #include &quot;../plc/SDRAMInfo.c&quot;
  115. #include &quot;../plc/SetNMK.c&quot;
  116. #include &quot;../plc/Request.c&quot;
  117. #include &quot;../plc/ReadFirmware1.c&quot;
  118. #include &quot;../plc/ReadMME.c&quot;
  119. #include &quot;../plc/ReadMFG.c&quot;
  120. #include &quot;../plc/ReadParameters1.c&quot;
  121. #include &quot;../plc/ResetDevice.c&quot;
  122. #include &quot;../plc/SendMME.c&quot;
  123. #include &quot;../plc/VersionInfo1.c&quot;
  124. #include &quot;../plc/WriteCFG.c&quot;
  125. #include &quot;../plc/WriteNVM.c&quot;
  126. #include &quot;../plc/WritePIB.c&quot;
  127. #include &quot;../plc/WaitForReset.c&quot;
  128. #include &quot;../plc/WaitForStart.c&quot;
  129. #include &quot;../plc/WaitForRestart.c&quot;
  130. #include &quot;../plc/WatchdogReport.c&quot;
  131. #include &quot;../plc/StationRole.c&quot;
  132. #include &quot;../plc/ModuleRead.c&quot;
  133. #endif
  134. #ifndef MAKEFILE
  135. #include &quot;../tools/synonym.c&quot;
  136. #include &quot;../tools/getoptv.c&quot;
  137. #include &quot;../tools/putoptv.c&quot;
  138. #include &quot;../tools/version.c&quot;
  139. #include &quot;../tools/uintspec.c&quot;
  140. #include &quot;../tools/hexdump.c&quot;
  141. #include &quot;../tools/hexencode.c&quot;
  142. #include &quot;../tools/hexdecode.c&quot;
  143. #include &quot;../tools/hexstring.c&quot;
  144. #include &quot;../tools/todigit.c&quot;
  145. #include &quot;../tools/checkfilename.c&quot;
  146. #include &quot;../tools/checksum32.c&quot;
  147. #include &quot;../tools/fdchecksum32.c&quot;
  148. #include &quot;../tools/strfbits.c&quot;
  149. #include &quot;../tools/typename.c&quot;
  150. #include &quot;../tools/error.c&quot;
  151. #endif
  152. #ifndef MAKEFILE
  153. #include &quot;../ether/openchannel.c&quot;
  154. #include &quot;../ether/closechannel.c&quot;
  155. #include &quot;../ether/readpacket.c&quot;
  156. #include &quot;../ether/sendpacket.c&quot;
  157. #include &quot;../ether/channel.c&quot;
  158. #endif
  159. #ifndef MAKEFILE
  160. #include &quot;../ram/nvram.c&quot;
  161. #include &quot;../ram/sdramfile.c&quot;
  162. #include &quot;../ram/sdrampeek.c&quot;
  163. #endif
  164. #ifndef MAKEFILE
  165. #include &quot;../nvm/nvmfile1.c&quot;
  166. #endif
  167. #ifndef MAKEFILE
  168. #include &quot;../pib/pibfile1.c&quot;
  169. #include &quot;../pib/pibpeek1.c&quot;
  170. #endif
  171. #ifndef MAKEFILE
  172. #include &quot;../mme/MMECode.c&quot;
  173. #include &quot;../mme/EthernetHeader.c&quot;
  174. #include &quot;../mme/QualcommHeader.c&quot;
  175. #include &quot;../mme/QualcommHeader1.c&quot;
  176. #include &quot;../mme/UnwantedMessage.c&quot;
  177. #endif
  178. #ifndef MAKEFILE
  179. #include &quot;../key/keys.c&quot;
  180. #endif
  181. /*====================================================================*
  182. * program constants;
  183. *--------------------------------------------------------------------*/
  184. #define INT6K_WAIT 0
  185. #define INT6K_LOOP 1
  186. /*====================================================================*
  187. * program variables;
  188. *--------------------------------------------------------------------*/
  189. static struct _term_ const modules [] =
  190. {
  191. {
  192. &quot;nvm&quot;,
  193. &quot;1&quot;
  194. },
  195. {
  196. &quot;pib&quot;,
  197. &quot;2&quot;
  198. },
  199. {
  200. &quot;both&quot;,
  201. &quot;3&quot;
  202. }
  203. };
  204. static struct _term_ const buttons [] =
  205. {
  206. {
  207. &quot;join&quot;,
  208. &quot;1&quot;
  209. },
  210. {
  211. &quot;leave&quot;,
  212. &quot;2&quot;
  213. },
  214. {
  215. &quot;status&quot;,
  216. &quot;3&quot;
  217. }
  218. };
  219. /*====================================================================*
  220. *
  221. * void manager (struct plc * plc, signed count, signed pause);
  222. *
  223. * perform operations in logical order despite any order specfied
  224. * on the command line; for example read PIB before writing PIB;
  225. *
  226. * operation order is controlled by the order of &quot;if&quot; statements
  227. * shown here; the entire operation sequence can be repeated with
  228. * an optional pause between each iteration;
  229. *
  230. *
  231. *--------------------------------------------------------------------*/
  232. static void manager (struct plc * plc, signed count, signed pause)
  233. {
  234. while (count--)
  235. {
  236. if (_anyset (plc-&gt;flags, PLC_VERSION))
  237. {
  238. VersionInfo1 (plc);
  239. }
  240. if (_anyset (plc-&gt;flags, PLC_ATTRIBUTES))
  241. {
  242. Attributes1 (plc);
  243. }
  244. if (_anyset (plc-&gt;flags, PLC_WATCHDOG_REPORT))
  245. {
  246. WatchdogReport (plc);
  247. }
  248. if (_anyset (plc-&gt;flags, PLC_NVRAM_INFO))
  249. {
  250. NVRAMInfo (plc);
  251. }
  252. if (_anyset (plc-&gt;flags, PLC_SDRAM_INFO))
  253. {
  254. SDRAMInfo (plc);
  255. }
  256. if (_anyset (plc-&gt;flags, PLC_READ_IDENTITY))
  257. {
  258. Identity1 (plc);
  259. }
  260. if (_anyset (plc-&gt;flags, PLC_NETWORK))
  261. {
  262. NetInfo1 (plc);
  263. }
  264. if (_anyset (plc-&gt;flags, PLC_SDRAM_CONFIG))
  265. {
  266. WriteCFG (plc);
  267. }
  268. if (_anyset (plc-&gt;flags, PLC_WRITE_MAC))
  269. {
  270. WriteNVM (plc);
  271. }
  272. if (_anyset (plc-&gt;flags, PLC_READ_MAC))
  273. {
  274. ReadFirmware1 (plc);
  275. }
  276. if (_anyset (plc-&gt;flags, PLC_WRITE_PIB))
  277. {
  278. WritePIB (plc);
  279. }
  280. if (_anyset (plc-&gt;flags, PLC_READ_PIB))
  281. {
  282. ReadParameters1 (plc);
  283. }
  284. if (_anyset (plc-&gt;flags, PLC_HOST_ACTION))
  285. {
  286. HostActionResponse (plc);
  287. }
  288. if (_anyset (plc-&gt;flags, PLC_PUSH_BUTTON))
  289. {
  290. PushButton (plc);
  291. }
  292. if (_anyset (plc-&gt;flags, (PLC_SETLOCALKEY | PLC_SETREMOTEKEY)))
  293. {
  294. SetNMK (plc);
  295. }
  296. if (_anyset (plc-&gt;flags, PLC_FACTORY_DEFAULTS))
  297. {
  298. FactoryDefaults (plc);
  299. }
  300. if (_anyset (plc-&gt;flags, PLC_FLASH_DEVICE))
  301. {
  302. FlashNVM (plc);
  303. WaitForRestart (plc);
  304. }
  305. if (_anyset (plc-&gt;flags, PLC_RESET_DEVICE))
  306. {
  307. ResetDevice (plc);
  308. }
  309. sleep (pause);
  310. }
  311. return;
  312. }
  313. /*====================================================================*
  314. *
  315. * int main (int argc, char const * argv[]);
  316. *
  317. * parse command line, populate plc structure and perform selected
  318. * operations; show help summary if asked; see getoptv and putoptv
  319. * to understand command line parsing and help summary display; see
  320. * plc.h for the definition of struct plc;
  321. *
  322. * the command line accepts multiple MAC addresses and the program
  323. * performs the specified operations on each address, in turn; the
  324. * address order is significant but the option order is not; the
  325. * default address is a local broadcast that causes all devices on
  326. * the local H1 interface to respond but not those at the remote
  327. * end of the powerline;
  328. *
  329. * the default address is 00:B0:52:00:00:01; omitting the address
  330. * will automatically address the local device; some options will
  331. * cancel themselves if this makes no sense;
  332. *
  333. * the default interface is eth1 because most people use eth0 as
  334. * their principle network connection; you can specify another
  335. * interface with -i or define environment string PLC to make
  336. * that the default interface and save typing;
  337. *
  338. *
  339. *--------------------------------------------------------------------*/
  340. int main (int argc, char const * argv [])
  341. {
  342. extern struct channel channel;
  343. extern struct _term_ const daks [];
  344. extern struct _term_ const nmks [];
  345. static char const * optv [] =
  346. {
  347. &quot;aB:C:d:D:efFHi:IJ:K:l:mMn:N:p:P:QqrRS:st:Tvw:x&quot;,
  348. &quot;device [device] [...]&quot;,
  349. &quot;Qualcomm Atheros INT6x00 Powerline Device Manager&quot;,
  350. &quot;a\tread device attributes using VS_OP_ATTRIBUTES&quot;,
  351. &quot;B n\tperform pushbutton action (n) using MS_PB_ENC [1|2|3|'join'|'leave'|'status']&quot;,
  352. &quot;C n\tflash NVRAM with module (n) using VS_MOD_NVM [1|2|3|'nvm'|'pib'|'both']&quot;,
  353. &quot;d f\tdump and clear watchdog report to file (f) using VS_WD_RPT&quot;,
  354. &quot;D x\tset DAK to (x) for option -J [&quot; DAK1 &quot;]&quot;,
  355. &quot;e\tredirect stderr to stdout&quot;,
  356. &quot;f\tread NVRAM Configuration using VS_GET_NVM&quot;,
  357. &quot;F[F]\tflash [force] NVRAM with PIB and firmware using VS_MOD_NVM&quot;,
  358. &quot;H\tstop host action requests using VS_HOST_ACTION.IND&quot;,
  359. #if defined (WINPCAP) || defined (LIBPCAP)
  360. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  361. #else
  362. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  363. #endif
  364. &quot;I\tread device identity using VS_RD_MOD&quot;,
  365. &quot;J x\tset NMK on remote device (x) via local device using VS_SET_KEY (see -K)&quot;,
  366. &quot;K x\tset NMK to (x) for options -J and -M [&quot; NMK1 &quot;]&quot;,
  367. &quot;l n\tloop (n) times [&quot; LITERAL (INT6K_LOOP) &quot;]&quot;,
  368. &quot;m\tread network membership information using VS_NW_INFO&quot;,
  369. &quot;M\tset NMK on local device using VS_SET_KEY (see -K)&quot;,
  370. &quot;n f\tread NVM from SDRAM to file (f) using VS_RD_MOD&quot;,
  371. &quot;N f\twrite NVM file (f) to SDRAM using VS_WR_MOD&quot;,
  372. &quot;p f\tread PIB from SDRAM to file (f) using VS_RD_MOD&quot;,
  373. &quot;P f\twrite PIB file (f) to SDRAM using VS_WR_MOD&quot;,
  374. &quot;q\tquiet mode&quot;,
  375. &quot;Q\tquick flash (return immediately)&quot;,
  376. &quot;r\tread hardware and firmware revision using VS_SW_VER&quot;,
  377. &quot;R\treset device using VS_RS_DEV&quot;,
  378. &quot;s\tread SDRAM Configuration using VS_RD_CBLOCK&quot;,
  379. &quot;S f\twrite an SDRAM Configuration file (f) using VS_SET_SDRAM&quot;,
  380. &quot;t n\tread timeout is (n) milliseconds [&quot; LITERAL (CHANNEL_TIMEOUT) &quot;]&quot;,
  381. &quot;T\trestore factory defaults using VS_FAC_DEFAULTS&quot;,
  382. &quot;v\tverbose mode&quot;,
  383. &quot;w n\tpause (n) seconds [&quot; LITERAL (INT6K_WAIT) &quot;]&quot;,
  384. &quot;x\texit on error&quot;,
  385. (char const *) (0)
  386. };
  387. #include &quot;../plc/plc.c&quot;
  388. signed loop = INT6K_LOOP;
  389. signed wait = INT6K_WAIT;
  390. signed c;
  391. if (getenv (PLCDEVICE))
  392. {
  393. #if defined (WINPCAP) || defined (LIBPCAP)
  394. channel.ifindex = atoi (getenv (PLCDEVICE));
  395. #else
  396. channel.ifname = strdup (getenv (PLCDEVICE));
  397. #endif
  398. }
  399. optind = 1;
  400. while ((c = getoptv (argc, argv, optv)) != -1)
  401. {
  402. switch (c)
  403. {
  404. case 'a':
  405. _setbits (plc.flags, PLC_ATTRIBUTES);
  406. break;
  407. case 'B':
  408. _setbits (plc.flags, PLC_PUSH_BUTTON);
  409. plc.pushbutton = (unsigned)(uintspec (synonym (optarg, buttons, SIZEOF (buttons)), 0, UCHAR_MAX));
  410. break;
  411. case 'C':
  412. _setbits (plc.flags, PLC_FLASH_DEVICE);
  413. plc.module = (unsigned)(uintspec (synonym (optarg, modules, SIZEOF (modules)), 0, UCHAR_MAX));
  414. break;
  415. case 'd':
  416. _setbits (plc.flags, PLC_WATCHDOG_REPORT);
  417. if (!checkfilename (optarg))
  418. {
  419. error (1, EINVAL, &quot;%s&quot;, optarg);
  420. }
  421. if ((plc.rpt.file = open (plc.rpt.name = optarg, O_BINARY|O_CREAT|O_RDWR|O_TRUNC, FILE_FILEMODE)) == -1)
  422. {
  423. error (1, errno, &quot;%s&quot;, plc.rpt.name);
  424. }
  425. #ifndef WIN32
  426. chown (optarg, getuid (), getgid ());
  427. #endif
  428. plc.readaction = 3;
  429. break;
  430. case 'D':
  431. if (!hexencode (plc.DAK, sizeof (plc.DAK), synonym (optarg, daks, SIZEOF (daks))))
  432. {
  433. error (1, errno, PLC_BAD_DAK, optarg);
  434. }
  435. break;
  436. case 'e':
  437. dup2 (STDOUT_FILENO, STDERR_FILENO);
  438. break;
  439. case 'f':
  440. _setbits (plc.flags, PLC_NVRAM_INFO);
  441. break;
  442. case 'F':
  443. _setbits (plc.module, (VS_MODULE_MAC | VS_MODULE_PIB));
  444. if (_anyset (plc.flags, PLC_FLASH_DEVICE))
  445. {
  446. _setbits (plc.module, VS_MODULE_FORCE);
  447. }
  448. _setbits (plc.flags, PLC_FLASH_DEVICE);
  449. break;
  450. case 'H':
  451. _setbits (plc.flags, PLC_HOST_ACTION);
  452. break;
  453. case 'I':
  454. _setbits (plc.flags, PLC_READ_IDENTITY);
  455. break;
  456. case 'i':
  457. #if defined (WINPCAP) || defined (LIBPCAP)
  458. channel.ifindex = atoi (optarg);
  459. #else
  460. channel.ifname = optarg;
  461. #endif
  462. break;
  463. case 'J':
  464. if (!hexencode (plc.RDA, sizeof (plc.RDA), (char const *)(optarg)))
  465. {
  466. error (1, errno, PLC_BAD_MAC, optarg);
  467. }
  468. _setbits (plc.flags, PLC_SETREMOTEKEY);
  469. break;
  470. case 'K':
  471. if (!hexencode (plc.NMK, sizeof (plc.NMK), synonym (optarg, nmks, SIZEOF (nmks))))
  472. {
  473. error (1, errno, PLC_BAD_NMK, optarg);
  474. }
  475. break;
  476. case 'M':
  477. _setbits (plc.flags, PLC_SETLOCALKEY);
  478. break;
  479. case 'l':
  480. loop = (unsigned)(uintspec (optarg, 0, UINT_MAX));
  481. break;
  482. case 'm':
  483. _setbits (plc.flags, PLC_NETWORK);
  484. break;
  485. case 'N':
  486. if (!checkfilename (optarg))
  487. {
  488. error (1, EINVAL, &quot;%s&quot;, optarg);
  489. }
  490. if ((plc.NVM.file = open (plc.NVM.name = optarg, O_BINARY|O_RDONLY)) == -1)
  491. {
  492. error (1, errno, &quot;%s&quot;, plc.NVM.name);
  493. }
  494. if (nvmfile1 (&amp;plc.NVM))
  495. {
  496. error (1, errno, &quot;Bad firmware file: %s&quot;, plc.NVM.name);
  497. }
  498. _setbits (plc.flags, PLC_WRITE_MAC);
  499. break;
  500. case 'n':
  501. if (!checkfilename (optarg))
  502. {
  503. error (1, EINVAL, &quot;%s&quot;, optarg);
  504. }
  505. if ((plc.nvm.file = open (plc.nvm.name = optarg, O_BINARY|O_CREAT|O_RDWR|O_TRUNC, FILE_FILEMODE)) == -1)
  506. {
  507. error (1, errno, &quot;%s&quot;, plc.nvm.name);
  508. }
  509. #ifndef WIN32
  510. chown (optarg, getuid (), getgid ());
  511. #endif
  512. _setbits (plc.flags, PLC_READ_MAC);
  513. break;
  514. case 'P':
  515. if (!checkfilename (optarg))
  516. {
  517. error (1, EINVAL, &quot;%s&quot;, optarg);
  518. }
  519. if ((plc.PIB.file = open (plc.PIB.name = optarg, O_BINARY|O_RDONLY)) == -1)
  520. {
  521. error (1, errno, &quot;%s&quot;, plc.PIB.name);
  522. }
  523. if (pibfile1 (&amp;plc.PIB))
  524. {
  525. error (1, errno, &quot;Bad parameter file: %s&quot;, plc.PIB.name);
  526. }
  527. _setbits (plc.flags, PLC_WRITE_PIB);
  528. break;
  529. case 'p':
  530. if (!checkfilename (optarg))
  531. {
  532. error (1, EINVAL, &quot;%s&quot;, optarg);
  533. }
  534. if ((plc.pib.file = open (plc.pib.name = optarg, O_BINARY|O_CREAT|O_RDWR|O_TRUNC, FILE_FILEMODE)) == -1)
  535. {
  536. error (1, errno, &quot;%s&quot;, plc.pib.name);
  537. }
  538. #ifndef WIN32
  539. chown (optarg, getuid (), getgid ());
  540. #endif
  541. _setbits (plc.flags, PLC_READ_PIB);
  542. break;
  543. case 'Q':
  544. _setbits (plc.flags, PLC_QUICK_FLASH);
  545. break;
  546. case 'q':
  547. _setbits (channel.flags, CHANNEL_SILENCE);
  548. _setbits (plc.flags, PLC_SILENCE);
  549. break;
  550. case 'R':
  551. _setbits (plc.flags, PLC_RESET_DEVICE);
  552. break;
  553. case 'r':
  554. _setbits (plc.flags, PLC_VERSION);
  555. break;
  556. case 'S':
  557. if (!checkfilename (optarg))
  558. {
  559. error (1, EINVAL, &quot;%s&quot;, optarg);
  560. }
  561. if ((plc.CFG.file = open (plc.CFG.name = optarg, O_BINARY|O_RDONLY)) == -1)
  562. {
  563. error (1, errno, &quot;%s&quot;, plc.CFG.name);
  564. }
  565. if (sdramfile (plc.CFG.file, optarg, plc.flags))
  566. {
  567. error (1, ECANCELED, &quot;SDRAM config file %s is corrupt&quot;, optarg);
  568. }
  569. _setbits (plc.flags, PLC_SDRAM_CONFIG);
  570. break;
  571. case 's':
  572. _setbits (plc.flags, PLC_SDRAM_INFO);
  573. break;
  574. case 't':
  575. channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
  576. break;
  577. case 'T':
  578. _setbits (plc.flags, PLC_FACTORY_DEFAULTS);
  579. break;
  580. case 'v':
  581. _setbits (channel.flags, CHANNEL_VERBOSE);
  582. _setbits (plc.flags, PLC_VERBOSE);
  583. break;
  584. case 'V':
  585. _setbits (plc.flags, PLC_SNIFFER);
  586. plc.action = (uint8_t)(uintspec (optarg, 0, UCHAR_MAX));
  587. break;
  588. case 'w':
  589. wait = (unsigned)(uintspec (optarg, 0, 3600));
  590. break;
  591. case 'x':
  592. _setbits (plc.flags, PLC_BAILOUT);
  593. break;
  594. default:
  595. break;
  596. }
  597. }
  598. argc -= optind;
  599. argv += optind;
  600. if (argc != 1)
  601. {
  602. if (plc.nvm.file != -1)
  603. {
  604. error (1, ECANCELED, PLC_NODEVICE);
  605. }
  606. if (plc.pib.file != -1)
  607. {
  608. error (1, ECANCELED, PLC_NODEVICE);
  609. }
  610. if (plc.rpt.file != -1)
  611. {
  612. error (1, ECANCELED, PLC_NODEVICE);
  613. }
  614. }
  615. openchannel (&amp;channel);
  616. if (!(plc.message = malloc (sizeof (* plc.message))))
  617. {
  618. error (1, errno, PLC_NOMEMORY);
  619. }
  620. if (!argc)
  621. {
  622. manager (&amp;plc, loop, wait);
  623. }
  624. while ((argc) &amp;&amp; (* argv))
  625. {
  626. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  627. {
  628. error (1, errno, PLC_BAD_MAC, * argv);
  629. }
  630. manager (&amp;plc, loop, wait);
  631. argc--;
  632. argv++;
  633. }
  634. free (plc.message);
  635. closechannel (&amp;channel);
  636. exit (0);
  637. }
  638. </pre>
  639. <div class='footerlink'>
  640. [<a href='int6kboot.c.html' title=' int6kboot.c '>PREV</a>]
  641. [<a href='toolkit.html' title=' Index '>HOME</a>]
  642. [<a href='int6kdetect.c.html' title=' int6kdetect.c '>NEXT</a>]
  643. </div>
  644. </body>
  645. </html>