print-mpcp.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Copyright (c) 1998-2006 The TCPDUMP project
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that: (1) source code
  6. * distributions retain the above copyright notice and this paragraph
  7. * in its entirety, and (2) distributions including binary code include
  8. * the above copyright notice and this paragraph in its entirety in
  9. * the documentation or other materials provided with the distribution.
  10. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  11. * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
  12. * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  13. * FOR A PARTICULAR PURPOSE.
  14. *
  15. * Original code by Hannes Gredler (hannes@gredler.at)
  16. */
  17. /* \summary: IEEE 802.3ah Multi-Point Control Protocol (MPCP) printer */
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include <netdissect-stdinc.h>
  22. #include "netdissect.h"
  23. #include "extract.h"
  24. #define MPCP_TIMESTAMP_LEN 4
  25. #define MPCP_TIMESTAMP_DURATION_LEN 2
  26. struct mpcp_common_header_t {
  27. uint8_t opcode[2];
  28. uint8_t timestamp[MPCP_TIMESTAMP_LEN];
  29. };
  30. #define MPCP_OPCODE_PAUSE 0x0001
  31. #define MPCP_OPCODE_GATE 0x0002
  32. #define MPCP_OPCODE_REPORT 0x0003
  33. #define MPCP_OPCODE_REG_REQ 0x0004
  34. #define MPCP_OPCODE_REG 0x0005
  35. #define MPCP_OPCODE_REG_ACK 0x0006
  36. static const struct tok mpcp_opcode_values[] = {
  37. { MPCP_OPCODE_PAUSE, "Pause" },
  38. { MPCP_OPCODE_GATE, "Gate" },
  39. { MPCP_OPCODE_REPORT, "Report" },
  40. { MPCP_OPCODE_REG_REQ, "Register Request" },
  41. { MPCP_OPCODE_REG, "Register" },
  42. { MPCP_OPCODE_REG_ACK, "Register ACK" },
  43. { 0, NULL}
  44. };
  45. #define MPCP_GRANT_NUMBER_LEN 1
  46. #define MPCP_GRANT_NUMBER_MASK 0x7
  47. static const struct tok mpcp_grant_flag_values[] = {
  48. { 0x08, "Discovery" },
  49. { 0x10, "Force Grant #1" },
  50. { 0x20, "Force Grant #2" },
  51. { 0x40, "Force Grant #3" },
  52. { 0x80, "Force Grant #4" },
  53. { 0, NULL}
  54. };
  55. struct mpcp_grant_t {
  56. uint8_t starttime[MPCP_TIMESTAMP_LEN];
  57. uint8_t duration[MPCP_TIMESTAMP_DURATION_LEN];
  58. };
  59. struct mpcp_reg_req_t {
  60. uint8_t flags;
  61. uint8_t pending_grants;
  62. };
  63. static const struct tok mpcp_reg_req_flag_values[] = {
  64. { 1, "Register" },
  65. { 3, "De-Register" },
  66. { 0, NULL}
  67. };
  68. struct mpcp_reg_t {
  69. uint8_t assigned_port[2];
  70. uint8_t flags;
  71. uint8_t sync_time[MPCP_TIMESTAMP_DURATION_LEN];
  72. uint8_t echoed_pending_grants;
  73. };
  74. static const struct tok mpcp_reg_flag_values[] = {
  75. { 1, "Re-Register" },
  76. { 2, "De-Register" },
  77. { 3, "ACK" },
  78. { 4, "NACK" },
  79. { 0, NULL}
  80. };
  81. #define MPCP_REPORT_QUEUESETS_LEN 1
  82. #define MPCP_REPORT_REPORTBITMAP_LEN 1
  83. static const struct tok mpcp_report_bitmap_values[] = {
  84. { 0x01, "Q0" },
  85. { 0x02, "Q1" },
  86. { 0x04, "Q2" },
  87. { 0x08, "Q3" },
  88. { 0x10, "Q4" },
  89. { 0x20, "Q5" },
  90. { 0x40, "Q6" },
  91. { 0x80, "Q7" },
  92. { 0, NULL}
  93. };
  94. struct mpcp_reg_ack_t {
  95. uint8_t flags;
  96. uint8_t echoed_assigned_port[2];
  97. uint8_t echoed_sync_time[MPCP_TIMESTAMP_DURATION_LEN];
  98. };
  99. static const struct tok mpcp_reg_ack_flag_values[] = {
  100. { 0, "NACK" },
  101. { 1, "ACK" },
  102. { 0, NULL}
  103. };
  104. void
  105. mpcp_print(netdissect_options *ndo, register const u_char *pptr, register u_int length)
  106. {
  107. union {
  108. const struct mpcp_common_header_t *common_header;
  109. const struct mpcp_grant_t *grant;
  110. const struct mpcp_reg_req_t *reg_req;
  111. const struct mpcp_reg_t *reg;
  112. const struct mpcp_reg_ack_t *reg_ack;
  113. } mpcp;
  114. const u_char *tptr;
  115. uint16_t opcode;
  116. uint8_t grant_numbers, grant;
  117. uint8_t queue_sets, queue_set, report_bitmap, report;
  118. tptr=pptr;
  119. mpcp.common_header = (const struct mpcp_common_header_t *)pptr;
  120. ND_TCHECK2(*tptr, sizeof(const struct mpcp_common_header_t));
  121. opcode = EXTRACT_16BITS(mpcp.common_header->opcode);
  122. ND_PRINT((ndo, "MPCP, Opcode %s", tok2str(mpcp_opcode_values, "Unknown (%u)", opcode)));
  123. if (opcode != MPCP_OPCODE_PAUSE) {
  124. ND_PRINT((ndo, ", Timestamp %u ticks", EXTRACT_32BITS(mpcp.common_header->timestamp)));
  125. }
  126. ND_PRINT((ndo, ", length %u", length));
  127. if (!ndo->ndo_vflag)
  128. return;
  129. tptr += sizeof(const struct mpcp_common_header_t);
  130. switch (opcode) {
  131. case MPCP_OPCODE_PAUSE:
  132. break;
  133. case MPCP_OPCODE_GATE:
  134. ND_TCHECK2(*tptr, MPCP_GRANT_NUMBER_LEN);
  135. grant_numbers = *tptr & MPCP_GRANT_NUMBER_MASK;
  136. ND_PRINT((ndo, "\n\tGrant Numbers %u, Flags [ %s ]",
  137. grant_numbers,
  138. bittok2str(mpcp_grant_flag_values,
  139. "?",
  140. *tptr &~ MPCP_GRANT_NUMBER_MASK)));
  141. tptr++;
  142. for (grant = 1; grant <= grant_numbers; grant++) {
  143. ND_TCHECK2(*tptr, sizeof(const struct mpcp_grant_t));
  144. mpcp.grant = (const struct mpcp_grant_t *)tptr;
  145. ND_PRINT((ndo, "\n\tGrant #%u, Start-Time %u ticks, duration %u ticks",
  146. grant,
  147. EXTRACT_32BITS(mpcp.grant->starttime),
  148. EXTRACT_16BITS(mpcp.grant->duration)));
  149. tptr += sizeof(const struct mpcp_grant_t);
  150. }
  151. ND_TCHECK2(*tptr, MPCP_TIMESTAMP_DURATION_LEN);
  152. ND_PRINT((ndo, "\n\tSync-Time %u ticks", EXTRACT_16BITS(tptr)));
  153. break;
  154. case MPCP_OPCODE_REPORT:
  155. ND_TCHECK2(*tptr, MPCP_REPORT_QUEUESETS_LEN);
  156. queue_sets = *tptr;
  157. tptr+=MPCP_REPORT_QUEUESETS_LEN;
  158. ND_PRINT((ndo, "\n\tTotal Queue-Sets %u", queue_sets));
  159. for (queue_set = 1; queue_set < queue_sets; queue_set++) {
  160. ND_TCHECK2(*tptr, MPCP_REPORT_REPORTBITMAP_LEN);
  161. report_bitmap = *(tptr);
  162. ND_PRINT((ndo, "\n\t Queue-Set #%u, Report-Bitmap [ %s ]",
  163. queue_sets,
  164. bittok2str(mpcp_report_bitmap_values, "Unknown", report_bitmap)));
  165. tptr++;
  166. report=1;
  167. while (report_bitmap != 0) {
  168. if (report_bitmap & 1) {
  169. ND_TCHECK2(*tptr, MPCP_TIMESTAMP_DURATION_LEN);
  170. ND_PRINT((ndo, "\n\t Q%u Report, Duration %u ticks",
  171. report,
  172. EXTRACT_16BITS(tptr)));
  173. tptr+=MPCP_TIMESTAMP_DURATION_LEN;
  174. }
  175. report++;
  176. report_bitmap = report_bitmap >> 1;
  177. }
  178. }
  179. break;
  180. case MPCP_OPCODE_REG_REQ:
  181. ND_TCHECK2(*tptr, sizeof(const struct mpcp_reg_req_t));
  182. mpcp.reg_req = (const struct mpcp_reg_req_t *)tptr;
  183. ND_PRINT((ndo, "\n\tFlags [ %s ], Pending-Grants %u",
  184. bittok2str(mpcp_reg_req_flag_values, "Reserved", mpcp.reg_req->flags),
  185. mpcp.reg_req->pending_grants));
  186. break;
  187. case MPCP_OPCODE_REG:
  188. ND_TCHECK2(*tptr, sizeof(const struct mpcp_reg_t));
  189. mpcp.reg = (const struct mpcp_reg_t *)tptr;
  190. ND_PRINT((ndo, "\n\tAssigned-Port %u, Flags [ %s ]" \
  191. "\n\tSync-Time %u ticks, Echoed-Pending-Grants %u",
  192. EXTRACT_16BITS(mpcp.reg->assigned_port),
  193. bittok2str(mpcp_reg_flag_values, "Reserved", mpcp.reg->flags),
  194. EXTRACT_16BITS(mpcp.reg->sync_time),
  195. mpcp.reg->echoed_pending_grants));
  196. break;
  197. case MPCP_OPCODE_REG_ACK:
  198. ND_TCHECK2(*tptr, sizeof(const struct mpcp_reg_ack_t));
  199. mpcp.reg_ack = (const struct mpcp_reg_ack_t *)tptr;
  200. ND_PRINT((ndo, "\n\tEchoed-Assigned-Port %u, Flags [ %s ]" \
  201. "\n\tEchoed-Sync-Time %u ticks",
  202. EXTRACT_16BITS(mpcp.reg_ack->echoed_assigned_port),
  203. bittok2str(mpcp_reg_ack_flag_values, "Reserved", mpcp.reg_ack->flags),
  204. EXTRACT_16BITS(mpcp.reg_ack->echoed_sync_time)));
  205. break;
  206. default:
  207. /* unknown opcode - hexdump for now */
  208. print_unknown_data(ndo,pptr, "\n\t", length);
  209. break;
  210. }
  211. return;
  212. trunc:
  213. ND_PRINT((ndo, "\n\t[|MPCP]"));
  214. }
  215. /*
  216. * Local Variables:
  217. * c-style: whitesmith
  218. * c-basic-offset: 8
  219. * End:
  220. */