Wed Aug 18 22:34:34 2010

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"

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 (struct ast_udptl *udptl)
 retrieves far max ifp
unsigned int ast_udptl_get_local_max_datagram (struct ast_udptl *udptl)
 retrieves local_max_datagram.
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)
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)
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)
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)
 sets far max datagram size. If max_datagram is = 0, the far max datagram size is set to a default value.
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_tag (struct ast_udptl *udptl, const char *format,...)
 Associates a character string 'tag' with a UDPTL session.
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

enum ast_t38_ec_modes

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 1150 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, 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.

01151 {
01152    struct ast_frame *f;
01153    struct ast_channel *who;
01154    struct ast_channel *cs[3];
01155    struct ast_udptl *p0;
01156    struct ast_udptl *p1;
01157    struct ast_udptl_protocol *pr0;
01158    struct ast_udptl_protocol *pr1;
01159    struct sockaddr_in ac0;
01160    struct sockaddr_in ac1;
01161    struct sockaddr_in t0;
01162    struct sockaddr_in t1;
01163    void *pvt0;
01164    void *pvt1;
01165    int to;
01166    
01167    ast_channel_lock(c0);
01168    while (ast_channel_trylock(c1)) {
01169       ast_channel_unlock(c0);
01170       usleep(1);
01171       ast_channel_lock(c0);
01172    }
01173    pr0 = get_proto(c0);
01174    pr1 = get_proto(c1);
01175    if (!pr0) {
01176       ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name);
01177       ast_channel_unlock(c0);
01178       ast_channel_unlock(c1);
01179       return -1;
01180    }
01181    if (!pr1) {
01182       ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name);
01183       ast_channel_unlock(c0);
01184       ast_channel_unlock(c1);
01185       return -1;
01186    }
01187    pvt0 = c0->tech_pvt;
01188    pvt1 = c1->tech_pvt;
01189    p0 = pr0->get_udptl_info(c0);
01190    p1 = pr1->get_udptl_info(c1);
01191    if (!p0 || !p1) {
01192       /* Somebody doesn't want to play... */
01193       ast_channel_unlock(c0);
01194       ast_channel_unlock(c1);
01195       return -2;
01196    }
01197    if (pr0->set_udptl_peer(c0, p1)) {
01198       ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
01199       memset(&ac1, 0, sizeof(ac1));
01200    } else {
01201       /* Store UDPTL peer */
01202       ast_udptl_get_peer(p1, &ac1);
01203    }
01204    if (pr1->set_udptl_peer(c1, p0)) {
01205       ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name);
01206       memset(&ac0, 0, sizeof(ac0));
01207    } else {
01208       /* Store UDPTL peer */
01209       ast_udptl_get_peer(p0, &ac0);
01210    }
01211    ast_channel_unlock(c0);
01212    ast_channel_unlock(c1);
01213    cs[0] = c0;
01214    cs[1] = c1;
01215    cs[2] = NULL;
01216    for (;;) {
01217       if ((c0->tech_pvt != pvt0) ||
01218          (c1->tech_pvt != pvt1) ||
01219          (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
01220             ast_debug(1, "Oooh, something is weird, backing out\n");
01221             /* Tell it to try again later */
01222             return -3;
01223       }
01224       to = -1;
01225       ast_udptl_get_peer(p1, &t1);
01226       ast_udptl_get_peer(p0, &t0);
01227       if (inaddrcmp(&t1, &ac1)) {
01228          ast_debug(1, "Oooh, '%s' changed end address to %s:%d\n", 
01229             c1->name, ast_inet_ntoa(t1.sin_addr), ntohs(t1.sin_port));
01230          ast_debug(1, "Oooh, '%s' was %s:%d\n", 
01231             c1->name, ast_inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port));
01232          memcpy(&ac1, &t1, sizeof(ac1));
01233       }
01234       if (inaddrcmp(&t0, &ac0)) {
01235          ast_debug(1, "Oooh, '%s' changed end address to %s:%d\n", 
01236             c0->name, ast_inet_ntoa(t0.sin_addr), ntohs(t0.sin_port));
01237          ast_debug(1, "Oooh, '%s' was %s:%d\n", 
01238             c0->name, ast_inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port));
01239          memcpy(&ac0, &t0, sizeof(ac0));
01240       }
01241       who = ast_waitfor_n(cs, 2, &to);
01242       if (!who) {
01243          ast_debug(1, "Ooh, empty read...\n");
01244          /* check for hangup / whentohangup */
01245          if (ast_check_hangup(c0) || ast_check_hangup(c1))
01246             break;
01247          continue;
01248       }
01249       f = ast_read(who);
01250       if (!f) {
01251          *fo = f;
01252          *rc = who;
01253          ast_debug(1, "Oooh, got a %s\n", f ? "digit" : "hangup");
01254          /* That's all we needed */
01255          return 0;
01256       } else {
01257          if (f->frametype == AST_FRAME_MODEM) {
01258             /* Forward T.38 frames if they happen upon us */
01259             if (who == c0) {
01260                ast_write(c1, f);
01261             } else if (who == c1) {
01262                ast_write(c0, f);
01263             }
01264          }
01265          ast_frfree(f);
01266       }
01267       /* Swap priority. Not that it's a big deal at this point */
01268       cs[2] = cs[0];
01269       cs[0] = cs[1];
01270       cs[1] = cs[2];
01271    }
01272    return -1;
01273 }

void ast_udptl_destroy ( struct ast_udptl udptl  ) 

Definition at line 1049 of file udptl.c.

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

Referenced by __sip_destroy(), and create_addr_from_peer().

01050 {
01051    if (udptl->ioid)
01052       ast_io_remove(udptl->io, udptl->ioid);
01053    if (udptl->fd > -1)
01054       close(udptl->fd);
01055    if (udptl->tag)
01056       ast_free(udptl->tag);
01057    ast_free(udptl);
01058 }

int ast_udptl_fd ( const struct ast_udptl udptl  ) 

Definition at line 640 of file udptl.c.

References ast_udptl::fd.

Referenced by __oh323_new(), and sip_new().

00641 {
00642    return udptl->fd;
00643 }

enum ast_t38_ec_modes ast_udptl_get_error_correction_scheme ( const struct ast_udptl udptl  ) 

Definition at line 831 of file udptl.c.

References ast_udptl::error_correction_scheme.

Referenced by add_sdp().

00832 {
00833    return udptl->error_correction_scheme;
00834 }

unsigned int ast_udptl_get_far_max_datagram ( const struct ast_udptl udptl  ) 

Definition at line 899 of file udptl.c.

References ast_udptl::far_max_datagram.

Referenced by process_sdp().

00900 {
00901    if (udptl->far_max_datagram < 0) {
00902       return 0;
00903    }
00904    return udptl->far_max_datagram;
00905 }

unsigned int ast_udptl_get_far_max_ifp ( struct ast_udptl udptl  ) 

retrieves far max ifp

Return values:
positive value representing max ifp size
0 if no value is present

Definition at line 907 of file udptl.c.

References calculate_far_max_ifp(), and ast_udptl::far_max_ifp.

Referenced by change_t38_state().

00908 {
00909    if (udptl->far_max_ifp == -1) {
00910       calculate_far_max_ifp(udptl);
00911    }
00912 
00913    if (udptl->far_max_ifp < 0) {
00914       return 0;
00915    }
00916    return udptl->far_max_ifp;
00917 }

unsigned int ast_udptl_get_local_max_datagram ( struct ast_udptl udptl  ) 

retrieves local_max_datagram.

Return values:
positive value representing max datagram size.
0 if no value is present

Definition at line 875 of file udptl.c.

References calculate_local_max_datagram(), and ast_udptl::local_max_datagram.

Referenced by add_sdp().

00876 {
00877    if (udptl->local_max_datagram == -1) {
00878       calculate_local_max_datagram(udptl);
00879    }
00880 
00881    /* this function expects a unsigned value in return. */
00882    if (udptl->local_max_datagram < 0) {
00883       return 0;
00884    }
00885    return udptl->local_max_datagram;
00886 }

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

Definition at line 1030 of file udptl.c.

References ast_udptl::them.

Referenced by ast_udptl_bridge(), and sip_set_udptl_peer().

01031 {
01032    memset(them, 0, sizeof(*them));
01033    them->sin_family = AF_INET;
01034    them->sin_port = udptl->them.sin_port;
01035    them->sin_addr = udptl->them.sin_addr;
01036 }

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

Definition at line 1038 of file udptl.c.

References ast_udptl::us.

Referenced by add_sdp().

01039 {
01040    memcpy(us, &udptl->us, sizeof(udptl->us));
01041 }

void ast_udptl_init ( void   ) 

Definition at line 1507 of file udptl.c.

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

Referenced by main().

01508 {
01509    ast_cli_register_multiple(cli_udptl, sizeof(cli_udptl) / sizeof(struct ast_cli_entry));
01510    __ast_udptl_reload(0);
01511 }

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

Definition at line 997 of file udptl.c.

References ast_udptl_new_with_bindaddr(), io, and sched.

00998 {
00999    struct in_addr ia;
01000    memset(&ia, 0, sizeof(ia));
01001    return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
01002 }

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

References ast_calloc, ast_free, ast_io_add(), AST_IO_IN, ast_log(), ast_random(), errno, ast_udptl::flags, io, LOG_WARNING, sched, and udptlread().

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

00920 {
00921    struct ast_udptl *udptl;
00922    int x;
00923    int startplace;
00924    int i;
00925    long int flags;
00926 
00927    if (!(udptl = ast_calloc(1, sizeof(*udptl))))
00928       return NULL;
00929 
00930    udptl->error_correction_span = udptlfecspan;
00931    udptl->error_correction_entries = udptlfecentries;
00932    
00933    udptl->far_max_datagram = -1;
00934    udptl->far_max_ifp = -1;
00935    udptl->local_max_ifp = -1;
00936    udptl->local_max_datagram = -1;
00937 
00938    for (i = 0; i <= UDPTL_BUF_MASK; i++) {
00939       udptl->rx[i].buf_len = -1;
00940       udptl->tx[i].buf_len = -1;
00941    }
00942 
00943    udptl->them.sin_family = AF_INET;
00944    udptl->us.sin_family = AF_INET;
00945 
00946    if ((udptl->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
00947       ast_free(udptl);
00948       ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
00949       return NULL;
00950    }
00951    flags = fcntl(udptl->fd, F_GETFL);
00952    fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK);
00953 #ifdef SO_NO_CHECK
00954    if (nochecksums)
00955       setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
00956 #endif
00957    /* Find us a place */
00958    x = (udptlstart == udptlend) ? udptlstart : (ast_random() % (udptlend - udptlstart)) + udptlstart;
00959    if (use_even_ports && (x & 1)) {
00960       ++x;
00961    }
00962    startplace = x;
00963    for (;;) {
00964       udptl->us.sin_port = htons(x);
00965       udptl->us.sin_addr = addr;
00966       if (bind(udptl->fd, (struct sockaddr *) &udptl->us, sizeof(udptl->us)) == 0)
00967          break;
00968       if (errno != EADDRINUSE) {
00969          ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
00970          close(udptl->fd);
00971          ast_free(udptl);
00972          return NULL;
00973       }
00974       if (use_even_ports) {
00975          x += 2;
00976       } else {
00977          ++x;
00978       }
00979       if (x > udptlend)
00980          x = udptlstart;
00981       if (x == startplace) {
00982          ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
00983          close(udptl->fd);
00984          ast_free(udptl);
00985          return NULL;
00986       }
00987    }
00988    if (io && sched && callbackmode) {
00989       /* Operate this one in a callback mode */
00990       udptl->sched = sched;
00991       udptl->io = io;
00992       udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
00993    }
00994    return udptl;
00995 }

int ast_udptl_proto_register ( struct ast_udptl_protocol proto  ) 

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

01120 {
01121    struct ast_udptl_protocol *cur;
01122 
01123    AST_RWLIST_WRLOCK(&protos);
01124    AST_RWLIST_TRAVERSE(&protos, cur, list) {
01125       if (cur->type == proto->type) {
01126          ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
01127          AST_RWLIST_UNLOCK(&protos);
01128          return -1;
01129       }
01130    }
01131    AST_RWLIST_INSERT_TAIL(&protos, proto, list);
01132    AST_RWLIST_UNLOCK(&protos);
01133    return 0;
01134 }

void ast_udptl_proto_unregister ( struct ast_udptl_protocol proto  ) 

Definition at line 1112 of file udptl.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by unload_module().

01113 {
01114    AST_RWLIST_WRLOCK(&protos);
01115    AST_RWLIST_REMOVE(&protos, proto, list);
01116    AST_RWLIST_UNLOCK(&protos);
01117 }

struct ast_frame* ast_udptl_read ( struct ast_udptl udptl  ) 

Definition at line 672 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_TAG, 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().

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

int ast_udptl_reload ( void   ) 

Version:
1.6.1 return changed to int

Definition at line 1501 of file udptl.c.

References __ast_udptl_reload().

01502 {
01503    __ast_udptl_reload(1);
01504    return 0;
01505 }

void ast_udptl_reset ( struct ast_udptl udptl  ) 

void ast_udptl_set_callback ( struct ast_udptl udptl,
ast_udptl_callback  callback 
)

Definition at line 650 of file udptl.c.

References ast_udptl::callback.

00651 {
00652    udptl->callback = callback;
00653 }

void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 645 of file udptl.c.

References ast_udptl::data.

00646 {
00647    udptl->data = data;
00648 }

void ast_udptl_set_error_correction_scheme ( struct ast_udptl udptl,
enum ast_t38_ec_modes  ec 
)

Definition at line 836 of file udptl.c.

References ast_udptl::error_correction_entries, ast_udptl::error_correction_scheme, ast_udptl::error_correction_span, ast_udptl::far_max_ifp, ast_udptl::local_max_datagram, UDPTL_ERROR_CORRECTION_FEC, and UDPTL_ERROR_CORRECTION_REDUNDANCY.

Referenced by process_sdp_a_image(), and set_t38_capabilities().

00837 {
00838    udptl->error_correction_scheme = ec;
00839    switch (ec) {
00840    case UDPTL_ERROR_CORRECTION_FEC:
00841       udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC;
00842       if (udptl->error_correction_entries == 0) {
00843          udptl->error_correction_entries = 3;
00844       }
00845       if (udptl->error_correction_span == 0) {
00846          udptl->error_correction_span = 3;
00847       }
00848       break;
00849    case UDPTL_ERROR_CORRECTION_REDUNDANCY:
00850       udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY;
00851       if (udptl->error_correction_entries == 0) {
00852          udptl->error_correction_entries = 3;
00853       }
00854       break;
00855    default:
00856       /* nothing to do */
00857       break;
00858    };
00859    /* reset calculated values so they'll be computed again */
00860    udptl->local_max_datagram = -1;
00861    udptl->far_max_ifp = -1;
00862 }

void ast_udptl_set_far_max_datagram ( struct ast_udptl udptl,
unsigned int  max_datagram 
)

sets far max datagram size. If max_datagram is = 0, the far max datagram size is set to a default value.

Definition at line 888 of file udptl.c.

References DEFAULT_FAX_MAX_DATAGRAM, ast_udptl::far_max_datagram, ast_udptl::far_max_ifp, and FAX_MAX_DATAGRAM_LIMIT.

Referenced by process_sdp(), and process_sdp_a_image().

00889 {
00890    if (!max_datagram || (max_datagram > FAX_MAX_DATAGRAM_LIMIT)) {
00891       udptl->far_max_datagram = DEFAULT_FAX_MAX_DATAGRAM;
00892    } else {
00893       udptl->far_max_datagram = max_datagram;
00894    }
00895    /* reset calculated values so they'll be computed again */
00896    udptl->far_max_ifp = -1;
00897 }

void ast_udptl_set_local_max_ifp ( struct ast_udptl udptl,
unsigned int  max_ifp 
)

Definition at line 864 of file udptl.c.

References ast_udptl::local_max_datagram, and ast_udptl::local_max_ifp.

Referenced by interpret_t38_parameters().

00865 {
00866    /* make sure max_ifp is a positive value since a cast will take place when
00867     * when setting local_max_ifp */
00868    if ((signed int) max_ifp > 0) {
00869       udptl->local_max_ifp = max_ifp;
00870       /* reset calculated values so they'll be computed again */
00871       udptl->local_max_datagram = -1;
00872    }
00873 }

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

References ast_udptl::them.

Referenced by process_sdp().

01025 {
01026    udptl->them.sin_port = them->sin_port;
01027    udptl->them.sin_addr = them->sin_addr;
01028 }

void ast_udptl_set_tag ( struct ast_udptl udptl,
const char *  format,
  ... 
)

Associates a character string 'tag' with a UDPTL session.

Parameters:
udptl The UDPTL session.
format printf-style format string used to construct the tag
This function formats a tag for the specified UDPTL session, so that any log messages generated by the UDPTL stack related to that session will include the tag and the reader of the messages will be able to identify which endpoint caused them to be generated.

Return values:
none 

Definition at line 1004 of file udptl.c.

References ast_free, ast_vasprintf, and ast_udptl::tag.

Referenced by change_t38_state().

01005 {
01006    va_list ap;
01007 
01008    if (udptl->tag) {
01009       ast_free(udptl->tag);
01010       udptl->tag = NULL;
01011    }
01012    va_start(ap, format);
01013    if (ast_vasprintf(&udptl->tag, format, ap) == -1) {
01014       udptl->tag = NULL;
01015    }
01016    va_end(ap);
01017 }

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

References ast_udptl::nat.

Referenced by do_setnat().

00656 {
00657    udptl->nat = nat;
00658 }

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

Definition at line 1019 of file udptl.c.

References ast_netsock_set_qos(), and ast_udptl::fd.

Referenced by sip_alloc().

01020 {
01021    return ast_netsock_set_qos(udptl->fd, tos, cos, "UDPTL");
01022 }

void ast_udptl_stop ( struct ast_udptl udptl  ) 

Definition at line 1043 of file udptl.c.

References ast_udptl::them.

Referenced by process_sdp(), and stop_media_flows().

01044 {
01045    memset(&udptl->them.sin_addr, 0, sizeof(udptl->them.sin_addr));
01046    memset(&udptl->them.sin_port, 0, sizeof(udptl->them.sin_port));
01047 }

int ast_udptl_write ( struct ast_udptl udptl,
struct ast_frame f 
)

Definition at line 1060 of file udptl.c.

References AST_FRAME_MODEM, ast_inet_ntoa(), ast_log(), AST_MODEM_T38, ast_verb, buf, DEFAULT_FAX_MAX_DATAGRAM, errno, f, len(), LOG_NOTICE, LOG_TAG, LOG_WARNING, s, seq, udptl_build_packet(), and udptl_debug_test_addr().

Referenced by sip_write().

01061 {
01062    unsigned int seq;
01063    unsigned int len = f->datalen;
01064    int res;
01065    /* if no max datagram size is provided, use default value */
01066    const int bufsize = (s->far_max_datagram > 0) ? s->far_max_datagram : DEFAULT_FAX_MAX_DATAGRAM;
01067    uint8_t buf[bufsize];
01068 
01069    memset(buf, 0, sizeof(buf));
01070 
01071    /* If we have no peer, return immediately */ 
01072    if (s->them.sin_addr.s_addr == INADDR_ANY)
01073       return 0;
01074 
01075    /* If there is no data length, return immediately */
01076    if (f->datalen == 0)
01077       return 0;
01078    
01079    if ((f->frametype != AST_FRAME_MODEM) ||
01080        (f->subclass != AST_MODEM_T38)) {
01081       ast_log(LOG_WARNING, "(%s): UDPTL can only send T.38 data.\n",
01082          LOG_TAG(s));
01083       return -1;
01084    }
01085 
01086    if (len > s->far_max_ifp) {
01087       ast_log(LOG_WARNING,
01088          "(%s): UDPTL asked to send %d bytes of IFP when far end only prepared to accept %d bytes; data loss will occur."
01089          "You may need to override the T38FaxMaxDatagram value for this endpoint in the channel driver configuration.\n",
01090          LOG_TAG(s), len, s->far_max_ifp);
01091       len = s->far_max_ifp;
01092    }
01093 
01094    /* Save seq_no for debug output because udptl_build_packet increments it */
01095    seq = s->tx_seq_no & 0xFFFF;
01096 
01097    /* Cook up the UDPTL packet, with the relevant EC info. */
01098    len = udptl_build_packet(s, buf, sizeof(buf), f->data.ptr, len);
01099 
01100    if (len > 0 && s->them.sin_port && s->them.sin_addr.s_addr) {
01101       if ((res = sendto(s->fd, buf, len, 0, (struct sockaddr *) &s->them, sizeof(s->them))) < 0)
01102          ast_log(LOG_NOTICE, "(%s): UDPTL Transmission error to %s:%d: %s\n",
01103             LOG_TAG(s), ast_inet_ntoa(s->them.sin_addr), ntohs(s->them.sin_port), strerror(errno));
01104       if (udptl_debug_test_addr(&s->them))
01105          ast_verb(1, "UDPTL (%s): packet to %s:%d (type %d, seq %d, len %d)\n",
01106              LOG_TAG(s), ast_inet_ntoa(s->them.sin_addr), ntohs(s->them.sin_port), 0, seq, len);
01107    }
01108       
01109    return 0;
01110 }


Generated on Wed Aug 18 22:34:34 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7