]> The Tcpdump Group git mirrors - tcpdump/blob - print-atm.c
Revert partially the commit 21b1273
[tcpdump] / print-atm.c
1 /*
2 * Copyright (c) 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 /* \summary: Asynchronous Transfer Mode (ATM) printer */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "netdissect-stdinc.h"
29
30 #include "netdissect.h"
31 #include "extract.h"
32 #include "addrtoname.h"
33 #include "atm.h"
34 #include "llc.h"
35
36 /* start of the original atmuni31.h */
37
38 /*
39 * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
40 * All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by Yen Yen Lim and
53 North Dakota State University
54 * 4. The name of the author may not be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
61 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
63 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
65 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
66 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
67 * POSSIBILITY OF SUCH DAMAGE.
68 */
69
70 /* Based on UNI3.1 standard by ATM Forum */
71
72 /* ATM traffic types based on VPI=0 and (the following VCI */
73 #define VCI_PPC 0x05 /* Point-to-point signal msg */
74 #define VCI_BCC 0x02 /* Broadcast signal msg */
75 #define VCI_OAMF4SC 0x03 /* Segment OAM F4 flow cell */
76 #define VCI_OAMF4EC 0x04 /* End-to-end OAM F4 flow cell */
77 #define VCI_METAC 0x01 /* Meta signal msg */
78 #define VCI_ILMIC 0x10 /* ILMI msg */
79
80 /* Q.2931 signalling messages */
81 #define CALL_PROCEED 0x02 /* call proceeding */
82 #define CONNECT 0x07 /* connect */
83 #define CONNECT_ACK 0x0f /* connect_ack */
84 #define SETUP 0x05 /* setup */
85 #define RELEASE 0x4d /* release */
86 #define RELEASE_DONE 0x5a /* release_done */
87 #define RESTART 0x46 /* restart */
88 #define RESTART_ACK 0x4e /* restart ack */
89 #define STATUS 0x7d /* status */
90 #define STATUS_ENQ 0x75 /* status ack */
91 #define ADD_PARTY 0x80 /* add party */
92 #define ADD_PARTY_ACK 0x81 /* add party ack */
93 #define ADD_PARTY_REJ 0x82 /* add party rej */
94 #define DROP_PARTY 0x83 /* drop party */
95 #define DROP_PARTY_ACK 0x84 /* drop party ack */
96
97 /* Information Element Parameters in the signalling messages */
98 #define CAUSE 0x08 /* cause */
99 #define ENDPT_REF 0x54 /* endpoint reference */
100 #define AAL_PARA 0x58 /* ATM adaptation layer parameters */
101 #define TRAFF_DESCRIP 0x59 /* atm traffic descriptors */
102 #define CONNECT_ID 0x5a /* connection identifier */
103 #define QOS_PARA 0x5c /* quality of service parameters */
104 #define B_HIGHER 0x5d /* broadband higher layer information */
105 #define B_BEARER 0x5e /* broadband bearer capability */
106 #define B_LOWER 0x5f /* broadband lower information */
107 #define CALLING_PARTY 0x6c /* calling party number */
108 #define CALLED_PARTY 0x70 /* called party nmber */
109
110 #define Q2931 0x09
111
112 /* Q.2931 signalling general messages format */
113 #define PROTO_POS 0 /* offset of protocol discriminator */
114 #define CALL_REF_POS 2 /* offset of call reference value */
115 #define MSG_TYPE_POS 5 /* offset of message type */
116 #define MSG_LEN_POS 7 /* offset of mesage length */
117 #define IE_BEGIN_POS 9 /* offset of first information element */
118
119 /* format of signalling messages */
120 #define TYPE_POS 0
121 #define LEN_POS 2
122 #define FIELD_BEGIN_POS 4
123
124 /* end of the original atmuni31.h */
125
126
127 #define OAM_CRC10_MASK 0x3ff
128 #define OAM_PAYLOAD_LEN 48
129 #define OAM_FUNCTION_SPECIFIC_LEN 45 /* this excludes crc10 and cell-type/function-type */
130 #define OAM_CELLTYPE_FUNCTYPE_LEN 1
131
132 static const struct tok oam_f_values[] = {
133 { VCI_OAMF4SC, "OAM F4 (segment)" },
134 { VCI_OAMF4EC, "OAM F4 (end)" },
135 { 0, NULL }
136 };
137
138 static const struct tok atm_pty_values[] = {
139 { 0x0, "user data, uncongested, SDU 0" },
140 { 0x1, "user data, uncongested, SDU 1" },
141 { 0x2, "user data, congested, SDU 0" },
142 { 0x3, "user data, congested, SDU 1" },
143 { 0x4, "VCC OAM F5 flow segment" },
144 { 0x5, "VCC OAM F5 flow end-to-end" },
145 { 0x6, "Traffic Control and resource Mgmt" },
146 { 0, NULL }
147 };
148
149 #define OAM_CELLTYPE_FM 0x1
150 #define OAM_CELLTYPE_PM 0x2
151 #define OAM_CELLTYPE_AD 0x8
152 #define OAM_CELLTYPE_SM 0xf
153
154 static const struct tok oam_celltype_values[] = {
155 { OAM_CELLTYPE_FM, "Fault Management" },
156 { OAM_CELLTYPE_PM, "Performance Management" },
157 { OAM_CELLTYPE_AD, "activate/deactivate" },
158 { OAM_CELLTYPE_SM, "System Management" },
159 { 0, NULL }
160 };
161
162 #define OAM_FM_FUNCTYPE_AIS 0x0
163 #define OAM_FM_FUNCTYPE_RDI 0x1
164 #define OAM_FM_FUNCTYPE_CONTCHECK 0x4
165 #define OAM_FM_FUNCTYPE_LOOPBACK 0x8
166
167 static const struct tok oam_fm_functype_values[] = {
168 { OAM_FM_FUNCTYPE_AIS, "AIS" },
169 { OAM_FM_FUNCTYPE_RDI, "RDI" },
170 { OAM_FM_FUNCTYPE_CONTCHECK, "Continuity Check" },
171 { OAM_FM_FUNCTYPE_LOOPBACK, "Loopback" },
172 { 0, NULL }
173 };
174
175 static const struct tok oam_pm_functype_values[] = {
176 { 0x0, "Forward Monitoring" },
177 { 0x1, "Backward Reporting" },
178 { 0x2, "Monitoring and Reporting" },
179 { 0, NULL }
180 };
181
182 static const struct tok oam_ad_functype_values[] = {
183 { 0x0, "Performance Monitoring" },
184 { 0x1, "Continuity Check" },
185 { 0, NULL }
186 };
187
188 #define OAM_FM_LOOPBACK_INDICATOR_MASK 0x1
189
190 static const struct tok oam_fm_loopback_indicator_values[] = {
191 { 0x0, "Reply" },
192 { 0x1, "Request" },
193 { 0, NULL }
194 };
195
196 static const struct tok *oam_functype_values[16] = {
197 NULL,
198 oam_fm_functype_values, /* 1 */
199 oam_pm_functype_values, /* 2 */
200 NULL,
201 NULL,
202 NULL,
203 NULL,
204 NULL,
205 oam_ad_functype_values, /* 8 */
206 NULL,
207 NULL,
208 NULL,
209 NULL,
210 NULL,
211 NULL,
212 NULL
213 };
214
215 /*
216 * Print an RFC 1483 LLC-encapsulated ATM frame.
217 */
218 static u_int
219 atm_llc_print(netdissect_options *ndo,
220 const u_char *p, int length, int caplen)
221 {
222 int llc_hdrlen;
223
224 llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
225 if (llc_hdrlen < 0) {
226 /* packet not known, print raw packet */
227 if (!ndo->ndo_suppress_default_print)
228 ND_DEFAULTPRINT(p, caplen);
229 llc_hdrlen = -llc_hdrlen;
230 }
231 return (llc_hdrlen);
232 }
233
234 /*
235 * Given a SAP value, generate the LLC header value for a UI packet
236 * with that SAP as the source and destination SAP.
237 */
238 #define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03)
239
240 /*
241 * This is the top level routine of the printer. 'p' points
242 * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp,
243 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
244 * is the number of bytes actually captured.
245 */
246 void
247 atm_if_print(netdissect_options *ndo,
248 const struct pcap_pkthdr *h, const u_char *p)
249 {
250 u_int caplen = h->caplen;
251 u_int length = h->len;
252 uint32_t llchdr;
253 u_int hdrlen = 0;
254
255 ndo->ndo_protocol = "atm";
256 if (caplen < 1) {
257 nd_print_trunc(ndo);
258 ndo->ndo_ll_hdr_len += caplen;
259 return;
260 }
261
262 /* Cisco Style NLPID ? */
263 if (GET_U_1(p) == LLC_UI) {
264 if (ndo->ndo_eflag)
265 ND_PRINT("CNLPID ");
266 isoclns_print(ndo, p + 1, length - 1);
267 ndo->ndo_ll_hdr_len += hdrlen;
268 return;
269 }
270
271 /*
272 * Must have at least a DSAP, an SSAP, and the first byte of the
273 * control field.
274 */
275 if (caplen < 3) {
276 nd_print_trunc(ndo);
277 ndo->ndo_ll_hdr_len += caplen;
278 return;
279 }
280
281 /*
282 * Extract the presumed LLC header into a variable, for quick
283 * testing.
284 * Then check for a header that's neither a header for a SNAP
285 * packet nor an RFC 2684 routed NLPID-formatted PDU nor
286 * an 802.2-but-no-SNAP IP packet.
287 */
288 llchdr = GET_BE_U_3(p);
289 if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) &&
290 llchdr != LLC_UI_HDR(LLCSAP_ISONS) &&
291 llchdr != LLC_UI_HDR(LLCSAP_IP)) {
292 /*
293 * XXX - assume 802.6 MAC header from Fore driver.
294 *
295 * Unfortunately, the above list doesn't check for
296 * all known SAPs, doesn't check for headers where
297 * the source and destination SAP aren't the same,
298 * and doesn't check for non-UI frames. It also
299 * runs the risk of an 802.6 MAC header that happens
300 * to begin with one of those values being
301 * incorrectly treated as an 802.2 header.
302 *
303 * So is that Fore driver still around? And, if so,
304 * is it still putting 802.6 MAC headers on ATM
305 * packets? If so, could it be changed to use a
306 * new DLT_IEEE802_6 value if we added it?
307 */
308 if (caplen < 20) {
309 nd_print_trunc(ndo);
310 ndo->ndo_ll_hdr_len += caplen;
311 return;
312 }
313 if (ndo->ndo_eflag)
314 ND_PRINT("%08x%08x %08x%08x ",
315 GET_BE_U_4(p),
316 GET_BE_U_4(p + 4),
317 GET_BE_U_4(p + 8),
318 GET_BE_U_4(p + 12));
319 p += 20;
320 length -= 20;
321 caplen -= 20;
322 hdrlen += 20;
323 }
324 hdrlen += atm_llc_print(ndo, p, length, caplen);
325 ndo->ndo_ll_hdr_len += hdrlen;
326 }
327
328 /*
329 * ATM signalling.
330 */
331 static const struct tok msgtype2str[] = {
332 { CALL_PROCEED, "Call_proceeding" },
333 { CONNECT, "Connect" },
334 { CONNECT_ACK, "Connect_ack" },
335 { SETUP, "Setup" },
336 { RELEASE, "Release" },
337 { RELEASE_DONE, "Release_complete" },
338 { RESTART, "Restart" },
339 { RESTART_ACK, "Restart_ack" },
340 { STATUS, "Status" },
341 { STATUS_ENQ, "Status_enquiry" },
342 { ADD_PARTY, "Add_party" },
343 { ADD_PARTY_ACK, "Add_party_ack" },
344 { ADD_PARTY_REJ, "Add_party_reject" },
345 { DROP_PARTY, "Drop_party" },
346 { DROP_PARTY_ACK, "Drop_party_ack" },
347 { 0, NULL }
348 };
349
350 static void
351 sig_print(netdissect_options *ndo,
352 const u_char *p)
353 {
354 uint32_t call_ref;
355
356 if (GET_U_1(p + PROTO_POS) == Q2931) {
357 /*
358 * protocol:Q.2931 for User to Network Interface
359 * (UNI 3.1) signalling
360 */
361 ND_PRINT("Q.2931");
362 ND_PRINT(":%s ",
363 tok2str(msgtype2str, "msgtype#%u", GET_U_1(p + MSG_TYPE_POS)));
364
365 /*
366 * The call reference comes before the message type,
367 * so if we know we have the message type, which we
368 * do from the caplen test above, we also know we have
369 * the call reference.
370 */
371 call_ref = GET_BE_U_3(p + CALL_REF_POS);
372 ND_PRINT("CALL_REF:0x%06x", call_ref);
373 } else {
374 /* SSCOP with some unknown protocol atop it */
375 ND_PRINT("SSCOP, proto %u ", GET_U_1(p + PROTO_POS));
376 }
377 }
378
379 /*
380 * Print an ATM PDU (such as an AAL5 PDU).
381 */
382 void
383 atm_print(netdissect_options *ndo,
384 u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length,
385 u_int caplen)
386 {
387 ndo->ndo_protocol = "atm";
388 if (ndo->ndo_eflag)
389 ND_PRINT("VPI:%u VCI:%u ", vpi, vci);
390
391 if (vpi == 0) {
392 switch (vci) {
393
394 case VCI_PPC:
395 sig_print(ndo, p);
396 return;
397
398 case VCI_BCC:
399 ND_PRINT("broadcast sig: ");
400 return;
401
402 case VCI_OAMF4SC: /* fall through */
403 case VCI_OAMF4EC:
404 oam_print(ndo, p, length, ATM_OAM_HEC);
405 return;
406
407 case VCI_METAC:
408 ND_PRINT("meta: ");
409 return;
410
411 case VCI_ILMIC:
412 ND_PRINT("ilmi: ");
413 snmp_print(ndo, p, length);
414 return;
415 }
416 }
417
418 switch (traftype) {
419
420 case ATM_LLC:
421 default:
422 /*
423 * Assumes traffic is LLC if unknown.
424 */
425 atm_llc_print(ndo, p, length, caplen);
426 break;
427
428 case ATM_LANE:
429 lane_print(ndo, p, length, caplen);
430 break;
431 }
432 }
433
434 struct oam_fm_loopback_t {
435 nd_uint8_t loopback_indicator;
436 nd_uint32_t correlation_tag;
437 nd_byte loopback_id[12];
438 nd_byte source_id[12];
439 nd_byte unused[16];
440 };
441
442 struct oam_fm_ais_rdi_t {
443 nd_uint8_t failure_type;
444 nd_byte failure_location[16];
445 nd_byte unused[28];
446 };
447
448 void
449 oam_print(netdissect_options *ndo,
450 const u_char *p, u_int length, u_int hec)
451 {
452 uint32_t cell_header;
453 uint16_t vpi, vci, cksum, cksum_shouldbe, idx;
454 uint8_t cell_type, func_type, payload, clp;
455
456 union {
457 const struct oam_fm_loopback_t *oam_fm_loopback;
458 const struct oam_fm_ais_rdi_t *oam_fm_ais_rdi;
459 } oam_ptr;
460
461 ndo->ndo_protocol = "oam";
462 cell_header = GET_BE_U_4(p + hec);
463 cell_type = (GET_U_1((p + ATM_HDR_LEN_NOHEC + hec)) >> 4) & 0x0f;
464 func_type = GET_U_1((p + ATM_HDR_LEN_NOHEC + hec)) & 0x0f;
465
466 vpi = (cell_header>>20)&0xff;
467 vci = (cell_header>>4)&0xffff;
468 payload = (cell_header>>1)&0x7;
469 clp = cell_header&0x1;
470
471 ND_PRINT("%s, vpi %u, vci %u, payload [ %s ], clp %u, length %u",
472 tok2str(oam_f_values, "OAM F5", vci),
473 vpi, vci,
474 tok2str(atm_pty_values, "Unknown", payload),
475 clp, length);
476
477 if (!ndo->ndo_vflag) {
478 return;
479 }
480
481 ND_PRINT("\n\tcell-type %s (%u)",
482 tok2str(oam_celltype_values, "unknown", cell_type),
483 cell_type);
484
485 if (oam_functype_values[cell_type] == NULL)
486 ND_PRINT(", func-type unknown (%u)", func_type);
487 else
488 ND_PRINT(", func-type %s (%u)",
489 tok2str(oam_functype_values[cell_type],"none",func_type),
490 func_type);
491
492 p += ATM_HDR_LEN_NOHEC + hec;
493
494 switch (cell_type << 4 | func_type) {
495 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_LOOPBACK):
496 oam_ptr.oam_fm_loopback = (const struct oam_fm_loopback_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN);
497 ND_TCHECK_SIZE(oam_ptr.oam_fm_loopback);
498 ND_PRINT("\n\tLoopback-Indicator %s, Correlation-Tag 0x%08x",
499 tok2str(oam_fm_loopback_indicator_values,
500 "Unknown",
501 GET_U_1(oam_ptr.oam_fm_loopback->loopback_indicator) & OAM_FM_LOOPBACK_INDICATOR_MASK),
502 GET_BE_U_4(oam_ptr.oam_fm_loopback->correlation_tag));
503 ND_PRINT("\n\tLocation-ID ");
504 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) {
505 if (idx % 2) {
506 ND_PRINT("%04x ",
507 GET_BE_U_2(&oam_ptr.oam_fm_loopback->loopback_id[idx]));
508 }
509 }
510 ND_PRINT("\n\tSource-ID ");
511 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->source_id); idx++) {
512 if (idx % 2) {
513 ND_PRINT("%04x ",
514 GET_BE_U_2(&oam_ptr.oam_fm_loopback->source_id[idx]));
515 }
516 }
517 break;
518
519 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_AIS):
520 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_RDI):
521 oam_ptr.oam_fm_ais_rdi = (const struct oam_fm_ais_rdi_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN);
522 ND_TCHECK_SIZE(oam_ptr.oam_fm_ais_rdi);
523 ND_PRINT("\n\tFailure-type 0x%02x",
524 GET_U_1(oam_ptr.oam_fm_ais_rdi->failure_type));
525 ND_PRINT("\n\tLocation-ID ");
526 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_ais_rdi->failure_location); idx++) {
527 if (idx % 2) {
528 ND_PRINT("%04x ",
529 GET_BE_U_2(&oam_ptr.oam_fm_ais_rdi->failure_location[idx]));
530 }
531 }
532 break;
533
534 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK):
535 /* FIXME */
536 break;
537
538 default:
539 break;
540 }
541
542 /* crc10 checksum verification */
543 cksum = GET_BE_U_2(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN)
544 & OAM_CRC10_MASK;
545 cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN);
546
547 ND_PRINT("\n\tcksum 0x%03x (%scorrect)",
548 cksum,
549 cksum_shouldbe == 0 ? "" : "in");
550
551 return;
552
553 trunc:
554 nd_print_trunc(ndo);
555 return;
556 }