Wed Jan 8 2020 09:50:21

Asterisk developer's documentation


udptl.h File Reference

UDPTL support for T.38. More...

#include "asterisk/network.h"
#include "asterisk/frame.h"
#include "asterisk/io.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/netsock2.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 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)
 
void ast_udptl_init (void)
 
struct ast_udptlast_udptl_new_with_bindaddr (struct sched_context *sched, struct io_context *io, int callbackmode, struct ast_sockaddr *in)
 
int ast_udptl_proto_register (struct ast_udptl_protocol *proto)
 
void ast_udptl_proto_unregister (struct ast_udptl_protocol *proto)
 
struct ast_frameast_udptl_read (struct ast_udptl *udptl)
 
int ast_udptl_reload (void)
 
void ast_udptl_reset (struct ast_udptl *udptl)
 
void ast_udptl_set_callback (struct ast_udptl *udptl, ast_udptl_callback callback)
 
void ast_udptl_set_data (struct ast_udptl *udptl, void *data)
 
void ast_udptl_set_error_correction_scheme (struct ast_udptl *udptl, enum ast_t38_ec_modes ec)
 
void ast_udptl_set_far_max_datagram (struct ast_udptl *udptl, unsigned int max_datagram)
 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

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

Definition at line 58 of file udptl.h.

Enumeration Type Documentation

Enumerator
UDPTL_ERROR_CORRECTION_NONE 
UDPTL_ERROR_CORRECTION_FEC 
UDPTL_ERROR_CORRECTION_REDUNDANCY 

Definition at line 37 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 1146 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_log(), ast_read(), ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_stringify(), ast_udptl_get_peer(), ast_waitfor_n(), ast_write(), f, ast_frame::frametype, get_proto(), ast_udptl_protocol::get_udptl_info, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::name, ast_udptl_protocol::set_udptl_peer, and ast_channel::tech_pvt.

1147 {
1148  struct ast_frame *f;
1149  struct ast_channel *who;
1150  struct ast_channel *cs[3];
1151  struct ast_udptl *p0;
1152  struct ast_udptl *p1;
1153  struct ast_udptl_protocol *pr0;
1154  struct ast_udptl_protocol *pr1;
1155  struct ast_sockaddr ac0;
1156  struct ast_sockaddr ac1;
1157  struct ast_sockaddr t0;
1158  struct ast_sockaddr t1;
1159  void *pvt0;
1160  void *pvt1;
1161  int to;
1162 
1163  ast_channel_lock(c0);
1164  while (ast_channel_trylock(c1)) {
1165  ast_channel_unlock(c0);
1166  usleep(1);
1167  ast_channel_lock(c0);
1168  }
1169  pr0 = get_proto(c0);
1170  pr1 = get_proto(c1);
1171  if (!pr0) {
1172  ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name);
1173  ast_channel_unlock(c0);
1174  ast_channel_unlock(c1);
1175  return -1;
1176  }
1177  if (!pr1) {
1178  ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name);
1179  ast_channel_unlock(c0);
1180  ast_channel_unlock(c1);
1181  return -1;
1182  }
1183  pvt0 = c0->tech_pvt;
1184  pvt1 = c1->tech_pvt;
1185  p0 = pr0->get_udptl_info(c0);
1186  p1 = pr1->get_udptl_info(c1);
1187  if (!p0 || !p1) {
1188  /* Somebody doesn't want to play... */
1189  ast_channel_unlock(c0);
1190  ast_channel_unlock(c1);
1191  return -2;
1192  }
1193  if (pr0->set_udptl_peer(c0, p1)) {
1194  ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
1195  memset(&ac1, 0, sizeof(ac1));
1196  } else {
1197  /* Store UDPTL peer */
1198  ast_udptl_get_peer(p1, &ac1);
1199  }
1200  if (pr1->set_udptl_peer(c1, p0)) {
1201  ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name);
1202  memset(&ac0, 0, sizeof(ac0));
1203  } else {
1204  /* Store UDPTL peer */
1205  ast_udptl_get_peer(p0, &ac0);
1206  }
1207  ast_channel_unlock(c0);
1208  ast_channel_unlock(c1);
1209  cs[0] = c0;
1210  cs[1] = c1;
1211  cs[2] = NULL;
1212  for (;;) {
1213  if ((c0->tech_pvt != pvt0) ||
1214  (c1->tech_pvt != pvt1) ||
1215  (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
1216  ast_debug(1, "Oooh, something is weird, backing out\n");
1217  /* Tell it to try again later */
1218  return -3;
1219  }
1220  to = -1;
1221  ast_udptl_get_peer(p1, &t1);
1222  ast_udptl_get_peer(p0, &t0);
1223  if (ast_sockaddr_cmp(&t1, &ac1)) {
1224  ast_debug(1, "Oooh, '%s' changed end address to %s\n",
1225  c1->name, ast_sockaddr_stringify(&t1));
1226  ast_debug(1, "Oooh, '%s' was %s\n",
1227  c1->name, ast_sockaddr_stringify(&ac1));
1228  ast_sockaddr_copy(&ac1, &t1);
1229  }
1230  if (ast_sockaddr_cmp(&t0, &ac0)) {
1231  ast_debug(1, "Oooh, '%s' changed end address to %s\n",
1232  c0->name, ast_sockaddr_stringify(&t0));
1233  ast_debug(1, "Oooh, '%s' was %s\n",
1234  c0->name, ast_sockaddr_stringify(&ac0));
1235  ast_sockaddr_copy(&ac0, &t0);
1236  }
1237  who = ast_waitfor_n(cs, 2, &to);
1238  if (!who) {
1239  ast_debug(1, "Ooh, empty read...\n");
1240  /* check for hangup / whentohangup */
1241  if (ast_check_hangup(c0) || ast_check_hangup(c1))
1242  break;
1243  continue;
1244  }
1245  f = ast_read(who);
1246  if (!f) {
1247  *fo = f;
1248  *rc = who;
1249  ast_debug(1, "Oooh, got a %s\n", f ? "digit" : "hangup");
1250  /* That's all we needed */
1251  return 0;
1252  } else {
1253  if (f->frametype == AST_FRAME_MODEM) {
1254  /* Forward T.38 frames if they happen upon us */
1255  if (who == c0) {
1256  ast_write(c1, f);
1257  } else if (who == c1) {
1258  ast_write(c0, f);
1259  }
1260  }
1261  ast_frfree(f);
1262  }
1263  /* Swap priority. Not that it's a big deal at this point */
1264  cs[2] = cs[0];
1265  cs[0] = cs[1];
1266  cs[1] = cs[2];
1267  }
1268  return -1;
1269 }
struct ast_channel * ast_waitfor_n(struct ast_channel **chan, int n, int *ms)
Waits for input on a group of channels Wait for input on an array of channels for a given # of millis...
Definition: channel.c:3534
struct ast_channel * masqr
Definition: channel.h:752
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
struct ast_channel * masq
Definition: channel.h:751
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:121
void * tech_pvt
Definition: channel.h:744
#define LOG_WARNING
Definition: logger.h:144
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4383
int(*const set_udptl_peer)(struct ast_channel *chan, struct ast_udptl *peer)
Set UDPTL peer.
Definition: udptl.h:51
Structure for an UDPTL session.
Definition: udptl.c:119
void ast_udptl_get_peer(const struct ast_udptl *udptl, struct ast_sockaddr *them)
Definition: udptl.c:1029
struct ast_udptl *(* get_udptl_info)(struct ast_channel *chan)
Get UDPTL struct, or NULL if unwilling to transfer.
Definition: udptl.h:49
static struct ast_udptl_protocol * get_proto(struct ast_channel *chan)
Definition: udptl.c:1132
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:300
Socket address structure.
Definition: netsock2.h:63
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:806
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:210
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static struct ast_format f[]
Definition: format_g726.c:181
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:4916
Data structure associated with a single frame of data.
Definition: frame.h:142
enum ast_frame_type frametype
Definition: frame.h:144
#define ast_channel_trylock(chan)
Definition: channel.h:2468
#define ast_frfree(fr)
Definition: frame.h:583
static uint16_t t1
Definition: res_pktccops.c:159
void ast_udptl_destroy ( struct ast_udptl udptl)

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

1045 {
1046  if (udptl->ioid)
1047  ast_io_remove(udptl->io, udptl->ioid);
1048  if (udptl->fd > -1)
1049  close(udptl->fd);
1050  if (udptl->tag)
1051  ast_free(udptl->tag);
1052  ast_free(udptl);
1053 }
int fd
Definition: udptl.c:120
int * ioid
Definition: udptl.c:129
char * tag
Definition: udptl.c:133
struct io_context * io
Definition: udptl.c:131
#define ast_free(a)
Definition: astmm.h:97
int ast_io_remove(struct io_context *ioc, int *id)
Removes an IO context.
Definition: io.c:240
int ast_udptl_fd ( const struct ast_udptl udptl)

Definition at line 643 of file udptl.c.

References ast_udptl::fd.

Referenced by __oh323_new(), initialize_udptl(), and sip_new().

644 {
645  return udptl->fd;
646 }
int fd
Definition: udptl.c:120
enum ast_t38_ec_modes ast_udptl_get_error_correction_scheme ( const struct ast_udptl udptl)

Definition at line 841 of file udptl.c.

References ast_udptl::error_correction_scheme.

Referenced by add_sdp().

842 {
843  return udptl->error_correction_scheme;
844 }
enum ast_t38_ec_modes error_correction_scheme
Definition: udptl.c:139
unsigned int ast_udptl_get_far_max_datagram ( const struct ast_udptl udptl)

Definition at line 909 of file udptl.c.

References ast_udptl::far_max_datagram.

Referenced by process_sdp().

910 {
911  if (udptl->far_max_datagram < 0) {
912  return 0;
913  }
914  return udptl->far_max_datagram;
915 }
int far_max_datagram
Definition: udptl.c:154
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 917 of file udptl.c.

References calculate_far_max_ifp(), and ast_udptl::far_max_ifp.

Referenced by change_t38_state(), and interpret_t38_parameters().

918 {
919  if (udptl->far_max_ifp == -1) {
920  calculate_far_max_ifp(udptl);
921  }
922 
923  if (udptl->far_max_ifp < 0) {
924  return 0;
925  }
926  return udptl->far_max_ifp;
927 }
int far_max_ifp
Definition: udptl.c:168
static void calculate_far_max_ifp(struct ast_udptl *udptl)
Definition: udptl.c:773
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 885 of file udptl.c.

References calculate_local_max_datagram(), and ast_udptl::local_max_datagram.

Referenced by add_sdp().

886 {
887  if (udptl->local_max_datagram == -1) {
889  }
890 
891  /* this function expects a unsigned value in return. */
892  if (udptl->local_max_datagram < 0) {
893  return 0;
894  }
895  return udptl->local_max_datagram;
896 }
int local_max_datagram
Definition: udptl.c:160
static void calculate_local_max_datagram(struct ast_udptl *udptl)
Definition: udptl.c:732
void ast_udptl_get_peer ( const struct ast_udptl udptl,
struct ast_sockaddr them 
)

Definition at line 1029 of file udptl.c.

References ast_sockaddr_copy(), and ast_udptl::them.

Referenced by ast_udptl_bridge(), and sip_set_udptl_peer().

1030 {
1031  ast_sockaddr_copy(them, &udptl->them);
1032 }
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:121
struct ast_sockaddr them
Definition: udptl.c:128
void ast_udptl_get_us ( const struct ast_udptl udptl,
struct ast_sockaddr us 
)

Definition at line 1034 of file udptl.c.

References ast_sockaddr_copy(), and ast_udptl::us.

Referenced by add_sdp().

1035 {
1036  ast_sockaddr_copy(us, &udptl->us);
1037 }
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:121
struct ast_sockaddr us
Definition: udptl.c:127
void ast_udptl_init ( void  )

Definition at line 1436 of file udptl.c.

References __ast_udptl_reload(), ARRAY_LEN, ast_cli_register_multiple(), ast_register_atexit(), and udptl_shutdown().

Referenced by main().

1437 {
1438  __ast_udptl_reload(0);
1439 
1441 
1443 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static void __ast_udptl_reload(int reload)
Definition: udptl.c:1321
static void udptl_shutdown(void)
Definition: udptl.c:1431
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: asterisk.c:998
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
static struct ast_cli_entry cli_udptl[]
Definition: udptl.c:1317
struct ast_udptl* ast_udptl_new_with_bindaddr ( struct sched_context sched,
struct io_context io,
int  callbackmode,
struct ast_sockaddr in 
)

Definition at line 929 of file udptl.c.

References 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, 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, ast_udptl::flags, ast_udptl::io, io, ast_udptl::ioid, ast_udptl::local_max_datagram, ast_udptl::local_max_ifp, LOG_WARNING, ast_udptl::rx, ast_udptl::sched, sched, ast_udptl::tx, UDPTL_BUF_MASK, udptlend, udptlfecentries, udptlfecspan, udptlread(), udptlstart, and ast_udptl::us.

Referenced by initialize_udptl().

930 {
931  struct ast_udptl *udptl;
932  int x;
933  int startplace;
934  int i;
935  long int flags;
936 
937  if (!(udptl = ast_calloc(1, sizeof(*udptl))))
938  return NULL;
939 
942 
943  udptl->far_max_datagram = -1;
944  udptl->far_max_ifp = -1;
945  udptl->local_max_ifp = -1;
946  udptl->local_max_datagram = -1;
947 
948  for (i = 0; i <= UDPTL_BUF_MASK; i++) {
949  udptl->rx[i].buf_len = -1;
950  udptl->tx[i].buf_len = -1;
951  }
952 
953  if ((udptl->fd = socket(ast_sockaddr_is_ipv6(addr) ?
954  AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) {
955  ast_free(udptl);
956  ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
957  return NULL;
958  }
959  flags = fcntl(udptl->fd, F_GETFL);
960  fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK);
961 #ifdef SO_NO_CHECK
962  if (nochecksums)
963  setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
964 #endif
965  /* Find us a place */
967  if (use_even_ports && (x & 1)) {
968  ++x;
969  }
970  startplace = x;
971  for (;;) {
972  ast_sockaddr_copy(&udptl->us, addr);
973  ast_sockaddr_set_port(&udptl->us, x);
974  if (ast_bind(udptl->fd, &udptl->us) == 0) {
975  break;
976  }
977  if (errno != EADDRINUSE && errno != EACCES) {
978  ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
979  close(udptl->fd);
980  ast_free(udptl);
981  return NULL;
982  }
983  if (use_even_ports) {
984  x += 2;
985  } else {
986  ++x;
987  }
988  if (x > udptlend)
989  x = udptlstart;
990  if (x == startplace) {
991  ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
992  close(udptl->fd);
993  ast_free(udptl);
994  return NULL;
995  }
996  }
997  if (io && sched && callbackmode) {
998  /* Operate this one in a callback mode */
999  udptl->sched = sched;
1000  udptl->io = io;
1001  udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
1002  }
1003  return udptl;
1004 }
int fd
Definition: udptl.c:120
unsigned int error_correction_span
Definition: udptl.c:149
static struct io_context * io
Definition: chan_gtalk.c:228
int local_max_datagram
Definition: udptl.c:160
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:121
#define LOG_WARNING
Definition: logger.h:144
static int udptlstart
Definition: udptl.c:85
int * ioid
Definition: udptl.c:129
#define AST_IO_IN
Definition: io.h:33
Structure for an UDPTL session.
Definition: udptl.c:119
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:157
unsigned int error_correction_entries
Definition: udptl.c:144
struct ast_sockaddr us
Definition: udptl.c:127
static int use_even_ports
Definition: udptl.c:94
int ast_bind(int sockfd, const struct ast_sockaddr *addr)
Wrapper around bind(2) that uses struct ast_sockaddr.
Definition: netsock2.c:462
struct sched_context * sched
Definition: chan_sip.c:782
int far_max_datagram
Definition: udptl.c:154
udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK+1]
Definition: udptl.c:180
long int ast_random(void)
Definition: utils.c:1640
static int udptlfecspan
Definition: udptl.c:93
static int udptlread(int *id, int fd, short events, void *cbdata)
Definition: udptl.c:663
struct io_context * io
Definition: udptl.c:131
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition: netsock2.h:422
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
#define ast_free(a)
Definition: astmm.h:97
static int udptlend
Definition: udptl.c:86
int far_max_ifp
Definition: udptl.c:168
int flags
Definition: udptl.c:126
struct sched_context * sched
Definition: udptl.c:130
#define ast_calloc(a, b)
Definition: astmm.h:82
int local_max_ifp
Definition: udptl.c:174
static int udptlfecentries
Definition: udptl.c:92
udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK+1]
Definition: udptl.c:179
#define UDPTL_BUF_MASK
Definition: udptl.c:102
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.
Definition: netsock2.c:418
int ast_udptl_proto_register ( struct ast_udptl_protocol proto)

Definition at line 1115 of file udptl.c.

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

Referenced by load_module().

1116 {
1117  struct ast_udptl_protocol *cur;
1118 
1120  AST_RWLIST_TRAVERSE(&protos, cur, list) {
1121  if (cur->type == proto->type) {
1122  ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
1124  return -1;
1125  }
1126  }
1127  AST_RWLIST_INSERT_TAIL(&protos, proto, list);
1129  return 0;
1130 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:144
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
Definition: udptl.c:183
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:726
const char *const type
Definition: udptl.h:52
void ast_udptl_proto_unregister ( struct ast_udptl_protocol proto)

Definition at line 1108 of file udptl.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by unload_module().

1109 {
1111  AST_RWLIST_REMOVE(&protos, proto, list);
1113 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: udptl.c:183
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:870
struct ast_frame* ast_udptl_read ( struct ast_udptl udptl)

Definition at line 675 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, errno, ast_udptl::f, ast_udptl::fd, 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().

676 {
677  int res;
678  struct ast_sockaddr addr;
679  uint8_t *buf;
680 
681  buf = udptl->rawdata + AST_FRIENDLY_OFFSET;
682 
683  /* Cache where the header will go */
684  res = ast_recvfrom(udptl->fd,
685  buf,
686  sizeof(udptl->rawdata) - AST_FRIENDLY_OFFSET,
687  0,
688  &addr);
689  if (res < 0) {
690  if (errno != EAGAIN)
691  ast_log(LOG_WARNING, "UDPTL (%s): read error: %s\n",
692  LOG_TAG(udptl), strerror(errno));
693  ast_assert(errno != EBADF);
694  return &ast_null_frame;
695  }
696 
697  /* Ignore if the other side hasn't been given an address yet. */
698  if (ast_sockaddr_isnull(&udptl->them)) {
699  return &ast_null_frame;
700  }
701 
702  if (udptl->nat) {
703  /* Send to whoever sent to us */
704  if (ast_sockaddr_cmp(&udptl->them, &addr)) {
705  ast_sockaddr_copy(&udptl->them, &addr);
706  ast_debug(1, "UDPTL (%s): NAT, Using address %s\n",
707  LOG_TAG(udptl), ast_sockaddr_stringify(&udptl->them));
708  }
709  }
710 
711  if (udptl_debug_test_addr(&addr)) {
712  int seq_no;
713 
714  /* Decode sequence number just for verbose message. */
715  if (res < 2) {
716  /* Short packet. */
717  seq_no = -1;
718  } else {
719  seq_no = (buf[0] << 8) | buf[1];
720  }
721 
722  ast_verb(1, "UDPTL (%s): packet from %s (seq %d, len %d)\n",
723  LOG_TAG(udptl), ast_sockaddr_stringify(&addr), seq_no, res);
724  }
725  if (udptl_rx_packet(udptl, buf, res) < 1) {
726  return &ast_null_frame;
727  }
728 
729  return &udptl->f[0];
730 }
int fd
Definition: udptl.c:120
int nat
Definition: udptl.c:125
struct ast_frame ast_null_frame
Definition: frame.c:131
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:121
#define LOG_WARNING
Definition: logger.h:144
#define ast_assert(a)
Definition: utils.h:738
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:300
static int udptl_debug_test_addr(const struct ast_sockaddr *addr)
Definition: udptl.c:185
Socket address structure.
Definition: netsock2.h:63
#define ast_verb(level,...)
Definition: logger.h:243
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. &quot;null&quot; in this sense essentially means uninitialized, or having a 0 length.
Definition: netsock2.h:93
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
Definition: frame.h:204
struct ast_sockaddr them
Definition: udptl.c:128
#define LOG_TAG(u)
Definition: udptl.c:83
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:210
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:478
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
struct ast_frame f[16]
Definition: udptl.c:122
unsigned char rawdata[8192+AST_FRIENDLY_OFFSET]
Definition: udptl.c:123
static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, unsigned int len)
Definition: udptl.c:310
int ast_udptl_reload ( void  )
Version
1.6.1 return changed to int

Definition at line 1421 of file udptl.c.

References __ast_udptl_reload().

1422 {
1423  __ast_udptl_reload(1);
1424  return 0;
1425 }
static void __ast_udptl_reload(int reload)
Definition: udptl.c:1321
void ast_udptl_reset ( struct ast_udptl udptl)
void ast_udptl_set_callback ( struct ast_udptl udptl,
ast_udptl_callback  callback 
)

Definition at line 653 of file udptl.c.

References ast_udptl::callback.

654 {
655  udptl->callback = callback;
656 }
ast_udptl_callback callback
Definition: udptl.c:134
void ast_udptl_set_data ( struct ast_udptl udptl,
void *  data 
)

Definition at line 648 of file udptl.c.

References ast_udptl::data.

649 {
650  udptl->data = data;
651 }
void * data
Definition: udptl.c:132
void ast_udptl_set_error_correction_scheme ( struct ast_udptl udptl,
enum ast_t38_ec_modes  ec 
)

Definition at line 846 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(), and set_t38_capabilities().

847 {
848  udptl->error_correction_scheme = ec;
849  switch (ec) {
852  if (udptl->error_correction_entries == 0) {
853  udptl->error_correction_entries = 3;
854  }
855  if (udptl->error_correction_span == 0) {
856  udptl->error_correction_span = 3;
857  }
858  break;
861  if (udptl->error_correction_entries == 0) {
862  udptl->error_correction_entries = 3;
863  }
864  break;
865  default:
866  /* nothing to do */
867  break;
868  };
869  /* reset calculated values so they'll be computed again */
870  udptl->local_max_datagram = -1;
871  udptl->far_max_ifp = -1;
872 }
unsigned int error_correction_span
Definition: udptl.c:149
int local_max_datagram
Definition: udptl.c:160
unsigned int error_correction_entries
Definition: udptl.c:144
int far_max_ifp
Definition: udptl.c:168
enum ast_t38_ec_modes error_correction_scheme
Definition: udptl.c:139
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 898 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().

899 {
900  if (!max_datagram || (max_datagram > FAX_MAX_DATAGRAM_LIMIT)) {
902  } else {
903  udptl->far_max_datagram = max_datagram;
904  }
905  /* reset calculated values so they'll be computed again */
906  udptl->far_max_ifp = -1;
907 }
int far_max_datagram
Definition: udptl.c:154
int far_max_ifp
Definition: udptl.c:168
#define FAX_MAX_DATAGRAM_LIMIT
Definition: udptl.c:98
#define DEFAULT_FAX_MAX_DATAGRAM
Definition: udptl.c:97
void ast_udptl_set_local_max_ifp ( struct ast_udptl udptl,
unsigned int  max_ifp 
)

Definition at line 874 of file udptl.c.

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

Referenced by interpret_t38_parameters().

875 {
876  /* make sure max_ifp is a positive value since a cast will take place when
877  * when setting local_max_ifp */
878  if ((signed int) max_ifp > 0) {
879  udptl->local_max_ifp = max_ifp;
880  /* reset calculated values so they'll be computed again */
881  udptl->local_max_datagram = -1;
882  }
883 }
int local_max_datagram
Definition: udptl.c:160
int local_max_ifp
Definition: udptl.c:174
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 
)

Definition at line 1024 of file udptl.c.

References ast_sockaddr_copy(), and ast_udptl::them.

Referenced by process_sdp().

1025 {
1026  ast_sockaddr_copy(&udptl->them, them);
1027 }
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:121
struct ast_sockaddr them
Definition: udptl.c:128
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 1006 of file udptl.c.

References ast_free, ast_vasprintf, and ast_udptl::tag.

Referenced by change_t38_state().

1007 {
1008  va_list ap;
1009 
1010  ast_free(udptl->tag);
1011  udptl->tag = NULL;
1012  va_start(ap, format);
1013  if (ast_vasprintf(&udptl->tag, format, ap) == -1) {
1014  udptl->tag = NULL;
1015  }
1016  va_end(ap);
1017 }
#define ast_vasprintf(a, b, c)
Definition: astmm.h:127
char * tag
Definition: udptl.c:133
#define ast_free(a)
Definition: astmm.h:97
static snd_pcm_format_t format
Definition: chan_alsa.c:93
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 658 of file udptl.c.

References ast_udptl::nat, and nat.

Referenced by do_setnat(), and initialize_udptl().

659 {
660  udptl->nat = nat;
661 }
int nat
Definition: udptl.c:125
static int nat
Definition: chan_mgcp.c:161
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 initialize_udptl().

1020 {
1021  return ast_netsock_set_qos(udptl->fd, tos, cos, "UDPTL");
1022 }
int fd
Definition: udptl.c:120
static unsigned int tos
Definition: chan_h323.c:146
int ast_netsock_set_qos(int netsocket, int tos, int cos, const char *desc)
Definition: netsock.c:158
static unsigned int cos
Definition: chan_h323.c:147
void ast_udptl_stop ( struct ast_udptl udptl)

Definition at line 1039 of file udptl.c.

References ast_sockaddr_setnull(), and ast_udptl::them.

Referenced by process_sdp(), and stop_media_flows().

1040 {
1041  ast_sockaddr_setnull(&udptl->them);
1042 }
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition: netsock2.h:106
struct ast_sockaddr them
Definition: udptl.c:128
int ast_udptl_write ( struct ast_udptl udptl,
struct ast_frame f 
)

Definition at line 1055 of file udptl.c.

References AST_FRAME_MODEM, ast_log(), AST_MODEM_T38, ast_sendto(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_verb, ast_frame_subclass::codec, 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, 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 sip_write().

1056 {
1057  unsigned int seq;
1058  unsigned int len = f->datalen;
1059  int res;
1060  /* if no max datagram size is provided, use default value */
1061  const int bufsize = (s->far_max_datagram > 0) ? s->far_max_datagram : DEFAULT_FAX_MAX_DATAGRAM;
1062  uint8_t buf[bufsize];
1063 
1064  memset(buf, 0, sizeof(buf));
1065 
1066  /* If we have no peer, return immediately */
1067  if (ast_sockaddr_isnull(&s->them)) {
1068  return 0;
1069  }
1070 
1071  /* If there is no data length, return immediately */
1072  if (f->datalen == 0)
1073  return 0;
1074 
1075  if ((f->frametype != AST_FRAME_MODEM) ||
1076  (f->subclass.codec != AST_MODEM_T38)) {
1077  ast_log(LOG_WARNING, "UDPTL (%s): UDPTL can only send T.38 data.\n",
1078  LOG_TAG(s));
1079  return -1;
1080  }
1081 
1082  if (len > s->far_max_ifp) {
1084  "UDPTL (%s): UDPTL asked to send %u bytes of IFP when far end only prepared to accept %d bytes; data loss will occur."
1085  "You may need to override the T38FaxMaxDatagram value for this endpoint in the channel driver configuration.\n",
1086  LOG_TAG(s), len, s->far_max_ifp);
1087  len = s->far_max_ifp;
1088  }
1089 
1090  /* Save seq_no for debug output because udptl_build_packet increments it */
1091  seq = s->tx_seq_no & 0xFFFF;
1092 
1093  /* Cook up the UDPTL packet, with the relevant EC info. */
1094  len = udptl_build_packet(s, buf, sizeof(buf), f->data.ptr, len);
1095 
1096  if ((signed int) len > 0 && !ast_sockaddr_isnull(&s->them)) {
1097  if ((res = ast_sendto(s->fd, buf, len, 0, &s->them)) < 0)
1098  ast_log(LOG_NOTICE, "UDPTL (%s): Transmission error to %s: %s\n",
1099  LOG_TAG(s), ast_sockaddr_stringify(&s->them), strerror(errno));
1100  if (udptl_debug_test_addr(&s->them))
1101  ast_verb(1, "UDPTL (%s): packet to %s (seq %u, len %u)\n",
1102  LOG_TAG(s), ast_sockaddr_stringify(&s->them), seq, len);
1103  }
1104 
1105  return 0;
1106 }
union ast_frame_subclass subclass
Definition: frame.h:146
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:486
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
#define AST_MODEM_T38
Definition: frame.h:216
format_t codec
Definition: frame.h:137
static int udptl_debug_test_addr(const struct ast_sockaddr *addr)
Definition: udptl.c:185
#define ast_verb(level,...)
Definition: logger.h:243
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. &quot;null&quot; in this sense essentially means uninitialized, or having a 0 length.
Definition: netsock2.h:93
int datalen
Definition: frame.h:148
#define LOG_TAG(u)
Definition: udptl.c:83
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:210
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
int errno
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:532
static volatile unsigned int seq
Definition: app_sms.c:118
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
#define DEFAULT_FAX_MAX_DATAGRAM
Definition: udptl.c:97