From 268781e2ec678dfbb9abb4954e322e332020b4af Mon Sep 17 00:00:00 2001 From: donald Date: Sun, 28 Jul 2024 15:55:54 +0000 Subject: [PATCH 1/2] fix: second ue release uecontext without authetication --- internal/context/amf_ran.go | 1 + internal/context/ran_ue.go | 5 +++-- internal/gmm/common/user_profile.go | 8 ++++++++ internal/nas/handler.go | 5 +++++ internal/ngap/handler.go | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/context/amf_ran.go b/internal/context/amf_ran.go index 51197ed..97b3264 100644 --- a/internal/context/amf_ran.go +++ b/internal/context/amf_ran.go @@ -63,6 +63,7 @@ func (ran *AmfRan) NewRanUe(ranUeNgapID int64) (*RanUe, error) { ranUe.RanUeNgapId = ranUeNgapID ranUe.Ran = ran ranUe.Log = ran.Log + ranUe.FindAmfUe = nil ranUe.UpdateLogFields() if ranUeNgapID != RanUeNgapIdUnspecified { diff --git a/internal/context/ran_ue.go b/internal/context/ran_ue.go index 198cbce..4b69aaf 100644 --- a/internal/context/ran_ue.go +++ b/internal/context/ran_ue.go @@ -47,8 +47,9 @@ type RanUe struct { LastActTime *time.Time /* Related Context*/ - AmfUe *AmfUe - Ran *AmfRan + AmfUe *AmfUe + Ran *AmfRan + FindAmfUe *AmfUe /* Routing ID */ RoutingID string diff --git a/internal/gmm/common/user_profile.go b/internal/gmm/common/user_profile.go index 48e1b20..5367d26 100644 --- a/internal/gmm/common/user_profile.go +++ b/internal/gmm/common/user_profile.go @@ -69,6 +69,14 @@ func AttachRanUeToAmfUeAndReleaseOldIfAny(ue *context.AmfUe, ranUe *context.RanU ue.AttachRanUe(ranUe) } +func ClearHoldingRanUe(ranUe *context.RanUe) { + ranUe.DetachAmfUe() + ranUe.Log.Error("Clear Holding RanUE") + causeGroup := ngapType.CausePresentRadioNetwork + causeValue := ngapType.CauseRadioNetworkPresentReleaseDueToNgranGeneratedReason + ngap_message.SendUEContextReleaseCommand(ranUe, context.UeContextReleaseUeContext, causeGroup, causeValue) +} + func PurgeSubscriberData(ue *context.AmfUe, accessType models.AccessType) error { logger.GmmLog.Debugln("PurgeSubscriberData") diff --git a/internal/nas/handler.go b/internal/nas/handler.go index 1b77c88..5584074 100644 --- a/internal/nas/handler.go +++ b/internal/nas/handler.go @@ -36,6 +36,11 @@ func HandleNAS(ue *amf_context.RanUe, procedureCode int64, nasPdu []byte, initia ue.AmfUe.NasPduValue = nasPdu ue.AmfUe.MacFailed = !integrityProtected + if ue.AmfUe.SecurityContextIsValid() && ue.FindAmfUe != nil { + gmm_common.ClearHoldingRanUe(ue.FindAmfUe.RanUe[ue.Ran.AnType]) + ue.FindAmfUe = nil + } + if errDispatch := Dispatch(ue.AmfUe, ue.Ran.AnType, procedureCode, msg); errDispatch != nil { ue.AmfUe.NASLog.Errorf("Handle NAS Error: %v", errDispatch) } diff --git a/internal/ngap/handler.go b/internal/ngap/handler.go index bc61c6b..677b323 100644 --- a/internal/ngap/handler.go +++ b/internal/ngap/handler.go @@ -498,7 +498,7 @@ func handleInitialUEMessageMain(ran *context.AmfRan, // Described in TS 23.502 4.2.2.2.2 step 4 (without UDSF deployment) ranUe.Log.Infof("find AmfUe [%q:%q]", idType, id) ranUe.Log.Debugf("AmfUe Attach RanUe [RanUeNgapID: %d]", ranUe.RanUeNgapId) - gmm_common.AttachRanUeToAmfUeAndReleaseOldIfAny(amfUe, ranUe) + ranUe.FindAmfUe = amfUe } else if regReqType != nasMessage.RegistrationType5GSInitialRegistration { if regReqType == nasMessage.RegistrationType5GSPeriodicRegistrationUpdating || regReqType == nasMessage.RegistrationType5GSMobilityRegistrationUpdating { From 89266cff1c415a934c523dfdf284d38d1aef359d Mon Sep 17 00:00:00 2001 From: donald1218 Date: Mon, 12 Aug 2024 16:06:07 +0000 Subject: [PATCH 2/2] fix: check RanUE is nil or not before detach --- internal/gmm/common/user_profile.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/gmm/common/user_profile.go b/internal/gmm/common/user_profile.go index 5367d26..8201340 100644 --- a/internal/gmm/common/user_profile.go +++ b/internal/gmm/common/user_profile.go @@ -70,11 +70,15 @@ func AttachRanUeToAmfUeAndReleaseOldIfAny(ue *context.AmfUe, ranUe *context.RanU } func ClearHoldingRanUe(ranUe *context.RanUe) { - ranUe.DetachAmfUe() - ranUe.Log.Error("Clear Holding RanUE") - causeGroup := ngapType.CausePresentRadioNetwork - causeValue := ngapType.CauseRadioNetworkPresentReleaseDueToNgranGeneratedReason - ngap_message.SendUEContextReleaseCommand(ranUe, context.UeContextReleaseUeContext, causeGroup, causeValue) + if ranUe != nil { + ranUe.DetachAmfUe() + ranUe.Log.Infof("Clear Holding RanUE") + causeGroup := ngapType.CausePresentRadioNetwork + causeValue := ngapType.CauseRadioNetworkPresentReleaseDueToNgranGeneratedReason + ngap_message.SendUEContextReleaseCommand(ranUe, context.UeContextReleaseUeContext, causeGroup, causeValue) + } else { + logger.GmmLog.Warnf("RanUE is nil") + } } func PurgeSubscriberData(ue *context.AmfUe, accessType models.AccessType) error {