diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c index 14adf5c561e07edf83bdfc789bfeff9a5629447a..9ee8d0a6437e8b3b4a7efb2429f54a94bb6f4fff 100644 --- a/channels/chan_pjsip.c +++ b/channels/chan_pjsip.c @@ -2835,6 +2835,9 @@ static struct ast_channel *chan_pjsip_request_with_stream_topology(const char *t SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't create channel\n"); } + /* sync emergency call flag between requester(chan_voicemngr) and the new session channel*/ + ast_debug(3, "Emergency call flag syncing %s, %s\n", ast_channel_name(requestor) , ast_channel_name(session->channel)); + ast_channel_emergency_ongoing_set(session->channel, ast_channel_emergency_ongoing_get(requestor)); SCOPE_EXIT_RTN_VALUE(session->channel, "Channel: %s\n", ast_channel_name(session->channel)); } diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 2843de513faff2973c893986aa3ce580df3c7894..5fbc6b182be7fde27a9e0cb2fa2d8bc918df1976 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -4319,8 +4319,10 @@ void ast_channel_sipResponseCode_set(struct ast_channel *chan, unsigned int valu struct ast_channel_snapshot *ast_channel_snapshot(const struct ast_channel *chan); void ast_channel_snapshot_set(struct ast_channel *chan, struct ast_channel_snapshot *snapshot); struct ast_flags *ast_channel_snapshot_segment_flags(struct ast_channel *chan); -rtp_statistics *ast_channel_rtpStats(const struct ast_channel *chan); +rtp_statistics *ast_channel_rtpStats_get(const struct ast_channel *chan); void ast_channel_rtpStats_set(struct ast_channel *chan, rtp_statistics *rtp_stats); +int ast_channel_emergency_ongoing_get(const struct ast_channel *chan); +void ast_channel_emergency_ongoing_set(struct ast_channel *chan, int emergency_ongoing); /*! * \pre chan is locked diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h index 8085e394e0c7c8ce8416c9bfb9f8530d60731bd3..4c1a96b2d6d1f7fc8dd7ecde4c539fea793e057d 100644 --- a/include/asterisk/res_pjsip_session.h +++ b/include/asterisk/res_pjsip_session.h @@ -241,7 +241,7 @@ struct ast_sip_session { enum ast_sip_session_call_direction call_direction; /*! Originating Line Info (ANI II digits) */ int ani2; - int ring_cw; + int ring_cw; int early_media; }; diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c index f35e4b59b5fcd4e423d99edfa5e44ff19d958b74..4d95ab1ec23ef6eda22aec3e463e5ef5cfa922b3 100644 --- a/main/channel_internal_api.c +++ b/main/channel_internal_api.c @@ -231,6 +231,7 @@ struct ast_channel { unsigned int sipResponseCode; /*!< SIP response Code */ char codec[40]; /*!< Negotiated codec used */ rtp_statistics *rtp_stats; /*!< RTP statistics */ + int emergency_ongoing; /*!< indicate if an emergency session is ongoing */ }; /*! \brief The monotonically increasing integer counter for channel uniqueids */ @@ -880,6 +881,16 @@ void ast_channel_rtpStats_set(struct ast_channel *chan, rtp_statistics *rtp_stat chan->rtp_stats = rtp_stats; } +int ast_channel_emergency_ongoing_get(const struct ast_channel *chan) +{ + return chan->emergency_ongoing; +} + +void ast_channel_emergency_ongoing_set(struct ast_channel *chan, int emergency_ongoing) +{ + chan->emergency_ongoing = emergency_ongoing; +} + void ast_channel_callid_set(struct ast_channel *chan, ast_callid callid) { char call_identifier_from[AST_CALLID_BUFFER_LENGTH]; diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index 0cb8babe21fc210e2a26edf315e8f815103ae4ba..80efa3221bb3c41f233a9365077bbffd08d3bfe6 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -2938,6 +2938,14 @@ int ast_sip_session_create_invite(struct ast_sip_session *session, pjsip_tx_data ast_sip_add_header(*tdata,"P-Early-Media","supported"); session->early_media = 1; } + /*Add emergency headers if it is an emergency call */ + /*If dialing an emergency number, add `Priority: emergency` and `Resource-Priority: emrg.0` */ + if(session->channel && ast_channel_emergency_ongoing_get(session->channel)){ + ast_debug(3, "Emergency Call: %s, emergency: %d\n", ast_channel_name(session->channel), ast_channel_emergency_ongoing_get(session->channel)); + ast_debug(3, "INVITE: Adding Priority and Resource-Priority headers \n"); + ast_sip_add_header(*tdata,"Priority","emergency"); + ast_sip_add_header(*tdata,"Resource-Priority","emrg.0"); + } SCOPE_EXIT_RTN_VALUE(0); } @@ -4693,6 +4701,8 @@ static void handle_session_end(struct ast_sip_session *session) if (current_session_count) current_session_count--; + if (session->channel && ast_channel_emergency_ongoing_get(session->channel)) + ast_channel_emergency_ongoing_set(session->channel, 0); /* Session is dead. Notify the supplements. */ AST_LIST_TRAVERSE(&session->supplements, iter, next) { if (iter->session_end) {