plcotst.c.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. plcotst.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='PLCNetworkInfo.c.html' title=' PLCNetworkInfo.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='PLCPhyRates.c.html' title=' PLCPhyRates.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. * plcotst.c - Atheros PLC One-Time Self-Test Manager;
  64. *
  65. * Use VS_SELFTEST_ONETIME_CONFIG and VS_SELFTEST_RESULTS message
  66. * type to configure the Atheros PLC One-Time Self-Test then read
  67. * and display stored selftest results;
  68. *
  69. * Contributor(s):
  70. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  71. *
  72. *--------------------------------------------------------------------*/
  73. /*====================================================================*&quot;
  74. * system header files;
  75. *--------------------------------------------------------------------*/
  76. #include &lt;unistd.h&gt;
  77. #include &lt;stdlib.h&gt;
  78. #include &lt;stdint.h&gt;
  79. #include &lt;limits.h&gt;
  80. /*====================================================================*
  81. * custom header files;
  82. *--------------------------------------------------------------------*/
  83. #include &quot;../tools/getoptv.h&quot;
  84. #include &quot;../tools/putoptv.h&quot;
  85. #include &quot;../tools/memory.h&quot;
  86. #include &quot;../tools/number.h&quot;
  87. #include &quot;../tools/symbol.h&quot;
  88. #include &quot;../tools/types.h&quot;
  89. #include &quot;../tools/flags.h&quot;
  90. #include &quot;../tools/files.h&quot;
  91. #include &quot;../tools/error.h&quot;
  92. #include &quot;../plc/plc.h&quot;
  93. /*====================================================================*
  94. * custom source files;
  95. *--------------------------------------------------------------------*/
  96. #ifndef MAKEFILE
  97. #include &quot;../plc/Confirm.c&quot;
  98. #include &quot;../plc/Display.c&quot;
  99. #include &quot;../plc/Failure.c&quot;
  100. #include &quot;../plc/Request.c&quot;
  101. #include &quot;../plc/ReadMME.c&quot;
  102. #include &quot;../plc/SendMME.c&quot;
  103. #include &quot;../mme/UnwantedMessage.c&quot;
  104. #include &quot;../plc/Devices.c&quot;
  105. #endif
  106. #ifndef MAKEFILE
  107. #include &quot;../tools/getoptv.c&quot;
  108. #include &quot;../tools/putoptv.c&quot;
  109. #include &quot;../tools/version.c&quot;
  110. #include &quot;../tools/uintspec.c&quot;
  111. #include &quot;../tools/hexdump.c&quot;
  112. #include &quot;../tools/hexencode.c&quot;
  113. #include &quot;../tools/hexdecode.c&quot;
  114. #include &quot;../tools/todigit.c&quot;
  115. #include &quot;../tools/synonym.c&quot;
  116. #include &quot;../tools/error.c&quot;
  117. #endif
  118. #ifndef MAKEFILE
  119. #include &quot;../ether/openchannel.c&quot;
  120. #include &quot;../ether/closechannel.c&quot;
  121. #include &quot;../ether/readpacket.c&quot;
  122. #include &quot;../ether/sendpacket.c&quot;
  123. #include &quot;../ether/channel.c&quot;
  124. #endif
  125. #ifndef MAKEFILE
  126. #include &quot;../mme/MMECode.c&quot;
  127. #include &quot;../mme/EthernetHeader.c&quot;
  128. #include &quot;../mme/QualcommHeader.c&quot;
  129. #endif
  130. /*====================================================================*
  131. * program constants;
  132. *--------------------------------------------------------------------*/
  133. #define PLCOTST_MVERSION 0
  134. #define PLCOTST_RUNAFTERRESET 1
  135. #define PLCOTST_DELAYTORUN 0
  136. #define PLCOTST_MEMRUNS 0
  137. #define PLCOTST_FLASHRUNS 0
  138. #define PLCOTST_RESETONDONE 0
  139. /*====================================================================*
  140. * program variables;
  141. *--------------------------------------------------------------------*/
  142. #ifndef __GNUC__
  143. #pragma pack (push,1)
  144. #endif
  145. typedef struct __packed selftest
  146. {
  147. uint8_t MVERSION;
  148. uint8_t RUNAFTERRESET;
  149. uint32_t DELAYTORUN;
  150. uint32_t MEMRUNS;
  151. uint32_t FLASHRUNS;
  152. uint8_t RESETONDONE;
  153. }
  154. selftest;
  155. #ifndef __GNUC__
  156. #pragma pack (pop)
  157. #endif
  158. /*====================================================================*
  159. *
  160. * signed configure (struct plc * plc, struct selftest * selftest);
  161. *
  162. *
  163. *--------------------------------------------------------------------*/
  164. static signed configure (struct plc * plc, struct selftest * selftest)
  165. {
  166. struct channel * channel = (struct channel *)(plc-&gt;channel);
  167. struct message * message = (struct message *)(plc-&gt;message);
  168. #ifndef __GNUC__
  169. #pragma pack (push,1)
  170. #endif
  171. struct __packed vs_selftest_onetime_config_request
  172. {
  173. struct ethernet_hdr ethernet;
  174. struct qualcomm_hdr qualcomm;
  175. uint8_t MVERSION;
  176. uint8_t RUNAFTERRESET;
  177. uint32_t DELAYTORUN;
  178. uint32_t MEMRUNS;
  179. uint32_t FLASHRUNS;
  180. uint8_t RESETONDONE;
  181. }
  182. * request = (struct vs_selftest_onetime_config_request *) (message);
  183. struct __packed vs_selftest_onetime_config_confirm
  184. {
  185. struct ethernet_hdr ethernet;
  186. struct qualcomm_hdr qualcomm;
  187. uint8_t MSTATUS;
  188. }
  189. * confirm = (struct vs_selftest_onetime_config_confirm *) (message);
  190. #ifndef __GNUC__
  191. #pragma pack (pop)
  192. #endif
  193. Request (plc, &quot;Configure One-Time Self-Test&quot;);
  194. memset (message, 0, sizeof (* message));
  195. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  196. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_SELFTEST_ONETIME_CONFIG | MMTYPE_REQ));
  197. request-&gt;MVERSION = selftest-&gt;MVERSION;
  198. request-&gt;RUNAFTERRESET = selftest-&gt;RUNAFTERRESET;
  199. request-&gt;DELAYTORUN = HTOLE32 (selftest-&gt;DELAYTORUN);
  200. request-&gt;MEMRUNS = HTOLE32 (selftest-&gt;MEMRUNS);
  201. request-&gt;FLASHRUNS = HTOLE32 (selftest-&gt;FLASHRUNS);
  202. request-&gt;RESETONDONE = selftest-&gt;RESETONDONE;
  203. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  204. if (SendMME (plc) &lt;= 0)
  205. {
  206. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  207. return (-1);
  208. }
  209. while (ReadMME (plc, 0, (VS_SELFTEST_ONETIME_CONFIG | MMTYPE_CNF)) &gt; 0)
  210. {
  211. if (confirm-&gt;MSTATUS)
  212. {
  213. Failure (plc, PLC_WONTDOIT);
  214. continue;
  215. }
  216. Display (plc, &quot;%s&quot;, &quot;Configured&quot;);
  217. }
  218. return (0);
  219. }
  220. /*====================================================================*
  221. *
  222. * signed retrieve (struct plc * plc, struct selftest * selftest);
  223. *
  224. *
  225. *--------------------------------------------------------------------*/
  226. static signed retrieve (struct plc * plc, struct selftest * selftest)
  227. {
  228. struct channel * channel = (struct channel *)(plc-&gt;channel);
  229. struct message * message = (struct message *)(plc-&gt;message);
  230. #ifndef __GNUC__
  231. #pragma pack (push,1)
  232. #endif
  233. struct __packed vs_selftest_results_request
  234. {
  235. struct ethernet_hdr ethernet;
  236. struct qualcomm_hdr qualcomm;
  237. uint8_t MVERSION;
  238. uint8_t MACTION;
  239. }
  240. * request = (struct vs_selftest_results_request *) (message);
  241. struct __packed vs_selftest_results_confirm
  242. {
  243. struct ethernet_hdr ethernet;
  244. struct qualcomm_hdr qualcomm;
  245. uint8_t MVERSION;
  246. uint8_t MSTATUS;
  247. uint32_t NUMBER [6];
  248. }
  249. * confirm = (struct vs_selftest_results_confirm *) (message);
  250. #ifndef __GNUC__
  251. #pragma pack (pop)
  252. #endif
  253. Request (plc, &quot;Retrieve Self-Test Results&quot;);
  254. memset (message, 0, sizeof (* message));
  255. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  256. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_SELFTEST_RESULTS | MMTYPE_REQ));
  257. request-&gt;MVERSION = selftest-&gt;MVERSION;
  258. request-&gt;MACTION = plc-&gt;action;
  259. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  260. if (SendMME (plc) &lt;= 0)
  261. {
  262. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  263. return (-1);
  264. }
  265. while (ReadMME (plc, 0, (VS_SELFTEST_RESULTS | MMTYPE_CNF)) &gt; 0)
  266. {
  267. if ((confirm-&gt;MSTATUS == 2) || (confirm-&gt;MSTATUS == 4) || (confirm-&gt;MSTATUS == 6))
  268. {
  269. Display (plc, &quot;Memory test %d Passed %d Failed %d Flash test %d Passed %d Failed %d&quot;, LE32TOH (confirm-&gt;NUMBER [0]), LE32TOH (confirm-&gt;NUMBER [1]), LE32TOH (confirm-&gt;NUMBER [2]), LE32TOH (confirm-&gt;NUMBER [3]), LE32TOH (confirm-&gt;NUMBER [4]), LE32TOH (confirm-&gt;NUMBER [5]));
  270. continue;
  271. }
  272. if (confirm-&gt;MSTATUS == 3)
  273. {
  274. Failure (plc, &quot;%d seconds remaining&quot;, LE32TOH (confirm-&gt;NUMBER [0]));
  275. continue;
  276. }
  277. if (confirm-&gt;MSTATUS)
  278. {
  279. Failure (plc, PLC_WONTDOIT);
  280. continue;
  281. }
  282. Confirm (plc, &quot;Cleared Results&quot;);
  283. }
  284. return (0);
  285. }
  286. /*====================================================================*
  287. *
  288. * signed manager (struct plc * plc, struct selftest * selftest);
  289. *
  290. *
  291. *--------------------------------------------------------------------*/
  292. static signed manager (struct plc * plc, struct selftest * selftest)
  293. {
  294. if (_anyset (plc-&gt;flags, PLC_CONFIGURE))
  295. {
  296. configure (plc, selftest);
  297. }
  298. if (_anyset (plc-&gt;flags, PLC_RESULTS))
  299. {
  300. retrieve (plc, selftest);
  301. }
  302. return (0);
  303. }
  304. /*====================================================================*
  305. *
  306. * int main (int argc, char const * argv[]);
  307. *
  308. *
  309. *--------------------------------------------------------------------*/
  310. int main (int argc, char const * argv [])
  311. {
  312. extern struct channel channel;
  313. static char const * optv [] =
  314. {
  315. &quot;c:Cd:ef:i:m:qr:R:t:vx&quot;,
  316. &quot;device [device] [...] [&gt; stdout]&quot;,
  317. &quot;Qualcomm Atheros Powerline One-Time Self-Test Manager&quot;,
  318. &quot;c n\tconfiguration version&quot;,
  319. &quot;C\tclear selftest results&quot;,
  320. &quot;d n\tdelay selftest start by (n) seconds [&quot; LITERAL (PLCOTST_DELAYTORUN) &quot;]&quot;,
  321. &quot;e\tredirect stderr to stdout&quot;,
  322. &quot;f n\trun flash selftest (n) times [&quot; LITERAL (PLCOTST_FLASHRUNS) &quot;]&quot;,
  323. #if defined (WINPCAP) || defined (LIBPCAP)
  324. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  325. #else
  326. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  327. #endif
  328. &quot;m n\trun memory selftest (n) times [&quot; LITERAL (PLCOTST_MEMRUNS) &quot;]&quot;,
  329. &quot;q\tquiet mode&quot;,
  330. &quot;r n\trun selftest after reset [&quot; LITERAL (PLCOTST_RUNAFTERRESET) &quot;]&quot;,
  331. &quot;R n\treset after selftest completes [&quot; LITERAL (PLCOTST_RESETONDONE) &quot;]&quot;,
  332. &quot;t n\tread timeout is (n) milliseconds [&quot; LITERAL (CHANNEL_TIMEOUT) &quot;]&quot;,
  333. &quot;v\tverbose mode&quot;,
  334. &quot;x\texit on error&quot;,
  335. (char const *) (0)
  336. };
  337. #include &quot;../plc/plc.c&quot;
  338. struct selftest selftest =
  339. {
  340. PLCOTST_MVERSION,
  341. PLCOTST_RUNAFTERRESET,
  342. PLCOTST_DELAYTORUN,
  343. PLCOTST_MEMRUNS,
  344. PLCOTST_FLASHRUNS,
  345. PLCOTST_RESETONDONE
  346. };
  347. signed c;
  348. if (getenv (PLCDEVICE))
  349. {
  350. channel.ifname = strdup (getenv (PLCDEVICE));
  351. }
  352. optind = 1;
  353. while ((c = getoptv (argc, argv, optv)) != -1)
  354. {
  355. switch (c)
  356. {
  357. case 'c':
  358. selftest.MVERSION = (uint8_t)(uintspec (optarg, 0, UCHAR_MAX));
  359. break;
  360. case 'C':
  361. _setbits (plc.flags, PLC_RESULTS);
  362. plc.action = 1;
  363. break;
  364. case 'd':
  365. _setbits (plc.flags, PLC_CONFIGURE);
  366. selftest.DELAYTORUN = (uint32_t)(uintspec (optarg, 0, UINT_MAX));
  367. break;
  368. case 'e':
  369. dup2 (STDOUT_FILENO, STDERR_FILENO);
  370. break;
  371. case 'f':
  372. _setbits (plc.flags, PLC_CONFIGURE);
  373. selftest.FLASHRUNS = (uint32_t)(uintspec (optarg, 0, UINT_MAX));
  374. break;
  375. case 'i':
  376. #if defined (WINPCAP) || defined (LIBPCAP)
  377. channel.ifindex = atoi (optarg);
  378. #else
  379. channel.ifname = optarg;
  380. #endif
  381. break;
  382. case 'm':
  383. _setbits (plc.flags, PLC_CONFIGURE);
  384. selftest.MEMRUNS = (uint32_t)(uintspec (optarg, 0, UINT_MAX));
  385. break;
  386. case 'q':
  387. _setbits (channel.flags, CHANNEL_SILENCE);
  388. _setbits (plc.flags, PLC_SILENCE);
  389. break;
  390. case 'r':
  391. _setbits (plc.flags, PLC_CONFIGURE);
  392. selftest.RUNAFTERRESET = (uint8_t)(uintspec (optarg, false, true));
  393. break;
  394. case 'R':
  395. _setbits (plc.flags, PLC_CONFIGURE);
  396. selftest.RESETONDONE = (uint8_t)(uintspec (optarg, false, true));
  397. break;
  398. case 't':
  399. channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
  400. break;
  401. case 'v':
  402. _setbits (channel.flags, CHANNEL_VERBOSE);
  403. _setbits (plc.flags, PLC_VERBOSE);
  404. break;
  405. case 'x':
  406. _setbits (plc.flags, PLC_BAILOUT);
  407. break;
  408. default:
  409. break;
  410. }
  411. }
  412. argc -= optind;
  413. argv += optind;
  414. if (_allclr (plc.flags, (PLC_CONFIGURE | PLC_RESULTS)))
  415. {
  416. _setbits (plc.flags, PLC_RESULTS);
  417. }
  418. openchannel (&amp;channel);
  419. if (!(plc.message = malloc (sizeof (* plc.message))))
  420. {
  421. error (1, errno, PLC_NOMEMORY);
  422. }
  423. if (!argc)
  424. {
  425. manager (&amp;plc, &amp;selftest);
  426. }
  427. while ((argc) &amp;&amp; (* argv))
  428. {
  429. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  430. {
  431. error (1, errno, PLC_BAD_MAC, * argv);
  432. }
  433. manager (&amp;plc, &amp;selftest);
  434. argv++;
  435. argc--;
  436. }
  437. free (plc.message);
  438. closechannel (&amp;channel);
  439. return (0);
  440. }
  441. </pre>
  442. <div class='footerlink'>
  443. [<a href='PLCNetworkInfo.c.html' title=' PLCNetworkInfo.c '>PREV</a>]
  444. [<a href='toolkit.html' title=' Index '>HOME</a>]
  445. [<a href='PLCPhyRates.c.html' title=' PLCPhyRates.c '>NEXT</a>]
  446. </div>
  447. </body>
  448. </html>