Skip to content

Commit

Permalink
Fix #84 Wrong MCC+MNC encoding
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin <[email protected]>
  • Loading branch information
linouxis9 committed Feb 28, 2024
1 parent b58e1aa commit ae436e1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 85 deletions.
2 changes: 1 addition & 1 deletion cmd/packetrusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"my5G-RANTester/config"
"my5G-RANTester/internal/templates"
pcap "my5G-RANTester/internal/utils"
pcap "my5G-RANTester/internal/utils/pcap"

// "fmt"
"os"
Expand Down
20 changes: 5 additions & 15 deletions internal/control_test_engine/gnb/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,29 +422,19 @@ func (gnb *GNBContext) GetMccAndMnc() (string, string) {
}

func (gnb *GNBContext) GetMccAndMncInOctets() []byte {
var res string

// reverse mcc and mnc
mcc := reverse(gnb.controlInfo.mcc)
mnc := reverse(gnb.controlInfo.mnc)

// include mcc and mnc in octets
oct5 := mcc[1:3]
var oct6 string
var oct7 string
if len(gnb.controlInfo.mnc) == 2 {
oct6 = "f" + string(mcc[0])
oct7 = mnc
if len(mnc) == 2 {
res = fmt.Sprintf("%c%cf%c%c%c", mcc[1], mcc[2], mcc[0], mnc[0], mnc[1])
} else {
oct6 = string(mnc[0]) + string(mcc[0])
oct7 = mnc[1:3]
}

// changed for bytes.
resu, err := hex.DecodeString(oct5 + oct6 + oct7)
if err != nil {
fmt.Println(err)
res = fmt.Sprintf("%c%c%c%c%c%c", mcc[1], mcc[2], mnc[2], mcc[0], mnc[0], mnc[1])
}

resu, _ := hex.DecodeString(res)
return resu
}

Expand Down
20 changes: 5 additions & 15 deletions internal/control_test_engine/ue/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,29 +422,19 @@ func (ue *UEContext) GetUeSecurityCapability() *nasType.UESecurityCapability {
}

func (ue *UEContext) GetMccAndMncInOctets() []byte {
var res string

// reverse mcc and mnc
mcc := reverse(ue.UeSecurity.mcc)
mnc := reverse(ue.UeSecurity.mnc)

// include mcc and mnc in octets
oct5 := mcc[1:3]
var oct6 string
var oct7 string
if len(ue.UeSecurity.mnc) == 2 {
oct6 = "f" + string(mcc[0])
oct7 = mnc
if len(mnc) == 2 {
res = fmt.Sprintf("%c%cf%c%c%c", mcc[1], mcc[2], mcc[0], mnc[0], mnc[1])
} else {
oct6 = string(mnc[0]) + string(mcc[0])
oct7 = mnc[1:3]
}

// changed for bytes.
resu, err := hex.DecodeString(oct5 + oct6 + oct7)
if err != nil {
fmt.Println(err)
res = fmt.Sprintf("%c%c%c%c%c%c", mcc[1], mcc[2], mnc[2], mcc[0], mnc[0], mnc[1])
}

resu, _ := hex.DecodeString(res)
return resu
}

Expand Down
54 changes: 0 additions & 54 deletions internal/utils/pcap.go

This file was deleted.

0 comments on commit ae436e1

Please sign in to comment.