]> The Tcpdump Group git mirrors - tcpdump/blob - print-fr.c
717ff9c8af8dc16ebbdc7a79d880cdc2d7ea59a7
[tcpdump] / print-fr.c
1 /*
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
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 #ifndef lint
23 static const char rcsid[] _U_ =
24 "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.32.2.6 2005-07-20 22:18:47 hannes Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <tcpdump-stdinc.h>
32
33 #include <stdio.h>
34 #include <string.h>
35 #include <pcap.h>
36
37 #include "addrtoname.h"
38 #include "interface.h"
39 #include "ethertype.h"
40 #include "nlpid.h"
41 #include "extract.h"
42 #include "oui.h"
43
44 static void frf15_print(const u_char *, u_int);
45
46 /*
47 * the frame relay header has a variable length
48 *
49 * the EA bit determines if there is another byte
50 * in the header
51 *
52 * minimum header length is 2 bytes
53 * maximum header length is 4 bytes
54 *
55 * 7 6 5 4 3 2 1 0
56 * +----+----+----+----+----+----+----+----+
57 * | DLCI (6 bits) | CR | EA |
58 * +----+----+----+----+----+----+----+----+
59 * | DLCI (4 bits) |FECN|BECN| DE | EA |
60 * +----+----+----+----+----+----+----+----+
61 * | DLCI (7 bits) | EA |
62 * +----+----+----+----+----+----+----+----+
63 * | DLCI (6 bits) |SDLC| EA |
64 * +----+----+----+----+----+----+----+----+
65 */
66
67 #define FR_EA_BIT 0x01
68
69 #define FR_CR_BIT 0x02000000
70 #define FR_DE_BIT 0x00020000
71 #define FR_BECN_BIT 0x00040000
72 #define FR_FECN_BIT 0x00080000
73 #define FR_SDLC_BIT 0x00000002
74
75
76 struct tok fr_header_flag_values[] = {
77 { FR_CR_BIT, "C!" },
78 { FR_DE_BIT, "DE" },
79 { FR_BECN_BIT, "BECN" },
80 { FR_FECN_BIT, "FECN" },
81 { FR_SDLC_BIT, "sdlcore" },
82 { 0, NULL }
83 };
84
85
86 /* Finds out Q.922 address length, DLCI and flags. Returns 0 on success
87 * save the flags dep. on address length
88 */
89 static int parse_q922_addr(const u_char *p, u_int *dlci, u_int *sdlcore,
90 u_int *addr_len, u_int8_t *flags)
91 {
92 if ((p[0] & FR_EA_BIT))
93 return -1;
94
95 *addr_len = 2;
96 *dlci = ((p[0] & 0xFC) << 2) | ((p[1] & 0xF0) >> 4);
97
98 flags[0] = p[0] & 0x02; /* populate the first flag fields */
99 flags[1] = p[1] & 0x0c;
100
101 if (p[1] & FR_EA_BIT)
102 return 0; /* 2-byte Q.922 address */
103
104 p += 2;
105 (*addr_len)++; /* 3- or 4-byte Q.922 address */
106 if ((p[0] & FR_EA_BIT) == 0) {
107 *dlci = (*dlci << 7) | (p[0] >> 1);
108 (*addr_len)++; /* 4-byte Q.922 address */
109 p++;
110 }
111
112 if ((p[0] & FR_EA_BIT) == 0)
113 return -1; /* more than 4 bytes of Q.922 address? */
114
115 flags[3] = p[0] & 0x02;
116
117 if (p[0] & 0x02)
118 *sdlcore = p[0] >> 2;
119 else
120 *dlci = (*dlci << 6) | (p[0] >> 2);
121
122 return 0;
123 }
124
125 /* Frame Relay packet structure, with flags and CRC removed
126
127 +---------------------------+
128 | Q.922 Address* |
129 +-- --+
130 | |
131 +---------------------------+
132 | Control (UI = 0x03) |
133 +---------------------------+
134 | Optional Pad (0x00) |
135 +---------------------------+
136 | NLPID |
137 +---------------------------+
138 | . |
139 | . |
140 | . |
141 | Data |
142 | . |
143 | . |
144 +---------------------------+
145
146 * Q.922 addresses, as presently defined, are two octets and
147 contain a 10-bit DLCI. In some networks Q.922 addresses
148 may optionally be increased to three or four octets.
149 */
150
151 static u_int
152 fr_hdrlen(const u_char *p, u_int addr_len)
153 {
154 if (!p[addr_len + 1] /* pad exist */)
155 return addr_len + 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
156 else
157 return addr_len + 1 /* UI */ + 1 /* NLPID */;
158 }
159
160 static void
161 fr_hdr_print(int length, u_int addr_len, u_int dlci, u_int8_t *flags, u_int16_t nlpid)
162 {
163 if (qflag) {
164 (void)printf("Q.922, DLCI %u, length %u: ",
165 dlci,
166 length);
167 } else {
168 if (nlpid <= 0xff) /* if its smaller than 256 then its a NLPID */
169 (void)printf("Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
170 addr_len,
171 dlci,
172 bittok2str(fr_header_flag_values, "none", EXTRACT_32BITS(flags)),
173 tok2str(nlpid_values,"unknown", nlpid),
174 nlpid,
175 length);
176 else /* must be an ethertype */
177 (void)printf("Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
178 addr_len,
179 dlci,
180 bittok2str(fr_header_flag_values, "none", EXTRACT_32BITS(flags)),
181 tok2str(ethertype_values, "unknown", nlpid),
182 nlpid,
183 length);
184 }
185 }
186
187 u_int
188 fr_if_print(const struct pcap_pkthdr *h, register const u_char *p)
189 {
190 register u_int length = h->len;
191 register u_int caplen = h->caplen;
192
193 TCHECK2(*p, 4); /* minimum frame header length */
194
195 if ((length = fr_print(p, length)) == 0)
196 return (0);
197 else
198 return length;
199 trunc:
200 printf("[|fr]");
201 return caplen;
202 }
203
204 u_int
205 fr_print(register const u_char *p, u_int length)
206 {
207 u_int16_t extracted_ethertype;
208 u_int dlci;
209 u_int sdlcore;
210 u_int addr_len;
211 u_int16_t nlpid;
212 u_int hdr_len;
213 u_int8_t flags[4];
214
215 if (parse_q922_addr(p, &dlci, &sdlcore, &addr_len, flags)) {
216 printf("Q.922, invalid address");
217 return 0;
218 }
219
220 TCHECK2(*p,addr_len+1+1);
221 hdr_len = fr_hdrlen(p, addr_len);
222 TCHECK2(*p,hdr_len);
223
224 if (p[addr_len] != 0x03 && dlci != 0) {
225
226 /* lets figure out if we have cisco style encapsulation: */
227 extracted_ethertype = EXTRACT_16BITS(p+addr_len);
228
229 if (eflag)
230 fr_hdr_print(length, addr_len, dlci, flags, extracted_ethertype);
231
232 if (ether_encap_print(extracted_ethertype,
233 p+addr_len+ETHERTYPE_LEN,
234 length-addr_len-ETHERTYPE_LEN,
235 length-addr_len-ETHERTYPE_LEN,
236 &extracted_ethertype) == 0)
237 /* ether_type not known, probably it wasn't one */
238 printf("UI %02x! ", p[addr_len]);
239 else
240 return hdr_len;
241 }
242
243 if (!p[addr_len + 1]) { /* pad byte should be used with 3-byte Q.922 */
244 if (addr_len != 3)
245 printf("Pad! ");
246 } else if (addr_len == 3)
247 printf("No pad! ");
248
249 nlpid = p[hdr_len - 1];
250
251 if (eflag)
252 fr_hdr_print(length, addr_len, dlci, flags, nlpid);
253
254 p += hdr_len;
255 length -= hdr_len;
256
257 switch (nlpid) {
258 case NLPID_IP:
259 ip_print(gndo, p, length);
260 break;
261
262 #ifdef INET6
263 case NLPID_IP6:
264 ip6_print(p, length);
265 break;
266 #endif
267 case NLPID_CLNP:
268 case NLPID_ESIS:
269 case NLPID_ISIS:
270 isoclns_print(p-1, length+1, length+1); /* OSI printers need the NLPID field */
271 break;
272
273 case NLPID_SNAP:
274 if (snap_print(p, length, length, &extracted_ethertype, 0) == 0) {
275 /* ether_type not known, print raw packet */
276 if (!eflag)
277 fr_hdr_print(length + hdr_len, hdr_len,
278 dlci, flags, nlpid);
279 if (!suppress_default_print)
280 default_print(p - hdr_len, length + hdr_len);
281 }
282 break;
283
284 case NLPID_Q933:
285 q933_print(p, length);
286 break;
287
288 case NLPID_MFR:
289 frf15_print(p, length);
290 break;
291
292 default:
293 if (!eflag)
294 fr_hdr_print(length + hdr_len, addr_len,
295 dlci, flags, nlpid);
296 if (!xflag)
297 default_print(p, length);
298 }
299
300 return hdr_len;
301
302 trunc:
303 printf("[|fr]");
304 return 0;
305
306 }
307
308 #define MFR_B_BIT 0x80
309 #define MFR_E_BIT 0x40
310 #define MFR_C_BIT 0x20
311 #define MFR_BEC_MASK (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
312 #define MFR_CTRL_FRAME (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
313 #define MFR_FRAG_FRAME (MFR_B_BIT | MFR_E_BIT )
314
315 #define MFR_CTRL_MSG_ADD_LINK 1
316 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
317 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
318 #define MFR_CTRL_MSG_HELLO 4
319 #define MFR_CTRL_MSG_HELLO_ACK 5
320 #define MFR_CTRL_MSG_REMOVE_LINK 6
321 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
322
323 struct tok mfr_ctrl_msg_values[] = {
324 { MFR_CTRL_MSG_ADD_LINK, "Add Link" },
325 { MFR_CTRL_MSG_ADD_LINK_ACK, "Add Link ACK" },
326 { MFR_CTRL_MSG_ADD_LINK_REJ, "Add Link Reject" },
327 { MFR_CTRL_MSG_HELLO, "Hello" },
328 { MFR_CTRL_MSG_HELLO_ACK, "Hello ACK" },
329 { MFR_CTRL_MSG_REMOVE_LINK, "Remove Link" },
330 { MFR_CTRL_MSG_REMOVE_LINK_ACK, "Remove Link ACK" },
331 { 0, NULL }
332 };
333
334 u_int
335 mfr_print(register const u_char *p, u_int length)
336 {
337 u_int hdr_len = 0;
338 u_int16_t sequence_num;
339
340 /*
341 * FRF.16 Link Integrity Control Frame
342 *
343 * 7 6 5 4 3 2 1 0
344 * +----+----+----+----+----+----+----+----+
345 * | B | E | C=1| 0 0 0 0 | EA |
346 * +----+----+----+----+----+----+----+----+
347 * | 0 0 0 0 0 0 0 0 |
348 * +----+----+----+----+----+----+----+----+
349 * | message type |
350 * +----+----+----+----+----+----+----+----+
351 */
352
353 if ((p[0] & MFR_BEC_MASK) == MFR_CTRL_FRAME && p[1] == 0) {
354 printf("FRF.16 Control, %s, length %u",
355 tok2str(mfr_ctrl_msg_values,"Unknown Message (0x%02x)",p[2]),
356 length);
357 switch (p[2]) {
358 /* no decoder yet - so fall through */
359 case MFR_CTRL_MSG_ADD_LINK:
360 case MFR_CTRL_MSG_ADD_LINK_ACK:
361 case MFR_CTRL_MSG_ADD_LINK_REJ:
362 case MFR_CTRL_MSG_HELLO:
363 case MFR_CTRL_MSG_HELLO_ACK:
364 case MFR_CTRL_MSG_REMOVE_LINK:
365 case MFR_CTRL_MSG_REMOVE_LINK_ACK:
366 default:
367 if (vflag >= 1)
368 print_unknown_data(p+3,"\n\t",length-3);
369 break;
370 }
371 return hdr_len;
372 }
373 /*
374 * FRF.16 Fragmentation Frame
375 *
376 * 7 6 5 4 3 2 1 0
377 * +----+----+----+----+----+----+----+----+
378 * | B | E | C=0|seq. (high 4 bits) | EA |
379 * +----+----+----+----+----+----+----+----+
380 * | sequence (low 8 bits) |
381 * +----+----+----+----+----+----+----+----+
382 * | DLCI (6 bits) | CR | EA |
383 * +----+----+----+----+----+----+----+----+
384 * | DLCI (4 bits) |FECN|BECN| DE | EA |
385 * +----+----+----+----+----+----+----+----+
386 */
387
388 if ((p[0] & MFR_BEC_MASK) == MFR_FRAG_FRAME) {
389 sequence_num = (p[0]&0x1e)<<7 | p[1];
390 if (eflag)
391 printf("FRF.16 Frag, seq %u, ", sequence_num);
392 hdr_len = 2;
393 fr_print(p+hdr_len,length-hdr_len);
394 }
395
396 return hdr_len;
397 }
398
399 /* an NLPID of 0xb1 indicates a 2-byte
400 * FRF.15 header
401 *
402 * 7 6 5 4 3 2 1 0
403 * +----+----+----+----+----+----+----+----+
404 * ~ Q.922 header ~
405 * +----+----+----+----+----+----+----+----+
406 * | NLPID (8 bits) | NLPID=0xb1
407 * +----+----+----+----+----+----+----+----+
408 * | B | E | C |seq. (high 4 bits) | R |
409 * +----+----+----+----+----+----+----+----+
410 * | sequence (low 8 bits) |
411 * +----+----+----+----+----+----+----+----+
412 */
413
414 struct tok frf15_flag_values[] = {
415 { 0x80, "Begin" },
416 { 0x40, "End" },
417 { 0x20, "Control" },
418 { 0, NULL }
419 };
420
421 #define FR_FRF15_FRAGTYPE 0x01
422
423 static void
424 frf15_print (const u_char *p, u_int length) {
425
426 u_int16_t sequence_num, flags;
427
428 flags = p[0]&0xe0;
429 sequence_num = (p[0]&0x1e)<<7 | p[1];
430
431 printf("FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
432 sequence_num,
433 bittok2str(frf15_flag_values,"none",flags),
434 flags&FR_FRF15_FRAGTYPE ? "Interface" : "End-to-End",
435 length);
436
437 /* TODO:
438 * depending on all permutations of the B, E and C bit
439 * dig as deep as we can - e.g. on the first (B) fragment
440 * there is enough payload to print the IP header
441 * on non (B) fragments it depends if the fragmentation
442 * model is end-to-end or interface based wether we want to print
443 * another Q.922 header
444 */
445
446 }
447
448 /*
449 * Q.933 decoding portion for framerelay specific.
450 */
451
452 /* Q.933 packet format
453 Format of Other Protocols
454 using Q.933 NLPID
455 +-------------------------------+
456 | Q.922 Address |
457 +---------------+---------------+
458 |Control 0x03 | NLPID 0x08 |
459 +---------------+---------------+
460 | L2 Protocol ID |
461 | octet 1 | octet 2 |
462 +-------------------------------+
463 | L3 Protocol ID |
464 | octet 2 | octet 2 |
465 +-------------------------------+
466 | Protocol Data |
467 +-------------------------------+
468 | FCS |
469 +-------------------------------+
470 */
471
472 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
473
474 /*
475 * L2 (Octet 2)- Message Types definition 1 byte long.
476 */
477 /* Call Establish */
478 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
479 #define MSG_TYPE_ALERT 0x01
480 #define MSG_TYPE_CALL_PROCEEDING 0x02
481 #define MSG_TYPE_CONNECT 0x07
482 #define MSG_TYPE_CONNECT_ACK 0x0F
483 #define MSG_TYPE_PROGRESS 0x03
484 #define MSG_TYPE_SETUP 0x05
485 /* Call Clear */
486 #define MSG_TYPE_DISCONNECT 0x45
487 #define MSG_TYPE_RELEASE 0x4D
488 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
489 #define MSG_TYPE_RESTART 0x46
490 #define MSG_TYPE_RESTART_ACK 0x4E
491 /* Status */
492 #define MSG_TYPE_STATUS 0x7D
493 #define MSG_TYPE_STATUS_ENQ 0x75
494
495 struct tok fr_q933_msg_values[] = {
496 { MSG_TYPE_ESC_TO_NATIONAL, "ESC to National" },
497 { MSG_TYPE_ALERT, "Alert" },
498 { MSG_TYPE_CALL_PROCEEDING, "Call proceeding" },
499 { MSG_TYPE_CONNECT, "Connect" },
500 { MSG_TYPE_CONNECT_ACK, "Connect ACK" },
501 { MSG_TYPE_PROGRESS, "Progress" },
502 { MSG_TYPE_SETUP, "Setup" },
503 { MSG_TYPE_DISCONNECT, "Disconnect" },
504 { MSG_TYPE_RELEASE, "Release" },
505 { MSG_TYPE_RELEASE_COMPLETE, "Release Complete" },
506 { MSG_TYPE_RESTART, "Restart" },
507 { MSG_TYPE_RESTART_ACK, "Restart ACK" },
508 { MSG_TYPE_STATUS, "Status Reply" },
509 { MSG_TYPE_STATUS_ENQ, "Status Enquiry" },
510 { 0, NULL }
511 };
512
513 #define MSG_ANSI_LOCKING_SHIFT 0x95
514
515 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
516 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
517 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
518 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
519
520 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
521 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
522 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
523
524 struct tok fr_q933_ie_values_codeset5[] = {
525 { FR_LMI_ANSI_REPORT_TYPE_IE, "ANSI Report Type" },
526 { FR_LMI_ANSI_LINK_VERIFY_IE_91, "ANSI Link Verify" },
527 { FR_LMI_ANSI_LINK_VERIFY_IE, "ANSI Link Verify" },
528 { FR_LMI_ANSI_PVC_STATUS_IE, "ANSI PVC Status" },
529 { FR_LMI_CCITT_REPORT_TYPE_IE, "CCITT Report Type" },
530 { FR_LMI_CCITT_LINK_VERIFY_IE, "CCITT Link Verify" },
531 { FR_LMI_CCITT_PVC_STATUS_IE, "CCITT PVC Status" },
532 { 0, NULL }
533 };
534
535 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
536 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
537 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
538
539 struct tok fr_lmi_report_type_ie_values[] = {
540 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS, "Full Status" },
541 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY, "Link verify" },
542 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC, "Async PVC Status" },
543 { 0, NULL }
544 };
545
546 /* array of 16 codepages - currently we only support codepage 5 */
547 static struct tok *fr_q933_ie_codesets[] = {
548 NULL,
549 NULL,
550 NULL,
551 NULL,
552 NULL,
553 fr_q933_ie_values_codeset5,
554 NULL,
555 NULL,
556 NULL,
557 NULL,
558 NULL,
559 NULL,
560 NULL,
561 NULL,
562 NULL,
563 NULL
564 };
565
566
567 struct common_ie_header {
568 u_int8_t ie_id;
569 u_int8_t ie_len;
570 };
571
572 static int fr_q933_print_ie_codeset5(const struct common_ie_header *ie_p,
573 const u_char *p);
574
575 typedef int (*codeset_pr_func_t)(const struct common_ie_header *ie_p,
576 const u_char *p);
577
578 /* array of 16 codepages - currently we only support codepage 5 */
579 static codeset_pr_func_t fr_q933_print_ie_codeset[] = {
580 NULL,
581 NULL,
582 NULL,
583 NULL,
584 NULL,
585 fr_q933_print_ie_codeset5,
586 NULL,
587 NULL,
588 NULL,
589 NULL,
590 NULL,
591 NULL,
592 NULL,
593 NULL,
594 NULL,
595 NULL
596 };
597
598 void
599 q933_print(const u_char *p, u_int length)
600 {
601 const u_char *ptemp = p;
602 struct common_ie_header *ie_p;
603 int olen;
604 int is_ansi = 0;
605 u_int codeset;
606 u_int ie_is_known = 0;
607
608 if (length < 9) { /* shortest: Q.933a LINK VERIFY */
609 printf("[|q.933]");
610 return;
611 }
612
613 codeset = p[2]&0x0f; /* extract the codeset */
614
615 if (p[2] == MSG_ANSI_LOCKING_SHIFT)
616 is_ansi = 1;
617
618 printf("%s", eflag ? "" : "Q.933, ");
619
620 /* printing out header part */
621 printf(is_ansi ? "ANSI" : "CCITT");
622
623 if (p[0])
624 printf(", Call Ref: 0x%02x", p[0]);
625
626 if (vflag)
627 printf(", %s (0x%02x), length %u",
628 tok2str(fr_q933_msg_values,"unknown message",p[1]),
629 p[1],
630 length);
631 else
632 printf(", %s",
633 tok2str(fr_q933_msg_values,"unknown message 0x%02x",p[1]));
634
635 olen = length; /* preserve the original length for non verbose mode */
636
637 if (length < (u_int)(2 - is_ansi)) {
638 printf("[|q.933]");
639 return;
640 }
641 length -= 2 - is_ansi;
642 ptemp += 2 + is_ansi;
643
644 /* Loop through the rest of IE */
645 while (length > sizeof(struct common_ie_header)) {
646 ie_p = (struct common_ie_header *)ptemp;
647 if (length < sizeof(struct common_ie_header) ||
648 length < sizeof(struct common_ie_header) + ie_p->ie_len) {
649 if (vflag) /* not bark if there is just a trailer */
650 printf("\n[|q.933]");
651 else
652 printf(", length %u",olen);
653 return;
654 }
655
656 /* lets do the full IE parsing only in verbose mode
657 * however some IEs (DLCI Status, Link Verify)
658 * are also intereststing in non-verbose mode */
659 if (vflag)
660 printf("\n\t%s IE (%u), length %u: ",
661 tok2str(fr_q933_ie_codesets[codeset],"unknown",ie_p->ie_id),
662 ie_p->ie_id,
663 ie_p->ie_len);
664
665 if (fr_q933_print_ie_codeset[codeset] != NULL)
666 ie_is_known = fr_q933_print_ie_codeset[codeset](ie_p, ptemp);
667
668 if (vflag >= 1 && !ie_is_known)
669 print_unknown_data(ptemp+2,"\n\t",ie_p->ie_len);
670
671 /* do we want to see a hexdump of the IE ? */
672 if (vflag> 1 && ie_is_known)
673 print_unknown_data(ptemp+2,"\n\t ",ie_p->ie_len);
674
675 length = length - ie_p->ie_len - 2;
676 ptemp = ptemp + ie_p->ie_len + 2;
677 }
678 if (!vflag)
679 printf(", length %u",olen);
680 }
681
682 static int
683 fr_q933_print_ie_codeset5(const struct common_ie_header *ie_p, const u_char *p)
684 {
685 u_int dlci;
686
687 switch (ie_p->ie_id) {
688
689 case FR_LMI_ANSI_REPORT_TYPE_IE: /* fall through */
690 case FR_LMI_CCITT_REPORT_TYPE_IE:
691 if (vflag)
692 printf("%s (%u)",
693 tok2str(fr_lmi_report_type_ie_values,"unknown",p[2]),
694 p[2]);
695 return 1;
696
697 case FR_LMI_ANSI_LINK_VERIFY_IE: /* fall through */
698 case FR_LMI_CCITT_LINK_VERIFY_IE:
699 case FR_LMI_ANSI_LINK_VERIFY_IE_91:
700 if (!vflag)
701 printf(", ");
702 printf("TX Seq: %3d, RX Seq: %3d", p[2], p[3]);
703 return 1;
704
705 case FR_LMI_ANSI_PVC_STATUS_IE: /* fall through */
706 case FR_LMI_CCITT_PVC_STATUS_IE:
707 if (!vflag)
708 printf(", ");
709 /* now parse the DLCI information element. */
710 if ((ie_p->ie_len < 3) ||
711 (p[2] & 0x80) ||
712 ((ie_p->ie_len == 3) && !(p[3] & 0x80)) ||
713 ((ie_p->ie_len == 4) && ((p[3] & 0x80) || !(p[4] & 0x80))) ||
714 ((ie_p->ie_len == 5) && ((p[3] & 0x80) || (p[4] & 0x80) ||
715 !(p[5] & 0x80))) ||
716 (ie_p->ie_len > 5) ||
717 !(p[ie_p->ie_len + 1] & 0x80))
718 printf("Invalid DLCI IE");
719
720 dlci = ((p[2] & 0x3F) << 4) | ((p[3] & 0x78) >> 3);
721 if (ie_p->ie_len == 4)
722 dlci = (dlci << 6) | ((p[4] & 0x7E) >> 1);
723 else if (ie_p->ie_len == 5)
724 dlci = (dlci << 13) | (p[4] & 0x7F) | ((p[5] & 0x7E) >> 1);
725
726 printf("DLCI %u: status %s%s", dlci,
727 p[ie_p->ie_len + 1] & 0x8 ? "New, " : "",
728 p[ie_p->ie_len + 1] & 0x2 ? "Active" : "Inactive");
729 return 1;
730 }
731
732 return 0;
733 }