iax2-parser.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Asterisk -- A telephony toolkit for Linux.
  3. *
  4. * Implementation of Inter-Asterisk eXchange
  5. *
  6. * Copyright (C) 2003, Digium
  7. *
  8. * Mark Spencer <markster@digium.com>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. /*!\file
  14. * \brief Implementation of the IAX2 protocol
  15. */
  16. #ifndef _IAX2_PARSER_H
  17. #define _IAX2_PARSER_H
  18. #include "asterisk/linkedlists.h"
  19. #include "asterisk/crypto.h"
  20. #include "iax2.h"
  21. struct iax_ies {
  22. char *called_number;
  23. char *calling_number;
  24. char *calling_ani;
  25. char *calling_name;
  26. int calling_ton;
  27. int calling_tns;
  28. int calling_pres;
  29. char *called_context;
  30. char *username;
  31. char *password;
  32. iax2_format capability;
  33. iax2_format format;
  34. char *codec_prefs;
  35. char *language;
  36. int version;
  37. unsigned short adsicpe;
  38. char *dnid;
  39. char *rdnis;
  40. unsigned int authmethods;
  41. unsigned int encmethods;
  42. char *challenge;
  43. char *md5_result;
  44. char *rsa_result;
  45. struct sockaddr_in *apparent_addr;
  46. unsigned short refresh;
  47. unsigned short dpstatus;
  48. unsigned short callno;
  49. char *cause;
  50. unsigned char causecode;
  51. unsigned char iax_unknown;
  52. int msgcount;
  53. int autoanswer;
  54. int musiconhold;
  55. unsigned int transferid;
  56. unsigned int datetime;
  57. char *devicetype;
  58. char *serviceident;
  59. int firmwarever;
  60. unsigned int fwdesc;
  61. unsigned char *fwdata;
  62. unsigned char fwdatalen;
  63. unsigned char *enckey;
  64. unsigned char enckeylen;
  65. unsigned int provver;
  66. unsigned short samprate;
  67. int provverpres;
  68. unsigned int rr_jitter;
  69. unsigned int rr_loss;
  70. unsigned int rr_pkts;
  71. unsigned short rr_delay;
  72. unsigned int rr_dropped;
  73. unsigned int rr_ooo;
  74. struct ast_variable *vars;
  75. char *osptokenblock[IAX_MAX_OSPBLOCK_NUM];
  76. unsigned int ospblocklength[IAX_MAX_OSPBLOCK_NUM];
  77. unsigned char calltoken;
  78. unsigned char *calltokendata;
  79. };
  80. #define DIRECTION_INGRESS 1
  81. #define DIRECTION_OUTGRESS 2
  82. struct iax_frame {
  83. #ifdef LIBIAX
  84. struct iax_session *session;
  85. struct iax_event *event;
  86. #else
  87. int sockfd;
  88. #endif
  89. /*! /Our/ call number */
  90. unsigned short callno;
  91. /*! /Their/ call number */
  92. unsigned short dcallno;
  93. /*! Start of raw frame (outgoing only) */
  94. void *data;
  95. /*! Length of frame (outgoing only) */
  96. int datalen;
  97. /*! How many retries so far? */
  98. int retries;
  99. /*! Outgoing relative timestamp (ms) */
  100. unsigned int ts;
  101. /*! How long to wait before retrying */
  102. int retrytime;
  103. /*! Are we received out of order? */
  104. unsigned int outoforder:1;
  105. /*! Have we been sent at all yet? */
  106. unsigned int sentyet:1;
  107. /*! Non-zero if should be sent to transfer peer */
  108. unsigned int transfer:1;
  109. /*! Non-zero if this is the final message */
  110. unsigned int final:1;
  111. /*! Ingress or outgres */
  112. unsigned int direction:2;
  113. /*! Can this frame be cached? */
  114. unsigned int cacheable:1;
  115. /*! Outgoing Packet sequence number */
  116. int oseqno;
  117. /*! Next expected incoming packet sequence number */
  118. int iseqno;
  119. /*! Retransmission ID */
  120. int retrans;
  121. /*! is this packet encrypted or not. if set this varible holds encryption methods*/
  122. int encmethods;
  123. /*! store encrypt key */
  124. ast_aes_encrypt_key ecx;
  125. /*! store decrypt key which corresponds to ecx */
  126. ast_aes_decrypt_key mydcx;
  127. /*! random data for encryption pad */
  128. unsigned char semirand[32];
  129. /*! Easy linking */
  130. AST_LIST_ENTRY(iax_frame) list;
  131. /*! Actual, isolated frame header */
  132. struct ast_frame af;
  133. /*! Amount of space _allocated_ for data */
  134. size_t afdatalen;
  135. unsigned char unused[AST_FRIENDLY_OFFSET];
  136. unsigned char afdata[0]; /* Data for frame */
  137. };
  138. struct iax_ie_data {
  139. unsigned char buf[1024];
  140. int pos;
  141. };
  142. /* Choose a different function for output */
  143. void iax_set_output(void (*output)(const char *data));
  144. /* Choose a different function for errors */
  145. void iax_set_error(void (*output)(const char *data));
  146. void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen);
  147. void iax_frame_subclass2str(enum iax_frame_subclass subclass, char *str, size_t len);
  148. const char *iax_ie2str(int ie);
  149. int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen);
  150. int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, const struct sockaddr_in *sin);
  151. int iax_ie_append_versioned_uint64(struct iax_ie_data *ied, unsigned char ie, unsigned char version, uint64_t value);
  152. int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value);
  153. int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value);
  154. int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str);
  155. int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat);
  156. int iax_ie_append(struct iax_ie_data *ied, unsigned char ie);
  157. int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen);
  158. int iax_get_frames(void);
  159. int iax_get_iframes(void);
  160. int iax_get_oframes(void);
  161. void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f);
  162. struct iax_frame *iax_frame_new(int direction, int datalen, unsigned int cacheable);
  163. void iax_frame_free(struct iax_frame *fr);
  164. #endif