32#include <sys/socket.h>
33#include <netinet/in.h>
55#if (defined(LOW_MEMORY) || defined(MALLOC_DEBUG)) && !defined(NO_FRAME_CACHE)
59#if !defined(NO_FRAME_CACHE)
74#define FRAME_CACHE_MAX_SIZE 20
84 fprintf(stderr,
"WARNING: %s",
str);
94 if (
len == (
int)
sizeof(
struct sockaddr_in)) {
95 addr.
ss.ss_family = AF_INET;
96 }
else if (
len == (
int)
sizeof(
struct sockaddr_in6)) {
97 addr.
ss.ss_family = AF_INET6;
106 snprintf(output, maxlen,
"%s %s",
115 while (
len-- && (i + 1) * 4 < maxlen) {
116 sprintf(output + (4 * i),
"\\x%02hhx", *((
unsigned char *)
value + i));
126 strncpy(output,
value, maxlen);
127 output[maxlen] =
'\0';
141 strncpy(output,
value, maxlen);
142 output[maxlen] =
'\0';
145 memset(output,0,total_len);
151 if (
len == (
int)
sizeof(
unsigned int))
159 if (
len == (
int)
sizeof(
unsigned short))
167 if (
len == (
int)
sizeof(
unsigned char))
168 snprintf(output, maxlen,
"%d", *((
unsigned char *)
value));
177 if (
len == (
int)
sizeof(
unsigned int)) {
194 if (
len == (
int)
sizeof(
struct sockaddr_in)) {
195 addr.
ss.ss_family = AF_INET;
196 }
else if (
len == (
int)
sizeof(
struct sockaddr_in6)) {
197 addr.
ss.ss_family = AF_INET6;
214 if (
len == (
int)
sizeof(
unsigned int))
225 if (
len == (
int)
sizeof(
unsigned short)) {
226 sr = ntohs(*((
unsigned short *)
value));
228 strcat(
tmp,
",8khz");
230 strcat(
tmp,
",11.025khz");
232 strcat(
tmp,
",16khz");
234 strcat(
tmp,
",22.05khz");
236 strcat(
tmp,
",44.1khz");
238 strcat(
tmp,
",48khz");
263static void dump_prov_ies(
char *output,
int maxlen,
unsigned char *iedata,
int len);
374 strcpy(output,
"\n");
375 maxlen -= strlen(output); output += strlen(output);
379 if (ielen + 2>
len) {
380 snprintf(
tmp, (
int)
sizeof(
tmp),
"Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2,
len);
382 maxlen -= strlen(output);
383 output += strlen(output);
390 prov_ies[x].
dump(interp, (
int)
sizeof(interp), iedata + 2, ielen);
393 maxlen -= strlen(output); output += strlen(output);
396 snprintf(interp, (
int)
sizeof(interp),
"%d bytes", ielen);
398 strcpy(interp,
"Present");
401 maxlen -= strlen(output); output += strlen(output);
407 snprintf(
tmp, (
int)
sizeof(
tmp),
" Unknown Prov IE %03d : Present\n",
ie);
409 maxlen -= strlen(output); output += strlen(output);
411 iedata += (2 + ielen);
430 if (ielen + 2>
len) {
431 snprintf(
tmp, (
int)
sizeof(
tmp),
"Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2,
len);
439 infoelts[x].
dump(interp, (
int)
sizeof(interp), iedata + 2, ielen);
444 snprintf(interp, (
int)
sizeof(interp),
"%d bytes", ielen);
446 strcpy(interp,
"Present");
454 snprintf(
tmp, (
int)
sizeof(
tmp),
" Unknown IE %03d : Present\n",
ie);
457 iedata += (2 + ielen);
465 const char *cmd =
"Unknown";
597 const char *framelist[] = {
612 const char *cmds[] = {
653 const char *subclass;
673 snprintf(retries,
sizeof(retries),
"%03d", f->
retries);
677 strcpy(retries,
"Yes");
679 strcpy(retries,
" No");
686 snprintf(class2,
sizeof(class2),
"(%d?)", fh->
type);
689 class = framelist[(int)fh->
type];
692 sprintf(subclass2,
"%c", fh->
csub);
693 subclass = subclass2;
696 subclass = subclass2;
699 snprintf(subclass2,
sizeof(subclass2),
"(%d?)", fh->
csub);
700 subclass = subclass2;
702 subclass = cmds[(int)fh->
csub];
705 snprintf(subclass2,
sizeof(subclass2),
"%d", fh->
csub);
706 subclass = subclass2;
709 snprintf(
tmp,
sizeof(
tmp),
710 "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
714 snprintf(
tmp,
sizeof(
tmp),
" Timestamp: %05lums SCall: %5.5d DCall: %5.5d %s\n",
715 (
unsigned long)ntohl(fh->
ts),
729 if (datalen > ((
int)
sizeof(ied->
buf) - ied->
pos)) {
730 snprintf(
tmp, (
int)
sizeof(
tmp),
"Out of space for ie '%s' (%d), need %d have %d\n",
iax_ie2str(ie), ie, datalen, (
int)
sizeof(ied->
buf) - ied->
pos);
734 ied->
buf[ied->
pos++] = ie;
735 ied->
buf[ied->
pos++] = datalen;
736 memcpy(ied->
buf + ied->
pos, data, datalen);
751 } __attribute__((packed)) newval = {
version, };
759 newval = htonl(
value);
765 unsigned short newval;
766 newval = htons(
value);
800 char tmp[256], *tmp2;
803 memset(ies, 0, (
int)
sizeof(
struct iax_ies));
811 while(datalen >= 2) {
814 if (
len > datalen - 2) {
815 errorf(
"Information element length exceeds message size\n");
844 if (
len != (
int)
sizeof(
unsigned int)) {
845 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting capability to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
856 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting capability to be %d bytes long but was %d\n", (
int) (
sizeof(
iax2_format) +
sizeof(
char)),
len);
865 if (
len != (
int)
sizeof(
unsigned int)) {
866 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting format to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
868 }
else if (ies->
format == 0) {
877 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting format to be %d bytes long but was %d\n", (
int) (
sizeof(
iax2_format) +
sizeof(
char)),
len);
889 if (
len != (
int)
sizeof(
unsigned short)) {
890 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting version to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
896 if (
len != (
int)
sizeof(
unsigned short)) {
897 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting adsicpe to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
903 if (
len != (
int)
sizeof(
unsigned short)) {
904 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting samplingrate to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
910 ies->
dnid = (
char *)data + 2;
913 ies->
rdnis = (
char *)data + 2;
916 if (
len != (
int)
sizeof(
unsigned short)) {
917 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting authmethods to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
923 if (
len != (
int)
sizeof(
unsigned short)) {
924 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting encryption to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
943 if (
len != (
int)
sizeof(
unsigned short)) {
944 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting refresh to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
950 if (
len != (
int)
sizeof(
unsigned short)) {
951 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting dpstatus to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
957 if (
len != (
int)
sizeof(
unsigned short)) {
958 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting callno to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
964 ies->
cause = (
char *)data + 2;
968 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting causecode to be single byte but was %d\n",
len);
978 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected single byte Unknown command, but was %d long\n",
len);
983 if (
len != (
int)
sizeof(
unsigned short)) {
984 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting msgcount to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
996 if (
len != (
int)
sizeof(
unsigned int)) {
997 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting transferid to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1003 if (
len != (
int)
sizeof(
unsigned int)) {
1004 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting date/time to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1010 if (
len != (
int)
sizeof(
unsigned short)) {
1011 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting firmwarever to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
1023 if (
len != (
int)
sizeof(
unsigned int)) {
1024 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected block desc to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1038 if (
len != (
int)
sizeof(
unsigned int)) {
1039 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected provisioning version to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1050 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected single byte callingpres, but was %d long\n",
len);
1058 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected single byte callington, but was %d long\n",
len);
1063 if (
len == (
int)
sizeof(
unsigned int)) {
1066 snprintf(
tmp,
sizeof(
tmp),
"Expected callingani2 to be %zu bytes but was %d\n",
sizeof(
unsigned int),
len);
1071 if (
len != (
int)
sizeof(
unsigned short)) {
1072 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expecting callingtns to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
1078 if (
len != (
int)
sizeof(
unsigned int)) {
1079 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected jitter rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1086 if (
len != (
int)
sizeof(
unsigned int)) {
1087 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected loss rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1094 if (
len != (
int)
sizeof(
unsigned int)) {
1095 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected packets rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1102 if (
len != (
int)
sizeof(
unsigned short)) {
1103 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected loss rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short),
len);
1110 if (
len != (
int)
sizeof(
unsigned int)) {
1111 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected packets rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1118 if (
len != (
int)
sizeof(
unsigned int)) {
1119 snprintf(
tmp, (
int)
sizeof(
tmp),
"Expected packets rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int),
len);
1127 tmp2 = strchr(
tmp,
'=');
1135 for (var2 = ies->
vars, prev =
NULL; var2; prev = var2, var2 = var2->
next) {
1136 if (strcmp(
tmp, var2->
name) == 0) {
1145 snprintf(
tmp,
sizeof(
tmp),
"Assigned (%p)%s to (%p)%s\n",
var->name,
var->name,
var->value,
var->value);
1156 snprintf(
tmp,
sizeof(
tmp),
"Assigned (%p)%s to (%p)%s\n",
var->name,
var->name,
var->value,
var->value);
1178 snprintf(
tmp, (
int)
sizeof(
tmp),
"Ignoring unknown information element '%s' (%d) of length %d\n",
iax_ie2str(ie), ie,
len);
1183 datalen -= (
len + 2);
1189 errorf(
"Invalid information element contents, strange boundary\n");
1212 ast_log(
LOG_ERROR,
"Losing frame data because destination buffer size '%d' bytes not big enough for '%d' bytes in the frame\n",
1216#if __BYTE_ORDER == __LITTLE_ENDIAN
1232#if !defined(NO_FRAME_CACHE)
1245 memset(fr, 0,
sizeof(*fr));
1297#if !defined(NO_FRAME_CACHE)
1307 errorf(
"Attempt to double free frame detected\n");
1312#if !defined(NO_FRAME_CACHE)
1336#if !defined(NO_FRAME_CACHE)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
const char * iax2_getformatname(iax2_format format)
iax2 wrapper function for ast_getformatname
static char version[AST_MAX_EXTENSION]
int iax2_codec_pref_string(struct iax2_codec_pref *pref, char *buf, size_t size)
Dump audio codec preference list into a string.
void iax2_codec_pref_convert(struct iax2_codec_pref *pref, char *buf, size_t size, int right)
Shift an audio codec preference list up or down 65 bytes so that it becomes an ASCII string.
Media Format Bitfield Compatibility API.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Implementation of Inter-Asterisk eXchange, version 2 parser.c parser.h chan_iax2.c.
#define IAX_IE_SERVICEIDENT
#define IAX_IE_CALLINGANI2
#define IAX_IE_CALLING_NUMBER
#define IAX_IE_SAMPLINGRATE
#define IAX_IE_TRANSFERID
#define IAX_IE_CALLING_ANI
#define IAX_IE_CALLINGTNS
#define IAX_IE_RSA_RESULT
#define IAX_IE_IAX_UNKNOWN
#define IAX_IE_CAPABILITY2
#define IAX_IE_CALLING_NAME
#define IAX_IE_RR_DROPPED
#define IAX_IE_MUSICONHOLD
#define IAX_IE_ENCRYPTION
#define IAX_IE_FIRMWAREVER
#define IAX_IE_CODEC_PREFS
#define IAX_IE_CALLED_NUMBER
#define IAX_IE_FWBLOCKDATA
#define IAX_IE_CAPABILITY
#define IAX_IE_PROVISIONING
#define IAX_IE_MD5_RESULT
#define IAX_IE_AUTOANSWER
#define IAX_IE_APPARENT_ADDR
#define IAX_IE_AESPROVISIONING
#define IAX_MAX_OSPBLOCK_NUM
#define IAX_IE_CALLINGPRES
#define IAX_IE_DEVICETYPE
#define IAX_IE_AUTHMETHODS
#define IAX_IE_FWBLOCKDESC
#define IAX_IE_CALLED_CONTEXT
#define IAX_IE_CALLINGTON
uint64_t ntohll(uint64_t net64)
uint64_t htonll(uint64_t host64)
Configuration File Parser.
#define ast_variable_new(name, value, filename)
Asterisk internal frame definitions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
void ast_swapcopy_samples(void *dst, const void *src, int samples)
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Asterisk locking-related definitions:
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
int ast_sockaddr_is_ipv4_mapped(const struct ast_sockaddr *addr)
Determine if this is an IPv4-mapped IPv6 address.
#define ast_opt_cache_media_frames
int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen)
static void dump_int(char *output, int maxlen, void *value, int len)
int iax_get_iframes(void)
static struct ast_threadstorage frame_cache
static void dump_samprate(char *output, int maxlen, void *value, int len)
int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, const struct ast_sockaddr *addr)
void iax_frame_subclass2str(enum iax_frame_subclass subclass, char *str, size_t len)
static void dump_prov(char *output, int maxlen, void *value, int len)
static void dump_short(char *output, int maxlen, void *value, int len)
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
static void(* errorf)(const char *str)
#define FRAME_CACHE_MAX_SIZE
void iax_frame_free(struct iax_frame *fr)
static void dump_ies(unsigned char *iedata, int len)
static void dump_ipaddr(char *output, int maxlen, void *value, int len)
void iax_set_error(void(*func)(const char *))
void iax_set_output(void(*func)(const char *))
static void dump_datetime(char *output, int maxlen, void *value, int len)
static void dump_string(char *output, int maxlen, void *value, int len)
int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
static const struct iax2_ie prov_ies[]
int iax_ie_append_versioned_uint64(struct iax_ie_data *ied, unsigned char ie, unsigned char version, uint64_t value)
struct iax_frame * iax_frame_new(int direction, int datalen, unsigned int cacheable)
static void dump_versioned_codec(char *output, int maxlen, void *value, int len)
static void internalerror(const char *str)
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len)
static void dump_byte(char *output, int maxlen, void *value, int len)
int iax_get_oframes(void)
static void(* outputf)(const char *str)
static void dump_prov_flags(char *output, int maxlen, void *value, int len)
void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f)
static void dump_string_hex(char *output, int maxlen, void *value, int len)
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct ast_sockaddr *addr, int datalen)
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str)
static void dump_addr(char *output, int maxlen, void *value, int len)
static void internaloutput(const char *str)
static void frame_cache_cleanup(void *data)
static struct iax2_ie infoelts[]
static void dump_prefs(char *output, int maxlen, void *value, int len)
const char * iax_ie2str(int ie)
Implementation of the IAX2 protocol.
#define DIRECTION_OUTGRESS
#define DIRECTION_INGRESS
IAX2 Provisioning protocol.
#define PROV_IE_NEWAESKEY
char * iax_provflags2str(char *buf, int buflen, unsigned int flags)
#define PROV_IE_SERVERPORT
#define PROV_IE_ALTSERVER
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@226 data
enum ast_frame_type frametype
Socket address structure.
struct sockaddr_storage ss
Support for dynamic strings.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
void(* dump)(char *output, int maxlen, void *value, int len)
This is just so iax_frames, a list head struct for holding a list of iax_frame structures,...
struct iax_frame::@139 list
struct iax_frame_list list
struct ast_sockaddr apparent_addr
unsigned char * calltokendata
struct ast_variable * vars
unsigned char iax_unknown
unsigned int ospblocklength[IAX_MAX_OSPBLOCK_NUM]
char * osptokenblock[IAX_MAX_OSPBLOCK_NUM]
Definitions to aid in the use of thread local storage.
#define AST_THREADSTORAGE_CUSTOM(a, b, c)
Define a thread storage variable, with custom initialization and cleanup.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
Handle unaligned data access.
static unsigned int get_unaligned_uint32(const void *p)
static unsigned short get_unaligned_uint16(const void *p)
static void put_unaligned_uint64(void *p, uint64_t datum)
static uint64_t get_unaligned_uint64(const void *p)