Removed all patch kit headers, sccsid and rcsid strings, put $Id$ in, some
[unix-history] / sys / netccitt / hd_debug.c
CommitLineData
15637ed4
RG
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 *
38 * @(#)hd_debug.c 7.5 (Berkeley) 5/29/91
39 */
40
41#include "param.h"
42#include "systm.h"
43#include "mbuf.h"
44#include "domain.h"
45#include "socket.h"
46#include "protosw.h"
47#include "errno.h"
48#include "time.h"
49#include "kernel.h"
50
51#include "../net/if.h"
52
53#include "hdlc.h"
54#include "hd_var.h"
55#include "x25.h"
56
57#ifdef HDLCDEBUG
58#define NTRACE 32
59
60struct hdlctrace {
61 struct hdcb *ht_hdp;
62 short ht_dir;
63 struct mbuf *ht_frame;
64 struct timeval ht_time;
65} hdtrace[NTRACE];
66
67int lasttracelogged, freezetrace;
68#endif
69
70hd_trace (hdp, direction, frame)
71struct hdcb *hdp;
72register struct Hdlc_frame *frame;
73{
74 register char *s;
75 register int nr, pf, ns, i;
76 struct Hdlc_iframe *iframe = (struct Hdlc_iframe *) frame;
77
78#ifdef HDLCDEBUG
79 hd_savetrace (hdp, direction, frame);
80#endif
81 if (hdp -> hd_xcp -> xc_ltrace) {
82 if (direction == RX)
83 printf ("F-In: ");
84 else if (direction == 2)
85 printf ("F-Xmt: ");
86 else
87 printf ("F-Out: ");
88
89 nr = iframe -> nr;
90 pf = iframe -> pf;
91 ns = iframe -> ns;
92
93 switch (hd_decode (hdp, frame)) {
94 case SABM:
95 printf ("SABM : PF=%d\n", pf);
96 break;
97
98 case DISC:
99 printf ("DISC : PF=%d\n", pf);
100 break;
101
102 case DM:
103 printf ("DM : PF=%d\n", pf);
104 break;
105
106 case FRMR:
107 {
108 register struct Frmr_frame *f = (struct Frmr_frame *)frame;
109
110 printf ("FRMR : PF=%d, TEXT=", pf);
111 for (s = (char *) frame, i = 0; i < 5; ++i, ++s)
112 printf ("%x ", (int) * s & 0xff);
113 printf ("\n");
114 printf ("control=%x v(s)=%d v(r)=%d w%d x%d y%d z%d\n",
115 f->frmr_control, f->frmr_ns, f->frmr_nr,
116 f->frmr_w, f->frmr_x, f->frmr_y, f->frmr_z);
117 break;
118 }
119
120 case UA:
121 printf ("UA : PF=%d\n", pf);
122 break;
123
124 case RR:
125 printf ("RR : N(R)=%d, PF=%d\n", nr, pf);
126 break;
127
128 case RNR:
129 printf ("RNR : N(R)=%d, PF=%d\n", nr, pf);
130 break;
131
132 case REJ:
133 printf ("REJ : N(R)=%d, PF=%d\n", nr, pf);
134 break;
135
136 case IFRAME:
137 {
138 register struct mbuf *m;
139 register int len = 0;
140
141 for(m = dtom (frame); m; m = m -> m_next)
142 len += m -> m_len;
143 len -= HDHEADERLN;
144 printf ("IFRAME : N(R)=%d, PF=%d, N(S)=%d, DATA(%d)=",
145 nr, pf, ns, len);
146 for (s = (char *)iframe->i_field, i = 0; i < 3; ++i, ++s)
147 printf ("%x ", (int) *s & 0xff);
148 printf ("\n");
149 break;
150 }
151
152 default:
153 printf ("ILLEGAL: ");
154 for (s = (char *) frame, i = 0; i < 5; ++i, ++s)
155 printf ("%x ", (int) *s & 0xff);
156 printf ("\n");
157 }
158
159 }
160}
161
162#ifdef HDLCDEBUG
163static
164hd_savetrace (hdp, dir, frame)
165struct hdcb *hdp;
166struct Hdlc_frame *frame;
167{
168 register struct hdlctrace *htp;
169 register struct mbuf *m;
170
171 if (freezetrace)
172 return;
173 htp = &hdtrace[lasttracelogged];
174 lasttracelogged = (lasttracelogged + 1) % NTRACE;
175 if (m = htp->ht_frame)
176 m_freem (m);
177 m = dtom (frame);
178 htp->ht_frame = m_copy (m, 0, m->m_len);
179 htp->ht_hdp = hdp;
180 htp->ht_dir = dir;
181 htp->ht_time = time;
182}
183
184hd_dumptrace (hdp)
185struct hdcb *hdp;
186{
187 register int i, ltrace;
188 register struct hdlctrace *htp;
189
190 freezetrace = 1;
191 hd_status (hdp);
192 printf ("retransmit queue:");
193 for (i = 0; i < 8; i++)
194 printf (" %x", hdp -> hd_retxq[i]);
195 printf ("\n");
196 ltrace = hdp -> hd_xcp -> xc_ltrace;
197 hdp -> hd_xcp -> xc_ltrace = 1;
198 for (i = 0; i < NTRACE; i++) {
199 htp = &hdtrace[(lasttracelogged + i) % NTRACE];
200 if (htp->ht_hdp != hdp || htp->ht_frame == 0)
201 continue;
202 printf ("%d/%d ", htp->ht_time.tv_sec & 0xff,
203 htp->ht_time.tv_usec / 10000);
204 hd_trace (htp->ht_hdp, htp->ht_dir,
205 mtod (htp->ht_frame, struct Hdlc_frame *));
206 m_freem (htp->ht_frame);
207 htp->ht_frame = 0;
208 }
209 hdp -> hd_xcp -> xc_ltrace = ltrace;
210 freezetrace = 0;
211}
212#endif