plclog.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * plclog.c - Atheros INT6x00 Log Retrieval Utility;
  44. *
  45. *
  46. * Contributor(s):
  47. * Charles Maier
  48. * Nathaniel Houghton
  49. *
  50. *--------------------------------------------------------------------*/
  51. /*====================================================================*"
  52. * system header files;
  53. *--------------------------------------------------------------------*/
  54. #include <unistd.h>
  55. #include <stdint.h>
  56. #include <stdlib.h>
  57. #include <ctype.h>
  58. /*====================================================================*
  59. * custom header files;
  60. *--------------------------------------------------------------------*/
  61. #include "../tools/getoptv.h"
  62. #include "../tools/putoptv.h"
  63. #include "../tools/memory.h"
  64. #include "../tools/number.h"
  65. #include "../tools/symbol.h"
  66. #include "../tools/format.h"
  67. #include "../tools/base64.h"
  68. #include "../tools/types.h"
  69. #include "../tools/flags.h"
  70. #include "../tools/files.h"
  71. #include "../tools/error.h"
  72. #include "../ether/channel.h"
  73. #include "../plc/plc.h"
  74. /*====================================================================*
  75. * custom source files;
  76. *--------------------------------------------------------------------*/
  77. #ifndef MAKEFILE
  78. #include "../plc/Devices.c"
  79. #include "../plc/Failure.c"
  80. #include "../plc/SendMME.c"
  81. #include "../plc/ReadMME.c"
  82. #include "../mme/EthernetHeader.c"
  83. #include "../mme/QualcommHeader.c"
  84. #include "../mme/UnwantedMessage.c"
  85. #endif
  86. #ifndef MAKEFILE
  87. #include "../tools/error.c"
  88. #include "../tools/getoptv.c"
  89. #include "../tools/putoptv.c"
  90. #include "../tools/version.c"
  91. #include "../tools/uintspec.c"
  92. #include "../tools/hexdump.c"
  93. #include "../tools/hexencode.c"
  94. #include "../tools/hexdecode.c"
  95. #include "../tools/hexstring.c"
  96. #include "../tools/todigit.c"
  97. #include "../tools/strfbits.c"
  98. #include "../tools/synonym.c"
  99. #include "../tools/b64dump.c"
  100. #endif
  101. #ifndef MAKEFILE
  102. #include "../ether/openchannel.c"
  103. #include "../ether/closechannel.c"
  104. #include "../ether/readpacket.c"
  105. #include "../ether/sendpacket.c"
  106. #include "../ether/channel.c"
  107. #endif
  108. #ifndef MAKEFILE
  109. #include "../mme/MMECode.c"
  110. #endif
  111. /*====================================================================*
  112. * constants
  113. *--------------------------------------------------------------------*/
  114. #define MSTATUS_STATUS (7 << 0)
  115. #define MSTATUS_MAJORVERSION (1 << 3)
  116. #define MSTATUS_BUFFERISLOCKED (1 << 4)
  117. #define MSTATUS_AUTOLOCKONRESET (1 << 5)
  118. #define MSTATUS_UNSOLICITEDUPDATES (1 << 6)
  119. #define MSTATUS_UNSOLICITED (1 << 7)
  120. #define WD_SESSION_ID 0xFEFE
  121. #define WD_ACTION_READ (1 << 0)
  122. #define WD_ACTION_CLEAR (1 << 1)
  123. #define WD_ACTION_CUSTOM (1 << 2)
  124. /*====================================================================*
  125. *
  126. * static signed PrintRawWatchdogReport (struct plc * plc);
  127. *
  128. * Read the watchdog report using VS_WD_RPT and write to file in
  129. * binary or XML format; this file can be sent to Atheros Support
  130. * for analysis;
  131. *
  132. * The XML version rquires additional information and so VS_SW_VER
  133. * is used to collect it;
  134. *
  135. * This VW_WD_RPT message protocol returns an indication message,
  136. * not a confirm message;
  137. *
  138. *
  139. * Contributor(s):
  140. * Charles Maier
  141. *
  142. *--------------------------------------------------------------------*/
  143. static signed PrintRawWatchdogReport (struct plc * plc)
  144. {
  145. struct channel * channel = (struct channel *)(plc->channel);
  146. struct message * message = (struct message *)(plc->message);
  147. #ifndef __GNUC__
  148. #pragma pack (push,1)
  149. #endif
  150. struct __packed vs_wd_rpt_request
  151. {
  152. struct ethernet_hdr ethernet;
  153. struct qualcomm_hdr qualcomm;
  154. uint16_t SESSIONID;
  155. uint8_t CLR;
  156. }
  157. * request = (struct vs_wd_rpt_request *) (message);
  158. struct __packed vs_wd_rpt_ind
  159. {
  160. struct ethernet_hdr ethernet;
  161. struct qualcomm_hdr qualcomm;
  162. uint8_t MSTATUS;
  163. uint16_t SESSIONID;
  164. uint8_t NUMPARTS;
  165. uint8_t CURPART;
  166. uint16_t RDATALENGTH;
  167. uint8_t RDATAOFFSET;
  168. uint8_t RDATA [1];
  169. }
  170. * indicate = (struct vs_wd_rpt_ind *) (message);
  171. #ifndef __GNUC__
  172. #pragma pack (pop)
  173. #endif
  174. memset (message, 0, sizeof (* message));
  175. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  176. QualcommHeader (&request->qualcomm, 0, (VS_WD_RPT | MMTYPE_REQ));
  177. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  178. request->SESSIONID = HTOLE16 (WD_SESSION_ID);
  179. request->CLR = plc->readaction;
  180. if (SendMME (plc) <= 0)
  181. {
  182. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  183. return (-1);
  184. }
  185. do
  186. {
  187. if (ReadMME (plc, 0, (VS_WD_RPT | MMTYPE_IND)) <= 0)
  188. {
  189. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  190. return (-1);
  191. }
  192. if (indicate->MSTATUS)
  193. {
  194. Failure (plc, PLC_WONTDOIT);
  195. return (-1);
  196. }
  197. write (STDOUT_FILENO, indicate->RDATA + indicate->RDATAOFFSET, LE16TOH (indicate->RDATALENGTH) - indicate->RDATAOFFSET);
  198. }
  199. while (indicate->CURPART < indicate->NUMPARTS);
  200. return (0);
  201. }
  202. /*====================================================================*
  203. *
  204. * static signed PrintWatchdogReport (struct plc * plc, char const * version);
  205. *
  206. * Read the watchdog report using VS_WD_RPT and write to file in
  207. * XML format; this file may be sent to QCA for analysis;
  208. *
  209. * The XML version rquires additional information and so VS_SW_VER
  210. * is used to collect it;
  211. *
  212. * This VW_WD_RPT message protocol returns an indication message,
  213. * not a confirm message;
  214. *
  215. *
  216. * Contributor(s):
  217. * Charles Maier
  218. *
  219. *--------------------------------------------------------------------*/
  220. static signed PrintWatchdogReport (struct plc * plc, char const * version)
  221. {
  222. struct channel * channel = (struct channel *)(plc->channel);
  223. struct message * message = (struct message *)(plc->message);
  224. #ifndef __GNUC__
  225. #pragma pack (push,1)
  226. #endif
  227. struct __packed vs_wd_rpt_request
  228. {
  229. struct ethernet_hdr ethernet;
  230. struct qualcomm_hdr qualcomm;
  231. uint16_t SESSIONID;
  232. uint8_t CLR;
  233. }
  234. * request = (struct vs_wd_rpt_request *) (message);
  235. struct __packed vs_wd_rpt_ind
  236. {
  237. struct ethernet_hdr ethernet;
  238. struct qualcomm_hdr qualcomm;
  239. uint8_t MSTATUS;
  240. uint16_t SESSIONID;
  241. uint8_t NUMPARTS;
  242. uint8_t CURPART;
  243. uint16_t RDATALENGTH;
  244. uint8_t RDATAOFFSET;
  245. uint8_t RDATA [1];
  246. }
  247. * indicate = (struct vs_wd_rpt_ind *) (message);
  248. #ifndef __GNUC__
  249. #pragma pack (pop)
  250. #endif
  251. memset (message, 0, sizeof (* message));
  252. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  253. QualcommHeader (&request->qualcomm, 0, (VS_WD_RPT | MMTYPE_REQ));
  254. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  255. request->SESSIONID = HTOLE16 (WD_SESSION_ID);
  256. request->CLR = plc->readaction;
  257. if (SendMME (plc) <= 0)
  258. {
  259. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  260. return (-1);
  261. }
  262. printf ("<WatchdogReport>");
  263. do
  264. {
  265. if (ReadMME (plc, 0, (VS_WD_RPT | MMTYPE_IND)) <= 0)
  266. {
  267. printf ("</WatchdogReport>");
  268. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  269. return (-1);
  270. }
  271. if (indicate->MSTATUS)
  272. {
  273. printf ("</WatchdogReport>");
  274. Failure (plc, PLC_WONTDOIT);
  275. return (-1);
  276. }
  277. printf ("<Packet>");
  278. printf ("<Version>%s</Version>", version);
  279. printf ("<OUI>%s</OUI>", "00B052");
  280. printf ("<Status>0</Status>");
  281. printf ("<SessionId>0</SessionId>");
  282. printf ("<NumParts>%d</NumParts>", indicate->NUMPARTS);
  283. printf ("<CurPart>%d</CurPart>", indicate->CURPART);
  284. printf ("<DataLength>%d</DataLength>", LE16TOH (indicate->RDATALENGTH));
  285. printf ("<DataOffset>%d</DataOffset>", indicate->RDATAOFFSET);
  286. printf ("<Data>");
  287. b64dump (indicate->RDATA, LE16TOH (indicate->RDATALENGTH), 0, stdout);
  288. printf ("</Data>");
  289. printf ("</Packet>");
  290. }
  291. while (indicate->CURPART < indicate->NUMPARTS);
  292. printf ("</WatchdogReport>");
  293. return (0);
  294. }
  295. /*====================================================================*
  296. *
  297. * static signed PrintCheckpointReport (struct plc * plc, char const * version);
  298. *
  299. * Read the watchdog reqport using VS_CP_RPT and write to file in
  300. * binary or XML format; this file can be sent to Atheros Support
  301. * for analysis;
  302. *
  303. * The XML version rquires additional information and so VS_SW_VER
  304. * is used to collect it;
  305. *
  306. * This VW_WD_RPT message protocol returns an indication message,
  307. * not a confirm message;
  308. *
  309. *
  310. * Contributor(s):
  311. * Charles Maier
  312. * Nathaniel Houghton
  313. *
  314. *--------------------------------------------------------------------*/
  315. static signed PrintCheckpointReport (struct plc * plc, char const * version)
  316. {
  317. struct channel * channel = (struct channel *)(plc->channel);
  318. struct message * message = (struct message *)(plc->message);
  319. #ifndef __GNUC__
  320. #pragma pack (push,1)
  321. #endif
  322. struct __packed vs_cp_rpt_request
  323. {
  324. struct ethernet_hdr ethernet;
  325. struct qualcomm_hdr qualcomm;
  326. uint16_t SESSIONID;
  327. uint8_t CLR;
  328. }
  329. * request = (struct vs_cp_rpt_request *) (message);
  330. struct __packed vs_cp_rpt_ind
  331. {
  332. struct ethernet_hdr ethernet;
  333. struct qualcomm_hdr qualcomm;
  334. uint8_t MSTATUS;
  335. uint8_t MAJORVERSION;
  336. uint8_t MINORVERSION;
  337. uint8_t RESERVED [14];
  338. uint16_t SESSIONID;
  339. uint32_t TOTALBUFFERSIZE;
  340. uint32_t BLOCKOFFSET;
  341. uint32_t BYTEINDEXOFNEXTPOSITION;
  342. uint8_t NUMPARTS;
  343. uint8_t CURPART;
  344. uint16_t RDATALENGTH;
  345. uint8_t RDATAOFFSET;
  346. uint8_t RDATA [1];
  347. }
  348. * indicate = (struct vs_cp_rpt_ind *) (message);
  349. #ifndef __GNUC__
  350. #pragma pack (pop)
  351. #endif
  352. memset (message, 0, sizeof (* message));
  353. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  354. QualcommHeader (&request->qualcomm, 0, (VS_CP_RPT | MMTYPE_REQ));
  355. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  356. request->SESSIONID = HTOLE16 (WD_SESSION_ID);
  357. request->CLR = plc->readaction;
  358. if (SendMME (plc) <= 0)
  359. {
  360. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  361. return (-1);
  362. }
  363. printf ("<CheckpointReport>");
  364. do
  365. {
  366. if (ReadMME (plc, 0, (VS_CP_RPT | MMTYPE_IND)) <= 0)
  367. {
  368. printf ("</CheckpointReport>");
  369. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  370. return (-1);
  371. }
  372. if (_anyset (indicate->MSTATUS, MSTATUS_STATUS))
  373. {
  374. printf ("</CheckpointReport>");
  375. Failure (plc, PLC_WONTDOIT);
  376. return (-1);
  377. }
  378. printf ("<Packet>");
  379. printf ("<Version>%s</Version>", version);
  380. printf ("<Status>0</Status>");
  381. printf ("<MajorVersionBit>%d</MajorVersionBit>", indicate->MSTATUS & MSTATUS_MAJORVERSION? 1:0);
  382. printf ("<BufferIsLocked>%d</BufferIsLocked>", indicate->MSTATUS & MSTATUS_BUFFERISLOCKED? 1:0);
  383. printf ("<AutoLockOnResetIsOn>%d</AutoLockOnResetIsOn>", indicate->MSTATUS & MSTATUS_AUTOLOCKONRESET? 1:0);
  384. printf ("<UnsolicitedUpdatesIsOn>%d</UnsolicitedUpdatesIsOn>", indicate->MSTATUS & MSTATUS_UNSOLICITEDUPDATES? 1:0);
  385. printf ("<Unsolicited>%d</Unsolicited>", indicate->MSTATUS & MSTATUS_UNSOLICITED? 1:0);
  386. printf ("<MajorVersion>%d</MajorVersion>", indicate->MAJORVERSION);
  387. printf ("<MinorVersion>%d</MinorVersion>", indicate->MINORVERSION);
  388. printf ("<Reserved1>0</Reserved1>");
  389. printf ("<Reserved2>0</Reserved2>");
  390. printf ("<Reserved3>0</Reserved3>");
  391. printf ("<Reserved4>0</Reserved4>");
  392. printf ("<SessionId>1</SessionId>");
  393. printf ("<TotalBufferSize>%d</TotalBufferSize>", LE32TOH (indicate->TOTALBUFFERSIZE));
  394. printf ("<BlockOffset>%d</BlockOffset>", LE32TOH (indicate->BLOCKOFFSET));
  395. printf ("<ByteIndexOfNextPos>%d</ByteIndexOfNextPos>", LE32TOH (indicate->BYTEINDEXOFNEXTPOSITION));
  396. printf ("<NumParts>%d</NumParts>", indicate->NUMPARTS);
  397. printf ("<CurPart>%d</CurPart>", indicate->CURPART);
  398. printf ("<RDataLength>%d</RDataLength>", LE16TOH (indicate->RDATALENGTH));
  399. printf ("<RDataOffset>%d</RDataOffset>", indicate->RDATAOFFSET);
  400. printf ("<RData>");
  401. b64dump (indicate->RDATA, LE16TOH (indicate->RDATALENGTH), 0, stdout);
  402. printf ("</RData>");
  403. printf ("</Packet>");
  404. }
  405. while (indicate->CURPART < indicate->NUMPARTS);
  406. printf ("</CheckpointReport>");
  407. return (0);
  408. }
  409. /*====================================================================*
  410. *
  411. * static signed Diagnostics (struct plc * plc)
  412. *
  413. * read the firmware version string from a device before reading
  414. * and writing the watchdog and checkpoint reports in XML format;
  415. *
  416. *
  417. *--------------------------------------------------------------------*/
  418. static signed Diagnostics (struct plc * plc)
  419. {
  420. char version [PLC_VERSION_STRING];
  421. struct channel * channel = (struct channel *)(plc->channel);
  422. struct message * message = (struct message *)(plc->message);
  423. #ifndef __GNUC__
  424. #pragma pack (push,1)
  425. #endif
  426. struct __packed vs_sw_ver_request
  427. {
  428. struct ethernet_hdr ethernet;
  429. struct qualcomm_hdr qualcomm;
  430. uint8_t MSTATUS;
  431. uint8_t MDEVICEID;
  432. uint8_t MVERLENGTH;
  433. char MVERSION [PLC_VERSION_STRING];
  434. }
  435. * request = (struct vs_sw_ver_request *) (message);
  436. struct __packed vs_sw_ver_confirm
  437. {
  438. struct ethernet_hdr ethernet;
  439. struct qualcomm_hdr qualcomm;
  440. uint8_t MSTATUS;
  441. uint8_t MDEVICEID;
  442. uint8_t MVERLENGTH;
  443. char MVERSION [PLC_VERSION_STRING];
  444. }
  445. * confirm = (struct vs_sw_ver_confirm *) (message);
  446. #ifndef __GNUC__
  447. #pragma pack (pop)
  448. #endif
  449. memset (message, 0, sizeof (* message));
  450. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  451. QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
  452. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  453. if (SendMME (plc) <= 0)
  454. {
  455. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  456. return (-1);
  457. }
  458. if (ReadMME (plc, 0, (VS_SW_VER | MMTYPE_CNF)) <= 0)
  459. {
  460. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  461. return (-1);
  462. }
  463. if (confirm->MSTATUS)
  464. {
  465. Failure (plc, PLC_WONTDOIT);
  466. return (-1);
  467. }
  468. memcpy (version, confirm->MVERSION, sizeof (version));
  469. if (_anyset (plc->flags, PLC_XML_FORMAT))
  470. {
  471. printf ("<?xml version='1.0' encoding='utf-8' standalone='yes'?>");
  472. printf ("<Diagnostics>");
  473. PrintWatchdogReport (plc, version);
  474. PrintCheckpointReport (plc, version);
  475. printf ("</Diagnostics>\n");
  476. return (0);
  477. }
  478. PrintRawWatchdogReport (plc);
  479. return (0);
  480. }
  481. /*====================================================================*
  482. *
  483. * int main (int argc, char const * argv[]);
  484. *
  485. * parse command line, populate plc structure and perform selected
  486. * operations; show help summary if asked; see getoptv and putoptv
  487. * to understand command line parsing and help summary display; see
  488. * plc.h for the definition of struct plc;
  489. *
  490. * the command line accepts multiple MAC addresses and the program
  491. * performs the specified operations on each address, in turn; the
  492. * address order is significant but the option order is not; the
  493. * default address is a local broadcast that causes all devices on
  494. * the local H1 interface to respond but not those at the remote
  495. * end of the powerline;
  496. *
  497. * the default address is 00:B0:52:00:00:01; omitting the address
  498. * will automatically address the local device; some options will
  499. * cancel themselves if this makes no sense;
  500. *
  501. * the default interface is eth1 because most people use eth0 as
  502. * their principle network connection; you can specify another
  503. * interface with -i or define environment string PLC to make
  504. * that the default interface and save typing;
  505. *
  506. *
  507. *--------------------------------------------------------------------*/
  508. int main (int argc, char const * argv [])
  509. {
  510. extern struct channel channel;
  511. static char const * optv [] =
  512. {
  513. "cCei:qvx",
  514. "device [device] [...] [> stdout]",
  515. "Qualcomm Atheros INT6x00 Log Retrieval Utility",
  516. "c\tcustom report",
  517. "C\tclear report",
  518. "e\tredirect stderr to stdout",
  519. #if defined (WINPCAP) || defined (LIBPCAP)
  520. "i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]",
  521. #else
  522. "i s\thost interface is (s) [" LITERAL (CHANNEL_ETHDEVICE) "]",
  523. #endif
  524. "q\tquiet mode",
  525. "v\tverbose mode",
  526. "x\tprint watchdog report in XML format",
  527. (char const *) (0)
  528. };
  529. #include "../plc/plc.c"
  530. signed c;
  531. if (getenv (PLCDEVICE))
  532. {
  533. #if defined (WINPCAP) || defined (LIBPCAP)
  534. channel.ifindex = atoi (getenv (PLCDEVICE));
  535. #else
  536. channel.ifname = strdup (getenv (PLCDEVICE));
  537. #endif
  538. }
  539. optind = 1;
  540. plc.readaction = WD_ACTION_READ;
  541. while ((c = getoptv (argc, argv, optv)) != -1)
  542. {
  543. switch (c)
  544. {
  545. case 'C':
  546. plc.readaction |= WD_ACTION_CLEAR;
  547. break;
  548. case 'c':
  549. plc.readaction |= WD_ACTION_CUSTOM;
  550. break;
  551. case 'e':
  552. dup2 (STDOUT_FILENO, STDERR_FILENO);
  553. break;
  554. case 'x':
  555. _setbits (plc.flags, PLC_XML_FORMAT);
  556. break;
  557. case 'i':
  558. #if defined (WINPCAP) || defined (LIBPCAP)
  559. channel.ifindex = atoi (optarg);
  560. #else
  561. channel.ifname = optarg;
  562. #endif
  563. break;
  564. case 'q':
  565. _setbits (channel.flags, CHANNEL_SILENCE);
  566. _setbits (plc.flags, PLC_SILENCE);
  567. break;
  568. case 'v':
  569. _setbits (channel.flags, CHANNEL_VERBOSE);
  570. _setbits (plc.flags, PLC_VERBOSE);
  571. break;
  572. default:
  573. break;
  574. }
  575. }
  576. argc -= optind;
  577. argv += optind;
  578. if (argc != 1)
  579. {
  580. if (plc.rpt.file != -1)
  581. {
  582. error (1, ECANCELED, PLC_NODEVICE);
  583. }
  584. }
  585. openchannel (&channel);
  586. if (!(plc.message = malloc (sizeof (* plc.message))))
  587. {
  588. error (1, errno, PLC_NOMEMORY);
  589. }
  590. #if defined (WIN32)
  591. if (!_anyset(plc.flags, PLC_XML_FORMAT))
  592. {
  593. setmode (STDOUT_FILENO, O_BINARY);
  594. }
  595. #endif
  596. if (!argc)
  597. {
  598. Diagnostics (&plc);
  599. }
  600. while ((argc) && (* argv))
  601. {
  602. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  603. {
  604. error (1, errno, PLC_BAD_MAC, * argv);
  605. }
  606. Diagnostics (&plc);
  607. argc--;
  608. argv++;
  609. }
  610. free (plc.message);
  611. closechannel (&channel);
  612. exit (0);
  613. }