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/netisdn/i4b_iframe.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 /*
    2  * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  *
   13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   23  * SUCH DAMAGE.
   24  *
   25  *---------------------------------------------------------------------------
   26  *
   27  *      i4b_iframe.c - i frame handling routines
   28  *      ------------------------------------------
   29  *
   30  *      $Id: i4b_iframe.c,v 1.6 2002/05/21 10:31:10 martin Exp $ 
   31  *
   32  * $FreeBSD$
   33  *
   34  *      last edit-date: [Fri Jan  5 11:33:47 2001]
   35  *
   36  *---------------------------------------------------------------------------*/
   37 
   38 #include <sys/cdefs.h>
   39 __KERNEL_RCSID(0, "$NetBSD: i4b_iframe.c,v 1.6 2002/05/21 10:31:10 martin Exp $");
   40 
   41 #ifdef __FreeBSD__
   42 #include "i4bq921.h"
   43 #else
   44 #define NI4BQ921        1
   45 #endif
   46 #if NI4BQ921 > 0
   47 
   48 #include <sys/param.h>
   49 #include <sys/kernel.h>
   50 #include <sys/systm.h>
   51 #include <sys/mbuf.h>
   52 #include <sys/socket.h>
   53 #include <net/if.h>
   54 
   55 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
   56 #include <sys/callout.h>
   57 #endif
   58 
   59 #ifdef __FreeBSD__
   60 #include <machine/i4b_debug.h>
   61 #include <machine/i4b_ioctl.h>
   62 #include <machine/i4b_trace.h>
   63 #else
   64 #include <netisdn/i4b_debug.h>
   65 #include <netisdn/i4b_ioctl.h>
   66 #include <netisdn/i4b_trace.h>
   67 #endif
   68 
   69 #include <netisdn/i4b_global.h>
   70 #include <netisdn/i4b_l2.h>
   71 #include <netisdn/i4b_l1l2.h>
   72 #include <netisdn/i4b_isdnq931.h>
   73 #include <netisdn/i4b_mbuf.h>
   74 #include <netisdn/i4b_l2fsm.h>
   75 
   76 /*---------------------------------------------------------------------------*
   77  *      process i frame
   78  *      implements the routine "I COMMAND" Q.921 03/93 pp 68 and pp 77
   79  *---------------------------------------------------------------------------*/
   80 void
   81 i4b_rxd_i_frame(l2_softc_t *l2sc, struct isdn_l3_driver *drv, struct mbuf *m)
   82 {
   83         u_char *ptr = m->m_data;
   84         int nr;
   85         int ns;
   86         int p;
   87         int s;
   88         
   89         if(!((l2sc->tei_valid == TEI_VALID) &&
   90              (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))))
   91         {
   92                 i4b_Dfreembuf(m);
   93                 return;
   94         }
   95 
   96         if((l2sc->Q921_state != ST_MULTIFR) && (l2sc->Q921_state != ST_TIMREC))
   97         {
   98                 i4b_Dfreembuf(m);
   99                 NDBGL2(L2_I_ERR, "ERROR, state != (MF || TR)!");
  100                 return;
  101         }
  102 
  103         s = splnet();
  104 
  105         l2sc->stat.rx_i++;              /* update frame count */
  106         
  107         nr = GETINR(*(ptr + OFF_INR));
  108         ns = GETINS(*(ptr + OFF_INS));
  109         p = GETIP(*(ptr + OFF_INR));
  110         
  111         i4b_rxd_ack(l2sc, drv, nr);             /* last packet ack */
  112 
  113         if(l2sc->own_busy)              /* own receiver busy ? */
  114         {       
  115                 i4b_Dfreembuf(m);       /* yes, discard information */
  116 
  117                 if(p == 1)              /* P bit == 1 ? */
  118                 {
  119                         i4b_tx_rnr_response(l2sc, p); /* yes, tx RNR */
  120                         l2sc->ack_pend = 0;     /* clear ACK pending */
  121                 }
  122         }
  123         else    /* own receiver ready */
  124         {
  125                 if(ns == l2sc->vr)      /* expected sequence number ? */
  126                 {
  127                         M128INC(l2sc->vr);      /* yes, update */
  128                         
  129                         l2sc->rej_excpt = 0;    /* clr reject exception */
  130 
  131                         m_adj(m, I_HDR_LEN);    /* strip i frame header */
  132 
  133                         l2sc->iframe_sent = 0;  /* reset i acked already */
  134 
  135                         i4b_dl_data_ind(drv, m);        /* pass data up */
  136 
  137                         if(!l2sc->iframe_sent)
  138                         {
  139                                 i4b_tx_rr_response(l2sc, p); /* yes, tx RR */
  140                                 l2sc->ack_pend = 0;     /* clr ACK pending */
  141                         }
  142                 }
  143                 else    /* ERROR, sequence number NOT expected */
  144                 {
  145                         i4b_Dfreembuf(m);       /* discard information */
  146 
  147                         if(l2sc->rej_excpt == 1)  /* already exception ? */
  148                         {
  149                                 if(p == 1)      /* immediate response ? */
  150                                 {
  151                                         i4b_tx_rr_response(l2sc, p); /* yes, tx RR */
  152                                         l2sc->ack_pend = 0; /* clr ack pend */
  153                                 }
  154                         }
  155                         else    /* not in exception cond */
  156                         {
  157                                 l2sc->rej_excpt = 1;    /* set exception */
  158                                 i4b_tx_rej_response(l2sc, p);   /* tx REJ */
  159                                 l2sc->ack_pend = 0;     /* clr ack pending */
  160                         }
  161                 }
  162         }
  163 
  164         /* sequence number ranges as expected ? */
  165         
  166         if(i4b_l2_nr_ok(nr, l2sc->va, l2sc->vs))
  167         {
  168                 if(l2sc->Q921_state == ST_TIMREC)
  169                 {
  170                         l2sc->va = nr;
  171 
  172                         splx(s);
  173 
  174                         return;
  175                 }
  176 
  177                 if(l2sc->peer_busy)     /* yes, other side busy ? */
  178                 {
  179                         l2sc->va = nr;  /* yes, update ack count */
  180                 }
  181                 else    /* other side ready */
  182                 {
  183                         if(nr == l2sc->vs)      /* count expected ? */
  184                         {
  185                                 l2sc->va = nr;  /* update ack */
  186                                 i4b_T200_stop(l2sc);
  187                                 i4b_T203_restart(l2sc);
  188                         }
  189                         else
  190                         {
  191                                 if(nr != l2sc->va)
  192                                 {
  193                                         l2sc->va = nr;
  194                                         i4b_T200_restart(l2sc);
  195                                 }
  196                         }
  197                 }
  198         }
  199         else
  200         {
  201                 i4b_nr_error_recovery(l2sc);    /* sequence error */
  202                 l2sc->Q921_state = ST_AW_EST; 
  203         }
  204 
  205         splx(s);
  206 }
  207 
  208 /*---------------------------------------------------------------------------*
  209  *      internal I FRAME QUEUED UP routine (Q.921 03/93 p 61)
  210  *---------------------------------------------------------------------------*/
  211 void
  212 i4b_i_frame_queued_up(l2_softc_t *l2sc)
  213 {
  214         struct mbuf *m;
  215         u_char *ptr;
  216         int s;
  217 
  218         s = splnet();
  219         
  220         if((l2sc->peer_busy) || (l2sc->vs == ((l2sc->va + MAX_K_VALUE) & 127)))
  221         {
  222                 if(l2sc->peer_busy)
  223                 {
  224                         NDBGL2(L2_I_MSG, "regen IFQUP, cause: peer busy!");
  225                 }
  226 
  227                 if(l2sc->vs == ((l2sc->va + MAX_K_VALUE) & 127))
  228                 {
  229                         NDBGL2(L2_I_MSG, "regen IFQUP, cause: vs=va+k!");
  230                 }       
  231 
  232                 /*
  233                  * XXX see: Q.921, page 36, 5.6.1 ".. may retransmit an I
  234                  * frame ...", shall we retransmit the last i frame ?
  235                  */
  236 
  237                 if(!(IF_QEMPTY(&l2sc->i_queue)))
  238                 {
  239                         NDBGL2(L2_I_MSG, "re-scheduling IFQU call!");
  240                         START_TIMER(l2sc->IFQU_callout, i4b_i_frame_queued_up, l2sc, IFQU_DLY);
  241                 }
  242                 splx(s);
  243                 return;
  244         }
  245 
  246         IF_DEQUEUE(&l2sc->i_queue, m);    /* fetch next frame to tx */
  247 
  248         if(!m)
  249         {
  250                 NDBGL2(L2_I_ERR, "ERROR, mbuf NULL after IF_DEQUEUE");
  251                 splx(s);
  252                 return;
  253         }
  254 
  255         ptr = m->m_data;
  256         
  257         PUTSAPI(SAPI_CCP, CR_CMD_TO_NT, *(ptr + OFF_SAPI));
  258         PUTTEI(l2sc->tei, *(ptr + OFF_TEI));
  259 
  260         *(ptr + OFF_INS) = (l2sc->vs << 1) & 0xfe; /* bit 0 = 0 */
  261         *(ptr + OFF_INR) = (l2sc->vr << 1) & 0xfe; /* P bit = 0 */
  262 
  263         l2sc->stat.tx_i++;      /* update frame counter */
  264 
  265         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_DONTFREE); /* free'd when ack'd ! */
  266 
  267         l2sc->iframe_sent = 1;          /* in case we ack an I frame with another I frame */
  268         
  269         if(l2sc->ua_num != UA_EMPTY)    /* failsafe */
  270         {
  271                 NDBGL2(L2_I_ERR, "ERROR, l2sc->ua_num: %d != UA_EMPTY", l2sc->ua_num);
  272                 i4b_print_l2var(l2sc);
  273                 i4b_Dfreembuf(l2sc->ua_frame);
  274         }
  275 
  276         l2sc->ua_frame = m;             /* save unacked frame */
  277         l2sc->ua_num = l2sc->vs;        /* save frame number */
  278 
  279         M128INC(l2sc->vs);
  280         
  281         l2sc->ack_pend = 0;
  282 
  283         splx(s);
  284 
  285         if(l2sc->T200 == TIMER_IDLE)
  286         {
  287                 i4b_T203_stop(l2sc);
  288                 i4b_T200_start(l2sc);
  289         }
  290 }
  291  
  292 #endif /* NI4BQ921 > 0 */

Cache object: 48917e54bca0598071f4079f06f2c570


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