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_output.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_output.c,v 1.17 2005/02/26 22:45:10 perry 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_output.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_output.c 8.1 (Berkeley) 6/10/93
   74  */
   75 
   76 #include <sys/cdefs.h>
   77 __KERNEL_RCSID(0, "$NetBSD: hd_output.c,v 1.17 2005/02/26 22:45:10 perry 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/syslog.h>
   85 #include <sys/protosw.h>
   86 #include <sys/errno.h>
   87 #include <sys/time.h>
   88 #include <sys/kernel.h>
   89 
   90 #include <net/if.h>
   91 
   92 #include <netccitt/hdlc.h>
   93 #include <netccitt/hd_var.h>
   94 #include <netccitt/x25.h>
   95 #include <netccitt/pk_extern.h>
   96 
   97 #include <machine/stdarg.h>
   98 
   99 /*
  100  *      HDLC OUTPUT INTERFACE
  101  *
  102  *      This routine is called when the X.25 packet layer output routine
  103  *      has a information frame (iframe)  to write.   It is  also called
  104  *      by the input and control routines of the HDLC layer.
  105  */
  106 
  107 int
  108 hd_output(struct mbuf *m0, ...)
  109 {
  110         struct hdcb *hdp;
  111         struct mbuf *m = m0;
  112         int             len;
  113         va_list ap;
  114 
  115         va_start(ap, m0);
  116         hdp = va_arg(ap, struct hdcb *);
  117         va_end(ap);
  118 
  119         if (m == NULL)
  120                 panic("hd_output");
  121         if ((m->m_flags & M_PKTHDR) == 0)
  122                 panic("hd_output 2");
  123 
  124         if (hdp->hd_state != ABM) {
  125                 m_freem(m);
  126                 return 0;
  127         }
  128         /*
  129          * Make room for the hdlc header either by prepending
  130          * another mbuf, or by adjusting the offset and length
  131          * of the first mbuf in the mbuf chain.
  132          */
  133 
  134         M_PREPEND(m, HDHEADERLN, M_DONTWAIT);
  135         if (m == NULL)
  136                 return 0;
  137         for (len = 0; m; m = m->m_next)
  138                 len += m->m_len;
  139         m = m0;
  140         m->m_pkthdr.len = len;
  141 
  142         hd_append(&hdp->hd_txq, m);
  143         hd_start(hdp);
  144         return 0;
  145 }
  146 
  147 void
  148 hd_start(hdp)
  149         struct hdcb *hdp;
  150 {
  151         struct mbuf *m;
  152 
  153         /*
  154          * The iframe is only transmitted if all these conditions are FALSE.
  155          * The iframe remains queued (hdp->hd_txq) however and will be
  156          * transmitted as soon as these conditions are cleared.
  157          */
  158 
  159         while (!(hdp->hd_condition & (TIMER_RECOVERY_CONDITION |
  160                                      REMOTE_RNR_CONDITION | REJ_CONDITION))) {
  161                 if (hdp->hd_vs ==
  162                         (hdp->hd_lastrxnr + hdp->hd_xcp->xc_lwsize) % MODULUS) {
  163 
  164                         /*
  165                          * We have now exceeded the  maximum  number  of
  166                          * outstanding iframes. Therefore,  we must wait
  167                          * until  at least  one is acknowledged if this
  168                          * condition  is not  turned off before we are
  169                          * requested to write another iframe.
  170                          */
  171                         hdp->hd_window_condition++;
  172                         break;
  173                 }
  174                 /* hd_remove top iframe from transmit queue. */
  175                 if ((m = hd_remove(&hdp->hd_txq)) == NULL)
  176                         break;
  177 
  178                 hd_send_iframe(hdp, m, POLLOFF);
  179         }
  180 }
  181 
  182 /*
  183  * This procedure is passed a buffer descriptor for an iframe. It builds the
  184  * rest of the control part of the frame and then writes it out.  It also
  185  * starts the  acknowledgement  timer and keeps  the iframe in the Retransmit
  186  * queue (Retxq) just in case  we have to do this again.
  187  *
  188  * Note: This routine is also called from hd_input.c when retransmission of old
  189  * frames is required.
  190  */
  191 void
  192 hd_send_iframe(hdp, buf, poll_bit)
  193         struct hdcb *hdp;
  194         struct mbuf *buf;
  195         int             poll_bit;
  196 {
  197         struct Hdlc_iframe *iframe;
  198         struct mbuf    *m;
  199 
  200         KILL_TIMER(hdp);
  201 
  202         if (buf == 0) {
  203                 printf("hd_send_iframe: zero arg\n");
  204 #ifdef HDLCDEBUG
  205                 hd_status(hdp);
  206                 hd_dumptrace(hdp);
  207 #endif
  208                 hdp->hd_vs = (hdp->hd_vs + 7) % MODULUS;
  209                 return;
  210         }
  211         iframe = mtod(buf, struct Hdlc_iframe *);
  212 
  213         iframe->hdlc_0 = 0;
  214         iframe->nr = hdp->hd_vr;
  215         iframe->pf = poll_bit;
  216         iframe->ns = hdp->hd_vs;
  217         iframe->address = ADDRESS_B;
  218         hdp->hd_lasttxnr = hdp->hd_vr;
  219         hdp->hd_rrtimer = 0;
  220 
  221         if (hdp->hd_vs == hdp->hd_retxqi) {
  222                 /* Check for retransmissions. */
  223                 /* Put iframe only once in the Retransmission queue. */
  224                 hdp->hd_retxq[(u_char) hdp->hd_retxqi] = buf;
  225                 hdp->hd_retxqi = (hdp->hd_retxqi + 1) % MODULUS;
  226                 hdp->hd_iframes_out++;
  227         }
  228         hdp->hd_vs = (hdp->hd_vs + 1) % MODULUS;
  229 
  230         hd_trace(hdp, TX, buf);
  231 
  232         /* Write buffer on device. */
  233         m = hdp->hd_dontcopy ? buf : m_copy(buf, 0, (int) M_COPYALL);
  234         if (m == 0) {
  235                 printf("hdlc: out of mbufs\n");
  236                 return;
  237         }
  238         (*hdp->hd_output) (m, hdp);
  239         SET_TIMER(hdp);
  240 }
  241 
  242 int
  243 hd_ifoutput(struct mbuf *m, ...)
  244 {
  245         struct hdcb *hdp;
  246         struct ifnet *ifp;
  247         int             s = splnet();
  248         va_list ap;
  249 
  250         va_start(ap, m);
  251         hdp = va_arg(ap, struct hdcb *);
  252         va_end(ap);
  253         ifp = hdp->hd_ifp;
  254 
  255         /*
  256          * Queue message on interface, and start output if interface
  257          * not yet active.
  258          */
  259 
  260         if (IF_QFULL(&ifp->if_snd)) {
  261                 IF_DROP(&ifp->if_snd);
  262 #if 0
  263                 printf("%s: HDLC says OK to send but queue full, may hang\n",
  264                     ifp->if_xname);
  265 #endif
  266                 m_freem(m);
  267         } else {
  268                 IF_ENQUEUE(&ifp->if_snd, m);
  269                 if ((ifp->if_flags & IFF_OACTIVE) == 0)
  270                         (*ifp->if_start) (ifp);
  271         }
  272         splx(s);
  273         return 0;
  274 }
  275 
  276 
  277 /*
  278  * This routine gets control when the timer expires because we have not
  279  * received an acknowledgement for a iframe.
  280  */
  281 
  282 void
  283 hd_resend_iframe(hdp)
  284         struct hdcb *hdp;
  285 {
  286 
  287         if (hdp->hd_retxcnt++ < hd_n2) {
  288                 if (!(hdp->hd_condition & TIMER_RECOVERY_CONDITION)) {
  289                         hdp->hd_xx = hdp->hd_vs;
  290                         hdp->hd_condition |= TIMER_RECOVERY_CONDITION;
  291                 }
  292                 hdp->hd_vs = hdp->hd_lastrxnr;
  293                 hd_send_iframe(hdp, hdp->hd_retxq[(u_char)hdp->hd_vs], POLLON);
  294         } else {
  295                 /*
  296                  * At this point we have not received a RR even after N2
  297                  * retries - attempt to reset link.
  298                  */
  299 
  300                 hd_initvars(hdp);
  301                 hd_writeinternal(hdp, SABM, POLLOFF);
  302                 hdp->hd_state = WAIT_UA;
  303                 SET_TIMER(hdp);
  304                 hd_message(hdp, "Timer recovery failed: link down");
  305                 (void) pk_ctlinput(PRC_LINKDOWN,
  306                                    (struct sockaddr *)hdp->hd_pkp, NULL);
  307         }
  308 }

Cache object: 56adb356da5a60232cb5dce50ab81568


[ 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.