]> The Tcpdump Group git mirrors - tcpdump/blob - print-m3ua.c
Merge branch 'kivinen-master'
[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 /* \summary: Message Transfer Part 3 (MTP3) User Adaptation Layer (M3UA) printer */
26
27 /* RFC 4666 */
28
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32
33 #include "netdissect-stdinc.h"
34
35 #include "netdissect.h"
36 #include "extract.h"
37
38
39 #define M3UA_REL_1_0 1
40
41 struct m3ua_common_header {
42 nd_uint8_t v;
43 nd_uint8_t reserved;
44 nd_uint8_t msg_class;
45 nd_uint8_t msg_type;
46 nd_uint32_t len;
47 };
48
49 struct m3ua_param_header {
50 nd_uint16_t tag;
51 nd_uint16_t len;
52 };
53
54 /* message classes */
55 #define M3UA_MSGC_MGMT 0
56 #define M3UA_MSGC_TRANSFER 1
57 #define M3UA_MSGC_SSNM 2
58 #define M3UA_MSGC_ASPSM 3
59 #define M3UA_MSGC_ASPTM 4
60 /* reserved values */
61 #define M3UA_MSGC_RKM 9
62
63 static const struct tok MessageClasses[] = {
64 { M3UA_MSGC_MGMT, "Management" },
65 { M3UA_MSGC_TRANSFER, "Transfer" },
66 { M3UA_MSGC_SSNM, "SS7" },
67 { M3UA_MSGC_ASPSM, "ASP" },
68 { M3UA_MSGC_ASPTM, "ASP" },
69 { M3UA_MSGC_RKM, "Routing Key Management"},
70 { 0, NULL }
71 };
72
73 /* management messages */
74 #define M3UA_MGMT_ERROR 0
75 #define M3UA_MGMT_NOTIFY 1
76
77 static const struct tok MgmtMessages[] = {
78 { M3UA_MGMT_ERROR, "Error" },
79 { M3UA_MGMT_NOTIFY, "Notify" },
80 { 0, NULL }
81 };
82
83 /* transfer messages */
84 #define M3UA_TRANSFER_DATA 1
85
86 static const struct tok TransferMessages[] = {
87 { M3UA_TRANSFER_DATA, "Data" },
88 { 0, NULL }
89 };
90
91 /* SS7 Signaling Network Management messages */
92 #define M3UA_SSNM_DUNA 1
93 #define M3UA_SSNM_DAVA 2
94 #define M3UA_SSNM_DAUD 3
95 #define M3UA_SSNM_SCON 4
96 #define M3UA_SSNM_DUPU 5
97 #define M3UA_SSNM_DRST 6
98
99 static const struct tok SS7Messages[] = {
100 { M3UA_SSNM_DUNA, "Destination Unavailable" },
101 { M3UA_SSNM_DAVA, "Destination Available" },
102 { M3UA_SSNM_DAUD, "Destination State Audit" },
103 { M3UA_SSNM_SCON, "Signalling Congestion" },
104 { M3UA_SSNM_DUPU, "Destination User Part Unavailable" },
105 { M3UA_SSNM_DRST, "Destination Restricted" },
106 { 0, NULL }
107 };
108
109 /* ASP State Maintenance messages */
110 #define M3UA_ASP_UP 1
111 #define M3UA_ASP_DN 2
112 #define M3UA_ASP_BEAT 3
113 #define M3UA_ASP_UP_ACK 4
114 #define M3UA_ASP_DN_ACK 5
115 #define M3UA_ASP_BEAT_ACK 6
116
117 static const struct tok ASPStateMessages[] = {
118 { M3UA_ASP_UP, "Up" },
119 { M3UA_ASP_DN, "Down" },
120 { M3UA_ASP_BEAT, "Heartbeat" },
121 { M3UA_ASP_UP_ACK, "Up Acknowledgement" },
122 { M3UA_ASP_DN_ACK, "Down Acknowledgement" },
123 { M3UA_ASP_BEAT_ACK, "Heartbeat Acknowledgement" },
124 { 0, NULL }
125 };
126
127 /* ASP Traffic Maintenance messages */
128 #define M3UA_ASP_AC 1
129 #define M3UA_ASP_IA 2
130 #define M3UA_ASP_AC_ACK 3
131 #define M3UA_ASP_IA_ACK 4
132
133 static const struct tok ASPTrafficMessages[] = {
134 { M3UA_ASP_AC, "Active" },
135 { M3UA_ASP_IA, "Inactive" },
136 { M3UA_ASP_AC_ACK, "Active Acknowledgement" },
137 { M3UA_ASP_IA_ACK, "Inactive Acknowledgement" },
138 { 0, NULL }
139 };
140
141 /* Routing Key Management messages */
142 #define M3UA_RKM_REQ 1
143 #define M3UA_RKM_RSP 2
144 #define M3UA_RKM_DEREQ 3
145 #define M3UA_RKM_DERSP 4
146
147 static const struct tok RoutingKeyMgmtMessages[] = {
148 { M3UA_RKM_REQ, "Registration Request" },
149 { M3UA_RKM_RSP, "Registration Response" },
150 { M3UA_RKM_DEREQ, "Deregistration Request" },
151 { M3UA_RKM_DERSP, "Deregistration Response" },
152 { 0, NULL }
153 };
154
155 /* M3UA Parameters */
156 #define M3UA_PARAM_INFO 0x0004
157 #define M3UA_PARAM_ROUTING_CTX 0x0006
158 #define M3UA_PARAM_DIAGNOSTIC 0x0007
159 #define M3UA_PARAM_HB_DATA 0x0009
160 #define M3UA_PARAM_TRAFFIC_MODE_TYPE 0x000b
161 #define M3UA_PARAM_ERROR_CODE 0x000c
162 #define M3UA_PARAM_STATUS 0x000d
163 #define M3UA_PARAM_ASP_ID 0x0011
164 #define M3UA_PARAM_AFFECTED_POINT_CODE 0x0012
165 #define M3UA_PARAM_CORR_ID 0x0013
166
167 #define M3UA_PARAM_NETWORK_APPEARANCE 0x0200
168 #define M3UA_PARAM_USER 0x0204
169 #define M3UA_PARAM_CONGESTION_INDICATION 0x0205
170 #define M3UA_PARAM_CONCERNED_DST 0x0206
171 #define M3UA_PARAM_ROUTING_KEY 0x0207
172 #define M3UA_PARAM_REG_RESULT 0x0208
173 #define M3UA_PARAM_DEREG_RESULT 0x0209
174 #define M3UA_PARAM_LOCAL_ROUTING_KEY_ID 0x020a
175 #define M3UA_PARAM_DST_POINT_CODE 0x020b
176 #define M3UA_PARAM_SI 0x020c
177 #define M3UA_PARAM_ORIGIN_POINT_CODE_LIST 0x020e
178 #define M3UA_PARAM_PROTO_DATA 0x0210
179 #define M3UA_PARAM_REG_STATUS 0x0212
180 #define M3UA_PARAM_DEREG_STATUS 0x0213
181
182 static const struct tok ParamName[] = {
183 { M3UA_PARAM_INFO, "INFO String" },
184 { M3UA_PARAM_ROUTING_CTX, "Routing Context" },
185 { M3UA_PARAM_DIAGNOSTIC, "Diagnostic Info" },
186 { M3UA_PARAM_HB_DATA, "Heartbeat Data" },
187 { M3UA_PARAM_TRAFFIC_MODE_TYPE, "Traffic Mode Type" },
188 { M3UA_PARAM_ERROR_CODE, "Error Code" },
189 { M3UA_PARAM_STATUS, "Status" },
190 { M3UA_PARAM_ASP_ID, "ASP Identifier" },
191 { M3UA_PARAM_AFFECTED_POINT_CODE, "Affected Point Code" },
192 { M3UA_PARAM_CORR_ID, "Correlation ID" },
193 { M3UA_PARAM_NETWORK_APPEARANCE, "Network Appearance" },
194 { M3UA_PARAM_USER, "User/Cause" },
195 { M3UA_PARAM_CONGESTION_INDICATION, "Congestion Indications" },
196 { M3UA_PARAM_CONCERNED_DST, "Concerned Destination" },
197 { M3UA_PARAM_ROUTING_KEY, "Routing Key" },
198 { M3UA_PARAM_REG_RESULT, "Registration Result" },
199 { M3UA_PARAM_DEREG_RESULT, "Deregistration Result" },
200 { M3UA_PARAM_LOCAL_ROUTING_KEY_ID, "Local Routing Key Identifier" },
201 { M3UA_PARAM_DST_POINT_CODE, "Destination Point Code" },
202 { M3UA_PARAM_SI, "Service Indicators" },
203 { M3UA_PARAM_ORIGIN_POINT_CODE_LIST, "Originating Point Code List" },
204 { M3UA_PARAM_PROTO_DATA, "Protocol Data" },
205 { M3UA_PARAM_REG_STATUS, "Registration Status" },
206 { M3UA_PARAM_DEREG_STATUS, "Deregistration Status" },
207 { 0, NULL }
208 };
209
210 static void
211 tag_value_print(netdissect_options *ndo,
212 const u_char *buf, const uint16_t tag, const uint16_t size)
213 {
214 switch (tag) {
215 case M3UA_PARAM_NETWORK_APPEARANCE:
216 case M3UA_PARAM_ROUTING_CTX:
217 case M3UA_PARAM_CORR_ID:
218 /* buf and size don't include the header */
219 if (size < 4)
220 goto invalid;
221 ND_TCHECK_LEN(buf, size);
222 ND_PRINT("0x%08x", EXTRACT_BE_U_4(buf));
223 break;
224 /* ... */
225 default:
226 ND_PRINT("(length %u)", size + (u_int)sizeof(struct m3ua_param_header));
227 ND_TCHECK_LEN(buf, size);
228 }
229 return;
230
231 invalid:
232 nd_print_invalid(ndo);
233 ND_TCHECK_LEN(buf, size);
234 return;
235 trunc:
236 nd_print_trunc(ndo);
237 }
238
239 /*
240 * 0 1 2 3
241 * 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
242 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
243 * | Parameter Tag | Parameter Length |
244 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
245 * \ \
246 * / Parameter Value /
247 * \ \
248 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
249 */
250 static void
251 m3ua_tags_print(netdissect_options *ndo,
252 const u_char *buf, const u_int size)
253 {
254 const u_char *p = buf;
255 int align;
256 uint16_t hdr_tag;
257 uint16_t hdr_len;
258
259 while (p < buf + size) {
260 if (p + sizeof(struct m3ua_param_header) > buf + size)
261 goto invalid;
262 ND_TCHECK_LEN(p, sizeof(struct m3ua_param_header));
263 /* Parameter Tag */
264 hdr_tag = EXTRACT_BE_U_2(p);
265 ND_PRINT("\n\t\t\t%s: ", tok2str(ParamName, "Unknown Parameter (0x%04x)", hdr_tag));
266 /* Parameter Length */
267 hdr_len = EXTRACT_BE_U_2(p + 2);
268 if (hdr_len < sizeof(struct m3ua_param_header))
269 goto invalid;
270 /* Parameter Value */
271 align = (p + hdr_len - buf) % 4;
272 align = align ? 4 - align : 0;
273 ND_TCHECK_LEN(p, hdr_len + align);
274 tag_value_print(ndo, p, hdr_tag, hdr_len - sizeof(struct m3ua_param_header));
275 p += hdr_len + align;
276 }
277 return;
278
279 invalid:
280 nd_print_invalid(ndo);
281 ND_TCHECK_LEN(buf, size);
282 return;
283 trunc:
284 nd_print_trunc(ndo);
285 }
286
287 /*
288 * 0 1 2 3
289 * 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
290 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
291 * | Version | Reserved | Message Class | Message Type |
292 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
293 * | Message Length |
294 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
295 * \ \
296 * / /
297 */
298 void
299 m3ua_print(netdissect_options *ndo,
300 const u_char *buf, const u_int size)
301 {
302 const struct m3ua_common_header *hdr = (const struct m3ua_common_header *) buf;
303 const struct tok *dict;
304 uint8_t msg_class;
305
306 ndo->ndo_protocol = "m3ua";
307 /* size includes the header */
308 if (size < sizeof(struct m3ua_common_header))
309 goto invalid;
310 ND_TCHECK_SIZE(hdr);
311 if (EXTRACT_U_1(hdr->v) != M3UA_REL_1_0)
312 return;
313
314 msg_class = EXTRACT_U_1(hdr->msg_class);
315 dict =
316 msg_class == M3UA_MSGC_MGMT ? MgmtMessages :
317 msg_class == M3UA_MSGC_TRANSFER ? TransferMessages :
318 msg_class == M3UA_MSGC_SSNM ? SS7Messages :
319 msg_class == M3UA_MSGC_ASPSM ? ASPStateMessages :
320 msg_class == M3UA_MSGC_ASPTM ? ASPTrafficMessages :
321 msg_class == M3UA_MSGC_RKM ? RoutingKeyMgmtMessages :
322 NULL;
323
324 ND_PRINT("\n\t\t%s", tok2str(MessageClasses, "Unknown message class %i", msg_class));
325 if (dict != NULL)
326 ND_PRINT(" %s Message", tok2str(dict, "Unknown (0x%02x)", EXTRACT_U_1(hdr->msg_type)));
327
328 if (size != EXTRACT_BE_U_4(hdr->len))
329 ND_PRINT("\n\t\t\t@@@@@@ Corrupted length %u of message @@@@@@", EXTRACT_BE_U_4(hdr->len));
330 else
331 m3ua_tags_print(ndo, buf + sizeof(struct m3ua_common_header),
332 EXTRACT_BE_U_4(hdr->len) - sizeof(struct m3ua_common_header));
333 return;
334
335 invalid:
336 nd_print_invalid(ndo);
337 ND_TCHECK_LEN(buf, size);
338 return;
339 trunc:
340 nd_print_trunc(ndo);
341 }
342