[MME] Implicit Network-initiated Deregistration (#2013)

* [MME] Introduce aging timers

* Creating three new timers
* mirroring work done by gstaa on the AMF
* Implicit detach procedures added
* Fix for detach from unknown UE

* no Purge Timer, no config, expanded code
This commit is contained in:
jmasterfunk84 2023-01-26 06:22:17 -06:00 committed by GitHub
parent 95e5d95faf
commit 1e6b1d4f7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 285 additions and 39 deletions

View File

@ -437,5 +437,4 @@ usrsctp:
# value: 3240 # 54 minutes * 60 = 3240 seconds
# t3423:
# value: 720 # 12 minutes * 60 = 720 seconds
#
time:

View File

@ -61,6 +61,8 @@ void emm_state_de_registered(ogs_fsm_t *s, mme_event_t *e)
ogs_assert(e);
mme_sm_debug(e);
mme_ue = e->mme_ue;
ogs_assert(mme_ue);
@ -110,6 +112,8 @@ void emm_state_registered(ogs_fsm_t *s, mme_event_t *e)
ogs_assert(e);
mme_sm_debug(e);
mme_ue = e->mme_ue;
ogs_assert(mme_ue);
@ -176,6 +180,37 @@ void emm_state_registered(ogs_fsm_t *s, mme_event_t *e)
}
break;
case MME_TIMER_MOBILE_REACHABLE:
ogs_info("[%s] Mobile Reachable timer expired", mme_ue->imsi_bcd);
CLEAR_MME_UE_TIMER(mme_ue->t_mobile_reachable);
/* TS 24.301 5.3.5
* Upon expiry of the mobile reachable timer the network shall
* start the implicit detach timer.
*/
ogs_debug("[%s] Starting Implicit Detach timer",
mme_ue->imsi_bcd);
ogs_timer_start(mme_ue->t_implicit_detach.timer,
ogs_time_from_sec(mme_self()->time.t3412.value + 240));
break;
case MME_TIMER_IMPLICIT_DETACH:
ogs_info("[%s] Implicit Detach timer expired, detaching UE",
mme_ue->imsi_bcd);
CLEAR_MME_UE_TIMER(mme_ue->t_implicit_detach);
/* TS 24.301 5.3.5
* If the implicit detach timer expires before the UE contacts
* the network, the network shall implicitly detach the UE.
*/
mme_ue->detach_type = MME_DETACH_TYPE_MME_IMPLICIT;
if (MME_P_TMSI_IS_AVAILABLE(mme_ue)) {
ogs_assert(OGS_OK == sgsap_send_detach_indication(mme_ue));
} else {
mme_send_delete_session_or_detach(mme_ue);
}
OGS_FSM_TRAN(s, &emm_state_de_registered);
break;
default:
ogs_error("Unknown timer[%s:%d]",
mme_timer_get_name(e->timer_id), e->timer_id);
@ -195,9 +230,11 @@ static void common_register_state(ogs_fsm_t *s, mme_event_t *e)
enb_ue_t *enb_ue = NULL;
ogs_nas_eps_message_t *message = NULL;
ogs_nas_security_header_type_t h;
ogs_assert(e);
mme_sm_debug(e);
mme_ue = e->mme_ue;
ogs_assert(mme_ue);
@ -640,6 +677,24 @@ static void common_register_state(ogs_fsm_t *s, mme_event_t *e)
break;
}
if (!MME_UE_HAVE_IMSI(mme_ue)) {
ogs_warn("Detach request : Unknown UE");
ogs_assert(OGS_OK ==
nas_eps_send_service_reject(mme_ue,
OGS_NAS_EMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK));
OGS_FSM_TRAN(s, &emm_state_exception);
break;
}
if (!SECURITY_CONTEXT_IS_VALID(mme_ue)) {
ogs_warn("No Security Context : IMSI[%s]", mme_ue->imsi_bcd);
ogs_assert(OGS_OK ==
nas_eps_send_service_reject(mme_ue,
OGS_NAS_EMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK));
OGS_FSM_TRAN(s, &emm_state_exception);
break;
}
if (MME_P_TMSI_IS_AVAILABLE(mme_ue)) {
ogs_assert(OGS_OK == sgsap_send_detach_indication(mme_ue));
} else {

View File

@ -2402,6 +2402,22 @@ mme_ue_t *mme_ue_add(enb_ue_t *enb_ue)
return NULL;
}
mme_ue->t3470.pkbuf = NULL;
mme_ue->t_mobile_reachable.timer = ogs_timer_add(
ogs_app()->timer_mgr, mme_timer_mobile_reachable_expire, mme_ue);
if (!mme_ue->t_mobile_reachable.timer) {
ogs_error("ogs_timer_add() failed");
ogs_pool_free(&mme_ue_pool, mme_ue);
return NULL;
}
mme_ue->t_mobile_reachable.pkbuf = NULL;
mme_ue->t_implicit_detach.timer = ogs_timer_add(
ogs_app()->timer_mgr, mme_timer_implicit_detach_expire, mme_ue);
if (!mme_ue->t_implicit_detach.timer) {
ogs_error("ogs_timer_add() failed");
ogs_pool_free(&mme_ue_pool, mme_ue);
return NULL;
}
mme_ue->t_implicit_detach.pkbuf = NULL;
mme_ebi_pool_init(mme_ue);
@ -2493,6 +2509,8 @@ void mme_ue_remove(mme_ue_t *mme_ue)
ogs_timer_delete(mme_ue->t3450.timer);
ogs_timer_delete(mme_ue->t3460.timer);
ogs_timer_delete(mme_ue->t3470.timer);
ogs_timer_delete(mme_ue->t_mobile_reachable.timer);
ogs_timer_delete(mme_ue->t_implicit_detach.timer);
enb_ue_unlink(mme_ue);

View File

@ -517,6 +517,8 @@ struct mme_ue_s {
CLEAR_MME_UE_TIMER((__mME)->t3450); \
CLEAR_MME_UE_TIMER((__mME)->t3460); \
CLEAR_MME_UE_TIMER((__mME)->t3470); \
CLEAR_MME_UE_TIMER((__mME)->t_mobile_reachable); \
CLEAR_MME_UE_TIMER((__mME)->t_implicit_detach); \
\
ogs_list_for_each(&mme_ue->sess_list, sess) { \
ogs_list_for_each(&sess->bearer_list, bearer) { \
@ -537,7 +539,8 @@ struct mme_ue_s {
ogs_pkbuf_t *pkbuf;
ogs_timer_t *timer;
uint32_t retry_count;;
} t3413, t3422, t3450, t3460, t3470;
} t3413, t3422, t3450, t3460, t3470, t_mobile_reachable,
t_implicit_detach;
#define CLEAR_SERVICE_INDICATOR(__mME) \
do { \

View File

@ -22,6 +22,7 @@
#include "sgsap-path.h"
#include "mme-gtp-path.h"
#include "mme-path.h"
#include "mme-fd-path.h"
#include "mme-sm.h"
void mme_send_delete_session_or_detach(mme_ue_t *mme_ue)
@ -61,10 +62,31 @@ void mme_send_delete_session_or_detach(mme_ue_t *mme_ue)
}
break;
/* MME Implicit Detach, ie: Lost Communication */
/* MME Implicit Detach, ie: Lost Communication
* TS23.401 - V16.10.0
* Ch 5.3.8.3 MME-initiated Detach procedure (Without Step 1)
*/
case MME_DETACH_TYPE_MME_IMPLICIT:
ogs_fatal("Not Implemented : MME_DETACH_TYPE_MME_IMPLICIT");
ogs_assert_if_reached();
ogs_debug("Implicit MME Detach");
if (SESSION_CONTEXT_IS_AVAILABLE(mme_ue)) {
mme_gtp_send_delete_all_sessions(mme_ue,
OGS_GTP_DELETE_SEND_RELEASE_WITH_UE_CONTEXT_REMOVE);
} else {
enb_ue_t *enb_ue = enb_ue_cycle(mme_ue->enb_ue);
if (enb_ue) {
ogs_assert(OGS_OK ==
s1ap_send_ue_context_release_command(enb_ue,
S1AP_Cause_PR_nas, S1AP_CauseNas_normal_release,
S1AP_UE_CTX_REL_UE_CONTEXT_REMOVE, 0));
} else {
if (mme_ue->location_updated_but_not_canceled_yet == true) {
mme_s6a_send_pur(mme_ue);
} else {
mme_ue_hash_remove(mme_ue);
mme_ue_remove(mme_ue);
}
}
}
break;
/* HSS Implicit Detach, ie: MME-UPDATE-PROCEDURE

View File

@ -904,11 +904,27 @@ void mme_s11_handle_create_bearer_request(
if (OGS_FSM_CHECK(&default_bearer->sm, esm_state_active)) {
if (ECM_IDLE(mme_ue)) {
MME_STORE_PAGING_INFO(mme_ue,
if (ogs_timer_running(mme_ue->t_implicit_detach.timer)) {
/*
* TS 24.301 5.3.7
* If ISR is not activated, the network behaviour upon expiry of
* the mobile reachable timer is network dependent, but typically
* the network stops sending paging messages to the UE on the
* first expiry, and may take other appropriate actions
*/
ogs_debug("[%s] Paging stopped: Mobile Reachable timer expiry",
mme_ue->imsi_bcd);
ogs_assert(OGS_OK ==
mme_gtp_send_create_bearer_response(
bearer, OGS_GTP2_CAUSE_UNABLE_TO_PAGE_UE));
} else {
MME_STORE_PAGING_INFO(mme_ue,
MME_PAGING_TYPE_CREATE_BEARER, bearer);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
}
} else {
r = nas_eps_send_activate_dedicated_bearer_context_request(bearer);
ogs_expect(r == OGS_OK);
@ -1036,11 +1052,27 @@ void mme_s11_handle_update_bearer_request(
if (req->bearer_contexts.bearer_level_qos.presence == 1 ||
req->bearer_contexts.tft.presence == 1) {
if (ECM_IDLE(mme_ue)) {
MME_STORE_PAGING_INFO(mme_ue,
if (ogs_timer_running(mme_ue->t_implicit_detach.timer)) {
/*
* TS 24.301 5.3.7
* If ISR is not activated, the network behaviour upon expiry of
* the mobile reachable timer is network dependent, but typically
* the network stops sending paging messages to the UE on the
* first expiry, and may take other appropriate actions
*/
ogs_debug("[%s] Paging stopped: Mobile Reachable timer expiry",
mme_ue->imsi_bcd);
ogs_assert(OGS_OK ==
mme_gtp_send_update_bearer_response(
bearer, OGS_GTP2_CAUSE_UNABLE_TO_PAGE_UE));
} else {
MME_STORE_PAGING_INFO(mme_ue,
MME_PAGING_TYPE_UPDATE_BEARER, bearer);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
}
} else {
r = nas_eps_send_modify_bearer_context_request(bearer,
req->bearer_contexts.bearer_level_qos.presence,
@ -1175,10 +1207,27 @@ void mme_s11_handle_delete_bearer_request(
bearer->delete.xact = xact;
if (ECM_IDLE(mme_ue)) {
MME_STORE_PAGING_INFO(mme_ue, MME_PAGING_TYPE_DELETE_BEARER, bearer);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
if (ogs_timer_running(mme_ue->t_implicit_detach.timer)) {
/*
* TS 24.301 5.3.7
* If ISR is not activated, the network behaviour upon expiry of
* the mobile reachable timer is network dependent, but typically
* the network stops sending paging messages to the UE on the
* first expiry, and may take other appropriate actions
*/
ogs_debug("[%s] Paging stopped: Mobile Reachable timer expiry",
mme_ue->imsi_bcd);
ogs_assert(OGS_OK ==
mme_gtp_send_delete_bearer_response(
bearer, OGS_GTP2_CAUSE_UNABLE_TO_PAGE_UE));
} else {
MME_STORE_PAGING_INFO(mme_ue,
MME_PAGING_TYPE_DELETE_BEARER, bearer);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
}
} else {
r = nas_eps_send_deactivate_bearer_context_request(bearer);
ogs_expect(r == OGS_OK);
@ -1435,12 +1484,26 @@ void mme_s11_handle_downlink_data_notification(
* before step 9, the MME shall not send S1 interface paging messages
*/
if (ECM_IDLE(mme_ue)) {
MME_STORE_PAGING_INFO(mme_ue,
if (ogs_timer_running(mme_ue->t_implicit_detach.timer)) {
/*
* TS 24.301 5.3.7
* If ISR is not activated, the network behaviour upon expiry of
* the mobile reachable timer is network dependent, but typically
* the network stops sending paging messages to the UE on the
* first expiry, and may take other appropriate actions
*/
ogs_debug("[%s] Paging stopped: Mobile Reachable timer expiry",
mme_ue->imsi_bcd);
ogs_assert(OGS_OK ==
mme_gtp_send_downlink_data_notification_ack(
bearer, OGS_GTP2_CAUSE_UNABLE_TO_PAGE_UE));
} else {
MME_STORE_PAGING_INFO(mme_ue,
MME_PAGING_TYPE_DOWNLINK_DATA_NOTIFICATION, bearer);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
}
} else if (ECM_CONNECTED(mme_ue)) {
if (cause_value == OGS_GTP2_CAUSE_ERROR_INDICATION_RECEIVED) {

View File

@ -264,10 +264,28 @@ void mme_s6a_handle_clr(mme_ue_t *mme_ue, ogs_diam_s6a_message_t *s6a_message)
* we need to check whether UE is IDLE or not.
*/
if (ECM_IDLE(mme_ue)) {
MME_STORE_PAGING_INFO(mme_ue, MME_PAGING_TYPE_DETACH_TO_UE, NULL);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
if (ogs_timer_running(mme_ue->t_implicit_detach.timer)) {
/*
* TS 24.301 5.3.7
* If ISR is not activated, the network behaviour upon expiry of
* the mobile reachable timer is network dependent, but typically
* the network stops sending paging messages to the UE on the
* first expiry, and may take other appropriate actions
*/
ogs_debug("[%s] Paging stopped: Mobile Reachable timer expiry",
mme_ue->imsi_bcd);
if (MME_P_TMSI_IS_AVAILABLE(mme_ue)) {
ogs_assert(OGS_OK == sgsap_send_detach_indication(mme_ue));
} else {
mme_send_delete_session_or_detach(mme_ue);
}
} else {
MME_STORE_PAGING_INFO(mme_ue,
MME_PAGING_TYPE_DETACH_TO_UE, NULL);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
}
} else {
r = nas_eps_send_detach_request(mme_ue);
ogs_expect(r == OGS_OK);

View File

@ -307,6 +307,9 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e)
ogs_assert(r != OGS_ERROR);
}
enb_ue_associate_mme_ue(enb_ue, mme_ue);
ogs_debug("Mobile Reachable timer stopped for IMSI[%s]",
mme_ue->imsi_bcd);
CLEAR_MME_UE_TIMER(mme_ue->t_mobile_reachable);
}
ogs_assert(mme_ue);

View File

@ -92,6 +92,10 @@ const char *mme_timer_get_name(mme_timer_e id)
return "MME_TIMER_T3470";
case MME_TIMER_T3489:
return "MME_TIMER_T3489";
case MME_TIMER_MOBILE_REACHABLE:
return "MME_TIMER_MOBILE_REACHABLE";
case MME_TIMER_IMPLICIT_DETACH:
return "MME_TIMER_IMPLICIT_DETACH";
case MME_TIMER_SGS_CLI_CONN_TO_SRV:
return "MME_TIMER_SGS_CLI_CONN_TO_SRV";
case MME_TIMER_S1_HOLDING:
@ -160,6 +164,14 @@ void mme_timer_t3470_expire(void *data)
{
emm_timer_event_send(MME_TIMER_T3470, data);
}
void mme_timer_mobile_reachable_expire(void *data)
{
emm_timer_event_send(MME_TIMER_MOBILE_REACHABLE, data);
}
void mme_timer_implicit_detach_expire(void *data)
{
emm_timer_event_send(MME_TIMER_IMPLICIT_DETACH, data);
}
static void esm_timer_event_send(
mme_timer_e timer_id, mme_bearer_t *bearer)

View File

@ -40,6 +40,9 @@ typedef enum {
MME_TIMER_T3470,
MME_TIMER_T3489,
MME_TIMER_MOBILE_REACHABLE,
MME_TIMER_IMPLICIT_DETACH,
MME_TIMER_S11_HOLDING,
MME_TIMER_SGS_CLI_CONN_TO_SRV,
@ -67,6 +70,9 @@ void mme_timer_t3460_expire(void *data);
void mme_timer_t3470_expire(void *data);
void mme_timer_t3489_expire(void *data);
void mme_timer_mobile_reachable_expire(void *data);
void mme_timer_implicit_detach_expire(void *data);
void mme_timer_sgs_cli_conn_to_srv(void *data);
void mme_timer_s1_holding_timer_expire(void *data);
void mme_timer_s11_holding_timer_expire(void *data);

View File

@ -330,6 +330,9 @@ void s1ap_handle_initial_ue_message(mme_enb_t *enb, ogs_s1ap_message_t *message)
ogs_assert(r != OGS_ERROR);
}
enb_ue_associate_mme_ue(enb_ue, mme_ue);
ogs_debug("Mobile Reachable timer stopped for IMSI[%s]",
mme_ue->imsi_bcd);
CLEAR_MME_UE_TIMER(mme_ue->t_mobile_reachable);
}
}
}
@ -1535,6 +1538,13 @@ void s1ap_handle_ue_context_release_action(enb_ue_t *enb_ue)
* to prevent retransmission of NAS messages.
*/
CLEAR_MME_UE_ALL_TIMERS(mme_ue);
if (OGS_FSM_CHECK(&mme_ue->sm, emm_state_registered)) {
ogs_debug("Mobile Reachable timer started for IMSI[%s]",
mme_ue->imsi_bcd);
ogs_timer_start(mme_ue->t_mobile_reachable.timer,
ogs_time_from_sec(mme_self()->time.t3412.value + 240));
}
}
switch (enb_ue->ue_ctx_rel_action) {
@ -3099,6 +3109,8 @@ void s1ap_handle_handover_notification(
target_ue->enb_ue_s1ap_id, target_ue->mme_ue_s1ap_id);
enb_ue_associate_mme_ue(target_ue, mme_ue);
ogs_debug("Mobile Reachable timer stopped for IMSI[%s]", mme_ue->imsi_bcd);
CLEAR_MME_UE_TIMER(mme_ue->t_mobile_reachable);
memcpy(&target_ue->saved.tai.plmn_id, pLMNidentity->buf,
sizeof(target_ue->saved.tai.plmn_id));

View File

@ -380,6 +380,8 @@ int s1ap_send_paging(mme_ue_t *mme_ue, S1AP_CNDomain_t cn_domain)
int i;
int rv;
ogs_assert(ogs_timer_running(mme_ue->t_implicit_detach.timer) == false);
/* Find enB with matched TAI */
ogs_list_for_each(&mme_self()->enb_list, enb) {
for (i = 0; i < enb->num_of_supported_ta_list; i++) {

View File

@ -387,20 +387,53 @@ void sgsap_handle_paging_request(mme_vlr_t *vlr, ogs_pkbuf_t *pkbuf)
if (ECM_IDLE(mme_ue)) {
if (CS_CALL_SERVICE_INDICATOR(mme_ue)) {
/* UE will respond Extended Service Request in PS CNDomain*/
MME_STORE_PAGING_INFO(mme_ue,
MME_PAGING_TYPE_CS_CALL_SERVICE, NULL);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_cs);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
if (ogs_timer_running(mme_ue->t_implicit_detach.timer)) {
/*
* TS 24.301 5.3.7
* If ISR is not activated, the network behaviour upon
* expiry of the mobile reachable timer is network dependent,
* but typically the network stops sending paging messages to
* the UE on the first expiry, and may take other appropriate
* actions
*/
ogs_debug("[%s] Paging stopped: Mobile Reachable timeout",
mme_ue->imsi_bcd);
ogs_assert(OGS_OK ==
sgsap_send_paging_reject(
mme_ue, SGSAP_SGS_CAUSE_UE_UNREACHABLE));
} else {
/* UE will respond Extended Service Request in PS CNDomain*/
MME_STORE_PAGING_INFO(mme_ue,
MME_PAGING_TYPE_CS_CALL_SERVICE, NULL);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_cs);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
}
} else if (SMS_SERVICE_INDICATOR(mme_ue)) {
/* UE will respond Service Request in PS CNDomain*/
MME_STORE_PAGING_INFO(mme_ue,
if (ogs_timer_running(mme_ue->t_implicit_detach.timer)) {
/*
* TS 24.301 5.3.7
* If ISR is not activated, the network behaviour upon
* expiry of the mobile reachable timer is network dependent,
* but typically the network stops sending paging messages to
* the UE on the first expiry, and may take other appropriate
* actions
*/
ogs_debug("[%s] Paging stopped: Mobile Reachable timer expiry",
mme_ue->imsi_bcd);
ogs_assert(OGS_OK ==
sgsap_send_paging_reject(
mme_ue, SGSAP_SGS_CAUSE_UE_UNREACHABLE));
} else {
/* UE will respond Service Request in PS CNDomain*/
MME_STORE_PAGING_INFO(mme_ue,
MME_PAGING_TYPE_SMS_SERVICE, NULL);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
r = s1ap_send_paging(mme_ue, S1AP_CNDomain_ps);
ogs_expect(r == OGS_OK);
ogs_assert(r != OGS_ERROR);
}
} else
goto paging_reject;