Merged revisions 140566 via svnmerge from
[asterisk-bristuff.git] / channels / iax2.h
blob98e7480db6be093468ef86c3386db77d1a1bc655
1 /*
2 * Asterisk -- A telephony toolkit for Linux.
4 * Implementation of Inter-Asterisk eXchange
5 *
6 * Copyright (C) 2003, Digium
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
14 /*! \file
15 * \brief
17 * Implementation of Inter-Asterisk eXchange, version 2
18 * \ref iax2-parser.c
19 * \ref iax2-parser.h
20 * \ref chan_iax2.c
23 #ifndef _IAX2_H
24 #define _IAX2_H
26 /* Max version of IAX protocol we support */
27 #define IAX_PROTO_VERSION 2
29 /* NOTE: IT IS CRITICAL THAT IAX_MAX_CALLS BE A POWER OF 2. */
30 #if defined(LOW_MEMORY)
31 #define IAX_MAX_CALLS 2048
32 #else
33 #define IAX_MAX_CALLS 32768
34 #endif
36 #define IAX_FLAG_FULL 0x8000
38 #define IAX_FLAG_RETRANS 0x8000
40 #define IAX_FLAG_SC_LOG 0x80
42 #define IAX_MAX_SHIFT 0x1F
44 #define IAX_WINDOW 64
46 /*! Subclass for AST_FRAME_IAX */
47 enum {
48 IAX_COMMAND_NEW = 1,
49 IAX_COMMAND_PING = 2,
50 IAX_COMMAND_PONG = 3,
51 IAX_COMMAND_ACK = 4,
52 IAX_COMMAND_HANGUP = 5,
53 IAX_COMMAND_REJECT = 6,
54 IAX_COMMAND_ACCEPT = 7,
55 IAX_COMMAND_AUTHREQ = 8,
56 IAX_COMMAND_AUTHREP = 9,
57 IAX_COMMAND_INVAL = 10,
58 IAX_COMMAND_LAGRQ = 11,
59 IAX_COMMAND_LAGRP = 12,
60 /*! Registration request */
61 IAX_COMMAND_REGREQ = 13,
62 /*! Registration authentication required */
63 IAX_COMMAND_REGAUTH = 14,
64 /*! Registration accepted */
65 IAX_COMMAND_REGACK = 15,
66 /*! Registration rejected */
67 IAX_COMMAND_REGREJ = 16,
68 /*! Force release of registration */
69 IAX_COMMAND_REGREL = 17,
70 /*! If we receive voice before valid first voice frame, send this */
71 IAX_COMMAND_VNAK = 18,
72 /*! Request status of a dialplan entry */
73 IAX_COMMAND_DPREQ = 19,
74 /*! Request status of a dialplan entry */
75 IAX_COMMAND_DPREP = 20,
76 /*! Request a dial on channel brought up TBD */
77 IAX_COMMAND_DIAL = 21,
78 /*! Transfer Request */
79 IAX_COMMAND_TXREQ = 22,
80 /*! Transfer Connect */
81 IAX_COMMAND_TXCNT = 23,
82 /*! Transfer Accepted */
83 IAX_COMMAND_TXACC = 24,
84 /*! Transfer ready */
85 IAX_COMMAND_TXREADY = 25,
86 /*! Transfer release */
87 IAX_COMMAND_TXREL = 26,
88 /*! Transfer reject */
89 IAX_COMMAND_TXREJ = 27,
90 /*! Stop audio/video transmission */
91 IAX_COMMAND_QUELCH = 28,
92 /*! Resume audio/video transmission */
93 IAX_COMMAND_UNQUELCH = 29,
94 /*! Like ping, but does not require an open connection */
95 IAX_COMMAND_POKE = 30,
96 /*! Paging description */
97 IAX_COMMAND_PAGE = 31,
98 /*! Stand-alone message waiting indicator */
99 IAX_COMMAND_MWI = 32,
100 /*! Unsupported message received */
101 IAX_COMMAND_UNSUPPORT = 33,
102 /*! Request remote transfer */
103 IAX_COMMAND_TRANSFER = 34,
104 /*! Provision device */
105 IAX_COMMAND_PROVISION = 35,
106 /*! Download firmware */
107 IAX_COMMAND_FWDOWNL = 36,
108 /*! Firmware Data */
109 IAX_COMMAND_FWDATA = 37,
110 /*! Transfer media only */
111 IAX_COMMAND_TXMEDIA = 38,
112 /*! Command to rotate key */
113 IAX_COMMAND_RTKEY = 39,
116 /*! By default require re-registration once per minute */
117 #define IAX_DEFAULT_REG_EXPIRE 60
119 /*! How long to wait before closing bridged call */
120 #define IAX_LINGER_TIMEOUT 10
122 #define IAX_DEFAULT_PORTNO 4569
124 /*! IAX Information elements */
125 #define IAX_IE_CALLED_NUMBER 1 /*!< Number/extension being called - string */
126 #define IAX_IE_CALLING_NUMBER 2 /*!< Calling number - string */
127 #define IAX_IE_CALLING_ANI 3 /*!< Calling number ANI for billing - string */
128 #define IAX_IE_CALLING_NAME 4 /*!< Name of caller - string */
129 #define IAX_IE_CALLED_CONTEXT 5 /*!< Context for number - string */
130 #define IAX_IE_USERNAME 6 /*!< Username (peer or user) for authentication - string */
131 #define IAX_IE_PASSWORD 7 /*!< Password for authentication - string */
132 #define IAX_IE_CAPABILITY 8 /*!< Actual codec capability - unsigned int */
133 #define IAX_IE_FORMAT 9 /*!< Desired codec format - unsigned int */
134 #define IAX_IE_LANGUAGE 10 /*!< Desired language - string */
135 #define IAX_IE_VERSION 11 /*!< Protocol version - short */
136 #define IAX_IE_ADSICPE 12 /*!< CPE ADSI capability - short */
137 #define IAX_IE_DNID 13 /*!< Originally dialed DNID - string */
138 #define IAX_IE_AUTHMETHODS 14 /*!< Authentication method(s) - short */
139 #define IAX_IE_CHALLENGE 15 /*!< Challenge data for MD5/RSA - string */
140 #define IAX_IE_MD5_RESULT 16 /*!< MD5 challenge result - string */
141 #define IAX_IE_RSA_RESULT 17 /*!< RSA challenge result - string */
142 #define IAX_IE_APPARENT_ADDR 18 /*!< Apparent address of peer - struct sockaddr_in */
143 #define IAX_IE_REFRESH 19 /*!< When to refresh registration - short */
144 #define IAX_IE_DPSTATUS 20 /*!< Dialplan status - short */
145 #define IAX_IE_CALLNO 21 /*!< Call number of peer - short */
146 #define IAX_IE_CAUSE 22 /*!< Cause - string */
147 #define IAX_IE_IAX_UNKNOWN 23 /*!< Unknown IAX command - byte */
148 #define IAX_IE_MSGCOUNT 24 /*!< How many messages waiting - short */
149 #define IAX_IE_AUTOANSWER 25 /*!< Request auto-answering -- none */
150 #define IAX_IE_MUSICONHOLD 26 /*!< Request musiconhold with QUELCH -- none or string */
151 #define IAX_IE_TRANSFERID 27 /*!< Transfer Request Identifier -- int */
152 #define IAX_IE_RDNIS 28 /*!< Referring DNIS -- string */
153 #define IAX_IE_PROVISIONING 29 /*!< Provisioning info */
154 #define IAX_IE_AESPROVISIONING 30 /*!< AES Provisioning info */
155 #define IAX_IE_DATETIME 31 /*!< Date/Time */
156 #define IAX_IE_DEVICETYPE 32 /*!< Device Type -- string */
157 #define IAX_IE_SERVICEIDENT 33 /*!< Service Identifier -- string */
158 #define IAX_IE_FIRMWAREVER 34 /*!< Firmware revision -- u16 */
159 #define IAX_IE_FWBLOCKDESC 35 /*!< Firmware block description -- u32 */
160 #define IAX_IE_FWBLOCKDATA 36 /*!< Firmware block of data -- raw */
161 #define IAX_IE_PROVVER 37 /*!< Provisioning Version (u32) */
162 #define IAX_IE_CALLINGPRES 38 /*!< Calling presentation (u8) */
163 #define IAX_IE_CALLINGTON 39 /*!< Calling type of number (u8) */
164 #define IAX_IE_CALLINGTNS 40 /*!< Calling transit network select (u16) */
165 #define IAX_IE_SAMPLINGRATE 41 /*!< Supported sampling rates (u16) */
166 #define IAX_IE_CAUSECODE 42 /*!< Hangup cause (u8) */
167 #define IAX_IE_ENCRYPTION 43 /*!< Encryption format (u16) */
168 #define IAX_IE_ENCKEY 44 /*!< Encryption key (raw) */
169 #define IAX_IE_CODEC_PREFS 45 /*!< Codec Negotiation */
171 #define IAX_IE_RR_JITTER 46 /*!< Received jitter (as in RFC1889) u32 */
172 #define IAX_IE_RR_LOSS 47 /*!< Received loss (high byte loss pct, low 24 bits loss count, as in rfc1889 */
173 #define IAX_IE_RR_PKTS 48 /*!< Received frames (total frames received) u32 */
174 #define IAX_IE_RR_DELAY 49 /*!< Max playout delay for received frames (in ms) u16 */
175 #define IAX_IE_RR_DROPPED 50 /*!< Dropped frames (presumably by jitterbuf) u32 */
176 #define IAX_IE_RR_OOO 51 /*!< Frames received Out of Order u32 */
177 #define IAX_IE_VARIABLE 52 /*!< Remote variables */
178 #define IAX_IE_OSPTOKEN 53 /*!< OSP token */
180 #define IAX_MAX_OSPBLOCK_SIZE 254 /*!< Max OSP token block size, 255 bytes - 1 byte OSP token block index */
181 #define IAX_MAX_OSPBLOCK_NUM 4
182 #define IAX_MAX_OSPTOKEN_SIZE (IAX_MAX_OSPBLOCK_SIZE * IAX_MAX_OSPBLOCK_NUM)
183 #define IAX_MAX_OSPBUFF_SIZE (IAX_MAX_OSPTOKEN_SIZE + 16)
185 #define IAX_AUTH_PLAINTEXT (1 << 0)
186 #define IAX_AUTH_MD5 (1 << 1)
187 #define IAX_AUTH_RSA (1 << 2)
189 #define IAX_ENCRYPT_AES128 (1 << 0)
191 #define IAX_META_TRUNK 1 /*!< Trunk meta-message */
192 #define IAX_META_VIDEO 2 /*!< Video frame */
194 #define IAX_META_TRUNK_SUPERMINI 0 /*!< This trunk frame contains classic supermini frames */
195 #define IAX_META_TRUNK_MINI 1 /*!< This trunk frame contains trunked mini frames */
197 #define IAX_RATE_8KHZ (1 << 0) /*!< 8khz sampling (default if absent) */
198 #define IAX_RATE_11KHZ (1 << 1) /*!< 11.025khz sampling */
199 #define IAX_RATE_16KHZ (1 << 2) /*!< 16khz sampling */
200 #define IAX_RATE_22KHZ (1 << 3) /*!< 22.05khz sampling */
201 #define IAX_RATE_44KHZ (1 << 4) /*!< 44.1khz sampling */
202 #define IAX_RATE_48KHZ (1 << 5) /*!< 48khz sampling */
204 #define IAX_DPSTATUS_EXISTS (1 << 0)
205 #define IAX_DPSTATUS_CANEXIST (1 << 1)
206 #define IAX_DPSTATUS_NONEXISTENT (1 << 2)
207 #define IAX_DPSTATUS_IGNOREPAT (1 << 14)
208 #define IAX_DPSTATUS_MATCHMORE (1 << 15)
210 /*! Full frames are always delivered reliably */
211 struct ast_iax2_full_hdr {
212 unsigned short scallno; /*!< Source call number -- high bit must be 1 */
213 unsigned short dcallno; /*!< Destination call number -- high bit is 1 if retransmission */
214 unsigned int ts; /*!< 32-bit timestamp in milliseconds (from 1st transmission) */
215 unsigned char oseqno; /*!< Packet number (outgoing) */
216 unsigned char iseqno; /*!< Packet number (next incoming expected) */
217 unsigned char type; /*!< Frame type */
218 unsigned char csub; /*!< Compressed subclass */
219 unsigned char iedata[0];
220 } __attribute__ ((__packed__));
222 /*! Full frames are always delivered reliably */
223 struct ast_iax2_full_enc_hdr {
224 unsigned short scallno; /*!< Source call number -- high bit must be 1 */
225 unsigned short dcallno; /*!< Destination call number -- high bit is 1 if retransmission */
226 unsigned char encdata[0];
227 } __attribute__ ((__packed__));
229 /*! Mini header is used only for voice frames -- delivered unreliably */
230 struct ast_iax2_mini_hdr {
231 unsigned short callno; /*!< Source call number -- high bit must be 0, rest must be non-zero */
232 unsigned short ts; /*!< 16-bit Timestamp (high 16 bits from last ast_iax2_full_hdr) */
233 /* Frametype implicitly VOICE_FRAME */
234 /* subclass implicit from last ast_iax2_full_hdr */
235 unsigned char data[0];
236 } __attribute__ ((__packed__));
238 /*! Mini header is used only for voice frames -- delivered unreliably */
239 struct ast_iax2_mini_enc_hdr {
240 unsigned short callno; /*!< Source call number -- high bit must be 0, rest must be non-zero */
241 unsigned char encdata[0];
242 } __attribute__ ((__packed__));
244 struct ast_iax2_meta_hdr {
245 unsigned short zeros; /*!< Zeros field -- must be zero */
246 unsigned char metacmd; /*!< Meta command */
247 unsigned char cmddata; /*!< Command Data */
248 unsigned char data[0];
249 } __attribute__ ((__packed__));
251 struct ast_iax2_video_hdr {
252 unsigned short zeros; /*!< Zeros field -- must be zero */
253 unsigned short callno; /*!< Video call number */
254 unsigned short ts; /*!< Timestamp and mark if present */
255 unsigned char data[0];
256 } __attribute__ ((__packed__));
258 struct ast_iax2_meta_trunk_hdr {
259 unsigned int ts; /*!< 32-bit timestamp for all messages */
260 unsigned char data[0];
261 } __attribute__ ((__packed__));
263 struct ast_iax2_meta_trunk_entry {
264 unsigned short callno; /*!< Call number */
265 unsigned short len; /*!< Length of data for this callno */
266 } __attribute__ ((__packed__));
268 /*! When trunktimestamps are used, we use this format instead */
269 struct ast_iax2_meta_trunk_mini {
270 unsigned short len;
271 struct ast_iax2_mini_hdr mini; /*!< this is an actual miniframe */
272 } __attribute__ ((__packed__));
274 #define IAX_FIRMWARE_MAGIC 0x69617879
276 struct ast_iax2_firmware_header {
277 unsigned int magic; /*!< Magic number */
278 unsigned short version; /*!< Software version */
279 unsigned char devname[16]; /*!< Device */
280 unsigned int datalen; /*!< Data length of file beyond header */
281 unsigned char chksum[16]; /*!< Checksum of all data */
282 unsigned char data[0];
283 } __attribute__ ((__packed__));
284 #endif