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