Skip to content

Commit

Permalink
fix:remove unused line and remove BindJson
Browse files Browse the repository at this point in the history
  • Loading branch information
donald1218 committed Jun 5, 2024
1 parent 84c470c commit 01ae65b
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 152 deletions.
4 changes: 3 additions & 1 deletion internal/gmm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2168,14 +2168,16 @@ func HandleAuthenticationFailure(ue *context.AmfUe, anType models.AccessType,
gmm_message.SendAuthenticationRequest(ue.RanUe[anType])
}
} else if ue.AuthenticationCtx.AuthType == models.AuthType_EAP_AKA_PRIME {
if cause5GMM == nasMessage.Cause5GMMngKSIAlreadyInUse {
switch cause5GMM {
case nasMessage.Cause5GMMngKSIAlreadyInUse:
ue.GmmLog.Warn("Authentication Failure 5GMM Cause: NgKSI Already In Use")
if ue.NgKsi.Ksi < 6 { // ksi is range from 0 to 6
ue.NgKsi.Ksi += 1
} else {
ue.NgKsi.Ksi = 0
}
gmm_message.SendAuthenticationRequest(ue.RanUe[anType])
default:
}
}

Expand Down
5 changes: 3 additions & 2 deletions internal/ngap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ func handlePDUSessionResourceModifyResponseMain(ran *context.AmfRan,
ranUe.Log.Errorf("SmContext[PDU Session ID:%d] not found", pduSessionID)
continue
}
// response, _, _, err := consumer.GetConsumer().SendUpdateSmContextN2Info(amfUe, pduSessionID,
_, _, _, err := consumer.GetConsumer().SendUpdateSmContextN2Info(amfUe, smContext,
models.N2SmInfoType_PDU_RES_MOD_FAIL, transfer)
if err != nil {
Expand Down Expand Up @@ -777,7 +776,8 @@ func handlePDUSessionResourceNotifyMain(ran *context.AmfRan,
n2Info := response.BinaryDataN1SmMessage
n1Msg := response.BinaryDataN2SmInformation
if n2Info != nil {
if responseData.N2SmInfoType == models.N2SmInfoType_PDU_RES_MOD_REQ {
switch responseData.N2SmInfoType {
case models.N2SmInfoType_PDU_RES_MOD_REQ:
ranUe.Log.Debugln("AMF Transfer NGAP PDU Resource Modify Req from SMF")
var nasPdu []byte
if n1Msg != nil {
Expand All @@ -791,6 +791,7 @@ func handlePDUSessionResourceNotifyMain(ran *context.AmfRan,
list := ngapType.PDUSessionResourceModifyListModReq{}
ngap_message.AppendPDUSessionResourceModifyListModReq(&list, pduSessionID, nasPdu, n2Info)
ngap_message.SendPDUSessionResourceModifyRequest(ranUe, list)
default:
}
}
} else if errResponse != nil {
Expand Down
14 changes: 7 additions & 7 deletions internal/ngap/message/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,15 @@ func BuildHandoverCancelAcknowledge(

// Criticality Diagnostics [optional]
if criticalityDiagnostics != nil {
HandoverCancelAcknowledgeIEsie := ngapType.HandoverCancelAcknowledgeIEs{}
HandoverCancelAcknowledgeIEsie.Id.Value = ngapType.ProtocolIEIDCriticalityDiagnostics
HandoverCancelAcknowledgeIEsie.Criticality.Value = ngapType.CriticalityPresentIgnore
HandoverCancelAcknowledgeIEsie.Value.Present = ngapType.HandoverCancelAcknowledgeIEsPresentCriticalityDiagnostics
HandoverCancelAcknowledgeIEsie.Value.CriticalityDiagnostics = new(ngapType.CriticalityDiagnostics)
handoverCancelAcknowledgeIEsie := ngapType.HandoverCancelAcknowledgeIEs{}
handoverCancelAcknowledgeIEsie.Id.Value = ngapType.ProtocolIEIDCriticalityDiagnostics
handoverCancelAcknowledgeIEsie.Criticality.Value = ngapType.CriticalityPresentIgnore
handoverCancelAcknowledgeIEsie.Value.Present = ngapType.HandoverCancelAcknowledgeIEsPresentCriticalityDiagnostics
handoverCancelAcknowledgeIEsie.Value.CriticalityDiagnostics = new(ngapType.CriticalityDiagnostics)

HandoverCancelAcknowledgeIEsie.Value.CriticalityDiagnostics = criticalityDiagnostics
handoverCancelAcknowledgeIEsie.Value.CriticalityDiagnostics = criticalityDiagnostics

handoverCancelAcknowledgeIEs.List = append(handoverCancelAcknowledgeIEs.List, HandoverCancelAcknowledgeIEsie)
handoverCancelAcknowledgeIEs.List = append(handoverCancelAcknowledgeIEs.List, handoverCancelAcknowledgeIEsie)
}

return ngap.Encoder(pdu)
Expand Down
2 changes: 1 addition & 1 deletion internal/ngap/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func listenAndServe(addr *sctp.SCTPAddr, handler NGAPHandler, sctpConfig *sctp.S
logger.NgapLog.Infof("Listen on %s", sctpListener.Addr())

for {
newConn, err := sctpListener.AcceptSCTP(5)
newConn, err := sctpListener.AcceptSCTP(-1)
if err != nil {
switch err {
case syscall.EINTR, syscall.EAGAIN:
Expand Down
16 changes: 8 additions & 8 deletions internal/sbi/api_communication.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *Server) HTTPAMFStatusChangeSubscribeModify(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleAMFStatusChangeSubscribeModify(c)
s.Processor().HandleAMFStatusChangeSubscribeModify(c, subscriptionData)
}

// AMFStatusChangeUnSubscribe - Namf_Communication AMF Status Change UnSubscribe service Operation
Expand Down Expand Up @@ -179,7 +179,7 @@ func (s *Server) HTTPCreateUEContext(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleCreateUEContextRequest(c)
s.Processor().HandleCreateUEContextRequest(c, createUeContextRequest)
}

// EBIAssignment - Namf_Communication EBI Assignment service Operation
Expand Down Expand Up @@ -211,7 +211,7 @@ func (s *Server) HTTPEBIAssignment(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleAssignEbiDataRequest(c)
s.Processor().HandleAssignEbiDataRequest(c, assignEbiData)
}

// RegistrationStatusUpdate - Namf_Communication RegistrationStatusUpdate service Operation
Expand Down Expand Up @@ -243,7 +243,7 @@ func (s *Server) HTTPRegistrationStatusUpdate(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleRegistrationStatusUpdateRequest(c)
s.Processor().HandleRegistrationStatusUpdateRequest(c, ueRegStatusUpdateReqData)
}

// ReleaseUEContext - Namf_Communication ReleaseUEContext service Operation
Expand Down Expand Up @@ -275,7 +275,7 @@ func (s *Server) HTTPReleaseUEContext(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleReleaseUEContextRequest(c)
s.Processor().HandleReleaseUEContextRequest(c, ueContextRelease)
}

// UEContextTransfer - Namf_Communication UEContextTransfer service Operation
Expand Down Expand Up @@ -316,7 +316,7 @@ func (s *Server) HTTPUEContextTransfer(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleUEContextTransferRequest(c)
s.Processor().HandleUEContextTransferRequest(c, ueContextTransferRequest)
}

func (s *Server) HTTPN1N2MessageUnSubscribe(c *gin.Context) {
Expand Down Expand Up @@ -397,7 +397,7 @@ func (s *Server) HTTPN1N2MessageSubscribe(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleN1N2MessageSubscribeRequest(c)
s.Processor().HandleN1N2MessageSubscribeRequest(c, ueN1N2InfoSubscriptionCreateData)
}

func (s *Server) HTTPNonUeN2InfoUnSubscribe(c *gin.Context) {
Expand Down Expand Up @@ -443,5 +443,5 @@ func (s *Server) HTTPAMFStatusChangeSubscribe(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleAMFStatusChangeSubscribeRequest(c)
s.Processor().HandleAMFStatusChangeSubscribeRequest(c, subscriptionData)
}
4 changes: 2 additions & 2 deletions internal/sbi/api_eventexposure.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *Server) HTTPModifySubscription(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleModifyAMFEventSubscription(c)
s.Processor().HandleModifyAMFEventSubscription(c, modifySubscriptionRequest)
}

func (s *Server) HTTPCreateSubscription(c *gin.Context) {
Expand Down Expand Up @@ -102,5 +102,5 @@ func (s *Server) HTTPCreateSubscription(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleCreateAMFEventSubscription(c)
s.Processor().HandleCreateAMFEventSubscription(c, createEventSubscription)
}
10 changes: 5 additions & 5 deletions internal/sbi/api_httpcallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *Server) HTTPAmPolicyControlUpdateNotifyUpdate(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleAmPolicyControlUpdateNotifyUpdate(c)
s.Processor().HandleAmPolicyControlUpdateNotifyUpdate(c, policyUpdate)
}

func (s *Server) HTTPAmPolicyControlUpdateNotifyTerminate(c *gin.Context) {
Expand Down Expand Up @@ -102,11 +102,11 @@ func (s *Server) HTTPAmPolicyControlUpdateNotifyTerminate(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleAmPolicyControlUpdateNotifyTerminate(c)
s.Processor().HandleAmPolicyControlUpdateNotifyTerminate(c, terminationNotification)
}

func (s *Server) HTTPN1MessageNotify(c *gin.Context) {
var n1MessageNotification models.N1MessageNotification
var n1MessageNotify models.N1MessageNotify

requestBody, err := c.GetRawData()
if err != nil {
Expand All @@ -121,7 +121,7 @@ func (s *Server) HTTPN1MessageNotify(c *gin.Context) {
return
}

err = openapi.Deserialize(&n1MessageNotification, requestBody, "application/json")
err = openapi.Deserialize(&n1MessageNotify, requestBody, "application/json")
if err != nil {
problemDetail := reqbody + err.Error()
rsp := models.ProblemDetails{
Expand All @@ -133,7 +133,7 @@ func (s *Server) HTTPN1MessageNotify(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleN1MessageNotify(c)
s.Processor().HandleN1MessageNotify(c, n1MessageNotify)
}

func (s *Server) HTTPHandleDeregistrationNotification(c *gin.Context) {
Expand Down
2 changes: 1 addition & 1 deletion internal/sbi/api_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *Server) HTTPProvideLocationInfo(c *gin.Context) {
c.JSON(http.StatusBadRequest, rsp)
return
}
s.Processor().HandleProvideLocationInfoRequest(c)
s.Processor().HandleProvideLocationInfoRequest(c, requestLocInfo)
}

// ProvidePositioningInfo - Namf_Location ProvidePositioningInfo service Operation
Expand Down
38 changes: 8 additions & 30 deletions internal/sbi/processor/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
"github.com/free5gc/openapi/models"
)

func (p *Processor) HandleSmContextStatusNotify(c *gin.Context) {
func (p *Processor) HandleSmContextStatusNotify(c *gin.Context,
smContextStatusNotification models.SmContextStatusNotification,
) {
logger.ProducerLog.Infoln("[AMF] Handle SmContext Status Notify")

supi := c.Param("supi")
Expand All @@ -29,16 +31,6 @@ func (p *Processor) HandleSmContextStatusNotify(c *gin.Context) {
} else {
pduSessionID = pduSessionIDTmp
}
var smContextStatusNotification models.SmContextStatusNotification
if err := c.ShouldBindJSON(&smContextStatusNotification); err != nil {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "INVALID_BODY_FORMAT",
Detail: fmt.Sprintf("Failed to parse SmContextStatusNotification: %+v", err),
}
c.JSON(int(problemDetails.Status), problemDetails)
return
}

problemDetails := p.SmContextStatusNotifyProcedure(supi, int32(pduSessionID), smContextStatusNotification)
if problemDetails != nil {
Expand Down Expand Up @@ -99,15 +91,10 @@ func (p *Processor) SmContextStatusNotifyProcedure(supi string, pduSessionID int
return nil
}

func (p *Processor) HandleAmPolicyControlUpdateNotifyUpdate(c *gin.Context) {
func (p *Processor) HandleAmPolicyControlUpdateNotifyUpdate(c *gin.Context, policyUpdate models.PolicyUpdate) {
logger.ProducerLog.Infoln("Handle AM Policy Control Update Notify [Policy update notification]")

polAssoID := c.Param("polAssoId")
var policyUpdate models.PolicyUpdate
if err := c.ShouldBindJSON(&policyUpdate); err != nil {
logger.ProducerLog.Errorf("Failed to bind JSON: %v", err)
}

problemDetails := p.AmPolicyControlUpdateNotifyUpdateProcedure(polAssoID, policyUpdate)

if problemDetails != nil {
Expand Down Expand Up @@ -202,15 +189,12 @@ func (p *Processor) AmPolicyControlUpdateNotifyUpdateProcedure(polAssoID string,
}

// TS 29.507 4.2.4.3
func (p *Processor) HandleAmPolicyControlUpdateNotifyTerminate(c *gin.Context) {
func (p *Processor) HandleAmPolicyControlUpdateNotifyTerminate(c *gin.Context,
terminationNotification models.TerminationNotification,
) {
logger.ProducerLog.Infoln("Handle AM Policy Control Update Notify [Request for termination of the policy association]")

polAssoID := c.Param("polAssoId")
var terminationNotification models.TerminationNotification
if err := c.ShouldBindJSON(&terminationNotification); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

problemDetails := p.AmPolicyControlUpdateNotifyTerminateProcedure(polAssoID, terminationNotification)
if problemDetails != nil {
Expand Down Expand Up @@ -260,15 +244,9 @@ func (p *Processor) AmPolicyControlUpdateNotifyTerminateProcedure(polAssoID stri
}

// TS 23.502 4.2.2.2.3 Registration with AMF re-allocation
func (p *Processor) HandleN1MessageNotify(c *gin.Context) {
func (p *Processor) HandleN1MessageNotify(c *gin.Context, n1MessageNotify models.N1MessageNotify) {
logger.ProducerLog.Infoln("[AMF] Handle N1 Message Notify")

var n1MessageNotify models.N1MessageNotify
if err := c.ShouldBindJSON(&n1MessageNotify); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

problemDetails := p.N1MessageNotifyProcedure(n1MessageNotify)
if problemDetails != nil {
c.JSON(int(problemDetails.Status), problemDetails)
Expand Down
19 changes: 6 additions & 13 deletions internal/sbi/processor/event_exposure.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ import (
"github.com/free5gc/openapi/models"
)

func (p *Processor) HandleCreateAMFEventSubscription(c *gin.Context) {
var createEventSubscription models.AmfCreateEventSubscription
if err := c.ShouldBindJSON(&createEventSubscription); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

func (p *Processor) HandleCreateAMFEventSubscription(c *gin.Context,
createEventSubscription models.AmfCreateEventSubscription,
) {
createdEventSubscription, problemDetails := p.CreateAMFEventSubscriptionProcedure(createEventSubscription)
if createdEventSubscription != nil {
c.JSON(http.StatusCreated, createdEventSubscription)
Expand Down Expand Up @@ -243,15 +239,12 @@ func (p *Processor) DeleteAMFEventSubscriptionProcedure(subscriptionID string) *
return nil
}

func (p *Processor) HandleModifyAMFEventSubscription(c *gin.Context) {
func (p *Processor) HandleModifyAMFEventSubscription(c *gin.Context,
modifySubscriptionRequest models.ModifySubscriptionRequest,
) {
logger.EeLog.Infoln("Handle Modify AMF Event Subscription")

subscriptionID := c.Param("subscriptionId")
var modifySubscriptionRequest models.ModifySubscriptionRequest
if err := c.ShouldBindJSON(&modifySubscriptionRequest); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

updatedEventSubscription, problemDetails := p.
ModifyAMFEventSubscriptionProcedure(subscriptionID, modifySubscriptionRequest)
Expand Down
8 changes: 1 addition & 7 deletions internal/sbi/processor/location_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ import (
"github.com/free5gc/openapi/models"
)

func (p *Processor) HandleProvideLocationInfoRequest(c *gin.Context) {
func (p *Processor) HandleProvideLocationInfoRequest(c *gin.Context, requestLocInfo models.RequestLocInfo) {
logger.ProducerLog.Info("Handle Provide Location Info Request")

var requestLocInfo models.RequestLocInfo
if err := c.ShouldBindJSON(&requestLocInfo); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

ueContextID := c.Param("ueContextId")

provideLocInfo, problemDetails := p.ProvideLocationInfoProcedure(requestLocInfo, ueContextID)
Expand Down
10 changes: 3 additions & 7 deletions internal/sbi/processor/n1n2message.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,9 @@ func (p *Processor) N1N2MessageTransferStatusProcedure(ueContextID string,
}

// TS 29.518 5.2.2.3.3
func (p *Processor) HandleN1N2MessageSubscribeRequest(c *gin.Context) {
var ueN1N2InfoSubscriptionCreateData models.UeN1N2InfoSubscriptionCreateData
if err := c.ShouldBindJSON(&ueN1N2InfoSubscriptionCreateData); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

func (p *Processor) HandleN1N2MessageSubscribeRequest(c *gin.Context,
ueN1N2InfoSubscriptionCreateData models.UeN1N2InfoSubscriptionCreateData,
) {
ueContextID := c.Param("ueContextId")

ueN1N2InfoSubscriptionCreatedData, problemDetails := p.
Expand Down
18 changes: 4 additions & 14 deletions internal/sbi/processor/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ import (
)

// TS 29.518 5.2.2.5.1
func (p *Processor) HandleAMFStatusChangeSubscribeRequest(c *gin.Context) {
func (p *Processor) HandleAMFStatusChangeSubscribeRequest(c *gin.Context, subscriptionDataReq models.SubscriptionData) {
logger.CommLog.Info("Handle AMF Status Change Subscribe Request")

var subscriptionDataReq models.SubscriptionData
if err := c.ShouldBindJSON(&subscriptionDataReq); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

subscriptionDataRsp, locationHeader, problemDetails := p.AMFStatusChangeSubscribeProcedure(subscriptionDataReq)
if problemDetails != nil {
c.JSON(int(problemDetails.Status), problemDetails)
Expand Down Expand Up @@ -89,15 +83,11 @@ func (p *Processor) AMFStatusChangeUnSubscribeProcedure(subscriptionID string) (
}

// TS 29.518 5.2.2.5.1.3
func (p *Processor) HandleAMFStatusChangeSubscribeModify(c *gin.Context) {
func (p *Processor) HandleAMFStatusChangeSubscribeModify(c *gin.Context,
updateSubscriptionData models.SubscriptionData,
) {
logger.CommLog.Info("Handle AMF Status Change Subscribe Modify Request")

var updateSubscriptionData models.SubscriptionData
if err := c.ShouldBindJSON(&updateSubscriptionData); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

subscriptionID := c.Param("subscriptionId")

updatedSubscriptionData, problemDetails := p.
Expand Down
Loading

0 comments on commit 01ae65b

Please sign in to comment.