Asterisk - The Open Source Telephony Project
21.4.1
|
PSJIP SIP Channel Driver. More...
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_ua.h>
#include <pjlib.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/causes.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/dsp.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/indications.h"
#include "asterisk/format_cache.h"
#include "asterisk/translate.h"
#include "asterisk/threadstorage.h"
#include "asterisk/features_config.h"
#include "asterisk/pickup.h"
#include "asterisk/test.h"
#include "asterisk/message.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "asterisk/stream.h"
#include "pjsip/include/chan_pjsip.h"
#include "pjsip/include/dialplan_functions.h"
#include "pjsip/include/cli_functions.h"
Go to the source code of this file.
Data Structures | |
struct | answer_data |
struct | hangup_data |
struct | indicate_data |
struct | info_dtmf_data |
struct | request_data |
struct | rtp_direct_media_data |
struct | sendtext_data |
struct | topology_change_refresh_data |
struct | transfer_data |
Macros | |
#define | UNIQUEID_BUFSIZE 256 |
Functions | |
static void | __init_uniqueid_threadbuf (void) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | answer (void *data) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static int | call (void *data) |
static int | call_pickup_incoming_request (struct ast_sip_session *session, pjsip_rx_data *rdata) |
static int | chan_pjsip_add_hold (const char *chan_uid) |
Add a channel ID to the list of PJSIP channels on hold. More... | |
static int | chan_pjsip_answer (struct ast_channel *ast) |
Function called by core when we should answer a PJSIP session. | |
static int | chan_pjsip_call (struct ast_channel *ast, const char *dest, int timeout) |
Function called by core to actually start calling a remote party. | |
static struct ast_frame * | chan_pjsip_cng_tone_detected (struct ast_channel *ast, struct ast_sip_session *session, struct ast_frame *f) |
Internal helper function called when CNG tone is detected. | |
static int | chan_pjsip_devicestate (const char *data) |
Function called to get the device state of an endpoint. | |
static int | chan_pjsip_digit_begin (struct ast_channel *chan, char digit) |
Function called by core to start a DTMF digit. | |
static int | chan_pjsip_digit_end (struct ast_channel *ast, char digit, unsigned int duration) |
Function called by core to stop a DTMF digit. | |
static int | chan_pjsip_fixup (struct ast_channel *oldchan, struct ast_channel *newchan) |
Function called by core to change the underlying owner channel. | |
static void | chan_pjsip_get_codec (struct ast_channel *chan, struct ast_format_cap *result) |
Function called by RTP engine to get peer capabilities. | |
static int | chan_pjsip_get_hold (const char *chan_uid) |
Determine whether a channel ID is in the list of PJSIP channels on hold. More... | |
static enum ast_rtp_glue_result | chan_pjsip_get_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance) |
Function called by RTP engine to get local audio RTP peer. | |
static const char * | chan_pjsip_get_uniqueid (struct ast_channel *ast) |
static enum ast_rtp_glue_result | chan_pjsip_get_vrtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance) |
Function called by RTP engine to get local video RTP peer. | |
static int | chan_pjsip_hangup (struct ast_channel *ast) |
Function called by core to hang up a PJSIP session. | |
static int | chan_pjsip_incoming_ack (struct ast_sip_session *session, struct pjsip_rx_data *rdata) |
static int | chan_pjsip_incoming_prack (struct ast_sip_session *session, struct pjsip_rx_data *rdata) |
static int | chan_pjsip_incoming_request (struct ast_sip_session *session, struct pjsip_rx_data *rdata) |
Function called when a request is received on the session. | |
static void | chan_pjsip_incoming_response (struct ast_sip_session *session, struct pjsip_rx_data *rdata) |
Function called when a response is received on the session. | |
static void | chan_pjsip_incoming_response_update_cause (struct ast_sip_session *session, struct pjsip_rx_data *rdata) |
Function called when a response is received on the session. | |
static int | chan_pjsip_indicate (struct ast_channel *ast, int condition, const void *data, size_t datalen) |
Function called by core to ask the channel to indicate some sort of condition. | |
static struct ast_channel * | chan_pjsip_new (struct ast_sip_session *session, int state, const char *exten, const char *title, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *cid_name) |
Function called to create a new PJSIP Asterisk channel. | |
static void | chan_pjsip_pvt_dtor (void *obj) |
static int | chan_pjsip_queryoption (struct ast_channel *ast, int option, void *data, int *datalen) |
Function called to query options on a channel. | |
static struct ast_frame * | chan_pjsip_read_stream (struct ast_channel *ast) |
Function called by core to read any waiting frames. More... | |
static void | chan_pjsip_remove_hold (const char *chan_uid) |
Remove a channel ID from the list of PJSIP channels on hold. More... | |
static struct ast_channel * | chan_pjsip_request (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause) |
Asterisk core interaction functions. | |
static struct ast_channel * | chan_pjsip_request_with_stream_topology (const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause) |
Function called by core to create a new outgoing PJSIP session. | |
static int | chan_pjsip_sendtext (struct ast_channel *ast, const char *text) |
static int | chan_pjsip_sendtext_data (struct ast_channel *ast, struct ast_msg_data *msg) |
Function called by core to send text on PJSIP session. | |
static void | chan_pjsip_session_begin (struct ast_sip_session *session) |
SIP session interaction functions. | |
static void | chan_pjsip_session_end (struct ast_sip_session *session) |
Function called when the session ends. | |
static int | chan_pjsip_set_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *tpeer, const struct ast_format_cap *cap, int nat_active) |
Function called by RTP engine to change where the remote party should send media. | |
static int | chan_pjsip_transfer (struct ast_channel *chan, const char *target) |
Function called by core for Asterisk initiated transfer. | |
static int | chan_pjsip_write (struct ast_channel *ast, struct ast_frame *f) |
static int | chan_pjsip_write_stream (struct ast_channel *ast, int stream_num, struct ast_frame *f) |
static int | check_for_rtp_changes (struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_sip_session_media *media, struct ast_sip_session *session) |
static void | clear_session_and_channel (struct ast_sip_session *session, struct ast_channel *ast) |
Clear a channel from a session along with its PVT. | |
static int | compatible_formats_exist (struct ast_stream_topology *top, struct ast_format_cap *cap) |
Determine if a topology is compatible with format capabilities. More... | |
static int | direct_media_mitigate_glare (struct ast_sip_session *session) |
static int | handle_topology_request_change (struct ast_sip_session *session, const struct ast_stream_topology *proposed) |
static int | hangup (void *data) |
static int | hangup_cause2sip (int cause) |
Internal function which translates from Asterisk cause codes to SIP response codes. | |
static struct hangup_data * | hangup_data_alloc (int cause, struct ast_channel *chan) |
static void | hangup_data_destroy (void *obj) |
static int | indicate (void *data) |
static struct indicate_data * | indicate_data_alloc (struct ast_sip_session *session, int condition, int response_code, const void *frame_data, size_t datalen) |
static void | indicate_data_destroy (void *obj) |
static struct info_dtmf_data * | info_dtmf_data_alloc (struct ast_sip_session *session, char digit, unsigned int duration) |
static void | info_dtmf_data_destroy (void *obj) |
static int | is_colp_update_allowed (struct ast_sip_session *session) |
static int | is_compatible_format (struct ast_sip_session *session, struct ast_frame *f) |
Determine if the given frame is in a format we've negotiated. | |
static int | load_module (void) |
Load the module. More... | |
static int | on_topology_change_response (struct ast_sip_session *session, pjsip_rx_data *rdata) |
static int | pbx_start_incoming_request (struct ast_sip_session *session, pjsip_rx_data *rdata) |
static int | remote_send_hold (void *data) |
Update local hold state to be held. | |
static int | remote_send_hold_refresh (struct ast_sip_session *session, unsigned int held) |
Update local hold state and send a re-INVITE with the new SDP. | |
static int | remote_send_unhold (void *data) |
Update local hold state to be unheld. | |
static int | request (void *obj) |
static struct rtp_direct_media_data * | rtp_direct_media_data_create (struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, const struct ast_format_cap *cap, struct ast_sip_session *session) |
static void | rtp_direct_media_data_destroy (void *data) |
static int | rtp_find_rtcp_fd_position (struct ast_sip_session *session, struct ast_rtp_instance *rtp) |
Helper function to find the position for RTCP. | |
static int | send_direct_media_request (void *data) |
static int | send_topology_change_refresh (void *data) |
static int | sendtext (void *obj) |
static struct sendtext_data * | sendtext_data_create (struct ast_channel *chan, struct ast_msg_data *msg) |
static void | sendtext_data_destroy (void *obj) |
static void | set_channel_on_rtp_instance (const struct ast_sip_session *session, const char *channel_id) |
static void | set_sipdomain_variable (struct ast_sip_session *session) |
static struct topology_change_refresh_data * | topology_change_refresh_data_alloc (struct ast_sip_session *session, const struct ast_stream_topology *topology) |
static void | topology_change_refresh_data_free (struct topology_change_refresh_data *refresh_data) |
static int | transfer (void *data) |
static struct transfer_data * | transfer_data_alloc (struct ast_sip_session *session, const char *target) |
static void | transfer_data_destroy (void *obj) |
static void | transfer_redirect (struct ast_sip_session *session, const char *target) |
static void | transfer_refer (struct ast_sip_session *session, const char *target) |
static int | transmit_info_dtmf (void *data) |
static int | transmit_info_with_vidupdate (void *data) |
Send SIP INFO with video update request. | |
static void | transport_info_destroy (void *obj) |
Destructor function for transport_info_data. | |
static int | uid_hold_hash_fn (const void *obj, const int flags) |
static int | uid_hold_sort_fn (const void *obj_left, const void *obj_right, const int flags) |
static int | unload_module (void) |
Unload the PJSIP channel from Asterisk. | |
static int | update_connected_line_information (void *data) |
Update connected line information. | |
static int | update_devstate (void *obj, void *arg, int flags) |
static void | update_initial_connected_line (struct ast_sip_session *session) |
static void | xfer_client_on_evsub_state (pjsip_evsub *sub, pjsip_event *event) |
Callback function to report status of implicit REFER-NOTIFY subscription. More... | |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Channel Driver" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "da6642af068ee5e6490c5b1d2cc1d238" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DRIVER, .requires = "res_pjsip,res_pjsip_session,res_pjsip_pubsub", } |
static char * | app_pjsip_hangup = "PJSIPHangup" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_sip_session_supplement | call_pickup_supplement |
static unsigned int | chan_idx |
static struct ast_sip_session_supplement | chan_pjsip_ack_supplement |
static struct ast_custom_function | chan_pjsip_dial_contacts_function |
static struct ast_custom_function | chan_pjsip_parse_uri_from_function |
static struct ast_custom_function | chan_pjsip_parse_uri_function |
static struct ast_sip_session_supplement | chan_pjsip_prack_supplement |
static struct ast_rtp_glue | chan_pjsip_rtp_glue |
Local glue for interacting with the RTP engine core. | |
static struct ast_sip_session_supplement | chan_pjsip_supplement |
SIP session supplement structure. | |
static struct ast_sip_session_supplement | chan_pjsip_supplement_response |
SIP session supplement structure just for responses. | |
struct ast_channel_tech | chan_pjsip_tech |
PBX interface structure for channel registration. | |
static const char | channel_type [] = "PJSIP" |
static struct ast_datastore_info | direct_media_mitigation_info = { } |
static struct ast_custom_function | dtmf_mode_function |
static struct ast_custom_function | media_offer_function |
static struct ast_custom_function | moh_passthrough_function |
static struct ast_sip_session_supplement | pbx_start_supplement |
static struct ao2_container * | pjsip_uids_onhold |
static pjsip_module | refer_callback_module |
REFER Callback module, used to attach session data structure to subscription. More... | |
static struct ast_custom_function | session_refresh_function |
static struct ast_datastore_info | transport_info |
Datastore used to store local/remote addresses for the INVITE request that created the PJSIP channel. More... | |
static struct ast_threadstorage | uniqueid_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_uniqueid_threadbuf , .custom_init = NULL , } |
PSJIP SIP Channel Driver.
Definition in file chan_pjsip.c.
|
static |
Add a channel ID to the list of PJSIP channels on hold.
chan_uid | - Unique ID of the channel being put into the hold list |
0 | Channel has been added to or was already in the hold list |
-1 | Failed to add channel to the hold list |
Definition at line 1118 of file chan_pjsip.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_link, ast_copy_string(), OBJ_SEARCH_KEY, and RAII_VAR.
Referenced by chan_pjsip_indicate().
|
static |
Determine whether a channel ID is in the list of PJSIP channels on hold.
chan_uid | - Channel being checked |
0 | The channel is not in the hold list |
1 | The channel is in the hold list |
Definition at line 1162 of file chan_pjsip.c.
References OBJ_SEARCH_KEY, and RAII_VAR.
Referenced by chan_pjsip_devicestate().
|
static |
Function called by core to read any waiting frames.
Definition at line 839 of file chan_pjsip.c.
References ast_sip_session::active_media_state, ao2_ref, ast_channel_get_up_time(), ast_channel_is_bridged(), ast_channel_set_unbridged_nolock(), ast_debug, ast_dsp_get_features(), ast_dsp_process(), ast_dsp_set_features(), AST_EXTENDED_FDS, ast_format_cap_alloc, ast_format_cap_append, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_iscompatible_format(), ast_format_cap_remove_by_type(), ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_name(), AST_FRAME_VOICE, AST_LIST_NEXT, ast_null_frame, ast_set_read_format_path(), ast_set_write_format_path(), AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, ast_sip_endpoint::asymmetric_rtp_codec, chan_pjsip_cng_tone_detected(), ast_sip_session_media_state::default_session, ast_sip_session::dsp, ast_sip_session::endpoint, ast_sip_endpoint::faxdetect_timeout, ast_frame_subclass::format, ast_frame::frametype, ast_frame_subclass::integer, is_compatible_format(), ast_sip_session_media_read_callback_state::read_callback, ast_sip_session_media_state::read_callbacks, ast_sip_session_media_read_callback_state::session, ast_sip_channel_pvt::session, ast_frame::subclass, and ast_sip_session_media::type.
|
static |
Remove a channel ID from the list of PJSIP channels on hold.
chan_uid | - Unique ID of the channel being taken out of the hold list |
Definition at line 1149 of file chan_pjsip.c.
References OBJ_NODATA, OBJ_SEARCH_KEY, and OBJ_UNLINK.
Referenced by chan_pjsip_indicate(), and chan_pjsip_session_end().
|
static |
Definition at line 327 of file chan_pjsip.c.
References ast_channel_set_fd(), AST_EXTENDED_FDS, ast_rtp_instance_fd(), ast_rtp_instance_get_and_cmp_remote_address, ast_rtp_instance_set_prop(), AST_RTP_PROPERTY_RTCP, ast_sockaddr_isnull(), ast_sockaddr_setnull(), ast_sip_session_media::direct_media_addr, ast_sip_session_media::rtp, and rtp_find_rtcp_fd_position().
|
static |
Determine if a topology is compatible with format capabilities.
This will return true if ANY formats in the topology are compatible with the format capabilities.
XXX When supporting true multistream, we will need to be sure to mark which streams from top1 are compatible with which streams from top2. Then the ones that are not compatible will need to be marked as "removed" so that they are negotiated as expected.
top | Topology |
cap | Format capabilities |
1 | The topology has at least one compatible format |
0 | The topology has no compatible formats or an error occurred. |
Definition at line 526 of file chan_pjsip.c.
References ao2_ref, ast_format_cap_get_names(), ast_format_cap_iscompatible(), AST_FORMAT_CAP_NAMES_LEN, ast_str_tmp, ast_stream_topology_get_formats(), and ast_stream_topology_to_str().
Referenced by chan_pjsip_new().
|
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 3286 of file chan_pjsip.c.
References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_callback, ao2_container_alloc_hash, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, ao2_ref, ast_channel_register(), ast_channel_unregister(), ast_custom_function_register, ast_custom_function_unregister(), ast_format_cap_alloc, ast_format_cap_append_by_type(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_manager_register_xml, ast_manager_unregister(), AST_MODULE_LOAD_DECLINE, ast_register_application_xml, ast_rtp_glue_unregister(), ast_unregister_application(), ast_channel_tech::capabilities, endpoints, OBJ_NODATA, pjsip_action_hangup(), pjsip_app_hangup(), pjsip_channel_cli_register(), uid_hold_hash_fn(), and uid_hold_sort_fn().
|
static |
AO2 hash function for on hold UIDs
Definition at line 1067 of file chan_pjsip.c.
References ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.
Referenced by load_module().
|
static |
AO2 sort function for on hold UIDs
Definition at line 1085 of file chan_pjsip.c.
References OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.
Referenced by load_module().
|
static |
Callback function to report status of implicit REFER-NOTIFY subscription.
This function will be called on any state change in the REFER-NOTIFY subscription. Its primary purpose is to report SUCCESS/FAILURE of a transfer initiated via transfer_refer as well as to terminate the subscription, if necessary.
Definition at line 1960 of file chan_pjsip.c.
References ao2_ref, AST_CONTROL_TRANSFER, ast_debug, ast_queue_control_data(), AST_TRANSFER_FAILED, and AST_TRANSFER_SUCCESS.
|
static |
Definition at line 3070 of file chan_pjsip.c.
|
static |
Definition at line 164 of file chan_pjsip.c.
|
static |
Definition at line 3236 of file chan_pjsip.c.
|
static |
Definition at line 3246 of file chan_pjsip.c.
|
static |
Definition at line 3241 of file chan_pjsip.c.
|
static |
Definition at line 172 of file chan_pjsip.c.
|
static |
Definition at line 3257 of file chan_pjsip.c.
|
static |
Definition at line 3251 of file chan_pjsip.c.
|
static |
Definition at line 3263 of file chan_pjsip.c.
|
static |
Definition at line 3110 of file chan_pjsip.c.
|
static |
REFER Callback module, used to attach session data structure to subscription.
Definition at line 1948 of file chan_pjsip.c.
|
static |
Definition at line 3269 of file chan_pjsip.c.
|
static |
Datastore used to store local/remote addresses for the INVITE request that created the PJSIP channel.
Definition at line 269 of file chan_pjsip.c.