print-m3ua.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* Copyright (c) 2013, The TCPDUMP project
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright notice, this
  8. * list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright notice,
  10. * this list of conditions and the following disclaimer in the documentation
  11. * and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  20. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. /* \summary: Message Transfer Part 3 (MTP3) User Adaptation Layer (M3UA) printer */
  25. /* RFC 4666 */
  26. #ifdef HAVE_CONFIG_H
  27. #include "config.h"
  28. #endif
  29. #include <netdissect-stdinc.h>
  30. #include "netdissect.h"
  31. #include "extract.h"
  32. static const char tstr[] = " [|m3ua]";
  33. #define M3UA_REL_1_0 1
  34. struct m3ua_common_header {
  35. uint8_t v;
  36. uint8_t reserved;
  37. uint8_t msg_class;
  38. uint8_t msg_type;
  39. uint32_t len;
  40. };
  41. struct m3ua_param_header {
  42. uint16_t tag;
  43. uint16_t len;
  44. };
  45. /* message classes */
  46. #define M3UA_MSGC_MGMT 0
  47. #define M3UA_MSGC_TRANSFER 1
  48. #define M3UA_MSGC_SSNM 2
  49. #define M3UA_MSGC_ASPSM 3
  50. #define M3UA_MSGC_ASPTM 4
  51. /* reserved values */
  52. #define M3UA_MSGC_RKM 9
  53. static const struct tok MessageClasses[] = {
  54. { M3UA_MSGC_MGMT, "Management" },
  55. { M3UA_MSGC_TRANSFER, "Transfer" },
  56. { M3UA_MSGC_SSNM, "SS7" },
  57. { M3UA_MSGC_ASPSM, "ASP" },
  58. { M3UA_MSGC_ASPTM, "ASP" },
  59. { M3UA_MSGC_RKM, "Routing Key Management"},
  60. { 0, NULL }
  61. };
  62. /* management messages */
  63. #define M3UA_MGMT_ERROR 0
  64. #define M3UA_MGMT_NOTIFY 1
  65. static const struct tok MgmtMessages[] = {
  66. { M3UA_MGMT_ERROR, "Error" },
  67. { M3UA_MGMT_NOTIFY, "Notify" },
  68. { 0, NULL }
  69. };
  70. /* transfer messages */
  71. #define M3UA_TRANSFER_DATA 1
  72. static const struct tok TransferMessages[] = {
  73. { M3UA_TRANSFER_DATA, "Data" },
  74. { 0, NULL }
  75. };
  76. /* SS7 Signaling Network Management messages */
  77. #define M3UA_SSNM_DUNA 1
  78. #define M3UA_SSNM_DAVA 2
  79. #define M3UA_SSNM_DAUD 3
  80. #define M3UA_SSNM_SCON 4
  81. #define M3UA_SSNM_DUPU 5
  82. #define M3UA_SSNM_DRST 6
  83. static const struct tok SS7Messages[] = {
  84. { M3UA_SSNM_DUNA, "Destination Unavailable" },
  85. { M3UA_SSNM_DAVA, "Destination Available" },
  86. { M3UA_SSNM_DAUD, "Destination State Audit" },
  87. { M3UA_SSNM_SCON, "Signalling Congestion" },
  88. { M3UA_SSNM_DUPU, "Destination User Part Unavailable" },
  89. { M3UA_SSNM_DRST, "Destination Restricted" },
  90. { 0, NULL }
  91. };
  92. /* ASP State Maintenance messages */
  93. #define M3UA_ASP_UP 1
  94. #define M3UA_ASP_DN 2
  95. #define M3UA_ASP_BEAT 3
  96. #define M3UA_ASP_UP_ACK 4
  97. #define M3UA_ASP_DN_ACK 5
  98. #define M3UA_ASP_BEAT_ACK 6
  99. static const struct tok ASPStateMessages[] = {
  100. { M3UA_ASP_UP, "Up" },
  101. { M3UA_ASP_DN, "Down" },
  102. { M3UA_ASP_BEAT, "Heartbeat" },
  103. { M3UA_ASP_UP_ACK, "Up Acknowledgement" },
  104. { M3UA_ASP_DN_ACK, "Down Acknowledgement" },
  105. { M3UA_ASP_BEAT_ACK, "Heartbeat Acknowledgement" },
  106. { 0, NULL }
  107. };
  108. /* ASP Traffic Maintenance messages */
  109. #define M3UA_ASP_AC 1
  110. #define M3UA_ASP_IA 2
  111. #define M3UA_ASP_AC_ACK 3
  112. #define M3UA_ASP_IA_ACK 4
  113. static const struct tok ASPTrafficMessages[] = {
  114. { M3UA_ASP_AC, "Active" },
  115. { M3UA_ASP_IA, "Inactive" },
  116. { M3UA_ASP_AC_ACK, "Active Acknowledgement" },
  117. { M3UA_ASP_IA_ACK, "Inactive Acknowledgement" },
  118. { 0, NULL }
  119. };
  120. /* Routing Key Management messages */
  121. #define M3UA_RKM_REQ 1
  122. #define M3UA_RKM_RSP 2
  123. #define M3UA_RKM_DEREQ 3
  124. #define M3UA_RKM_DERSP 4
  125. static const struct tok RoutingKeyMgmtMessages[] = {
  126. { M3UA_RKM_REQ, "Registration Request" },
  127. { M3UA_RKM_RSP, "Registration Response" },
  128. { M3UA_RKM_DEREQ, "Deregistration Request" },
  129. { M3UA_RKM_DERSP, "Deregistration Response" },
  130. { 0, NULL }
  131. };
  132. /* M3UA Parameters */
  133. #define M3UA_PARAM_INFO 0x0004
  134. #define M3UA_PARAM_ROUTING_CTX 0x0006
  135. #define M3UA_PARAM_DIAGNOSTIC 0x0007
  136. #define M3UA_PARAM_HB_DATA 0x0009
  137. #define M3UA_PARAM_TRAFFIC_MODE_TYPE 0x000b
  138. #define M3UA_PARAM_ERROR_CODE 0x000c
  139. #define M3UA_PARAM_STATUS 0x000d
  140. #define M3UA_PARAM_ASP_ID 0x0011
  141. #define M3UA_PARAM_AFFECTED_POINT_CODE 0x0012
  142. #define M3UA_PARAM_CORR_ID 0x0013
  143. #define M3UA_PARAM_NETWORK_APPEARANCE 0x0200
  144. #define M3UA_PARAM_USER 0x0204
  145. #define M3UA_PARAM_CONGESTION_INDICATION 0x0205
  146. #define M3UA_PARAM_CONCERNED_DST 0x0206
  147. #define M3UA_PARAM_ROUTING_KEY 0x0207
  148. #define M3UA_PARAM_REG_RESULT 0x0208
  149. #define M3UA_PARAM_DEREG_RESULT 0x0209
  150. #define M3UA_PARAM_LOCAL_ROUTING_KEY_ID 0x020a
  151. #define M3UA_PARAM_DST_POINT_CODE 0x020b
  152. #define M3UA_PARAM_SI 0x020c
  153. #define M3UA_PARAM_ORIGIN_POINT_CODE_LIST 0x020e
  154. #define M3UA_PARAM_PROTO_DATA 0x0210
  155. #define M3UA_PARAM_REG_STATUS 0x0212
  156. #define M3UA_PARAM_DEREG_STATUS 0x0213
  157. static const struct tok ParamName[] = {
  158. { M3UA_PARAM_INFO, "INFO String" },
  159. { M3UA_PARAM_ROUTING_CTX, "Routing Context" },
  160. { M3UA_PARAM_DIAGNOSTIC, "Diagnostic Info" },
  161. { M3UA_PARAM_HB_DATA, "Heartbeat Data" },
  162. { M3UA_PARAM_TRAFFIC_MODE_TYPE, "Traffic Mode Type" },
  163. { M3UA_PARAM_ERROR_CODE, "Error Code" },
  164. { M3UA_PARAM_STATUS, "Status" },
  165. { M3UA_PARAM_ASP_ID, "ASP Identifier" },
  166. { M3UA_PARAM_AFFECTED_POINT_CODE, "Affected Point Code" },
  167. { M3UA_PARAM_CORR_ID, "Correlation ID" },
  168. { M3UA_PARAM_NETWORK_APPEARANCE, "Network Appearance" },
  169. { M3UA_PARAM_USER, "User/Cause" },
  170. { M3UA_PARAM_CONGESTION_INDICATION, "Congestion Indications" },
  171. { M3UA_PARAM_CONCERNED_DST, "Concerned Destination" },
  172. { M3UA_PARAM_ROUTING_KEY, "Routing Key" },
  173. { M3UA_PARAM_REG_RESULT, "Registration Result" },
  174. { M3UA_PARAM_DEREG_RESULT, "Deregistration Result" },
  175. { M3UA_PARAM_LOCAL_ROUTING_KEY_ID, "Local Routing Key Identifier" },
  176. { M3UA_PARAM_DST_POINT_CODE, "Destination Point Code" },
  177. { M3UA_PARAM_SI, "Service Indicators" },
  178. { M3UA_PARAM_ORIGIN_POINT_CODE_LIST, "Originating Point Code List" },
  179. { M3UA_PARAM_PROTO_DATA, "Protocol Data" },
  180. { M3UA_PARAM_REG_STATUS, "Registration Status" },
  181. { M3UA_PARAM_DEREG_STATUS, "Deregistration Status" },
  182. { 0, NULL }
  183. };
  184. static void
  185. tag_value_print(netdissect_options *ndo,
  186. const u_char *buf, const uint16_t tag, const uint16_t size)
  187. {
  188. switch (tag) {
  189. case M3UA_PARAM_NETWORK_APPEARANCE:
  190. case M3UA_PARAM_ROUTING_CTX:
  191. case M3UA_PARAM_CORR_ID:
  192. /* buf and size don't include the header */
  193. if (size < 4)
  194. goto invalid;
  195. ND_TCHECK2(*buf, size);
  196. ND_PRINT((ndo, "0x%08x", EXTRACT_32BITS(buf)));
  197. break;
  198. /* ... */
  199. default:
  200. ND_PRINT((ndo, "(length %u)", size + (u_int)sizeof(struct m3ua_param_header)));
  201. ND_TCHECK2(*buf, size);
  202. }
  203. return;
  204. invalid:
  205. ND_PRINT((ndo, "%s", istr));
  206. ND_TCHECK2(*buf, size);
  207. return;
  208. trunc:
  209. ND_PRINT((ndo, "%s", tstr));
  210. }
  211. /*
  212. * 0 1 2 3
  213. * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  214. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  215. * | Parameter Tag | Parameter Length |
  216. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  217. * \ \
  218. * / Parameter Value /
  219. * \ \
  220. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  221. */
  222. static void
  223. m3ua_tags_print(netdissect_options *ndo,
  224. const u_char *buf, const u_int size)
  225. {
  226. const u_char *p = buf;
  227. int align;
  228. uint16_t hdr_tag;
  229. uint16_t hdr_len;
  230. while (p < buf + size) {
  231. if (p + sizeof(struct m3ua_param_header) > buf + size)
  232. goto invalid;
  233. ND_TCHECK2(*p, sizeof(struct m3ua_param_header));
  234. /* Parameter Tag */
  235. hdr_tag = EXTRACT_16BITS(p);
  236. ND_PRINT((ndo, "\n\t\t\t%s: ", tok2str(ParamName, "Unknown Parameter (0x%04x)", hdr_tag)));
  237. /* Parameter Length */
  238. hdr_len = EXTRACT_16BITS(p + 2);
  239. if (hdr_len < sizeof(struct m3ua_param_header))
  240. goto invalid;
  241. /* Parameter Value */
  242. align = (p + hdr_len - buf) % 4;
  243. align = align ? 4 - align : 0;
  244. ND_TCHECK2(*p, hdr_len + align);
  245. tag_value_print(ndo, p, hdr_tag, hdr_len - sizeof(struct m3ua_param_header));
  246. p += hdr_len + align;
  247. }
  248. return;
  249. invalid:
  250. ND_PRINT((ndo, "%s", istr));
  251. ND_TCHECK2(*buf, size);
  252. return;
  253. trunc:
  254. ND_PRINT((ndo, "%s", tstr));
  255. }
  256. /*
  257. * 0 1 2 3
  258. * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  259. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  260. * | Version | Reserved | Message Class | Message Type |
  261. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  262. * | Message Length |
  263. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  264. * \ \
  265. * / /
  266. */
  267. void
  268. m3ua_print(netdissect_options *ndo,
  269. const u_char *buf, const u_int size)
  270. {
  271. const struct m3ua_common_header *hdr = (const struct m3ua_common_header *) buf;
  272. const struct tok *dict;
  273. /* size includes the header */
  274. if (size < sizeof(struct m3ua_common_header))
  275. goto invalid;
  276. ND_TCHECK(*hdr);
  277. if (hdr->v != M3UA_REL_1_0)
  278. return;
  279. dict =
  280. hdr->msg_class == M3UA_MSGC_MGMT ? MgmtMessages :
  281. hdr->msg_class == M3UA_MSGC_TRANSFER ? TransferMessages :
  282. hdr->msg_class == M3UA_MSGC_SSNM ? SS7Messages :
  283. hdr->msg_class == M3UA_MSGC_ASPSM ? ASPStateMessages :
  284. hdr->msg_class == M3UA_MSGC_ASPTM ? ASPTrafficMessages :
  285. hdr->msg_class == M3UA_MSGC_RKM ? RoutingKeyMgmtMessages :
  286. NULL;
  287. ND_PRINT((ndo, "\n\t\t%s", tok2str(MessageClasses, "Unknown message class %i", hdr->msg_class)));
  288. if (dict != NULL)
  289. ND_PRINT((ndo, " %s Message", tok2str(dict, "Unknown (0x%02x)", hdr->msg_type)));
  290. if (size != EXTRACT_32BITS(&hdr->len))
  291. ND_PRINT((ndo, "\n\t\t\t@@@@@@ Corrupted length %u of message @@@@@@", EXTRACT_32BITS(&hdr->len)));
  292. else
  293. m3ua_tags_print(ndo, buf + sizeof(struct m3ua_common_header), EXTRACT_32BITS(&hdr->len) - sizeof(struct m3ua_common_header));
  294. return;
  295. invalid:
  296. ND_PRINT((ndo, "%s", istr));
  297. ND_TCHECK2(*buf, size);
  298. return;
  299. trunc:
  300. ND_PRINT((ndo, "%s", tstr));
  301. }