2 * libpri: An implementation of Primary Rate ISDN
4 * Written by Mark Spencer <markster@digium.com>
6 * Copyright (C) 2001, Digium, Inc.
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
31 #define DBGHEAD __FILE__ ":%d %s: "
32 #define DBGINFO __LINE__,__PRETTY_FUNCTION__
36 void (*callback
)(void *data
);
37 void (*callback2
)(void *data
, int);
47 /* No more than 128 scheduled events */
48 /* XXX is this sufficient for nfs ??? */
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
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 */
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 */
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) */
79 unsigned int acceptinbanddisconnect
:1; /* Should we allow inband progress after DISCONNECT? */
82 int q921_state
[Q921_MAX_TEIS
];
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
];
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 */
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 */
124 pri_event ev
; /* Static event thingy */
126 /* Q.921 (Re)transmission queue */
127 struct q921_frame
*txqueue
[Q921_MAX_TEIS
];
130 q931_call
**callpool
;
131 q931_call
*localpool
;
133 /* do we do overlap dialing */
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
;
144 unsigned char last_invoke
; /* Last ROSE invoke ID */
145 unsigned char sendfacility
;
147 int span
; /* our fellow pri lives on this zaptel span */
165 char *redirectingnum
;
168 int redirectingreason
;
170 const char *useruserinfo
;
175 /* Internal switch types */
176 #define PRI_SWITCH_GR303_EOC_PATH 19
177 #define PRI_SWITCH_GR303_TMC_SWITCHING 20
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 */
192 struct pri
*pri
; /* PRI */
193 int cr
; /* Call Reference */
194 int forceinvert
; /* Force inversion of call number even if 0 */
196 /* Slotmap specified (bitmap of channels 31/24-1) (Channel Identifier IE) (-1 means not specified) */
198 /* An explicit channel (Channel Identifier IE) (-1 means not specified) */
200 /* An explicit DS1 (-1 means not specified) */
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) */
205 /* Channel flags (0 means none retrieved) */
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 */
218 int ri
; /* Restart Indicator (Restart Indicator IE) */
220 /* Bearer Capability */
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 */
249 int callerpres
; /* Caller presentation */
250 char callerani
[256]; /* Caller */
252 char callername
[256];
256 char keypad_digits
[64]; /* Buffer for digits that come in KEYPAD_FACILITY */
258 int ani2
; /* ANI II */
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 */
271 int redirectingreason
;
272 char redirectingnum
[256]; /* Number of redirecting party */
273 char redirectingname
[256]; /* Name of redirecting party */
278 /* Filled in cases of multiple diversions */
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 */
297 long aoc_units
; /* Advice of Charge Units */
299 struct apdu_event
*apdus
; /* APDU queue for call */
301 char llc
[16]; /* low layer compatibility */
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
);