Attributes1.c.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. Attributes1.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='assist.c.html' title=' assist.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='Attributes2.c.html' title=' Attributes2.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. * signed Attributes1 (struct plc * plc);
  64. *
  65. * plc.h
  66. *
  67. * This plugin for program plc requests device attributes using
  68. * a VS_OP_ATTRIBUTES message; attributes are pre-parsed versions
  69. * of information returned by VS_SW_VER and other messages;
  70. *
  71. * The VS_OP_ATTRIBUTES message structure changed between FW 3.3.4
  72. * and 3.3.5 and fields are ocassionally appended to the end; you
  73. * should not use this message for operational systems because the
  74. * format may change again; it was originally intended for PTS use
  75. * only;
  76. *
  77. *
  78. * Contributor(s):
  79. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  80. *
  81. *--------------------------------------------------------------------*/
  82. #ifndef ATTRIBUTES1_SOURCE
  83. #define ATTRIBUTES1_SOURCE
  84. #include &lt;stdint.h&gt;
  85. #include &lt;memory.h&gt;
  86. #include &quot;../plc/plc.h&quot;
  87. #include &quot;../tools/memory.h&quot;
  88. #include &quot;../tools/format.h&quot;
  89. #include &quot;../tools/error.h&quot;
  90. #include &quot;../tools/flags.h&quot;
  91. #ifdef WIN32
  92. #define snprintf _snprintf
  93. #endif
  94. signed Attributes1 (struct plc * plc)
  95. {
  96. struct channel * channel = (struct channel *)(plc-&gt;channel);
  97. struct message * message = (struct message *)(plc-&gt;message);
  98. #ifndef __GNUC__
  99. #pragma pack (push,1)
  100. #endif
  101. struct __packed vs_op_attributes_request
  102. {
  103. struct ethernet_hdr ethernet;
  104. struct qualcomm_hdr qualcomm;
  105. uint32_t COOKIE;
  106. uint8_t RTYPE;
  107. }
  108. * request = (struct vs_op_attributes_request *) (message);
  109. struct __packed vs_op_attributes_confirm
  110. {
  111. struct ethernet_hdr ethernet;
  112. struct qualcomm_hdr qualcomm;
  113. uint16_t MSTATUS;
  114. uint32_t COOKIE;
  115. uint8_t RTYPE;
  116. uint16_t MLENGTH;
  117. uint8_t MBUFFER [1024];
  118. }
  119. * confirm = (struct vs_op_attributes_confirm *) (message);
  120. struct __packed attributes
  121. {
  122. uint8_t HARDWARE [16];
  123. uint8_t SOFTWARE [16];
  124. uint32_t FWVERSION [5];
  125. uint8_t RELEASEDATE [8];
  126. uint8_t RELEASETYPE [12];
  127. uint8_t SDRAMTYPE;
  128. uint8_t RESERVED;
  129. uint8_t LINEFREQ;
  130. uint32_t SDRAMSIZE;
  131. uint8_t AUTHMODE;
  132. }
  133. * attributes = (struct attributes *)(confirm-&gt;MBUFFER);
  134. #ifndef __GNUC__
  135. #pragma pack (pop)
  136. #endif
  137. Request (plc, &quot;Fetch Device Attributes&quot;);
  138. memset (message, 0, sizeof (* message));
  139. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  140. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_OP_ATTRIBUTES | MMTYPE_REQ));
  141. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  142. request-&gt;COOKIE = HTOLE32 (plc-&gt;cookie);
  143. request-&gt;RTYPE = 0;
  144. if (SendMME (plc) &lt;= 0)
  145. {
  146. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  147. return (-1);
  148. }
  149. while (ReadMME (plc, 0, (VS_OP_ATTRIBUTES | MMTYPE_CNF)) &gt; 0)
  150. {
  151. static char const * frequency [] =
  152. {
  153. &quot;Unknown frequency&quot;,
  154. &quot;50Hz&quot;,
  155. &quot;60Hz&quot;,
  156. };
  157. static char const * zero_cross [] =
  158. {
  159. &quot;Not yet detected&quot;,
  160. &quot;Detected&quot;,
  161. &quot;Missing&quot;,
  162. };
  163. char string [512];
  164. size_t length = 0;
  165. if (confirm-&gt;MSTATUS)
  166. {
  167. Failure (plc, PLC_WONTDOIT);
  168. continue;
  169. }
  170. #if 0
  171. #if defined (__GNUC__)
  172. #warning &quot;Debug code active in module Attributes1&quot;
  173. #endif
  174. fprintf (stderr, &quot;HARDWARE=[%-16.16s]\n&quot;, attributes-&gt;HARDWARE);
  175. fprintf (stderr, &quot;SOFTWARE=[%-16.16s]\n&quot;, attributes-&gt;SOFTWARE);
  176. fprintf (stderr, &quot;FIRMWARE MAJOR VERSION=(%d)\n&quot;, LE32TOH (attributes-&gt;FWVERSION [0]));
  177. fprintf (stderr, &quot;FIRMWARE MINOR VERSION=(%d)\n&quot;, LE32TOH (attributes-&gt;FWVERSION [1]));
  178. fprintf (stderr, &quot;FIRMWARE [2]=(%d)\n&quot;, LE32TOH (attributes-&gt;FWVERSION [2]));
  179. fprintf (stderr, &quot;FIRMWARE [3]=(%d)\n&quot;, LE32TOH (attributes-&gt;FWVERSION [3]));
  180. fprintf (stderr, &quot;FIRMWARE [4]=(%d)\n&quot;, LE32TOH (attributes-&gt;FWVERSION [4]));
  181. fprintf (stderr, &quot;RELEASE DATE=[%-8.8s]\n&quot;, attributes-&gt;RELEASEDATE);
  182. fprintf (stderr, &quot;RELEASE TYPE=[%-12.12s]\n&quot;, attributes-&gt;RELEASETYPE);
  183. fprintf (stderr, &quot;SDRAM SIZE=[0x%08X]\n&quot;, LE32TOH (attributes-&gt;SDRAMSIZE));
  184. fprintf (stderr, &quot;SDRAM TYPE=[0x%02X]\n&quot;, attributes-&gt;SDRAMTYPE);
  185. fprintf (stderr, &quot;RESERVED=[0x%02X]\n&quot;, attributes-&gt;RESERVED);
  186. fprintf (stderr, &quot;LINE FREQUENCY=[0x%02X]\n&quot;, attributes-&gt;LINEFREQ);
  187. fprintf (stderr, &quot;AUTHORIZATION MODE=[0x%02X]\n&quot;, attributes-&gt;AUTHMODE);
  188. #endif
  189. length += snprintf (string + length, sizeof (string) - length, &quot;%s&quot;, attributes-&gt;HARDWARE);
  190. length += snprintf (string + length, sizeof (string) - length, &quot;-%s&quot;, attributes-&gt;SOFTWARE);
  191. length += snprintf (string + length, sizeof (string) - length, &quot;-%d&quot;, LE32TOH (attributes-&gt;FWVERSION [0]));
  192. length += snprintf (string + length, sizeof (string) - length, &quot;-%d&quot;, LE32TOH (attributes-&gt;FWVERSION [1]));
  193. length += snprintf (string + length, sizeof (string) - length, &quot;-%04d&quot;, LE32TOH (attributes-&gt;FWVERSION [2]));
  194. length += snprintf (string + length, sizeof (string) - length, &quot;-%02d&quot;, LE32TOH (attributes-&gt;FWVERSION [3]));
  195. length += snprintf (string + length, sizeof (string) - length, &quot;-%04d&quot;, LE32TOH (attributes-&gt;FWVERSION [4]));
  196. length += snprintf (string + length, sizeof (string) - length, &quot;-%-8.8s&quot;, attributes-&gt;RELEASEDATE);
  197. length += snprintf (string + length, sizeof (string) - length, &quot;-%s&quot;, attributes-&gt;RELEASETYPE);
  198. length += snprintf (string + length, sizeof (string) - length, &quot;-%c&quot;, attributes-&gt;SDRAMTYPE);
  199. length += snprintf (string + length, sizeof (string) - length, &quot; (%dmb)&quot;, LE32TOH (attributes-&gt;SDRAMSIZE));
  200. length += snprintf (string + length, sizeof (string) - length, &quot; (0x%02X) \&quot;%s\&quot; \&quot;%s\&quot; &quot;, attributes-&gt;LINEFREQ, frequency [attributes-&gt;LINEFREQ &amp; 0x03], zero_cross [(attributes-&gt;LINEFREQ &amp; 0x0C) &gt;&gt; 2]);
  201. length += snprintf (string + length, sizeof (string) - length, &quot; 0x%02X&quot;, attributes-&gt;AUTHMODE);
  202. Display (plc, &quot;%s&quot;, string);
  203. }
  204. return (0);
  205. }
  206. #endif
  207. </pre>
  208. <div class='footerlink'>
  209. [<a href='assist.c.html' title=' assist.c '>PREV</a>]
  210. [<a href='toolkit.html' title=' Index '>HOME</a>]
  211. [<a href='Attributes2.c.html' title=' Attributes2.c '>NEXT</a>]
  212. </div>
  213. </body>
  214. </html>