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