libpri.h 27.9 KB
Newer Older
Mark Spencer's avatar
Mark Spencer committed
1 2 3
/*
 * libpri: An implementation of Primary Rate ISDN
 *
4
 * Written by Mark Spencer <markster@digium.com>
Mark Spencer's avatar
Mark Spencer committed
5
 *
6
 * Copyright (C) 2001, Digium, Inc.
Mark Spencer's avatar
Mark Spencer committed
7
 * All Rights Reserved.
8 9 10 11 12 13 14 15
 */

/*
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
Mark Spencer's avatar
Mark Spencer committed
16
 *
17 18 19 20
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2 as published by the
 * Free Software Foundation. See the LICENSE file included with
 * this program for more details.
Mark Spencer's avatar
Mark Spencer committed
21
 *
22 23 24 25 26 27
 * In addition, when this program is distributed with Asterisk in
 * any form that would qualify as a 'combined work' or as a
 * 'derivative work' (but not mere aggregation), you can redistribute
 * and/or modify the combination under the terms of the license
 * provided with that copy of Asterisk, instead of the license
 * terms granted here.
Mark Spencer's avatar
Mark Spencer committed
28
 */
29 30 31 32 33 34 35 36

/*
 * NOTE:
 * All new global identifiers that are added to this file MUST be
 * prefixed with PRI_ or pri_ to indicate that they are part of this
 * library and to reduce potential naming conflicts.
 */

Mark Spencer's avatar
Mark Spencer committed
37 38
#ifndef _LIBPRI_H
#define _LIBPRI_H
Mark Spencer's avatar
Mark Spencer committed
39 40 41 42 43 44 45 46 47 48 49 50

/* Node types */
#define PRI_NETWORK		1
#define PRI_CPE			2

/* Debugging */
#define PRI_DEBUG_Q921_RAW		(1 << 0)	/* Show raw HDLC frames */
#define PRI_DEBUG_Q921_DUMP		(1 << 1)	/* Show each interpreted Q.921 frame */
#define PRI_DEBUG_Q921_STATE 	(1 << 2)	/* Debug state machine changes */
#define PRI_DEBUG_CONFIG		(1 << 3) 	/* Display error events on stdout */
#define PRI_DEBUG_Q931_DUMP		(1 << 5)	/* Show interpreted Q.931 frames */
#define PRI_DEBUG_Q931_STATE	(1 << 6)	/* Debug Q.931 state machine changes */
Mark Spencer's avatar
Mark Spencer committed
51
#define	PRI_DEBUG_Q931_ANOMALY 	(1 << 7)	/* Show unexpected events */
52 53
#define PRI_DEBUG_APDU			(1 << 8)	/* Debug of APDU components such as ROSE */
#define PRI_DEBUG_AOC			(1 << 9)	/* Debug of Advice of Charge ROSE Messages */
Mark Spencer's avatar
Mark Spencer committed
54 55 56 57

#define PRI_DEBUG_ALL			(0xffff)	/* Everything */

/* Switch types */
Mark Spencer's avatar
Mark Spencer committed
58 59 60 61 62
#define PRI_SWITCH_UNKNOWN 		0
#define PRI_SWITCH_NI2	   		1	/* National ISDN 2 */
#define PRI_SWITCH_DMS100		2	/* DMS 100 */
#define PRI_SWITCH_LUCENT5E		3	/* Lucent 5E */
#define PRI_SWITCH_ATT4ESS		4	/* AT&T 4ESS */
63 64
#define PRI_SWITCH_EUROISDN_E1		5	/* Standard EuroISDN (CTR4, ETSI 300-102) */
#define PRI_SWITCH_EUROISDN_T1		6	/* T1 EuroISDN variant (ETSI 300-102) */
65
#define PRI_SWITCH_NI1			7	/* National ISDN 1 */
66 67
#define PRI_SWITCH_GR303_EOC		8	/* GR-303 Embedded Operations Channel */
#define PRI_SWITCH_GR303_TMC		9	/* GR-303 Timeslot Management Channel */
68
#define PRI_SWITCH_QSIG			10	/* QSIG Switch */
69
/* Switchtypes 11 - 20 are reserved for internal use */
70

Mark Spencer's avatar
Mark Spencer committed
71 72

/* PRI D-Channel Events */
73
#define PRI_EVENT_DCHAN_UP		 1	/* D-channel is up */
74
#define PRI_EVENT_DCHAN_DOWN	 2	/* D-channel is down */
75 76
#define PRI_EVENT_RESTART		 3	/* B-channel is restarted */
#define PRI_EVENT_CONFIG_ERR 	 4	/* Configuration Error Detected */
77 78 79 80
#define PRI_EVENT_RING			 5	/* Incoming call (SETUP) */
#define PRI_EVENT_HANGUP		 6	/* Call got hung up (RELEASE/RELEASE_COMPLETE/other) */
#define PRI_EVENT_RINGING		 7	/* Call is ringing (ALERTING) */
#define PRI_EVENT_ANSWER		 8	/* Call has been answered (CONNECT) */
81
#define PRI_EVENT_HANGUP_ACK	 9	/* Call hangup has been acknowledged */
82
#define PRI_EVENT_RESTART_ACK	10	/* Restart complete on a given channel (RESTART_ACKNOWLEDGE) */
83
#define PRI_EVENT_FACNAME		11	/* Caller*ID Name received on Facility */
84 85
#define PRI_EVENT_INFO_RECEIVED 12	/* Additional info (digits) received (INFORMATION) */
#define PRI_EVENT_PROCEEDING	13	/* When we get CALL_PROCEEDING */
86
#define PRI_EVENT_SETUP_ACK		14	/* When we get SETUP_ACKNOWLEDGE */
87 88 89 90
#define PRI_EVENT_HANGUP_REQ	15	/* Requesting the higher layer to hangup (DISCONNECT) */
#define PRI_EVENT_NOTIFY		16	/* Notification received (NOTIFY) */
#define PRI_EVENT_PROGRESS		17	/* When we get PROGRESS */
#define PRI_EVENT_KEYPAD_DIGIT	18	/* When we receive during ACTIVE state (INFORMATION) */
91 92
#define PRI_EVENT_SERVICE       19	/* SERVICE maintenance message */
#define PRI_EVENT_SERVICE_ACK   20	/* SERVICE maintenance acknowledgement message */
Mark Spencer's avatar
Mark Spencer committed
93 94 95 96 97

/* Simple states */
#define PRI_STATE_DOWN		0
#define PRI_STATE_UP		1

98 99 100 101 102 103 104 105 106 107 108 109
#define PRI_PROGRESS_MASK

/* Progress indicator values */
#define PRI_PROG_CALL_NOT_E2E_ISDN						(1 << 0)
#define PRI_PROG_CALLED_NOT_ISDN						(1 << 1)
#define PRI_PROG_CALLER_NOT_ISDN						(1 << 2)
#define PRI_PROG_INBAND_AVAILABLE						(1 << 3)
#define PRI_PROG_DELAY_AT_INTERF						(1 << 4)
#define PRI_PROG_INTERWORKING_WITH_PUBLIC				(1 << 5)
#define PRI_PROG_INTERWORKING_NO_RELEASE				(1 << 6)
#define PRI_PROG_INTERWORKING_NO_RELEASE_PRE_ANSWER		(1 << 7)
#define PRI_PROG_INTERWORKING_NO_RELEASE_POST_ANSWER	(1 << 8)
110
#define PRI_PROG_CALLER_RETURNED_TO_ISDN					(1 << 9)
111

Mark Spencer's avatar
Mark Spencer committed
112
/* Numbering plan identifier */
113 114 115 116 117 118 119
#define PRI_NPI_UNKNOWN					0x0 /*!< Unknown numbering plan */
#define PRI_NPI_E163_E164				0x1 /*!< ISDN/telephony numbering plan (public) */
#define PRI_NPI_X121					0x3 /*!< Data numbering plan */
#define PRI_NPI_F69						0x4 /*!< Telex numbering plan */
#define PRI_NPI_NATIONAL				0x8 /*!< National standard numbering plan */
#define PRI_NPI_PRIVATE					0x9 /*!< Private numbering plan */
#define PRI_NPI_RESERVED				0xF /*!< Reserved for extension */
Mark Spencer's avatar
Mark Spencer committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

/* Type of number */
#define PRI_TON_UNKNOWN					0x0
#define PRI_TON_INTERNATIONAL			0x1
#define PRI_TON_NATIONAL				0x2
#define PRI_TON_NET_SPECIFIC			0x3
#define PRI_TON_SUBSCRIBER				0x4
#define PRI_TON_ABBREVIATED				0x6
#define PRI_TON_RESERVED				0x7

/* Redirection reasons */
#define PRI_REDIR_UNKNOWN				0x0
#define PRI_REDIR_FORWARD_ON_BUSY		0x1
#define PRI_REDIR_FORWARD_ON_NO_REPLY	0x2
#define PRI_REDIR_DEFLECTION			0x3
#define PRI_REDIR_DTE_OUT_OF_ORDER		0x9
#define PRI_REDIR_FORWARDED_BY_DTE		0xA
#define PRI_REDIR_UNCONDITIONAL			0xF

Mark Spencer's avatar
Mark Spencer committed
139 140 141 142 143 144 145 146
/* Dialing plan */
#define PRI_INTERNATIONAL_ISDN		0x11
#define PRI_NATIONAL_ISDN			0x21
#define PRI_LOCAL_ISDN				0x41
#define PRI_PRIVATE					0x49
#define PRI_UNKNOWN					0x0

/* Presentation */
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
#define PRI_PRES_NUMBER_TYPE				0x03
#define PRI_PRES_USER_NUMBER_UNSCREENED		0x00
#define PRI_PRES_USER_NUMBER_PASSED_SCREEN	0x01
#define PRI_PRES_USER_NUMBER_FAILED_SCREEN	0x02
#define PRI_PRES_NETWORK_NUMBER				0x03

#define PRI_PRES_RESTRICTION				0x60
#define PRI_PRES_ALLOWED					0x00
#define PRI_PRES_RESTRICTED					0x20
#define PRI_PRES_UNAVAILABLE				0x40
#define PRI_PRES_RESERVED					0x60

#define PRES_ALLOWED_USER_NUMBER_NOT_SCREENED \
	(PRI_PRES_ALLOWED | PRI_PRES_USER_NUMBER_UNSCREENED)

#define PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN \
	(PRI_PRES_ALLOWED | PRI_PRES_USER_NUMBER_PASSED_SCREEN)

#define PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN \
	(PRI_PRES_ALLOWED | PRI_PRES_USER_NUMBER_FAILED_SCREEN)

#define PRES_ALLOWED_NETWORK_NUMBER	\
	(PRI_PRES_ALLOWED | PRI_PRES_NETWORK_NUMBER)

#define PRES_PROHIB_USER_NUMBER_NOT_SCREENED \
	(PRI_PRES_RESTRICTED | PRI_PRES_USER_NUMBER_UNSCREENED)

#define PRES_PROHIB_USER_NUMBER_PASSED_SCREEN \
	(PRI_PRES_RESTRICTED | PRI_PRES_USER_NUMBER_PASSED_SCREEN)

#define PRES_PROHIB_USER_NUMBER_FAILED_SCREEN \
	(PRI_PRES_RESTRICTED | PRI_PRES_USER_NUMBER_FAILED_SCREEN)

#define PRES_PROHIB_NETWORK_NUMBER \
	(PRI_PRES_RESTRICTED | PRI_PRES_NETWORK_NUMBER)

#define PRES_NUMBER_NOT_AVAILABLE \
	(PRI_PRES_UNAVAILABLE | PRI_PRES_NETWORK_NUMBER)
Mark Spencer's avatar
Mark Spencer committed
185 186 187

/* Causes for disconnection */
#define PRI_CAUSE_UNALLOCATED					1
188
#define PRI_CAUSE_NO_ROUTE_TRANSIT_NET			2	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
189 190
#define PRI_CAUSE_NO_ROUTE_DESTINATION			3
#define PRI_CAUSE_CHANNEL_UNACCEPTABLE			6
191
#define PRI_CAUSE_CALL_AWARDED_DELIVERED		7	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
192 193 194 195 196
#define PRI_CAUSE_NORMAL_CLEARING				16
#define PRI_CAUSE_USER_BUSY						17
#define PRI_CAUSE_NO_USER_RESPONSE				18
#define PRI_CAUSE_NO_ANSWER						19
#define PRI_CAUSE_CALL_REJECTED					21
Mark Spencer's avatar
Mark Spencer committed
197
#define PRI_CAUSE_NUMBER_CHANGED				22
Mark Spencer's avatar
Mark Spencer committed
198 199
#define PRI_CAUSE_DESTINATION_OUT_OF_ORDER		27
#define PRI_CAUSE_INVALID_NUMBER_FORMAT			28
200
#define PRI_CAUSE_FACILITY_REJECTED				29	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
201 202 203
#define PRI_CAUSE_RESPONSE_TO_STATUS_ENQUIRY	30
#define PRI_CAUSE_NORMAL_UNSPECIFIED			31
#define PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION		34
204
#define PRI_CAUSE_NETWORK_OUT_OF_ORDER			38	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
205
#define PRI_CAUSE_NORMAL_TEMPORARY_FAILURE		41
206 207
#define PRI_CAUSE_SWITCH_CONGESTION				42	/* !Q.SIG */
#define PRI_CAUSE_ACCESS_INFO_DISCARDED			43	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
208
#define PRI_CAUSE_REQUESTED_CHAN_UNAVAIL		44
209 210 211 212
#define PRI_CAUSE_PRE_EMPTED					45	/* !Q.SIG */
#define PRI_CAUSE_FACILITY_NOT_SUBSCRIBED  		50	/* !Q.SIG */
#define PRI_CAUSE_OUTGOING_CALL_BARRED     		52	/* !Q.SIG */
#define PRI_CAUSE_INCOMING_CALL_BARRED     		54	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
213
#define PRI_CAUSE_BEARERCAPABILITY_NOTAUTH		57
Mark Spencer's avatar
Mark Spencer committed
214
#define PRI_CAUSE_BEARERCAPABILITY_NOTAVAIL     58
215
#define PRI_CAUSE_SERVICEOROPTION_NOTAVAIL		63	/* Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
216
#define PRI_CAUSE_BEARERCAPABILITY_NOTIMPL		65
217 218
#define PRI_CAUSE_CHAN_NOT_IMPLEMENTED     		66	/* !Q.SIG */
#define PRI_CAUSE_FACILITY_NOT_IMPLEMENTED      69	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
219
#define PRI_CAUSE_INVALID_CALL_REFERENCE		81
220
#define PRI_CAUSE_IDENTIFIED_CHANNEL_NOTEXIST	82	/* Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
221
#define PRI_CAUSE_INCOMPATIBLE_DESTINATION		88
222
#define PRI_CAUSE_INVALID_MSG_UNSPECIFIED  		95	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
223 224
#define PRI_CAUSE_MANDATORY_IE_MISSING			96
#define PRI_CAUSE_MESSAGE_TYPE_NONEXIST			97
Mark Spencer's avatar
Mark Spencer committed
225
#define PRI_CAUSE_WRONG_MESSAGE					98
Mark Spencer's avatar
Mark Spencer committed
226 227 228 229
#define PRI_CAUSE_IE_NONEXIST					99
#define PRI_CAUSE_INVALID_IE_CONTENTS			100
#define PRI_CAUSE_WRONG_CALL_STATE				101
#define PRI_CAUSE_RECOVERY_ON_TIMER_EXPIRE		102
230
#define PRI_CAUSE_MANDATORY_IE_LENGTH_ERROR		103	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
231
#define PRI_CAUSE_PROTOCOL_ERROR				111
232
#define PRI_CAUSE_INTERWORKING					127	/* !Q.SIG */
Mark Spencer's avatar
Mark Spencer committed
233 234

/* Transmit capabilities */
Mark Spencer's avatar
Mark Spencer committed
235 236 237 238
#define PRI_TRANS_CAP_SPEECH					0x0
#define PRI_TRANS_CAP_DIGITAL					0x08
#define PRI_TRANS_CAP_RESTRICTED_DIGITAL		0x09
#define PRI_TRANS_CAP_3_1K_AUDIO				0x10
239 240
#define PRI_TRANS_CAP_7K_AUDIO					0x11	/* Depriciated ITU Q.931 (05/1998)*/
#define PRI_TRANS_CAP_DIGITAL_W_TONES			0x11
Mark Spencer's avatar
Mark Spencer committed
241
#define PRI_TRANS_CAP_VIDEO						0x18
Mark Spencer's avatar
Mark Spencer committed
242

Mark Spencer's avatar
Mark Spencer committed
243
#define PRI_LAYER_1_ITU_RATE_ADAPT	0x21
Mark Spencer's avatar
Mark Spencer committed
244 245 246
#define PRI_LAYER_1_ULAW			0x22
#define PRI_LAYER_1_ALAW			0x23
#define PRI_LAYER_1_G721			0x24
Mark Spencer's avatar
Mark Spencer committed
247
#define PRI_LAYER_1_G722_G725		0x25
248
#define PRI_LAYER_1_H223_H245		0x26
Mark Spencer's avatar
Mark Spencer committed
249 250 251 252
#define PRI_LAYER_1_NON_ITU_ADAPT	0x27
#define PRI_LAYER_1_V120_RATE_ADAPT	0x28
#define PRI_LAYER_1_X31_RATE_ADAPT	0x29

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

/* Intermediate rates for V.110 */
#define PRI_INT_RATE_8K			1
#define PRI_INT_RATE_16K		2
#define PRI_INT_RATE_32K		3


/* Rate adaption for bottom 5 bits of rateadaption */
#define PRI_RATE_USER_RATE_MASK		0x1F
#define PRI_RATE_ADAPT_UNSPEC		0x00
#define PRI_RATE_ADAPT_0K6		0x01
#define PRI_RATE_ADAPT_1K2		0x02
#define PRI_RATE_ADAPT_2K4		0x03
#define PRI_RATE_ADAPT_3K6		0x04
#define PRI_RATE_ADAPT_4K8		0x05
#define PRI_RATE_ADAPT_7K2		0x06
#define PRI_RATE_ADAPT_8K		0x07
#define PRI_RATE_ADAPT_9K6		0x08
#define PRI_RATE_ADAPT_14K4		0x09
#define PRI_RATE_ADAPT_16K		0x0A
#define PRI_RATE_ADAPT_19K2		0x0B
#define PRI_RATE_ADAPT_32K		0x0C
#define PRI_RATE_ADAPT_38K4		0x0D
#define PRI_RATE_ADAPT_48K		0x0E
#define PRI_RATE_ADAPT_56K		0x0F
#define PRI_RATE_ADAPT_57K6		0x12
#define PRI_RATE_ADAPT_28K8		0x13
#define PRI_RATE_ADAPT_24K		0x14
#define PRI_RATE_ADAPT_0K1345		0x15
#define PRI_RATE_ADAPT_0K1		0x16
#define PRI_RATE_ADAPT_0K075_1K2	0x17
#define PRI_RATE_ADAPT_1K2_0K075	0x18
#define PRI_RATE_ADAPT_0K05		0x19
#define PRI_RATE_ADAPT_0K075		0x1A
#define PRI_RATE_ADAPT_0K110		0x1B
#define PRI_RATE_ADAPT_0K150		0x1C
#define PRI_RATE_ADAPT_0K200		0x1D
#define PRI_RATE_ADAPT_0K300		0x1E
#define PRI_RATE_ADAPT_12K		0x1F

/* in-band negotiation flag for rateadaption bit 5 */
#define PRI_RATE_ADAPT_NEGOTIATION_POSS	0x20

/* async flag for rateadaption bit 6 */
#define PRI_RATE_ADAPT_ASYNC		0x40

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
/* Notifications */
#define PRI_NOTIFY_USER_SUSPENDED		0x00	/* User suspended */
#define PRI_NOTIFY_USER_RESUMED			0x01	/* User resumed */
#define PRI_NOTIFY_BEARER_CHANGE		0x02	/* Bearer service change (DSS1) */
#define PRI_NOTIFY_ASN1_COMPONENT		0x03	/* ASN.1 encoded component (DSS1) */
#define PRI_NOTIFY_COMPLETION_DELAY		0x04	/* Call completion delay */
#define PRI_NOTIFY_CONF_ESTABLISHED		0x42	/* Conference established */
#define PRI_NOTIFY_CONF_DISCONNECTED		0x43	/* Conference disconnected */
#define PRI_NOTIFY_CONF_PARTY_ADDED		0x44	/* Other party added */
#define PRI_NOTIFY_CONF_ISOLATED		0x45	/* Isolated */
#define PRI_NOTIFY_CONF_REATTACHED		0x46	/* Reattached */
#define PRI_NOTIFY_CONF_OTHER_ISOLATED		0x47	/* Other party isolated */
#define PRI_NOTIFY_CONF_OTHER_REATTACHED	0x48	/* Other party reattached */
#define PRI_NOTIFY_CONF_OTHER_SPLIT		0x49	/* Other party split */
#define PRI_NOTIFY_CONF_OTHER_DISCONNECTED	0x4a	/* Other party disconnected */
#define PRI_NOTIFY_CONF_FLOATING		0x4b	/* Conference floating */
#define PRI_NOTIFY_WAITING_CALL			0x60	/* Call is waiting call */
#define PRI_NOTIFY_DIVERSION_ACTIVATED		0x68	/* Diversion activated (DSS1) */
#define PRI_NOTIFY_TRANSFER_ALERTING		0x69	/* Call transfer, alerting */
#define PRI_NOTIFY_TRANSFER_ACTIVE		0x6a	/* Call transfer, active */
#define PRI_NOTIFY_REMOTE_HOLD			0x79	/* Remote hold */
#define PRI_NOTIFY_REMOTE_RETRIEVAL		0x7a	/* Remote retrieval */
#define PRI_NOTIFY_CALL_DIVERTING		0x7b	/* Call is diverting */

323 324
#define PRI_COPY_DIGITS_CALLED_NUMBER

325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
/* Network Specific Facilities (AT&T) */
#define PRI_NSF_NONE                   -1
#define PRI_NSF_SID_PREFERRED          0xB1
#define PRI_NSF_ANI_PREFERRED          0xB2
#define PRI_NSF_SID_ONLY               0xB3
#define PRI_NSF_ANI_ONLY               0xB4
#define PRI_NSF_CALL_ASSOC_TSC         0xB9
#define PRI_NSF_NOTIF_CATSC_CLEARING   0xBA
#define PRI_NSF_OPERATOR               0xB5
#define PRI_NSF_PCCO                   0xB6
#define PRI_NSF_SDN                    0xE1
#define PRI_NSF_TOLL_FREE_MEGACOM      0xE2
#define PRI_NSF_MEGACOM                        0xE3
#define PRI_NSF_ACCUNET                        0xE6
#define PRI_NSF_LONG_DISTANCE_SERVICE  0xE7
#define PRI_NSF_INTERNATIONAL_TOLL_FREE        0xE8
#define PRI_NSF_ATT_MULTIQUEST         0xF0
#define PRI_NSF_CALL_REDIRECTION_SERVICE       0xF7

Mark Spencer's avatar
Mark Spencer committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
typedef struct q931_call q931_call;

typedef struct pri_event_generic {
	/* Events with no additional information fall in this category */
	int e;
} pri_event_generic;

typedef struct pri_event_error {
	int e;
	char err[256];
} pri_event_error;

typedef struct pri_event_restart {
	int e;
	int channel;
} pri_event_restart;

typedef struct pri_event_ringing {
	int e;
	int channel;
	int cref;
365
	int progress;
366
	int progressmask;
Mark Spencer's avatar
Mark Spencer committed
367
	q931_call *call;
368
	char useruserinfo[260];		/* User->User info */
Mark Spencer's avatar
Mark Spencer committed
369 370 371 372 373 374
} pri_event_ringing;

typedef struct pri_event_answer {
	int e;
	int channel;
	int cref;
375
	int progress;
376
	int progressmask;
Mark Spencer's avatar
Mark Spencer committed
377
	q931_call *call;
378
	char useruserinfo[260];		/* User->User info */
Mark Spencer's avatar
Mark Spencer committed
379 380
} pri_event_answer;

381 382 383 384 385 386 387
typedef struct pri_event_facname {
	int e;
	char callingname[256];
	char callingnum[256];
	int channel;
	int cref;
	q931_call *call;
388 389
	int callingpres;			/* Presentation of Calling CallerID */
	int callingplan;			/* Dialing plan of Calling entity */
390 391
} pri_event_facname;

392
#define PRI_CALLINGPLANANI
393
#define PRI_CALLINGPLANRDNIS
Mark Spencer's avatar
Mark Spencer committed
394 395 396 397
typedef struct pri_event_ring {
	int e;
	int channel;				/* Channel requested */
	int callingpres;			/* Presentation of Calling CallerID */
398
	int callingplanani;			/* Dialing plan of Calling entity ANI */
Mark Spencer's avatar
Mark Spencer committed
399
	int callingplan;			/* Dialing plan of Calling entity */
400
	char callingani[256];		/* Calling ANI */
Mark Spencer's avatar
Mark Spencer committed
401
	char callingnum[256];		/* Calling number */
402
	char callingname[256];		/* Calling name (if provided) */
Mark Spencer's avatar
Mark Spencer committed
403
	int calledplan;				/* Dialing plan of Called number */
404
	int ani2;                   /* ANI II */
Mark Spencer's avatar
Mark Spencer committed
405
	char callednum[256];		/* Called number */
406 407 408
	char redirectingnum[256];	/* Redirecting number */
	char redirectingname[256];	/* Redirecting name */
	int redirectingreason;		/* Reason for redirect */
409
	int callingplanrdnis;			/* Dialing plan of Redirecting Number */
410
	char useruserinfo[260];		/* User->User info */
Mark Spencer's avatar
Mark Spencer committed
411 412 413
	int flexible;				/* Are we flexible with our channel selection? */
	int cref;					/* Call Reference Number */
	int ctype;					/* Call type (see PRI_TRANS_CAP_* */
414
	int layer1;					/* User layer 1 */
Mark Spencer's avatar
Mark Spencer committed
415
	int complete;				/* Have we seen "Complete" i.e. no more number? */
Mark Spencer's avatar
Mark Spencer committed
416
	q931_call *call;			/* Opaque call pointer */
417
	char callingsubaddr[256];	/* Calling parties subaddress */
418 419
	int progress;
	int progressmask;
420 421
	char origcalledname[256];
	char origcallednum[256];
422
	int callingplanorigcalled;		/* Dialing plan of Originally Called Number */
423
	int origredirectingreason;
Mark Spencer's avatar
Mark Spencer committed
424 425 426 427 428 429 430 431
} pri_event_ring;

typedef struct pri_event_hangup {
	int e;
	int channel;				/* Channel requested */
	int cause;
	int cref;
	q931_call *call;			/* Opaque call pointer */
432
	long aoc_units;				/* Advise of Charge number of charged units */
433
	char useruserinfo[260];		/* User->User info */
Mark Spencer's avatar
Mark Spencer committed
434 435
} pri_event_hangup;	

Mark Spencer's avatar
Mark Spencer committed
436 437 438 439 440
typedef struct pri_event_restart_ack {
	int e;
	int channel;
} pri_event_restart_ack;

Matthew Fredrickson's avatar
Matthew Fredrickson committed
441
#define PRI_PROGRESS_CAUSE
442 443 444
typedef struct pri_event_proceeding {
	int e;
	int channel;
445 446
	int cref;
	int progress;
447
	int progressmask;
448
	int cause;
449
	q931_call *call;
450 451
} pri_event_proceeding;
 
452 453 454
typedef struct pri_event_setup_ack {
	int e;
	int channel;
455
	q931_call *call;
456
} pri_event_setup_ack;
457

458 459 460 461 462 463
typedef struct pri_event_notify {
	int e;
	int channel;
	int info;
} pri_event_notify;

464 465 466 467 468 469 470
typedef struct pri_event_keypad_digit {
	int e;
	int channel;
	q931_call *call;
	char digits[64];
} pri_event_keypad_digit;

471 472 473 474 475 476 477 478 479 480 481 482
typedef struct pri_event_service {
	int e;
	int channel;
	int changestatus;
} pri_event_service;

typedef struct pri_event_service_ack {
	int e;
	int channel;
	int changestatus;
} pri_event_service_ack;

Mark Spencer's avatar
Mark Spencer committed
483 484 485 486 487
typedef union {
	int e;
	pri_event_generic gen;		/* Generic view */
	pri_event_restart restart;	/* Restart view */
	pri_event_error	  err;		/* Error view */
488
	pri_event_facname facname;	/* Caller*ID Name on Facility */
Mark Spencer's avatar
Mark Spencer committed
489 490 491
	pri_event_ring	  ring;		/* Ring */
	pri_event_hangup  hangup;	/* Hang up */
	pri_event_ringing ringing;	/* Ringing */
492
	pri_event_answer  answer;	/* Answer */
Mark Spencer's avatar
Mark Spencer committed
493
	pri_event_restart_ack restartack;	/* Restart Acknowledge */
494
	pri_event_proceeding  proceeding;	/* Call proceeding & Progress */
495
	pri_event_setup_ack   setup_ack;	/* SETUP_ACKNOWLEDGE structure */
496
	pri_event_notify notify;		/* Notification */
497
	pri_event_keypad_digit digit;			/* Digits that come during a call */
498 499
	pri_event_service service;				/* service message */
	pri_event_service_ack service_ack;		/* service acknowledgement message */
Mark Spencer's avatar
Mark Spencer committed
500 501 502
} pri_event;

struct pri;
503
struct pri_sr;
Mark Spencer's avatar
Mark Spencer committed
504

505 506 507
#define PRI_IO_FUNCS
/* Type declaration for callbacks to read or write a HDLC frame as below */
typedef int (*pri_io_cb)(struct pri *pri, void *buf, int buflen);
Mark Spencer's avatar
Mark Spencer committed
508 509 510 511 512

/* Create a D-channel on a given file descriptor.  The file descriptor must be a
   channel operating in HDLC mode with FCS computed by the fd's driver.  Also it
   must be NON-BLOCKING! Frames received on the fd should include FCS.  Nodetype 
   must be one of PRI_NETWORK or PRI_CPE.  switchtype should be PRI_SWITCH_* */
513 514
struct pri *pri_new(int fd, int nodetype, int switchtype);
struct pri *pri_new_bri(int fd, int ptpmode, int nodetype, int switchtype);
Mark Spencer's avatar
Mark Spencer committed
515

516
/* Create D-channel just as above with user defined I/O callbacks and data */
517
struct pri *pri_new_cb(int fd, int nodetype, int switchtype, pri_io_cb io_read, pri_io_cb io_write, void *userdata);
518 519

/* Retrieve the user data associated with the D channel */
520
void *pri_get_userdata(struct pri *pri);
521 522

/* Set the user data associated with the D channel */
523
void pri_set_userdata(struct pri *pri, void *userdata);
524

525
/* Set Network Specific Facility for PRI */
526
void pri_set_nsf(struct pri *pri, int nsf);
527

Mark Spencer's avatar
Mark Spencer committed
528
/* Set debug parameters on PRI -- see above debug definitions */
529
void pri_set_debug(struct pri *pri, int debug);
Mark Spencer's avatar
Mark Spencer committed
530

531
/* Get debug parameters on PRI -- see above debug definitions */
532
int pri_get_debug(struct pri *pri);
533

534 535
#define PRI_FACILITY_ENABLE
/* Enable transmission support of Facility IEs on the pri */
536
void pri_facility_enable(struct pri *pri);
537

Mark Spencer's avatar
Mark Spencer committed
538 539 540
/* Run PRI on the given D-channel, taking care of any events that
   need to be handled.  If block is set, it will block until an event
   occurs which needs to be handled */
541
pri_event *pri_dchannel_run(struct pri *pri, int block);
Mark Spencer's avatar
Mark Spencer committed
542 543 544 545 546

/* Check for an outstanding event on the PRI */
pri_event *pri_check_event(struct pri *pri);

/* Give a name to a given event ID */
547
char *pri_event2str(int id);
Mark Spencer's avatar
Mark Spencer committed
548

549
/* Give a name to a node type */
550
char *pri_node2str(int id);
Mark Spencer's avatar
Mark Spencer committed
551 552

/* Give a name to a switch type */
553
char *pri_switch2str(int id);
Mark Spencer's avatar
Mark Spencer committed
554 555

/* Print an event */
556
void pri_dump_event(struct pri *pri, pri_event *e);
Mark Spencer's avatar
Mark Spencer committed
557 558

/* Turn presentation into a string */
559
char *pri_pres2str(int pres);
Mark Spencer's avatar
Mark Spencer committed
560 561

/* Turn numbering plan into a string */
562
char *pri_plan2str(int plan);
Mark Spencer's avatar
Mark Spencer committed
563 564

/* Turn cause into a string */
565
char *pri_cause2str(int cause);
Mark Spencer's avatar
Mark Spencer committed
566 567 568

/* Acknowledge a call and place it on the given channel.  Set info to non-zero if there
   is in-band data available on the channel */
569
int pri_acknowledge(struct pri *pri, q931_call *call, int channel, int info);
Mark Spencer's avatar
Mark Spencer committed
570

571
/* Send a digit in overlap mode */
572
int pri_information(struct pri *pri, q931_call *call, char digit);
573

574
#define PRI_KEYPAD_FACILITY_TX
575
/* Send a keypad facility string of digits */
576
int pri_keypad_facility(struct pri *pri, q931_call *call, char *digits);
577

578 579
/* Answer the incomplete(call without called number) call on the given channel.
   Set non-isdn to non-zero if you are not connecting to ISDN equipment */
580
int pri_need_more_info(struct pri *pri, q931_call *call, int channel, int nonisdn);
581

Mark Spencer's avatar
Mark Spencer committed
582 583
/* Answer the call on the given channel (ignored if you called acknowledge already).
   Set non-isdn to non-zero if you are not connecting to ISDN equipment */
584
int pri_answer(struct pri *pri, q931_call *call, int channel, int nonisdn);
Mark Spencer's avatar
Mark Spencer committed
585

586
/* Set CRV reference for GR-303 calls */
Mark Spencer's avatar
Mark Spencer committed
587

588

589 590 591 592 593 594 595 596 597 598
#undef pri_release
#undef pri_disconnect

/* backwards compatibility for those who don't use asterisk with libpri */
#define pri_release(a,b,c) \
	pri_hangup(a,b,c)

#define pri_disconnect(a,b,c) \
	pri_hangup(a,b,c)

599
/* Hangup a call */
600
#define PRI_HANGUP
601
int pri_hangup(struct pri *pri, q931_call *call, int cause);
Mark Spencer's avatar
Mark Spencer committed
602

Martin Pycko's avatar
Martin Pycko committed
603
#define PRI_DESTROYCALL
604
void pri_destroycall(struct pri *pri, q931_call *call);
Martin Pycko's avatar
Martin Pycko committed
605

606
#define PRI_RESTART
607
int pri_restart(struct pri *pri);
608

609
int pri_reset(struct pri *pri, int channel);
Mark Spencer's avatar
Mark Spencer committed
610

611 612 613
/* handle b-channel maintenance messages */
extern int pri_maintenance_service(struct pri *pri, int span, int channel, int changestatus);

Mark Spencer's avatar
Mark Spencer committed
614
/* Create a new call */
615
q931_call *pri_new_call(struct pri *pri);
Mark Spencer's avatar
Mark Spencer committed
616

617
/* Retrieve CRV reference for GR-303 calls.  Returns >0 on success. */
618
int pri_get_crv(struct pri *pri, q931_call *call, int *callmode);
619 620

/* Retrieve CRV reference for GR-303 calls.  CRV must be >0, call mode should be 0 */
621
int pri_set_crv(struct pri *pri, q931_call *call, int crv, int callmode);
622

Mark Spencer's avatar
Mark Spencer committed
623
/* How long until you need to poll for a new event */
624
struct timeval *pri_schedule_next(struct pri *pri);
Mark Spencer's avatar
Mark Spencer committed
625 626

/* Run any pending schedule events */
Mark Spencer's avatar
Mark Spencer committed
627
extern pri_event *pri_schedule_run(struct pri *pri);
628
extern pri_event *pri_schedule_run_tv(struct pri *pri, const struct timeval *now);
Mark Spencer's avatar
Mark Spencer committed
629

630
int pri_call(struct pri *pri, q931_call *c, int transmode, int channel,
631
   int exclusive, int nonisdn, char *caller, int callerplan, char *callername, int callerpres,
Mark Spencer's avatar
Mark Spencer committed
632
	 char *called,int calledplan, int ulayer1);
633

634 635
struct pri_sr *pri_sr_new(void);
void pri_sr_free(struct pri_sr *sr);
636

637 638 639 640 641
int pri_sr_set_channel(struct pri_sr *sr, int channel, int exclusive, int nonisdn);
int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1);
int pri_sr_set_called(struct pri_sr *sr, char *called, int calledplan, int complete);
int pri_sr_set_caller(struct pri_sr *sr, char *caller, char *callername, int callerplan, int callerpres);
int pri_sr_set_redirecting(struct pri_sr *sr, char *num, int plan, int pres, int reason);
642
#define PRI_USER_USER_TX
643
/* Set the user user field.  Warning!  don't send binary data accross this field */
644
void pri_sr_set_useruser(struct pri_sr *sr, const char *userchars);
645

646
void pri_call_set_useruser(q931_call *sr, const char *userchars);
647

648
int pri_setup(struct pri *pri, q931_call *call, struct pri_sr *req);
649 650

/* Set a call has a call indpendent signalling connection (i.e. no bchan) */
651
int pri_sr_set_connection_call_independent(struct pri_sr *req);
652

653
/* Send an MWI indication to a remote location.  If activate is non zero, activates, if zero, deactivates */
654
int pri_mwi_activate(struct pri *pri, q931_call *c, char *caller, int callerplan, char *callername, int callerpres, char *called, int calledplan);
655 656

/* Send an MWI deactivate request to a remote location */
657
int pri_mwi_deactivate(struct pri *pri, q931_call *c, char *caller, int callerplan, char *callername, int callerpres, char *called, int calledplan);
658

659 660 661
/* Set service message support flag */
int pri_set_service_message_support(struct pri *pri, int supportflag);

662 663 664 665 666
#define PRI_2BCT
/* Attempt to pass the channels back to the NET side if compatable and
 * suscribed.  Sometimes called 2 bchannel transfer (2BCT) */
int pri_channel_bridge(q931_call *call1, q931_call *call2);

667
/* Override message and error stuff */
668
#define PRI_NEW_SET_API
669 670
void pri_set_message(void (*__pri_error)(struct pri *pri, char *));
void pri_set_error(void (*__pri_error)(struct pri *pri, char *));
671 672 673

/* Set overlap mode */
#define PRI_SET_OVERLAPDIAL
674
void pri_set_overlapdial(struct pri *pri,int state);
675

676 677 678 679
/* QSIG logical channel mapping option, do not skip channel 16 */
#define PRI_SET_CHAN_MAPPING_LOGICAL
void pri_set_chan_mapping_logical(struct pri *pri, int state);

680
#define PRI_DUMP_INFO_STR
681
char *pri_dump_info_str(struct pri *pri);
682

683
/* Get file descriptor */
684
int pri_fd(struct pri *pri);
685

686
#define PRI_PROGRESS
687
/* Send progress */
688
int pri_progress(struct pri *pri, q931_call *c, int channel, int info);
689

690 691 692
/* Send progress with cause IE */
int pri_progress_with_cause(struct pri *pri, q931_call *c, int channel, int info, int cause);

693
#define PRI_PROCEEDING_FULL
694
/* Send call proceeding */
695
int pri_proceeding(struct pri *pri, q931_call *c, int channel, int info);
696

697
/* Enable inband progress when a DISCONNECT is received */
698
void pri_set_inbanddisconnect(struct pri *pri, unsigned int enable);
699

700 701
/* Enslave a PRI to another, so they share the same call list
   (and maybe some timers) */
702
void pri_enslave(struct pri *master, struct pri *slave);
703

704
#define PRI_GR303_SUPPORT
705
#define PRI_ENSLAVE_SUPPORT
706
#define PRI_SETUP_CALL
Mark Spencer's avatar
Mark Spencer committed
707
#define PRI_RECEIVE_SUBADDR
708
#define PRI_REDIRECTING_REASON
709
#define PRI_AOC_UNITS
710
#define PRI_ANI
711 712

/* Send notification */
713
int pri_notify(struct pri *pri, q931_call *c, int channel, int info);
714

715 716
int pri_callrerouting_facility(struct pri *pri, q931_call *call, const char *dest, const char* original, const char* reason);

717 718
/* Get/Set PRI Timers  */
#define PRI_GETSET_TIMERS
719 720 721
int pri_set_timer(struct pri *pri, int timer, int value);
int pri_get_timer(struct pri *pri, int timer);
int pri_timer2idx(char *timer);
722 723 724 725 726 727

#define PRI_MAX_TIMERS 32

#define PRI_TIMER_N200	0	/* Maximum numer of q921 retransmissions */
#define PRI_TIMER_N201	1	/* Maximum numer of octets in an information field */
#define PRI_TIMER_N202	2	/* Maximum numer of transmissions of the TEI identity request message */
728
#define PRI_TIMER_K		3	/* Maximum number of outstanding I-frames */
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755

#define PRI_TIMER_T200	4	/* time between SABME's */
#define PRI_TIMER_T201	5	/* minimum time between retransmissions of the TEI Identity check messages */
#define PRI_TIMER_T202	6	/* minimum time between transmission of TEI Identity request messages */
#define PRI_TIMER_T203	7	/* maxiumum time without exchanging packets */

#define PRI_TIMER_T300	8	
#define PRI_TIMER_T301	9	/* maximum time to respond to an ALERT */
#define PRI_TIMER_T302	10
#define PRI_TIMER_T303	11	/* maximum time to wait after sending a SETUP without a response */
#define PRI_TIMER_T304	12
#define PRI_TIMER_T305	13
#define PRI_TIMER_T306	14
#define PRI_TIMER_T307	15
#define PRI_TIMER_T308	16
#define PRI_TIMER_T309	17
#define PRI_TIMER_T310	18	/* maximum time between receiving a CALLPROCEEDING and receiving a ALERT/CONNECT/DISCONNECT/PROGRESS */
#define PRI_TIMER_T313	19
#define PRI_TIMER_T314	20
#define PRI_TIMER_T316	21	/* maximum time between transmitting a RESTART and receiving a RESTART ACK */
#define PRI_TIMER_T317	22
#define PRI_TIMER_T318	23
#define PRI_TIMER_T319	24
#define PRI_TIMER_T320	25
#define PRI_TIMER_T321	26
#define PRI_TIMER_T322	27

756 757 758
#define PRI_TIMER_TM20	28	/* maximum time avaiting XID response */
#define PRI_TIMER_NM20	29	/* number of XID retransmits */

759 760 761
/* Get PRI version */
const char *pri_get_version(void);

762
#endif