117680Spst/* 239300Sfenner * Copyright (c) 1994, 1995, 1996, 1997 317680Spst * The Regents of the University of California. All rights reserved. 417680Spst * 517680Spst * Redistribution and use in source and binary forms, with or without 617680Spst * modification, are permitted provided that: (1) source code distributions 717680Spst * retain the above copyright notice and this paragraph in its entirety, (2) 817680Spst * distributions including binary code include the above copyright notice and 917680Spst * this paragraph in its entirety in the documentation or other materials 1017680Spst * provided with the distribution, and (3) all advertising materials mentioning 1117680Spst * features or use of this software display the following acknowledgement: 1217680Spst * ``This product includes software developed by the University of California, 1317680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 1417680Spst * the University nor the names of its contributors may be used to endorse 1517680Spst * or promote products derived from this software without specific prior 1617680Spst * written permission. 1717680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 1817680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 1917680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2056896Sfenner * 2156896Sfenner * $FreeBSD$ 2217680Spst */ 2317680Spst#ifndef lint 24127675Sbmsstatic const char rcsid[] _U_ = 25214478Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.49 2007-10-22 19:37:51 guy Exp $ (LBL)"; 2617680Spst#endif 2717680Spst 2856896Sfenner#ifdef HAVE_CONFIG_H 2956896Sfenner#include "config.h" 3056896Sfenner#endif 3156896Sfenner 32127675Sbms#include <tcpdump-stdinc.h> 3317680Spst 3417680Spst#include <stdio.h> 3517680Spst#include <pcap.h> 36127675Sbms#include <string.h> 3717680Spst 3839300Sfenner#include "interface.h" 39127675Sbms#include "extract.h" 4017680Spst#include "addrtoname.h" 4117680Spst#include "ethertype.h" 42127675Sbms#include "atm.h" 43127675Sbms#include "atmuni31.h" 44127675Sbms#include "llc.h" 4517680Spst 46127675Sbms#include "ether.h" 47127675Sbms 48190207Srpaulo#define OAM_CRC10_MASK 0x3ff 49190207Srpaulo#define OAM_PAYLOAD_LEN 48 50190207Srpaulo#define OAM_FUNCTION_SPECIFIC_LEN 45 /* this excludes crc10 and cell-type/function-type */ 51190207Srpaulo#define OAM_CELLTYPE_FUNCTYPE_LEN 1 52190207Srpaulo 53172686Smlaierstruct tok oam_f_values[] = { 54190207Srpaulo { VCI_OAMF4SC, "OAM F4 (segment)" }, 55190207Srpaulo { VCI_OAMF4EC, "OAM F4 (end)" }, 56172686Smlaier { 0, NULL } 57172686Smlaier}; 58172686Smlaier 59190207Srpaulostruct tok atm_pty_values[] = { 60190207Srpaulo { 0x0, "user data, uncongested, SDU 0" }, 61190207Srpaulo { 0x1, "user data, uncongested, SDU 1" }, 62190207Srpaulo { 0x2, "user data, congested, SDU 0" }, 63190207Srpaulo { 0x3, "user data, congested, SDU 1" }, 64190207Srpaulo { 0x4, "VCC OAM F5 flow segment" }, 65190207Srpaulo { 0x5, "VCC OAM F5 flow end-to-end" }, 66190207Srpaulo { 0x6, "Traffic Control and resource Mgmt" }, 67190207Srpaulo { 0, NULL } 68190207Srpaulo}; 69190207Srpaulo 70190207Srpaulo#define OAM_CELLTYPE_FM 0x1 71190207Srpaulo#define OAM_CELLTYPE_PM 0x2 72190207Srpaulo#define OAM_CELLTYPE_AD 0x8 73190207Srpaulo#define OAM_CELLTYPE_SM 0xf 74190207Srpaulo 75146778Ssamstruct tok oam_celltype_values[] = { 76190207Srpaulo { OAM_CELLTYPE_FM, "Fault Management" }, 77190207Srpaulo { OAM_CELLTYPE_PM, "Performance Management" }, 78190207Srpaulo { OAM_CELLTYPE_AD, "activate/deactivate" }, 79190207Srpaulo { OAM_CELLTYPE_SM, "System Management" }, 80146778Ssam { 0, NULL } 81146778Ssam}; 82146778Ssam 83190207Srpaulo#define OAM_FM_FUNCTYPE_AIS 0x0 84190207Srpaulo#define OAM_FM_FUNCTYPE_RDI 0x1 85190207Srpaulo#define OAM_FM_FUNCTYPE_CONTCHECK 0x4 86190207Srpaulo#define OAM_FM_FUNCTYPE_LOOPBACK 0x8 87190207Srpaulo 88146778Ssamstruct tok oam_fm_functype_values[] = { 89190207Srpaulo { OAM_FM_FUNCTYPE_AIS, "AIS" }, 90190207Srpaulo { OAM_FM_FUNCTYPE_RDI, "RDI" }, 91190207Srpaulo { OAM_FM_FUNCTYPE_CONTCHECK, "Continuity Check" }, 92190207Srpaulo { OAM_FM_FUNCTYPE_LOOPBACK, "Loopback" }, 93146778Ssam { 0, NULL } 94146778Ssam}; 95146778Ssam 96146778Ssamstruct tok oam_pm_functype_values[] = { 97146778Ssam { 0x0, "Forward Monitoring" }, 98146778Ssam { 0x1, "Backward Reporting" }, 99146778Ssam { 0x2, "Monitoring and Reporting" }, 100146778Ssam { 0, NULL } 101146778Ssam}; 102146778Ssam 103146778Ssamstruct tok oam_ad_functype_values[] = { 104146778Ssam { 0x0, "Performance Monitoring" }, 105146778Ssam { 0x1, "Continuity Check" }, 106146778Ssam { 0, NULL } 107146778Ssam}; 108146778Ssam 109190207Srpaulo#define OAM_FM_LOOPBACK_INDICATOR_MASK 0x1 110190207Srpaulo 111190207Srpaulostruct tok oam_fm_loopback_indicator_values[] = { 112190207Srpaulo { 0x0, "Reply" }, 113190207Srpaulo { 0x1, "Request" }, 114190207Srpaulo { 0, NULL } 115190207Srpaulo}; 116190207Srpaulo 117146778Ssamstatic const struct tok *oam_functype_values[16] = { 118146778Ssam NULL, 119146778Ssam oam_fm_functype_values, /* 1 */ 120146778Ssam oam_pm_functype_values, /* 2 */ 121146778Ssam NULL, 122146778Ssam NULL, 123146778Ssam NULL, 124146778Ssam NULL, 125146778Ssam NULL, 126146778Ssam oam_ad_functype_values, /* 8 */ 127146778Ssam NULL, 128146778Ssam NULL, 129146778Ssam NULL, 130146778Ssam NULL, 131146778Ssam NULL, 132146778Ssam NULL, 133146778Ssam NULL 134146778Ssam}; 135146778Ssam 13617680Spst/* 137127675Sbms * Print an RFC 1483 LLC-encapsulated ATM frame. 138127675Sbms */ 139127675Sbmsstatic void 140127675Sbmsatm_llc_print(const u_char *p, int length, int caplen) 141127675Sbms{ 142127675Sbms u_short extracted_ethertype; 143127675Sbms 144127675Sbms if (!llc_print(p, length, caplen, NULL, NULL, 145127675Sbms &extracted_ethertype)) { 146127675Sbms /* ether_type not known, print raw packet */ 147127675Sbms if (extracted_ethertype) { 148127675Sbms printf("(LLC %s) ", 149127675Sbms etherproto_string(htons(extracted_ethertype))); 150127675Sbms } 151162021Ssam if (!suppress_default_print) 152127675Sbms default_print(p, caplen); 153127675Sbms } 154127675Sbms} 155127675Sbms 156127675Sbms/* 157127675Sbms * Given a SAP value, generate the LLC header value for a UI packet 158127675Sbms * with that SAP as the source and destination SAP. 159127675Sbms */ 160127675Sbms#define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03) 161127675Sbms 162127675Sbms/* 163127675Sbms * This is the top level routine of the printer. 'p' points 164127675Sbms * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp, 165146778Ssam * 'h->len' is the length of the packet off the wire, and 'h->caplen' 16617680Spst * is the number of bytes actually captured. 16717680Spst */ 168127675Sbmsu_int 169127675Sbmsatm_if_print(const struct pcap_pkthdr *h, const u_char *p) 17017680Spst{ 17117680Spst u_int caplen = h->caplen; 17217680Spst u_int length = h->len; 173127675Sbms u_int32_t llchdr; 174127675Sbms u_int hdrlen = 0; 17517680Spst 17617680Spst if (caplen < 8) { 17717680Spst printf("[|atm]"); 178127675Sbms return (caplen); 17917680Spst } 180172686Smlaier 181172686Smlaier /* Cisco Style NLPID ? */ 182172686Smlaier if (*p == LLC_UI) { 183172686Smlaier if (eflag) 184172686Smlaier printf("CNLPID "); 185172686Smlaier isoclns_print(p+1, length-1, caplen-1); 186172686Smlaier return hdrlen; 187172686Smlaier } 188172686Smlaier 189127675Sbms /* 190127675Sbms * Extract the presumed LLC header into a variable, for quick 191127675Sbms * testing. 192127675Sbms * Then check for a header that's neither a header for a SNAP 193127675Sbms * packet nor an RFC 2684 routed NLPID-formatted PDU nor 194127675Sbms * an 802.2-but-no-SNAP IP packet. 195127675Sbms */ 196127675Sbms llchdr = EXTRACT_24BITS(p); 197127675Sbms if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) && 198127675Sbms llchdr != LLC_UI_HDR(LLCSAP_ISONS) && 199127675Sbms llchdr != LLC_UI_HDR(LLCSAP_IP)) { 200127675Sbms /* 201127675Sbms * XXX - assume 802.6 MAC header from Fore driver. 202127675Sbms * 203127675Sbms * Unfortunately, the above list doesn't check for 204127675Sbms * all known SAPs, doesn't check for headers where 205127675Sbms * the source and destination SAP aren't the same, 206127675Sbms * and doesn't check for non-UI frames. It also 207127675Sbms * runs the risk of an 802.6 MAC header that happens 208127675Sbms * to begin with one of those values being 209127675Sbms * incorrectly treated as an 802.2 header. 210127675Sbms * 211127675Sbms * So is that Fore driver still around? And, if so, 212127675Sbms * is it still putting 802.6 MAC headers on ATM 213127675Sbms * packets? If so, could it be changed to use a 214127675Sbms * new DLT_IEEE802_6 value if we added it? 215127675Sbms */ 21617680Spst if (eflag) 217127675Sbms printf("%08x%08x %08x%08x ", 218127675Sbms EXTRACT_32BITS(p), 219127675Sbms EXTRACT_32BITS(p+4), 220127675Sbms EXTRACT_32BITS(p+8), 221127675Sbms EXTRACT_32BITS(p+12)); 22217680Spst p += 20; 22317680Spst length -= 20; 22417680Spst caplen -= 20; 225127675Sbms hdrlen += 20; 22617680Spst } 227127675Sbms atm_llc_print(p, length, caplen); 228127675Sbms return (hdrlen); 229127675Sbms} 230127675Sbms 231127675Sbms/* 232127675Sbms * ATM signalling. 233127675Sbms */ 234127675Sbmsstatic struct tok msgtype2str[] = { 235127675Sbms { CALL_PROCEED, "Call_proceeding" }, 236127675Sbms { CONNECT, "Connect" }, 237127675Sbms { CONNECT_ACK, "Connect_ack" }, 238127675Sbms { SETUP, "Setup" }, 239127675Sbms { RELEASE, "Release" }, 240127675Sbms { RELEASE_DONE, "Release_complete" }, 241127675Sbms { RESTART, "Restart" }, 242127675Sbms { RESTART_ACK, "Restart_ack" }, 243127675Sbms { STATUS, "Status" }, 244127675Sbms { STATUS_ENQ, "Status_enquiry" }, 245127675Sbms { ADD_PARTY, "Add_party" }, 246127675Sbms { ADD_PARTY_ACK, "Add_party_ack" }, 247127675Sbms { ADD_PARTY_REJ, "Add_party_reject" }, 248127675Sbms { DROP_PARTY, "Drop_party" }, 249127675Sbms { DROP_PARTY_ACK, "Drop_party_ack" }, 250127675Sbms { 0, NULL } 251127675Sbms}; 252127675Sbms 253127675Sbmsstatic void 254127675Sbmssig_print(const u_char *p, int caplen) 255127675Sbms{ 256127675Sbms bpf_u_int32 call_ref; 257127675Sbms 258127675Sbms if (caplen < PROTO_POS) { 259127675Sbms printf("[|atm]"); 260127675Sbms return; 261127675Sbms } 262127675Sbms if (p[PROTO_POS] == Q2931) { 263127675Sbms /* 264127675Sbms * protocol:Q.2931 for User to Network Interface 265127675Sbms * (UNI 3.1) signalling 266127675Sbms */ 267127675Sbms printf("Q.2931"); 268127675Sbms if (caplen < MSG_TYPE_POS) { 269127675Sbms printf(" [|atm]"); 270127675Sbms return; 271127675Sbms } 272127675Sbms printf(":%s ", 273127675Sbms tok2str(msgtype2str, "msgtype#%d", p[MSG_TYPE_POS])); 274127675Sbms 275235530Sdelphij /* 276235530Sdelphij * The call reference comes before the message type, 277235530Sdelphij * so if we know we have the message type, which we 278235530Sdelphij * do from the caplen test above, we also know we have 279235530Sdelphij * the call reference. 280235530Sdelphij */ 281127675Sbms call_ref = EXTRACT_24BITS(&p[CALL_REF_POS]); 282127675Sbms printf("CALL_REF:0x%06x", call_ref); 283127675Sbms } else { 284127675Sbms /* SCCOP with some unknown protocol atop it */ 285127675Sbms printf("SSCOP, proto %d ", p[PROTO_POS]); 286127675Sbms } 287127675Sbms} 288127675Sbms 289127675Sbms/* 290127675Sbms * Print an ATM PDU (such as an AAL5 PDU). 291127675Sbms */ 292127675Sbmsvoid 293127675Sbmsatm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length, 294127675Sbms u_int caplen) 295127675Sbms{ 29617680Spst if (eflag) 297127675Sbms printf("VPI:%u VCI:%u ", vpi, vci); 29817680Spst 299127675Sbms if (vpi == 0) { 300127675Sbms switch (vci) { 30117680Spst 302190207Srpaulo case VCI_PPC: 303127675Sbms sig_print(p, caplen); 304127675Sbms return; 30517680Spst 306190207Srpaulo case VCI_BCC: 307127675Sbms printf("broadcast sig: "); 308127675Sbms return; 30917680Spst 310190207Srpaulo case VCI_OAMF4SC: /* fall through */ 311190207Srpaulo case VCI_OAMF4EC: 312147904Ssam oam_print(p, length, ATM_OAM_HEC); 313127675Sbms return; 31456896Sfenner 315190207Srpaulo case VCI_METAC: 316127675Sbms printf("meta: "); 317127675Sbms return; 31817680Spst 319190207Srpaulo case VCI_ILMIC: 320127675Sbms printf("ilmi: "); 321127675Sbms snmp_print(p, length); 322127675Sbms return; 323127675Sbms } 324127675Sbms } 325127675Sbms 326127675Sbms switch (traftype) { 327127675Sbms 328127675Sbms case ATM_LLC: 329127675Sbms default: 330127675Sbms /* 331127675Sbms * Assumes traffic is LLC if unknown. 332127675Sbms */ 333127675Sbms atm_llc_print(p, length, caplen); 33417680Spst break; 33517680Spst 336127675Sbms case ATM_LANE: 337127675Sbms lane_print(p, length, caplen); 33817680Spst break; 33917680Spst } 34017680Spst} 341146778Ssam 342190207Srpaulostruct oam_fm_loopback_t { 343190207Srpaulo u_int8_t loopback_indicator; 344190207Srpaulo u_int8_t correlation_tag[4]; 345190207Srpaulo u_int8_t loopback_id[12]; 346190207Srpaulo u_int8_t source_id[12]; 347190207Srpaulo u_int8_t unused[16]; 348190207Srpaulo}; 349190207Srpaulo 350190207Srpaulostruct oam_fm_ais_rdi_t { 351190207Srpaulo u_int8_t failure_type; 352190207Srpaulo u_int8_t failure_location[16]; 353190207Srpaulo u_int8_t unused[28]; 354190207Srpaulo}; 355190207Srpaulo 356146778Ssamint 357147904Ssamoam_print (const u_char *p, u_int length, u_int hec) { 358146778Ssam 359172686Smlaier u_int32_t cell_header; 360190207Srpaulo u_int16_t vpi, vci, cksum, cksum_shouldbe, idx; 361190207Srpaulo u_int8_t cell_type, func_type, payload, clp; 362146778Ssam 363190207Srpaulo union { 364190207Srpaulo const struct oam_fm_loopback_t *oam_fm_loopback; 365190207Srpaulo const struct oam_fm_ais_rdi_t *oam_fm_ais_rdi; 366190207Srpaulo } oam_ptr; 367190207Srpaulo 368190207Srpaulo 369172686Smlaier cell_header = EXTRACT_32BITS(p+hec); 370190207Srpaulo cell_type = ((*(p+ATM_HDR_LEN_NOHEC+hec))>>4) & 0x0f; 371190207Srpaulo func_type = (*(p+ATM_HDR_LEN_NOHEC+hec)) & 0x0f; 372146778Ssam 373146778Ssam vpi = (cell_header>>20)&0xff; 374146778Ssam vci = (cell_header>>4)&0xffff; 375146778Ssam payload = (cell_header>>1)&0x7; 376146778Ssam clp = cell_header&0x1; 377146778Ssam 378190207Srpaulo printf("%s, vpi %u, vci %u, payload [ %s ], clp %u, length %u", 379172686Smlaier tok2str(oam_f_values, "OAM F5", vci), 380190207Srpaulo vpi, vci, 381190207Srpaulo tok2str(atm_pty_values, "Unknown", payload), 382190207Srpaulo clp, length); 383146778Ssam 384190207Srpaulo if (!vflag) { 385190207Srpaulo return 1; 386190207Srpaulo } 387190207Srpaulo 388190207Srpaulo printf("\n\tcell-type %s (%u)", 389146778Ssam tok2str(oam_celltype_values, "unknown", cell_type), 390146778Ssam cell_type); 391146778Ssam 392146778Ssam if (oam_functype_values[cell_type] == NULL) 393146778Ssam printf(", func-type unknown (%u)", func_type); 394146778Ssam else 395146778Ssam printf(", func-type %s (%u)", 396190207Srpaulo tok2str(oam_functype_values[cell_type],"none",func_type), 397146778Ssam func_type); 398146778Ssam 399190207Srpaulo p += ATM_HDR_LEN_NOHEC + hec; 400190207Srpaulo 401190207Srpaulo switch (cell_type << 4 | func_type) { 402190207Srpaulo case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_LOOPBACK): 403190207Srpaulo oam_ptr.oam_fm_loopback = (const struct oam_fm_loopback_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN); 404190207Srpaulo printf("\n\tLoopback-Indicator %s, Correlation-Tag 0x%08x", 405190207Srpaulo tok2str(oam_fm_loopback_indicator_values, 406190207Srpaulo "Unknown", 407190207Srpaulo oam_ptr.oam_fm_loopback->loopback_indicator & OAM_FM_LOOPBACK_INDICATOR_MASK), 408190207Srpaulo EXTRACT_32BITS(&oam_ptr.oam_fm_loopback->correlation_tag)); 409190207Srpaulo printf("\n\tLocation-ID "); 410190207Srpaulo for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) { 411190207Srpaulo if (idx % 2) { 412190207Srpaulo printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_loopback->loopback_id[idx])); 413190207Srpaulo } 414190207Srpaulo } 415190207Srpaulo printf("\n\tSource-ID "); 416190207Srpaulo for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->source_id); idx++) { 417190207Srpaulo if (idx % 2) { 418190207Srpaulo printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_loopback->source_id[idx])); 419190207Srpaulo } 420190207Srpaulo } 421190207Srpaulo break; 422190207Srpaulo 423190207Srpaulo case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_AIS): 424190207Srpaulo case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_RDI): 425190207Srpaulo oam_ptr.oam_fm_ais_rdi = (const struct oam_fm_ais_rdi_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN); 426190207Srpaulo printf("\n\tFailure-type 0x%02x", oam_ptr.oam_fm_ais_rdi->failure_type); 427190207Srpaulo printf("\n\tLocation-ID "); 428190207Srpaulo for (idx = 0; idx < sizeof(oam_ptr.oam_fm_ais_rdi->failure_location); idx++) { 429190207Srpaulo if (idx % 2) { 430190207Srpaulo printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_ais_rdi->failure_location[idx])); 431190207Srpaulo } 432190207Srpaulo } 433190207Srpaulo break; 434190207Srpaulo 435190207Srpaulo case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK): 436190207Srpaulo /* FIXME */ 437190207Srpaulo break; 438190207Srpaulo 439190207Srpaulo default: 440190207Srpaulo break; 441190207Srpaulo } 442190207Srpaulo 443190207Srpaulo /* crc10 checksum verification */ 444190207Srpaulo cksum = EXTRACT_16BITS(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN) 445190207Srpaulo & OAM_CRC10_MASK; 446190207Srpaulo cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN); 447190207Srpaulo 448190207Srpaulo printf("\n\tcksum 0x%03x (%scorrect)", 449190207Srpaulo cksum, 450190207Srpaulo cksum_shouldbe == 0 ? "" : "in"); 451190207Srpaulo 452146778Ssam return 1; 453146778Ssam} 454