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_util.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_util.c - layer 2 utility routines
   28  *      -------------------------------------
   29  *
   30  *      $Id: i4b_util.c,v 1.11 2006/11/16 01:33:49 christos 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_util.c,v 1.11 2006/11/16 01:33:49 christos 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 #else
   63 #include <netisdn/i4b_debug.h>
   64 #include <netisdn/i4b_ioctl.h>
   65 #endif
   66 
   67 #include <netisdn/i4b_global.h>
   68 #include <netisdn/i4b_l2.h>
   69 #include <netisdn/i4b_l1l2.h>
   70 #include <netisdn/i4b_isdnq931.h>
   71 #include <netisdn/i4b_mbuf.h>
   72 #include <netisdn/i4b_l2fsm.h>
   73 #include <netisdn/i4b_l3l4.h>
   74 
   75 /*---------------------------------------------------------------------------*
   76  *      routine ESTABLISH DATA LINK (Q.921 03/93 page 83)
   77  *---------------------------------------------------------------------------*/
   78 void
   79 i4b_establish_data_link(l2_softc_t *l2sc)
   80 {
   81         i4b_l1_activate(l2sc);
   82 
   83         i4b_clear_exception_conditions(l2sc);
   84 
   85         l2sc->RC = 0;
   86 
   87         i4b_tx_sabme(l2sc, P1);
   88 
   89         i4b_T200_restart(l2sc);
   90 
   91         i4b_T203_stop(l2sc);
   92 }
   93 
   94 /*---------------------------------------------------------------------------*
   95  *      routine CLEAR EXCEPTION CONDITIONS (Q.921 03/93 page 83)
   96  *---------------------------------------------------------------------------*/
   97 void
   98 i4b_clear_exception_conditions(l2_softc_t *l2sc)
   99 {
  100         int s;
  101 
  102         s = splnet();
  103 
  104 /*XXX -------------------------------------------------------------- */
  105 /*XXX is this really appropriate here or should it moved elsewhere ? */
  106 
  107         i4b_Dcleanifq(&l2sc->i_queue);
  108 
  109         if(l2sc->ua_num != UA_EMPTY)
  110         {
  111                 i4b_Dfreembuf(l2sc->ua_frame);
  112                 l2sc->ua_num = UA_EMPTY;
  113         }
  114 /*XXX -------------------------------------------------------------- */
  115 
  116         l2sc->peer_busy = 0;
  117 
  118         l2sc->rej_excpt = 0;
  119 
  120         l2sc->own_busy = 0;
  121 
  122         l2sc->ack_pend = 0;
  123 
  124         splx(s);
  125 }
  126 
  127 /*---------------------------------------------------------------------------*
  128  *      routine TRANSMIT ENQUIRE (Q.921 03/93 page 83)
  129  *---------------------------------------------------------------------------*/
  130 void
  131 i4b_transmit_enquire(l2_softc_t *l2sc)
  132 {
  133         if(l2sc->own_busy)
  134                 i4b_tx_rnr_command(l2sc, P1);
  135         else
  136                 i4b_tx_rr_command(l2sc, P1);
  137 
  138         l2sc->ack_pend = 0;
  139 
  140         i4b_T200_start(l2sc);
  141 }
  142 
  143 /*---------------------------------------------------------------------------*
  144  *      routine NR ERROR RECOVERY (Q.921 03/93 page 83)
  145  *---------------------------------------------------------------------------*/
  146 void
  147 i4b_nr_error_recovery(l2_softc_t *l2sc)
  148 {
  149         i4b_mdl_error_ind(l2sc, "i4b_nr_error_recovery", MDL_ERR_J);
  150 
  151         i4b_establish_data_link(l2sc);
  152 
  153         l2sc->l3initiated = 0;
  154 }
  155 
  156 /*---------------------------------------------------------------------------*
  157  *      routine ENQUIRY RESPONSE (Q.921 03/93 page 84)
  158  *---------------------------------------------------------------------------*/
  159 void
  160 i4b_enquiry_response(l2_softc_t *l2sc)
  161 {
  162         if(l2sc->own_busy)
  163                 i4b_tx_rnr_response(l2sc, F1);
  164         else
  165                 i4b_tx_rr_response(l2sc, F1);
  166 
  167         l2sc->ack_pend = 0;
  168 }
  169 
  170 /*---------------------------------------------------------------------------*
  171  *      routine INVOKE RETRANSMISSION (Q.921 03/93 page 84)
  172  *---------------------------------------------------------------------------*/
  173 void
  174 i4b_invoke_retransmission(l2_softc_t *l2sc, int nr)
  175 {
  176         int s;
  177 
  178         s = splnet();
  179 
  180         NDBGL2(L2_ERROR, "nr = %d", nr );
  181 
  182         while(l2sc->vs != nr)
  183         {
  184                 NDBGL2(L2_ERROR, "nr(%d) != vs(%d)", nr, l2sc->vs);
  185 
  186                 M128DEC(l2sc->vs);
  187 
  188 /* XXXXXXXXXXXXXXXXX */
  189 
  190                 if((l2sc->ua_num != UA_EMPTY) && (l2sc->vs == l2sc->ua_num))
  191                 {
  192                         if(IF_QFULL(&l2sc->i_queue))
  193                         {
  194                                 NDBGL2(L2_ERROR, "ERROR, I-queue full!");
  195                         }
  196                         else
  197                         {
  198                                 IF_ENQUEUE(&l2sc->i_queue, l2sc->ua_frame);
  199                                 l2sc->ua_num = UA_EMPTY;
  200                         }
  201                 }
  202                 else
  203                 {
  204                         NDBGL2(L2_ERROR, "ERROR, l2sc->vs = %d, l2sc->ua_num = %d ",l2sc->vs, l2sc->ua_num);
  205                 }
  206 
  207 /* XXXXXXXXXXXXXXXXX */
  208 
  209                 i4b_i_frame_queued_up(l2sc);
  210         }
  211 
  212         splx(s);
  213 }
  214 
  215 /*---------------------------------------------------------------------------*
  216  *      routine ACKNOWLEDGE PENDING (Q.921 03/93 p 70)
  217  *---------------------------------------------------------------------------*/
  218 void
  219 i4b_acknowledge_pending(l2_softc_t *l2sc)
  220 {
  221         if(l2sc->ack_pend)
  222         {
  223                 l2sc->ack_pend = 0;
  224                 i4b_tx_rr_response(l2sc, F0);
  225         }
  226 }
  227 
  228 /*---------------------------------------------------------------------------*
  229  *      i4b_print_frame - just print the hex contents of a frame
  230  *---------------------------------------------------------------------------*/
  231 void
  232 i4b_print_frame(int len, u_char *buf)
  233 {
  234 #if DO_I4B_DEBUG
  235         int i;
  236 
  237         if (!(i4b_l2_debug & L2_ERROR))         /* XXXXXXXXXXXXXXXXXXXXX */
  238                 return;
  239 
  240         for(i = 0; i < len; i++)
  241                 printf(" 0x%x", buf[i]);
  242         printf("\n");
  243 #endif
  244 }
  245 
  246 /*---------------------------------------------------------------------------*
  247  *      i4b_print_l2var - print some l2softc vars
  248  *---------------------------------------------------------------------------*/
  249 void
  250 i4b_print_l2var(l2_softc_t *l2sc)
  251 {
  252         NDBGL2(L2_ERROR, "isdnif %d V(R)=%d, V(S)=%d, V(A)=%d,ACKP=%d,PBSY=%d,OBSY=%d",
  253                 l2sc->drv->isdnif,
  254                 l2sc->vr,
  255                 l2sc->vs,
  256                 l2sc->va,
  257                 l2sc->ack_pend,
  258                 l2sc->peer_busy,
  259                 l2sc->own_busy);
  260 }
  261 
  262 /*---------------------------------------------------------------------------*
  263  *      got s or i frame, check if valid ack for last sent frame
  264  *---------------------------------------------------------------------------*/
  265 void
  266 i4b_rxd_ack(l2_softc_t *l2sc, struct isdn_l3_driver *drv, int nr)
  267 {
  268 
  269 #ifdef NOTDEF
  270         NDBGL2(L2_ERROR, "N(R)=%d, UA=%d, V(R)=%d, V(S)=%d, V(A)=%d",
  271                 nr,
  272                 l2sc->ua_num,
  273                 l2sc->vr,
  274                 l2sc->vs,
  275                 l2sc->va);
  276 #endif
  277 
  278         if(l2sc->ua_num != UA_EMPTY)
  279         {
  280                 int s;
  281 
  282                 s = splnet();
  283 
  284                 M128DEC(nr);
  285 
  286                 if(l2sc->ua_num != nr)
  287                         NDBGL2(L2_ERROR, "((N(R)-1)=%d) != (UA=%d) !!!", nr, l2sc->ua_num);
  288 
  289                 i4b_Dfreembuf(l2sc->ua_frame);
  290                 l2sc->ua_num = UA_EMPTY;
  291 
  292                 splx(s);
  293         }
  294 }
  295 
  296 /*---------------------------------------------------------------------------*
  297  *      if not already active, activate layer 1
  298  *---------------------------------------------------------------------------*/
  299 void
  300 i4b_l1_activate(l2_softc_t *l2sc)
  301 {
  302         if(l2sc->ph_active == PH_INACTIVE)
  303         {
  304                 l2sc->ph_active = PH_ACTIVEPEND;
  305                 l2sc->driver->ph_activate_req(l2sc->l1_token);
  306         }
  307 };
  308 
  309 /*---------------------------------------------------------------------------*
  310  *      check for v(a) <= n(r) <= v(s)
  311  *      nr = receive sequence frame counter, va = acknowledge sequence frame
  312  *      counter and vs = transmit sequence frame counter
  313  *---------------------------------------------------------------------------*/
  314 int
  315 i4b_l2_nr_ok(int nr, int va, int vs)
  316 {
  317         if((va > nr) && ((nr != 0) || (va != 127)))
  318         {
  319                 NDBGL2(L2_ERROR, "ERROR, va = %d, nr = %d, vs = %d [1]", va, nr, vs);
  320                 return 0;       /* fail */
  321         }
  322 
  323         if((nr > vs) && ((vs != 0) || (nr != 127)))
  324         {
  325                 NDBGL2(L2_ERROR, "ERROR, va = %d, nr = %d, vs = %d [2]", va, nr, vs);
  326                 return 0;       /* fail */
  327         }
  328         return 1;               /* good */
  329 }
  330 
  331 #endif /* NI4BQ921 > 0 */
  332 

Cache object: b057c5a7d72908d5d7ba6c2265ea30b5


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