Asterisk - The Open Source Telephony Project  18.5.0
iax2.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Implementation of Inter-Asterisk eXchange
5  *
6  * Copyright (C) 2003, Digium
7  *
8  * Mark Spencer <[email protected]>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13 
14 /*! \file
15  * \brief
16  *
17  * Implementation of Inter-Asterisk eXchange, version 2
18  * \ref iax2-parser.c
19  * \ref iax2-parser.h
20  * \ref chan_iax2.c
21  */
22 
23 #ifndef _IAX2_H
24 #define _IAX2_H
25 
26 /* Max version of IAX protocol we support */
27 #define IAX_PROTO_VERSION 2
28 
29 /* NOTE: It is recommended that IAX_MAX_CALLS be a power of 2, but it is not
30  * required. The maximum number of calls supported by the protocol is 32768.
31  *
32  * For LOW_MEMORY, we use 2049 for compatibility with earlier code because
33  * callno 2048 leaked out when the intended callno range was 2 - 2047. */
34 #if defined(LOW_MEMORY)
35 #define IAX_MAX_CALLS 2049
36 #else
37 #define IAX_MAX_CALLS 32768
38 #endif
39 
40 #define IAX_FLAG_FULL 0x8000
41 
42 #define IAX_FLAG_RETRANS 0x8000
43 
44 #define IAX_FLAG_SC_LOG 0x80
45 
46 #define IAX_MAX_SHIFT 0x3F
47 
48 #define IAX_WINDOW 64
49 
50 /*! Subclass for AST_FRAME_IAX */
64  /*! Registration request */
66  /*! Registration authentication required */
68  /*! Registration accepted */
70  /*! Registration rejected */
72  /*! Force release of registration */
74  /*! If we receive voice before valid first voice frame, send this */
76  /*! Request status of a dialplan entry */
78  /*! Request status of a dialplan entry */
80  /*! Request a dial on channel brought up TBD */
82  /*! Transfer Request */
84  /*! Transfer Connect */
86  /*! Transfer Accepted */
88  /*! Transfer ready */
90  /*! Transfer release */
92  /*! Transfer reject */
94  /*! Stop audio/video transmission */
96  /*! Resume audio/video transmission */
98  /*! Like ping, but does not require an open connection */
100  /*! Paging description */
102  /*! Stand-alone message waiting indicator */
104  /*! Unsupported message received */
106  /*! Request remote transfer */
108  /*! Provision device */
110  /*! Download firmware */
112  /*! Firmware Data */
114  /*! Transfer media only */
116  /*! Command to rotate key */
118  /*! Call number token */
120 };
121 
122 /*! By default require re-registration once per minute */
123 #define IAX_DEFAULT_REG_EXPIRE 60
124 
125 /*! How long to wait before closing bridged call */
126 #define IAX_LINGER_TIMEOUT 10
127 
128 #define IAX_DEFAULT_PORTNO 4569
129 
130 /*! IAX Information elements */
131 #define IAX_IE_CALLED_NUMBER 1 /*!< Number/extension being called - string */
132 #define IAX_IE_CALLING_NUMBER 2 /*!< Calling number - string */
133 #define IAX_IE_CALLING_ANI 3 /*!< Calling number ANI for billing - string */
134 #define IAX_IE_CALLING_NAME 4 /*!< Name of caller - string */
135 #define IAX_IE_CALLED_CONTEXT 5 /*!< Context for number - string */
136 #define IAX_IE_USERNAME 6 /*!< Username (peer or user) for authentication - string */
137 #define IAX_IE_PASSWORD 7 /*!< Password for authentication - string */
138 #define IAX_IE_CAPABILITY 8 /*!< Actual codec capability - unsigned int */
139 #define IAX_IE_FORMAT 9 /*!< Desired codec format - unsigned int */
140 #define IAX_IE_LANGUAGE 10 /*!< Desired language - string */
141 #define IAX_IE_VERSION 11 /*!< Protocol version - short */
142 #define IAX_IE_ADSICPE 12 /*!< CPE ADSI capability - short */
143 #define IAX_IE_DNID 13 /*!< Originally dialed DNID - string */
144 #define IAX_IE_AUTHMETHODS 14 /*!< Authentication method(s) - short */
145 #define IAX_IE_CHALLENGE 15 /*!< Challenge data for MD5/RSA - string */
146 #define IAX_IE_MD5_RESULT 16 /*!< MD5 challenge result - string */
147 #define IAX_IE_RSA_RESULT 17 /*!< RSA challenge result - string */
148 #define IAX_IE_APPARENT_ADDR 18 /*!< Apparent address of peer - struct sockaddr_in */
149 #define IAX_IE_REFRESH 19 /*!< When to refresh registration - short */
150 #define IAX_IE_DPSTATUS 20 /*!< Dialplan status - short */
151 #define IAX_IE_CALLNO 21 /*!< Call number of peer - short */
152 #define IAX_IE_CAUSE 22 /*!< Cause - string */
153 #define IAX_IE_IAX_UNKNOWN 23 /*!< Unknown IAX command - byte */
154 #define IAX_IE_MSGCOUNT 24 /*!< How many messages waiting - short */
155 #define IAX_IE_AUTOANSWER 25 /*!< Request auto-answering -- none */
156 #define IAX_IE_MUSICONHOLD 26 /*!< Request musiconhold with QUELCH -- none or string */
157 #define IAX_IE_TRANSFERID 27 /*!< Transfer Request Identifier -- int */
158 #define IAX_IE_RDNIS 28 /*!< Referring DNIS -- string */
159 #define IAX_IE_PROVISIONING 29 /*!< Provisioning info */
160 #define IAX_IE_AESPROVISIONING 30 /*!< AES Provisioning info */
161 #define IAX_IE_DATETIME 31 /*!< Date/Time */
162 #define IAX_IE_DEVICETYPE 32 /*!< Device Type -- string */
163 #define IAX_IE_SERVICEIDENT 33 /*!< Service Identifier -- string */
164 #define IAX_IE_FIRMWAREVER 34 /*!< Firmware revision -- u16 */
165 #define IAX_IE_FWBLOCKDESC 35 /*!< Firmware block description -- u32 */
166 #define IAX_IE_FWBLOCKDATA 36 /*!< Firmware block of data -- raw */
167 #define IAX_IE_PROVVER 37 /*!< Provisioning Version (u32) */
168 #define IAX_IE_CALLINGPRES 38 /*!< Calling presentation (u8) */
169 #define IAX_IE_CALLINGTON 39 /*!< Calling type of number (u8) */
170 #define IAX_IE_CALLINGTNS 40 /*!< Calling transit network select (u16) */
171 #define IAX_IE_SAMPLINGRATE 41 /*!< Supported sampling rates (u16) */
172 #define IAX_IE_CAUSECODE 42 /*!< Hangup cause (u8) */
173 #define IAX_IE_ENCRYPTION 43 /*!< Encryption format (u16) */
174 #define IAX_IE_ENCKEY 44 /*!< Encryption key (raw) */
175 #define IAX_IE_CODEC_PREFS 45 /*!< Codec Negotiation */
176 
177 #define IAX_IE_RR_JITTER 46 /*!< Received jitter (as in RFC1889) u32 */
178 #define IAX_IE_RR_LOSS 47 /*!< Received loss (high byte loss pct, low 24 bits loss count, as in rfc1889 */
179 #define IAX_IE_RR_PKTS 48 /*!< Received frames (total frames received) u32 */
180 #define IAX_IE_RR_DELAY 49 /*!< Max playout delay for received frames (in ms) u16 */
181 #define IAX_IE_RR_DROPPED 50 /*!< Dropped frames (presumably by jitterbuf) u32 */
182 #define IAX_IE_RR_OOO 51 /*!< Frames received Out of Order u32 */
183 #define IAX_IE_VARIABLE 52 /*!< Remote variables */
184 #define IAX_IE_OSPTOKEN 53 /*!< OSP token */
185 #define IAX_IE_CALLTOKEN 54 /*!< Call number security token */
186 
187 #define IAX_IE_CAPABILITY2 55 /*!< Actual codec capability - u8 version + integer array */
188 #define IAX_IE_FORMAT2 56 /*!< Desired codec format - u8 version + integer array */
189 
190 #define IAX_MAX_OSPBLOCK_SIZE 254 /*!< Max OSP token block size, 255 bytes - 1 byte OSP token block index */
191 #define IAX_MAX_OSPBLOCK_NUM 4
192 #define IAX_MAX_OSPTOKEN_SIZE (IAX_MAX_OSPBLOCK_SIZE * IAX_MAX_OSPBLOCK_NUM)
193 #define IAX_MAX_OSPBUFF_SIZE (IAX_MAX_OSPTOKEN_SIZE + 16)
194 
195 #define IAX_AUTH_PLAINTEXT (1 << 0)
196 #define IAX_AUTH_MD5 (1 << 1)
197 #define IAX_AUTH_RSA (1 << 2)
198 
199 #define IAX_ENCRYPT_AES128 (1 << 0)
200 #define IAX_ENCRYPT_KEYROTATE (1 << 15) /*!< Keyrotation support */
201 
202 #define IAX_META_TRUNK 1 /*!< Trunk meta-message */
203 #define IAX_META_VIDEO 2 /*!< Video frame */
204 
205 #define IAX_META_TRUNK_SUPERMINI 0 /*!< This trunk frame contains classic supermini frames */
206 #define IAX_META_TRUNK_MINI 1 /*!< This trunk frame contains trunked mini frames */
207 
208 #define IAX_RATE_8KHZ (1 << 0) /*!< 8khz sampling (default if absent) */
209 #define IAX_RATE_11KHZ (1 << 1) /*!< 11.025khz sampling */
210 #define IAX_RATE_16KHZ (1 << 2) /*!< 16khz sampling */
211 #define IAX_RATE_22KHZ (1 << 3) /*!< 22.05khz sampling */
212 #define IAX_RATE_44KHZ (1 << 4) /*!< 44.1khz sampling */
213 #define IAX_RATE_48KHZ (1 << 5) /*!< 48khz sampling */
214 
215 #define IAX_DPSTATUS_EXISTS (1 << 0)
216 #define IAX_DPSTATUS_CANEXIST (1 << 1)
217 #define IAX_DPSTATUS_NONEXISTENT (1 << 2)
218 #define IAX_DPSTATUS_IGNOREPAT (1 << 14)
219 #define IAX_DPSTATUS_MATCHMORE (1 << 15)
220 
221 /*! iax2 format bit field for handling codecs the old way */
222 typedef int64_t iax2_format;
223 
224 /*!\brief iax2 wrapper function for ast_getformatname */
226 
227 /*! Full frames are always delivered reliably */
229  unsigned short scallno; /*!< Source call number -- high bit must be 1 */
230  unsigned short dcallno; /*!< Destination call number -- high bit is 1 if retransmission */
231  unsigned int ts; /*!< 32-bit timestamp in milliseconds (from 1st transmission) */
232  unsigned char oseqno; /*!< Packet number (outgoing) */
233  unsigned char iseqno; /*!< Packet number (next incoming expected) */
234  unsigned char type; /*!< Frame type */
235  unsigned char csub; /*!< Compressed subclass */
236  unsigned char iedata[0];
237 } __attribute__ ((__packed__));
238 
239 /*! Full frames are always delivered reliably */
241  unsigned short scallno; /*!< Source call number -- high bit must be 1 */
242  unsigned short dcallno; /*!< Destination call number -- high bit is 1 if retransmission */
243  unsigned char encdata[0];
244 } __attribute__ ((__packed__));
245 
246 /*! Mini header is used only for voice frames -- delivered unreliably */
248  unsigned short callno; /*!< Source call number -- high bit must be 0, rest must be non-zero */
249  unsigned short ts; /*!< 16-bit Timestamp (high 16 bits from last ast_iax2_full_hdr) */
250  /* Frametype implicitly VOICE_FRAME */
251  /* subclass implicit from last ast_iax2_full_hdr */
252  unsigned char data[0];
253 } __attribute__ ((__packed__));
254 
255 /*! Mini header is used only for voice frames -- delivered unreliably */
257  unsigned short callno; /*!< Source call number -- high bit must be 0, rest must be non-zero */
258  unsigned char encdata[0];
259 } __attribute__ ((__packed__));
260 
262  unsigned short zeros; /*!< Zeros field -- must be zero */
263  unsigned char metacmd; /*!< Meta command */
264  unsigned char cmddata; /*!< Command Data */
265  unsigned char data[0];
266 } __attribute__ ((__packed__));
267 
269  unsigned short zeros; /*!< Zeros field -- must be zero */
270  unsigned short callno; /*!< Video call number */
271  unsigned short ts; /*!< Timestamp and mark if present */
272  unsigned char data[0];
273 } __attribute__ ((__packed__));
274 
276  unsigned int ts; /*!< 32-bit timestamp for all messages */
277  unsigned char data[0];
278 } __attribute__ ((__packed__));
279 
281  unsigned short callno; /*!< Call number */
282  unsigned short len; /*!< Length of data for this callno */
283 } __attribute__ ((__packed__));
284 
285 /*! When trunktimestamps are used, we use this format instead */
287  unsigned short len;
288  struct ast_iax2_mini_hdr mini; /*!< this is an actual miniframe */
289 } __attribute__ ((__packed__));
290 
291 #define IAX_FIRMWARE_MAGIC 0x69617879
292 
294  unsigned int magic; /*!< Magic number */
295  unsigned short version; /*!< Software version */
296  unsigned char devname[16]; /*!< Device */
297  unsigned int datalen; /*!< Data length of file beyond header */
298  unsigned char chksum[16]; /*!< Checksum of all data */
299  unsigned char data[0];
300 } __attribute__ ((__packed__));
301 #endif
unsigned int datalen
Definition: iax2.h:297
unsigned short callno
Definition: iax2.h:257
unsigned char csub
Definition: iax2.h:235
unsigned int magic
Definition: iax2.h:294
Definition: iax2.h:280
unsigned short scallno
Definition: iax2.h:229
iax_frame_subclass
Definition: iax2.h:51
unsigned short version
Definition: iax2.h:295
unsigned char oseqno
Definition: iax2.h:232
unsigned short callno
Definition: iax2.h:270
unsigned short callno
Definition: iax2.h:248
unsigned char type
Definition: iax2.h:234
unsigned short dcallno
Definition: iax2.h:230
unsigned int ts
Definition: iax2.h:276
unsigned short dcallno
Definition: iax2.h:242
unsigned short len
Definition: iax2.h:287
unsigned short scallno
Definition: iax2.h:241
unsigned short len
Definition: iax2.h:282
unsigned short zeros
Definition: iax2.h:262
unsigned short callno
Definition: iax2.h:281
unsigned short ts
Definition: iax2.h:271
unsigned short ts
Definition: iax2.h:249
unsigned char cmddata
Definition: iax2.h:264
unsigned char iedata[0]
Definition: iax2.h:236
unsigned char iseqno
Definition: iax2.h:233
const char * iax2_getformatname(iax2_format format)
iax2 wrapper function for ast_getformatname
Definition: chan_iax2.c:1903
unsigned short zeros
Definition: iax2.h:269
static snd_pcm_format_t format
Definition: chan_alsa.c:102
unsigned char metacmd
Definition: iax2.h:263
int64_t iax2_format
Definition: iax2.h:222
unsigned int ts
Definition: iax2.h:231