Mon Oct 8 12:39:03 2012

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      0x3F
00043 
00044 #define IAX_WINDOW         64
00045 
00046 /*! Subclass for AST_FRAME_IAX */
00047 enum iax_frame_subclass {
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    /*! Call number token */
00115    IAX_COMMAND_CALLTOKEN = 40,
00116 };
00117 
00118 /*! By default require re-registration once per minute */
00119 #define IAX_DEFAULT_REG_EXPIRE  60
00120 
00121 /*! How long to wait before closing bridged call */
00122 #define IAX_LINGER_TIMEOUT    10
00123 
00124 #define IAX_DEFAULT_PORTNO    4569
00125 
00126 /*! IAX Information elements */
00127 #define IAX_IE_CALLED_NUMBER     1     /*!< Number/extension being called - string */
00128 #define IAX_IE_CALLING_NUMBER    2     /*!< Calling number - string */
00129 #define IAX_IE_CALLING_ANI       3     /*!< Calling number ANI for billing  - string */
00130 #define IAX_IE_CALLING_NAME         4     /*!< Name of caller - string */
00131 #define IAX_IE_CALLED_CONTEXT    5     /*!< Context for number - string */
00132 #define IAX_IE_USERNAME          6     /*!< Username (peer or user) for authentication - string */
00133 #define IAX_IE_PASSWORD          7     /*!< Password for authentication - string */
00134 #define IAX_IE_CAPABILITY        8     /*!< Actual codec capability - unsigned int */
00135 #define IAX_IE_FORMAT            9     /*!< Desired codec format - unsigned int */
00136 #define IAX_IE_LANGUAGE          10    /*!< Desired language - string */
00137 #define IAX_IE_VERSION           11    /*!< Protocol version - short */
00138 #define IAX_IE_ADSICPE           12    /*!< CPE ADSI capability - short */
00139 #define IAX_IE_DNID              13    /*!< Originally dialed DNID - string */
00140 #define IAX_IE_AUTHMETHODS       14    /*!< Authentication method(s) - short */
00141 #define IAX_IE_CHALLENGE         15    /*!< Challenge data for MD5/RSA - string */
00142 #define IAX_IE_MD5_RESULT        16    /*!< MD5 challenge result - string */
00143 #define IAX_IE_RSA_RESULT        17    /*!< RSA challenge result - string */
00144 #define IAX_IE_APPARENT_ADDR     18    /*!< Apparent address of peer - struct sockaddr_in */
00145 #define IAX_IE_REFRESH           19    /*!< When to refresh registration - short */
00146 #define IAX_IE_DPSTATUS          20    /*!< Dialplan status - short */
00147 #define IAX_IE_CALLNO            21    /*!< Call number of peer - short */
00148 #define IAX_IE_CAUSE          22    /*!< Cause - string */
00149 #define IAX_IE_IAX_UNKNOWN       23    /*!< Unknown IAX command - byte */
00150 #define IAX_IE_MSGCOUNT          24    /*!< How many messages waiting - short */
00151 #define IAX_IE_AUTOANSWER        25    /*!< Request auto-answering -- none */
00152 #define IAX_IE_MUSICONHOLD       26    /*!< Request musiconhold with QUELCH -- none or string */
00153 #define IAX_IE_TRANSFERID        27    /*!< Transfer Request Identifier -- int */
00154 #define IAX_IE_RDNIS          28    /*!< Referring DNIS -- string */
00155 #define IAX_IE_PROVISIONING         29    /*!< Provisioning info */
00156 #define IAX_IE_AESPROVISIONING      30    /*!< AES Provisioning info */
00157 #define IAX_IE_DATETIME          31    /*!< Date/Time */
00158 #define IAX_IE_DEVICETYPE        32    /*!< Device Type -- string */
00159 #define IAX_IE_SERVICEIDENT         33    /*!< Service Identifier -- string */
00160 #define IAX_IE_FIRMWAREVER       34    /*!< Firmware revision -- u16 */
00161 #define IAX_IE_FWBLOCKDESC       35    /*!< Firmware block description -- u32 */
00162 #define IAX_IE_FWBLOCKDATA       36    /*!< Firmware block of data -- raw */
00163 #define IAX_IE_PROVVER           37    /*!< Provisioning Version (u32) */
00164 #define IAX_IE_CALLINGPRES       38    /*!< Calling presentation (u8) */
00165 #define IAX_IE_CALLINGTON        39    /*!< Calling type of number (u8) */
00166 #define IAX_IE_CALLINGTNS        40    /*!< Calling transit network select (u16) */
00167 #define IAX_IE_SAMPLINGRATE         41    /*!< Supported sampling rates (u16) */
00168 #define IAX_IE_CAUSECODE         42    /*!< Hangup cause (u8) */
00169 #define IAX_IE_ENCRYPTION        43    /*!< Encryption format (u16) */
00170 #define IAX_IE_ENCKEY            44    /*!< Encryption key (raw) */
00171 #define IAX_IE_CODEC_PREFS          45      /*!< Codec Negotiation */
00172 
00173 #define IAX_IE_RR_JITTER         46    /*!< Received jitter (as in RFC1889) u32 */
00174 #define IAX_IE_RR_LOSS           47    /*!< Received loss (high byte loss pct, low 24 bits loss count, as in rfc1889 */
00175 #define IAX_IE_RR_PKTS           48    /*!< Received frames (total frames received) u32 */
00176 #define IAX_IE_RR_DELAY          49    /*!< Max playout delay for received frames (in ms) u16 */
00177 #define IAX_IE_RR_DROPPED        50    /*!< Dropped frames (presumably by jitterbuf) u32 */
00178 #define IAX_IE_RR_OOO            51    /*!< Frames received Out of Order u32 */
00179 #define IAX_IE_VARIABLE          52    /*!< Remote variables */
00180 #define IAX_IE_OSPTOKEN          53    /*!< OSP token */
00181 #define IAX_IE_CALLTOKEN         54    /*!< Call number security token */
00182 
00183 #define IAX_IE_CAPABILITY2          55      /*!< Actual codec capability - u8 version + integer array */
00184 #define IAX_IE_FORMAT2              56      /*!< Desired codec format - u8 version + integer array */
00185 
00186 #define IAX_MAX_OSPBLOCK_SIZE    254      /*!< Max OSP token block size, 255 bytes - 1 byte OSP token block index */
00187 #define IAX_MAX_OSPBLOCK_NUM     4
00188 #define IAX_MAX_OSPTOKEN_SIZE    (IAX_MAX_OSPBLOCK_SIZE * IAX_MAX_OSPBLOCK_NUM)
00189 #define IAX_MAX_OSPBUFF_SIZE     (IAX_MAX_OSPTOKEN_SIZE + 16)
00190 
00191 #define IAX_AUTH_PLAINTEXT       (1 << 0)
00192 #define IAX_AUTH_MD5          (1 << 1)
00193 #define IAX_AUTH_RSA          (1 << 2)
00194 
00195 #define IAX_ENCRYPT_AES128       (1 << 0)
00196 #define IAX_ENCRYPT_KEYROTATE       (1 << 15)       /*!< Keyrotation support */
00197 
00198 #define IAX_META_TRUNK           1     /*!< Trunk meta-message */
00199 #define IAX_META_VIDEO           2     /*!< Video frame */
00200 
00201 #define IAX_META_TRUNK_SUPERMINI    0  /*!< This trunk frame contains classic supermini frames */
00202 #define IAX_META_TRUNK_MINI         1  /*!< This trunk frame contains trunked mini frames */
00203 
00204 #define IAX_RATE_8KHZ            (1 << 0) /*!< 8khz sampling (default if absent) */
00205 #define IAX_RATE_11KHZ           (1 << 1) /*!< 11.025khz sampling */
00206 #define IAX_RATE_16KHZ           (1 << 2) /*!< 16khz sampling */
00207 #define IAX_RATE_22KHZ           (1 << 3) /*!< 22.05khz sampling */
00208 #define IAX_RATE_44KHZ           (1 << 4) /*!< 44.1khz sampling */
00209 #define IAX_RATE_48KHZ           (1 << 5) /*!< 48khz sampling */
00210 
00211 #define IAX_DPSTATUS_EXISTS         (1 << 0)
00212 #define IAX_DPSTATUS_CANEXIST    (1 << 1)
00213 #define IAX_DPSTATUS_NONEXISTENT (1 << 2)
00214 #define IAX_DPSTATUS_IGNOREPAT      (1 << 14)
00215 #define IAX_DPSTATUS_MATCHMORE      (1 << 15)
00216 
00217 /*! Full frames are always delivered reliably */
00218 struct ast_iax2_full_hdr {
00219    unsigned short scallno; /*!< Source call number -- high bit must be 1 */
00220    unsigned short dcallno; /*!< Destination call number -- high bit is 1 if retransmission */
00221    unsigned int ts;     /*!< 32-bit timestamp in milliseconds (from 1st transmission) */
00222    unsigned char oseqno;   /*!< Packet number (outgoing) */
00223    unsigned char iseqno;   /*!< Packet number (next incoming expected) */
00224    unsigned char type;     /*!< Frame type */
00225    unsigned char csub;     /*!< Compressed subclass */
00226    unsigned char iedata[0];
00227 } __attribute__ ((__packed__));
00228 
00229 /*! Full frames are always delivered reliably */
00230 struct ast_iax2_full_enc_hdr {
00231    unsigned short scallno; /*!< Source call number -- high bit must be 1 */
00232    unsigned short dcallno; /*!< Destination call number -- high bit is 1 if retransmission */
00233    unsigned char encdata[0];
00234 } __attribute__ ((__packed__));
00235 
00236 /*! Mini header is used only for voice frames -- delivered unreliably */
00237 struct ast_iax2_mini_hdr {
00238    unsigned short callno;  /*!< Source call number -- high bit must be 0, rest must be non-zero */
00239    unsigned short ts;      /*!< 16-bit Timestamp (high 16 bits from last ast_iax2_full_hdr) */
00240                      /* Frametype implicitly VOICE_FRAME */
00241                      /* subclass implicit from last ast_iax2_full_hdr */
00242    unsigned char data[0];
00243 } __attribute__ ((__packed__));
00244 
00245 /*! Mini header is used only for voice frames -- delivered unreliably */
00246 struct ast_iax2_mini_enc_hdr {
00247    unsigned short callno;  /*!< Source call number -- high bit must be 0, rest must be non-zero */
00248    unsigned char encdata[0];
00249 } __attribute__ ((__packed__));
00250 
00251 struct ast_iax2_meta_hdr {
00252    unsigned short zeros;         /*!< Zeros field -- must be zero */
00253    unsigned char metacmd;        /*!< Meta command */
00254    unsigned char cmddata;        /*!< Command Data */
00255    unsigned char data[0];
00256 } __attribute__ ((__packed__));
00257 
00258 struct ast_iax2_video_hdr {
00259    unsigned short zeros;         /*!< Zeros field -- must be zero */
00260    unsigned short callno;        /*!< Video call number */
00261    unsigned short ts;            /*!< Timestamp and mark if present */
00262    unsigned char data[0];
00263 } __attribute__ ((__packed__));
00264 
00265 struct ast_iax2_meta_trunk_hdr {
00266    unsigned int ts;           /*!< 32-bit timestamp for all messages */
00267    unsigned char data[0];
00268 } __attribute__ ((__packed__));
00269 
00270 struct ast_iax2_meta_trunk_entry {
00271    unsigned short callno;        /*!< Call number */
00272    unsigned short len;           /*!< Length of data for this callno */
00273 } __attribute__ ((__packed__));
00274 
00275 /*! When trunktimestamps are used, we use this format instead */
00276 struct ast_iax2_meta_trunk_mini {
00277    unsigned short len;
00278    struct ast_iax2_mini_hdr mini;      /*!< this is an actual miniframe */
00279 } __attribute__ ((__packed__));
00280 
00281 #define IAX_FIRMWARE_MAGIC 0x69617879
00282 
00283 struct ast_iax2_firmware_header {
00284    unsigned int magic;     /*!< Magic number */
00285    unsigned short version;    /*!< Software version */
00286    unsigned char devname[16]; /*!< Device */
00287    unsigned int datalen;      /*!< Data length of file beyond header */
00288    unsigned char chksum[16];  /*!< Checksum of all data */
00289    unsigned char data[0];
00290 } __attribute__ ((__packed__));
00291 #endif

Generated on Mon Oct 8 12:39:03 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7