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