iax2-parser.h 4.8 KB

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