]> The Tcpdump Group git mirrors - tcpdump/blob - print-m3ua.c
e38e8769cefe4d80c517101d2586bd3e396d588b
[tcpdump] / print-m3ua.c
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
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <tcpdump-stdinc.h>
30 #include "m3ua.h"
31
32 #include "interface.h"
33 #include "addrtoname.h"
34 #include "extract.h"
35
36 static const struct tok MgmtMessages[] = {
37 { M3UA_MGMT_ERROR, "Error" },
38 { M3UA_MGMT_NOTIFY, "Notify" },
39 { 0, NULL }
40 };
41
42 static const struct tok TransferMessages[] = {
43 { M3UA_TRANSFER_DATA, "Data" },
44 { 0, NULL }
45 };
46
47 static const struct tok SS7Messages[] = {
48 { M3UA_SSNM_DUNA, "Destination Unavailable" },
49 { M3UA_SSNM_DAVA, "Destination Available" },
50 { M3UA_SSNM_DAUD, "Destination State Audit" },
51 { M3UA_SSNM_SCON, "Signalling Congestion" },
52 { M3UA_SSNM_DUPU, "Destination User Part Unavailable" },
53 { M3UA_SSNM_DRST, "Destination Restricted" },
54 { 0, NULL }
55 };
56
57 static const struct tok ASPStateMessages[] = {
58 { M3UA_ASP_UP, "Up" },
59 { M3UA_ASP_DN, "Down" },
60 { M3UA_ASP_BEAT, "Heartbeat" },
61 { M3UA_ASP_UP_ACK, "Up Acknowledgement" },
62 { M3UA_ASP_DN_ACK, "Down Acknowledgement" },
63 { M3UA_ASP_BEAT_ACK, "Heartbeat Acknowledgement" },
64 { 0, NULL }
65 };
66
67 static const struct tok ASPTrafficMessages[] = {
68 { M3UA_ASP_AC, "Active" },
69 { M3UA_ASP_IA, "Inactive" },
70 { M3UA_ASP_AC_ACK, "Active Acknowledgement" },
71 { M3UA_ASP_IA_ACK, "Inactive Acknowledgement" },
72 { 0, NULL }
73 };
74
75 static const struct tok RoutingKeyMgmtMessages[] = {
76 { M3UA_RKM_REQ, "Registration Request" },
77 { M3UA_RKM_RSP, "Registration Response" },
78 { M3UA_RKM_DEREQ, "Deregistration Request" },
79 { M3UA_RKM_DERSP, "Deregistration Response" },
80 { 0, NULL }
81 };
82
83 static const struct tok ParamName[] = {
84 { M3UA_PARAM_INFO, "INFO String" },
85 { M3UA_PARAM_ROUTING_CTX, "Routing Context" },
86 { M3UA_PARAM_DIAGNOSTIC, "Diagnostic Info" },
87 { M3UA_PARAM_HB_DATA, "Heartbeat Data" },
88 { M3UA_PARAM_TRAFFIC_MODE_TYPE, "Traffic Mode Type" },
89 { M3UA_PARAM_ERROR_CODE, "Error Code" },
90 { M3UA_PARAM_STATUS, "Status" },
91 { M3UA_PARAM_ASP_ID, "ASP Identifier" },
92 { M3UA_PARAM_AFFECTED_POINT_CODE, "Affected Point Code" },
93 { M3UA_PARAM_CORR_ID, "Correlation ID" },
94 { M3UA_PARAM_NETWORK_APPEARANCE, "Network Appearance" },
95 { M3UA_PARAM_USER, "User/Cause" },
96 { M3UA_PARAM_CONGESTION_INDICATION, "Congestion Indications" },
97 { M3UA_PARAM_CONCERNED_DST, "Concerned Destination" },
98 { M3UA_PARAM_ROUTING_KEY, "Routing Key" },
99 { M3UA_PARAM_REG_RESULT, "Registration Result" },
100 { M3UA_PARAM_DEREG_RESULT, "Deregistration Result" },
101 { M3UA_PARAM_LOCAL_ROUTING_KEY_ID, "Local Routing Key Identifier" },
102 { M3UA_PARAM_DST_POINT_CODE, "Destination Point Code" },
103 { M3UA_PARAM_SI, "Service Indicators" },
104 { M3UA_PARAM_ORIGIN_POINT_CODE_LIST, "Originating Point Code List" },
105 { M3UA_PARAM_PROTO_DATA, "Protocol Data" },
106 { M3UA_PARAM_REG_STATUS, "Registration Status" },
107 { M3UA_PARAM_DEREG_STATUS, "Deregistration Status" },
108 { 0, NULL }
109 };
110
111 static void print_tag_value(const u_char *buf, u_int16_t tag, u_int16_t size)
112 {
113 switch (tag) {
114 case M3UA_PARAM_NETWORK_APPEARANCE:
115 case M3UA_PARAM_ROUTING_CTX:
116 case M3UA_PARAM_CORR_ID:
117 printf("0x%08x", EXTRACT_32BITS(buf));
118 break;
119 /* ... */
120 default:
121 printf("(length %u)", size);
122 }
123 }
124
125 static void print_m3ua_tags(const u_char *buf, u_int size)
126 {
127 const u_char *p = buf;
128 while (p < buf + size) {
129 const struct m3ua_param_header *hdr = (const struct m3ua_param_header *) p;
130 printf("\n\t\t\t%s: ", tok2str(ParamName, "Unknown Parameter (0x%04x)", EXTRACT_16BITS(&hdr->tag)));
131 print_tag_value(p + sizeof(struct m3ua_param_header), EXTRACT_16BITS(&hdr->tag), EXTRACT_16BITS(&hdr->len));
132 p += EXTRACT_16BITS(&hdr->len);
133 int align = (int) (p - buf) % 4;
134 p += (align) ? 4 - align : 0;
135 }
136 }
137
138 void print_m3ua(const u_char *buf, u_int size)
139 {
140 const struct m3ua_common_header *hdr = (const struct m3ua_common_header *) buf;
141
142 printf("\n\t\t");
143 switch (hdr->msg_class) {
144 case M3UA_MSGC_MGMT:
145 printf("Management %s Message", tok2str(MgmtMessages, "Unknown (0x%02x)", hdr->msg_type));
146 break;
147 case M3UA_MSGC_TRANSFER:
148 printf("Transfer %s Message", tok2str(TransferMessages, "Unknown (0x%02x)", hdr->msg_type));
149 break;
150 case M3UA_MSGC_SSNM:
151 printf("SS7 %s Message", tok2str(SS7Messages, "Unknown (0x%02x)", hdr->msg_type));
152 break;
153 case M3UA_MSGC_ASPSM:
154 printf("ASP %s Message", tok2str(ASPStateMessages, "Unknown (0x%02x)", hdr->msg_type));
155 break;
156 case M3UA_MSGC_ASPTM:
157 printf("ASP %s Message", tok2str(ASPTrafficMessages, "Unknown (0x%02x)", hdr->msg_type));
158 break;
159 case M3UA_MSGC_RKM:
160 printf("Routing Key Managment %s Message",
161 tok2str(RoutingKeyMgmtMessages, "Unknown (0x%02x)", hdr->msg_type));
162 break;
163 default:
164 printf("Unknown message class %i", hdr->msg_class);
165 break;
166 };
167
168 fflush(stdout);
169
170 if (size != EXTRACT_32BITS(&hdr->len))
171 printf("\n\t\t\t@@@@@@ Corrupted length %u of message @@@@@@", EXTRACT_32BITS(&hdr->len));
172 else
173 print_m3ua_tags(buf + sizeof(struct m3ua_common_header), EXTRACT_32BITS(&hdr->len) - sizeof(struct m3ua_common_header));
174 }
175