]> The Tcpdump Group git mirrors - tcpdump/blob - print-atm.c
get rid of EXTRACT_ lookalikes, eliminated atm_llc_print -> call direct to llc_print
[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[] =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.27 2002-12-04 19:12:39 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
43 #include "ether.h"
44
45 /*
46 * This is the top level routine of the printer. 'p' points
47 * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp,
48 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
49 * is the number of bytes actually captured.
50 */
51 void
52 atm_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p)
53 {
54 u_int caplen = h->caplen;
55 u_int length = h->len;
56
57 ++infodelay;
58 ts_print(&h->ts);
59
60 if (caplen < 8) {
61 printf("[|atm]");
62 goto out;
63 }
64
65 /*
66 * Some printers want to check that they're not walking off the
67 * end of the packet.
68 * Rather than pass it all the way down, we set this global.
69 */
70 snapend = p + caplen;
71
72 if (EXTRACT_24BITS(p) == 0xaaaa03) {
73 /*
74 * XXX - assume 802.6 MAC header from Fore driver.
75 * XXX - should we also assume it's not a MAC header
76 * if it begins with 0xfe 0xfe 0x03, for RFC 2684
77 * routed NLPID-formatted PDUs?
78 */
79 if (eflag)
80 printf("%08x%08x %08x%08x ",
81 EXTRACT_32BITS(p),
82 EXTRACT_32BITS(p+4),
83 EXTRACT_32BITS(p+8),
84 EXTRACT_32BITS(p+12));
85 p += 20;
86 length -= 20;
87 caplen -= 20;
88 }
89
90 /* lets call into the generic LLC handler */
91 llc_print(p, length, caplen, NULL, NULL, NULL);
92
93 if (xflag)
94 default_print(p, caplen);
95 out:
96 putchar('\n');
97 }
98
99 /*
100 * ATM signalling.
101 */
102 static struct tok msgtype2str[] = {
103 { CALL_PROCEED, "Call_proceeding" },
104 { CONNECT, "Connect" },
105 { CONNECT_ACK, "Connect_ack" },
106 { SETUP, "Setup" },
107 { RELEASE, "Release" },
108 { RELEASE_DONE, "Release_complete" },
109 { RESTART, "Restart" },
110 { RESTART_ACK, "Restart_ack" },
111 { STATUS, "Status" },
112 { STATUS_ENQ, "Status_enquiry" },
113 { ADD_PARTY, "Add_party" },
114 { ADD_PARTY_ACK, "Add_party_ack" },
115 { ADD_PARTY_REJ, "Add_party_reject" },
116 { DROP_PARTY, "Drop_party" },
117 { DROP_PARTY_ACK, "Drop_party_ack" },
118 { 0, NULL }
119 };
120
121 static void
122 sig_print(const u_char *p, int caplen)
123 {
124 bpf_u_int32 call_ref;
125
126 if (caplen < PROTO_POS) {
127 printf("[|atm]");
128 return;
129 }
130 if (p[PROTO_POS] == Q2931) {
131 /*
132 * protocol:Q.2931 for User to Network Interface
133 * (UNI 3.1) signalling
134 */
135 printf("Q.2931");
136 if (caplen < MSG_TYPE_POS) {
137 printf(" [|atm]");
138 return;
139 }
140 printf(":%s ",
141 tok2str(msgtype2str, "msgtype#%d", p[MSG_TYPE_POS]));
142
143 if (caplen < CALL_REF_POS+3) {
144 printf("[|atm]");
145 return;
146 }
147 call_ref = EXTRACT_24BITS(&p[CALL_REF_POS]);
148 printf("CALL_REF:0x%06x", call_ref);
149 } else {
150 /* SCCOP with some unknown protocol atop it */
151 printf("SSCOP, proto %d ", p[PROTO_POS]);
152 }
153 }
154
155 /*
156 * Print an ATM PDU (such as an AAL5 PDU).
157 */
158 void
159 atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length,
160 u_int caplen)
161 {
162 if (eflag)
163 printf("VPI:%u VCI:%u ", vpi, vci);
164
165 /*
166 * Some printers want to check that they're not walking off the
167 * end of the packet.
168 * Rather than pass it all the way down, we set this global.
169 */
170 snapend = p + caplen;
171
172 if (vpi == 0) {
173 switch (vci) {
174
175 case PPC:
176 sig_print(p, caplen);
177 goto out;
178
179 case BCC:
180 printf("broadcast sig: ");
181 goto out;
182
183 case OAMF4SC:
184 printf("oamF4(segment): ");
185 goto out;
186
187 case OAMF4EC:
188 printf("oamF4(end): ");
189 goto out;
190
191 case METAC:
192 printf("meta: ");
193 goto out;
194
195 case ILMIC:
196 printf("ilmi: ");
197 snmp_print(p, length);
198 goto out;
199 }
200 }
201
202 switch (traftype) {
203
204 case ATM_LLC:
205 default:
206 /*
207 * Assumes traffic is LLC if unknown.
208 * call into the generic LLC handler
209 */
210 llc_print(p, length, caplen, NULL, NULL, NULL);
211 break;
212
213 case ATM_LANE:
214 lane_print(p, length, caplen);
215 break;
216 }
217
218 out:
219 if (xflag)
220 default_print(p, caplen);
221 }