mme.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * mme.c - Qualcomm Atheros vendor-specific message code and name printer;
  11. *
  12. * print vendor-specific mesage codes and names and with associated
  13. * error codes and error text on stdout in various formats; options
  14. * are HTML, CSV and plain text;
  15. *
  16. * Contributor(s):
  17. * Charles Maier <cmaier@qca.qualcomm.com>
  18. *
  19. *--------------------------------------------------------------------*/
  20. /*====================================================================*
  21. * system header files;
  22. *--------------------------------------------------------------------*/
  23. #include <stdio.h>
  24. #include <errno.h>
  25. /*====================================================================*
  26. * custom header files;
  27. *--------------------------------------------------------------------*/
  28. #include "../tools/getoptv.h"
  29. #include "../tools/putoptv.h"
  30. #include "../tools/number.h"
  31. #include "../tools/format.h"
  32. #include "../tools/error.h"
  33. #include "../tools/flags.h"
  34. #include "../mme/mme.h"
  35. /*====================================================================*
  36. * custom source files;
  37. *--------------------------------------------------------------------*/
  38. #ifndef MAKEFILE
  39. #include "../tools/getoptv.c"
  40. #include "../tools/putoptv.c"
  41. #include "../tools/version.c"
  42. #include "../tools/error.c"
  43. #include "../tools/uintspec.c"
  44. #include "../tools/todigit.c"
  45. #include "../tools/output.c"
  46. #endif
  47. #ifndef MAKEFILE
  48. #include "../mme/MMEName.c"
  49. #include "../mme/MMEMode.c"
  50. #endif
  51. /*====================================================================*
  52. *
  53. *--------------------------------------------------------------------*/
  54. #include "../mme/MMECode.c"
  55. #include "../mme/MMESize.c"
  56. /*====================================================================*
  57. * program constants;
  58. *--------------------------------------------------------------------*/
  59. #define MME_VERBOSE (1 << 0)
  60. #define MME_SILENCE (1 << 1)
  61. #define MME_ORDER (1 << 2)
  62. #define MME_TOCSV (1 << 3)
  63. #define MME_TOHTML (1 << 4)
  64. #define MME_TOTEXT (1 << 5)
  65. #define MME_TOSIZE (1 << 6)
  66. #define DEFAULT_COLUMN 50
  67. #define DEFAULT_INDENT 2
  68. /*====================================================================*
  69. *
  70. * void mmetocsv ();
  71. *
  72. *
  73. *--------------------------------------------------------------------*/
  74. static void mmetocsv (void)
  75. {
  76. unsigned index;
  77. printf ("Name,Type,Code,Text\n");
  78. for (index = 0; index < SIZEOF (mme_codes); index++)
  79. {
  80. unsigned type = mme_codes [index].type;
  81. printf ("0x%04X,", type);
  82. printf ("%s.%s,", MMEName (type), MMEMode (type));
  83. printf ("0x%02X,", mme_codes [index].code);
  84. printf ("\"%s\"\n", mme_codes [index].text);
  85. }
  86. return;
  87. }
  88. /*====================================================================*
  89. *
  90. * void mmetohtml (signed margin);
  91. *
  92. *
  93. *--------------------------------------------------------------------*/
  94. static void mmetohtml (unsigned margin)
  95. {
  96. unsigned index;
  97. output (margin++, "<table class='mme'>");
  98. output (margin++, "<tr class='mme'>");
  99. output (margin, "<th class='type'>Type</th>");
  100. output (margin, "<th class='name'>Name</th>");
  101. output (margin, "<th class='code'>Code</th>");
  102. output (margin, "<th class='text'>Text</th>");
  103. output (margin--, "</tr>");
  104. for (index = 0; index < SIZEOF (mme_codes); index++)
  105. {
  106. unsigned type = mme_codes [index].type;
  107. output (margin++, "<tr class='mme'>");
  108. output (margin, "<td class='type'>0x%04X</td>", type);
  109. output (margin, "<td class='name'>%s.%s</td>", MMEName (type), MMEMode (type));
  110. output (margin, "<td class='code'>0x%02X</td>", mme_codes [index].code);
  111. output (margin, "<td class='text'>%s</td>", mme_codes [index].text);
  112. output (margin--, "</tr>");
  113. }
  114. output (margin--, "</table>");
  115. return;
  116. }
  117. /*====================================================================*
  118. *
  119. * void mmetotext (void);
  120. *
  121. *
  122. *--------------------------------------------------------------------*/
  123. static void mmetotext (unsigned column)
  124. {
  125. unsigned index;
  126. for (index = 0; index < SIZEOF (mme_codes); index++)
  127. {
  128. signed indent = column;
  129. unsigned type = mme_codes [index].type;
  130. indent -= printf ("0x%04X ", type);
  131. indent -= printf ("%s.%s ", MMEName (type), MMEMode (type));
  132. while (indent-- > 0)
  133. {
  134. putc (' ', stdout);
  135. }
  136. printf ("0x%02X ", mme_codes [index].code);
  137. printf ("\"%s\"\n", mme_codes [index].text);
  138. }
  139. return;
  140. }
  141. /*====================================================================*
  142. *
  143. * int main (int argc, char * argv[]);
  144. *
  145. * print vendor-specific message codes and names with associated
  146. * error codes and text on stdout; output options are HTML, CSV
  147. * and plain text;
  148. *
  149. *--------------------------------------------------------------------*/
  150. int main (int argc, char const * argv [])
  151. {
  152. static char const * optv [] =
  153. {
  154. "chost",
  155. PUTOPTV_S_DIVINE,
  156. "Qualcomm Atheros vendor-specific message enumerator",
  157. "c\tprint CSV table on stdout",
  158. "h\tprint HTML table on stdout",
  159. "o\tcheck the order of MMECode table",
  160. "s\tprint frame size table on stdout",
  161. "t\tprint TEXT table on stdout",
  162. (char const *) (0)
  163. };
  164. unsigned column = DEFAULT_COLUMN;
  165. unsigned indent = DEFAULT_INDENT;
  166. flag_t flags = (flag_t) (0);
  167. signed c;
  168. optind = 1;
  169. while (~ (c = getoptv (argc, argv, optv)))
  170. {
  171. switch ((char) (c))
  172. {
  173. case 'c':
  174. _setbits (flags, MME_TOCSV);
  175. break;
  176. case 'h':
  177. _setbits (flags, MME_TOHTML);
  178. break;
  179. case 'o':
  180. _setbits (flags, MME_ORDER);
  181. break;
  182. case 's':
  183. _setbits (flags, MME_TOSIZE);
  184. break;
  185. case 't':
  186. _setbits (flags, MME_TOTEXT);
  187. break;
  188. default:
  189. break;
  190. }
  191. }
  192. argc -= optind;
  193. argv += optind;
  194. if (argc)
  195. {
  196. error (1, ENOTSUP, ERROR_TOOMANY);
  197. }
  198. if (_anyset (flags, MME_ORDER))
  199. {
  200. MMETest ();
  201. return (0);
  202. }
  203. if (_anyset (flags, MME_TOSIZE))
  204. {
  205. MMESize ();
  206. return (0);
  207. }
  208. if (_anyset (flags, MME_TOTEXT))
  209. {
  210. mmetotext (column);
  211. return (0);
  212. }
  213. if (_anyset (flags, MME_TOHTML))
  214. {
  215. mmetohtml (indent);
  216. return (0);
  217. }
  218. if (_anyset (flags, MME_TOCSV))
  219. {
  220. mmetocsv ();
  221. return (0);
  222. }
  223. mmetotext (column);
  224. return (0);
  225. }