parser.h 5.0 KB

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