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