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