Asterisk - The Open Source Telephony Project  18.5.0
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.

Function Documentation

◆ ast_udptl_destroy()

void ast_udptl_destroy ( struct ast_udptl udptl)

Definition at line 1150 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 ooh323_destroy(), sip_pvt_dtor(), and stream_destroy().

1151 {
1152  if (udptl->ioid)
1153  ast_io_remove(udptl->io, udptl->ioid);
1154  if (udptl->fd > -1)
1155  close(udptl->fd);
1156  if (udptl->tag)
1157  ast_free(udptl->tag);
1158  ast_free(udptl);
1159 }
int fd
Definition: udptl.c:157
int * ioid
Definition: udptl.c:166
char * tag
Definition: udptl.c:170
struct io_context * io
Definition: udptl.c:168
#define ast_free(a)
Definition: astmm.h:182
int ast_io_remove(struct io_context *ioc, int *id)
Removes an IO context.
Definition: io.c:245

◆ ast_udptl_fd()

int ast_udptl_fd ( const struct ast_udptl udptl)

Definition at line 730 of file udptl.c.

References ast_udptl::fd.

Referenced by apply_negotiated_sdp_stream(), configure_local_rtp(), initialize_udptl(), and sip_new().

731 {
732  return udptl->fd;
733 }
int fd
Definition: udptl.c:157

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

References ast_udptl::error_correction_scheme.

Referenced by add_sdp(), and create_outgoing_sdp_stream().

941 {
942  return udptl->error_correction_scheme;
943 }
enum ast_t38_ec_modes error_correction_scheme
Definition: udptl.c:176

◆ ast_udptl_get_far_max_datagram()

unsigned int ast_udptl_get_far_max_datagram ( const struct ast_udptl udptl)

Definition at line 1008 of file udptl.c.

References ast_udptl::far_max_datagram.

Referenced by process_sdp().

1009 {
1010  if (udptl->far_max_datagram < 0) {
1011  return 0;
1012  }
1013  return udptl->far_max_datagram;
1014 }
int far_max_datagram
Definition: udptl.c:191

◆ ast_udptl_get_far_max_ifp()

unsigned int ast_udptl_get_far_max_ifp ( struct ast_udptl udptl)

retrieves far max ifp

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

Definition at line 1016 of file udptl.c.

References calculate_far_max_ifp(), and ast_udptl::far_max_ifp.

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

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

◆ ast_udptl_get_local_max_datagram()

unsigned int ast_udptl_get_local_max_datagram ( struct ast_udptl udptl)

retrieves local_max_datagram.

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

Definition at line 984 of file udptl.c.

References calculate_local_max_datagram(), and ast_udptl::local_max_datagram.

Referenced by add_sdp(), and create_outgoing_sdp_stream().

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

◆ ast_udptl_get_peer()

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

Definition at line 1135 of file udptl.c.

References ast_sockaddr_copy(), and ast_udptl::them.

1136 {
1137  ast_sockaddr_copy(them, &udptl->them);
1138 }
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:171
struct ast_sockaddr them
Definition: udptl.c:165

◆ ast_udptl_get_us()

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

Definition at line 1140 of file udptl.c.

References ast_sockaddr_copy(), and ast_udptl::us.

Referenced by add_sdp(), configure_local_rtp(), and create_outgoing_sdp_stream().

1141 {
1142  ast_sockaddr_copy(us, &udptl->us);
1143 }
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:171
struct ast_sockaddr us
Definition: udptl.c:164

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

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, ast_udptl::io, io, ast_udptl::ioid, ast_udptl::local_max_datagram, ast_udptl::local_max_ifp, LOG_ERROR, LOG_WARNING, NULL, RAII_VAR, ast_udptl::rx, ast_udptl::sched, sched, ast_udptl::tx, UDPTL_BUF_MASK, udptlread(), and ast_udptl::us.

Referenced by configure_local_rtp(), initialize_udptl(), and t38_initialize_session().

1029 {
1030  struct ast_udptl *udptl;
1031  int x;
1032  int startplace;
1033  int i;
1035 
1036  if (!cfg || !cfg->general) {
1037  ast_log(LOG_ERROR, "Could not access global udptl options!\n");
1038  return NULL;
1039  }
1040 
1041  if (!(udptl = ast_calloc(1, sizeof(*udptl)))) {
1042  return NULL;
1043  }
1044 
1045  udptl->error_correction_span = cfg->general->fecspan;
1046  udptl->error_correction_entries = cfg->general->fecentries;
1047 
1048  udptl->far_max_datagram = -1;
1049  udptl->far_max_ifp = -1;
1050  udptl->local_max_ifp = -1;
1051  udptl->local_max_datagram = -1;
1052 
1053  for (i = 0; i <= UDPTL_BUF_MASK; i++) {
1054  udptl->rx[i].buf_len = -1;
1055  udptl->tx[i].buf_len = -1;
1056  }
1057 
1058  if ((udptl->fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(addr) ?
1059  AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) {
1060  ast_free(udptl);
1061  ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
1062  return NULL;
1063  }
1064 
1065 #ifdef SO_NO_CHECK
1066  if (cfg->general->nochecksums)
1067  setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &cfg->general->nochecksums, sizeof(cfg->general->nochecksums));
1068 #endif
1069 
1070  /* Find us a place */
1071  x = (cfg->general->start == cfg->general->end) ? cfg->general->start : (ast_random() % (cfg->general->end - cfg->general->start)) + cfg->general->start;
1072  if (cfg->general->use_even_ports && (x & 1)) {
1073  ++x;
1074  }
1075  startplace = x;
1076  for (;;) {
1077  ast_sockaddr_copy(&udptl->us, addr);
1078  ast_sockaddr_set_port(&udptl->us, x);
1079  if (ast_bind(udptl->fd, &udptl->us) == 0) {
1080  break;
1081  }
1082  if (errno != EADDRINUSE && errno != EACCES) {
1083  ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
1084  close(udptl->fd);
1085  ast_free(udptl);
1086  return NULL;
1087  }
1088  if (cfg->general->use_even_ports) {
1089  x += 2;
1090  } else {
1091  ++x;
1092  }
1093  if (x > cfg->general->end)
1094  x = cfg->general->start;
1095  if (x == startplace) {
1096  ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
1097  close(udptl->fd);
1098  ast_free(udptl);
1099  return NULL;
1100  }
1101  }
1102  if (io && sched && callbackmode) {
1103  /* Operate this one in a callback mode */
1104  udptl->sched = sched;
1105  udptl->io = io;
1106  udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
1107  }
1108 
1109  return udptl;
1110 }
int fd
Definition: udptl.c:157
static struct ast_sched_context * sched
Definition: chan_ooh323.c:400
unsigned int error_correction_span
Definition: udptl.c:186
int local_max_datagram
Definition: udptl.c:197
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:171
#define LOG_WARNING
Definition: logger.h:274
#define ast_socket_nonblock(domain, type, protocol)
Create a non-blocking socket.
Definition: utils.h:1043
int * ioid
Definition: udptl.c:166
#define AST_IO_IN
Definition: io.h:34
Structure for an UDPTL session.
Definition: udptl.c:156
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
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
unsigned int error_correction_entries
Definition: udptl.c:181
#define NULL
Definition: resample.c:96
struct ast_sockaddr us
Definition: udptl.c:164
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_log
Definition: astobj2.c:42
#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:911
int far_max_datagram
Definition: udptl.c:191
struct ast_sched_context * sched
Definition: udptl.c:167
static struct io_context * io
Definition: chan_ooh323.c:401
udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK+1]
Definition: udptl.c:217
long int ast_random(void)
Definition: main/utils.c:2064
static struct console_pvt globals
static int udptlread(int *id, int fd, short events, void *cbdata)
Definition: udptl.c:750
#define LOG_ERROR
Definition: logger.h:285
struct io_context * io
Definition: udptl.c:168
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition: netsock2.h:537
int errno
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
int far_max_ifp
Definition: udptl.c:205
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
int local_max_ifp
Definition: udptl.c:211
udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK+1]
Definition: udptl.c:216
#define UDPTL_BUF_MASK
Definition: udptl.c:139
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.
Definition: netsock2.c:524

◆ ast_udptl_read()

struct ast_frame* ast_udptl_read ( struct ast_udptl udptl)

Definition at line 762 of file udptl.c.

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(), sip_rtp_read(), skinny_rtp_read(), and udptlread().

763 {
764  int res;
765  struct ast_sockaddr addr;
766  uint8_t *buf;
767 
768  buf = udptl->rawdata + AST_FRIENDLY_OFFSET;
769 
770  /* Cache where the header will go */
771  res = ast_recvfrom(udptl->fd,
772  buf,
773  sizeof(udptl->rawdata) - AST_FRIENDLY_OFFSET,
774  0,
775  &addr);
776  if (res < 0) {
777  if (errno != EAGAIN)
778  ast_log(LOG_WARNING, "UDPTL (%s): read error: %s\n",
779  LOG_TAG(udptl), strerror(errno));
780  ast_assert(errno != EBADF);
781  return &ast_null_frame;
782  }
783 
784  /* Ignore if the other side hasn't been given an address yet. */
785  if (ast_sockaddr_isnull(&udptl->them)) {
786  return &ast_null_frame;
787  }
788 
789  /*
790  * If early media isn't turned on for the channel driver, it's going to
791  * drop this frame. By that time though, udptl has already incremented
792  * the expected sequence number so if the CPE re-sends, the second frame
793  * will be dropped as a dup even though the first frame never went through.
794  * So we drop the frame here if the channel isn't up. 'tag' is set by the
795  * channel drivers on T38_ENABLED or T38_PEER_REINVITE.
796  */
797  if (udptl->tag == NULL) {
798  return &ast_null_frame;
799  }
800 
801  if (udptl->nat) {
802  /* Send to whoever sent to us */
803  if (ast_sockaddr_cmp(&udptl->them, &addr)) {
804  ast_sockaddr_copy(&udptl->them, &addr);
805  ast_debug(1, "UDPTL (%s): NAT, Using address %s\n",
806  LOG_TAG(udptl), ast_sockaddr_stringify(&udptl->them));
807  }
808  }
809 
810  if (udptl_debug_test_addr(&addr)) {
811  int seq_no;
812 
813  /* Decode sequence number just for verbose message. */
814  if (res < 2) {
815  /* Short packet. */
816  seq_no = -1;
817  } else {
818  seq_no = (buf[0] << 8) | buf[1];
819  }
820 
821  ast_verb(1, "UDPTL (%s): packet from %s (seq %d, len %d)\n",
822  LOG_TAG(udptl), ast_sockaddr_stringify(&addr), seq_no, res);
823  }
824  if (udptl_rx_packet(udptl, buf, res) < 1) {
825  return &ast_null_frame;
826  }
827 
828  return &udptl->f[0];
829 }
int fd
Definition: udptl.c:157
int nat
Definition: udptl.c:162
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:171
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
char * tag
Definition: udptl.c:170
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:388
static int udptl_debug_test_addr(const struct ast_sockaddr *addr)
Definition: udptl.c:258
Socket address structure.
Definition: netsock2.h:97
#define ast_verb(level,...)
Definition: logger.h:463
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized, or having a 0 length.
Definition: netsock2.h:127
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
struct ast_sockaddr them
Definition: udptl.c:165
#define LOG_TAG(u)
Definition: udptl.c:125
int errno
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:260
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
struct ast_frame f[16]
Definition: udptl.c:159
struct ast_frame ast_null_frame
Definition: main/frame.c:79
unsigned char rawdata[8192+AST_FRIENDLY_OFFSET]
Definition: udptl.c:160
static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, unsigned int len)
Definition: udptl.c:381

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

References ast_udptl::callback.

741 {
742  udptl->callback = callback;
743 }
ast_udptl_callback callback
Definition: udptl.c:171

◆ ast_udptl_set_data()

void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 735 of file udptl.c.

References ast_udptl::data.

736 {
737  udptl->data = data;
738 }
void * data
Definition: udptl.c:169

◆ 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 945 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(), process_sdp_a_image(), set_t38_capabilities(), t38_initialize_session(), and t38_interpret_sdp().

946 {
947  udptl->error_correction_scheme = ec;
948  switch (ec) {
951  if (udptl->error_correction_entries == 0) {
952  udptl->error_correction_entries = 3;
953  }
954  if (udptl->error_correction_span == 0) {
955  udptl->error_correction_span = 3;
956  }
957  break;
960  if (udptl->error_correction_entries == 0) {
961  udptl->error_correction_entries = 3;
962  }
963  break;
964  default:
965  /* nothing to do */
966  break;
967  };
968  /* reset calculated values so they'll be computed again */
969  udptl->local_max_datagram = -1;
970  udptl->far_max_ifp = -1;
971 }
unsigned int error_correction_span
Definition: udptl.c:186
int local_max_datagram
Definition: udptl.c:197
unsigned int error_correction_entries
Definition: udptl.c:181
int far_max_ifp
Definition: udptl.c:205
enum ast_t38_ec_modes error_correction_scheme
Definition: udptl.c:176

◆ 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 997 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 configure_local_rtp(), onModeChanged(), process_sdp(), process_sdp_a_image(), t38_initialize_session(), and t38_interpret_sdp().

998 {
999  if (!max_datagram || (max_datagram > FAX_MAX_DATAGRAM_LIMIT)) {
1001  } else {
1002  udptl->far_max_datagram = max_datagram;
1003  }
1004  /* reset calculated values so they'll be computed again */
1005  udptl->far_max_ifp = -1;
1006 }
int far_max_datagram
Definition: udptl.c:191
int far_max_ifp
Definition: udptl.c:205
#define FAX_MAX_DATAGRAM_LIMIT
Definition: udptl.c:135
#define DEFAULT_FAX_MAX_DATAGRAM
Definition: udptl.c:134

◆ ast_udptl_set_local_max_ifp()

void ast_udptl_set_local_max_ifp ( struct ast_udptl udptl,
unsigned int  max_ifp 
)

Definition at line 973 of file udptl.c.

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

Referenced by interpret_t38_parameters(), and t38_interpret_parameters().

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

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

References ast_sockaddr_copy(), and ast_udptl::them.

Referenced by apply_negotiated_sdp_stream(), process_sdp(), and setup_udptl_connection().

1131 {
1132  ast_sockaddr_copy(&udptl->them, them);
1133 }
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:171
struct ast_sockaddr them
Definition: udptl.c:165

◆ 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.

Return values
none

Definition at line 1112 of file udptl.c.

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

Referenced by change_t38_state(), setup_udptl_connection(), and t38_change_state().

1113 {
1114  va_list ap;
1115 
1116  ast_free(udptl->tag);
1117  udptl->tag = NULL;
1118  va_start(ap, format);
1119  if (ast_vasprintf(&udptl->tag, format, ap) == -1) {
1120  udptl->tag = NULL;
1121  }
1122  va_end(ap);
1123 }
char * tag
Definition: udptl.c:170
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
Definition: astmm.h:280
#define NULL
Definition: resample.c:96
#define ast_free(a)
Definition: astmm.h:182
static snd_pcm_format_t format
Definition: chan_alsa.c:102

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

References ast_udptl::nat, and nat.

Referenced by do_setnat(), initialize_udptl(), and t38_initialize_session().

746 {
747  udptl->nat = nat;
748 }
int nat
Definition: udptl.c:162
static int nat
Definition: chan_mgcp.c:168

◆ ast_udptl_setqos()

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

Definition at line 1125 of file udptl.c.

References ast_set_qos(), and ast_udptl::fd.

Referenced by initialize_udptl().

1126 {
1127  return ast_set_qos(udptl->fd, tos, cos, "UDPTL");
1128 }
int fd
Definition: udptl.c:157
unsigned int cos
Definition: chan_iax2.c:352
unsigned int tos
Definition: chan_iax2.c:351
int ast_set_qos(int sockfd, int tos, int cos, const char *desc)
Set type of service.
Definition: netsock2.c:621

◆ ast_udptl_stop()

void ast_udptl_stop ( struct ast_udptl udptl)

Definition at line 1145 of file udptl.c.

References ast_sockaddr_setnull(), and ast_udptl::them.

Referenced by process_sdp(), and stop_media_flows().

1146 {
1147  ast_sockaddr_setnull(&udptl->them);
1148 }
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition: netsock2.h:140
struct ast_sockaddr them
Definition: udptl.c:165

◆ ast_udptl_write()

int ast_udptl_write ( struct ast_udptl udptl,
struct ast_frame f 
)

Definition at line 1161 of file udptl.c.

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::far_max_datagram, ast_udptl::far_max_ifp, ast_udptl::fd, ast_frame::frametype, ast_frame_subclass::integer, ast_sockaddr::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(), ooh323_write(), and sip_write().

1162 {
1163  unsigned int seq;
1164  unsigned int len = f->datalen;
1165  /* if no max datagram size is provided, use default value */
1166  const int bufsize = (s->far_max_datagram > 0) ? s->far_max_datagram : DEFAULT_FAX_MAX_DATAGRAM;
1167  uint8_t buf[bufsize];
1168 
1169  memset(buf, 0, sizeof(buf));
1170 
1171  /* If we have no peer, return immediately */
1172  if (ast_sockaddr_isnull(&s->them)) {
1173  return 0;
1174  }
1175 
1176  /* If there is no data length, return immediately */
1177  if (f->datalen == 0)
1178  return 0;
1179 
1180  if ((f->frametype != AST_FRAME_MODEM) ||
1181  (f->subclass.integer != AST_MODEM_T38)) {
1182  ast_log(LOG_WARNING, "UDPTL (%s): UDPTL can only send T.38 data.\n",
1183  LOG_TAG(s));
1184  return -1;
1185  }
1186 
1187  if (len > s->far_max_ifp) {
1189  "UDPTL (%s): UDPTL asked to send %u bytes of IFP when far end only prepared to accept %d bytes; data loss will occur."
1190  "You may need to override the T38FaxMaxDatagram value for this endpoint in the channel driver configuration.\n",
1191  LOG_TAG(s), len, s->far_max_ifp);
1192  len = s->far_max_ifp;
1193  }
1194 
1195  /* Save seq_no for debug output because udptl_build_packet increments it */
1196  seq = s->tx_seq_no & 0xFFFF;
1197 
1198  /* Cook up the UDPTL packet, with the relevant EC info. */
1199  len = udptl_build_packet(s, buf, sizeof(buf), f->data.ptr, len);
1200 
1201  if ((signed int) len > 0 && !ast_sockaddr_isnull(&s->them)) {
1202  if (ast_sendto(s->fd, buf, len, 0, &s->them) < 0) {
1203  ast_log(LOG_NOTICE, "UDPTL (%s): Transmission error to %s: %s\n",
1204  LOG_TAG(s), ast_sockaddr_stringify(&s->them), strerror(errno));
1205  }
1206  if (udptl_debug_test_addr(&s->them)) {
1207  ast_verb(1, "UDPTL (%s): packet to %s (seq %u, len %u)\n",
1208  LOG_TAG(s), ast_sockaddr_stringify(&s->them), seq, len);
1209  }
1210  }
1211 
1212  return 0;
1213 }
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
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
static int udptl_debug_test_addr(const struct ast_sockaddr *addr)
Definition: udptl.c:258
#define ast_verb(level,...)
Definition: logger.h:463
struct ast_frame_subclass subclass
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized, or having a 0 length.
Definition: netsock2.h:127
#define ast_log
Definition: astobj2.c:42
#define LOG_TAG(u)
Definition: udptl.c:125
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int errno
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:260
#define LOG_NOTICE
Definition: logger.h:263
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:621
static volatile unsigned int seq
Definition: app_sms.c:120
#define AST_MODEM_T38
union ast_frame::@263 data
enum ast_frame_type frametype
#define DEFAULT_FAX_MAX_DATAGRAM
Definition: udptl.c:134