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