plcID.c.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. plcID.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='plchostd.c.html' title=' plchostd.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='plclist.c.html' title=' plclist.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. * plcID.c - Qualcomm Atheros Powerline Device Identity
  64. *
  65. *
  66. * Contributor(s):
  67. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  68. *
  69. *--------------------------------------------------------------------*/
  70. /*====================================================================*&quot;
  71. * system header files;
  72. *--------------------------------------------------------------------*/
  73. #include &lt;unistd.h&gt;
  74. #include &lt;stdlib.h&gt;
  75. #include &lt;limits.h&gt;
  76. #include &lt;string.h&gt;
  77. #include &lt;ctype.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;../ram/nvram.h&quot;
  92. #include &quot;../ram/sdram.h&quot;
  93. #include &quot;../nvm/nvm.h&quot;
  94. #include &quot;../pib/pib.h&quot;
  95. #include &quot;../mme/mme.h&quot;
  96. /*====================================================================*
  97. * custom source files;
  98. *--------------------------------------------------------------------*/
  99. #ifndef MAKEFILE
  100. #include &quot;../tools/getoptv.c&quot;
  101. #include &quot;../tools/putoptv.c&quot;
  102. #include &quot;../tools/version.c&quot;
  103. #include &quot;../tools/uintspec.c&quot;
  104. #include &quot;../tools/hexencode.c&quot;
  105. #include &quot;../tools/hexdecode.c&quot;
  106. #include &quot;../tools/todigit.c&quot;
  107. #include &quot;../tools/hexdump.c&quot;
  108. #include &quot;../tools/hexout.c&quot;
  109. #include &quot;../tools/error.c&quot;
  110. #include &quot;../tools/synonym.c&quot;
  111. #include &quot;../tools/checksum32.c&quot;
  112. #include &quot;../tools/typename.c&quot;
  113. #endif
  114. #ifndef MAKEFILE
  115. #include &quot;../plc/Display.c&quot;
  116. #include &quot;../plc/Devices.c&quot;
  117. #include &quot;../plc/Failure.c&quot;
  118. #include &quot;../plc/ReadMME.c&quot;
  119. #include &quot;../plc/SendMME.c&quot;
  120. #include &quot;../plc/WaitForStart.c&quot;
  121. #include &quot;../plc/chipset.c&quot;
  122. #endif
  123. #ifndef MAKEFILE
  124. #include &quot;../mme/EthernetHeader.c&quot;
  125. #include &quot;../mme/QualcommHeader.c&quot;
  126. #include &quot;../mme/UnwantedMessage.c&quot;
  127. #endif
  128. #ifndef MAKEFILE
  129. #include &quot;../ether/openchannel.c&quot;
  130. #include &quot;../ether/closechannel.c&quot;
  131. #include &quot;../ether/readpacket.c&quot;
  132. #include &quot;../ether/sendpacket.c&quot;
  133. #include &quot;../ether/channel.c&quot;
  134. #endif
  135. #ifndef MAKEFILE
  136. #include &quot;../mme/MMECode.c&quot;
  137. #endif
  138. /*====================================================================*
  139. * program constants;
  140. *--------------------------------------------------------------------*/
  141. #define PLCID_DAK 0
  142. #define PLCID_NMK 1
  143. #define PLCID_MAC 2
  144. #define PLCID_MFG 3
  145. #define PLCID_USR 4
  146. #define PLCID_NET 5
  147. /*====================================================================*
  148. *
  149. * signed PLCSelect (struct plc * plc, signed old (struct plc *), signed new (struct plc *));
  150. *
  151. * plc.h
  152. *
  153. * wait for device to start in order to determine chipset then call
  154. * the approproate function based on chipset; unfortunately, chipset
  155. * detection and selection may not be this simple in the future;
  156. *
  157. * Contributor(s):
  158. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  159. *
  160. *--------------------------------------------------------------------*/
  161. signed PLCSelect (struct plc * plc, signed old (struct plc *), signed new (struct plc *))
  162. {
  163. char firmware [PLC_VERSION_STRING];
  164. if (WaitForStart (plc, firmware, sizeof (firmware)))
  165. {
  166. Failure (plc, PLC_NODETECT);
  167. exit (1);
  168. }
  169. return ((plc-&gt;hardwareID &lt; CHIPSET_QCA7420)? old (plc): new (plc));
  170. }
  171. /*====================================================================*
  172. *
  173. * signed ReadKey1 (struct plc * plc);
  174. *
  175. * read the first block of the PIB from a device then echo one of
  176. * several parameters on stdout as a string; program output can be
  177. * used in scripts to define variables or compare strings;
  178. *
  179. * this function is an abridged version of ReadParameters(); it reads only
  180. * the first 1024 bytes of the PIB then stops; most parameters of
  181. * general interest occur in that block;
  182. *
  183. *--------------------------------------------------------------------*/
  184. static signed ReadKey1 (struct plc * plc)
  185. {
  186. static signed count = 0;
  187. struct channel * channel = (struct channel *) (plc-&gt;channel);
  188. struct message * message = (struct message *) (plc-&gt;message);
  189. #ifndef __GNUC__
  190. #pragma pack (push,1)
  191. #endif
  192. struct __packed vs_rd_mod_request
  193. {
  194. struct ethernet_hdr ethernet;
  195. struct qualcomm_hdr qualcomm;
  196. uint8_t MODULEID;
  197. uint8_t RESERVED;
  198. uint16_t MLENGTH;
  199. uint32_t MOFFSET;
  200. uint8_t DAK [16];
  201. }
  202. * request = (struct vs_rd_mod_request *) (message);
  203. struct __packed vs_rd_mod_confirm
  204. {
  205. struct ethernet_hdr ethernet;
  206. struct qualcomm_hdr qualcomm;
  207. uint8_t MSTATUS;
  208. uint8_t RESERVED1 [3];
  209. uint8_t MODULEID;
  210. uint8_t RESERVED2;
  211. uint16_t MLENGTH;
  212. uint32_t MOFFSET;
  213. uint32_t MCHKSUM;
  214. struct simple_pib pib;
  215. }
  216. * confirm = (struct vs_rd_mod_confirm *) (message);
  217. #ifndef __GNUC__
  218. #pragma pack (pop)
  219. #endif
  220. memset (message, 0, sizeof (* message));
  221. EthernetHeader (&amp; request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  222. QualcommHeader (&amp; request-&gt;qualcomm, 0, (VS_RD_MOD | MMTYPE_REQ));
  223. request-&gt;MODULEID = VS_MODULE_PIB;
  224. request-&gt;MLENGTH = HTOLE16 (PLC_RECORD_SIZE);
  225. request-&gt;MOFFSET = HTOLE32 (0);
  226. plc-&gt;packetsize = ETHER_MIN_LEN - ETHER_CRC_LEN;
  227. if (SendMME (plc) &lt;= 0)
  228. {
  229. error (1, errno, CHANNEL_CANTSEND);
  230. }
  231. while (ReadMME (plc, 0, (VS_RD_MOD | MMTYPE_CNF)) &gt; 0)
  232. {
  233. if (confirm-&gt;MSTATUS)
  234. {
  235. Failure (plc, PLC_WONTDOIT);
  236. return (-1);
  237. }
  238. if (count++ &gt; 0)
  239. {
  240. putc (plc-&gt;coupling, stdout);
  241. }
  242. if (plc-&gt;action == PLCID_MAC)
  243. {
  244. hexout (confirm-&gt;pib.MAC, sizeof (confirm-&gt;pib.MAC), HEX_EXTENDER, 0, stdout);
  245. }
  246. else if (plc-&gt;action == PLCID_DAK)
  247. {
  248. hexout (confirm-&gt;pib.DAK, sizeof (confirm-&gt;pib.DAK), HEX_EXTENDER, 0, stdout);
  249. }
  250. else if (plc-&gt;action == PLCID_NMK)
  251. {
  252. hexout (confirm-&gt;pib.NMK, sizeof (confirm-&gt;pib.NMK), HEX_EXTENDER, 0, stdout);
  253. }
  254. else if (plc-&gt;action == PLCID_MFG)
  255. {
  256. confirm-&gt;pib.MFG [PIB_HFID_LEN -1] = (char) (0);
  257. printf (&quot;%s&quot;, confirm-&gt;pib.MFG);
  258. }
  259. else if (plc-&gt;action == PLCID_USR)
  260. {
  261. confirm-&gt;pib.USR [PIB_HFID_LEN -1] = (char) (0);
  262. printf (&quot;%s&quot;, confirm-&gt;pib.USR);
  263. }
  264. else if (plc-&gt;action == PLCID_NET)
  265. {
  266. confirm-&gt;pib.NET [PIB_HFID_LEN -1] = (char) (0);
  267. printf (&quot;%s&quot;, confirm-&gt;pib.NET);
  268. }
  269. }
  270. if (plc-&gt;packetsize &lt; 0)
  271. {
  272. error (1, errno, CHANNEL_CANTREAD);
  273. }
  274. return (0);
  275. }
  276. /*====================================================================*
  277. *
  278. * signed ReadKey2 (struct plc * plc);
  279. *
  280. * plc.h
  281. *
  282. * read start of parameter chain from the device using a single
  283. * VS_MODULE_OPERATION message; search parameter chain for PIB and
  284. * print requested plc-&gt;action on stdout;
  285. *
  286. * Contributor(s):
  287. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  288. *
  289. *--------------------------------------------------------------------*/
  290. static signed ReadKey2 (struct plc * plc)
  291. {
  292. static signed count = 0;
  293. struct channel * channel = (struct channel *) (plc-&gt;channel);
  294. struct message * message = (struct message *) (plc-&gt;message);
  295. struct nvm_header2 * nvm_header;
  296. uint32_t origin = ~ 0;
  297. uint32_t offset = 0;
  298. signed module = 0;
  299. char * filename = &quot;device&quot;;
  300. #ifndef __GNUC__
  301. #pragma pack (push,1)
  302. #endif
  303. struct __packed vs_module_operation_read_request
  304. {
  305. struct ethernet_hdr ethernet;
  306. struct qualcomm_hdr qualcomm;
  307. uint32_t RESERVED;
  308. uint8_t NUM_OP_DATA;
  309. struct __packed
  310. {
  311. uint16_t MOD_OP;
  312. uint16_t MOD_OP_DATA_LEN;
  313. uint32_t MOD_OP_RSVD;
  314. uint16_t MODULE_ID;
  315. uint16_t MODULE_SUB_ID;
  316. uint16_t MODULE_LENGTH;
  317. uint32_t MODULE_OFFSET;
  318. }
  319. MODULE_SPEC;
  320. }
  321. * request = (struct vs_module_operation_read_request *) (message);
  322. struct __packed vs_module_operation_read_confirm
  323. {
  324. struct ethernet_hdr ethernet;
  325. struct qualcomm_hdr qualcomm;
  326. uint16_t MSTATUS;
  327. uint16_t ERR_REC_CODE;
  328. uint32_t RESERVED;
  329. uint8_t NUM_OP_DATA;
  330. struct __packed
  331. {
  332. uint16_t MOD_OP;
  333. uint16_t MOD_OP_DATA_LEN;
  334. uint32_t MOD_OP_RSVD;
  335. uint16_t MODULE_ID;
  336. uint16_t MODULE_SUB_ID;
  337. uint16_t MODULE_LENGTH;
  338. uint32_t MODULE_OFFSET;
  339. }
  340. MODULE_SPEC;
  341. uint8_t MODULE_DATA [PLC_MODULE_SIZE];
  342. }
  343. * confirm = (struct vs_module_operation_read_confirm *) (message);
  344. #ifndef __GNUC__
  345. #pragma pack (pop)
  346. #endif
  347. memset (message, 0, sizeof (* message));
  348. EthernetHeader (&amp; request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  349. QualcommHeader (&amp; request-&gt;qualcomm, 0, (VS_MODULE_OPERATION | MMTYPE_REQ));
  350. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  351. request-&gt;NUM_OP_DATA = 1;
  352. request-&gt;MODULE_SPEC.MOD_OP = HTOLE16 (0);
  353. request-&gt;MODULE_SPEC.MOD_OP_DATA_LEN = HTOLE16 (sizeof (request-&gt;MODULE_SPEC));
  354. request-&gt;MODULE_SPEC.MOD_OP_RSVD = HTOLE32 (0);
  355. request-&gt;MODULE_SPEC.MODULE_ID = HTOLE16 (PLC_MODULEID_PARAMETERS);
  356. request-&gt;MODULE_SPEC.MODULE_SUB_ID = HTOLE16 (0);
  357. request-&gt;MODULE_SPEC.MODULE_LENGTH = HTOLE16 (PLC_MODULE_SIZE);
  358. request-&gt;MODULE_SPEC.MODULE_OFFSET = HTOLE32 (0);
  359. if (SendMME (plc) &lt;= 0)
  360. {
  361. error (1, errno, CHANNEL_CANTSEND);
  362. }
  363. while (ReadMME (plc, 0, (VS_MODULE_OPERATION | MMTYPE_CNF)) &gt; 0)
  364. {
  365. if (confirm-&gt;MSTATUS)
  366. {
  367. Failure (plc, PLC_WONTDOIT);
  368. return (-1);
  369. }
  370. if (count++ &gt; 0)
  371. {
  372. putc (plc-&gt;coupling, stdout);
  373. }
  374. do
  375. {
  376. nvm_header = (struct nvm_header2 *) (&amp; confirm-&gt;MODULE_DATA [offset]);
  377. if (LE16TOH (nvm_header-&gt;MajorVersion) != 1)
  378. {
  379. if (_allclr (plc-&gt;flags, PLC_SILENCE))
  380. {
  381. error (0, errno, NVM_HDR_VERSION, filename, module);
  382. }
  383. return (-1);
  384. }
  385. if (LE16TOH (nvm_header-&gt;MinorVersion) != 1)
  386. {
  387. if (_allclr (plc-&gt;flags, PLC_SILENCE))
  388. {
  389. error (0, errno, NVM_HDR_VERSION, filename, module);
  390. }
  391. return (-1);
  392. }
  393. if (LE32TOH (nvm_header-&gt;PrevHeader) != origin)
  394. {
  395. if (_allclr (plc-&gt;flags, PLC_SILENCE))
  396. {
  397. error (0, errno, NVM_HDR_LINK, filename, module);
  398. }
  399. return (-1);
  400. }
  401. if (checksum32 (nvm_header, sizeof (* nvm_header), 0))
  402. {
  403. error (0, 0, NVM_HDR_CHECKSUM, filename, module);
  404. return (-1);
  405. }
  406. origin = offset;
  407. offset += sizeof (* nvm_header);
  408. if (LE32TOH (nvm_header-&gt;ImageType) == NVM_IMAGE_PIB)
  409. {
  410. struct simple_pib * pib = (struct simple_pib *) (&amp; confirm-&gt;MODULE_DATA [offset]);
  411. if (plc-&gt;action == PLCID_MAC)
  412. {
  413. hexout (pib-&gt;MAC, sizeof (pib-&gt;MAC), HEX_EXTENDER, 0, stdout);
  414. }
  415. else if (plc-&gt;action == PLCID_DAK)
  416. {
  417. hexout (pib-&gt;DAK, sizeof (pib-&gt;DAK), HEX_EXTENDER, 0, stdout);
  418. }
  419. else if (plc-&gt;action == PLCID_NMK)
  420. {
  421. hexout (pib-&gt;NMK, sizeof (pib-&gt;NMK), HEX_EXTENDER, 0, stdout);
  422. }
  423. else if (plc-&gt;action == PLCID_MFG)
  424. {
  425. pib-&gt;MFG [PIB_HFID_LEN -1] = (char) (0);
  426. printf (&quot;%s&quot;, pib-&gt;MFG);
  427. }
  428. else if (plc-&gt;action == PLCID_USR)
  429. {
  430. pib-&gt;USR [PIB_HFID_LEN -1] = (char) (0);
  431. printf (&quot;%s&quot;, pib-&gt;USR);
  432. }
  433. else if (plc-&gt;action == PLCID_NET)
  434. {
  435. pib-&gt;NET [PIB_HFID_LEN -1] = (char) (0);
  436. printf (&quot;%s&quot;, pib-&gt;NET);
  437. }
  438. break;
  439. }
  440. if (checksum32 (&amp; confirm-&gt;MODULE_DATA [offset], LE32TOH (nvm_header-&gt;ImageLength), nvm_header-&gt;ImageChecksum))
  441. {
  442. if (_allclr (plc-&gt;flags, PLC_SILENCE))
  443. {
  444. error (0, errno, NVM_IMG_CHECKSUM, filename, module);
  445. }
  446. return (-1);
  447. }
  448. offset += LE32TOH (nvm_header-&gt;ImageLength);
  449. module++;
  450. }
  451. while (~ nvm_header-&gt;NextHeader);
  452. }
  453. if (plc-&gt;packetsize &lt; 0)
  454. {
  455. error (1, errno, CHANNEL_CANTREAD);
  456. }
  457. return (0);
  458. }
  459. /*====================================================================*
  460. *
  461. * int main (int argc, char const * argv []);
  462. *
  463. *--------------------------------------------------------------------*/
  464. int main (int argc, char const * argv [])
  465. {
  466. extern struct channel channel;
  467. static char const * optv [] =
  468. {
  469. &quot;Ac:Dei:MnNqSUv&quot;,
  470. &quot;device&quot;,
  471. &quot;Qualcomm Atheros Powerline Device Identity&quot;,
  472. &quot;A\tEthernet address (MAC)&quot;,
  473. &quot;c c\tcharacter delimiter is (c)&quot;,
  474. &quot;D\tDevice Access Key (DAK)&quot;,
  475. &quot;e\tredirect stderr to stdout&quot;,
  476. #if defined (WINPCAP) || defined (LIBPCAP)
  477. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  478. #else
  479. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  480. #endif
  481. &quot;M\tNetwork Membership Key (NMK)&quot;,
  482. &quot;n\tappend newline on output&quot;,
  483. &quot;N\tnetwork HFID&quot;,
  484. &quot;q\tquiet mode&quot;,
  485. &quot;S\tmanufacturer HFID&quot;,
  486. &quot;U\tuser HFID&quot;,
  487. &quot;v\tverbose mode&quot;,
  488. (char const *) (0)
  489. };
  490. #include &quot;../plc/plc.c&quot;
  491. signed c;
  492. plc.action = PLCID_DAK;
  493. plc.coupling = '\n';
  494. if (getenv (PLCDEVICE))
  495. {
  496. #if defined (WINPCAP) || defined (LIBPCAP)
  497. channel.ifindex = atoi (getenv (PLCDEVICE));
  498. #else
  499. channel.ifname = strdup (getenv (PLCDEVICE));
  500. #endif
  501. }
  502. optind = 1;
  503. while (~ (c = getoptv (argc, argv, optv)))
  504. {
  505. switch (c)
  506. {
  507. case 'A':
  508. plc.action = PLCID_MAC;
  509. break;
  510. case 'c':
  511. plc.coupling = * optarg;
  512. break;
  513. case 'D':
  514. plc.action = PLCID_DAK;
  515. break;
  516. case 'e':
  517. dup2 (STDOUT_FILENO, STDERR_FILENO);
  518. break;
  519. case 'i':
  520. #if defined (WINPCAP) || defined (LIBPCAP)
  521. channel.ifindex = atoi (optarg);
  522. #else
  523. channel.ifname = optarg;
  524. #endif
  525. break;
  526. case 'M':
  527. plc.action = PLCID_NMK;
  528. break;
  529. case 'n':
  530. _setbits (plc.flags, PLC_NEWLINE);
  531. break;
  532. case 'N':
  533. plc.action = PLCID_NET;
  534. break;
  535. case 'q':
  536. _setbits (channel.flags, CHANNEL_SILENCE);
  537. _setbits (plc.flags, PLC_SILENCE);
  538. break;
  539. case 'S':
  540. plc.action = PLCID_MFG;
  541. break;
  542. case 'U':
  543. plc.action = PLCID_USR;
  544. break;
  545. case 'v':
  546. _setbits (channel.flags, CHANNEL_VERBOSE);
  547. _setbits (plc.flags, PLC_VERBOSE);
  548. break;
  549. default:
  550. break;
  551. }
  552. }
  553. argc -= optind;
  554. argv += optind;
  555. openchannel (&amp; channel);
  556. if (! (plc.message = malloc (sizeof (* plc.message))))
  557. {
  558. error (1, errno, PLC_NOMEMORY);
  559. }
  560. if (! argc)
  561. {
  562. PLCSelect (&amp; plc, ReadKey1, ReadKey2);
  563. }
  564. while ((argc) &amp;&amp; (* argv))
  565. {
  566. if (! hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  567. {
  568. error (1, errno, PLC_BAD_MAC, * argv);
  569. }
  570. PLCSelect (&amp; plc, ReadKey1, ReadKey2);
  571. argv++;
  572. argc--;
  573. }
  574. if (_anyset (plc.flags, PLC_NEWLINE))
  575. {
  576. printf (&quot;\n&quot;);
  577. }
  578. free (plc.message);
  579. closechannel (&amp; channel);
  580. return (0);
  581. }
  582. </pre>
  583. <div class='footerlink'>
  584. [<a href='plchostd.c.html' title=' plchostd.c '>PREV</a>]
  585. [<a href='toolkit.html' title=' Index '>HOME</a>]
  586. [<a href='plclist.c.html' title=' plclist.c '>NEXT</a>]
  587. </div>
  588. </body>
  589. </html>