Ignore files generated in the dependency checks.
[libpri-bristuff.git] / pri_internal.h
blob3d5379759cfee973116ba91b139cce64c231e0dc
1 /*
2 * libpri: An implementation of Primary Rate ISDN
4 * Written by Mark Spencer <markster@digium.com>
6 * Copyright (C) 2001, Digium, Inc.
7 * All Rights Reserved.
8 * Copyright (C) 2003-2006 Junghanns.NET GmbH
9 * Klaus-Peter Junghanns <kpj@junghanns.net>
13 * See http://www.asterisk.org for more information about
14 * the Asterisk project. Please do not directly contact
15 * any of the maintainers of this project for assistance;
16 * the project provides a web site, mailing lists and IRC
17 * channels for your use.
19 * This program is free software, distributed under the terms of
20 * the GNU General Public License Version 2 as published by the
21 * Free Software Foundation. See the LICENSE file included with
22 * this program for more details.
25 #ifndef _PRI_INTERNAL_H
26 #define _PRI_INTERNAL_H
28 #include <stddef.h>
29 #include <sys/time.h>
31 #define DBGHEAD __FILE__ ":%d %s: "
32 #define DBGINFO __LINE__,__PRETTY_FUNCTION__
34 struct pri_sched {
35 struct timeval when;
36 void (*callback)(void *data);
37 void (*callback2)(void *data, int);
38 void *data;
39 char hasdata2;
40 int data2;
43 struct q921_frame;
44 enum q931_state;
45 enum q931_mode;
47 /* No more than 128 scheduled events */
48 /* XXX is this sufficient for nfs ??? */
49 #define MAX_SCHED 128
51 /* this can be freely configured to support more devices .... ok, 63 would be max! */
52 #define Q921_MAX_TEIS 16
54 /* dynamically allocated TEIs start here */
55 #define Q921_TEI_BASE 64
57 #define MAX_TIMERS 32
59 struct pri {
60 int fd; /* File descriptor for D-Channel */
61 pri_io_cb read_func; /* Read data callback */
62 pri_io_cb write_func; /* Write data callback */
63 void *userdata;
64 struct pri *subchannel; /* Sub-channel if appropriate */
65 struct pri *master; /* Master channel if appropriate */
66 struct pri_sched pri_sched[MAX_SCHED]; /* Scheduled events */
67 int debug; /* Debug stuff */
68 int debugfd;
69 int state; /* State of D-channel */
70 int switchtype; /* Switch type */
71 int nsf; /* Network-Specific Facility (if any) */
72 int localtype; /* Local network type (unknown, network, cpe) */
73 int remotetype; /* Remote network type (unknown, network, cpe) */
75 int sapi;
76 int tei;
77 int protodisc;
78 unsigned int bri:1;
79 unsigned int acceptinbanddisconnect:1; /* Should we allow inband progress after DISCONNECT? */
81 /* Q.921 State */
82 int q921_state[Q921_MAX_TEIS];
83 char dchanup;
85 /* TEI registry */
86 char q921_teis[Q921_MAX_TEIS];
88 char q921_tei_check[Q921_MAX_TEIS];
89 unsigned short q921_tei_check_ri[Q921_MAX_TEIS];
91 unsigned int ri;
93 int busy[Q921_MAX_TEIS]; /* Peer is busy */
95 int window[Q921_MAX_TEIS]; /* Max window size */
96 int windowlen[Q921_MAX_TEIS]; /* Fullness of window */
97 int v_s[Q921_MAX_TEIS]; /* Next N(S) for transmission */
98 int v_a[Q921_MAX_TEIS]; /* Last acknowledged frame */
99 int v_r[Q921_MAX_TEIS]; /* Next frame expected to be received */
100 int v_na[Q921_MAX_TEIS]; /* What we've told our peer we've acknowledged */
101 int solicitfbit[Q921_MAX_TEIS]; /* Have we sent an I or S frame with the F-bit set? */
102 int retrans[Q921_MAX_TEIS]; /* Retransmissions */
103 int sabme_retrans[Q921_MAX_TEIS]; /* Retransmissions */
105 int sentrej[Q921_MAX_TEIS]; /* Are we in reject state */
107 /* Various timers */
108 int sabme_timer[Q921_MAX_TEIS];
109 int t203_timer[Q921_MAX_TEIS];
110 int t202_timer[Q921_MAX_TEIS];
112 int t201_timer[Q921_MAX_TEIS];
113 int t200_timer[Q921_MAX_TEIS];
116 int cref; /* Next call reference value */
118 /* All ISDN Timer values */
119 int timers[MAX_TIMERS];
121 /* Used by scheduler */
122 struct timeval tv;
123 int schedev;
124 pri_event ev; /* Static event thingy */
126 /* Q.921 (Re)transmission queue */
127 struct q921_frame *txqueue[Q921_MAX_TEIS];
129 /* Q.931 calls */
130 q931_call **callpool;
131 q931_call *localpool;
133 /* do we do overlap dialing */
134 int overlapdial;
136 #ifdef LIBPRI_COUNTERS
137 /* q921/q931 packet counters */
138 unsigned int q921_txcount;
139 unsigned int q921_rxcount;
140 unsigned int q931_txcount;
141 unsigned int q931_rxcount;
142 #endif
144 unsigned char last_invoke; /* Last ROSE invoke ID */
145 unsigned char sendfacility;
147 int span; /* our fellow pri lives on this zaptel span */
151 struct pri_sr {
152 int transmode;
153 int channel;
154 int exclusive;
155 int nonisdn;
156 char *caller;
157 int callerplan;
158 int callerplanani;
159 char *callername;
160 int callerpres;
161 char *called;
162 int calledplan;
163 int userl1;
164 int numcomplete;
165 char *redirectingnum;
166 int redirectingplan;
167 int redirectingpres;
168 int redirectingreason;
169 int justsignalling;
170 const char *useruserinfo;
171 char *llc;
172 int transferable;
175 /* Internal switch types */
176 #define PRI_SWITCH_GR303_EOC_PATH 19
177 #define PRI_SWITCH_GR303_TMC_SWITCHING 20
179 struct apdu_event {
180 int message; /* What message to send the ADPU in */
181 void (*callback)(void *data); /* Callback function for when response is received */
182 void *data; /* Data to callback */
183 unsigned char apdu[255]; /* ADPU to send */
184 int apdu_len; /* Length of ADPU */
185 int sent; /* Have we been sent already? */
186 struct apdu_event *next; /* Linked list pointer */
189 /* q931_call datastructure */
191 struct q931_call {
192 struct pri *pri; /* PRI */
193 int cr; /* Call Reference */
194 int forceinvert; /* Force inversion of call number even if 0 */
195 q931_call *next;
196 /* Slotmap specified (bitmap of channels 31/24-1) (Channel Identifier IE) (-1 means not specified) */
197 int slotmap;
198 /* An explicit channel (Channel Identifier IE) (-1 means not specified) */
199 int channelno;
200 /* An explicit DS1 (-1 means not specified) */
201 int ds1no;
202 /* Whether or not the ds1 is explicitly identified or implicit. If implicit
203 the bchan is on the same span as the current active dchan (NFAS) */
204 int ds1explicit;
205 /* Channel flags (0 means none retrieved) */
206 int chanflags;
208 int alive; /* Whether or not the call is alive */
209 int acked; /* Whether setup has been acked or not */
210 int con_acked; /* Whether CONNECT has been CONNECT_ACKNOWLEDGEd or not */
211 int sendhangupack; /* Whether or not to send a hangup ack */
212 int proc; /* Whether we've sent a call proceeding / alerting */
213 int alert; /* Whether we've sent an alerting */
215 int tei;
216 q921_call *phones;
218 int ri; /* Restart Indicator (Restart Indicator IE) */
220 /* Bearer Capability */
221 int transcapability;
222 int transmoderate;
223 int transmultiple;
224 int userl1;
225 int userl2;
226 int userl3;
227 int rateadaption;
229 int sentchannel;
230 int justsignalling; /* for a signalling-only connection */
232 int progcode; /* Progress coding */
233 int progloc; /* Progress Location */
234 int progress; /* Progress indicator */
235 int progressmask; /* Progress Indicator bitmask */
237 int notify; /* Notification */
239 int causecode; /* Cause Coding */
240 int causeloc; /* Cause Location */
241 int cause; /* Cause of clearing */
243 int peercallstate; /* Call state of peer as reported */
244 int ourcallstate; /* Our call state */
245 int sugcallstate; /* Status call state */
247 int callerplan;
248 int callerplanani;
249 int callerpres; /* Caller presentation */
250 char callerani[256]; /* Caller */
251 char callernum[256];
252 char callername[256];
253 int callerplanuser;
254 int callerpresuser;
256 char keypad_digits[64]; /* Buffer for digits that come in KEYPAD_FACILITY */
258 int ani2; /* ANI II */
260 int calledplan;
261 int nonisdn;
262 char callednum[256]; /* Called Number */
263 int complete; /* no more digits coming */
264 int newcall; /* if the received message has a new call reference value */
266 int retranstimer; /* Timer for retransmitting DISC */
267 int t308_timedout; /* Whether t308 timed out once */
269 int redirectingplan;
270 int redirectingpres;
271 int redirectingreason;
272 char redirectingnum[256]; /* Number of redirecting party */
273 char redirectingname[256]; /* Name of redirecting party */
275 int t303timer;
276 int t303running;
278 /* Filled in cases of multiple diversions */
279 int origcalledplan;
280 int origcalledpres;
281 int origredirectingreason; /* Original reason for redirect (in cases of multiple redirects) */
282 char origcalledname[256]; /* Original name of person being called */
283 char origcallednum[256]; /* Orignal number of person being called */
285 int useruserprotocoldisc;
286 char useruserinfo[256];
287 char callingsubaddr[256]; /* Calling parties sub address */
289 char callid[10]; /* call identity for SUSPEND/RESUME */
290 char digits[256]; /* additional digits received via info msgs (cpn or keypad) */
291 char display[256]; /* display ie received in info msgs or for sending */
293 /* euroisdn facility fun */
294 int facility; /* FACILTIY received */
295 int aoc;
297 long aoc_units; /* Advice of Charge Units */
299 struct apdu_event *apdus; /* APDU queue for call */
301 char llc[16]; /* low layer compatibility */
302 int transferable;
303 unsigned int rlt_call_id; /* RLT call id */
306 extern int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), void *data);
308 extern int pri_schedule_event2(struct pri *pri, int ms, void (*function)(void *data, int data2), void *data, int data2);
310 extern pri_event *pri_schedule_run(struct pri *pri);
312 extern void pri_schedule_del(struct pri *pri, int ev);
314 extern pri_event *pri_mkerror(struct pri *pri, char *errstr);
316 extern void pri_message(struct pri *pri, char *fmt, ...);
318 extern void pri_error(struct pri *pri, char *fmt, ...);
320 void libpri_copy_string(char *dst, const char *src, size_t size);
322 #endif