1998-12-27 21:47:14 +00:00
|
|
|
/*
|
2002-03-17 09:33:15 +00:00
|
|
|
* Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* i4b_l2.c - ISDN layer 2 (Q.921)
|
|
|
|
* -------------------------------
|
|
|
|
*
|
1999-12-14 20:48:35 +00:00
|
|
|
* $FreeBSD$
|
|
|
|
*
|
2002-03-17 09:33:15 +00:00
|
|
|
* last edit-date: [Sat Mar 9 16:11:14 2002]
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <machine/i4b_debug.h>
|
|
|
|
|
|
|
|
#include <i4b/include/i4b_l1l2.h>
|
|
|
|
#include <i4b/include/i4b_l2l3.h>
|
|
|
|
#include <i4b/include/i4b_mbuf.h>
|
|
|
|
#include <i4b/include/i4b_global.h>
|
|
|
|
|
|
|
|
#include <i4b/layer2/i4b_l2.h>
|
|
|
|
#include <i4b/layer2/i4b_l2fsm.h>
|
|
|
|
|
|
|
|
int i4b_dl_establish_ind(int);
|
|
|
|
int i4b_dl_establish_cnf(int);
|
|
|
|
int i4b_dl_release_ind(int);
|
|
|
|
int i4b_dl_release_cnf(int);
|
|
|
|
int i4b_dl_data_ind(int, struct mbuf *);
|
|
|
|
int i4b_dl_unit_data_ind(int, struct mbuf *);
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
static int i4b_mdl_command_req(int, int, void *);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
/* from layer 2 */
|
|
|
|
|
|
|
|
extern int i4b_mdl_status_ind(int, int, int);
|
|
|
|
|
|
|
|
/* this layers debug level */
|
|
|
|
|
|
|
|
unsigned int i4b_l2_debug = L2_DEBUG_DEFAULT;
|
|
|
|
|
|
|
|
struct i4b_l2l3_func i4b_l2l3_func = {
|
|
|
|
|
|
|
|
/* Layer 2 --> Layer 3 */
|
|
|
|
|
|
|
|
(int (*)(int)) i4b_dl_establish_ind,
|
|
|
|
(int (*)(int)) i4b_dl_establish_cnf,
|
|
|
|
(int (*)(int)) i4b_dl_release_ind,
|
|
|
|
(int (*)(int)) i4b_dl_release_cnf,
|
|
|
|
(int (*)(int, struct mbuf *)) i4b_dl_data_ind,
|
|
|
|
(int (*)(int, struct mbuf *)) i4b_dl_unit_data_ind,
|
|
|
|
|
|
|
|
/* Layer 3 --> Layer 2 */
|
|
|
|
|
|
|
|
(int (*)(int)) i4b_dl_establish_req,
|
|
|
|
(int (*)(int)) i4b_dl_release_req,
|
|
|
|
(int (*)(int, struct mbuf *)) i4b_dl_data_req,
|
|
|
|
(int (*)(int, struct mbuf *)) i4b_dl_unit_data_req,
|
|
|
|
|
|
|
|
/* Layer 2 --> Layer 3 management */
|
|
|
|
|
|
|
|
(int (*)(int, int, int)) i4b_mdl_status_ind,
|
|
|
|
|
|
|
|
/* Layer 3 --> Layer 2 management */
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
(int (*)(int, int, void *)) i4b_mdl_command_req
|
1998-12-27 21:47:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* DL_ESTABLISH_REQ from layer 3
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int i4b_dl_establish_req(int unit)
|
|
|
|
{
|
|
|
|
l2_softc_t *l2sc = &l2_softc[unit];
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_PRIM, "unit %d",unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_l1_activate(l2sc);
|
|
|
|
i4b_next_l2state(l2sc, EV_DLESTRQ);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* DL_RELEASE_REQ from layer 3
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int i4b_dl_release_req(int unit)
|
|
|
|
{
|
|
|
|
l2_softc_t *l2sc = &l2_softc[unit];
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_PRIM, "unit %d",unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_next_l2state(l2sc, EV_DLRELRQ);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* DL UNIT DATA REQUEST from Layer 3
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int i4b_dl_unit_data_req(int unit, struct mbuf *m)
|
|
|
|
{
|
|
|
|
#ifdef NOTDEF
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_PRIM, "unit %d",unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
#endif
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* DL DATA REQUEST from Layer 3
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int i4b_dl_data_req(int unit, struct mbuf *m)
|
|
|
|
{
|
|
|
|
l2_softc_t *l2sc = &l2_softc[unit];
|
1999-05-20 10:14:57 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
#ifdef NOTDEF
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_PRIM, "unit %d",unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
#endif
|
|
|
|
switch(l2sc->Q921_state)
|
|
|
|
{
|
|
|
|
case ST_AW_EST:
|
|
|
|
case ST_MULTIFR:
|
|
|
|
case ST_TIMREC:
|
|
|
|
|
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and
if_omcasts fields should only be manipulated under protection of the mutex.
IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on
the queue. An IF_LOCK macro is provided, as well as the old (mutex-less)
versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which
needs them, but their use is discouraged.
Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF,
which takes care of locking/enqueue, and also statistics updating/start
if necessary.
2000-11-25 07:35:38 +00:00
|
|
|
if(_IF_QFULL(&l2sc->i_queue))
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "i_queue full!!");
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_Dfreembuf(m);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-05-20 10:14:57 +00:00
|
|
|
CRIT_VAR;
|
|
|
|
|
|
|
|
CRIT_BEG;
|
1998-12-27 21:47:14 +00:00
|
|
|
IF_ENQUEUE(&l2sc->i_queue, m);
|
1999-05-20 10:14:57 +00:00
|
|
|
CRIT_END;
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_i_frame_queued_up(l2sc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "unit %d ERROR in state [%s], freeing mbuf", unit, i4b_print_l2state(l2sc));
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_Dfreembuf(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4b_ph_activate_ind - link activation indication from layer 1
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
i4b_ph_activate_ind(int unit)
|
|
|
|
{
|
|
|
|
l2_softc_t *l2sc = &l2_softc[unit];
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL1(L1_PRIM, "unit %d",unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
l2sc->ph_active = PH_ACTIVE;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4b_ph_deactivate_ind - link deactivation indication from layer 1
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
i4b_ph_deactivate_ind(int unit)
|
|
|
|
{
|
|
|
|
l2_softc_t *l2sc = &l2_softc[unit];
|
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL1(L1_PRIM, "unit %d",unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
l2sc->ph_active = PH_INACTIVE;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4b_l2_unit_init - place layer 2 unit into known state
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
i4b_l2_unit_init(int unit)
|
|
|
|
{
|
|
|
|
l2_softc_t *l2sc = &l2_softc[unit];
|
1999-05-20 10:14:57 +00:00
|
|
|
CRIT_VAR;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
CRIT_BEG;
|
1998-12-27 21:47:14 +00:00
|
|
|
l2sc->Q921_state = ST_TEI_UNAS;
|
|
|
|
l2sc->tei_valid = TEI_INVALID;
|
|
|
|
l2sc->vr = 0;
|
|
|
|
l2sc->vs = 0;
|
|
|
|
l2sc->va = 0;
|
|
|
|
l2sc->ack_pend = 0;
|
|
|
|
l2sc->rej_excpt = 0;
|
|
|
|
l2sc->peer_busy = 0;
|
|
|
|
l2sc->own_busy = 0;
|
|
|
|
l2sc->l3initiated = 0;
|
|
|
|
|
|
|
|
l2sc->rxd_CR = 0;
|
|
|
|
l2sc->rxd_PF = 0;
|
|
|
|
l2sc->rxd_NR = 0;
|
|
|
|
l2sc->RC = 0;
|
|
|
|
l2sc->iframe_sent = 0;
|
|
|
|
|
|
|
|
l2sc->postfsmfunc = NULL;
|
|
|
|
|
|
|
|
if(l2sc->ua_num != UA_EMPTY)
|
|
|
|
{
|
|
|
|
i4b_Dfreembuf(l2sc->ua_frame);
|
|
|
|
l2sc->ua_num = UA_EMPTY;
|
|
|
|
l2sc->ua_frame = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
i4b_T200_stop(l2sc);
|
|
|
|
i4b_T202_stop(l2sc);
|
1999-05-20 10:14:57 +00:00
|
|
|
i4b_T203_stop(l2sc);
|
|
|
|
|
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4b_mph_status_ind - status indication upward
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
i4b_mph_status_ind(int unit, int status, int parm)
|
|
|
|
{
|
|
|
|
l2_softc_t *l2sc = &l2_softc[unit];
|
1999-05-20 10:14:57 +00:00
|
|
|
CRIT_VAR;
|
1998-12-27 21:47:14 +00:00
|
|
|
int sendup = 1;
|
1999-05-20 10:14:57 +00:00
|
|
|
|
|
|
|
CRIT_BEG;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL1(L1_PRIM, "unit %d, status=%d, parm=%d", unit, status, parm);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
case STI_ATTACH:
|
|
|
|
l2sc->unit = unit;
|
|
|
|
l2sc->i_queue.ifq_maxlen = IQUEUE_MAXLEN;
|
2001-01-15 14:54:43 +00:00
|
|
|
|
2001-12-30 09:27:28 +00:00
|
|
|
if(!mtx_initialized(&l2sc->i_queue.ifq_mtx))
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&l2sc->i_queue.ifq_mtx, "i4b_l2sc", NULL, MTX_DEF);
|
2002-03-17 09:33:15 +00:00
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
l2sc->ua_frame = NULL;
|
1999-08-06 14:05:10 +00:00
|
|
|
bzero(&l2sc->stat, sizeof(lapdstat_t));
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_l2_unit_init(unit);
|
|
|
|
|
|
|
|
/* initialize the callout handles for timeout routines */
|
|
|
|
callout_handle_init(&l2sc->T200_callout);
|
|
|
|
callout_handle_init(&l2sc->T202_callout);
|
|
|
|
callout_handle_init(&l2sc->T203_callout);
|
1999-05-20 10:14:57 +00:00
|
|
|
callout_handle_init(&l2sc->IFQU_callout);
|
1998-12-27 21:47:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STI_L1STAT: /* state of layer 1 */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STI_PDEACT: /* Timer 4 expired */
|
1999-12-14 20:48:35 +00:00
|
|
|
/*XXX*/ if((l2sc->Q921_state >= ST_AW_EST) &&
|
1998-12-27 21:47:14 +00:00
|
|
|
(l2sc->Q921_state <= ST_TIMREC))
|
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "unit %d, persistent deactivation!", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_l2_unit_init(unit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendup = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STI_NOL1ACC:
|
|
|
|
i4b_l2_unit_init(unit);
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "unit %d, cannot access S0 bus!", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "ERROR, unit %d, unknown status message!", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sendup)
|
|
|
|
MDL_Status_Ind(unit, status, parm); /* send up to layer 3 */
|
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
CRIT_END;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* MDL_COMMAND_REQ from layer 3
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-10-15 20:32:45 +00:00
|
|
|
static int
|
|
|
|
i4b_mdl_command_req(int unit, int command, void * parm)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_PRIM, "unit %d, command=%d, parm=%d", unit, command, (unsigned int)parm);
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
switch(command)
|
|
|
|
{
|
|
|
|
case CMR_DOPEN:
|
|
|
|
i4b_l2_unit_init(unit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MPH_Command_Req(unit, command, parm);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4b_ph_data_ind - process a rx'd frame got from layer 1
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
i4b_ph_data_ind(int unit, struct mbuf *m)
|
|
|
|
{
|
1999-08-06 14:05:10 +00:00
|
|
|
l2_softc_t *l2sc = &l2_softc[unit];
|
1998-12-27 21:47:14 +00:00
|
|
|
#ifdef NOTDEF
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL1(L1_PRIM, "unit %d", unit);
|
1998-12-27 21:47:14 +00:00
|
|
|
#endif
|
|
|
|
u_char *ptr = m->m_data;
|
|
|
|
|
|
|
|
if ( (*(ptr + OFF_CNTL) & 0x01) == 0 )
|
|
|
|
{
|
|
|
|
if(m->m_len < 4) /* 6 oct - 2 chksum oct */
|
|
|
|
{
|
1999-08-06 14:05:10 +00:00
|
|
|
l2sc->stat.err_rx_len++;
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "ERROR, I-frame < 6 octetts!");
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_Dfreembuf(m);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
i4b_rxd_i_frame(unit, m);
|
|
|
|
}
|
|
|
|
else if ( (*(ptr + OFF_CNTL) & 0x03) == 0x01 )
|
|
|
|
{
|
|
|
|
if(m->m_len < 4) /* 6 oct - 2 chksum oct */
|
|
|
|
{
|
1999-08-06 14:05:10 +00:00
|
|
|
l2sc->stat.err_rx_len++;
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "ERROR, S-frame < 6 octetts!");
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_Dfreembuf(m);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
i4b_rxd_s_frame(unit, m);
|
|
|
|
}
|
|
|
|
else if ( (*(ptr + OFF_CNTL) & 0x03) == 0x03 )
|
|
|
|
{
|
|
|
|
if(m->m_len < 3) /* 5 oct - 2 chksum oct */
|
|
|
|
{
|
1999-08-06 14:05:10 +00:00
|
|
|
l2sc->stat.err_rx_len++;
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "ERROR, U-frame < 5 octetts!");
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_Dfreembuf(m);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
i4b_rxd_u_frame(unit, m);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-08-06 14:05:10 +00:00
|
|
|
l2sc->stat.err_rx_badf++;
|
2000-10-09 13:18:17 +00:00
|
|
|
NDBGL2(L2_ERROR, "ERROR, bad frame rx'd - ");
|
1998-12-27 21:47:14 +00:00
|
|
|
i4b_print_frame(m->m_len, m->m_data);
|
|
|
|
i4b_Dfreembuf(m);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|