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_uframe.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_uframe.c - routines for handling U-frames
   28  *      -----------------------------------------------
   29  *
   30  *      $Id: i4b_uframe.c,v 1.5 2002/05/21 10:31:11 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_uframe.c,v 1.5 2002/05/21 10:31:11 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 #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 
   72 #include <netisdn/i4b_l2.h>
   73 #include <netisdn/i4b_l2fsm.h>
   74 
   75 /*---------------------------------------------------------------------------*
   76  *      process a received U-frame
   77  *---------------------------------------------------------------------------*/
   78 void
   79 i4b_rxd_u_frame(l2_softc_t *l2sc, struct isdn_l3_driver *drv, struct mbuf *m)
   80 {
   81         u_char *ptr = m->m_data;
   82 
   83         int sapi = GETSAPI(*(ptr + OFF_SAPI));
   84         int tei = GETTEI(*(ptr + OFF_TEI));     
   85         int pfbit = GETUPF(*(ptr + OFF_CNTL));
   86         
   87         switch(*(ptr + OFF_CNTL) & ~UPFBIT)
   88         {
   89                 /* commands */
   90 
   91                 case SABME:
   92                         if((l2sc->tei_valid == TEI_VALID) &&
   93                            (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
   94                         {
   95                                 l2sc->stat.rx_sabme++;
   96                                 NDBGL2(L2_U_MSG, "SABME, sapi = %d, tei = %d", sapi, tei);
   97                                 l2sc->rxd_PF = pfbit;
   98                                 i4b_next_l2state(l2sc, drv, EV_RXSABME);
   99                         }
  100                         i4b_Dfreembuf(m);
  101                         break;
  102 
  103                 case UI:
  104                         if(sapi == SAPI_L2M &&
  105                            tei == GROUP_TEI &&
  106                            *(ptr + OFF_MEI) == MEI)
  107                         {
  108                                 /* layer 2 management (SAPI = 63) */
  109                                 l2sc->stat.rx_tei++;
  110                                 i4b_tei_rxframe(l2sc, drv, m);
  111                         }
  112                         else if(sapi == SAPI_CCP && tei == GROUP_TEI)
  113                         {
  114                                 /* call control (SAPI = 0) */
  115                                 l2sc->stat.rx_ui++;
  116                                 /* strip ui header */
  117                                 m_adj(m, UI_HDR_LEN);
  118                                 /* to upper layer */
  119                                 i4b_dl_unit_data_ind(l2sc->drv, m);
  120                         }
  121                         else
  122                         {
  123                                 l2sc->stat.err_rx_badui++;
  124                                 NDBGL2(L2_U_ERR, "unknown UI frame!");
  125                                 i4b_Dfreembuf(m);                               
  126                         }
  127                         break;
  128                         
  129                 case DISC:
  130                         if((l2sc->tei_valid == TEI_VALID) &&
  131                            (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
  132                         {               
  133                                 l2sc->stat.rx_disc++;
  134                                 NDBGL2(L2_U_MSG, "DISC, sapi = %d, tei = %d", sapi, tei);
  135                                 l2sc->rxd_PF = pfbit;
  136                                 i4b_next_l2state(l2sc, drv, EV_RXDISC);
  137                         }
  138                         i4b_Dfreembuf(m);
  139                         break;
  140 
  141                 case XID:
  142                         if((l2sc->tei_valid == TEI_VALID) &&
  143                            (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
  144                         {               
  145                                 l2sc->stat.rx_xid++;
  146                                 NDBGL2(L2_U_MSG, "XID, sapi = %d, tei = %d", sapi, tei);
  147                         }
  148                         i4b_Dfreembuf(m);                       
  149                         break;
  150                         
  151                 /* responses */
  152 
  153                 case DM:
  154                         if((l2sc->tei_valid == TEI_VALID) &&
  155                            (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
  156                         {               
  157                                 l2sc->stat.rx_dm++;
  158                                 NDBGL2(L2_U_MSG, "DM, sapi = %d, tei = %d", sapi, tei);
  159                                 i4b_print_frame(m->m_len, m->m_data);
  160                                 l2sc->rxd_PF = pfbit;
  161                                 i4b_next_l2state(l2sc, drv, EV_RXDM);
  162                         }
  163                         i4b_Dfreembuf(m);
  164                         break;
  165                         
  166                 case UA:
  167                         if((l2sc->tei_valid == TEI_VALID) &&
  168                            (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
  169                         {               
  170                                 l2sc->stat.rx_ua++;
  171                                 NDBGL2(L2_U_MSG, "UA, sapi = %d, tei = %d", sapi, tei);
  172                                 l2sc->rxd_PF = pfbit;
  173                                 i4b_next_l2state(l2sc, drv, EV_RXUA);
  174                         }
  175                         i4b_Dfreembuf(m);                       
  176                         break;                  
  177 
  178                 case FRMR:
  179                         if((l2sc->tei_valid == TEI_VALID) &&
  180                            (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
  181                         {
  182                                 l2sc->stat.rx_frmr++;
  183                                 NDBGL2(L2_U_MSG, "FRMR, sapi = %d, tei = %d", sapi, tei);
  184                                 l2sc->rxd_PF = pfbit;
  185                                 i4b_next_l2state(l2sc, drv, EV_RXFRMR);
  186                         }
  187                         i4b_Dfreembuf(m);                       
  188                         break;
  189 
  190                 default:
  191                         if((l2sc->tei_valid == TEI_VALID) &&
  192                            (l2sc->tei == GETTEI(*(ptr+OFF_TEI))))
  193                         {               
  194                                 NDBGL2(L2_U_ERR, "UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei);
  195                                 i4b_print_frame(m->m_len, m->m_data);
  196                         }
  197                         else
  198                         {               
  199                                 NDBGL2(L2_U_ERR, "not mine -  UNKNOWN TYPE ERROR, sapi = %d, tei = %d, frame = ", sapi, tei);
  200                                 i4b_print_frame(m->m_len, m->m_data);
  201                         }
  202                         l2sc->stat.err_rx_badui++;                      
  203                         i4b_Dfreembuf(m);                       
  204                         break;
  205         }
  206 }
  207 
  208 /*---------------------------------------------------------------------------*
  209  *      build U-frame for sending
  210  *---------------------------------------------------------------------------*/
  211 struct mbuf *
  212 i4b_build_u_frame(l2_softc_t *l2sc, crbit_to_nt_t crbit, pbit_t pbit, u_char type)
  213 {
  214         struct mbuf *m;
  215         
  216         if((m = i4b_Dgetmbuf(U_FRAME_LEN)) == NULL)
  217                 return(NULL);
  218 
  219         PUTSAPI(SAPI_CCP, crbit, m->m_data[OFF_SAPI]);
  220                 
  221         PUTTEI(l2sc->tei, m->m_data[OFF_TEI]);
  222 
  223         if(pbit)
  224                 m->m_data[OFF_CNTL] = type | UPBITSET;
  225         else
  226                 m->m_data[OFF_CNTL] = type & ~UPBITSET;
  227 
  228         return(m);
  229 }
  230 
  231 /*---------------------------------------------------------------------------*
  232  *      transmit SABME command
  233  *---------------------------------------------------------------------------*/
  234 void
  235 i4b_tx_sabme(l2_softc_t *l2sc, pbit_t pbit)
  236 {
  237         struct mbuf *m;
  238 
  239         l2sc->stat.tx_sabme++;
  240         NDBGL2(L2_U_MSG, "tx SABME, tei = %d", l2sc->tei);
  241         m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, SABME);
  242         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  243 }
  244 
  245 /*---------------------------------------------------------------------------*
  246  *      transmit DM response
  247  *---------------------------------------------------------------------------*/
  248 void
  249 i4b_tx_dm(l2_softc_t *l2sc, fbit_t fbit)
  250 {
  251         struct mbuf *m;
  252 
  253         l2sc->stat.tx_dm++;     
  254         NDBGL2(L2_U_MSG, "tx DM, tei = %d", l2sc->tei);
  255         m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, DM);
  256         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  257 }
  258 
  259 /*---------------------------------------------------------------------------*
  260  *      transmit DISC command
  261  *---------------------------------------------------------------------------*/
  262 void
  263 i4b_tx_disc(l2_softc_t *l2sc, pbit_t pbit)
  264 {
  265         struct mbuf *m;
  266         
  267         l2sc->stat.tx_disc++;
  268         NDBGL2(L2_U_MSG, "tx DISC, tei = %d", l2sc->tei);
  269         m = i4b_build_u_frame(l2sc, CR_CMD_TO_NT, pbit, DISC);
  270         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  271 }
  272 
  273 /*---------------------------------------------------------------------------*
  274  *      transmit UA response
  275  *---------------------------------------------------------------------------*/
  276 void
  277 i4b_tx_ua(l2_softc_t *l2sc, fbit_t fbit)
  278 {
  279         struct mbuf *m;
  280         
  281         l2sc->stat.tx_ua++;
  282         NDBGL2(L2_U_MSG, "tx UA, tei = %d", l2sc->tei);
  283         m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, UA);
  284         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  285 }
  286 
  287 /*---------------------------------------------------------------------------*
  288  *      transmit FRMR response
  289  *---------------------------------------------------------------------------*/
  290 void
  291 i4b_tx_frmr(l2_softc_t *l2sc, fbit_t fbit)
  292 {
  293         struct mbuf *m;
  294         
  295         l2sc->stat.tx_frmr++;
  296         NDBGL2(L2_U_MSG, "tx FRMR, tei = %d", l2sc->tei);
  297         m = i4b_build_u_frame(l2sc, CR_RSP_TO_NT, fbit, FRMR);
  298         l2sc->driver->ph_data_req(l2sc->l1_token, m, MBUF_FREE);
  299 }
  300 
  301 #endif /* NI4BQ921 > 0 */

Cache object: 7023f5042583fd85c7d741af0677c7ed


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