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.
28 typedef enum q931_state
{
33 U3_OUTGOING_CALL_PROCEEDING
,
38 U9_INCOMING_CALL_PROCEEDING
,
40 U11_DISCONNECT_REQUEST
,
41 U12_DISCONNECT_INDICATION
,
45 U25_OVERLAP_RECEIVING
,
50 N3_OUTGOING_CALL_PROCEEDING
,
55 N9_INCOMING_CALL_PROCEEDING
,
57 N11_DISCONNECT_REQUEST
,
58 N12_DISCONNECT_INDICATION
,
66 typedef enum q931_mode
{
72 typedef struct q931_h
{
74 u_int8_t pd
; /* Protocol Discriminator */
75 #if __BYTE_ORDER == __BIG_ENDIAN
84 } __attribute__ ((packed
)) q931_h
;
87 /* Message type header */
88 typedef struct q931_mh
{
89 #if __BYTE_ORDER == __BIG_ENDIAN
97 } __attribute__ ((packed
)) q931_mh
;
99 /* Information element format */
100 typedef struct q931_ie
{
104 } __attribute__ ((packed
)) q931_ie
;
106 #define Q931_RES_HAVEEVENT (1 << 0)
107 #define Q931_RES_INERRROR (1 << 1)
109 #define Q931_PROTOCOL_DISCRIMINATOR 0x08
110 #define GR303_PROTOCOL_DISCRIMINATOR 0x4f
112 /* Q.931 / National ISDN Message Types */
114 /* Call Establishment Messages */
115 #define Q931_ALERTING 0x01
116 #define Q931_CALL_PROCEEDING 0x02
117 #define Q931_CONNECT 0x07
118 #define Q931_CONNECT_ACKNOWLEDGE 0x0f
119 #define Q931_PROGRESS 0x03
120 #define Q931_SETUP 0x05
121 #define Q931_SETUP_ACKNOWLEDGE 0x0d
123 /* Call Disestablishment Messages */
124 #define Q931_DISCONNECT 0x45
125 #define Q931_RELEASE 0x4d
126 #define Q931_RELEASE_COMPLETE 0x5a
127 #define Q931_RESTART 0x46
128 #define Q931_RESTART_ACKNOWLEDGE 0x4e
130 /* Miscellaneous Messages */
131 #define Q931_STATUS 0x7d
132 #define Q931_STATUS_ENQUIRY 0x75
133 #define Q931_USER_INFORMATION 0x20
134 #define Q931_SEGMENT 0x60
135 #define Q931_CONGESTION_CONTROL 0x79
136 #define Q931_INFORMATION 0x7b
137 #define Q931_FACILITY 0x62
138 #define Q931_NOTIFY 0x6e
140 /* Call Management Messages */
141 #define Q931_HOLD 0x24
142 #define Q931_HOLD_ACKNOWLEDGE 0x28
143 #define Q931_HOLD_REJECT 0x30
144 #define Q931_RETRIEVE 0x31
145 #define Q931_RETRIEVE_ACKNOWLEDGE 0x33
146 #define Q931_RETRIEVE_REJECT 0x37
147 #define Q931_RESUME 0x26
148 #define Q931_RESUME_ACKNOWLEDGE 0x2e
149 #define Q931_RESUME_REJECT 0x22
150 #define Q931_SUSPEND 0x25
151 #define Q931_SUSPEND_ACKNOWLEDGE 0x2d
152 #define Q931_SUSPEND_REJECT 0x21
154 /* Maintenance messages (codeset 0 only) */
155 #define NATIONAL_SERVICE 0x0f
156 #define NATIONAL_SERVICE_ACKNOWLEDGE 0x07
158 /* Special codeset 0 IE */
159 #define NATIONAL_CHANGE_STATUS 0x1
161 /* Q.931 / National ISDN Information Elements */
162 #define Q931_LOCKING_SHIFT 0x90
163 #define Q931_NON_LOCKING_SHIFT 0x98
164 #define Q931_BEARER_CAPABILITY 0x04
165 #define Q931_CAUSE 0x08
166 #define Q931_CALL_STATE 0x14
167 #define Q931_CHANNEL_IDENT 0x18
168 #define Q931_PROGRESS_INDICATOR 0x1e
169 #define Q931_NETWORK_SPEC_FAC 0x20
170 #define Q931_INFORMATION_RATE 0x40
171 #define Q931_TRANSIT_DELAY 0x42
172 #define Q931_TRANS_DELAY_SELECT 0x43
173 #define Q931_BINARY_PARAMETERS 0x44
174 #define Q931_WINDOW_SIZE 0x45
175 #define Q931_PACKET_SIZE 0x46
176 #define Q931_CLOSED_USER_GROUP 0x47
177 #define Q931_REVERSE_CHARGE_INDIC 0x4a
178 #define Q931_CALLING_PARTY_NUMBER 0x6c
179 #define Q931_CALLING_PARTY_SUBADDR 0x6d
180 #define Q931_CALLED_PARTY_NUMBER 0x70
181 #define Q931_CALLED_PARTY_SUBADDR 0x71
182 #define Q931_REDIRECTING_NUMBER 0x74
183 #define Q931_REDIRECTING_SUBADDR 0x75
184 #define Q931_TRANSIT_NET_SELECT 0x78
185 #define Q931_RESTART_INDICATOR 0x79
186 #define Q931_LOW_LAYER_COMPAT 0x7c
187 #define Q931_HIGH_LAYER_COMPAT 0x7d
189 #define Q931_CODESET(x) ((x) << 8)
190 #define Q931_IE_CODESET(x) ((x) >> 8)
191 #define Q931_IE_IE(x) ((x) & 0xff)
192 #define Q931_FULL_IE(codeset, ie) (((codeset) << 8) | ((ie) & 0xff))
193 #define Q931_IE_MAX_LEN 257
196 #define Q931_COLP 0x4c
198 #define Q931_DISPLAY 0x28
199 #define Q931_IE_SEGMENTED_MSG 0x00
200 #define Q931_IE_CHANGE_STATUS 0x01
201 #define Q931_IE_ORIGINATING_LINE_INFO (0x01 | Q931_CODESET(6))
202 #define Q931_IE_CONNECTED_ADDR 0x0C
203 #define Q931_IE_CONNECTED_NUM 0x4C
204 #define Q931_IE_CALL_IDENTITY 0x10
205 #define Q931_IE_FACILITY 0x1c
206 #define Q931_IE_ENDPOINT_ID 0x26
207 #define Q931_IE_NOTIFY_IND 0x27
208 #define Q931_IE_TIME_DATE 0x29
209 #define Q931_IE_KEYPAD_FACILITY 0x2c
210 #define Q931_IE_CALL_STATUS 0x2d
211 #define Q931_IE_UPDATE 0x31
212 #define Q931_IE_INFO_REQUEST 0x32
213 #define Q931_IE_SIGNAL 0x34
214 #define Q931_IE_SWITCHHOOK 0x36
215 #define Q931_IE_GENERIC_DIGITS (0x37 | Q931_CODESET(6))
216 #define Q931_IE_FEATURE_ACTIVATE 0x38
217 #define Q931_IE_FEATURE_IND 0x39
218 #define Q931_IE_ORIGINAL_CALLED_NUMBER 0x73
219 #define Q931_IE_REDIRECTION_NUMBER 0x76
220 #define Q931_IE_REDIRECTION_SUBADDR 0x77
221 #define Q931_IE_USER_USER_FACILITY 0x7A
222 #define Q931_IE_USER_USER 0x7E
223 #define Q931_IE_ESCAPE_FOR_EXT 0x7F
225 #define Q931_IE_SPECIAL 0x02
228 /* Call state stuff */
229 #define Q931_CALL_STATE_NULL 0
230 #define Q931_CALL_STATE_CALL_INITIATED 1
231 #define Q931_CALL_STATE_OVERLAP_SENDING 2
232 #define Q931_CALL_STATE_OUTGOING_CALL_PROCEEDING 3
233 #define Q931_CALL_STATE_CALL_DELIVERED 4
234 #define Q931_CALL_STATE_CALL_PRESENT 6
235 #define Q931_CALL_STATE_CALL_RECEIVED 7
236 #define Q931_CALL_STATE_CONNECT_REQUEST 8
237 #define Q931_CALL_STATE_INCOMING_CALL_PROCEEDING 9
238 #define Q931_CALL_STATE_ACTIVE 10
239 #define Q931_CALL_STATE_DISCONNECT_REQUEST 11
240 #define Q931_CALL_STATE_DISCONNECT_INDICATION 12
241 #define Q931_CALL_STATE_SUSPEND_REQUEST 15
242 #define Q931_CALL_STATE_RESUME_REQUEST 17
243 #define Q931_CALL_STATE_RELEASE_REQUEST 19
244 #define Q931_CALL_STATE_OVERLAP_RECEIVING 25
245 #define Q931_CALL_STATE_RESTART_REQUEST 61
246 #define Q931_CALL_STATE_RESTART 62
250 #define Q931_SENDING_COMPLETE 0xa1
254 #define QSIG_IE_TRANSIT_COUNT 0x31
256 extern int q931_receive(struct pri
*pri
, q931_h
*h
, int len
, int tei
);
258 extern int q931_alerting(struct pri
*pri
, q931_call
*call
, int channel
, int info
);
260 extern int q931_call_progress(struct pri
*pri
, q931_call
*call
, int channel
, int info
);
262 extern int q931_notify(struct pri
*pri
, q931_call
*call
, int channel
, int info
);
264 extern int q931_call_proceeding(struct pri
*pri
, q931_call
*call
, int channel
, int info
);
266 extern int q931_setup_ack(struct pri
*pri
, q931_call
*call
, int channel
, int nonisdn
);
268 extern int q931_information(struct pri
*pri
, q931_call
*call
, char digit
);
270 extern int q931_keypad_facility(struct pri
*pri
, q931_call
*call
, char *digits
);
272 extern int q931_information_display(struct pri
*pri
, q931_call
*call
, char *display
);
274 extern int q931_add_display(struct pri
*pri
, q931_call
*call
, char *display
);
276 extern int q931_connect(struct pri
*pri
, q931_call
*call
, int channel
, int nonisdn
);
278 extern int q931_release(struct pri
*pri
, q931_call
*call
, int cause
);
280 extern int q931_disconnect(struct pri
*pri
, q931_call
*call
, int cause
);
282 extern int q931_hangup(struct pri
*pri
, q931_call
*call
, int cause
);
284 extern int q921_hangup(struct pri
*pri
, q931_call
*c
, int tei
);
286 extern int q921_handle_hangup(struct pri
*pri
, q931_call
*c
, int tei
);
288 extern int q931_restart(struct pri
*pri
, int channel
);
290 extern int q931_facility(struct pri
*pri
, q931_call
*call
);
292 extern int q931_call_getcrv(struct pri
*pri
, q931_call
*call
, int *callmode
);
294 extern int q931_call_setcrv(struct pri
*pri
, q931_call
*call
, int crv
, int callmode
);
296 extern q931_call
*q931_new_call(struct pri
*pri
);
298 extern int q931_setup(struct pri
*pri
, q931_call
*c
, struct pri_sr
*req
);
299 extern void q931_dump(struct pri
*pri
, q931_h
*h
, int len
, int txrx
);
301 extern void __q931_destroycall(struct pri
*pri
, q931_call
*c
);
303 extern int q931_hold_acknowledge(struct pri
*pri
, q931_call
*c
);
305 extern int q931_hold_reject(struct pri
*pri
, q931_call
*c
);
307 extern int q931_retrieve_acknowledge(struct pri
*pri
, q931_call
*c
, int channel
);
309 extern int q931_retrieve_reject(struct pri
*pri
, q931_call
*c
);
311 extern int q931_suspend_acknowledge(struct pri
*pri
, q931_call
*c
, char *display
);
313 extern int q931_suspend_reject(struct pri
*pri
, q931_call
*c
, char *display
);
315 extern int q931_resume_reject(struct pri
*pri
, q931_call
*c
, char *display
);
317 extern int q931_resume_acknowledge(struct pri
*pri
, q931_call
*c
, int channel
, char *display
);
319 extern void q931_dl_indication(struct pri
*pri
, int event
);