Fri Sep 11 13:45:43 2009

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 969 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.

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

void ast_udptl_destroy ( struct ast_udptl udptl  ) 

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

00870 {
00871    if (udptl->ioid)
00872       ast_io_remove(udptl->io, udptl->ioid);
00873    if (udptl->fd > -1)
00874       close(udptl->fd);
00875    free(udptl);
00876 }

int ast_udptl_fd ( struct ast_udptl udptl  ) 

Definition at line 595 of file udptl.c.

References ast_udptl::fd.

Referenced by __oh323_new(), and sip_new().

00596 {
00597    return udptl->fd;
00598 }

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

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

int ast_udptl_get_far_max_datagram ( struct ast_udptl udptl  ) 

Definition at line 726 of file udptl.c.

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

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

int ast_udptl_get_local_max_datagram ( struct ast_udptl udptl  ) 

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

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

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

Definition at line 850 of file udptl.c.

References ast_udptl::them.

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

00851 {
00852    memset(them, 0, sizeof(*them));
00853    them->sin_family = AF_INET;
00854    them->sin_port = udptl->them.sin_port;
00855    them->sin_addr = udptl->them.sin_addr;
00856 }

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

Definition at line 858 of file udptl.c.

References ast_udptl::us.

Referenced by add_sdp().

00859 {
00860    memcpy(us, &udptl->us, sizeof(udptl->us));
00861 }

void ast_udptl_init ( void   ) 

Definition at line 1271 of file udptl.c.

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

Referenced by main().

01272 {
01273    ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry));
01274    ast_udptl_reload();
01275 }

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

References ast_udptl_new_with_bindaddr(), io, and sched.

00829 {
00830    struct in_addr ia;
00831    memset(&ia, 0, sizeof(ia));
00832    return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
00833 }

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

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

void ast_udptl_offered_from_local ( struct ast_udptl udptl,
int  local 
)

Definition at line 678 of file udptl.c.

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

Referenced by transmit_invite().

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

int ast_udptl_proto_register ( struct ast_udptl_protocol proto  ) 

Definition at line 939 of file udptl.c.

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

Referenced by load_module().

00940 {
00941    struct ast_udptl_protocol *cur;
00942 
00943    cur = protos;
00944    while (cur) {
00945       if (cur->type == proto->type) {
00946          ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
00947          return -1;
00948       }
00949       cur = cur->next;
00950    }
00951    proto->next = protos;
00952    protos = proto;
00953    return 0;
00954 }

void ast_udptl_proto_unregister ( struct ast_udptl_protocol proto  ) 

Definition at line 919 of file udptl.c.

References ast_udptl_protocol::next, and protos.

Referenced by unload_module().

00920 {
00921    struct ast_udptl_protocol *cur;
00922    struct ast_udptl_protocol *prev;
00923 
00924    cur = protos;
00925    prev = NULL;
00926    while (cur) {
00927       if (cur == proto) {
00928          if (prev)
00929             prev->next = proto->next;
00930          else
00931             protos = proto->next;
00932          return;
00933       }
00934       prev = cur;
00935       cur = cur->next;
00936    }
00937 }

struct ast_frame* ast_udptl_read ( struct ast_udptl udptl  ) 

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

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

void ast_udptl_reload ( void   ) 

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

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

void ast_udptl_reset ( struct ast_udptl udptl  ) 

void ast_udptl_set_callback ( struct ast_udptl udptl,
ast_udptl_callback  callback 
)

Definition at line 605 of file udptl.c.

References ast_udptl::callback.

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

void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 600 of file udptl.c.

References ast_udptl::data.

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

void ast_udptl_set_error_correction_scheme ( struct ast_udptl udptl,
int  ec 
)

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

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

void ast_udptl_set_far_max_datagram ( struct ast_udptl udptl,
int  max_datagram 
)

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

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

void ast_udptl_set_local_max_datagram ( struct ast_udptl udptl,
int  max_datagram 
)

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

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

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

References ast_udptl::them.

Referenced by process_sdp().

00845 {
00846    udptl->them.sin_port = them->sin_port;
00847    udptl->them.sin_addr = them->sin_addr;
00848 }

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

References ast_udptl::nat.

Referenced by do_setnat().

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

int ast_udptl_settos ( struct ast_udptl udptl,
int  tos 
)

Definition at line 835 of file udptl.c.

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

Referenced by sip_alloc().

00836 {
00837    int res;
00838 
00839    if ((res = setsockopt(udptl->fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 
00840       ast_log(LOG_WARNING, "UDPTL unable to set TOS to %d\n", tos);
00841    return res;
00842 }

void ast_udptl_stop ( struct ast_udptl udptl  ) 

Definition at line 863 of file udptl.c.

References ast_udptl::them.

Referenced by process_sdp(), and stop_media_flows().

00864 {
00865    memset(&udptl->them.sin_addr, 0, sizeof(udptl->them.sin_addr));
00866    memset(&udptl->them.sin_port, 0, sizeof(udptl->them.sin_port));
00867 }

int ast_udptl_write ( struct ast_udptl udptl,
struct ast_frame f 
)

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

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


Generated on Fri Sep 11 13:45:43 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7