Identity2.c.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. Identity2.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='Identity1.c.html' title=' Identity1.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='Identity.c.html' title=' Identity.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. #ifndef IDENTITY2_SOURCE
  62. #define IDENTITY2_SOURCE
  63. #include &lt;stdint.h&gt;
  64. #include &lt;unistd.h&gt;
  65. #include &lt;memory.h&gt;
  66. #include &quot;../tools/error.h&quot;
  67. #include &quot;../tools/files.h&quot;
  68. #include &quot;../tools/endian.h&quot;
  69. #include &quot;../tools/memory.h&quot;
  70. #include &quot;../tools/flags.h&quot;
  71. #include &quot;../nvm/nvm.h&quot;
  72. #include &quot;../plc/plc.h&quot;
  73. /*====================================================================*
  74. *
  75. * signed pibchain2 (void const * memory);
  76. *
  77. * search panther/lynx image chain for the next PIB image; print
  78. * information on stdout and return;
  79. *
  80. *
  81. * Contributor(s):
  82. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  83. *
  84. *--------------------------------------------------------------------*/
  85. static signed pibchain2 (void const * memory, char const * filename, flag_t flags)
  86. {
  87. struct nvm_header2 * nvm_header;
  88. uint32_t origin = ~0;
  89. uint32_t offset = 0;
  90. signed module = 0;
  91. do
  92. {
  93. nvm_header = (struct nvm_header2 *)((char *)(memory) + offset);
  94. if (LE16TOH (nvm_header-&gt;MajorVersion) != 1)
  95. {
  96. if (_allclr (flags, NVM_SILENCE))
  97. {
  98. error (0, errno, NVM_HDR_VERSION, filename, module);
  99. }
  100. return (-1);
  101. }
  102. if (LE16TOH (nvm_header-&gt;MinorVersion) != 1)
  103. {
  104. if (_allclr (flags, NVM_SILENCE))
  105. {
  106. error (0, errno, NVM_HDR_VERSION, filename, module);
  107. }
  108. return (-1);
  109. }
  110. if (LE32TOH (nvm_header-&gt;PrevHeader) != origin)
  111. {
  112. if (_allclr (flags, NVM_SILENCE))
  113. {
  114. error (0, errno, NVM_HDR_LINK, filename, module);
  115. }
  116. return (-1);
  117. }
  118. if (checksum32 (nvm_header, sizeof (* nvm_header), 0))
  119. {
  120. error (0, 0, NVM_HDR_CHECKSUM, filename, module);
  121. return (-1);
  122. }
  123. origin = offset;
  124. offset += sizeof (* nvm_header);
  125. if (LE32TOH (nvm_header-&gt;ImageType) == NVM_IMAGE_PIB)
  126. {
  127. struct pib_header * pib_header = (struct pib_header *)((char *)(memory) + offset);
  128. pib_header-&gt;PIBLENGTH = HTOLE16((uint16_t)(LE32TOH(nvm_header-&gt;ImageLength)));
  129. pibpeek2 ((char *)(memory) + offset);
  130. pib_header-&gt;PIBLENGTH = 0;
  131. break;
  132. }
  133. if (checksum32 ((char *)(memory) + offset, LE32TOH (nvm_header-&gt;ImageLength), nvm_header-&gt;ImageChecksum))
  134. {
  135. if (_allclr (flags, NVM_SILENCE))
  136. {
  137. error (0, errno, NVM_IMG_CHECKSUM, filename, module);
  138. }
  139. return (-1);
  140. }
  141. offset += LE32TOH (nvm_header-&gt;ImageLength);
  142. module++;
  143. }
  144. while (~nvm_header-&gt;NextHeader);
  145. return (0);
  146. }
  147. /*====================================================================*
  148. *
  149. * signed Identity2 (struct plc * plc);
  150. *
  151. * plc.h
  152. *
  153. * read start of parameter chain from flash memory using single
  154. * VS_MODULE_OPERATION message and print identity information on
  155. * stdout;
  156. *
  157. *
  158. * Contributor(s):
  159. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  160. *
  161. *--------------------------------------------------------------------*/
  162. signed Identity2 (struct plc * plc)
  163. {
  164. struct channel * channel = (struct channel *)(plc-&gt;channel);
  165. struct message * message = (struct message *)(plc-&gt;message);
  166. #ifndef __GNUC__
  167. #pragma pack (push,1)
  168. #endif
  169. struct __packed vs_module_operation_read_request
  170. {
  171. struct ethernet_hdr ethernet;
  172. struct qualcomm_hdr qualcomm;
  173. uint32_t RESERVED;
  174. uint8_t NUM_OP_DATA;
  175. struct __packed
  176. {
  177. uint16_t MOD_OP;
  178. uint16_t MOD_OP_DATA_LEN;
  179. uint32_t MOD_OP_RSVD;
  180. uint16_t MODULE_ID;
  181. uint16_t MODULE_SUB_ID;
  182. uint16_t MODULE_LENGTH;
  183. uint32_t MODULE_OFFSET;
  184. }
  185. MODULE_SPEC;
  186. }
  187. * request = (struct vs_module_operation_read_request *)(message);
  188. struct __packed vs_module_operation_read_confirm
  189. {
  190. struct ethernet_hdr ethernet;
  191. struct qualcomm_hdr qualcomm;
  192. uint16_t MSTATUS;
  193. uint16_t ERR_REC_CODE;
  194. uint32_t RESERVED;
  195. uint8_t NUM_OP_DATA;
  196. struct __packed
  197. {
  198. uint16_t MOD_OP;
  199. uint16_t MOD_OP_DATA_LEN;
  200. uint32_t MOD_OP_RSVD;
  201. uint16_t MODULE_ID;
  202. uint16_t MODULE_SUB_ID;
  203. uint16_t MODULE_LENGTH;
  204. uint32_t MODULE_OFFSET;
  205. }
  206. MODULE_SPEC;
  207. uint8_t MODULE_DATA [PLC_MODULE_SIZE];
  208. }
  209. * confirm = (struct vs_module_operation_read_confirm *)(message);
  210. #ifndef __GNUC__
  211. #pragma pack (pop)
  212. #endif
  213. memset (message, 0, sizeof (* message));
  214. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  215. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_MODULE_OPERATION | MMTYPE_REQ));
  216. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  217. request-&gt;NUM_OP_DATA = 1;
  218. request-&gt;MODULE_SPEC.MOD_OP = HTOLE16 (0);
  219. request-&gt;MODULE_SPEC.MOD_OP_DATA_LEN = HTOLE16 (sizeof (request-&gt;MODULE_SPEC));
  220. request-&gt;MODULE_SPEC.MOD_OP_RSVD = HTOLE32 (0);
  221. request-&gt;MODULE_SPEC.MODULE_ID = HTOLE16 (PLC_MODULEID_PARAMETERS);
  222. request-&gt;MODULE_SPEC.MODULE_SUB_ID = HTOLE16 (0);
  223. request-&gt;MODULE_SPEC.MODULE_LENGTH = HTOLE16 (PLC_MODULE_SIZE);
  224. request-&gt;MODULE_SPEC.MODULE_OFFSET = HTOLE32 (0);
  225. if (SendMME (plc) &lt;= 0)
  226. {
  227. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  228. return (-1);
  229. }
  230. if (ReadMME (plc, 0, (VS_MODULE_OPERATION | MMTYPE_CNF)) &lt;= 0)
  231. {
  232. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  233. return (-1);
  234. }
  235. if (confirm-&gt;MSTATUS)
  236. {
  237. Failure (plc, PLC_WONTDOIT);
  238. return (-1);
  239. }
  240. pibchain2 (confirm-&gt;MODULE_DATA, &quot;device&quot;, plc-&gt;flags);
  241. return (0);
  242. }
  243. #endif
  244. </pre>
  245. <div class='footerlink'>
  246. [<a href='Identity1.c.html' title=' Identity1.c '>PREV</a>]
  247. [<a href='toolkit.html' title=' Index '>HOME</a>]
  248. [<a href='Identity.c.html' title=' Identity.c '>NEXT</a>]
  249. </div>
  250. </body>
  251. </html>