plctool.c.html 20 KB

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