Explicitly request literal mode after .Xr.
[netbsd-mini2440.git] / dist / tcpdump / print-fr.c
blob3a7bb057f4319a559fe3b4cc37f55cf6cc6ba1af
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
25 #ifndef lint
26 #if 0
27 static const char rcsid[] _U_ =
28 "@(#)Header: /tcpdump/master/tcpdump/print-fr.c,v 1.32.2.15 2006/02/01 14:39:56 hannes Exp (LBL)";
29 #else
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
31 #endif
32 #endif
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #include <tcpdump-stdinc.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <pcap.h>
44 #include "addrtoname.h"
45 #include "interface.h"
46 #include "ethertype.h"
47 #include "nlpid.h"
48 #include "extract.h"
49 #include "oui.h"
51 static void frf15_print(const u_char *, u_int);
54 * the frame relay header has a variable length
56 * the EA bit determines if there is another byte
57 * in the header
59 * minimum header length is 2 bytes
60 * maximum header length is 4 bytes
62 * 7 6 5 4 3 2 1 0
63 * +----+----+----+----+----+----+----+----+
64 * | DLCI (6 bits) | CR | EA |
65 * +----+----+----+----+----+----+----+----+
66 * | DLCI (4 bits) |FECN|BECN| DE | EA |
67 * +----+----+----+----+----+----+----+----+
68 * | DLCI (7 bits) | EA |
69 * +----+----+----+----+----+----+----+----+
70 * | DLCI (6 bits) |SDLC| EA |
71 * +----+----+----+----+----+----+----+----+
74 #define FR_EA_BIT 0x01
76 #define FR_CR_BIT 0x02000000
77 #define FR_DE_BIT 0x00020000
78 #define FR_BECN_BIT 0x00040000
79 #define FR_FECN_BIT 0x00080000
80 #define FR_SDLC_BIT 0x00000002
83 struct tok fr_header_flag_values[] = {
84 { FR_CR_BIT, "C!" },
85 { FR_DE_BIT, "DE" },
86 { FR_BECN_BIT, "BECN" },
87 { FR_FECN_BIT, "FECN" },
88 { FR_SDLC_BIT, "sdlcore" },
89 { 0, NULL }
92 /* FRF.15 / FRF.16 */
93 #define MFR_B_BIT 0x80
94 #define MFR_E_BIT 0x40
95 #define MFR_C_BIT 0x20
96 #define MFR_BEC_MASK (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
97 #define MFR_CTRL_FRAME (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
98 #define MFR_FRAG_FRAME (MFR_B_BIT | MFR_E_BIT )
100 struct tok frf_flag_values[] = {
101 { MFR_B_BIT, "Begin" },
102 { MFR_E_BIT, "End" },
103 { MFR_C_BIT, "Control" },
104 { 0, NULL }
107 /* Finds out Q.922 address length, DLCI and flags. Returns 0 on success
108 * save the flags dep. on address length
110 static int parse_q922_addr(const u_char *p, u_int *dlci, u_int *sdlcore,
111 u_int *addr_len, u_int8_t *flags)
113 if ((p[0] & FR_EA_BIT))
114 return -1;
116 *addr_len = 2;
117 *dlci = ((p[0] & 0xFC) << 2) | ((p[1] & 0xF0) >> 4);
119 flags[0] = p[0] & 0x02; /* populate the first flag fields */
120 flags[1] = p[1] & 0x0c;
121 flags[2] = 0; /* clear the rest of the flags */
122 flags[3] = 0;
124 if (p[1] & FR_EA_BIT)
125 return 0; /* 2-byte Q.922 address */
127 p += 2;
128 (*addr_len)++; /* 3- or 4-byte Q.922 address */
129 if ((p[0] & FR_EA_BIT) == 0) {
130 *dlci = (*dlci << 7) | (p[0] >> 1);
131 (*addr_len)++; /* 4-byte Q.922 address */
132 p++;
135 if ((p[0] & FR_EA_BIT) == 0)
136 return -1; /* more than 4 bytes of Q.922 address? */
138 flags[3] = p[0] & 0x02;
140 if (p[0] & 0x02)
141 *sdlcore = p[0] >> 2;
142 else
143 *dlci = (*dlci << 6) | (p[0] >> 2);
145 return 0;
148 /* Frame Relay packet structure, with flags and CRC removed
150 +---------------------------+
151 | Q.922 Address* |
152 +-- --+
154 +---------------------------+
155 | Control (UI = 0x03) |
156 +---------------------------+
157 | Optional Pad (0x00) |
158 +---------------------------+
159 | NLPID |
160 +---------------------------+
161 | . |
162 | . |
163 | . |
164 | Data |
165 | . |
166 | . |
167 +---------------------------+
169 * Q.922 addresses, as presently defined, are two octets and
170 contain a 10-bit DLCI. In some networks Q.922 addresses
171 may optionally be increased to three or four octets.
174 static u_int
175 fr_hdrlen(const u_char *p, u_int addr_len)
177 if (!p[addr_len + 1] /* pad exist */)
178 return addr_len + 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
179 else
180 return addr_len + 1 /* UI */ + 1 /* NLPID */;
183 static void
184 fr_hdr_print(int length, u_int addr_len, u_int dlci, u_int8_t *flags, u_int16_t nlpid)
186 if (qflag) {
187 (void)printf("Q.922, DLCI %u, length %u: ",
188 dlci,
189 length);
190 } else {
191 if (nlpid <= 0xff) /* if its smaller than 256 then its a NLPID */
192 (void)printf("Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
193 addr_len,
194 dlci,
195 bittok2str(fr_header_flag_values, "none", EXTRACT_32BITS(flags)),
196 tok2str(nlpid_values,"unknown", nlpid),
197 nlpid,
198 length);
199 else /* must be an ethertype */
200 (void)printf("Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
201 addr_len,
202 dlci,
203 bittok2str(fr_header_flag_values, "none", EXTRACT_32BITS(flags)),
204 tok2str(ethertype_values, "unknown", nlpid),
205 nlpid,
206 length);
210 u_int
211 fr_if_print(const struct pcap_pkthdr *h, register const u_char *p)
213 register u_int length = h->len;
214 register u_int caplen = h->caplen;
216 TCHECK2(*p, 4); /* minimum frame header length */
218 if ((length = fr_print(p, length)) == 0)
219 return (0);
220 else
221 return length;
222 trunc:
223 printf("[|fr]");
224 return caplen;
227 u_int
228 fr_print(register const u_char *p, u_int length)
230 u_int16_t extracted_ethertype;
231 u_int dlci;
232 u_int sdlcore;
233 u_int addr_len;
234 u_int16_t nlpid;
235 u_int hdr_len;
236 u_int8_t flags[4];
238 if (parse_q922_addr(p, &dlci, &sdlcore, &addr_len, flags)) {
239 printf("Q.922, invalid address");
240 return 0;
243 TCHECK2(*p,addr_len+1+1);
244 hdr_len = fr_hdrlen(p, addr_len);
245 TCHECK2(*p,hdr_len);
247 if (p[addr_len] != 0x03 && dlci != 0) {
249 /* lets figure out if we have cisco style encapsulation: */
250 extracted_ethertype = EXTRACT_16BITS(p+addr_len);
252 if (eflag)
253 fr_hdr_print(length, addr_len, dlci, flags, extracted_ethertype);
255 if (ether_encap_print(extracted_ethertype,
256 p+addr_len+ETHERTYPE_LEN,
257 length-addr_len-ETHERTYPE_LEN,
258 length-addr_len-ETHERTYPE_LEN,
259 &extracted_ethertype) == 0)
260 /* ether_type not known, probably it wasn't one */
261 printf("UI %02x! ", p[addr_len]);
262 else
263 return hdr_len;
266 if (!p[addr_len + 1]) { /* pad byte should be used with 3-byte Q.922 */
267 if (addr_len != 3)
268 printf("Pad! ");
269 } else if (addr_len == 3)
270 printf("No pad! ");
272 nlpid = p[hdr_len - 1];
274 if (eflag)
275 fr_hdr_print(length, addr_len, dlci, flags, nlpid);
276 p += hdr_len;
277 length -= hdr_len;
279 switch (nlpid) {
280 case NLPID_IP:
281 ip_print(gndo, p, length);
282 break;
284 #ifdef INET6
285 case NLPID_IP6:
286 ip6_print(p, length);
287 break;
288 #endif
289 case NLPID_CLNP:
290 case NLPID_ESIS:
291 case NLPID_ISIS:
292 isoclns_print(p-1, length+1, length+1); /* OSI printers need the NLPID field */
293 break;
295 case NLPID_SNAP:
296 if (snap_print(p, length, length, &extracted_ethertype, 0) == 0) {
297 /* ether_type not known, print raw packet */
298 if (!eflag)
299 fr_hdr_print(length + hdr_len, hdr_len,
300 dlci, flags, nlpid);
301 if (!suppress_default_print)
302 default_print(p - hdr_len, length + hdr_len);
304 break;
306 case NLPID_Q933:
307 q933_print(p, length);
308 break;
310 case NLPID_MFR:
311 frf15_print(p, length);
312 break;
314 case NLPID_PPP:
315 ppp_print(p, length);
316 break;
318 default:
319 if (!eflag)
320 fr_hdr_print(length + hdr_len, addr_len,
321 dlci, flags, nlpid);
322 if (!xflag)
323 default_print(p, length);
326 return hdr_len;
328 trunc:
329 printf("[|fr]");
330 return 0;
334 u_int
335 mfr_if_print(const struct pcap_pkthdr *h, register const u_char *p)
337 register u_int length = h->len;
338 register u_int caplen = h->caplen;
340 TCHECK2(*p, 2); /* minimum frame header length */
342 if ((length = mfr_print(p, length)) == 0)
343 return (0);
344 else
345 return length;
346 trunc:
347 printf("[|mfr]");
348 return caplen;
352 #define MFR_CTRL_MSG_ADD_LINK 1
353 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
354 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
355 #define MFR_CTRL_MSG_HELLO 4
356 #define MFR_CTRL_MSG_HELLO_ACK 5
357 #define MFR_CTRL_MSG_REMOVE_LINK 6
358 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
360 struct tok mfr_ctrl_msg_values[] = {
361 { MFR_CTRL_MSG_ADD_LINK, "Add Link" },
362 { MFR_CTRL_MSG_ADD_LINK_ACK, "Add Link ACK" },
363 { MFR_CTRL_MSG_ADD_LINK_REJ, "Add Link Reject" },
364 { MFR_CTRL_MSG_HELLO, "Hello" },
365 { MFR_CTRL_MSG_HELLO_ACK, "Hello ACK" },
366 { MFR_CTRL_MSG_REMOVE_LINK, "Remove Link" },
367 { MFR_CTRL_MSG_REMOVE_LINK_ACK, "Remove Link ACK" },
368 { 0, NULL }
371 #define MFR_CTRL_IE_BUNDLE_ID 1
372 #define MFR_CTRL_IE_LINK_ID 2
373 #define MFR_CTRL_IE_MAGIC_NUM 3
374 #define MFR_CTRL_IE_TIMESTAMP 5
375 #define MFR_CTRL_IE_VENDOR_EXT 6
376 #define MFR_CTRL_IE_CAUSE 7
378 struct tok mfr_ctrl_ie_values[] = {
379 { MFR_CTRL_IE_BUNDLE_ID, "Bundle ID"},
380 { MFR_CTRL_IE_LINK_ID, "Link ID"},
381 { MFR_CTRL_IE_MAGIC_NUM, "Magic Number"},
382 { MFR_CTRL_IE_TIMESTAMP, "Timestamp"},
383 { MFR_CTRL_IE_VENDOR_EXT, "Vendor Extension"},
384 { MFR_CTRL_IE_CAUSE, "Cause"},
385 { 0, NULL }
388 #define MFR_ID_STRING_MAXLEN 50
390 struct ie_tlv_header_t {
391 u_int8_t ie_type;
392 u_int8_t ie_len;
395 u_int
396 mfr_print(register const u_char *p, u_int length)
398 u_int tlen,idx,hdr_len = 0;
399 u_int16_t sequence_num;
400 u_int8_t ie_type,ie_len;
401 const u_int8_t *tptr;
405 * FRF.16 Link Integrity Control Frame
407 * 7 6 5 4 3 2 1 0
408 * +----+----+----+----+----+----+----+----+
409 * | B | E | C=1| 0 0 0 0 | EA |
410 * +----+----+----+----+----+----+----+----+
411 * | 0 0 0 0 0 0 0 0 |
412 * +----+----+----+----+----+----+----+----+
413 * | message type |
414 * +----+----+----+----+----+----+----+----+
417 TCHECK2(*p, 4); /* minimum frame header length */
419 if ((p[0] & MFR_BEC_MASK) == MFR_CTRL_FRAME && p[1] == 0) {
420 printf("FRF.16 Control, Flags [%s], %s, length %u",
421 bittok2str(frf_flag_values,"none",(p[0] & MFR_BEC_MASK)),
422 tok2str(mfr_ctrl_msg_values,"Unknown Message (0x%02x)",p[2]),
423 length);
424 tptr = p + 3;
425 tlen = length -3;
426 hdr_len = 3;
428 if (!vflag)
429 return hdr_len;
431 while (tlen>sizeof(struct ie_tlv_header_t)) {
432 TCHECK2(*tptr, sizeof(struct ie_tlv_header_t));
433 ie_type=tptr[0];
434 ie_len=tptr[1];
436 printf("\n\tIE %s (%u), length %u: ",
437 tok2str(mfr_ctrl_ie_values,"Unknown",ie_type),
438 ie_type,
439 ie_len);
441 /* infinite loop check */
442 if (ie_type == 0 || ie_len <= sizeof(struct ie_tlv_header_t))
443 return hdr_len;
445 TCHECK2(*tptr,ie_len);
446 tptr+=sizeof(struct ie_tlv_header_t);
447 /* tlv len includes header */
448 ie_len-=sizeof(struct ie_tlv_header_t);
449 tlen-=sizeof(struct ie_tlv_header_t);
451 switch (ie_type) {
453 case MFR_CTRL_IE_MAGIC_NUM:
454 printf("0x%08x",EXTRACT_32BITS(tptr));
455 break;
457 case MFR_CTRL_IE_BUNDLE_ID: /* same message format */
458 case MFR_CTRL_IE_LINK_ID:
459 for (idx = 0; idx < ie_len && idx < MFR_ID_STRING_MAXLEN; idx++) {
460 if (*(tptr+idx) != 0) /* don't print null termination */
461 safeputchar(*(tptr+idx));
462 else
463 break;
465 break;
467 case MFR_CTRL_IE_TIMESTAMP:
468 if (ie_len == sizeof(struct timeval)) {
469 ts_print((const struct timeval *)tptr);
470 break;
472 /* fall through and hexdump if no unix timestamp */
475 * FIXME those are the defined IEs that lack a decoder
476 * you are welcome to contribute code ;-)
479 case MFR_CTRL_IE_VENDOR_EXT:
480 case MFR_CTRL_IE_CAUSE:
482 default:
483 if (vflag <= 1)
484 print_unknown_data(tptr,"\n\t ",ie_len);
485 break;
488 /* do we want to see a hexdump of the IE ? */
489 if (vflag > 1 )
490 print_unknown_data(tptr,"\n\t ",ie_len);
492 tlen-=ie_len;
493 tptr+=ie_len;
495 return hdr_len;
498 * FRF.16 Fragmentation Frame
500 * 7 6 5 4 3 2 1 0
501 * +----+----+----+----+----+----+----+----+
502 * | B | E | C=0|seq. (high 4 bits) | EA |
503 * +----+----+----+----+----+----+----+----+
504 * | sequence (low 8 bits) |
505 * +----+----+----+----+----+----+----+----+
506 * | DLCI (6 bits) | CR | EA |
507 * +----+----+----+----+----+----+----+----+
508 * | DLCI (4 bits) |FECN|BECN| DE | EA |
509 * +----+----+----+----+----+----+----+----+
512 sequence_num = (p[0]&0x1e)<<7 | p[1];
513 /* whole packet or first fragment ? */
514 if ((p[0] & MFR_BEC_MASK) == MFR_FRAG_FRAME ||
515 (p[0] & MFR_BEC_MASK) == MFR_B_BIT) {
516 printf("FRF.16 Frag, seq %u, Flags [%s], ",
517 sequence_num,
518 bittok2str(frf_flag_values,"none",(p[0] & MFR_BEC_MASK)));
519 hdr_len = 2;
520 fr_print(p+hdr_len,length-hdr_len);
521 return hdr_len;
524 /* must be a middle or the last fragment */
525 printf("FRF.16 Frag, seq %u, Flags [%s]",
526 sequence_num,
527 bittok2str(frf_flag_values,"none",(p[0] & MFR_BEC_MASK)));
528 print_unknown_data(p,"\n\t",length);
530 return hdr_len;
532 trunc:
533 printf("[|mfr]");
534 return length;
537 /* an NLPID of 0xb1 indicates a 2-byte
538 * FRF.15 header
540 * 7 6 5 4 3 2 1 0
541 * +----+----+----+----+----+----+----+----+
542 * ~ Q.922 header ~
543 * +----+----+----+----+----+----+----+----+
544 * | NLPID (8 bits) | NLPID=0xb1
545 * +----+----+----+----+----+----+----+----+
546 * | B | E | C |seq. (high 4 bits) | R |
547 * +----+----+----+----+----+----+----+----+
548 * | sequence (low 8 bits) |
549 * +----+----+----+----+----+----+----+----+
552 #define FR_FRF15_FRAGTYPE 0x01
554 static void
555 frf15_print (const u_char *p, u_int length) {
557 u_int16_t sequence_num, flags;
559 flags = p[0]&MFR_BEC_MASK;
560 sequence_num = (p[0]&0x1e)<<7 | p[1];
562 printf("FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
563 sequence_num,
564 bittok2str(frf_flag_values,"none",flags),
565 p[0]&FR_FRF15_FRAGTYPE ? "Interface" : "End-to-End",
566 length);
568 /* TODO:
569 * depending on all permutations of the B, E and C bit
570 * dig as deep as we can - e.g. on the first (B) fragment
571 * there is enough payload to print the IP header
572 * on non (B) fragments it depends if the fragmentation
573 * model is end-to-end or interface based wether we want to print
574 * another Q.922 header
580 * Q.933 decoding portion for framerelay specific.
583 /* Q.933 packet format
584 Format of Other Protocols
585 using Q.933 NLPID
586 +-------------------------------+
587 | Q.922 Address |
588 +---------------+---------------+
589 |Control 0x03 | NLPID 0x08 |
590 +---------------+---------------+
591 | L2 Protocol ID |
592 | octet 1 | octet 2 |
593 +-------------------------------+
594 | L3 Protocol ID |
595 | octet 2 | octet 2 |
596 +-------------------------------+
597 | Protocol Data |
598 +-------------------------------+
599 | FCS |
600 +-------------------------------+
603 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
606 * L2 (Octet 2)- Message Types definition 1 byte long.
608 /* Call Establish */
609 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
610 #define MSG_TYPE_ALERT 0x01
611 #define MSG_TYPE_CALL_PROCEEDING 0x02
612 #define MSG_TYPE_CONNECT 0x07
613 #define MSG_TYPE_CONNECT_ACK 0x0F
614 #define MSG_TYPE_PROGRESS 0x03
615 #define MSG_TYPE_SETUP 0x05
616 /* Call Clear */
617 #define MSG_TYPE_DISCONNECT 0x45
618 #define MSG_TYPE_RELEASE 0x4D
619 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
620 #define MSG_TYPE_RESTART 0x46
621 #define MSG_TYPE_RESTART_ACK 0x4E
622 /* Status */
623 #define MSG_TYPE_STATUS 0x7D
624 #define MSG_TYPE_STATUS_ENQ 0x75
626 struct tok fr_q933_msg_values[] = {
627 { MSG_TYPE_ESC_TO_NATIONAL, "ESC to National" },
628 { MSG_TYPE_ALERT, "Alert" },
629 { MSG_TYPE_CALL_PROCEEDING, "Call proceeding" },
630 { MSG_TYPE_CONNECT, "Connect" },
631 { MSG_TYPE_CONNECT_ACK, "Connect ACK" },
632 { MSG_TYPE_PROGRESS, "Progress" },
633 { MSG_TYPE_SETUP, "Setup" },
634 { MSG_TYPE_DISCONNECT, "Disconnect" },
635 { MSG_TYPE_RELEASE, "Release" },
636 { MSG_TYPE_RELEASE_COMPLETE, "Release Complete" },
637 { MSG_TYPE_RESTART, "Restart" },
638 { MSG_TYPE_RESTART_ACK, "Restart ACK" },
639 { MSG_TYPE_STATUS, "Status Reply" },
640 { MSG_TYPE_STATUS_ENQ, "Status Enquiry" },
641 { 0, NULL }
644 #define MSG_ANSI_LOCKING_SHIFT 0x95
646 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
647 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
648 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
649 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
651 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
652 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
653 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
655 struct tok fr_q933_ie_values_codeset5[] = {
656 { FR_LMI_ANSI_REPORT_TYPE_IE, "ANSI Report Type" },
657 { FR_LMI_ANSI_LINK_VERIFY_IE_91, "ANSI Link Verify" },
658 { FR_LMI_ANSI_LINK_VERIFY_IE, "ANSI Link Verify" },
659 { FR_LMI_ANSI_PVC_STATUS_IE, "ANSI PVC Status" },
660 { FR_LMI_CCITT_REPORT_TYPE_IE, "CCITT Report Type" },
661 { FR_LMI_CCITT_LINK_VERIFY_IE, "CCITT Link Verify" },
662 { FR_LMI_CCITT_PVC_STATUS_IE, "CCITT PVC Status" },
663 { 0, NULL }
666 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
667 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
668 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
670 struct tok fr_lmi_report_type_ie_values[] = {
671 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS, "Full Status" },
672 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY, "Link verify" },
673 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC, "Async PVC Status" },
674 { 0, NULL }
677 /* array of 16 codepages - currently we only support codepage 1,5 */
678 static struct tok *fr_q933_ie_codesets[] = {
679 NULL,
680 fr_q933_ie_values_codeset5,
681 NULL,
682 NULL,
683 NULL,
684 fr_q933_ie_values_codeset5,
685 NULL,
686 NULL,
687 NULL,
688 NULL,
689 NULL,
690 NULL,
691 NULL,
692 NULL,
693 NULL,
694 NULL
697 static int fr_q933_print_ie_codeset5(const struct ie_tlv_header_t *ie_p,
698 const u_char *p);
700 typedef int (*codeset_pr_func_t)(const struct ie_tlv_header_t *ie_p,
701 const u_char *p);
703 /* array of 16 codepages - currently we only support codepage 1,5 */
704 static codeset_pr_func_t fr_q933_print_ie_codeset[] = {
705 NULL,
706 fr_q933_print_ie_codeset5,
707 NULL,
708 NULL,
709 NULL,
710 fr_q933_print_ie_codeset5,
711 NULL,
712 NULL,
713 NULL,
714 NULL,
715 NULL,
716 NULL,
717 NULL,
718 NULL,
719 NULL,
720 NULL
723 void
724 q933_print(const u_char *p, u_int length)
726 const u_char *ptemp = p;
727 struct ie_tlv_header_t *ie_p;
728 int olen;
729 int is_ansi = 0;
730 u_int codeset;
731 u_int ie_is_known = 0;
733 if (length < 9) { /* shortest: Q.933a LINK VERIFY */
734 printf("[|q.933]");
735 return;
738 codeset = p[2]&0x0f; /* extract the codeset */
740 if (p[2] == MSG_ANSI_LOCKING_SHIFT)
741 is_ansi = 1;
743 printf("%s", eflag ? "" : "Q.933, ");
745 /* printing out header part */
746 printf("%s, codeset %u", is_ansi ? "ANSI" : "CCITT", codeset);
748 if (p[0])
749 printf(", Call Ref: 0x%02x", p[0]);
751 if (vflag)
752 printf(", %s (0x%02x), length %u",
753 tok2str(fr_q933_msg_values,"unknown message",p[1]),
754 p[1],
755 length);
756 else
757 printf(", %s",
758 tok2str(fr_q933_msg_values,"unknown message 0x%02x",p[1]));
760 olen = length; /* preserve the original length for non verbose mode */
762 if (length < (u_int)(2 - is_ansi)) {
763 printf("[|q.933]");
764 return;
766 length -= 2 - is_ansi;
767 ptemp += 2 + is_ansi;
769 /* Loop through the rest of IE */
770 while (length > sizeof(struct ie_tlv_header_t )) {
771 ie_p = (struct ie_tlv_header_t *)ptemp;
772 if (length < sizeof(struct ie_tlv_header_t ) ||
773 length < sizeof(struct ie_tlv_header_t ) + ie_p->ie_len) {
774 if (vflag) /* not bark if there is just a trailer */
775 printf("\n[|q.933]");
776 else
777 printf(", length %u",olen);
778 return;
781 /* lets do the full IE parsing only in verbose mode
782 * however some IEs (DLCI Status, Link Verify)
783 * are also intereststing in non-verbose mode */
784 if (vflag)
785 printf("\n\t%s IE (0x%02x), length %u: ",
786 tok2str(fr_q933_ie_codesets[codeset],"unknown",ie_p->ie_type),
787 ie_p->ie_type,
788 ie_p->ie_len);
790 /* sanity check */
791 if (ie_p->ie_type == 0 || ie_p->ie_len == 0)
792 return;
794 if (fr_q933_print_ie_codeset[codeset] != NULL)
795 ie_is_known = fr_q933_print_ie_codeset[codeset](ie_p, ptemp);
797 if (vflag >= 1 && !ie_is_known)
798 print_unknown_data(ptemp+2,"\n\t",ie_p->ie_len);
800 /* do we want to see a hexdump of the IE ? */
801 if (vflag> 1 && ie_is_known)
802 print_unknown_data(ptemp+2,"\n\t ",ie_p->ie_len);
804 length = length - ie_p->ie_len - 2;
805 ptemp = ptemp + ie_p->ie_len + 2;
807 if (!vflag)
808 printf(", length %u",olen);
811 static int
812 fr_q933_print_ie_codeset5(const struct ie_tlv_header_t *ie_p, const u_char *p)
814 u_int dlci;
816 switch (ie_p->ie_type) {
818 case FR_LMI_ANSI_REPORT_TYPE_IE: /* fall through */
819 case FR_LMI_CCITT_REPORT_TYPE_IE:
820 if (vflag)
821 printf("%s (%u)",
822 tok2str(fr_lmi_report_type_ie_values,"unknown",p[2]),
823 p[2]);
824 return 1;
826 case FR_LMI_ANSI_LINK_VERIFY_IE: /* fall through */
827 case FR_LMI_CCITT_LINK_VERIFY_IE:
828 case FR_LMI_ANSI_LINK_VERIFY_IE_91:
829 if (!vflag)
830 printf(", ");
831 printf("TX Seq: %3d, RX Seq: %3d", p[2], p[3]);
832 return 1;
834 case FR_LMI_ANSI_PVC_STATUS_IE: /* fall through */
835 case FR_LMI_CCITT_PVC_STATUS_IE:
836 if (!vflag)
837 printf(", ");
838 /* now parse the DLCI information element. */
839 if ((ie_p->ie_len < 3) ||
840 (p[2] & 0x80) ||
841 ((ie_p->ie_len == 3) && !(p[3] & 0x80)) ||
842 ((ie_p->ie_len == 4) && ((p[3] & 0x80) || !(p[4] & 0x80))) ||
843 ((ie_p->ie_len == 5) && ((p[3] & 0x80) || (p[4] & 0x80) ||
844 !(p[5] & 0x80))) ||
845 (ie_p->ie_len > 5) ||
846 !(p[ie_p->ie_len + 1] & 0x80))
847 printf("Invalid DLCI IE");
849 dlci = ((p[2] & 0x3F) << 4) | ((p[3] & 0x78) >> 3);
850 if (ie_p->ie_len == 4)
851 dlci = (dlci << 6) | ((p[4] & 0x7E) >> 1);
852 else if (ie_p->ie_len == 5)
853 dlci = (dlci << 13) | (p[4] & 0x7F) | ((p[5] & 0x7E) >> 1);
855 printf("DLCI %u: status %s%s", dlci,
856 p[ie_p->ie_len + 1] & 0x8 ? "New, " : "",
857 p[ie_p->ie_len + 1] & 0x2 ? "Active" : "Inactive");
858 return 1;
861 return 0;