File:  [DragonFly] / src / sys / net / i4b / capi / capi_llif.c
Revision 1.5: download - view: text, annotated - select for diffs
Fri Apr 16 15:40:20 2004 UTC (10 years, 4 months ago) by joerg
Branches: MAIN
CVS tags: HEAD, DragonFly_Stable, DragonFly_Snap29Sep2004, DragonFly_Snap13Sep2004, DragonFly_RELEASE_1_6_Slip, DragonFly_RELEASE_1_6, DragonFly_RELEASE_1_4_Slip, DragonFly_RELEASE_1_4, DragonFly_RELEASE_1_2_Slip, DragonFly_RELEASE_1_2, DragonFly_1_0_REL, DragonFly_1_0_RC1, DragonFly_1_0A_REL
Merge changes from FreeBSD 5:
- remove dependency on device counting
- undo massive inlining on iavc

    1: /*
    2:  * Copyright (c) 2001 Cubical Solutions Ltd. 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:  * capi/capi_llif.c	The i4b CAPI link layer interface.
   26:  *
   27:  * $FreeBSD: src/sys/i4b/capi/capi_llif.c,v 1.1.2.1 2001/08/10 14:08:34 obrien Exp $
   28:  * $DragonFly: src/sys/net/i4b/capi/capi_llif.c,v 1.5 2004/04/16 15:40:20 joerg Exp $
   29:  */
   30: 
   31: #include <sys/param.h>
   32: #include <sys/kernel.h>
   33: #include <sys/systm.h>
   34: #include <sys/mbuf.h>
   35: #include <sys/socket.h>
   36: #include <net/if.h>
   37: 
   38: #include <net/i4b/include/machine/i4b_debug.h>
   39: #include <net/i4b/include/machine/i4b_ioctl.h>
   40: #include <net/i4b/include/machine/i4b_cause.h>
   41: 
   42: #include "../include/i4b_l3l4.h"
   43: #include "../include/i4b_mbuf.h"
   44: #include "../include/i4b_global.h"
   45: #include "../layer4/i4b_l4.h"
   46: 
   47: #include "capi.h"
   48: #include "capi_msgs.h"
   49: 
   50: /*
   51: //  capi_ll_control
   52: //      CAPI link layer control routine. Called by a link layer
   53: //      driver when its state changes.
   54: */
   55: 
   56: int
   57: capi_ll_control(capi_softc_t *sc, int op, int arg)
   58: {
   59:     switch (op) {
   60:     case CAPI_CTRL_READY:
   61: 	if (arg) {
   62: 	    sc->sc_state = C_READY;
   63: 
   64: 	    /*
   65: 	     *  Register our CAPI ApplId and send CAPI_LISTEN_REQ
   66: 	     *  with CIP Mask value 1 (match all).
   67: 	     */
   68: 
   69: 	    sc->reg_appl(sc, I4BCAPI_APPLID, sc->sc_nbch);
   70: 	    capi_listen_req(sc, 0x10007);
   71: 
   72: 	} else {
   73: 	    sc->sc_state = C_DOWN;
   74: 	    /* XXX go through cds and notify L4 of pdeact? XXX */
   75: 	}
   76: 	break;
   77: 
   78:     case CAPI_CTRL_PROFILE:
   79: 	bcopy((char*) arg, &sc->sc_profile, sizeof(sc->sc_profile));
   80: 	break;
   81: 
   82:     case CAPI_CTRL_NEW_NCCI:
   83:     case CAPI_CTRL_FREE_NCCI:
   84: 	/* We ignore the controller's NCCI notifications. */
   85: 	break;
   86: 
   87:     default:
   88: 	printf("capi%d: unknown control %d\n", sc->sc_unit, op);
   89:     }
   90: 
   91:     return 0;
   92: }
   93: 
   94: /*
   95: //  i4b_capi_handlers
   96: //      Array of message-handler pairs used to dispatch CAPI
   97: //      messages sent to I4BCAPI_APPLID.
   98: */
   99: 
  100: static struct capi_cmdtab {
  101:     u_int16_t cmd;
  102:     void (*handler)(capi_softc_t *, struct mbuf *);
  103: } i4b_capi_handlers[] = {
  104:     { CAPI_LISTEN_CONF,           capi_listen_conf },
  105:     { CAPI_INFO_IND,              capi_info_ind },
  106:     { CAPI_ALERT_CONF,            capi_alert_conf },
  107:     { CAPI_CONNECT_CONF,          capi_connect_conf },
  108:     { CAPI_CONNECT_IND,           capi_connect_ind },
  109:     { CAPI_CONNECT_ACTIVE_IND,    capi_connect_active_ind },
  110:     { CAPI_CONNECT_B3_CONF,       capi_connect_b3_conf },
  111:     { CAPI_CONNECT_B3_IND,        capi_connect_b3_ind },
  112:     { CAPI_CONNECT_B3_ACTIVE_IND, capi_connect_b3_active_ind },
  113:     { CAPI_DATA_B3_CONF,          capi_data_b3_conf },
  114:     { CAPI_DATA_B3_IND,           capi_data_b3_ind },
  115:     { CAPI_DISCONNECT_B3_IND,     capi_disconnect_b3_ind },
  116:     { CAPI_DISCONNECT_CONF,       capi_disconnect_conf },
  117:     { CAPI_DISCONNECT_IND,        capi_disconnect_ind },
  118:     { 0, 0 }
  119: };
  120: 
  121: /*
  122: //  capi_ll_receive
  123: //      CAPI link layer receive upcall. Called by a link layer
  124: //      driver to dispatch incoming CAPI messages.
  125: */
  126: 
  127: int
  128: capi_ll_receive(capi_softc_t *sc, struct mbuf *m)
  129: {
  130:     u_int8_t *p = mtod(m, u_int8_t*);
  131:     u_int16_t len, applid, msgid, cmd;
  132: 
  133:     capimsg_getu16(p + 0, &len);
  134:     capimsg_getu16(p + 2, &applid);
  135:     capimsg_getu16(p + 4, &cmd);
  136:     capimsg_getu16(p + 6, &msgid);
  137: 
  138: #if 0
  139:     printf("capi%d: ll_receive hdr %04x %04x %04x %04x\n", sc->sc_unit,
  140: 	   len, applid, cmd, msgid);
  141: #endif
  142: 
  143:     if (applid == I4BCAPI_APPLID) {
  144: 	struct capi_cmdtab *e;
  145: 	for (e = i4b_capi_handlers; e->cmd && e->cmd != cmd; e++);
  146: 	if (e->cmd) (*e->handler)(sc, m);
  147: 	else printf("capi%d: unknown message %04x\n", sc->sc_unit, cmd);
  148: 
  149:     } else {
  150: 	/* XXX we could handle arbitrary ApplIds here XXX */
  151: 	printf("capi%d: message %04x for unknown applid %d\n", sc->sc_unit,
  152: 	       cmd, applid);
  153:     }
  154: 
  155:     if (m->m_next) {
  156: 	i4b_Bfreembuf(m->m_next);
  157: 	m->m_next = NULL;
  158:     }
  159:     i4b_Dfreembuf(m);
  160:     return(0);
  161: }