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: potential problems that may cause a panic during context setup #359

Merged
merged 4 commits into from
Dec 9, 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
42 changes: 35 additions & 7 deletions gmm/sm.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,17 @@ func SecurityMode(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
func ContextSetup(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
switch event {
case fsm.EntryEvent:
amfUe := args[ArgAmfUe].(*context.AmfUe)
amfUe, ok := args[ArgAmfUe].(*context.AmfUe)
if !ok {
logger.GmmLog.Errorln("invalid type assertion for ArgAmfUe")
return
}
gmmMessage := args[ArgNASMessage]
accessType := args[ArgAccessType].(models.AccessType)
accessType, ok := args[ArgAccessType].(models.AccessType)
if !ok {
logger.GmmLog.Errorln("invalid type assertion for ArgAccessType")
return
}
amfUe.GmmLog.Debugln("EntryEvent at GMM State[ContextSetup]")
amfUe.PublishUeCtxtInfo()
switch message := gmmMessage.(type) {
Expand All @@ -397,9 +405,21 @@ func ContextSetup(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
logger.GmmLog.Errorf("UE state mismatch: receieve wrong gmm message")
}
case GmmMessageEvent:
amfUe := args[ArgAmfUe].(*context.AmfUe)
gmmMessage := args[ArgNASMessage].(*nas.GmmMessage)
accessType := args[ArgAccessType].(models.AccessType)
amfUe, ok := args[ArgAmfUe].(*context.AmfUe)
if !ok {
logger.GmmLog.Errorln("invalid type assertion for ArgAmfUe")
return
}
gmmMessage, ok := args[ArgNASMessage].(*nas.GmmMessage)
if !ok {
logger.GmmLog.Errorln("invalid type assertion for ArgNASMessage")
return
}
accessType, ok := args[ArgAccessType].(models.AccessType)
if !ok {
logger.GmmLog.Errorln("invalid type assertion for ArgAccessType")
return
}
amfUe.GmmLog.Debugln("GmmMessageEvent at GMM State[ContextSetup]")
switch gmmMessage.GetMessageType() {
case nas.MsgTypeIdentityResponse:
Expand Down Expand Up @@ -448,8 +468,16 @@ func ContextSetup(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
logger.GmmLog.Debugln(event)
case NwInitiatedDeregistrationEvent:
logger.GmmLog.Debugln(event)
amfUe := args[ArgAmfUe].(*context.AmfUe)
accessType := args[ArgAccessType].(models.AccessType)
amfUe, ok := args[ArgAmfUe].(*context.AmfUe)
if !ok {
logger.GmmLog.Errorln("invalid type assertion for ArgAmfUe")
return
}
accessType, ok := args[ArgAccessType].(models.AccessType)
if !ok {
logger.GmmLog.Errorln("invalid type assertion for ArgAccessType")
return
}
amfUe.T3550.Stop()
amfUe.T3550 = nil
amfUe.State[accessType].Set(context.Registered)
Expand Down
41 changes: 29 additions & 12 deletions producer/ue_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,18 @@ func AssignEbiDataProcedure(ueContextID string, assignEbiData models.AssignEbiDa
}
}

// TS 29.518 5.2.2.2.2
// HandleRegistrationStatusUpdateRequest TS 29.518 5.2.2.2.2
func HandleRegistrationStatusUpdateRequest(request *httpwrapper.Request) *httpwrapper.Response {
logger.CommLog.Info("Handle Registration Status Update Request")

ueRegStatusUpdateReqData := request.Body.(models.UeRegStatusUpdateReqData)
ueRegStatusUpdateReqData, ok := request.Body.(models.UeRegStatusUpdateReqData)
if !ok {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "INVALID_BODY_FORMAT",
}
return httpwrapper.NewResponse(http.StatusBadRequest, nil, problemDetails)
}
ueContextID := request.Params["ueContextId"]

amfSelf := context.AMF_Self()
Expand All @@ -579,7 +586,7 @@ func HandleRegistrationStatusUpdateRequest(request *httpwrapper.Request) *httpwr
Status: http.StatusNotFound,
Cause: "CONTEXT_NOT_FOUND",
}
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
return httpwrapper.NewResponse(http.StatusNotFound, nil, problemDetails)
}
sbiMsg := context.SbiMsg{
UeContextId: ueContextID,
Expand All @@ -592,17 +599,27 @@ func HandleRegistrationStatusUpdateRequest(request *httpwrapper.Request) *httpwr
ue.EventChannel.SubmitMessage(sbiMsg)
msg, read := <-sbiMsg.Result
if !read {
return httpwrapper.NewResponse(http.StatusNoContent, nil, nil)
}
if msg.RespData != nil {
ueRegStatusUpdateRspData = msg.RespData.(*models.UeRegStatusUpdateRspData)
problemDetails := &models.ProblemDetails{
Status: http.StatusNoContent,
Cause: "MESSAGE_NOT_RECEIVED",
}
return httpwrapper.NewResponse(http.StatusNoContent, nil, problemDetails)
}
// ueRegStatusUpdateRspData, problemDetails := RegistrationStatusUpdateProcedure(ueContextID, ueRegStatusUpdateReqData)
if msg.ProblemDetails != nil {
return httpwrapper.NewResponse(int(msg.ProblemDetails.(*models.ProblemDetails).Status), nil, msg.ProblemDetails.(*models.ProblemDetails))
} else {
return httpwrapper.NewResponse(http.StatusOK, nil, ueRegStatusUpdateRspData)
ueRegStatusUpdateRspData, ok = msg.RespData.(*models.UeRegStatusUpdateRspData)
if !ok {
if msg.ProblemDetails != nil {
if problemDetails, ok := msg.ProblemDetails.(*models.ProblemDetails); ok {
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
}
// Handle unexpected response data type
problemDetails := &models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "UNEXPECTED_RESPONSE_TYPE",
}
return httpwrapper.NewResponse(http.StatusInternalServerError, nil, problemDetails)
}
return httpwrapper.NewResponse(http.StatusOK, nil, ueRegStatusUpdateRspData)
}

func RegistrationStatusUpdateProcedure(ueContextID string, ueRegStatusUpdateReqData models.UeRegStatusUpdateReqData) (
Expand Down
Loading