]> The Tcpdump Group git mirrors - tcpdump/blob - print-atm.c
05fca9de9ac0e2c1ace1575a0bb0cc890f686f77
[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 #ifndef lint
22 static const char rcsid[] _U_ =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.46 2006-02-08 16:18:56 hannes Exp $ (LBL)";
24 #endif
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <tcpdump-stdinc.h>
31
32 #include <stdio.h>
33 #include <pcap.h>
34 #include <string.h>
35
36 #include "interface.h"
37 #include "extract.h"
38 #include "addrtoname.h"
39 #include "ethertype.h"
40 #include "atm.h"
41 #include "atmuni31.h"
42 #include "llc.h"
43
44 #include "ether.h"
45
46 #define OAM_CRC10_MASK 0x3ff
47 #define OAM_PAYLOAD_LEN 48
48 #define OAM_FUNCTION_SPECIFIC_LEN 45 /* this excludes crc10 and cell-type/function-type */
49 #define OAM_CELLTYPE_FUNCTYPE_LEN 1
50
51 struct tok oam_f_values[] = {
52 { OAMF4SC, "OAM F4 (segment)" },
53 { OAMF4EC, "OAM F4 (end)" },
54 { 0, NULL }
55 };
56
57 #define OAM_CELLTYPE_FM 0x1
58 #define OAM_CELLTYPE_PM 0x2
59 #define OAM_CELLTYPE_AD 0x8
60 #define OAM_CELLTYPE_SM 0xf
61
62 struct tok oam_celltype_values[] = {
63 { OAM_CELLTYPE_FM, "Fault Management" },
64 { OAM_CELLTYPE_PM, "Performance Management" },
65 { OAM_CELLTYPE_AD, "activate/deactivate" },
66 { OAM_CELLTYPE_SM, "System Management" },
67 { 0, NULL }
68 };
69
70 #define OAM_FM_FUNCTYPE_AIS 0x0
71 #define OAM_FM_FUNCTYPE_RDI 0x1
72 #define OAM_FM_FUNCTYPE_CONTCHECK 0x4
73 #define OAM_FM_FUNCTYPE_LOOPBACK 0x8
74
75 struct tok oam_fm_functype_values[] = {
76 { OAM_FM_FUNCTYPE_AIS, "AIS" },
77 { OAM_FM_FUNCTYPE_RDI, "RDI" },
78 { OAM_FM_FUNCTYPE_CONTCHECK, "Continuity Check" },
79 { OAM_FM_FUNCTYPE_LOOPBACK, "Loopback" },
80 { 0, NULL }
81 };
82
83 struct tok oam_pm_functype_values[] = {
84 { 0x0, "Forward Monitoring" },
85 { 0x1, "Backward Reporting" },
86 { 0x2, "Monitoring and Reporting" },
87 { 0, NULL }
88 };
89
90 struct tok oam_ad_functype_values[] = {
91 { 0x0, "Performance Monitoring" },
92 { 0x1, "Continuity Check" },
93 { 0, NULL }
94 };
95
96 #define OAM_FM_LOOPBACK_INDICATOR_MASK 0x1
97
98 struct tok oam_fm_loopback_indicator_values[] = {
99 { 0x0, "Reply" },
100 { 0x1, "Request" },
101 { 0, NULL }
102 };
103
104 static const struct tok *oam_functype_values[16] = {
105 NULL,
106 oam_fm_functype_values, /* 1 */
107 oam_pm_functype_values, /* 2 */
108 NULL,
109 NULL,
110 NULL,
111 NULL,
112 NULL,
113 oam_ad_functype_values, /* 8 */
114 NULL,
115 NULL,
116 NULL,
117 NULL,
118 NULL,
119 NULL,
120 NULL
121 };
122
123 /*
124 * Print an RFC 1483 LLC-encapsulated ATM frame.
125 */
126 static void
127 atm_llc_print(const u_char *p, int length, int caplen)
128 {
129 u_short extracted_ethertype;
130
131 if (!llc_print(p, length, caplen, NULL, NULL,
132 &extracted_ethertype)) {
133 /* ether_type not known, print raw packet */
134 if (extracted_ethertype) {
135 printf("(LLC %s) ",
136 etherproto_string(htons(extracted_ethertype)));
137 }
138 if (!suppress_default_print)
139 default_print(p, caplen);
140 }
141 }
142
143 /*
144 * Given a SAP value, generate the LLC header value for a UI packet
145 * with that SAP as the source and destination SAP.
146 */
147 #define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03)
148
149 /*
150 * This is the top level routine of the printer. 'p' points
151 * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp,
152 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
153 * is the number of bytes actually captured.
154 */
155 u_int
156 atm_if_print(const struct pcap_pkthdr *h, const u_char *p)
157 {
158 u_int caplen = h->caplen;
159 u_int length = h->len;
160 u_int32_t llchdr;
161 u_int hdrlen = 0;
162
163 if (caplen < 8) {
164 printf("[|atm]");
165 return (caplen);
166 }
167
168 /* Cisco Style NLPID ? */
169 if (*p == LLC_UI) {
170 if (eflag)
171 printf("CNLPID ");
172 isoclns_print(p+1, length-1, caplen-1);
173 return hdrlen;
174 }
175
176 /*
177 * Extract the presumed LLC header into a variable, for quick
178 * testing.
179 * Then check for a header that's neither a header for a SNAP
180 * packet nor an RFC 2684 routed NLPID-formatted PDU nor
181 * an 802.2-but-no-SNAP IP packet.
182 */
183 llchdr = EXTRACT_24BITS(p);
184 if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) &&
185 llchdr != LLC_UI_HDR(LLCSAP_ISONS) &&
186 llchdr != LLC_UI_HDR(LLCSAP_IP)) {
187 /*
188 * XXX - assume 802.6 MAC header from Fore driver.
189 *
190 * Unfortunately, the above list doesn't check for
191 * all known SAPs, doesn't check for headers where
192 * the source and destination SAP aren't the same,
193 * and doesn't check for non-UI frames. It also
194 * runs the risk of an 802.6 MAC header that happens
195 * to begin with one of those values being
196 * incorrectly treated as an 802.2 header.
197 *
198 * So is that Fore driver still around? And, if so,
199 * is it still putting 802.6 MAC headers on ATM
200 * packets? If so, could it be changed to use a
201 * new DLT_IEEE802_6 value if we added it?
202 */
203 if (eflag)
204 printf("%08x%08x %08x%08x ",
205 EXTRACT_32BITS(p),
206 EXTRACT_32BITS(p+4),
207 EXTRACT_32BITS(p+8),
208 EXTRACT_32BITS(p+12));
209 p += 20;
210 length -= 20;
211 caplen -= 20;
212 hdrlen += 20;
213 }
214 atm_llc_print(p, length, caplen);
215 return (hdrlen);
216 }
217
218 /*
219 * ATM signalling.
220 */
221 static struct tok msgtype2str[] = {
222 { CALL_PROCEED, "Call_proceeding" },
223 { CONNECT, "Connect" },
224 { CONNECT_ACK, "Connect_ack" },
225 { SETUP, "Setup" },
226 { RELEASE, "Release" },
227 { RELEASE_DONE, "Release_complete" },
228 { RESTART, "Restart" },
229 { RESTART_ACK, "Restart_ack" },
230 { STATUS, "Status" },
231 { STATUS_ENQ, "Status_enquiry" },
232 { ADD_PARTY, "Add_party" },
233 { ADD_PARTY_ACK, "Add_party_ack" },
234 { ADD_PARTY_REJ, "Add_party_reject" },
235 { DROP_PARTY, "Drop_party" },
236 { DROP_PARTY_ACK, "Drop_party_ack" },
237 { 0, NULL }
238 };
239
240 static void
241 sig_print(const u_char *p, int caplen)
242 {
243 bpf_u_int32 call_ref;
244
245 if (caplen < PROTO_POS) {
246 printf("[|atm]");
247 return;
248 }
249 if (p[PROTO_POS] == Q2931) {
250 /*
251 * protocol:Q.2931 for User to Network Interface
252 * (UNI 3.1) signalling
253 */
254 printf("Q.2931");
255 if (caplen < MSG_TYPE_POS) {
256 printf(" [|atm]");
257 return;
258 }
259 printf(":%s ",
260 tok2str(msgtype2str, "msgtype#%d", p[MSG_TYPE_POS]));
261
262 if (caplen < CALL_REF_POS+3) {
263 printf("[|atm]");
264 return;
265 }
266 call_ref = EXTRACT_24BITS(&p[CALL_REF_POS]);
267 printf("CALL_REF:0x%06x", call_ref);
268 } else {
269 /* SCCOP with some unknown protocol atop it */
270 printf("SSCOP, proto %d ", p[PROTO_POS]);
271 }
272 }
273
274 /*
275 * Print an ATM PDU (such as an AAL5 PDU).
276 */
277 void
278 atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length,
279 u_int caplen)
280 {
281 if (eflag)
282 printf("VPI:%u VCI:%u ", vpi, vci);
283
284 if (vpi == 0) {
285 switch (vci) {
286
287 case PPC:
288 sig_print(p, caplen);
289 return;
290
291 case BCC:
292 printf("broadcast sig: ");
293 return;
294
295 case OAMF4SC: /* fall through */
296 case OAMF4EC:
297 oam_print(p, length, ATM_OAM_HEC);
298 return;
299
300 case METAC:
301 printf("meta: ");
302 return;
303
304 case ILMIC:
305 printf("ilmi: ");
306 snmp_print(p, length);
307 return;
308 }
309 }
310
311 switch (traftype) {
312
313 case ATM_LLC:
314 default:
315 /*
316 * Assumes traffic is LLC if unknown.
317 */
318 atm_llc_print(p, length, caplen);
319 break;
320
321 case ATM_LANE:
322 lane_print(p, length, caplen);
323 break;
324 }
325 }
326
327 struct oam_fm_loopback_t {
328 u_int8_t loopback_indicator;
329 u_int8_t correlation_tag[4];
330 u_int8_t loopback_id[12];
331 u_int8_t source_id[12];
332 u_int8_t unused[16];
333 };
334
335 struct oam_fm_ais_rdi_t {
336 u_int8_t failure_type;
337 u_int8_t failure_location[16];
338 u_int8_t unused[28];
339 };
340
341
342 #define CRC10_POLYNOMIAL 0x633
343 static u_int16_t crc10_table[256];
344
345 static void
346 gen_crc10_table(void)
347 {
348 register int i, j;
349 register u_int16_t accum;
350
351 for ( i = 0; i < 256; i++ )
352 {
353 accum = ((unsigned short) i << 2);
354 for ( j = 0; j < 8; j++ )
355 {
356 if ((accum <<= 1) & 0x400) accum ^= CRC10_POLYNOMIAL;
357 }
358 crc10_table[i] = accum;
359 }
360 return;
361 }
362
363 static u_int16_t
364 verify_crc10_cksum(u_int16_t accum, const u_char *p, int length)
365 {
366 register int i;
367
368 for ( i = 0; i < length; i++ )
369 {
370 accum = ((accum << 8) & 0x3ff)
371 ^ crc10_table[( accum >> 2) & 0xff]
372 ^ *p++;
373 }
374 return accum;
375 }
376
377 int
378 oam_print (const u_char *p, u_int length, u_int hec) {
379
380 u_int32_t cell_header;
381 u_int16_t vpi, vci, cksum, cksum_shouldbe, idx;
382 u_int8_t cell_type, func_type, payload, clp;
383
384 union {
385 const struct oam_fm_loopback_t *oam_fm_loopback;
386 const struct oam_fm_ais_rdi_t *oam_fm_ais_rdi;
387 } oam_ptr;
388
389
390 cell_header = EXTRACT_32BITS(p+hec);
391 cell_type = ((*(p+ATM_HDR_LEN_NOHEC+hec))>>4) & 0x0f;
392 func_type = (*(p+ATM_HDR_LEN_NOHEC+hec)) & 0x0f;
393
394 vpi = (cell_header>>20)&0xff;
395 vci = (cell_header>>4)&0xffff;
396 payload = (cell_header>>1)&0x7;
397 clp = cell_header&0x1;
398
399 printf("%s, vpi %u, vci %u, payload %u, clp %u, length %u",
400 tok2str(oam_f_values, "OAM F5", vci),
401 vpi, vci, payload, clp, length);
402
403 if (!vflag) {
404 return 1;
405 }
406
407 printf("\n\tcell-type %s (%u)",
408 tok2str(oam_celltype_values, "unknown", cell_type),
409 cell_type);
410
411 if (oam_functype_values[cell_type] == NULL)
412 printf(", func-type unknown (%u)", func_type);
413 else
414 printf(", func-type %s (%u)",
415 tok2str(oam_functype_values[cell_type],"none",func_type),
416 func_type);
417
418 p += ATM_HDR_LEN_NOHEC + hec;
419
420 switch (cell_type << 4 | func_type) {
421 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_LOOPBACK):
422 oam_ptr.oam_fm_loopback = (const struct oam_fm_loopback_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN);
423 printf("\n\tLoopback-Indicator %s, Correlation-Tag 0x%08x",
424 tok2str(oam_fm_loopback_indicator_values,
425 "Unknown",
426 oam_ptr.oam_fm_loopback->loopback_indicator & OAM_FM_LOOPBACK_INDICATOR_MASK),
427 EXTRACT_LE_32BITS(&oam_ptr.oam_fm_loopback->correlation_tag));
428 printf("\n\tLocation-ID ");
429 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) {
430 printf("0x%02x ", oam_ptr.oam_fm_loopback->loopback_id[idx]);
431 }
432 printf("\n\tSource-ID ");
433 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->source_id); idx++) {
434 printf("0x%02x ", oam_ptr.oam_fm_loopback->source_id[idx]);
435 }
436 break;
437
438 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_AIS):
439 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_RDI):
440 oam_ptr.oam_fm_ais_rdi = (const struct oam_fm_ais_rdi_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN);
441 printf("\n\tFailure-type 0x%02x", oam_ptr.oam_fm_ais_rdi->failure_type);
442 printf("\n\tLocation-ID ");
443 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_ais_rdi->failure_location); idx++) {
444 printf("0x%02x ", oam_ptr.oam_fm_ais_rdi->failure_location[idx]);
445 }
446 break;
447
448 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK):
449 break;
450
451 default:
452 break;
453 }
454
455 /* crc10 checksum verification */
456 gen_crc10_table();
457 cksum = EXTRACT_16BITS(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN)
458 & OAM_CRC10_MASK;
459 cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN);
460
461 printf("\n\tcksum 0x%03x (%scorrect)",
462 cksum,
463 cksum_shouldbe == 0 ? "" : "in");
464
465 return 1;
466 }