2 * Asterisk -- A telephony toolkit for Linux.
4 * Implementation of Inter-Asterisk eXchange
6 * Copyright (C) 2003, Digium
8 * Mark Spencer <markster@digium.com>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
15 * \brief Implementation of the IAX2 protocol
18 #ifndef _IAX2_PARSER_H
19 #define _IAX2_PARSER_H
21 #include "asterisk/linkedlists.h"
22 #include "asterisk/crypto.h"
36 iax2_format capability;
41 unsigned short adsicpe;
44 unsigned int authmethods;
45 unsigned int encmethods;
49 struct sockaddr_in *apparent_addr;
50 unsigned short refresh;
51 unsigned short dpstatus;
52 unsigned short callno;
54 unsigned char causecode;
55 unsigned char iax_unknown;
59 unsigned int transferid;
60 unsigned int datetime;
65 unsigned char *fwdata;
66 unsigned char fwdatalen;
67 unsigned char *enckey;
68 unsigned char enckeylen;
70 unsigned short samprate;
72 unsigned int rr_jitter;
75 unsigned short rr_delay;
76 unsigned int rr_dropped;
78 struct ast_variable *vars;
79 char *osptokenblock[IAX_MAX_OSPBLOCK_NUM];
80 unsigned int ospblocklength[IAX_MAX_OSPBLOCK_NUM];
81 unsigned char calltoken;
82 unsigned char *calltokendata;
85 #define DIRECTION_INGRESS 1
86 #define DIRECTION_OUTGRESS 2
90 struct iax_session *session;
91 struct iax_event *event;
96 /*! /Our/ call number */
97 unsigned short callno;
98 /*! /Their/ call number */
99 unsigned short dcallno;
100 /*! Start of raw frame (outgoing only) */
102 /*! Length of frame (outgoing only) */
104 /*! How many retries so far? */
106 /*! Outgoing relative timestamp (ms) */
108 /*! How long to wait before retrying */
110 /*! Are we received out of order? */
111 unsigned int outoforder:1;
112 /*! Have we been sent at all yet? */
113 unsigned int sentyet:1;
114 /*! Non-zero if should be sent to transfer peer */
115 unsigned int transfer:1;
116 /*! Non-zero if this is the final message */
117 unsigned int final:1;
118 /*! Ingress or outgres */
119 unsigned int direction:2;
120 /*! Can this frame be cached? */
121 unsigned int cacheable:1;
122 /*! Outgoing Packet sequence number */
124 /*! Next expected incoming packet sequence number */
126 /*! Retransmission ID */
128 /*! is this packet encrypted or not. if set this varible holds encryption methods*/
130 /*! store encrypt key */
131 ast_aes_encrypt_key ecx;
132 /*! store decrypt key which corresponds to ecx */
133 ast_aes_decrypt_key mydcx;
134 /*! random data for encryption pad */
135 unsigned char semirand[32];
137 AST_LIST_ENTRY(iax_frame) list;
138 /*! Actual, isolated frame header */
140 /*! Amount of space _allocated_ for data */
142 unsigned char unused[AST_FRIENDLY_OFFSET];
143 unsigned char afdata[0]; /* Data for frame */
147 unsigned char buf[1024];
151 /* Choose a different function for output */
152 void iax_set_output(void (*output)(const char *data));
153 /* Choose a different function for errors */
154 void iax_set_error(void (*output)(const char *data));
155 void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen);
156 void iax_frame_subclass2str(enum iax_frame_subclass subclass, char *str, size_t len);
158 const char *iax_ie2str(int ie);
160 int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen);
161 int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, const struct sockaddr_in *sin);
162 int iax_ie_append_versioned_uint64(struct iax_ie_data *ied, unsigned char ie, unsigned char version, uint64_t value);
163 int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value);
164 int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value);
165 int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str);
166 int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat);
167 int iax_ie_append(struct iax_ie_data *ied, unsigned char ie);
168 int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen);
170 int iax_get_frames(void);
171 int iax_get_iframes(void);
172 int iax_get_oframes(void);
174 void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f);
175 struct iax_frame *iax_frame_new(int direction, int datalen, unsigned int cacheable);
176 void iax_frame_free(struct iax_frame *fr);