1 /**	$MirOS: src/sys/netisdn/i4b_l3l4.h,v 1.2 2005/03/06 21:28:27 tg Exp $	*/
2 /*	$NetBSD: i4b_l3l4.h,v 1.15 2003/10/03 16:38:44 pooka Exp $	*/
3 
4 /*
5  * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  *---------------------------------------------------------------------------
29  *
30  *	i4b_l3l4.h - layer 3 / layer 4 interface
31  *
32  *---------------------------------------------------------------------------*/
33 
34 #ifndef _I4B_L3L4_H_
35 #define _I4B_L3L4_H_
36 
37 #include <sys/device.h>
38 #include <sys/timeout.h>
39 #define T303VAL	(hz*4)			/* 4 seconds timeout		*/
40 #define T305VAL	(hz*30)			/* 30 seconds timeout		*/
41 #define T308VAL	(hz*4)			/* 4 seconds timeout		*/
42 #define T309VAL	(hz*90)			/* 90 seconds timeout		*/
43 #define T310VAL	(hz*60)			/* 30-120 seconds timeout	*/
44 #define T313VAL	(hz*4)			/* 4 seconds timeout		*/
45 #define T400DEF	(hz*10)			/* 10 seconds timeout		*/
46 
47 #define MAX_BCHAN	2
48 #define N_CALL_DESC	(20*(MAX_BCHAN))	/* XXX: make resizable */
49 
50 typedef struct bchan_statistics {
51 	int outbytes;
52 	int inbytes;
53 } bchan_statistics_t;
54 
55 /*---------------------------------------------------------------------------*
56  * table of things the driver needs to know about the b channel
57  * it is connected to for data transfer
58  *---------------------------------------------------------------------------*/
59 typedef struct i4b_isdn_bchan_linktab {
60 	void* l1token;
61 	int channel;
62 	const struct isdn_l4_bchannel_functions *bchannel_driver;
63 	struct ifqueue *tx_queue;
64 	struct ifqueue *rx_queue;	/* data xfer for NON-HDLC traffic   */
65 	struct mbuf **rx_mbuf;		/* data xfer for HDLC based traffic */
66 } isdn_link_t;
67 
68 struct isdn_l4_driver_functions;
69 struct isdn_l3_driver;
70 
71 /*---------------------------------------------------------------------------*
72  *	this structure describes one call/connection on one B-channel
73  *	and all its parameters
74  *---------------------------------------------------------------------------*/
75 typedef struct call_desc
76 {
77 	u_int	cdid;			/* call descriptor id		*/
78 	int	isdnif;			/* isdn interface number	*/
79 	struct isdn_l3_driver *l3drv;
80 	int	cr;			/* call reference value		*/
81 
82 	int	crflag;			/* call reference flag		*/
83 #define CRF_ORIG	0		/* originating side		*/
84 #define CRF_DEST	1		/* destinating side		*/
85 
86 	int	channelid;		/* channel id value		*/
87 	int	channelexcl;		/* channel exclusive		*/
88 
89 	int	bprot;			/* B channel protocol BPROT_XXX */
90 
91 	int	bchan_driver_index;	/* driver to use for B channel	*/
92 	int	bchan_driver_unit;	/* unit for above driver number	*/
93 
94 	cause_t	cause_in;		/* cause value from NT	*/
95 	cause_t	cause_out;		/* cause value to NT	*/
96 
97 	int	call_state;		/* from incoming SETUP	*/
98 
99 	u_char	dst_telno[TELNO_MAX];	/* destination number	*/
100 	u_char	src_telno[TELNO_MAX];	/* source number	*/
101 	u_char	src_subaddr[SUBADDR_MAX];
102 	u_char	dest_subaddr[SUBADDR_MAX];
103 
104 	int	scr_ind;		/* screening ind for incoming call */
105 	int	prs_ind;		/* presentation ind for incoming call */
106 	int	type_plan;		/* type and plan for incoming number */
107 
108 	int	Q931state;		/* Q.931 state for call	*/
109 	int	event;			/* event to be processed */
110 
111 	int	response;		/* setup response type	*/
112 
113 	int	T303;			/* SETUP sent response timeout	*/
114 	int	T303_first_to;		/* first timeout flag		*/
115 
116 	int	T305;			/* DISC without PROG IND	*/
117 
118 	int	T308;			/* RELEASE sent response timeout*/
119 	int	T308_first_to;		/* first timeout flag		*/
120 
121 	int	T309;			/* data link disconnect timeout	*/
122 
123 	int	T310;			/* CALL PROC received		*/
124 
125 	int	T313;			/* CONNECT sent timeout		*/
126 
127 	int	T400;			/* L4 timeout */
128 
129 	isdn_link_t	*ilt;		/* isdn B channel driver/state	*/
130 	const struct isdn_l4_driver_functions *l4_driver;		/* layer 4 driver		*/
131 	void	*l4_driver_softc;					/* layer 4 driver instance	*/
132 
133 	int	dir;			/* outgoing or incoming call	*/
134 #define DIR_OUTGOING	0
135 #define DIR_INCOMING	1
136 
137 	int	timeout_active;		/* idle timeout() active flag	*/
138 
139 	struct	timeout	idle_timeout_handle;
140 	struct	timeout	T303_callout;
141 	struct	timeout	T305_callout;
142 	struct	timeout	T308_callout;
143 	struct	timeout	T309_callout;
144 	struct	timeout	T310_callout;
145 	struct	timeout	T313_callout;
146 	struct	timeout	T400_callout;
147 	int	callouts_inited;		/* must init before use */
148 
149 	int	idletime_state;		/* wait for idle_time begin	*/
150 #define IST_IDLE	0	/* shorthold mode disabled 	*/
151 #define IST_NONCHK	1	/* in non-checked window	*/
152 #define IST_CHECK	2	/* in idle check window		*/
153 #define IST_SAFE	3	/* in safety zone		*/
154 
155 	time_t	idletimechk_start;	/* check idletime window start	*/
156 	time_t	connect_time;		/* time connect was made	*/
157 	time_t	last_active_time;	/* last time with activity	*/
158 
159 					/* for incoming connections:	*/
160 	time_t	max_idle_time;		/* max time without activity	*/
161 
162 					/* for outgoing connections:	*/
163 	msg_shorthold_t shorthold_data;	/* shorthold data to use */
164 
165 	int	aocd_flag;		/* AOCD used for unitlength calc*/
166 	time_t	last_aocd_time;		/* last time AOCD received	*/
167 	int	units;			/* number of AOCD charging units*/
168 	int	units_type;		/* units type: AOCD, AOCE	*/
169 	int	cunits;			/* calculated units		*/
170 
171 	int	isdntxdelay;		/* isdn tx delay after connect	*/
172 
173 	u_char	display[DISPLAY_MAX];	/* display information element	*/
174 	char	datetime[DATETIME_MAX];	/* date/time information element*/
175 } call_desc_t;
176 
177 extern call_desc_t call_desc[];
178 extern int num_call_desc;
179 
180 /*
181  * Set of functions layer 4 drivers calls to manipulate the B channel
182  * they are using.
183  */
184 struct isdn_l4_bchannel_functions {
185 	void (*bch_config)(void*, int channel, int bprot, int updown);
186 	void (*bch_tx_start)(void*, int channel);
187 	void (*bch_stat)(void*, int channel, bchan_statistics_t *bsp);
188 };
189 
190 /*
191  * Functions a layer 4 application driver exports
192  */
193 struct isdn_l4_driver_functions {
194 	/*
195 	 * Functions for use by the B channel driver
196 	 */
197 	void (*bch_rx_data_ready)(void *softc);
198 	void (*bch_tx_queue_empty)(void *softc);
199 	void (*bch_activity)(void *softc, int rxtx);
200 #define ACT_RX 0
201 #define ACT_TX 1
202 	void (*line_connected)(void *softc, void *cde);
203 	void (*line_disconnected)(void *softc, void *cde);
204 	void (*dial_response)(void *softc, int stat, cause_t cause);
205 	void (*updown_ind)(void *softc, int updown);
206 	/*
207 	 * Functions used by the ISDN management system
208 	 */
209 	void* (*get_softc)(int unit);
210 	void (*set_linktab)(void *softc, isdn_link_t *ilt);
211 	/*
212 	 * Optional accounting function
213 	 */
214 	time_t (*get_idletime)(void* softc);
215 };
216 
217 /* global registry of layer 4 drivers */
218 int isdn_l4_driver_attach(const char *name, int units, const struct isdn_l4_driver_functions *driver);
219 int isdn_l4_driver_detatch(const char *name);
220 int isdn_l4_find_driverid(const char *name);
221 const struct isdn_l4_driver_functions *isdn_l4_find_driver(const char *name, int unit);
222 const struct isdn_l4_driver_functions *isdn_l4_get_driver(int driver_id, int unit);
223 
224 /* forward decl. */
225 struct isdn_diagnostic_request;
226 struct isdn_dr_prot;
227 
228 /*
229  * functions exported by a layer 3 driver to layer 4
230  */
231 struct isdn_l3_driver_functions {
232 	isdn_link_t* (*get_linktab)(void*, int channel);
233 	void (*set_l4_driver)(void*, int channel, const struct isdn_l4_driver_functions *l4_driver, void *l4_driver_softc);
234 
235 	void	(*N_CONNECT_REQUEST)	(struct call_desc *cd);
236 	void	(*N_CONNECT_RESPONSE)	(struct call_desc *cd, int, int);
237 	void	(*N_DISCONNECT_REQUEST)	(struct call_desc *cd, int);
238 	void	(*N_ALERT_REQUEST)	(struct call_desc *cd);
239 	int     (*N_DOWNLOAD)		(void*, int numprotos, struct isdn_dr_prot *protocols);
240 	int     (*N_DIAGNOSTICS)	(void*, struct isdn_diagnostic_request*);
241 	void	(*N_MGMT_COMMAND)	(struct isdn_l3_driver *, int cmd, void *);
242 };
243 
244 /*---------------------------------------------------------------------------*
245  *	This structure "describes" one ISDN interface (typically identical
246  * 	to one controller, but when one controller drives multiple ISDN's,
247  *	this is just one of those ISDN's).
248  *
249  *	An ISDN can be either a Basic Rate Interface (BRI, 2 B channels)
250  *	or a Primary Rate Interface (PRI, 30 B channels).
251  *---------------------------------------------------------------------------*/
252 struct isdn_l3_driver {
253 	SLIST_ENTRY(isdn_l3_driver) l3drvq;
254 	void*	l1_token;		/* softc of hardware driver, actually
255 					 * this is the l2_softc (!!) for
256 					 * passive cards, and something else
257 					 * for active cards (maybe actually
258 					 * the softc there) */
259 	int	isdnif;			/* ISDN id assigned to this */
260 	char *devname;			/* pointer to autoconf identifier */
261 					/* e.g. "isic0" or "daic0 port 2" */
262 	char *card_name;		/* type of card */
263 
264 	int	protocol;		/* D-channel protocol type */
265 
266 	int	dl_est;			/* layer 2 established	*/
267 #define DL_DOWN	0
268 #define DL_UP	1
269 
270 	int	nbch;			/* number of B channels */
271 	int	*bch_state;		/* states of the nbch B channels */
272 #define BCH_ST_FREE	0		/* free to be used, idle */
273 #define BCH_ST_RSVD	1		/* reserved, may become free or used */
274 #define BCH_ST_USED	2		/* in use for data transfer */
275 
276 	int	tei;			/* current tei or -1 if invalid */
277 
278 	/* pointers to functions to be called from L4 */
279 	const struct isdn_l3_driver_functions * l3driver;
280 };
281 
282 #define NBCH_BRI 2
283 #define NBCH_PRI 30
284 
285 void i4b_l4_contr_ev_ind(int controller, int attach);
286 struct isdn_l3_driver * isdn_attach_isdnif(const char *devname,
287     const char *cardname, void *l1_token,
288     const struct isdn_l3_driver_functions * l3driver, int nbch);
289 int isdn_detach_isdnif(struct isdn_l3_driver *);
290 void isdn_isdnif_ready(int isdnif);
291 struct isdn_l3_driver *isdn_find_l3_by_isdnif(int isdnif);
292 int isdn_count_isdnif(int *max_isdnif);
293 
294 #endif /* _I4B_Q931_H_ */
295