xref: /dragonfly/contrib/tcpdump/print-atm.c (revision ed775ee7)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (c) 1994, 1995, 1996, 1997
341c99275SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos  * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos  * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos  * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos  * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos  * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos  * or promote products derived from this software without specific prior
1641c99275SPeter Avalos  * written permission.
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos  */
21411677aeSAaron LI 
22411677aeSAaron LI /* \summary: Asynchronous Transfer Mode (ATM) printer */
2341c99275SPeter Avalos 
2441c99275SPeter Avalos #ifdef HAVE_CONFIG_H
25*ed775ee7SAntonio Huete Jimenez #include <config.h>
2641c99275SPeter Avalos #endif
2741c99275SPeter Avalos 
28*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
2941c99275SPeter Avalos 
30*ed775ee7SAntonio Huete Jimenez #define ND_LONGJMP_FROM_TCHECK
31411677aeSAaron LI #include "netdissect.h"
3241c99275SPeter Avalos #include "extract.h"
3341c99275SPeter Avalos #include "addrtoname.h"
3441c99275SPeter Avalos #include "atm.h"
3541c99275SPeter Avalos #include "llc.h"
3641c99275SPeter Avalos 
37411677aeSAaron LI /* start of the original atmuni31.h */
38411677aeSAaron LI 
39411677aeSAaron LI /*
40411677aeSAaron LI  * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
41411677aeSAaron LI  * All rights reserved.
42411677aeSAaron LI  *
43411677aeSAaron LI  * Redistribution and use in source and binary forms, with or without
44411677aeSAaron LI  * modification, are permitted provided that the following conditions
45411677aeSAaron LI  * are met:
46411677aeSAaron LI  * 1. Redistributions of source code must retain the above copyright
47411677aeSAaron LI  *    notice, this list of conditions and the following disclaimer.
48411677aeSAaron LI  * 2. Redistributions in binary form must reproduce the above copyright
49411677aeSAaron LI  *    notice, this list of conditions and the following disclaimer in the
50411677aeSAaron LI  *    documentation and/or other materials provided with the distribution.
51411677aeSAaron LI  * 3. All advertising materials mentioning features or use of this software
52411677aeSAaron LI  *    must display the following acknowledgement:
53411677aeSAaron LI  *      This product includes software developed by Yen Yen Lim and
54411677aeSAaron LI         North Dakota State University
55411677aeSAaron LI  * 4. The name of the author may not be used to endorse or promote products
56411677aeSAaron LI  *    derived from this software without specific prior written permission.
57411677aeSAaron LI  *
58411677aeSAaron LI  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59411677aeSAaron LI  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
60411677aeSAaron LI  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
61411677aeSAaron LI  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
62411677aeSAaron LI  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
63411677aeSAaron LI  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
64411677aeSAaron LI  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65411677aeSAaron LI  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
66411677aeSAaron LI  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
67411677aeSAaron LI  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68411677aeSAaron LI  * POSSIBILITY OF SUCH DAMAGE.
69411677aeSAaron LI  */
70411677aeSAaron LI 
71411677aeSAaron LI /* Based on UNI3.1 standard by ATM Forum */
72411677aeSAaron LI 
73411677aeSAaron LI /* ATM traffic types based on VPI=0 and (the following VCI */
74411677aeSAaron LI #define VCI_PPC			0x05	/* Point-to-point signal msg */
75411677aeSAaron LI #define VCI_BCC			0x02	/* Broadcast signal msg */
76411677aeSAaron LI #define VCI_OAMF4SC		0x03	/* Segment OAM F4 flow cell */
77411677aeSAaron LI #define VCI_OAMF4EC		0x04	/* End-to-end OAM F4 flow cell */
78411677aeSAaron LI #define VCI_METAC		0x01	/* Meta signal msg */
79411677aeSAaron LI #define VCI_ILMIC		0x10	/* ILMI msg */
80411677aeSAaron LI 
81411677aeSAaron LI /* Q.2931 signalling messages */
82411677aeSAaron LI #define CALL_PROCEED		0x02	/* call proceeding */
83411677aeSAaron LI #define CONNECT			0x07	/* connect */
84411677aeSAaron LI #define CONNECT_ACK		0x0f	/* connect_ack */
85411677aeSAaron LI #define SETUP			0x05	/* setup */
86411677aeSAaron LI #define RELEASE			0x4d	/* release */
87411677aeSAaron LI #define RELEASE_DONE		0x5a	/* release_done */
88411677aeSAaron LI #define RESTART			0x46	/* restart */
89411677aeSAaron LI #define RESTART_ACK		0x4e	/* restart ack */
90411677aeSAaron LI #define STATUS			0x7d	/* status */
91411677aeSAaron LI #define STATUS_ENQ		0x75	/* status ack */
92411677aeSAaron LI #define ADD_PARTY		0x80	/* add party */
93411677aeSAaron LI #define ADD_PARTY_ACK		0x81	/* add party ack */
94411677aeSAaron LI #define ADD_PARTY_REJ		0x82	/* add party rej */
95411677aeSAaron LI #define DROP_PARTY		0x83	/* drop party */
96411677aeSAaron LI #define DROP_PARTY_ACK		0x84	/* drop party ack */
97411677aeSAaron LI 
98411677aeSAaron LI /* Information Element Parameters in the signalling messages */
99411677aeSAaron LI #define CAUSE			0x08	/* cause */
100411677aeSAaron LI #define ENDPT_REF		0x54	/* endpoint reference */
101411677aeSAaron LI #define AAL_PARA		0x58	/* ATM adaptation layer parameters */
102411677aeSAaron LI #define TRAFF_DESCRIP		0x59	/* atm traffic descriptors */
103411677aeSAaron LI #define CONNECT_ID		0x5a	/* connection identifier */
104411677aeSAaron LI #define QOS_PARA		0x5c	/* quality of service parameters */
105411677aeSAaron LI #define B_HIGHER		0x5d	/* broadband higher layer information */
106411677aeSAaron LI #define B_BEARER		0x5e	/* broadband bearer capability */
107411677aeSAaron LI #define B_LOWER			0x5f	/* broadband lower information */
108411677aeSAaron LI #define CALLING_PARTY		0x6c	/* calling party number */
109411677aeSAaron LI #define CALLED_PARTY		0x70	/* called party nmber */
110411677aeSAaron LI 
111411677aeSAaron LI #define Q2931			0x09
112411677aeSAaron LI 
113411677aeSAaron LI /* Q.2931 signalling general messages format */
114411677aeSAaron LI #define PROTO_POS       0	/* offset of protocol discriminator */
115411677aeSAaron LI #define CALL_REF_POS    2	/* offset of call reference value */
116411677aeSAaron LI #define MSG_TYPE_POS    5	/* offset of message type */
117*ed775ee7SAntonio Huete Jimenez #if 0
118*ed775ee7SAntonio Huete Jimenez #define MSG_LEN_POS     7	/* offset of message length */
119411677aeSAaron LI #define IE_BEGIN_POS    9	/* offset of first information element */
120411677aeSAaron LI 
121411677aeSAaron LI /* format of signalling messages */
122411677aeSAaron LI #define TYPE_POS	0
123411677aeSAaron LI #define LEN_POS		2
124411677aeSAaron LI #define FIELD_BEGIN_POS 4
125*ed775ee7SAntonio Huete Jimenez #endif
126411677aeSAaron LI 
127411677aeSAaron LI /* end of the original atmuni31.h */
128411677aeSAaron LI 
12941c99275SPeter Avalos 
130ea7b4bf5SPeter Avalos #define OAM_CRC10_MASK 0x3ff
131ea7b4bf5SPeter Avalos #define OAM_PAYLOAD_LEN 48
132ea7b4bf5SPeter Avalos #define OAM_FUNCTION_SPECIFIC_LEN 45 /* this excludes crc10 and cell-type/function-type */
133ea7b4bf5SPeter Avalos #define OAM_CELLTYPE_FUNCTYPE_LEN 1
134ea7b4bf5SPeter Avalos 
135411677aeSAaron LI static const struct tok oam_f_values[] = {
136ea7b4bf5SPeter Avalos     { VCI_OAMF4SC, "OAM F4 (segment)" },
137ea7b4bf5SPeter Avalos     { VCI_OAMF4EC, "OAM F4 (end)" },
13841c99275SPeter Avalos     { 0, NULL }
13941c99275SPeter Avalos };
14041c99275SPeter Avalos 
141411677aeSAaron LI static const struct tok atm_pty_values[] = {
142ea7b4bf5SPeter Avalos     { 0x0, "user data, uncongested, SDU 0" },
143ea7b4bf5SPeter Avalos     { 0x1, "user data, uncongested, SDU 1" },
144ea7b4bf5SPeter Avalos     { 0x2, "user data, congested, SDU 0" },
145ea7b4bf5SPeter Avalos     { 0x3, "user data, congested, SDU 1" },
146ea7b4bf5SPeter Avalos     { 0x4, "VCC OAM F5 flow segment" },
147ea7b4bf5SPeter Avalos     { 0x5, "VCC OAM F5 flow end-to-end" },
148ea7b4bf5SPeter Avalos     { 0x6, "Traffic Control and resource Mgmt" },
149ea7b4bf5SPeter Avalos     { 0, NULL }
150ea7b4bf5SPeter Avalos };
151ea7b4bf5SPeter Avalos 
152ea7b4bf5SPeter Avalos #define OAM_CELLTYPE_FM 0x1
153ea7b4bf5SPeter Avalos #define OAM_CELLTYPE_PM 0x2
154ea7b4bf5SPeter Avalos #define OAM_CELLTYPE_AD 0x8
155ea7b4bf5SPeter Avalos #define OAM_CELLTYPE_SM 0xf
156ea7b4bf5SPeter Avalos 
157411677aeSAaron LI static const struct tok oam_celltype_values[] = {
158ea7b4bf5SPeter Avalos     { OAM_CELLTYPE_FM, "Fault Management" },
159ea7b4bf5SPeter Avalos     { OAM_CELLTYPE_PM, "Performance Management" },
160ea7b4bf5SPeter Avalos     { OAM_CELLTYPE_AD, "activate/deactivate" },
161ea7b4bf5SPeter Avalos     { OAM_CELLTYPE_SM, "System Management" },
16241c99275SPeter Avalos     { 0, NULL }
16341c99275SPeter Avalos };
16441c99275SPeter Avalos 
165ea7b4bf5SPeter Avalos #define OAM_FM_FUNCTYPE_AIS       0x0
166ea7b4bf5SPeter Avalos #define OAM_FM_FUNCTYPE_RDI       0x1
167ea7b4bf5SPeter Avalos #define OAM_FM_FUNCTYPE_CONTCHECK 0x4
168ea7b4bf5SPeter Avalos #define OAM_FM_FUNCTYPE_LOOPBACK  0x8
169ea7b4bf5SPeter Avalos 
170411677aeSAaron LI static const struct tok oam_fm_functype_values[] = {
171ea7b4bf5SPeter Avalos     { OAM_FM_FUNCTYPE_AIS, "AIS" },
172ea7b4bf5SPeter Avalos     { OAM_FM_FUNCTYPE_RDI, "RDI" },
173ea7b4bf5SPeter Avalos     { OAM_FM_FUNCTYPE_CONTCHECK, "Continuity Check" },
174ea7b4bf5SPeter Avalos     { OAM_FM_FUNCTYPE_LOOPBACK, "Loopback" },
17541c99275SPeter Avalos     { 0, NULL }
17641c99275SPeter Avalos };
17741c99275SPeter Avalos 
178411677aeSAaron LI static const struct tok oam_pm_functype_values[] = {
17941c99275SPeter Avalos     { 0x0, "Forward Monitoring" },
18041c99275SPeter Avalos     { 0x1, "Backward Reporting" },
18141c99275SPeter Avalos     { 0x2, "Monitoring and Reporting" },
18241c99275SPeter Avalos     { 0, NULL }
18341c99275SPeter Avalos };
18441c99275SPeter Avalos 
185411677aeSAaron LI static const struct tok oam_ad_functype_values[] = {
18641c99275SPeter Avalos     { 0x0, "Performance Monitoring" },
18741c99275SPeter Avalos     { 0x1, "Continuity Check" },
18841c99275SPeter Avalos     { 0, NULL }
18941c99275SPeter Avalos };
19041c99275SPeter Avalos 
191ea7b4bf5SPeter Avalos #define OAM_FM_LOOPBACK_INDICATOR_MASK 0x1
192ea7b4bf5SPeter Avalos 
193411677aeSAaron LI static const struct tok oam_fm_loopback_indicator_values[] = {
194ea7b4bf5SPeter Avalos     { 0x0, "Reply" },
195ea7b4bf5SPeter Avalos     { 0x1, "Request" },
196ea7b4bf5SPeter Avalos     { 0, NULL }
197ea7b4bf5SPeter Avalos };
198ea7b4bf5SPeter Avalos 
199*ed775ee7SAntonio Huete Jimenez static const struct uint_tokary oam_celltype2tokary[] = {
200*ed775ee7SAntonio Huete Jimenez 	{ OAM_CELLTYPE_FM, oam_fm_functype_values },
201*ed775ee7SAntonio Huete Jimenez 	{ OAM_CELLTYPE_PM, oam_pm_functype_values },
202*ed775ee7SAntonio Huete Jimenez 	{ OAM_CELLTYPE_AD, oam_ad_functype_values },
203*ed775ee7SAntonio Huete Jimenez 	/* uint2tokary() does not use array termination. */
20441c99275SPeter Avalos };
20541c99275SPeter Avalos 
20641c99275SPeter Avalos /*
20741c99275SPeter Avalos  * Print an RFC 1483 LLC-encapsulated ATM frame.
20841c99275SPeter Avalos  */
209411677aeSAaron LI static u_int
atm_llc_print(netdissect_options * ndo,const u_char * p,int length,int caplen)210411677aeSAaron LI atm_llc_print(netdissect_options *ndo,
211411677aeSAaron LI               const u_char *p, int length, int caplen)
21241c99275SPeter Avalos {
213411677aeSAaron LI 	int llc_hdrlen;
21441c99275SPeter Avalos 
215411677aeSAaron LI 	llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
216411677aeSAaron LI 	if (llc_hdrlen < 0) {
217411677aeSAaron LI 		/* packet not known, print raw packet */
218411677aeSAaron LI 		if (!ndo->ndo_suppress_default_print)
219411677aeSAaron LI 			ND_DEFAULTPRINT(p, caplen);
220411677aeSAaron LI 		llc_hdrlen = -llc_hdrlen;
22141c99275SPeter Avalos 	}
222411677aeSAaron LI 	return (llc_hdrlen);
22341c99275SPeter Avalos }
22441c99275SPeter Avalos 
22541c99275SPeter Avalos /*
22641c99275SPeter Avalos  * Given a SAP value, generate the LLC header value for a UI packet
22741c99275SPeter Avalos  * with that SAP as the source and destination SAP.
22841c99275SPeter Avalos  */
22941c99275SPeter Avalos #define LLC_UI_HDR(sap)	((sap)<<16 | (sap<<8) | 0x03)
23041c99275SPeter Avalos 
23141c99275SPeter Avalos /*
23241c99275SPeter Avalos  * This is the top level routine of the printer.  'p' points
23341c99275SPeter Avalos  * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp,
23441c99275SPeter Avalos  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
23541c99275SPeter Avalos  * is the number of bytes actually captured.
23641c99275SPeter Avalos  */
237*ed775ee7SAntonio Huete Jimenez void
atm_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)238411677aeSAaron LI atm_if_print(netdissect_options *ndo,
239411677aeSAaron LI              const struct pcap_pkthdr *h, const u_char *p)
24041c99275SPeter Avalos {
24141c99275SPeter Avalos 	u_int caplen = h->caplen;
24241c99275SPeter Avalos 	u_int length = h->len;
243411677aeSAaron LI 	uint32_t llchdr;
24441c99275SPeter Avalos 	u_int hdrlen = 0;
24541c99275SPeter Avalos 
246*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "atm";
24741c99275SPeter Avalos 
24841c99275SPeter Avalos         /* Cisco Style NLPID ? */
249*ed775ee7SAntonio Huete Jimenez         if (GET_U_1(p) == LLC_UI) {
250411677aeSAaron LI             if (ndo->ndo_eflag)
251*ed775ee7SAntonio Huete Jimenez                 ND_PRINT("CNLPID ");
252*ed775ee7SAntonio Huete Jimenez             ndo->ndo_ll_hdr_len += 1;
253411677aeSAaron LI             isoclns_print(ndo, p + 1, length - 1);
254*ed775ee7SAntonio Huete Jimenez             return;
25541c99275SPeter Avalos         }
25641c99275SPeter Avalos 
25741c99275SPeter Avalos 	/*
258411677aeSAaron LI 	 * Must have at least a DSAP, an SSAP, and the first byte of the
259411677aeSAaron LI 	 * control field.
260411677aeSAaron LI 	 */
261411677aeSAaron LI 
262411677aeSAaron LI 	/*
26341c99275SPeter Avalos 	 * Extract the presumed LLC header into a variable, for quick
26441c99275SPeter Avalos 	 * testing.
26541c99275SPeter Avalos 	 * Then check for a header that's neither a header for a SNAP
26641c99275SPeter Avalos 	 * packet nor an RFC 2684 routed NLPID-formatted PDU nor
26741c99275SPeter Avalos 	 * an 802.2-but-no-SNAP IP packet.
26841c99275SPeter Avalos 	 */
269*ed775ee7SAntonio Huete Jimenez 	llchdr = GET_BE_U_3(p);
27041c99275SPeter Avalos 	if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) &&
27141c99275SPeter Avalos 	    llchdr != LLC_UI_HDR(LLCSAP_ISONS) &&
27241c99275SPeter Avalos 	    llchdr != LLC_UI_HDR(LLCSAP_IP)) {
27341c99275SPeter Avalos 		/*
27441c99275SPeter Avalos 		 * XXX - assume 802.6 MAC header from Fore driver.
27541c99275SPeter Avalos 		 *
27641c99275SPeter Avalos 		 * Unfortunately, the above list doesn't check for
27741c99275SPeter Avalos 		 * all known SAPs, doesn't check for headers where
27841c99275SPeter Avalos 		 * the source and destination SAP aren't the same,
27941c99275SPeter Avalos 		 * and doesn't check for non-UI frames.  It also
28041c99275SPeter Avalos 		 * runs the risk of an 802.6 MAC header that happens
28141c99275SPeter Avalos 		 * to begin with one of those values being
28241c99275SPeter Avalos 		 * incorrectly treated as an 802.2 header.
28341c99275SPeter Avalos 		 *
28441c99275SPeter Avalos 		 * So is that Fore driver still around?  And, if so,
28541c99275SPeter Avalos 		 * is it still putting 802.6 MAC headers on ATM
28641c99275SPeter Avalos 		 * packets?  If so, could it be changed to use a
28741c99275SPeter Avalos 		 * new DLT_IEEE802_6 value if we added it?
28841c99275SPeter Avalos 		 */
289411677aeSAaron LI 		if (ndo->ndo_eflag)
290*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("%08x%08x %08x%08x ",
291*ed775ee7SAntonio Huete Jimenez 			       GET_BE_U_4(p),
292*ed775ee7SAntonio Huete Jimenez 			       GET_BE_U_4(p + 4),
293*ed775ee7SAntonio Huete Jimenez 			       GET_BE_U_4(p + 8),
294*ed775ee7SAntonio Huete Jimenez 			       GET_BE_U_4(p + 12));
295*ed775ee7SAntonio Huete Jimenez 		/* Always cover the full header. */
296*ed775ee7SAntonio Huete Jimenez 		ND_TCHECK_LEN(p, 20);
29741c99275SPeter Avalos 		p += 20;
29841c99275SPeter Avalos 		length -= 20;
29941c99275SPeter Avalos 		caplen -= 20;
30041c99275SPeter Avalos 		hdrlen += 20;
30141c99275SPeter Avalos 	}
302*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_ll_hdr_len += hdrlen;
303*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_ll_hdr_len += atm_llc_print(ndo, p, length, caplen);
30441c99275SPeter Avalos }
30541c99275SPeter Avalos 
30641c99275SPeter Avalos /*
30741c99275SPeter Avalos  * ATM signalling.
30841c99275SPeter Avalos  */
309411677aeSAaron LI static const struct tok msgtype2str[] = {
31041c99275SPeter Avalos 	{ CALL_PROCEED,		"Call_proceeding" },
31141c99275SPeter Avalos 	{ CONNECT,		"Connect" },
31241c99275SPeter Avalos 	{ CONNECT_ACK,		"Connect_ack" },
31341c99275SPeter Avalos 	{ SETUP,		"Setup" },
31441c99275SPeter Avalos 	{ RELEASE,		"Release" },
31541c99275SPeter Avalos 	{ RELEASE_DONE,		"Release_complete" },
31641c99275SPeter Avalos 	{ RESTART,		"Restart" },
31741c99275SPeter Avalos 	{ RESTART_ACK,		"Restart_ack" },
31841c99275SPeter Avalos 	{ STATUS,		"Status" },
31941c99275SPeter Avalos 	{ STATUS_ENQ,		"Status_enquiry" },
32041c99275SPeter Avalos 	{ ADD_PARTY,		"Add_party" },
32141c99275SPeter Avalos 	{ ADD_PARTY_ACK,	"Add_party_ack" },
32241c99275SPeter Avalos 	{ ADD_PARTY_REJ,	"Add_party_reject" },
32341c99275SPeter Avalos 	{ DROP_PARTY,		"Drop_party" },
32441c99275SPeter Avalos 	{ DROP_PARTY_ACK,	"Drop_party_ack" },
32541c99275SPeter Avalos 	{ 0,			NULL }
32641c99275SPeter Avalos };
32741c99275SPeter Avalos 
32841c99275SPeter Avalos static void
sig_print(netdissect_options * ndo,const u_char * p)329411677aeSAaron LI sig_print(netdissect_options *ndo,
330411677aeSAaron LI           const u_char *p)
33141c99275SPeter Avalos {
332411677aeSAaron LI 	uint32_t call_ref;
33341c99275SPeter Avalos 
334*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(p + PROTO_POS) == Q2931) {
33541c99275SPeter Avalos 		/*
33641c99275SPeter Avalos 		 * protocol:Q.2931 for User to Network Interface
33741c99275SPeter Avalos 		 * (UNI 3.1) signalling
33841c99275SPeter Avalos 		 */
339*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("Q.2931");
340*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(":%s ",
341*ed775ee7SAntonio Huete Jimenez 		    tok2str(msgtype2str, "msgtype#%u", GET_U_1(p + MSG_TYPE_POS)));
34241c99275SPeter Avalos 
34327bfbee1SPeter Avalos 		/*
34427bfbee1SPeter Avalos 		 * The call reference comes before the message type,
34527bfbee1SPeter Avalos 		 * so if we know we have the message type, which we
34627bfbee1SPeter Avalos 		 * do from the caplen test above, we also know we have
34727bfbee1SPeter Avalos 		 * the call reference.
34827bfbee1SPeter Avalos 		 */
349*ed775ee7SAntonio Huete Jimenez 		call_ref = GET_BE_U_3(p + CALL_REF_POS);
350*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("CALL_REF:0x%06x", call_ref);
35141c99275SPeter Avalos 	} else {
352*ed775ee7SAntonio Huete Jimenez 		/* SSCOP with some unknown protocol atop it */
353*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("SSCOP, proto %u ", GET_U_1(p + PROTO_POS));
35441c99275SPeter Avalos 	}
35541c99275SPeter Avalos }
35641c99275SPeter Avalos 
35741c99275SPeter Avalos /*
35841c99275SPeter Avalos  * Print an ATM PDU (such as an AAL5 PDU).
35941c99275SPeter Avalos  */
36041c99275SPeter Avalos void
atm_print(netdissect_options * ndo,u_int vpi,u_int vci,u_int traftype,const u_char * p,u_int length,u_int caplen)361411677aeSAaron LI atm_print(netdissect_options *ndo,
362411677aeSAaron LI           u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length,
36341c99275SPeter Avalos           u_int caplen)
36441c99275SPeter Avalos {
365*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "atm";
366411677aeSAaron LI 	if (ndo->ndo_eflag)
367*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("VPI:%u VCI:%u ", vpi, vci);
36841c99275SPeter Avalos 
36941c99275SPeter Avalos 	if (vpi == 0) {
37041c99275SPeter Avalos 		switch (vci) {
37141c99275SPeter Avalos 
372ea7b4bf5SPeter Avalos 		case VCI_PPC:
373411677aeSAaron LI 			sig_print(ndo, p);
37441c99275SPeter Avalos 			return;
37541c99275SPeter Avalos 
376ea7b4bf5SPeter Avalos 		case VCI_BCC:
377*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("broadcast sig: ");
37841c99275SPeter Avalos 			return;
37941c99275SPeter Avalos 
380ea7b4bf5SPeter Avalos 		case VCI_OAMF4SC: /* fall through */
381ea7b4bf5SPeter Avalos 		case VCI_OAMF4EC:
382411677aeSAaron LI 			oam_print(ndo, p, length, ATM_OAM_HEC);
38341c99275SPeter Avalos 			return;
38441c99275SPeter Avalos 
385ea7b4bf5SPeter Avalos 		case VCI_METAC:
386*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("meta: ");
38741c99275SPeter Avalos 			return;
38841c99275SPeter Avalos 
389ea7b4bf5SPeter Avalos 		case VCI_ILMIC:
390*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("ilmi: ");
391411677aeSAaron LI 			snmp_print(ndo, p, length);
39241c99275SPeter Avalos 			return;
39341c99275SPeter Avalos 		}
39441c99275SPeter Avalos 	}
39541c99275SPeter Avalos 
39641c99275SPeter Avalos 	switch (traftype) {
39741c99275SPeter Avalos 
39841c99275SPeter Avalos 	case ATM_LLC:
39941c99275SPeter Avalos 	default:
40041c99275SPeter Avalos 		/*
40141c99275SPeter Avalos 		 * Assumes traffic is LLC if unknown.
40241c99275SPeter Avalos 		 */
403411677aeSAaron LI 		atm_llc_print(ndo, p, length, caplen);
40441c99275SPeter Avalos 		break;
40541c99275SPeter Avalos 
40641c99275SPeter Avalos 	case ATM_LANE:
407411677aeSAaron LI 		lane_print(ndo, p, length, caplen);
40841c99275SPeter Avalos 		break;
40941c99275SPeter Avalos 	}
41041c99275SPeter Avalos }
41141c99275SPeter Avalos 
412ea7b4bf5SPeter Avalos struct oam_fm_loopback_t {
413*ed775ee7SAntonio Huete Jimenez     nd_uint8_t  loopback_indicator;
414*ed775ee7SAntonio Huete Jimenez     nd_uint32_t correlation_tag;
415*ed775ee7SAntonio Huete Jimenez     nd_byte     loopback_id[12];
416*ed775ee7SAntonio Huete Jimenez     nd_byte     source_id[12];
417*ed775ee7SAntonio Huete Jimenez     nd_byte     unused[16];
418ea7b4bf5SPeter Avalos };
419ea7b4bf5SPeter Avalos 
420ea7b4bf5SPeter Avalos struct oam_fm_ais_rdi_t {
421*ed775ee7SAntonio Huete Jimenez     nd_uint8_t  failure_type;
422*ed775ee7SAntonio Huete Jimenez     nd_byte     failure_location[16];
423*ed775ee7SAntonio Huete Jimenez     nd_byte     unused[28];
424ea7b4bf5SPeter Avalos };
425ea7b4bf5SPeter Avalos 
426411677aeSAaron LI void
oam_print(netdissect_options * ndo,const u_char * p,u_int length,u_int hec)427411677aeSAaron LI oam_print(netdissect_options *ndo,
428411677aeSAaron LI           const u_char *p, u_int length, u_int hec)
429411677aeSAaron LI {
430411677aeSAaron LI     uint32_t cell_header;
431411677aeSAaron LI     uint16_t vpi, vci, cksum, cksum_shouldbe, idx;
432411677aeSAaron LI     uint8_t  cell_type, func_type, payload, clp;
433*ed775ee7SAntonio Huete Jimenez     const struct tok *oam_functype_str;
434ea7b4bf5SPeter Avalos 
435ea7b4bf5SPeter Avalos     union {
436ea7b4bf5SPeter Avalos         const struct oam_fm_loopback_t *oam_fm_loopback;
437ea7b4bf5SPeter Avalos         const struct oam_fm_ais_rdi_t *oam_fm_ais_rdi;
438ea7b4bf5SPeter Avalos     } oam_ptr;
439ea7b4bf5SPeter Avalos 
440*ed775ee7SAntonio Huete Jimenez     ndo->ndo_protocol = "oam";
441*ed775ee7SAntonio Huete Jimenez     cell_header = GET_BE_U_4(p + hec);
442*ed775ee7SAntonio Huete Jimenez     cell_type = (GET_U_1((p + ATM_HDR_LEN_NOHEC + hec)) >> 4) & 0x0f;
443*ed775ee7SAntonio Huete Jimenez     func_type = GET_U_1((p + ATM_HDR_LEN_NOHEC + hec)) & 0x0f;
44441c99275SPeter Avalos 
44541c99275SPeter Avalos     vpi = (cell_header>>20)&0xff;
44641c99275SPeter Avalos     vci = (cell_header>>4)&0xffff;
44741c99275SPeter Avalos     payload = (cell_header>>1)&0x7;
44841c99275SPeter Avalos     clp = cell_header&0x1;
44941c99275SPeter Avalos 
450*ed775ee7SAntonio Huete Jimenez     ND_PRINT("%s, vpi %u, vci %u, payload [ %s ], clp %u, length %u",
45141c99275SPeter Avalos            tok2str(oam_f_values, "OAM F5", vci),
452ea7b4bf5SPeter Avalos            vpi, vci,
453ea7b4bf5SPeter Avalos            tok2str(atm_pty_values, "Unknown", payload),
454*ed775ee7SAntonio Huete Jimenez            clp, length);
45541c99275SPeter Avalos 
456411677aeSAaron LI     if (!ndo->ndo_vflag) {
457411677aeSAaron LI         return;
458ea7b4bf5SPeter Avalos     }
459ea7b4bf5SPeter Avalos 
460*ed775ee7SAntonio Huete Jimenez     ND_PRINT("\n\tcell-type %s (%u)",
46141c99275SPeter Avalos            tok2str(oam_celltype_values, "unknown", cell_type),
462*ed775ee7SAntonio Huete Jimenez            cell_type);
46341c99275SPeter Avalos 
464*ed775ee7SAntonio Huete Jimenez     oam_functype_str = uint2tokary(oam_celltype2tokary, cell_type);
465*ed775ee7SAntonio Huete Jimenez     if (oam_functype_str == NULL)
466*ed775ee7SAntonio Huete Jimenez         ND_PRINT(", func-type unknown (%u)", func_type);
46741c99275SPeter Avalos     else
468*ed775ee7SAntonio Huete Jimenez         ND_PRINT(", func-type %s (%u)",
469*ed775ee7SAntonio Huete Jimenez                tok2str(oam_functype_str, "none", func_type),
470*ed775ee7SAntonio Huete Jimenez                func_type);
47141c99275SPeter Avalos 
472ea7b4bf5SPeter Avalos     p += ATM_HDR_LEN_NOHEC + hec;
473ea7b4bf5SPeter Avalos 
474ea7b4bf5SPeter Avalos     switch (cell_type << 4 | func_type) {
475ea7b4bf5SPeter Avalos     case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_LOOPBACK):
476ea7b4bf5SPeter Avalos         oam_ptr.oam_fm_loopback = (const struct oam_fm_loopback_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN);
477*ed775ee7SAntonio Huete Jimenez         ND_TCHECK_SIZE(oam_ptr.oam_fm_loopback);
478*ed775ee7SAntonio Huete Jimenez         ND_PRINT("\n\tLoopback-Indicator %s, Correlation-Tag 0x%08x",
479ea7b4bf5SPeter Avalos                tok2str(oam_fm_loopback_indicator_values,
480ea7b4bf5SPeter Avalos                        "Unknown",
481*ed775ee7SAntonio Huete Jimenez                        GET_U_1(oam_ptr.oam_fm_loopback->loopback_indicator) & OAM_FM_LOOPBACK_INDICATOR_MASK),
482*ed775ee7SAntonio Huete Jimenez                GET_BE_U_4(oam_ptr.oam_fm_loopback->correlation_tag));
483*ed775ee7SAntonio Huete Jimenez         ND_PRINT("\n\tLocation-ID ");
484ea7b4bf5SPeter Avalos         for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) {
485ea7b4bf5SPeter Avalos             if (idx % 2) {
486*ed775ee7SAntonio Huete Jimenez                 ND_PRINT("%04x ",
487*ed775ee7SAntonio Huete Jimenez                          GET_BE_U_2(&oam_ptr.oam_fm_loopback->loopback_id[idx]));
488ea7b4bf5SPeter Avalos             }
489ea7b4bf5SPeter Avalos         }
490*ed775ee7SAntonio Huete Jimenez         ND_PRINT("\n\tSource-ID   ");
491ea7b4bf5SPeter Avalos         for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->source_id); idx++) {
492ea7b4bf5SPeter Avalos             if (idx % 2) {
493*ed775ee7SAntonio Huete Jimenez                 ND_PRINT("%04x ",
494*ed775ee7SAntonio Huete Jimenez                          GET_BE_U_2(&oam_ptr.oam_fm_loopback->source_id[idx]));
495ea7b4bf5SPeter Avalos             }
496ea7b4bf5SPeter Avalos         }
497ea7b4bf5SPeter Avalos         break;
498ea7b4bf5SPeter Avalos 
499ea7b4bf5SPeter Avalos     case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_AIS):
500ea7b4bf5SPeter Avalos     case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_RDI):
501ea7b4bf5SPeter Avalos         oam_ptr.oam_fm_ais_rdi = (const struct oam_fm_ais_rdi_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN);
502*ed775ee7SAntonio Huete Jimenez         ND_TCHECK_SIZE(oam_ptr.oam_fm_ais_rdi);
503*ed775ee7SAntonio Huete Jimenez         ND_PRINT("\n\tFailure-type 0x%02x",
504*ed775ee7SAntonio Huete Jimenez                  GET_U_1(oam_ptr.oam_fm_ais_rdi->failure_type));
505*ed775ee7SAntonio Huete Jimenez         ND_PRINT("\n\tLocation-ID ");
506ea7b4bf5SPeter Avalos         for (idx = 0; idx < sizeof(oam_ptr.oam_fm_ais_rdi->failure_location); idx++) {
507ea7b4bf5SPeter Avalos             if (idx % 2) {
508*ed775ee7SAntonio Huete Jimenez                 ND_PRINT("%04x ",
509*ed775ee7SAntonio Huete Jimenez                          GET_BE_U_2(&oam_ptr.oam_fm_ais_rdi->failure_location[idx]));
510ea7b4bf5SPeter Avalos             }
511ea7b4bf5SPeter Avalos         }
512ea7b4bf5SPeter Avalos         break;
513ea7b4bf5SPeter Avalos 
514ea7b4bf5SPeter Avalos     case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK):
515ea7b4bf5SPeter Avalos         /* FIXME */
516ea7b4bf5SPeter Avalos         break;
517ea7b4bf5SPeter Avalos 
518ea7b4bf5SPeter Avalos     default:
519ea7b4bf5SPeter Avalos         break;
520ea7b4bf5SPeter Avalos     }
521ea7b4bf5SPeter Avalos 
522ea7b4bf5SPeter Avalos     /* crc10 checksum verification */
523*ed775ee7SAntonio Huete Jimenez     cksum = GET_BE_U_2(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN)
524ea7b4bf5SPeter Avalos         & OAM_CRC10_MASK;
525ea7b4bf5SPeter Avalos     cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN);
526ea7b4bf5SPeter Avalos 
527*ed775ee7SAntonio Huete Jimenez     ND_PRINT("\n\tcksum 0x%03x (%scorrect)",
528ea7b4bf5SPeter Avalos            cksum,
529*ed775ee7SAntonio Huete Jimenez            cksum_shouldbe == 0 ? "" : "in");
53041c99275SPeter Avalos }
531