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