qosinfo.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. * qosinfo.c - print qos information;
  44. *
  45. *
  46. *--------------------------------------------------------------------*/
  47. /*====================================================================*
  48. * system header files;
  49. *--------------------------------------------------------------------*/
  50. #include <unistd.h>
  51. #include <limits.h>
  52. #include <errno.h>
  53. /*====================================================================*
  54. * custom header files;
  55. *--------------------------------------------------------------------*/
  56. #include "../tools/getoptv.h"
  57. #include "../tools/putoptv.h"
  58. #include "../tools/number.h"
  59. #include "../tools/error.h"
  60. #include "../tools/files.h"
  61. /*====================================================================*
  62. * custom source files;
  63. *--------------------------------------------------------------------*/
  64. #ifndef MAKEFILE
  65. #include "../tools/getoptv.c"
  66. #include "../tools/putoptv.c"
  67. #include "../tools/version.c"
  68. #include "../tools/uintspec.c"
  69. #include "../tools/todigit.c"
  70. #include "../tools/error.c"
  71. #endif
  72. /*====================================================================*
  73. * program constants;
  74. *--------------------------------------------------------------------*/
  75. #define TM_VERBOSE (1 << 0)
  76. #define TM_SILENCE (1 << 1)
  77. #define OFFSET 0x020C
  78. #define LENGTH 0x0800
  79. /*====================================================================*
  80. *
  81. * int main (int argc, char const * argv []);
  82. *
  83. *
  84. *
  85. *--------------------------------------------------------------------*/
  86. int main (int argc, char const * argv [])
  87. {
  88. static char const * optv [] =
  89. {
  90. "",
  91. "file [file] [...] [> stdout]",
  92. "print qos information",
  93. (char const *) (0)
  94. };
  95. #ifndef __GNUC__
  96. #pragma pack (push, 1)
  97. #endif
  98. struct __packed QoS
  99. {
  100. uint8_t UniCastPriority;
  101. uint8_t McastPriority;
  102. uint8_t IGMPPriority;
  103. uint8_t AVStreamPriority;
  104. uint32_t PriorityTTL [4];
  105. uint8_t EnableVLANOver;
  106. uint8_t EnableTOSOver;
  107. uint16_t RSVD1;
  108. uint16_t VLANPrioMatrix;
  109. uint16_t TOSPrecMatrix;
  110. uint8_t NumberOfConfigEntries;
  111. struct
  112. {
  113. uint8_t one;
  114. uint8_t two;
  115. }
  116. AggregateConfigEntries [8];
  117. uint8_t CustomAggregationParameters [384];
  118. uint8_t RSVD2 [1619];
  119. }
  120. QoS;
  121. #ifndef __GNUC__
  122. #pragma pack (pop)
  123. #endif
  124. file_t fd;
  125. signed c;
  126. optind = 1;
  127. while ((c = getoptv (argc, argv, optv)) != -1)
  128. {
  129. switch (c)
  130. {
  131. default:
  132. break;
  133. }
  134. }
  135. argc -= optind;
  136. argv += optind;
  137. while ((argc) && (* argv))
  138. {
  139. if ((fd = open (* argv, O_BINARY|O_RDONLY)) == -1)
  140. {
  141. error (0, errno, "Can't open %s", * argv);
  142. }
  143. else if (lseek (fd, OFFSET, SEEK_SET) != OFFSET)
  144. {
  145. error (0, errno, "Can't seek %s", * argv);
  146. close (fd);
  147. }
  148. else if (read (fd, &QoS, sizeof (QoS)) != sizeof (QoS))
  149. {
  150. error (0, errno, "Can't read %s", * argv);
  151. close (fd);
  152. }
  153. else
  154. {
  155. for (c = 0; c < 8; c++)
  156. {
  157. unsigned VLAN = (QoS.VLANPrioMatrix >> (c * 2)) & 0x03;
  158. unsigned TOS = (QoS.TOSPrecMatrix >> (c * 2)) & 0x03;
  159. printf ("VLAN %u TOS %u\n", VLAN, TOS);
  160. }
  161. for (c = 0; c < 4; c++)
  162. {
  163. printf ("TTL [%d]=%d\n", c, QoS.PriorityTTL [c]);
  164. }
  165. for (c = 0; c < 8; c++)
  166. {
  167. printf ("AggregateConfigEntries [%d] %02x %02X\n", c, QoS.AggregateConfigEntries [c].one, QoS.AggregateConfigEntries [c].two);
  168. }
  169. printf ("QoS "SIZE_T_SPEC" %04X\n", sizeof (QoS), (unsigned int) sizeof (QoS));
  170. close (fd);
  171. }
  172. argc--;
  173. argv++;
  174. }
  175. return (0);
  176. }