Attributes1.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 Attributes1 (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 ATTRIBUTES1_SOURCE
  63. #define ATTRIBUTES1_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 Attributes1 (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 HARDWARE [16];
  105. uint8_t SOFTWARE [16];
  106. uint32_t FWVERSION [5];
  107. uint8_t RELEASEDATE [8];
  108. uint8_t RELEASETYPE [12];
  109. uint8_t SDRAMTYPE;
  110. uint8_t RESERVED;
  111. uint8_t LINEFREQ;
  112. uint32_t SDRAMSIZE;
  113. uint8_t AUTHMODE;
  114. }
  115. * attributes = (struct attributes *)(confirm->MBUFFER);
  116. #ifndef __GNUC__
  117. #pragma pack (pop)
  118. #endif
  119. Request (plc, "Fetch Device Attributes");
  120. memset (message, 0, sizeof (* message));
  121. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  122. QualcommHeader (&request->qualcomm, 0, (VS_OP_ATTRIBUTES | MMTYPE_REQ));
  123. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  124. request->COOKIE = HTOLE32 (plc->cookie);
  125. request->RTYPE = 0;
  126. if (SendMME (plc) <= 0)
  127. {
  128. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  129. return (-1);
  130. }
  131. while (ReadMME (plc, 0, (VS_OP_ATTRIBUTES | MMTYPE_CNF)) > 0)
  132. {
  133. static char const * frequency [] =
  134. {
  135. "Unknown frequency",
  136. "50Hz",
  137. "60Hz",
  138. };
  139. static char const * zero_cross [] =
  140. {
  141. "Not yet detected",
  142. "Detected",
  143. "Missing",
  144. };
  145. char string [512];
  146. size_t length = 0;
  147. if (confirm->COOKIE != HTOLE32 (plc->cookie)) {
  148. continue;
  149. }
  150. if (confirm->MSTATUS)
  151. {
  152. Failure (plc, PLC_WONTDOIT);
  153. continue;
  154. }
  155. #if 0
  156. #if defined (__GNUC__)
  157. #warning "Debug code active in module Attributes1"
  158. #endif
  159. fprintf (stderr, "HARDWARE=[%-16.16s]\n", attributes->HARDWARE);
  160. fprintf (stderr, "SOFTWARE=[%-16.16s]\n", attributes->SOFTWARE);
  161. fprintf (stderr, "FIRMWARE MAJOR VERSION=(%d)\n", LE32TOH (attributes->FWVERSION [0]));
  162. fprintf (stderr, "FIRMWARE MINOR VERSION=(%d)\n", LE32TOH (attributes->FWVERSION [1]));
  163. fprintf (stderr, "FIRMWARE [2]=(%d)\n", LE32TOH (attributes->FWVERSION [2]));
  164. fprintf (stderr, "FIRMWARE [3]=(%d)\n", LE32TOH (attributes->FWVERSION [3]));
  165. fprintf (stderr, "FIRMWARE [4]=(%d)\n", LE32TOH (attributes->FWVERSION [4]));
  166. fprintf (stderr, "RELEASE DATE=[%-8.8s]\n", attributes->RELEASEDATE);
  167. fprintf (stderr, "RELEASE TYPE=[%-12.12s]\n", attributes->RELEASETYPE);
  168. fprintf (stderr, "SDRAM SIZE=[0x%08X]\n", LE32TOH (attributes->SDRAMSIZE));
  169. fprintf (stderr, "SDRAM TYPE=[0x%02X]\n", attributes->SDRAMTYPE);
  170. fprintf (stderr, "RESERVED=[0x%02X]\n", attributes->RESERVED);
  171. fprintf (stderr, "LINE FREQUENCY=[0x%02X]\n", attributes->LINEFREQ);
  172. fprintf (stderr, "AUTHORIZATION MODE=[0x%02X]\n", attributes->AUTHMODE);
  173. #endif
  174. length += snprintf (string + length, sizeof (string) - length, "%s", attributes->HARDWARE);
  175. length += snprintf (string + length, sizeof (string) - length, "-%s", attributes->SOFTWARE);
  176. length += snprintf (string + length, sizeof (string) - length, "-%d", LE32TOH (attributes->FWVERSION [0]));
  177. length += snprintf (string + length, sizeof (string) - length, "-%d", LE32TOH (attributes->FWVERSION [1]));
  178. length += snprintf (string + length, sizeof (string) - length, "-%04d", LE32TOH (attributes->FWVERSION [2]));
  179. length += snprintf (string + length, sizeof (string) - length, "-%02d", LE32TOH (attributes->FWVERSION [3]));
  180. length += snprintf (string + length, sizeof (string) - length, "-%04d", LE32TOH (attributes->FWVERSION [4]));
  181. length += snprintf (string + length, sizeof (string) - length, "-%-8.8s", attributes->RELEASEDATE);
  182. length += snprintf (string + length, sizeof (string) - length, "-%s", attributes->RELEASETYPE);
  183. length += snprintf (string + length, sizeof (string) - length, "-%c", attributes->SDRAMTYPE);
  184. length += snprintf (string + length, sizeof (string) - length, " (%dmb)", LE32TOH (attributes->SDRAMSIZE));
  185. length += snprintf (string + length, sizeof (string) - length, " (0x%02X) \"%s\" \"%s\" ", attributes->LINEFREQ, frequency [attributes->LINEFREQ & 0x03], zero_cross [(attributes->LINEFREQ & 0x0C) >> 2]);
  186. length += snprintf (string + length, sizeof (string) - length, " 0x%02X", attributes->AUTHMODE);
  187. Display (plc, "%s", string);
  188. }
  189. return (0);
  190. }
  191. #endif