10f74e101Schristos /* 20f74e101Schristos * Copyright (c) 1994, 1995, 1996, 1997 30f74e101Schristos * The Regents of the University of California. All rights reserved. 40f74e101Schristos * 50f74e101Schristos * Redistribution and use in source and binary forms, with or without 60f74e101Schristos * modification, are permitted provided that: (1) source code distributions 70f74e101Schristos * retain the above copyright notice and this paragraph in its entirety, (2) 80f74e101Schristos * distributions including binary code include the above copyright notice and 90f74e101Schristos * this paragraph in its entirety in the documentation or other materials 100f74e101Schristos * provided with the distribution, and (3) all advertising materials mentioning 110f74e101Schristos * features or use of this software display the following acknowledgement: 120f74e101Schristos * ``This product includes software developed by the University of California, 130f74e101Schristos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 140f74e101Schristos * the University nor the names of its contributors may be used to endorse 150f74e101Schristos * or promote products derived from this software without specific prior 160f74e101Schristos * written permission. 170f74e101Schristos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 180f74e101Schristos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 190f74e101Schristos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 200f74e101Schristos */ 21b3a00663Schristos 2211b3aaa1Schristos #include <sys/cdefs.h> 230f74e101Schristos #ifndef lint 24*26ba0b50Schristos __RCSID("$NetBSD: print-atm.c,v 1.11 2024/09/02 16:15:30 christos Exp $"); 250f74e101Schristos #endif 260f74e101Schristos 27dc860a36Sspz /* \summary: Asynchronous Transfer Mode (ATM) printer */ 28dc860a36Sspz 29c74ad251Schristos #include <config.h> 300f74e101Schristos 31c74ad251Schristos #include "netdissect-stdinc.h" 320f74e101Schristos 33c74ad251Schristos #define ND_LONGJMP_FROM_TCHECK 34fdccd7e4Schristos #include "netdissect.h" 350f74e101Schristos #include "extract.h" 360f74e101Schristos #include "addrtoname.h" 370f74e101Schristos #include "atm.h" 380f74e101Schristos #include "llc.h" 390f74e101Schristos 40fdccd7e4Schristos /* start of the original atmuni31.h */ 41fdccd7e4Schristos 42fdccd7e4Schristos /* 43fdccd7e4Schristos * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 44fdccd7e4Schristos * All rights reserved. 45fdccd7e4Schristos * 46fdccd7e4Schristos * Redistribution and use in source and binary forms, with or without 47fdccd7e4Schristos * modification, are permitted provided that the following conditions 48fdccd7e4Schristos * are met: 49fdccd7e4Schristos * 1. Redistributions of source code must retain the above copyright 50fdccd7e4Schristos * notice, this list of conditions and the following disclaimer. 51fdccd7e4Schristos * 2. Redistributions in binary form must reproduce the above copyright 52fdccd7e4Schristos * notice, this list of conditions and the following disclaimer in the 53fdccd7e4Schristos * documentation and/or other materials provided with the distribution. 54fdccd7e4Schristos * 3. All advertising materials mentioning features or use of this software 55fdccd7e4Schristos * must display the following acknowledgement: 56fdccd7e4Schristos * This product includes software developed by Yen Yen Lim and 57fdccd7e4Schristos North Dakota State University 58fdccd7e4Schristos * 4. The name of the author may not be used to endorse or promote products 59fdccd7e4Schristos * derived from this software without specific prior written permission. 60fdccd7e4Schristos * 61fdccd7e4Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 62fdccd7e4Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 63fdccd7e4Schristos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 64fdccd7e4Schristos * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 65fdccd7e4Schristos * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 66fdccd7e4Schristos * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 67fdccd7e4Schristos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 68fdccd7e4Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 69fdccd7e4Schristos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 70fdccd7e4Schristos * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 71fdccd7e4Schristos * POSSIBILITY OF SUCH DAMAGE. 72fdccd7e4Schristos */ 73fdccd7e4Schristos 74fdccd7e4Schristos /* Based on UNI3.1 standard by ATM Forum */ 75fdccd7e4Schristos 76fdccd7e4Schristos /* ATM traffic types based on VPI=0 and (the following VCI */ 77fdccd7e4Schristos #define VCI_PPC 0x05 /* Point-to-point signal msg */ 78fdccd7e4Schristos #define VCI_BCC 0x02 /* Broadcast signal msg */ 79fdccd7e4Schristos #define VCI_OAMF4SC 0x03 /* Segment OAM F4 flow cell */ 80fdccd7e4Schristos #define VCI_OAMF4EC 0x04 /* End-to-end OAM F4 flow cell */ 81fdccd7e4Schristos #define VCI_METAC 0x01 /* Meta signal msg */ 82fdccd7e4Schristos #define VCI_ILMIC 0x10 /* ILMI msg */ 83fdccd7e4Schristos 84fdccd7e4Schristos /* Q.2931 signalling messages */ 85fdccd7e4Schristos #define CALL_PROCEED 0x02 /* call proceeding */ 86fdccd7e4Schristos #define CONNECT 0x07 /* connect */ 87fdccd7e4Schristos #define CONNECT_ACK 0x0f /* connect_ack */ 88fdccd7e4Schristos #define SETUP 0x05 /* setup */ 89fdccd7e4Schristos #define RELEASE 0x4d /* release */ 90fdccd7e4Schristos #define RELEASE_DONE 0x5a /* release_done */ 91fdccd7e4Schristos #define RESTART 0x46 /* restart */ 92fdccd7e4Schristos #define RESTART_ACK 0x4e /* restart ack */ 93fdccd7e4Schristos #define STATUS 0x7d /* status */ 94fdccd7e4Schristos #define STATUS_ENQ 0x75 /* status ack */ 95fdccd7e4Schristos #define ADD_PARTY 0x80 /* add party */ 96fdccd7e4Schristos #define ADD_PARTY_ACK 0x81 /* add party ack */ 97fdccd7e4Schristos #define ADD_PARTY_REJ 0x82 /* add party rej */ 98fdccd7e4Schristos #define DROP_PARTY 0x83 /* drop party */ 99fdccd7e4Schristos #define DROP_PARTY_ACK 0x84 /* drop party ack */ 100fdccd7e4Schristos 101fdccd7e4Schristos /* Information Element Parameters in the signalling messages */ 102fdccd7e4Schristos #define CAUSE 0x08 /* cause */ 103fdccd7e4Schristos #define ENDPT_REF 0x54 /* endpoint reference */ 104fdccd7e4Schristos #define AAL_PARA 0x58 /* ATM adaptation layer parameters */ 105fdccd7e4Schristos #define TRAFF_DESCRIP 0x59 /* atm traffic descriptors */ 106fdccd7e4Schristos #define CONNECT_ID 0x5a /* connection identifier */ 107fdccd7e4Schristos #define QOS_PARA 0x5c /* quality of service parameters */ 108fdccd7e4Schristos #define B_HIGHER 0x5d /* broadband higher layer information */ 109fdccd7e4Schristos #define B_BEARER 0x5e /* broadband bearer capability */ 110fdccd7e4Schristos #define B_LOWER 0x5f /* broadband lower information */ 111fdccd7e4Schristos #define CALLING_PARTY 0x6c /* calling party number */ 112*26ba0b50Schristos #define CALLED_PARTY 0x70 /* called party number */ 113fdccd7e4Schristos 114fdccd7e4Schristos #define Q2931 0x09 115fdccd7e4Schristos 116fdccd7e4Schristos /* Q.2931 signalling general messages format */ 117fdccd7e4Schristos #define PROTO_POS 0 /* offset of protocol discriminator */ 118fdccd7e4Schristos #define CALL_REF_POS 2 /* offset of call reference value */ 119fdccd7e4Schristos #define MSG_TYPE_POS 5 /* offset of message type */ 120c74ad251Schristos #if 0 121c74ad251Schristos #define MSG_LEN_POS 7 /* offset of message length */ 122fdccd7e4Schristos #define IE_BEGIN_POS 9 /* offset of first information element */ 123fdccd7e4Schristos 124fdccd7e4Schristos /* format of signalling messages */ 125fdccd7e4Schristos #define TYPE_POS 0 126fdccd7e4Schristos #define LEN_POS 2 127fdccd7e4Schristos #define FIELD_BEGIN_POS 4 128c74ad251Schristos #endif 129fdccd7e4Schristos 130fdccd7e4Schristos /* end of the original atmuni31.h */ 131fdccd7e4Schristos 1320f74e101Schristos 1330f74e101Schristos #define OAM_CRC10_MASK 0x3ff 1340f74e101Schristos #define OAM_PAYLOAD_LEN 48 1350f74e101Schristos #define OAM_FUNCTION_SPECIFIC_LEN 45 /* this excludes crc10 and cell-type/function-type */ 1360f74e101Schristos #define OAM_CELLTYPE_FUNCTYPE_LEN 1 1370f74e101Schristos 138870189d2Schristos static const struct tok oam_f_values[] = { 1390f74e101Schristos { VCI_OAMF4SC, "OAM F4 (segment)" }, 1400f74e101Schristos { VCI_OAMF4EC, "OAM F4 (end)" }, 1410f74e101Schristos { 0, NULL } 1420f74e101Schristos }; 1430f74e101Schristos 144870189d2Schristos static const struct tok atm_pty_values[] = { 1450f74e101Schristos { 0x0, "user data, uncongested, SDU 0" }, 1460f74e101Schristos { 0x1, "user data, uncongested, SDU 1" }, 1470f74e101Schristos { 0x2, "user data, congested, SDU 0" }, 1480f74e101Schristos { 0x3, "user data, congested, SDU 1" }, 1490f74e101Schristos { 0x4, "VCC OAM F5 flow segment" }, 1500f74e101Schristos { 0x5, "VCC OAM F5 flow end-to-end" }, 1510f74e101Schristos { 0x6, "Traffic Control and resource Mgmt" }, 1520f74e101Schristos { 0, NULL } 1530f74e101Schristos }; 1540f74e101Schristos 1550f74e101Schristos #define OAM_CELLTYPE_FM 0x1 1560f74e101Schristos #define OAM_CELLTYPE_PM 0x2 1570f74e101Schristos #define OAM_CELLTYPE_AD 0x8 1580f74e101Schristos #define OAM_CELLTYPE_SM 0xf 1590f74e101Schristos 160870189d2Schristos static const struct tok oam_celltype_values[] = { 1610f74e101Schristos { OAM_CELLTYPE_FM, "Fault Management" }, 1620f74e101Schristos { OAM_CELLTYPE_PM, "Performance Management" }, 1630f74e101Schristos { OAM_CELLTYPE_AD, "activate/deactivate" }, 1640f74e101Schristos { OAM_CELLTYPE_SM, "System Management" }, 1650f74e101Schristos { 0, NULL } 1660f74e101Schristos }; 1670f74e101Schristos 1680f74e101Schristos #define OAM_FM_FUNCTYPE_AIS 0x0 1690f74e101Schristos #define OAM_FM_FUNCTYPE_RDI 0x1 1700f74e101Schristos #define OAM_FM_FUNCTYPE_CONTCHECK 0x4 1710f74e101Schristos #define OAM_FM_FUNCTYPE_LOOPBACK 0x8 1720f74e101Schristos 173870189d2Schristos static const struct tok oam_fm_functype_values[] = { 1740f74e101Schristos { OAM_FM_FUNCTYPE_AIS, "AIS" }, 1750f74e101Schristos { OAM_FM_FUNCTYPE_RDI, "RDI" }, 1760f74e101Schristos { OAM_FM_FUNCTYPE_CONTCHECK, "Continuity Check" }, 1770f74e101Schristos { OAM_FM_FUNCTYPE_LOOPBACK, "Loopback" }, 1780f74e101Schristos { 0, NULL } 1790f74e101Schristos }; 1800f74e101Schristos 181870189d2Schristos static const struct tok oam_pm_functype_values[] = { 1820f74e101Schristos { 0x0, "Forward Monitoring" }, 1830f74e101Schristos { 0x1, "Backward Reporting" }, 1840f74e101Schristos { 0x2, "Monitoring and Reporting" }, 1850f74e101Schristos { 0, NULL } 1860f74e101Schristos }; 1870f74e101Schristos 188870189d2Schristos static const struct tok oam_ad_functype_values[] = { 1890f74e101Schristos { 0x0, "Performance Monitoring" }, 1900f74e101Schristos { 0x1, "Continuity Check" }, 1910f74e101Schristos { 0, NULL } 1920f74e101Schristos }; 1930f74e101Schristos 1940f74e101Schristos #define OAM_FM_LOOPBACK_INDICATOR_MASK 0x1 1950f74e101Schristos 196870189d2Schristos static const struct tok oam_fm_loopback_indicator_values[] = { 1970f74e101Schristos { 0x0, "Reply" }, 1980f74e101Schristos { 0x1, "Request" }, 1990f74e101Schristos { 0, NULL } 2000f74e101Schristos }; 2010f74e101Schristos 202c74ad251Schristos static const struct uint_tokary oam_celltype2tokary[] = { 203c74ad251Schristos { OAM_CELLTYPE_FM, oam_fm_functype_values }, 204c74ad251Schristos { OAM_CELLTYPE_PM, oam_pm_functype_values }, 205c74ad251Schristos { OAM_CELLTYPE_AD, oam_ad_functype_values }, 206c74ad251Schristos /* uint2tokary() does not use array termination. */ 2070f74e101Schristos }; 2080f74e101Schristos 2090f74e101Schristos /* 2100f74e101Schristos * Print an RFC 1483 LLC-encapsulated ATM frame. 2110f74e101Schristos */ 212fdccd7e4Schristos static u_int 213b3a00663Schristos atm_llc_print(netdissect_options *ndo, 214b3a00663Schristos const u_char *p, int length, int caplen) 2150f74e101Schristos { 216fdccd7e4Schristos int llc_hdrlen; 2170f74e101Schristos 218fdccd7e4Schristos llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL); 219fdccd7e4Schristos if (llc_hdrlen < 0) { 220fdccd7e4Schristos /* packet not known, print raw packet */ 221b3a00663Schristos if (!ndo->ndo_suppress_default_print) 222b3a00663Schristos ND_DEFAULTPRINT(p, caplen); 223fdccd7e4Schristos llc_hdrlen = -llc_hdrlen; 2240f74e101Schristos } 225fdccd7e4Schristos return (llc_hdrlen); 2260f74e101Schristos } 2270f74e101Schristos 2280f74e101Schristos /* 2290f74e101Schristos * Given a SAP value, generate the LLC header value for a UI packet 2300f74e101Schristos * with that SAP as the source and destination SAP. 2310f74e101Schristos */ 2320f74e101Schristos #define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03) 2330f74e101Schristos 2340f74e101Schristos /* 2350f74e101Schristos * This is the top level routine of the printer. 'p' points 2360f74e101Schristos * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp, 2370f74e101Schristos * 'h->len' is the length of the packet off the wire, and 'h->caplen' 2380f74e101Schristos * is the number of bytes actually captured. 2390f74e101Schristos */ 240c74ad251Schristos void 241b3a00663Schristos atm_if_print(netdissect_options *ndo, 242b3a00663Schristos const struct pcap_pkthdr *h, const u_char *p) 2430f74e101Schristos { 2440f74e101Schristos u_int caplen = h->caplen; 2450f74e101Schristos u_int length = h->len; 246b3a00663Schristos uint32_t llchdr; 2470f74e101Schristos u_int hdrlen = 0; 2480f74e101Schristos 249c74ad251Schristos ndo->ndo_protocol = "atm"; 2500f74e101Schristos 2510f74e101Schristos /* Cisco Style NLPID ? */ 252c74ad251Schristos if (GET_U_1(p) == LLC_UI) { 253b3a00663Schristos if (ndo->ndo_eflag) 254c74ad251Schristos ND_PRINT("CNLPID "); 255c74ad251Schristos ndo->ndo_ll_hdr_len += 1; 25672c96ff3Schristos isoclns_print(ndo, p + 1, length - 1); 257c74ad251Schristos return; 2580f74e101Schristos } 2590f74e101Schristos 2600f74e101Schristos /* 261ba2ff121Schristos * Must have at least a DSAP, an SSAP, and the first byte of the 262ba2ff121Schristos * control field. 263ba2ff121Schristos */ 264ba2ff121Schristos 265ba2ff121Schristos /* 2660f74e101Schristos * Extract the presumed LLC header into a variable, for quick 2670f74e101Schristos * testing. 2680f74e101Schristos * Then check for a header that's neither a header for a SNAP 2690f74e101Schristos * packet nor an RFC 2684 routed NLPID-formatted PDU nor 2700f74e101Schristos * an 802.2-but-no-SNAP IP packet. 2710f74e101Schristos */ 272c74ad251Schristos llchdr = GET_BE_U_3(p); 2730f74e101Schristos if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) && 2740f74e101Schristos llchdr != LLC_UI_HDR(LLCSAP_ISONS) && 2750f74e101Schristos llchdr != LLC_UI_HDR(LLCSAP_IP)) { 2760f74e101Schristos /* 2770f74e101Schristos * XXX - assume 802.6 MAC header from Fore driver. 2780f74e101Schristos * 2790f74e101Schristos * Unfortunately, the above list doesn't check for 2800f74e101Schristos * all known SAPs, doesn't check for headers where 2810f74e101Schristos * the source and destination SAP aren't the same, 2820f74e101Schristos * and doesn't check for non-UI frames. It also 2830f74e101Schristos * runs the risk of an 802.6 MAC header that happens 2840f74e101Schristos * to begin with one of those values being 2850f74e101Schristos * incorrectly treated as an 802.2 header. 2860f74e101Schristos * 2870f74e101Schristos * So is that Fore driver still around? And, if so, 2880f74e101Schristos * is it still putting 802.6 MAC headers on ATM 2890f74e101Schristos * packets? If so, could it be changed to use a 2900f74e101Schristos * new DLT_IEEE802_6 value if we added it? 2910f74e101Schristos */ 292b3a00663Schristos if (ndo->ndo_eflag) 293c74ad251Schristos ND_PRINT("%08x%08x %08x%08x ", 294c74ad251Schristos GET_BE_U_4(p), 295c74ad251Schristos GET_BE_U_4(p + 4), 296c74ad251Schristos GET_BE_U_4(p + 8), 297c74ad251Schristos GET_BE_U_4(p + 12)); 298c74ad251Schristos /* Always cover the full header. */ 299c74ad251Schristos ND_TCHECK_LEN(p, 20); 3000f74e101Schristos p += 20; 3010f74e101Schristos length -= 20; 3020f74e101Schristos caplen -= 20; 3030f74e101Schristos hdrlen += 20; 3040f74e101Schristos } 305c74ad251Schristos ndo->ndo_ll_hdr_len += hdrlen; 306c74ad251Schristos ndo->ndo_ll_hdr_len += atm_llc_print(ndo, p, length, caplen); 3070f74e101Schristos } 3080f74e101Schristos 3090f74e101Schristos /* 3100f74e101Schristos * ATM signalling. 3110f74e101Schristos */ 312870189d2Schristos static const struct tok msgtype2str[] = { 3130f74e101Schristos { CALL_PROCEED, "Call_proceeding" }, 3140f74e101Schristos { CONNECT, "Connect" }, 3150f74e101Schristos { CONNECT_ACK, "Connect_ack" }, 3160f74e101Schristos { SETUP, "Setup" }, 3170f74e101Schristos { RELEASE, "Release" }, 3180f74e101Schristos { RELEASE_DONE, "Release_complete" }, 3190f74e101Schristos { RESTART, "Restart" }, 3200f74e101Schristos { RESTART_ACK, "Restart_ack" }, 3210f74e101Schristos { STATUS, "Status" }, 3220f74e101Schristos { STATUS_ENQ, "Status_enquiry" }, 3230f74e101Schristos { ADD_PARTY, "Add_party" }, 3240f74e101Schristos { ADD_PARTY_ACK, "Add_party_ack" }, 3250f74e101Schristos { ADD_PARTY_REJ, "Add_party_reject" }, 3260f74e101Schristos { DROP_PARTY, "Drop_party" }, 3270f74e101Schristos { DROP_PARTY_ACK, "Drop_party_ack" }, 3280f74e101Schristos { 0, NULL } 3290f74e101Schristos }; 3300f74e101Schristos 3310f74e101Schristos static void 332b3a00663Schristos sig_print(netdissect_options *ndo, 333dc860a36Sspz const u_char *p) 3340f74e101Schristos { 335b3a00663Schristos uint32_t call_ref; 3360f74e101Schristos 337c74ad251Schristos if (GET_U_1(p + PROTO_POS) == Q2931) { 3380f74e101Schristos /* 3390f74e101Schristos * protocol:Q.2931 for User to Network Interface 3400f74e101Schristos * (UNI 3.1) signalling 3410f74e101Schristos */ 342c74ad251Schristos ND_PRINT("Q.2931"); 343c74ad251Schristos ND_PRINT(":%s ", 344c74ad251Schristos tok2str(msgtype2str, "msgtype#%u", GET_U_1(p + MSG_TYPE_POS))); 3450f74e101Schristos 3460e9868baSchristos /* 3470e9868baSchristos * The call reference comes before the message type, 3480e9868baSchristos * so if we know we have the message type, which we 3490e9868baSchristos * do from the caplen test above, we also know we have 3500e9868baSchristos * the call reference. 3510e9868baSchristos */ 352c74ad251Schristos call_ref = GET_BE_U_3(p + CALL_REF_POS); 353c74ad251Schristos ND_PRINT("CALL_REF:0x%06x", call_ref); 3540f74e101Schristos } else { 355c74ad251Schristos /* SSCOP with some unknown protocol atop it */ 356c74ad251Schristos ND_PRINT("SSCOP, proto %u ", GET_U_1(p + PROTO_POS)); 3570f74e101Schristos } 3580f74e101Schristos } 3590f74e101Schristos 3600f74e101Schristos /* 3610f74e101Schristos * Print an ATM PDU (such as an AAL5 PDU). 3620f74e101Schristos */ 3630f74e101Schristos void 364b3a00663Schristos atm_print(netdissect_options *ndo, 365b3a00663Schristos u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length, 3660f74e101Schristos u_int caplen) 3670f74e101Schristos { 368c74ad251Schristos ndo->ndo_protocol = "atm"; 369b3a00663Schristos if (ndo->ndo_eflag) 370c74ad251Schristos ND_PRINT("VPI:%u VCI:%u ", vpi, vci); 3710f74e101Schristos 3720f74e101Schristos if (vpi == 0) { 3730f74e101Schristos switch (vci) { 3740f74e101Schristos 3750f74e101Schristos case VCI_PPC: 376dc860a36Sspz sig_print(ndo, p); 3770f74e101Schristos return; 3780f74e101Schristos 3790f74e101Schristos case VCI_BCC: 380c74ad251Schristos ND_PRINT("broadcast sig: "); 3810f74e101Schristos return; 3820f74e101Schristos 3830f74e101Schristos case VCI_OAMF4SC: /* fall through */ 3840f74e101Schristos case VCI_OAMF4EC: 385b3a00663Schristos oam_print(ndo, p, length, ATM_OAM_HEC); 3860f74e101Schristos return; 3870f74e101Schristos 3880f74e101Schristos case VCI_METAC: 389c74ad251Schristos ND_PRINT("meta: "); 3900f74e101Schristos return; 3910f74e101Schristos 3920f74e101Schristos case VCI_ILMIC: 393c74ad251Schristos ND_PRINT("ilmi: "); 394b3a00663Schristos snmp_print(ndo, p, length); 3950f74e101Schristos return; 3960f74e101Schristos } 3970f74e101Schristos } 3980f74e101Schristos 3990f74e101Schristos switch (traftype) { 4000f74e101Schristos 4010f74e101Schristos case ATM_LLC: 4020f74e101Schristos default: 4030f74e101Schristos /* 4040f74e101Schristos * Assumes traffic is LLC if unknown. 4050f74e101Schristos */ 406b3a00663Schristos atm_llc_print(ndo, p, length, caplen); 4070f74e101Schristos break; 4080f74e101Schristos 4090f74e101Schristos case ATM_LANE: 410b3a00663Schristos lane_print(ndo, p, length, caplen); 4110f74e101Schristos break; 4120f74e101Schristos } 4130f74e101Schristos } 4140f74e101Schristos 4150f74e101Schristos struct oam_fm_loopback_t { 416c74ad251Schristos nd_uint8_t loopback_indicator; 417c74ad251Schristos nd_uint32_t correlation_tag; 418c74ad251Schristos nd_byte loopback_id[12]; 419c74ad251Schristos nd_byte source_id[12]; 420c74ad251Schristos nd_byte unused[16]; 4210f74e101Schristos }; 4220f74e101Schristos 4230f74e101Schristos struct oam_fm_ais_rdi_t { 424c74ad251Schristos nd_uint8_t failure_type; 425c74ad251Schristos nd_byte failure_location[16]; 426c74ad251Schristos nd_byte unused[28]; 4270f74e101Schristos }; 4280f74e101Schristos 429dc860a36Sspz void 430b3a00663Schristos oam_print(netdissect_options *ndo, 431ba2ff121Schristos const u_char *p, u_int length, u_int hec) 432ba2ff121Schristos { 433b3a00663Schristos uint32_t cell_header; 434b3a00663Schristos uint16_t vpi, vci, cksum, cksum_shouldbe, idx; 435b3a00663Schristos uint8_t cell_type, func_type, payload, clp; 436c74ad251Schristos const struct tok *oam_functype_str; 4370f74e101Schristos 4380f74e101Schristos union { 4390f74e101Schristos const struct oam_fm_loopback_t *oam_fm_loopback; 4400f74e101Schristos const struct oam_fm_ais_rdi_t *oam_fm_ais_rdi; 4410f74e101Schristos } oam_ptr; 4420f74e101Schristos 443c74ad251Schristos ndo->ndo_protocol = "oam"; 444c74ad251Schristos cell_header = GET_BE_U_4(p + hec); 445c74ad251Schristos cell_type = (GET_U_1((p + ATM_HDR_LEN_NOHEC + hec)) >> 4) & 0x0f; 446c74ad251Schristos func_type = GET_U_1((p + ATM_HDR_LEN_NOHEC + hec)) & 0x0f; 4470f74e101Schristos 4480f74e101Schristos vpi = (cell_header>>20)&0xff; 4490f74e101Schristos vci = (cell_header>>4)&0xffff; 4500f74e101Schristos payload = (cell_header>>1)&0x7; 4510f74e101Schristos clp = cell_header&0x1; 4520f74e101Schristos 453c74ad251Schristos ND_PRINT("%s, vpi %u, vci %u, payload [ %s ], clp %u, length %u", 4540f74e101Schristos tok2str(oam_f_values, "OAM F5", vci), 4550f74e101Schristos vpi, vci, 4560f74e101Schristos tok2str(atm_pty_values, "Unknown", payload), 457c74ad251Schristos clp, length); 4580f74e101Schristos 459b3a00663Schristos if (!ndo->ndo_vflag) { 460dc860a36Sspz return; 4610f74e101Schristos } 4620f74e101Schristos 463c74ad251Schristos ND_PRINT("\n\tcell-type %s (%u)", 4640f74e101Schristos tok2str(oam_celltype_values, "unknown", cell_type), 465c74ad251Schristos cell_type); 4660f74e101Schristos 467c74ad251Schristos oam_functype_str = uint2tokary(oam_celltype2tokary, cell_type); 468c74ad251Schristos if (oam_functype_str == NULL) 469c74ad251Schristos ND_PRINT(", func-type unknown (%u)", func_type); 4700f74e101Schristos else 471c74ad251Schristos ND_PRINT(", func-type %s (%u)", 472c74ad251Schristos tok2str(oam_functype_str, "none", func_type), 473c74ad251Schristos func_type); 4740f74e101Schristos 4750f74e101Schristos p += ATM_HDR_LEN_NOHEC + hec; 4760f74e101Schristos 4770f74e101Schristos switch (cell_type << 4 | func_type) { 4780f74e101Schristos case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_LOOPBACK): 4790f74e101Schristos oam_ptr.oam_fm_loopback = (const struct oam_fm_loopback_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN); 480c74ad251Schristos ND_TCHECK_SIZE(oam_ptr.oam_fm_loopback); 481c74ad251Schristos ND_PRINT("\n\tLoopback-Indicator %s, Correlation-Tag 0x%08x", 4820f74e101Schristos tok2str(oam_fm_loopback_indicator_values, 4830f74e101Schristos "Unknown", 484c74ad251Schristos GET_U_1(oam_ptr.oam_fm_loopback->loopback_indicator) & OAM_FM_LOOPBACK_INDICATOR_MASK), 485c74ad251Schristos GET_BE_U_4(oam_ptr.oam_fm_loopback->correlation_tag)); 486c74ad251Schristos ND_PRINT("\n\tLocation-ID "); 4870f74e101Schristos for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) { 4880f74e101Schristos if (idx % 2) { 489c74ad251Schristos ND_PRINT("%04x ", 490c74ad251Schristos GET_BE_U_2(&oam_ptr.oam_fm_loopback->loopback_id[idx])); 4910f74e101Schristos } 4920f74e101Schristos } 493c74ad251Schristos ND_PRINT("\n\tSource-ID "); 4940f74e101Schristos for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->source_id); idx++) { 4950f74e101Schristos if (idx % 2) { 496c74ad251Schristos ND_PRINT("%04x ", 497c74ad251Schristos GET_BE_U_2(&oam_ptr.oam_fm_loopback->source_id[idx])); 4980f74e101Schristos } 4990f74e101Schristos } 5000f74e101Schristos break; 5010f74e101Schristos 5020f74e101Schristos case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_AIS): 5030f74e101Schristos case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_RDI): 5040f74e101Schristos oam_ptr.oam_fm_ais_rdi = (const struct oam_fm_ais_rdi_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN); 505c74ad251Schristos ND_TCHECK_SIZE(oam_ptr.oam_fm_ais_rdi); 506c74ad251Schristos ND_PRINT("\n\tFailure-type 0x%02x", 507c74ad251Schristos GET_U_1(oam_ptr.oam_fm_ais_rdi->failure_type)); 508c74ad251Schristos ND_PRINT("\n\tLocation-ID "); 5090f74e101Schristos for (idx = 0; idx < sizeof(oam_ptr.oam_fm_ais_rdi->failure_location); idx++) { 5100f74e101Schristos if (idx % 2) { 511c74ad251Schristos ND_PRINT("%04x ", 512c74ad251Schristos GET_BE_U_2(&oam_ptr.oam_fm_ais_rdi->failure_location[idx])); 5130f74e101Schristos } 5140f74e101Schristos } 5150f74e101Schristos break; 5160f74e101Schristos 5170f74e101Schristos case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK): 5180f74e101Schristos /* FIXME */ 5190f74e101Schristos break; 5200f74e101Schristos 5210f74e101Schristos default: 5220f74e101Schristos break; 5230f74e101Schristos } 5240f74e101Schristos 5250f74e101Schristos /* crc10 checksum verification */ 526c74ad251Schristos cksum = GET_BE_U_2(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN) 5270f74e101Schristos & OAM_CRC10_MASK; 5280f74e101Schristos cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN); 5290f74e101Schristos 530c74ad251Schristos ND_PRINT("\n\tcksum 0x%03x (%scorrect)", 5310f74e101Schristos cksum, 532c74ad251Schristos cksum_shouldbe == 0 ? "" : "in"); 5330f74e101Schristos } 534