Thu Mar 25 10:39:31 2010

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>

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)
ast_udptlast_udptl_new (struct sched_context *sched, struct io_context *io, int callbackmode)
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)
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 978 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, get_proto(), ast_udptl_protocol::get_udptl_info, inaddrcmp(), LOG_DEBUG, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::name, ast_udptl_protocol::set_udptl_peer, and ast_channel::tech_pvt.

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

void ast_udptl_destroy ( struct ast_udptl udptl  ) 

Definition at line 878 of file udptl.c.

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

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

00879 {
00880    if (udptl->ioid)
00881       ast_io_remove(udptl->io, udptl->ioid);
00882    if (udptl->fd > -1)
00883       close(udptl->fd);
00884    free(udptl);
00885 }

int ast_udptl_fd ( struct ast_udptl udptl  ) 

Definition at line 596 of file udptl.c.

References ast_udptl::fd.

Referenced by __oh323_new(), and sip_new().

00597 {
00598    return udptl->fd;
00599 }

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

00688 {
00689    if (udptl)
00690       return udptl->error_correction_scheme;
00691    else {
00692       ast_log(LOG_WARNING, "udptl structure is null\n");
00693       return -1;
00694    }
00695 }

int ast_udptl_get_far_max_datagram ( struct ast_udptl udptl  ) 

Definition at line 727 of file udptl.c.

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

00728 {
00729    if (udptl)
00730       return udptl->far_max_datagram_size;
00731    else {
00732       ast_log(LOG_WARNING, "udptl structure is null\n");
00733       return -1;
00734    }
00735 }

int ast_udptl_get_local_max_datagram ( struct ast_udptl udptl  ) 

Definition at line 717 of file udptl.c.

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

Referenced by add_sdp(), and sip_handle_t38_reinvite().

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

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

Definition at line 859 of file udptl.c.

References ast_udptl::them.

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

00860 {
00861    memset(them, 0, sizeof(*them));
00862    them->sin_family = AF_INET;
00863    them->sin_port = udptl->them.sin_port;
00864    them->sin_addr = udptl->them.sin_addr;
00865 }

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

Definition at line 867 of file udptl.c.

References ast_udptl::us.

Referenced by add_sdp().

00868 {
00869    memcpy(us, &udptl->us, sizeof(udptl->us));
00870 }

void ast_udptl_init ( void   ) 

Definition at line 1292 of file udptl.c.

References ast_cli_register_multiple(), ast_udptl_reload(), and cli_udptl.

Referenced by main().

01293 {
01294    ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry));
01295    ast_udptl_reload();
01296 }

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 
)

Definition at line 837 of file udptl.c.

References ast_udptl_new_with_bindaddr(), io, and sched.

00838 {
00839    struct in_addr ia;
00840    memset(&ia, 0, sizeof(ia));
00841    return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
00842 }

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

Definition at line 753 of file udptl.c.

References ast_calloc, ast_io_add(), AST_IO_IN, ast_log(), ast_random(), errno, ast_udptl::flags, free, io, LOG_WARNING, sched, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, and udptlread().

Referenced by ast_udptl_new(), and sip_alloc().

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

void ast_udptl_offered_from_local ( struct ast_udptl udptl,
int  local 
)

Definition at line 679 of file udptl.c.

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

Referenced by transmit_invite().

00680 {
00681    if (udptl)
00682       udptl->udptl_offered_from_local = local;
00683    else
00684       ast_log(LOG_WARNING, "udptl structure is null\n");
00685 }

int ast_udptl_proto_register ( struct ast_udptl_protocol proto  ) 

Definition at line 948 of file udptl.c.

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

Referenced by load_module().

00949 {
00950    struct ast_udptl_protocol *cur;
00951 
00952    cur = protos;
00953    while (cur) {
00954       if (cur->type == proto->type) {
00955          ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
00956          return -1;
00957       }
00958       cur = cur->next;
00959    }
00960    proto->next = protos;
00961    protos = proto;
00962    return 0;
00963 }

void ast_udptl_proto_unregister ( struct ast_udptl_protocol proto  ) 

Definition at line 928 of file udptl.c.

References ast_udptl_protocol::next, and protos.

Referenced by unload_module().

00929 {
00930    struct ast_udptl_protocol *cur;
00931    struct ast_udptl_protocol *prev;
00932 
00933    cur = protos;
00934    prev = NULL;
00935    while (cur) {
00936       if (cur == proto) {
00937          if (prev)
00938             prev->next = proto->next;
00939          else
00940             protos = proto->next;
00941          return;
00942       }
00943       prev = cur;
00944       cur = cur->next;
00945    }
00946 }

struct ast_frame* ast_udptl_read ( struct ast_udptl udptl  ) 

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

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

void ast_udptl_reload ( void   ) 

Definition at line 1184 of file udptl.c.

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

Referenced by ast_udptl_init().

01185 {
01186    struct ast_config *cfg;
01187    const char *s;
01188 
01189    udptlstart = 4500;
01190    udptlend = 4999;
01191    udptlfectype = 0;
01192    udptlfecentries = 0;
01193    udptlfecspan = 0;
01194    udptlmaxdatagram = 0;
01195    use_even_ports = 0;
01196 
01197    if ((cfg = ast_config_load("udptl.conf"))) {
01198       if ((s = ast_variable_retrieve(cfg, "general", "udptlstart"))) {
01199          udptlstart = atoi(s);
01200          if (udptlstart < 1024) {
01201             ast_log(LOG_WARNING, "Ports under 1024 are not allowed for T.38.\n");
01202             udptlstart = 1024;
01203          }
01204          if (udptlstart > 65535) {
01205             ast_log(LOG_WARNING, "Ports over 65535 are invalid.\n");
01206             udptlstart = 65535;
01207          }
01208       }
01209       if ((s = ast_variable_retrieve(cfg, "general", "udptlend"))) {
01210          udptlend = atoi(s);
01211          if (udptlend < 1024) {
01212             ast_log(LOG_WARNING, "Ports under 1024 are not allowed for T.38.\n");
01213             udptlend = 1024;
01214          }
01215          if (udptlend > 65535) {
01216             ast_log(LOG_WARNING, "Ports over 65535 are invalid.\n");
01217             udptlend = 65535;
01218          }
01219       }
01220       if ((s = ast_variable_retrieve(cfg, "general", "udptlchecksums"))) {
01221 #ifdef SO_NO_CHECK
01222          if (ast_false(s))
01223             nochecksums = 1;
01224          else
01225             nochecksums = 0;
01226 #else
01227          if (ast_false(s))
01228             ast_log(LOG_WARNING, "Disabling UDPTL checksums is not supported on this operating system!\n");
01229 #endif
01230       }
01231       if ((s = ast_variable_retrieve(cfg, "general", "T38FaxUdpEC"))) {
01232          if (strcmp(s, "t38UDPFEC") == 0)
01233             udptlfectype = 2;
01234          else if (strcmp(s, "t38UDPRedundancy") == 0)
01235             udptlfectype = 1;
01236       }
01237       if ((s = ast_variable_retrieve(cfg, "general", "T38FaxMaxDatagram"))) {
01238          udptlmaxdatagram = atoi(s);
01239          if (udptlmaxdatagram < 100) {
01240             ast_log(LOG_WARNING, "Too small T38FaxMaxDatagram size.  Defaulting to 100.\n");
01241             udptlmaxdatagram = 100;
01242          }
01243          if (udptlmaxdatagram > LOCAL_FAX_MAX_DATAGRAM) {
01244             ast_log(LOG_WARNING, "Too large T38FaxMaxDatagram size.  Defaulting to %d.\n", LOCAL_FAX_MAX_DATAGRAM);
01245             udptlmaxdatagram = LOCAL_FAX_MAX_DATAGRAM;
01246          }
01247       }
01248       if ((s = ast_variable_retrieve(cfg, "general", "UDPTLFECentries"))) {
01249          udptlfecentries = atoi(s);
01250          if (udptlfecentries < 1) {
01251             ast_log(LOG_WARNING, "Too small UDPTLFECentries value.  Defaulting to 1.\n");
01252             udptlfecentries = 1;
01253          }
01254          if (udptlfecentries > MAX_FEC_ENTRIES) {
01255             ast_log(LOG_WARNING, "Too large UDPTLFECentries value.  Defaulting to %d.\n", MAX_FEC_ENTRIES);
01256             udptlfecentries = MAX_FEC_ENTRIES;
01257          }
01258       }
01259       if ((s = ast_variable_retrieve(cfg, "general", "UDPTLFECspan"))) {
01260          udptlfecspan = atoi(s);
01261          if (udptlfecspan < 1) {
01262             ast_log(LOG_WARNING, "Too small UDPTLFECspan value.  Defaulting to 1.\n");
01263             udptlfecspan = 1;
01264          }
01265          if (udptlfecspan > MAX_FEC_SPAN) {
01266             ast_log(LOG_WARNING, "Too large UDPTLFECspan value.  Defaulting to %d.\n", MAX_FEC_SPAN);
01267             udptlfecspan = MAX_FEC_SPAN;
01268          }
01269       }
01270       if ((s = ast_variable_retrieve(cfg, "general", "use_even_ports"))) {
01271          use_even_ports = ast_true(s);
01272       }
01273       ast_config_destroy(cfg);
01274    }
01275    if (udptlstart >= udptlend) {
01276       ast_log(LOG_WARNING, "Unreasonable values for UDPTL start/end\n");
01277       udptlstart = 4500;
01278       udptlend = 4999;
01279    }
01280    if (use_even_ports && (udptlstart & 1)) {
01281       ++udptlstart;
01282       ast_log(LOG_NOTICE, "Odd numbered udptlstart specified but use_even_ports enabled. udptlstart is now %d\n", udptlstart);
01283    }
01284    if (use_even_ports && (udptlend & 1)) {
01285       --udptlend;
01286       ast_log(LOG_NOTICE, "Odd numbered udptlend specified but use_event_ports enabled. udptlend is now %d\n", udptlend);
01287    }
01288    if (option_verbose > 1)
01289       ast_verbose(VERBOSE_PREFIX_2 "UDPTL allocating from port range %d -> %d\n", udptlstart, udptlend);
01290 }

void ast_udptl_reset ( struct ast_udptl udptl  ) 

void ast_udptl_set_callback ( struct ast_udptl udptl,
ast_udptl_callback  callback 
)

Definition at line 606 of file udptl.c.

References ast_udptl::callback.

00607 {
00608    udptl->callback = callback;
00609 }

void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 601 of file udptl.c.

References ast_udptl::data.

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

void ast_udptl_set_error_correction_scheme ( struct ast_udptl udptl,
int  ec 
)

Definition at line 697 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_a_image(), and sip_handle_t38_reinvite().

00698 {
00699    if (udptl) {
00700       switch (ec) {
00701       case UDPTL_ERROR_CORRECTION_FEC:
00702          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC;
00703          break;
00704       case UDPTL_ERROR_CORRECTION_REDUNDANCY:
00705          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY;
00706          break;
00707       case UDPTL_ERROR_CORRECTION_NONE:
00708          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_NONE;
00709          break;
00710       default:
00711          ast_log(LOG_WARNING, "error correction parameter invalid\n");
00712       };
00713    } else
00714       ast_log(LOG_WARNING, "udptl structure is null\n");
00715 }

void ast_udptl_set_far_max_datagram ( struct ast_udptl udptl,
int  max_datagram 
)

Definition at line 745 of file udptl.c.

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

Referenced by process_sdp_a_image(), and sip_handle_t38_reinvite().

00746 {
00747    if (udptl)
00748       udptl->far_max_datagram_size = max_datagram;
00749    else
00750       ast_log(LOG_WARNING, "udptl structure is null\n");
00751 }

void ast_udptl_set_local_max_datagram ( struct ast_udptl udptl,
int  max_datagram 
)

Definition at line 737 of file udptl.c.

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

Referenced by process_sdp_a_image(), and sip_handle_t38_reinvite().

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

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 853 of file udptl.c.

References ast_udptl::them.

Referenced by process_sdp().

00854 {
00855    udptl->them.sin_port = them->sin_port;
00856    udptl->them.sin_addr = them->sin_addr;
00857 }

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 611 of file udptl.c.

References ast_udptl::nat.

Referenced by do_setnat().

00612 {
00613    udptl->nat = nat;
00614 }

int ast_udptl_settos ( struct ast_udptl udptl,
int  tos 
)

Definition at line 844 of file udptl.c.

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

Referenced by sip_alloc().

00845 {
00846    int res;
00847 
00848    if ((res = setsockopt(udptl->fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 
00849       ast_log(LOG_WARNING, "UDPTL unable to set TOS to %d\n", tos);
00850    return res;
00851 }

void ast_udptl_stop ( struct ast_udptl udptl  ) 

Definition at line 872 of file udptl.c.

References ast_udptl::them.

Referenced by process_sdp(), and stop_media_flows().

00873 {
00874    memset(&udptl->them.sin_addr, 0, sizeof(udptl->them.sin_addr));
00875    memset(&udptl->them.sin_port, 0, sizeof(udptl->them.sin_port));
00876 }

int ast_udptl_write ( struct ast_udptl udptl,
struct ast_frame f 
)

Definition at line 887 of file udptl.c.

References AST_FRAME_MODEM, ast_inet_ntoa(), ast_log(), ast_verbose(), errno, f, len(), LOCAL_FAX_MAX_DATAGRAM, LOG_NOTICE, LOG_WARNING, s, seq, udptl_build_packet(), and udptl_debug_test_addr().

Referenced by sip_write().

00888 {
00889    int seq;
00890    int len;
00891    int res;
00892    uint8_t buf[LOCAL_FAX_MAX_DATAGRAM * 2];
00893 
00894    /* If we have no peer, return immediately */ 
00895    if (s->them.sin_addr.s_addr == INADDR_ANY)
00896       return 0;
00897 
00898    /* If there is no data length, return immediately */
00899    if (f->datalen == 0)
00900       return 0;
00901    
00902    if (f->frametype != AST_FRAME_MODEM) {
00903       ast_log(LOG_WARNING, "UDPTL can only send T.38 data\n");
00904       return -1;
00905    }
00906 
00907    /* Save seq_no for debug output because udptl_build_packet increments it */
00908    seq = s->tx_seq_no & 0xFFFF;
00909 
00910    /* Cook up the UDPTL packet, with the relevant EC info. */
00911    len = udptl_build_packet(s, buf, sizeof(buf), f->data, f->datalen);
00912 
00913    if (len > 0 && s->them.sin_port && s->them.sin_addr.s_addr) {
00914       if ((res = sendto(s->fd, buf, len, 0, (struct sockaddr *) &s->them, sizeof(s->them))) < 0)
00915          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));
00916 #if 0
00917       printf("Sent %d bytes of UDPTL data to %s:%d\n", res, ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
00918 #endif
00919       if (udptl_debug_test_addr(&s->them))
00920          ast_verbose("Sent UDPTL packet to %s:%d (type %d, seq %d, len %d)\n",
00921                ast_inet_ntoa(s->them.sin_addr),
00922                ntohs(s->them.sin_port), 0, seq, len);
00923    }
00924       
00925    return 0;
00926 }


Generated on Thu Mar 25 10:39:31 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7