diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c index 61c4cfb7e6..d55bdf9f2e 100644 --- a/channels/chan_pjsip.c +++ b/channels/chan_pjsip.c @@ -1630,8 +1630,12 @@ static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const voi if (channel->session->endpoint->inband_progress || (channel->session->inv_session && channel->session->inv_session->neg && pjmedia_sdp_neg_get_state(channel->session->inv_session->neg) == PJMEDIA_SDP_NEG_STATE_DONE)) { - response_code = 183; res = -1; + if (ast_sip_get_allow_sending_180_after_183()) { + response_code = 180; + } else { + response_code = 183; + } } else { response_code = 180; } diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample index 2d93bd1276..0303050d8f 100644 --- a/configs/samples/pjsip.conf.sample +++ b/configs/samples/pjsip.conf.sample @@ -1311,6 +1311,12 @@ ; creating an implicit subscription (see RFC 4488). ; (default: "yes") +;allow_sending_180_after_183=yes ; Allow Asterisk to send 180 Ringing to an endpoint + ; after 183 Session Progress has been send. + ; If disabled Asterisk will instead send only a + ; 183 Session Progress to the endpoint. + ; (default: "no") + ; MODULE PROVIDING BELOW SECTION(S): res_pjsip_acl ;==========================ACL SECTION OPTIONS========================= ;[acl] diff --git a/contrib/ast-db-manage/config/versions/0bee61aa9425_allow_180_ringing_with_sdp.py b/contrib/ast-db-manage/config/versions/0bee61aa9425_allow_180_ringing_with_sdp.py new file mode 100644 index 0000000000..a6711406e2 --- /dev/null +++ b/contrib/ast-db-manage/config/versions/0bee61aa9425_allow_180_ringing_with_sdp.py @@ -0,0 +1,36 @@ +"""allow_sending_180_after_183 + +Revision ID: 0bee61aa9425 +Revises: 8f72185e437f +Create Date: 2022-04-07 13:51:33.400664 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects.postgresql import ENUM + +# revision identifiers, used by Alembic. +revision = '0bee61aa9425' +down_revision = '8f72185e437f' +AST_BOOL_NAME = 'ast_bool_values' +# We'll just ignore the n/y and f/t abbreviations as Asterisk does not write +# those aliases. +AST_BOOL_VALUES = [ '0', '1', + 'off', 'on', + 'false', 'true', + 'no', 'yes' ] + +def upgrade(): + ############################# Enums ############################## + + # ast_bool_values has already been created, so use postgres enum object + # type to get around "already created" issue - works okay with mysql + ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False) + + op.add_column('ps_globals', sa.Column('allow_sending_180_after_183', ast_bool_values)) + + +def downgrade(): + if op.get_context().bind.dialect.name == 'mssql': + op.drop_constraint('ck_ps_globals_allow_sending_180_after_183_ast_bool_values', 'ps_globals') + op.drop_column('ps_globals', 'allow_sending_180_after_183') diff --git a/doc/CHANGES-staging/chan_pjsip_180_sdp.txt b/doc/CHANGES-staging/chan_pjsip_180_sdp.txt new file mode 100644 index 0000000000..ffd14af10c --- /dev/null +++ b/doc/CHANGES-staging/chan_pjsip_180_sdp.txt @@ -0,0 +1,8 @@ +Subject: chan_pjsip + +added global config option "allow_sending_180_after_183" + +Allow Asterisk to send 180 Ringing to an endpoint +after 183 Session Progress has been send. +If disabled Asterisk will instead send only a +183 Session Progress to the endpoint. diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index 209cdbfba2..ba95c276f2 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -3065,6 +3065,13 @@ int ast_sip_get_mwi_tps_queue_low(void); */ unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void); +/*! + * \brief Retrieve the global setting 'allow_sending_180_after_183'. + * + * \retval non zero if disable. + */ +unsigned int ast_sip_get_allow_sending_180_after_183(void); + /*! * \brief Retrieve the global setting 'use_callerid_contact'. * \since 13.24.0 diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c index 5bc1cc6704..4620c3f544 100644 --- a/res/res_pjsip/config_global.c +++ b/res/res_pjsip/config_global.c @@ -48,6 +48,7 @@ #define DEFAULT_MWI_TPS_QUEUE_HIGH AST_TASKPROCESSOR_HIGH_WATER_LEVEL #define DEFAULT_MWI_TPS_QUEUE_LOW -1 #define DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED 0 +#define DEFAULT_ALLOW_SENDING_180_AFTER_183 0 #define DEFAULT_IGNORE_URI_USER_OPTIONS 0 #define DEFAULT_USE_CALLERID_CONTACT 0 #define DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION 0 @@ -92,6 +93,8 @@ struct global_config { unsigned int contact_expiration_check_interval; /*! Nonzero to disable multi domain support */ unsigned int disable_multi_domain; + /*! Nonzero to disable changing 180/SDP to 183/SDP */ + unsigned int allow_sending_180_after_183; /*! The maximum number of unidentified requests per source IP address before a security event is logged */ unsigned int unidentified_request_count; /*! The period during which unidentified requests are accumulated */ @@ -444,6 +447,21 @@ unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void) return disable_initial_unsolicited; } +unsigned int ast_sip_get_allow_sending_180_after_183(void) +{ + unsigned int allow_sending_180_after_183; + struct global_config *cfg; + + cfg = get_global_cfg(); + if (!cfg) { + return DEFAULT_ALLOW_SENDING_180_AFTER_183; + } + + allow_sending_180_after_183 = cfg->allow_sending_180_after_183; + ao2_ref(cfg, -1); + return allow_sending_180_after_183; +} + unsigned int ast_sip_get_ignore_uri_user_options(void) { unsigned int ignore_uri_user_options; @@ -708,6 +726,9 @@ int ast_sip_initialize_sorcery_global(void) ast_sorcery_object_field_register(sorcery, "global", "mwi_disable_initial_unsolicited", DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED ? "yes" : "no", OPT_BOOL_T, 1, FLDSET(struct global_config, mwi.disable_initial_unsolicited)); + ast_sorcery_object_field_register(sorcery, "global", "allow_sending_180_after_183", + DEFAULT_ALLOW_SENDING_180_AFTER_183 ? "yes" : "no", + OPT_BOOL_T, 1, FLDSET(struct global_config, allow_sending_180_after_183)); ast_sorcery_object_field_register(sorcery, "global", "ignore_uri_user_options", DEFAULT_IGNORE_URI_USER_OPTIONS ? "yes" : "no", OPT_BOOL_T, 1, FLDSET(struct global_config, ignore_uri_user_options)); diff --git a/res/res_pjsip/pjsip_config.xml b/res/res_pjsip/pjsip_config.xml index 9a9ef485bc..84736d6ce5 100644 --- a/res/res_pjsip/pjsip_config.xml +++ b/res/res_pjsip/pjsip_config.xml @@ -2348,6 +2348,17 @@ Advertise support for RFC4488 REFER subscription suppression + + Allow 180 after 183 + + Allow Asterisk to send 180 Ringing to an endpoint + after 183 Session Progress has been send. + If disabled Asterisk will instead send only a + 183 Session Progress to the endpoint. + (default: "no") + + +