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