Wed Oct 28 11:53:22 2009

Asterisk developer's documentation


udptl.h File Reference

UDPTL support for T.38. More...

#include "asterisk/network.h"
#include "asterisk/frame.h"
#include "asterisk/io.h"
#include "asterisk/sched.h"
#include "asterisk/channel.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  ast_t38_ec_modes { 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 (const struct ast_udptl *udptl)
enum ast_t38_ec_modes ast_udptl_get_error_correction_scheme (const struct ast_udptl *udptl)
unsigned int ast_udptl_get_far_max_datagram (const struct ast_udptl *udptl)
unsigned int ast_udptl_get_far_max_ifp (const struct ast_udptl *udptl)
unsigned int ast_udptl_get_local_max_datagram (const struct ast_udptl *udptl)
void ast_udptl_get_peer (const struct ast_udptl *udptl, struct sockaddr_in *them)
void ast_udptl_get_us (const struct ast_udptl *udptl, struct sockaddr_in *us)
void ast_udptl_init (void)
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)
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)
int 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, enum ast_t38_ec_modes ec)
void ast_udptl_set_far_max_datagram (struct ast_udptl *udptl, unsigned int max_datagram)
void ast_udptl_set_local_max_ifp (struct ast_udptl *udptl, unsigned int max_ifp)
void ast_udptl_set_m_type (struct ast_udptl *udptl, unsigned int pt)
void ast_udptl_set_peer (struct ast_udptl *udptl, const struct sockaddr_in *them)
void ast_udptl_set_udptlmap_type (struct ast_udptl *udptl, unsigned int pt, char *mimeType, char *mimeSubtype)
void ast_udptl_setnat (struct ast_udptl *udptl, int nat)
int ast_udptl_setqos (struct ast_udptl *udptl, unsigned int tos, unsigned int cos)
void ast_udptl_stop (struct ast_udptl *udptl)
int ast_udptl_write (struct ast_udptl *udptl, struct ast_frame *f)


Detailed Description

UDPTL support for T.38.

Author:
Steve Underwood <steveu@coppice.org> udptl.c
Todo:
add doxygen documentation to this file!

Definition in file udptl.h.


Typedef Documentation

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

Definition at line 57 of file udptl.h.


Enumeration Type Documentation

Enumerator:
UDPTL_ERROR_CORRECTION_NONE 
UDPTL_ERROR_CORRECTION_FEC 
UDPTL_ERROR_CORRECTION_REDUNDANCY 

Definition at line 36 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 1061 of file udptl.c.

References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_debug, 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_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::name, ast_udptl_protocol::set_udptl_peer, and ast_channel::tech_pvt.

01062 {
01063    struct ast_frame *f;
01064    struct ast_channel *who;
01065    struct ast_channel *cs[3];
01066    struct ast_udptl *p0;
01067    struct ast_udptl *p1;
01068    struct ast_udptl_protocol *pr0;
01069    struct ast_udptl_protocol *pr1;
01070    struct sockaddr_in ac0;
01071    struct sockaddr_in ac1;
01072    struct sockaddr_in t0;
01073    struct sockaddr_in t1;
01074    void *pvt0;
01075    void *pvt1;
01076    int to;
01077    
01078    ast_channel_lock(c0);
01079    while (ast_channel_trylock(c1)) {
01080       ast_channel_unlock(c0);
01081       usleep(1);
01082       ast_channel_lock(c0);
01083    }
01084    pr0 = get_proto(c0);
01085    pr1 = get_proto(c1);
01086    if (!pr0) {
01087       ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name);
01088       ast_channel_unlock(c0);
01089       ast_channel_unlock(c1);
01090       return -1;
01091    }
01092    if (!pr1) {
01093       ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name);
01094       ast_channel_unlock(c0);
01095       ast_channel_unlock(c1);
01096       return -1;
01097    }
01098    pvt0 = c0->tech_pvt;
01099    pvt1 = c1->tech_pvt;
01100    p0 = pr0->get_udptl_info(c0);
01101    p1 = pr1->get_udptl_info(c1);
01102    if (!p0 || !p1) {
01103       /* Somebody doesn't want to play... */
01104       ast_channel_unlock(c0);
01105       ast_channel_unlock(c1);
01106       return -2;
01107    }
01108    if (pr0->set_udptl_peer(c0, p1)) {
01109       ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
01110       memset(&ac1, 0, sizeof(ac1));
01111    } else {
01112       /* Store UDPTL peer */
01113       ast_udptl_get_peer(p1, &ac1);
01114    }
01115    if (pr1->set_udptl_peer(c1, p0)) {
01116       ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name);
01117       memset(&ac0, 0, sizeof(ac0));
01118    } else {
01119       /* Store UDPTL peer */
01120       ast_udptl_get_peer(p0, &ac0);
01121    }
01122    ast_channel_unlock(c0);
01123    ast_channel_unlock(c1);
01124    cs[0] = c0;
01125    cs[1] = c1;
01126    cs[2] = NULL;
01127    for (;;) {
01128       if ((c0->tech_pvt != pvt0) ||
01129          (c1->tech_pvt != pvt1) ||
01130          (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
01131             ast_debug(1, "Oooh, something is weird, backing out\n");
01132             /* Tell it to try again later */
01133             return -3;
01134       }
01135       to = -1;
01136       ast_udptl_get_peer(p1, &t1);
01137       ast_udptl_get_peer(p0, &t0);
01138       if (inaddrcmp(&t1, &ac1)) {
01139          ast_debug(1, "Oooh, '%s' changed end address to %s:%d\n", 
01140             c1->name, ast_inet_ntoa(t1.sin_addr), ntohs(t1.sin_port));
01141          ast_debug(1, "Oooh, '%s' was %s:%d\n", 
01142             c1->name, ast_inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port));
01143          memcpy(&ac1, &t1, sizeof(ac1));
01144       }
01145       if (inaddrcmp(&t0, &ac0)) {
01146          ast_debug(1, "Oooh, '%s' changed end address to %s:%d\n", 
01147             c0->name, ast_inet_ntoa(t0.sin_addr), ntohs(t0.sin_port));
01148          ast_debug(1, "Oooh, '%s' was %s:%d\n", 
01149             c0->name, ast_inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port));
01150          memcpy(&ac0, &t0, sizeof(ac0));
01151       }
01152       who = ast_waitfor_n(cs, 2, &to);
01153       if (!who) {
01154          ast_debug(1, "Ooh, empty read...\n");
01155          /* check for hangup / whentohangup */
01156          if (ast_check_hangup(c0) || ast_check_hangup(c1))
01157             break;
01158          continue;
01159       }
01160       f = ast_read(who);
01161       if (!f) {
01162          *fo = f;
01163          *rc = who;
01164          ast_debug(1, "Oooh, got a %s\n", f ? "digit" : "hangup");
01165          /* That's all we needed */
01166          return 0;
01167       } else {
01168          if (f->frametype == AST_FRAME_MODEM) {
01169             /* Forward T.38 frames if they happen upon us */
01170             if (who == c0) {
01171                ast_write(c1, f);
01172             } else if (who == c1) {
01173                ast_write(c0, f);
01174             }
01175          }
01176          ast_frfree(f);
01177       }
01178       /* Swap priority. Not that it's a big deal at this point */
01179       cs[2] = cs[0];
01180       cs[0] = cs[1];
01181       cs[1] = cs[2];
01182    }
01183    return -1;
01184 }

void ast_udptl_destroy ( struct ast_udptl udptl  ) 

Definition at line 966 of file udptl.c.

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

Referenced by __sip_destroy(), and create_addr_from_peer().

00967 {
00968    if (udptl->ioid)
00969       ast_io_remove(udptl->io, udptl->ioid);
00970    if (udptl->fd > -1)
00971       close(udptl->fd);
00972    ast_free(udptl);
00973 }

int ast_udptl_fd ( const struct ast_udptl udptl  ) 

Definition at line 629 of file udptl.c.

References ast_udptl::fd.

Referenced by __oh323_new(), and sip_new().

00630 {
00631    return udptl->fd;
00632 }

enum ast_t38_ec_modes ast_udptl_get_error_correction_scheme ( const struct ast_udptl udptl  ) 

Definition at line 772 of file udptl.c.

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

Referenced by add_sdp().

00773 {
00774    if (udptl)
00775       return udptl->error_correction_scheme;
00776    else {
00777       ast_log(LOG_WARNING, "udptl structure is null\n");
00778       return -1;
00779    }
00780 }

unsigned int ast_udptl_get_far_max_datagram ( const struct ast_udptl udptl  ) 

Definition at line 822 of file udptl.c.

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

00823 {
00824    if (udptl)
00825       return udptl->far_max_datagram;
00826    else {
00827       ast_log(LOG_WARNING, "udptl structure is null\n");
00828       return 0;
00829    }
00830 }

unsigned int ast_udptl_get_far_max_ifp ( const struct ast_udptl udptl  ) 

Definition at line 848 of file udptl.c.

References ast_udptl::far_max_ifp.

Referenced by change_t38_state().

00849 {
00850    return udptl->far_max_ifp;
00851 }

unsigned int ast_udptl_get_local_max_datagram ( const struct ast_udptl udptl  ) 

Definition at line 812 of file udptl.c.

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

Referenced by add_sdp().

00813 {
00814    if (udptl)
00815       return udptl->local_max_datagram;
00816    else {
00817       ast_log(LOG_WARNING, "udptl structure is null\n");
00818       return 0;
00819    }
00820 }

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

Definition at line 947 of file udptl.c.

References ast_udptl::them.

Referenced by ast_udptl_bridge(), and sip_set_udptl_peer().

00948 {
00949    memset(them, 0, sizeof(*them));
00950    them->sin_family = AF_INET;
00951    them->sin_port = udptl->them.sin_port;
00952    them->sin_addr = udptl->them.sin_addr;
00953 }

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

Definition at line 955 of file udptl.c.

References ast_udptl::us.

Referenced by add_sdp().

00956 {
00957    memcpy(us, &udptl->us, sizeof(udptl->us));
00958 }

void ast_udptl_init ( void   ) 

Definition at line 1427 of file udptl.c.

References __ast_udptl_reload(), and ast_cli_register_multiple().

Referenced by main().

01428 {
01429    ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry));
01430    __ast_udptl_reload(0);
01431 }

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

Definition at line 929 of file udptl.c.

References ast_udptl_new_with_bindaddr().

00930 {
00931    struct in_addr ia;
00932    memset(&ia, 0, sizeof(ia));
00933    return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
00934 }

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

References ast_calloc, ast_free, 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_span, ast_udptl::far_max_datagram, ast_udptl::fd, ast_udptl::flags, ast_udptl::io, ast_udptl::ioid, ast_udptl::local_max_datagram, LOG_WARNING, ast_udptl::rx, ast_udptl::sched, ast_udptl::them, ast_udptl::tx, UDPTL_BUF_MASK, udptlread(), and ast_udptl::us.

Referenced by ast_udptl_new(), create_addr_from_peer(), handle_request_invite(), and sip_alloc().

00854 {
00855    struct ast_udptl *udptl;
00856    int x;
00857    int startplace;
00858    int i;
00859    long int flags;
00860 
00861    if (!(udptl = ast_calloc(1, sizeof(*udptl))))
00862       return NULL;
00863 
00864    udptl->error_correction_span = udptlfecspan;
00865    udptl->error_correction_entries = udptlfecentries;
00866    
00867    udptl->far_max_datagram = udptlmaxdatagram;
00868    udptl->local_max_datagram = udptlmaxdatagram;
00869 
00870    for (i = 0; i <= UDPTL_BUF_MASK; i++) {
00871       udptl->rx[i].buf_len = -1;
00872       udptl->tx[i].buf_len = -1;
00873    }
00874 
00875    udptl->them.sin_family = AF_INET;
00876    udptl->us.sin_family = AF_INET;
00877 
00878    if ((udptl->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
00879       ast_free(udptl);
00880       ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
00881       return NULL;
00882    }
00883    flags = fcntl(udptl->fd, F_GETFL);
00884    fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK);
00885 #ifdef SO_NO_CHECK
00886    if (nochecksums)
00887       setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
00888 #endif
00889    /* Find us a place */
00890    x = (udptlstart == udptlend) ? udptlstart : (ast_random() % (udptlend - udptlstart)) + udptlstart;
00891    if (use_even_ports && (x & 1)) {
00892       ++x;
00893    }
00894    startplace = x;
00895    for (;;) {
00896       udptl->us.sin_port = htons(x);
00897       udptl->us.sin_addr = addr;
00898       if (bind(udptl->fd, (struct sockaddr *) &udptl->us, sizeof(udptl->us)) == 0)
00899          break;
00900       if (errno != EADDRINUSE) {
00901          ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
00902          close(udptl->fd);
00903          ast_free(udptl);
00904          return NULL;
00905       }
00906       if (use_even_ports) {
00907          x += 2;
00908       } else {
00909          ++x;
00910       }
00911       if (x > udptlend)
00912          x = udptlstart;
00913       if (x == startplace) {
00914          ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
00915          close(udptl->fd);
00916          ast_free(udptl);
00917          return NULL;
00918       }
00919    }
00920    if (io && sched && callbackmode) {
00921       /* Operate this one in a callback mode */
00922       udptl->sched = sched;
00923       udptl->io = io;
00924       udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
00925    }
00926    return udptl;
00927 }

int ast_udptl_proto_register ( struct ast_udptl_protocol proto  ) 

Definition at line 1030 of file udptl.c.

References ast_log(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_udptl_protocol::list, LOG_WARNING, and ast_udptl_protocol::type.

Referenced by load_module().

01031 {
01032    struct ast_udptl_protocol *cur;
01033 
01034    AST_RWLIST_WRLOCK(&protos);
01035    AST_RWLIST_TRAVERSE(&protos, cur, list) {
01036       if (cur->type == proto->type) {
01037          ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
01038          AST_RWLIST_UNLOCK(&protos);
01039          return -1;
01040       }
01041    }
01042    AST_RWLIST_INSERT_TAIL(&protos, proto, list);
01043    AST_RWLIST_UNLOCK(&protos);
01044    return 0;
01045 }

void ast_udptl_proto_unregister ( struct ast_udptl_protocol proto  ) 

Definition at line 1023 of file udptl.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by unload_module().

01024 {
01025    AST_RWLIST_WRLOCK(&protos);
01026    AST_RWLIST_REMOVE(&protos, proto, list);
01027    AST_RWLIST_UNLOCK(&protos);
01028 }

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

Definition at line 661 of file udptl.c.

References ast_assert, ast_debug, AST_FRIENDLY_OFFSET, ast_inet_ntoa(), ast_log(), ast_null_frame, ast_verb, errno, ast_udptl::f, ast_udptl::fd, len(), 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().

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

int ast_udptl_reload ( void   ) 

Version:
1.6.1 return changed to int

Definition at line 1421 of file udptl.c.

References __ast_udptl_reload().

01422 {
01423    __ast_udptl_reload(1);
01424    return 0;
01425 }

void ast_udptl_reset ( struct ast_udptl udptl  ) 

void ast_udptl_set_callback ( struct ast_udptl udptl,
ast_udptl_callback  callback 
)

Definition at line 639 of file udptl.c.

References ast_udptl::callback.

00640 {
00641    udptl->callback = callback;
00642 }

void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 634 of file udptl.c.

References ast_udptl::data.

00635 {
00636    udptl->data = data;
00637 }

void ast_udptl_set_error_correction_scheme ( struct ast_udptl udptl,
enum ast_t38_ec_modes  ec 
)

Definition at line 782 of file udptl.c.

References ast_log(), calculate_far_max_ifp(), calculate_local_max_datagram(), ast_udptl::error_correction_entries, ast_udptl::error_correction_scheme, ast_udptl::error_correction_span, LOG_WARNING, UDPTL_ERROR_CORRECTION_FEC, and UDPTL_ERROR_CORRECTION_REDUNDANCY.

Referenced by process_sdp(), and set_t38_capabilities().

00783 {
00784    if (udptl) {
00785       udptl->error_correction_scheme = ec;
00786       switch (ec) {
00787       case UDPTL_ERROR_CORRECTION_FEC:
00788          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC;
00789          if (udptl->error_correction_entries == 0) {
00790             udptl->error_correction_entries = 3;
00791          }
00792          if (udptl->error_correction_span == 0) {
00793             udptl->error_correction_span = 3;
00794          }
00795          break;
00796       case UDPTL_ERROR_CORRECTION_REDUNDANCY:
00797          udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY;
00798          if (udptl->error_correction_entries == 0) {
00799             udptl->error_correction_entries = 3;
00800          }
00801          break;
00802       default:
00803          /* nothing to do */
00804          break;
00805       };
00806       calculate_local_max_datagram(udptl);
00807       calculate_far_max_ifp(udptl);
00808    } else
00809       ast_log(LOG_WARNING, "udptl structure is null\n");
00810 }

void ast_udptl_set_far_max_datagram ( struct ast_udptl udptl,
unsigned int  max_datagram 
)

Definition at line 832 of file udptl.c.

References ast_log(), calculate_far_max_ifp(), ast_udptl::far_max_datagram, and LOG_WARNING.

Referenced by process_sdp().

00833 {
00834    if (udptl) {
00835       udptl->far_max_datagram = max_datagram;
00836       calculate_far_max_ifp(udptl);
00837    } else {
00838       ast_log(LOG_WARNING, "udptl structure is null\n");
00839    }
00840 }

void ast_udptl_set_local_max_ifp ( struct ast_udptl udptl,
unsigned int  max_ifp 
)

Definition at line 842 of file udptl.c.

References calculate_local_max_datagram(), and ast_udptl::local_max_ifp.

Referenced by interpret_t38_parameters().

00843 {
00844    udptl->local_max_ifp = max_ifp;
00845    calculate_local_max_datagram(udptl);
00846 }

void ast_udptl_set_m_type ( struct ast_udptl udptl,
unsigned int  pt 
)

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

Definition at line 941 of file udptl.c.

References ast_udptl::them.

Referenced by process_sdp().

00942 {
00943    udptl->them.sin_port = them->sin_port;
00944    udptl->them.sin_addr = them->sin_addr;
00945 }

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

void ast_udptl_setnat ( struct ast_udptl udptl,
int  nat 
)

Definition at line 644 of file udptl.c.

References ast_udptl::nat.

Referenced by do_setnat().

00645 {
00646    udptl->nat = nat;
00647 }

int ast_udptl_setqos ( struct ast_udptl udptl,
unsigned int  tos,
unsigned int  cos 
)

Definition at line 936 of file udptl.c.

References ast_netsock_set_qos(), and ast_udptl::fd.

Referenced by sip_alloc().

00937 {
00938    return ast_netsock_set_qos(udptl->fd, tos, cos, "UDPTL");
00939 }

void ast_udptl_stop ( struct ast_udptl udptl  ) 

Definition at line 960 of file udptl.c.

References ast_udptl::them.

Referenced by process_sdp(), and stop_media_flows().

00961 {
00962    memset(&udptl->them.sin_addr, 0, sizeof(udptl->them.sin_addr));
00963    memset(&udptl->them.sin_port, 0, sizeof(udptl->them.sin_port));
00964 }

int ast_udptl_write ( struct ast_udptl udptl,
struct ast_frame f 
)

Definition at line 975 of file udptl.c.

References AST_FRAME_MODEM, ast_inet_ntoa(), ast_log(), AST_MODEM_T38, ast_verb, buf, ast_frame::data, ast_frame::datalen, errno, ast_udptl::far_max_datagram, ast_udptl::far_max_ifp, ast_udptl::fd, ast_frame::frametype, len(), LOG_NOTICE, LOG_WARNING, ast_frame::ptr, seq, ast_frame::subclass, ast_udptl::them, ast_udptl::tx_seq_no, udptl_build_packet(), and udptl_debug_test_addr().

Referenced by sip_write().

00976 {
00977    unsigned int seq;
00978    unsigned int len;
00979    int res;
00980    uint8_t buf[s->far_max_datagram];
00981 
00982    /* If we have no peer, return immediately */ 
00983    if (s->them.sin_addr.s_addr == INADDR_ANY)
00984       return 0;
00985 
00986    /* If there is no data length, return immediately */
00987    if (f->datalen == 0)
00988       return 0;
00989    
00990    if ((f->frametype != AST_FRAME_MODEM) ||
00991        (f->subclass != AST_MODEM_T38)) {
00992       ast_log(LOG_WARNING, "UDPTL can only send T.38 data.\n");
00993       return -1;
00994    }
00995 
00996    if (f->datalen > s->far_max_ifp) {
00997       ast_log(LOG_WARNING,
00998          "UDPTL asked to send %d bytes of IFP when far end only prepared to accept %d bytes; data loss may occur. "
00999          "You may need to override the T38FaxMaxDatagram value for this endpoint in the channel driver configuration.\n", f->datalen, s->far_max_ifp);
01000    }
01001 
01002    /* Save seq_no for debug output because udptl_build_packet increments it */
01003    seq = s->tx_seq_no & 0xFFFF;
01004 
01005    /* Cook up the UDPTL packet, with the relevant EC info. */
01006    len = udptl_build_packet(s, buf, sizeof(buf), f->data.ptr, f->datalen);
01007 
01008    if (len > 0 && s->them.sin_port && s->them.sin_addr.s_addr) {
01009       if ((res = sendto(s->fd, buf, len, 0, (struct sockaddr *) &s->them, sizeof(s->them))) < 0)
01010          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));
01011 #if 0
01012       printf("Sent %d bytes of UDPTL data to %s:%d\n", res, ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
01013 #endif
01014       if (udptl_debug_test_addr(&s->them))
01015          ast_verb(1, "Sent UDPTL packet to %s:%d (type %d, seq %d, len %d)\n",
01016                ast_inet_ntoa(s->them.sin_addr),
01017                ntohs(s->them.sin_port), 0, seq, len);
01018    }
01019       
01020    return 0;
01021 }


Generated on Wed Oct 28 11:53:23 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6