Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / net / i4b / capi / capi.h
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.h          The CAPI device interface.
26  *
27  * $FreeBSD: src/sys/i4b/capi/capi.h,v 1.1.2.1 2001/08/10 14:08:34 obrien Exp $
28  */
29
30 #ifndef _I4B_CAPI_H_
31 #define _I4B_CAPI_H_
32
33 /*
34 //  CAPI driver context: B channels and controller softcs.
35 */
36
37 #define INVALID -1
38
39 enum capi_b_state {
40     B_FREE,                  /* channel free, ncci invalid */
41     B_CONNECT_CONF,          /* wait for CONNECT_CONF */
42     B_CONNECT_IND,           /* IND got, wait for appl RESP */
43     B_CONNECT_ACTIVE_IND,    /* wait for CONNECT_ACTIVE_IND */
44     B_CONNECT_B3_CONF,       /* wait for CONNECT_B3_CONF */
45     B_CONNECT_B3_IND,        /* wait for CONNECT_B3_IND */
46     B_CONNECT_B3_ACTIVE_IND, /* wait for CONNECT_B3_ACTIVE_IND */
47     B_CONNECTED,             /* channel connected & in use */
48     B_DISCONNECT_CONF,       /* wait for DISCONNECT_CONF */
49     B_DISCONNECT_B3_CONF,    /* wait for DISCONNECT_B3_CONF */
50     B_DISCONNECT_IND,        /* wait for DISCONNECT_IND */
51 };
52
53 typedef struct capi_bchan
54 {
55     /* Channel state */
56
57     int ncci;
58 #define CAPI_CTRL_MASK 0x000000ff
59 #define CAPI_PLCI_MASK 0x0000ffff
60 #define CAPI_NCCI_MASK 0xffff0000
61     u_int16_t msgid;
62     int busy;
63     enum capi_b_state state;
64
65     struct ifqueue tx_queue;
66     struct ifqueue rx_queue;
67     int rxcount;
68     int txcount;
69
70     /* The rest is needed for i4b integration */
71
72     int bprot;
73     int cdid;
74
75     struct mbuf *in_mbuf;
76     isdn_link_t capi_isdn_linktab;
77     drvr_link_t *capi_drvr_linktab;
78 } capi_bchan_t;
79
80 enum capi_c_state {
81     C_DOWN,             /* controller uninitialized */
82     C_READY,            /* controller initialized but not listening */
83     C_UP,               /* controller listening */
84 };
85
86 typedef struct capi_softc {
87     int sc_unit;        /* index in capi_sc[]                      */
88     int ctrl_unit;      /* index in isdn_ctrl_tab[]                */
89     int card_type;      /* CARD_TYPEC_xxx, filled by ll driver     */
90     int sc_nbch;        /* number of b channels on this controller */
91     int sc_enabled;     /* is daemon connected TRUE/FALSE          */
92     int sc_msgid;       /* next CAPI message id                    */
93     char sc_profile[64];/* CAPI profile data                       */
94     enum capi_c_state sc_state;
95
96     capi_bchan_t sc_bchan[MAX_BCHAN];
97
98     /* Link layer driver context holder and methods */
99
100     void *ctx;
101     
102     int (*load)(struct capi_softc *, int, u_int8_t *);
103     int (*reg_appl)(struct capi_softc *, int, int);
104     int (*rel_appl)(struct capi_softc *, int);
105     int (*send)(struct capi_softc *, struct mbuf *);
106 } capi_softc_t;
107
108 extern capi_softc_t *capi_sc[];
109 extern int ncapi;
110
111 /*
112 //  CAPI upcalls for the link layer.
113 */
114
115 #define I4BCAPI_APPLID 1
116
117 extern int capi_ll_attach(capi_softc_t *);
118 extern int capi_ll_control(capi_softc_t *, int op, int arg);
119
120 #define CAPI_CTRL_READY     0 /* ctrl ready, value=TRUE/FALSE */
121 #define CAPI_CTRL_PROFILE   1 /* set CAPI profile             */
122 #define CAPI_CTRL_NEW_NCCI  2 /* new ncci value, assign bchan */
123 #define CAPI_CTRL_FREE_NCCI 3 /* free ncci value, clear bchan */
124
125 extern int capi_ll_receive(capi_softc_t *, struct mbuf *);
126
127 extern int capi_start_tx(capi_softc_t *, int bchan);
128
129 #endif /* _I4B_CAPI_H_ */