Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / tcpdump / print-atm.c
blob531bc8858bcbfc03f6ca6b39827acf19af9a6e4e
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 #include <sys/cdefs.h>
24 #ifndef lint
25 #if 0
26 static const char rcsid[] _U_ =
27 "@(#) Header: /tcpdump/master/tcpdump/print-atm.c,v 1.38.2.6 2006/01/25 13:27:24 hannes Exp (LBL)";
28 #else
29 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
30 #endif
31 #endif
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
37 #include <tcpdump-stdinc.h>
39 #include <stdio.h>
40 #include <pcap.h>
41 #include <string.h>
43 #include "interface.h"
44 #include "extract.h"
45 #include "addrtoname.h"
46 #include "ethertype.h"
47 #include "atm.h"
48 #include "atmuni31.h"
49 #include "llc.h"
51 #include "ether.h"
53 struct tok oam_f_values[] = {
54 { OAMF4SC, "OAM F4 (segment)" },
55 { OAMF4EC, "OAM F4 (end)" },
56 { 0, NULL }
59 struct tok oam_celltype_values[] = {
60 { 0x1, "Fault Management" },
61 { 0x2, "Performance Management" },
62 { 0x8, "activate/deactivate" },
63 { 0xf, "System Management" },
64 { 0, NULL }
67 struct tok oam_fm_functype_values[] = {
68 { 0x0, "AIS" },
69 { 0x1, "RDI" },
70 { 0x4, "Continuity Check" },
71 { 0x8, "Loopback" },
72 { 0, NULL }
75 struct tok oam_pm_functype_values[] = {
76 { 0x0, "Forward Monitoring" },
77 { 0x1, "Backward Reporting" },
78 { 0x2, "Monitoring and Reporting" },
79 { 0, NULL }
82 struct tok oam_ad_functype_values[] = {
83 { 0x0, "Performance Monitoring" },
84 { 0x1, "Continuity Check" },
85 { 0, NULL }
88 static const struct tok *oam_functype_values[16] = {
89 NULL,
90 oam_fm_functype_values, /* 1 */
91 oam_pm_functype_values, /* 2 */
92 NULL,
93 NULL,
94 NULL,
95 NULL,
96 NULL,
97 oam_ad_functype_values, /* 8 */
98 NULL,
99 NULL,
100 NULL,
101 NULL,
102 NULL,
103 NULL,
104 NULL
108 * Print an RFC 1483 LLC-encapsulated ATM frame.
110 static void
111 atm_llc_print(const u_char *p, int length, int caplen)
113 u_short extracted_ethertype;
115 if (!llc_print(p, length, caplen, NULL, NULL,
116 &extracted_ethertype)) {
117 /* ether_type not known, print raw packet */
118 if (extracted_ethertype) {
119 printf("(LLC %s) ",
120 etherproto_string(htons(extracted_ethertype)));
122 if (!suppress_default_print)
123 default_print(p, caplen);
128 * Given a SAP value, generate the LLC header value for a UI packet
129 * with that SAP as the source and destination SAP.
131 #define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03)
134 * This is the top level routine of the printer. 'p' points
135 * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp,
136 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
137 * is the number of bytes actually captured.
139 u_int
140 atm_if_print(const struct pcap_pkthdr *h, const u_char *p)
142 u_int caplen = h->caplen;
143 u_int length = h->len;
144 u_int32_t llchdr;
145 u_int hdrlen = 0;
147 if (caplen < 8) {
148 printf("[|atm]");
149 return (caplen);
152 /* Cisco Style NLPID ? */
153 if (*p == LLC_UI) {
154 if (eflag)
155 printf("CNLPID ");
156 isoclns_print(p+1, length-1, caplen-1);
157 return hdrlen;
161 * Extract the presumed LLC header into a variable, for quick
162 * testing.
163 * Then check for a header that's neither a header for a SNAP
164 * packet nor an RFC 2684 routed NLPID-formatted PDU nor
165 * an 802.2-but-no-SNAP IP packet.
167 llchdr = EXTRACT_24BITS(p);
168 if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) &&
169 llchdr != LLC_UI_HDR(LLCSAP_ISONS) &&
170 llchdr != LLC_UI_HDR(LLCSAP_IP)) {
172 * XXX - assume 802.6 MAC header from Fore driver.
174 * Unfortunately, the above list doesn't check for
175 * all known SAPs, doesn't check for headers where
176 * the source and destination SAP aren't the same,
177 * and doesn't check for non-UI frames. It also
178 * runs the risk of an 802.6 MAC header that happens
179 * to begin with one of those values being
180 * incorrectly treated as an 802.2 header.
182 * So is that Fore driver still around? And, if so,
183 * is it still putting 802.6 MAC headers on ATM
184 * packets? If so, could it be changed to use a
185 * new DLT_IEEE802_6 value if we added it?
187 if (eflag)
188 printf("%08x%08x %08x%08x ",
189 EXTRACT_32BITS(p),
190 EXTRACT_32BITS(p+4),
191 EXTRACT_32BITS(p+8),
192 EXTRACT_32BITS(p+12));
193 p += 20;
194 length -= 20;
195 caplen -= 20;
196 hdrlen += 20;
198 atm_llc_print(p, length, caplen);
199 return (hdrlen);
203 * ATM signalling.
205 static struct tok msgtype2str[] = {
206 { CALL_PROCEED, "Call_proceeding" },
207 { CONNECT, "Connect" },
208 { CONNECT_ACK, "Connect_ack" },
209 { SETUP, "Setup" },
210 { RELEASE, "Release" },
211 { RELEASE_DONE, "Release_complete" },
212 { RESTART, "Restart" },
213 { RESTART_ACK, "Restart_ack" },
214 { STATUS, "Status" },
215 { STATUS_ENQ, "Status_enquiry" },
216 { ADD_PARTY, "Add_party" },
217 { ADD_PARTY_ACK, "Add_party_ack" },
218 { ADD_PARTY_REJ, "Add_party_reject" },
219 { DROP_PARTY, "Drop_party" },
220 { DROP_PARTY_ACK, "Drop_party_ack" },
221 { 0, NULL }
224 static void
225 sig_print(const u_char *p, int caplen)
227 bpf_u_int32 call_ref;
229 if (caplen < PROTO_POS) {
230 printf("[|atm]");
231 return;
233 if (p[PROTO_POS] == Q2931) {
235 * protocol:Q.2931 for User to Network Interface
236 * (UNI 3.1) signalling
238 printf("Q.2931");
239 if (caplen < MSG_TYPE_POS) {
240 printf(" [|atm]");
241 return;
243 printf(":%s ",
244 tok2str(msgtype2str, "msgtype#%d", p[MSG_TYPE_POS]));
246 if (caplen < CALL_REF_POS+3) {
247 printf("[|atm]");
248 return;
250 call_ref = EXTRACT_24BITS(&p[CALL_REF_POS]);
251 printf("CALL_REF:0x%06x", call_ref);
252 } else {
253 /* SCCOP with some unknown protocol atop it */
254 printf("SSCOP, proto %d ", p[PROTO_POS]);
259 * Print an ATM PDU (such as an AAL5 PDU).
261 void
262 atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length,
263 u_int caplen)
265 if (eflag)
266 printf("VPI:%u VCI:%u ", vpi, vci);
268 if (vpi == 0) {
269 switch (vci) {
271 case PPC:
272 sig_print(p, caplen);
273 return;
275 case BCC:
276 printf("broadcast sig: ");
277 return;
279 case OAMF4SC: /* fall through */
280 case OAMF4EC:
281 oam_print(p, length, ATM_OAM_HEC);
282 return;
284 case METAC:
285 printf("meta: ");
286 return;
288 case ILMIC:
289 printf("ilmi: ");
290 snmp_print(p, length);
291 return;
295 switch (traftype) {
297 case ATM_LLC:
298 default:
300 * Assumes traffic is LLC if unknown.
302 atm_llc_print(p, length, caplen);
303 break;
305 case ATM_LANE:
306 lane_print(p, length, caplen);
307 break;
311 int
312 oam_print (const u_char *p, u_int length, u_int hec) {
314 u_int32_t cell_header;
315 u_int16_t cell_type, func_type,vpi,vci,payload,clp;
317 cell_header = EXTRACT_32BITS(p+hec);
318 cell_type = ((*(p+4+hec))>>4) & 0x0f;
319 func_type = *(p+4+hec) & 0x0f;
321 vpi = (cell_header>>20)&0xff;
322 vci = (cell_header>>4)&0xffff;
323 payload = (cell_header>>1)&0x7;
324 clp = cell_header&0x1;
326 printf("%s, vpi %u, vci %u, payload %u, clp %u, ",
327 tok2str(oam_f_values, "OAM F5", vci),
328 vpi, vci, payload, clp);
330 printf("cell-type %s (%u)",
331 tok2str(oam_celltype_values, "unknown", cell_type),
332 cell_type);
334 if (oam_functype_values[cell_type] == NULL)
335 printf(", func-type unknown (%u)", func_type);
336 else
337 printf(", func-type %s (%u)",
338 bittok2str(oam_functype_values[cell_type],"none",func_type),
339 func_type);
341 printf(", length %u",length);
342 return 1;