Tue Jul 14 23:10:25 2009

Asterisk developer's documentation


iax2-parser.h File Reference

Implementation of the IAX2 protocol. More...

#include "asterisk/linkedlists.h"
#include "asterisk/aes.h"

Go to the source code of this file.

Data Structures

struct  iax_frame
struct  iax_ie_data
struct  iax_ies

Defines

#define DIRECTION_INGRESS   1
#define DIRECTION_OUTGRESS   2

Functions

void iax_frame_free (struct iax_frame *fr)
iax_frameiax_frame_new (int direction, int datalen, unsigned int cacheable)
void iax_frame_subclass2str (int 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_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.


Define Documentation

#define DIRECTION_INGRESS   1

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

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

#define DIRECTION_OUTGRESS   2

Definition at line 80 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 1058 of file iax2-parser.c.

References ast_atomic_fetchadd_int(), AST_LIST_INSERT_HEAD, ast_threadstorage_get(), iax_frame::cacheable, iax_frame::direction, DIRECTION_INGRESS, DIRECTION_OUTGRESS, errorf, frame_cache, FRAME_CACHE_MAX_SIZE, free, and iax_frames::list.

Referenced by iax2_frame_free(), and network_thread().

01059 {
01060 #if !defined(LOW_MEMORY)
01061    struct iax_frames *iax_frames;
01062 #endif
01063 
01064    /* Note: does not remove from scheduler! */
01065    if (fr->direction == DIRECTION_INGRESS)
01066       ast_atomic_fetchadd_int(&iframes, -1);
01067    else if (fr->direction == DIRECTION_OUTGRESS)
01068       ast_atomic_fetchadd_int(&oframes, -1);
01069    else {
01070       errorf("Attempt to double free frame detected\n");
01071       return;
01072    }
01073    ast_atomic_fetchadd_int(&frames, -1);
01074 
01075 #if !defined(LOW_MEMORY)
01076    if (!fr->cacheable || !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
01077       free(fr);
01078       return;
01079    }
01080 
01081    if (iax_frames->size < FRAME_CACHE_MAX_SIZE) {
01082       fr->direction = 0;
01083       AST_LIST_INSERT_HEAD(&iax_frames->list, fr, list);
01084       iax_frames->size++;
01085       return;
01086    }
01087 #endif
01088    free(fr);
01089 }

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

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

References iax_frame::afdatalen, ast_atomic_fetchadd_int(), ast_calloc, ast_calloc_cache, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_threadstorage_get(), DIRECTION_INGRESS, frame_cache, and iax_frames::list.

Referenced by iax2_send(), and iaxfrdup2().

01012 {
01013    struct iax_frame *fr = NULL;
01014 
01015 #if !defined(LOW_MEMORY)
01016    struct iax_frames *iax_frames;
01017 
01018    /* Attempt to get a frame from this thread's cache */
01019    if ((iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
01020       AST_LIST_TRAVERSE_SAFE_BEGIN(&iax_frames->list, fr, list) {
01021          if (fr->afdatalen >= datalen) {
01022             size_t afdatalen = fr->afdatalen;
01023             AST_LIST_REMOVE_CURRENT(&iax_frames->list, list);
01024             iax_frames->size--;
01025             memset(fr, 0, sizeof(*fr));
01026             fr->afdatalen = afdatalen;
01027             break;
01028          }
01029       }
01030       AST_LIST_TRAVERSE_SAFE_END
01031    }
01032    if (!fr) {
01033       if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen)))
01034          return NULL;
01035       fr->afdatalen = datalen;
01036    }
01037 #else
01038    if (!(fr = ast_calloc(1, sizeof(*fr) + datalen)))
01039       return NULL;
01040    fr->afdatalen = datalen;
01041 #endif
01042 
01043 
01044    fr->direction = direction;
01045    fr->retrans = -1;
01046    fr->cacheable = cacheable;
01047    
01048    if (fr->direction == DIRECTION_INGRESS)
01049       ast_atomic_fetchadd_int(&iframes, 1);
01050    else
01051       ast_atomic_fetchadd_int(&oframes, 1);
01052    
01053    ast_atomic_fetchadd_int(&frames, 1);
01054 
01055    return fr;
01056 }

void iax_frame_subclass2str ( int  subclass,
char *  str,
size_t  len 
)

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

References ARRAY_LEN, ast_copy_string(), and iaxs.

Referenced by ast_cli_netstats(), and iax2_show_channels().

00404 {
00405    static const size_t copylen = 8;
00406    const char *iaxs[] = {
00407       "(0?)   ",
00408       "NEW    ",
00409       "PING   ",
00410       "PONG   ",
00411       "ACK    ",
00412       "HANGUP ",
00413       "REJECT ",
00414       "ACCEPT ",
00415       "AUTHREQ",
00416       "AUTHREP",
00417       "INVAL  ",
00418       "LAGRQ  ",
00419       "LAGRP  ",
00420       "REGREQ ",
00421       "REGAUTH",
00422       "REGACK ",
00423       "REGREJ ",
00424       "REGREL ",
00425       "VNAK   ",
00426       "DPREQ  ",
00427       "DPREP  ",
00428       "DIAL   ",
00429       "TXREQ  ",
00430       "TXCNT  ",
00431       "TXACC  ",
00432       "TXREADY",
00433       "TXREL  ",
00434       "TXREJ  ",
00435       "QUELCH ",
00436       "UNQULCH",
00437       "POKE   ",
00438       "PAGE   ",
00439       "MWI    ",
00440       "UNSPRTD",
00441       "TRANSFR",
00442       "PROVISN",
00443       "FWDWNLD",
00444       "FWDATA ",
00445       "TXMEDIA"
00446    };
00447    if ((copylen > len) || !subclass || (subclass < 0)) {
00448       str[0] = '\0';
00449    } else if (subclass < ARRAY_LEN(iaxs)) {
00450       ast_copy_string(str, iaxs[subclass], len);
00451    } else {
00452       ast_copy_string(str, "Unknown", len);
00453    }
00454 }

void iax_frame_wrap ( struct iax_frame fr,
struct ast_frame f 
)

Definition at line 980 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::data, ast_frame::datalen, ast_frame::delivery, f, ast_frame::frametype, ast_frame::len, LOG_ERROR, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, ast_frame::src, and ast_frame::subclass.

Referenced by iax2_send(), iaxfrdup2(), and socket_process().

00981 {
00982    fr->af.frametype = f->frametype;
00983    fr->af.subclass = f->subclass;
00984    fr->af.mallocd = 0;           /* Our frame is static relative to the container */
00985    fr->af.datalen = f->datalen;
00986    fr->af.samples = f->samples;
00987    fr->af.offset = AST_FRIENDLY_OFFSET;
00988    fr->af.src = f->src;
00989    fr->af.delivery.tv_sec = 0;
00990    fr->af.delivery.tv_usec = 0;
00991    fr->af.data = fr->afdata;
00992    fr->af.len = f->len;
00993    if (fr->af.datalen) {
00994       size_t copy_len = fr->af.datalen;
00995       if (copy_len > fr->afdatalen) {
00996          ast_log(LOG_ERROR, "Losing frame data because destination buffer size '%d' bytes not big enough for '%d' bytes in the frame\n",
00997             (int) fr->afdatalen, (int) fr->af.datalen);
00998          copy_len = fr->afdatalen;
00999       }
01000 #if __BYTE_ORDER == __LITTLE_ENDIAN
01001       /* We need to byte-swap slinear samples from network byte order */
01002       if ((fr->af.frametype == AST_FRAME_VOICE) && (fr->af.subclass == AST_FORMAT_SLINEAR)) {
01003          /* 2 bytes / sample for SLINEAR */
01004          ast_swapcopy_samples(fr->af.data, f->data, copy_len / 2);
01005       } else
01006 #endif
01007          memcpy(fr->af.data, f->data, copy_len);
01008    }
01009 }

int iax_get_frames ( void   ) 

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

Referenced by iax2_show_stats().

01104 { return frames; }

int iax_get_iframes ( void   ) 

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

Referenced by iax2_show_stats().

01105 { return iframes; }

int iax_get_oframes ( void   ) 

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

Referenced by iax2_show_stats().

01106 { return oframes; }

const char* iax_ie2str ( int  ie  ) 

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

References ies, and name.

Referenced by iax_ie_append_raw(), and iax_parse_ies().

00295 {
00296    int x;
00297    for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
00298       if (ies[x].ie == ie)
00299          return ies[x].name;
00300    }
00301    return "Unknown IE";
00302 }

int iax_ie_append ( struct iax_ie_data ied,
unsigned char  ie 
)

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

References iax_ie_append_raw().

Referenced by iax2_call(), and iax_firmware_append().

00658 {
00659    return iax_ie_append_raw(ied, ie, NULL, 0);
00660 }

int iax_ie_append_addr ( struct iax_ie_data ied,
unsigned char  ie,
const struct sockaddr_in *  sin 
)

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

References iax_ie_append_raw().

Referenced by iax2_start_transfer(), and update_registry().

00629 {
00630    return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
00631 }

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

Definition at line 652 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().

00653 {
00654    return iax_ie_append_raw(ied, ie, &dat, 1);
00655 }

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

Definition at line 633 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().

00634 {
00635    unsigned int newval;
00636    newval = htonl(value);
00637    return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
00638 }

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

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

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

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

00614 {
00615    char tmp[256];
00616    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00617       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);
00618       errorf(tmp);
00619       return -1;
00620    }
00621    ied->buf[ied->pos++] = ie;
00622    ied->buf[ied->pos++] = datalen;
00623    memcpy(ied->buf + ied->pos, data, datalen);
00624    ied->pos += datalen;
00625    return 0;
00626 }

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

Definition at line 640 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().

00641 {
00642    unsigned short newval;
00643    newval = htons(value);
00644    return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
00645 }

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

Definition at line 647 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(), iax2_call(), iax2_do_register(), iax2_dprequest(), iax2_transfer(), iax_provision_build(), registry_authrequest(), registry_rerequest(), socket_process(), and update_registry().

00648 {
00649    return iax_ie_append_raw(ied, ie, str, strlen(str));
00650 }

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

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

References errorf, get_unaligned_uint16(), get_unaligned_uint32(), 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_CAPABILITY, 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_FWBLOCKDATA, IAX_IE_FWBLOCKDESC, IAX_IE_IAX_UNKNOWN, IAX_IE_LANGUAGE, IAX_IE_MD5_RESULT, IAX_IE_MSGCOUNT, IAX_IE_MUSICONHOLD, 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_VERSION, IAX_RATE_8KHZ, ies, len(), and outputf.

Referenced by socket_process().

00673 {
00674    /* Parse data into information elements */
00675    int len;
00676    int ie;
00677    char tmp[256];
00678    memset(ies, 0, (int)sizeof(struct iax_ies));
00679    ies->msgcount = -1;
00680    ies->firmwarever = -1;
00681    ies->calling_ton = -1;
00682    ies->calling_tns = -1;
00683    ies->calling_pres = -1;
00684    ies->samprate = IAX_RATE_8KHZ;
00685    while(datalen >= 2) {
00686       ie = data[0];
00687       len = data[1];
00688       if (len > datalen - 2) {
00689          errorf("Information element length exceeds message size\n");
00690          return -1;
00691       }
00692       switch(ie) {
00693       case IAX_IE_CALLED_NUMBER:
00694          ies->called_number = (char *)data + 2;
00695          break;
00696       case IAX_IE_CALLING_NUMBER:
00697          ies->calling_number = (char *)data + 2;
00698          break;
00699       case IAX_IE_CALLING_ANI:
00700          ies->calling_ani = (char *)data + 2;
00701          break;
00702       case IAX_IE_CALLING_NAME:
00703          ies->calling_name = (char *)data + 2;
00704          break;
00705       case IAX_IE_CALLED_CONTEXT:
00706          ies->called_context = (char *)data + 2;
00707          break;
00708       case IAX_IE_USERNAME:
00709          ies->username = (char *)data + 2;
00710          break;
00711       case IAX_IE_PASSWORD:
00712          ies->password = (char *)data + 2;
00713          break;
00714       case IAX_IE_CODEC_PREFS:
00715          ies->codec_prefs = (char *)data + 2;
00716          break;
00717       case IAX_IE_CAPABILITY:
00718          if (len != (int)sizeof(unsigned int)) {
00719             snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00720             errorf(tmp);
00721          } else
00722             ies->capability = ntohl(get_unaligned_uint32(data + 2));
00723          break;
00724       case IAX_IE_FORMAT:
00725          if (len != (int)sizeof(unsigned int)) {
00726             snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00727             errorf(tmp);
00728          } else
00729             ies->format = ntohl(get_unaligned_uint32(data + 2));
00730          break;
00731       case IAX_IE_LANGUAGE:
00732          ies->language = (char *)data + 2;
00733          break;
00734       case IAX_IE_VERSION:
00735          if (len != (int)sizeof(unsigned short)) {
00736             snprintf(tmp, (int)sizeof(tmp),  "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00737             errorf(tmp);
00738          } else
00739             ies->version = ntohs(get_unaligned_uint16(data + 2));
00740          break;
00741       case IAX_IE_ADSICPE:
00742          if (len != (int)sizeof(unsigned short)) {
00743             snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00744             errorf(tmp);
00745          } else
00746             ies->adsicpe = ntohs(get_unaligned_uint16(data + 2));
00747          break;
00748       case IAX_IE_SAMPLINGRATE:
00749          if (len != (int)sizeof(unsigned short)) {
00750             snprintf(tmp, (int)sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00751             errorf(tmp);
00752          } else
00753             ies->samprate = ntohs(get_unaligned_uint16(data + 2));
00754          break;
00755       case IAX_IE_DNID:
00756          ies->dnid = (char *)data + 2;
00757          break;
00758       case IAX_IE_RDNIS:
00759          ies->rdnis = (char *)data + 2;
00760          break;
00761       case IAX_IE_AUTHMETHODS:
00762          if (len != (int)sizeof(unsigned short))  {
00763             snprintf(tmp, (int)sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00764             errorf(tmp);
00765          } else
00766             ies->authmethods = ntohs(get_unaligned_uint16(data + 2));
00767          break;
00768       case IAX_IE_ENCRYPTION:
00769          if (len != (int)sizeof(unsigned short))  {
00770             snprintf(tmp, (int)sizeof(tmp), "Expecting encryption to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00771             errorf(tmp);
00772          } else
00773             ies->encmethods = ntohs(get_unaligned_uint16(data + 2));
00774          break;
00775       case IAX_IE_CHALLENGE:
00776          ies->challenge = (char *)data + 2;
00777          break;
00778       case IAX_IE_MD5_RESULT:
00779          ies->md5_result = (char *)data + 2;
00780          break;
00781       case IAX_IE_RSA_RESULT:
00782          ies->rsa_result = (char *)data + 2;
00783          break;
00784       case IAX_IE_APPARENT_ADDR:
00785          ies->apparent_addr = ((struct sockaddr_in *)(data + 2));
00786          break;
00787       case IAX_IE_REFRESH:
00788          if (len != (int)sizeof(unsigned short)) {
00789             snprintf(tmp, (int)sizeof(tmp),  "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00790             errorf(tmp);
00791          } else
00792             ies->refresh = ntohs(get_unaligned_uint16(data + 2));
00793          break;
00794       case IAX_IE_DPSTATUS:
00795          if (len != (int)sizeof(unsigned short)) {
00796             snprintf(tmp, (int)sizeof(tmp),  "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00797             errorf(tmp);
00798          } else
00799             ies->dpstatus = ntohs(get_unaligned_uint16(data + 2));
00800          break;
00801       case IAX_IE_CALLNO:
00802          if (len != (int)sizeof(unsigned short)) {
00803             snprintf(tmp, (int)sizeof(tmp),  "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00804             errorf(tmp);
00805          } else
00806             ies->callno = ntohs(get_unaligned_uint16(data + 2));
00807          break;
00808       case IAX_IE_CAUSE:
00809          ies->cause = (char *)data + 2;
00810          break;
00811       case IAX_IE_CAUSECODE:
00812          if (len != 1) {
00813             snprintf(tmp, (int)sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
00814             errorf(tmp);
00815          } else {
00816             ies->causecode = data[2];
00817          }
00818          break;
00819       case IAX_IE_IAX_UNKNOWN:
00820          if (len == 1)
00821             ies->iax_unknown = data[2];
00822          else {
00823             snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
00824             errorf(tmp);
00825          }
00826          break;
00827       case IAX_IE_MSGCOUNT:
00828          if (len != (int)sizeof(unsigned short)) {
00829             snprintf(tmp, (int)sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00830             errorf(tmp);
00831          } else
00832             ies->msgcount = ntohs(get_unaligned_uint16(data + 2));   
00833          break;
00834       case IAX_IE_AUTOANSWER:
00835          ies->autoanswer = 1;
00836          break;
00837       case IAX_IE_MUSICONHOLD:
00838          ies->musiconhold = 1;
00839          break;
00840       case IAX_IE_TRANSFERID:
00841          if (len != (int)sizeof(unsigned int)) {
00842             snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00843             errorf(tmp);
00844          } else
00845             ies->transferid = ntohl(get_unaligned_uint32(data + 2));
00846          break;
00847       case IAX_IE_DATETIME:
00848          if (len != (int)sizeof(unsigned int)) {
00849             snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00850             errorf(tmp);
00851          } else
00852             ies->datetime = ntohl(get_unaligned_uint32(data + 2));
00853          break;
00854       case IAX_IE_FIRMWAREVER:
00855          if (len != (int)sizeof(unsigned short)) {
00856             snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00857             errorf(tmp);
00858          } else
00859             ies->firmwarever = ntohs(get_unaligned_uint16(data + 2));   
00860          break;
00861       case IAX_IE_DEVICETYPE:
00862          ies->devicetype = (char *)data + 2;
00863          break;
00864       case IAX_IE_SERVICEIDENT:
00865          ies->serviceident = (char *)data + 2;
00866          break;
00867       case IAX_IE_FWBLOCKDESC:
00868          if (len != (int)sizeof(unsigned int)) {
00869             snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00870             errorf(tmp);
00871          } else
00872             ies->fwdesc = ntohl(get_unaligned_uint32(data + 2));
00873          break;
00874       case IAX_IE_FWBLOCKDATA:
00875          ies->fwdata = data + 2;
00876          ies->fwdatalen = len;
00877          break;
00878       case IAX_IE_ENCKEY:
00879          ies->enckey = data + 2;
00880          ies->enckeylen = len;
00881          break;
00882       case IAX_IE_PROVVER:
00883          if (len != (int)sizeof(unsigned int)) {
00884             snprintf(tmp, (int)sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00885             errorf(tmp);
00886          } else {
00887             ies->provverpres = 1;
00888             ies->provver = ntohl(get_unaligned_uint32(data + 2));
00889          }
00890          break;
00891       case IAX_IE_CALLINGPRES:
00892          if (len == 1)
00893             ies->calling_pres = data[2];
00894          else {
00895             snprintf(tmp, (int)sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
00896             errorf(tmp);
00897          }
00898          break;
00899       case IAX_IE_CALLINGTON:
00900          if (len == 1)
00901             ies->calling_ton = data[2];
00902          else {
00903             snprintf(tmp, (int)sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
00904             errorf(tmp);
00905          }
00906          break;
00907       case IAX_IE_CALLINGTNS:
00908          if (len != (int)sizeof(unsigned short)) {
00909             snprintf(tmp, (int)sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00910             errorf(tmp);
00911          } else
00912             ies->calling_tns = ntohs(get_unaligned_uint16(data + 2));   
00913          break;
00914                case IAX_IE_RR_JITTER:
00915                        if (len != (int)sizeof(unsigned int)) {
00916                                snprintf(tmp, (int)sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00917                                errorf(tmp);
00918                        } else {
00919                                ies->rr_jitter = ntohl(get_unaligned_uint32(data + 2));
00920                        }
00921                        break;
00922                case IAX_IE_RR_LOSS:
00923                        if (len != (int)sizeof(unsigned int)) {
00924                                snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00925                                errorf(tmp);
00926                        } else {
00927                                ies->rr_loss = ntohl(get_unaligned_uint32(data + 2));
00928                        }
00929                        break;
00930                case IAX_IE_RR_PKTS:
00931                        if (len != (int)sizeof(unsigned int)) {
00932                                snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00933                                errorf(tmp);
00934                        } else {
00935                                ies->rr_pkts = ntohl(get_unaligned_uint32(data + 2));
00936                        }
00937                        break;
00938                case IAX_IE_RR_DELAY:
00939                        if (len != (int)sizeof(unsigned short)) {
00940                                snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00941                         errorf(tmp);
00942                        } else {
00943                                ies->rr_delay = ntohs(get_unaligned_uint16(data + 2));
00944                        }
00945                        break;
00946       case IAX_IE_RR_DROPPED:
00947          if (len != (int)sizeof(unsigned int)) {
00948             snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00949             errorf(tmp);
00950          } else {
00951             ies->rr_dropped = ntohl(get_unaligned_uint32(data + 2));
00952          }
00953          break;
00954       case IAX_IE_RR_OOO:
00955          if (len != (int)sizeof(unsigned int)) {
00956             snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00957             errorf(tmp);
00958          } else {
00959             ies->rr_ooo = ntohl(get_unaligned_uint32(data + 2));
00960          }
00961          break;
00962       default:
00963          snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
00964          outputf(tmp);
00965       }
00966       /* Overwrite information element with 0, to null terminate previous portion */
00967       data[0] = 0;
00968       datalen -= (len + 2);
00969       data += (len + 2);
00970    }
00971    /* Null-terminate last field */
00972    *data = '\0';
00973    if (datalen) {
00974       errorf("Invalid information element contents, strange boundary\n");
00975       return -1;
00976    }
00977    return 0;
00978 }

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 456 of file iax2-parser.c.

References AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_IAX, ast_inet_ntoa(), ast_iax2_full_hdr::csub, ast_iax2_full_hdr::dcallno, dump_ies(), f, IAX_FLAG_FULL, IAX_FLAG_RETRANS, iaxs, ast_iax2_full_hdr::iedata, ast_iax2_full_hdr::iseqno, ast_iax2_full_hdr::oseqno, outputf, ast_iax2_full_hdr::scallno, ast_iax2_full_hdr::ts, and ast_iax2_full_hdr::type.

Referenced by iax2_send(), raw_hangup(), send_packet(), and socket_process().

00457 {
00458    const char *frames[] = {
00459       "(0?)",
00460       "DTMF_E ",
00461       "VOICE  ",
00462       "VIDEO  ",
00463       "CONTROL",
00464       "NULL   ",
00465       "IAX    ",
00466       "TEXT   ",
00467       "IMAGE  ",
00468       "HTML   ",
00469       "CNG    ",
00470       "MODEM  ",
00471       "DTMF_B ",
00472    };
00473    const char *iaxs[] = {
00474       "(0?)",
00475       "NEW    ",
00476       "PING   ",
00477       "PONG   ",
00478       "ACK    ",
00479       "HANGUP ",
00480       "REJECT ",
00481       "ACCEPT ",
00482       "AUTHREQ",
00483       "AUTHREP",
00484       "INVAL  ",
00485       "LAGRQ  ",
00486       "LAGRP  ",
00487       "REGREQ ",
00488       "REGAUTH",
00489       "REGACK ",
00490       "REGREJ ",
00491       "REGREL ",
00492       "VNAK   ",
00493       "DPREQ  ",
00494       "DPREP  ",
00495       "DIAL   ",
00496       "TXREQ  ",
00497       "TXCNT  ",
00498       "TXACC  ",
00499       "TXREADY",
00500       "TXREL  ",
00501       "TXREJ  ",
00502       "QUELCH ",
00503       "UNQULCH",
00504       "POKE   ",
00505       "PAGE   ",
00506       "MWI    ",
00507       "UNSPRTD",
00508       "TRANSFR",
00509       "PROVISN",
00510       "FWDWNLD",
00511       "FWDATA ",
00512       "TXMEDIA"
00513    };
00514    const char *cmds[] = {
00515       "(0?)",
00516       "HANGUP ",
00517       "RING   ",
00518       "RINGING",
00519       "ANSWER ",
00520       "BUSY   ",
00521       "TKOFFHK",
00522       "OFFHOOK",
00523       "CONGSTN",
00524       "FLASH  ",
00525       "WINK   ",
00526       "OPTION ",
00527       "RDKEY  ",
00528       "RDUNKEY",
00529       "PROGRES",
00530       "PROCDNG",
00531       "HOLD   ",
00532       "UNHOLD ",
00533       "VIDUPDT", };
00534    struct ast_iax2_full_hdr *fh;
00535    char retries[20];
00536    char class2[20];
00537    char subclass2[20];
00538    const char *class;
00539    const char *subclass;
00540    char *dir;
00541    char tmp[512];
00542 
00543    switch(rx) {
00544    case 0:
00545       dir = "Tx";
00546       break;
00547    case 2:
00548       dir = "TE";
00549       break;
00550    case 3:
00551       dir = "RD";
00552       break;
00553    default:
00554       dir = "Rx";
00555       break;
00556    }
00557    if (f) {
00558       fh = f->data;
00559       snprintf(retries, sizeof(retries), "%03d", f->retries);
00560    } else {
00561       fh = fhi;
00562       if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
00563          strcpy(retries, "Yes");
00564       else
00565          strcpy(retries, " No");
00566    }
00567    if (!(ntohs(fh->scallno) & IAX_FLAG_FULL)) {
00568       /* Don't mess with mini-frames */
00569       return;
00570    }
00571    if (fh->type >= (int)sizeof(frames)/(int)sizeof(frames[0])) {
00572       snprintf(class2, sizeof(class2), "(%d?)", fh->type);
00573       class = class2;
00574    } else {
00575       class = frames[(int)fh->type];
00576    }
00577    if (fh->type == AST_FRAME_DTMF_BEGIN || fh->type == AST_FRAME_DTMF_END) {
00578       sprintf(subclass2, "%c", fh->csub);
00579       subclass = subclass2;
00580    } else if (fh->type == AST_FRAME_IAX) {
00581       if (fh->csub >= (int)sizeof(iaxs)/(int)sizeof(iaxs[0])) {
00582          snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
00583          subclass = subclass2;
00584       } else {
00585          subclass = iaxs[(int)fh->csub];
00586       }
00587    } else if (fh->type == AST_FRAME_CONTROL) {
00588       if (fh->csub >= (int)sizeof(cmds)/(int)sizeof(cmds[0])) {
00589          snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
00590          subclass = subclass2;
00591       } else {
00592          subclass = cmds[(int)fh->csub];
00593       }
00594    } else {
00595       snprintf(subclass2, sizeof(subclass2), "%d", fh->csub);
00596       subclass = subclass2;
00597    }
00598    snprintf(tmp, sizeof(tmp), 
00599        "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
00600        dir,
00601        retries, fh->oseqno, fh->iseqno, class, subclass);
00602    outputf(tmp);
00603    snprintf(tmp, sizeof(tmp), 
00604        "   Timestamp: %05lums  SCall: %5.5d  DCall: %5.5d [%s:%d]\n",
00605        (unsigned long)ntohl(fh->ts),
00606        ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
00607        ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
00608    outputf(tmp);
00609    if (fh->type == AST_FRAME_IAX)
00610       dump_ies(fh->iedata, datalen);
00611 }


Generated on Tue Jul 14 23:10:25 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7