blob: ecf7db834385238019e90cfe81c1ceba2c92b085 [file] [log] [blame]
Elliott Hughes892a68b2015-10-19 14:43:53 -07001/* 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
Elliott Hughese2e3bd12017-05-15 10:59:29 -070025/* \summary: Message Transfer Part 3 (MTP3) User Adaptation Layer (M3UA) printer */
26
27/* RFC 4666 */
28
Elliott Hughes892a68b2015-10-19 14:43:53 -070029#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070030#include <config.h>
Elliott Hughes892a68b2015-10-19 14:43:53 -070031#endif
32
Elliott Hughes820eced2021-08-20 18:00:50 -070033#include "netdissect-stdinc.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070034
Elliott Hughes820eced2021-08-20 18:00:50 -070035#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070036#include "netdissect.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070037#include "extract.h"
38
Elliott Hughes892a68b2015-10-19 14:43:53 -070039
40#define M3UA_REL_1_0 1
41
42struct m3ua_common_header {
Elliott Hughes820eced2021-08-20 18:00:50 -070043 nd_uint8_t v;
44 nd_uint8_t reserved;
45 nd_uint8_t msg_class;
46 nd_uint8_t msg_type;
47 nd_uint32_t len;
Elliott Hughes892a68b2015-10-19 14:43:53 -070048};
49
50struct m3ua_param_header {
Elliott Hughes820eced2021-08-20 18:00:50 -070051 nd_uint16_t tag;
52 nd_uint16_t len;
Elliott Hughes892a68b2015-10-19 14:43:53 -070053};
54
55/* message classes */
56#define M3UA_MSGC_MGMT 0
57#define M3UA_MSGC_TRANSFER 1
58#define M3UA_MSGC_SSNM 2
59#define M3UA_MSGC_ASPSM 3
60#define M3UA_MSGC_ASPTM 4
61/* reserved values */
62#define M3UA_MSGC_RKM 9
63
64static const struct tok MessageClasses[] = {
65 { M3UA_MSGC_MGMT, "Management" },
66 { M3UA_MSGC_TRANSFER, "Transfer" },
67 { M3UA_MSGC_SSNM, "SS7" },
68 { M3UA_MSGC_ASPSM, "ASP" },
69 { M3UA_MSGC_ASPTM, "ASP" },
Elliott Hughes9a986422017-12-19 14:49:10 -080070 { M3UA_MSGC_RKM, "Routing Key Management"},
Elliott Hughes892a68b2015-10-19 14:43:53 -070071 { 0, NULL }
72};
73
74/* management messages */
75#define M3UA_MGMT_ERROR 0
76#define M3UA_MGMT_NOTIFY 1
77
78static const struct tok MgmtMessages[] = {
79 { M3UA_MGMT_ERROR, "Error" },
80 { M3UA_MGMT_NOTIFY, "Notify" },
81 { 0, NULL }
82};
83
84/* transfer messages */
85#define M3UA_TRANSFER_DATA 1
86
87static const struct tok TransferMessages[] = {
88 { M3UA_TRANSFER_DATA, "Data" },
89 { 0, NULL }
90};
91
92/* SS7 Signaling Network Management messages */
93#define M3UA_SSNM_DUNA 1
94#define M3UA_SSNM_DAVA 2
95#define M3UA_SSNM_DAUD 3
96#define M3UA_SSNM_SCON 4
97#define M3UA_SSNM_DUPU 5
98#define M3UA_SSNM_DRST 6
99
100static const struct tok SS7Messages[] = {
101 { M3UA_SSNM_DUNA, "Destination Unavailable" },
102 { M3UA_SSNM_DAVA, "Destination Available" },
103 { M3UA_SSNM_DAUD, "Destination State Audit" },
104 { M3UA_SSNM_SCON, "Signalling Congestion" },
105 { M3UA_SSNM_DUPU, "Destination User Part Unavailable" },
106 { M3UA_SSNM_DRST, "Destination Restricted" },
107 { 0, NULL }
108};
109
110/* ASP State Maintenance messages */
111#define M3UA_ASP_UP 1
112#define M3UA_ASP_DN 2
113#define M3UA_ASP_BEAT 3
114#define M3UA_ASP_UP_ACK 4
115#define M3UA_ASP_DN_ACK 5
116#define M3UA_ASP_BEAT_ACK 6
117
118static const struct tok ASPStateMessages[] = {
119 { M3UA_ASP_UP, "Up" },
120 { M3UA_ASP_DN, "Down" },
121 { M3UA_ASP_BEAT, "Heartbeat" },
122 { M3UA_ASP_UP_ACK, "Up Acknowledgement" },
123 { M3UA_ASP_DN_ACK, "Down Acknowledgement" },
124 { M3UA_ASP_BEAT_ACK, "Heartbeat Acknowledgement" },
125 { 0, NULL }
126};
127
128/* ASP Traffic Maintenance messages */
129#define M3UA_ASP_AC 1
130#define M3UA_ASP_IA 2
131#define M3UA_ASP_AC_ACK 3
132#define M3UA_ASP_IA_ACK 4
133
134static const struct tok ASPTrafficMessages[] = {
135 { M3UA_ASP_AC, "Active" },
136 { M3UA_ASP_IA, "Inactive" },
137 { M3UA_ASP_AC_ACK, "Active Acknowledgement" },
138 { M3UA_ASP_IA_ACK, "Inactive Acknowledgement" },
139 { 0, NULL }
140};
141
142/* Routing Key Management messages */
143#define M3UA_RKM_REQ 1
144#define M3UA_RKM_RSP 2
145#define M3UA_RKM_DEREQ 3
146#define M3UA_RKM_DERSP 4
147
148static const struct tok RoutingKeyMgmtMessages[] = {
149 { M3UA_RKM_REQ, "Registration Request" },
150 { M3UA_RKM_RSP, "Registration Response" },
151 { M3UA_RKM_DEREQ, "Deregistration Request" },
152 { M3UA_RKM_DERSP, "Deregistration Response" },
153 { 0, NULL }
154};
155
Elliott Hughes820eced2021-08-20 18:00:50 -0700156static const struct uint_tokary m3ua_msgc2tokary[] = {
157 { M3UA_MSGC_MGMT, MgmtMessages },
158 { M3UA_MSGC_TRANSFER, TransferMessages },
159 { M3UA_MSGC_SSNM, SS7Messages },
160 { M3UA_MSGC_ASPSM, ASPStateMessages },
161 { M3UA_MSGC_ASPTM, ASPTrafficMessages },
162 { M3UA_MSGC_RKM, RoutingKeyMgmtMessages },
163 /* uint2tokary() does not use array termination. */
164};
165
Elliott Hughes892a68b2015-10-19 14:43:53 -0700166/* M3UA Parameters */
167#define M3UA_PARAM_INFO 0x0004
168#define M3UA_PARAM_ROUTING_CTX 0x0006
169#define M3UA_PARAM_DIAGNOSTIC 0x0007
170#define M3UA_PARAM_HB_DATA 0x0009
171#define M3UA_PARAM_TRAFFIC_MODE_TYPE 0x000b
172#define M3UA_PARAM_ERROR_CODE 0x000c
173#define M3UA_PARAM_STATUS 0x000d
174#define M3UA_PARAM_ASP_ID 0x0011
175#define M3UA_PARAM_AFFECTED_POINT_CODE 0x0012
176#define M3UA_PARAM_CORR_ID 0x0013
177
178#define M3UA_PARAM_NETWORK_APPEARANCE 0x0200
179#define M3UA_PARAM_USER 0x0204
180#define M3UA_PARAM_CONGESTION_INDICATION 0x0205
181#define M3UA_PARAM_CONCERNED_DST 0x0206
182#define M3UA_PARAM_ROUTING_KEY 0x0207
183#define M3UA_PARAM_REG_RESULT 0x0208
184#define M3UA_PARAM_DEREG_RESULT 0x0209
185#define M3UA_PARAM_LOCAL_ROUTING_KEY_ID 0x020a
186#define M3UA_PARAM_DST_POINT_CODE 0x020b
187#define M3UA_PARAM_SI 0x020c
188#define M3UA_PARAM_ORIGIN_POINT_CODE_LIST 0x020e
189#define M3UA_PARAM_PROTO_DATA 0x0210
190#define M3UA_PARAM_REG_STATUS 0x0212
191#define M3UA_PARAM_DEREG_STATUS 0x0213
192
193static const struct tok ParamName[] = {
194 { M3UA_PARAM_INFO, "INFO String" },
195 { M3UA_PARAM_ROUTING_CTX, "Routing Context" },
196 { M3UA_PARAM_DIAGNOSTIC, "Diagnostic Info" },
197 { M3UA_PARAM_HB_DATA, "Heartbeat Data" },
198 { M3UA_PARAM_TRAFFIC_MODE_TYPE, "Traffic Mode Type" },
199 { M3UA_PARAM_ERROR_CODE, "Error Code" },
200 { M3UA_PARAM_STATUS, "Status" },
201 { M3UA_PARAM_ASP_ID, "ASP Identifier" },
202 { M3UA_PARAM_AFFECTED_POINT_CODE, "Affected Point Code" },
203 { M3UA_PARAM_CORR_ID, "Correlation ID" },
204 { M3UA_PARAM_NETWORK_APPEARANCE, "Network Appearance" },
205 { M3UA_PARAM_USER, "User/Cause" },
206 { M3UA_PARAM_CONGESTION_INDICATION, "Congestion Indications" },
207 { M3UA_PARAM_CONCERNED_DST, "Concerned Destination" },
208 { M3UA_PARAM_ROUTING_KEY, "Routing Key" },
209 { M3UA_PARAM_REG_RESULT, "Registration Result" },
210 { M3UA_PARAM_DEREG_RESULT, "Deregistration Result" },
211 { M3UA_PARAM_LOCAL_ROUTING_KEY_ID, "Local Routing Key Identifier" },
212 { M3UA_PARAM_DST_POINT_CODE, "Destination Point Code" },
213 { M3UA_PARAM_SI, "Service Indicators" },
214 { M3UA_PARAM_ORIGIN_POINT_CODE_LIST, "Originating Point Code List" },
215 { M3UA_PARAM_PROTO_DATA, "Protocol Data" },
216 { M3UA_PARAM_REG_STATUS, "Registration Status" },
217 { M3UA_PARAM_DEREG_STATUS, "Deregistration Status" },
218 { 0, NULL }
219};
220
221static void
222tag_value_print(netdissect_options *ndo,
223 const u_char *buf, const uint16_t tag, const uint16_t size)
224{
225 switch (tag) {
226 case M3UA_PARAM_NETWORK_APPEARANCE:
227 case M3UA_PARAM_ROUTING_CTX:
228 case M3UA_PARAM_CORR_ID:
229 /* buf and size don't include the header */
230 if (size < 4)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700231 goto invalid;
Elliott Hughes820eced2021-08-20 18:00:50 -0700232 ND_PRINT("0x%08x", GET_BE_U_4(buf));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700233 break;
234 /* ... */
235 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700236 ND_PRINT("(length %zu)", size + sizeof(struct m3ua_param_header));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700237 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700238 ND_TCHECK_LEN(buf, size);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700239 return;
240
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700241invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700242 nd_print_invalid(ndo);
243 ND_TCHECK_LEN(buf, size);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700244}
245
246/*
247 * 0 1 2 3
248 * 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
249 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
250 * | Parameter Tag | Parameter Length |
251 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
252 * \ \
253 * / Parameter Value /
254 * \ \
255 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
256 */
257static void
258m3ua_tags_print(netdissect_options *ndo,
259 const u_char *buf, const u_int size)
260{
261 const u_char *p = buf;
262 int align;
263 uint16_t hdr_tag;
264 uint16_t hdr_len;
265
266 while (p < buf + size) {
267 if (p + sizeof(struct m3ua_param_header) > buf + size)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700268 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700269 /* Parameter Tag */
Elliott Hughes820eced2021-08-20 18:00:50 -0700270 hdr_tag = GET_BE_U_2(p);
271 ND_PRINT("\n\t\t\t%s: ", tok2str(ParamName, "Unknown Parameter (0x%04x)", hdr_tag));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700272 /* Parameter Length */
Elliott Hughes820eced2021-08-20 18:00:50 -0700273 hdr_len = GET_BE_U_2(p + 2);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700274 if (hdr_len < sizeof(struct m3ua_param_header))
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700275 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700276 /* Parameter Value */
277 align = (p + hdr_len - buf) % 4;
278 align = align ? 4 - align : 0;
Elliott Hughes820eced2021-08-20 18:00:50 -0700279 ND_TCHECK_LEN(p, hdr_len + align);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700280 tag_value_print(ndo, p, hdr_tag, hdr_len - sizeof(struct m3ua_param_header));
281 p += hdr_len + align;
282 }
283 return;
284
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700285invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700286 nd_print_invalid(ndo);
287 ND_TCHECK_LEN(buf, size);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700288}
289
290/*
291 * 0 1 2 3
292 * 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
293 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
294 * | Version | Reserved | Message Class | Message Type |
295 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
296 * | Message Length |
297 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
298 * \ \
299 * / /
300 */
301void
302m3ua_print(netdissect_options *ndo,
303 const u_char *buf, const u_int size)
304{
305 const struct m3ua_common_header *hdr = (const struct m3ua_common_header *) buf;
306 const struct tok *dict;
Elliott Hughes820eced2021-08-20 18:00:50 -0700307 uint8_t msg_class;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700308
Elliott Hughes820eced2021-08-20 18:00:50 -0700309 ndo->ndo_protocol = "m3ua";
Elliott Hughes892a68b2015-10-19 14:43:53 -0700310 /* size includes the header */
311 if (size < sizeof(struct m3ua_common_header))
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700312 goto invalid;
Elliott Hughes820eced2021-08-20 18:00:50 -0700313 ND_TCHECK_SIZE(hdr);
314 if (GET_U_1(hdr->v) != M3UA_REL_1_0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700315 return;
316
Elliott Hughes820eced2021-08-20 18:00:50 -0700317 msg_class = GET_U_1(hdr->msg_class);
318 dict = uint2tokary(m3ua_msgc2tokary, msg_class);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700319
Elliott Hughes820eced2021-08-20 18:00:50 -0700320 ND_PRINT("\n\t\t%s", tok2str(MessageClasses, "Unknown message class %i", msg_class));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700321 if (dict != NULL)
Elliott Hughes820eced2021-08-20 18:00:50 -0700322 ND_PRINT(" %s Message",
323 tok2str(dict, "Unknown (0x%02x)", GET_U_1(hdr->msg_type)));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700324
Elliott Hughes820eced2021-08-20 18:00:50 -0700325 if (size != GET_BE_U_4(hdr->len))
326 ND_PRINT("\n\t\t\t@@@@@@ Corrupted length %u of message @@@@@@",
327 GET_BE_U_4(hdr->len));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700328 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700329 m3ua_tags_print(ndo, buf + sizeof(struct m3ua_common_header),
330 GET_BE_U_4(hdr->len) - sizeof(struct m3ua_common_header));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700331 return;
332
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700333invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700334 nd_print_invalid(ndo);
335 ND_TCHECK_LEN(buf, size);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700336}
337