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