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