Asterisk - The Open Source Telephony Project GIT-master-2de1a68
Data Structures | Macros | Functions
parser.h File Reference

Implementation of the IAX2 protocol. More...

#include "asterisk/frame.h"
#include "asterisk/linkedlists.h"
#include "asterisk/crypto.h"
#include "asterisk/netsock2.h"
#include "iax2.h"
Include dependency graph for parser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  iax_frame
 
struct  iax_ie_data
 
struct  iax_ies
 

Macros

#define DIRECTION_INGRESS   1
 
#define DIRECTION_OUTGRESS   2
 

Functions

void iax_frame_free (struct iax_frame *fr)
 
struct iax_frameiax_frame_new (int direction, int datalen, unsigned int cacheable)
 
void iax_frame_subclass2str (enum iax_frame_subclass subclass, char *str, size_t len)
 
void iax_frame_wrap (struct iax_frame *fr, struct ast_frame *f)
 
int iax_get_frames (void)
 
int iax_get_iframes (void)
 
int iax_get_oframes (void)
 
const char * iax_ie2str (int ie)
 
int iax_ie_append (struct iax_ie_data *ied, unsigned char ie)
 
int iax_ie_append_addr (struct iax_ie_data *ied, unsigned char ie, const struct ast_sockaddr *addr)
 
int iax_ie_append_byte (struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
 
int iax_ie_append_int (struct iax_ie_data *ied, unsigned char ie, unsigned int value)
 
int iax_ie_append_raw (struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
 
int iax_ie_append_short (struct iax_ie_data *ied, unsigned char ie, unsigned short value)
 
int iax_ie_append_str (struct iax_ie_data *ied, unsigned char ie, const char *str)
 
int iax_ie_append_versioned_uint64 (struct iax_ie_data *ied, unsigned char ie, unsigned char version, uint64_t value)
 
int iax_parse_ies (struct iax_ies *ies, unsigned char *data, int datalen)
 
void iax_set_error (void(*output)(const char *data))
 
void iax_set_output (void(*output)(const char *data))
 
void iax_showframe (struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct ast_sockaddr *addr, int datalen)
 

Detailed Description

Implementation of the IAX2 protocol.

Definition in file parser.h.

Macro Definition Documentation

◆ DIRECTION_INGRESS

#define DIRECTION_INGRESS   1

Definition at line 88 of file parser.h.

◆ DIRECTION_OUTGRESS

#define DIRECTION_OUTGRESS   2

Definition at line 89 of file parser.h.

Function Documentation

◆ iax_frame_free()

void iax_frame_free ( struct iax_frame fr)

Definition at line 1295 of file parser.c.

1296{
1297#if !defined(NO_FRAME_CACHE)
1298 struct iax_frames *iax_frames = NULL;
1299#endif
1300
1301 /* Note: does not remove from scheduler! */
1302 if (fr->direction == DIRECTION_INGRESS)
1304 else if (fr->direction == DIRECTION_OUTGRESS)
1306 else {
1307 errorf("Attempt to double free frame detected\n");
1308 return;
1309 }
1311
1312#if !defined(NO_FRAME_CACHE)
1313 if (!fr->cacheable
1316 ast_free(fr);
1317 return;
1318 }
1319
1321 fr->direction = 0;
1322 /* Pseudo-sort: keep smaller frames at the top of the list. This should
1323 * increase the chance that we pick the smallest applicable frame for use. */
1324 if (AST_LIST_FIRST(&iax_frames->list) && AST_LIST_FIRST(&iax_frames->list)->afdatalen < fr->afdatalen) {
1326 } else {
1328 }
1329 iax_frames->size++;
1330 return;
1331 }
1332#endif
1333 ast_free(fr);
1334}
#define ast_free(a)
Definition: astmm.h:180
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:711
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:421
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:757
#define ast_opt_cache_media_frames
Definition: options.h:121
static struct ast_threadstorage frame_cache
Definition: parser.c:63
static void(* errorf)(const char *str)
Definition: parser.c:88
static int iframes
Definition: parser.c:52
#define FRAME_CACHE_MAX_SIZE
Definition: parser.c:74
static int frames
Definition: parser.c:51
static int oframes
Definition: parser.c:53
#define DIRECTION_OUTGRESS
Definition: parser.h:89
#define DIRECTION_INGRESS
Definition: parser.h:88
#define NULL
Definition: resample.c:96
size_t afdatalen
Definition: parser.h:144
unsigned int direction
Definition: parser.h:122
unsigned int cacheable
Definition: parser.h:124
struct iax_frame_list list
Definition: parser.c:70
size_t size
Definition: parser.c:71
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.

References iax_frame::afdatalen, ast_atomic_fetchadd_int(), ast_free, AST_LIST_FIRST, AST_LIST_INSERT_HEAD, AST_LIST_INSERT_TAIL, ast_opt_cache_media_frames, ast_threadstorage_get(), iax_frame::cacheable, iax_frame::direction, DIRECTION_INGRESS, DIRECTION_OUTGRESS, errorf, frame_cache, FRAME_CACHE_MAX_SIZE, frames, iframes, iax_frames::list, NULL, oframes, and iax_frames::size.

Referenced by iax2_frame_free(), and transmit_frame().

◆ iax_frame_new()

struct iax_frame * iax_frame_new ( int  direction,
int  datalen,
unsigned int  cacheable 
)

Definition at line 1228 of file parser.c.

1229{
1230 struct iax_frame *fr;
1231
1232#if !defined(NO_FRAME_CACHE)
1233 if (cacheable) {
1234 struct iax_frames *iax_frames;
1235 struct iax_frame *smallest;
1236
1237 /* Attempt to get a frame from this thread's cache */
1239 smallest = AST_LIST_FIRST(&iax_frames->list);
1241 if (fr->afdatalen >= datalen) {
1242 size_t afdatalen = fr->afdatalen;
1244 iax_frames->size--;
1245 memset(fr, 0, sizeof(*fr));
1246 fr->afdatalen = afdatalen;
1247 break;
1248 } else if (smallest->afdatalen > fr->afdatalen) {
1249 smallest = fr;
1250 }
1251 }
1253 if (!fr) {
1254 if (iax_frames->size >= FRAME_CACHE_MAX_SIZE && smallest) {
1255 /* Make useless cache into something more useful */
1256 AST_LIST_REMOVE(&iax_frames->list, smallest, list);
1257 iax_frames->size--;
1258 ast_free(smallest);
1259 }
1260 if (!(fr = ast_calloc(1, sizeof(*fr) + datalen))) {
1261 return NULL;
1262 }
1263 fr->afdatalen = datalen;
1264 }
1265 } else {
1266 if (!(fr = ast_calloc(1, sizeof(*fr) + datalen))) {
1267 return NULL;
1268 }
1269 fr->afdatalen = datalen;
1270 }
1271 fr->cacheable = 1;
1272 } else
1273#endif
1274 {
1275 if (!(fr = ast_calloc(1, sizeof(*fr) + datalen))) {
1276 return NULL;
1277 }
1278 fr->afdatalen = datalen;
1279 }
1280
1281
1282 fr->direction = direction;
1283 fr->retrans = -1;
1284
1285 if (fr->direction == DIRECTION_INGRESS)
1287 else
1289
1291
1292 return fr;
1293}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
direction
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:856
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
struct iax_frame::@139 list
int retrans
Definition: parser.h:130
int datalen
Definition: parser.h:106

References iax_frame::afdatalen, ast_atomic_fetchadd_int(), ast_calloc, ast_free, AST_LIST_FIRST, AST_LIST_REMOVE, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_threadstorage_get(), iax_frame::cacheable, iax_frame::datalen, iax_frame::direction, DIRECTION_INGRESS, frame_cache, FRAME_CACHE_MAX_SIZE, frames, iframes, iax_frame::list, iax_frames::list, NULL, oframes, iax_frame::retrans, and iax_frames::size.

Referenced by iax2_send(), and iaxfrdup2().

◆ iax_frame_subclass2str()

void iax_frame_subclass2str ( enum iax_frame_subclass  subclass,
char *  str,
size_t  len 
)

Definition at line 463 of file parser.c.

464{
465 const char *cmd = "Unknown";
466
467 /* if an error occurs here during compile, that means a new iax frame subclass
468 * has been added to the iax_frame_subclass enum. Add the new subclass to the
469 * switch case and make sure to update it with a new string representation. */
470 switch (subclass) {
471 case IAX_COMMAND_NEW:
472 cmd = "NEW ";
473 break;
474 case IAX_COMMAND_PING:
475 cmd = "PING ";
476 break;
477 case IAX_COMMAND_PONG:
478 cmd = "PONG ";
479 break;
480 case IAX_COMMAND_ACK:
481 cmd = "ACK ";
482 break;
484 cmd = "HANGUP ";
485 break;
487 cmd = "REJECT ";
488 break;
490 cmd = "ACCEPT ";
491 break;
493 cmd = "AUTHREQ";
494 break;
496 cmd = "AUTHREP";
497 break;
499 cmd = "INVAL ";
500 break;
502 cmd = "LAGRQ ";
503 break;
505 cmd = "LAGRP ";
506 break;
508 cmd = "REGREQ ";
509 break;
511 cmd = "REGAUTH";
512 break;
514 cmd = "REGACK ";
515 break;
517 cmd = "REGREJ ";
518 break;
520 cmd = "REGREL ";
521 break;
522 case IAX_COMMAND_VNAK:
523 cmd = "VNAK ";
524 break;
526 cmd = "DPREQ ";
527 break;
529 cmd = "DPREP ";
530 break;
531 case IAX_COMMAND_DIAL:
532 cmd = "DIAL ";
533 break;
535 cmd = "TXREQ ";
536 break;
538 cmd = "TXCNT ";
539 break;
541 cmd = "TXACC ";
542 break;
544 cmd = "TXREADY";
545 break;
547 cmd = "TXREL ";
548 break;
550 cmd = "TXREJ ";
551 break;
553 cmd = "QUELCH ";
554 break;
556 cmd = "UNQUELCH";
557 break;
558 case IAX_COMMAND_POKE:
559 cmd = "POKE ";
560 break;
561 case IAX_COMMAND_PAGE:
562 cmd = "PAGE ";
563 break;
564 case IAX_COMMAND_MWI:
565 cmd = "MWI ";
566 break;
568 cmd = "UNSPRTD";
569 break;
571 cmd = "TRANSFR";
572 break;
574 cmd = "PROVISN";
575 break;
577 cmd = "FWDWNLD";
578 break;
580 cmd = "FWDATA ";
581 break;
583 cmd = "TXMEDIA";
584 break;
586 cmd = "RTKEY ";
587 break;
589 cmd = "CTOKEN ";
590 break;
591 }
592 ast_copy_string(str, cmd, len);
593}
const char * str
Definition: app_jack.c:147
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
@ IAX_COMMAND_MWI
Definition: iax2.h:103
@ IAX_COMMAND_FWDOWNL
Definition: iax2.h:111
@ IAX_COMMAND_TXREL
Definition: iax2.h:91
@ IAX_COMMAND_TXMEDIA
Definition: iax2.h:115
@ IAX_COMMAND_AUTHREP
Definition: iax2.h:60
@ IAX_COMMAND_PROVISION
Definition: iax2.h:109
@ IAX_COMMAND_DPREP
Definition: iax2.h:79
@ IAX_COMMAND_REGAUTH
Definition: iax2.h:67
@ IAX_COMMAND_INVAL
Definition: iax2.h:61
@ IAX_COMMAND_REJECT
Definition: iax2.h:57
@ IAX_COMMAND_FWDATA
Definition: iax2.h:113
@ IAX_COMMAND_ACK
Definition: iax2.h:55
@ IAX_COMMAND_PONG
Definition: iax2.h:54
@ IAX_COMMAND_LAGRQ
Definition: iax2.h:62
@ IAX_COMMAND_HANGUP
Definition: iax2.h:56
@ IAX_COMMAND_TXREADY
Definition: iax2.h:89
@ IAX_COMMAND_TXACC
Definition: iax2.h:87
@ IAX_COMMAND_QUELCH
Definition: iax2.h:95
@ IAX_COMMAND_PING
Definition: iax2.h:53
@ IAX_COMMAND_TRANSFER
Definition: iax2.h:107
@ IAX_COMMAND_LAGRP
Definition: iax2.h:63
@ IAX_COMMAND_TXCNT
Definition: iax2.h:85
@ IAX_COMMAND_REGACK
Definition: iax2.h:69
@ IAX_COMMAND_AUTHREQ
Definition: iax2.h:59
@ IAX_COMMAND_TXREJ
Definition: iax2.h:93
@ IAX_COMMAND_REGREJ
Definition: iax2.h:71
@ IAX_COMMAND_REGREL
Definition: iax2.h:73
@ IAX_COMMAND_CALLTOKEN
Definition: iax2.h:119
@ IAX_COMMAND_DIAL
Definition: iax2.h:81
@ IAX_COMMAND_ACCEPT
Definition: iax2.h:58
@ IAX_COMMAND_UNSUPPORT
Definition: iax2.h:105
@ IAX_COMMAND_NEW
Definition: iax2.h:52
@ IAX_COMMAND_POKE
Definition: iax2.h:99
@ IAX_COMMAND_PAGE
Definition: iax2.h:101
@ IAX_COMMAND_REGREQ
Definition: iax2.h:65
@ IAX_COMMAND_VNAK
Definition: iax2.h:75
@ IAX_COMMAND_UNQUELCH
Definition: iax2.h:97
@ IAX_COMMAND_TXREQ
Definition: iax2.h:83
@ IAX_COMMAND_RTKEY
Definition: iax2.h:117
@ IAX_COMMAND_DPREQ
Definition: iax2.h:77
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425

References ast_copy_string(), IAX_COMMAND_ACCEPT, IAX_COMMAND_ACK, IAX_COMMAND_AUTHREP, IAX_COMMAND_AUTHREQ, IAX_COMMAND_CALLTOKEN, IAX_COMMAND_DIAL, IAX_COMMAND_DPREP, IAX_COMMAND_DPREQ, IAX_COMMAND_FWDATA, IAX_COMMAND_FWDOWNL, IAX_COMMAND_HANGUP, IAX_COMMAND_INVAL, IAX_COMMAND_LAGRP, IAX_COMMAND_LAGRQ, IAX_COMMAND_MWI, IAX_COMMAND_NEW, IAX_COMMAND_PAGE, IAX_COMMAND_PING, IAX_COMMAND_POKE, IAX_COMMAND_PONG, IAX_COMMAND_PROVISION, IAX_COMMAND_QUELCH, IAX_COMMAND_REGACK, IAX_COMMAND_REGAUTH, IAX_COMMAND_REGREJ, IAX_COMMAND_REGREL, IAX_COMMAND_REGREQ, IAX_COMMAND_REJECT, IAX_COMMAND_RTKEY, IAX_COMMAND_TRANSFER, IAX_COMMAND_TXACC, IAX_COMMAND_TXCNT, IAX_COMMAND_TXMEDIA, IAX_COMMAND_TXREADY, IAX_COMMAND_TXREJ, IAX_COMMAND_TXREL, IAX_COMMAND_TXREQ, IAX_COMMAND_UNQUELCH, IAX_COMMAND_UNSUPPORT, IAX_COMMAND_VNAK, len(), and str.

Referenced by ast_cli_netstats(), handle_cli_iax2_show_channels(), iax_showframe(), and socket_process_helper().

◆ iax_frame_wrap()

void iax_frame_wrap ( struct iax_frame fr,
struct ast_frame f 
)

Definition at line 1195 of file parser.c.

1196{
1197 fr->af.frametype = f->frametype;
1198 fr->af.subclass.format = f->subclass.format;
1200 fr->af.mallocd = 0; /* Our frame is static relative to the container */
1201 fr->af.datalen = f->datalen;
1202 fr->af.samples = f->samples;
1204 fr->af.src = f->src;
1205 fr->af.delivery.tv_sec = 0;
1206 fr->af.delivery.tv_usec = 0;
1207 fr->af.data.ptr = fr->afdata;
1208 fr->af.len = f->len;
1209 if (fr->af.datalen) {
1210 size_t copy_len = fr->af.datalen;
1211 if (copy_len > fr->afdatalen) {
1212 ast_log(LOG_ERROR, "Losing frame data because destination buffer size '%d' bytes not big enough for '%d' bytes in the frame\n",
1213 (int) fr->afdatalen, (int) fr->af.datalen);
1214 copy_len = fr->afdatalen;
1215 }
1216#if __BYTE_ORDER == __LITTLE_ENDIAN
1217 /* We need to byte-swap slinear samples from network byte order */
1218 if ((fr->af.frametype == AST_FRAME_VOICE) &&
1220 /* 2 bytes / sample for SLINEAR */
1221 ast_swapcopy_samples(fr->af.data.ptr, f->data.ptr, copy_len / 2);
1222 } else
1223#endif
1224 memcpy(fr->af.data.ptr, f->data.ptr, copy_len);
1225 }
1226}
#define ast_log
Definition: astobj2.c:42
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_EQUAL
Definition: format.h:36
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
void ast_swapcopy_samples(void *dst, const void *src, int samples)
Definition: main/frame.c:396
@ AST_FRAME_VOICE
#define LOG_ERROR
struct ast_format * format
struct ast_frame_subclass subclass
union ast_frame::@226 data
struct timeval delivery
enum ast_frame_type frametype
const char * src
unsigned char afdata[0]
Definition: parser.h:146
struct ast_frame af
Definition: parser.h:142

References iax_frame::af, iax_frame::afdata, iax_frame::afdatalen, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_slin, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log, ast_swapcopy_samples(), ast_frame::data, ast_frame::datalen, ast_frame::delivery, ast_frame_subclass::format, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::len, LOG_ERROR, ast_frame::mallocd, ast_frame::offset, ast_frame::ptr, ast_frame::samples, ast_frame::src, and ast_frame::subclass.

Referenced by iax2_send(), iaxfrdup2(), socket_process_helper(), and socket_process_meta().

◆ iax_get_frames()

int iax_get_frames ( void  )

Definition at line 1349 of file parser.c.

1349{ return frames; }

References frames.

Referenced by handle_cli_iax2_show_stats().

◆ iax_get_iframes()

int iax_get_iframes ( void  )

Definition at line 1350 of file parser.c.

1350{ return iframes; }

References iframes.

Referenced by handle_cli_iax2_show_stats().

◆ iax_get_oframes()

int iax_get_oframes ( void  )

Definition at line 1351 of file parser.c.

1351{ return oframes; }

References oframes.

Referenced by handle_cli_iax2_show_stats().

◆ iax_ie2str()

const char * iax_ie2str ( int  ie)

Definition at line 353 of file parser.c.

354{
355 int x;
356 for (x = 0; x < ARRAY_LEN(infoelts); x++) {
357 if (infoelts[x].ie == ie)
358 return infoelts[x].name;
359 }
360 return "Unknown IE";
361}
static struct iax2_ie infoelts[]
Definition: parser.c:274
char * name
Definition: parser.c:271
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, iax2_ie::ie, infoelts, and iax2_ie::name.

Referenced by iax_ie_append_raw(), and iax_parse_ies().

◆ iax_ie_append()

int iax_ie_append ( struct iax_ie_data ied,
unsigned char  ie 
)

Definition at line 780 of file parser.c.

781{
782 return iax_ie_append_raw(ied, ie, NULL, 0);
783}
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: parser.c:726

References iax_ie_append_raw(), and NULL.

Referenced by iax2_call(), and iax_firmware_append().

◆ iax_ie_append_addr()

int iax_ie_append_addr ( struct iax_ie_data ied,
unsigned char  ie,
const struct ast_sockaddr addr 
)

Definition at line 741 of file parser.c.

742{
743 return iax_ie_append_raw(ied, ie, addr, addr->len);
744}
socklen_t len
Definition: netsock2.h:99

References iax_ie_append_raw(), and ast_sockaddr::len.

Referenced by update_registry().

◆ iax_ie_append_byte()

int iax_ie_append_byte ( struct iax_ie_data ied,
unsigned char  ie,
unsigned char  dat 
)

Definition at line 775 of file parser.c.

776{
777 return iax_ie_append_raw(ied, ie, &dat, 1);
778}

References iax_ie_append_raw().

Referenced by __auth_reject(), __auto_hangup(), authenticate_request(), iax2_call(), iax2_hangup(), iax_provision_build(), and socket_process_helper().

◆ iax_ie_append_int()

int iax_ie_append_int ( struct iax_ie_data ied,
unsigned char  ie,
unsigned int  value 
)

Definition at line 756 of file parser.c.

757{
758 unsigned int newval;
759 newval = htonl(value);
760 return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
761}
int value
Definition: syslog.c:37

References iax_ie_append_raw(), and value.

Referenced by cache_get_callno_locked(), construct_rr(), iax2_call(), iax_firmware_append(), iax_provision_build(), socket_process_helper(), try_transfer(), and update_registry().

◆ iax_ie_append_raw()

int iax_ie_append_raw ( struct iax_ie_data ied,
unsigned char  ie,
const void *  data,
int  datalen 
)

Definition at line 726 of file parser.c.

727{
728 char tmp[256];
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);
731 errorf(tmp);
732 return -1;
733 }
734 ied->buf[ied->pos++] = ie;
735 ied->buf[ied->pos++] = datalen;
736 memcpy(ied->buf + ied->pos, data, datalen);
737 ied->pos += datalen;
738 return 0;
739}
static int tmp()
Definition: bt_open.c:389
const char * iax_ie2str(int ie)
Definition: parser.c:353
int pos
Definition: parser.h:151
unsigned char buf[1024]
Definition: parser.h:150

References iax_ie_data::buf, errorf, iax_ie2str(), iax_ie_data::pos, and tmp().

Referenced by iax2_call(), iax2_key_rotate(), iax2_provision(), iax_firmware_append(), iax_ie_append(), iax_ie_append_addr(), iax_ie_append_byte(), iax_ie_append_int(), iax_ie_append_short(), iax_ie_append_str(), and iax_ie_append_versioned_uint64().

◆ iax_ie_append_short()

int iax_ie_append_short ( struct iax_ie_data ied,
unsigned char  ie,
unsigned short  value 
)

Definition at line 763 of file parser.c.

764{
765 unsigned short newval;
766 newval = htons(value);
767 return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
768}

References iax_ie_append_raw(), and value.

Referenced by authenticate_request(), cache_get_callno_locked(), construct_rr(), dp_lookup(), iax2_call(), iax2_do_register(), iax_provision_build(), registry_authrequest(), registry_rerequest(), socket_process_helper(), and update_registry().

◆ iax_ie_append_str()

int iax_ie_append_str ( struct iax_ie_data ied,
unsigned char  ie,
const char *  str 
)

◆ iax_ie_append_versioned_uint64()

int iax_ie_append_versioned_uint64 ( struct iax_ie_data ied,
unsigned char  ie,
unsigned char  version,
uint64_t  value 
)

Definition at line 746 of file parser.c.

747{
748 struct _local {
749 unsigned char version;
750 uint64_t value;
751 } __attribute__((packed)) newval = { version, };
752 put_unaligned_uint64(&newval.value, htonll(value));
753 return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
754}
static char version[AST_MAX_EXTENSION]
Definition: chan_ooh323.c:391
uint64_t htonll(uint64_t host64)
Definition: strcompat.c:390
static void put_unaligned_uint64(void *p, uint64_t datum)
Definition: unaligned.h:51

References htonll(), iax_ie_append_raw(), put_unaligned_uint64(), value, and version.

Referenced by iax2_call(), and socket_process_helper().

◆ iax_parse_ies()

int iax_parse_ies ( struct iax_ies ies,
unsigned char *  data,
int  datalen 
)

Definition at line 795 of file parser.c.

796{
797 /* Parse data into information elements */
798 int len;
799 int ie;
800 char tmp[256], *tmp2;
801 struct ast_variable *var, *var2, *prev;
802 unsigned int count;
803 memset(ies, 0, (int)sizeof(struct iax_ies));
804 ies->msgcount = -1;
805 ies->firmwarever = -1;
806 ies->calling_ton = -1;
807 ies->calling_tns = -1;
808 ies->calling_pres = -1;
809 ies->calling_ani2 = -1;
810 ies->samprate = IAX_RATE_8KHZ;
811 while(datalen >= 2) {
812 ie = data[0];
813 len = data[1];
814 if (len > datalen - 2) {
815 errorf("Information element length exceeds message size\n");
816 return -1;
817 }
818 switch(ie) {
820 ies->called_number = (char *)data + 2;
821 break;
823 ies->calling_number = (char *)data + 2;
824 break;
826 ies->calling_ani = (char *)data + 2;
827 break;
829 ies->calling_name = (char *)data + 2;
830 break;
832 ies->called_context = (char *)data + 2;
833 break;
834 case IAX_IE_USERNAME:
835 ies->username = (char *)data + 2;
836 break;
837 case IAX_IE_PASSWORD:
838 ies->password = (char *)data + 2;
839 break;
841 ies->codec_prefs = (char *)data + 2;
842 break;
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);
846 errorf(tmp);
847 } else if (ies->capability == 0) { /* Don't overwrite capability2, if specified */
848 ies->capability = ntohl(get_unaligned_uint32(data + 2));
849 }
850 break;
852 {
853 int version = data[2];
854 if (version == 0) {
855 if (len != (int)sizeof(char) + sizeof(iax2_format)) {
856 snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int) (sizeof(iax2_format) + sizeof(char)), len);
857 errorf(tmp);
858 } else {
860 }
861 } /* else unknown version */
862 }
863 break;
864 case IAX_IE_FORMAT:
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);
867 errorf(tmp);
868 } else if (ies->format == 0) { /* Don't overwrite format2, if specified */
869 ies->format = ntohl(get_unaligned_uint32(data + 2));
870 }
871 break;
872 case IAX_IE_FORMAT2:
873 {
874 int version = data[2];
875 if (version == 0) {
876 if (len != (int)sizeof(char) + sizeof(iax2_format)) {
877 snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int) (sizeof(iax2_format) + sizeof(char)), len);
878 errorf(tmp);
879 } else {
880 ies->format = (iax2_format) ntohll(get_unaligned_uint64(data + 3));
881 }
882 } /* else unknown version */
883 }
884 break;
885 case IAX_IE_LANGUAGE:
886 ies->language = (char *)data + 2;
887 break;
888 case IAX_IE_VERSION:
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);
891 errorf(tmp);
892 } else
893 ies->version = ntohs(get_unaligned_uint16(data + 2));
894 break;
895 case IAX_IE_ADSICPE:
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);
898 errorf(tmp);
899 } else
900 ies->adsicpe = ntohs(get_unaligned_uint16(data + 2));
901 break;
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);
905 errorf(tmp);
906 } else
907 ies->samprate = ntohs(get_unaligned_uint16(data + 2));
908 break;
909 case IAX_IE_DNID:
910 ies->dnid = (char *)data + 2;
911 break;
912 case IAX_IE_RDNIS:
913 ies->rdnis = (char *)data + 2;
914 break;
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);
918 errorf(tmp);
919 } else
920 ies->authmethods = ntohs(get_unaligned_uint16(data + 2));
921 break;
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);
925 errorf(tmp);
926 } else
927 ies->encmethods = ntohs(get_unaligned_uint16(data + 2));
928 break;
929 case IAX_IE_CHALLENGE:
930 ies->challenge = (char *)data + 2;
931 break;
933 ies->md5_result = (char *)data + 2;
934 break;
936 ies->rsa_result = (char *)data + 2;
937 break;
939 memcpy(&ies->apparent_addr , (struct ast_sockaddr *) (data + 2), len);
940 ies->apparent_addr.len = len;
941 break;
942 case IAX_IE_REFRESH:
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);
945 errorf(tmp);
946 } else
947 ies->refresh = ntohs(get_unaligned_uint16(data + 2));
948 break;
949 case IAX_IE_DPSTATUS:
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);
952 errorf(tmp);
953 } else
954 ies->dpstatus = ntohs(get_unaligned_uint16(data + 2));
955 break;
956 case IAX_IE_CALLNO:
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);
959 errorf(tmp);
960 } else
961 ies->callno = ntohs(get_unaligned_uint16(data + 2));
962 break;
963 case IAX_IE_CAUSE:
964 ies->cause = (char *)data + 2;
965 break;
966 case IAX_IE_CAUSECODE:
967 if (len != 1) {
968 snprintf(tmp, (int)sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
969 errorf(tmp);
970 } else {
971 ies->causecode = data[2];
972 }
973 break;
975 if (len == 1)
976 ies->iax_unknown = data[2];
977 else {
978 snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
979 errorf(tmp);
980 }
981 break;
982 case IAX_IE_MSGCOUNT:
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);
985 errorf(tmp);
986 } else
987 ies->msgcount = ntohs(get_unaligned_uint16(data + 2));
988 break;
990 ies->autoanswer = 1;
991 break;
993 ies->musiconhold = 1;
994 break;
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);
998 errorf(tmp);
999 } else
1000 ies->transferid = ntohl(get_unaligned_uint32(data + 2));
1001 break;
1002 case IAX_IE_DATETIME:
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);
1005 errorf(tmp);
1006 } else
1007 ies->datetime = ntohl(get_unaligned_uint32(data + 2));
1008 break;
1009 case IAX_IE_FIRMWAREVER:
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);
1012 errorf(tmp);
1013 } else
1014 ies->firmwarever = ntohs(get_unaligned_uint16(data + 2));
1015 break;
1016 case IAX_IE_DEVICETYPE:
1017 ies->devicetype = (char *)data + 2;
1018 break;
1020 ies->serviceident = (char *)data + 2;
1021 break;
1022 case IAX_IE_FWBLOCKDESC:
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);
1025 errorf(tmp);
1026 } else
1027 ies->fwdesc = ntohl(get_unaligned_uint32(data + 2));
1028 break;
1029 case IAX_IE_FWBLOCKDATA:
1030 ies->fwdata = data + 2;
1031 ies->fwdatalen = len;
1032 break;
1033 case IAX_IE_ENCKEY:
1034 ies->enckey = data + 2;
1035 ies->enckeylen = len;
1036 break;
1037 case IAX_IE_PROVVER:
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);
1040 errorf(tmp);
1041 } else {
1042 ies->provverpres = 1;
1043 ies->provver = ntohl(get_unaligned_uint32(data + 2));
1044 }
1045 break;
1046 case IAX_IE_CALLINGPRES:
1047 if (len == 1)
1048 ies->calling_pres = data[2];
1049 else {
1050 snprintf(tmp, (int)sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
1051 errorf(tmp);
1052 }
1053 break;
1054 case IAX_IE_CALLINGTON:
1055 if (len == 1)
1056 ies->calling_ton = data[2];
1057 else {
1058 snprintf(tmp, (int)sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
1059 errorf(tmp);
1060 }
1061 break;
1062 case IAX_IE_CALLINGANI2:
1063 if (len == (int)sizeof(unsigned int)) {
1064 ies->calling_ani2 = ntohl(get_unaligned_uint32(data + 2));
1065 } else {
1066 snprintf(tmp, sizeof(tmp), "Expected callingani2 to be %zu bytes but was %d\n", sizeof(unsigned int), len);
1067 errorf(tmp);
1068 }
1069 break;
1070 case IAX_IE_CALLINGTNS:
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);
1073 errorf(tmp);
1074 } else
1075 ies->calling_tns = ntohs(get_unaligned_uint16(data + 2));
1076 break;
1077 case IAX_IE_RR_JITTER:
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);
1080 errorf(tmp);
1081 } else {
1082 ies->rr_jitter = ntohl(get_unaligned_uint32(data + 2));
1083 }
1084 break;
1085 case IAX_IE_RR_LOSS:
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);
1088 errorf(tmp);
1089 } else {
1090 ies->rr_loss = ntohl(get_unaligned_uint32(data + 2));
1091 }
1092 break;
1093 case IAX_IE_RR_PKTS:
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);
1096 errorf(tmp);
1097 } else {
1098 ies->rr_pkts = ntohl(get_unaligned_uint32(data + 2));
1099 }
1100 break;
1101 case IAX_IE_RR_DELAY:
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);
1104 errorf(tmp);
1105 } else {
1106 ies->rr_delay = ntohs(get_unaligned_uint16(data + 2));
1107 }
1108 break;
1109 case IAX_IE_RR_DROPPED:
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);
1112 errorf(tmp);
1113 } else {
1114 ies->rr_dropped = ntohl(get_unaligned_uint32(data + 2));
1115 }
1116 break;
1117 case IAX_IE_RR_OOO:
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);
1120 errorf(tmp);
1121 } else {
1122 ies->rr_ooo = ntohl(get_unaligned_uint32(data + 2));
1123 }
1124 break;
1125 case IAX_IE_VARIABLE:
1126 ast_copy_string(tmp, (char *)data + 2, len + 1);
1127 tmp2 = strchr(tmp, '=');
1128 if (tmp2)
1129 *tmp2++ = '\0';
1130 else
1131 tmp2 = "";
1132 {
1133 struct ast_str *str = ast_str_create(16);
1134 /* Existing variable or new variable? */
1135 for (var2 = ies->vars, prev = NULL; var2; prev = var2, var2 = var2->next) {
1136 if (strcmp(tmp, var2->name) == 0) {
1137 ast_str_set(&str, 0, "%s%s", var2->value, tmp2);
1139 var->next = var2->next;
1140 if (prev) {
1141 prev->next = var;
1142 } else {
1143 ies->vars = var;
1144 }
1145 snprintf(tmp, sizeof(tmp), "Assigned (%p)%s to (%p)%s\n", var->name, var->name, var->value, var->value);
1146 outputf(tmp);
1147 ast_free(var2);
1148 break;
1149 }
1150 }
1151 ast_free(str);
1152 }
1153
1154 if (!var2) {
1155 var = ast_variable_new(tmp, tmp2, "");
1156 snprintf(tmp, sizeof(tmp), "Assigned (%p)%s to (%p)%s\n", var->name, var->name, var->value, var->value);
1157 outputf(tmp);
1158 var->next = ies->vars;
1159 ies->vars = var;
1160 }
1161 break;
1162 case IAX_IE_OSPTOKEN:
1163 if ((count = data[2]) < IAX_MAX_OSPBLOCK_NUM) {
1164 ies->osptokenblock[count] = (char *)data + 2 + 1;
1165 ies->ospblocklength[count] = len - 1;
1166 } else {
1167 snprintf(tmp, (int)sizeof(tmp), "Expected OSP token block index to be 0~%d but was %u\n", IAX_MAX_OSPBLOCK_NUM - 1, count);
1168 errorf(tmp);
1169 }
1170 break;
1171 case IAX_IE_CALLTOKEN:
1172 if (len) {
1173 ies->calltokendata = (unsigned char *) data + 2;
1174 }
1175 ies->calltoken = 1;
1176 break;
1177 default:
1178 snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
1179 outputf(tmp);
1180 }
1181 /* Overwrite information element with 0, to null terminate previous portion */
1182 data[0] = 0;
1183 datalen -= (len + 2);
1184 data += (len + 2);
1185 }
1186 /* Null-terminate last field */
1187 *data = '\0';
1188 if (datalen) {
1189 errorf("Invalid information element contents, strange boundary\n");
1190 return -1;
1191 }
1192 return 0;
1193}
#define var
Definition: ast_expr2f.c:605
#define IAX_IE_PASSWORD
Definition: iax2.h:137
#define IAX_IE_RR_PKTS
Definition: iax2.h:179
#define IAX_IE_RR_JITTER
Definition: iax2.h:177
#define IAX_IE_DNID
Definition: iax2.h:143
#define IAX_IE_SERVICEIDENT
Definition: iax2.h:163
#define IAX_IE_CALLINGANI2
Definition: iax2.h:190
#define IAX_IE_DATETIME
Definition: iax2.h:161
#define IAX_IE_CAUSE
Definition: iax2.h:152
#define IAX_IE_DPSTATUS
Definition: iax2.h:150
#define IAX_IE_CALLING_NUMBER
Definition: iax2.h:132
#define IAX_IE_SAMPLINGRATE
Definition: iax2.h:171
#define IAX_IE_TRANSFERID
Definition: iax2.h:157
#define IAX_IE_CALLTOKEN
Definition: iax2.h:185
#define IAX_IE_CALLING_ANI
Definition: iax2.h:133
#define IAX_IE_CALLINGTNS
Definition: iax2.h:170
#define IAX_IE_RSA_RESULT
Definition: iax2.h:147
#define IAX_IE_MSGCOUNT
Definition: iax2.h:154
#define IAX_IE_IAX_UNKNOWN
Definition: iax2.h:153
int64_t iax2_format
Definition: iax2.h:224
#define IAX_IE_ENCKEY
Definition: iax2.h:174
#define IAX_IE_FORMAT2
Definition: iax2.h:188
#define IAX_RATE_8KHZ
Definition: iax2.h:210
#define IAX_IE_CAPABILITY2
Definition: iax2.h:187
#define IAX_IE_CALLING_NAME
Definition: iax2.h:134
#define IAX_IE_ADSICPE
Definition: iax2.h:142
#define IAX_IE_VARIABLE
Definition: iax2.h:183
#define IAX_IE_OSPTOKEN
Definition: iax2.h:184
#define IAX_IE_LANGUAGE
Definition: iax2.h:140
#define IAX_IE_RDNIS
Definition: iax2.h:158
#define IAX_IE_RR_DROPPED
Definition: iax2.h:181
#define IAX_IE_MUSICONHOLD
Definition: iax2.h:156
#define IAX_IE_FORMAT
Definition: iax2.h:139
#define IAX_IE_ENCRYPTION
Definition: iax2.h:173
#define IAX_IE_FIRMWAREVER
Definition: iax2.h:164
#define IAX_IE_CODEC_PREFS
Definition: iax2.h:175
#define IAX_IE_CALLED_NUMBER
Definition: iax2.h:131
#define IAX_IE_FWBLOCKDATA
Definition: iax2.h:166
#define IAX_IE_CAPABILITY
Definition: iax2.h:138
#define IAX_IE_MD5_RESULT
Definition: iax2.h:146
#define IAX_IE_AUTOANSWER
Definition: iax2.h:155
#define IAX_IE_VERSION
Definition: iax2.h:141
#define IAX_IE_RR_OOO
Definition: iax2.h:182
#define IAX_IE_CALLNO
Definition: iax2.h:151
#define IAX_IE_APPARENT_ADDR
Definition: iax2.h:148
#define IAX_IE_REFRESH
Definition: iax2.h:149
#define IAX_IE_PROVVER
Definition: iax2.h:167
#define IAX_MAX_OSPBLOCK_NUM
Definition: iax2.h:193
#define IAX_IE_CALLINGPRES
Definition: iax2.h:168
#define IAX_IE_CAUSECODE
Definition: iax2.h:172
#define IAX_IE_DEVICETYPE
Definition: iax2.h:162
#define IAX_IE_AUTHMETHODS
Definition: iax2.h:144
#define IAX_IE_RR_LOSS
Definition: iax2.h:178
#define IAX_IE_FWBLOCKDESC
Definition: iax2.h:165
#define IAX_IE_CALLED_CONTEXT
Definition: iax2.h:135
#define IAX_IE_CALLINGTON
Definition: iax2.h:169
#define IAX_IE_USERNAME
Definition: iax2.h:136
#define IAX_IE_CHALLENGE
Definition: iax2.h:145
#define IAX_IE_RR_DELAY
Definition: iax2.h:180
uint64_t ntohll(uint64_t net64)
Definition: strcompat.c:364
#define ast_variable_new(name, value, filename)
static void(* outputf)(const char *str)
Definition: parser.c:87
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
Socket address structure.
Definition: netsock2.h:97
Support for dynamic strings.
Definition: strings.h:623
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
Definition: parser.h:27
struct ast_sockaddr apparent_addr
Definition: parser.h:52
unsigned short adsicpe
Definition: parser.h:44
unsigned int rr_jitter
Definition: parser.h:75
unsigned int provver
Definition: parser.h:72
unsigned char * calltokendata
Definition: parser.h:85
unsigned int rr_pkts
Definition: parser.h:77
struct ast_variable * vars
Definition: parser.h:81
unsigned char calltoken
Definition: parser.h:84
unsigned char iax_unknown
Definition: parser.h:58
int calling_ani2
Definition: parser.h:35
unsigned int rr_loss
Definition: parser.h:76
unsigned int authmethods
Definition: parser.h:47
char * challenge
Definition: parser.h:49
char * dnid
Definition: parser.h:45
char * calling_name
Definition: parser.h:31
iax2_format capability
Definition: parser.h:39
char * called_context
Definition: parser.h:36
unsigned char * enckey
Definition: parser.h:70
char * calling_number
Definition: parser.h:29
unsigned int fwdesc
Definition: parser.h:67
char * calling_ani
Definition: parser.h:30
int calling_ton
Definition: parser.h:32
char * password
Definition: parser.h:38
unsigned int transferid
Definition: parser.h:62
unsigned int datetime
Definition: parser.h:63
unsigned int rr_dropped
Definition: parser.h:79
unsigned char causecode
Definition: parser.h:57
int firmwarever
Definition: parser.h:66
unsigned int ospblocklength[IAX_MAX_OSPBLOCK_NUM]
Definition: parser.h:83
int msgcount
Definition: parser.h:59
int calling_tns
Definition: parser.h:33
char * called_number
Definition: parser.h:28
unsigned short callno
Definition: parser.h:55
char * md5_result
Definition: parser.h:50
int provverpres
Definition: parser.h:74
char * language
Definition: parser.h:42
char * codec_prefs
Definition: parser.h:41
iax2_format format
Definition: parser.h:40
unsigned int encmethods
Definition: parser.h:48
unsigned char * fwdata
Definition: parser.h:68
unsigned short dpstatus
Definition: parser.h:54
char * username
Definition: parser.h:37
char * rsa_result
Definition: parser.h:51
int calling_pres
Definition: parser.h:34
int autoanswer
Definition: parser.h:60
unsigned short samprate
Definition: parser.h:73
int version
Definition: parser.h:43
unsigned char fwdatalen
Definition: parser.h:69
char * cause
Definition: parser.h:56
int musiconhold
Definition: parser.h:61
unsigned short refresh
Definition: parser.h:53
char * serviceident
Definition: parser.h:65
unsigned int rr_ooo
Definition: parser.h:80
char * devicetype
Definition: parser.h:64
char * rdnis
Definition: parser.h:46
unsigned short rr_delay
Definition: parser.h:78
unsigned char enckeylen
Definition: parser.h:71
char * osptokenblock[IAX_MAX_OSPBLOCK_NUM]
Definition: parser.h:82
static unsigned int get_unaligned_uint32(const void *p)
Definition: unaligned.h:38
static unsigned short get_unaligned_uint16(const void *p)
Definition: unaligned.h:44
static uint64_t get_unaligned_uint64(const void *p)
Definition: unaligned.h:32

References iax_ies::adsicpe, iax_ies::apparent_addr, ast_copy_string(), ast_free, ast_str_buffer(), ast_str_create, ast_str_set(), ast_variable_new, iax_ies::authmethods, iax_ies::autoanswer, iax_ies::called_context, iax_ies::called_number, iax_ies::calling_ani, iax_ies::calling_ani2, iax_ies::calling_name, iax_ies::calling_number, iax_ies::calling_pres, iax_ies::calling_tns, iax_ies::calling_ton, iax_ies::callno, iax_ies::calltoken, iax_ies::calltokendata, iax_ies::capability, iax_ies::cause, iax_ies::causecode, iax_ies::challenge, iax_ies::codec_prefs, iax_ies::datetime, iax_ies::devicetype, iax_ies::dnid, iax_ies::dpstatus, iax_ies::enckey, iax_ies::enckeylen, iax_ies::encmethods, errorf, ast_variable::file, iax_ies::firmwarever, iax_ies::format, iax_ies::fwdata, iax_ies::fwdatalen, iax_ies::fwdesc, get_unaligned_uint16(), get_unaligned_uint32(), get_unaligned_uint64(), iax_ie2str(), IAX_IE_ADSICPE, IAX_IE_APPARENT_ADDR, IAX_IE_AUTHMETHODS, IAX_IE_AUTOANSWER, IAX_IE_CALLED_CONTEXT, IAX_IE_CALLED_NUMBER, IAX_IE_CALLING_ANI, IAX_IE_CALLING_NAME, IAX_IE_CALLING_NUMBER, IAX_IE_CALLINGANI2, IAX_IE_CALLINGPRES, IAX_IE_CALLINGTNS, IAX_IE_CALLINGTON, IAX_IE_CALLNO, IAX_IE_CALLTOKEN, IAX_IE_CAPABILITY, IAX_IE_CAPABILITY2, IAX_IE_CAUSE, IAX_IE_CAUSECODE, IAX_IE_CHALLENGE, IAX_IE_CODEC_PREFS, IAX_IE_DATETIME, IAX_IE_DEVICETYPE, IAX_IE_DNID, IAX_IE_DPSTATUS, IAX_IE_ENCKEY, IAX_IE_ENCRYPTION, IAX_IE_FIRMWAREVER, IAX_IE_FORMAT, IAX_IE_FORMAT2, IAX_IE_FWBLOCKDATA, IAX_IE_FWBLOCKDESC, IAX_IE_IAX_UNKNOWN, IAX_IE_LANGUAGE, IAX_IE_MD5_RESULT, IAX_IE_MSGCOUNT, IAX_IE_MUSICONHOLD, IAX_IE_OSPTOKEN, IAX_IE_PASSWORD, IAX_IE_PROVVER, IAX_IE_RDNIS, IAX_IE_REFRESH, IAX_IE_RR_DELAY, IAX_IE_RR_DROPPED, IAX_IE_RR_JITTER, IAX_IE_RR_LOSS, IAX_IE_RR_OOO, IAX_IE_RR_PKTS, IAX_IE_RSA_RESULT, IAX_IE_SAMPLINGRATE, IAX_IE_SERVICEIDENT, IAX_IE_TRANSFERID, IAX_IE_USERNAME, IAX_IE_VARIABLE, IAX_IE_VERSION, IAX_MAX_OSPBLOCK_NUM, IAX_RATE_8KHZ, iax_ies::iax_unknown, iax_ies::language, len(), ast_sockaddr::len, iax_ies::md5_result, iax_ies::msgcount, iax_ies::musiconhold, ast_variable::name, ast_variable::next, ntohll(), NULL, iax_ies::ospblocklength, iax_ies::osptokenblock, outputf, iax_ies::password, iax_ies::provver, iax_ies::provverpres, iax_ies::rdnis, iax_ies::refresh, iax_ies::rr_delay, iax_ies::rr_dropped, iax_ies::rr_jitter, iax_ies::rr_loss, iax_ies::rr_ooo, iax_ies::rr_pkts, iax_ies::rsa_result, iax_ies::samprate, iax_ies::serviceident, str, tmp(), iax_ies::transferid, iax_ies::username, ast_variable::value, var, iax_ies::vars, version, and iax_ies::version.

Referenced by socket_process_helper().

◆ iax_set_error()

void iax_set_error ( void(*)(const char *data)  output)

Referenced by load_module().

◆ iax_set_output()

void iax_set_output ( void(*)(const char *data)  output)

Referenced by load_module().

◆ iax_showframe()

void iax_showframe ( struct iax_frame f,
struct ast_iax2_full_hdr fhi,
int  rx,
struct ast_sockaddr addr,
int  datalen 
)

Definition at line 595 of file parser.c.

596{
597 const char *framelist[] = {
598 "(0?)",
599 "DTMF_E ",
600 "VOICE ",
601 "VIDEO ",
602 "CONTROL",
603 "NULL ",
604 "IAX ",
605 "TEXT ",
606 "IMAGE ",
607 "HTML ",
608 "CNG ",
609 "MODEM ",
610 "DTMF_B ",
611 };
612 const char *cmds[] = {
613 "(0?)",
614 "HANGUP ",
615 "RING ",
616 "RINGING",
617 "ANSWER ",
618 "BUSY ",
619 "TKOFFHK",
620 "OFFHOOK",
621 "CONGSTN",
622 "FLASH ",
623 "WINK ",
624 "OPTION ",
625 "RDKEY ",
626 "RDUNKEY",
627 "PROGRES",
628 "PROCDNG",
629 "HOLD ",
630 "UNHOLD ",
631 "VIDUPDT",
632 "T38 ",
633 "SRCUPDT",
634 "TXFER ",
635 "CNLINE ",
636 "REDIR ",
637 "T38PARM",
638 "CC ERR!",/* This must never go across an IAX link. */
639 "SRCCHG ",
640 "READACT",
641 "AOC ",
642 "ENDOFQ ",
643 "INCOMPL",
644 "MCID ",
645 "UPDRTPP",
646 "PCAUSEC",
647 };
648 struct ast_iax2_full_hdr *fh;
649 char retries[20];
650 char class2[20];
651 char subclass2[20];
652 const char *class;
653 const char *subclass;
654 char *dir;
655 char tmp[512];
656
657 switch(rx) {
658 case 0:
659 dir = "Tx";
660 break;
661 case 2:
662 dir = "TE";
663 break;
664 case 3:
665 dir = "RD";
666 break;
667 default:
668 dir = "Rx";
669 break;
670 }
671 if (f) {
672 fh = f->data;
673 snprintf(retries, sizeof(retries), "%03d", f->retries);
674 } else {
675 fh = fhi;
676 if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
677 strcpy(retries, "Yes");
678 else
679 strcpy(retries, " No");
680 }
681 if (!(ntohs(fh->scallno) & IAX_FLAG_FULL)) {
682 /* Don't mess with mini-frames */
683 return;
684 }
685 if (fh->type >= ARRAY_LEN(framelist)) {
686 snprintf(class2, sizeof(class2), "(%d?)", fh->type);
687 class = class2;
688 } else {
689 class = framelist[(int)fh->type];
690 }
691 if (fh->type == AST_FRAME_DTMF_BEGIN || fh->type == AST_FRAME_DTMF_END) {
692 sprintf(subclass2, "%c", fh->csub);
693 subclass = subclass2;
694 } else if (fh->type == AST_FRAME_IAX) {
695 iax_frame_subclass2str((int)fh->csub, subclass2, sizeof(subclass2));
696 subclass = subclass2;
697 } else if (fh->type == AST_FRAME_CONTROL) {
698 if (fh->csub >= ARRAY_LEN(cmds)) {
699 snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
700 subclass = subclass2;
701 } else {
702 subclass = cmds[(int)fh->csub];
703 }
704 } else {
705 snprintf(subclass2, sizeof(subclass2), "%d", fh->csub);
706 subclass = subclass2;
707 }
708
709 snprintf(tmp, sizeof(tmp),
710 "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
711 dir,
712 retries, fh->oseqno, fh->iseqno, class, subclass);
713 outputf(tmp);
714 snprintf(tmp, sizeof(tmp), " Timestamp: %05lums SCall: %5.5d DCall: %5.5d %s\n",
715 (unsigned long)ntohl(fh->ts),
716 ntohs(fh->scallno) & ~IAX_FLAG_FULL,
717 ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
719
720 outputf(tmp);
721 if (fh->type == AST_FRAME_IAX)
722 dump_ies(fh->iedata, datalen);
723
724}
static const char type[]
Definition: chan_ooh323.c:109
#define IAX_FLAG_FULL
Definition: iax2.h:40
#define IAX_FLAG_RETRANS
Definition: iax2.h:42
@ AST_FRAME_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_CONTROL
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:256
void iax_frame_subclass2str(enum iax_frame_subclass subclass, char *str, size_t len)
Definition: parser.c:463
static void dump_ies(unsigned char *iedata, int len)
Definition: parser.c:416
unsigned char iedata[0]
Definition: iax2.h:238
unsigned short dcallno
Definition: iax2.h:232
unsigned short scallno
Definition: iax2.h:231
unsigned int ts
Definition: iax2.h:233
unsigned char iseqno
Definition: iax2.h:235
unsigned char csub
Definition: iax2.h:237
unsigned char oseqno
Definition: iax2.h:234
unsigned char type
Definition: iax2.h:236
void * data
Definition: parser.h:104
int retries
Definition: parser.h:108

References ARRAY_LEN, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_IAX, ast_sockaddr_stringify(), ast_iax2_full_hdr::csub, iax_frame::data, ast_iax2_full_hdr::dcallno, dump_ies(), IAX_FLAG_FULL, IAX_FLAG_RETRANS, iax_frame_subclass2str(), ast_iax2_full_hdr::iedata, ast_iax2_full_hdr::iseqno, ast_iax2_full_hdr::oseqno, outputf, iax_frame::retries, ast_iax2_full_hdr::scallno, tmp(), ast_iax2_full_hdr::ts, type, and ast_iax2_full_hdr::type.

Referenced by iax_outputframe().