12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142 |
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include <netdissect-stdinc.h>
- #include <stdio.h>
- #include <string.h>
- #include "netdissect.h"
- #include "addrtoname.h"
- #include "ethertype.h"
- #include "llc.h"
- #include "nlpid.h"
- #include "extract.h"
- #include "oui.h"
- static void frf15_print(netdissect_options *ndo, const u_char *, u_int);
- #define FR_EA_BIT 0x01
- #define FR_CR_BIT 0x02000000
- #define FR_DE_BIT 0x00020000
- #define FR_BECN_BIT 0x00040000
- #define FR_FECN_BIT 0x00080000
- #define FR_SDLC_BIT 0x00000002
- static const struct tok fr_header_flag_values[] = {
- { FR_CR_BIT, "C!" },
- { FR_DE_BIT, "DE" },
- { FR_BECN_BIT, "BECN" },
- { FR_FECN_BIT, "FECN" },
- { FR_SDLC_BIT, "sdlcore" },
- { 0, NULL }
- };
- #define MFR_B_BIT 0x80
- #define MFR_E_BIT 0x40
- #define MFR_C_BIT 0x20
- #define MFR_BEC_MASK (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
- #define MFR_CTRL_FRAME (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
- #define MFR_FRAG_FRAME (MFR_B_BIT | MFR_E_BIT )
- static const struct tok frf_flag_values[] = {
- { MFR_B_BIT, "Begin" },
- { MFR_E_BIT, "End" },
- { MFR_C_BIT, "Control" },
- { 0, NULL }
- };
- static int parse_q922_addr(netdissect_options *ndo,
- const u_char *p, u_int *dlci,
- u_int *addr_len, uint8_t *flags, u_int length)
- {
- if (!ND_TTEST(p[0]) || length < 1)
- return -1;
- if ((p[0] & FR_EA_BIT))
- return 0;
- if (!ND_TTEST(p[1]) || length < 2)
- return -1;
- *addr_len = 2;
- *dlci = ((p[0] & 0xFC) << 2) | ((p[1] & 0xF0) >> 4);
- flags[0] = p[0] & 0x02;
- flags[1] = p[1] & 0x0c;
- flags[2] = 0;
- flags[3] = 0;
- if (p[1] & FR_EA_BIT)
- return 1;
- p += 2;
- length -= 2;
- if (!ND_TTEST(p[0]) || length < 1)
- return -1;
- (*addr_len)++;
- if ((p[0] & FR_EA_BIT) == 0) {
- *dlci = (*dlci << 7) | (p[0] >> 1);
- (*addr_len)++;
- p++;
- length--;
- }
- if (!ND_TTEST(p[0]) || length < 1)
- return -1;
- if ((p[0] & FR_EA_BIT) == 0)
- return 0;
- flags[3] = p[0] & 0x02;
- *dlci = (*dlci << 6) | (p[0] >> 2);
- return 1;
- }
- char *
- q922_string(netdissect_options *ndo, const u_char *p, u_int length)
- {
- static u_int dlci, addr_len;
- static uint8_t flags[4];
- static char buffer[sizeof("DLCI xxxxxxxxxx")];
- memset(buffer, 0, sizeof(buffer));
- if (parse_q922_addr(ndo, p, &dlci, &addr_len, flags, length) == 1){
- snprintf(buffer, sizeof(buffer), "DLCI %u", dlci);
- }
- return buffer;
- }
- static void
- fr_hdr_print(netdissect_options *ndo,
- int length, u_int addr_len, u_int dlci, uint8_t *flags, uint16_t nlpid)
- {
- if (ndo->ndo_qflag) {
- ND_PRINT((ndo, "Q.922, DLCI %u, length %u: ",
- dlci,
- length));
- } else {
- if (nlpid <= 0xff)
- ND_PRINT((ndo, "Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
- addr_len,
- dlci,
- bittok2str(fr_header_flag_values, "none", EXTRACT_32BITS(flags)),
- tok2str(nlpid_values,"unknown", nlpid),
- nlpid,
- length));
- else
- ND_PRINT((ndo, "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", EXTRACT_32BITS(flags)),
- tok2str(ethertype_values, "unknown", nlpid),
- nlpid,
- length));
- }
- }
- u_int
- fr_if_print(netdissect_options *ndo,
- const struct pcap_pkthdr *h, register const u_char *p)
- {
- register u_int length = h->len;
- register u_int caplen = h->caplen;
- ND_TCHECK2(*p, 4);
- if ((length = fr_print(ndo, p, length)) == 0)
- return (0);
- else
- return length;
- trunc:
- ND_PRINT((ndo, "[|fr]"));
- return caplen;
- }
- u_int
- fr_print(netdissect_options *ndo,
- register const u_char *p, u_int length)
- {
- int ret;
- uint16_t extracted_ethertype;
- u_int dlci;
- u_int addr_len;
- uint16_t nlpid;
- u_int hdr_len;
- uint8_t flags[4];
- ret = parse_q922_addr(ndo, p, &dlci, &addr_len, flags, length);
- if (ret == -1)
- goto trunc;
- if (ret == 0) {
- ND_PRINT((ndo, "Q.922, invalid address"));
- return 0;
- }
- ND_TCHECK(p[addr_len]);
- if (length < addr_len + 1)
- goto trunc;
- if (p[addr_len] != LLC_UI && dlci != 0) {
-
- if (!ND_TTEST2(p[addr_len], 2) || length < addr_len + 2) {
-
- ND_PRINT((ndo, "UI %02x! ", p[addr_len]));
- } else {
- extracted_ethertype = EXTRACT_16BITS(p+addr_len);
- if (ndo->ndo_eflag)
- fr_hdr_print(ndo, length, addr_len, dlci,
- flags, extracted_ethertype);
- if (ethertype_print(ndo, extracted_ethertype,
- p+addr_len+ETHERTYPE_LEN,
- length-addr_len-ETHERTYPE_LEN,
- ndo->ndo_snapend-p-addr_len-ETHERTYPE_LEN,
- NULL, NULL) == 0)
-
- ND_PRINT((ndo, "UI %02x! ", p[addr_len]));
- else
- return addr_len + 2;
- }
- }
- ND_TCHECK(p[addr_len+1]);
- if (length < addr_len + 2)
- goto trunc;
- if (p[addr_len + 1] == 0) {
-
- if (addr_len != 3)
- ND_PRINT((ndo, "Pad! "));
- hdr_len = addr_len + 1 + 1 + 1 ;
- } else {
-
- if (addr_len == 3)
- ND_PRINT((ndo, "No pad! "));
- hdr_len = addr_len + 1 + 1 ;
- }
- ND_TCHECK(p[hdr_len - 1]);
- if (length < hdr_len)
- goto trunc;
- nlpid = p[hdr_len - 1];
- if (ndo->ndo_eflag)
- fr_hdr_print(ndo, length, addr_len, dlci, flags, nlpid);
- p += hdr_len;
- length -= hdr_len;
- switch (nlpid) {
- case NLPID_IP:
- ip_print(ndo, p, length);
- break;
- case NLPID_IP6:
- ip6_print(ndo, p, length);
- break;
- case NLPID_CLNP:
- case NLPID_ESIS:
- case NLPID_ISIS:
- isoclns_print(ndo, p - 1, length + 1);
- break;
- case NLPID_SNAP:
- if (snap_print(ndo, p, length, ndo->ndo_snapend - p, NULL, NULL, 0) == 0) {
-
- if (!ndo->ndo_eflag)
- fr_hdr_print(ndo, length + hdr_len, hdr_len,
- dlci, flags, nlpid);
- if (!ndo->ndo_suppress_default_print)
- ND_DEFAULTPRINT(p - hdr_len, length + hdr_len);
- }
- break;
- case NLPID_Q933:
- q933_print(ndo, p, length);
- break;
- case NLPID_MFR:
- frf15_print(ndo, p, length);
- break;
- case NLPID_PPP:
- ppp_print(ndo, p, length);
- break;
- default:
- if (!ndo->ndo_eflag)
- fr_hdr_print(ndo, length + hdr_len, addr_len,
- dlci, flags, nlpid);
- if (!ndo->ndo_xflag)
- ND_DEFAULTPRINT(p, length);
- }
- return hdr_len;
- trunc:
- ND_PRINT((ndo, "[|fr]"));
- return 0;
- }
- u_int
- mfr_if_print(netdissect_options *ndo,
- const struct pcap_pkthdr *h, register const u_char *p)
- {
- register u_int length = h->len;
- register u_int caplen = h->caplen;
- ND_TCHECK2(*p, 2);
- if ((length = mfr_print(ndo, p, length)) == 0)
- return (0);
- else
- return length;
- trunc:
- ND_PRINT((ndo, "[|mfr]"));
- return caplen;
- }
- #define MFR_CTRL_MSG_ADD_LINK 1
- #define MFR_CTRL_MSG_ADD_LINK_ACK 2
- #define MFR_CTRL_MSG_ADD_LINK_REJ 3
- #define MFR_CTRL_MSG_HELLO 4
- #define MFR_CTRL_MSG_HELLO_ACK 5
- #define MFR_CTRL_MSG_REMOVE_LINK 6
- #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
- static const struct tok mfr_ctrl_msg_values[] = {
- { MFR_CTRL_MSG_ADD_LINK, "Add Link" },
- { MFR_CTRL_MSG_ADD_LINK_ACK, "Add Link ACK" },
- { MFR_CTRL_MSG_ADD_LINK_REJ, "Add Link Reject" },
- { MFR_CTRL_MSG_HELLO, "Hello" },
- { MFR_CTRL_MSG_HELLO_ACK, "Hello ACK" },
- { MFR_CTRL_MSG_REMOVE_LINK, "Remove Link" },
- { MFR_CTRL_MSG_REMOVE_LINK_ACK, "Remove Link ACK" },
- { 0, NULL }
- };
- #define MFR_CTRL_IE_BUNDLE_ID 1
- #define MFR_CTRL_IE_LINK_ID 2
- #define MFR_CTRL_IE_MAGIC_NUM 3
- #define MFR_CTRL_IE_TIMESTAMP 5
- #define MFR_CTRL_IE_VENDOR_EXT 6
- #define MFR_CTRL_IE_CAUSE 7
- static const struct tok mfr_ctrl_ie_values[] = {
- { MFR_CTRL_IE_BUNDLE_ID, "Bundle ID"},
- { MFR_CTRL_IE_LINK_ID, "Link ID"},
- { MFR_CTRL_IE_MAGIC_NUM, "Magic Number"},
- { MFR_CTRL_IE_TIMESTAMP, "Timestamp"},
- { MFR_CTRL_IE_VENDOR_EXT, "Vendor Extension"},
- { MFR_CTRL_IE_CAUSE, "Cause"},
- { 0, NULL }
- };
- #define MFR_ID_STRING_MAXLEN 50
- struct ie_tlv_header_t {
- uint8_t ie_type;
- uint8_t ie_len;
- };
- u_int
- mfr_print(netdissect_options *ndo,
- register const u_char *p, u_int length)
- {
- u_int tlen,idx,hdr_len = 0;
- uint16_t sequence_num;
- uint8_t ie_type,ie_len;
- const uint8_t *tptr;
- ND_TCHECK2(*p, 4);
- if ((p[0] & MFR_BEC_MASK) == MFR_CTRL_FRAME && p[1] == 0) {
- ND_PRINT((ndo, "FRF.16 Control, Flags [%s], %s, length %u",
- bittok2str(frf_flag_values,"none",(p[0] & MFR_BEC_MASK)),
- tok2str(mfr_ctrl_msg_values,"Unknown Message (0x%02x)",p[2]),
- length));
- tptr = p + 3;
- tlen = length -3;
- hdr_len = 3;
- if (!ndo->ndo_vflag)
- return hdr_len;
- while (tlen>sizeof(struct ie_tlv_header_t)) {
- ND_TCHECK2(*tptr, sizeof(struct ie_tlv_header_t));
- ie_type=tptr[0];
- ie_len=tptr[1];
- ND_PRINT((ndo, "\n\tIE %s (%u), length %u: ",
- tok2str(mfr_ctrl_ie_values,"Unknown",ie_type),
- ie_type,
- ie_len));
-
- if (ie_type == 0 || ie_len <= sizeof(struct ie_tlv_header_t))
- return hdr_len;
- ND_TCHECK2(*tptr, ie_len);
- tptr+=sizeof(struct ie_tlv_header_t);
-
- ie_len-=sizeof(struct ie_tlv_header_t);
- tlen-=sizeof(struct ie_tlv_header_t);
- switch (ie_type) {
- case MFR_CTRL_IE_MAGIC_NUM:
- ND_PRINT((ndo, "0x%08x", EXTRACT_32BITS(tptr)));
- break;
- case MFR_CTRL_IE_BUNDLE_ID:
- case MFR_CTRL_IE_LINK_ID:
- for (idx = 0; idx < ie_len && idx < MFR_ID_STRING_MAXLEN; idx++) {
- if (*(tptr+idx) != 0)
- safeputchar(ndo, *(tptr + idx));
- else
- break;
- }
- break;
- case MFR_CTRL_IE_TIMESTAMP:
- if (ie_len == sizeof(struct timeval)) {
- ts_print(ndo, (const struct timeval *)tptr);
- break;
- }
-
-
- case MFR_CTRL_IE_VENDOR_EXT:
- case MFR_CTRL_IE_CAUSE:
- default:
- if (ndo->ndo_vflag <= 1)
- print_unknown_data(ndo, tptr, "\n\t ", ie_len);
- break;
- }
-
- if (ndo->ndo_vflag > 1 )
- print_unknown_data(ndo, tptr, "\n\t ", ie_len);
- tlen-=ie_len;
- tptr+=ie_len;
- }
- return hdr_len;
- }
- sequence_num = (p[0]&0x1e)<<7 | p[1];
-
- if ((p[0] & MFR_BEC_MASK) == MFR_FRAG_FRAME ||
- (p[0] & MFR_BEC_MASK) == MFR_B_BIT) {
- ND_PRINT((ndo, "FRF.16 Frag, seq %u, Flags [%s], ",
- sequence_num,
- bittok2str(frf_flag_values,"none",(p[0] & MFR_BEC_MASK))));
- hdr_len = 2;
- fr_print(ndo, p+hdr_len,length-hdr_len);
- return hdr_len;
- }
-
- ND_PRINT((ndo, "FRF.16 Frag, seq %u, Flags [%s]",
- sequence_num,
- bittok2str(frf_flag_values,"none",(p[0] & MFR_BEC_MASK))));
- print_unknown_data(ndo, p, "\n\t", length);
- return hdr_len;
- trunc:
- ND_PRINT((ndo, "[|mfr]"));
- return length;
- }
- #define FR_FRF15_FRAGTYPE 0x01
- static void
- frf15_print(netdissect_options *ndo,
- const u_char *p, u_int length)
- {
- uint16_t sequence_num, flags;
- if (length < 2)
- goto trunc;
- ND_TCHECK2(*p, 2);
- flags = p[0]&MFR_BEC_MASK;
- sequence_num = (p[0]&0x1e)<<7 | p[1];
- ND_PRINT((ndo, "FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
- sequence_num,
- bittok2str(frf_flag_values,"none",flags),
- p[0]&FR_FRF15_FRAGTYPE ? "Interface" : "End-to-End",
- length));
- return;
- trunc:
- ND_PRINT((ndo, "[|frf.15]"));
- }
- #define MSG_TYPE_ESC_TO_NATIONAL 0x00
- #define MSG_TYPE_ALERT 0x01
- #define MSG_TYPE_CALL_PROCEEDING 0x02
- #define MSG_TYPE_CONNECT 0x07
- #define MSG_TYPE_CONNECT_ACK 0x0F
- #define MSG_TYPE_PROGRESS 0x03
- #define MSG_TYPE_SETUP 0x05
- #define MSG_TYPE_DISCONNECT 0x45
- #define MSG_TYPE_RELEASE 0x4D
- #define MSG_TYPE_RELEASE_COMPLETE 0x5A
- #define MSG_TYPE_RESTART 0x46
- #define MSG_TYPE_RESTART_ACK 0x4E
- #define MSG_TYPE_STATUS 0x7D
- #define MSG_TYPE_STATUS_ENQ 0x75
- static const struct tok fr_q933_msg_values[] = {
- { MSG_TYPE_ESC_TO_NATIONAL, "ESC to National" },
- { MSG_TYPE_ALERT, "Alert" },
- { MSG_TYPE_CALL_PROCEEDING, "Call proceeding" },
- { MSG_TYPE_CONNECT, "Connect" },
- { MSG_TYPE_CONNECT_ACK, "Connect ACK" },
- { MSG_TYPE_PROGRESS, "Progress" },
- { MSG_TYPE_SETUP, "Setup" },
- { MSG_TYPE_DISCONNECT, "Disconnect" },
- { MSG_TYPE_RELEASE, "Release" },
- { MSG_TYPE_RELEASE_COMPLETE, "Release Complete" },
- { MSG_TYPE_RESTART, "Restart" },
- { MSG_TYPE_RESTART_ACK, "Restart ACK" },
- { MSG_TYPE_STATUS, "Status Reply" },
- { MSG_TYPE_STATUS_ENQ, "Status Enquiry" },
- { 0, NULL }
- };
- #define IE_IS_SINGLE_OCTET(iecode) ((iecode) & 0x80)
- #define IE_IS_SHIFT(iecode) (((iecode) & 0xF0) == 0x90)
- #define IE_SHIFT_IS_NON_LOCKING(iecode) ((iecode) & 0x08)
- #define IE_SHIFT_IS_LOCKING(iecode) (!(IE_SHIFT_IS_NON_LOCKING(iecode)))
- #define IE_SHIFT_CODESET(iecode) ((iecode) & 0x07)
- #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
- #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19
- #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
- #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
- #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
- #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
- #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
- static const struct tok fr_q933_ie_values_codeset_0_5[] = {
- { FR_LMI_ANSI_REPORT_TYPE_IE, "ANSI Report Type" },
- { FR_LMI_ANSI_LINK_VERIFY_IE_91, "ANSI Link Verify" },
- { FR_LMI_ANSI_LINK_VERIFY_IE, "ANSI Link Verify" },
- { FR_LMI_ANSI_PVC_STATUS_IE, "ANSI PVC Status" },
- { FR_LMI_CCITT_REPORT_TYPE_IE, "CCITT Report Type" },
- { FR_LMI_CCITT_LINK_VERIFY_IE, "CCITT Link Verify" },
- { FR_LMI_CCITT_PVC_STATUS_IE, "CCITT PVC Status" },
- { 0, NULL }
- };
- #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
- #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
- #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
- static const struct tok fr_lmi_report_type_ie_values[] = {
- { FR_LMI_REPORT_TYPE_IE_FULL_STATUS, "Full Status" },
- { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY, "Link verify" },
- { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC, "Async PVC Status" },
- { 0, NULL }
- };
- static const struct tok *fr_q933_ie_codesets[] = {
- fr_q933_ie_values_codeset_0_5,
- NULL,
- NULL,
- NULL,
- NULL,
- fr_q933_ie_values_codeset_0_5,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
- };
- static int fr_q933_print_ie_codeset_0_5(netdissect_options *ndo, u_int iecode,
- u_int ielength, const u_char *p);
- typedef int (*codeset_pr_func_t)(netdissect_options *, u_int iecode,
- u_int ielength, const u_char *p);
- 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
- };
- 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];
- 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;
- ND_PRINT((ndo, "%s", ndo->ndo_eflag ? "" : "Q.933"));
- if (length == 0 || !ND_TTEST(*p)) {
- if (!ndo->ndo_eflag)
- ND_PRINT((ndo, ", "));
- ND_PRINT((ndo, "length %u", length));
- goto trunc;
- }
-
- olen = length;
- call_ref_length = (*p) & 0x0f;
- p++;
- length--;
-
- for (i = 0; i < call_ref_length; i++) {
- if (length == 0 || !ND_TTEST(*p)) {
- if (!ndo->ndo_eflag)
- ND_PRINT((ndo, ", "));
- ND_PRINT((ndo, "length %u", olen));
- goto trunc;
- }
- call_ref[i] = *p;
- p++;
- length--;
- }
-
- if (length == 0 || !ND_TTEST(*p)) {
- if (!ndo->ndo_eflag)
- ND_PRINT((ndo, ", "));
- ND_PRINT((ndo, "length %u", olen));
- goto trunc;
- }
- msgtype = *p;
- p++;
- length--;
-
- non_locking_shift = 0;
- unshift_codeset = codeset;
- if (length != 0) {
- if (!ND_TTEST(*p)) {
- if (!ndo->ndo_eflag)
- ND_PRINT((ndo, ", "));
- ND_PRINT((ndo, "length %u", olen));
- goto trunc;
- }
- iecode = *p;
- if (IE_IS_SHIFT(iecode)) {
-
- p++;
- length--;
-
- codeset = IE_SHIFT_CODESET(iecode);
-
- if (IE_SHIFT_IS_LOCKING(iecode)) {
-
- if (codeset == 5) {
-
- is_ansi = 1;
- }
- } else {
-
- non_locking_shift = 1;
- unshift_codeset = 0;
- }
- }
- }
-
- if (!ndo->ndo_eflag)
- ND_PRINT((ndo, ", "));
- ND_PRINT((ndo, "%s, codeset %u", is_ansi ? "ANSI" : "CCITT", codeset));
- if (call_ref_length != 0) {
- ND_TCHECK(p[0]);
- if (call_ref_length > 1 || p[0] != 0) {
-
- ND_PRINT((ndo, ", Call Ref: 0x"));
- for (i = 0; i < call_ref_length; i++)
- ND_PRINT((ndo, "%02x", call_ref[i]));
- }
- }
- if (ndo->ndo_vflag) {
- ND_PRINT((ndo, ", %s (0x%02x), length %u",
- tok2str(fr_q933_msg_values,
- "unknown message", msgtype),
- msgtype,
- olen));
- } else {
- ND_PRINT((ndo, ", %s",
- tok2str(fr_q933_msg_values,
- "unknown message 0x%02x", msgtype)));
- }
-
- while (length != 0) {
-
- if (non_locking_shift == 1) {
-
- non_locking_shift = 2;
- } else if (non_locking_shift == 2) {
-
- codeset = unshift_codeset;
- non_locking_shift = 0;
- }
-
- if (!ND_TTEST(*p)) {
- if (!ndo->ndo_vflag) {
- ND_PRINT((ndo, ", length %u", olen));
- }
- goto trunc;
- }
- iecode = *p;
- p++;
- length--;
-
- if (IE_IS_SINGLE_OCTET(iecode)) {
-
- if (IE_IS_SHIFT(iecode)) {
-
- if (IE_SHIFT_IS_LOCKING(iecode)) {
-
- non_locking_shift = 0;
- } else {
-
- non_locking_shift = 1;
- unshift_codeset = codeset;
- }
-
- codeset = IE_SHIFT_CODESET(iecode);
- }
- } else {
-
- if (length == 0 || !ND_TTEST(*p)) {
- if (!ndo->ndo_vflag) {
- ND_PRINT((ndo, ", length %u", olen));
- }
- goto trunc;
- }
- ielength = *p;
- p++;
- length--;
-
- if (ndo->ndo_vflag) {
- ND_PRINT((ndo, "\n\t%s IE (0x%02x), length %u: ",
- tok2str(fr_q933_ie_codesets[codeset],
- "unknown", iecode),
- iecode,
- ielength));
- }
-
- if (iecode == 0 || ielength == 0) {
- return;
- }
- if (length < ielength || !ND_TTEST2(*p, ielength)) {
- if (!ndo->ndo_vflag) {
- ND_PRINT((ndo, ", length %u", olen));
- }
- goto trunc;
- }
- ie_is_known = 0;
- if (fr_q933_print_ie_codeset[codeset] != NULL) {
- ie_is_known = fr_q933_print_ie_codeset[codeset](ndo, iecode, ielength, p);
- }
- if (ie_is_known) {
-
- if (ndo->ndo_vflag > 1) {
-
- print_unknown_data(ndo, p, "\n\t ", ielength);
- }
- } else {
-
- if (ndo->ndo_vflag >= 1) {
- print_unknown_data(ndo, p, "\n\t", ielength);
- }
- }
- length -= ielength;
- p += ielength;
- }
- }
- if (!ndo->ndo_vflag) {
- ND_PRINT((ndo, ", length %u", olen));
- }
- return;
- trunc:
- ND_PRINT((ndo, "[|q.933]"));
- }
- static int
- fr_q933_print_ie_codeset_0_5(netdissect_options *ndo, u_int iecode,
- u_int ielength, const u_char *p)
- {
- u_int dlci;
- switch (iecode) {
- case FR_LMI_ANSI_REPORT_TYPE_IE:
- case FR_LMI_CCITT_REPORT_TYPE_IE:
- if (ielength < 1) {
- if (!ndo->ndo_vflag) {
- ND_PRINT((ndo, ", "));
- }
- ND_PRINT((ndo, "Invalid REPORT TYPE IE"));
- return 1;
- }
- if (ndo->ndo_vflag) {
- ND_PRINT((ndo, "%s (%u)",
- tok2str(fr_lmi_report_type_ie_values,"unknown",p[0]),
- p[0]));
- }
- return 1;
- case FR_LMI_ANSI_LINK_VERIFY_IE:
- case FR_LMI_CCITT_LINK_VERIFY_IE:
- case FR_LMI_ANSI_LINK_VERIFY_IE_91:
- if (!ndo->ndo_vflag) {
- ND_PRINT((ndo, ", "));
- }
- if (ielength < 2) {
- ND_PRINT((ndo, "Invalid LINK VERIFY IE"));
- return 1;
- }
- ND_PRINT((ndo, "TX Seq: %3d, RX Seq: %3d", p[0], p[1]));
- return 1;
- case FR_LMI_ANSI_PVC_STATUS_IE:
- case FR_LMI_CCITT_PVC_STATUS_IE:
- if (!ndo->ndo_vflag) {
- ND_PRINT((ndo, ", "));
- }
-
- if ((ielength < 3) ||
- (p[0] & 0x80) ||
- ((ielength == 3) && !(p[1] & 0x80)) ||
- ((ielength == 4) && ((p[1] & 0x80) || !(p[2] & 0x80))) ||
- ((ielength == 5) && ((p[1] & 0x80) || (p[2] & 0x80) ||
- !(p[3] & 0x80))) ||
- (ielength > 5) ||
- !(p[ielength - 1] & 0x80)) {
- ND_PRINT((ndo, "Invalid DLCI in PVC STATUS IE"));
- return 1;
- }
- dlci = ((p[0] & 0x3F) << 4) | ((p[1] & 0x78) >> 3);
- if (ielength == 4) {
- dlci = (dlci << 6) | ((p[2] & 0x7E) >> 1);
- }
- else if (ielength == 5) {
- dlci = (dlci << 13) | (p[2] & 0x7F) | ((p[3] & 0x7E) >> 1);
- }
- ND_PRINT((ndo, "DLCI %u: status %s%s", dlci,
- p[ielength - 1] & 0x8 ? "New, " : "",
- p[ielength - 1] & 0x2 ? "Active" : "Inactive"));
- return 1;
- }
- return 0;
- }
|