2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
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
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.
24 "@(#)$Header: /home/ncvs/src/contrib/tcpdump/print-fr.c,v 1.1 1997/12/31 21:50:31 pst Exp $ (LBL)";
28 #include <sys/param.h>
30 #include <sys/socket.h>
32 #include <sys/ioctl.h>
39 #include <net/if_var.h>
41 #include <netinet/in.h>
42 #include <netinet/in_systm.h>
43 #include <netinet/ip.h>
51 #include <netinet/if_ether.h>
52 #include "ethertype.h"
54 #include <net/ppp_defs.h>
55 #include "interface.h"
56 #include "addrtoname.h"
61 #define FR_EA_BIT(p) ((p)&0x1)
62 #define FR_DLCI(b0,b1) ((((b0)&0xFC)<<2)+(((b1)&0xF0)>>4))
69 /* find out how many bytes are there in a frame */
71 fr_addr_len(const u_char *p)
75 while (!FR_EA_BIT(p[i]) && i++ && !FR_EA_BIT(p[i+1])) i++;
79 /* the following is for framerelay */
80 #define NLPID_LEN 1 /* NLPID is one byte long */
81 #define NLPID_Q933 0x08
82 #define NLPID_CLNP 0x81
83 #define NLPID_ESIS 0x82
84 #define NLPID_ISIS 0x83
85 #define NLPID_CONS 0x84
86 #define NLPID_IDRP 0x85
87 #define NLPID_X25_ESIS 0x8a
91 static struct fr_nlpids fr_nlpids[256];
92 static fr_nlpid_flag =0;
99 for (i=0; i < 256; i++) {
101 fr_nlpids[i].name = "Not Specified";
103 fr_nlpids[NLPID_Q933].name = "Q.933";
104 fr_nlpids[NLPID_CLNP].name = "CLNP";
105 fr_nlpids[NLPID_ESIS].name = "ESIS";
106 fr_nlpids[NLPID_ISIS].name = "ISIS";
107 fr_nlpids[NLPID_CONS].name = "CONS";
108 fr_nlpids[NLPID_IDRP].name = "IDRP";
109 fr_nlpids[NLPID_X25_ESIS].name = "X25_ESIS";
110 fr_nlpids[NLPID_IP].name = "IP";
115 /* Framerelay packet structure */
118 +---------------------------+
119 | flag (7E hexadecimal) |
120 +---------------------------+
124 +---------------------------+
125 | Control (UI = 0x03) |
126 +---------------------------+
127 | Optional Pad (0x00) |
128 +---------------------------+
130 +---------------------------+
137 +---------------------------+
138 | Frame Check Sequence |
141 +---------------------------+
142 | flag (7E hexadecimal) |
143 +---------------------------+
145 * Q.922 addresses, as presently defined, are two octets and
146 contain a 10-bit DLCI. In some networks Q.922 addresses
147 may optionally be increased to three or four octets.
151 #define FR_PROTOCOL(p) fr_protocol((p))
154 fr_hdrlen(const u_char *p)
157 hlen = fr_addr_len(p)+1; /* addr_len + 0x03 + padding */
164 #define LAYER2_LEN(p) (fr_hdrlen((p))+NLPID_LEN)
167 fr_protocol(const u_char *p)
171 hlen = fr_addr_len(p) + 1;
172 if (p[hlen]) /* check for padding */
179 fr_hdlc_print(const u_char *p, int length)
185 proto = FR_PROTOCOL(p);
188 /* this is kinda kludge since it assumed that DLCI is two bytes. */
189 printf("%4d %02x%02x=DLCI(%d) ", length, p[0], p[1], FR_DLCI(p[0],p[1]));
190 printf("%02x %6s: ", proto, fr_nlpids[proto].name);
196 fr_if_print(u_char *user, const struct pcap_pkthdr *h,
197 register const u_char *p)
199 register u_int length = h->len;
200 register u_int caplen = h->caplen;
202 proto = FR_PROTOCOL(p);
207 if (caplen < fr_hdrlen(p)) {
213 * Some printers want to get back at the link level addresses,
214 * and/or check that they're not walking off the end of the packet.
215 * Rather than pass them all the way down, we set these globals.
218 snapend = p + caplen;
221 fr_hdlc_print(p, length);
223 length = length - (fr_hdrlen(p) + NLPID_LEN);
226 switch(FR_PROTOCOL(p)) {
229 ip_print((const u_char *)(p + LAYER2_LEN(p)), length);
234 isoclns_print((const u_char *)(p + LAYER2_LEN(p)), length,
235 caplen, "000000", "000000");
238 q933_print((const u_char *)(p + LAYER2_LEN(p)), length);
242 fr_hdlc_print(p, length);
244 default_print((const u_char *)(p + LAYER2_LEN(p)),
245 caplen - LAYER2_LEN(p));
249 default_print((const u_char *)(p + LAYER2_LEN(p)),
250 caplen - LAYER2_LEN(p));
255 #include <sys/types.h>
256 #include <sys/time.h>
260 #include "interface.h"
262 fr_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
264 error("not configured for ppp");
270 * Q.933 decoding portion for framerelay specific.
273 /* Q.933 packet format
274 Format of Other Protocols
276 +-------------------------------+
278 +---------------+---------------+
279 |Control 0x03 | NLPID 0x08 |
280 +---------------+---------------+
282 | octet 1 | octet 2 |
283 +-------------------------------+
285 | octet 2 | octet 2 |
286 +-------------------------------+
288 +-------------------------------+
290 +-------------------------------+
293 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
296 * L2 (Octet 2)- Message Types definition 1 byte long.
299 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
300 #define MSG_TYPE_ALERT 0x01
301 #define MSG_TYPE_CALL_PROCEEDING 0x02
302 #define MSG_TYPE_CONNECT 0x07
303 #define MSG_TYPE_CONNECT_ACK 0x0F
304 #define MSG_TYPE_PROGRESS 0x03
305 #define MSG_TYPE_SETUP 0x05
307 #define MSG_TYPE_DISCONNECT 0x45
308 #define MSG_TYPE_RELEASE 0x4D
309 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
310 #define MSG_TYPE_RESTART 0x46
311 #define MSG_TYPE_RESTART_ACK 0x4E
313 #define MSG_TYPE_STATUS 0x7D
314 #define MSG_TYPE_STATUS_ENQ 0x75
316 #define ONE_BYTE_IE_MASK 0xF0
318 /* See L2 protocol ID picture above */
320 u_char call_ref; /* usually is 0 for framerelay PVC */
324 #define REPORT_TYPE_IE 0x01
325 #define LINK_VERIFY_IE_91 0x19
326 #define LINK_VERIFY_IE_94 0x03
327 #define PVC_STATUS_IE 0x07
331 struct common_ie_header {
336 #define FULL_STATUS 0
337 #define LINK_VERIFY 1
342 q933_print(const u_char *p, int length)
344 struct q933_header *header = (struct q933_header *)(p+1);
345 const u_char *ptemp = p;
347 char *decode_str, temp_str[255];
348 struct common_ie_header *ie_p;
351 /* printing out header part */
352 printf("Call Ref: %02x, MSG Type: %02x",
353 header->call_ref, header->msg_type);
354 switch(header->msg_type) {
355 case MSG_TYPE_STATUS:
356 decode_str = "STATUS REPLY";
358 case MSG_TYPE_STATUS_ENQ:
359 decode_str = "STATUS ENQUIRY";
362 decode_str = "UNKNOWN MSG Type";
364 printf(" %s\n", decode_str);
369 /* Loop through the rest of IE */
370 while( length > 0 ) {
371 if( ptemp[0] & ONE_BYTE_IE_MASK ) {
373 printf("\t\tOne byte IE: %02x, Content %02x\n",
374 (*ptemp & 0x70)>>4, (*ptemp & 0x0F));
378 else { /* Multi-byte IE */
379 ie_p = (struct common_ie_header *)ptemp;
380 switch (ie_p->ie_id) {
384 decode_str = "FULL STATUS";
387 decode_str = "LINK VERIFY";
390 decode_str = "Async PVC Status";
393 decode_str = "Reserved Value";
396 case LINK_VERIFY_IE_91:
397 case LINK_VERIFY_IE_94:
398 sprintf(temp_str,"TX Seq: %3d, RX Seq: %3d",
400 decode_str = temp_str;
403 sprintf(temp_str,"DLCI %d: status %s %s",
404 ((ptemp[2]&0x3f)<<4)+ ((ptemp[3]&0x78)>>3),
405 ptemp[4] & 0x8 ?"new,":" ",
406 ptemp[4] & 0x2 ?"Active":"Inactive");
409 decode_str = "Non-decoded Value";
411 printf("\t\tIE: %02X Len: %d, %s\n",
412 ie_p->ie_id, ie_p->ie_len, decode_str);
413 length = length - ie_p->ie_len - 2;
414 ptemp = ptemp + ie_p->ie_len + 2;