|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) University of British Columbia, 1984
27: * Copyright (c) 1990, 1993
28: * The Regents of the University of California. All rights reserved.
29: *
30: * This code is derived from software contributed to Berkeley by
31: * the Laboratory for Computation Vision and the Computer Science Department
32: * of the University of British Columbia.
33: *
34: * Redistribution and use in source and binary forms, with or without
35: * modification, are permitted provided that the following conditions
36: * are met:
37: * 1. Redistributions of source code must retain the above copyright
38: * notice, this list of conditions and the following disclaimer.
39: * 2. Redistributions in binary form must reproduce the above copyright
40: * notice, this list of conditions and the following disclaimer in the
41: * documentation and/or other materials provided with the distribution.
42: * 3. All advertising materials mentioning features or use of this software
43: * must display the following acknowledgement:
44: * This product includes software developed by the University of
45: * California, Berkeley and its contributors.
46: * 4. Neither the name of the University nor the names of its contributors
47: * may be used to endorse or promote products derived from this software
48: * without specific prior written permission.
49: *
50: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60: * SUCH DAMAGE.
61: *
62: * @(#)hd_debug.c 8.1 (Berkeley) 6/10/93
63: */
64:
65: #include <sys/param.h>
66: #include <sys/systm.h>
67: #include <sys/mbuf.h>
68: #include <sys/domain.h>
69: #include <sys/socket.h>
70: #include <sys/protosw.h>
71: #include <sys/errno.h>
72: #include <sys/time.h>
73: #include <sys/kernel.h>
74:
75: #include <net/if.h>
76:
77: #include <netccitt/hdlc.h>
78: #include <netccitt/hd_var.h>
79: #include <netccitt/x25.h>
80:
81: #ifdef HDLCDEBUG
82: #define NTRACE 32
83:
84: struct hdlctrace {
85: struct hdcb *ht_hdp;
86: short ht_dir;
87: struct mbuf *ht_frame;
88: struct timeval ht_time;
89: } hdtrace[NTRACE];
90:
91: int lasttracelogged, freezetrace;
92: #endif
93:
94: hd_trace (hdp, direction, frame)
95: struct hdcb *hdp;
96: register struct Hdlc_frame *frame;
97: {
98: register char *s;
99: register int nr, pf, ns, i;
100: struct Hdlc_iframe *iframe = (struct Hdlc_iframe *) frame;
101:
102: #ifdef HDLCDEBUG
103: hd_savetrace (hdp, direction, frame);
104: #endif
105: if (hdp -> hd_xcp -> xc_ltrace) {
106: if (direction == RX)
107: printf ("F-In: ");
108: else if (direction == 2)
109: printf ("F-Xmt: ");
110: else
111: printf ("F-Out: ");
112:
113: nr = iframe -> nr;
114: pf = iframe -> pf;
115: ns = iframe -> ns;
116:
117: switch (hd_decode (hdp, frame)) {
118: case SABM:
119: printf ("SABM : PF=%d\n", pf);
120: break;
121:
122: case DISC:
123: printf ("DISC : PF=%d\n", pf);
124: break;
125:
126: case DM:
127: printf ("DM : PF=%d\n", pf);
128: break;
129:
130: case FRMR:
131: {
132: register struct Frmr_frame *f = (struct Frmr_frame *)frame;
133:
134: printf ("FRMR : PF=%d, TEXT=", pf);
135: for (s = (char *) frame, i = 0; i < 5; ++i, ++s)
136: printf ("%x ", (int) * s & 0xff);
137: printf ("\n");
138: printf ("control=%x v(s)=%d v(r)=%d w%d x%d y%d z%d\n",
139: f->frmr_control, f->frmr_ns, f->frmr_nr,
140: f->frmr_w, f->frmr_x, f->frmr_y, f->frmr_z);
141: break;
142: }
143:
144: case UA:
145: printf ("UA : PF=%d\n", pf);
146: break;
147:
148: case RR:
149: printf ("RR : N(R)=%d, PF=%d\n", nr, pf);
150: break;
151:
152: case RNR:
153: printf ("RNR : N(R)=%d, PF=%d\n", nr, pf);
154: break;
155:
156: case REJ:
157: printf ("REJ : N(R)=%d, PF=%d\n", nr, pf);
158: break;
159:
160: case IFRAME:
161: {
162: register struct mbuf *m;
163: register int len = 0;
164:
165: for(m = dtom (frame); m; m = m -> m_next)
166: len += m -> m_len;
167: len -= HDHEADERLN;
168: printf ("IFRAME : N(R)=%d, PF=%d, N(S)=%d, DATA(%d)=",
169: nr, pf, ns, len);
170: for (s = (char *)iframe->i_field, i = 0; i < 3; ++i, ++s)
171: printf ("%x ", (int) *s & 0xff);
172: printf ("\n");
173: break;
174: }
175:
176: default:
177: printf ("ILLEGAL: ");
178: for (s = (char *) frame, i = 0; i < 5; ++i, ++s)
179: printf ("%x ", (int) *s & 0xff);
180: printf ("\n");
181: }
182:
183: }
184: }
185:
186: #ifdef HDLCDEBUG
187: static
188: hd_savetrace (hdp, dir, frame)
189: struct hdcb *hdp;
190: struct Hdlc_frame *frame;
191: {
192: register struct hdlctrace *htp;
193: register struct mbuf *m;
194:
195: if (freezetrace)
196: return;
197: htp = &hdtrace[lasttracelogged];
198: lasttracelogged = (lasttracelogged + 1) % NTRACE;
199: if (m = htp->ht_frame)
200: m_freem (m);
201: m = dtom (frame);
202: htp->ht_frame = m_copy (m, 0, m->m_len);
203: htp->ht_hdp = hdp;
204: htp->ht_dir = dir;
205: htp->ht_time = time;
206: }
207:
208: hd_dumptrace (hdp)
209: struct hdcb *hdp;
210: {
211: register int i, ltrace;
212: register struct hdlctrace *htp;
213:
214: freezetrace = 1;
215: hd_status (hdp);
216: printf ("retransmit queue:");
217: for (i = 0; i < 8; i++)
218: printf (" %x", hdp -> hd_retxq[i]);
219: printf ("\n");
220: ltrace = hdp -> hd_xcp -> xc_ltrace;
221: hdp -> hd_xcp -> xc_ltrace = 1;
222: for (i = 0; i < NTRACE; i++) {
223: htp = &hdtrace[(lasttracelogged + i) % NTRACE];
224: if (htp->ht_hdp != hdp || htp->ht_frame == 0)
225: continue;
226: printf ("%d/%d ", htp->ht_time.tv_sec & 0xff,
227: htp->ht_time.tv_usec / 10000);
228: hd_trace (htp->ht_hdp, htp->ht_dir,
229: mtod (htp->ht_frame, struct Hdlc_frame *));
230: m_freem (htp->ht_frame);
231: htp->ht_frame = 0;
232: }
233: hdp -> hd_xcp -> xc_ltrace = ltrace;
234: freezetrace = 0;
235: }
236: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.