int6kwait.c.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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. int6kwait.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='int6kuart.c.html' title=' int6kuart.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='ipv4spec.c.html' title=' ipv4spec.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. * int6kwait.c - Atheros Powerline Device Procrastinator;
  64. *
  65. * wait for device events to start or finish before returning;
  66. *
  67. *
  68. * Contributor(s):
  69. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  70. *
  71. *--------------------------------------------------------------------*/
  72. /*====================================================================*&quot;
  73. * system header files;
  74. *--------------------------------------------------------------------*/
  75. #include &lt;unistd.h&gt;
  76. #include &lt;stdlib.h&gt;
  77. #include &lt;stdint.h&gt;
  78. #include &lt;limits.h&gt;
  79. #include &lt;sys/time.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/timer.h&quot;
  92. #include &quot;../tools/error.h&quot;
  93. #include &quot;../plc/plc.h&quot;
  94. /*====================================================================*
  95. * custom source files;
  96. *--------------------------------------------------------------------*/
  97. #ifndef MAKEFILE
  98. #include &quot;../tools/getoptv.c&quot;
  99. #include &quot;../tools/putoptv.c&quot;
  100. #include &quot;../tools/version.c&quot;
  101. #include &quot;../tools/uintspec.c&quot;
  102. #include &quot;../tools/hexdump.c&quot;
  103. #include &quot;../tools/hexencode.c&quot;
  104. #include &quot;../tools/hexdecode.c&quot;
  105. #include &quot;../tools/todigit.c&quot;
  106. #include &quot;../tools/checkfilename.c&quot;
  107. #include &quot;../tools/synonym.c&quot;
  108. #include &quot;../tools/error.c&quot;
  109. #endif
  110. #ifndef MAKEFILE
  111. #include &quot;../plc/Confirm.c&quot;
  112. #include &quot;../plc/Display.c&quot;
  113. #include &quot;../plc/Failure.c&quot;
  114. #include &quot;../plc/ReadMME.c&quot;
  115. #include &quot;../plc/Request.c&quot;
  116. #include &quot;../plc/SendMME.c&quot;
  117. #include &quot;../plc/Devices.c&quot;
  118. #endif
  119. #ifndef MAKEFILE
  120. #include &quot;../ether/openchannel.c&quot;
  121. #include &quot;../ether/closechannel.c&quot;
  122. #include &quot;../ether/readpacket.c&quot;
  123. #include &quot;../ether/sendpacket.c&quot;
  124. #include &quot;../ether/channel.c&quot;
  125. #endif
  126. #ifndef MAKEFILE
  127. #include &quot;../mme/MMECode.c&quot;
  128. #include &quot;../mme/EthernetHeader.c&quot;
  129. #include &quot;../mme/QualcommHeader.c&quot;
  130. #include &quot;../mme/QualcommHeader1.c&quot;
  131. #include &quot;../mme/UnwantedMessage.c&quot;
  132. #endif
  133. #define RETRY 300
  134. #define POLL 5
  135. /*====================================================================*
  136. *
  137. * signed ResetAndWait (struct plc * plc);
  138. *
  139. * plc.h
  140. *
  141. * reset the device using a VS_RS_DEV Request message; continue to
  142. * request resets each second until the device accepts the request
  143. * or the wait period expires;
  144. *
  145. *--------------------------------------------------------------------*/
  146. signed ResetAndWait (struct plc * plc)
  147. {
  148. struct channel * channel = (struct channel *)(plc-&gt;channel);
  149. struct message * message = (struct message *)(plc-&gt;message);
  150. struct timeval ts;
  151. struct timeval tc;
  152. unsigned timer = 0;
  153. #ifndef __GNUC__
  154. #pragma pack (push,1)
  155. #endif
  156. struct __packed vs_rs_dev_request
  157. {
  158. struct ethernet_hdr ethernet;
  159. struct qualcomm_hdr qualcomm;
  160. }
  161. * request = (struct vs_rs_dev_request *) (message);
  162. struct __packed vs_rs_dev_confirm
  163. {
  164. struct ethernet_hdr ethernet;
  165. struct qualcomm_hdr qualcomm;
  166. uint8_t MSTATUS;
  167. }
  168. * confirm = (struct vs_rs_dev_confirm *) (message);
  169. #ifndef __GNUC__
  170. #pragma pack (pop)
  171. #endif
  172. Request (plc, &quot;Reset when Ready&quot;);
  173. if (gettimeofday (&amp;ts, NULL) == -1)
  174. {
  175. error (1, errno, CANT_START_TIMER);
  176. }
  177. for (timer = 0; timer &lt; plc-&gt;timer; timer = SECONDS (ts, tc))
  178. {
  179. memset (message, 0, sizeof (* message));
  180. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  181. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_RS_DEV | MMTYPE_REQ));
  182. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  183. if (SendMME (plc) &lt;= 0)
  184. {
  185. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  186. return (-1);
  187. }
  188. if (ReadMME (plc, 0, (VS_RS_DEV | MMTYPE_CNF)) &lt; 0)
  189. {
  190. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  191. return (-1);
  192. }
  193. if (gettimeofday (&amp;tc, NULL) == -1)
  194. {
  195. error (1, errno, CANT_RESET_TIMER);
  196. }
  197. if (plc-&gt;packetsize)
  198. {
  199. if (!confirm-&gt;MSTATUS)
  200. {
  201. Confirm (plc, &quot;Resetting ...&quot;);
  202. return (0);
  203. }
  204. }
  205. }
  206. return (-1);
  207. }
  208. /*====================================================================*
  209. *
  210. * signed WaitForReset (struct plc * plc, char string [], size_t length);
  211. *
  212. * plc.h
  213. *
  214. * send and receive VS_SW_VER messages until a confirmation is not
  215. * received within channel-&gt;timeout milliseconds to indicate that
  216. * the device is inactive; return 0 if the device resets within
  217. * plc-&gt;timer seconds; otherwise, return -1;
  218. *
  219. * this function cannot distinguish between a software reset and
  220. * hardware reset;
  221. *
  222. *--------------------------------------------------------------------*/
  223. signed WaitForReset (struct plc * plc, char string [], size_t length)
  224. {
  225. struct channel * channel = (struct channel *)(plc-&gt;channel);
  226. struct message * message = (struct message *)(plc-&gt;message);
  227. struct timeval ts;
  228. struct timeval tc;
  229. unsigned timer = 0;
  230. #ifndef __GNUC__
  231. #pragma pack (push,1)
  232. #endif
  233. struct __packed vs_sw_ver_request
  234. {
  235. struct ethernet_hdr ethernet;
  236. struct qualcomm_hdr qualcomm;
  237. uint8_t MSTATUS;
  238. uint8_t MDEVICEID;
  239. uint8_t MVERLENGTH;
  240. char MVERSION [PLC_VERSION_STRING];
  241. }
  242. * request = (struct vs_sw_ver_request *) (message);
  243. struct __packed vs_sw_ver_confirm
  244. {
  245. struct ethernet_hdr ethernet;
  246. struct qualcomm_hdr qualcomm;
  247. uint8_t MSTATUS;
  248. uint8_t MDEVICEID;
  249. uint8_t MVERLENGTH;
  250. char MVERSION [PLC_VERSION_STRING];
  251. }
  252. * confirm = (struct vs_sw_ver_confirm *) (message);
  253. #ifndef __GNUC__
  254. #pragma pack (pop)
  255. #endif
  256. memset (string, 0, length);
  257. Request (plc, &quot;Allow %d seconds for Reset&quot;, plc-&gt;timer);
  258. if (gettimeofday (&amp;ts, NULL) == -1)
  259. {
  260. error (1, errno, CANT_START_TIMER);
  261. }
  262. for (timer = 0; timer &lt; plc-&gt;timer; timer = SECONDS (ts, tc))
  263. {
  264. memset (message, 0, sizeof (* message));
  265. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  266. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
  267. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  268. if (SendMME (plc) &lt;= 0)
  269. {
  270. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  271. return (-1);
  272. }
  273. if (ReadMME (plc, 0, (VS_SW_VER | MMTYPE_CNF)) &lt; 0)
  274. {
  275. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  276. return (-1);
  277. }
  278. if (gettimeofday (&amp;tc, NULL) == -1)
  279. {
  280. error (1, errno, CANT_RESET_TIMER);
  281. }
  282. if (!plc-&gt;packetsize)
  283. {
  284. if (_allset (plc-&gt;flags, (PLC_WAITFORRESET | PLC_ANALYSE)))
  285. {
  286. Confirm (plc, &quot;Waited %d seconds for Reset&quot;, timer);
  287. }
  288. memcpy (string, confirm-&gt;MVERSION, confirm-&gt;MVERLENGTH);
  289. return (0);
  290. }
  291. }
  292. if (_allset (plc-&gt;flags, (PLC_WAITFORRESET | PLC_ANALYSE)))
  293. {
  294. Confirm (plc, &quot;Waited %d seconds for Reset&quot;, timer);
  295. }
  296. return (-1);
  297. }
  298. /*====================================================================*
  299. *
  300. * signed WaitForStart (struct plc * plc, char string [], size_t length);
  301. *
  302. * plc.h
  303. *
  304. * send VS_SW_VER messages until confirmation is received within
  305. * channel-&gt;timeout milliseconds to indicate that the device is
  306. * active; return 0 if the device responds within plc-&gt;timer
  307. * seconds; otherwise, return -1;
  308. *
  309. * poll the device using VS_SW_VER messages until it responds or
  310. * the allotted time expires; return 0 if the device responds within
  311. * the allotted time or -1 if it does not or if a transmission error
  312. * occurs;
  313. *
  314. *--------------------------------------------------------------------*/
  315. signed WaitForStart (struct plc * plc, char string [], size_t length)
  316. {
  317. struct channel * channel = (struct channel *)(plc-&gt;channel);
  318. struct message * message = (struct message *)(plc-&gt;message);
  319. struct timeval ts;
  320. struct timeval tc;
  321. unsigned timer = 0;
  322. #ifndef __GNUC__
  323. #pragma pack (push,1)
  324. #endif
  325. struct __packed vs_sw_ver_request
  326. {
  327. struct ethernet_hdr ethernet;
  328. struct qualcomm_hdr qualcomm;
  329. uint8_t MSTATUS;
  330. uint8_t MDEVICEID;
  331. uint8_t MVERLENGTH;
  332. char MVERSION [PLC_VERSION_STRING];
  333. }
  334. * request = (struct vs_sw_ver_request *) (message);
  335. struct __packed vs_sw_ver_confirm
  336. {
  337. struct ethernet_hdr ethernet;
  338. struct qualcomm_hdr qualcomm;
  339. uint8_t MSTATUS;
  340. uint8_t MDEVICEID;
  341. uint8_t MVERLENGTH;
  342. char MVERSION [PLC_VERSION_STRING];
  343. }
  344. * confirm = (struct vs_sw_ver_confirm *) (message);
  345. #ifndef __GNUC__
  346. #pragma pack (pop)
  347. #endif
  348. Request (plc, &quot;Allow %d seconds for Start&quot;, plc-&gt;timer);
  349. if (gettimeofday (&amp;ts, NULL) == -1)
  350. {
  351. error (1, errno, CANT_START_TIMER);
  352. }
  353. for (timer = 0; timer &lt; plc-&gt;timer; timer = SECONDS (ts, tc))
  354. {
  355. memset (message, 0, sizeof (* message));
  356. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  357. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
  358. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  359. if (SendMME (plc) &lt;= 0)
  360. {
  361. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  362. return (-1);
  363. }
  364. if (ReadMME (plc, 0, (VS_SW_VER | MMTYPE_CNF)) &lt; 0)
  365. {
  366. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  367. return (-1);
  368. }
  369. if (gettimeofday (&amp;tc, NULL) == -1)
  370. {
  371. error (1, errno, CANT_RESET_TIMER);
  372. }
  373. if (plc-&gt;packetsize)
  374. {
  375. if (confirm-&gt;MSTATUS)
  376. {
  377. Failure (plc, PLC_WONTDOIT);
  378. return (-1);
  379. }
  380. if (_allset (plc-&gt;flags, (PLC_WAITFORSTART | PLC_ANALYSE)))
  381. {
  382. Confirm (plc, &quot;Waited %d seconds for Start&quot;, timer);
  383. }
  384. strncpy (string, confirm-&gt;MVERSION, length);
  385. return (0);
  386. }
  387. }
  388. if (_allset (plc-&gt;flags, (PLC_WAITFORSTART | PLC_ANALYSE)))
  389. {
  390. Confirm (plc, &quot;Waited %d seconds for Start&quot;, timer);
  391. }
  392. return (-1);
  393. }
  394. /*====================================================================*
  395. *
  396. * signed WaitForAssoc (struct plc * plc);
  397. *
  398. * plc.h
  399. *
  400. * send and receive VS_NW_INFO messages until the device reports
  401. * that a network exists and has at least one station; return 0 if
  402. * a network forms within plc-&gt;timer seconds; otherwise, return
  403. * -1;
  404. *
  405. *--------------------------------------------------------------------*/
  406. signed WaitForAssoc (struct plc * plc)
  407. {
  408. extern const uint8_t broadcast [ETHER_ADDR_LEN];
  409. struct channel * channel = (struct channel *)(plc-&gt;channel);
  410. struct message * message = (struct message *)(plc-&gt;message);
  411. struct timeval ts;
  412. struct timeval tc;
  413. unsigned timer = 0;
  414. #ifndef __GNUC__
  415. #pragma pack (push,1)
  416. #endif
  417. struct __packed vs_nw_info_request
  418. {
  419. struct ethernet_hdr ethernet;
  420. struct qualcomm_fmi qualcomm;
  421. }
  422. * request = (struct vs_nw_info_request *)(message);
  423. struct __packed vs_nw_info_confirm
  424. {
  425. struct ethernet_hdr ethernet;
  426. struct qualcomm_fmi qualcomm;
  427. uint8_t SUB_VERSION;
  428. uint8_t Reserved;
  429. uint16_t DATA_LEN;
  430. uint8_t DATA [1];
  431. }
  432. * confirm = (struct vs_nw_info_confirm *)(message);
  433. struct __packed station
  434. {
  435. uint8_t MAC [ETHER_ADDR_LEN];
  436. uint8_t TEI;
  437. uint8_t Reserved [3];
  438. uint8_t BDA [ETHER_ADDR_LEN];
  439. uint16_t AVGTX;
  440. uint8_t COUPLING;
  441. uint8_t Reserved3;
  442. uint16_t AVGRX;
  443. uint16_t Reserved4;
  444. }
  445. * station;
  446. struct __packed network
  447. {
  448. uint8_t NID [7];
  449. uint8_t Reserved1 [2];
  450. uint8_t SNID;
  451. uint8_t TEI;
  452. uint8_t Reserved2 [4];
  453. uint8_t ROLE;
  454. uint8_t CCO_MAC [ETHER_ADDR_LEN];
  455. uint8_t CCO_TEI;
  456. uint8_t Reserved3 [3];
  457. uint8_t NUMSTAS;
  458. uint8_t Reserved4 [5];
  459. struct station stations [1];
  460. }
  461. * network;
  462. struct __packed networks
  463. {
  464. uint8_t Reserved;
  465. uint8_t NUMAVLNS;
  466. struct network networks [1];
  467. }
  468. * networks = (struct networks *) (confirm-&gt;DATA);
  469. #ifndef __GNUC__
  470. #pragma pack (pop)
  471. #endif
  472. Request (plc, &quot;Allow %d seconds for Assoc&quot;, plc-&gt;timer);
  473. if (gettimeofday (&amp;ts, NULL) == -1)
  474. {
  475. error (1, errno, CANT_START_TIMER);
  476. }
  477. for (timer = 0; timer &lt; plc-&gt;timer; timer = SECONDS (ts, tc))
  478. {
  479. memset (message, 0, sizeof (* message));
  480. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  481. QualcommHeader1 (&amp;request-&gt;qualcomm, 1, (VS_NW_INFO | MMTYPE_REQ));
  482. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  483. if (SendMME (plc) &lt;= 0)
  484. {
  485. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  486. return (-1);
  487. }
  488. if (ReadMME (plc, 1, (VS_NW_INFO | MMTYPE_CNF)) &lt; 0)
  489. {
  490. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  491. return (-1);
  492. }
  493. if (gettimeofday (&amp;tc, NULL) == -1)
  494. {
  495. error (1, errno, CANT_RESET_TIMER);
  496. }
  497. if (plc-&gt;packetsize)
  498. {
  499. network = (struct network *)(&amp;networks-&gt;networks);
  500. while (networks-&gt;NUMAVLNS--)
  501. {
  502. station = (struct station *)(&amp;network-&gt;stations);
  503. while (network-&gt;NUMSTAS--)
  504. {
  505. if (memcmp (station-&gt;MAC, broadcast, sizeof (broadcast)))
  506. {
  507. if (_allset (plc-&gt;flags, (PLC_WAITFORASSOC | PLC_ANALYSE)))
  508. {
  509. Confirm (plc, &quot;Waited %d seconds for Assoc&quot;, timer);
  510. }
  511. return (0);
  512. }
  513. station++;
  514. }
  515. network = (struct network *)(station);
  516. }
  517. }
  518. }
  519. if (_allset (plc-&gt;flags, (PLC_WAITFORASSOC | PLC_ANALYSE)))
  520. {
  521. Confirm (plc, &quot;Waited %d seconds for Assoc&quot;, timer);
  522. }
  523. return (-1);
  524. }
  525. /*====================================================================*
  526. *
  527. * void function (struct plc * plc, char const * firmware);
  528. *
  529. * perform operations in a logical order;
  530. *
  531. *
  532. *--------------------------------------------------------------------*/
  533. static void function (struct plc * plc, char const * firmware)
  534. {
  535. char string [PLC_VERSION_STRING];
  536. if (_anyset (plc-&gt;flags, PLC_RESET_DEVICE))
  537. {
  538. if (ResetAndWait (plc))
  539. {
  540. Failure (plc, &quot;Device did not Reset.&quot;);
  541. }
  542. }
  543. if (_anyset (plc-&gt;flags, PLC_WAITFORRESET))
  544. {
  545. if (WaitForReset (plc, string, sizeof (string)))
  546. {
  547. Failure (plc, &quot;Device did not Reset.&quot;);
  548. }
  549. }
  550. if (_anyset (plc-&gt;flags, PLC_WAITFORSTART))
  551. {
  552. if (WaitForStart (plc, string, sizeof (string)))
  553. {
  554. Failure (plc, &quot;Device did not Start.&quot;);
  555. }
  556. if ((firmware) &amp;&amp; (*firmware) &amp;&amp; strcmp (firmware, string))
  557. {
  558. Failure (plc, &quot;Started wrong firmware&quot;);
  559. }
  560. }
  561. if (_anyset (plc-&gt;flags, PLC_WAITFORASSOC))
  562. {
  563. if (WaitForAssoc (plc))
  564. {
  565. Failure (plc, &quot;Device did not Assoc.&quot;);
  566. }
  567. }
  568. if (plc-&gt;sleep)
  569. {
  570. Request (plc, &quot;Pause %d seconds&quot;, plc-&gt;sleep);
  571. sleep (plc-&gt;sleep);
  572. }
  573. return;
  574. }
  575. /*====================================================================*
  576. *
  577. * int main (int argc, char const * argv[]);
  578. *
  579. * parse command line, populate plc structure and perform selected
  580. * operations; show help summary if asked; see getoptv and putoptv
  581. * to understand command line parsing and help summary display; see
  582. * plc.h for the definition of struct plc;
  583. *
  584. * the command line accepts multiple MAC addresses and the program
  585. * performs the specified operations on each address, in turn; the
  586. * address order is significant but the option order is not; the
  587. * default address is a local broadcast that causes all devices on
  588. * the local H1 interface to respond but not those at the remote
  589. * end of the powerline;
  590. *
  591. * the default address is 00:B0:52:00:00:01; omitting the address
  592. * will automatically address the local device; some options will
  593. * cancel themselves if this makes no sense;
  594. *
  595. * the default interface is eth1 because most people use eth0 as
  596. * their principle network connection; you can specify another
  597. * interface with -i or define environment string PLC to make
  598. * that the default interface and save typing;
  599. *
  600. *
  601. *--------------------------------------------------------------------*/
  602. int main (int argc, char const * argv [])
  603. {
  604. extern struct channel channel;
  605. static char const * optv [] =
  606. {
  607. &quot;ac:ef:i:p:qrRstvxw:&quot;,
  608. &quot;device [device] [...] [&gt; stdout]&quot;,
  609. &quot;Qualcomm Atheros INT6x00 Powerline Device Procrastinator&quot;,
  610. &quot;a\twait for device assoc&quot;,
  611. &quot;c n\tpolling retry count [&quot; LITERAL (RETRY) &quot;]&quot;,
  612. &quot;e\tredirect stderr to stdout&quot;,
  613. &quot;f s\tconfirm firmware is revision s&quot;,
  614. #if defined (WINPCAP) || defined (LIBPCAP)
  615. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  616. #else
  617. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  618. #endif
  619. &quot;p n\tpoll (n) times per second [&quot; LITERAL (POLL) &quot;]&quot;,
  620. &quot;q\tquiet mode&quot;,
  621. &quot;v\tverbose mode&quot;,
  622. &quot;R\treset device and wait&quot;,
  623. &quot;r\twait for device reset&quot;,
  624. &quot;s\twait for device start&quot;,
  625. &quot;t\tshow wait times&quot;,
  626. &quot;w n\twait n seconds&quot;,
  627. &quot;x\texit on error&quot;,
  628. (char const *) (0)
  629. };
  630. #include &quot;../plc/plc.c&quot;
  631. char const * firmware = &quot;&quot;;
  632. unsigned retry = RETRY;
  633. unsigned poll = POLL;
  634. signed c;
  635. if (getenv (PLCDEVICE))
  636. {
  637. #if defined (WINPCAP) || defined (LIBPCAP)
  638. channel.ifindex = atoi (getenv (PLCDEVICE));
  639. #else
  640. channel.ifname = strdup (getenv (PLCDEVICE));
  641. #endif
  642. }
  643. optind = 1;
  644. while ((c = getoptv (argc, argv, optv)) != -1)
  645. {
  646. switch (c)
  647. {
  648. case 'a':
  649. _setbits (plc.flags, PLC_WAITFORASSOC);
  650. break;
  651. case 'c':
  652. retry = (unsigned)(uintspec (optarg, 1, UINT_MAX));
  653. break;
  654. case 'e':
  655. dup2 (STDOUT_FILENO, STDERR_FILENO);
  656. break;
  657. case 'f':
  658. firmware = optarg;
  659. break;
  660. case 'i':
  661. #if defined (WINPCAP) || defined (LIBPCAP)
  662. channel.ifindex = atoi (optarg);
  663. #else
  664. channel.ifname = optarg;
  665. #endif
  666. break;
  667. case 'p':
  668. poll = (unsigned)(uintspec (optarg, 1, 50));
  669. break;
  670. case 'q':
  671. _setbits (channel.flags, CHANNEL_SILENCE);
  672. _setbits (plc.flags, PLC_SILENCE);
  673. break;
  674. case 'r':
  675. _setbits (plc.flags, PLC_WAITFORRESET);
  676. break;
  677. case 'R':
  678. _setbits (plc.flags, PLC_RESET_DEVICE);
  679. break;
  680. case 's':
  681. _setbits (plc.flags, PLC_WAITFORSTART);
  682. break;
  683. case 't':
  684. _setbits (plc.flags, PLC_ANALYSE);
  685. break;
  686. case 'v':
  687. _setbits (channel.flags, CHANNEL_VERBOSE);
  688. _setbits (plc.flags, PLC_VERBOSE);
  689. break;
  690. case 'w':
  691. plc.sleep = (unsigned)(uintspec (optarg, 0, 3600));
  692. break;
  693. case 'x':
  694. _setbits (plc.flags, PLC_BAILOUT);
  695. break;
  696. default:
  697. break;
  698. }
  699. }
  700. argc -= optind;
  701. argv += optind;
  702. plc.timer = retry / poll;
  703. openchannel (&amp;channel);
  704. if (!(plc.message = malloc (sizeof (* plc.message))))
  705. {
  706. error (1, errno, PLC_NOMEMORY);
  707. }
  708. if (!argc)
  709. {
  710. function (&amp;plc, firmware);
  711. }
  712. while ((argc) &amp;&amp; (* argv))
  713. {
  714. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  715. {
  716. error (1, errno, PLC_BAD_MAC, * argv);
  717. }
  718. function (&amp;plc, firmware);
  719. argv++;
  720. argc--;
  721. }
  722. free (plc.message);
  723. closechannel (&amp;channel);
  724. exit (0);
  725. }
  726. </pre>
  727. <div class='footerlink'>
  728. [<a href='int6kuart.c.html' title=' int6kuart.c '>PREV</a>]
  729. [<a href='toolkit.html' title=' Index '>HOME</a>]
  730. [<a href='ipv4spec.c.html' title=' ipv4spec.c '>NEXT</a>]
  731. </div>
  732. </body>
  733. </html>