NetBSD/sys/netisdn/i4b_l1l2.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

84 lines
2.8 KiB
C

/* $NetBSD: i4b_l1l2.c,v 1.1 2001/03/24 12:40:31 martin Exp $ */
/*
* Copyright (c) 2001 Martin Husemann. 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.
*
*/
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <net/if.h>
#include <sys/callout.h>
#include <netisdn/i4b_debug.h>
#include <netisdn/i4b_ioctl.h>
#include <netisdn/i4b_global.h>
#include <netisdn/i4b_l1l2.h>
#include <netisdn/i4b_l2.h>
#include <netisdn/i4b_trace.h>
static SIMPLEQ_HEAD(, l2_softc) bri_list = SIMPLEQ_HEAD_INITIALIZER(bri_list);
static int next_bri = 0;
/* Attach a new BRI and return it's layer 2 token. */
isdn_layer2token
isdn_attach_layer1_bri(isdn_layer1token l1sc,
const char * device_name,
const char * human_readable_name,
const struct isdn_layer1_bri_driver * drv)
{
struct l2_softc *l2sc;
l2sc = malloc(sizeof(struct l2_softc), M_DEVBUF, 0);
memset(l2sc, 0, sizeof(struct l2_softc));
l2sc->l1_token = l1sc;
l2sc->driver = drv;
l2sc->bri = next_bri++;
SIMPLEQ_INSERT_HEAD(&bri_list, l2sc, briq);
printf("BRI %d at %s: %s\n", l2sc->bri, device_name, human_readable_name);
isdn_layer2_status_ind(l2sc, STI_ATTACH, 1 /* lying about cardtype for now */ );
return l2sc;
}
/* Detach a BRI. */
int
isdn_detach_layer1_bri(isdn_layer2token l2sc)
{
/* XXX - not yet implemented */
return 0;
}
/* this function will go away once we have all inter-layer interfaces straight */
isdn_layer2token isdn_find_l2_by_bri(int bri)
{
struct l2_softc *sc;
SIMPLEQ_FOREACH(sc, &bri_list, briq)
if (sc->bri == bri)
return sc;
return NULL;
}