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