NetBSD/sys/netisdn/i4b_l3timer.c
martin 5171d409a5 First step to cleanup the hardware driver <-> upper layers interface.
This now provides slightly more functionality than the FreeBSD layer1-newbus
interface. It was meant to be a simple change to one header and a few
c files, but the change rippled all through various stuff.

To prevent a change to the kernel<->userland interface right now the kernel
is now lying about card types to userland (but who cares). This will be fixed
when the userland interface changes, after layer 3 <-> layer 4 has been
fixed.

Functional changes:

Provide a clean interface for hardware drivers to attach to the upper
layers. This will need another small change in the B-channel handling
when a similar change to the layer 3 <-> layer 4 interface happens.

Avoid passing indices into global arrays of pointers around, instead pass
the pointers itself. Don't code hardware driver types by predefined magic
numbers (think LKM). Prepare for detachable drivers (think pcmcia).

While there remove some sets of function pointers always pointing to the
same function (meant to be the configurable set of D channel protocol
handlers). It is unlikely another supported D-channel protocol will fit into
that (maximal layer interface) abstraction. When we get support for another
protocol, we will need to come up with a workable interface. Besides, the
old implementation was, uhm, strange.
2001-03-24 12:40:29 +00:00

353 lines
9.3 KiB
C

/*
* Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
*
* 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_l3timer.c - timer and timeout handling for layer 3
* ------------------------------------------------------
*
* $Id: i4b_l3timer.c,v 1.3 2001/03/24 12:40:32 martin Exp $
*
* $FreeBSD$
*
* last edit-date: [Fri Jan 5 11:33:47 2001]
*
*---------------------------------------------------------------------------*/
#ifdef __FreeBSD__
#include "i4bq931.h"
#else
#define NI4BQ931 1
#endif
#if NI4BQ931 > 0
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <net/if.h>
#if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
#include <sys/callout.h>
#endif
#ifdef __FreeBSD__
#include <machine/i4b_debug.h>
#include <machine/i4b_ioctl.h>
#else
#include <netisdn/i4b_debug.h>
#include <netisdn/i4b_ioctl.h>
#endif
#include <netisdn/i4b_global.h>
#include <netisdn/i4b_isdnq931.h>
#include <netisdn/i4b_l3l4.h>
#include <netisdn/i4b_mbuf.h>
#include <netisdn/i4b_l3.h>
#include <netisdn/i4b_l3fsm.h>
#include <netisdn/i4b_q931.h>
#include <netisdn/i4b_l4.h>
/*---------------------------------------------------------------------------*
* stop all layer 3 timers
*---------------------------------------------------------------------------*/
void i4b_l3_stop_all_timers(call_desc_t *cd)
{
T303_stop(cd);
T305_stop(cd);
T308_stop(cd);
T309_stop(cd);
T310_stop(cd);
T313_stop(cd);
}
/*---------------------------------------------------------------------------*
* timer T303 timeout function
*---------------------------------------------------------------------------*/
static void
T303_timeout(call_desc_t *cd)
{
NDBGL3(L3_T_ERR, "SETUP not answered, cr = %d", cd->cr);
next_l3state(cd, EV_T303EXP);
}
/*---------------------------------------------------------------------------*
* timer T303 start
*---------------------------------------------------------------------------*/
void
T303_start(call_desc_t *cd)
{
if (cd->T303 == TIMER_ACTIVE)
return;
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
cd->T303 = TIMER_ACTIVE;
START_TIMER(cd->T303_callout, T303_timeout, cd, T303VAL);
}
/*---------------------------------------------------------------------------*
* timer T303 stop
*---------------------------------------------------------------------------*/
void
T303_stop(call_desc_t *cd)
{
int s;
s = splnet();
if(cd->T303 != TIMER_IDLE)
{
STOP_TIMER(cd->T303_callout, T303_timeout, cd);
cd->T303 = TIMER_IDLE;
}
splx(s);
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
}
/*---------------------------------------------------------------------------*
* timer T305 timeout function
*---------------------------------------------------------------------------*/
static void
T305_timeout(call_desc_t *cd)
{
NDBGL3(L3_T_ERR, "DISC not answered, cr = %d", cd->cr);
next_l3state(cd, EV_T305EXP);
}
/*---------------------------------------------------------------------------*
* timer T305 start
*---------------------------------------------------------------------------*/
void
T305_start(call_desc_t *cd)
{
if (cd->T305 == TIMER_ACTIVE)
return;
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
cd->T305 = TIMER_ACTIVE;
START_TIMER(cd->T305_callout, T305_timeout, cd, T305VAL);
}
/*---------------------------------------------------------------------------*
* timer T305 stop
*---------------------------------------------------------------------------*/
void
T305_stop(call_desc_t *cd)
{
int s;
s = splnet();
if(cd->T305 != TIMER_IDLE)
{
STOP_TIMER(cd->T305_callout, T305_timeout, cd);
cd->T305 = TIMER_IDLE;
}
splx(s);
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
}
/*---------------------------------------------------------------------------*
* timer T308 timeout function
*---------------------------------------------------------------------------*/
static void
T308_timeout(call_desc_t *cd)
{
NDBGL3(L3_T_ERR, "REL not answered, cr = %d", cd->cr);
next_l3state(cd, EV_T308EXP);
}
/*---------------------------------------------------------------------------*
* timer T308 start
*---------------------------------------------------------------------------*/
void
T308_start(call_desc_t *cd)
{
if(cd->T308 == TIMER_ACTIVE)
return;
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
cd->T308 = TIMER_ACTIVE;
START_TIMER(cd->T308_callout, T308_timeout, cd, T308VAL);
}
/*---------------------------------------------------------------------------*
* timer T308 stop
*---------------------------------------------------------------------------*/
void
T308_stop(call_desc_t *cd)
{
int s;
s = splnet();
if(cd->T308 != TIMER_IDLE)
{
STOP_TIMER(cd->T308_callout, T308_timeout, cd);
cd->T308 = TIMER_IDLE;
}
splx(s);
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
}
/*---------------------------------------------------------------------------*
* timer T309 timeout function
*---------------------------------------------------------------------------*/
static void
T309_timeout(call_desc_t *cd)
{
NDBGL3(L3_T_ERR, "datalink not reconnected, cr = %d", cd->cr);
next_l3state(cd, EV_T309EXP);
}
/*---------------------------------------------------------------------------*
* timer T309 start
*---------------------------------------------------------------------------*/
void
T309_start(call_desc_t *cd)
{
if (cd->T309 == TIMER_ACTIVE)
return;
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
cd->T309 = TIMER_ACTIVE;
START_TIMER(cd->T309_callout, T309_timeout, cd, T309VAL);
}
/*---------------------------------------------------------------------------*
* timer T309 stop
*---------------------------------------------------------------------------*/
void
T309_stop(call_desc_t *cd)
{
int s;
s = splnet();
if(cd->T309 != TIMER_IDLE)
{
STOP_TIMER(cd->T309_callout, T309_timeout, cd);
cd->T309 = TIMER_IDLE;
}
splx(s);
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
}
/*---------------------------------------------------------------------------*
* timer T310 timeout function
*---------------------------------------------------------------------------*/
static void
T310_timeout(call_desc_t *cd)
{
NDBGL3(L3_T_ERR, "CALL PROC timeout, cr = %d", cd->cr);
next_l3state(cd, EV_T310EXP);
}
/*---------------------------------------------------------------------------*
* timer T310 start
*---------------------------------------------------------------------------*/
void
T310_start(call_desc_t *cd)
{
if (cd->T310 == TIMER_ACTIVE)
return;
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
cd->T310 = TIMER_ACTIVE;
START_TIMER(cd->T310_callout, T310_timeout, cd, T310VAL);
}
/*---------------------------------------------------------------------------*
* timer T310 stop
*---------------------------------------------------------------------------*/
void
T310_stop(call_desc_t *cd)
{
int s;
s = splnet();
if(cd->T310 != TIMER_IDLE)
{
STOP_TIMER(cd->T310_callout, T310_timeout, cd);
cd->T310 = TIMER_IDLE;
}
splx(s);
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
}
/*---------------------------------------------------------------------------*
* timer T313 timeout function
*---------------------------------------------------------------------------*/
static void
T313_timeout(call_desc_t *cd)
{
NDBGL3(L3_T_ERR, "CONN ACK not received, cr = %d", cd->cr);
next_l3state(cd, EV_T313EXP);
}
/*---------------------------------------------------------------------------*
* timer T313 start
*---------------------------------------------------------------------------*/
void
T313_start(call_desc_t *cd)
{
if (cd->T313 == TIMER_ACTIVE)
return;
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
cd->T313 = TIMER_ACTIVE;
START_TIMER(cd->T313_callout, T313_timeout, cd, T313VAL);
}
/*---------------------------------------------------------------------------*
* timer T313 stop
*---------------------------------------------------------------------------*/
void
T313_stop(call_desc_t *cd)
{
int s;
s = splnet();
if(cd->T313 != TIMER_IDLE)
{
cd->T313 = TIMER_IDLE;
STOP_TIMER(cd->T313_callout, T313_timeout, cd);
}
splx(s);
NDBGL3(L3_T_MSG, "cr = %d", cd->cr);
}
#endif /* NI4BQ931 > 0 */