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