]> The Tcpdump Group git mirrors - tcpdump/blob - print-fr.c
86ce38a109023e5d062bd7c9e120ad4acae6de38
[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.42 2005-07-26 13:18:07 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 p += hdr_len;
254 length -= hdr_len;
255
256 switch (nlpid) {
257 case NLPID_IP:
258 ip_print(gndo, p, length);
259 break;
260
261 #ifdef INET6
262 case NLPID_IP6:
263 ip6_print(p, length);
264 break;
265 #endif
266 case NLPID_CLNP:
267 case NLPID_ESIS:
268 case NLPID_ISIS:
269 isoclns_print(p-1, length+1, length+1); /* OSI printers need the NLPID field */
270 break;
271
272 case NLPID_SNAP:
273 if (snap_print(p, length, length, &extracted_ethertype, 0) == 0) {
274 /* ether_type not known, print raw packet */
275 if (!eflag)
276 fr_hdr_print(length + hdr_len, hdr_len,
277 dlci, flags, nlpid);
278 if (!suppress_default_print)
279 default_print(p - hdr_len, length + hdr_len);
280 }
281 break;
282
283 case NLPID_Q933:
284 q933_print(p, length);
285 break;
286
287 case NLPID_MFR:
288 frf15_print(p, length);
289 break;
290
291 default:
292 if (!eflag)
293 fr_hdr_print(length + hdr_len, addr_len,
294 dlci, flags, nlpid);
295 if (!xflag)
296 default_print(p, length);
297 }
298
299 return hdr_len;
300
301 trunc:
302 printf("[|fr]");
303 return 0;
304
305 }
306
307 #define MFR_B_BIT 0x80
308 #define MFR_E_BIT 0x40
309 #define MFR_C_BIT 0x20
310 #define MFR_BEC_MASK (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
311 #define MFR_CTRL_FRAME (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
312 #define MFR_FRAG_FRAME (MFR_B_BIT | MFR_E_BIT )
313
314 #define MFR_CTRL_MSG_ADD_LINK 1
315 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
316 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
317 #define MFR_CTRL_MSG_HELLO 4
318 #define MFR_CTRL_MSG_HELLO_ACK 5
319 #define MFR_CTRL_MSG_REMOVE_LINK 6
320 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
321
322 struct tok mfr_ctrl_msg_values[] = {
323 { MFR_CTRL_MSG_ADD_LINK, "Add Link" },
324 { MFR_CTRL_MSG_ADD_LINK_ACK, "Add Link ACK" },
325 { MFR_CTRL_MSG_ADD_LINK_REJ, "Add Link Reject" },
326 { MFR_CTRL_MSG_HELLO, "Hello" },
327 { MFR_CTRL_MSG_HELLO_ACK, "Hello ACK" },
328 { MFR_CTRL_MSG_REMOVE_LINK, "Remove Link" },
329 { MFR_CTRL_MSG_REMOVE_LINK_ACK, "Remove Link ACK" },
330 { 0, NULL }
331 };
332
333 #define MFR_CTRL_IE_BUNDLE_ID 1
334 #define MFR_CTRL_IE_LINK_ID 2
335 #define MFR_CTRL_IE_MAGIC_NUM 3
336 #define MFR_CTRL_IE_TIMESTAMP 5
337 #define MFR_CTRL_IE_VENDOR_EXT 6
338 #define MFR_CTRL_IE_CAUSE 7
339
340 struct tok mfr_ctrl_ie_values[] = {
341 { MFR_CTRL_IE_BUNDLE_ID, "Bundle ID"},
342 { MFR_CTRL_IE_LINK_ID, "Link ID"},
343 { MFR_CTRL_IE_MAGIC_NUM, "Magic Number"},
344 { MFR_CTRL_IE_TIMESTAMP, "Timestamp"},
345 { MFR_CTRL_IE_VENDOR_EXT, "Vendor Extension"},
346 { MFR_CTRL_IE_CAUSE, "Cause"},
347 { 0, NULL }
348 };
349
350 #define MFR_ID_STRING_MAXLEN 50
351
352 struct ie_tlv_header_t {
353 u_int8_t ie_type;
354 u_int8_t ie_len;
355 };
356
357 u_int
358 mfr_print(register const u_char *p, u_int length)
359 {
360 u_int tlen,idx,hdr_len = 0;
361 u_int16_t sequence_num;
362 u_int8_t ie_type,ie_len;
363 const char *tptr;
364
365
366 /*
367 * FRF.16 Link Integrity Control Frame
368 *
369 * 7 6 5 4 3 2 1 0
370 * +----+----+----+----+----+----+----+----+
371 * | B | E | C=1| 0 0 0 0 | EA |
372 * +----+----+----+----+----+----+----+----+
373 * | 0 0 0 0 0 0 0 0 |
374 * +----+----+----+----+----+----+----+----+
375 * | message type |
376 * +----+----+----+----+----+----+----+----+
377 */
378
379 TCHECK2(*p, 4); /* minimum frame header length */
380
381 if ((p[0] & MFR_BEC_MASK) == MFR_CTRL_FRAME && p[1] == 0) {
382 printf("FRF.16 Control, %s, length %u",
383 tok2str(mfr_ctrl_msg_values,"Unknown Message (0x%02x)",p[2]),
384 length);
385 tptr = p + 3;
386 tlen = length -3;
387 hdr_len = 3;
388
389 if (!vflag)
390 return hdr_len;
391
392 while (tlen>sizeof(struct ie_tlv_header_t)) {
393 TCHECK2(*tptr, sizeof(struct ie_tlv_header_t));
394 ie_type=tptr[0];
395 ie_len=tptr[1];
396
397 printf("\n\tIE %s (%u), length %u: ",
398 tok2str(mfr_ctrl_ie_values,"Unknown",ie_type),
399 ie_type,
400 ie_len);
401
402 /* infinite loop check */
403 if (ie_type == 0 || ie_len <= sizeof(struct ie_tlv_header_t))
404 return hdr_len;
405
406 TCHECK2(*tptr,ie_len);
407 tptr+=sizeof(struct ie_tlv_header_t);
408 /* tlv len includes header */
409 ie_len-=sizeof(struct ie_tlv_header_t);
410 tlen-=sizeof(struct ie_tlv_header_t);
411
412 switch (ie_type) {
413
414 case MFR_CTRL_IE_MAGIC_NUM:
415 printf("0x%08x",EXTRACT_32BITS(tptr));
416 break;
417
418 case MFR_CTRL_IE_BUNDLE_ID: /* same message format */
419 case MFR_CTRL_IE_LINK_ID:
420 for (idx = 0; idx < ie_len && idx < MFR_ID_STRING_MAXLEN; idx++) {
421 if (*(tptr+idx) != 0) /* don't print null termination */
422 safeputchar(*(tptr+idx));
423 else
424 break;
425 }
426 break;
427
428 case MFR_CTRL_IE_TIMESTAMP:
429 if (ie_len == sizeof(struct timeval)) {
430 ts_print((const struct timeval *)tptr);
431 break;
432 }
433 /* fall through and hexdump if no unix timestamp */
434
435 /*
436 * FIXME those are the defined IEs that lack a decoder
437 * you are welcome to contribute code ;-)
438 */
439
440 case MFR_CTRL_IE_VENDOR_EXT:
441 case MFR_CTRL_IE_CAUSE:
442
443 default:
444 if (vflag <= 1)
445 print_unknown_data(tptr,"\n\t ",ie_len);
446 break;
447 }
448
449 /* do we want to see a hexdump of the IE ? */
450 if (vflag > 1 )
451 print_unknown_data(tptr,"\n\t ",ie_len);
452
453 tlen-=ie_len;
454 tptr+=ie_len;
455 }
456 return hdr_len;
457 }
458 /*
459 * FRF.16 Fragmentation Frame
460 *
461 * 7 6 5 4 3 2 1 0
462 * +----+----+----+----+----+----+----+----+
463 * | B | E | C=0|seq. (high 4 bits) | EA |
464 * +----+----+----+----+----+----+----+----+
465 * | sequence (low 8 bits) |
466 * +----+----+----+----+----+----+----+----+
467 * | DLCI (6 bits) | CR | EA |
468 * +----+----+----+----+----+----+----+----+
469 * | DLCI (4 bits) |FECN|BECN| DE | EA |
470 * +----+----+----+----+----+----+----+----+
471 */
472
473 if ((p[0] & MFR_BEC_MASK) == MFR_FRAG_FRAME) {
474 sequence_num = (p[0]&0x1e)<<7 | p[1];
475 if (eflag)
476 printf("FRF.16 Frag, seq %u, ", sequence_num);
477 hdr_len = 2;
478 fr_print(p+hdr_len,length-hdr_len);
479 }
480
481 return hdr_len;
482
483 trunc:
484 printf("[|mfr]");
485 return length;
486 }
487
488 /* an NLPID of 0xb1 indicates a 2-byte
489 * FRF.15 header
490 *
491 * 7 6 5 4 3 2 1 0
492 * +----+----+----+----+----+----+----+----+
493 * ~ Q.922 header ~
494 * +----+----+----+----+----+----+----+----+
495 * | NLPID (8 bits) | NLPID=0xb1
496 * +----+----+----+----+----+----+----+----+
497 * | B | E | C |seq. (high 4 bits) | R |
498 * +----+----+----+----+----+----+----+----+
499 * | sequence (low 8 bits) |
500 * +----+----+----+----+----+----+----+----+
501 */
502
503 struct tok frf15_flag_values[] = {
504 { 0x80, "Begin" },
505 { 0x40, "End" },
506 { 0x20, "Control" },
507 { 0, NULL }
508 };
509
510 #define FR_FRF15_FRAGTYPE 0x01
511
512 static void
513 frf15_print (const u_char *p, u_int length) {
514
515 u_int16_t sequence_num, flags;
516
517 flags = p[0]&0xe0;
518 sequence_num = (p[0]&0x1e)<<7 | p[1];
519
520 printf("FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
521 sequence_num,
522 bittok2str(frf15_flag_values,"none",flags),
523 flags&FR_FRF15_FRAGTYPE ? "Interface" : "End-to-End",
524 length);
525
526 /* TODO:
527 * depending on all permutations of the B, E and C bit
528 * dig as deep as we can - e.g. on the first (B) fragment
529 * there is enough payload to print the IP header
530 * on non (B) fragments it depends if the fragmentation
531 * model is end-to-end or interface based wether we want to print
532 * another Q.922 header
533 */
534
535 }
536
537 /*
538 * Q.933 decoding portion for framerelay specific.
539 */
540
541 /* Q.933 packet format
542 Format of Other Protocols
543 using Q.933 NLPID
544 +-------------------------------+
545 | Q.922 Address |
546 +---------------+---------------+
547 |Control 0x03 | NLPID 0x08 |
548 +---------------+---------------+
549 | L2 Protocol ID |
550 | octet 1 | octet 2 |
551 +-------------------------------+
552 | L3 Protocol ID |
553 | octet 2 | octet 2 |
554 +-------------------------------+
555 | Protocol Data |
556 +-------------------------------+
557 | FCS |
558 +-------------------------------+
559 */
560
561 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
562
563 /*
564 * L2 (Octet 2)- Message Types definition 1 byte long.
565 */
566 /* Call Establish */
567 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
568 #define MSG_TYPE_ALERT 0x01
569 #define MSG_TYPE_CALL_PROCEEDING 0x02
570 #define MSG_TYPE_CONNECT 0x07
571 #define MSG_TYPE_CONNECT_ACK 0x0F
572 #define MSG_TYPE_PROGRESS 0x03
573 #define MSG_TYPE_SETUP 0x05
574 /* Call Clear */
575 #define MSG_TYPE_DISCONNECT 0x45
576 #define MSG_TYPE_RELEASE 0x4D
577 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
578 #define MSG_TYPE_RESTART 0x46
579 #define MSG_TYPE_RESTART_ACK 0x4E
580 /* Status */
581 #define MSG_TYPE_STATUS 0x7D
582 #define MSG_TYPE_STATUS_ENQ 0x75
583
584 struct tok fr_q933_msg_values[] = {
585 { MSG_TYPE_ESC_TO_NATIONAL, "ESC to National" },
586 { MSG_TYPE_ALERT, "Alert" },
587 { MSG_TYPE_CALL_PROCEEDING, "Call proceeding" },
588 { MSG_TYPE_CONNECT, "Connect" },
589 { MSG_TYPE_CONNECT_ACK, "Connect ACK" },
590 { MSG_TYPE_PROGRESS, "Progress" },
591 { MSG_TYPE_SETUP, "Setup" },
592 { MSG_TYPE_DISCONNECT, "Disconnect" },
593 { MSG_TYPE_RELEASE, "Release" },
594 { MSG_TYPE_RELEASE_COMPLETE, "Release Complete" },
595 { MSG_TYPE_RESTART, "Restart" },
596 { MSG_TYPE_RESTART_ACK, "Restart ACK" },
597 { MSG_TYPE_STATUS, "Status Reply" },
598 { MSG_TYPE_STATUS_ENQ, "Status Enquiry" },
599 { 0, NULL }
600 };
601
602 #define MSG_ANSI_LOCKING_SHIFT 0x95
603
604 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
605 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
606 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
607 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
608
609 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
610 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
611 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
612
613 struct tok fr_q933_ie_values_codeset5[] = {
614 { FR_LMI_ANSI_REPORT_TYPE_IE, "ANSI Report Type" },
615 { FR_LMI_ANSI_LINK_VERIFY_IE_91, "ANSI Link Verify" },
616 { FR_LMI_ANSI_LINK_VERIFY_IE, "ANSI Link Verify" },
617 { FR_LMI_ANSI_PVC_STATUS_IE, "ANSI PVC Status" },
618 { FR_LMI_CCITT_REPORT_TYPE_IE, "CCITT Report Type" },
619 { FR_LMI_CCITT_LINK_VERIFY_IE, "CCITT Link Verify" },
620 { FR_LMI_CCITT_PVC_STATUS_IE, "CCITT PVC Status" },
621 { 0, NULL }
622 };
623
624 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
625 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
626 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
627
628 struct tok fr_lmi_report_type_ie_values[] = {
629 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS, "Full Status" },
630 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY, "Link verify" },
631 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC, "Async PVC Status" },
632 { 0, NULL }
633 };
634
635 /* array of 16 codepages - currently we only support codepage 1,5 */
636 static struct tok *fr_q933_ie_codesets[] = {
637 NULL,
638 fr_q933_ie_values_codeset5,
639 NULL,
640 NULL,
641 NULL,
642 fr_q933_ie_values_codeset5,
643 NULL,
644 NULL,
645 NULL,
646 NULL,
647 NULL,
648 NULL,
649 NULL,
650 NULL,
651 NULL,
652 NULL
653 };
654
655 static int fr_q933_print_ie_codeset5(const struct ie_tlv_header_t *ie_p,
656 const u_char *p);
657
658 typedef int (*codeset_pr_func_t)(const struct ie_tlv_header_t *ie_p,
659 const u_char *p);
660
661 /* array of 16 codepages - currently we only support codepage 1,5 */
662 static codeset_pr_func_t fr_q933_print_ie_codeset[] = {
663 NULL,
664 fr_q933_print_ie_codeset5,
665 NULL,
666 NULL,
667 NULL,
668 fr_q933_print_ie_codeset5,
669 NULL,
670 NULL,
671 NULL,
672 NULL,
673 NULL,
674 NULL,
675 NULL,
676 NULL,
677 NULL,
678 NULL
679 };
680
681 void
682 q933_print(const u_char *p, u_int length)
683 {
684 const u_char *ptemp = p;
685 struct ie_tlv_header_t *ie_p;
686 int olen;
687 int is_ansi = 0;
688 u_int codeset;
689 u_int ie_is_known = 0;
690
691 if (length < 9) { /* shortest: Q.933a LINK VERIFY */
692 printf("[|q.933]");
693 return;
694 }
695
696 codeset = p[2]&0x0f; /* extract the codeset */
697
698 if (p[2] == MSG_ANSI_LOCKING_SHIFT)
699 is_ansi = 1;
700
701 printf("%s", eflag ? "" : "Q.933, ");
702
703 /* printing out header part */
704 printf("%s, codeset %u", is_ansi ? "ANSI" : "CCITT", codeset);
705
706 if (p[0])
707 printf(", Call Ref: 0x%02x", p[0]);
708
709 if (vflag)
710 printf(", %s (0x%02x), length %u",
711 tok2str(fr_q933_msg_values,"unknown message",p[1]),
712 p[1],
713 length);
714 else
715 printf(", %s",
716 tok2str(fr_q933_msg_values,"unknown message 0x%02x",p[1]));
717
718 olen = length; /* preserve the original length for non verbose mode */
719
720 if (length < (u_int)(2 - is_ansi)) {
721 printf("[|q.933]");
722 return;
723 }
724 length -= 2 - is_ansi;
725 ptemp += 2 + is_ansi;
726
727 /* Loop through the rest of IE */
728 while (length > sizeof(struct ie_tlv_header_t )) {
729 ie_p = (struct ie_tlv_header_t *)ptemp;
730 if (length < sizeof(struct ie_tlv_header_t ) ||
731 length < sizeof(struct ie_tlv_header_t ) + ie_p->ie_len) {
732 if (vflag) /* not bark if there is just a trailer */
733 printf("\n[|q.933]");
734 else
735 printf(", length %u",olen);
736 return;
737 }
738
739 /* lets do the full IE parsing only in verbose mode
740 * however some IEs (DLCI Status, Link Verify)
741 * are also intereststing in non-verbose mode */
742 if (vflag)
743 printf("\n\t%s IE (0x%02x), length %u: ",
744 tok2str(fr_q933_ie_codesets[codeset],"unknown",ie_p->ie_type),
745 ie_p->ie_type,
746 ie_p->ie_len);
747
748 /* sanity check */
749 if (ie_p->ie_type == 0 || ie_p->ie_len == 0)
750 return;
751
752 if (fr_q933_print_ie_codeset[codeset] != NULL)
753 ie_is_known = fr_q933_print_ie_codeset[codeset](ie_p, ptemp);
754
755 if (vflag >= 1 && !ie_is_known)
756 print_unknown_data(ptemp+2,"\n\t",ie_p->ie_len);
757
758 /* do we want to see a hexdump of the IE ? */
759 if (vflag> 1 && ie_is_known)
760 print_unknown_data(ptemp+2,"\n\t ",ie_p->ie_len);
761
762 length = length - ie_p->ie_len - 2;
763 ptemp = ptemp + ie_p->ie_len + 2;
764 }
765 if (!vflag)
766 printf(", length %u",olen);
767 }
768
769 static int
770 fr_q933_print_ie_codeset5(const struct ie_tlv_header_t *ie_p, const u_char *p)
771 {
772 u_int dlci;
773
774 switch (ie_p->ie_type) {
775
776 case FR_LMI_ANSI_REPORT_TYPE_IE: /* fall through */
777 case FR_LMI_CCITT_REPORT_TYPE_IE:
778 if (vflag)
779 printf("%s (%u)",
780 tok2str(fr_lmi_report_type_ie_values,"unknown",p[2]),
781 p[2]);
782 return 1;
783
784 case FR_LMI_ANSI_LINK_VERIFY_IE: /* fall through */
785 case FR_LMI_CCITT_LINK_VERIFY_IE:
786 case FR_LMI_ANSI_LINK_VERIFY_IE_91:
787 if (!vflag)
788 printf(", ");
789 printf("TX Seq: %3d, RX Seq: %3d", p[2], p[3]);
790 return 1;
791
792 case FR_LMI_ANSI_PVC_STATUS_IE: /* fall through */
793 case FR_LMI_CCITT_PVC_STATUS_IE:
794 if (!vflag)
795 printf(", ");
796 /* now parse the DLCI information element. */
797 if ((ie_p->ie_len < 3) ||
798 (p[2] & 0x80) ||
799 ((ie_p->ie_len == 3) && !(p[3] & 0x80)) ||
800 ((ie_p->ie_len == 4) && ((p[3] & 0x80) || !(p[4] & 0x80))) ||
801 ((ie_p->ie_len == 5) && ((p[3] & 0x80) || (p[4] & 0x80) ||
802 !(p[5] & 0x80))) ||
803 (ie_p->ie_len > 5) ||
804 !(p[ie_p->ie_len + 1] & 0x80))
805 printf("Invalid DLCI IE");
806
807 dlci = ((p[2] & 0x3F) << 4) | ((p[3] & 0x78) >> 3);
808 if (ie_p->ie_len == 4)
809 dlci = (dlci << 6) | ((p[4] & 0x7E) >> 1);
810 else if (ie_p->ie_len == 5)
811 dlci = (dlci << 13) | (p[4] & 0x7F) | ((p[5] & 0x7E) >> 1);
812
813 printf("DLCI %u: status %s%s", dlci,
814 p[ie_p->ie_len + 1] & 0x8 ? "New, " : "",
815 p[ie_p->ie_len + 1] & 0x2 ? "Active" : "Inactive");
816 return 1;
817 }
818
819 return 0;
820 }