Mon Aug 31 12:30:08 2015

Asterisk developer's documentation


iax2.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * Implementation of Inter-Asterisk eXchange
00005  * 
00006  * Copyright (C) 2003, Digium
00007  *
00008  * Mark Spencer <markster@linux-support.net>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License
00012  */
00013 
00014 /*! \file
00015  * \brief
00016  *
00017  * Implementation of Inter-Asterisk eXchange, version 2
00018  * \ref iax2-parser.c
00019  * \ref iax2-parser.h
00020  * \ref chan_iax2.c
00021  */
00022  
00023 #ifndef _IAX2_H
00024 #define _IAX2_H
00025 
00026 /* Max version of IAX protocol we support */
00027 #define IAX_PROTO_VERSION 2
00028 
00029 /* NOTE: It is recommended that IAX_MAX_CALLS be a power of 2, but it is not
00030  * required.  The maximum number of calls supported by the protocol is 32768.
00031  *
00032  * For LOW_MEMORY, we use 2049 for compatibility with earlier code because
00033  * callno 2048 leaked out when the intended callno range was 2 - 2047. */
00034 #if defined(LOW_MEMORY)
00035 #define IAX_MAX_CALLS 2049
00036 #else
00037 #define IAX_MAX_CALLS 32768
00038 #endif
00039 
00040 #define IAX_FLAG_FULL      0x8000
00041 
00042 #define IAX_FLAG_RETRANS   0x8000
00043 
00044 #define IAX_FLAG_SC_LOG    0x80
00045 
00046 #define IAX_MAX_SHIFT      0x3F
00047 
00048 #define IAX_WINDOW         64
00049 
00050 /*! Subclass for AST_FRAME_IAX */
00051 enum iax_frame_subclass {
00052    IAX_COMMAND_NEW =       1,
00053    IAX_COMMAND_PING =      2,
00054    IAX_COMMAND_PONG =      3,
00055    IAX_COMMAND_ACK =       4,
00056    IAX_COMMAND_HANGUP =    5,
00057    IAX_COMMAND_REJECT =    6,
00058    IAX_COMMAND_ACCEPT =    7,
00059    IAX_COMMAND_AUTHREQ =   8,
00060    IAX_COMMAND_AUTHREP =   9,
00061    IAX_COMMAND_INVAL =     10,
00062    IAX_COMMAND_LAGRQ =     11,
00063    IAX_COMMAND_LAGRP =     12,
00064    /*! Registration request */
00065    IAX_COMMAND_REGREQ =    13,
00066    /*! Registration authentication required */
00067    IAX_COMMAND_REGAUTH =   14,
00068    /*! Registration accepted */
00069    IAX_COMMAND_REGACK =    15,
00070    /*! Registration rejected */
00071    IAX_COMMAND_REGREJ =    16,
00072    /*! Force release of registration */
00073    IAX_COMMAND_REGREL =    17,
00074    /*! If we receive voice before valid first voice frame, send this */
00075    IAX_COMMAND_VNAK =      18,
00076    /*! Request status of a dialplan entry */
00077    IAX_COMMAND_DPREQ =     19,
00078    /*! Request status of a dialplan entry */
00079    IAX_COMMAND_DPREP =     20,
00080    /*! Request a dial on channel brought up TBD */
00081    IAX_COMMAND_DIAL =      21,
00082    /*! Transfer Request */
00083    IAX_COMMAND_TXREQ =     22,
00084    /*! Transfer Connect */
00085    IAX_COMMAND_TXCNT =     23,
00086    /*! Transfer Accepted */
00087    IAX_COMMAND_TXACC =     24,
00088    /*! Transfer ready */
00089    IAX_COMMAND_TXREADY =   25,
00090    /*! Transfer release */
00091    IAX_COMMAND_TXREL =     26,
00092    /*! Transfer reject */
00093    IAX_COMMAND_TXREJ =     27,
00094    /*! Stop audio/video transmission */
00095    IAX_COMMAND_QUELCH =    28,
00096    /*! Resume audio/video transmission */
00097    IAX_COMMAND_UNQUELCH =  29,
00098    /*! Like ping, but does not require an open connection */
00099    IAX_COMMAND_POKE =      30,
00100    /*! Paging description */
00101    IAX_COMMAND_PAGE =      31,
00102    /*! Stand-alone message waiting indicator */
00103    IAX_COMMAND_MWI =       32,
00104    /*! Unsupported message received */
00105    IAX_COMMAND_UNSUPPORT = 33,
00106    /*! Request remote transfer */
00107    IAX_COMMAND_TRANSFER =  34,
00108    /*! Provision device */
00109    IAX_COMMAND_PROVISION = 35,
00110    /*! Download firmware */
00111    IAX_COMMAND_FWDOWNL =   36,
00112    /*! Firmware Data */
00113    IAX_COMMAND_FWDATA =    37,
00114    /*! Transfer media only */
00115    IAX_COMMAND_TXMEDIA =   38,
00116    /*! Command to rotate key */
00117    IAX_COMMAND_RTKEY =     39,
00118    /*! Call number token */
00119    IAX_COMMAND_CALLTOKEN = 40,
00120 };
00121 
00122 /*! By default require re-registration once per minute */
00123 #define IAX_DEFAULT_REG_EXPIRE  60
00124 
00125 /*! How long to wait before closing bridged call */
00126 #define IAX_LINGER_TIMEOUT    10
00127 
00128 #define IAX_DEFAULT_PORTNO    4569
00129 
00130 /*! IAX Information elements */
00131 #define IAX_IE_CALLED_NUMBER     1     /*!< Number/extension being called - string */
00132 #define IAX_IE_CALLING_NUMBER    2     /*!< Calling number - string */
00133 #define IAX_IE_CALLING_ANI       3     /*!< Calling number ANI for billing  - string */
00134 #define IAX_IE_CALLING_NAME         4     /*!< Name of caller - string */
00135 #define IAX_IE_CALLED_CONTEXT    5     /*!< Context for number - string */
00136 #define IAX_IE_USERNAME          6     /*!< Username (peer or user) for authentication - string */
00137 #define IAX_IE_PASSWORD          7     /*!< Password for authentication - string */
00138 #define IAX_IE_CAPABILITY        8     /*!< Actual codec capability - unsigned int */
00139 #define IAX_IE_FORMAT            9     /*!< Desired codec format - unsigned int */
00140 #define IAX_IE_LANGUAGE          10    /*!< Desired language - string */
00141 #define IAX_IE_VERSION           11    /*!< Protocol version - short */
00142 #define IAX_IE_ADSICPE           12    /*!< CPE ADSI capability - short */
00143 #define IAX_IE_DNID              13    /*!< Originally dialed DNID - string */
00144 #define IAX_IE_AUTHMETHODS       14    /*!< Authentication method(s) - short */
00145 #define IAX_IE_CHALLENGE         15    /*!< Challenge data for MD5/RSA - string */
00146 #define IAX_IE_MD5_RESULT        16    /*!< MD5 challenge result - string */
00147 #define IAX_IE_RSA_RESULT        17    /*!< RSA challenge result - string */
00148 #define IAX_IE_APPARENT_ADDR     18    /*!< Apparent address of peer - struct sockaddr_in */
00149 #define IAX_IE_REFRESH           19    /*!< When to refresh registration - short */
00150 #define IAX_IE_DPSTATUS          20    /*!< Dialplan status - short */
00151 #define IAX_IE_CALLNO            21    /*!< Call number of peer - short */
00152 #define IAX_IE_CAUSE          22    /*!< Cause - string */
00153 #define IAX_IE_IAX_UNKNOWN       23    /*!< Unknown IAX command - byte */
00154 #define IAX_IE_MSGCOUNT          24    /*!< How many messages waiting - short */
00155 #define IAX_IE_AUTOANSWER        25    /*!< Request auto-answering -- none */
00156 #define IAX_IE_MUSICONHOLD       26    /*!< Request musiconhold with QUELCH -- none or string */
00157 #define IAX_IE_TRANSFERID        27    /*!< Transfer Request Identifier -- int */
00158 #define IAX_IE_RDNIS          28    /*!< Referring DNIS -- string */
00159 #define IAX_IE_PROVISIONING         29    /*!< Provisioning info */
00160 #define IAX_IE_AESPROVISIONING      30    /*!< AES Provisioning info */
00161 #define IAX_IE_DATETIME          31    /*!< Date/Time */
00162 #define IAX_IE_DEVICETYPE        32    /*!< Device Type -- string */
00163 #define IAX_IE_SERVICEIDENT         33    /*!< Service Identifier -- string */
00164 #define IAX_IE_FIRMWAREVER       34    /*!< Firmware revision -- u16 */
00165 #define IAX_IE_FWBLOCKDESC       35    /*!< Firmware block description -- u32 */
00166 #define IAX_IE_FWBLOCKDATA       36    /*!< Firmware block of data -- raw */
00167 #define IAX_IE_PROVVER           37    /*!< Provisioning Version (u32) */
00168 #define IAX_IE_CALLINGPRES       38    /*!< Calling presentation (u8) */
00169 #define IAX_IE_CALLINGTON        39    /*!< Calling type of number (u8) */
00170 #define IAX_IE_CALLINGTNS        40    /*!< Calling transit network select (u16) */
00171 #define IAX_IE_SAMPLINGRATE         41    /*!< Supported sampling rates (u16) */
00172 #define IAX_IE_CAUSECODE         42    /*!< Hangup cause (u8) */
00173 #define IAX_IE_ENCRYPTION        43    /*!< Encryption format (u16) */
00174 #define IAX_IE_ENCKEY            44    /*!< Encryption key (raw) */
00175 #define IAX_IE_CODEC_PREFS          45      /*!< Codec Negotiation */
00176 
00177 #define IAX_IE_RR_JITTER         46    /*!< Received jitter (as in RFC1889) u32 */
00178 #define IAX_IE_RR_LOSS           47    /*!< Received loss (high byte loss pct, low 24 bits loss count, as in rfc1889 */
00179 #define IAX_IE_RR_PKTS           48    /*!< Received frames (total frames received) u32 */
00180 #define IAX_IE_RR_DELAY          49    /*!< Max playout delay for received frames (in ms) u16 */
00181 #define IAX_IE_RR_DROPPED        50    /*!< Dropped frames (presumably by jitterbuf) u32 */
00182 #define IAX_IE_RR_OOO            51    /*!< Frames received Out of Order u32 */
00183 #define IAX_IE_VARIABLE          52    /*!< Remote variables */
00184 #define IAX_IE_OSPTOKEN          53    /*!< OSP token */
00185 #define IAX_IE_CALLTOKEN         54    /*!< Call number security token */
00186 
00187 #define IAX_IE_CAPABILITY2          55      /*!< Actual codec capability - u8 version + integer array */
00188 #define IAX_IE_FORMAT2              56      /*!< Desired codec format - u8 version + integer array */
00189 
00190 #define IAX_MAX_OSPBLOCK_SIZE    254      /*!< Max OSP token block size, 255 bytes - 1 byte OSP token block index */
00191 #define IAX_MAX_OSPBLOCK_NUM     4
00192 #define IAX_MAX_OSPTOKEN_SIZE    (IAX_MAX_OSPBLOCK_SIZE * IAX_MAX_OSPBLOCK_NUM)
00193 #define IAX_MAX_OSPBUFF_SIZE     (IAX_MAX_OSPTOKEN_SIZE + 16)
00194 
00195 #define IAX_AUTH_PLAINTEXT       (1 << 0)
00196 #define IAX_AUTH_MD5          (1 << 1)
00197 #define IAX_AUTH_RSA          (1 << 2)
00198 
00199 #define IAX_ENCRYPT_AES128       (1 << 0)
00200 #define IAX_ENCRYPT_KEYROTATE       (1 << 15)       /*!< Keyrotation support */
00201 
00202 #define IAX_META_TRUNK           1     /*!< Trunk meta-message */
00203 #define IAX_META_VIDEO           2     /*!< Video frame */
00204 
00205 #define IAX_META_TRUNK_SUPERMINI    0  /*!< This trunk frame contains classic supermini frames */
00206 #define IAX_META_TRUNK_MINI         1  /*!< This trunk frame contains trunked mini frames */
00207 
00208 #define IAX_RATE_8KHZ            (1 << 0) /*!< 8khz sampling (default if absent) */
00209 #define IAX_RATE_11KHZ           (1 << 1) /*!< 11.025khz sampling */
00210 #define IAX_RATE_16KHZ           (1 << 2) /*!< 16khz sampling */
00211 #define IAX_RATE_22KHZ           (1 << 3) /*!< 22.05khz sampling */
00212 #define IAX_RATE_44KHZ           (1 << 4) /*!< 44.1khz sampling */
00213 #define IAX_RATE_48KHZ           (1 << 5) /*!< 48khz sampling */
00214 
00215 #define IAX_DPSTATUS_EXISTS         (1 << 0)
00216 #define IAX_DPSTATUS_CANEXIST    (1 << 1)
00217 #define IAX_DPSTATUS_NONEXISTENT (1 << 2)
00218 #define IAX_DPSTATUS_IGNOREPAT      (1 << 14)
00219 #define IAX_DPSTATUS_MATCHMORE      (1 << 15)
00220 
00221 /*! Full frames are always delivered reliably */
00222 struct ast_iax2_full_hdr {
00223    unsigned short scallno; /*!< Source call number -- high bit must be 1 */
00224    unsigned short dcallno; /*!< Destination call number -- high bit is 1 if retransmission */
00225    unsigned int ts;     /*!< 32-bit timestamp in milliseconds (from 1st transmission) */
00226    unsigned char oseqno;   /*!< Packet number (outgoing) */
00227    unsigned char iseqno;   /*!< Packet number (next incoming expected) */
00228    unsigned char type;     /*!< Frame type */
00229    unsigned char csub;     /*!< Compressed subclass */
00230    unsigned char iedata[0];
00231 } __attribute__ ((__packed__));
00232 
00233 /*! Full frames are always delivered reliably */
00234 struct ast_iax2_full_enc_hdr {
00235    unsigned short scallno; /*!< Source call number -- high bit must be 1 */
00236    unsigned short dcallno; /*!< Destination call number -- high bit is 1 if retransmission */
00237    unsigned char encdata[0];
00238 } __attribute__ ((__packed__));
00239 
00240 /*! Mini header is used only for voice frames -- delivered unreliably */
00241 struct ast_iax2_mini_hdr {
00242    unsigned short callno;  /*!< Source call number -- high bit must be 0, rest must be non-zero */
00243    unsigned short ts;      /*!< 16-bit Timestamp (high 16 bits from last ast_iax2_full_hdr) */
00244                      /* Frametype implicitly VOICE_FRAME */
00245                      /* subclass implicit from last ast_iax2_full_hdr */
00246    unsigned char data[0];
00247 } __attribute__ ((__packed__));
00248 
00249 /*! Mini header is used only for voice frames -- delivered unreliably */
00250 struct ast_iax2_mini_enc_hdr {
00251    unsigned short callno;  /*!< Source call number -- high bit must be 0, rest must be non-zero */
00252    unsigned char encdata[0];
00253 } __attribute__ ((__packed__));
00254 
00255 struct ast_iax2_meta_hdr {
00256    unsigned short zeros;         /*!< Zeros field -- must be zero */
00257    unsigned char metacmd;        /*!< Meta command */
00258    unsigned char cmddata;        /*!< Command Data */
00259    unsigned char data[0];
00260 } __attribute__ ((__packed__));
00261 
00262 struct ast_iax2_video_hdr {
00263    unsigned short zeros;         /*!< Zeros field -- must be zero */
00264    unsigned short callno;        /*!< Video call number */
00265    unsigned short ts;            /*!< Timestamp and mark if present */
00266    unsigned char data[0];
00267 } __attribute__ ((__packed__));
00268 
00269 struct ast_iax2_meta_trunk_hdr {
00270    unsigned int ts;           /*!< 32-bit timestamp for all messages */
00271    unsigned char data[0];
00272 } __attribute__ ((__packed__));
00273 
00274 struct ast_iax2_meta_trunk_entry {
00275    unsigned short callno;        /*!< Call number */
00276    unsigned short len;           /*!< Length of data for this callno */
00277 } __attribute__ ((__packed__));
00278 
00279 /*! When trunktimestamps are used, we use this format instead */
00280 struct ast_iax2_meta_trunk_mini {
00281    unsigned short len;
00282    struct ast_iax2_mini_hdr mini;      /*!< this is an actual miniframe */
00283 } __attribute__ ((__packed__));
00284 
00285 #define IAX_FIRMWARE_MAGIC 0x69617879
00286 
00287 struct ast_iax2_firmware_header {
00288    unsigned int magic;     /*!< Magic number */
00289    unsigned short version;    /*!< Software version */
00290    unsigned char devname[16]; /*!< Device */
00291    unsigned int datalen;      /*!< Data length of file beyond header */
00292    unsigned char chksum[16];  /*!< Checksum of all data */
00293    unsigned char data[0];
00294 } __attribute__ ((__packed__));
00295 #endif

Generated on 31 Aug 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1