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