The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netccitt/hd_debug.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 94b9ba8f6ffee9ea91fe5bed16531eae


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.