iax2.h 12 KB

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