int6klog.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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. * int6klog.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. #endif
  83. #ifndef MAKEFILE
  84. #include "../tools/error.c"
  85. #include "../tools/getoptv.c"
  86. #include "../tools/putoptv.c"
  87. #include "../tools/version.c"
  88. #include "../tools/uintspec.c"
  89. #include "../tools/hexdump.c"
  90. #include "../tools/hexencode.c"
  91. #include "../tools/hexdecode.c"
  92. #include "../tools/hexstring.c"
  93. #include "../tools/todigit.c"
  94. #include "../tools/strfbits.c"
  95. #include "../tools/synonym.c"
  96. #include "../tools/lookup.c"
  97. #include "../tools/assist.c"
  98. #include "../tools/codelist.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. #include "../mme/EthernetHeader.c"
  111. #include "../mme/QualcommHeader.c"
  112. #include "../mme/UnwantedMessage.c"
  113. #endif
  114. /*====================================================================*
  115. * constants
  116. *--------------------------------------------------------------------*/
  117. #define MSTATUS_STATUS (7 << 0)
  118. #define MSTATUS_MAJORVERSION (1 << 3)
  119. #define MSTATUS_BUFFERISLOCKED (1 << 4)
  120. #define MSTATUS_AUTOLOCKONRESET (1 << 5)
  121. #define MSTATUS_UNSOLICITEDUPDATES (1 << 6)
  122. #define MSTATUS_UNSOLICITED (1 << 7)
  123. #define INT6KLOG_FMT_RAW 1
  124. #define INT6KLOG_FMT_XML 2
  125. #define WD_ACTION_READ (1 << 0)
  126. #define WD_ACTION_CLEAR (1 << 1)
  127. #define WD_ACTION_CUSTOM (1 << 2)
  128. /*====================================================================*
  129. * program variables;
  130. *--------------------------------------------------------------------*/
  131. static struct _code_ const formats [] =
  132. {
  133. {
  134. INT6KLOG_FMT_RAW,
  135. "raw",
  136. },
  137. {
  138. INT6KLOG_FMT_XML,
  139. "xml",
  140. }
  141. };
  142. /*====================================================================*
  143. *
  144. * static signed PrintRawWatchdogReport (struct plc * plc);
  145. *
  146. * Read the watchdog report using VS_WD_RPT and write to file in
  147. * binary format; the output can be sent to Atheros Support for
  148. * analysis;
  149. *
  150. * VS_WD_RPT request returns an indication instead of a confirmation
  151. * message; this is unusual but so is life;
  152. *
  153. *
  154. * Contributor(s):
  155. * Charles Maier
  156. *
  157. *--------------------------------------------------------------------*/
  158. static signed PrintRawWatchdogReport (struct plc * plc)
  159. {
  160. struct channel * channel = (struct channel *)(plc->channel);
  161. struct message * message = (struct message *)(plc->message);
  162. #ifndef __GNUC__
  163. #pragma pack (push,1)
  164. #endif
  165. struct __packed vs_wd_rpt_request
  166. {
  167. struct ethernet_hdr ethernet;
  168. struct qualcomm_hdr qualcomm;
  169. uint16_t SESSIONID;
  170. uint8_t CLR;
  171. }
  172. * request = (struct vs_wd_rpt_request *) (message);
  173. struct __packed vs_wd_rpt_indicate
  174. {
  175. struct ethernet_hdr ethernet;
  176. struct qualcomm_hdr qualcomm;
  177. uint8_t MSTATUS;
  178. uint16_t SESSIONID;
  179. uint8_t NUMPARTS;
  180. uint8_t CURPART;
  181. uint16_t RDATALENGTH;
  182. uint8_t RDATAOFFSET;
  183. uint8_t RDATA [1];
  184. }
  185. * indicate = (struct vs_wd_rpt_indicate *) (message);
  186. #ifndef __GNUC__
  187. #pragma pack (pop)
  188. #endif
  189. memset (message, 0, sizeof (* message));
  190. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  191. QualcommHeader (&request->qualcomm, 0, (VS_WD_RPT | MMTYPE_REQ));
  192. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  193. request->SESSIONID = HTOLE16 (plc->cookie);
  194. request->CLR = plc->readaction;
  195. if (SendMME (plc) <= 0)
  196. {
  197. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  198. return (-1);
  199. }
  200. do
  201. {
  202. printf ("%d %d\n", LE16TOH (indicate->RDATALENGTH), indicate->RDATAOFFSET);
  203. if (ReadMME (plc, 0, (VS_WD_RPT | MMTYPE_IND)) <= 0)
  204. {
  205. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  206. return (-1);
  207. }
  208. printf ("%d %d\n", LE16TOH (indicate->RDATALENGTH), indicate->RDATAOFFSET);
  209. if (indicate->MSTATUS)
  210. {
  211. Failure (plc, PLC_WONTDOIT);
  212. return (-1);
  213. }
  214. printf ("%d %d\n", LE16TOH (indicate->RDATALENGTH), indicate->RDATAOFFSET);
  215. write (STDOUT_FILENO, indicate->RDATA + indicate->RDATAOFFSET, LE16TOH (indicate->RDATALENGTH) - indicate->RDATAOFFSET);
  216. }
  217. while (indicate->CURPART < indicate->NUMPARTS);
  218. return (0);
  219. }
  220. /*====================================================================*
  221. *
  222. * static signed PrintWatchdogReport (struct plc * plc, char const * version);
  223. *
  224. * Read the watchdog report using VS_WD_RPT and print to file in
  225. * XML format; this file may be sent to QCA for analysis;
  226. *
  227. * VS_WD_RPT request returns an indication instead of a confirmation
  228. * message; this is unusual but so is life;
  229. *
  230. *
  231. * Contributor(s):
  232. * Charles Maier
  233. *
  234. *--------------------------------------------------------------------*/
  235. static signed PrintWatchdogReport (struct plc * plc, char const * version)
  236. {
  237. struct channel * channel = (struct channel *)(plc->channel);
  238. struct message * message = (struct message *)(plc->message);
  239. #ifndef __GNUC__
  240. #pragma pack (push,1)
  241. #endif
  242. struct __packed vs_wd_rpt_request
  243. {
  244. struct ethernet_hdr ethernet;
  245. struct qualcomm_hdr qualcomm;
  246. uint16_t SESSIONID;
  247. uint8_t CLR;
  248. }
  249. * request = (struct vs_wd_rpt_request *) (message);
  250. struct __packed vs_wd_rpt_ind
  251. {
  252. struct ethernet_hdr ethernet;
  253. struct qualcomm_hdr qualcomm;
  254. uint8_t MSTATUS;
  255. uint16_t SESSIONID;
  256. uint8_t NUMPARTS;
  257. uint8_t CURPART;
  258. uint16_t RDATALENGTH;
  259. uint8_t RDATAOFFSET;
  260. uint8_t RDATA [1];
  261. }
  262. * indicate = (struct vs_wd_rpt_ind *) (message);
  263. #ifndef __GNUC__
  264. #pragma pack (pop)
  265. #endif
  266. memset (message, 0, sizeof (* message));
  267. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  268. QualcommHeader (&request->qualcomm, 0, (VS_WD_RPT | MMTYPE_REQ));
  269. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  270. request->SESSIONID = HTOLE16 (plc->cookie);
  271. request->CLR = plc->readaction;
  272. if (SendMME (plc) <= 0)
  273. {
  274. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  275. return (-1);
  276. }
  277. printf ("<WatchdogReport>");
  278. do
  279. {
  280. if (ReadMME (plc, 0, (VS_WD_RPT | MMTYPE_IND)) < 0)
  281. {
  282. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  283. return (-1);
  284. }
  285. if (indicate->MSTATUS)
  286. {
  287. Failure (plc, PLC_WONTDOIT);
  288. return (-1);
  289. }
  290. printf ("<Packet>");
  291. printf ("<Version>%s</Version>", version);
  292. printf ("<OUI>%s</OUI>", "00B052");
  293. printf ("<Status>0</Status>");
  294. printf ("<SessionId>0</SessionId>");
  295. printf ("<NumParts>%d</NumParts>", indicate->NUMPARTS);
  296. printf ("<CurPart>%d</CurPart>", indicate->CURPART);
  297. printf ("<DataLength>%d</DataLength>", LE16TOH (indicate->RDATALENGTH));
  298. printf ("<DataOffset>%d</DataOffset>", indicate->RDATAOFFSET);
  299. printf ("<Data>");
  300. b64dump (indicate->RDATA + indicate->RDATAOFFSET, LE16TOH (indicate->RDATALENGTH) - indicate->RDATAOFFSET, 0, stdout);
  301. printf ("</Data>");
  302. printf ("</Packet>");
  303. }
  304. while (indicate->CURPART < indicate->NUMPARTS);
  305. printf ("</WatchdogReport>");
  306. return (0);
  307. }
  308. /*====================================================================*
  309. *
  310. * static signed PrintCheckpointReport (struct plc * plc, char const * version);
  311. *
  312. * Read the watchdog reqport using VS_CP_RPT and write to file in
  313. * binary or XML format; this file can be sent to Atheros Support
  314. * for analysis;
  315. *
  316. * VS_CP_RPT request returns an indication instead of a confirmation
  317. * message; this is unusual but so is life;
  318. *
  319. *
  320. * Contributor(s):
  321. * Charles Maier
  322. * Nathaniel Houghton
  323. *
  324. *--------------------------------------------------------------------*/
  325. static signed PrintCheckpointReport (struct plc * plc, char const * version)
  326. {
  327. struct channel * channel = (struct channel *)(plc->channel);
  328. struct message * message = (struct message *)(plc->message);
  329. #ifndef __GNUC__
  330. #pragma pack (push,1)
  331. #endif
  332. struct __packed vs_cp_rpt_request
  333. {
  334. struct ethernet_hdr ethernet;
  335. struct qualcomm_hdr qualcomm;
  336. uint16_t SESSIONID;
  337. uint8_t CLR;
  338. }
  339. * request = (struct vs_cp_rpt_request *) (message);
  340. struct __packed vs_cp_rpt_ind
  341. {
  342. struct ethernet_hdr ethernet;
  343. struct qualcomm_hdr qualcomm;
  344. uint8_t MSTATUS;
  345. uint8_t MAJORVERSION;
  346. uint8_t MINORVERSION;
  347. uint8_t RESERVED [14];
  348. uint16_t SESSIONID;
  349. uint32_t TOTALBUFFERSIZE;
  350. uint32_t BLOCKOFFSET;
  351. uint32_t BYTEINDEXOFNEXTPOSITION;
  352. uint8_t NUMPARTS;
  353. uint8_t CURPART;
  354. uint16_t RDATALENGTH;
  355. uint8_t RDATAOFFSET;
  356. uint8_t RDATA [1];
  357. }
  358. * indicate = (struct vs_cp_rpt_ind *) (message);
  359. #ifndef __GNUC__
  360. #pragma pack (pop)
  361. #endif
  362. memset (message, 0, sizeof (* message));
  363. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  364. QualcommHeader (&request->qualcomm, 0, (VS_CP_RPT | MMTYPE_REQ));
  365. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  366. request->SESSIONID = HTOLE16 (plc->cookie);
  367. request->CLR = plc->readaction;
  368. if (SendMME (plc) <= 0)
  369. {
  370. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  371. return (-1);
  372. }
  373. printf ("<CheckpointReport>");
  374. do
  375. {
  376. if (ReadMME (plc, 0, (VS_CP_RPT | MMTYPE_IND)) <= 0)
  377. {
  378. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  379. return (-1);
  380. }
  381. if (_anyset (indicate->MSTATUS, MSTATUS_STATUS))
  382. {
  383. Failure (plc, PLC_WONTDOIT);
  384. return (-1);
  385. }
  386. printf ("<Packet>");
  387. printf ("<Version>%s</Version>", version);
  388. printf ("<Status>0</Status>");
  389. printf ("<MajorVersionBit>%d</MajorVersionBit>", indicate->MSTATUS & MSTATUS_MAJORVERSION? 1:0);
  390. printf ("<BufferIsLocked>%d</BufferIsLocked>", indicate->MSTATUS & MSTATUS_BUFFERISLOCKED? 1:0);
  391. printf ("<AutoLockOnResetIsOn>%d</AutoLockOnResetIsOn>", indicate->MSTATUS & MSTATUS_AUTOLOCKONRESET? 1:0);
  392. printf ("<UnsolicitedUpdatesIsOn>%d</UnsolicitedUpdatesIsOn>", indicate->MSTATUS & MSTATUS_UNSOLICITEDUPDATES? 1:0);
  393. printf ("<Unsolicited>%d</Unsolicited>", indicate->MSTATUS & MSTATUS_UNSOLICITED? 1:0);
  394. printf ("<MajorVersion>%d</MajorVersion>", indicate->MAJORVERSION);
  395. printf ("<MinorVersion>%d</MinorVersion>", indicate->MINORVERSION);
  396. printf ("<Reserved1>0</Reserved1>");
  397. printf ("<Reserved2>0</Reserved2>");
  398. printf ("<Reserved3>0</Reserved3>");
  399. printf ("<Reserved4>0</Reserved4>");
  400. printf ("<SessionId>1</SessionId>");
  401. printf ("<TotalBufferSize>%d</TotalBufferSize>", LE32TOH (indicate->TOTALBUFFERSIZE));
  402. printf ("<BlockOffset>%d</BlockOffset>", LE32TOH (indicate->BLOCKOFFSET));
  403. printf ("<ByteIndexOfNextPos>%d</ByteIndexOfNextPos>", LE32TOH (indicate->BYTEINDEXOFNEXTPOSITION));
  404. printf ("<NumParts>%d</NumParts>", indicate->NUMPARTS);
  405. printf ("<CurPart>%d</CurPart>", indicate->CURPART);
  406. printf ("<RDataLength>%d</RDataLength>", LE16TOH (indicate->RDATALENGTH));
  407. printf ("<RDataOffset>%d</RDataOffset>", indicate->RDATAOFFSET);
  408. printf ("<RData>");
  409. b64dump (indicate->RDATA + indicate->RDATAOFFSET, LE16TOH (indicate->RDATALENGTH), 0, stdout);
  410. printf ("</RData>");
  411. printf ("</Packet>");
  412. }
  413. while (indicate->CURPART < indicate->NUMPARTS);
  414. printf ("</CheckpointReport>");
  415. return (0);
  416. }
  417. /*====================================================================*
  418. *
  419. * static signed Diagnostics (struct plc * plc)
  420. *
  421. * read the firmware version string from a device before reading
  422. * and writing the watchdog and checkpoint reports in XML format;
  423. *
  424. *
  425. *--------------------------------------------------------------------*/
  426. static signed Diagnostics (struct plc * plc)
  427. {
  428. char version [PLC_VERSION_STRING];
  429. struct channel * channel = (struct channel *)(plc->channel);
  430. struct message * message = (struct message *)(plc->message);
  431. #ifndef __GNUC__
  432. #pragma pack (push,1)
  433. #endif
  434. struct __packed vs_sw_ver_request
  435. {
  436. struct ethernet_hdr ethernet;
  437. struct qualcomm_hdr qualcomm;
  438. uint8_t MSTATUS;
  439. uint8_t MDEVICEID;
  440. uint8_t MVERLENGTH;
  441. char MVERSION [PLC_VERSION_STRING];
  442. }
  443. * request = (struct vs_sw_ver_request *) (message);
  444. struct __packed vs_sw_ver_confirm
  445. {
  446. struct ethernet_hdr ethernet;
  447. struct qualcomm_hdr qualcomm;
  448. uint8_t MSTATUS;
  449. uint8_t MDEVICEID;
  450. uint8_t MVERLENGTH;
  451. char MVERSION [PLC_VERSION_STRING];
  452. }
  453. * confirm = (struct vs_sw_ver_confirm *) (message);
  454. #ifndef __GNUC__
  455. #pragma pack (pop)
  456. #endif
  457. memset (message, 0, sizeof (* message));
  458. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  459. QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
  460. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  461. if (SendMME (plc) <= 0)
  462. {
  463. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  464. return (-1);
  465. }
  466. if (ReadMME (plc, 0, (VS_SW_VER | MMTYPE_CNF)) <= 0)
  467. {
  468. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  469. return (-1);
  470. }
  471. if (confirm->MSTATUS)
  472. {
  473. Failure (plc, PLC_WONTDOIT);
  474. return (-1);
  475. }
  476. memcpy (version, confirm->MVERSION, sizeof (version));
  477. if (plc->action == INT6KLOG_FMT_XML)
  478. {
  479. printf ("<?xml version='1.0' encoding='utf-8' standalone='yes'?>");
  480. printf ("<Diagnostics>");
  481. PrintWatchdogReport (plc, version);
  482. PrintCheckpointReport (plc, version);
  483. printf ("</Diagnostics>\n");
  484. return (0);
  485. }
  486. if (plc->action == INT6KLOG_FMT_RAW)
  487. {
  488. PrintRawWatchdogReport (plc);
  489. return (0);
  490. }
  491. return (0);
  492. }
  493. /*====================================================================*
  494. *
  495. * int main (int argc, char const * argv[]);
  496. *
  497. * parse command line, populate plc structure and perform selected
  498. * operations; show help summary if asked; see getoptv and putoptv
  499. * to understand command line parsing and help summary display; see
  500. * plc.h for the definition of struct plc;
  501. *
  502. * the command line accepts multiple MAC addresses and the program
  503. * performs the specified operations on each address, in turn; the
  504. * address order is significant but the option order is not; the
  505. * default address is a local broadcast that causes all devices on
  506. * the local H1 interface to respond but not those at the remote
  507. * end of the powerline;
  508. *
  509. * the default address is 00:B0:52:00:00:01; omitting the address
  510. * will automatically address the local device; some options will
  511. * cancel themselves if this makes no sense;
  512. *
  513. * the default interface is eth1 because most people use eth0 as
  514. * their principle network connection; you can specify another
  515. * interface with -i or define environment string PLC to make
  516. * that the default interface and save typing;
  517. *
  518. *
  519. *--------------------------------------------------------------------*/
  520. int main (int argc, char const * argv [])
  521. {
  522. extern struct channel channel;
  523. static char const * optv [] =
  524. {
  525. "cCef:ri:qvz:",
  526. "device [device] [...] [> stdout]",
  527. "Qualcomm Atheros INT6x00 Log Retrieval Utility",
  528. "c\tclear watchdog and checkpoint reports",
  529. "C\tcustom watchdog report",
  530. "e\tredirect stderr to stdout",
  531. "f s\tprint Watchdog Report in format (s) [xml]",
  532. #if defined (WINPCAP) || defined (LIBPCAP)
  533. "i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]",
  534. #else
  535. "i s\thost interface is (s) [" LITERAL (CHANNEL_ETHDEVICE) "]",
  536. #endif
  537. "q\tquiet mode",
  538. "r\tread ",
  539. "v\tverbose mode",
  540. (char const *) (0)
  541. };
  542. #include "../plc/plc.c"
  543. signed c;
  544. if (getenv (PLCDEVICE))
  545. {
  546. #if defined (WINPCAP) || defined (LIBPCAP)
  547. channel.ifindex = atoi (getenv (PLCDEVICE));
  548. #else
  549. channel.ifname = strdup (getenv (PLCDEVICE));
  550. #endif
  551. }
  552. optind = 1;
  553. plc.readaction = 0;
  554. plc.action = INT6KLOG_FMT_XML;
  555. while ((c = getoptv (argc, argv, optv)) != -1)
  556. {
  557. switch (c)
  558. {
  559. case 'C':
  560. _setbits (plc.readaction, WD_ACTION_CUSTOM);
  561. break;
  562. case 'c':
  563. _setbits (plc.readaction, WD_ACTION_CLEAR);
  564. break;
  565. case 'e':
  566. dup2 (STDOUT_FILENO, STDERR_FILENO);
  567. break;
  568. case 'f':
  569. if ((c = lookup (optarg, formats, SIZEOF (formats))) == -1)
  570. {
  571. assist (optarg, "format", formats, SIZEOF (formats));
  572. }
  573. plc.action = (uint8_t)(c);
  574. break;
  575. case 'i':
  576. #if defined (WINPCAP) || defined (LIBPCAP)
  577. channel.ifindex = atoi (optarg);
  578. #else
  579. channel.ifname = optarg;
  580. #endif
  581. break;
  582. case 'q':
  583. _setbits (channel.flags, CHANNEL_SILENCE);
  584. _setbits (plc.flags, PLC_SILENCE);
  585. break;
  586. case 'r':
  587. _setbits (plc.readaction, WD_ACTION_READ);
  588. break;
  589. case 'v':
  590. _setbits (channel.flags, CHANNEL_VERBOSE);
  591. _setbits (plc.flags, PLC_VERBOSE);
  592. break;
  593. case 'z':
  594. plc.readaction = (uint8_t)(uintspec (optarg, 0, 255));
  595. break;
  596. default:
  597. break;
  598. }
  599. }
  600. argc -= optind;
  601. argv += optind;
  602. if (argc != 1)
  603. {
  604. if (plc.rpt.file != -1)
  605. {
  606. error (1, ECANCELED, PLC_NODEVICE);
  607. }
  608. }
  609. openchannel (&channel);
  610. if (!(plc.message = malloc (sizeof (* plc.message))))
  611. {
  612. error (1, errno, PLC_NOMEMORY);
  613. }
  614. #ifdef WIN32
  615. if (plc.action == INT6KLOG_FMT_RAW)
  616. {
  617. setmode (STDOUT_FILENO, O_BINARY);
  618. }
  619. #endif
  620. if (!argc)
  621. {
  622. Diagnostics (&plc);
  623. }
  624. while ((argc) && (* argv))
  625. {
  626. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  627. {
  628. error (1, errno, PLC_BAD_MAC, * argv);
  629. }
  630. Diagnostics (&plc);
  631. argc--;
  632. argv++;
  633. }
  634. free (plc.message);
  635. closechannel (&channel);
  636. exit (0);
  637. }