2001-01-05 15:49:52 +03:00
|
|
|
/*
|
|
|
|
* 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_l4if.c - Layer 3 interface to Layer 4
|
|
|
|
* -------------------------------------------
|
|
|
|
*
|
2005-02-27 01:31:44 +03:00
|
|
|
* $Id: i4b_l4if.c,v 1.18 2005/02/26 22:39:49 perry Exp $
|
2001-01-05 15:49:52 +03:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*
|
|
|
|
* last edit-date: [Fri Jan 5 11:33:47 2001]
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
2001-11-13 03:56:55 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-02-27 01:31:44 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: i4b_l4if.c,v 1.18 2005/02/26 22:39:49 perry Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
#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>
|
|
|
|
#include <machine/i4b_cause.h>
|
|
|
|
#else
|
|
|
|
#include <netisdn/i4b_debug.h>
|
|
|
|
#include <netisdn/i4b_ioctl.h>
|
|
|
|
#include <netisdn/i4b_cause.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netisdn/i4b_isdnq931.h>
|
2002-03-24 23:35:43 +03:00
|
|
|
#include <netisdn/i4b_l2.h>
|
2001-03-24 15:40:29 +03:00
|
|
|
#include <netisdn/i4b_l1l2.h>
|
2001-01-05 15:49:52 +03:00
|
|
|
#include <netisdn/i4b_l3l4.h>
|
|
|
|
#include <netisdn/i4b_mbuf.h>
|
|
|
|
#include <netisdn/i4b_global.h>
|
|
|
|
|
|
|
|
#include <netisdn/i4b_l3.h>
|
|
|
|
#include <netisdn/i4b_l3fsm.h>
|
|
|
|
#include <netisdn/i4b_q931.h>
|
|
|
|
|
|
|
|
#include <netisdn/i4b_l4.h>
|
|
|
|
|
2002-03-30 14:15:41 +03:00
|
|
|
void n_connect_request(struct call_desc *cd);
|
|
|
|
void n_connect_response(struct call_desc *cd, int response, int cause);
|
|
|
|
void n_disconnect_request(struct call_desc *cd, int cause);
|
|
|
|
void n_alert_request(struct call_desc *cd);
|
|
|
|
void n_mgmt_command(struct isdn_l3_driver *drv, int cmd, void *parm);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* i4b_mdl_status_ind - status indication from lower layers
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int
|
2002-05-21 14:31:10 +04:00
|
|
|
i4b_mdl_status_ind(struct isdn_l3_driver *d, int status, int parm)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-30 20:54:17 +03:00
|
|
|
int sendup, update_leds = 0;
|
2001-01-05 15:49:52 +03:00
|
|
|
int i;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "isdnif = %d, status = %d, parm = %d",
|
|
|
|
d->isdnif, status, parm);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
case STI_ATTACH:
|
2002-03-24 23:35:43 +03:00
|
|
|
if (parm) {
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "STI_ATTACH: attaching isdnif %d", d->isdnif);
|
2002-03-24 23:35:43 +03:00
|
|
|
} else {
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "STI_ATTACH: dettaching isdnif %d", d->isdnif);
|
2002-03-24 23:35:43 +03:00
|
|
|
}
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
2002-03-24 23:35:43 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
case STI_L1STAT:
|
2002-05-21 14:31:10 +04:00
|
|
|
i4b_l4_l12stat(d, 1, parm);
|
2002-03-30 20:54:17 +03:00
|
|
|
update_leds = 1;
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "STI_L1STAT: isdnif %d layer 1 = %s", d->isdnif, status ? "up" : "down");
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
case STI_L2STAT:
|
2002-05-21 14:31:10 +04:00
|
|
|
i4b_l4_l12stat(d, 2, parm);
|
2002-03-30 20:54:17 +03:00
|
|
|
update_leds = 1;
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "STI_L2STAT: isdnif %d layer 2 = %s", d->isdnif, status ? "up" : "down");
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STI_TEIASG:
|
2002-03-24 23:35:43 +03:00
|
|
|
d->tei = parm;
|
2002-05-21 14:31:10 +04:00
|
|
|
i4b_l4_teiasg(d, parm);
|
2002-03-30 20:54:17 +03:00
|
|
|
update_leds = 1;
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "STI_TEIASG: isdnif %d TEI = %d = 0x%02x", d->isdnif, parm, parm);
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STI_PDEACT: /* L1 T4 timeout */
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_ERR, "STI_PDEACT: isdnif %d TEI = %d = 0x%02x", d->isdnif, parm, parm);
|
2001-01-05 15:49:52 +03:00
|
|
|
|
2002-03-30 20:54:17 +03:00
|
|
|
update_leds = 1;
|
2001-01-05 15:49:52 +03:00
|
|
|
sendup = 0;
|
|
|
|
|
2002-03-24 23:35:43 +03:00
|
|
|
for(i=0; i < num_call_desc; i++)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2003-10-03 20:38:44 +04:00
|
|
|
if(call_desc[i].isdnif == d->isdnif)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
i4b_l3_stop_all_timers(&(call_desc[i]));
|
2003-09-27 02:20:12 +04:00
|
|
|
if(call_desc[i].cdid != CDID_UNUSED) {
|
2001-01-05 15:49:52 +03:00
|
|
|
sendup++;
|
2003-09-27 02:20:12 +04:00
|
|
|
call_desc[i].cdid = CDID_UNUSED;
|
|
|
|
}
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-24 23:35:43 +03:00
|
|
|
d->dl_est = DL_DOWN;
|
2003-10-03 20:38:44 +04:00
|
|
|
|
|
|
|
for (i = 0; i < d->nbch; i++)
|
|
|
|
d->bch_state[i] = BCH_ST_FREE;
|
2002-03-24 23:35:43 +03:00
|
|
|
d->tei = -1;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
if(sendup)
|
|
|
|
{
|
2002-05-21 14:31:10 +04:00
|
|
|
i4b_l4_pdeact(d, sendup);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STI_NOL1ACC: /* no outgoing access to S0 */
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_ERR, "STI_NOL1ACC: isdnif %d no outgoing access to S0", d->isdnif);
|
2002-03-30 20:54:17 +03:00
|
|
|
update_leds = 1;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
2002-03-24 23:35:43 +03:00
|
|
|
for(i=0; i < num_call_desc; i++)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2003-10-03 20:38:44 +04:00
|
|
|
if(call_desc[i].isdnif == d->isdnif)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
if(call_desc[i].cdid != CDID_UNUSED)
|
|
|
|
{
|
|
|
|
SET_CAUSE_TYPE(call_desc[i].cause_in, CAUSET_I4B);
|
|
|
|
SET_CAUSE_VAL(call_desc[i].cause_in, CAUSE_I4B_L1ERROR);
|
|
|
|
i4b_l4_disconnect_ind(&(call_desc[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-24 23:35:43 +03:00
|
|
|
d->dl_est = DL_DOWN;
|
2003-10-03 20:38:44 +04:00
|
|
|
|
|
|
|
for (i = 0; i < d->nbch; i++)
|
|
|
|
d->bch_state[i] = BCH_ST_FREE;
|
2002-03-24 23:35:43 +03:00
|
|
|
d->tei = -1;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_ERR, "ERROR, isdnif %d, unknown status value %d!", d->isdnif, status);
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
2002-03-30 20:54:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (update_leds && d != NULL)
|
|
|
|
update_controller_leds(d);
|
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-05-02 22:56:55 +04:00
|
|
|
void
|
2002-03-30 20:54:17 +03:00
|
|
|
update_controller_leds(struct isdn_l3_driver *d)
|
|
|
|
{
|
2003-05-09 01:15:13 +04:00
|
|
|
intptr_t leds = 0;
|
2002-03-30 20:54:17 +03:00
|
|
|
|
|
|
|
if (d->tei != -1)
|
|
|
|
leds |= CMRLEDS_TEI;
|
|
|
|
if (d->bch_state[CHAN_B1] != BCH_ST_FREE)
|
|
|
|
leds |= CMRLEDS_B0;
|
|
|
|
if (d->bch_state[CHAN_B2] != BCH_ST_FREE)
|
|
|
|
leds |= CMRLEDS_B1;
|
|
|
|
|
|
|
|
d->l3driver->N_MGMT_COMMAND(d, CMR_SETLEDS, (void*)leds);
|
|
|
|
}
|
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* send command to the lower layers
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-24 23:35:43 +03:00
|
|
|
void
|
2002-03-30 14:15:41 +03:00
|
|
|
n_mgmt_command(struct isdn_l3_driver *d, int cmd, void *parm)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case CMR_DOPEN:
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "CMR_DOPEN for isdnif %d", d->isdnif);
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2002-03-24 23:35:43 +03:00
|
|
|
for(i=0; i < num_call_desc; i++)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2003-10-03 20:38:44 +04:00
|
|
|
if(call_desc[i].isdnif == d->isdnif)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
call_desc[i].cdid = CDID_UNUSED;
|
|
|
|
}
|
|
|
|
}
|
2002-03-24 23:35:43 +03:00
|
|
|
d->dl_est = DL_DOWN;
|
2003-10-03 20:38:44 +04:00
|
|
|
for (i = 0; i < d->nbch; i++)
|
|
|
|
d->bch_state[i] = BCH_ST_FREE;
|
2002-03-24 23:35:43 +03:00
|
|
|
d->tei = -1;
|
2001-01-05 15:49:52 +03:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMR_DCLOSE:
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "CMR_DCLOSE for isdnif %d", d->isdnif);
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
default:
|
2003-10-03 20:38:44 +04:00
|
|
|
NDBGL3(L3_MSG, "unknown cmd %d for isdnif %d",
|
|
|
|
cmd, d->isdnif);
|
2001-01-05 15:49:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-03-30 14:15:41 +03:00
|
|
|
i4b_mdl_command_req(d, cmd, parm);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* handle connect request message from userland
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-24 23:35:43 +03:00
|
|
|
void
|
2002-03-30 14:15:41 +03:00
|
|
|
n_connect_request(struct call_desc *cd)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2005-02-27 01:31:44 +03:00
|
|
|
next_l3state(cd, EV_SETUPRQ);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* handle setup response message from userland
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-24 23:35:43 +03:00
|
|
|
void
|
2002-03-30 14:15:41 +03:00
|
|
|
n_connect_response(struct call_desc *cd, int response, int cause)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-30 14:43:33 +03:00
|
|
|
struct isdn_l3_driver *d = cd->l3drv;
|
2001-01-05 15:49:52 +03:00
|
|
|
int chstate;
|
|
|
|
|
|
|
|
T400_stop(cd);
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
cd->response = response;
|
|
|
|
cd->cause_out = cause;
|
|
|
|
|
|
|
|
switch(response)
|
|
|
|
{
|
|
|
|
case SETUP_RESP_ACCEPT:
|
|
|
|
next_l3state(cd, EV_SETACRS);
|
|
|
|
chstate = BCH_ST_USED;
|
|
|
|
break;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
case SETUP_RESP_REJECT:
|
|
|
|
next_l3state(cd, EV_SETRJRS);
|
|
|
|
chstate = BCH_ST_FREE;
|
|
|
|
break;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2001-01-05 15:49:52 +03:00
|
|
|
case SETUP_RESP_DNTCRE:
|
|
|
|
next_l3state(cd, EV_SETDCRS);
|
|
|
|
chstate = BCH_ST_FREE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* failsafe */
|
|
|
|
next_l3state(cd, EV_SETDCRS);
|
|
|
|
chstate = BCH_ST_FREE;
|
|
|
|
NDBGL3(L3_ERR, "unknown response, doing SETUP_RESP_DNTCRE");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-10-03 20:38:44 +04:00
|
|
|
if((cd->channelid >= 0) && (cd->channelid < d->nbch))
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
2002-03-24 23:35:43 +03:00
|
|
|
d->bch_state[cd->channelid] = chstate;
|
2003-09-25 18:17:57 +04:00
|
|
|
/*
|
|
|
|
* XXX: don't call l2 function for active cards
|
|
|
|
*/
|
|
|
|
if (d->l3driver->N_DOWNLOAD == NULL)
|
|
|
|
i4b_l2_channel_set_state(cd->l3drv,
|
|
|
|
cd->channelid, chstate);
|
2002-03-30 20:54:17 +03:00
|
|
|
update_controller_leds(d);
|
2001-01-05 15:49:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NDBGL3(L3_MSG, "Warning, invalid channelid %d, response = %d\n", cd->channelid, response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* handle disconnect request message from userland
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-24 23:35:43 +03:00
|
|
|
void
|
2002-03-30 14:15:41 +03:00
|
|
|
n_disconnect_request(struct call_desc *cd, int cause)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
cd->cause_out = cause;
|
|
|
|
|
|
|
|
next_l3state(cd, EV_DISCRQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* handle alert request message from userland
|
|
|
|
*---------------------------------------------------------------------------*/
|
2002-03-24 23:35:43 +03:00
|
|
|
void
|
2002-03-30 14:15:41 +03:00
|
|
|
n_alert_request(struct call_desc *cd)
|
2001-01-05 15:49:52 +03:00
|
|
|
{
|
|
|
|
next_l3state(cd, EV_ALERTRQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NI4BQ931 > 0 */
|