diff --git a/cmd/packetrusher.go b/cmd/packetrusher.go index 3cbecee3..ce51e27c 100644 --- a/cmd/packetrusher.go +++ b/cmd/packetrusher.go @@ -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" diff --git a/internal/control_test_engine/gnb/context/context.go b/internal/control_test_engine/gnb/context/context.go index b2be1a21..b9e70f57 100644 --- a/internal/control_test_engine/gnb/context/context.go +++ b/internal/control_test_engine/gnb/context/context.go @@ -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 } diff --git a/internal/control_test_engine/ue/context/context.go b/internal/control_test_engine/ue/context/context.go index 8dc09900..facc740b 100644 --- a/internal/control_test_engine/ue/context/context.go +++ b/internal/control_test_engine/ue/context/context.go @@ -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 } diff --git a/internal/utils/pcap.go b/internal/utils/pcap.go deleted file mode 100644 index 8709d51b..00000000 --- a/internal/utils/pcap.go +++ /dev/null @@ -1,54 +0,0 @@ -/** - * SPDX-License-Identifier: Apache-2.0 - * © Copyright 2023 Hewlett Packard Enterprise Development LP - */ -package pcap - -import ( - "my5G-RANTester/config" - "net" - "os" - - log "github.com/sirupsen/logrus" - "github.com/urfave/cli/v2" - "github.com/vishvananda/netlink" - - "github.com/google/gopacket" - "github.com/google/gopacket/layers" - "github.com/google/gopacket/pcapgo" -) - -func CaptureTraffic(path cli.Path) { - f, err := os.Create(path) - if err != nil { - log.Fatal(err) - } - - config := config.GetConfig() - ip := net.ParseIP(config.AMF.Ip) - route, err := netlink.RouteGet(ip) - if err != nil || len(route) <= 0 { - log.Fatal("Unable to capture traffic to AMF as we are unable to determine route to AMF. Aborting.", err) - } - - iif, err := netlink.LinkByIndex(route[0].LinkIndex) - - pcapw := pcapgo.NewWriter(f) - if err := pcapw.WriteFileHeader(1600, layers.LinkTypeEthernet); err != nil { - log.Fatalf("WriteFileHeader: %v", err) - } - - handle, err := pcapgo.NewEthernetHandle(iif.Attrs().Name) - if err != nil { - log.Fatalf("OpenEthernet: %v", err) - } - - pkgsrc := gopacket.NewPacketSource(handle, layers.LayerTypeEthernet) - go func() { - for packet := range pkgsrc.Packets() { - if err := pcapw.WritePacket(packet.Metadata().CaptureInfo, packet.Data()); err != nil { - log.Fatalf("pcap.WritePacket(): %v", err) - } - } - }() -}