qosinfo.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * qosinfo.c - print qos information;
  11. *
  12. *--------------------------------------------------------------------*/
  13. /*====================================================================*
  14. * system header files;
  15. *--------------------------------------------------------------------*/
  16. #include <unistd.h>
  17. #include <limits.h>
  18. #include <errno.h>
  19. /*====================================================================*
  20. * custom header files;
  21. *--------------------------------------------------------------------*/
  22. #include "../tools/getoptv.h"
  23. #include "../tools/putoptv.h"
  24. #include "../tools/number.h"
  25. #include "../tools/error.h"
  26. #include "../tools/files.h"
  27. /*====================================================================*
  28. * custom source files;
  29. *--------------------------------------------------------------------*/
  30. #ifndef MAKEFILE
  31. #include "../tools/getoptv.c"
  32. #include "../tools/putoptv.c"
  33. #include "../tools/version.c"
  34. #include "../tools/uintspec.c"
  35. #include "../tools/todigit.c"
  36. #include "../tools/error.c"
  37. #endif
  38. /*====================================================================*
  39. * program constants;
  40. *--------------------------------------------------------------------*/
  41. #define TM_VERBOSE (1 << 0)
  42. #define TM_SILENCE (1 << 1)
  43. #define OFFSET 0x020C
  44. #define LENGTH 0x0800
  45. /*====================================================================*
  46. *
  47. * int main (int argc, char const * argv []);
  48. *
  49. *--------------------------------------------------------------------*/
  50. int main (int argc, char const * argv [])
  51. {
  52. static char const * optv [] =
  53. {
  54. "",
  55. "file [file] [...] [> stdout]",
  56. "print qos information",
  57. (char const *) (0)
  58. };
  59. #ifndef __GNUC__
  60. #pragma pack (push, 1)
  61. #endif
  62. struct __packed QoS
  63. {
  64. uint8_t UniCastPriority;
  65. uint8_t McastPriority;
  66. uint8_t IGMPPriority;
  67. uint8_t AVStreamPriority;
  68. uint32_t PriorityTTL [4];
  69. uint8_t EnableVLANOver;
  70. uint8_t EnableTOSOver;
  71. uint16_t RSVD1;
  72. uint16_t VLANPrioMatrix;
  73. uint16_t TOSPrecMatrix;
  74. uint8_t NumberOfConfigEntries;
  75. struct
  76. {
  77. uint8_t one;
  78. uint8_t two;
  79. }
  80. AggregateConfigEntries [8];
  81. uint8_t CustomAggregationParameters [384];
  82. uint8_t RSVD2 [1619];
  83. }
  84. QoS;
  85. #ifndef __GNUC__
  86. #pragma pack (pop)
  87. #endif
  88. file_t fd;
  89. signed c;
  90. optind = 1;
  91. while (~ (c = getoptv (argc, argv, optv)))
  92. {
  93. switch (c)
  94. {
  95. default:
  96. break;
  97. }
  98. }
  99. argc -= optind;
  100. argv += optind;
  101. while ((argc) && (* argv))
  102. {
  103. if ((fd = open (* argv, O_BINARY | O_RDONLY)) == - 1)
  104. {
  105. error (0, errno, "Can't open %s", * argv);
  106. }
  107. else if (lseek (fd, OFFSET, SEEK_SET) != OFFSET)
  108. {
  109. error (0, errno, "Can't seek %s", * argv);
  110. close (fd);
  111. }
  112. else if (read (fd, & QoS, sizeof (QoS)) != sizeof (QoS))
  113. {
  114. error (0, errno, "Can't read %s", * argv);
  115. close (fd);
  116. }
  117. else
  118. {
  119. for (c = 0; c < 8; c++)
  120. {
  121. unsigned VLAN = (QoS.VLANPrioMatrix >> (c * 2)) & 0x03;
  122. unsigned TOS = (QoS.TOSPrecMatrix >> (c * 2)) & 0x03;
  123. printf ("VLAN %d TOS %d\n", VLAN, TOS);
  124. }
  125. for (c = 0; c < 4; c++)
  126. {
  127. printf ("TTL [%d]=%d\n", c, QoS.PriorityTTL [c]);
  128. }
  129. for (c = 0; c < 8; c++)
  130. {
  131. printf ("AggregateConfigEntries [%d] %02x %02X\n", c, QoS.AggregateConfigEntries [c].one, QoS.AggregateConfigEntries [c].two);
  132. }
  133. printf ("QoS %d %04X\n", sizeof (QoS), sizeof (QoS));
  134. close (fd);
  135. }
  136. argc--;
  137. argv++;
  138. }
  139. return (0);
  140. }