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