Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:57 2007

Asterisk developer's documentation :: Codename Pineapple


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

References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_log(), get_proto(), ast_udptl_protocol::get_udptl_info, LOG_WARNING, ast_udptl_protocol::set_udptl_peer, and ast_channel::tech_pvt.

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

void ast_udptl_destroy struct ast_udptl udptl  ) 
 

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

00909 {
00910    if (udptl->ioid)
00911       ast_io_remove(udptl->io, udptl->ioid);
00912    if (udptl->fd > -1)
00913       close(udptl->fd);
00914    free(udptl);
00915 }

int ast_udptl_fd struct ast_udptl udptl  ) 
 

Definition at line 632 of file udptl.c.

References ast_udptl::fd.

Referenced by __oh323_new(), and sip_new().

00633 {
00634    return udptl->fd;
00635 }

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

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

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

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

int ast_udptl_get_far_max_datagram struct ast_udptl udptl  ) 
 

Definition at line 765 of file udptl.c.

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

00766 {
00767    if (udptl)
00768       return udptl->far_max_datagram_size;
00769    else {
00770       ast_log(LOG_WARNING, "udptl structure is null\n");
00771       return -1;
00772    }
00773 }

int ast_udptl_get_local_max_datagram struct ast_udptl udptl  ) 
 

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

00756 {
00757    if (udptl)
00758       return udptl->local_max_datagram_size;
00759    else {
00760       ast_log(LOG_WARNING, "udptl structure is null\n");
00761       return -1;
00762    }
00763 }

void ast_udptl_get_peer struct ast_udptl udptl,
struct sockaddr_in *  them
 

Definition at line 890 of file udptl.c.

References ast_udptl::them.

Referenced by sip_handle_t38_reinvite(), and sip_set_udptl_peer().

00891 {
00892    them->sin_family = AF_INET;
00893    them->sin_port = udptl->them.sin_port;
00894    them->sin_addr = udptl->them.sin_addr;
00895 }

void ast_udptl_get_us struct ast_udptl udptl,
struct sockaddr_in *  us
 

Definition at line 897 of file udptl.c.

References ast_udptl::us.

Referenced by add_t38_sdp().

00898 {
00899    memcpy(us, &udptl->us, sizeof(udptl->us));
00900 }

void ast_udptl_init void   ) 
 

Definition at line 1286 of file udptl.c.

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

01287 {
01288    ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry));
01289    ast_udptl_reload();
01290 }

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

References ast_udptl_new_with_bindaddr(), io, and sched.

00869 {
00870    struct in_addr ia;
00871    memset(&ia, 0, sizeof(ia));
00872    return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
00873 }

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

References ast_calloc, ast_udptl::error_correction_scheme, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, udptlfecentries, udptlfecspan, udptlfectype, and udptlmaxdatagram.

Referenced by ast_udptl_new(), dialog_activate_media(), and sip_alloc().

00792 {
00793    struct ast_udptl *udptl;
00794    int x;
00795    int startplace;
00796    int i;
00797    long int flags;
00798 
00799    if (!(udptl = ast_calloc(1, sizeof(*udptl))))
00800       return NULL;
00801 
00802    if (udptlfectype == 2)
00803       udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC;
00804    else if (udptlfectype == 1)
00805       udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY;
00806    else
00807       udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_NONE;
00808    udptl->error_correction_span = udptlfecspan;
00809    udptl->error_correction_entries = udptlfecentries;
00810    
00811    udptl->far_max_datagram_size = udptlmaxdatagram;
00812    udptl->local_max_datagram_size = udptlmaxdatagram;
00813 
00814    memset(&udptl->rx, 0, sizeof(udptl->rx));
00815    memset(&udptl->tx, 0, sizeof(udptl->tx));
00816    for (i = 0; i <= UDPTL_BUF_MASK; i++) {
00817       udptl->rx[i].buf_len = -1;
00818       udptl->tx[i].buf_len = -1;
00819    }
00820 
00821    udptl->seqno = ast_random() & 0xffff;
00822    udptl->them.sin_family = AF_INET;
00823    udptl->us.sin_family = AF_INET;
00824 
00825    if ((udptl->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
00826       free(udptl);
00827       ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
00828       return NULL;
00829    }
00830    flags = fcntl(udptl->fd, F_GETFL);
00831    fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK);
00832 #ifdef SO_NO_CHECK
00833    if (nochecksums)
00834       setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
00835 #endif
00836    /* Find us a place */
00837    x = (ast_random() % (udptlend - udptlstart)) + udptlstart;
00838    startplace = x;
00839    for (;;) {
00840       udptl->us.sin_port = htons(x);
00841       udptl->us.sin_addr = addr;
00842       if (bind(udptl->fd, (struct sockaddr *) &udptl->us, sizeof(udptl->us)) == 0)
00843          break;
00844       if (errno != EADDRINUSE) {
00845          ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
00846          close(udptl->fd);
00847          free(udptl);
00848          return NULL;
00849       }
00850       if (++x > udptlend)
00851          x = udptlstart;
00852       if (x == startplace) {
00853          ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
00854          close(udptl->fd);
00855          free(udptl);
00856          return NULL;
00857       }
00858    }
00859    if (io && sched && callbackmode) {
00860       /* Operate this one in a callback mode */
00861       udptl->sched = sched;
00862       udptl->io = io;
00863       udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
00864    }
00865    return udptl;
00866 }

void ast_udptl_offered_from_local struct ast_udptl udptl,
int  local
 

Definition at line 717 of file udptl.c.

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

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

00718 {
00719    if (udptl)
00720       udptl->udptl_offered_from_local = local;
00721    else
00722       ast_log(LOG_WARNING, "udptl structure is null\n");
00723 }

int ast_udptl_proto_register struct ast_udptl_protocol proto  ) 
 

Definition at line 974 of file udptl.c.

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

Referenced by load_module(), and register_rtp_and_udptl().

00975 {
00976    struct ast_udptl_protocol *cur;
00977 
00978    cur = protos;
00979    while (cur) {
00980       if (cur->type == proto->type) {
00981          ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
00982          return -1;
00983       }
00984       cur = cur->next;
00985    }
00986    proto->next = protos;
00987    protos = proto;
00988    return 0;
00989 }

void ast_udptl_proto_unregister struct ast_udptl_protocol proto  ) 
 

Definition at line 954 of file udptl.c.

References ast_udptl_protocol::next, and protos.

Referenced by unload_module(), and unregister_rtp_and_udptl().

00955 {
00956    struct ast_udptl_protocol *cur;
00957    struct ast_udptl_protocol *prev;
00958 
00959    cur = protos;
00960    prev = NULL;
00961    while (cur) {
00962       if (cur == proto) {
00963          if (prev)
00964             prev->next = proto->next;
00965          else
00966             protos = proto->next;
00967          return;
00968       }
00969       prev = cur;
00970       cur = cur->next;
00971    }
00972 }

struct ast_frame* ast_udptl_read struct ast_udptl udptl  ) 
 

Definition at line 664 of file udptl.c.

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

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

00665 {
00666    int res;
00667    struct sockaddr_in sin;
00668    socklen_t len;
00669    uint16_t seqno = 0;
00670    uint16_t *udptlheader;
00671 
00672    len = sizeof(sin);
00673    
00674    /* Cache where the header will go */
00675    res = recvfrom(udptl->fd,
00676          udptl->rawdata + AST_FRIENDLY_OFFSET,
00677          sizeof(udptl->rawdata) - AST_FRIENDLY_OFFSET,
00678          0,
00679          (struct sockaddr *) &sin,
00680          &len);
00681    udptlheader = (uint16_t *)(udptl->rawdata + AST_FRIENDLY_OFFSET);
00682    if (res < 0) {
00683       if (errno != EAGAIN)
00684          ast_log(LOG_WARNING, "UDPTL read error: %s\n", strerror(errno));
00685       if (errno == EBADF)
00686          CRASH;
00687       return &ast_null_frame;
00688    }
00689 
00690    /* Ignore if the other side hasn't been given an address yet. */
00691    if (!udptl->them.sin_addr.s_addr || !udptl->them.sin_port)
00692       return &ast_null_frame;
00693 
00694    if (udptl->nat) {
00695       /* Send to whoever sent to us */
00696       if ((udptl->them.sin_addr.s_addr != sin.sin_addr.s_addr) ||
00697          (udptl->them.sin_port != sin.sin_port)) {
00698          memcpy(&udptl->them, &sin, sizeof(udptl->them));
00699          if (option_debug)
00700             ast_log(LOG_DEBUG, "UDPTL NAT: Using address %s:%d\n", ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
00701       }
00702    }
00703 
00704    if (udptl_debug_test_addr(&sin)) {
00705       if (option_verbose)
00706          ast_verbose("Got UDPTL packet from %s:%d (type %d, seq %d, len %d)\n",
00707             ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), 0, seqno, res);
00708    }
00709 #if 0
00710    printf("Got UDPTL packet from %s:%d (seq %d, len = %d)\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), seqno, res);
00711 #endif
00712    udptl_rx_packet(udptl, udptl->rawdata + AST_FRIENDLY_OFFSET, res);
00713 
00714    return &udptl->f[0];
00715 }

void ast_udptl_reload void   ) 
 

Definition at line 1210 of file udptl.c.

References ast_config_destroy(), ast_config_load(), ast_false(), ast_log(), ast_variable_retrieve(), ast_verbose(), LOCAL_FAX_MAX_DATAGRAM, MAX_FEC_ENTRIES, MAX_FEC_SPAN, option_verbose, s, udptlend, udptlfecentries, udptlfecspan, udptlfectype, udptlmaxdatagram, udptlstart, and VERBOSE_PREFIX_2.

Referenced by ast_udptl_init().

01211 {
01212    struct ast_config *cfg;
01213    const char *s;
01214 
01215    udptlstart = 4500;
01216    udptlend = 4999;
01217    udptlfectype = 0;
01218    udptlfecentries = 0;
01219    udptlfecspan = 0;
01220    udptlmaxdatagram = 0;
01221 
01222    if ((cfg = ast_config_load("udptl.conf"))) {
01223       if ((s = ast_variable_retrieve(cfg, "general", "udptlstart"))) {
01224          udptlstart = atoi(s);
01225          if (udptlstart < 1024)
01226             udptlstart = 1024;
01227          if (udptlstart > 65535)
01228             udptlstart = 65535;
01229       }
01230       if ((s = ast_variable_retrieve(cfg, "general", "udptlend"))) {
01231          udptlend = atoi(s);
01232          if (udptlend < 1024)
01233             udptlend = 1024;
01234          if (udptlend > 65535)
01235             udptlend = 65535;
01236       }
01237       if ((s = ast_variable_retrieve(cfg, "general", "udptlchecksums"))) {
01238 #ifdef SO_NO_CHECK
01239          if (ast_false(s))
01240             nochecksums = 1;
01241          else
01242             nochecksums = 0;
01243 #else
01244          if (ast_false(s))
01245             ast_log(LOG_WARNING, "Disabling UDPTL checksums is not supported on this operating system!\n");
01246 #endif
01247       }
01248       if ((s = ast_variable_retrieve(cfg, "general", "T38FaxUdpEC"))) {
01249          if (strcmp(s, "t38UDPFEC") == 0)
01250             udptlfectype = 2;
01251          else if (strcmp(s, "t38UDPRedundancy") == 0)
01252             udptlfectype = 1;
01253       }
01254       if ((s = ast_variable_retrieve(cfg, "general", "T38FaxMaxDatagram"))) {
01255          udptlmaxdatagram = atoi(s);
01256          if (udptlmaxdatagram < 0)
01257             udptlmaxdatagram = 0;
01258          if (udptlmaxdatagram > LOCAL_FAX_MAX_DATAGRAM)
01259             udptlmaxdatagram = LOCAL_FAX_MAX_DATAGRAM;
01260       }
01261       if ((s = ast_variable_retrieve(cfg, "general", "UDPTLFECentries"))) {
01262          udptlfecentries = atoi(s);
01263          if (udptlfecentries < 0)
01264             udptlfecentries = 0;
01265          if (udptlfecentries > MAX_FEC_ENTRIES)
01266             udptlfecentries = MAX_FEC_ENTRIES;
01267       }
01268       if ((s = ast_variable_retrieve(cfg, "general", "UDPTLFECspan"))) {
01269          udptlfecspan = atoi(s);
01270          if (udptlfecspan < 0)
01271             udptlfecspan = 0;
01272          if (udptlfecspan > MAX_FEC_SPAN)
01273             udptlfecspan = MAX_FEC_SPAN;
01274       }
01275       ast_config_destroy(cfg);
01276    }
01277    if (udptlstart >= udptlend) {
01278       ast_log(LOG_WARNING, "Unreasonable values for UDPTL start/end\n");
01279       udptlstart = 4500;
01280       udptlend = 4999;
01281    }
01282    if (option_verbose > 1)
01283       ast_verbose(VERBOSE_PREFIX_2 "UDPTL allocating from port range %d -> %d\n", udptlstart, udptlend);
01284 }

void ast_udptl_reset struct ast_udptl udptl  ) 
 

void ast_udptl_set_callback struct ast_udptl udptl,
ast_udptl_callback  callback
 

Definition at line 642 of file udptl.c.

References ast_udptl::callback.

00643 {
00644    udptl->callback = callback;
00645 }

void ast_udptl_set_data struct ast_udptl udptl,
void *  data
 

Definition at line 637 of file udptl.c.

References ast_udptl::data.

00638 {
00639    udptl->data = data;
00640 }

void ast_udptl_set_error_correction_scheme struct ast_udptl udptl,
int  ec
 

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

00736 {
00737    if (udptl) {
00738       switch (ec) {
00739       case UDPTL_ERROR_CORRECTION_FEC:
00740          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC;
00741          break;
00742       case UDPTL_ERROR_CORRECTION_REDUNDANCY:
00743          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY;
00744          break;
00745       case UDPTL_ERROR_CORRECTION_NONE:
00746          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_NONE;
00747          break;
00748       default:
00749          ast_log(LOG_WARNING, "error correction parameter invalid\n");
00750       };
00751    } else
00752       ast_log(LOG_WARNING, "udptl structure is null\n");
00753 }

void ast_udptl_set_far_max_datagram struct ast_udptl udptl,
int  max_datagram
 

Definition at line 783 of file udptl.c.

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

Referenced by sip_handle_t38_reinvite().

00784 {
00785    if (udptl)
00786       udptl->far_max_datagram_size = max_datagram;
00787    else
00788       ast_log(LOG_WARNING, "udptl structure is null\n");
00789 }

void ast_udptl_set_local_max_datagram struct ast_udptl udptl,
int  max_datagram
 

Definition at line 775 of file udptl.c.

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

Referenced by sip_handle_t38_reinvite().

00776 {
00777    if (udptl)
00778       udptl->local_max_datagram_size = max_datagram;
00779    else
00780       ast_log(LOG_WARNING, "udptl structure is null\n");
00781 }

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

References ast_udptl::them.

00885 {
00886    udptl->them.sin_port = them->sin_port;
00887    udptl->them.sin_addr = them->sin_addr;
00888 }

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

References ast_udptl::nat.

Referenced by do_setnat().

00648 {
00649    udptl->nat = nat;
00650 }

int ast_udptl_settos struct ast_udptl udptl,
int  tos
 

Definition at line 875 of file udptl.c.

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

Referenced by dialog_activate_media(), and sip_alloc().

00876 {
00877    int res;
00878 
00879    if ((res = setsockopt(udptl->fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 
00880       ast_log(LOG_WARNING, "UDPTL unable to set TOS to %d\n", tos);
00881    return res;
00882 }

void ast_udptl_stop struct ast_udptl udptl  ) 
 

Definition at line 902 of file udptl.c.

References ast_udptl::them.

Referenced by stop_media_flows().

00903 {
00904    memset(&udptl->them.sin_addr, 0, sizeof(udptl->them.sin_addr));
00905    memset(&udptl->them.sin_port, 0, sizeof(udptl->them.sin_port));
00906 }

int ast_udptl_write struct ast_udptl udptl,
struct ast_frame f
 

Definition at line 917 of file udptl.c.

References AST_FRAME_MODEM, ast_inet_ntoa(), ast_log(), ast_verbose(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, len, LOCAL_FAX_MAX_DATAGRAM, LOG_NOTICE, LOG_WARNING, s, udptl_build_packet(), and udptl_debug_test_addr().

Referenced by sip_write().

00918 {
00919    int len;
00920    int res;
00921    uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
00922 
00923    /* If we have no peer, return immediately */ 
00924    if (s->them.sin_addr.s_addr == INADDR_ANY)
00925       return 0;
00926 
00927    /* If there is no data length, return immediately */
00928    if (f->datalen == 0)
00929       return 0;
00930    
00931    if (f->frametype != AST_FRAME_MODEM) {
00932       ast_log(LOG_WARNING, "UDPTL can only send T.38 data\n");
00933       return -1;
00934    }
00935 
00936    /* Cook up the UDPTL packet, with the relevant EC info. */
00937    len = udptl_build_packet(s, buf, f->data, f->datalen);
00938 
00939    if (len > 0 && s->them.sin_port && s->them.sin_addr.s_addr) {
00940       if ((res = sendto(s->fd, buf, len, 0, (struct sockaddr *) &s->them, sizeof(s->them))) < 0)
00941          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));
00942 #if 0
00943       printf("Sent %d bytes of UDPTL data to %s:%d\n", res, ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
00944 #endif
00945       if (udptl_debug_test_addr(&s->them))
00946          ast_verbose("Sent UDPTL packet to %s:%d (type %d, seq %d, len %d)\n",
00947                ast_inet_ntoa(s->them.sin_addr),
00948                ntohs(s->them.sin_port), 0, s->seqno, len);
00949    }
00950       
00951    return 0;
00952 }


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen