Identity2.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. #ifndef IDENTITY2_SOURCE
  42. #define IDENTITY2_SOURCE
  43. #include <stdint.h>
  44. #include <unistd.h>
  45. #include <memory.h>
  46. #include "../tools/error.h"
  47. #include "../tools/files.h"
  48. #include "../tools/endian.h"
  49. #include "../tools/memory.h"
  50. #include "../tools/flags.h"
  51. #include "../nvm/nvm.h"
  52. #include "../plc/plc.h"
  53. /*====================================================================*
  54. *
  55. * signed pibchain2 (void const * memory);
  56. *
  57. * search panther/lynx image chain for the next PIB image; print
  58. * information on stdout and return;
  59. *
  60. *
  61. * Contributor(s):
  62. * Charles Maier
  63. *
  64. *--------------------------------------------------------------------*/
  65. static signed pibchain2 (void const * memory, char const * filename, flag_t flags)
  66. {
  67. struct nvm_header2 * nvm_header;
  68. uint32_t origin = ~0;
  69. uint32_t offset = 0;
  70. signed module = 0;
  71. do
  72. {
  73. nvm_header = (struct nvm_header2 *)((char *)(memory) + offset);
  74. if (LE16TOH (nvm_header->MajorVersion) != 1)
  75. {
  76. if (_allclr (flags, NVM_SILENCE))
  77. {
  78. error (0, errno, NVM_HDR_VERSION, filename, module);
  79. }
  80. return (-1);
  81. }
  82. if (LE16TOH (nvm_header->MinorVersion) != 1)
  83. {
  84. if (_allclr (flags, NVM_SILENCE))
  85. {
  86. error (0, errno, NVM_HDR_VERSION, filename, module);
  87. }
  88. return (-1);
  89. }
  90. if (LE32TOH (nvm_header->PrevHeader) != origin)
  91. {
  92. if (_allclr (flags, NVM_SILENCE))
  93. {
  94. error (0, errno, NVM_HDR_LINK, filename, module);
  95. }
  96. return (-1);
  97. }
  98. if (checksum32 (nvm_header, sizeof (* nvm_header), 0))
  99. {
  100. error (0, 0, NVM_HDR_CHECKSUM, filename, module);
  101. return (-1);
  102. }
  103. origin = offset;
  104. offset += sizeof (* nvm_header);
  105. if (LE32TOH (nvm_header->ImageType) == NVM_IMAGE_PIB)
  106. {
  107. struct pib_header * pib_header = (struct pib_header *)((char *)(memory) + offset);
  108. pib_header->PIBLENGTH = HTOLE16((uint16_t)(LE32TOH(nvm_header->ImageLength)));
  109. pibpeek2 ((char *)(memory) + offset);
  110. pib_header->PIBLENGTH = 0;
  111. break;
  112. }
  113. if (checksum32 ((char *)(memory) + offset, LE32TOH (nvm_header->ImageLength), nvm_header->ImageChecksum))
  114. {
  115. if (_allclr (flags, NVM_SILENCE))
  116. {
  117. error (0, errno, NVM_IMG_CHECKSUM, filename, module);
  118. }
  119. return (-1);
  120. }
  121. offset += LE32TOH (nvm_header->ImageLength);
  122. module++;
  123. }
  124. while (~nvm_header->NextHeader);
  125. return (0);
  126. }
  127. /*====================================================================*
  128. *
  129. * signed Identity2 (struct plc * plc);
  130. *
  131. * plc.h
  132. *
  133. * read start of parameter chain from flash memory using single
  134. * VS_MODULE_OPERATION message and print identity information on
  135. * stdout;
  136. *
  137. *
  138. * Contributor(s):
  139. * Charles Maier
  140. *
  141. *--------------------------------------------------------------------*/
  142. signed Identity2 (struct plc * plc)
  143. {
  144. struct channel * channel = (struct channel *)(plc->channel);
  145. struct message * message = (struct message *)(plc->message);
  146. #ifndef __GNUC__
  147. #pragma pack (push,1)
  148. #endif
  149. struct __packed vs_module_operation_read_request
  150. {
  151. struct ethernet_hdr ethernet;
  152. struct qualcomm_hdr qualcomm;
  153. uint32_t RESERVED;
  154. uint8_t NUM_OP_DATA;
  155. struct __packed
  156. {
  157. uint16_t MOD_OP;
  158. uint16_t MOD_OP_DATA_LEN;
  159. uint32_t MOD_OP_RSVD;
  160. uint16_t MODULE_ID;
  161. uint16_t MODULE_SUB_ID;
  162. uint16_t MODULE_LENGTH;
  163. uint32_t MODULE_OFFSET;
  164. }
  165. MODULE_SPEC;
  166. }
  167. * request = (struct vs_module_operation_read_request *)(message);
  168. struct __packed vs_module_operation_read_confirm
  169. {
  170. struct ethernet_hdr ethernet;
  171. struct qualcomm_hdr qualcomm;
  172. uint16_t MSTATUS;
  173. uint16_t ERR_REC_CODE;
  174. uint32_t RESERVED;
  175. uint8_t NUM_OP_DATA;
  176. struct __packed
  177. {
  178. uint16_t MOD_OP;
  179. uint16_t MOD_OP_DATA_LEN;
  180. uint32_t MOD_OP_RSVD;
  181. uint16_t MODULE_ID;
  182. uint16_t MODULE_SUB_ID;
  183. uint16_t MODULE_LENGTH;
  184. uint32_t MODULE_OFFSET;
  185. }
  186. MODULE_SPEC;
  187. uint8_t MODULE_DATA [PLC_MODULE_SIZE];
  188. }
  189. * confirm = (struct vs_module_operation_read_confirm *)(message);
  190. #ifndef __GNUC__
  191. #pragma pack (pop)
  192. #endif
  193. memset (message, 0, sizeof (* message));
  194. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  195. QualcommHeader (&request->qualcomm, 0, (VS_MODULE_OPERATION | MMTYPE_REQ));
  196. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  197. request->NUM_OP_DATA = 1;
  198. request->MODULE_SPEC.MOD_OP = HTOLE16 (0);
  199. request->MODULE_SPEC.MOD_OP_DATA_LEN = HTOLE16 (sizeof (request->MODULE_SPEC));
  200. request->MODULE_SPEC.MOD_OP_RSVD = HTOLE32 (0);
  201. request->MODULE_SPEC.MODULE_ID = HTOLE16 (PLC_MODULEID_PARAMETERS);
  202. request->MODULE_SPEC.MODULE_SUB_ID = HTOLE16 (0);
  203. request->MODULE_SPEC.MODULE_LENGTH = HTOLE16 (PLC_MODULE_SIZE);
  204. request->MODULE_SPEC.MODULE_OFFSET = HTOLE32 (0);
  205. if (SendMME (plc) <= 0)
  206. {
  207. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  208. return (-1);
  209. }
  210. if (ReadMME (plc, 0, (VS_MODULE_OPERATION | MMTYPE_CNF)) <= 0)
  211. {
  212. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  213. return (-1);
  214. }
  215. if (confirm->MSTATUS)
  216. {
  217. Failure (plc, PLC_WONTDOIT);
  218. return (-1);
  219. }
  220. pibchain2 (confirm->MODULE_DATA, "device", plc->flags);
  221. return (0);
  222. }
  223. #endif