EmulateHost64.c.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. EmulateHost64.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='emalloc.c.html' title=' emalloc.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='EmulateHost.c.html' title=' EmulateHost.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. * int EmulateHost64 (struct plc * plc);
  64. *
  65. * plc.h
  66. *
  67. * wait indefinitely for VS_HOST_ACTION messages; service the device
  68. * only; it will stop dead - like a bug! - on error;
  69. *
  70. *
  71. * Contributor(s):
  72. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  73. *
  74. *--------------------------------------------------------------------*/
  75. #ifndef EMULATEHOST64_SOURCE
  76. #define EMULATEHOST64_SOURCE
  77. #include &lt;unistd.h&gt;
  78. #include &lt;memory.h&gt;
  79. #include &quot;../plc/plc.h&quot;
  80. #include &quot;../ether/channel.h&quot;
  81. #include &quot;../tools/error.h&quot;
  82. #include &quot;../tools/flags.h&quot;
  83. #include &quot;../tools/files.h&quot;
  84. #include &quot;../nvm/nvm.h&quot;
  85. #include &quot;../pib/pib.h&quot;
  86. signed EmulateHost64 (struct plc * plc)
  87. {
  88. struct channel * channel = (struct channel *)(plc-&gt;channel);
  89. struct message * message = (struct message *)(plc-&gt;message);
  90. static char const * actions [] =
  91. {
  92. &quot;start device&quot;,
  93. &quot;store firmware&quot;,
  94. &quot;store parameters&quot;,
  95. &quot;update host&quot;,
  96. &quot;config memory&quot;,
  97. &quot;restore defaults&quot;,
  98. &quot;unknown&quot;
  99. };
  100. #ifndef __GNUC__
  101. #pragma pack (push,1)
  102. #endif
  103. struct __packed vs_host_action_ind
  104. {
  105. struct ethernet_hdr ethernet;
  106. struct qualcomm_hdr qualcomm;
  107. uint8_t MACTION;
  108. uint8_t MAJOR_VERSION;
  109. uint8_t MINOR_VERSION;
  110. }
  111. * indicate = (struct vs_host_action_ind *) (message);
  112. #if 0
  113. struct __packed vs_host_action_rsp
  114. {
  115. struct ethernet_hdr ethernet;
  116. struct qualcomm_hdr qualcomm;
  117. uint8_t MSTATUS;
  118. }
  119. * response = (struct vs_host_action_rsp *) (message);
  120. #endif
  121. #ifndef __GNUC__
  122. #pragma pack (pop)
  123. #endif
  124. char const * NVM = plc-&gt;NVM.name;
  125. char const * PIB = plc-&gt;PIB.name;
  126. signed status;
  127. signed action;
  128. Request (plc, &quot;Waiting for Host Action&quot;);
  129. while (1)
  130. {
  131. status = ReadMME (plc, 0, (VS_HOST_ACTION | MMTYPE_IND));
  132. if (status &lt; 0)
  133. {
  134. break;
  135. }
  136. if (status &gt; 0)
  137. {
  138. printf (&quot;\n&quot;);
  139. if (indicate-&gt;MACTION &lt; (sizeof (actions) / sizeof (char const *)))
  140. {
  141. Confirm (plc, &quot;Host Action Request is (%d) %s.&quot;, indicate-&gt;MACTION, actions [indicate-&gt;MACTION]);
  142. }
  143. else
  144. {
  145. error (0, ENOTSUP, &quot;Host Action 0x%0X&quot;, indicate-&gt;MACTION);
  146. continue;
  147. }
  148. action = indicate-&gt;MACTION;
  149. memcpy (channel-&gt;peer, indicate-&gt;ethernet.OSA, sizeof (channel-&gt;peer));
  150. if (HostActionResponse (plc))
  151. {
  152. return (-1);
  153. }
  154. if (action == 0x00)
  155. {
  156. if (BootDevice1 (plc))
  157. {
  158. return (-1);
  159. }
  160. if (_anyset (plc-&gt;flags, PLC_FLASH_DEVICE))
  161. {
  162. if (WriteNVM (plc))
  163. {
  164. return (-1);
  165. }
  166. if (WritePIB (plc))
  167. {
  168. return (-1);
  169. }
  170. if (FlashNVM (plc))
  171. {
  172. return (-1);
  173. }
  174. }
  175. continue;
  176. }
  177. if (action == 0x01)
  178. {
  179. close (plc-&gt;NVM.file);
  180. if (ReadFirmware1 (plc))
  181. {
  182. return (-1);
  183. }
  184. if ((plc-&gt;NVM.file = open (plc-&gt;NVM.name = plc-&gt;nvm.name, O_BINARY|O_RDONLY)) == -1)
  185. {
  186. error (1, errno, &quot;%s&quot;, plc-&gt;NVM.name);
  187. }
  188. if (ResetDevice (plc))
  189. {
  190. return (-1);
  191. }
  192. continue;
  193. }
  194. if (action == 0x02)
  195. {
  196. close (plc-&gt;PIB.file);
  197. if (ReadParameters1 (plc))
  198. {
  199. return (-1);
  200. }
  201. if ((plc-&gt;PIB.file = open (plc-&gt;PIB.name = plc-&gt;pib.name, O_BINARY|O_RDONLY)) == -1)
  202. {
  203. error (1, errno, &quot;%s&quot;, plc-&gt;PIB.name);
  204. }
  205. if (ResetDevice (plc))
  206. {
  207. return (-1);
  208. }
  209. continue;
  210. }
  211. if (action == 0x03)
  212. {
  213. close (plc-&gt;PIB.file);
  214. if (ReadParameters1 (plc))
  215. {
  216. return (-1);
  217. }
  218. if ((plc-&gt;PIB.file = open (plc-&gt;PIB.name = plc-&gt;pib.name, O_BINARY|O_RDONLY)) == -1)
  219. {
  220. error (1, errno, &quot;%s&quot;, plc-&gt;PIB.name);
  221. }
  222. close (plc-&gt;NVM.file);
  223. if (ReadFirmware1 (plc))
  224. {
  225. return (-1);
  226. }
  227. if ((plc-&gt;NVM.file = open (plc-&gt;NVM.name = plc-&gt;nvm.name, O_BINARY|O_RDONLY)) == -1)
  228. {
  229. error (1, errno, &quot;%s&quot;, plc-&gt;NVM.name);
  230. }
  231. if (ResetDevice (plc))
  232. {
  233. return (-1);
  234. }
  235. continue;
  236. }
  237. if (action == 0x04)
  238. {
  239. if (InitDevice1 (plc))
  240. {
  241. return (-1);
  242. }
  243. continue;
  244. }
  245. if (action == 0x05)
  246. {
  247. close (plc-&gt;NVM.file);
  248. if ((plc-&gt;NVM.file = open (plc-&gt;NVM.name = NVM, O_BINARY|O_RDONLY)) == -1)
  249. {
  250. error (1, errno, &quot;%s&quot;, plc-&gt;NVM.name);
  251. }
  252. close (plc-&gt;PIB.file);
  253. if ((plc-&gt;PIB.file = open (plc-&gt;PIB.name = PIB, O_BINARY|O_RDONLY)) == -1)
  254. {
  255. error (1, errno, &quot;%s&quot;, plc-&gt;PIB.name);
  256. }
  257. if (ResetDevice (plc))
  258. {
  259. return (-1);
  260. }
  261. continue;
  262. }
  263. if (action == 0x06)
  264. {
  265. close (plc-&gt;PIB.file);
  266. if (ReadParameters1 (plc))
  267. {
  268. return (-1);
  269. }
  270. if ((plc-&gt;PIB.file = open (plc-&gt;PIB.name = plc-&gt;pib.name, O_BINARY|O_RDONLY)) == -1)
  271. {
  272. error (1, errno, &quot;%s&quot;, plc-&gt;PIB.name);
  273. }
  274. continue;
  275. }
  276. error (0, ENOSYS, &quot;Host Action 0x%02X&quot;, action);
  277. }
  278. }
  279. return (0);
  280. }
  281. #endif
  282. </pre>
  283. <div class='footerlink'>
  284. [<a href='emalloc.c.html' title=' emalloc.c '>PREV</a>]
  285. [<a href='toolkit.html' title=' Index '>HOME</a>]
  286. [<a href='EmulateHost.c.html' title=' EmulateHost.c '>NEXT</a>]
  287. </div>
  288. </body>
  289. </html>