Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: HoldingAmfUe restore when CM-Idle #141

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (ran *AmfRan) NewRanUe(ranUeNgapID int64) (*RanUe, error) {
ranUe.RanUeNgapId = ranUeNgapID
ranUe.Ran = ran
ranUe.Log = ran.Log
ranUe.FindAmfUe = nil
ranUe.HoldingAmfUe = nil
ranUe.UpdateLogFields()

if ranUeNgapID != RanUeNgapIdUnspecified {
Expand Down
6 changes: 3 additions & 3 deletions internal/context/ran_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type RanUe struct {
LastActTime *time.Time

/* Related Context*/
AmfUe *AmfUe
Ran *AmfRan
FindAmfUe *AmfUe
AmfUe *AmfUe
Ran *AmfRan
HoldingAmfUe *AmfUe // The AmfUe that is already exist (CM-Idle, Re-Registration)

/* Routing ID */
RoutingID string
Expand Down
12 changes: 6 additions & 6 deletions internal/gmm/common/user_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ func PurgeAmfUeSubscriberData(ue *context.AmfUe) {
}
}

func AttachRanUeToAmfUeAndReleaseOldIfAny(ue *context.AmfUe, ranUe *context.RanUe) {
if oldRanUe := ue.RanUe[ranUe.Ran.AnType]; oldRanUe != nil {
func AttachRanUeToAmfUeAndReleaseOldIfAny(amfUe *context.AmfUe, ranUe *context.RanUe) {
if oldRanUe := amfUe.RanUe[ranUe.Ran.AnType]; oldRanUe != nil {
oldRanUe.Log.Infof("Implicit Deregistration - RanUeNgapID[%d]", oldRanUe.RanUeNgapId)
oldRanUe.DetachAmfUe()
if ue.T3550 != nil {
ue.State[ranUe.Ran.AnType].Set(context.Registered)
if amfUe.T3550 != nil {
amfUe.State[ranUe.Ran.AnType].Set(context.Registered)
}
StopAll5GSMMTimers(ue)
StopAll5GSMMTimers(amfUe)
causeGroup := ngapType.CausePresentRadioNetwork
causeValue := ngapType.CauseRadioNetworkPresentReleaseDueToNgranGeneratedReason
ngap_message.SendUEContextReleaseCommand(oldRanUe, context.UeContextReleaseUeContext, causeGroup, causeValue)
}
ue.AttachRanUe(ranUe)
amfUe.AttachRanUe(ranUe)
}

func ClearHoldingRanUe(ranUe *context.RanUe) {
Expand Down
40 changes: 25 additions & 15 deletions internal/nas/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,49 @@ import (
"github.com/free5gc/nas"
)

func HandleNAS(ue *amf_context.RanUe, procedureCode int64, nasPdu []byte, initialMessage bool) {
func HandleNAS(ranUe *amf_context.RanUe, procedureCode int64, nasPdu []byte, initialMessage bool) {
amfSelf := amf_context.GetSelf()

if ue == nil {
if ranUe == nil {
logger.NasLog.Error("RanUe is nil")
return
}

if nasPdu == nil {
ue.Log.Error("nasPdu is nil")
ranUe.Log.Error("nasPdu is nil")
return
}

if ue.AmfUe == nil {
ue.AmfUe = amfSelf.NewAmfUe("")
gmm_common.AttachRanUeToAmfUeAndReleaseOldIfAny(ue.AmfUe, ue)
if ranUe.AmfUe == nil {
// Only the New created RanUE will have no AmfUe in it

if ranUe.HoldingAmfUe != nil && !ranUe.HoldingAmfUe.CmConnect(ranUe.Ran.AnType) {
// If the UE is CM-IDLE, there is no RanUE in AmfUe, so here we attach new RanUe to AmfUe.
gmm_common.AttachRanUeToAmfUeAndReleaseOldIfAny(ranUe.HoldingAmfUe, ranUe)
ranUe.HoldingAmfUe = nil
} else {
// Assume we have an existing UE context in CM-CONNECTED state. (RanUe <-> AmfUe)
// We will release it if the new UE context has a valid security context(Authenticated) in line 50.
ranUe.AmfUe = amfSelf.NewAmfUe("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case of Service Request
UE context is in CM-IDLE state.

gmm_common.AttachRanUeToAmfUeAndReleaseOldIfAny(ranUe.AmfUe, ranUe)
}
}

msg, integrityProtected, err := nas_security.Decode(ue.AmfUe, ue.Ran.AnType, nasPdu, initialMessage)
msg, integrityProtected, err := nas_security.Decode(ranUe.AmfUe, ranUe.Ran.AnType, nasPdu, initialMessage)
if err != nil {
ue.AmfUe.NASLog.Errorln(err)
ranUe.AmfUe.NASLog.Errorln(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assume that we have an existing UE context, which is in CM-CONNECTED state.
We will release it if the new UE context has a valid security context in line 53.

return
}
ue.AmfUe.NasPduValue = nasPdu
ue.AmfUe.MacFailed = !integrityProtected
ranUe.AmfUe.NasPduValue = nasPdu
ranUe.AmfUe.MacFailed = !integrityProtected

if ue.AmfUe.SecurityContextIsValid() && ue.FindAmfUe != nil {
gmm_common.ClearHoldingRanUe(ue.FindAmfUe.RanUe[ue.Ran.AnType])
ue.FindAmfUe = nil
if ranUe.AmfUe.SecurityContextIsValid() && ranUe.HoldingAmfUe != nil {
gmm_common.ClearHoldingRanUe(ranUe.HoldingAmfUe.RanUe[ranUe.Ran.AnType])
ranUe.HoldingAmfUe = nil
}

if errDispatch := Dispatch(ue.AmfUe, ue.Ran.AnType, procedureCode, msg); errDispatch != nil {
ue.AmfUe.NASLog.Errorf("Handle NAS Error: %v", errDispatch)
if errDispatch := Dispatch(ranUe.AmfUe, ranUe.Ran.AnType, procedureCode, msg); errDispatch != nil {
ranUe.AmfUe.NASLog.Errorf("Handle NAS Error: %v", errDispatch)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/ngap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
ranUe.FindAmfUe = amfUe
ranUe.HoldingAmfUe = amfUe
} else if regReqType != nasMessage.RegistrationType5GSInitialRegistration {
if regReqType == nasMessage.RegistrationType5GSPeriodicRegistrationUpdating ||
regReqType == nasMessage.RegistrationType5GSMobilityRegistrationUpdating {
Expand Down
Loading