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