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.
26 "@(#)$Header: /home/ncvs/src/contrib/tcpdump/print-fr.c,v 1.1 1997/12/31 21:50:31 pst Exp $ (LBL)";
30 #include <sys/param.h>
32 #include <sys/socket.h>
34 #include <sys/ioctl.h>
41 #include <net/if_var.h>
43 #include <netinet/in.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
53 #include <netinet/if_ether.h>
54 #include "ethertype.h"
56 #include <net/ppp_defs.h>
57 #include "interface.h"
58 #include "addrtoname.h"
63 #define FR_EA_BIT(p) ((p)&0x1)
64 #define FR_DLCI(b0,b1) ((((b0)&0xFC)<<2)+(((b1)&0xF0)>>4))
71 /* find out how many bytes are there in a frame */
73 fr_addr_len(const u_char *p)
77 while (!FR_EA_BIT(p[i]) && i++ && !FR_EA_BIT(p[i+1])) i++;
81 /* the following is for framerelay */
82 #define NLPID_LEN 1 /* NLPID is one byte long */
83 #define NLPID_Q933 0x08
84 #define NLPID_CLNP 0x81
85 #define NLPID_ESIS 0x82
86 #define NLPID_ISIS 0x83
87 #define NLPID_CONS 0x84
88 #define NLPID_IDRP 0x85
89 #define NLPID_X25_ESIS 0x8a
93 static struct fr_nlpids fr_nlpids[256];
94 static fr_nlpid_flag =0;
100 if (!fr_nlpid_flag) {
101 for (i=0; i < 256; i++) {
103 fr_nlpids[i].name = "Not Specified";
105 fr_nlpids[NLPID_Q933].name = "Q.933";
106 fr_nlpids[NLPID_CLNP].name = "CLNP";
107 fr_nlpids[NLPID_ESIS].name = "ESIS";
108 fr_nlpids[NLPID_ISIS].name = "ISIS";
109 fr_nlpids[NLPID_CONS].name = "CONS";
110 fr_nlpids[NLPID_IDRP].name = "IDRP";
111 fr_nlpids[NLPID_X25_ESIS].name = "X25_ESIS";
112 fr_nlpids[NLPID_IP].name = "IP";
117 /* Framerelay packet structure */
120 +---------------------------+
121 | flag (7E hexadecimal) |
122 +---------------------------+
126 +---------------------------+
127 | Control (UI = 0x03) |
128 +---------------------------+
129 | Optional Pad (0x00) |
130 +---------------------------+
132 +---------------------------+
139 +---------------------------+
140 | Frame Check Sequence |
143 +---------------------------+
144 | flag (7E hexadecimal) |
145 +---------------------------+
147 * Q.922 addresses, as presently defined, are two octets and
148 contain a 10-bit DLCI. In some networks Q.922 addresses
149 may optionally be increased to three or four octets.
153 #define FR_PROTOCOL(p) fr_protocol((p))
156 fr_hdrlen(const u_char *p)
159 hlen = fr_addr_len(p)+1; /* addr_len + 0x03 + padding */
166 #define LAYER2_LEN(p) (fr_hdrlen((p))+NLPID_LEN)
169 fr_protocol(const u_char *p)
173 hlen = fr_addr_len(p) + 1;
174 if (p[hlen]) /* check for padding */
181 fr_hdlc_print(const u_char *p, int length)
187 proto = FR_PROTOCOL(p);
190 /* this is kinda kludge since it assumed that DLCI is two bytes. */
191 printf("%4d %02x%02x=DLCI(%d) ", length, p[0], p[1], FR_DLCI(p[0],p[1]));
192 printf("%02x %6s: ", proto, fr_nlpids[proto].name);
198 fr_if_print(u_char *user, const struct pcap_pkthdr *h,
199 register const u_char *p)
201 register u_int length = h->len;
202 register u_int caplen = h->caplen;
204 proto = FR_PROTOCOL(p);
209 if (caplen < fr_hdrlen(p)) {
215 * Some printers want to get back at the link level addresses,
216 * and/or check that they're not walking off the end of the packet.
217 * Rather than pass them all the way down, we set these globals.
220 snapend = p + caplen;
223 fr_hdlc_print(p, length);
225 length = length - (fr_hdrlen(p) + NLPID_LEN);
228 switch(FR_PROTOCOL(p)) {
231 ip_print((const u_char *)(p + LAYER2_LEN(p)), length);
236 isoclns_print((const u_char *)(p + LAYER2_LEN(p)), length,
237 caplen, "000000", "000000");
240 q933_print((const u_char *)(p + LAYER2_LEN(p)), length);
244 fr_hdlc_print(p, length);
246 default_print((const u_char *)(p + LAYER2_LEN(p)),
247 caplen - LAYER2_LEN(p));
251 default_print((const u_char *)(p + LAYER2_LEN(p)),
252 caplen - LAYER2_LEN(p));
257 #include <sys/types.h>
258 #include <sys/time.h>
262 #include "interface.h"
264 fr_if_print(const struct pcap_pkthdr *h, const u_char *p)
266 error("not configured for ppp");
272 * Q.933 decoding portion for framerelay specific.
275 /* Q.933 packet format
276 Format of Other Protocols
278 +-------------------------------+
280 +---------------+---------------+
281 |Control 0x03 | NLPID 0x08 |
282 +---------------+---------------+
284 | octet 1 | octet 2 |
285 +-------------------------------+
287 | octet 2 | octet 2 |
288 +-------------------------------+
290 +-------------------------------+
292 +-------------------------------+
295 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
298 * L2 (Octet 2)- Message Types definition 1 byte long.
301 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
302 #define MSG_TYPE_ALERT 0x01
303 #define MSG_TYPE_CALL_PROCEEDING 0x02
304 #define MSG_TYPE_CONNECT 0x07
305 #define MSG_TYPE_CONNECT_ACK 0x0F
306 #define MSG_TYPE_PROGRESS 0x03
307 #define MSG_TYPE_SETUP 0x05
309 #define MSG_TYPE_DISCONNECT 0x45
310 #define MSG_TYPE_RELEASE 0x4D
311 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
312 #define MSG_TYPE_RESTART 0x46
313 #define MSG_TYPE_RESTART_ACK 0x4E
315 #define MSG_TYPE_STATUS 0x7D
316 #define MSG_TYPE_STATUS_ENQ 0x75
318 #define ONE_BYTE_IE_MASK 0xF0
320 /* See L2 protocol ID picture above */
322 u_char call_ref; /* usually is 0 for framerelay PVC */
326 #define REPORT_TYPE_IE 0x01
327 #define LINK_VERIFY_IE_91 0x19
328 #define LINK_VERIFY_IE_94 0x03
329 #define PVC_STATUS_IE 0x07
333 struct common_ie_header {
338 #define FULL_STATUS 0
339 #define LINK_VERIFY 1
344 q933_print(const u_char *p, int length)
346 struct q933_header *header = (struct q933_header *)(p+1);
347 const u_char *ptemp = p;
349 char *decode_str, temp_str[255];
350 struct common_ie_header *ie_p;
353 /* printing out header part */
354 printf("Call Ref: %02x, MSG Type: %02x",
355 header->call_ref, header->msg_type);
356 switch(header->msg_type) {
357 case MSG_TYPE_STATUS:
358 decode_str = "STATUS REPLY";
360 case MSG_TYPE_STATUS_ENQ:
361 decode_str = "STATUS ENQUIRY";
364 decode_str = "UNKNOWN MSG Type";
366 printf(" %s\n", decode_str);
371 /* Loop through the rest of IE */
372 while( length > 0 ) {
373 if( ptemp[0] & ONE_BYTE_IE_MASK ) {
375 printf("\t\tOne byte IE: %02x, Content %02x\n",
376 (*ptemp & 0x70)>>4, (*ptemp & 0x0F));
380 else { /* Multi-byte IE */
381 ie_p = (struct common_ie_header *)ptemp;
382 switch (ie_p->ie_id) {
386 decode_str = "FULL STATUS";
389 decode_str = "LINK VERIFY";
392 decode_str = "Async PVC Status";
395 decode_str = "Reserved Value";
398 case LINK_VERIFY_IE_91:
399 case LINK_VERIFY_IE_94:
400 snprintf(temp_str, sizeof(temp_str), "TX Seq: %3d, RX Seq: %3d",
402 decode_str = temp_str;
405 snprintf(temp_str,sizeof(temp_str), "DLCI %d: status %s %s",
406 ((ptemp[2]&0x3f)<<4)+ ((ptemp[3]&0x78)>>3),
407 ptemp[4] & 0x8 ?"new,":" ",
408 ptemp[4] & 0x2 ?"Active":"Inactive");
411 decode_str = "Non-decoded Value";
413 printf("\t\tIE: %02X Len: %d, %s\n",
414 ie_p->ie_id, ie_p->ie_len, decode_str);
415 length = length - ie_p->ie_len - 2;
416 ptemp = ptemp + ie_p->ie_len + 2;