Asterisk.org: Developer Documentation (28 Oct 2009)

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