Attributes2.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. /*====================================================================*
  42. *
  43. * signed Attributes2 (struct plc * plc);
  44. *
  45. * plc.h
  46. *
  47. * This plugin for program plc requests device attributes using
  48. * a VS_OP_ATTRIBUTES message; attributes are pre-parsed versions
  49. * of information returned by VS_SW_VER and other messages;
  50. *
  51. * The VS_OP_ATTRIBUTES message structure changed between FW 3.3.4
  52. * and 3.3.5 and fields are ocassionally appended to the end; you
  53. * should not use this message for operational systems because the
  54. * format may change again; it was originally intended for PTS use
  55. * only;
  56. *
  57. *
  58. * Contributor(s):
  59. * Charles Maier
  60. *
  61. *--------------------------------------------------------------------*/
  62. #ifndef ATTRIBUTES2_SOURCE
  63. #define ATTRIBUTES2_SOURCE
  64. #include <stdint.h>
  65. #include <memory.h>
  66. #include "../plc/plc.h"
  67. #include "../tools/memory.h"
  68. #include "../tools/format.h"
  69. #include "../tools/error.h"
  70. #include "../tools/flags.h"
  71. #ifdef WIN32
  72. #if !defined (_MSC_VER) || _MSC_VER < 1900
  73. #define snprintf _snprintf
  74. #endif
  75. #endif
  76. signed Attributes2 (struct plc * plc)
  77. {
  78. struct channel * channel = (struct channel *)(plc->channel);
  79. struct message * message = (struct message *)(plc->message);
  80. #ifndef __GNUC__
  81. #pragma pack (push,1)
  82. #endif
  83. struct __packed vs_op_attributes_request
  84. {
  85. struct ethernet_hdr ethernet;
  86. struct qualcomm_hdr qualcomm;
  87. uint32_t COOKIE;
  88. uint8_t RTYPE;
  89. }
  90. * request = (struct vs_op_attributes_request *) (message);
  91. struct __packed vs_op_attributes_confirm
  92. {
  93. struct ethernet_hdr ethernet;
  94. struct qualcomm_hdr qualcomm;
  95. uint16_t MSTATUS;
  96. uint32_t COOKIE;
  97. uint8_t RTYPE;
  98. uint16_t MLENGTH;
  99. uint8_t MBUFFER [1024];
  100. }
  101. * confirm = (struct vs_op_attributes_confirm *) (message);
  102. struct __packed attributes
  103. {
  104. uint8_t DEVICEFAMILY [16];
  105. uint8_t DEVICETYPE [16];
  106. uint32_t FWMAJORVERSION;
  107. uint32_t FWMINORVERSION;
  108. uint32_t COMPOSITEVERSION;
  109. uint32_t SUSTAININGVERSION;
  110. uint32_t BUILDNUMBER;
  111. uint8_t BUILDDATE [8];
  112. uint8_t RELEASETYPE [12];
  113. uint8_t FLAGS [3];
  114. uint32_t DRAMSIZE;
  115. uint32_t RAMBLOCKRXCOUNT;
  116. uint32_t RAMBLOCKTXCOUNT;
  117. uint32_t RAMBLOCKSHAREDCOUNT;
  118. uint32_t RAMBLOCKFREERXCOUNT;
  119. uint32_t RAMBLOCKFREETXCOUNT;
  120. uint32_t RAMBLOCKFREESHAREDCOUNT;
  121. uint32_t RELATIVESNRDIFFDB;
  122. uint32_t DSP384THREGVAL;
  123. uint8_t AFETXGAINDB;
  124. uint8_t AUTHMODE;
  125. uint8_t MICROCONTROLLERDIAGENABLED;
  126. }
  127. * attributes = (struct attributes *)(confirm->MBUFFER);
  128. #ifndef __GNUC__
  129. #pragma pack (pop)
  130. #endif
  131. Request (plc, "Fetch Device Attributes");
  132. memset (message, 0, sizeof (* message));
  133. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  134. QualcommHeader (&request->qualcomm, 0, (VS_OP_ATTRIBUTES | MMTYPE_REQ));
  135. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  136. request->COOKIE = HTOLE32 (plc->cookie);
  137. request->RTYPE = 0;
  138. if (SendMME (plc) <= 0)
  139. {
  140. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  141. return (-1);
  142. }
  143. while (ReadMME (plc, 0, (VS_OP_ATTRIBUTES | MMTYPE_CNF)) > 0)
  144. {
  145. #if 0
  146. static char const * frequency [] =
  147. {
  148. "Unknown Frequency",
  149. "50Hz",
  150. "60Hz",
  151. };
  152. static char const * zero_cross [] =
  153. {
  154. "Not yet detected",
  155. "Detected",
  156. "Missing",
  157. };
  158. #endif
  159. char string [512];
  160. size_t length = 0;
  161. if (confirm->COOKIE != HTOLE32 (plc->cookie)) {
  162. continue;
  163. }
  164. if (confirm->MSTATUS)
  165. {
  166. Failure (plc, PLC_WONTDOIT);
  167. continue;
  168. }
  169. #if 0
  170. #if defined (__GNUC__)
  171. #warning "Debug code active in module Attributes2"
  172. #endif
  173. fprintf (stderr, "DEVICE FAMILY=[%-16.16s]\n", attributes->DEVICEFAMILY);
  174. fprintf (stderr, "DEVICE TYPE=[%-16.16s]\n", attributes->DEVICETYPE);
  175. fprintf (stderr, "FIRMWARE MAJOR VERSION=(%d)\n", LE32TOH (attributes->FWMAJORVERSION));
  176. fprintf (stderr, "FIRMWARE MINOR VERSION=(%d)\n", LE32TOH (attributes->FWMINORVERSION));
  177. fprintf (stderr, "COMPOSITE VERSION=(%d)\n", LE32TOH (attributes->COMPOSITEVERSION));
  178. fprintf (stderr, "SUSTAINING VERSION=(%d)\n", LE32TOH (attributes->SUSTAININGVERSION));
  179. fprintf (stderr, "BUILD NUMBER=(%d)\n", LE32TOH (attributes->BUILDNUMBER));
  180. fprintf (stderr, "BUILD DATE=[%-8.8s]\n", attributes->BUILDDATE);
  181. fprintf (stderr, "RELEASE TYPE=[%-12.12s]\n", attributes->RELEASETYPE);
  182. fprintf (stderr, "DRAM SIZE=[0x%08X](%d)\n", LE32TOH (attributes->DRAMSIZE), LE32TOH (attributes->DRAMSIZE));
  183. fprintf (stderr, "DRAM TYPES=[0x%02X]\n", attributes->FLAGS [0]);
  184. fprintf (stderr, "RESERVED FLAG=[0x%02X]\n", attributes->FLAGS [1]);
  185. fprintf (stderr, "LINE FREQUENCY=[0x%02X]\n", attributes->FLAGS [2]);
  186. fprintf (stderr, "AUTHORIZATION MODE=[0x%02X]\n", attributes->AUTHMODE);
  187. fprintf (stderr, "DSP384THREGVAL=[0x%02X]\n", attributes->DSP384THREGVAL);
  188. fprintf (stderr, "AFETXGAINDB=[0x%02X]\n", attributes->AFETXGAINDB);
  189. fprintf (stderr, "AUTHORIZATION MODE=[0x%02X]\n", attributes->AUTHMODE);
  190. #if 0
  191. fprintf (stderr, "DSP384THREGVAL=[0x%08X]\n", LE32TOH (attributes->DSP384THREGVAL));
  192. fprintf (stderr, "AFETXGAINDB=[0x%02X]\n", attributes->AFETXGAINDB);
  193. #endif
  194. #endif
  195. length += snprintf (string + length, sizeof (string) - length, "%s", attributes->DEVICEFAMILY);
  196. length += snprintf (string + length, sizeof (string) - length, "-%s", attributes->DEVICETYPE);
  197. length += snprintf (string + length, sizeof (string) - length, "-%s", attributes->DEVICEFAMILY);
  198. length += snprintf (string + length, sizeof (string) - length, "-%d", LE32TOH (attributes->FWMAJORVERSION));
  199. length += snprintf (string + length, sizeof (string) - length, ".%d", LE32TOH (attributes->FWMINORVERSION));
  200. length += snprintf (string + length, sizeof (string) - length, ".%d", LE32TOH (attributes->COMPOSITEVERSION));
  201. length += snprintf (string + length, sizeof (string) - length, ".%d", LE32TOH (attributes->BUILDNUMBER));
  202. length += snprintf (string + length, sizeof (string) - length, "-%02d", LE32TOH (attributes->SUSTAININGVERSION));
  203. length += snprintf (string + length, sizeof (string) - length, "-%8.8s", attributes->BUILDDATE);
  204. length += snprintf (string + length, sizeof (string) - length, "-%s", attributes->RELEASETYPE);
  205. length += snprintf (string + length, sizeof (string) - length, " (%dmb)", LE32TOH (attributes->DRAMSIZE));
  206. Display (plc, "%s", string);
  207. }
  208. return (0);
  209. }
  210. #endif