Asterisk - The Open Source Telephony Project GIT-master-650240a
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 1148 of file udptl.c.

1149{
1150 if (udptl->ioid)
1151 ast_io_remove(udptl->io, udptl->ioid);
1152 if (udptl->fd > -1)
1153 close(udptl->fd);
1154 if (udptl->tag)
1155 ast_free(udptl->tag);
1156 ast_free(udptl);
1157}
#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:164
int fd
Definition: udptl.c:155
char * tag
Definition: udptl.c:168
struct io_context * io
Definition: udptl.c:166

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

729{
730 return udptl->fd;
731}

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

939{
940 return udptl->error_correction_scheme;
941}
enum ast_t38_ec_modes error_correction_scheme
Definition: udptl.c:174

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

1007{
1008 if (udptl->far_max_datagram < 0) {
1009 return 0;
1010 }
1011 return udptl->far_max_datagram;
1012}
int far_max_datagram
Definition: udptl.c:189

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

1015{
1016 if (udptl->far_max_ifp == -1) {
1017 calculate_far_max_ifp(udptl);
1018 }
1019
1020 if (udptl->far_max_ifp < 0) {
1021 return 0;
1022 }
1023 return udptl->far_max_ifp;
1024}
int far_max_ifp
Definition: udptl.c:203
static void calculate_far_max_ifp(struct ast_udptl *udptl)
Definition: udptl.c:870

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

983{
984 if (udptl->local_max_datagram == -1) {
986 }
987
988 /* this function expects a unsigned value in return. */
989 if (udptl->local_max_datagram < 0) {
990 return 0;
991 }
992 return udptl->local_max_datagram;
993}
int local_max_datagram
Definition: udptl.c:195
static void calculate_local_max_datagram(struct ast_udptl *udptl)
Definition: udptl.c:829

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

1134{
1135 ast_sockaddr_copy(them, &udptl->them);
1136}
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:163

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

1139{
1140 ast_sockaddr_copy(us, &udptl->us);
1141}
struct ast_sockaddr us
Definition: udptl.c:162

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

1027{
1028 struct ast_udptl *udptl;
1029 int x;
1030 int startplace;
1031 int i;
1033
1034 if (!cfg || !cfg->general) {
1035 ast_log(LOG_ERROR, "Could not access global udptl options!\n");
1036 return NULL;
1037 }
1038
1039 if (!(udptl = ast_calloc(1, sizeof(*udptl)))) {
1040 return NULL;
1041 }
1042
1043 udptl->error_correction_span = cfg->general->fecspan;
1044 udptl->error_correction_entries = cfg->general->fecentries;
1045
1046 udptl->far_max_datagram = -1;
1047 udptl->far_max_ifp = -1;
1048 udptl->local_max_ifp = -1;
1049 udptl->local_max_datagram = -1;
1050
1051 for (i = 0; i <= UDPTL_BUF_MASK; i++) {
1052 udptl->rx[i].buf_len = -1;
1053 udptl->tx[i].buf_len = -1;
1054 }
1055
1056 if ((udptl->fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(addr) ?
1057 AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) {
1058 ast_free(udptl);
1059 ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
1060 return NULL;
1061 }
1062
1063#ifdef SO_NO_CHECK
1064 if (cfg->general->nochecksums)
1065 setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &cfg->general->nochecksums, sizeof(cfg->general->nochecksums));
1066#endif
1067
1068 /* Find us a place */
1069 x = (cfg->general->start == cfg->general->end) ? cfg->general->start : (ast_random() % (cfg->general->end - cfg->general->start)) + cfg->general->start;
1070 if (cfg->general->use_even_ports && (x & 1)) {
1071 ++x;
1072 }
1073 startplace = x;
1074 for (;;) {
1075 ast_sockaddr_copy(&udptl->us, addr);
1076 ast_sockaddr_set_port(&udptl->us, x);
1077 if (ast_bind(udptl->fd, &udptl->us) == 0) {
1078 break;
1079 }
1080 if (errno != EADDRINUSE && errno != EACCES) {
1081 ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
1082 close(udptl->fd);
1083 ast_free(udptl);
1084 return NULL;
1085 }
1086 if (cfg->general->use_even_ports) {
1087 x += 2;
1088 } else {
1089 ++x;
1090 }
1091 if (x > cfg->general->end)
1092 x = cfg->general->start;
1093 if (x == startplace) {
1094 ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
1095 close(udptl->fd);
1096 ast_free(udptl);
1097 return NULL;
1098 }
1099 }
1100 if (io && sched && callbackmode) {
1101 /* Operate this one in a callback mode */
1102 udptl->sched = sched;
1103 udptl->io = io;
1104 udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
1105 }
1106
1107 return udptl;
1108}
#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:154
struct ast_sched_context * sched
Definition: udptl.c:165
unsigned int error_correction_entries
Definition: udptl.c:179
int local_max_ifp
Definition: udptl.c:209
udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK+1]
Definition: udptl.c:215
unsigned int error_correction_span
Definition: udptl.c:184
udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK+1]
Definition: udptl.c:214
Definition: sched.c:76
#define UDPTL_BUF_MASK
Definition: udptl.c:137
static int udptlread(int *id, int fd, short events, void *cbdata)
Definition: udptl.c:748
#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 760 of file udptl.c.

761{
762 int res;
763 struct ast_sockaddr addr;
764 uint8_t *buf;
765
767
768 /* Cache where the header will go */
769 res = ast_recvfrom(udptl->fd,
770 buf,
771 sizeof(udptl->rawdata) - AST_FRIENDLY_OFFSET,
772 0,
773 &addr);
774 if (res < 0) {
775 if (errno != EAGAIN)
776 ast_log(LOG_WARNING, "UDPTL (%s): read error: %s\n",
777 LOG_TAG(udptl), strerror(errno));
778 ast_assert(errno != EBADF);
779 return &ast_null_frame;
780 }
781
782 /* Ignore if the other side hasn't been given an address yet. */
783 if (ast_sockaddr_isnull(&udptl->them)) {
784 return &ast_null_frame;
785 }
786
787 /*
788 * If early media isn't turned on for the channel driver, it's going to
789 * drop this frame. By that time though, udptl has already incremented
790 * the expected sequence number so if the CPE re-sends, the second frame
791 * will be dropped as a dup even though the first frame never went through.
792 * So we drop the frame here if the channel isn't up. 'tag' is set by the
793 * channel drivers on T38_ENABLED or T38_PEER_REINVITE.
794 */
795 if (udptl->tag == NULL) {
796 return &ast_null_frame;
797 }
798
799 if (udptl->nat) {
800 /* Send to whoever sent to us */
801 if (ast_sockaddr_cmp(&udptl->them, &addr)) {
802 ast_sockaddr_copy(&udptl->them, &addr);
803 ast_debug(1, "UDPTL (%s): NAT, Using address %s\n",
804 LOG_TAG(udptl), ast_sockaddr_stringify(&udptl->them));
805 }
806 }
807
808 if (udptl_debug_test_addr(&addr)) {
809 int seq_no;
810
811 /* Decode sequence number just for verbose message. */
812 if (res < 2) {
813 /* Short packet. */
814 seq_no = -1;
815 } else {
816 seq_no = (buf[0] << 8) | buf[1];
817 }
818
819 ast_verb(1, "UDPTL (%s): packet from %s (seq %d, len %d)\n",
820 LOG_TAG(udptl), ast_sockaddr_stringify(&addr), seq_no, res);
821 }
822 if (udptl_rx_packet(udptl, buf, res) < 1) {
823 return &ast_null_frame;
824 }
825
826 return &udptl->f[0];
827}
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:158
struct ast_frame f[16]
Definition: udptl.c:157
int nat
Definition: udptl.c:160
static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, unsigned int len)
Definition: udptl.c:379
#define LOG_TAG(u)
Definition: udptl.c:123
static int udptl_debug_test_addr(const struct ast_sockaddr *addr)
Definition: udptl.c:256
#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 738 of file udptl.c.

739{
740 udptl->callback = callback;
741}
ast_udptl_callback callback
Definition: udptl.c:169

References ast_udptl::callback.

◆ ast_udptl_set_data()

void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 733 of file udptl.c.

734{
735 udptl->data = data;
736}
void * data
Definition: udptl.c:167

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

944{
945 udptl->error_correction_scheme = ec;
946 switch (ec) {
949 if (udptl->error_correction_entries == 0) {
950 udptl->error_correction_entries = 3;
951 }
952 if (udptl->error_correction_span == 0) {
953 udptl->error_correction_span = 3;
954 }
955 break;
958 if (udptl->error_correction_entries == 0) {
959 udptl->error_correction_entries = 3;
960 }
961 break;
962 default:
963 /* nothing to do */
964 break;
965 };
966 /* reset calculated values so they'll be computed again */
967 udptl->local_max_datagram = -1;
968 udptl->far_max_ifp = -1;
969}

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

996{
997 if (!max_datagram || (max_datagram > FAX_MAX_DATAGRAM_LIMIT)) {
999 } else {
1000 udptl->far_max_datagram = max_datagram;
1001 }
1002 /* reset calculated values so they'll be computed again */
1003 udptl->far_max_ifp = -1;
1004}
#define DEFAULT_FAX_MAX_DATAGRAM
Definition: udptl.c:132
#define FAX_MAX_DATAGRAM_LIMIT
Definition: udptl.c:133

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

972{
973 /* make sure max_ifp is a positive value since a cast will take place when
974 * when setting local_max_ifp */
975 if ((signed int) max_ifp > 0) {
976 udptl->local_max_ifp = max_ifp;
977 /* reset calculated values so they'll be computed again */
978 udptl->local_max_datagram = -1;
979 }
980}

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

1129{
1130 ast_sockaddr_copy(&udptl->them, them);
1131}

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

1111{
1112 va_list ap;
1113
1114 ast_free(udptl->tag);
1115 udptl->tag = NULL;
1116 va_start(ap, format);
1117 if (ast_vasprintf(&udptl->tag, format, ap) == -1) {
1118 udptl->tag = NULL;
1119 }
1120 va_end(ap);
1121}
#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 743 of file udptl.c.

744{
745 udptl->nat = nat;
746}

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

1124{
1125 return ast_set_qos(udptl->fd, tos, cos, "UDPTL");
1126}
unsigned int tos
Definition: chan_iax2.c:358
unsigned int cos
Definition: chan_iax2.c:359
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 1143 of file udptl.c.

1144{
1145 ast_sockaddr_setnull(&udptl->them);
1146}
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 1159 of file udptl.c.

1160{
1161 unsigned int seq;
1162 unsigned int len = f->datalen;
1163 /* if no max datagram size is provided, use default value */
1164 const int bufsize = (s->far_max_datagram > 0) ? s->far_max_datagram : DEFAULT_FAX_MAX_DATAGRAM;
1165 uint8_t buf[bufsize];
1166
1167 memset(buf, 0, sizeof(buf));
1168
1169 /* If we have no peer, return immediately */
1170 if (ast_sockaddr_isnull(&s->them)) {
1171 return 0;
1172 }
1173
1174 /* If there is no data length, return immediately */
1175 if (f->datalen == 0)
1176 return 0;
1177
1178 if ((f->frametype != AST_FRAME_MODEM) ||
1179 (f->subclass.integer != AST_MODEM_T38)) {
1180 ast_log(LOG_WARNING, "UDPTL (%s): UDPTL can only send T.38 data.\n",
1181 LOG_TAG(s));
1182 return -1;
1183 }
1184
1185 if (len > s->far_max_ifp) {
1187 "UDPTL (%s): UDPTL asked to send %u bytes of IFP when far end only prepared to accept %d bytes; data loss will occur."
1188 "You may need to override the T38FaxMaxDatagram value for this endpoint in the channel driver configuration.\n",
1189 LOG_TAG(s), len, s->far_max_ifp);
1190 len = s->far_max_ifp;
1191 }
1192
1193 /* Save seq_no for debug output because udptl_build_packet increments it */
1194 seq = s->tx_seq_no & 0xFFFF;
1195
1196 /* Cook up the UDPTL packet, with the relevant EC info. */
1197 len = udptl_build_packet(s, buf, sizeof(buf), f->data.ptr, len);
1198
1199 if ((signed int) len > 0 && !ast_sockaddr_isnull(&s->them)) {
1200 if (ast_sendto(s->fd, buf, len, 0, &s->them) < 0) {
1201 ast_log(LOG_NOTICE, "UDPTL (%s): Transmission error to %s: %s\n",
1202 LOG_TAG(s), ast_sockaddr_stringify(&s->them), strerror(errno));
1203 }
1204 if (udptl_debug_test_addr(&s->them)) {
1205 ast_verb(1, "UDPTL (%s): packet to %s (seq %u, len %u)\n",
1206 LOG_TAG(s), ast_sockaddr_stringify(&s->them), seq, len);
1207 }
1208 }
1209
1210 return 0;
1211}
static volatile unsigned int seq
Definition: app_sms.c:120
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
struct ast_frame_subclass subclass
union ast_frame::@226 data
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:619

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