Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


iax2-parser.h File Reference

Implementation of the IAX2 protocol. More...

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 sockaddr_in *sin)
 
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 sockaddr_in *sin, int datalen)
 

Detailed Description

Implementation of the IAX2 protocol.

Definition in file iax2-parser.h.

Macro Definition Documentation

#define DIRECTION_INGRESS   1

Definition at line 85 of file iax2-parser.h.

Referenced by iax_frame_free(), iax_frame_new(), and iaxfrdup2().

#define DIRECTION_OUTGRESS   2

Definition at line 86 of file iax2-parser.h.

Referenced by iax2_send(), iax_frame_free(), and send_trunk().

Function Documentation

void iax_frame_free ( struct iax_frame fr)

Definition at line 1241 of file iax2-parser.c.

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

Referenced by iax2_frame_free(), and transmit_frame().

1242 {
1243 #if !defined(LOW_MEMORY)
1244  struct iax_frames *iax_frames = NULL;
1245 #endif
1246 
1247  /* Note: does not remove from scheduler! */
1248  if (fr->direction == DIRECTION_INGRESS)
1250  else if (fr->direction == DIRECTION_OUTGRESS)
1252  else {
1253  errorf("Attempt to double free frame detected\n");
1254  return;
1255  }
1257 
1258 #if !defined(LOW_MEMORY)
1259  if (!fr->cacheable || !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
1260  ast_free(fr);
1261  return;
1262  }
1263 
1264  if (iax_frames->size < FRAME_CACHE_MAX_SIZE) {
1265  fr->direction = 0;
1266  /* Pseudo-sort: keep smaller frames at the top of the list. This should
1267  * increase the chance that we pick the smallest applicable frame for use. */
1268  if (AST_LIST_FIRST(&iax_frames->list) && AST_LIST_FIRST(&iax_frames->list)->afdatalen < fr->afdatalen) {
1269  AST_LIST_INSERT_TAIL(&iax_frames->list, fr, list);
1270  } else {
1271  AST_LIST_INSERT_HEAD(&iax_frames->list, fr, list);
1272  }
1273  iax_frames->size++;
1274  return;
1275  }
1276 #endif
1277  ast_free(fr);
1278 }
#define DIRECTION_INGRESS
Definition: iax2-parser.h:85
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define DIRECTION_OUTGRESS
Definition: iax2-parser.h:86
size_t afdatalen
Definition: iax2-parser.h:141
static void(* errorf)(const char *str)
Definition: iax2-parser.c:82
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...
Definition: lock.h:603
static int frames
Definition: iax2-parser.c:49
unsigned int cacheable
Definition: iax2-parser.h:121
static int iframes
Definition: iax2-parser.c:50
size_t size
Definition: iax2-parser.c:65
#define FRAME_CACHE_MAX_SIZE
Definition: iax2-parser.c:68
unsigned int direction
Definition: iax2-parser.h:119
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:696
#define ast_free(a)
Definition: astmm.h:97
static int oframes
Definition: iax2-parser.c:51
struct iax_frame_list list
Definition: iax2-parser.c:64
static struct ast_threadstorage frame_cache
Definition: iax2-parser.c:57
struct iax_frame* iax_frame_new ( int  direction,
int  datalen,
unsigned int  cacheable 
)

Definition at line 1183 of file iax2-parser.c.

References iax_frame::afdatalen, ast_atomic_fetchadd_int(), ast_calloc, ast_calloc_cache, AST_LIST_FIRST, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_realloc, ast_threadstorage_get(), iax_frame::cacheable, iax_frame::datalen, iax_frame::direction, DIRECTION_INGRESS, frame_cache, FRAME_CACHE_MAX_SIZE, iax_frames::list, iax_frame::list, iax_frame::retrans, and iax_frames::size.

Referenced by iax2_send(), and iaxfrdup2().

1184 {
1185  struct iax_frame *fr = NULL;
1186 
1187 #if !defined(LOW_MEMORY)
1188  struct iax_frames *iax_frames = NULL;
1189  struct iax_frame *smallest = NULL;
1190 
1191  /* Attempt to get a frame from this thread's cache */
1192  if ((iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
1193  smallest = AST_LIST_FIRST(&iax_frames->list);
1194  AST_LIST_TRAVERSE_SAFE_BEGIN(&iax_frames->list, fr, list) {
1195  if (fr->afdatalen >= datalen) {
1196  size_t afdatalen = fr->afdatalen;
1198  iax_frames->size--;
1199  memset(fr, 0, sizeof(*fr));
1200  fr->afdatalen = afdatalen;
1201  break;
1202  } else if (smallest->afdatalen > fr->afdatalen) {
1203  smallest = fr;
1204  }
1205  }
1207  }
1208  if (!fr) {
1209  if (iax_frames && iax_frames->size >= FRAME_CACHE_MAX_SIZE && smallest) {
1210  /* Make useless cache into something more useful */
1211  AST_LIST_REMOVE(&iax_frames->list, smallest, list);
1212  if (!(fr = ast_realloc(smallest, sizeof(*fr) + datalen))) {
1213  AST_LIST_INSERT_TAIL(&iax_frames->list, smallest, list);
1214  return NULL;
1215  }
1216  } else if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen)))
1217  return NULL;
1218  fr->afdatalen = datalen;
1219  }
1220 #else
1221  if (!(fr = ast_calloc(1, sizeof(*fr) + datalen)))
1222  return NULL;
1223  fr->afdatalen = datalen;
1224 #endif
1225 
1226 
1227  fr->direction = direction;
1228  fr->retrans = -1;
1229  fr->cacheable = cacheable;
1230 
1231  if (fr->direction == DIRECTION_INGRESS)
1233  else
1235 
1237 
1238  return fr;
1239 }
#define DIRECTION_INGRESS
Definition: iax2-parser.h:85
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
size_t afdatalen
Definition: iax2-parser.h:141
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:841
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
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...
Definition: lock.h:603
static int frames
Definition: iax2-parser.c:49
unsigned int cacheable
Definition: iax2-parser.h:121
static int iframes
Definition: iax2-parser.c:50
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
size_t size
Definition: iax2-parser.c:65
#define FRAME_CACHE_MAX_SIZE
Definition: iax2-parser.c:68
unsigned int direction
Definition: iax2-parser.h:119
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
#define ast_calloc(a, b)
Definition: astmm.h:82
#define ast_realloc(a, b)
Definition: astmm.h:103
struct iax_frame::@116 list
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
static int oframes
Definition: iax2-parser.c:51
struct iax_frame_list list
Definition: iax2-parser.c:64
static struct ast_threadstorage frame_cache
Definition: iax2-parser.c:57
#define ast_calloc_cache(a, b)
Definition: astmm.h:85
void iax_frame_subclass2str ( enum iax_frame_subclass  subclass,
char *  str,
size_t  len 
)

Definition at line 435 of file iax2-parser.c.

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, and IAX_COMMAND_VNAK.

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

436 {
437  const char *cmd = "Unknown";
438 
439  /* if an error occurs here during compile, that means a new iax frame subclass
440  * has been added to the iax_frame_subclass enum. Add the new subclass to the
441  * switch case and make sure to update it with a new string representation. */
442  switch (subclass) {
443  case IAX_COMMAND_NEW:
444  cmd = "NEW ";
445  break;
446  case IAX_COMMAND_PING:
447  cmd = "PING ";
448  break;
449  case IAX_COMMAND_PONG:
450  cmd = "PONG ";
451  break;
452  case IAX_COMMAND_ACK:
453  cmd = "ACK ";
454  break;
455  case IAX_COMMAND_HANGUP:
456  cmd = "HANGUP ";
457  break;
458  case IAX_COMMAND_REJECT:
459  cmd = "REJECT ";
460  break;
461  case IAX_COMMAND_ACCEPT:
462  cmd = "ACCEPT ";
463  break;
464  case IAX_COMMAND_AUTHREQ:
465  cmd = "AUTHREQ";
466  break;
467  case IAX_COMMAND_AUTHREP:
468  cmd = "AUTHREP";
469  break;
470  case IAX_COMMAND_INVAL:
471  cmd = "INVAL ";
472  break;
473  case IAX_COMMAND_LAGRQ:
474  cmd = "LAGRQ ";
475  break;
476  case IAX_COMMAND_LAGRP:
477  cmd = "LAGRP ";
478  break;
479  case IAX_COMMAND_REGREQ:
480  cmd = "REGREQ ";
481  break;
482  case IAX_COMMAND_REGAUTH:
483  cmd = "REGAUTH";
484  break;
485  case IAX_COMMAND_REGACK:
486  cmd = "REGACK ";
487  break;
488  case IAX_COMMAND_REGREJ:
489  cmd = "REGREJ ";
490  break;
491  case IAX_COMMAND_REGREL:
492  cmd = "REGREL ";
493  break;
494  case IAX_COMMAND_VNAK:
495  cmd = "VNAK ";
496  break;
497  case IAX_COMMAND_DPREQ:
498  cmd = "DPREQ ";
499  break;
500  case IAX_COMMAND_DPREP:
501  cmd = "DPREP ";
502  break;
503  case IAX_COMMAND_DIAL:
504  cmd = "DIAL ";
505  break;
506  case IAX_COMMAND_TXREQ:
507  cmd = "TXREQ ";
508  break;
509  case IAX_COMMAND_TXCNT:
510  cmd = "TXCNT ";
511  break;
512  case IAX_COMMAND_TXACC:
513  cmd = "TXACC ";
514  break;
515  case IAX_COMMAND_TXREADY:
516  cmd = "TXREADY";
517  break;
518  case IAX_COMMAND_TXREL:
519  cmd = "TXREL ";
520  break;
521  case IAX_COMMAND_TXREJ:
522  cmd = "TXREJ ";
523  break;
524  case IAX_COMMAND_QUELCH:
525  cmd = "QUELCH ";
526  break;
528  cmd = "UNQULCH";
529  break;
530  case IAX_COMMAND_POKE:
531  cmd = "POKE ";
532  break;
533  case IAX_COMMAND_PAGE:
534  cmd = "PAGE ";
535  break;
536  case IAX_COMMAND_MWI:
537  cmd = "MWI ";
538  break;
540  cmd = "UNSPRTD";
541  break;
543  cmd = "TRANSFR";
544  break;
546  cmd = "PROVISN";
547  break;
548  case IAX_COMMAND_FWDOWNL:
549  cmd = "FWDWNLD";
550  break;
551  case IAX_COMMAND_FWDATA:
552  cmd = "FWDATA ";
553  break;
554  case IAX_COMMAND_TXMEDIA:
555  cmd = "TXMEDIA";
556  break;
557  case IAX_COMMAND_RTKEY:
558  cmd = "RTKEY ";
559  break;
561  cmd = "CTOKEN ";
562  break;
563  }
564  ast_copy_string(str, cmd, len);
565 }
const char * str
Definition: app_jack.c:144
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
void iax_frame_wrap ( struct iax_frame fr,
struct ast_frame f 
)

Definition at line 1152 of file iax2-parser.c.

References iax_frame::af, iax_frame::afdata, iax_frame::afdatalen, AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_swapcopy_samples(), ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, ast_frame::delivery, ast_frame::frametype, 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(), and socket_process_meta().

1153 {
1154  fr->af.frametype = f->frametype;
1155  fr->af.subclass.codec = f->subclass.codec;
1156  fr->af.mallocd = 0; /* Our frame is static relative to the container */
1157  fr->af.datalen = f->datalen;
1158  fr->af.samples = f->samples;
1160  fr->af.src = f->src;
1161  fr->af.delivery.tv_sec = 0;
1162  fr->af.delivery.tv_usec = 0;
1163  fr->af.data.ptr = fr->afdata;
1164  fr->af.len = f->len;
1165  if (fr->af.datalen) {
1166  size_t copy_len = fr->af.datalen;
1167  if (copy_len > fr->afdatalen) {
1168  ast_log(LOG_ERROR, "Losing frame data because destination buffer size '%d' bytes not big enough for '%d' bytes in the frame\n",
1169  (int) fr->afdatalen, (int) fr->af.datalen);
1170  copy_len = fr->afdatalen;
1171  }
1172 #if __BYTE_ORDER == __LITTLE_ENDIAN
1173  /* We need to byte-swap slinear samples from network byte order */
1174  if ((fr->af.frametype == AST_FRAME_VOICE) && (fr->af.subclass.codec == AST_FORMAT_SLINEAR)) {
1175  /* 2 bytes / sample for SLINEAR */
1176  ast_swapcopy_samples(fr->af.data.ptr, f->data.ptr, copy_len / 2);
1177  } else
1178 #endif
1179  memcpy(fr->af.data.ptr, f->data.ptr, copy_len);
1180  }
1181 }
union ast_frame_subclass subclass
Definition: frame.h:146
struct ast_frame af
Definition: iax2-parser.h:139
int offset
Definition: frame.h:156
size_t afdatalen
Definition: iax2-parser.h:141
void * ptr
Definition: frame.h:160
unsigned char afdata[0]
Definition: iax2-parser.h:143
format_t codec
Definition: frame.h:137
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
Definition: frame.h:204
const char * src
Definition: frame.h:158
int datalen
Definition: frame.h:148
#define LOG_ERROR
Definition: logger.h:155
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...
Definition: logger.c:1207
struct timeval delivery
Definition: frame.h:162
int mallocd
Definition: frame.h:152
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
enum ast_frame_type frametype
Definition: frame.h:144
void ast_swapcopy_samples(void *dst, const void *src, int samples)
Definition: frame.c:556
union ast_frame::@172 data
long len
Definition: frame.h:170
int samples
Definition: frame.h:150
int iax_get_frames ( void  )

Definition at line 1293 of file iax2-parser.c.

References frames.

Referenced by handle_cli_iax2_show_stats().

1293 { return frames; }
static int frames
Definition: iax2-parser.c:49
int iax_get_iframes ( void  )

Definition at line 1294 of file iax2-parser.c.

References iframes.

Referenced by handle_cli_iax2_show_stats().

1294 { return iframes; }
static int iframes
Definition: iax2-parser.c:50
int iax_get_oframes ( void  )

Definition at line 1295 of file iax2-parser.c.

References oframes.

Referenced by handle_cli_iax2_show_stats().

1295 { return oframes; }
static int oframes
Definition: iax2-parser.c:51
const char* iax_ie2str ( int  ie)

Definition at line 325 of file iax2-parser.c.

References ARRAY_LEN, and iax2_ie::name.

Referenced by iax_ie_append_raw(), and iax_parse_ies().

326 {
327  int x;
328  for (x = 0; x < ARRAY_LEN(infoelts); x++) {
329  if (infoelts[x].ie == ie)
330  return infoelts[x].name;
331  }
332  return "Unknown IE";
333 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct iax2_ie infoelts[]
Definition: iax2-parser.c:247
char * name
Definition: iax2-parser.c:244
int iax_ie_append ( struct iax_ie_data ied,
unsigned char  ie 
)

Definition at line 747 of file iax2-parser.c.

References iax_ie_append_raw().

Referenced by iax2_call(), and iax_firmware_append().

748 {
749  return iax_ie_append_raw(ied, ie, NULL, 0);
750 }
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: iax2-parser.c:693
int iax_ie_append_addr ( struct iax_ie_data ied,
unsigned char  ie,
const struct sockaddr_in *  sin 
)

Definition at line 708 of file iax2-parser.c.

References iax_ie_append_raw().

Referenced by iax2_start_transfer(), and update_registry().

709 {
710  return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
711 }
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: iax2-parser.c:693
int iax_ie_append_byte ( struct iax_ie_data ied,
unsigned char  ie,
unsigned char  dat 
)

Definition at line 742 of file iax2-parser.c.

References iax_ie_append_raw().

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

743 {
744  return iax_ie_append_raw(ied, ie, &dat, 1);
745 }
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: iax2-parser.c:693
int iax_ie_append_int ( struct iax_ie_data ied,
unsigned char  ie,
unsigned int  value 
)

Definition at line 723 of file iax2-parser.c.

References iax_ie_append_raw().

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

724 {
725  unsigned int newval;
726  newval = htonl(value);
727  return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
728 }
int value
Definition: syslog.c:39
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: iax2-parser.c:693
int iax_ie_append_raw ( struct iax_ie_data ied,
unsigned char  ie,
const void *  data,
int  datalen 
)

Definition at line 693 of file iax2-parser.c.

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

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().

694 {
695  char tmp[256];
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);
698  errorf(tmp);
699  return -1;
700  }
701  ied->buf[ied->pos++] = ie;
702  ied->buf[ied->pos++] = datalen;
703  memcpy(ied->buf + ied->pos, data, datalen);
704  ied->pos += datalen;
705  return 0;
706 }
static void(* errorf)(const char *str)
Definition: iax2-parser.c:82
void * data
Definition: iax2-parser.h:101
unsigned char buf[1024]
Definition: iax2-parser.h:147
const char * iax_ie2str(int ie)
Definition: iax2-parser.c:325
int iax_ie_append_short ( struct iax_ie_data ied,
unsigned char  ie,
unsigned short  value 
)

Definition at line 730 of file iax2-parser.c.

References iax_ie_append_raw().

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

731 {
732  unsigned short newval;
733  newval = htons(value);
734  return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
735 }
int value
Definition: syslog.c:39
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: iax2-parser.c:693
int iax_ie_append_str ( struct iax_ie_data ied,
unsigned char  ie,
const char *  str 
)

Definition at line 737 of file iax2-parser.c.

References iax_ie_append_raw().

Referenced by __auth_reject(), __auto_hangup(), authenticate(), authenticate_request(), cache_get_callno_locked(), dp_lookup(), handle_call_token(), iax2_call(), iax2_do_register(), iax2_dprequest(), iax2_transfer(), iax_provision_build(), registry_authrequest(), registry_rerequest(), resend_with_token(), socket_process(), and update_registry().

738 {
739  return iax_ie_append_raw(ied, ie, str, strlen(str));
740 }
const char * str
Definition: app_jack.c:144
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: iax2-parser.c:693
int iax_ie_append_versioned_uint64 ( struct iax_ie_data ied,
unsigned char  ie,
unsigned char  version,
uint64_t  value 
)

Definition at line 713 of file iax2-parser.c.

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

Referenced by iax2_call(), and socket_process().

714 {
715  struct _local {
716  unsigned char version;
717  uint64_t value;
718  } __attribute__((packed)) newval = { version, };
719  put_unaligned_uint64(&newval.value, htonll(value));
720  return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
721 }
uint32_t version
uint64_t htonll(uint64_t host64)
Definition: strcompat.c:387
int value
Definition: syslog.c:39
static void put_unaligned_uint64(void *p, uint64_t datum)
Definition: unaligned.h:51
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: iax2-parser.c:693
int iax_parse_ies ( struct iax_ies ies,
unsigned char *  data,
int  datalen 
)

Definition at line 762 of file iax2-parser.c.

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_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_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(), iax_ies::md5_result, iax_ies::msgcount, iax_ies::musiconhold, ast_variable::name, ast_variable::next, ntohll(), 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, iax_ies::transferid, iax_ies::username, ast_variable::value, var, iax_ies::vars, iax_ies::version, and version.

Referenced by socket_process().

763 {
764  /* Parse data into information elements */
765  int len;
766  int ie;
767  char tmp[256], *tmp2;
768  struct ast_variable *var, *var2, *prev;
769  unsigned int count;
770  memset(ies, 0, (int)sizeof(struct iax_ies));
771  ies->msgcount = -1;
772  ies->firmwarever = -1;
773  ies->calling_ton = -1;
774  ies->calling_tns = -1;
775  ies->calling_pres = -1;
776  ies->samprate = IAX_RATE_8KHZ;
777  while(datalen >= 2) {
778  ie = data[0];
779  len = data[1];
780  if (len > datalen - 2) {
781  errorf("Information element length exceeds message size\n");
782  return -1;
783  }
784  switch(ie) {
786  ies->called_number = (char *)data + 2;
787  break;
789  ies->calling_number = (char *)data + 2;
790  break;
791  case IAX_IE_CALLING_ANI:
792  ies->calling_ani = (char *)data + 2;
793  break;
794  case IAX_IE_CALLING_NAME:
795  ies->calling_name = (char *)data + 2;
796  break;
798  ies->called_context = (char *)data + 2;
799  break;
800  case IAX_IE_USERNAME:
801  ies->username = (char *)data + 2;
802  break;
803  case IAX_IE_PASSWORD:
804  ies->password = (char *)data + 2;
805  break;
806  case IAX_IE_CODEC_PREFS:
807  ies->codec_prefs = (char *)data + 2;
808  break;
809  case IAX_IE_CAPABILITY:
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);
812  errorf(tmp);
813  } else if (ies->capability == 0) { /* Don't overwrite capability2, if specified */
814  ies->capability = ntohl(get_unaligned_uint32(data + 2));
815  }
816  break;
817  case IAX_IE_CAPABILITY2:
818  {
819  int version = data[2];
820  if (version == 0) {
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);
823  errorf(tmp);
824  } else {
825  ies->capability = (format_t) ntohll(get_unaligned_uint64(data + 3));
826  }
827  } /* else unknown version */
828  }
829  break;
830  case IAX_IE_FORMAT:
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);
833  errorf(tmp);
834  } else if (ies->format == 0) { /* Don't overwrite format2, if specified */
835  ies->format = ntohl(get_unaligned_uint32(data + 2));
836  }
837  break;
838  case IAX_IE_FORMAT2:
839  {
840  int version = data[2];
841  if (version == 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);
844  errorf(tmp);
845  } else {
846  ies->format = (format_t) ntohll(get_unaligned_uint64(data + 3));
847  }
848  } /* else unknown version */
849  }
850  break;
851  case IAX_IE_LANGUAGE:
852  ies->language = (char *)data + 2;
853  break;
854  case IAX_IE_VERSION:
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);
857  errorf(tmp);
858  } else
859  ies->version = ntohs(get_unaligned_uint16(data + 2));
860  break;
861  case IAX_IE_ADSICPE:
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);
864  errorf(tmp);
865  } else
866  ies->adsicpe = ntohs(get_unaligned_uint16(data + 2));
867  break;
868  case IAX_IE_SAMPLINGRATE:
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);
871  errorf(tmp);
872  } else
873  ies->samprate = ntohs(get_unaligned_uint16(data + 2));
874  break;
875  case IAX_IE_DNID:
876  ies->dnid = (char *)data + 2;
877  break;
878  case IAX_IE_RDNIS:
879  ies->rdnis = (char *)data + 2;
880  break;
881  case IAX_IE_AUTHMETHODS:
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);
884  errorf(tmp);
885  } else
886  ies->authmethods = ntohs(get_unaligned_uint16(data + 2));
887  break;
888  case IAX_IE_ENCRYPTION:
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);
891  errorf(tmp);
892  } else
893  ies->encmethods = ntohs(get_unaligned_uint16(data + 2));
894  break;
895  case IAX_IE_CHALLENGE:
896  ies->challenge = (char *)data + 2;
897  break;
898  case IAX_IE_MD5_RESULT:
899  ies->md5_result = (char *)data + 2;
900  break;
901  case IAX_IE_RSA_RESULT:
902  ies->rsa_result = (char *)data + 2;
903  break;
905  ies->apparent_addr = ((struct sockaddr_in *)(data + 2));
906  break;
907  case IAX_IE_REFRESH:
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);
910  errorf(tmp);
911  } else
912  ies->refresh = ntohs(get_unaligned_uint16(data + 2));
913  break;
914  case IAX_IE_DPSTATUS:
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);
917  errorf(tmp);
918  } else
919  ies->dpstatus = ntohs(get_unaligned_uint16(data + 2));
920  break;
921  case IAX_IE_CALLNO:
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);
924  errorf(tmp);
925  } else
926  ies->callno = ntohs(get_unaligned_uint16(data + 2));
927  break;
928  case IAX_IE_CAUSE:
929  ies->cause = (char *)data + 2;
930  break;
931  case IAX_IE_CAUSECODE:
932  if (len != 1) {
933  snprintf(tmp, (int)sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
934  errorf(tmp);
935  } else {
936  ies->causecode = data[2];
937  }
938  break;
939  case IAX_IE_IAX_UNKNOWN:
940  if (len == 1)
941  ies->iax_unknown = data[2];
942  else {
943  snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
944  errorf(tmp);
945  }
946  break;
947  case IAX_IE_MSGCOUNT:
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);
950  errorf(tmp);
951  } else
952  ies->msgcount = ntohs(get_unaligned_uint16(data + 2));
953  break;
954  case IAX_IE_AUTOANSWER:
955  ies->autoanswer = 1;
956  break;
957  case IAX_IE_MUSICONHOLD:
958  ies->musiconhold = 1;
959  break;
960  case IAX_IE_TRANSFERID:
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);
963  errorf(tmp);
964  } else
965  ies->transferid = ntohl(get_unaligned_uint32(data + 2));
966  break;
967  case IAX_IE_DATETIME:
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);
970  errorf(tmp);
971  } else
972  ies->datetime = ntohl(get_unaligned_uint32(data + 2));
973  break;
974  case IAX_IE_FIRMWAREVER:
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);
977  errorf(tmp);
978  } else
979  ies->firmwarever = ntohs(get_unaligned_uint16(data + 2));
980  break;
981  case IAX_IE_DEVICETYPE:
982  ies->devicetype = (char *)data + 2;
983  break;
984  case IAX_IE_SERVICEIDENT:
985  ies->serviceident = (char *)data + 2;
986  break;
987  case IAX_IE_FWBLOCKDESC:
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);
990  errorf(tmp);
991  } else
992  ies->fwdesc = ntohl(get_unaligned_uint32(data + 2));
993  break;
994  case IAX_IE_FWBLOCKDATA:
995  ies->fwdata = data + 2;
996  ies->fwdatalen = len;
997  break;
998  case IAX_IE_ENCKEY:
999  ies->enckey = data + 2;
1000  ies->enckeylen = len;
1001  break;
1002  case IAX_IE_PROVVER:
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);
1005  errorf(tmp);
1006  } else {
1007  ies->provverpres = 1;
1008  ies->provver = ntohl(get_unaligned_uint32(data + 2));
1009  }
1010  break;
1011  case IAX_IE_CALLINGPRES:
1012  if (len == 1)
1013  ies->calling_pres = data[2];
1014  else {
1015  snprintf(tmp, (int)sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
1016  errorf(tmp);
1017  }
1018  break;
1019  case IAX_IE_CALLINGTON:
1020  if (len == 1)
1021  ies->calling_ton = data[2];
1022  else {
1023  snprintf(tmp, (int)sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
1024  errorf(tmp);
1025  }
1026  break;
1027  case IAX_IE_CALLINGTNS:
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);
1030  errorf(tmp);
1031  } else
1032  ies->calling_tns = ntohs(get_unaligned_uint16(data + 2));
1033  break;
1034  case IAX_IE_RR_JITTER:
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);
1037  errorf(tmp);
1038  } else {
1039  ies->rr_jitter = ntohl(get_unaligned_uint32(data + 2));
1040  }
1041  break;
1042  case IAX_IE_RR_LOSS:
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);
1045  errorf(tmp);
1046  } else {
1047  ies->rr_loss = ntohl(get_unaligned_uint32(data + 2));
1048  }
1049  break;
1050  case IAX_IE_RR_PKTS:
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);
1053  errorf(tmp);
1054  } else {
1055  ies->rr_pkts = ntohl(get_unaligned_uint32(data + 2));
1056  }
1057  break;
1058  case IAX_IE_RR_DELAY:
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);
1061  errorf(tmp);
1062  } else {
1063  ies->rr_delay = ntohs(get_unaligned_uint16(data + 2));
1064  }
1065  break;
1066  case IAX_IE_RR_DROPPED:
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);
1069  errorf(tmp);
1070  } else {
1071  ies->rr_dropped = ntohl(get_unaligned_uint32(data + 2));
1072  }
1073  break;
1074  case IAX_IE_RR_OOO:
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);
1077  errorf(tmp);
1078  } else {
1079  ies->rr_ooo = ntohl(get_unaligned_uint32(data + 2));
1080  }
1081  break;
1082  case IAX_IE_VARIABLE:
1083  ast_copy_string(tmp, (char *)data + 2, len + 1);
1084  tmp2 = strchr(tmp, '=');
1085  if (tmp2)
1086  *tmp2++ = '\0';
1087  else
1088  tmp2 = "";
1089  {
1090  struct ast_str *str = ast_str_create(16);
1091  /* Existing variable or new variable? */
1092  for (var2 = ies->vars, prev = NULL; var2; prev = var2, var2 = var2->next) {
1093  if (strcmp(tmp, var2->name) == 0) {
1094  ast_str_set(&str, 0, "%s%s", var2->value, tmp2);
1095  var = ast_variable_new(tmp, ast_str_buffer(str), var2->file);
1096  var->next = var2->next;
1097  if (prev) {
1098  prev->next = var;
1099  } else {
1100  ies->vars = var;
1101  }
1102  snprintf(tmp, sizeof(tmp), "Assigned (%p)%s to (%p)%s\n", var->name, var->name, var->value, var->value);
1103  outputf(tmp);
1104  ast_free(var2);
1105  break;
1106  }
1107  }
1108  ast_free(str);
1109  }
1110 
1111  if (!var2) {
1112  var = ast_variable_new(tmp, tmp2, "");
1113  snprintf(tmp, sizeof(tmp), "Assigned (%p)%s to (%p)%s\n", var->name, var->name, var->value, var->value);
1114  outputf(tmp);
1115  var->next = ies->vars;
1116  ies->vars = var;
1117  }
1118  break;
1119  case IAX_IE_OSPTOKEN:
1120  if ((count = data[2]) < IAX_MAX_OSPBLOCK_NUM) {
1121  ies->osptokenblock[count] = (char *)data + 2 + 1;
1122  ies->ospblocklength[count] = len - 1;
1123  } else {
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);
1125  errorf(tmp);
1126  }
1127  break;
1128  case IAX_IE_CALLTOKEN:
1129  if (len) {
1130  ies->calltokendata = (unsigned char *) data + 2;
1131  }
1132  ies->calltoken = 1;
1133  break;
1134  default:
1135  snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
1136  outputf(tmp);
1137  }
1138  /* Overwrite information element with 0, to null terminate previous portion */
1139  data[0] = 0;
1140  datalen -= (len + 2);
1141  data += (len + 2);
1142  }
1143  /* Null-terminate last field */
1144  *data = '\0';
1145  if (datalen) {
1146  errorf("Invalid information element contents, strange boundary\n");
1147  return -1;
1148  }
1149  return 0;
1150 }
unsigned int fwdesc
Definition: iax2-parser.h:64
#define IAX_IE_IAX_UNKNOWN
Definition: iax2.h:153
#define IAX_IE_CAPABILITY2
Definition: iax2.h:187
uint32_t version
int calling_tns
Definition: iax2-parser.h:31
#define IAX_IE_CALLINGTNS
Definition: iax2.h:170
char * serviceident
Definition: iax2-parser.h:62
#define IAX_IE_PROVVER
Definition: iax2.h:167
char * rsa_result
Definition: iax2-parser.h:48
char * md5_result
Definition: iax2-parser.h:47
uint64_t ntohll(uint64_t net64)
Definition: strcompat.c:361
unsigned int transferid
Definition: iax2-parser.h:59
#define IAX_IE_VARIABLE
Definition: iax2.h:183
#define IAX_IE_RR_LOSS
Definition: iax2.h:178
struct sockaddr_in * apparent_addr
Definition: iax2-parser.h:49
unsigned char * fwdata
Definition: iax2-parser.h:65
#define IAX_IE_DATETIME
Definition: iax2.h:161
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
char * username
Definition: iax2-parser.h:34
unsigned int rr_dropped
Definition: iax2-parser.h:76
int calling_ton
Definition: iax2-parser.h:30
#define IAX_IE_CALLNO
Definition: iax2.h:151
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define IAX_IE_MD5_RESULT
Definition: iax2.h:146
unsigned char * enckey
Definition: iax2-parser.h:67
static void(* errorf)(const char *str)
Definition: iax2-parser.c:82
#define var
Definition: ast_expr2f.c:606
#define IAX_IE_FIRMWAREVER
Definition: iax2.h:164
format_t capability
Definition: iax2-parser.h:36
int firmwarever
Definition: iax2-parser.h:63
#define IAX_IE_RR_DELAY
Definition: iax2.h:180
#define IAX_IE_AUTOANSWER
Definition: iax2.h:155
struct ast_str * ast_str_create(size_t init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:420
#define IAX_IE_SAMPLINGRATE
Definition: iax2.h:171
unsigned int rr_loss
Definition: iax2-parser.h:73
unsigned int datetime
Definition: iax2-parser.h:60
const char * str
Definition: app_jack.c:144
#define IAX_IE_CHALLENGE
Definition: iax2.h:145
unsigned int provver
Definition: iax2-parser.h:69
unsigned short dpstatus
Definition: iax2-parser.h:51
unsigned char fwdatalen
Definition: iax2-parser.h:66
#define IAX_IE_DPSTATUS
Definition: iax2.h:150
char * devicetype
Definition: iax2-parser.h:61
#define IAX_IE_LANGUAGE
Definition: iax2.h:140
char * calling_number
Definition: iax2-parser.h:27
format_t format
Definition: iax2-parser.h:37
#define IAX_IE_RR_JITTER
Definition: iax2.h:177
#define IAX_IE_CALLING_NUMBER
Definition: iax2.h:132
#define IAX_IE_CALLING_ANI
Definition: iax2.h:133
#define IAX_IE_DEVICETYPE
Definition: iax2.h:162
#define IAX_IE_ENCRYPTION
Definition: iax2.h:173
#define IAX_IE_ENCKEY
Definition: iax2.h:174
int msgcount
Definition: iax2-parser.h:56
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:874
char * called_context
Definition: iax2-parser.h:33
char * codec_prefs
Definition: iax2-parser.h:38
char * challenge
Definition: iax2-parser.h:46
#define IAX_MAX_OSPBLOCK_NUM
Definition: iax2.h:191
unsigned int encmethods
Definition: iax2-parser.h:45
const char * value
Definition: config.h:79
unsigned short callno
Definition: iax2-parser.h:52
int provverpres
Definition: iax2-parser.h:71
unsigned char * calltokendata
Definition: iax2-parser.h:82
#define IAX_IE_FORMAT2
Definition: iax2.h:188
unsigned char causecode
Definition: iax2-parser.h:54
#define IAX_IE_CAUSECODE
Definition: iax2.h:172
unsigned int rr_jitter
Definition: iax2-parser.h:72
#define IAX_IE_VERSION
Definition: iax2.h:141
unsigned char iax_unknown
Definition: iax2-parser.h:55
char * osptokenblock[IAX_MAX_OSPBLOCK_NUM]
Definition: iax2-parser.h:79
#define IAX_IE_SERVICEIDENT
Definition: iax2.h:163
#define IAX_IE_CALLING_NAME
Definition: iax2.h:134
const char * name
Definition: config.h:77
unsigned short adsicpe
Definition: iax2-parser.h:41
#define IAX_IE_DNID
Definition: iax2.h:143
static unsigned int get_unaligned_uint32(const void *p)
Definition: unaligned.h:38
int version
Definition: iax2-parser.h:40
static unsigned short get_unaligned_uint16(const void *p)
Definition: unaligned.h:44
#define IAX_IE_CALLTOKEN
Definition: iax2.h:185
unsigned int rr_ooo
Definition: iax2-parser.h:77
#define IAX_IE_CALLED_NUMBER
Definition: iax2.h:131
#define IAX_IE_ADSICPE
Definition: iax2.h:142
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
int64_t format_t
Definition: frame_defs.h:32
const char * file
Definition: config.h:85
int calling_pres
Definition: iax2-parser.h:32
#define IAX_IE_AUTHMETHODS
Definition: iax2.h:144
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * language
Definition: iax2-parser.h:39
#define IAX_IE_PASSWORD
Definition: iax2.h:137
char * rdnis
Definition: iax2-parser.h:43
#define IAX_IE_MSGCOUNT
Definition: iax2.h:154
#define IAX_IE_FWBLOCKDESC
Definition: iax2.h:165
char * calling_name
Definition: iax2-parser.h:29
#define IAX_IE_RR_OOO
Definition: iax2.h:182
unsigned int authmethods
Definition: iax2-parser.h:44
#define ast_free(a)
Definition: astmm.h:97
unsigned char calltoken
Definition: iax2-parser.h:81
int autoanswer
Definition: iax2-parser.h:57
#define IAX_IE_CODEC_PREFS
Definition: iax2.h:175
char * called_number
Definition: iax2-parser.h:26
#define IAX_IE_OSPTOKEN
Definition: iax2.h:184
unsigned char enckeylen
Definition: iax2-parser.h:68
unsigned short rr_delay
Definition: iax2-parser.h:75
#define IAX_IE_CALLINGTON
Definition: iax2.h:169
#define IAX_IE_REFRESH
Definition: iax2.h:149
static void(* outputf)(const char *str)
Definition: iax2-parser.c:81
struct ast_variable * vars
Definition: iax2-parser.h:78
#define IAX_IE_CALLINGPRES
Definition: iax2.h:168
#define IAX_IE_RDNIS
Definition: iax2.h:158
int musiconhold
Definition: iax2-parser.h:58
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define IAX_IE_USERNAME
Definition: iax2.h:136
#define IAX_IE_RR_DROPPED
Definition: iax2.h:181
unsigned int rr_pkts
Definition: iax2-parser.h:74
#define IAX_IE_MUSICONHOLD
Definition: iax2.h:156
#define IAX_IE_RR_PKTS
Definition: iax2.h:179
#define IAX_IE_CAUSE
Definition: iax2.h:152
#define IAX_IE_RSA_RESULT
Definition: iax2.h:147
unsigned int ospblocklength[IAX_MAX_OSPBLOCK_NUM]
Definition: iax2-parser.h:80
char * password
Definition: iax2-parser.h:35
#define IAX_IE_FWBLOCKDATA
Definition: iax2.h:166
char * calling_ani
Definition: iax2-parser.h:28
#define IAX_IE_CALLED_CONTEXT
Definition: iax2.h:135
struct ast_variable * next
Definition: config.h:82
#define IAX_IE_APPARENT_ADDR
Definition: iax2.h:148
unsigned short refresh
Definition: iax2-parser.h:50
#define IAX_IE_TRANSFERID
Definition: iax2.h:157
char * cause
Definition: iax2-parser.h:53
const char * iax_ie2str(int ie)
Definition: iax2-parser.c:325
#define IAX_IE_FORMAT
Definition: iax2.h:139
#define IAX_IE_CAPABILITY
Definition: iax2.h:138
#define IAX_RATE_8KHZ
Definition: iax2.h:208
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
Definition: config.c:278
static uint64_t get_unaligned_uint64(const void *p)
Definition: unaligned.h:32
char * dnid
Definition: iax2-parser.h:42
unsigned short samprate
Definition: iax2-parser.h:70
void iax_set_error ( void(*)(const char *data)  output)
void iax_set_output ( void(*)(const char *data)  output)
void iax_showframe ( struct iax_frame f,
struct ast_iax2_full_hdr fhi,
int  rx,
struct sockaddr_in *  sin,
int  datalen 
)

Definition at line 567 of file iax2-parser.c.

References ARRAY_LEN, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_IAX, ast_inet_ntoa(), 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, ast_iax2_full_hdr::ts, and ast_iax2_full_hdr::type.

Referenced by iax_outputframe().

568 {
569  const char *framelist[] = {
570  "(0?)",
571  "DTMF_E ",
572  "VOICE ",
573  "VIDEO ",
574  "CONTROL",
575  "NULL ",
576  "IAX ",
577  "TEXT ",
578  "IMAGE ",
579  "HTML ",
580  "CNG ",
581  "MODEM ",
582  "DTMF_B ",
583  };
584  const char *cmds[] = {
585  "(0?)",
586  "HANGUP ",
587  "RING ",
588  "RINGING",
589  "ANSWER ",
590  "BUSY ",
591  "TKOFFHK",
592  "OFFHOOK",
593  "CONGSTN",
594  "FLASH ",
595  "WINK ",
596  "OPTION ",
597  "RDKEY ",
598  "RDUNKEY",
599  "PROGRES",
600  "PROCDNG",
601  "HOLD ",
602  "UNHOLD ",
603  "VIDUPDT",
604  "T38 ",
605  "SRCUPDT",
606  "TXFER ",
607  "CNLINE ",
608  "REDIR ",
609  "T38PARM",
610  "CC ERR!",/* This must never go across an IAX link. */
611  "SRCCHG ",
612  "READACT",
613  "AOC ",
614  "ENDOFQ ",
615  "INCOMPL",
616  "UPDRTPP",
617  };
618  struct ast_iax2_full_hdr *fh;
619  char retries[20];
620  char class2[20];
621  char subclass2[20];
622  const char *class;
623  const char *subclass;
624  char *dir;
625  char tmp[512];
626 
627  switch(rx) {
628  case 0:
629  dir = "Tx";
630  break;
631  case 2:
632  dir = "TE";
633  break;
634  case 3:
635  dir = "RD";
636  break;
637  default:
638  dir = "Rx";
639  break;
640  }
641  if (f) {
642  fh = f->data;
643  snprintf(retries, sizeof(retries), "%03d", f->retries);
644  } else {
645  fh = fhi;
646  if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
647  strcpy(retries, "Yes");
648  else
649  strcpy(retries, " No");
650  }
651  if (!(ntohs(fh->scallno) & IAX_FLAG_FULL)) {
652  /* Don't mess with mini-frames */
653  return;
654  }
655  if (fh->type >= ARRAY_LEN(framelist)) {
656  snprintf(class2, sizeof(class2), "(%d?)", fh->type);
657  class = class2;
658  } else {
659  class = framelist[(int)fh->type];
660  }
661  if (fh->type == AST_FRAME_DTMF_BEGIN || fh->type == AST_FRAME_DTMF_END) {
662  sprintf(subclass2, "%c", fh->csub);
663  subclass = subclass2;
664  } else if (fh->type == AST_FRAME_IAX) {
665  iax_frame_subclass2str((int)fh->csub, subclass2, sizeof(subclass2));
666  subclass = subclass2;
667  } else if (fh->type == AST_FRAME_CONTROL) {
668  if (fh->csub >= ARRAY_LEN(cmds)) {
669  snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
670  subclass = subclass2;
671  } else {
672  subclass = cmds[(int)fh->csub];
673  }
674  } else {
675  snprintf(subclass2, sizeof(subclass2), "%d", fh->csub);
676  subclass = subclass2;
677  }
678  snprintf(tmp, sizeof(tmp),
679  "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
680  dir,
681  retries, fh->oseqno, fh->iseqno, class, subclass);
682  outputf(tmp);
683  snprintf(tmp, sizeof(tmp),
684  " Timestamp: %05lums SCall: %5.5d DCall: %5.5d [%s:%d]\n",
685  (unsigned long)ntohl(fh->ts),
686  ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
687  ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
688  outputf(tmp);
689  if (fh->type == AST_FRAME_IAX)
690  dump_ies(fh->iedata, datalen);
691 }
void iax_frame_subclass2str(enum iax_frame_subclass subclass, char *str, size_t len)
Definition: iax2-parser.c:435
unsigned char csub
Definition: iax2.h:229
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
unsigned short scallno
Definition: iax2.h:223
unsigned char oseqno
Definition: iax2.h:226
unsigned char type
Definition: iax2.h:228
unsigned short dcallno
Definition: iax2.h:224
void * data
Definition: iax2-parser.h:101
static void dump_ies(unsigned char *iedata, int len)
Definition: iax2-parser.c:388
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: utils.c:564
unsigned char iedata[0]
Definition: iax2.h:230
unsigned char iseqno
Definition: iax2.h:227
static const char type[]
Definition: chan_nbs.c:57
static void(* outputf)(const char *str)
Definition: iax2-parser.c:81
#define IAX_FLAG_FULL
Definition: iax2.h:40
#define IAX_FLAG_RETRANS
Definition: iax2.h:42
unsigned int ts
Definition: iax2.h:225