/*
* Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* the frame relay header has a variable length
*
* the EA bit determines if there is another byte
* in the header
*
* minimum header length is 2 bytes
* maximum header length is 4 bytes
*
* 7 6 5 4 3 2 1 0
* +----+----+----+----+----+----+----+----+
* | DLCI (6 bits) | CR | EA |
* +----+----+----+----+----+----+----+----+
* | DLCI (4 bits) |FECN|BECN| DE | EA |
* +----+----+----+----+----+----+----+----+
* | DLCI (7 bits) | EA |
* +----+----+----+----+----+----+----+----+
* | DLCI (6 bits) |SDLC| EA |
* +----+----+----+----+----+----+----+----+
*/
* Q.922 addresses, as presently defined, are two octets and
contain a 10-bit DLCI. In some networks Q.922 addresses
may optionally be increased to three or four octets.
*/
static void
fr_hdr_print(netdissect_options *ndo, int length, u_int addr_len,
u_int dlci, uint32_t flags, uint16_t nlpid)
{
if (ndo->ndo_qflag) {
ND_PRINT("Q.922, DLCI %u, length %u: ",
dlci,
length);
} else {
if (nlpid <= 0xff) /* if its smaller than 256 then its a NLPID */
ND_PRINT("Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
addr_len,
dlci,
bittok2str(fr_header_flag_values, "none", flags),
tok2str(nlpid_values,"unknown", nlpid),
nlpid,
length);
else /* must be an ethertype */
ND_PRINT("Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
addr_len,
dlci,
bittok2str(fr_header_flag_values, "none", flags),
tok2str(ethertype_values, "unknown", nlpid),
nlpid,
length);
}
}
if (GET_U_1(p + addr_len + 1) == 0) {
/*
* Assume a pad byte after the control (UI) byte.
* A pad byte should only be used with 3-byte Q.922.
*/
if (addr_len != 3)
ND_PRINT("Pad! ");
hdr_len = addr_len + 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
} else {
/*
* Not a pad byte.
* A pad byte should be used with 3-byte Q.922.
*/
if (addr_len == 3)
ND_PRINT("No pad! ");
hdr_len = addr_len + 1 /* UI */ + 1 /* NLPID */;
}
ND_TCHECK_LEN(tptr, ie_len);
tptr+=sizeof(struct ie_tlv_header_t);
/* tlv len includes header */
ie_len-=sizeof(struct ie_tlv_header_t);
tlen-=sizeof(struct ie_tlv_header_t);
switch (ie_type) {
case MFR_CTRL_IE_MAGIC_NUM:
/* FRF.16.1 Section 3.4.3 Magic Number Information Element */
if (ie_len != 4) {
ND_PRINT("[IE data length %d != 4]", ie_len);
nd_print_invalid(ndo);
break;
}
ND_PRINT("0x%08x", GET_BE_U_4(tptr));
break;
case MFR_CTRL_IE_BUNDLE_ID: /* same message format */
case MFR_CTRL_IE_LINK_ID:
for (idx = 0; idx < ie_len && idx < MFR_ID_STRING_MAXLEN; idx++) {
if (GET_U_1(tptr + idx) != 0) /* don't print null termination */
fn_print_char(ndo, GET_U_1(tptr + idx));
else
break;
}
break;
case MFR_CTRL_IE_TIMESTAMP:
/*
* FRF.16.1 Section 3.4.4 Timestamp Information Element
*
* The maximum length is 14 octets. Format is implementation
* specific.
*/
if (ie_len > 14) {
ND_PRINT("[Timestamp IE length %d > 14]", ie_len);
nd_print_invalid(ndo);
break;
}
/* fall through and hexdump */
ND_FALL_THROUGH;
/*
* FIXME those are the defined IEs that lack a decoder
* you are welcome to contribute code ;-)
*/
case MFR_CTRL_IE_VENDOR_EXT:
case MFR_CTRL_IE_CAUSE:
/* must be a middle or the last fragment */
ND_PRINT("FRF.16 Frag, seq %u, Flags [%s]",
sequence_num,
bittok2str(frf_flag_values,"none",(GET_U_1(p) & MFR_BEC_MASK)));
print_unknown_data(ndo, p, "\n\t", length);
return hdr_len;
trunc:
nd_print_trunc(ndo);
return length;
}
/* an NLPID of 0xb1 indicates a 2-byte
* FRF.15 header
*
* 7 6 5 4 3 2 1 0
* +----+----+----+----+----+----+----+----+
* ~ Q.922 header ~
* +----+----+----+----+----+----+----+----+
* | NLPID (8 bits) | NLPID=0xb1
* +----+----+----+----+----+----+----+----+
* | B | E | C |seq. (high 4 bits) | R |
* +----+----+----+----+----+----+----+----+
* | sequence (low 8 bits) |
* +----+----+----+----+----+----+----+----+
*/
/* TODO:
* depending on all permutations of the B, E and C bit
* dig as deep as we can - e.g. on the first (B) fragment
* there is enough payload to print the IP header
* on non (B) fragments it depends if the fragmentation
* model is end-to-end or interface based whether we want to print
* another Q.922 header
*/
return;
trunc:
nd_print_trunc(ndo);
}
/*
* Q.933 decoding portion for framerelay specific.
*/
/* Q.933 packet format
Format of Other Protocols
using Q.933 NLPID
+-------------------------------+
| Q.922 Address |
+---------------+---------------+
|Control 0x03 | NLPID 0x08 |
+---------------+---------------+
| L2 Protocol ID |
| octet 1 | octet 2 |
+-------------------------------+
| L3 Protocol ID |
| octet 2 | octet 2 |
+-------------------------------+
| Protocol Data |
+-------------------------------+
| FCS |
+-------------------------------+
*/
/* array of 16 codesets - currently we only support codepage 0 and 5 */
static const codeset_pr_func_t fr_q933_print_ie_codeset[] = {
fr_q933_print_ie_codeset_0_5,
NULL,
NULL,
NULL,
NULL,
fr_q933_print_ie_codeset_0_5,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
/*
* ITU-T Q.933.
*
* p points to octet 2, the octet containing the length of the
* call reference value, so p[n] is octet n+2 ("octet X" is as
* used in Q.931/Q.933).
*
* XXX - actually used both for Q.931 and Q.933.
*/
void
q933_print(netdissect_options *ndo,
const u_char *p, u_int length)
{
u_int olen;
u_int call_ref_length, i;
uint8_t call_ref[15]; /* maximum length - length field is 4 bits */
u_int msgtype;
u_int iecode;
u_int ielength;
u_int codeset = 0;
u_int is_ansi = 0;
u_int ie_is_known;
u_int non_locking_shift;
u_int unshift_codeset;
if (length == 0 || !ND_TTEST_1(p)) {
if (!ndo->ndo_eflag)
ND_PRINT(", ");
ND_PRINT("length %u", length);
goto trunc;
}
/*
* Get the length of the call reference value.
*/
olen = length; /* preserve the original length for display */
call_ref_length = GET_U_1(p) & 0x0f;
p++;
length--;
/*
* Get the call reference value.
*/
for (i = 0; i < call_ref_length; i++) {
if (length == 0 || !ND_TTEST_1(p)) {
if (!ndo->ndo_eflag)
ND_PRINT(", ");
ND_PRINT("length %u", olen);
goto trunc;
}
call_ref[i] = GET_U_1(p);
p++;
length--;
}
/*
* Get the message type.
*/
if (length == 0 || !ND_TTEST_1(p)) {
if (!ndo->ndo_eflag)
ND_PRINT(", ");
ND_PRINT("length %u", olen);
goto trunc;
}
msgtype = GET_U_1(p);
p++;
length--;
/*
* Peek ahead to see if we start with a shift.
*/
non_locking_shift = 0;
unshift_codeset = codeset;
if (length != 0) {
if (!ND_TTEST_1(p)) {
if (!ndo->ndo_eflag)
ND_PRINT(", ");
ND_PRINT("length %u", olen);
goto trunc;
}
iecode = GET_U_1(p);
if (IE_IS_SHIFT(iecode)) {
/*
* It's a shift. Skip over it.
*/
p++;
length--;
/*
* Get the codeset.
*/
codeset = IE_SHIFT_CODESET(iecode);
/*
* If it's a locking shift to codeset 5,
* mark this as ANSI. (XXX - 5 is actually
* for national variants in general, not
* the US variant in particular, but maybe
* this is more American exceptionalism. :-))
*/
if (IE_SHIFT_IS_LOCKING(iecode)) {
/*
* It's a locking shift.
*/
if (codeset == 5) {
/*
* It's a locking shift to
* codeset 5, so this is
* T1.617 Annex D.
*/
is_ansi = 1;
}
} else {
/*
* It's a non-locking shift.
* Remember the current codeset, so we
* can revert to it after the next IE.
*/
non_locking_shift = 1;
unshift_codeset = 0;
}
}
}
/* printing out header part */
if (!ndo->ndo_eflag)
ND_PRINT(", ");
ND_PRINT("%s, codeset %u", is_ansi ? "ANSI" : "CCITT", codeset);
if (call_ref_length != 0) {
if (call_ref_length > 1 || GET_U_1(p) != 0) {
/*
* Not a dummy call reference.
*/
ND_PRINT(", Call Ref: 0x");
for (i = 0; i < call_ref_length; i++)
ND_PRINT("%02x", call_ref[i]);
}
}
if (ndo->ndo_vflag) {
ND_PRINT(", %s (0x%02x), length %u",
tok2str(fr_q933_msg_values,
"unknown message", msgtype),
msgtype,
olen);
} else {
ND_PRINT(", %s",
tok2str(fr_q933_msg_values,
"unknown message 0x%02x", msgtype));
}
/* Loop through the rest of the IEs */
while (length != 0) {
/*
* What's the state of any non-locking shifts?
*/
if (non_locking_shift == 1) {
/*
* There's a non-locking shift in effect for
* this IE. Count it, so we reset the codeset
* before the next IE.
*/
non_locking_shift = 2;
} else if (non_locking_shift == 2) {
/*
* Unshift.
*/
codeset = unshift_codeset;
non_locking_shift = 0;
}
/*
* Get the first octet of the IE.
*/
if (!ND_TTEST_1(p)) {
if (!ndo->ndo_vflag) {
ND_PRINT(", length %u", olen);
}
goto trunc;
}
iecode = GET_U_1(p);
p++;
length--;
/* Single-octet IE? */
if (IE_IS_SINGLE_OCTET(iecode)) {
/*
* Yes. Is it a shift?
*/
if (IE_IS_SHIFT(iecode)) {
/*
* Yes. Is it locking?
*/
if (IE_SHIFT_IS_LOCKING(iecode)) {
/*
* Yes.
*/
non_locking_shift = 0;
} else {
/*
* No. Remember the current
* codeset, so we can revert
* to it after the next IE.
*/
non_locking_shift = 1;
unshift_codeset = codeset;
}
/*
* Get the codeset.
*/
codeset = IE_SHIFT_CODESET(iecode);
}
} else {
/*
* No. Get the IE length.
*/
if (length == 0 || !ND_TTEST_1(p)) {
if (!ndo->ndo_vflag) {
ND_PRINT(", length %u", olen);
}
goto trunc;
}
ielength = GET_U_1(p);
p++;
length--;
/* lets do the full IE parsing only in verbose mode
* however some IEs (DLCI Status, Link Verify)
* are also interesting in non-verbose mode */
if (ndo->ndo_vflag) {
ND_PRINT("\n\t%s IE (0x%02x), length %u: ",
tok2str(fr_q933_ie_codesets[codeset],
"unknown", iecode),
iecode,
ielength);
}
if (ie_is_known) {
/*
* Known IE; do we want to see a hexdump
* of it?
*/
if (ndo->ndo_vflag > 1) {
/* Yes. */
print_unknown_data(ndo, p, "\n\t ", ielength);
}
} else {
/*
* Unknown IE; if we're printing verbosely,
* print its content in hex.
*/
if (ndo->ndo_vflag >= 1) {
print_unknown_data(ndo, p, "\n\t", ielength);
}
}
length -= ielength;
p += ielength;
}
}
if (!ndo->ndo_vflag) {
ND_PRINT(", length %u", olen);
}
return;
case FR_LMI_ANSI_REPORT_TYPE_IE: /* fall through */
case FR_LMI_CCITT_REPORT_TYPE_IE:
if (ielength < 1) {
if (!ndo->ndo_vflag) {
ND_PRINT(", ");
}
ND_PRINT("Invalid REPORT TYPE IE");
return 1;
}
if (ndo->ndo_vflag) {
ND_PRINT("%s (%u)",
tok2str(fr_lmi_report_type_ie_values,"unknown",GET_U_1(p)),
GET_U_1(p));
}
return 1;
case FR_LMI_ANSI_LINK_VERIFY_IE: /* fall through */
case FR_LMI_CCITT_LINK_VERIFY_IE:
case FR_LMI_ANSI_LINK_VERIFY_IE_91:
if (!ndo->ndo_vflag) {
ND_PRINT(", ");
}
if (ielength < 2) {
ND_PRINT("Invalid LINK VERIFY IE");
return 1;
}
ND_PRINT("TX Seq: %3d, RX Seq: %3d", GET_U_1(p), GET_U_1(p + 1));
return 1;
case FR_LMI_ANSI_PVC_STATUS_IE: /* fall through */
case FR_LMI_CCITT_PVC_STATUS_IE:
if (!ndo->ndo_vflag) {
ND_PRINT(", ");
}
/* now parse the DLCI information element. */
if ((ielength < 3) ||
(GET_U_1(p) & 0x80) ||
((ielength == 3) && !(GET_U_1(p + 1) & 0x80)) ||
((ielength == 4) &&
((GET_U_1(p + 1) & 0x80) || !(GET_U_1(p + 2) & 0x80))) ||
((ielength == 5) &&
((GET_U_1(p + 1) & 0x80) || (GET_U_1(p + 2) & 0x80) ||
!(GET_U_1(p + 3) & 0x80))) ||
(ielength > 5) ||
!(GET_U_1(p + ielength - 1) & 0x80)) {
ND_PRINT("Invalid DLCI in PVC STATUS IE");
return 1;
}