int6kuart.c.html 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  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. int6kuart.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='int6ktone.c.html' title=' int6ktone.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='int6kwait.c.html' title=' int6kwait.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. * int6kuart.c - Atheros Serial Line Device Manager;
  64. *
  65. *
  66. * Contributor(s):
  67. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  68. * Mathieu Olivari &lt;mathieu@qca.qualcomm.com&gt;
  69. *
  70. *--------------------------------------------------------------------*/
  71. /*====================================================================*
  72. * system header files;
  73. *--------------------------------------------------------------------*/
  74. #include &lt;unistd.h&gt;
  75. #include &lt;stdlib.h&gt;
  76. #include &lt;string.h&gt;
  77. #if defined (WIN32)
  78. # include &lt;net/ethernet.h&gt;
  79. #elif defined (__linux__)
  80. # include &lt;net/ethernet.h&gt;
  81. #elif defined (__APPLE__)
  82. # include &lt;net/ethernet.h&gt;
  83. #elif defined (__OpenBSD__)
  84. # include &lt;sys/socket.h&gt;
  85. # include &lt;net/if.h&gt;
  86. # include &lt;net/if_arp.h&gt;
  87. # include &lt;netinet/in.h&gt;
  88. # include &lt;netinet/if_ether.h&gt;
  89. #else
  90. #error &quot;Unknown Environment&quot;
  91. #endif
  92. /*====================================================================*
  93. * custom header files;
  94. *--------------------------------------------------------------------*/
  95. #include &quot;../tools/getoptv.h&quot;
  96. #include &quot;../tools/putoptv.h&quot;
  97. #include &quot;../tools/number.h&quot;
  98. #include &quot;../tools/memory.h&quot;
  99. #include &quot;../tools/endian.h&quot;
  100. #include &quot;../tools/files.h&quot;
  101. #include &quot;../tools/flags.h&quot;
  102. #include &quot;../tools/error.h&quot;
  103. #include &quot;../tools/types.h&quot;
  104. #include &quot;../serial/serial.h&quot;
  105. #include &quot;../plc/plc.h&quot;
  106. /*====================================================================*
  107. * custom source files;
  108. *--------------------------------------------------------------------*/
  109. #ifndef MAKEFILE
  110. #include &quot;../tools/getoptv.c&quot;
  111. #include &quot;../tools/putoptv.c&quot;
  112. #include &quot;../tools/version.c&quot;
  113. #include &quot;../tools/uintspec.c&quot;
  114. #include &quot;../tools/basespec.c&quot;
  115. #include &quot;../tools/synonym.c&quot;
  116. #include &quot;../tools/todigit.c&quot;
  117. #include &quot;../tools/error.c&quot;
  118. #include &quot;../tools/checksum32.c&quot;
  119. #include &quot;../tools/hexencode.c&quot;
  120. #include &quot;../tools/hexdump.c&quot;
  121. #include &quot;../tools/hexstring.c&quot;
  122. #include &quot;../tools/hexdecode.c&quot;
  123. #include &quot;../tools/error.c&quot;
  124. #endif
  125. #ifndef MAKEFILE
  126. #include &quot;../serial/openport.c&quot;
  127. #include &quot;../serial/closeport.c&quot;
  128. #include &quot;../serial/serial.c&quot;
  129. #endif
  130. /*====================================================================*
  131. * program constants;
  132. *--------------------------------------------------------------------*/
  133. #define FRAME_MIN_CHAR 120
  134. #define FRAME_MAX_CHAR 1496
  135. /*====================================================================*
  136. * program variables;
  137. *--------------------------------------------------------------------*/
  138. typedef struct uart
  139. {
  140. struct _file_ port;
  141. struct _file_ pib;
  142. struct _file_ nvm;
  143. struct _file_ eth;
  144. char const * string;
  145. char PIBVersion [3];
  146. char IMGVersion [128];
  147. byte MACAddress [ETHER_ADDR_LEN];
  148. char NMKDigest [16];
  149. byte NMKNumber;
  150. byte module;
  151. uint16_t bfsize;
  152. uint16_t snooze;
  153. uint16_t timeout;
  154. unsigned flags;
  155. }
  156. uart;
  157. /*====================================================================*
  158. *
  159. * void at_writenvm (struct uart * uart);
  160. *
  161. * read firmware image from file and send to device using command
  162. * &quot;ATWPF&quot;; the file descriptor is &quot;nvm&quot; member of struct uart;
  163. *
  164. *--------------------------------------------------------------------*/
  165. static void at_writenvm (struct uart * uart)
  166. {
  167. extern struct command command;
  168. byte memory [UART_BLOCKSIZE];
  169. signed mblock = sizeof (memory);
  170. uint16_t mlength = 0;
  171. uint32_t moffset = 0;
  172. uint32_t mchksum;
  173. uint16_t olength = 0;
  174. uint32_t ooffset = 0;
  175. uint32_t ochksum;
  176. while ((mblock = read (uart-&gt;nvm.file, memory, mblock)) &gt; 0)
  177. {
  178. clearcommand ();
  179. insert ('A');
  180. insert ('T');
  181. insert ('W');
  182. insert ('P');
  183. insert ('F');
  184. insert ('1');
  185. insert (',');
  186. mchksum = checksum32 (memory, (size_t)(mblock), 0);
  187. mlength = (uint16_t)(mblock);
  188. mlength = HTOBE16 (mlength);
  189. decode (&amp;mlength, sizeof (mlength));
  190. mlength = BE16TOH (mlength);
  191. insert (',');
  192. moffset = HTOBE32 (moffset);
  193. decode (&amp;moffset, sizeof (moffset));
  194. moffset = BE32TOH (moffset);
  195. insert (',');
  196. mchksum = HTOBE32 (mchksum);
  197. decode (&amp;mchksum, sizeof (mchksum));
  198. mchksum = BE32TOH (mchksum);
  199. insert (',');
  200. decode (memory, mlength);
  201. insert ('\r');
  202. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  203. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  204. mustbe ('O');
  205. mustbe ('K');
  206. mustbe ('1');
  207. mustbe (',');
  208. olength = (uint16_t)(hextoint (sizeof (olength)));
  209. if (olength != mlength)
  210. {
  211. command.buffer [command.offset] = (char)(0);
  212. error (1, EINVAL, &quot;[%s]: expected length %X&quot;, command.buffer, mlength);
  213. }
  214. mustbe (',');
  215. ooffset = (uint32_t)(hextoint (sizeof (ooffset)));
  216. if (ooffset != moffset)
  217. {
  218. command.buffer [command.offset] = (char)(0);
  219. error (1, EINVAL, &quot;[%s]: expected offset %X&quot;, command.buffer, moffset);
  220. }
  221. mustbe (',');
  222. ochksum = (uint32_t)(hextoint (sizeof (ochksum)));
  223. if (ochksum != mchksum)
  224. {
  225. command.buffer [command.offset] = (char)(0);
  226. error (1, EINVAL, &quot;[%s]: expected checksum %X (%X)&quot;, command.buffer, mchksum, ochksum);
  227. }
  228. mustbe (',');
  229. encode (memory, mblock);
  230. mustbe ('\r');
  231. moffset += mlength;
  232. if (_allclr (uart-&gt;flags, (UART_VERBOSE | UART_SILENCE)))
  233. {
  234. write (STDOUT_FILENO, &quot;.&quot;, 1);
  235. }
  236. }
  237. #ifndef WIN32
  238. if (_allclr (uart-&gt;flags, (UART_VERBOSE | UART_SILENCE)))
  239. {
  240. write (STDOUT_FILENO, &quot;\n&quot;, 1);
  241. }
  242. #endif
  243. return;
  244. }
  245. /*====================================================================*
  246. *
  247. * void at_writepib (struct uart * uart);
  248. *
  249. * read parameter block file and send to device using command
  250. * &quot;ATWPF&quot;; the file descriptor is &quot;pib&quot; member of struct uart;
  251. *
  252. *--------------------------------------------------------------------*/
  253. static void at_writepib (struct uart * uart)
  254. {
  255. extern struct command command;
  256. byte memory [UART_BLOCKSIZE];
  257. signed mblock = sizeof (memory);
  258. uint16_t mlength = 0;
  259. uint16_t moffset = 0;
  260. uint32_t mchksum;
  261. uint16_t olength = 0;
  262. uint16_t ooffset = 0;
  263. uint32_t ochksum;
  264. while ((mblock = read (uart-&gt;pib.file, memory, mblock)) &gt; 0)
  265. {
  266. clearcommand ();
  267. insert ('A');
  268. insert ('T');
  269. insert ('W');
  270. insert ('P');
  271. insert ('F');
  272. insert ('2');
  273. insert (',');
  274. mchksum = checksum32 (memory, (size_t)(mblock), 0);
  275. mlength = (uint16_t)(mblock);
  276. mlength = HTOBE16 (mlength);
  277. decode (&amp;mlength, sizeof (mlength));
  278. mlength = BE16TOH (mlength);
  279. insert (',');
  280. moffset = HTOBE16 (moffset);
  281. decode (&amp;moffset, sizeof (moffset));
  282. moffset = BE16TOH (moffset);
  283. insert (',');
  284. mchksum = HTOBE32 (mchksum);
  285. decode (&amp;mchksum, sizeof (mchksum));
  286. mchksum = BE32TOH (mchksum);
  287. insert (',');
  288. decode (memory, mlength);
  289. insert ('\r');
  290. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  291. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  292. mustbe ('O');
  293. mustbe ('K');
  294. mustbe ('2');
  295. mustbe (',');
  296. olength = (uint16_t)(hextoint (sizeof (olength)));
  297. if (olength != mlength)
  298. {
  299. command.buffer [command.offset] = (char)(0);
  300. error (1, EINVAL, &quot;[%s]: expected length %X&quot;, command.buffer, mlength);
  301. }
  302. mustbe (',');
  303. ooffset = (uint16_t)(hextoint (sizeof (ooffset)));
  304. if (ooffset != moffset)
  305. {
  306. command.buffer [command.offset] = (char)(0);
  307. error (1, EINVAL, &quot;[%s]: expected offset %X&quot;, command.buffer, moffset);
  308. }
  309. mustbe (',');
  310. ochksum = (uint32_t)(hextoint (sizeof (ochksum)));
  311. if (ochksum != mchksum)
  312. {
  313. command.buffer [command.offset] = (char)(0);
  314. error (1, EINVAL, &quot;[%s]: expected checksum %X (%X)&quot;, command.buffer, mchksum, ochksum);
  315. }
  316. mustbe (',');
  317. encode (memory, mblock);
  318. mustbe ('\r');
  319. moffset += mlength;
  320. if (_allclr (uart-&gt;flags, (UART_VERBOSE | UART_SILENCE)))
  321. {
  322. write (STDOUT_FILENO, &quot;.&quot;, 1);
  323. }
  324. }
  325. #ifndef WIN32
  326. if (_allclr (uart-&gt;flags, (UART_VERBOSE | UART_SILENCE)))
  327. {
  328. write (STDOUT_FILENO, &quot;\n&quot;, 1);
  329. }
  330. #endif
  331. return;
  332. }
  333. /*====================================================================*
  334. *
  335. * void at_readpib (struct uart * uart);
  336. *
  337. * read parameter block from device and save to file using command
  338. * &quot;ATRP&quot;; the file descriptor is &quot;pib&quot; member of struct uart;
  339. *
  340. *--------------------------------------------------------------------*/
  341. static void at_readpib (struct uart * uart)
  342. {
  343. extern struct command command;
  344. byte memory [UART_BLOCKSIZE];
  345. signed mblock = sizeof (memory);
  346. uint16_t mextent = 0;
  347. uint16_t mlength = 0;
  348. uint16_t moffset = 0;
  349. uint16_t olength = 0;
  350. uint16_t ooffset = 0;
  351. clearcommand ();
  352. insert ('A');
  353. insert ('T');
  354. insert ('R');
  355. insert ('P');
  356. insert ('2');
  357. insert (',');
  358. insert ('4');
  359. insert ('\r');
  360. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  361. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  362. mustbe ('O');
  363. mustbe ('K');
  364. mustbe ('2');
  365. mustbe (',');
  366. mustbe ('4');
  367. mustbe (',');
  368. encode (&amp;mextent, sizeof (mextent));
  369. mextent = LE16TOH (mextent);
  370. mustbe ('\r');
  371. while (mextent)
  372. {
  373. clearcommand ();
  374. insert ('A');
  375. insert ('T');
  376. insert ('R');
  377. insert ('P');
  378. if (mblock &gt; mextent)
  379. {
  380. mblock = mextent;
  381. }
  382. mlength = (uint16_t)(mblock);
  383. mlength = HTOBE16 (mlength);
  384. decode (&amp;mlength, sizeof (mlength));
  385. mlength = BE16TOH (mlength);
  386. insert (',');
  387. moffset = HTOBE16 (moffset);
  388. decode (&amp;moffset, sizeof (moffset));
  389. moffset = BE16TOH (moffset);
  390. insert ('\r');
  391. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  392. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  393. mustbe ('O');
  394. mustbe ('K');
  395. olength = (uint16_t)(hextoint (sizeof (olength)));
  396. if (olength != mlength)
  397. {
  398. command.buffer [command.offset] = (char)(0);
  399. error (1, EINVAL, &quot;[%s]: have %d bytes but wanted %d&quot;, command.buffer, olength, mlength);
  400. }
  401. mustbe (',');
  402. ooffset = (uint16_t)(hextoint (sizeof (ooffset)));
  403. if (ooffset != moffset)
  404. {
  405. command.buffer [command.offset] = (char)(0);
  406. error (1, EINVAL, &quot;[%s]: expected offset %X&quot;, command.buffer, moffset);
  407. }
  408. mustbe (',');
  409. encode (memory, mblock);
  410. if (write (uart-&gt;pib.file, memory, mblock) &lt; mblock)
  411. {
  412. command.buffer [command.offset] = (char)(0);
  413. error (1, errno, &quot;[%s]: expected length %d&quot;, command.buffer, mblock);
  414. }
  415. mustbe ('\r');
  416. moffset += mblock;
  417. mextent -= mblock;
  418. if (_allclr (uart-&gt;flags, (UART_VERBOSE | UART_SILENCE)))
  419. {
  420. write (STDOUT_FILENO, &quot;.&quot;, 1);
  421. }
  422. }
  423. #ifndef WIN32
  424. if (_allclr (uart-&gt;flags, (UART_VERBOSE | UART_SILENCE)))
  425. {
  426. write (STDOUT_FILENO, &quot;\n&quot;, 1);
  427. }
  428. #endif
  429. return;
  430. }
  431. /*====================================================================*
  432. *
  433. * void at_wake (struct uart * uart);
  434. *
  435. * send wake command &quot;+++&quot; to enter command mode;
  436. *
  437. *--------------------------------------------------------------------*/
  438. static void at_wake (struct uart * uart)
  439. {
  440. clearcommand ();
  441. insert ('+');
  442. insert ('+');
  443. insert ('+');
  444. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  445. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  446. mustbe ('O');
  447. mustbe ('K');
  448. mustbe ('\r');
  449. return;
  450. }
  451. /*====================================================================*
  452. *
  453. * void at_command (struct uart * uart);
  454. *
  455. * send custom command; use this function to send any serial line
  456. * command that may not be supported by this program;
  457. *
  458. *--------------------------------------------------------------------*/
  459. static void at_command (struct uart * uart)
  460. {
  461. clearcommand ();
  462. while (*uart-&gt;string)
  463. {
  464. insert (*uart-&gt;string++);
  465. }
  466. insert ('\r');
  467. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  468. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  469. clearcommand ();
  470. return;
  471. }
  472. /*====================================================================*
  473. *
  474. * void at_respond (struct uart * uart);
  475. *
  476. * send command &quot;AT&quot; to test command mode; this command does nothing
  477. * but echo &quot;OK&quot;;
  478. *
  479. *--------------------------------------------------------------------*/
  480. static void at_respond (struct uart * uart)
  481. {
  482. clearcommand ();
  483. insert ('A');
  484. insert ('T');
  485. insert ('\r');
  486. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  487. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  488. mustbe ('O');
  489. mustbe ('K');
  490. mustbe ('\r');
  491. return;
  492. }
  493. /*====================================================================*
  494. *
  495. * void atz (struct uart * uart);
  496. *
  497. * send command &quot;ATZ&quot; to reset the device; no response is expected;
  498. *
  499. *--------------------------------------------------------------------*/
  500. static void atz (struct uart * uart)
  501. {
  502. clearcommand ();
  503. insert ('A');
  504. insert ('T');
  505. insert ('Z');
  506. insert ('\r');
  507. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  508. return;
  509. }
  510. /*====================================================================*
  511. *
  512. * void atrv (struct uart * uart);
  513. *
  514. * read and display the firmware image version using command &quot;ATRV&quot;;
  515. * return the version string in IMGVersion member of struct uart;
  516. *
  517. *--------------------------------------------------------------------*/
  518. static void atrv (struct uart * uart)
  519. {
  520. clearcommand ();
  521. insert ('A');
  522. insert ('T');
  523. insert ('R');
  524. insert ('V');
  525. insert ('\r');
  526. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  527. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  528. mustbe ('O');
  529. mustbe ('K');
  530. mustbe ('\&quot;');
  531. string (uart-&gt;IMGVersion);
  532. mustbe ('\&quot;');
  533. mustbe ('\r');
  534. printf (&quot;%s\n&quot;, uart-&gt;IMGVersion);
  535. return;
  536. }
  537. /*====================================================================*
  538. *
  539. * void atrpm (struct uart * uart);
  540. *
  541. * read and display the PIB version and MAC address using command
  542. * &quot;ATRPM&quot;; return version string in PIBVersion member and address
  543. * string in MACAddress member of struct
  544. *
  545. *
  546. *--------------------------------------------------------------------*/
  547. static void atrpm (struct uart * uart)
  548. {
  549. char mac [ETHER_ADDR_LEN * 3];
  550. clearcommand ();
  551. insert ('A');
  552. insert ('T');
  553. insert ('R');
  554. insert ('P');
  555. insert ('M');
  556. insert ('\r');
  557. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  558. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  559. mustbe ('O');
  560. mustbe ('K');
  561. mustbe ('\&quot;');
  562. string (uart-&gt;PIBVersion);
  563. mustbe ('\&quot;');
  564. mustbe (',');
  565. encode (uart-&gt;MACAddress, sizeof (uart-&gt;MACAddress));
  566. mustbe ('\r');
  567. printf (&quot;%s %s\n&quot;, uart-&gt;PIBVersion, hexstring (mac, sizeof (mac), uart-&gt;MACAddress, sizeof (uart-&gt;MACAddress)));
  568. return;
  569. }
  570. /*====================================================================*
  571. *
  572. * void atsk1 (struct uart * uart);
  573. *
  574. * send Set Key command &quot;ATSK&quot;; ask device for NMK; encode returned
  575. * key into uart-NMK;
  576. *
  577. *--------------------------------------------------------------------*/
  578. static void atsk1 (struct uart * uart)
  579. {
  580. char key [48];
  581. clearcommand ();
  582. insert ('A');
  583. insert ('T');
  584. insert ('S');
  585. insert ('K');
  586. insert ('?');
  587. insert ('\r');
  588. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  589. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  590. mustbe ('O');
  591. mustbe ('K');
  592. encode (uart-&gt;NMKDigest, sizeof (uart-&gt;NMKDigest));
  593. mustbe ('\r');
  594. printf (&quot;%s\n&quot;, hexstring (key, sizeof (key), uart-&gt;NMKDigest, sizeof (uart-&gt;NMKDigest)));
  595. return;
  596. }
  597. /*====================================================================*
  598. *
  599. * void atsk2 (struct uart * uart);
  600. *
  601. * send Set Key command &quot;ATSK&quot;; send device the NMK; encode returned
  602. *
  603. *--------------------------------------------------------------------*/
  604. static void atsk2 (struct uart * uart)
  605. {
  606. char key [48];
  607. clearcommand ();
  608. insert ('A');
  609. insert ('T');
  610. insert ('S');
  611. insert ('K');
  612. decode (uart-&gt;NMKDigest, sizeof (uart-&gt;NMKDigest));
  613. insert ('\r');
  614. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  615. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  616. mustbe ('O');
  617. mustbe ('K');
  618. encode (uart-&gt;NMKDigest, sizeof (uart-&gt;NMKDigest));
  619. mustbe ('\r');
  620. printf (&quot;%s\n&quot;, hexstring (key, sizeof (key), uart-&gt;NMKDigest, sizeof (uart-&gt;NMKDigest)));
  621. return;
  622. }
  623. /*====================================================================*
  624. *
  625. * void atdst1 (struct uart * uart);
  626. *
  627. * read transparent mode destination MAC address command &quot;ATDST?&quot;;
  628. *
  629. *--------------------------------------------------------------------*/
  630. static void atdst1 (struct uart * uart)
  631. {
  632. char mac [ETHER_ADDR_LEN * 3];
  633. clearcommand ();
  634. insert ('A');
  635. insert ('T');
  636. insert ('D');
  637. insert ('S');
  638. insert ('T');
  639. insert ('?');
  640. insert ('\r');
  641. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  642. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  643. mustbe ('O');
  644. mustbe ('K');
  645. encode (uart-&gt;MACAddress, sizeof (uart-&gt;MACAddress));
  646. mustbe ('\r');
  647. printf (&quot;%s\n&quot;, hexstring (mac, sizeof (mac), uart-&gt;MACAddress, sizeof (uart-&gt;MACAddress)));
  648. return;
  649. }
  650. /*====================================================================*
  651. *
  652. * void atdst2 (struct uart * uart);
  653. *
  654. * read transparent mode destination MAC address command &quot;ATDST?&quot;;
  655. *
  656. *--------------------------------------------------------------------*/
  657. static void atdst2 (struct uart * uart)
  658. {
  659. char mac [ETHER_ADDR_LEN * 3];
  660. clearcommand ();
  661. insert ('A');
  662. insert ('T');
  663. insert ('D');
  664. insert ('S');
  665. insert ('T');
  666. decode (uart-&gt;MACAddress, sizeof (uart-&gt;MACAddress));
  667. insert ('\r');
  668. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  669. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  670. mustbe ('O');
  671. mustbe ('K');
  672. encode (uart-&gt;MACAddress, sizeof (uart-&gt;MACAddress));
  673. mustbe ('\r');
  674. printf (&quot;%s\n&quot;, hexstring (mac, sizeof (mac), uart-&gt;MACAddress, sizeof (uart-&gt;MACAddress)));
  675. return;
  676. }
  677. /*====================================================================*
  678. *
  679. * void atni (struct uart * uart);
  680. *
  681. * reset device to factory default pib command &quot;ATNI&quot;;
  682. *
  683. *--------------------------------------------------------------------*/
  684. static void atni (struct uart * uart)
  685. {
  686. unsigned count;
  687. unsigned index;
  688. uint16_t rxrate;
  689. uint16_t txrate;
  690. byte address [ETHER_ADDR_LEN];
  691. char mac [ETHER_ADDR_LEN * 3];
  692. clearcommand ();
  693. insert ('A');
  694. insert ('T');
  695. insert ('N');
  696. insert ('I');
  697. insert ('?');
  698. insert ('\r');
  699. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  700. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  701. mustbe ('O');
  702. mustbe ('K');
  703. count = (unsigned)(hextoint (sizeof (unsigned)));
  704. while (count--)
  705. {
  706. mustbe (',');
  707. index = (unsigned)(hextoint (sizeof (index)));
  708. mustbe (',');
  709. encode (address, sizeof (address));
  710. mustbe (',');
  711. txrate = (uint16_t)(hextoint (sizeof (rxrate)));
  712. mustbe (',');
  713. rxrate = (uint16_t)(hextoint (sizeof (txrate)));
  714. printf (&quot;%d %s %3d RX %3d TX\n&quot;, index, hexstring (mac, sizeof (mac), address, sizeof (address)), rxrate, txrate);
  715. }
  716. mustbe ('\r');
  717. return;
  718. }
  719. /*====================================================================*
  720. *
  721. * void atfd (struct uart * uart);
  722. *
  723. * reset device to factory default pib command &quot;ATFD&quot;;
  724. *
  725. *--------------------------------------------------------------------*/
  726. static void atfd (struct uart * uart)
  727. {
  728. clearcommand ();
  729. insert ('A');
  730. insert ('T');
  731. insert ('F');
  732. insert ('D');
  733. insert ('\r');
  734. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  735. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  736. mustbe ('O');
  737. mustbe ('K');
  738. mustbe ('\r');
  739. return;
  740. }
  741. /*====================================================================*
  742. *
  743. * void atps (struct uart * uart);
  744. *
  745. * etner power save mode command &quot;ATPS&quot;;
  746. *
  747. *--------------------------------------------------------------------*/
  748. static void atps (struct uart * uart)
  749. {
  750. extern struct command command;
  751. uint16_t result;
  752. clearcommand ();
  753. insert ('A');
  754. insert ('T');
  755. insert ('P');
  756. insert ('S');
  757. uart-&gt;snooze = HTOBE16 (uart-&gt;snooze);
  758. decode (&amp;uart-&gt;snooze, sizeof (uart-&gt;snooze));
  759. uart-&gt;snooze = BE16TOH (uart-&gt;snooze);
  760. insert ('\r');
  761. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  762. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  763. mustbe ('O');
  764. mustbe ('K');
  765. result = (uint16_t)(hextoint (sizeof (result)));
  766. if (result != uart-&gt;snooze)
  767. {
  768. error (1, EINVAL, &quot;[%s]: expected timeout %04X&quot;, command.buffer, uart-&gt;snooze);
  769. }
  770. mustbe ('\r');
  771. return;
  772. }
  773. /*====================================================================*
  774. *
  775. * void ato (struct uart * uart);
  776. *
  777. * exit command mode and enter tyransparent mode command &quot;ATO&quot;;
  778. *
  779. *--------------------------------------------------------------------*/
  780. static void ato (struct uart * uart)
  781. {
  782. clearcommand ();
  783. insert ('A');
  784. insert ('T');
  785. insert ('O');
  786. insert ('\r');
  787. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  788. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  789. mustbe ('O');
  790. mustbe ('K');
  791. mustbe ('\r');
  792. return;
  793. }
  794. /*====================================================================*
  795. *
  796. * void athsc (struct uart * uart);
  797. *
  798. * exit command mode; enter high speed command mode &quot;ATHSC&quot;;
  799. *
  800. *--------------------------------------------------------------------*/
  801. static void athsc (struct uart * uart)
  802. {
  803. clearcommand ();
  804. insert ('A');
  805. insert ('T');
  806. insert ('H');
  807. insert ('S');
  808. insert ('C');
  809. insert ('\r');
  810. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  811. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  812. mustbe ('O');
  813. mustbe ('K');
  814. mustbe ('\r');
  815. return;
  816. }
  817. /*====================================================================*
  818. *
  819. * void atwnv (struct uart * uart);
  820. *
  821. * write PIB and/or IMG to NVM &quot;ATWNVx&quot;;
  822. *
  823. *--------------------------------------------------------------------*/
  824. static void atwnv (struct uart * uart)
  825. {
  826. extern struct command command;
  827. byte result;
  828. clearcommand ();
  829. insert ('A');
  830. insert ('T');
  831. insert ('W');
  832. insert ('N');
  833. insert ('V');
  834. decode (&amp;uart-&gt;module, sizeof (uart-&gt;module));
  835. insert ('\r');
  836. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  837. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  838. mustbe ('O');
  839. mustbe ('K');
  840. result = (byte)(hextoint (sizeof (result)));
  841. if (result != uart-&gt;module)
  842. {
  843. error (1, EINVAL, &quot;[%s]: expected module %d&quot;, command.buffer, uart-&gt;module);
  844. }
  845. mustbe ('\r');
  846. return;
  847. }
  848. /*====================================================================*
  849. *
  850. * void atbsz1 (struct uart * uart);
  851. *
  852. * get transparent mode buffer size &quot;ATBSZ?&quot;;
  853. *
  854. *--------------------------------------------------------------------*/
  855. static void atbsz1 (struct uart * uart)
  856. {
  857. clearcommand ();
  858. insert ('A');
  859. insert ('T');
  860. insert ('B');
  861. insert ('S');
  862. insert ('Z');
  863. insert ('?');
  864. insert ('\r');
  865. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  866. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  867. mustbe ('O');
  868. mustbe ('K');
  869. uart-&gt;bfsize = (uint16_t)(hextoint (sizeof (uart-&gt;bfsize)));
  870. mustbe ('\r');
  871. printf (&quot;%d\n&quot;, uart-&gt;bfsize);
  872. return;
  873. }
  874. /*====================================================================*
  875. *
  876. * void atbsz2 (struct uart * uart);
  877. *
  878. * set transparent mode buffer size &quot;ATBSZn&quot;;
  879. *
  880. *--------------------------------------------------------------------*/
  881. static void atbsz2 (struct uart * uart)
  882. {
  883. extern struct command command;
  884. uint16_t result;
  885. clearcommand ();
  886. insert ('A');
  887. insert ('T');
  888. insert ('B');
  889. insert ('S');
  890. insert ('Z');
  891. uart-&gt;bfsize = HTOBE16 (uart-&gt;bfsize);
  892. decode (&amp;uart-&gt;bfsize, sizeof (uart-&gt;bfsize));
  893. uart-&gt;bfsize = BE16TOH (uart-&gt;bfsize);
  894. insert ('\r');
  895. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  896. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  897. mustbe ('O');
  898. mustbe ('K');
  899. result = (uint16_t)(hextoint (sizeof (result)));
  900. if (result != uart-&gt;bfsize)
  901. {
  902. error (1, EINVAL, &quot;[%s]: expected buffer size %04X&quot;, command.buffer, uart-&gt;bfsize);
  903. }
  904. mustbe ('\r');
  905. printf (&quot;%d\n&quot;, uart-&gt;bfsize);
  906. return;
  907. }
  908. /*====================================================================*
  909. *
  910. * void atto (struct uart * uart);
  911. *
  912. * set transparent mode buffer timeout &quot;ATTO&quot;;
  913. *
  914. *--------------------------------------------------------------------*/
  915. static void atto (struct uart * uart)
  916. {
  917. extern struct command command;
  918. uint16_t result;
  919. clearcommand ();
  920. insert ('A');
  921. insert ('T');
  922. insert ('T');
  923. insert ('O');
  924. uart-&gt;timeout = HTOBE16 (uart-&gt;timeout);
  925. decode (&amp;uart-&gt;timeout, sizeof (uart-&gt;timeout));
  926. uart-&gt;timeout = BE16TOH (uart-&gt;timeout);
  927. insert ('\r');
  928. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  929. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  930. mustbe ('O');
  931. mustbe ('K');
  932. result = (uint16_t)(hextoint (sizeof (result)));
  933. if (result != uart-&gt;timeout)
  934. {
  935. error (1, EINVAL, &quot;[%s]: expected timeout %04X&quot;, command.buffer, uart-&gt;timeout);
  936. }
  937. mustbe ('\r');
  938. return;
  939. }
  940. /*====================================================================*
  941. *
  942. * void atm (struct uart * uart);
  943. *
  944. *
  945. *--------------------------------------------------------------------*/
  946. static void atm (struct uart * uart)
  947. {
  948. extern struct command command;
  949. uint8_t buffer [ETHER_MAX_LEN + ETHER_MAX_LEN + 512];
  950. unsigned length = (unsigned)(readframe (uart-&gt;eth.file, buffer, sizeof (buffer)));
  951. if (length &lt; FRAME_MIN_CHAR)
  952. {
  953. error (1, ENOTSUP, &quot;Frame specification of %d bytes less than %d minimum&quot;, (length &gt;&gt; 1), (FRAME_MIN_CHAR &gt;&gt; 1));
  954. }
  955. if (length &gt; FRAME_MAX_CHAR)
  956. {
  957. error (1, ENOTSUP, &quot;Frame specification of %d bytes more than %d maximum&quot;, (length &gt;&gt; 1), (FRAME_MAX_CHAR &gt;&gt; 1));
  958. }
  959. clearcommand ();
  960. insert ('A');
  961. insert ('T');
  962. insert ('M');
  963. memcpy (command.buffer + command.length, buffer, length);
  964. command.length += (signed)(length);
  965. insert ('\r');
  966. sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
  967. readcommand (&amp;uart-&gt;port, uart-&gt;flags);
  968. write (STDOUT_FILENO, command.buffer, command.length);
  969. write (STDOUT_FILENO, &quot;\n&quot;, sizeof (char));
  970. return;
  971. }
  972. /*====================================================================*
  973. *
  974. * void manager (struct uart * uart);
  975. *
  976. * examine flagword in struct uart and perform requested operations
  977. * in the order that bits are tested; the order that bits are tested
  978. * may be changed as needed;
  979. *
  980. *--------------------------------------------------------------------*/
  981. static void manager (struct uart * uart)
  982. {
  983. if (_anyset (uart-&gt;flags, UART_WAKE))
  984. {
  985. at_wake (uart);
  986. }
  987. if (_anyset (uart-&gt;flags, UART_COMMAND))
  988. {
  989. at_command (uart);
  990. }
  991. if (_anyset (uart-&gt;flags, UART_RESPOND))
  992. {
  993. at_respond (uart);
  994. }
  995. if (_anyset (uart-&gt;flags, UART_ATRV))
  996. {
  997. atrv (uart);
  998. }
  999. if (_anyset (uart-&gt;flags, UART_ATRPM))
  1000. {
  1001. atrpm (uart);
  1002. }
  1003. if (_anyset (uart-&gt;flags, UART_ATDST1))
  1004. {
  1005. atdst1 (uart);
  1006. }
  1007. if (_anyset (uart-&gt;flags, UART_ATDST2))
  1008. {
  1009. atdst2 (uart);
  1010. }
  1011. if (_anyset (uart-&gt;flags, UART_ATZ))
  1012. {
  1013. atz (uart);
  1014. }
  1015. if (_anyset (uart-&gt;flags, UART_ATFD))
  1016. {
  1017. atfd (uart);
  1018. }
  1019. if (_anyset (uart-&gt;flags, UART_ATPS))
  1020. {
  1021. atps (uart);
  1022. }
  1023. if (_anyset (uart-&gt;flags, UART_ATO))
  1024. {
  1025. ato (uart);
  1026. }
  1027. if (_anyset (uart-&gt;flags, UART_ATNI))
  1028. {
  1029. atni (uart);
  1030. }
  1031. if (_anyset (uart-&gt;flags, UART_ATHSC))
  1032. {
  1033. athsc (uart);
  1034. }
  1035. if (_anyset (uart-&gt;flags, UART_ATSK1))
  1036. {
  1037. atsk1 (uart);
  1038. }
  1039. if (_anyset (uart-&gt;flags, UART_ATSK2))
  1040. {
  1041. atsk2 (uart);
  1042. }
  1043. if (_anyset (uart-&gt;flags, UART_ATRP))
  1044. {
  1045. at_readpib (uart);
  1046. }
  1047. if (_anyset (uart-&gt;flags, UART_ATWPF1))
  1048. {
  1049. at_writenvm (uart);
  1050. }
  1051. if (_anyset (uart-&gt;flags, UART_ATWPF2))
  1052. {
  1053. at_writepib (uart);
  1054. }
  1055. if (_anyset (uart-&gt;flags, UART_ATWNV))
  1056. {
  1057. atwnv (uart);
  1058. }
  1059. if (_anyset (uart-&gt;flags, UART_ATBSZ1))
  1060. {
  1061. atbsz1 (uart);
  1062. }
  1063. if (_anyset (uart-&gt;flags, UART_ATBSZ2))
  1064. {
  1065. atbsz2 (uart);
  1066. }
  1067. if (_anyset (uart-&gt;flags, UART_ATM))
  1068. {
  1069. atm (uart);
  1070. }
  1071. if (_anyset (uart-&gt;flags, UART_ATTO))
  1072. {
  1073. atto (uart);
  1074. }
  1075. return;
  1076. }
  1077. /*====================================================================*
  1078. *
  1079. * int main (int argc, char const * argv []);
  1080. *
  1081. *
  1082. *
  1083. *
  1084. *--------------------------------------------------------------------*/
  1085. int main (int argc, char const * argv [])
  1086. {
  1087. static char const * optv [] =
  1088. {
  1089. &quot;bc:C:dD:F:HiImM:n:N:Op:P:qrRS:s:tTvwW:zZ:&quot;,
  1090. &quot;&quot;,
  1091. &quot;Atheros Serial Line Device Manager&quot;,
  1092. &quot;b\tset default host baud rate&quot;,
  1093. &quot;c s\tsend custom serial line command (s)&quot;,
  1094. &quot;C x\tcommit module (x) to NVM [ATWNVx]&quot;,
  1095. &quot;d\tget destination mac address [ATDST?]&quot;,
  1096. &quot;D x\tset destination mac address [ATDSTx]&quot;,
  1097. &quot;F f\tframe file is (s)&quot;,
  1098. &quot;H\tplace device in High Speed Command Mode [ATHSC]&quot;,
  1099. &quot;i\tget network information [ATNI]&quot;,
  1100. &quot;I\tget PIB version and MAC address [ATRPM]&quot;,
  1101. &quot;m\tget network membership key [ATSK?]&quot;,
  1102. &quot;M x\tset network membership key [ATSKx]&quot;,
  1103. &quot;N f\twrite NVM file (f) to SDRAM [ATWFP1]&quot;,
  1104. &quot;O\tplace device in Transparent Mode [ATO]&quot;,
  1105. &quot;p f\tread PIB from SDRAM to file (f) [ATRP]&quot;,
  1106. &quot;P f\twrite PIB file (f) to SDRAM [ATWFP2]&quot;,
  1107. &quot;q\tplace program in quiet mode&quot;,
  1108. &quot;r\tget parameter/firmware revision [ATRV]&quot;,
  1109. &quot;R\treset device [ATZ]&quot;,
  1110. &quot;s f\tserial port is (f) [&quot; DEVICE &quot;]&quot;,
  1111. &quot;S n\tenter power save mode for (n) seconds [ATPS]&quot;,
  1112. &quot;t\ttest device [AT]&quot;,
  1113. &quot;T\treset to factory defaults [ATFD]&quot;,
  1114. &quot;v\tplace program verbose mode&quot;,
  1115. &quot;w\tplace device in Command Mode [+++]&quot;,
  1116. &quot;W x\tset Transparent Mode aggregation timeout [ATTO]&quot;,
  1117. &quot;z\tget Transparent Mode buffer size [ATBSZ?]&quot;,
  1118. &quot;Z n\tset Transparent Mode buffer size [ATBSZn]&quot;,
  1119. (char const *) (0)
  1120. };
  1121. struct uart uart =
  1122. {
  1123. {
  1124. 0,
  1125. DEVICE
  1126. },
  1127. {
  1128. -1,
  1129. &quot;nvmfile&quot;
  1130. },
  1131. {
  1132. -1,
  1133. &quot;pibfile&quot;
  1134. },
  1135. {
  1136. -1,
  1137. &quot;ethfile&quot;
  1138. },
  1139. (char *)(0),
  1140. {
  1141. 0
  1142. },
  1143. {
  1144. 0
  1145. },
  1146. {
  1147. 0
  1148. },
  1149. {
  1150. 0
  1151. },
  1152. (uint8_t)(0),
  1153. (uint8_t)(0),
  1154. (uint16_t)(0),
  1155. (uint16_t)(0),
  1156. (uint16_t)(0),
  1157. (unsigned)(0)
  1158. };
  1159. signed c;
  1160. if (getenv (UART_PORT))
  1161. {
  1162. uart.port.name = strdup (getenv (UART_PORT));
  1163. }
  1164. while ((c = getoptv (argc, argv, optv)) != -1)
  1165. {
  1166. switch (c)
  1167. {
  1168. case 'b':
  1169. _setbits (uart.flags, UART_DEFAULT);
  1170. break;
  1171. case 'c':
  1172. _setbits (uart.flags, UART_COMMAND);
  1173. uart.string = optarg;
  1174. break;
  1175. case 'C':
  1176. _setbits (uart.flags, UART_ATWNV);
  1177. uart.module = (byte)(basespec (optarg, 16, sizeof (uart.module)));
  1178. break;
  1179. case 'd':
  1180. _setbits (uart.flags, UART_ATDST1);
  1181. break;
  1182. case 'D':
  1183. _setbits (uart.flags, UART_ATDST2);
  1184. if (!hexencode (uart.MACAddress, sizeof (uart.MACAddress), optarg))
  1185. {
  1186. error (1, errno, PLC_BAD_MAC, optarg);
  1187. }
  1188. break;
  1189. case 'F':
  1190. if ((uart.eth.file = open (uart.eth.name = optarg, O_BINARY | O_RDONLY)) == -1)
  1191. {
  1192. error (1, errno, &quot;%s&quot;, uart.eth.name);
  1193. }
  1194. _setbits (uart.flags, UART_ATM);
  1195. break;
  1196. case 'H':
  1197. _setbits (uart.flags, UART_ATHSC);
  1198. break;
  1199. case 'i':
  1200. _setbits (uart.flags, UART_ATNI);
  1201. break;
  1202. case 'I':
  1203. _setbits (uart.flags, UART_ATRPM);
  1204. break;
  1205. case 'm':
  1206. _setbits (uart.flags, UART_ATSK1);
  1207. break;
  1208. case 'M':
  1209. _setbits (uart.flags, UART_ATSK2);
  1210. if (!hexencode (uart.NMKDigest, sizeof (uart.NMKDigest), optarg))
  1211. {
  1212. error (1, errno, PLC_BAD_NMK, optarg);
  1213. }
  1214. break;
  1215. case 'N':
  1216. if ((uart.nvm.file = open (uart.nvm.name = optarg, O_BINARY | O_RDONLY)) == -1)
  1217. {
  1218. error (1, errno, &quot;%s&quot;, uart.nvm.name);
  1219. }
  1220. _setbits (uart.flags, UART_ATWPF1);
  1221. break;
  1222. case 'O':
  1223. _setbits (uart.flags, UART_ATO);
  1224. break;
  1225. case 'P':
  1226. if ((uart.pib.file = open (uart.pib.name = optarg, O_BINARY | O_RDONLY)) == -1)
  1227. {
  1228. error (1, errno, &quot;%s&quot;, uart.pib.name);
  1229. }
  1230. _setbits (uart.flags, UART_ATWPF2);
  1231. break;
  1232. case 'p':
  1233. if ((uart.pib.file = open (uart.pib.name = optarg, O_BINARY|O_CREAT|O_RDWR|O_TRUNC, FILE_FILEMODE)) == -1)
  1234. {
  1235. error (1, errno, &quot;%s&quot;, uart.pib.name);
  1236. }
  1237. #ifndef WIN32
  1238. chown (optarg, getuid (), getgid ());
  1239. #endif
  1240. _setbits (uart.flags, UART_ATRP);
  1241. break;
  1242. case 'q':
  1243. _setbits (uart.flags, UART_SILENCE);
  1244. break;
  1245. case 'r':
  1246. _setbits (uart.flags, UART_ATRV);
  1247. break;
  1248. case 'R':
  1249. _setbits (uart.flags, UART_ATZ);
  1250. break;
  1251. case 'S':
  1252. _setbits (uart.flags, UART_ATPS);
  1253. uart.snooze = (uint16_t)(uintspec (optarg, 1, 900));
  1254. break;
  1255. case 's':
  1256. uart.port.name = optarg;
  1257. break;
  1258. case 'T':
  1259. _setbits (uart.flags, UART_ATFD);
  1260. break;
  1261. case 't':
  1262. _setbits (uart.flags, UART_RESPOND);
  1263. break;
  1264. case 'v':
  1265. _setbits (uart.flags, UART_VERBOSE);
  1266. break;
  1267. case 'w':
  1268. _setbits (uart.flags, UART_WAKE);
  1269. break;
  1270. case 'W':
  1271. _setbits (uart.flags, UART_ATTO);
  1272. uart.timeout = (unsigned)(uintspec (optarg, 1, 2000));
  1273. break;
  1274. case 'z':
  1275. _setbits (uart.flags, UART_ATBSZ1);
  1276. break;
  1277. case 'Z':
  1278. _setbits (uart.flags, UART_ATBSZ2);
  1279. uart.bfsize = (uint16_t)(uintspec (optarg, 1, 1500));
  1280. break;
  1281. default:
  1282. break;
  1283. }
  1284. }
  1285. argc -= optind;
  1286. argv += optind;
  1287. if (argc)
  1288. {
  1289. error (1, ENOTSUP, ERROR_TOOMANY);
  1290. }
  1291. openport (&amp;uart.port, uart.flags);
  1292. manager (&amp;uart);
  1293. closeport (&amp;uart.port);
  1294. exit (0);
  1295. }
  1296. </pre>
  1297. <div class='footerlink'>
  1298. [<a href='int6ktone.c.html' title=' int6ktone.c '>PREV</a>]
  1299. [<a href='toolkit.html' title=' Index '>HOME</a>]
  1300. [<a href='int6kwait.c.html' title=' int6kwait.c '>NEXT</a>]
  1301. </div>
  1302. </body>
  1303. </html>