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 #include <sys/cdefs.h> 22 #ifndef lint 23 #if 0 24 static const char rcsid[] _U_ = 25 "@(#) Header: /tcpdump/master/tcpdump/print-atm.c,v 1.49 2007-10-22 19:37:51 guy Exp (LBL)"; 26 #else 27 __RCSID("$NetBSD: print-atm.c,v 1.3 2013/04/06 19:33:08 christos Exp $"); 28 #endif 29 #endif 30 31 #ifdef HAVE_CONFIG_H 32 #include "config.h" 33 #endif 34 35 #include <tcpdump-stdinc.h> 36 37 #include <stdio.h> 38 #include <pcap.h> 39 #include <string.h> 40 41 #include "interface.h" 42 #include "extract.h" 43 #include "addrtoname.h" 44 #include "ethertype.h" 45 #include "atm.h" 46 #include "atmuni31.h" 47 #include "llc.h" 48 49 #include "ether.h" 50 51 #define OAM_CRC10_MASK 0x3ff 52 #define OAM_PAYLOAD_LEN 48 53 #define OAM_FUNCTION_SPECIFIC_LEN 45 /* this excludes crc10 and cell-type/function-type */ 54 #define OAM_CELLTYPE_FUNCTYPE_LEN 1 55 56 struct tok oam_f_values[] = { 57 { VCI_OAMF4SC, "OAM F4 (segment)" }, 58 { VCI_OAMF4EC, "OAM F4 (end)" }, 59 { 0, NULL } 60 }; 61 62 struct tok atm_pty_values[] = { 63 { 0x0, "user data, uncongested, SDU 0" }, 64 { 0x1, "user data, uncongested, SDU 1" }, 65 { 0x2, "user data, congested, SDU 0" }, 66 { 0x3, "user data, congested, SDU 1" }, 67 { 0x4, "VCC OAM F5 flow segment" }, 68 { 0x5, "VCC OAM F5 flow end-to-end" }, 69 { 0x6, "Traffic Control and resource Mgmt" }, 70 { 0, NULL } 71 }; 72 73 #define OAM_CELLTYPE_FM 0x1 74 #define OAM_CELLTYPE_PM 0x2 75 #define OAM_CELLTYPE_AD 0x8 76 #define OAM_CELLTYPE_SM 0xf 77 78 struct tok oam_celltype_values[] = { 79 { OAM_CELLTYPE_FM, "Fault Management" }, 80 { OAM_CELLTYPE_PM, "Performance Management" }, 81 { OAM_CELLTYPE_AD, "activate/deactivate" }, 82 { OAM_CELLTYPE_SM, "System Management" }, 83 { 0, NULL } 84 }; 85 86 #define OAM_FM_FUNCTYPE_AIS 0x0 87 #define OAM_FM_FUNCTYPE_RDI 0x1 88 #define OAM_FM_FUNCTYPE_CONTCHECK 0x4 89 #define OAM_FM_FUNCTYPE_LOOPBACK 0x8 90 91 struct tok oam_fm_functype_values[] = { 92 { OAM_FM_FUNCTYPE_AIS, "AIS" }, 93 { OAM_FM_FUNCTYPE_RDI, "RDI" }, 94 { OAM_FM_FUNCTYPE_CONTCHECK, "Continuity Check" }, 95 { OAM_FM_FUNCTYPE_LOOPBACK, "Loopback" }, 96 { 0, NULL } 97 }; 98 99 struct tok oam_pm_functype_values[] = { 100 { 0x0, "Forward Monitoring" }, 101 { 0x1, "Backward Reporting" }, 102 { 0x2, "Monitoring and Reporting" }, 103 { 0, NULL } 104 }; 105 106 struct tok oam_ad_functype_values[] = { 107 { 0x0, "Performance Monitoring" }, 108 { 0x1, "Continuity Check" }, 109 { 0, NULL } 110 }; 111 112 #define OAM_FM_LOOPBACK_INDICATOR_MASK 0x1 113 114 struct tok oam_fm_loopback_indicator_values[] = { 115 { 0x0, "Reply" }, 116 { 0x1, "Request" }, 117 { 0, NULL } 118 }; 119 120 static const struct tok *oam_functype_values[16] = { 121 NULL, 122 oam_fm_functype_values, /* 1 */ 123 oam_pm_functype_values, /* 2 */ 124 NULL, 125 NULL, 126 NULL, 127 NULL, 128 NULL, 129 oam_ad_functype_values, /* 8 */ 130 NULL, 131 NULL, 132 NULL, 133 NULL, 134 NULL, 135 NULL, 136 NULL 137 }; 138 139 /* 140 * Print an RFC 1483 LLC-encapsulated ATM frame. 141 */ 142 static void 143 atm_llc_print(const u_char *p, int length, int caplen) 144 { 145 u_short extracted_ethertype; 146 147 if (!llc_print(p, length, caplen, NULL, NULL, 148 &extracted_ethertype)) { 149 /* ether_type not known, print raw packet */ 150 if (extracted_ethertype) { 151 printf("(LLC %s) ", 152 etherproto_string(htons(extracted_ethertype))); 153 } 154 if (!suppress_default_print) 155 default_print(p, caplen); 156 } 157 } 158 159 /* 160 * Given a SAP value, generate the LLC header value for a UI packet 161 * with that SAP as the source and destination SAP. 162 */ 163 #define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03) 164 165 /* 166 * This is the top level routine of the printer. 'p' points 167 * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp, 168 * 'h->len' is the length of the packet off the wire, and 'h->caplen' 169 * is the number of bytes actually captured. 170 */ 171 u_int 172 atm_if_print(const struct pcap_pkthdr *h, const u_char *p) 173 { 174 u_int caplen = h->caplen; 175 u_int length = h->len; 176 u_int32_t llchdr; 177 u_int hdrlen = 0; 178 179 if (caplen < 8) { 180 printf("[|atm]"); 181 return (caplen); 182 } 183 184 /* Cisco Style NLPID ? */ 185 if (*p == LLC_UI) { 186 if (eflag) 187 printf("CNLPID "); 188 isoclns_print(p+1, length-1, caplen-1); 189 return hdrlen; 190 } 191 192 /* 193 * Extract the presumed LLC header into a variable, for quick 194 * testing. 195 * Then check for a header that's neither a header for a SNAP 196 * packet nor an RFC 2684 routed NLPID-formatted PDU nor 197 * an 802.2-but-no-SNAP IP packet. 198 */ 199 llchdr = EXTRACT_24BITS(p); 200 if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) && 201 llchdr != LLC_UI_HDR(LLCSAP_ISONS) && 202 llchdr != LLC_UI_HDR(LLCSAP_IP)) { 203 /* 204 * XXX - assume 802.6 MAC header from Fore driver. 205 * 206 * Unfortunately, the above list doesn't check for 207 * all known SAPs, doesn't check for headers where 208 * the source and destination SAP aren't the same, 209 * and doesn't check for non-UI frames. It also 210 * runs the risk of an 802.6 MAC header that happens 211 * to begin with one of those values being 212 * incorrectly treated as an 802.2 header. 213 * 214 * So is that Fore driver still around? And, if so, 215 * is it still putting 802.6 MAC headers on ATM 216 * packets? If so, could it be changed to use a 217 * new DLT_IEEE802_6 value if we added it? 218 */ 219 if (eflag) 220 printf("%08x%08x %08x%08x ", 221 EXTRACT_32BITS(p), 222 EXTRACT_32BITS(p+4), 223 EXTRACT_32BITS(p+8), 224 EXTRACT_32BITS(p+12)); 225 p += 20; 226 length -= 20; 227 caplen -= 20; 228 hdrlen += 20; 229 } 230 atm_llc_print(p, length, caplen); 231 return (hdrlen); 232 } 233 234 /* 235 * ATM signalling. 236 */ 237 static struct tok msgtype2str[] = { 238 { CALL_PROCEED, "Call_proceeding" }, 239 { CONNECT, "Connect" }, 240 { CONNECT_ACK, "Connect_ack" }, 241 { SETUP, "Setup" }, 242 { RELEASE, "Release" }, 243 { RELEASE_DONE, "Release_complete" }, 244 { RESTART, "Restart" }, 245 { RESTART_ACK, "Restart_ack" }, 246 { STATUS, "Status" }, 247 { STATUS_ENQ, "Status_enquiry" }, 248 { ADD_PARTY, "Add_party" }, 249 { ADD_PARTY_ACK, "Add_party_ack" }, 250 { ADD_PARTY_REJ, "Add_party_reject" }, 251 { DROP_PARTY, "Drop_party" }, 252 { DROP_PARTY_ACK, "Drop_party_ack" }, 253 { 0, NULL } 254 }; 255 256 static void 257 sig_print(const u_char *p, int caplen) 258 { 259 bpf_u_int32 call_ref; 260 261 if (caplen < PROTO_POS) { 262 printf("[|atm]"); 263 return; 264 } 265 if (p[PROTO_POS] == Q2931) { 266 /* 267 * protocol:Q.2931 for User to Network Interface 268 * (UNI 3.1) signalling 269 */ 270 printf("Q.2931"); 271 if (caplen < MSG_TYPE_POS) { 272 printf(" [|atm]"); 273 return; 274 } 275 printf(":%s ", 276 tok2str(msgtype2str, "msgtype#%d", p[MSG_TYPE_POS])); 277 278 /* 279 * The call reference comes before the message type, 280 * so if we know we have the message type, which we 281 * do from the caplen test above, we also know we have 282 * the call reference. 283 */ 284 call_ref = EXTRACT_24BITS(&p[CALL_REF_POS]); 285 printf("CALL_REF:0x%06x", call_ref); 286 } else { 287 /* SCCOP with some unknown protocol atop it */ 288 printf("SSCOP, proto %d ", p[PROTO_POS]); 289 } 290 } 291 292 /* 293 * Print an ATM PDU (such as an AAL5 PDU). 294 */ 295 void 296 atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length, 297 u_int caplen) 298 { 299 if (eflag) 300 printf("VPI:%u VCI:%u ", vpi, vci); 301 302 if (vpi == 0) { 303 switch (vci) { 304 305 case VCI_PPC: 306 sig_print(p, caplen); 307 return; 308 309 case VCI_BCC: 310 printf("broadcast sig: "); 311 return; 312 313 case VCI_OAMF4SC: /* fall through */ 314 case VCI_OAMF4EC: 315 oam_print(p, length, ATM_OAM_HEC); 316 return; 317 318 case VCI_METAC: 319 printf("meta: "); 320 return; 321 322 case VCI_ILMIC: 323 printf("ilmi: "); 324 snmp_print(p, length); 325 return; 326 } 327 } 328 329 switch (traftype) { 330 331 case ATM_LLC: 332 default: 333 /* 334 * Assumes traffic is LLC if unknown. 335 */ 336 atm_llc_print(p, length, caplen); 337 break; 338 339 case ATM_LANE: 340 lane_print(p, length, caplen); 341 break; 342 } 343 } 344 345 struct oam_fm_loopback_t { 346 u_int8_t loopback_indicator; 347 u_int8_t correlation_tag[4]; 348 u_int8_t loopback_id[12]; 349 u_int8_t source_id[12]; 350 u_int8_t unused[16]; 351 }; 352 353 struct oam_fm_ais_rdi_t { 354 u_int8_t failure_type; 355 u_int8_t failure_location[16]; 356 u_int8_t unused[28]; 357 }; 358 359 int 360 oam_print (const u_char *p, u_int length, u_int hec) { 361 362 u_int32_t cell_header; 363 u_int16_t vpi, vci, cksum, cksum_shouldbe, idx; 364 u_int8_t cell_type, func_type, payload, clp; 365 366 union { 367 const struct oam_fm_loopback_t *oam_fm_loopback; 368 const struct oam_fm_ais_rdi_t *oam_fm_ais_rdi; 369 } oam_ptr; 370 371 372 cell_header = EXTRACT_32BITS(p+hec); 373 cell_type = ((*(p+ATM_HDR_LEN_NOHEC+hec))>>4) & 0x0f; 374 func_type = (*(p+ATM_HDR_LEN_NOHEC+hec)) & 0x0f; 375 376 vpi = (cell_header>>20)&0xff; 377 vci = (cell_header>>4)&0xffff; 378 payload = (cell_header>>1)&0x7; 379 clp = cell_header&0x1; 380 381 printf("%s, vpi %u, vci %u, payload [ %s ], clp %u, length %u", 382 tok2str(oam_f_values, "OAM F5", vci), 383 vpi, vci, 384 tok2str(atm_pty_values, "Unknown", payload), 385 clp, length); 386 387 if (!vflag) { 388 return 1; 389 } 390 391 printf("\n\tcell-type %s (%u)", 392 tok2str(oam_celltype_values, "unknown", cell_type), 393 cell_type); 394 395 if (oam_functype_values[cell_type] == NULL) 396 printf(", func-type unknown (%u)", func_type); 397 else 398 printf(", func-type %s (%u)", 399 tok2str(oam_functype_values[cell_type],"none",func_type), 400 func_type); 401 402 p += ATM_HDR_LEN_NOHEC + hec; 403 404 switch (cell_type << 4 | func_type) { 405 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_LOOPBACK): 406 oam_ptr.oam_fm_loopback = (const struct oam_fm_loopback_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN); 407 printf("\n\tLoopback-Indicator %s, Correlation-Tag 0x%08x", 408 tok2str(oam_fm_loopback_indicator_values, 409 "Unknown", 410 oam_ptr.oam_fm_loopback->loopback_indicator & OAM_FM_LOOPBACK_INDICATOR_MASK), 411 EXTRACT_32BITS(&oam_ptr.oam_fm_loopback->correlation_tag)); 412 printf("\n\tLocation-ID "); 413 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) { 414 if (idx % 2) { 415 printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_loopback->loopback_id[idx])); 416 } 417 } 418 printf("\n\tSource-ID "); 419 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->source_id); idx++) { 420 if (idx % 2) { 421 printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_loopback->source_id[idx])); 422 } 423 } 424 break; 425 426 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_AIS): 427 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_RDI): 428 oam_ptr.oam_fm_ais_rdi = (const struct oam_fm_ais_rdi_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN); 429 printf("\n\tFailure-type 0x%02x", oam_ptr.oam_fm_ais_rdi->failure_type); 430 printf("\n\tLocation-ID "); 431 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_ais_rdi->failure_location); idx++) { 432 if (idx % 2) { 433 printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_ais_rdi->failure_location[idx])); 434 } 435 } 436 break; 437 438 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK): 439 /* FIXME */ 440 break; 441 442 default: 443 break; 444 } 445 446 /* crc10 checksum verification */ 447 cksum = EXTRACT_16BITS(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN) 448 & OAM_CRC10_MASK; 449 cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN); 450 451 printf("\n\tcksum 0x%03x (%scorrect)", 452 cksum, 453 cksum_shouldbe == 0 ? "" : "in"); 454 455 return 1; 456 } 457