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_sframe.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_sframe.c - s frame handling routines
   28  *      ----------------------------------------
   29  *
   30  *      $Id: i4b_sframe.c,v 1.6 2003/10/03 16:38:44 pooka 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_sframe.c,v 1.6 2003/10/03 16:38:44 pooka 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_l2.h>
   68 #include <netisdn/i4b_l1l2.h>
   69 #include <netisdn/i4b_isdnq931.h>
   70 #include <netisdn/i4b_mbuf.h>
   71 #include <netisdn/i4b_l2fsm.h>
   72 #include <netisdn/i4b_l3l4.h>
   73 
   74 /*---------------------------------------------------------------------------*
   75  *      process s frame
   76  *---------------------------------------------------------------------------*/
   77 void
   78 i4b_rxd_s_frame(l2_softc_t *l2sc, struct isdn_l3_driver *drv, struct mbuf *m)
   79 {
   80         u_char *ptr = m->m_data;
   81         
   82         if(!((l2sc->tei_valid == TEI_VALID) &&
   83              (l2sc->tei == GETTEI(*(ptr+OFF_TEI)))))
   84         {
   85                 i4b_Dfreembuf(m);
   86                 return;
   87         }
   88 
   89         l2sc->rxd_CR = GETCR(*(ptr + OFF_SAPI));
   90         l2sc->rxd_PF = GETSPF(*(ptr + OFF_SNR));
   91         l2sc->rxd_NR = GETSNR(*(ptr + OFF_SNR));
   92 
   93         i4b_rxd_ack(l2sc, drv, l2sc->rxd_NR);
   94         
   95         switch(*(ptr + OFF_SRCR))
   96         {
   97                 case RR:
   98                         l2sc->stat.rx_rr++; /* update statistics */
   99                         NDBGL2(L2_S_MSG, "rx'd RR, N(R) = %d", l2sc->rxd_NR);
  100                         i4b_next_l2state(l2sc, drv, EV_RXRR);
  101                         break;
  102 
  103                 case RNR:
  104                         l2sc->stat.rx_rnr++; /* update statistics */
  105                         NDBGL2(L2_S_MSG, "rx'd RNR, N(R) = %d", l2sc->rxd_NR);
  106                         i4b_next_l2state(l2sc, drv, EV_RXRNR);
  107                         break;
  108 
  109                 case REJ:
  110                         l2sc->stat.rx_rej++; /* update statistics */
  111                         NDBGL2(L2_S_MSG, "rx'd REJ, N(R) = %d", l2sc->rxd_NR);
  112                         i4b_next_l2state(l2sc, drv, EV_RXREJ);
  113                         break;
  114 
  115                 default:
  116                         l2sc->stat.err_rx_bads++; /* update statistics */
  117                         NDBGL2(L2_S_ERR, "ERROR, unknown code, frame = ");
  118                         i4b_print_frame(m->m_len, m->m_data);
  119                         break;
  120         }
  121         i4b_Dfreembuf(m);       
  122 }
  123 
  124 /*---------------------------------------------------------------------------*
  125  *      transmit RR command
  126  *---------------------------------------------------------------------------*/
  127 void
  128 i4b_tx_rr_command(l2_softc_t *l2sc, pbit_t pbit)
  129 {
  130         struct mbuf *m;
  131 
  132         NDBGL2(L2_S_MSG, "tx RR, isdnif = %d", l2sc->drv->isdnif);
  133 
  134         m = i4b_build_s_frame(l2sc, CR_CMD_TO_NT, pbit, RR);
  135 
  136         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  137 
  138         l2sc->stat.tx_rr++; /* update statistics */
  139 }
  140 
  141 /*---------------------------------------------------------------------------*
  142  *      transmit RR response
  143  *---------------------------------------------------------------------------*/
  144 void
  145 i4b_tx_rr_response(l2_softc_t *l2sc, fbit_t fbit)
  146 {
  147         struct mbuf *m;
  148 
  149         NDBGL2(L2_S_MSG, "tx RR, isdnif = %d", l2sc->drv->isdnif);
  150 
  151         m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, RR);    
  152 
  153         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  154 
  155         l2sc->stat.tx_rr++; /* update statistics */
  156 }
  157 
  158 /*---------------------------------------------------------------------------*
  159  *      transmit RNR command
  160  *---------------------------------------------------------------------------*/
  161 void
  162 i4b_tx_rnr_command(l2_softc_t *l2sc, pbit_t pbit)
  163 {
  164         struct mbuf *m;
  165 
  166         NDBGL2(L2_S_MSG, "tx RNR, isdnif = %d", l2sc->drv->isdnif);
  167 
  168         m = i4b_build_s_frame(l2sc, CR_CMD_TO_NT, pbit, RNR);   
  169 
  170         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  171 
  172         l2sc->stat.tx_rnr++; /* update statistics */
  173 }
  174 
  175 /*---------------------------------------------------------------------------*
  176  *      transmit RNR response
  177  *---------------------------------------------------------------------------*/
  178 void
  179 i4b_tx_rnr_response(l2_softc_t *l2sc, fbit_t fbit)
  180 {
  181         struct mbuf *m;
  182 
  183         NDBGL2(L2_S_MSG, "tx RNR, isdnif = %d", l2sc->drv->isdnif);
  184 
  185         m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, RNR);
  186 
  187         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  188 
  189         l2sc->stat.tx_rnr++; /* update statistics */
  190 }
  191 
  192 /*---------------------------------------------------------------------------*
  193  *      transmit REJ response
  194  *---------------------------------------------------------------------------*/
  195 void
  196 i4b_tx_rej_response(l2_softc_t *l2sc, fbit_t fbit)
  197 {
  198         struct mbuf *m;
  199 
  200         NDBGL2(L2_S_MSG, "tx REJ, isdnif = %d", l2sc->drv->isdnif);
  201 
  202         m = i4b_build_s_frame(l2sc, CR_RSP_TO_NT, fbit, REJ);
  203 
  204         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  205 
  206         l2sc->stat.tx_rej++; /* update statistics */    
  207 }
  208 
  209 /*---------------------------------------------------------------------------*
  210  *      build S-frame for sending
  211  *---------------------------------------------------------------------------*/
  212 struct mbuf *
  213 i4b_build_s_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type)
  214 {
  215         struct mbuf *m;
  216         
  217         if((m = i4b_Dgetmbuf(S_FRAME_LEN)) == NULL)
  218                 return(NULL);
  219 
  220         PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]);
  221                 
  222         PUTTEI(l2sc->tei, m->m_data[OFF_TEI]);
  223 
  224         m->m_data[OFF_SRCR] = type;
  225 
  226         m->m_data[OFF_SNR] = (l2sc->vr << 1) | (pbit & 0x01);
  227 
  228         return(m);
  229 }
  230 
  231 #endif /* NI4BQ921 > 0 */

Cache object: 93664493022fbd18248e450b29d0db3c


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