Skip to content

Commit

Permalink
fix: second UE release context without authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
donald1218 committed Jul 12, 2024
1 parent 4f48895 commit 424269b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (ran *AmfRan) NewRanUe(ranUeNgapID int64) (*RanUe, error) {
ranUe.Ran = ran
ranUe.Log = ran.Log
ranUe.UpdateLogFields()
ranUe.IsSecured = false

if ranUeNgapID != RanUeNgapIdUnspecified {
// store to RanUeList only when RANUENGAPID is specified
Expand Down
4 changes: 3 additions & 1 deletion internal/context/amf_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ type AmfUe struct {
/* Pdu Sesseion context */
SmContextList sync.Map // map[int32]*SmContext, pdu session id as key
/* Related Context */
RanUe map[models.AccessType]*RanUe
RanUe map[models.AccessType]*RanUe
HoldingRanUe map[models.AccessType]*RanUe
/* other */
onGoing map[models.AccessType]*OnGoing
UeRadioCapability string // OCTET string
Expand Down Expand Up @@ -272,6 +273,7 @@ func (ue *AmfUe) init() {
ue.UnauthenticatedSupi = true
ue.EventSubscriptionsInfo = make(map[string]*AmfUeEventSubscription)
ue.RanUe = make(map[models.AccessType]*RanUe)
ue.HoldingRanUe = make(map[models.AccessType]*RanUe)
ue.RegistrationArea = make(map[models.AccessType][]models.Tai)
ue.AllowedNssai = make(map[models.AccessType][]models.AllowedSnssai)
ue.N1N2MessageIDGenerator = idgenerator.NewGenerator(1, 2147483647)
Expand Down
5 changes: 3 additions & 2 deletions internal/context/ran_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ type RanUe struct {
LastActTime *time.Time

/* Related Context*/
AmfUe *AmfUe
Ran *AmfRan
AmfUe *AmfUe
Ran *AmfRan
IsSecured bool

/* Routing ID */
RoutingID string
Expand Down
12 changes: 11 additions & 1 deletion internal/gmm/common/user_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,21 @@ func AttachRanUeToAmfUeAndReleaseOldIfAny(ue *context.AmfUe, ranUe *context.RanU
StopAll5GSMMTimers(ue)
causeGroup := ngapType.CausePresentRadioNetwork
causeValue := ngapType.CauseRadioNetworkPresentReleaseDueToNgranGeneratedReason
ngap_message.SendUEContextReleaseCommand(oldRanUe, context.UeContextReleaseUeContext, causeGroup, causeValue)
if ranUe.IsSecured {
ngap_message.SendUEContextReleaseCommand(oldRanUe, context.UeContextReleaseUeContext, causeGroup, causeValue)
}
}
ue.AttachRanUe(ranUe)
}

func ClearHoldingRanUeContext(ue *context.AmfUe, ranUe *context.RanUe) {
ranUe.Log.Infof("ClearHoldingRanUeContext - RanUeNgapID[%d]", ranUe.RanUeNgapId)
causeGroup := ngapType.CausePresentRadioNetwork
causeValue := ngapType.CauseRadioNetworkPresentReleaseDueToNgranGeneratedReason
ngap_message.SendUEContextReleaseCommand(ranUe, context.UeContextReleaseUeContext, causeGroup, causeValue)
ue.HoldingRanUe[ranUe.Ran.AnType] = nil
}

func PurgeSubscriberData(ue *context.AmfUe, accessType models.AccessType) error {
logger.GmmLog.Debugln("PurgeSubscriberData")

Expand Down
8 changes: 8 additions & 0 deletions internal/nas/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func HandleNAS(ue *amf_context.RanUe, procedureCode int64, nasPdu []byte, initia
ue.AmfUe.NasPduValue = nasPdu
ue.AmfUe.MacFailed = !integrityProtected

if ue.AmfUe.SecurityContextIsValid() {
ue.IsSecured = true
}

if ue.AmfUe.HoldingRanUe[ue.Ran.AnType] != nil && ue.IsSecured {
gmm_common.ClearHoldingRanUeContext(ue.AmfUe, ue.AmfUe.HoldingRanUe[ue.Ran.AnType])
}

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

0 comments on commit 424269b

Please sign in to comment.