Skip to content

Commit

Permalink
Fix IMEISV decoding in gtp-v1
Browse files Browse the repository at this point in the history
* Add AUT
* No longer cut off the last digit of an IMEISV
  • Loading branch information
faaxm committed May 6, 2021
1 parent 8204c87 commit e1fa352
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gtpv1/ie/imei.go
Expand Up @@ -6,6 +6,7 @@ package ie

import (
"io"
"strings"

"github.com/wmnsk/go-gtp/utils"
)
Expand All @@ -27,7 +28,8 @@ func (i *IE) IMEISV() (string, error) {
if len(i.Payload) == 0 {
return "", io.ErrUnexpectedEOF
}
return utils.SwappedBytesToStr(i.Payload, true), nil
str := utils.SwappedBytesToStr(i.Payload, false)
return strings.TrimSuffix(str, "f"), nil
}

// MustIMEISV returns IMEISV in string if type matches.
Expand Down
27 changes: 27 additions & 0 deletions gtpv1/ie/imei_test.go
@@ -0,0 +1,27 @@
// Copyright 2019-2021 go-gtp authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.

package ie

import "testing"

func TestIE_IMEISV(t *testing.T) {
t.Run("Encode/Decode IMEI", func(t *testing.T) {
ie := NewIMEISV("123456789012345")

got := ie.MustIMEISV()
if got != "123456789012345" {
t.Errorf("wrong IMEI, got: %v", got)
}
})

t.Run("Encode/Decode IMEISV", func(t *testing.T) {
ie := NewIMEISV("1234567890123456")

got := ie.MustIMEISV()
if got != "1234567890123456" {
t.Errorf("wrong IMEISV, got: %v", got)
}
})
}

0 comments on commit e1fa352

Please sign in to comment.