]> The Tcpdump Group git mirrors - tcpdump/blob - print-fr.c
Squelch a Coverity 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 #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 flags = p[0]&MFR_BEC_MASK;
600 sequence_num = (p[0]&0x1e)<<7 | p[1];
601
602 ND_PRINT((ndo, "FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
603 sequence_num,
604 bittok2str(frf_flag_values,"none",flags),
605 p[0]&FR_FRF15_FRAGTYPE ? "Interface" : "End-to-End",
606 length));
607
608 /* TODO:
609 * depending on all permutations of the B, E and C bit
610 * dig as deep as we can - e.g. on the first (B) fragment
611 * there is enough payload to print the IP header
612 * on non (B) fragments it depends if the fragmentation
613 * model is end-to-end or interface based wether we want to print
614 * another Q.922 header
615 */
616
617 }
618
619 /*
620 * Q.933 decoding portion for framerelay specific.
621 */
622
623 /* Q.933 packet format
624 Format of Other Protocols
625 using Q.933 NLPID
626 +-------------------------------+
627 | Q.922 Address |
628 +---------------+---------------+
629 |Control 0x03 | NLPID 0x08 |
630 +---------------+---------------+
631 | L2 Protocol ID |
632 | octet 1 | octet 2 |
633 +-------------------------------+
634 | L3 Protocol ID |
635 | octet 2 | octet 2 |
636 +-------------------------------+
637 | Protocol Data |
638 +-------------------------------+
639 | FCS |
640 +-------------------------------+
641 */
642
643 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
644
645 /*
646 * L2 (Octet 2)- Message Types definition 1 byte long.
647 */
648 /* Call Establish */
649 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
650 #define MSG_TYPE_ALERT 0x01
651 #define MSG_TYPE_CALL_PROCEEDING 0x02
652 #define MSG_TYPE_CONNECT 0x07
653 #define MSG_TYPE_CONNECT_ACK 0x0F
654 #define MSG_TYPE_PROGRESS 0x03
655 #define MSG_TYPE_SETUP 0x05
656 /* Call Clear */
657 #define MSG_TYPE_DISCONNECT 0x45
658 #define MSG_TYPE_RELEASE 0x4D
659 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
660 #define MSG_TYPE_RESTART 0x46
661 #define MSG_TYPE_RESTART_ACK 0x4E
662 /* Status */
663 #define MSG_TYPE_STATUS 0x7D
664 #define MSG_TYPE_STATUS_ENQ 0x75
665
666 static const struct tok fr_q933_msg_values[] = {
667 { MSG_TYPE_ESC_TO_NATIONAL, "ESC to National" },
668 { MSG_TYPE_ALERT, "Alert" },
669 { MSG_TYPE_CALL_PROCEEDING, "Call proceeding" },
670 { MSG_TYPE_CONNECT, "Connect" },
671 { MSG_TYPE_CONNECT_ACK, "Connect ACK" },
672 { MSG_TYPE_PROGRESS, "Progress" },
673 { MSG_TYPE_SETUP, "Setup" },
674 { MSG_TYPE_DISCONNECT, "Disconnect" },
675 { MSG_TYPE_RELEASE, "Release" },
676 { MSG_TYPE_RELEASE_COMPLETE, "Release Complete" },
677 { MSG_TYPE_RESTART, "Restart" },
678 { MSG_TYPE_RESTART_ACK, "Restart ACK" },
679 { MSG_TYPE_STATUS, "Status Reply" },
680 { MSG_TYPE_STATUS_ENQ, "Status Enquiry" },
681 { 0, NULL }
682 };
683
684 #define MSG_ANSI_LOCKING_SHIFT 0x95
685
686 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
687 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
688 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
689 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
690
691 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
692 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
693 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
694
695 static const struct tok fr_q933_ie_values_codeset5[] = {
696 { FR_LMI_ANSI_REPORT_TYPE_IE, "ANSI Report Type" },
697 { FR_LMI_ANSI_LINK_VERIFY_IE_91, "ANSI Link Verify" },
698 { FR_LMI_ANSI_LINK_VERIFY_IE, "ANSI Link Verify" },
699 { FR_LMI_ANSI_PVC_STATUS_IE, "ANSI PVC Status" },
700 { FR_LMI_CCITT_REPORT_TYPE_IE, "CCITT Report Type" },
701 { FR_LMI_CCITT_LINK_VERIFY_IE, "CCITT Link Verify" },
702 { FR_LMI_CCITT_PVC_STATUS_IE, "CCITT PVC Status" },
703 { 0, NULL }
704 };
705
706 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
707 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
708 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
709
710 static const struct tok fr_lmi_report_type_ie_values[] = {
711 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS, "Full Status" },
712 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY, "Link verify" },
713 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC, "Async PVC Status" },
714 { 0, NULL }
715 };
716
717 /* array of 16 codepages - currently we only support codepage 1,5 */
718 static const struct tok *fr_q933_ie_codesets[] = {
719 NULL,
720 fr_q933_ie_values_codeset5,
721 NULL,
722 NULL,
723 NULL,
724 fr_q933_ie_values_codeset5,
725 NULL,
726 NULL,
727 NULL,
728 NULL,
729 NULL,
730 NULL,
731 NULL,
732 NULL,
733 NULL,
734 NULL
735 };
736
737 static int fr_q933_print_ie_codeset5(netdissect_options *ndo,
738 const struct ie_tlv_header_t *ie_p, const u_char *p);
739
740 typedef int (*codeset_pr_func_t)(netdissect_options *,
741 const struct ie_tlv_header_t *ie_p, const u_char *p);
742
743 /* array of 16 codepages - currently we only support codepage 1,5 */
744 static const codeset_pr_func_t fr_q933_print_ie_codeset[] = {
745 NULL,
746 fr_q933_print_ie_codeset5,
747 NULL,
748 NULL,
749 NULL,
750 fr_q933_print_ie_codeset5,
751 NULL,
752 NULL,
753 NULL,
754 NULL,
755 NULL,
756 NULL,
757 NULL,
758 NULL,
759 NULL,
760 NULL
761 };
762
763 void
764 q933_print(netdissect_options *ndo,
765 const u_char *p, u_int length)
766 {
767 const u_char *ptemp = p;
768 const struct ie_tlv_header_t *ie_p;
769 int olen;
770 int is_ansi = 0;
771 u_int codeset;
772 u_int ie_is_known = 0;
773
774 if (length < 9) { /* shortest: Q.933a LINK VERIFY */
775 ND_PRINT((ndo, "[|q.933]"));
776 return;
777 }
778
779 codeset = p[2]&0x0f; /* extract the codeset */
780
781 if (p[2] == MSG_ANSI_LOCKING_SHIFT) {
782 is_ansi = 1;
783 }
784
785 ND_PRINT((ndo, "%s", ndo->ndo_eflag ? "" : "Q.933, "));
786
787 /* printing out header part */
788 ND_PRINT((ndo, "%s, codeset %u", is_ansi ? "ANSI" : "CCITT", codeset));
789
790 if (p[0]) {
791 ND_PRINT((ndo, ", Call Ref: 0x%02x", p[0]));
792 }
793 if (ndo->ndo_vflag) {
794 ND_PRINT((ndo, ", %s (0x%02x), length %u",
795 tok2str(fr_q933_msg_values,
796 "unknown message", p[1]),
797 p[1],
798 length));
799 } else {
800 ND_PRINT((ndo, ", %s",
801 tok2str(fr_q933_msg_values,
802 "unknown message 0x%02x", p[1])));
803 }
804
805 olen = length; /* preserve the original length for non verbose mode */
806
807 if (length < (u_int)(2 - is_ansi)) {
808 ND_PRINT((ndo, "[|q.933]"));
809 return;
810 }
811 length -= 2 + is_ansi;
812 ptemp += 2 + is_ansi;
813
814 /* Loop through the rest of IE */
815 while (length > sizeof(struct ie_tlv_header_t)) {
816 ie_p = (const struct ie_tlv_header_t *)ptemp;
817 if (length < sizeof(struct ie_tlv_header_t) ||
818 length < sizeof(struct ie_tlv_header_t) + ie_p->ie_len) {
819 if (ndo->ndo_vflag) { /* not bark if there is just a trailer */
820 ND_PRINT((ndo, "\n[|q.933]"));
821 } else {
822 ND_PRINT((ndo, ", length %u", olen));
823 }
824 return;
825 }
826
827 /* lets do the full IE parsing only in verbose mode
828 * however some IEs (DLCI Status, Link Verify)
829 * are also interestting in non-verbose mode */
830 if (ndo->ndo_vflag) {
831 ND_PRINT((ndo, "\n\t%s IE (0x%02x), length %u: ",
832 tok2str(fr_q933_ie_codesets[codeset],
833 "unknown", ie_p->ie_type),
834 ie_p->ie_type,
835 ie_p->ie_len));
836 }
837
838 /* sanity check */
839 if (ie_p->ie_type == 0 || ie_p->ie_len == 0) {
840 return;
841 }
842
843 if (fr_q933_print_ie_codeset[codeset] != NULL) {
844 ie_is_known = fr_q933_print_ie_codeset[codeset](ndo, ie_p, ptemp);
845 }
846
847 if (ndo->ndo_vflag >= 1 && !ie_is_known) {
848 print_unknown_data(ndo, ptemp+2, "\n\t", ie_p->ie_len);
849 }
850
851 /* do we want to see a hexdump of the IE ? */
852 if (ndo->ndo_vflag> 1 && ie_is_known) {
853 print_unknown_data(ndo, ptemp+2, "\n\t ", ie_p->ie_len);
854 }
855
856 length = length - ie_p->ie_len - 2;
857 ptemp = ptemp + ie_p->ie_len + 2;
858 }
859 if (!ndo->ndo_vflag) {
860 ND_PRINT((ndo, ", length %u", olen));
861 }
862 }
863
864 static int
865 fr_q933_print_ie_codeset5(netdissect_options *ndo,
866 const struct ie_tlv_header_t *ie_p, const u_char *p)
867 {
868 u_int dlci;
869
870 switch (ie_p->ie_type) {
871
872 case FR_LMI_ANSI_REPORT_TYPE_IE: /* fall through */
873 case FR_LMI_CCITT_REPORT_TYPE_IE:
874 if (ndo->ndo_vflag) {
875 ND_PRINT((ndo, "%s (%u)",
876 tok2str(fr_lmi_report_type_ie_values,"unknown",p[2]),
877 p[2]));
878 }
879 return 1;
880
881 case FR_LMI_ANSI_LINK_VERIFY_IE: /* fall through */
882 case FR_LMI_CCITT_LINK_VERIFY_IE:
883 case FR_LMI_ANSI_LINK_VERIFY_IE_91:
884 if (!ndo->ndo_vflag) {
885 ND_PRINT((ndo, ", "));
886 }
887 ND_PRINT((ndo, "TX Seq: %3d, RX Seq: %3d", p[2], p[3]));
888 return 1;
889
890 case FR_LMI_ANSI_PVC_STATUS_IE: /* fall through */
891 case FR_LMI_CCITT_PVC_STATUS_IE:
892 if (!ndo->ndo_vflag) {
893 ND_PRINT((ndo, ", "));
894 }
895 /* now parse the DLCI information element. */
896 if ((ie_p->ie_len < 3) ||
897 (p[2] & 0x80) ||
898 ((ie_p->ie_len == 3) && !(p[3] & 0x80)) ||
899 ((ie_p->ie_len == 4) && ((p[3] & 0x80) || !(p[4] & 0x80))) ||
900 ((ie_p->ie_len == 5) && ((p[3] & 0x80) || (p[4] & 0x80) ||
901 !(p[5] & 0x80))) ||
902 (ie_p->ie_len > 5) ||
903 !(p[ie_p->ie_len + 1] & 0x80)) {
904 ND_PRINT((ndo, "Invalid DLCI IE"));
905 }
906
907 dlci = ((p[2] & 0x3F) << 4) | ((p[3] & 0x78) >> 3);
908 if (ie_p->ie_len == 4) {
909 dlci = (dlci << 6) | ((p[4] & 0x7E) >> 1);
910 }
911 else if (ie_p->ie_len == 5) {
912 dlci = (dlci << 13) | (p[4] & 0x7F) | ((p[5] & 0x7E) >> 1);
913 }
914
915 ND_PRINT((ndo, "DLCI %u: status %s%s", dlci,
916 p[ie_p->ie_len + 1] & 0x8 ? "New, " : "",
917 p[ie_p->ie_len + 1] & 0x2 ? "Active" : "Inactive"));
918 return 1;
919 }
920
921 return 0;
922 }
923 /*
924 * Local Variables:
925 * c-style: whitesmith
926 * c-basic-offset: 8
927 * End:
928 */