Skip to content

Commit

Permalink
Merge pull request #240 from wmnsk/v1-uli
Browse files Browse the repository at this point in the history
[gtpv1] Fix 3-digit MNC handling in ULI
  • Loading branch information
wmnsk authored Sep 2, 2023
2 parents b58c9a2 + 5beffd4 commit dfe8999
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
27 changes: 6 additions & 21 deletions gtpv1/ie/uli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ const (

// NewUserLocationInformationWithCGI creates a new UserLocationInformation IE with LAC.
func NewUserLocationInformationWithCGI(mcc, mnc string, lac, cgi uint16) *IE {
mc, err := utils.StrToSwappedBytes(mcc, "f")
if err != nil {
return nil
}
mn, err := utils.StrToSwappedBytes(mnc, "f")
plmn, err := utils.EncodePLMN(mcc, mnc)
if err != nil {
return nil
}
Expand All @@ -34,8 +30,7 @@ func NewUserLocationInformationWithCGI(mcc, mnc string, lac, cgi uint16) *IE {
make([]byte, 8),
)
uli.Payload[0] = locTypeCGI
copy(uli.Payload[1:3], mc)
uli.Payload[3] = mn[0]
copy(uli.Payload[1:4], plmn)
binary.BigEndian.PutUint16(uli.Payload[4:6], lac)
binary.BigEndian.PutUint16(uli.Payload[6:8], cgi)

Expand All @@ -44,11 +39,7 @@ func NewUserLocationInformationWithCGI(mcc, mnc string, lac, cgi uint16) *IE {

// NewUserLocationInformationWithSAI creates a new UserLocationInformation IE with LAC.
func NewUserLocationInformationWithSAI(mcc, mnc string, lac, sac uint16) *IE {
mc, err := utils.StrToSwappedBytes(mcc, "f")
if err != nil {
return nil
}
mn, err := utils.StrToSwappedBytes(mnc, "f")
plmn, err := utils.EncodePLMN(mcc, mnc)
if err != nil {
return nil
}
Expand All @@ -58,8 +49,7 @@ func NewUserLocationInformationWithSAI(mcc, mnc string, lac, sac uint16) *IE {
make([]byte, 8),
)
uli.Payload[0] = locTypeSAI
copy(uli.Payload[1:3], mc)
uli.Payload[3] = mn[0]
copy(uli.Payload[1:4], plmn)
binary.BigEndian.PutUint16(uli.Payload[4:6], lac)
binary.BigEndian.PutUint16(uli.Payload[6:8], sac)

Expand All @@ -68,11 +58,7 @@ func NewUserLocationInformationWithSAI(mcc, mnc string, lac, sac uint16) *IE {

// NewUserLocationInformationWithRAI creates a new UserLocationInformation IE with LAC.
func NewUserLocationInformationWithRAI(mcc, mnc string, lac uint16, rac uint8) *IE {
mc, err := utils.StrToSwappedBytes(mcc, "f")
if err != nil {
return nil
}
mn, err := utils.StrToSwappedBytes(mnc, "f")
plmn, err := utils.EncodePLMN(mcc, mnc)
if err != nil {
return nil
}
Expand All @@ -82,8 +68,7 @@ func NewUserLocationInformationWithRAI(mcc, mnc string, lac uint16, rac uint8) *
make([]byte, 7),
)
uli.Payload[0] = locTypeRAI
copy(uli.Payload[1:3], mc)
uli.Payload[3] = mn[0]
copy(uli.Payload[1:4], plmn)
binary.BigEndian.PutUint16(uli.Payload[4:6], lac)
uli.Payload[6] = rac

Expand Down
24 changes: 24 additions & 0 deletions gtpv1/ie/uli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ func TestUserLocationInformationWithCGI(t *testing.T) {
t.Errorf("wrong mnc, got %v", mnc)
}
})

t.Run("Test UserLocationInformation with CGI (3-digit MNC)", func(t *testing.T) {
ie := NewUserLocationInformationWithCGI("123", "456", 111, 222)

cgi := ie.MustCGI()
if cgi != 222 {
t.Errorf("wrong cgi, got %v", cgi)
}

lac := ie.MustLAC()
if lac != 111 {
t.Errorf("wrong lac, got %v", lac)
}

mcc := ie.MustMCC()
if mcc != "123" {
t.Errorf("wrong mcc, got %v", mcc)
}

mnc := ie.MustMNC()
if mnc != "456" {
t.Errorf("wrong mnc, got %v", mnc)
}
})
}

func TestUserLocationInformationWithRAI(t *testing.T) {
Expand Down

0 comments on commit dfe8999

Please sign in to comment.