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 22 /* \summary: Asynchronous Transfer Mode (ATM) printer */ 23 24 #include <config.h> 25 26 #include "netdissect-stdinc.h" 27 28 #define ND_LONGJMP_FROM_TCHECK 29 #include "netdissect.h" 30 #include "extract.h" 31 #include "addrtoname.h" 32 #include "atm.h" 33 #include "llc.h" 34 35 /* start of the original atmuni31.h */ 36 37 /* 38 * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 39 * All rights reserved. 40 * 41 * Redistribution and use in source and binary forms, with or without 42 * modification, are permitted provided that the following conditions 43 * are met: 44 * 1. Redistributions of source code must retain the above copyright 45 * notice, this list of conditions and the following disclaimer. 46 * 2. Redistributions in binary form must reproduce the above copyright 47 * notice, this list of conditions and the following disclaimer in the 48 * documentation and/or other materials provided with the distribution. 49 * 3. All advertising materials mentioning features or use of this software 50 * must display the following acknowledgement: 51 * This product includes software developed by Yen Yen Lim and 52 North Dakota State University 53 * 4. The name of the author may not be used to endorse or promote products 54 * derived from this software without specific prior written permission. 55 * 56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 58 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 59 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 60 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 61 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 62 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 65 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 66 * POSSIBILITY OF SUCH DAMAGE. 67 */ 68 69 /* Based on UNI3.1 standard by ATM Forum */ 70 71 /* ATM traffic types based on VPI=0 and (the following VCI */ 72 #define VCI_PPC 0x05 /* Point-to-point signal msg */ 73 #define VCI_BCC 0x02 /* Broadcast signal msg */ 74 #define VCI_OAMF4SC 0x03 /* Segment OAM F4 flow cell */ 75 #define VCI_OAMF4EC 0x04 /* End-to-end OAM F4 flow cell */ 76 #define VCI_METAC 0x01 /* Meta signal msg */ 77 #define VCI_ILMIC 0x10 /* ILMI msg */ 78 79 /* Q.2931 signalling messages */ 80 #define CALL_PROCEED 0x02 /* call proceeding */ 81 #define CONNECT 0x07 /* connect */ 82 #define CONNECT_ACK 0x0f /* connect_ack */ 83 #define SETUP 0x05 /* setup */ 84 #define RELEASE 0x4d /* release */ 85 #define RELEASE_DONE 0x5a /* release_done */ 86 #define RESTART 0x46 /* restart */ 87 #define RESTART_ACK 0x4e /* restart ack */ 88 #define STATUS 0x7d /* status */ 89 #define STATUS_ENQ 0x75 /* status ack */ 90 #define ADD_PARTY 0x80 /* add party */ 91 #define ADD_PARTY_ACK 0x81 /* add party ack */ 92 #define ADD_PARTY_REJ 0x82 /* add party rej */ 93 #define DROP_PARTY 0x83 /* drop party */ 94 #define DROP_PARTY_ACK 0x84 /* drop party ack */ 95 96 /* Information Element Parameters in the signalling messages */ 97 #define CAUSE 0x08 /* cause */ 98 #define ENDPT_REF 0x54 /* endpoint reference */ 99 #define AAL_PARA 0x58 /* ATM adaptation layer parameters */ 100 #define TRAFF_DESCRIP 0x59 /* atm traffic descriptors */ 101 #define CONNECT_ID 0x5a /* connection identifier */ 102 #define QOS_PARA 0x5c /* quality of service parameters */ 103 #define B_HIGHER 0x5d /* broadband higher layer information */ 104 #define B_BEARER 0x5e /* broadband bearer capability */ 105 #define B_LOWER 0x5f /* broadband lower information */ 106 #define CALLING_PARTY 0x6c /* calling party number */ 107 #define CALLED_PARTY 0x70 /* called party number */ 108 109 #define Q2931 0x09 110 111 /* Q.2931 signalling general messages format */ 112 #define PROTO_POS 0 /* offset of protocol discriminator */ 113 #define CALL_REF_POS 2 /* offset of call reference value */ 114 #define MSG_TYPE_POS 5 /* offset of message type */ 115 #if 0 116 #define MSG_LEN_POS 7 /* offset of message length */ 117 #define IE_BEGIN_POS 9 /* offset of first information element */ 118 119 /* format of signalling messages */ 120 #define TYPE_POS 0 121 #define LEN_POS 2 122 #define FIELD_BEGIN_POS 4 123 #endif 124 125 /* end of the original atmuni31.h */ 126 127 128 #define OAM_CRC10_MASK 0x3ff 129 #define OAM_PAYLOAD_LEN 48 130 #define OAM_FUNCTION_SPECIFIC_LEN 45 /* this excludes crc10 and cell-type/function-type */ 131 #define OAM_CELLTYPE_FUNCTYPE_LEN 1 132 133 static const struct tok oam_f_values[] = { 134 { VCI_OAMF4SC, "OAM F4 (segment)" }, 135 { VCI_OAMF4EC, "OAM F4 (end)" }, 136 { 0, NULL } 137 }; 138 139 static const struct tok atm_pty_values[] = { 140 { 0x0, "user data, uncongested, SDU 0" }, 141 { 0x1, "user data, uncongested, SDU 1" }, 142 { 0x2, "user data, congested, SDU 0" }, 143 { 0x3, "user data, congested, SDU 1" }, 144 { 0x4, "VCC OAM F5 flow segment" }, 145 { 0x5, "VCC OAM F5 flow end-to-end" }, 146 { 0x6, "Traffic Control and resource Mgmt" }, 147 { 0, NULL } 148 }; 149 150 #define OAM_CELLTYPE_FM 0x1 151 #define OAM_CELLTYPE_PM 0x2 152 #define OAM_CELLTYPE_AD 0x8 153 #define OAM_CELLTYPE_SM 0xf 154 155 static const struct tok oam_celltype_values[] = { 156 { OAM_CELLTYPE_FM, "Fault Management" }, 157 { OAM_CELLTYPE_PM, "Performance Management" }, 158 { OAM_CELLTYPE_AD, "activate/deactivate" }, 159 { OAM_CELLTYPE_SM, "System Management" }, 160 { 0, NULL } 161 }; 162 163 #define OAM_FM_FUNCTYPE_AIS 0x0 164 #define OAM_FM_FUNCTYPE_RDI 0x1 165 #define OAM_FM_FUNCTYPE_CONTCHECK 0x4 166 #define OAM_FM_FUNCTYPE_LOOPBACK 0x8 167 168 static const struct tok oam_fm_functype_values[] = { 169 { OAM_FM_FUNCTYPE_AIS, "AIS" }, 170 { OAM_FM_FUNCTYPE_RDI, "RDI" }, 171 { OAM_FM_FUNCTYPE_CONTCHECK, "Continuity Check" }, 172 { OAM_FM_FUNCTYPE_LOOPBACK, "Loopback" }, 173 { 0, NULL } 174 }; 175 176 static const struct tok oam_pm_functype_values[] = { 177 { 0x0, "Forward Monitoring" }, 178 { 0x1, "Backward Reporting" }, 179 { 0x2, "Monitoring and Reporting" }, 180 { 0, NULL } 181 }; 182 183 static const struct tok oam_ad_functype_values[] = { 184 { 0x0, "Performance Monitoring" }, 185 { 0x1, "Continuity Check" }, 186 { 0, NULL } 187 }; 188 189 #define OAM_FM_LOOPBACK_INDICATOR_MASK 0x1 190 191 static const struct tok oam_fm_loopback_indicator_values[] = { 192 { 0x0, "Reply" }, 193 { 0x1, "Request" }, 194 { 0, NULL } 195 }; 196 197 static const struct uint_tokary oam_celltype2tokary[] = { 198 { OAM_CELLTYPE_FM, oam_fm_functype_values }, 199 { OAM_CELLTYPE_PM, oam_pm_functype_values }, 200 { OAM_CELLTYPE_AD, oam_ad_functype_values }, 201 /* uint2tokary() does not use array termination. */ 202 }; 203 204 /* 205 * Print an RFC 1483 LLC-encapsulated ATM frame. 206 */ 207 static u_int 208 atm_llc_print(netdissect_options *ndo, 209 const u_char *p, int length, int caplen) 210 { 211 int llc_hdrlen; 212 213 llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL); 214 if (llc_hdrlen < 0) { 215 /* packet not known, print raw packet */ 216 if (!ndo->ndo_suppress_default_print) 217 ND_DEFAULTPRINT(p, caplen); 218 llc_hdrlen = -llc_hdrlen; 219 } 220 return (llc_hdrlen); 221 } 222 223 /* 224 * Given a SAP value, generate the LLC header value for a UI packet 225 * with that SAP as the source and destination SAP. 226 */ 227 #define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03) 228 229 /* 230 * This is the top level routine of the printer. 'p' points 231 * to the LLC/SNAP header of the packet, 'h->ts' is the timestamp, 232 * 'h->len' is the length of the packet off the wire, and 'h->caplen' 233 * is the number of bytes actually captured. 234 */ 235 void 236 atm_if_print(netdissect_options *ndo, 237 const struct pcap_pkthdr *h, const u_char *p) 238 { 239 u_int caplen = h->caplen; 240 u_int length = h->len; 241 uint32_t llchdr; 242 u_int hdrlen = 0; 243 244 ndo->ndo_protocol = "atm"; 245 246 /* Cisco Style NLPID ? */ 247 if (GET_U_1(p) == LLC_UI) { 248 if (ndo->ndo_eflag) 249 ND_PRINT("CNLPID "); 250 ndo->ndo_ll_hdr_len += 1; 251 isoclns_print(ndo, p + 1, length - 1); 252 return; 253 } 254 255 /* 256 * Must have at least a DSAP, an SSAP, and the first byte of the 257 * control field. 258 */ 259 260 /* 261 * Extract the presumed LLC header into a variable, for quick 262 * testing. 263 * Then check for a header that's neither a header for a SNAP 264 * packet nor an RFC 2684 routed NLPID-formatted PDU nor 265 * an 802.2-but-no-SNAP IP packet. 266 */ 267 llchdr = GET_BE_U_3(p); 268 if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) && 269 llchdr != LLC_UI_HDR(LLCSAP_ISONS) && 270 llchdr != LLC_UI_HDR(LLCSAP_IP)) { 271 /* 272 * XXX - assume 802.6 MAC header from Fore driver. 273 * 274 * Unfortunately, the above list doesn't check for 275 * all known SAPs, doesn't check for headers where 276 * the source and destination SAP aren't the same, 277 * and doesn't check for non-UI frames. It also 278 * runs the risk of an 802.6 MAC header that happens 279 * to begin with one of those values being 280 * incorrectly treated as an 802.2 header. 281 * 282 * So is that Fore driver still around? And, if so, 283 * is it still putting 802.6 MAC headers on ATM 284 * packets? If so, could it be changed to use a 285 * new DLT_IEEE802_6 value if we added it? 286 */ 287 if (ndo->ndo_eflag) 288 ND_PRINT("%08x%08x %08x%08x ", 289 GET_BE_U_4(p), 290 GET_BE_U_4(p + 4), 291 GET_BE_U_4(p + 8), 292 GET_BE_U_4(p + 12)); 293 /* Always cover the full header. */ 294 ND_TCHECK_LEN(p, 20); 295 p += 20; 296 length -= 20; 297 caplen -= 20; 298 hdrlen += 20; 299 } 300 ndo->ndo_ll_hdr_len += hdrlen; 301 ndo->ndo_ll_hdr_len += atm_llc_print(ndo, p, length, caplen); 302 } 303 304 /* 305 * ATM signalling. 306 */ 307 static const struct tok msgtype2str[] = { 308 { CALL_PROCEED, "Call_proceeding" }, 309 { CONNECT, "Connect" }, 310 { CONNECT_ACK, "Connect_ack" }, 311 { SETUP, "Setup" }, 312 { RELEASE, "Release" }, 313 { RELEASE_DONE, "Release_complete" }, 314 { RESTART, "Restart" }, 315 { RESTART_ACK, "Restart_ack" }, 316 { STATUS, "Status" }, 317 { STATUS_ENQ, "Status_enquiry" }, 318 { ADD_PARTY, "Add_party" }, 319 { ADD_PARTY_ACK, "Add_party_ack" }, 320 { ADD_PARTY_REJ, "Add_party_reject" }, 321 { DROP_PARTY, "Drop_party" }, 322 { DROP_PARTY_ACK, "Drop_party_ack" }, 323 { 0, NULL } 324 }; 325 326 static void 327 sig_print(netdissect_options *ndo, 328 const u_char *p) 329 { 330 uint32_t call_ref; 331 332 if (GET_U_1(p + PROTO_POS) == Q2931) { 333 /* 334 * protocol:Q.2931 for User to Network Interface 335 * (UNI 3.1) signalling 336 */ 337 ND_PRINT("Q.2931"); 338 ND_PRINT(":%s ", 339 tok2str(msgtype2str, "msgtype#%u", GET_U_1(p + MSG_TYPE_POS))); 340 341 /* 342 * The call reference comes before the message type, 343 * so if we know we have the message type, which we 344 * do from the caplen test above, we also know we have 345 * the call reference. 346 */ 347 call_ref = GET_BE_U_3(p + CALL_REF_POS); 348 ND_PRINT("CALL_REF:0x%06x", call_ref); 349 } else { 350 /* SSCOP with some unknown protocol atop it */ 351 ND_PRINT("SSCOP, proto %u ", GET_U_1(p + PROTO_POS)); 352 } 353 } 354 355 /* 356 * Print an ATM PDU (such as an AAL5 PDU). 357 */ 358 void 359 atm_print(netdissect_options *ndo, 360 u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length, 361 u_int caplen) 362 { 363 ndo->ndo_protocol = "atm"; 364 if (ndo->ndo_eflag) 365 ND_PRINT("VPI:%u VCI:%u ", vpi, vci); 366 367 if (vpi == 0) { 368 switch (vci) { 369 370 case VCI_PPC: 371 sig_print(ndo, p); 372 return; 373 374 case VCI_BCC: 375 ND_PRINT("broadcast sig: "); 376 return; 377 378 case VCI_OAMF4SC: /* fall through */ 379 case VCI_OAMF4EC: 380 oam_print(ndo, p, length, ATM_OAM_HEC); 381 return; 382 383 case VCI_METAC: 384 ND_PRINT("meta: "); 385 return; 386 387 case VCI_ILMIC: 388 ND_PRINT("ilmi: "); 389 snmp_print(ndo, p, length); 390 return; 391 } 392 } 393 394 switch (traftype) { 395 396 case ATM_LLC: 397 default: 398 /* 399 * Assumes traffic is LLC if unknown. 400 */ 401 atm_llc_print(ndo, p, length, caplen); 402 break; 403 404 case ATM_LANE: 405 lane_print(ndo, p, length, caplen); 406 break; 407 } 408 } 409 410 struct oam_fm_loopback_t { 411 nd_uint8_t loopback_indicator; 412 nd_uint32_t correlation_tag; 413 nd_byte loopback_id[12]; 414 nd_byte source_id[12]; 415 nd_byte unused[16]; 416 }; 417 418 struct oam_fm_ais_rdi_t { 419 nd_uint8_t failure_type; 420 nd_byte failure_location[16]; 421 nd_byte unused[28]; 422 }; 423 424 void 425 oam_print(netdissect_options *ndo, 426 const u_char *p, u_int length, u_int hec) 427 { 428 uint32_t cell_header; 429 uint16_t vpi, vci, cksum, cksum_shouldbe, idx; 430 uint8_t cell_type, func_type, payload, clp; 431 const struct tok *oam_functype_str; 432 433 union { 434 const struct oam_fm_loopback_t *oam_fm_loopback; 435 const struct oam_fm_ais_rdi_t *oam_fm_ais_rdi; 436 } oam_ptr; 437 438 ndo->ndo_protocol = "oam"; 439 cell_header = GET_BE_U_4(p + hec); 440 cell_type = (GET_U_1((p + ATM_HDR_LEN_NOHEC + hec)) >> 4) & 0x0f; 441 func_type = GET_U_1((p + ATM_HDR_LEN_NOHEC + hec)) & 0x0f; 442 443 vpi = (cell_header>>20)&0xff; 444 vci = (cell_header>>4)&0xffff; 445 payload = (cell_header>>1)&0x7; 446 clp = cell_header&0x1; 447 448 ND_PRINT("%s, vpi %u, vci %u, payload [ %s ], clp %u, length %u", 449 tok2str(oam_f_values, "OAM F5", vci), 450 vpi, vci, 451 tok2str(atm_pty_values, "Unknown", payload), 452 clp, length); 453 454 if (!ndo->ndo_vflag) { 455 return; 456 } 457 458 ND_PRINT("\n\tcell-type %s (%u)", 459 tok2str(oam_celltype_values, "unknown", cell_type), 460 cell_type); 461 462 oam_functype_str = uint2tokary(oam_celltype2tokary, cell_type); 463 if (oam_functype_str == NULL) 464 ND_PRINT(", func-type unknown (%u)", func_type); 465 else 466 ND_PRINT(", func-type %s (%u)", 467 tok2str(oam_functype_str, "none", func_type), 468 func_type); 469 470 p += ATM_HDR_LEN_NOHEC + hec; 471 472 switch (cell_type << 4 | func_type) { 473 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_LOOPBACK): 474 oam_ptr.oam_fm_loopback = (const struct oam_fm_loopback_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN); 475 ND_TCHECK_SIZE(oam_ptr.oam_fm_loopback); 476 ND_PRINT("\n\tLoopback-Indicator %s, Correlation-Tag 0x%08x", 477 tok2str(oam_fm_loopback_indicator_values, 478 "Unknown", 479 GET_U_1(oam_ptr.oam_fm_loopback->loopback_indicator) & OAM_FM_LOOPBACK_INDICATOR_MASK), 480 GET_BE_U_4(oam_ptr.oam_fm_loopback->correlation_tag)); 481 ND_PRINT("\n\tLocation-ID "); 482 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) { 483 if (idx % 2) { 484 ND_PRINT("%04x ", 485 GET_BE_U_2(&oam_ptr.oam_fm_loopback->loopback_id[idx])); 486 } 487 } 488 ND_PRINT("\n\tSource-ID "); 489 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->source_id); idx++) { 490 if (idx % 2) { 491 ND_PRINT("%04x ", 492 GET_BE_U_2(&oam_ptr.oam_fm_loopback->source_id[idx])); 493 } 494 } 495 break; 496 497 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_AIS): 498 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_RDI): 499 oam_ptr.oam_fm_ais_rdi = (const struct oam_fm_ais_rdi_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN); 500 ND_TCHECK_SIZE(oam_ptr.oam_fm_ais_rdi); 501 ND_PRINT("\n\tFailure-type 0x%02x", 502 GET_U_1(oam_ptr.oam_fm_ais_rdi->failure_type)); 503 ND_PRINT("\n\tLocation-ID "); 504 for (idx = 0; idx < sizeof(oam_ptr.oam_fm_ais_rdi->failure_location); idx++) { 505 if (idx % 2) { 506 ND_PRINT("%04x ", 507 GET_BE_U_2(&oam_ptr.oam_fm_ais_rdi->failure_location[idx])); 508 } 509 } 510 break; 511 512 case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK): 513 /* FIXME */ 514 break; 515 516 default: 517 break; 518 } 519 520 /* crc10 checksum verification */ 521 cksum = GET_BE_U_2(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN) 522 & OAM_CRC10_MASK; 523 cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN); 524 525 ND_PRINT("\n\tcksum 0x%03x (%scorrect)", 526 cksum, 527 cksum_shouldbe == 0 ? "" : "in"); 528 } 529