Asterisk - The Open Source Telephony Project GIT-master-b023714
|
SIP T.38 handling. More...
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_ua.h>
#include <pjmedia.h>
#include <pjlib.h>
#include "asterisk/utils.h"
#include "asterisk/module.h"
#include "asterisk/udptl.h"
#include "asterisk/netsock2.h"
#include "asterisk/channel.h"
#include "asterisk/acl.h"
#include "asterisk/stream.h"
#include "asterisk/format_cache.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
Go to the source code of this file.
Data Structures | |
struct | t38_parameters_task_data |
Structure for T.38 parameters task data. More... | |
struct | t38_state |
T.38 state information. More... | |
Macros | |
#define | T38_AUTOMATIC_REJECTION_SECONDS 5 |
The number of seconds after receiving a T.38 re-invite before automatically rejecting it. | |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | apply_negotiated_sdp_stream (struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *local, const struct pjmedia_sdp_session *remote, int index, struct ast_stream *asterisk_stream) |
Function which applies a negotiated stream. | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static void | change_outgoing_sdp_stream_media_address (pjsip_tx_data *tdata, struct pjmedia_sdp_media *stream, struct ast_sip_transport *transport) |
Function which updates the media stream with external media address, if applicable. | |
static int | create_outgoing_sdp_stream (struct ast_sip_session *session, struct ast_sip_session_media *session_media, struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_session *remote, struct ast_stream *stream) |
Function which creates an outgoing stream. | |
static enum ast_sip_session_sdp_stream_defer | defer_incoming_sdp_stream (struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream) |
Function which defers an incoming media stream. | |
static int | load_module (void) |
Load the module. | |
static struct ast_frame * | media_session_udptl_read_callback (struct ast_sip_session *session, struct ast_sip_session_media *session_media) |
static int | media_session_udptl_write_callback (struct ast_sip_session *session, struct ast_sip_session_media *session_media, struct ast_frame *frame) |
static int | negotiate_incoming_sdp_stream (struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *sdp, int index, struct ast_stream *asterisk_stream) |
Function which negotiates an incoming media stream. | |
static void | stream_destroy (struct ast_sip_session_media *session_media) |
Function which destroys the UDPTL instance when session ends. | |
static void | t38_attach_framehook (struct ast_sip_session *session) |
Function called to attach T.38 framehook to channel when appropriate. | |
static int | t38_automatic_reject (void *obj) |
Task function which rejects a T.38 re-invite and resumes handling it. | |
static void | t38_automatic_reject_timer_cb (pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry) |
Timer entry callback which queues a task to reject a T.38 re-invite and resume handling it. | |
static void | t38_change_state (struct ast_sip_session *session, struct ast_sip_session_media *session_media, struct t38_state *state, enum ast_sip_session_t38state new_state) |
Helper function for changing the T.38 state. | |
static int | t38_consume (void *data, enum ast_frame_type type) |
static struct ast_sip_session_media_state * | t38_create_media_state (struct ast_sip_session *session) |
Helper function which creates a media state for strictly T.38. | |
static struct ast_frame * | t38_framehook (struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data) |
Frame hook callback for T.38 related stuff. | |
static unsigned int | t38_get_rate (enum ast_control_t38_rate rate) |
Get Max T.38 Transmission rate from T38 capabilities. | |
static int | t38_incoming_invite_request (struct ast_sip_session *session, struct pjsip_rx_data *rdata) |
Function called when an INVITE arrives. | |
static int | t38_initialize_session (struct ast_sip_session *session, struct ast_sip_session_media *session_media) |
Initializes UDPTL support on a session, only done when actually needed. | |
static int | t38_interpret_parameters (void *obj) |
Task for reacting to T.38 control frame. | |
static void | t38_interpret_sdp (struct t38_state *state, struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_media *stream) |
Parse a T.38 image stream and store the attribute information. | |
static void | t38_masq (void *data, int framehook_id, struct ast_channel *old_chan, struct ast_channel *new_chan) |
static void | t38_outgoing_invite_request (struct ast_sip_session *session, struct pjsip_tx_data *tdata) |
Function called when an INVITE is sent. | |
static struct t38_parameters_task_data * | t38_parameters_task_data_alloc (struct ast_sip_session *session, struct ast_frame *frame) |
Allocator for T.38 data. | |
static void | t38_parameters_task_data_destroy (void *obj) |
Destructor for T.38 data. | |
static int | t38_reinvite_response_cb (struct ast_sip_session *session, pjsip_rx_data *rdata) |
Callback for when a response is received for a T.38 re-invite. | |
static int | t38_reinvite_sdp_cb (struct ast_sip_session *session, pjmedia_sdp_session *sdp) |
Callback for when T.38 reinvite SDP is created. | |
static void | t38_state_destroy (void *obj) |
Destructor for T.38 state information. | |
static struct t38_state * | t38_state_get_or_alloc (struct ast_sip_session *session) |
Helper function which retrieves or allocates a T.38 state information datastore. | |
static int | unload_module (void) |
Unloads the SIP T.38 module from Asterisk. | |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP T.38 UDPTL Support" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DRIVER, .requires = "res_pjsip,res_pjsip_session,udptl", } |
static struct ast_sockaddr | address |
Address for UDPTL. | |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_sip_session_sdp_handler | image_sdp_handler |
SDP handler for 'image' media stream. | |
static const struct ast_datastore_info | t38_datastore |
Datastore for attaching T.38 state information. | |
static const struct ast_datastore_info | t38_framehook_datastore |
static struct ast_sip_session_supplement | t38_supplement |
Supplement for adding framehook to session channel. | |
SIP T.38 handling.
Definition in file res_pjsip_t38.c.
#define T38_AUTOMATIC_REJECTION_SECONDS 5 |
The number of seconds after receiving a T.38 re-invite before automatically rejecting it.
Definition at line 53 of file res_pjsip_t38.c.
|
static |
Definition at line 1171 of file res_pjsip_t38.c.
|
static |
Definition at line 1171 of file res_pjsip_t38.c.
|
static |
Function which applies a negotiated stream.
Definition at line 1039 of file res_pjsip_t38.c.
References AST_AF_UNSPEC, ast_copy_pj_str(), ast_debug, ast_free, ast_sip_session_media_add_read_callback(), ast_sip_session_media_set_write_callback(), ast_sockaddr_resolve(), ast_sockaddr_set_port, ast_udptl_fd(), ast_udptl_set_peer(), media_session_udptl_read_callback(), media_session_udptl_write_callback(), NULL, PARSE_PORT_FORBID, RAII_VAR, session, t38_state::state, t38_interpret_sdp(), t38_state_get_or_alloc(), and ast_sip_session_media::udptl.
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1171 of file res_pjsip_t38.c.
|
static |
Function which updates the media stream with external media address, if applicable.
Definition at line 1079 of file res_pjsip_t38.c.
References ao2_cleanup, ast_copy_pj_str(), ast_debug, ast_sip_get_transport_state(), ast_sip_transport_is_nonlocal, ast_sockaddr_parse(), ast_sockaddr_stringify_addr_remote(), ast_sorcery_object_get_id(), PARSE_PORT_FORBID, and RAII_VAR.
|
static |
Function which creates an outgoing stream.
Definition at line 904 of file res_pjsip_t38.c.
References ast_codec_media_type2str(), ast_debug, ast_sip_get_host_ip_string(), ast_sockaddr_port, ast_strlen_zero(), AST_T38_RATE_MANAGEMENT_LOCAL_TCF, AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF, ast_udptl_get_error_correction_scheme(), ast_udptl_get_local_max_datagram(), ast_udptl_get_us(), NULL, session, t38_state::state, T38_ENABLED, t38_get_rate(), t38_initialize_session(), T38_LOCAL_REINVITE, T38_PEER_REINVITE, t38_state_get_or_alloc(), ast_sip_session_media::type, ast_sip_session_media::udptl, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
|
static |
Function which defers an incoming media stream.
Definition at line 826 of file res_pjsip_t38.c.
References ast_channel_name(), ast_debug, AST_SIP_SESSION_SDP_DEFER_ERROR, AST_SIP_SESSION_SDP_DEFER_NEEDED, AST_SIP_SESSION_SDP_DEFER_NOT_HANDLED, AST_SIP_SESSION_SDP_DEFER_NOT_NEEDED, session, t38_state::state, t38_change_state(), T38_DISABLED, t38_initialize_session(), t38_interpret_sdp(), T38_PEER_REINVITE, and t38_state_get_or_alloc().
|
static |
Load the module.
Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
Definition at line 1143 of file res_pjsip_t38.c.
References ast_check_ipv6(), ast_log, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_sip_session_register_sdp_handler(), ast_sip_session_register_supplement, ast_sockaddr_parse(), end, image_sdp_handler, LOG_ERROR, t38_supplement, and unload_module().
|
static |
Definition at line 1011 of file res_pjsip_t38.c.
References ast_null_frame, ast_udptl_read(), NULL, ast_frame::stream_num, ast_sip_session_media::stream_num, and ast_sip_session_media::udptl.
Referenced by apply_negotiated_sdp_stream().
|
static |
Definition at line 1029 of file res_pjsip_t38.c.
References ast_udptl_write(), and ast_sip_session_media::udptl.
Referenced by apply_negotiated_sdp_stream().
|
static |
Function which negotiates an incoming media stream.
Definition at line 859 of file res_pjsip_t38.c.
References AST_AF_UNSPEC, ast_copy_pj_str(), ast_debug, ast_free, ast_sockaddr_is_ipv4(), ast_sockaddr_is_ipv6(), ast_sockaddr_resolve(), NULL, PARSE_PORT_FORBID, RAII_VAR, session, t38_state::state, t38_change_state(), T38_DISABLED, T38_REJECTED, and t38_state_get_or_alloc().
|
static |
Function which destroys the UDPTL instance when session ends.
Definition at line 1105 of file res_pjsip_t38.c.
References ast_udptl_destroy(), NULL, and ast_sip_session_media::udptl.
|
static |
Function called to attach T.38 framehook to channel when appropriate.
Definition at line 650 of file res_pjsip_t38.c.
References ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_datastore_alloc, ast_framehook_attach(), ast_framehook_detach(), AST_FRAMEHOOK_INTERFACE_VERSION, ast_log, LOG_ERROR, LOG_WARNING, NULL, session, t38_consume(), t38_framehook(), t38_framehook_datastore, t38_masq(), and ast_framehook_interface::version.
Referenced by t38_incoming_invite_request(), and t38_outgoing_invite_request().
|
static |
Task function which rejects a T.38 re-invite and resumes handling it.
Definition at line 202 of file res_pjsip_t38.c.
References ao2_cleanup, ast_channel_name(), ast_debug, ast_sip_session_get_datastore(), ast_sip_session_resume_reinvite(), NULL, RAII_VAR, session, t38_change_state(), and T38_REJECTED.
Referenced by t38_automatic_reject_timer_cb().
|
static |
Timer entry callback which queues a task to reject a T.38 re-invite and resume handling it.
Definition at line 221 of file res_pjsip_t38.c.
References ao2_ref, ast_sip_push_task(), session, and t38_automatic_reject().
Referenced by t38_state_get_or_alloc().
|
static |
Helper function for changing the T.38 state.
Definition at line 129 of file res_pjsip_t38.c.
References ao2_ref, ast_assert, ast_channel_name(), ast_channel_set_unbridged(), AST_CONTROL_T38_PARAMETERS, ast_debug, ast_log, ast_queue_control_data(), ast_sip_get_pjsip_endpoint(), AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_TERMINATED, ast_udptl_get_far_max_ifp(), ast_udptl_set_tag(), LOG_WARNING, ast_control_t38_parameters::max_ifp, ast_control_t38_parameters::request_response, session, T38_AUTOMATIC_REJECTION_SECONDS, T38_DISABLED, T38_ENABLED, T38_LOCAL_REINVITE, T38_MAX_ENUM, T38_PEER_REINVITE, T38_REJECTED, and ast_sip_session_media::udptl.
Referenced by defer_incoming_sdp_stream(), negotiate_incoming_sdp_stream(), t38_automatic_reject(), t38_interpret_parameters(), and t38_reinvite_response_cb().
|
static |
Definition at line 640 of file res_pjsip_t38.c.
References AST_FRAME_CONTROL, and type.
Referenced by t38_attach_framehook().
|
static |
Helper function which creates a media state for strictly T.38.
Definition at line 408 of file res_pjsip_t38.c.
References ao2_ref, ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_t38, AST_MEDIA_TYPE_IMAGE, ast_sip_session_media_state_add(), ast_sip_session_media_state_alloc(), ast_sip_session_media_state_free(), ast_stream_alloc(), ast_stream_free(), ast_stream_set_formats(), ast_stream_set_state(), AST_STREAM_STATE_SENDRECV, ast_stream_topology_alloc(), ast_stream_topology_set_stream(), NULL, session, t38_initialize_session(), and ast_sip_session_media_state::topology.
Referenced by t38_interpret_parameters().
|
static |
Frame hook callback for T.38 related stuff.
Definition at line 578 of file res_pjsip_t38.c.
References ao2_ref, ast_channel_name(), ast_channel_tech_pvt(), AST_CONTROL_T38_PARAMETERS, ast_debug, AST_FRAME_CONTROL, AST_FRAMEHOOK_EVENT_WRITE, ast_queue_control_data(), ast_sip_push_task(), AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_REQUEST_TERMINATE, AST_T38_TERMINATED, ast_frame::data, ast_sip_t38_configuration::enabled, ast_sip_session::endpoint, ast_frame::frametype, ast_frame_subclass::integer, ast_sip_endpoint::media, ast_frame::ptr, ast_control_t38_parameters::request_response, ast_sip_session::serializer, ast_sip_channel_pvt::session, ast_frame::subclass, ast_sip_endpoint_media_configuration::t38, t38_interpret_parameters(), and t38_parameters_task_data_alloc().
Referenced by t38_attach_framehook().
|
static |
Get Max T.38 Transmission rate from T38 capabilities.
Definition at line 714 of file res_pjsip_t38.c.
References AST_T38_RATE_12000, AST_T38_RATE_14400, AST_T38_RATE_2400, AST_T38_RATE_4800, AST_T38_RATE_7200, and AST_T38_RATE_9600.
Referenced by create_outgoing_sdp_stream().
|
static |
Function called when an INVITE arrives.
Definition at line 701 of file res_pjsip_t38.c.
References session, and t38_attach_framehook().
|
static |
Initializes UDPTL support on a session, only done when actually needed.
Definition at line 256 of file res_pjsip_t38.c.
References address, ao2_ref, ast_channel_name(), ast_debug, ast_sip_get_sorcery(), ast_sip_get_transport_state(), ast_sockaddr_parse(), ast_sorcery_object_get_id(), ast_sorcery_retrieve_by_id(), ast_strlen_zero(), ast_udptl_new_with_bindaddr(), ast_udptl_set_error_correction_scheme(), ast_udptl_set_far_max_datagram(), ast_udptl_setnat(), ast_sip_transport_state::host, NULL, session, ast_sip_transport_state::transport, and ast_sip_session_media::udptl.
Referenced by create_outgoing_sdp_stream(), defer_incoming_sdp_stream(), and t38_create_media_state().
|
static |
Task for reacting to T.38 control frame.
Definition at line 469 of file res_pjsip_t38.c.
References ao2_cleanup, ast_channel_name(), AST_CONTROL_T38_PARAMETERS, ast_log, AST_MEDIA_TYPE_IMAGE, ast_queue_control_data(), ast_sip_session_refresh(), AST_SIP_SESSION_REFRESH_METHOD_INVITE, ast_sip_session_resume_reinvite(), AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_REQUEST_PARMS, AST_T38_REQUEST_TERMINATE, AST_T38_TERMINATED, ast_udptl_get_far_max_ifp(), ast_udptl_set_local_max_ifp(), ast_sip_session_media_state::default_session, LOG_ERROR, ast_control_t38_parameters::max_ifp, MIN, NULL, RAII_VAR, ast_control_t38_parameters::request_response, t38_change_state(), t38_create_media_state(), T38_DISABLED, T38_ENABLED, T38_LOCAL_REINVITE, T38_PEER_REINVITE, t38_reinvite_response_cb(), t38_reinvite_sdp_cb(), T38_REJECTED, t38_state_get_or_alloc(), and ast_sip_session_media::udptl.
Referenced by t38_framehook().
|
static |
Parse a T.38 image stream and store the attribute information.
Definition at line 743 of file res_pjsip_t38.c.
References AST_T38_RATE_12000, AST_T38_RATE_14400, AST_T38_RATE_2400, AST_T38_RATE_4800, AST_T38_RATE_7200, AST_T38_RATE_9600, AST_T38_RATE_MANAGEMENT_LOCAL_TCF, AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF, ast_udptl_set_error_correction_scheme(), ast_udptl_set_far_max_datagram(), session, T38_LOCAL_REINVITE, ast_sip_session_media::udptl, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
Referenced by apply_negotiated_sdp_stream(), and defer_incoming_sdp_stream().
|
static |
Definition at line 629 of file res_pjsip_t38.c.
References ast_framehook_detach().
Referenced by t38_attach_framehook().
|
static |
Function called when an INVITE is sent.
Definition at line 708 of file res_pjsip_t38.c.
References session, and t38_attach_framehook().
|
static |
Allocator for T.38 data.
Definition at line 108 of file res_pjsip_t38.c.
References ao2_alloc, ao2_ref, ast_frdup, t38_parameters_task_data::frame, NULL, t38_parameters_task_data::session, session, and t38_parameters_task_data_destroy().
Referenced by t38_framehook().
|
static |
Destructor for T.38 data.
Definition at line 96 of file res_pjsip_t38.c.
References ao2_cleanup, ast_frfree, t38_parameters_task_data::frame, and t38_parameters_task_data::session.
Referenced by t38_parameters_task_data_alloc().
|
static |
Callback for when a response is received for a T.38 re-invite.
Definition at line 331 of file res_pjsip_t38.c.
References ast_channel_name(), ast_debug, ast_log, AST_MEDIA_TYPE_IMAGE, ast_sip_session_media_state_free(), ast_sip_session_media_state_reset(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sip_session_media::handler, LOG_WARNING, NULL, session, t38_state::state, status, ast_sip_session_sdp_handler::stream_stop, t38_change_state(), T38_DISABLED, T38_ENABLED, T38_LOCAL_REINVITE, T38_REJECTED, t38_state_get_or_alloc(), and ast_sip_session_media::udptl.
Referenced by t38_interpret_parameters().
|
static |
Callback for when T.38 reinvite SDP is created.
Definition at line 316 of file res_pjsip_t38.c.
References ast_sip_session_media_state_clone(), session, t38_state::state, and t38_state_get_or_alloc().
Referenced by t38_interpret_parameters().
|
static |
Destructor for T.38 state information.
Definition at line 73 of file res_pjsip_t38.c.
References ast_free, and ast_sip_session_media_state_free().
|
static |
Helper function which retrieves or allocates a T.38 state information datastore.
Definition at line 231 of file res_pjsip_t38.c.
References ao2_cleanup, ast_calloc, ast_sip_session_add_datastore(), ast_sip_session_alloc_datastore(), ast_sip_session_get_datastore(), NULL, RAII_VAR, session, t38_state::state, t38_automatic_reject_timer_cb(), and t38_datastore.
Referenced by apply_negotiated_sdp_stream(), create_outgoing_sdp_stream(), defer_incoming_sdp_stream(), negotiate_incoming_sdp_stream(), t38_interpret_parameters(), t38_reinvite_response_cb(), and t38_reinvite_sdp_cb().
|
static |
Unloads the SIP T.38 module from Asterisk.
Definition at line 1125 of file res_pjsip_t38.c.
References ast_sip_session_unregister_sdp_handler(), ast_sip_session_unregister_supplement(), image_sdp_handler, and t38_supplement.
Referenced by load_module().
|
static |
Definition at line 1171 of file res_pjsip_t38.c.
|
static |
Address for UDPTL.
Definition at line 56 of file res_pjsip_t38.c.
Referenced by t38_initialize_session().
|
static |
Definition at line 1171 of file res_pjsip_t38.c.
|
static |
SDP handler for 'image' media stream.
Definition at line 1114 of file res_pjsip_t38.c.
Referenced by load_module(), and unload_module().
|
static |
Datastore for attaching T.38 state information.
Definition at line 82 of file res_pjsip_t38.c.
Referenced by t38_state_get_or_alloc().
|
static |
Definition at line 645 of file res_pjsip_t38.c.
Referenced by t38_attach_framehook().
|
static |
Supplement for adding framehook to session channel.
Definition at line 735 of file res_pjsip_t38.c.
Referenced by load_module(), and unload_module().