ModuleSession.c.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. ModuleSession.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='ModuleRead.c.html' title=' ModuleRead.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='ModuleSpec.c.html' title=' ModuleSpec.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 ModuleSession (struct plc * plc, unsigned modules, struct vs_module_spec * vs_module_spec);
  64. *
  65. * Establish a module download session; the session expires after
  66. * 30 minutes; the session is lost if no modules are committed in
  67. * that time; the timeout is set to 10 seconds so that the device
  68. * has enouth time to reply;
  69. *
  70. * array vs_module_spec contains information about each module in
  71. * this session;
  72. *
  73. *
  74. *--------------------------------------------------------------------*/
  75. #ifndef MODULESESSION_SOURCE
  76. #define MODULESESSION_SOURCE
  77. #include &quot;../tools/error.h&quot;
  78. #include &quot;../plc/plc.h&quot;
  79. signed ModuleSession (struct plc * plc, unsigned modules, struct vs_module_spec * vs_module_spec)
  80. {
  81. struct channel * channel = (struct channel *)(plc-&gt;channel);
  82. struct message * message = (struct message *)(plc-&gt;message);
  83. #ifndef __GNUC__
  84. #pragma pack (push,1)
  85. #endif
  86. struct __packed vs_module_operation_start_request
  87. {
  88. struct ethernet_hdr ethernet;
  89. struct qualcomm_hdr qualcomm;
  90. uint32_t RESERVED1;
  91. uint8_t NUM_OP_DATA;
  92. struct __packed
  93. {
  94. uint16_t MOD_OP;
  95. uint16_t MOD_OP_DATA_LEN;
  96. uint32_t MOD_OP_RSVD;
  97. uint32_t MOD_OP_SESSION_ID;
  98. uint8_t NUM_MODULES;
  99. }
  100. MODULE_SPEC;
  101. struct vs_module_spec MOD_OP_SPEC [10];
  102. }
  103. * request = (struct vs_module_operation_start_request *)(message);
  104. struct __packed vs_module_operation_start_confirm
  105. {
  106. struct ethernet_hdr ethernet;
  107. struct qualcomm_hdr qualcomm;
  108. uint16_t MSTATUS;
  109. uint16_t ERR_REC_CODE;
  110. uint32_t RESERVED;
  111. uint8_t NUM_OP_DATA;
  112. struct __packed
  113. {
  114. uint16_t MOD_OP;
  115. uint16_t MOD_OP_DATA_LEN;
  116. uint32_t MOD_OP_RSVD;
  117. uint32_t MOD_OP_SESSION_ID;
  118. uint8_t NUM_MODULES;
  119. }
  120. MODULE_SPEC;
  121. struct __packed
  122. {
  123. uint16_t MOD_STATUS;
  124. uint16_t ERR_REC_CODE;
  125. }
  126. MOD_OP_DATA [1];
  127. }
  128. * confirm = (struct vs_module_operation_start_confirm *)(message);
  129. #ifndef __GNUC__
  130. #pragma pack (pop)
  131. #endif
  132. unsigned timer = channel-&gt;timeout;
  133. struct vs_module_spec * request_spec = (struct vs_module_spec *)(&amp;request-&gt;MOD_OP_SPEC);
  134. Request (plc, &quot;Start Module Write Session&quot;);
  135. memset (message, 0, sizeof (* message));
  136. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  137. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_MODULE_OPERATION | MMTYPE_REQ));
  138. plc-&gt;packetsize = sizeof (* request);
  139. request-&gt;NUM_OP_DATA = 1;
  140. request-&gt;MODULE_SPEC.MOD_OP = HTOLE16 (PLC_MOD_OP_START_SESSION);
  141. request-&gt;MODULE_SPEC.MOD_OP_DATA_LEN = HTOLE16 ((uint16_t)(sizeof (request-&gt;MODULE_SPEC)) + modules * sizeof (struct vs_module_spec));
  142. request-&gt;MODULE_SPEC.MOD_OP_SESSION_ID = HTOLE32 (plc-&gt;cookie);
  143. request-&gt;MODULE_SPEC.NUM_MODULES = modules;
  144. while (modules--)
  145. {
  146. request_spec-&gt;MODULE_ID = HTOLE16 (vs_module_spec-&gt;MODULE_ID);
  147. request_spec-&gt;MODULE_SUB_ID = HTOLE16 (vs_module_spec-&gt;MODULE_SUB_ID);
  148. request_spec-&gt;MODULE_LENGTH = HTOLE32 (vs_module_spec-&gt;MODULE_LENGTH);
  149. request_spec-&gt;MODULE_CHKSUM = vs_module_spec-&gt;MODULE_CHKSUM;
  150. vs_module_spec++;
  151. request_spec++;
  152. }
  153. if (SendMME (plc) &lt;= 0)
  154. {
  155. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  156. return (-1);
  157. }
  158. channel-&gt;timeout = PLC_MODULE_REQUEST_TIMEOUT;
  159. if (ReadMME (plc, 0, (VS_MODULE_OPERATION | MMTYPE_CNF)) &lt;= 0)
  160. {
  161. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  162. channel-&gt;timeout = timer;
  163. return (-1);
  164. }
  165. channel-&gt;timeout = timer;
  166. if (confirm-&gt;MSTATUS)
  167. {
  168. Failure (plc, PLC_WONTDOIT);
  169. return (-1);
  170. }
  171. return (0);
  172. }
  173. #endif
  174. </pre>
  175. <div class='footerlink'>
  176. [<a href='ModuleRead.c.html' title=' ModuleRead.c '>PREV</a>]
  177. [<a href='toolkit.html' title=' Index '>HOME</a>]
  178. [<a href='ModuleSpec.c.html' title=' ModuleSpec.c '>NEXT</a>]
  179. </div>
  180. </body>
  181. </html>