amptool.c.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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. amptool.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='amptone.c.html' title=' amptone.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='ampwait.c.html' title=' ampwait.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. * amptool.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/Attributes1.c&quot;
  102. #include &quot;../plc/chipset.c&quot;
  103. #include &quot;../plc/NVRAMInfo.c&quot;
  104. #include &quot;../plc/SDRAMInfo.c&quot;
  105. #include &quot;../plc/Devices.c&quot;
  106. #include &quot;../plc/Confirm.c&quot;
  107. #include &quot;../plc/Display.c&quot;
  108. #include &quot;../plc/FlashNVM.c&quot;
  109. #include &quot;../plc/FactoryDefaults.c&quot;
  110. #include &quot;../plc/HostActionResponse.c&quot;
  111. #include &quot;../plc/Identity1.c&quot;
  112. #include &quot;../plc/NetInfo2.c&quot;
  113. #include &quot;../plc/PushButton.c&quot;
  114. #include &quot;../plc/SetNMK.c&quot;
  115. #include &quot;../plc/Request.c&quot;
  116. #include &quot;../plc/Failure.c&quot;
  117. #include &quot;../plc/PLCSelect.c&quot;
  118. #include &quot;../plc/ReadFirmware1.c&quot;
  119. #include &quot;../plc/ReadMME.c&quot;
  120. #include &quot;../plc/ReadMFG.c&quot;
  121. #include &quot;../plc/ReadParameters1.c&quot;
  122. #include &quot;../plc/RemoteHosts.c&quot;
  123. #include &quot;../plc/ResetDevice.c&quot;
  124. #include &quot;../plc/SendMME.c&quot;
  125. #include &quot;../plc/StationRole.c&quot;
  126. #include &quot;../plc/VersionInfo1.c&quot;
  127. #include &quot;../plc/WriteNVM.c&quot;
  128. #include &quot;../plc/WritePIB.c&quot;
  129. #include &quot;../plc/WaitForReset.c&quot;
  130. #include &quot;../plc/WaitForStart.c&quot;
  131. #include &quot;../plc/WatchdogReport.c&quot;
  132. #include &quot;../plc/StartFirmware1.c&quot;
  133. #endif
  134. #ifndef MAKEFILE
  135. #include &quot;../tools/error.c&quot;
  136. #include &quot;../tools/getoptv.c&quot;
  137. #include &quot;../tools/putoptv.c&quot;
  138. #include &quot;../tools/synonym.c&quot;
  139. #include &quot;../tools/uintspec.c&quot;
  140. #include &quot;../tools/version.c&quot;
  141. #include &quot;../tools/hexdump.c&quot;
  142. #include &quot;../tools/hexencode.c&quot;
  143. #include &quot;../tools/hexdecode.c&quot;
  144. #include &quot;../tools/hexstring.c&quot;
  145. #include &quot;../tools/hexout.c&quot;
  146. #include &quot;../tools/todigit.c&quot;
  147. #include &quot;../tools/checkfilename.c&quot;
  148. #include &quot;../tools/checksum32.c&quot;
  149. #include &quot;../tools/fdchecksum32.c&quot;
  150. #include &quot;../tools/strfbits.c&quot;
  151. #include &quot;../tools/typename.c&quot;
  152. #endif
  153. #ifndef MAKEFILE
  154. #include &quot;../ether/openchannel.c&quot;
  155. #include &quot;../ether/closechannel.c&quot;
  156. #include &quot;../ether/readpacket.c&quot;
  157. #include &quot;../ether/sendpacket.c&quot;
  158. #include &quot;../ether/channel.c&quot;
  159. #endif
  160. #ifndef MAKEFILE
  161. #include &quot;../ram/nvram.c&quot;
  162. #include &quot;../ram/sdramfile.c&quot;
  163. #include &quot;../ram/sdrampeek.c&quot;
  164. #endif
  165. #ifndef MAKEFILE
  166. #include &quot;../nvm/nvmfile1.c&quot;
  167. #endif
  168. #ifndef MAKEFILE
  169. #include &quot;../pib/pibfile1.c&quot;
  170. #include &quot;../pib/pibpeek1.c&quot;
  171. #endif
  172. #ifndef MAKEFILE
  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. #include &quot;../mme/MMECode.c&quot;
  178. #endif
  179. #ifndef MAKEFILE
  180. #include &quot;../key/keys.c&quot;
  181. #endif
  182. /*====================================================================*
  183. * program constants;
  184. *--------------------------------------------------------------------*/
  185. #define AMPTOOL_WAIT 0
  186. #define AMPTOOL_LOOP 1
  187. /*====================================================================*
  188. * program variables;
  189. *--------------------------------------------------------------------*/
  190. static const struct _term_ modules [] =
  191. {
  192. {
  193. &quot;nvm&quot;,
  194. &quot;1&quot;
  195. },
  196. {
  197. &quot;pib&quot;,
  198. &quot;2&quot;
  199. },
  200. {
  201. &quot;both&quot;,
  202. &quot;3&quot;
  203. }
  204. };
  205. static const struct _term_ buttons [] =
  206. {
  207. {
  208. &quot;join&quot;,
  209. &quot;1&quot;
  210. },
  211. {
  212. &quot;leave&quot;,
  213. &quot;2&quot;
  214. },
  215. {
  216. &quot;status&quot;,
  217. &quot;3&quot;
  218. }
  219. };
  220. /*====================================================================*
  221. *
  222. * void manager (struct plc * plc, signed count, signed pause);
  223. *
  224. * perform operations in logical order despite any order specfied
  225. * on the command line; for example read PIB before writing PIB;
  226. *
  227. * operation order is controlled by the order of &quot;if&quot; statements
  228. * shown here; the entire operation sequence can be repeated with
  229. * an optional pause between each iteration;
  230. *
  231. *
  232. *--------------------------------------------------------------------*/
  233. static void manager (struct plc * plc, signed count, signed pause)
  234. {
  235. while (count--)
  236. {
  237. if (_anyset (plc-&gt;flags, PLC_VERSION))
  238. {
  239. VersionInfo1 (plc);
  240. }
  241. if (_anyset (plc-&gt;flags, PLC_ATTRIBUTES))
  242. {
  243. Attributes1 (plc);
  244. }
  245. if (_anyset (plc-&gt;flags, PLC_WATCHDOG_REPORT))
  246. {
  247. WatchdogReport (plc);
  248. }
  249. if (_anyset (plc-&gt;flags, PLC_NVRAM_INFO))
  250. {
  251. NVRAMInfo (plc);
  252. }
  253. if (_anyset (plc-&gt;flags, PLC_SDRAM_INFO))
  254. {
  255. SDRAMInfo (plc);
  256. }
  257. if (_anyset (plc-&gt;flags, PLC_READ_IDENTITY))
  258. {
  259. Identity1 (plc);
  260. }
  261. if (_anyset (plc-&gt;flags, PLC_REMOTEHOSTS))
  262. {
  263. RemoteHosts (plc);
  264. }
  265. if (_anyset (plc-&gt;flags, PLC_NETWORK))
  266. {
  267. NetInfo2 (plc);
  268. }
  269. if (_anyset (plc-&gt;flags, PLC_WRITE_MAC))
  270. {
  271. WriteNVM (plc);
  272. }
  273. if (_anyset (plc-&gt;flags, PLC_READ_MAC))
  274. {
  275. ReadFirmware1 (plc);
  276. }
  277. if (_anyset (plc-&gt;flags, PLC_WRITE_PIB))
  278. {
  279. WritePIB (plc);
  280. }
  281. if (_anyset (plc-&gt;flags, PLC_READ_PIB))
  282. {
  283. ReadParameters1 (plc);
  284. }
  285. if (_anyset (plc-&gt;flags, PLC_HOST_ACTION))
  286. {
  287. HostActionResponse (plc);
  288. }
  289. if (_anyset (plc-&gt;flags, PLC_PUSH_BUTTON))
  290. {
  291. PushButton (plc);
  292. }
  293. if (_anyset (plc-&gt;flags, (PLC_SETLOCALKEY | PLC_SETREMOTEKEY)))
  294. {
  295. SetNMK (plc);
  296. }
  297. if (_anyset (plc-&gt;flags, PLC_FACTORY_DEFAULTS))
  298. {
  299. FactoryDefaults (plc);
  300. }
  301. if (_anyset (plc-&gt;flags, PLC_FLASH_DEVICE))
  302. {
  303. FlashNVM (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;abB:C:d:D:efFgHi:IJ:K:l:mMn:N:p:P:QqrsRt:Tvw:x&quot;,
  348. &quot;device [device] [...]&quot;,
  349. &quot;Qualcomm Atheros AR7x00 Powerline Device Manager&quot;,
  350. &quot;a\tread Device Attributes using VS_OP_ATTRIBUTES&quot;,
  351. &quot;b\tread device enumeration ID table using VS_EM_ID_TABLE&quot;,
  352. &quot;B n\tperform pushbutton action (n) using MS_PB_ENC [1|2|3|'join'|'leave'|'status']&quot;,
  353. &quot;C n\tflash NVRAM with module (n) using VS_MOD_NVM [1|2|3|'nvm'|'pib'|'both']&quot;,
  354. &quot;C n\tflash NVRAM with module (n) using VS_MOD_NVM&quot;,
  355. &quot;d f\tdump and clear watchdog report to file (f) using VS_WD_RPT&quot;,
  356. &quot;D x\tDevice Access Key (DAK) is (x) [&quot; DAK1 &quot;]&quot;,
  357. &quot;e\tredirect stderr to stdout&quot;,
  358. &quot;f\tread NVRAM Configuration using VS_GET_NVM&quot;,
  359. &quot;F[F]\tflash [force] NVRAM with PIB and firmware using VS_MOD_NVM&quot;,
  360. &quot;g\tdisplay multicast group information using VS_MULTICAST_INFO&quot;,
  361. &quot;H\tstop host action requests messages with VS_HOST_ACTION.IND&quot;,
  362. #if defined (WINPCAP) || defined (LIBPCAP)
  363. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  364. #else
  365. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  366. #endif
  367. &quot;I\tread device identity using VS_RD_MOD&quot;,
  368. &quot;J x\tset NMK on remote device (x) via local device using VS_SET_KEY (see -K)&quot;,
  369. &quot;K x\tNetwork Membership Key (NMK) is (x) [&quot; NMK1 &quot;]&quot;,
  370. &quot;l n\tloop (n) times [&quot; LITERAL (AMPTOOL_LOOP) &quot;]&quot;,
  371. &quot;m\tread network membership information using VS_NW_INFO&quot;,
  372. &quot;M\tset NMK on local device using VS_SET_KEY (see -K)&quot;,
  373. &quot;n f\tread NVM from SDRAM to file (f) using VS_RD_MOD&quot;,
  374. &quot;N f\twrite NVM file (f) to SDRAM using VS_WR_MOD&quot;,
  375. &quot;p f\tread PIB from SDRAM to file (f) using VS_RD_MOD&quot;,
  376. &quot;P f\twrite PIB file (f) to SDRAM using VS_WR_MOD&quot;,
  377. &quot;q\tquiet mode&quot;,
  378. &quot;Q\tquick flash (return immediately)&quot;,
  379. &quot;r\tread hardware and firmware revision using VS_SW_VER&quot;,
  380. &quot;R\treset device using VS_RS_DEV&quot;,
  381. &quot;s\tread SDRAM Configuration using VS_RD_CBLOCK&quot;,
  382. &quot;t n\tread timeout is (n) milliseconds [&quot; LITERAL (CHANNEL_TIMEOUT) &quot;]&quot;,
  383. &quot;T\trestore factory defaults using VS_FAC_DEFAULTS&quot;,
  384. &quot;v\tverbose mode&quot;,
  385. &quot;w n\tpause (n) seconds [&quot; LITERAL (AMPTOOL_WAIT) &quot;]&quot;,
  386. &quot;x\texit on error&quot;,
  387. (char const *) (0)
  388. };
  389. #include &quot;../plc/plc.c&quot;
  390. signed loop = AMPTOOL_LOOP;
  391. signed wait = AMPTOOL_WAIT;
  392. signed c;
  393. if (getenv (PLCDEVICE))
  394. {
  395. #if defined (WINPCAP) || defined (LIBPCAP)
  396. channel.ifindex = atoi (getenv (PLCDEVICE));
  397. #else
  398. channel.ifname = strdup (getenv (PLCDEVICE));
  399. #endif
  400. }
  401. optind = 1;
  402. while ((c = getoptv (argc, argv, optv)) != -1)
  403. {
  404. switch (c)
  405. {
  406. case 'a':
  407. _setbits (plc.flags, PLC_ATTRIBUTES);
  408. break;
  409. case 'B':
  410. _setbits (plc.flags, PLC_PUSH_BUTTON);
  411. plc.pushbutton = (unsigned)(uintspec (synonym (optarg, buttons, SIZEOF (buttons)), 0, UCHAR_MAX));
  412. break;
  413. case 'b':
  414. _setbits (plc.flags, PLC_REMOTEHOSTS);
  415. break;
  416. case 'C':
  417. _setbits (plc.flags, PLC_FLASH_DEVICE);
  418. plc.module = (unsigned)(uintspec (synonym (optarg, modules, SIZEOF (modules)), 0, UCHAR_MAX));
  419. break;
  420. case 'd':
  421. _setbits (plc.flags, PLC_WATCHDOG_REPORT);
  422. if (!checkfilename (optarg))
  423. {
  424. error (1, EINVAL, &quot;%s&quot;, optarg);
  425. }
  426. if ((plc.rpt.file = open (plc.rpt.name = optarg, O_BINARY|O_CREAT|O_RDWR|O_TRUNC, FILE_FILEMODE)) == -1)
  427. {
  428. error (1, errno, &quot;%s&quot;, plc.rpt.name);
  429. }
  430. #ifndef WIN32
  431. chown (optarg, getuid (), getgid ());
  432. #endif
  433. plc.readaction = 3;
  434. break;
  435. case 'D':
  436. if (!hexencode (plc.DAK, sizeof (plc.DAK), synonym (optarg, daks, SIZEOF (daks))))
  437. {
  438. error (1, errno, PLC_BAD_DAK, optarg);
  439. }
  440. break;
  441. case 'e':
  442. dup2 (STDOUT_FILENO, STDERR_FILENO);
  443. break;
  444. case 'f':
  445. _setbits (plc.flags, PLC_NVRAM_INFO);
  446. break;
  447. case 'F':
  448. _setbits (plc.module, (VS_MODULE_MAC | VS_MODULE_PIB));
  449. if (_anyset (plc.flags, PLC_FLASH_DEVICE))
  450. {
  451. _setbits (plc.module, VS_MODULE_FORCE);
  452. }
  453. _setbits (plc.flags, PLC_FLASH_DEVICE);
  454. break;
  455. case 'H':
  456. _setbits (plc.flags, PLC_HOST_ACTION);
  457. break;
  458. case 'I':
  459. _setbits (plc.flags, PLC_READ_IDENTITY);
  460. break;
  461. case 'i':
  462. #if defined (WINPCAP) || defined (LIBPCAP)
  463. channel.ifindex = atoi (optarg);
  464. #else
  465. channel.ifname = optarg;
  466. #endif
  467. break;
  468. case 'J':
  469. if (!hexencode (plc.RDA, sizeof (plc.RDA), (char const *)(optarg)))
  470. {
  471. error (1, errno, PLC_BAD_MAC, optarg);
  472. }
  473. _setbits (plc.flags, PLC_SETREMOTEKEY);
  474. break;
  475. case 'K':
  476. if (!hexencode (plc.NMK, sizeof (plc.NMK), synonym (optarg, nmks, SIZEOF (nmks))))
  477. {
  478. error (1, errno, PLC_BAD_NMK, optarg);
  479. }
  480. break;
  481. case 'M':
  482. _setbits (plc.flags, PLC_SETLOCALKEY);
  483. break;
  484. case 'l':
  485. loop = (unsigned)(uintspec (optarg, 0, UINT_MAX));
  486. break;
  487. case 'm':
  488. _setbits (plc.flags, PLC_NETWORK);
  489. break;
  490. case 'N':
  491. if (!checkfilename (optarg))
  492. {
  493. error (1, EINVAL, &quot;%s&quot;, optarg);
  494. }
  495. if ((plc.NVM.file = open (plc.NVM.name = optarg, O_BINARY|O_RDONLY)) == -1)
  496. {
  497. error (1, errno, &quot;%s&quot;, plc.NVM.name);
  498. }
  499. if (nvmfile1 (&amp;plc.NVM))
  500. {
  501. error (1, errno, &quot;Bad firmware file: %s&quot;, plc.NVM.name);
  502. }
  503. _setbits (plc.flags, PLC_WRITE_MAC);
  504. break;
  505. case 'n':
  506. if (!checkfilename (optarg))
  507. {
  508. error (1, EINVAL, &quot;%s&quot;, optarg);
  509. }
  510. if ((plc.nvm.file = open (plc.nvm.name = optarg, O_BINARY|O_CREAT|O_RDWR|O_TRUNC, FILE_FILEMODE)) == -1)
  511. {
  512. error (1, errno, &quot;%s&quot;, plc.nvm.name);
  513. }
  514. #ifndef WIN32
  515. chown (optarg, getuid (), getgid ());
  516. #endif
  517. _setbits (plc.flags, PLC_READ_MAC);
  518. break;
  519. case 'P':
  520. if (!checkfilename (optarg))
  521. {
  522. error (1, EINVAL, &quot;%s&quot;, optarg);
  523. }
  524. if ((plc.PIB.file = open (plc.PIB.name = optarg, O_BINARY|O_RDONLY)) == -1)
  525. {
  526. error (1, errno, &quot;%s&quot;, plc.PIB.name);
  527. }
  528. if (pibfile1 (&amp;plc.PIB))
  529. {
  530. error (1, errno, &quot;Bad parameter file: %s&quot;, plc.PIB.name);
  531. }
  532. _setbits (plc.flags, PLC_WRITE_PIB);
  533. break;
  534. case 'p':
  535. if (!checkfilename (optarg))
  536. {
  537. error (1, EINVAL, &quot;%s&quot;, optarg);
  538. }
  539. if ((plc.pib.file = open (plc.pib.name = optarg, O_BINARY|O_CREAT|O_RDWR|O_TRUNC, FILE_FILEMODE)) == -1)
  540. {
  541. error (1, errno, &quot;%s&quot;, plc.pib.name);
  542. }
  543. #ifndef WIN32
  544. chown (optarg, getuid (), getgid ());
  545. #endif
  546. _setbits (plc.flags, PLC_READ_PIB);
  547. break;
  548. case 'Q':
  549. _setbits (plc.flags, PLC_QUICK_FLASH);
  550. break;
  551. case 'q':
  552. _setbits (channel.flags, CHANNEL_SILENCE);
  553. _setbits (plc.flags, PLC_SILENCE);
  554. break;
  555. case 'R':
  556. _setbits (plc.flags, PLC_RESET_DEVICE);
  557. break;
  558. case 'r':
  559. _setbits (plc.flags, PLC_VERSION);
  560. break;
  561. case 's':
  562. _setbits (plc.flags, PLC_SDRAM_INFO);
  563. break;
  564. case 't':
  565. channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
  566. break;
  567. case 'T':
  568. _setbits (plc.flags, PLC_FACTORY_DEFAULTS);
  569. break;
  570. case 'v':
  571. _setbits (channel.flags, CHANNEL_VERBOSE);
  572. _setbits (plc.flags, PLC_VERBOSE);
  573. break;
  574. case 'V':
  575. _setbits (plc.flags, PLC_SNIFFER);
  576. plc.action = (uint8_t)(uintspec (optarg, 0, UCHAR_MAX));
  577. break;
  578. case 'w':
  579. wait = (unsigned)(uintspec (optarg, 0, 3600));
  580. break;
  581. case 'x':
  582. _setbits (plc.flags, PLC_BAILOUT);
  583. break;
  584. default:
  585. break;
  586. }
  587. }
  588. argc -= optind;
  589. argv += optind;
  590. if (argc != 1)
  591. {
  592. if (plc.nvm.file != -1)
  593. {
  594. error (1, ECANCELED, PLC_NODEVICE);
  595. }
  596. if (plc.pib.file != -1)
  597. {
  598. error (1, ECANCELED, PLC_NODEVICE);
  599. }
  600. if (plc.rpt.file != -1)
  601. {
  602. error (1, ECANCELED, PLC_NODEVICE);
  603. }
  604. }
  605. openchannel (&amp;channel);
  606. if (!(plc.message = malloc (sizeof (* plc.message))))
  607. {
  608. error (1, errno, PLC_NOMEMORY);
  609. }
  610. if (!argc)
  611. {
  612. manager (&amp;plc, loop, wait);
  613. }
  614. while ((argc) &amp;&amp; (* argv))
  615. {
  616. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  617. {
  618. error (1, errno, PLC_BAD_MAC, * argv);
  619. }
  620. manager (&amp;plc, loop, wait);
  621. argc--;
  622. argv++;
  623. }
  624. free (plc.message);
  625. closechannel (&amp;channel);
  626. exit (0);
  627. }
  628. </pre>
  629. <div class='footerlink'>
  630. [<a href='amptone.c.html' title=' amptone.c '>PREV</a>]
  631. [<a href='toolkit.html' title=' Index '>HOME</a>]
  632. [<a href='ampwait.c.html' title=' ampwait.c '>NEXT</a>]
  633. </div>
  634. </body>
  635. </html>