Fri Jun 19 12:09:46 2009

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

Generated on Fri Jun 19 12:09:46 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7