Sun Dec 18 20:55:55 2011

Asterisk developer's documentation


udptl.h File Reference

#include "asterisk/frame.h"
#include "asterisk/io.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include <netinet/in.h>

Include dependency graph for udptl.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_udptl_protocol

Typedefs

typedef int(* ast_udptl_callback )(struct ast_udptl *udptl, struct ast_frame *f, void *data)

Enumerations

enum  { UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_REDUNDANCY }

Functions

int ast_udptl_bridge (struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc)
void ast_udptl_destroy (struct ast_udptl *udptl)
int ast_udptl_fd (struct ast_udptl *udptl)
void ast_udptl_get_current_formats (struct ast_udptl *udptl, int *astFormats, int *nonAstFormats)
int ast_udptl_get_error_correction_scheme (struct ast_udptl *udptl)
int ast_udptl_get_far_max_datagram (struct ast_udptl *udptl)
int ast_udptl_get_local_max_datagram (struct ast_udptl *udptl)
void ast_udptl_get_peer (struct ast_udptl *udptl, struct sockaddr_in *them)
void ast_udptl_get_us (struct ast_udptl *udptl, struct sockaddr_in *us)
void ast_udptl_init (void)
int ast_udptl_lookup_code (struct ast_udptl *udptl, int isAstFormat, int code)
struct ast_udptlast_udptl_new (struct sched_context *sched, struct io_context *io, int callbackmode)
struct ast_udptlast_udptl_new_with_bindaddr (struct sched_context *sched, struct io_context *io, int callbackmode, struct in_addr in)
void ast_udptl_offered_from_local (struct ast_udptl *udptl, int local)
int ast_udptl_proto_register (struct ast_udptl_protocol *proto)
void ast_udptl_proto_unregister (struct ast_udptl_protocol *proto)
struct ast_frameast_udptl_read (struct ast_udptl *udptl)
void ast_udptl_reload (void)
void ast_udptl_reset (struct ast_udptl *udptl)
void ast_udptl_set_callback (struct ast_udptl *udptl, ast_udptl_callback callback)
void ast_udptl_set_data (struct ast_udptl *udptl, void *data)
void ast_udptl_set_error_correction_scheme (struct ast_udptl *udptl, int ec)
void ast_udptl_set_far_max_datagram (struct ast_udptl *udptl, int max_datagram)
void ast_udptl_set_local_max_datagram (struct ast_udptl *udptl, int max_datagram)
void ast_udptl_set_m_type (struct ast_udptl *udptl, int pt)
void ast_udptl_set_peer (struct ast_udptl *udptl, struct sockaddr_in *them)
void ast_udptl_set_udptlmap_type (struct ast_udptl *udptl, int pt, char *mimeType, char *mimeSubtype)
void ast_udptl_setnat (struct ast_udptl *udptl, int nat)
int ast_udptl_settos (struct ast_udptl *udptl, int tos)
void ast_udptl_stop (struct ast_udptl *udptl)
int ast_udptl_write (struct ast_udptl *udptl, struct ast_frame *f)


Typedef Documentation

typedef int(* ast_udptl_callback)(struct ast_udptl *udptl, struct ast_frame *f, void *data)

Definition at line 50 of file udptl.h.


Enumeration Type Documentation

anonymous enum

Enumerator:
UDPTL_ERROR_CORRECTION_NONE 
UDPTL_ERROR_CORRECTION_FEC 
UDPTL_ERROR_CORRECTION_REDUNDANCY 

Definition at line 28 of file udptl.h.


Function Documentation

int ast_udptl_bridge ( struct ast_channel c0,
struct ast_channel c1,
int  flags,
struct ast_frame **  fo,
struct ast_channel **  rc 
)

Definition at line 960 of file udptl.c.

References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), AST_FRAME_MODEM, ast_frfree, ast_inet_ntoa(), ast_log(), ast_read(), ast_udptl_get_peer(), ast_waitfor_n(), ast_write(), f, ast_frame::frametype, get_proto(), ast_udptl_protocol::get_udptl_info, inaddrcmp(), LOG_DEBUG, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_udptl_protocol::set_udptl_peer, and ast_channel::tech_pvt.

00961 {
00962    struct ast_frame *f;
00963    struct ast_channel *who;
00964    struct ast_channel *cs[3];
00965    struct ast_udptl *p0;
00966    struct ast_udptl *p1;
00967    struct ast_udptl_protocol *pr0;
00968    struct ast_udptl_protocol *pr1;
00969    struct sockaddr_in ac0;
00970    struct sockaddr_in ac1;
00971    struct sockaddr_in t0;
00972    struct sockaddr_in t1;
00973    void *pvt0;
00974    void *pvt1;
00975    int to;
00976    
00977    ast_channel_lock(c0);
00978    while (ast_channel_trylock(c1)) {
00979       ast_channel_unlock(c0);
00980       usleep(1);
00981       ast_channel_lock(c0);
00982    }
00983    pr0 = get_proto(c0);
00984    pr1 = get_proto(c1);
00985    if (!pr0) {
00986       ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name);
00987       ast_channel_unlock(c0);
00988       ast_channel_unlock(c1);
00989       return -1;
00990    }
00991    if (!pr1) {
00992       ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name);
00993       ast_channel_unlock(c0);
00994       ast_channel_unlock(c1);
00995       return -1;
00996    }
00997    pvt0 = c0->tech_pvt;
00998    pvt1 = c1->tech_pvt;
00999    p0 = pr0->get_udptl_info(c0);
01000    p1 = pr1->get_udptl_info(c1);
01001    if (!p0 || !p1) {
01002       /* Somebody doesn't want to play... */
01003       ast_channel_unlock(c0);
01004       ast_channel_unlock(c1);
01005       return -2;
01006    }
01007    if (pr0->set_udptl_peer(c0, p1)) {
01008       ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
01009       memset(&ac1, 0, sizeof(ac1));
01010    } else {
01011       /* Store UDPTL peer */
01012       ast_udptl_get_peer(p1, &ac1);
01013    }
01014    if (pr1->set_udptl_peer(c1, p0)) {
01015       ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name);
01016       memset(&ac0, 0, sizeof(ac0));
01017    } else {
01018       /* Store UDPTL peer */
01019       ast_udptl_get_peer(p0, &ac0);
01020    }
01021    ast_channel_unlock(c0);
01022    ast_channel_unlock(c1);
01023    cs[0] = c0;
01024    cs[1] = c1;
01025    cs[2] = NULL;
01026    for (;;) {
01027       if ((c0->tech_pvt != pvt0) ||
01028          (c1->tech_pvt != pvt1) ||
01029          (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
01030             ast_log(LOG_DEBUG, "Oooh, something is weird, backing out\n");
01031             /* Tell it to try again later */
01032             return -3;
01033       }
01034       to = -1;
01035       ast_udptl_get_peer(p1, &t1);
01036       ast_udptl_get_peer(p0, &t0);
01037       if (inaddrcmp(&t1, &ac1)) {
01038          ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d\n", 
01039             c1->name, ast_inet_ntoa(t1.sin_addr), ntohs(t1.sin_port));
01040          ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d\n", 
01041             c1->name, ast_inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port));
01042          memcpy(&ac1, &t1, sizeof(ac1));
01043       }
01044       if (inaddrcmp(&t0, &ac0)) {
01045          ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d\n", 
01046             c0->name, ast_inet_ntoa(t0.sin_addr), ntohs(t0.sin_port));
01047          ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d\n", 
01048             c0->name, ast_inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port));
01049          memcpy(&ac0, &t0, sizeof(ac0));
01050       }
01051       who = ast_waitfor_n(cs, 2, &to);
01052       if (!who) {
01053          ast_log(LOG_DEBUG, "Ooh, empty read...\n");
01054          /* check for hangup / whentohangup */
01055          if (ast_check_hangup(c0) || ast_check_hangup(c1))
01056             break;
01057          continue;
01058       }
01059       f = ast_read(who);
01060       if (!f) {
01061          *fo = f;
01062          *rc = who;
01063          ast_log(LOG_DEBUG, "Oooh, got a %s\n", f ? "digit" : "hangup");
01064          /* That's all we needed */
01065          return 0;
01066       } else {
01067          if (f->frametype == AST_FRAME_MODEM) {
01068             /* Forward T.38 frames if they happen upon us */
01069             if (who == c0) {
01070                ast_write(c1, f);
01071             } else if (who == c1) {
01072                ast_write(c0, f);
01073             }
01074          }
01075          ast_frfree(f);
01076       }
01077       /* Swap priority. Not that it's a big deal at this point */
01078       cs[2] = cs[0];
01079       cs[0] = cs[1];
01080       cs[1] = cs[2];
01081    }
01082    return -1;
01083 }

void ast_udptl_destroy ( struct ast_udptl udptl  ) 

Definition at line 860 of file udptl.c.

References ast_io_remove(), ast_udptl::fd, free, ast_udptl::io, and ast_udptl::ioid.

Referenced by __sip_destroy(), and create_addr_from_peer().

00861 {
00862    if (udptl->ioid)
00863       ast_io_remove(udptl->io, udptl->ioid);
00864    if (udptl->fd > -1)
00865       close(udptl->fd);
00866    free(udptl);
00867 }

int ast_udptl_fd ( struct ast_udptl udptl  ) 

Definition at line 586 of file udptl.c.

References ast_udptl::fd.

Referenced by __oh323_new(), and sip_new().

00587 {
00588    return udptl->fd;
00589 }

void ast_udptl_get_current_formats ( struct ast_udptl udptl,
int *  astFormats,
int *  nonAstFormats 
)

int ast_udptl_get_error_correction_scheme ( struct ast_udptl udptl  ) 

Definition at line 677 of file udptl.c.

References ast_log(), ast_udptl::error_correction_scheme, and LOG_WARNING.

Referenced by create_addr_from_peer(), sip_alloc(), and sip_handle_t38_reinvite().

00678 {
00679    if (udptl)
00680       return udptl->error_correction_scheme;
00681    else {
00682       ast_log(LOG_WARNING, "udptl structure is null\n");
00683       return -1;
00684    }
00685 }

int ast_udptl_get_far_max_datagram ( struct ast_udptl udptl  ) 

Definition at line 717 of file udptl.c.

References ast_log(), ast_udptl::far_max_datagram_size, and LOG_WARNING.

00718 {
00719    if (udptl)
00720       return udptl->far_max_datagram_size;
00721    else {
00722       ast_log(LOG_WARNING, "udptl structure is null\n");
00723       return -1;
00724    }
00725 }

int ast_udptl_get_local_max_datagram ( struct ast_udptl udptl  ) 

Definition at line 707 of file udptl.c.

References ast_log(), ast_udptl::local_max_datagram_size, and LOG_WARNING.

Referenced by add_t38_sdp(), and sip_handle_t38_reinvite().

00708 {
00709    if (udptl)
00710       return udptl->local_max_datagram_size;
00711    else {
00712       ast_log(LOG_WARNING, "udptl structure is null\n");
00713       return -1;
00714    }
00715 }

void ast_udptl_get_peer ( struct ast_udptl udptl,
struct sockaddr_in *  them 
)

Definition at line 841 of file udptl.c.

References ast_udptl::them.

Referenced by ast_udptl_bridge(), sip_handle_t38_reinvite(), and sip_set_udptl_peer().

00842 {
00843    memset(them, 0, sizeof(*them));
00844    them->sin_family = AF_INET;
00845    them->sin_port = udptl->them.sin_port;
00846    them->sin_addr = udptl->them.sin_addr;
00847 }

void ast_udptl_get_us ( struct ast_udptl udptl,
struct sockaddr_in *  us 
)

Definition at line 849 of file udptl.c.

References ast_udptl::us.

Referenced by add_t38_sdp().

00850 {
00851    memcpy(us, &udptl->us, sizeof(udptl->us));
00852 }

void ast_udptl_init ( void   ) 

Definition at line 1242 of file udptl.c.

References ast_cli_register_multiple(), and ast_udptl_reload().

Referenced by main().

01243 {
01244    ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry));
01245    ast_udptl_reload();
01246 }

int ast_udptl_lookup_code ( struct ast_udptl udptl,
int  isAstFormat,
int  code 
)

struct ast_udptl* ast_udptl_new ( struct sched_context sched,
struct io_context io,
int  callbackmode 
) [read]

Definition at line 819 of file udptl.c.

References ast_udptl_new_with_bindaddr().

00820 {
00821    struct in_addr ia;
00822    memset(&ia, 0, sizeof(ia));
00823    return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
00824 }

struct ast_udptl* ast_udptl_new_with_bindaddr ( struct sched_context sched,
struct io_context io,
int  callbackmode,
struct in_addr  in 
) [read]

Definition at line 743 of file udptl.c.

References ast_calloc, ast_io_add(), AST_IO_IN, ast_log(), ast_random(), udptl_fec_tx_buffer_t::buf_len, udptl_fec_rx_buffer_t::buf_len, errno, ast_udptl::error_correction_entries, ast_udptl::error_correction_scheme, ast_udptl::error_correction_span, ast_udptl::far_max_datagram_size, ast_udptl::fd, ast_udptl::flags, free, ast_udptl::io, ast_udptl::ioid, ast_udptl::local_max_datagram_size, LOG_WARNING, ast_udptl::rx, ast_udptl::sched, ast_udptl::them, ast_udptl::tx, UDPTL_BUF_MASK, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, udptlread(), and ast_udptl::us.

Referenced by ast_udptl_new(), and sip_alloc().

00744 {
00745    struct ast_udptl *udptl;
00746    int x;
00747    int startplace;
00748    int i;
00749    long int flags;
00750 
00751    if (!(udptl = ast_calloc(1, sizeof(*udptl))))
00752       return NULL;
00753 
00754    if (udptlfectype == 2)
00755       udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC;
00756    else if (udptlfectype == 1)
00757       udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY;
00758    else
00759       udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_NONE;
00760    udptl->error_correction_span = udptlfecspan;
00761    udptl->error_correction_entries = udptlfecentries;
00762    
00763    udptl->far_max_datagram_size = udptlmaxdatagram;
00764    udptl->local_max_datagram_size = udptlmaxdatagram;
00765 
00766    memset(&udptl->rx, 0, sizeof(udptl->rx));
00767    memset(&udptl->tx, 0, sizeof(udptl->tx));
00768    for (i = 0; i <= UDPTL_BUF_MASK; i++) {
00769       udptl->rx[i].buf_len = -1;
00770       udptl->tx[i].buf_len = -1;
00771    }
00772 
00773    udptl->them.sin_family = AF_INET;
00774    udptl->us.sin_family = AF_INET;
00775 
00776    if ((udptl->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
00777       free(udptl);
00778       ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
00779       return NULL;
00780    }
00781    flags = fcntl(udptl->fd, F_GETFL);
00782    fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK);
00783 #ifdef SO_NO_CHECK
00784    if (nochecksums)
00785       setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
00786 #endif
00787    /* Find us a place */
00788    x = (ast_random() % (udptlend - udptlstart)) + udptlstart;
00789    startplace = x;
00790    for (;;) {
00791       udptl->us.sin_port = htons(x);
00792       udptl->us.sin_addr = addr;
00793       if (bind(udptl->fd, (struct sockaddr *) &udptl->us, sizeof(udptl->us)) == 0)
00794          break;
00795       if (errno != EADDRINUSE) {
00796          ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
00797          close(udptl->fd);
00798          free(udptl);
00799          return NULL;
00800       }
00801       if (++x > udptlend)
00802          x = udptlstart;
00803       if (x == startplace) {
00804          ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
00805          close(udptl->fd);
00806          free(udptl);
00807          return NULL;
00808       }
00809    }
00810    if (io && sched && callbackmode) {
00811       /* Operate this one in a callback mode */
00812       udptl->sched = sched;
00813       udptl->io = io;
00814       udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
00815    }
00816    return udptl;
00817 }

void ast_udptl_offered_from_local ( struct ast_udptl udptl,
int  local 
)

Definition at line 669 of file udptl.c.

References ast_log(), LOG_WARNING, and ast_udptl::udptl_offered_from_local.

Referenced by transmit_invite(), transmit_reinvite_with_t38_sdp(), and transmit_response_with_t38_sdp().

00670 {
00671    if (udptl)
00672       udptl->udptl_offered_from_local = local;
00673    else
00674       ast_log(LOG_WARNING, "udptl structure is null\n");
00675 }

int ast_udptl_proto_register ( struct ast_udptl_protocol proto  ) 

Definition at line 930 of file udptl.c.

References ast_log(), LOG_WARNING, ast_udptl_protocol::next, and ast_udptl_protocol::type.

Referenced by load_module().

00931 {
00932    struct ast_udptl_protocol *cur;
00933 
00934    cur = protos;
00935    while (cur) {
00936       if (cur->type == proto->type) {
00937          ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
00938          return -1;
00939       }
00940       cur = cur->next;
00941    }
00942    proto->next = protos;
00943    protos = proto;
00944    return 0;
00945 }

void ast_udptl_proto_unregister ( struct ast_udptl_protocol proto  ) 

Definition at line 910 of file udptl.c.

References ast_udptl_protocol::next.

Referenced by unload_module().

00911 {
00912    struct ast_udptl_protocol *cur;
00913    struct ast_udptl_protocol *prev;
00914 
00915    cur = protos;
00916    prev = NULL;
00917    while (cur) {
00918       if (cur == proto) {
00919          if (prev)
00920             prev->next = proto->next;
00921          else
00922             protos = proto->next;
00923          return;
00924       }
00925       prev = cur;
00926       cur = cur->next;
00927    }
00928 }

struct ast_frame* ast_udptl_read ( struct ast_udptl udptl  )  [read]

Definition at line 618 of file udptl.c.

References ast_assert, AST_FRIENDLY_OFFSET, ast_inet_ntoa(), ast_log(), ast_null_frame, ast_verbose(), errno, ast_udptl::f, ast_udptl::fd, len, LOG_DEBUG, LOG_WARNING, ast_udptl::nat, ast_udptl::rawdata, ast_udptl::them, udptl_debug_test_addr(), and udptl_rx_packet().

Referenced by sip_rtp_read(), skinny_rtp_read(), and udptlread().

00619 {
00620    int res;
00621    struct sockaddr_in sin;
00622    socklen_t len;
00623    uint16_t seqno = 0;
00624    uint16_t *udptlheader;
00625 
00626    len = sizeof(sin);
00627    
00628    /* Cache where the header will go */
00629    res = recvfrom(udptl->fd,
00630          udptl->rawdata + AST_FRIENDLY_OFFSET,
00631          sizeof(udptl->rawdata) - AST_FRIENDLY_OFFSET,
00632          0,
00633          (struct sockaddr *) &sin,
00634          &len);
00635    udptlheader = (uint16_t *)(udptl->rawdata + AST_FRIENDLY_OFFSET);
00636    if (res < 0) {
00637       if (errno != EAGAIN)
00638          ast_log(LOG_WARNING, "UDPTL read error: %s\n", strerror(errno));
00639       ast_assert(errno != EBADF);
00640       return &ast_null_frame;
00641    }
00642 
00643    /* Ignore if the other side hasn't been given an address yet. */
00644    if (!udptl->them.sin_addr.s_addr || !udptl->them.sin_port)
00645       return &ast_null_frame;
00646 
00647    if (udptl->nat) {
00648       /* Send to whoever sent to us */
00649       if ((udptl->them.sin_addr.s_addr != sin.sin_addr.s_addr) ||
00650          (udptl->them.sin_port != sin.sin_port)) {
00651          memcpy(&udptl->them, &sin, sizeof(udptl->them));
00652          ast_log(LOG_DEBUG, "UDPTL NAT: Using address %s:%d\n", ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
00653       }
00654    }
00655 
00656    if (udptl_debug_test_addr(&sin)) {
00657       ast_verbose("Got UDPTL packet from %s:%d (type %d, seq %d, len %d)\n",
00658          ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), 0, seqno, res);
00659    }
00660 #if 0
00661    printf("Got UDPTL packet from %s:%d (seq %d, len = %d)\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), seqno, res);
00662 #endif
00663    if (udptl_rx_packet(udptl, udptl->rawdata + AST_FRIENDLY_OFFSET, res) < 1)
00664       return &ast_null_frame;
00665 
00666    return &udptl->f[0];
00667 }

void ast_udptl_reload ( void   ) 

Definition at line 1166 of file udptl.c.

References ast_config_destroy(), ast_config_load(), ast_false(), ast_log(), ast_variable_retrieve(), ast_verbose(), LOCAL_FAX_MAX_DATAGRAM, LOG_WARNING, MAX_FEC_ENTRIES, MAX_FEC_SPAN, option_verbose, s, and VERBOSE_PREFIX_2.

Referenced by ast_udptl_init().

01167 {
01168    struct ast_config *cfg;
01169    const char *s;
01170 
01171    udptlstart = 4500;
01172    udptlend = 4999;
01173    udptlfectype = 0;
01174    udptlfecentries = 0;
01175    udptlfecspan = 0;
01176    udptlmaxdatagram = 0;
01177 
01178    if ((cfg = ast_config_load("udptl.conf"))) {
01179       if ((s = ast_variable_retrieve(cfg, "general", "udptlstart"))) {
01180          udptlstart = atoi(s);
01181          if (udptlstart < 1024)
01182             udptlstart = 1024;
01183          if (udptlstart > 65535)
01184             udptlstart = 65535;
01185       }
01186       if ((s = ast_variable_retrieve(cfg, "general", "udptlend"))) {
01187          udptlend = atoi(s);
01188          if (udptlend < 1024)
01189             udptlend = 1024;
01190          if (udptlend > 65535)
01191             udptlend = 65535;
01192       }
01193       if ((s = ast_variable_retrieve(cfg, "general", "udptlchecksums"))) {
01194 #ifdef SO_NO_CHECK
01195          if (ast_false(s))
01196             nochecksums = 1;
01197          else
01198             nochecksums = 0;
01199 #else
01200          if (ast_false(s))
01201             ast_log(LOG_WARNING, "Disabling UDPTL checksums is not supported on this operating system!\n");
01202 #endif
01203       }
01204       if ((s = ast_variable_retrieve(cfg, "general", "T38FaxUdpEC"))) {
01205          if (strcmp(s, "t38UDPFEC") == 0)
01206             udptlfectype = 2;
01207          else if (strcmp(s, "t38UDPRedundancy") == 0)
01208             udptlfectype = 1;
01209       }
01210       if ((s = ast_variable_retrieve(cfg, "general", "T38FaxMaxDatagram"))) {
01211          udptlmaxdatagram = atoi(s);
01212          if (udptlmaxdatagram < 0)
01213             udptlmaxdatagram = 0;
01214          if (udptlmaxdatagram > LOCAL_FAX_MAX_DATAGRAM)
01215             udptlmaxdatagram = LOCAL_FAX_MAX_DATAGRAM;
01216       }
01217       if ((s = ast_variable_retrieve(cfg, "general", "UDPTLFECentries"))) {
01218          udptlfecentries = atoi(s);
01219          if (udptlfecentries < 0)
01220             udptlfecentries = 0;
01221          if (udptlfecentries > MAX_FEC_ENTRIES)
01222             udptlfecentries = MAX_FEC_ENTRIES;
01223       }
01224       if ((s = ast_variable_retrieve(cfg, "general", "UDPTLFECspan"))) {
01225          udptlfecspan = atoi(s);
01226          if (udptlfecspan < 0)
01227             udptlfecspan = 0;
01228          if (udptlfecspan > MAX_FEC_SPAN)
01229             udptlfecspan = MAX_FEC_SPAN;
01230       }
01231       ast_config_destroy(cfg);
01232    }
01233    if (udptlstart >= udptlend) {
01234       ast_log(LOG_WARNING, "Unreasonable values for UDPTL start/end\n");
01235       udptlstart = 4500;
01236       udptlend = 4999;
01237    }
01238    if (option_verbose > 1)
01239       ast_verbose(VERBOSE_PREFIX_2 "UDPTL allocating from port range %d -> %d\n", udptlstart, udptlend);
01240 }

void ast_udptl_reset ( struct ast_udptl udptl  ) 

void ast_udptl_set_callback ( struct ast_udptl udptl,
ast_udptl_callback  callback 
)

Definition at line 596 of file udptl.c.

References ast_udptl::callback.

00597 {
00598    udptl->callback = callback;
00599 }

void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 591 of file udptl.c.

References ast_udptl::data.

00592 {
00593    udptl->data = data;
00594 }

void ast_udptl_set_error_correction_scheme ( struct ast_udptl udptl,
int  ec 
)

Definition at line 687 of file udptl.c.

References ast_log(), ast_udptl::error_correction_scheme, LOG_WARNING, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.

Referenced by process_sdp(), and sip_handle_t38_reinvite().

00688 {
00689    if (udptl) {
00690       switch (ec) {
00691       case UDPTL_ERROR_CORRECTION_FEC:
00692          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC;
00693          break;
00694       case UDPTL_ERROR_CORRECTION_REDUNDANCY:
00695          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY;
00696          break;
00697       case UDPTL_ERROR_CORRECTION_NONE:
00698          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_NONE;
00699          break;
00700       default:
00701          ast_log(LOG_WARNING, "error correction parameter invalid\n");
00702       };
00703    } else
00704       ast_log(LOG_WARNING, "udptl structure is null\n");
00705 }

void ast_udptl_set_far_max_datagram ( struct ast_udptl udptl,
int  max_datagram 
)

Definition at line 735 of file udptl.c.

References ast_log(), ast_udptl::far_max_datagram_size, and LOG_WARNING.

Referenced by process_sdp(), and sip_handle_t38_reinvite().

00736 {
00737    if (udptl)
00738       udptl->far_max_datagram_size = max_datagram;
00739    else
00740       ast_log(LOG_WARNING, "udptl structure is null\n");
00741 }

void ast_udptl_set_local_max_datagram ( struct ast_udptl udptl,
int  max_datagram 
)

Definition at line 727 of file udptl.c.

References ast_log(), ast_udptl::local_max_datagram_size, and LOG_WARNING.

Referenced by process_sdp(), and sip_handle_t38_reinvite().

00728 {
00729    if (udptl)
00730       udptl->local_max_datagram_size = max_datagram;
00731    else
00732       ast_log(LOG_WARNING, "udptl structure is null\n");
00733 }

void ast_udptl_set_m_type ( struct ast_udptl udptl,
int  pt 
)

void ast_udptl_set_peer ( struct ast_udptl udptl,
struct sockaddr_in *  them 
)

Definition at line 835 of file udptl.c.

References ast_udptl::them.

Referenced by process_sdp().

00836 {
00837    udptl->them.sin_port = them->sin_port;
00838    udptl->them.sin_addr = them->sin_addr;
00839 }

void ast_udptl_set_udptlmap_type ( struct ast_udptl udptl,
int  pt,
char *  mimeType,
char *  mimeSubtype 
)

void ast_udptl_setnat ( struct ast_udptl udptl,
int  nat 
)

Definition at line 601 of file udptl.c.

References ast_udptl::nat.

Referenced by do_setnat().

00602 {
00603    udptl->nat = nat;
00604 }

int ast_udptl_settos ( struct ast_udptl udptl,
int  tos 
)

Definition at line 826 of file udptl.c.

References ast_log(), ast_udptl::fd, and LOG_WARNING.

Referenced by sip_alloc().

00827 {
00828    int res;
00829 
00830    if ((res = setsockopt(udptl->fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 
00831       ast_log(LOG_WARNING, "UDPTL unable to set TOS to %d\n", tos);
00832    return res;
00833 }

void ast_udptl_stop ( struct ast_udptl udptl  ) 

Definition at line 854 of file udptl.c.

References ast_udptl::them.

Referenced by process_sdp(), and stop_media_flows().

00855 {
00856    memset(&udptl->them.sin_addr, 0, sizeof(udptl->them.sin_addr));
00857    memset(&udptl->them.sin_port, 0, sizeof(udptl->them.sin_port));
00858 }

int ast_udptl_write ( struct ast_udptl udptl,
struct ast_frame f 
)

Definition at line 869 of file udptl.c.

References AST_FRAME_MODEM, ast_inet_ntoa(), ast_log(), ast_verbose(), ast_frame::data, ast_frame::datalen, errno, ast_udptl::fd, ast_frame::frametype, len, LOCAL_FAX_MAX_DATAGRAM, LOG_NOTICE, LOG_WARNING, seq, ast_udptl::them, ast_udptl::tx_seq_no, udptl_build_packet(), and udptl_debug_test_addr().

Referenced by sip_write().

00870 {
00871    int seq;
00872    int len;
00873    int res;
00874    uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
00875 
00876    /* If we have no peer, return immediately */ 
00877    if (s->them.sin_addr.s_addr == INADDR_ANY)
00878       return 0;
00879 
00880    /* If there is no data length, return immediately */
00881    if (f->datalen == 0)
00882       return 0;
00883    
00884    if (f->frametype != AST_FRAME_MODEM) {
00885       ast_log(LOG_WARNING, "UDPTL can only send T.38 data\n");
00886       return -1;
00887    }
00888 
00889    /* Save seq_no for debug output because udptl_build_packet increments it */
00890    seq = s->tx_seq_no & 0xFFFF;
00891 
00892    /* Cook up the UDPTL packet, with the relevant EC info. */
00893    len = udptl_build_packet(s, buf, f->data, f->datalen);
00894 
00895    if (len > 0 && s->them.sin_port && s->them.sin_addr.s_addr) {
00896       if ((res = sendto(s->fd, buf, len, 0, (struct sockaddr *) &s->them, sizeof(s->them))) < 0)
00897          ast_log(LOG_NOTICE, "UDPTL Transmission error to %s:%d: %s\n", ast_inet_ntoa(s->them.sin_addr), ntohs(s->them.sin_port), strerror(errno));
00898 #if 0
00899       printf("Sent %d bytes of UDPTL data to %s:%d\n", res, ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
00900 #endif
00901       if (udptl_debug_test_addr(&s->them))
00902          ast_verbose("Sent UDPTL packet to %s:%d (type %d, seq %d, len %d)\n",
00903                ast_inet_ntoa(s->them.sin_addr),
00904                ntohs(s->them.sin_port), 0, seq, len);
00905    }
00906       
00907    return 0;
00908 }


Generated on Sun Dec 18 20:55:55 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.6