Skip to content

Commit

Permalink
support retransmission of identity request and check receicved identi…
Browse files Browse the repository at this point in the history
…ty type (#50)
  • Loading branch information
chliu-nems committed Jan 3, 2022
1 parent e857bcd commit 2d6b9a8
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 28 deletions.
3 changes: 3 additions & 0 deletions context/amf_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type AmfUe struct {
DeregistrationTargetAccessType uint8 // only used when deregistration procedure is initialized by the network
RegistrationAcceptForNon3GPPAccess []byte
RetransmissionOfInitialNASMsg bool
RequestIdentityType uint8
/* Used for AMF relocation */
TargetAmfProfile *models.NfProfile
TargetAmfUri string
Expand Down Expand Up @@ -178,6 +179,8 @@ type AmfUe struct {
T3550 *Timer
/* T3522 (for deregistration request) */
T3522 *Timer
/* T3570 (for identity request) */
T3570 *Timer
/* Ue Context Release Cause */
ReleaseCause map[models.AccessType]*CauseAll
/* T3502 (Assigned by AMF, and used by UE to initialize registration procedure) */
Expand Down
1 change: 1 addition & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type AMFContext struct {
T3550Cfg factory.TimerValue
T3560Cfg factory.TimerValue
T3565Cfg factory.TimerValue
T3570Cfg factory.TimerValue
Locality string
}

Expand Down
1 change: 1 addition & 0 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Configuration struct {
T3550 TimerValue `yaml:"t3550"`
T3560 TimerValue `yaml:"t3560"`
T3565 TimerValue `yaml:"t3565"`
T3570 TimerValue `yaml:"t3570"`
Locality string `yaml:"locality,omitempty"`
}

Expand Down
9 changes: 9 additions & 0 deletions gmm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,15 @@ func HandleIdentityResponse(ue *context.AmfUe, identityResponse *nasMessage.Iden
ue.GmmLog.Info("Handle Identity Response")

mobileIdentityContents := identityResponse.MobileIdentity.GetMobileIdentityContents()
if nasConvert.GetTypeOfIdentity(mobileIdentityContents[0]) != ue.RequestIdentityType {
return fmt.Errorf("Received identity type doesn't match request type")
}

if ue.T3570 != nil {
ue.T3570.Stop()
ue.T3570 = nil // clear the timer
}

switch nasConvert.GetTypeOfIdentity(mobileIdentityContents[0]) { // get type of identity
case nasMessage.MobileIdentity5GSTypeSuci:
var plmnId string
Expand Down
14 changes: 14 additions & 0 deletions gmm/message/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ func SendIdentityRequest(ue *context.RanUe, accessType models.AccessType, typeOf
return
}
ngap_message.SendDownlinkNasTransport(ue, nasMsg, nil)

amfUe.RequestIdentityType = typeOfIdentity

if context.AMF_Self().T3570Cfg.Enable {
cfg := context.AMF_Self().T3570Cfg
amfUe.T3570 = context.NewTimer(cfg.ExpireTime, cfg.MaxRetryTimes, func(expireTimes int32) {
amfUe.GmmLog.Warnf("T3570 expires, retransmit Identity Request (retry: %d)", expireTimes)
ngap_message.SendDownlinkNasTransport(ue, nasMsg, nil)
}, func() {
amfUe.GmmLog.Warnf("T3570 Expires %d times, abort identification procedure & ongoing 5GMM procedure",
cfg.MaxRetryTimes)
gmm_common.RemoveAmfUe(amfUe)
})
}
}

func SendAuthenticationRequest(ue *context.RanUe) {
Expand Down
58 changes: 30 additions & 28 deletions gmm/sm.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ func Authentication(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
case nas.MsgTypeIdentityResponse:
if err := HandleIdentityResponse(amfUe, gmmMessage.IdentityResponse); err != nil {
logger.GmmLog.Errorln(err)
}
// update identity type used for reauthentication
mobileIdentityContents := gmmMessage.IdentityResponse.MobileIdentity.GetMobileIdentityContents()
amfUe.IdentityTypeUsedForRegistration = nasConvert.GetTypeOfIdentity(mobileIdentityContents[0])
} else {
// update identity type used for reauthentication
mobileIdentityContents := gmmMessage.IdentityResponse.MobileIdentity.GetMobileIdentityContents()
amfUe.IdentityTypeUsedForRegistration = nasConvert.GetTypeOfIdentity(mobileIdentityContents[0])

err := GmmFSM.SendEvent(state, AuthRestartEvent, fsm.ArgsType{ArgAmfUe: amfUe, ArgAccessType: accessType})
if err != nil {
logger.GmmLog.Errorln(err)
err := GmmFSM.SendEvent(state, AuthRestartEvent, fsm.ArgsType{ArgAmfUe: amfUe, ArgAccessType: accessType})
if err != nil {
logger.GmmLog.Errorln(err)
}
}
case nas.MsgTypeAuthenticationResponse:
if err := HandleAuthenticationResponse(amfUe, accessType, gmmMessage.AuthenticationResponse); err != nil {
Expand Down Expand Up @@ -327,30 +328,31 @@ func ContextSetup(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
case nas.MsgTypeIdentityResponse:
if err := HandleIdentityResponse(amfUe, gmmMessage.IdentityResponse); err != nil {
logger.GmmLog.Errorln(err)
}
switch amfUe.RegistrationType5GS {
case nasMessage.RegistrationType5GSInitialRegistration:
if err := HandleInitialRegistration(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
err = GmmFSM.SendEvent(state, ContextSetupFailEvent, fsm.ArgsType{
ArgAmfUe: amfUe,
ArgAccessType: accessType,
})
if err != nil {
} else {
switch amfUe.RegistrationType5GS {
case nasMessage.RegistrationType5GSInitialRegistration:
if err := HandleInitialRegistration(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
err = GmmFSM.SendEvent(state, ContextSetupFailEvent, fsm.ArgsType{
ArgAmfUe: amfUe,
ArgAccessType: accessType,
})
if err != nil {
logger.GmmLog.Errorln(err)
}
}
}
case nasMessage.RegistrationType5GSMobilityRegistrationUpdating:
fallthrough
case nasMessage.RegistrationType5GSPeriodicRegistrationUpdating:
if err := HandleMobilityAndPeriodicRegistrationUpdating(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
err = GmmFSM.SendEvent(state, ContextSetupFailEvent, fsm.ArgsType{
ArgAmfUe: amfUe,
ArgAccessType: accessType,
})
if err != nil {
case nasMessage.RegistrationType5GSMobilityRegistrationUpdating:
fallthrough
case nasMessage.RegistrationType5GSPeriodicRegistrationUpdating:
if err := HandleMobilityAndPeriodicRegistrationUpdating(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
err = GmmFSM.SendEvent(state, ContextSetupFailEvent, fsm.ArgsType{
ArgAmfUe: amfUe,
ArgAccessType: accessType,
})
if err != nil {
logger.GmmLog.Errorln(err)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions util/init_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func InitAmfContext(context *context.AMFContext) {
context.T3550Cfg = configuration.T3550
context.T3560Cfg = configuration.T3560
context.T3565Cfg = configuration.T3565
context.T3570Cfg = configuration.T3570
context.Locality = configuration.Locality
}

Expand Down

0 comments on commit 2d6b9a8

Please sign in to comment.