Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Typedefs | Enumerations | Functions
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 "asterisk/netsock2.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.

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

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 More...
 
unsigned int ast_udptl_get_local_max_datagram (struct ast_udptl *udptl)
 retrieves local_max_datagram. More...
 
void ast_udptl_get_peer (const struct ast_udptl *udptl, struct ast_sockaddr *them)
 
void ast_udptl_get_us (const struct ast_udptl *udptl, struct ast_sockaddr *us)
 
struct ast_udptlast_udptl_new_with_bindaddr (struct ast_sched_context *sched, struct io_context *io, int callbackmode, struct ast_sockaddr *in)
 
struct ast_frameast_udptl_read (struct ast_udptl *udptl)
 
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. More...
 
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 ast_sockaddr *them)
 
void ast_udptl_set_tag (struct ast_udptl *udptl, const char *format,...)
 Associates a character string 'tag' with a UDPTL session. More...
 
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 steve.nosp@m.u@co.nosp@m.ppice.nosp@m..org udptl.c
Todo:
add doxygen documentation to this file!

Definition in file udptl.h.

Typedef Documentation

◆ ast_udptl_callback

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

Definition at line 49 of file udptl.h.

Enumeration Type Documentation

◆ ast_t38_ec_modes

Enumerator
UDPTL_ERROR_CORRECTION_NONE 
UDPTL_ERROR_CORRECTION_FEC 
UDPTL_ERROR_CORRECTION_REDUNDANCY 

Definition at line 37 of file udptl.h.

37 {
41};
@ UDPTL_ERROR_CORRECTION_FEC
Definition: udptl.h:39
@ UDPTL_ERROR_CORRECTION_NONE
Definition: udptl.h:38
@ UDPTL_ERROR_CORRECTION_REDUNDANCY
Definition: udptl.h:40

Function Documentation

◆ ast_udptl_destroy()

void ast_udptl_destroy ( struct ast_udptl udptl)

Definition at line 1175 of file udptl.c.

1176{
1177 if (udptl->ioid)
1178 ast_io_remove(udptl->io, udptl->ioid);
1179 if (udptl->fd > -1)
1180 close(udptl->fd);
1181 if (udptl->tag)
1182 ast_free(udptl->tag);
1183 ast_free(udptl);
1184}
#define ast_free(a)
Definition: astmm.h:180
int ast_io_remove(struct io_context *ioc, int *id)
Removes an IO context.
Definition: io.c:245
int * ioid
Definition: udptl.c:191
int fd
Definition: udptl.c:182
char * tag
Definition: udptl.c:195
struct io_context * io
Definition: udptl.c:193

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

Referenced by ooh323_destroy(), and stream_destroy().

◆ ast_udptl_fd()

int ast_udptl_fd ( const struct ast_udptl udptl)

Definition at line 755 of file udptl.c.

756{
757 return udptl->fd;
758}

References ast_udptl::fd.

Referenced by apply_negotiated_sdp_stream(), and configure_local_rtp().

◆ ast_udptl_get_error_correction_scheme()

enum ast_t38_ec_modes ast_udptl_get_error_correction_scheme ( const struct ast_udptl udptl)

Definition at line 965 of file udptl.c.

966{
967 return udptl->error_correction_scheme;
968}
enum ast_t38_ec_modes error_correction_scheme
Definition: udptl.c:201

References ast_udptl::error_correction_scheme.

Referenced by create_outgoing_sdp_stream().

◆ ast_udptl_get_far_max_datagram()

unsigned int ast_udptl_get_far_max_datagram ( const struct ast_udptl udptl)

Definition at line 1033 of file udptl.c.

1034{
1035 if (udptl->far_max_datagram < 0) {
1036 return 0;
1037 }
1038 return udptl->far_max_datagram;
1039}
int far_max_datagram
Definition: udptl.c:216

References ast_udptl::far_max_datagram.

◆ ast_udptl_get_far_max_ifp()

unsigned int ast_udptl_get_far_max_ifp ( struct ast_udptl udptl)

retrieves far max ifp

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

Definition at line 1041 of file udptl.c.

1042{
1043 if (udptl->far_max_ifp == -1) {
1044 calculate_far_max_ifp(udptl);
1045 }
1046
1047 if (udptl->far_max_ifp < 0) {
1048 return 0;
1049 }
1050 return udptl->far_max_ifp;
1051}
int far_max_ifp
Definition: udptl.c:230
static void calculate_far_max_ifp(struct ast_udptl *udptl)
Definition: udptl.c:897

References calculate_far_max_ifp(), and ast_udptl::far_max_ifp.

Referenced by onModeChanged(), ooh323_indicate(), setup_udptl_connection(), t38_change_state(), and t38_interpret_parameters().

◆ ast_udptl_get_local_max_datagram()

unsigned int ast_udptl_get_local_max_datagram ( struct ast_udptl udptl)

retrieves local_max_datagram.

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

Definition at line 1009 of file udptl.c.

1010{
1011 if (udptl->local_max_datagram == -1) {
1013 }
1014
1015 /* this function expects a unsigned value in return. */
1016 if (udptl->local_max_datagram < 0) {
1017 return 0;
1018 }
1019 return udptl->local_max_datagram;
1020}
int local_max_datagram
Definition: udptl.c:222
static void calculate_local_max_datagram(struct ast_udptl *udptl)
Definition: udptl.c:856

References calculate_local_max_datagram(), and ast_udptl::local_max_datagram.

Referenced by create_outgoing_sdp_stream().

◆ ast_udptl_get_peer()

void ast_udptl_get_peer ( const struct ast_udptl udptl,
struct ast_sockaddr them 
)

Definition at line 1160 of file udptl.c.

1161{
1162 ast_sockaddr_copy(them, &udptl->them);
1163}
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:167
struct ast_sockaddr them
Definition: udptl.c:190

References ast_sockaddr_copy(), and ast_udptl::them.

◆ ast_udptl_get_us()

void ast_udptl_get_us ( const struct ast_udptl udptl,
struct ast_sockaddr us 
)

Definition at line 1165 of file udptl.c.

1166{
1167 ast_sockaddr_copy(us, &udptl->us);
1168}
struct ast_sockaddr us
Definition: udptl.c:189

References ast_sockaddr_copy(), and ast_udptl::us.

Referenced by configure_local_rtp(), and create_outgoing_sdp_stream().

◆ ast_udptl_new_with_bindaddr()

struct ast_udptl * ast_udptl_new_with_bindaddr ( struct ast_sched_context sched,
struct io_context io,
int  callbackmode,
struct ast_sockaddr in 
)

Definition at line 1053 of file udptl.c.

1054{
1055 struct ast_udptl *udptl;
1056 int x;
1057 int startplace;
1058 int i;
1060
1061 if (!cfg || !cfg->general) {
1062 ast_log(LOG_ERROR, "Could not access global udptl options!\n");
1063 return NULL;
1064 }
1065
1066 if (!(udptl = ast_calloc(1, sizeof(*udptl)))) {
1067 return NULL;
1068 }
1069
1070 udptl->error_correction_span = cfg->general->fecspan;
1071 udptl->error_correction_entries = cfg->general->fecentries;
1072
1073 udptl->far_max_datagram = -1;
1074 udptl->far_max_ifp = -1;
1075 udptl->local_max_ifp = -1;
1076 udptl->local_max_datagram = -1;
1077
1078 for (i = 0; i <= UDPTL_BUF_MASK; i++) {
1079 udptl->rx[i].buf_len = -1;
1080 udptl->tx[i].buf_len = -1;
1081 }
1082
1083 if ((udptl->fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(addr) ?
1084 AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) {
1085 ast_free(udptl);
1086 ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
1087 return NULL;
1088 }
1089
1090#ifdef SO_NO_CHECK
1091 if (cfg->general->nochecksums)
1092 setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &cfg->general->nochecksums, sizeof(cfg->general->nochecksums));
1093#endif
1094
1095 /* Find us a place */
1096 x = (cfg->general->start == cfg->general->end) ? cfg->general->start : (ast_random() % (cfg->general->end - cfg->general->start)) + cfg->general->start;
1097 if (cfg->general->use_even_ports && (x & 1)) {
1098 ++x;
1099 }
1100 startplace = x;
1101 for (;;) {
1102 ast_sockaddr_copy(&udptl->us, addr);
1103 ast_sockaddr_set_port(&udptl->us, x);
1104 if (ast_bind(udptl->fd, &udptl->us) == 0) {
1105 break;
1106 }
1107 if (errno != EADDRINUSE && errno != EACCES) {
1108 ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
1109 close(udptl->fd);
1110 ast_free(udptl);
1111 return NULL;
1112 }
1113 if (cfg->general->use_even_ports) {
1114 x += 2;
1115 } else {
1116 ++x;
1117 }
1118 if (x > cfg->general->end)
1119 x = cfg->general->start;
1120 if (x == startplace) {
1121 ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
1122 close(udptl->fd);
1123 ast_free(udptl);
1124 return NULL;
1125 }
1126 }
1127 if (io && sched && callbackmode) {
1128 /* Operate this one in a callback mode */
1129 udptl->sched = sched;
1130 udptl->io = io;
1131 udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
1132 }
1133
1134 return udptl;
1135}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
static struct console_pvt globals
static struct ast_sched_context * sched
Definition: chan_ooh323.c:400
static struct io_context * io
Definition: chan_ooh323.c:401
#define LOG_ERROR
#define LOG_WARNING
#define AST_IO_IN
Definition: io.h:34
int * ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events, void *data)
Adds an IO context.
Definition: io.c:162
int errno
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.
Definition: netsock2.c:524
int ast_bind(int sockfd, const struct ast_sockaddr *addr)
Wrapper around bind(2) that uses struct ast_sockaddr.
Definition: netsock2.c:590
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition: netsock2.h:532
#define NULL
Definition: resample.c:96
Structure for an UDPTL session.
Definition: udptl.c:181
struct ast_sched_context * sched
Definition: udptl.c:192
unsigned int error_correction_entries
Definition: udptl.c:206
int local_max_ifp
Definition: udptl.c:236
udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK+1]
Definition: udptl.c:242
unsigned int error_correction_span
Definition: udptl.c:211
udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK+1]
Definition: udptl.c:241
Definition: sched.c:76
#define UDPTL_BUF_MASK
Definition: udptl.c:164
static int udptlread(int *id, int fd, short events, void *cbdata)
Definition: udptl.c:775
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
#define ast_socket_nonblock(domain, type, protocol)
Create a non-blocking socket.
Definition: utils.h:1073
long int ast_random(void)
Definition: utils.c:2312

References ao2_cleanup, ao2_global_obj_ref, ast_bind(), ast_calloc, ast_free, ast_io_add(), AST_IO_IN, ast_log, ast_random(), ast_sockaddr_copy(), ast_sockaddr_is_ipv6(), ast_sockaddr_set_port, ast_socket_nonblock, 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::far_max_ifp, ast_udptl::fd, globals, io, ast_udptl::io, ast_udptl::ioid, ast_udptl::local_max_datagram, ast_udptl::local_max_ifp, LOG_ERROR, LOG_WARNING, NULL, RAII_VAR, ast_udptl::rx, sched, ast_udptl::sched, ast_udptl::tx, UDPTL_BUF_MASK, udptlread(), and ast_udptl::us.

Referenced by configure_local_rtp(), and t38_initialize_session().

◆ ast_udptl_read()

struct ast_frame * ast_udptl_read ( struct ast_udptl udptl)

Definition at line 787 of file udptl.c.

788{
789 int res;
790 struct ast_sockaddr addr;
791 uint8_t *buf;
792
794
795 /* Cache where the header will go */
796 res = ast_recvfrom(udptl->fd,
797 buf,
798 sizeof(udptl->rawdata) - AST_FRIENDLY_OFFSET,
799 0,
800 &addr);
801 if (res < 0) {
802 if (errno != EAGAIN)
803 ast_log(LOG_WARNING, "UDPTL (%s): read error: %s\n",
804 LOG_TAG(udptl), strerror(errno));
805 ast_assert(errno != EBADF);
806 return &ast_null_frame;
807 }
808
809 /* Ignore if the other side hasn't been given an address yet. */
810 if (ast_sockaddr_isnull(&udptl->them)) {
811 return &ast_null_frame;
812 }
813
814 /*
815 * If early media isn't turned on for the channel driver, it's going to
816 * drop this frame. By that time though, udptl has already incremented
817 * the expected sequence number so if the CPE re-sends, the second frame
818 * will be dropped as a dup even though the first frame never went through.
819 * So we drop the frame here if the channel isn't up. 'tag' is set by the
820 * channel drivers on T38_ENABLED or T38_PEER_REINVITE.
821 */
822 if (udptl->tag == NULL) {
823 return &ast_null_frame;
824 }
825
826 if (udptl->nat) {
827 /* Send to whoever sent to us */
828 if (ast_sockaddr_cmp(&udptl->them, &addr)) {
829 ast_sockaddr_copy(&udptl->them, &addr);
830 ast_debug(1, "UDPTL (%s): NAT, Using address %s\n",
831 LOG_TAG(udptl), ast_sockaddr_stringify(&udptl->them));
832 }
833 }
834
835 if (udptl_debug_test_addr(&addr)) {
836 int seq_no;
837
838 /* Decode sequence number just for verbose message. */
839 if (res < 2) {
840 /* Short packet. */
841 seq_no = -1;
842 } else {
843 seq_no = (buf[0] << 8) | buf[1];
844 }
845
846 ast_verb(1, "UDPTL (%s): packet from %s (seq %d, len %d)\n",
847 LOG_TAG(udptl), ast_sockaddr_stringify(&addr), seq_no, res);
848 }
849 if (udptl_rx_packet(udptl, buf, res) < 1) {
850 return &ast_null_frame;
851 }
852
853 return &udptl->f[0];
854}
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
struct ast_frame ast_null_frame
Definition: main/frame.c:79
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:256
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized,...
Definition: netsock2.h:127
ssize_t ast_recvfrom(int sockfd, void *buf, size_t len, int flags, struct ast_sockaddr *src_addr)
Wrapper around recvfrom(2) that uses struct ast_sockaddr.
Definition: netsock2.c:606
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:388
Socket address structure.
Definition: netsock2.h:97
unsigned char rawdata[8192+AST_FRIENDLY_OFFSET]
Definition: udptl.c:185
struct ast_frame f[16]
Definition: udptl.c:184
int nat
Definition: udptl.c:187
static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, unsigned int len)
Definition: udptl.c:406
#define LOG_TAG(u)
Definition: udptl.c:150
static int udptl_debug_test_addr(const struct ast_sockaddr *addr)
Definition: udptl.c:283
#define ast_assert(a)
Definition: utils.h:739

References ast_assert, ast_debug, AST_FRIENDLY_OFFSET, ast_log, ast_null_frame, ast_recvfrom(), ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_verb, buf, errno, ast_udptl::f, ast_udptl::fd, LOG_TAG, LOG_WARNING, ast_udptl::nat, NULL, ast_udptl::rawdata, ast_udptl::tag, ast_udptl::them, udptl_debug_test_addr(), and udptl_rx_packet().

Referenced by media_session_udptl_read_callback(), ooh323_rtp_read(), and udptlread().

◆ ast_udptl_reset()

void ast_udptl_reset ( struct ast_udptl udptl)

◆ ast_udptl_set_callback()

void ast_udptl_set_callback ( struct ast_udptl udptl,
ast_udptl_callback  callback 
)

Definition at line 765 of file udptl.c.

766{
767 udptl->callback = callback;
768}
ast_udptl_callback callback
Definition: udptl.c:196

References ast_udptl::callback.

◆ ast_udptl_set_data()

void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 760 of file udptl.c.

761{
762 udptl->data = data;
763}
void * data
Definition: udptl.c:194

References ast_udptl::data.

◆ ast_udptl_set_error_correction_scheme()

void ast_udptl_set_error_correction_scheme ( struct ast_udptl udptl,
enum ast_t38_ec_modes  ec 
)

Definition at line 970 of file udptl.c.

971{
972 udptl->error_correction_scheme = ec;
973 switch (ec) {
976 if (udptl->error_correction_entries == 0) {
977 udptl->error_correction_entries = 3;
978 }
979 if (udptl->error_correction_span == 0) {
980 udptl->error_correction_span = 3;
981 }
982 break;
985 if (udptl->error_correction_entries == 0) {
986 udptl->error_correction_entries = 3;
987 }
988 break;
989 default:
990 /* nothing to do */
991 break;
992 };
993 /* reset calculated values so they'll be computed again */
994 udptl->local_max_datagram = -1;
995 udptl->far_max_ifp = -1;
996}

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 t38_initialize_session(), and t38_interpret_sdp().

◆ ast_udptl_set_far_max_datagram()

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

1023{
1024 if (!max_datagram || (max_datagram > FAX_MAX_DATAGRAM_LIMIT)) {
1026 } else {
1027 udptl->far_max_datagram = max_datagram;
1028 }
1029 /* reset calculated values so they'll be computed again */
1030 udptl->far_max_ifp = -1;
1031}
#define DEFAULT_FAX_MAX_DATAGRAM
Definition: udptl.c:159
#define FAX_MAX_DATAGRAM_LIMIT
Definition: udptl.c:160

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

Referenced by configure_local_rtp(), onModeChanged(), t38_initialize_session(), and t38_interpret_sdp().

◆ ast_udptl_set_local_max_ifp()

void ast_udptl_set_local_max_ifp ( struct ast_udptl udptl,
unsigned int  max_ifp 
)

Definition at line 998 of file udptl.c.

999{
1000 /* make sure max_ifp is a positive value since a cast will take place when
1001 * when setting local_max_ifp */
1002 if ((signed int) max_ifp > 0) {
1003 udptl->local_max_ifp = max_ifp;
1004 /* reset calculated values so they'll be computed again */
1005 udptl->local_max_datagram = -1;
1006 }
1007}

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

Referenced by t38_interpret_parameters().

◆ ast_udptl_set_m_type()

void ast_udptl_set_m_type ( struct ast_udptl udptl,
unsigned int  pt 
)

◆ ast_udptl_set_peer()

void ast_udptl_set_peer ( struct ast_udptl udptl,
const struct ast_sockaddr them 
)

Definition at line 1155 of file udptl.c.

1156{
1157 ast_sockaddr_copy(&udptl->them, them);
1158}

References ast_sockaddr_copy(), and ast_udptl::them.

Referenced by apply_negotiated_sdp_stream(), and setup_udptl_connection().

◆ ast_udptl_set_tag()

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

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

Parameters
udptlThe UDPTL session.
formatprintf-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.

Definition at line 1137 of file udptl.c.

1138{
1139 va_list ap;
1140
1141 ast_free(udptl->tag);
1142 udptl->tag = NULL;
1143 va_start(ap, format);
1144 if (ast_vasprintf(&udptl->tag, format, ap) == -1) {
1145 udptl->tag = NULL;
1146 }
1147 va_end(ap);
1148}
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
Definition: astmm.h:278

References ast_free, ast_vasprintf, NULL, and ast_udptl::tag.

Referenced by setup_udptl_connection(), and t38_change_state().

◆ ast_udptl_set_udptlmap_type()

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

◆ ast_udptl_setnat()

void ast_udptl_setnat ( struct ast_udptl udptl,
int  nat 
)

Definition at line 770 of file udptl.c.

771{
772 udptl->nat = nat;
773}

References ast_udptl::nat.

Referenced by t38_initialize_session().

◆ ast_udptl_setqos()

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

Definition at line 1150 of file udptl.c.

1151{
1152 return ast_set_qos(udptl->fd, tos, cos, "UDPTL");
1153}
unsigned int tos
Definition: chan_iax2.c:379
unsigned int cos
Definition: chan_iax2.c:380
int ast_set_qos(int sockfd, int tos, int cos, const char *desc)
Set type of service.
Definition: netsock2.c:621

References ast_set_qos(), cos, ast_udptl::fd, and tos.

◆ ast_udptl_stop()

void ast_udptl_stop ( struct ast_udptl udptl)

Definition at line 1170 of file udptl.c.

1171{
1172 ast_sockaddr_setnull(&udptl->them);
1173}
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition: netsock2.h:138

References ast_sockaddr_setnull(), and ast_udptl::them.

◆ ast_udptl_write()

int ast_udptl_write ( struct ast_udptl udptl,
struct ast_frame f 
)

Definition at line 1186 of file udptl.c.

1187{
1188 unsigned int seq;
1189 unsigned int len = f->datalen;
1190 /* if no max datagram size is provided, use default value */
1191 const int bufsize = (s->far_max_datagram > 0) ? s->far_max_datagram : DEFAULT_FAX_MAX_DATAGRAM;
1192 uint8_t buf[bufsize];
1193
1194 memset(buf, 0, sizeof(buf));
1195
1196 /* If we have no peer, return immediately */
1197 if (ast_sockaddr_isnull(&s->them)) {
1198 return 0;
1199 }
1200
1201 /* If there is no data length, return immediately */
1202 if (f->datalen == 0)
1203 return 0;
1204
1205 if ((f->frametype != AST_FRAME_MODEM) ||
1206 (f->subclass.integer != AST_MODEM_T38)) {
1207 ast_log(LOG_WARNING, "UDPTL (%s): UDPTL can only send T.38 data.\n",
1208 LOG_TAG(s));
1209 return -1;
1210 }
1211
1212 if (len > s->far_max_ifp) {
1214 "UDPTL (%s): UDPTL asked to send %u bytes of IFP when far end only prepared to accept %d bytes; data loss will occur."
1215 "You may need to override the T38FaxMaxDatagram value for this endpoint in the channel driver configuration.\n",
1216 LOG_TAG(s), len, s->far_max_ifp);
1217 len = s->far_max_ifp;
1218 }
1219
1220 /* Save seq_no for debug output because udptl_build_packet increments it */
1221 seq = s->tx_seq_no & 0xFFFF;
1222
1223 /* Cook up the UDPTL packet, with the relevant EC info. */
1224 len = udptl_build_packet(s, buf, sizeof(buf), f->data.ptr, len);
1225
1226 if ((signed int) len > 0 && !ast_sockaddr_isnull(&s->them)) {
1227 if (ast_sendto(s->fd, buf, len, 0, &s->them) < 0) {
1228 ast_log(LOG_NOTICE, "UDPTL (%s): Transmission error to %s: %s\n",
1229 LOG_TAG(s), ast_sockaddr_stringify(&s->them), strerror(errno));
1230 }
1231 if (udptl_debug_test_addr(&s->them)) {
1232 ast_verb(1, "UDPTL (%s): packet to %s (seq %u, len %u)\n",
1233 LOG_TAG(s), ast_sockaddr_stringify(&s->them), seq, len);
1234 }
1235 }
1236
1237 return 0;
1238}
static volatile unsigned int seq
Definition: app_sms.c:123
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_MODEM_T38
@ AST_FRAME_MODEM
#define LOG_NOTICE
ssize_t ast_sendto(int sockfd, const void *buf, size_t len, int flags, const struct ast_sockaddr *dest_addr)
Wrapper around sendto(2) that uses ast_sockaddr.
Definition: netsock2.c:614
union ast_frame::@228 data
struct ast_frame_subclass subclass
enum ast_frame_type frametype
static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, unsigned int buflen, uint8_t *ifp, unsigned int ifp_len)
Definition: udptl.c:646

References AST_FRAME_MODEM, ast_log, AST_MODEM_T38, ast_sendto(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_verb, buf, ast_frame::data, ast_frame::datalen, DEFAULT_FAX_MAX_DATAGRAM, errno, ast_udptl::f, ast_udptl::far_max_datagram, ast_udptl::far_max_ifp, ast_udptl::fd, ast_frame::frametype, ast_frame_subclass::integer, len(), LOG_NOTICE, LOG_TAG, 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 media_session_udptl_write_callback(), and ooh323_write().