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