34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
53 #if !defined(LOW_MEMORY)
68 #define FRAME_CACHE_MAX_SIZE 20
78 fprintf(stderr,
"WARNING: %s", str);
86 struct sockaddr_in sin;
87 if (len == (
int)
sizeof(sin)) {
88 memcpy(&sin, value, len);
89 snprintf(output, maxlen,
"IPV4 %s:%d",
ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
99 while (len-- && (i + 1) * 4 < maxlen) {
100 sprintf(output + (4 * i),
"\\x%2.2x", (
unsigned)*((
unsigned char *)value + i));
110 strncpy(output, value, maxlen);
111 output[maxlen] =
'\0';
125 strncpy(output, value, maxlen);
126 output[maxlen] =
'\0';
129 memset(output,0,total_len);
135 if (len == (
int)
sizeof(
unsigned int))
143 if (len == (
int)
sizeof(
unsigned short))
151 if (len == (
int)
sizeof(
unsigned char))
152 snprintf(output, maxlen,
"%d", *((
unsigned char *)value));
161 if (len == (
int)
sizeof(
unsigned int)) {
162 tm.
tm_sec = (val & 0x1f) << 1;
163 tm.
tm_min = (val >> 5) & 0x3f;
164 tm.
tm_hour = (val >> 11) & 0x1f;
165 tm.
tm_mday = (val >> 16) & 0x1f;
166 tm.
tm_mon = ((val >> 21) & 0x0f) - 1;
167 tm.
tm_year = ((val >> 25) & 0x7f) + 100;
175 struct sockaddr_in sin;
176 if (len == (
int)
sizeof(
unsigned int)) {
177 memcpy(&sin.sin_addr, value, len);
187 if (len == (
int)
sizeof(
unsigned int))
198 if (len == (
int)
sizeof(
unsigned short)) {
199 sr = ntohs(*((
unsigned short *)value));
201 strcat(tmp,
",8khz");
203 strcat(tmp,
",11.025khz");
205 strcat(tmp,
",16khz");
207 strcat(tmp,
",22.05khz");
209 strcat(tmp,
",44.1khz");
211 strcat(tmp,
",48khz");
223 char *
version = (
char *) value;
224 if (version[0] == 0) {
225 if (len == (
int) (
sizeof(
format_t) +
sizeof(
char))) {
236 static void dump_prov_ies(
char *output,
int maxlen,
unsigned char *iedata,
int len);
328 for (x = 0; x <
ARRAY_LEN(infoelts); x++) {
329 if (infoelts[x].ie == ie)
330 return infoelts[x].
name;
346 strcpy(output,
"\n");
347 maxlen -= strlen(output); output += strlen(output);
351 if (ielen + 2> len) {
352 snprintf(tmp, (
int)
sizeof(tmp),
"Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
354 maxlen -= strlen(output);
355 output += strlen(output);
359 for (x=0;x<(int)
sizeof(prov_ies) / (int)
sizeof(prov_ies[0]); x++) {
360 if (prov_ies[x].ie == ie) {
361 if (prov_ies[x].
dump) {
362 prov_ies[x].
dump(interp, (
int)
sizeof(interp), iedata + 2, ielen);
363 snprintf(tmp, (
int)
sizeof(tmp),
" %-15.15s : %s\n", prov_ies[x].
name, interp);
365 maxlen -= strlen(output); output += strlen(output);
368 snprintf(interp, (
int)
sizeof(interp),
"%d bytes", ielen);
370 strcpy(interp,
"Present");
371 snprintf(tmp, (
int)
sizeof(tmp),
" %-15.15s : %s\n", prov_ies[x].
name, interp);
373 maxlen -= strlen(output); output += strlen(output);
379 snprintf(tmp, (
int)
sizeof(tmp),
" Unknown Prov IE %03d : Present\n", ie);
381 maxlen -= strlen(output); output += strlen(output);
383 iedata += (2 + ielen);
402 if (ielen + 2> len) {
403 snprintf(tmp, (
int)
sizeof(tmp),
"Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
408 for (x = 0; x <
ARRAY_LEN(infoelts); x++) {
409 if (infoelts[x].ie == ie) {
410 if (infoelts[x].
dump) {
411 infoelts[x].
dump(interp, (
int)
sizeof(interp), iedata + 2, ielen);
412 snprintf(tmp, (
int)
sizeof(tmp),
" %-15.15s : %s\n", infoelts[x].
name, interp);
416 snprintf(interp, (
int)
sizeof(interp),
"%d bytes", ielen);
418 strcpy(interp,
"Present");
419 snprintf(tmp, (
int)
sizeof(tmp),
" %-15.15s : %s\n", infoelts[x].
name, interp);
426 snprintf(tmp, (
int)
sizeof(tmp),
" Unknown IE %03d : Present\n", ie);
429 iedata += (2 + ielen);
437 const char *cmd =
"Unknown";
569 const char *framelist[] = {
584 const char *cmds[] = {
623 const char *subclass;
643 snprintf(retries,
sizeof(retries),
"%03d", f->
retries);
647 strcpy(retries,
"Yes");
649 strcpy(retries,
" No");
656 snprintf(class2,
sizeof(class2),
"(%d?)", fh->
type);
659 class = framelist[(int)fh->type];
662 sprintf(subclass2,
"%c", fh->
csub);
663 subclass = subclass2;
666 subclass = subclass2;
669 snprintf(subclass2,
sizeof(subclass2),
"(%d?)", fh->
csub);
670 subclass = subclass2;
672 subclass = cmds[(int)fh->
csub];
675 snprintf(subclass2,
sizeof(subclass2),
"%d", fh->
csub);
676 subclass = subclass2;
678 snprintf(tmp,
sizeof(tmp),
679 "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
683 snprintf(tmp,
sizeof(tmp),
684 " Timestamp: %05lums SCall: %5.5d DCall: %5.5d [%s:%d]\n",
685 (
unsigned long)ntohl(fh->
ts),
696 if (datalen > ((
int)
sizeof(ied->
buf) - ied->
pos)) {
697 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);
701 ied->
buf[ied->
pos++] = ie;
702 ied->
buf[ied->
pos++] = datalen;
703 memcpy(ied->
buf + ied->
pos, data, datalen);
718 } __attribute__((packed)) newval = {
version, };
726 newval = htonl(value);
732 unsigned short newval;
733 newval = htons(value);
767 char tmp[256], *tmp2;
770 memset(ies, 0, (
int)
sizeof(
struct iax_ies));
777 while(datalen >= 2) {
780 if (len > datalen - 2) {
781 errorf(
"Information element length exceeds message size\n");
810 if (len != (
int)
sizeof(
unsigned int)) {
811 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting capability to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
821 if (len != (
int)
sizeof(
char) +
sizeof(
format_t)) {
822 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting capability to be %d bytes long but was %d\n", (
int) (
sizeof(
format_t) +
sizeof(
char)), len);
831 if (len != (
int)
sizeof(
unsigned int)) {
832 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting format to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
834 }
else if (ies->
format == 0) {
842 if (len != (
int)
sizeof(
char) +
sizeof(
format_t)) {
843 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting format to be %d bytes long but was %d\n", (
int) (
sizeof(
format_t) +
sizeof(
char)), len);
855 if (len != (
int)
sizeof(
unsigned short)) {
856 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting version to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
862 if (len != (
int)
sizeof(
unsigned short)) {
863 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting adsicpe to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
869 if (len != (
int)
sizeof(
unsigned short)) {
870 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting samplingrate to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
876 ies->
dnid = (
char *)data + 2;
879 ies->
rdnis = (
char *)data + 2;
882 if (len != (
int)
sizeof(
unsigned short)) {
883 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting authmethods to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
889 if (len != (
int)
sizeof(
unsigned short)) {
890 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting encryption to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
908 if (len != (
int)
sizeof(
unsigned short)) {
909 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting refresh to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
915 if (len != (
int)
sizeof(
unsigned short)) {
916 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting dpstatus to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
922 if (len != (
int)
sizeof(
unsigned short)) {
923 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting callno to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
929 ies->
cause = (
char *)data + 2;
933 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting causecode to be single byte but was %d\n", len);
943 snprintf(tmp, (
int)
sizeof(tmp),
"Expected single byte Unknown command, but was %d long\n", len);
948 if (len != (
int)
sizeof(
unsigned short)) {
949 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting msgcount to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
961 if (len != (
int)
sizeof(
unsigned int)) {
962 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting transferid to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
968 if (len != (
int)
sizeof(
unsigned int)) {
969 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting date/time to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
975 if (len != (
int)
sizeof(
unsigned short)) {
976 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting firmwarever to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
988 if (len != (
int)
sizeof(
unsigned int)) {
989 snprintf(tmp, (
int)
sizeof(tmp),
"Expected block desc 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),
"Expected provisioning version to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
1015 snprintf(tmp, (
int)
sizeof(tmp),
"Expected single byte callingpres, but was %d long\n", len);
1023 snprintf(tmp, (
int)
sizeof(tmp),
"Expected single byte callington, but was %d long\n", len);
1028 if (len != (
int)
sizeof(
unsigned short)) {
1029 snprintf(tmp, (
int)
sizeof(tmp),
"Expecting callingtns to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
1035 if (len != (
int)
sizeof(
unsigned int)) {
1036 snprintf(tmp, (
int)
sizeof(tmp),
"Expected jitter rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
1043 if (len != (
int)
sizeof(
unsigned int)) {
1044 snprintf(tmp, (
int)
sizeof(tmp),
"Expected loss rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
1051 if (len != (
int)
sizeof(
unsigned int)) {
1052 snprintf(tmp, (
int)
sizeof(tmp),
"Expected packets rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
1059 if (len != (
int)
sizeof(
unsigned short)) {
1060 snprintf(tmp, (
int)
sizeof(tmp),
"Expected loss rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned short), len);
1067 if (len != (
int)
sizeof(
unsigned int)) {
1068 snprintf(tmp, (
int)
sizeof(tmp),
"Expected packets rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
1075 if (len != (
int)
sizeof(
unsigned int)) {
1076 snprintf(tmp, (
int)
sizeof(tmp),
"Expected packets rr to be %d bytes long but was %d\n", (
int)
sizeof(
unsigned int), len);
1084 tmp2 = strchr(tmp,
'=');
1092 for (var2 = ies->
vars, prev = NULL; var2; prev = var2, var2 = var2->
next) {
1093 if (strcmp(tmp, var2->
name) == 0) {
1102 snprintf(tmp,
sizeof(tmp),
"Assigned (%p)%s to (%p)%s\n", var->
name, var->
name, var->
value, var->
value);
1113 snprintf(tmp,
sizeof(tmp),
"Assigned (%p)%s to (%p)%s\n", var->
name, var->
name, var->
value, var->
value);
1124 snprintf(tmp, (
int)
sizeof(tmp),
"Expected OSP token block index to be 0~%d but was %u\n",
IAX_MAX_OSPBLOCK_NUM - 1, count);
1135 snprintf(tmp, (
int)
sizeof(tmp),
"Ignoring unknown information element '%s' (%d) of length %d\n",
iax_ie2str(ie), ie, len);
1140 datalen -= (len + 2);
1146 errorf(
"Invalid information element contents, strange boundary\n");
1168 ast_log(
LOG_ERROR,
"Losing frame data because destination buffer size '%d' bytes not big enough for '%d' bytes in the frame\n",
1172 #if __BYTE_ORDER == __LITTLE_ENDIAN
1187 #if !defined(LOW_MEMORY)
1199 memset(fr, 0,
sizeof(*fr));
1212 if (!(fr =
ast_realloc(smallest,
sizeof(*fr) + datalen))) {
1221 if (!(fr =
ast_calloc(1,
sizeof(*fr) + datalen)))
1243 #if !defined(LOW_MEMORY)
1253 errorf(
"Attempt to double free frame detected\n");
1258 #if !defined(LOW_MEMORY)
1280 #if !defined(LOW_MEMORY)
static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int len)
union ast_frame_subclass subclass
#define IAX_IE_IAX_UNKNOWN
void iax_frame_subclass2str(enum iax_frame_subclass subclass, char *str, size_t len)
#define DIRECTION_INGRESS
#define IAX_IE_CAPABILITY2
Asterisk locking-related definitions:
int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen)
#define IAX_IE_CALLINGTNS
Asterisk main include file. File version handling, generic pbx functions.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen)
void iax_set_output(void(*func)(const char *))
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
static void dump_string_hex(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, is defined.
#define DIRECTION_OUTGRESS
int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size)
Dump audio codec preference list into a string.
void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f)
uint64_t ntohll(uint64_t net64)
struct iax_frame * iax_frame_new(int direction, int datalen, unsigned int cacheable)
static struct iax2_ie prov_ies[]
struct sockaddr_in * apparent_addr
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
uint64_t htonll(uint64_t host64)
Structure for variables, used for configurations and for channel variables.
#define IAX_IE_MD5_RESULT
static void(* errorf)(const char *str)
#define IAX_IE_FIRMWAREVER
static void dump_short(char *output, int maxlen, void *value, int len)
Configuration File Parser.
static void dump_ipaddr(char *output, int maxlen, void *value, int len)
static void internaloutput(const char *str)
#define IAX_IE_AUTOANSWER
struct ast_str * ast_str_create(size_t init_len)
Create a malloc'ed dynamic length string.
#define IAX_IE_SAMPLINGRATE
int iax_get_iframes(void)
Definitions to aid in the use of thread local storage.
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
int iax_ie_append_versioned_uint64(struct iax_ie_data *ied, unsigned char ie, unsigned char version, uint64_t value)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return * the previous value of *p. This can be used to handle reference co...
#define IAX_IE_CALLING_NUMBER
#define IAX_IE_CALLING_ANI
#define IAX_IE_DEVICETYPE
static void dump_datetime(char *output, int maxlen, void *value, int len)
#define IAX_IE_ENCRYPTION
int iax_get_oframes(void)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
static void frame_cache_cleanup(void *data)
Handle unaligned data access.
#define IAX_MAX_OSPBLOCK_NUM
int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, const struct sockaddr_in *sin)
unsigned char * calltokendata
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
unsigned char iax_unknown
Asterisk internal frame definitions.
char * osptokenblock[IAX_MAX_OSPBLOCK_NUM]
#define IAX_IE_SERVICEIDENT
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
#define IAX_IE_CALLING_NAME
#define IAX_IE_PROVISIONING
#define IAX_IE_AESPROVISIONING
#define FRAME_CACHE_MAX_SIZE
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define PROV_IE_SERVERPORT
static unsigned int get_unaligned_uint32(const void *p)
static unsigned short get_unaligned_uint16(const void *p)
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define IAX_IE_CALLED_NUMBER
char * ast_getformatname(format_t format)
Get the name of a format.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Implementation of Inter-Asterisk eXchange, version 2 iax2-parser.c iax2-parser.h chan_iax2.c.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
#define IAX_IE_AUTHMETHODS
#define PROV_IE_NEWAESKEY
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static void dump_prefs(char *output, int maxlen, void *value, int len)
static void dump_ies(unsigned char *iedata, int len)
void iax_set_error(void(*func)(const char *))
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define IAX_IE_FWBLOCKDESC
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
static void put_unaligned_uint64(void *p, uint64_t datum)
#define PROV_IE_ALTSERVER
#define IAX_IE_CODEC_PREFS
static void dump_samprate(char *output, int maxlen, void *value, int len)
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...
static void dump_prov(char *output, int maxlen, void *value, int len)
static void dump_versioned_codec(char *output, int maxlen, void *value, int len)
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
#define AST_THREADSTORAGE_CUSTOM(a, b, c)
Define a thread storage variable, with custom initialization and cleanup.
static void internalerror(const char *str)
static struct iax2_ie infoelts[]
int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
#define IAX_IE_CALLINGTON
static void(* outputf)(const char *str)
struct ast_variable * vars
#define IAX_IE_CALLINGPRES
#define AST_FORMAT_SLINEAR
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
static void dump_string(char *output, int maxlen, void *value, int len)
Implementation of the IAX2 protocol.
#define IAX_IE_RR_DROPPED
#define ast_realloc(a, b)
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
#define IAX_IE_MUSICONHOLD
void(* dump)(char *output, int maxlen, void *value, int len)
static void dump_int(char *output, int maxlen, void *value, int len)
Data structure associated with a single frame of data.
#define IAX_IE_RSA_RESULT
void ast_codec_pref_convert(struct ast_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...
unsigned int ospblocklength[IAX_MAX_OSPBLOCK_NUM]
IAX2 Provisioning protocol.
#define IAX_IE_FWBLOCKDATA
#define IAX_IE_CALLED_CONTEXT
void iax_frame_free(struct iax_frame *fr)
struct iax_frame::@116 list
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
enum ast_frame_type frametype
struct ast_variable * next
#define IAX_IE_APPARENT_ADDR
struct iax_frame_list list
static void dump_addr(char *output, int maxlen, void *value, int len)
char * iax_provflags2str(char *buf, int buflen, unsigned int flags)
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
static void dump_prov_flags(char *output, int maxlen, void *value, int len)
#define IAX_IE_TRANSFERID
const char * iax_ie2str(int ie)
void ast_swapcopy_samples(void *dst, const void *src, int samples)
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str)
union ast_frame::@172 data
static void dump_byte(char *output, int maxlen, void *value, int len)
static struct ast_threadstorage frame_cache
#define IAX_IE_CAPABILITY
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
static uint64_t get_unaligned_uint64(const void *p)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define ast_calloc_cache(a, b)