ModuleRead.c.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. ModuleRead.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='ModuleDump.c.html' title=' ModuleDump.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='ModuleSession.c.html' title=' ModuleSession.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 ModuleRead (struct plc * plc, struct _file_ * file, uint16_t source, uint16_t module, uint16_t submodule);
  64. *
  65. * plc.h
  66. *
  67. * Read a module from volatile or non-volatile memory and write it
  68. * to file;
  69. *
  70. *
  71. * Contributor(s):
  72. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  73. *
  74. *--------------------------------------------------------------------*/
  75. #ifndef MODULEREAD_SOURCE
  76. #define MODULEREAD_SOURCE
  77. #include &lt;stdint.h&gt;
  78. #include &lt;unistd.h&gt;
  79. #include &lt;memory.h&gt;
  80. #include &quot;../tools/error.h&quot;
  81. #include &quot;../tools/files.h&quot;
  82. #include &quot;../tools/endian.h&quot;
  83. #include &quot;../tools/memory.h&quot;
  84. #include &quot;../plc/plc.h&quot;
  85. signed ModuleRead (struct plc * plc, struct _file_ * file, uint16_t source, uint16_t module, uint16_t submodule)
  86. {
  87. struct channel * channel = (struct channel *)(plc-&gt;channel);
  88. struct message * message = (struct message *)(plc-&gt;message);
  89. #ifndef __GNUC__
  90. #pragma pack (push,1)
  91. #endif
  92. struct __packed vs_module_operation_read_request
  93. {
  94. struct ethernet_hdr ethernet;
  95. struct qualcomm_hdr qualcomm;
  96. uint32_t RESERVED;
  97. uint8_t NUM_OP_DATA;
  98. struct __packed
  99. {
  100. uint16_t MOD_OP;
  101. uint16_t MOD_OP_DATA_LEN;
  102. uint32_t MOD_OP_RSVD;
  103. uint16_t MODULE_ID;
  104. uint16_t MODULE_SUB_ID;
  105. uint16_t MODULE_LENGTH;
  106. uint32_t MODULE_OFFSET;
  107. }
  108. MODULE_SPEC;
  109. }
  110. * request = (struct vs_module_operation_read_request *)(message);
  111. struct __packed vs_module_operation_read_confirm
  112. {
  113. struct ethernet_hdr ethernet;
  114. struct qualcomm_hdr qualcomm;
  115. uint16_t MSTATUS;
  116. uint16_t ERR_REC_CODE;
  117. uint32_t RESERVED;
  118. uint8_t NUM_OP_DATA;
  119. struct __packed
  120. {
  121. uint16_t MOD_OP;
  122. uint16_t MOD_OP_DATA_LEN;
  123. uint32_t MOD_OP_RSVD;
  124. uint16_t MODULE_ID;
  125. uint16_t MODULE_SUB_ID;
  126. uint16_t MODULE_LENGTH;
  127. uint32_t MODULE_OFFSET;
  128. }
  129. MODULE_SPEC;
  130. uint8_t MODULE_DATA [PLC_MODULE_SIZE];
  131. }
  132. * confirm = (struct vs_module_operation_read_confirm *)(message);
  133. #ifndef __GNUC__
  134. #pragma pack (pop)
  135. #endif
  136. unsigned timer = channel-&gt;timeout;
  137. uint16_t length = PLC_MODULE_SIZE;
  138. uint32_t offset = 0;
  139. Request (plc, &quot;Read Module from %s&quot;, source? &quot;Flash&quot;: &quot;Memory&quot;);
  140. if (lseek (file-&gt;file, 0, SEEK_SET) == -1)
  141. {
  142. error (PLC_EXIT (plc), errno, FILE_CANTHOME, file-&gt;name);
  143. return (-1);
  144. }
  145. while (length == PLC_MODULE_SIZE)
  146. {
  147. memset (message, 0, sizeof (* message));
  148. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  149. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_MODULE_OPERATION | MMTYPE_REQ));
  150. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  151. request-&gt;NUM_OP_DATA = 1;
  152. request-&gt;MODULE_SPEC.MOD_OP = HTOLE16 (source);
  153. request-&gt;MODULE_SPEC.MOD_OP_DATA_LEN = HTOLE16 (sizeof (request-&gt;MODULE_SPEC));
  154. request-&gt;MODULE_SPEC.MOD_OP_RSVD = HTOLE32 (0);
  155. request-&gt;MODULE_SPEC.MODULE_ID = HTOLE16 (module);
  156. request-&gt;MODULE_SPEC.MODULE_SUB_ID = HTOLE16 (submodule);
  157. request-&gt;MODULE_SPEC.MODULE_LENGTH = HTOLE16 (length);
  158. request-&gt;MODULE_SPEC.MODULE_OFFSET = HTOLE32 (offset);
  159. #if 0
  160. #if defined (__GNUC__)
  161. #warning &quot;Debug code active in module ModuleRead&quot;
  162. #endif
  163. fprintf (stderr, &quot;----- \n&quot;);
  164. fprintf (stderr, &quot;RESERVED 0x%08X\n&quot;, LE32TOH (request-&gt;RESERVED));
  165. fprintf (stderr, &quot;NUM_OP_DATA %d\n&quot;, request-&gt;NUM_OP_DATA);
  166. fprintf (stderr, &quot;MOD_OP 0x%02X\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MOD_OP));
  167. fprintf (stderr, &quot;MOD_OP_DATA_LEN %d\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MOD_OP_DATA_LEN));
  168. fprintf (stderr, &quot;RESERVED 0x%08X\n&quot;, LE32TOH (request-&gt;MODULE_SPEC.MOD_OP_RSVD));
  169. fprintf (stderr, &quot;MODULE_ID 0x%04X\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MODULE_ID));
  170. fprintf (stderr, &quot;MODULE_SUB_ID 0x%04X\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MODULE_SUB_ID));
  171. fprintf (stderr, &quot;MODULE_LENGTH %d\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MODULE_LENGTH));
  172. fprintf (stderr, &quot;MODULE_OFFSET 0x%08X\n&quot;, LE32TOH (request-&gt;MODULE_SPEC.MODULE_OFFSET));
  173. fprintf (stderr, &quot;\n&quot;);
  174. #endif
  175. if (SendMME (plc) &lt;= 0)
  176. {
  177. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  178. return (-1);
  179. }
  180. channel-&gt;timeout = PLC_MODULE_READ_TIMEOUT;
  181. if (ReadMME (plc, 0, (VS_MODULE_OPERATION | MMTYPE_CNF)) &lt;= 0)
  182. {
  183. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  184. return (-1);
  185. }
  186. channel-&gt;timeout = timer;
  187. #if 0
  188. #if defined (__GNUC__)
  189. #warning &quot;Debug code active in module ModuleRead&quot;
  190. #endif
  191. fprintf (stderr, &quot;MSTATUS 0x%04X\n&quot;, LE16TOH (confirm-&gt;MSTATUS));
  192. fprintf (stderr, &quot;ERROR_REC_CODE %d\n&quot;, LE16TOH (confirm-&gt;ERR_REC_CODE));
  193. fprintf (stderr, &quot;RESERVED 0x%08X\n&quot;, LE32TOH (confirm-&gt;RESERVED));
  194. fprintf (stderr, &quot;NUM_OP_DATA %d\n&quot;, confirm-&gt;NUM_OP_DATA);
  195. fprintf (stderr, &quot;MOD_OP 0x%02X\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MOD_OP));
  196. fprintf (stderr, &quot;MOD_OP_DATA_LEN %d\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MOD_OP_DATA_LEN));
  197. fprintf (stderr, &quot;RESERVED 0x%08X\n&quot;, LE32TOH (confirm-&gt;MODULE_SPEC.MOD_OP_RSVD));
  198. fprintf (stderr, &quot;MODULE_ID 0x%04X\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MODULE_ID));
  199. fprintf (stderr, &quot;MODULE_SUB_ID 0x%04X\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MODULE_SUB_ID));
  200. fprintf (stderr, &quot;MODULE_LENGTH %d\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MODULE_LENGTH));
  201. fprintf (stderr, &quot;MODULE_OFFSET 0x%08X\n&quot;, LE32TOH (confirm-&gt;MODULE_SPEC.MODULE_OFFSET));
  202. fprintf (stderr, &quot;\n&quot;);
  203. #endif
  204. if (LE16TOH (confirm-&gt;MSTATUS))
  205. {
  206. Failure (plc, PLC_WONTDOIT);
  207. return (-1);
  208. }
  209. length = LE16TOH (confirm-&gt;MODULE_SPEC.MODULE_LENGTH);
  210. offset = LE32TOH (confirm-&gt;MODULE_SPEC.MODULE_OFFSET);
  211. if (write (file-&gt;file, confirm-&gt;MODULE_DATA, length) != (signed)(length))
  212. {
  213. error (PLC_EXIT (plc), errno, FILE_CANTSAVE, file-&gt;name);
  214. return (-1);
  215. }
  216. offset += length;
  217. }
  218. return (0);
  219. }
  220. #endif
  221. </pre>
  222. <div class='footerlink'>
  223. [<a href='ModuleDump.c.html' title=' ModuleDump.c '>PREV</a>]
  224. [<a href='toolkit.html' title=' Index '>HOME</a>]
  225. [<a href='ModuleSession.c.html' title=' ModuleSession.c '>NEXT</a>]
  226. </div>
  227. </body>
  228. </html>