This commit was generated by cvs2svn to track changes on a CVS vendor
[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 *
1cdffd64 38 * from: @(#)hd_debug.c 7.5 (Berkeley) 5/29/91
4c45483e 39 * $Id: hd_debug.c,v 1.2 1993/10/16 19:46:34 rgrimes Exp $
15637ed4
RG
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
61struct hdlctrace {
62 struct hdcb *ht_hdp;
63 short ht_dir;
64 struct mbuf *ht_frame;
65 struct timeval ht_time;
66} hdtrace[NTRACE];
67
68int lasttracelogged, freezetrace;
69#endif
70
4c45483e 71void
15637ed4 72hd_trace (hdp, direction, frame)
4c45483e
GW
73 struct hdcb *hdp;
74 int direction;
75 register struct Hdlc_frame *frame;
15637ed4
RG
76{
77 register char *s;
78 register int nr, pf, ns, i;
79 struct Hdlc_iframe *iframe = (struct Hdlc_iframe *) frame;
80
81#ifdef HDLCDEBUG
82 hd_savetrace (hdp, direction, frame);
83#endif
84 if (hdp -> hd_xcp -> xc_ltrace) {
85 if (direction == RX)
86 printf ("F-In: ");
87 else if (direction == 2)
88 printf ("F-Xmt: ");
89 else
90 printf ("F-Out: ");
91
92 nr = iframe -> nr;
93 pf = iframe -> pf;
94 ns = iframe -> ns;
95
96 switch (hd_decode (hdp, frame)) {
97 case SABM:
98 printf ("SABM : PF=%d\n", pf);
99 break;
100
101 case DISC:
102 printf ("DISC : PF=%d\n", pf);
103 break;
104
105 case DM:
106 printf ("DM : PF=%d\n", pf);
107 break;
108
109 case FRMR:
110 {
111 register struct Frmr_frame *f = (struct Frmr_frame *)frame;
112
113 printf ("FRMR : PF=%d, TEXT=", pf);
114 for (s = (char *) frame, i = 0; i < 5; ++i, ++s)
115 printf ("%x ", (int) * s & 0xff);
116 printf ("\n");
117 printf ("control=%x v(s)=%d v(r)=%d w%d x%d y%d z%d\n",
118 f->frmr_control, f->frmr_ns, f->frmr_nr,
119 f->frmr_w, f->frmr_x, f->frmr_y, f->frmr_z);
120 break;
121 }
122
123 case UA:
124 printf ("UA : PF=%d\n", pf);
125 break;
126
127 case RR:
128 printf ("RR : N(R)=%d, PF=%d\n", nr, pf);
129 break;
130
131 case RNR:
132 printf ("RNR : N(R)=%d, PF=%d\n", nr, pf);
133 break;
134
135 case REJ:
136 printf ("REJ : N(R)=%d, PF=%d\n", nr, pf);
137 break;
138
139 case IFRAME:
140 {
141 register struct mbuf *m;
142 register int len = 0;
143
144 for(m = dtom (frame); m; m = m -> m_next)
145 len += m -> m_len;
146 len -= HDHEADERLN;
147 printf ("IFRAME : N(R)=%d, PF=%d, N(S)=%d, DATA(%d)=",
148 nr, pf, ns, len);
149 for (s = (char *)iframe->i_field, i = 0; i < 3; ++i, ++s)
150 printf ("%x ", (int) *s & 0xff);
151 printf ("\n");
152 break;
153 }
154
155 default:
156 printf ("ILLEGAL: ");
157 for (s = (char *) frame, i = 0; i < 5; ++i, ++s)
158 printf ("%x ", (int) *s & 0xff);
159 printf ("\n");
160 }
161
162 }
163}
164
165#ifdef HDLCDEBUG
166static
167hd_savetrace (hdp, dir, frame)
168struct hdcb *hdp;
169struct Hdlc_frame *frame;
170{
171 register struct hdlctrace *htp;
172 register struct mbuf *m;
173
174 if (freezetrace)
175 return;
176 htp = &hdtrace[lasttracelogged];
177 lasttracelogged = (lasttracelogged + 1) % NTRACE;
178 if (m = htp->ht_frame)
179 m_freem (m);
180 m = dtom (frame);
181 htp->ht_frame = m_copy (m, 0, m->m_len);
182 htp->ht_hdp = hdp;
183 htp->ht_dir = dir;
184 htp->ht_time = time;
185}
186
187hd_dumptrace (hdp)
188struct hdcb *hdp;
189{
190 register int i, ltrace;
191 register struct hdlctrace *htp;
192
193 freezetrace = 1;
194 hd_status (hdp);
195 printf ("retransmit queue:");
196 for (i = 0; i < 8; i++)
197 printf (" %x", hdp -> hd_retxq[i]);
198 printf ("\n");
199 ltrace = hdp -> hd_xcp -> xc_ltrace;
200 hdp -> hd_xcp -> xc_ltrace = 1;
201 for (i = 0; i < NTRACE; i++) {
202 htp = &hdtrace[(lasttracelogged + i) % NTRACE];
203 if (htp->ht_hdp != hdp || htp->ht_frame == 0)
204 continue;
205 printf ("%d/%d ", htp->ht_time.tv_sec & 0xff,
206 htp->ht_time.tv_usec / 10000);
207 hd_trace (htp->ht_hdp, htp->ht_dir,
208 mtod (htp->ht_frame, struct Hdlc_frame *));
209 m_freem (htp->ht_frame);
210 htp->ht_frame = 0;
211 }
212 hdp -> hd_xcp -> xc_ltrace = ltrace;
213 freezetrace = 0;
214}
215#endif