UDPTL support for T.38 faxing. More...
#include "asterisk.h"
#include <sys/time.h>
#include <signal.h>
#include <fcntl.h>
#include "asterisk/udptl.h"
#include "asterisk/frame.h"
#include "asterisk/channel.h"
#include "asterisk/acl.h"
#include "asterisk/config.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/netsock.h"
#include "asterisk/cli.h"
#include "asterisk/unaligned.h"
Go to the source code of this file.
Data Structures | |
struct | ast_udptl |
Structure for an UDPTL session. More... | |
struct | protos |
struct | udptl_fec_rx_buffer_t |
struct | udptl_fec_tx_buffer_t |
Macros | |
#define | DEFAULT_FAX_MAX_DATAGRAM 400 |
#define | FALSE 0 |
#define | FAX_MAX_DATAGRAM_LIMIT 1400 |
#define | LOCAL_FAX_MAX_DATAGRAM 1400 |
#define | LOG_TAG(u) S_OR(u->tag, "no tag") |
#define | MAX_FEC_ENTRIES 5 |
#define | MAX_FEC_SPAN 5 |
#define | TRUE (!FALSE) |
#define | UDPTL_BUF_MASK 15 |
#define | UDPTL_MTU 1200 |
Functions | |
static void | __ast_udptl_reload (int reload) |
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_udptl * | ast_udptl_new_with_bindaddr (struct sched_context *sched, struct io_context *io, int callbackmode, struct ast_sockaddr *addr) |
int | ast_udptl_proto_register (struct ast_udptl_protocol *proto) |
void | ast_udptl_proto_unregister (struct ast_udptl_protocol *proto) |
struct ast_frame * | ast_udptl_read (struct ast_udptl *udptl) |
int | ast_udptl_reload (void) |
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_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_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 *s, struct ast_frame *f) |
static void | calculate_far_max_ifp (struct ast_udptl *udptl) |
static void | calculate_local_max_datagram (struct ast_udptl *udptl) |
static int | decode_length (uint8_t *buf, unsigned int limit, unsigned int *len, unsigned int *pvalue) |
static int | decode_open_type (uint8_t *buf, unsigned int limit, unsigned int *len, const uint8_t **p_object, unsigned int *p_num_octets) |
static unsigned int | encode_length (uint8_t *buf, unsigned int *len, unsigned int value) |
static int | encode_open_type (const struct ast_udptl *udptl, uint8_t *buf, unsigned int buflen, unsigned int *len, const uint8_t *data, unsigned int num_octets) |
static struct ast_udptl_protocol * | get_proto (struct ast_channel *chan) |
static char * | handle_cli_udptl_set_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | udptl_build_packet (struct ast_udptl *s, uint8_t *buf, unsigned int buflen, uint8_t *ifp, unsigned int ifp_len) |
static int | udptl_debug_test_addr (const struct ast_sockaddr *addr) |
static int | udptl_rx_packet (struct ast_udptl *s, uint8_t *buf, unsigned int len) |
static void | udptl_shutdown (void) |
static int | udptlread (int *id, int fd, short events, void *cbdata) |
Variables | |
static struct ast_cli_entry | cli_udptl [] |
static struct protos | protos = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, 1 } , } |
static int | udptldebug |
static struct ast_sockaddr | udptldebugaddr |
static int | udptlend = 4599 |
static int | udptlfecentries |
static int | udptlfecspan |
static int | udptlstart = 4500 |
static int | use_even_ports |
UDPTL support for T.38 faxing.
Definition in file udptl.c.
#define DEFAULT_FAX_MAX_DATAGRAM 400 |
Definition at line 97 of file udptl.c.
Referenced by ast_udptl_set_far_max_datagram(), and ast_udptl_write().
#define FAX_MAX_DATAGRAM_LIMIT 1400 |
Definition at line 98 of file udptl.c.
Referenced by ast_udptl_set_far_max_datagram().
#define LOCAL_FAX_MAX_DATAGRAM 1400 |
Definition at line 96 of file udptl.c.
Referenced by calculate_local_max_datagram(), udptl_build_packet(), and udptl_rx_packet().
#define LOG_TAG | ( | u | ) | S_OR(u->tag, "no tag") |
Definition at line 83 of file udptl.c.
Referenced by ast_udptl_read(), ast_udptl_write(), calculate_far_max_ifp(), calculate_local_max_datagram(), encode_open_type(), and udptl_build_packet().
#define MAX_FEC_ENTRIES 5 |
Definition at line 99 of file udptl.c.
Referenced by __ast_udptl_reload(), and udptl_rx_packet().
#define MAX_FEC_SPAN 5 |
Definition at line 100 of file udptl.c.
Referenced by __ast_udptl_reload().
#define TRUE (!FALSE) |
Definition at line 80 of file udptl.c.
Referenced by udptl_rx_packet().
#define UDPTL_BUF_MASK 15 |
Definition at line 102 of file udptl.c.
Referenced by ast_udptl_new_with_bindaddr(), udptl_build_packet(), and udptl_rx_packet().
|
static |
Definition at line 1321 of file udptl.c.
References ast_config_destroy(), ast_config_load2(), ast_false(), ast_log(), ast_true(), ast_variable_retrieve(), ast_verb, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, LOG_NOTICE, LOG_WARNING, MAX_FEC_ENTRIES, MAX_FEC_SPAN, udptlend, and udptlstart.
Referenced by ast_udptl_init(), and ast_udptl_reload().
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.
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().
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().
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().
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().
unsigned int ast_udptl_get_far_max_ifp | ( | struct ast_udptl * | udptl | ) |
retrieves far max ifp
positive | value representing max ifp size |
0 | if 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().
unsigned int ast_udptl_get_local_max_datagram | ( | struct ast_udptl * | udptl | ) |
retrieves local_max_datagram.
positive | value representing max datagram size. |
0 | if 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().
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().
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().
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().
struct ast_udptl* ast_udptl_new_with_bindaddr | ( | struct sched_context * | sched, |
struct io_context * | io, | ||
int | callbackmode, | ||
struct ast_sockaddr * | addr | ||
) |
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().
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().
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().
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().
int ast_udptl_reload | ( | void | ) |
Definition at line 1421 of file udptl.c.
References __ast_udptl_reload().
void ast_udptl_set_callback | ( | struct ast_udptl * | udptl, |
ast_udptl_callback | callback | ||
) |
void ast_udptl_set_data | ( | struct ast_udptl * | udptl, |
void * | data | ||
) |
Definition at line 648 of file udptl.c.
References ast_udptl::data.
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().
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().
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().
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().
void ast_udptl_set_tag | ( | struct ast_udptl * | udptl, |
const char * | format, | ||
... | |||
) |
Associates a character string 'tag' with a UDPTL session.
udptl | The UDPTL session. |
format | printf-style format string used to construct the tag |
This function formats a tag for the specified UDPTL session, so that any log messages generated by the UDPTL stack related to that session will include the tag and the reader of the messages will be able to identify which endpoint caused them to be generated.
none |
Definition at line 1006 of file udptl.c.
References ast_free, ast_vasprintf, and ast_udptl::tag.
Referenced by change_t38_state().
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().
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().
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().
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().
|
static |
Definition at line 773 of file udptl.c.
References ast_log(), ast_udptl::error_correction_entries, ast_udptl::error_correction_scheme, ast_udptl::far_max_datagram, ast_udptl::far_max_ifp, LOG_TAG, LOG_WARNING, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
Referenced by ast_udptl_get_far_max_ifp().
|
static |
Definition at line 732 of file udptl.c.
References ast_log(), ast_udptl::error_correction_scheme, LOCAL_FAX_MAX_DATAGRAM, ast_udptl::local_max_datagram, ast_udptl::local_max_ifp, LOG_TAG, LOG_WARNING, MIN, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
Referenced by ast_udptl_get_local_max_datagram().
|
static |
Definition at line 201 of file udptl.c.
References ast_debug, and len().
Referenced by decode_open_type(), and udptl_rx_packet().
|
static |
Definition at line 227 of file udptl.c.
References decode_length(), and len().
Referenced by udptl_rx_packet().
|
static |
Definition at line 248 of file udptl.c.
Referenced by encode_open_type(), and udptl_build_packet().
|
static |
Definition at line 276 of file udptl.c.
References ast_log(), encode_length(), LOG_ERROR, and LOG_TAG.
Referenced by udptl_build_packet().
|
static |
Definition at line 1132 of file udptl.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_channel::tech, ast_udptl_protocol::type, and ast_channel_tech::type.
Referenced by ast_udptl_bridge().
|
static |
Definition at line 1271 of file udptl.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_free, ast_sockaddr_copy(), ast_sockaddr_resolve(), ast_sockaddr_stringify(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, udptldebugaddr, and ast_cli_entry::usage.
|
static |
Definition at line 532 of file udptl.c.
References ast_debug, udptl_fec_tx_buffer_t::buf, udptl_fec_tx_buffer_t::buf_len, encode_length(), encode_open_type(), ast_udptl::error_correction_entries, ast_udptl::error_correction_scheme, ast_udptl::error_correction_span, for(), len(), LOCAL_FAX_MAX_DATAGRAM, LOG_TAG, seq, ast_udptl::tx, ast_udptl::tx_seq_no, UDPTL_BUF_MASK, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
Referenced by ast_udptl_write().
|
inlinestatic |
Definition at line 185 of file udptl.c.
References ast_sockaddr_cmp(), ast_sockaddr_cmp_addr(), ast_sockaddr_isnull(), ast_sockaddr_port, and udptldebugaddr.
Referenced by ast_udptl_read(), and ast_udptl_write().
|
static |
Definition at line 310 of file udptl.c.
References ARRAY_LEN, ast_debug, AST_FRAME_MODEM, AST_LIST_NEXT, AST_MODEM_T38, udptl_fec_rx_buffer_t::buf, udptl_fec_rx_buffer_t::buf_len, ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, decode_length(), decode_open_type(), ast_udptl::f, udptl_fec_rx_buffer_t::fec, udptl_fec_rx_buffer_t::fec_entries, udptl_fec_rx_buffer_t::fec_len, udptl_fec_rx_buffer_t::fec_span, ast_frame::frametype, LOCAL_FAX_MAX_DATAGRAM, ast_frame::mallocd, MAX_FEC_ENTRIES, ast_frame::offset, ast_frame::ptr, ast_udptl::rx, ast_udptl::rx_seq_no, ast_frame::seqno, ast_frame::src, ast_frame::subclass, TRUE, and UDPTL_BUF_MASK.
Referenced by ast_udptl_read().
|
static |
Definition at line 1431 of file udptl.c.
References ARRAY_LEN, and ast_cli_unregister_multiple().
Referenced by ast_udptl_init().
|
static |
Definition at line 663 of file udptl.c.
References ast_udptl_read(), ast_udptl::callback, ast_udptl::data, and f.
Referenced by ast_udptl_new_with_bindaddr().
|
static |
|
static |
|
static |
Debug packets to/from this host
Definition at line 88 of file udptl.c.
Referenced by handle_cli_udptl_set_debug(), and udptl_debug_test_addr().
|
static |
Definition at line 86 of file udptl.c.
Referenced by __ast_udptl_reload(), and ast_udptl_new_with_bindaddr().
|
static |
Definition at line 92 of file udptl.c.
Referenced by ast_udptl_new_with_bindaddr().
|
static |
Definition at line 93 of file udptl.c.
Referenced by ast_udptl_new_with_bindaddr().
|
static |
Definition at line 85 of file udptl.c.
Referenced by __ast_udptl_reload(), and ast_udptl_new_with_bindaddr().