├── .gitignore ├── sample ├── sample1 ├── my5g_basic_config │ ├── utils │ │ ├── Stop │ │ ├── wireshark_core_n3iwf.sh │ │ ├── run_postman.sh │ │ ├── wireshark_ue.sh │ │ ├── wireshark_upf.sh │ │ ├── n3iwf_gtp_info.sh │ │ ├── kill_core.sh │ │ ├── upf_gtp_info.sh │ │ ├── run_upf.sh │ │ ├── list_interfaces.sh │ │ ├── run_ue.sh │ │ ├── initial_registration.sh │ │ ├── run_core.sh │ │ ├── env_manager.sh │ │ └── add_test_ue.sh │ ├── free5GC.conf │ ├── Architecture.png │ ├── webuicfg.conf │ ├── uecfg.conf │ ├── udrcfg.conf │ ├── nrfcfg.conf │ ├── ausfcfg.conf │ ├── upfcfg.yaml │ ├── pcfcfg.conf │ ├── uerouting.yaml │ ├── test │ │ ├── smfcfg.test.conf │ │ ├── smfcfg.single.test.conf │ │ └── smfcfg.ulcl.test.conf │ ├── amfcfg.conf │ ├── amfcfg.n3test.conf │ ├── smfcfg.conf │ ├── my5G-core.conf │ ├── n3iwfcfg.conf │ ├── udmcfg.conf │ └── nssfcfg.conf ├── my5g_wifi_config │ ├── figs │ │ ├── far.png │ │ ├── pdr.png │ │ ├── policy.png │ │ ├── state.png │ │ ├── bashpid.png │ │ ├── iwconfig.png │ │ ├── proposal.png │ │ ├── my5g-logo.png │ │ ├── pdu-session.png │ │ ├── interface-y2.png │ │ ├── registration.png │ │ ├── tshoot-gtp5g.png │ │ ├── first-terminal.png │ │ ├── ip-address-wlan1.png │ │ ├── ping-test-ue-upf.png │ │ ├── ping-ue-internet.png │ │ ├── second-terminal.png │ │ ├── hostapd-background.png │ │ ├── traceroute-ue-upf.png │ │ ├── general-architecture.png │ │ ├── success-interface-y1.png │ │ └── traceroute-ue-internet.png │ ├── captures │ │ ├── ping-test-ue-to-upf.zip │ │ └── wireshark-all-traffic.pcapng │ ├── webuicfg.conf │ ├── uecfg.conf │ ├── utils │ │ ├── fix_core.sh │ │ ├── env_manager.sh │ │ └── add_test_ue.sh │ ├── nrfcfg.conf │ ├── udrcfg.conf │ ├── ausfcfg.conf │ ├── upfcfg.yaml │ ├── pcfcfg.conf │ ├── uerouting.yaml │ ├── amfcfg.conf │ ├── amfcfg.n3test.conf │ ├── smfcfg.conf │ ├── free5GC.conf │ ├── my5G-core.conf │ ├── n3iwfcfg.conf │ ├── udmcfg.conf │ └── nssfcfg.conf ├── ran_attach_config │ ├── webuicfg.conf │ ├── udrcfg.conf │ ├── ausfcfg.conf │ ├── nrfcfg.conf │ ├── upfcfg.yaml │ ├── pcfcfg.conf │ ├── smfcfg.conf │ ├── amfcfg.conf │ ├── free5GC.conf │ ├── udmcfg.conf │ └── nssfcfg.conf └── my5g_docker_config │ ├── uecfg.conf │ ├── udrcfg.conf │ ├── ausfcfg.conf │ ├── nrfcfg.conf │ ├── upfcfg.yaml │ ├── pcfcfg.conf │ ├── uerouting.yaml │ ├── smfcfg.conf │ ├── test │ ├── smfcfg.single.test.conf │ ├── amfcfg.n3test.conf │ ├── smfcfg.test.conf │ ├── smfcfg.ulcl.test.conf │ └── smfcfg.conf │ ├── amfcfg.conf │ ├── free5GC.conf │ ├── n3iwfcfg.conf │ ├── udmcfg.conf │ └── nssfcfg.conf ├── docs └── media │ └── img │ ├── my5g-logo.png │ └── git-workflow.png ├── version └── version.go ├── n3iwf_handler └── n3iwf_message │ ├── event.go │ ├── channel.go │ └── message.go ├── ue_ike ├── udp_server │ ├── server_test.go │ └── server.go ├── ike_handler │ ├── send.go │ └── xfrm.go ├── dispatcher.go └── ike_message │ └── types.go ├── ue_handler ├── ue_message │ ├── channel.go │ ├── event.go │ └── message.go └── handler.go ├── ue_util └── path.go ├── factory ├── config_config.go └── factory.go ├── .github └── workflows │ └── ci-workflow.yml ├── ue.go ├── setup.sh ├── trigger_initial_registration.sh ├── README.md ├── ue_utils └── ping.go ├── rest_api ├── routers.go └── api.go ├── logger └── logger.go ├── CONTRIBUTING.md ├── test └── sample-ue.json ├── ue_procedures ├── security.go ├── packet.go └── ranUe.go ├── ue_context ├── context.go └── ue_n3iwf.go └── ue_service └── ue_init.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | -------------------------------------------------------------------------------- /sample/sample1: -------------------------------------------------------------------------------- 1 | my5g_basic_config/ -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/Stop: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/free5GC.conf: -------------------------------------------------------------------------------- 1 | my5G-core.conf -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/wireshark_core_n3iwf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | wireshark -kni any -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/run_postman.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo ip netns exec UEns postman %f -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/wireshark_ue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ip netns exec UEns wireshark -kni any -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/wireshark_upf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ip netns exec UPFns wireshark -kni any -------------------------------------------------------------------------------- /docs/media/img/my5g-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/docs/media/img/my5g-logo.png -------------------------------------------------------------------------------- /docs/media/img/git-workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/docs/media/img/git-workflow.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/far.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/far.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/pdr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/pdr.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/policy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/policy.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/state.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/state.png -------------------------------------------------------------------------------- /sample/my5g_basic_config/Architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_basic_config/Architecture.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/bashpid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/bashpid.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/iwconfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/iwconfig.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/proposal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/proposal.png -------------------------------------------------------------------------------- /version/version.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | var VERSION = "0.0.1" 4 | 5 | func GetVersion() (version string) { 6 | return VERSION 7 | } 8 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/n3iwf_gtp_info.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | watch -d -n 1 $(pwd)/../../../src/upf/lib/libgtp5gnl/tools/gtp5g-tunnel list $1 -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/my5g-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/my5g-logo.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/pdu-session.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/pdu-session.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/interface-y2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/interface-y2.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/registration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/registration.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/tshoot-gtp5g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/tshoot-gtp5g.png -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/kill_core.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | sudo ps -eaf | grep "free5gc" | grep -v grep | awk '{ print $2 }' | sudo xargs kill -9 -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/first-terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/first-terminal.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/ip-address-wlan1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/ip-address-wlan1.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/ping-test-ue-upf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/ping-test-ue-upf.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/ping-ue-internet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/ping-ue-internet.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/second-terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/second-terminal.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/hostapd-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/hostapd-background.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/traceroute-ue-upf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/traceroute-ue-upf.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/general-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/general-architecture.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/success-interface-y1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/success-interface-y1.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/captures/ping-test-ue-to-upf.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/captures/ping-test-ue-to-upf.zip -------------------------------------------------------------------------------- /sample/my5g_wifi_config/figs/traceroute-ue-internet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/figs/traceroute-ue-internet.png -------------------------------------------------------------------------------- /sample/my5g_wifi_config/captures/wireshark-all-traffic.pcapng: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/my5G/my5G-non3GPP-access/HEAD/sample/my5g_wifi_config/captures/wireshark-all-traffic.pcapng -------------------------------------------------------------------------------- /sample/my5g_basic_config/webuicfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: WebUI initial local configuration 4 | 5 | configuration: 6 | mongodb: 7 | name: free5gc 8 | url: mongodb://127.0.0.1:27017 9 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/webuicfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: WebUI initial local configuration 4 | 5 | configuration: 6 | mongodb: 7 | name: free5gc 8 | url: mongodb://127.0.0.1:27017 9 | -------------------------------------------------------------------------------- /sample/ran_attach_config/webuicfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: WebUI initial local configuration 4 | 5 | configuration: 6 | mongodb: 7 | name: free5gc 8 | url: mongodb://localhost:27017 9 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/uecfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: N3IWF initial local configuration 4 | 5 | configuration: 6 | UEConfiguration: 7 | HttpIPv4Address: 127.0.0.1 8 | HttpIPv4Port: 10000 9 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/uecfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: N3IWF initial local configuration 4 | 5 | configuration: 6 | UEConfiguration: 7 | HttpIPv4Address: 127.0.0.1 8 | HttpIPv4Port: 10000 9 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/uecfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: N3IWF initial local configuration 4 | 5 | configuration: 6 | UEConfiguration: 7 | HttpIPv4Address: 127.0.0.1 8 | HttpIPv4Port: 10000 9 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/upf_gtp_info.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | watch -d -n 1 ip netns exec UPFns $(pwd)/../../../src/upf/lib/libgtp5gnl/tools/gtp5g-tunnel list $1 4 | 5 | #ip netns exec UPFns $(pwd)/../src/upf/lib/libgtp5gnl/tools/gtp5g-tunnel list far -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/run_upf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PID_LIST=() 4 | 5 | cd ../../../src/upf/build 6 | sudo ip netns exec UPFns ./bin/free5gc-upfd & 7 | PID_LIST+=($!) 8 | 9 | sleep 5 10 | sudo ip netns exec UPFns ip link set dev upfgtp mtu 1500 11 | 12 | wait ${PID_LIST} -------------------------------------------------------------------------------- /n3iwf_handler/n3iwf_message/event.go: -------------------------------------------------------------------------------- 1 | package n3iwf_message 2 | 3 | type Event int 4 | 5 | const ( 6 | EventN1UDPMessage Event = iota 7 | EventN1TunnelCPMessage 8 | EventN1TunnelUPMessage 9 | EventSCTPConnectMessage 10 | EventNGAPMessage 11 | EventGTPMessage 12 | EventTimerSendRanConfigUpdateMessage 13 | ) 14 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/udrcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UDR initial local configuration 4 | 5 | configuration: 6 | sbi: 7 | scheme: https 8 | ipv4Addr: udr 9 | port: 29504 10 | mongodb: 11 | name: free5gc 12 | url: mongodb://db:27017 13 | nrfUri: https://nrf:29510 14 | -------------------------------------------------------------------------------- /ue_ike/udp_server/server_test.go: -------------------------------------------------------------------------------- 1 | package udp_server 2 | 3 | import ( 4 | "sync" 5 | "testing" 6 | // "free5gc/src/n3iwf/n3iwf_handler" 7 | ) 8 | 9 | func TestServer(t *testing.T) { 10 | 11 | var wg sync.WaitGroup 12 | 13 | wg.Add(2) 14 | 15 | go Run() 16 | // go n3iwf_handler.Handle() 17 | 18 | wg.Wait() 19 | 20 | } 21 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/utils/fix_core.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # enable forwarding 4 | sudo sysctl -w net.ipv4.ip_forward=1 5 | 6 | # stopping ufw service 7 | sudo /etc/init.d/ufw stop 8 | 9 | # compiling gtp5g module 10 | cd ~/gtp5g 11 | sudo make && sudo make install 12 | 13 | # adding rule in iptables 14 | sudo iptables -t nat -A POSTROUTING -o $(ip route | grep default | cut -d' ' -f5) -j MASQUERADE 15 | 16 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/ausfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AUSF initial local configuration 4 | 5 | configuration: 6 | sbi: 7 | scheme: https 8 | ipv4Addr: ausf 9 | port: 29509 10 | serviceNameList: 11 | - nausf-auth 12 | nrfUri: https://nrf:29510 13 | plmnSupportList: 14 | - mcc: 208 15 | mnc: 93 16 | - mcc: 123 17 | mnc: 45 18 | groupId: ausfGroup001 19 | -------------------------------------------------------------------------------- /sample/ran_attach_config/udrcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UDR initial local configuration 4 | 5 | configuration: 6 | sbi: 7 | scheme: http 8 | registerIPv4: 127.0.0.1 # IP used to register to NRF 9 | bindingIPv4: 127.0.0.1 # IP used to bind the service 10 | port: 29504 11 | mongodb: 12 | name: free5gc 13 | url: mongodb://localhost:27017 14 | nrfUri: http://localhost:29510 15 | -------------------------------------------------------------------------------- /ue_handler/ue_message/channel.go: -------------------------------------------------------------------------------- 1 | package ue_message 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | var UeChannel chan HandlerMessage 8 | var mtx sync.Mutex 9 | 10 | const ( 11 | MaxChannel int = 100000 12 | ) 13 | 14 | func init() { 15 | // init Pool 16 | UeChannel = make(chan HandlerMessage, MaxChannel) 17 | } 18 | 19 | func SendMessage(msg HandlerMessage) { 20 | mtx.Lock() 21 | UeChannel <- msg 22 | mtx.Unlock() 23 | } 24 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/nrfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: NRF initial local configuration 4 | 5 | configuration: 6 | MongoDBName: "free5gc" 7 | MongoDBUrl: "mongodb://db:27017" 8 | DefaultServiceIP: nrf 9 | sbi: 10 | scheme: https 11 | ipv4Addr: nrf 12 | port: 29510 13 | DefaultPlmnId: 14 | mcc: "208" 15 | mnc: "93" 16 | serviceNameList: 17 | - nnrf-nfm 18 | - nnrf-disc 19 | -------------------------------------------------------------------------------- /n3iwf_handler/n3iwf_message/channel.go: -------------------------------------------------------------------------------- 1 | package n3iwf_message 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | var N3iwfChannel chan HandlerMessage 8 | var mtx sync.Mutex 9 | 10 | const ( 11 | MaxChannel int = 100000 12 | ) 13 | 14 | func init() { 15 | // init Pool 16 | N3iwfChannel = make(chan HandlerMessage, MaxChannel) 17 | } 18 | 19 | func SendMessage(msg HandlerMessage) { 20 | mtx.Lock() 21 | N3iwfChannel <- msg 22 | mtx.Unlock() 23 | } 24 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/udrcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UDR initial local configuration 4 | 5 | configuration: 6 | sbi: 7 | scheme: http 8 | registerIPv4: 10.1.1.8 # Can also be a kubernetes service IP or domain name. 9 | bindingIPv4: 10.1.1.8 # Can also be an ENV. 10 | port: 29504 11 | mongodb: 12 | name: free5gc 13 | url: mongodb://127.0.0.1:27017 14 | nrfUri: http://10.1.1.10:29510 -------------------------------------------------------------------------------- /sample/my5g_wifi_config/nrfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: NRF initial local configuration 4 | 5 | configuration: 6 | MongoDBName: "free5gc" 7 | MongoDBUrl: "mongodb://127.0.0.1:27017" 8 | DefaultServiceIP: 10.1.1.10 9 | sbi: 10 | scheme: http 11 | ipv4Addr: 10.1.1.10 12 | port: 29510 13 | DefaultPlmnId: 14 | mcc: "208" 15 | mnc: "93" 16 | serviceNameList: 17 | - nnrf-nfm 18 | - nnrf-disc -------------------------------------------------------------------------------- /sample/my5g_wifi_config/udrcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UDR initial local configuration 4 | 5 | configuration: 6 | sbi: 7 | scheme: http 8 | registerIPv4: 10.1.1.8 # Can also be a kubernetes service IP or domain name. 9 | bindingIPv4: 10.1.1.8 # Can also be an ENV. 10 | port: 29504 11 | mongodb: 12 | name: free5gc 13 | url: mongodb://127.0.0.1:27017 14 | nrfUri: http://10.1.1.10:29510 -------------------------------------------------------------------------------- /sample/my5g_basic_config/nrfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: NRF initial local configuration 4 | 5 | configuration: 6 | MongoDBName: "free5gc" 7 | MongoDBUrl: "mongodb://127.0.0.1:27017" 8 | DefaultServiceIP: 10.1.1.10 9 | sbi: 10 | scheme: http 11 | ipv4Addr: 10.1.1.10 12 | port: 29510 13 | DefaultPlmnId: 14 | mcc: "208" 15 | mnc: "93" 16 | serviceNameList: 17 | - nnrf-nfm 18 | - nnrf-disc -------------------------------------------------------------------------------- /sample/my5g_basic_config/ausfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AUSF initial local configuration 4 | 5 | configuration: 6 | sbi: 7 | scheme: http 8 | registerIPv4: 10.1.1.4 9 | bindingIPv4: 10.1.1.4 10 | port: 29509 11 | serviceNameList: 12 | - nausf-auth 13 | nrfUri: http://10.1.1.10:29510 14 | plmnSupportList: 15 | - mcc: 208 16 | mnc: 93 17 | - mcc: 123 18 | mnc: 45 19 | groupId: ausfGroup001 -------------------------------------------------------------------------------- /sample/my5g_wifi_config/ausfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AUSF initial local configuration 4 | 5 | configuration: 6 | sbi: 7 | scheme: http 8 | registerIPv4: 10.1.1.4 9 | bindingIPv4: 10.1.1.4 10 | port: 29509 11 | serviceNameList: 12 | - nausf-auth 13 | nrfUri: http://10.1.1.10:29510 14 | plmnSupportList: 15 | - mcc: 208 16 | mnc: 93 17 | - mcc: 123 18 | mnc: 45 19 | groupId: ausfGroup001 -------------------------------------------------------------------------------- /ue_handler/ue_message/event.go: -------------------------------------------------------------------------------- 1 | package ue_message 2 | 3 | type Event int 4 | 5 | const ( 6 | EventRegistrationProcedure Event = iota 7 | EventDeregistrationProcedure 8 | EventPDUSessionEstablishment 9 | 10 | EventUEConfigurationUpdate 11 | EventServiceRequest 12 | EventPDUSessionModification 13 | 14 | EventN1UDPMessage 15 | 16 | EventN1TunnelCPMessage 17 | EventN1TunnelUPMessage 18 | EventGTPMessage 19 | EventTimerSendRanConfigUpdateMessage 20 | ) 21 | -------------------------------------------------------------------------------- /ue_util/path.go: -------------------------------------------------------------------------------- 1 | package ue_util 2 | 3 | import ( 4 | "free5gc/lib/path_util" 5 | ) 6 | 7 | var UeLogPath = path_util.Gofree5gcPath("free5gc/uesslkey.log") 8 | // TODO: #LABORA Create the key and pem certificate files for UE in free5gc/support 9 | var UePemPath = path_util.Gofree5gcPath("free5gc/support/TLS/ue.pem") 10 | var UeKeyPath = path_util.Gofree5gcPath("free5gc/support/TLS/ue.key") 11 | // TODO: #LABORA Add free5gc/config/uecfg.conf 12 | var DefaultUeConfigPath = path_util.Gofree5gcPath("free5gc/config/uecfg.conf") 13 | -------------------------------------------------------------------------------- /sample/ran_attach_config/ausfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AUSF initial local configuration 4 | 5 | configuration: 6 | sbi: 7 | scheme: http 8 | registerIPv4: 127.0.0.1 # IP used to register to NRF 9 | bindingIPv4: 127.0.0.1 # IP used to bind the service 10 | port: 29509 11 | serviceNameList: 12 | - nausf-auth 13 | nrfUri: http://localhost:29510 14 | plmnSupportList: 15 | - mcc: 208 16 | mnc: 93 17 | - mcc: 123 18 | mnc: 45 19 | groupId: ausfGroup001 20 | -------------------------------------------------------------------------------- /sample/ran_attach_config/nrfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: NRF initial local configuration 4 | 5 | configuration: 6 | MongoDBName: "free5gc" 7 | MongoDBUrl: "mongodb://127.0.0.1:27017" 8 | DefaultServiceIP: "127.0.0.1" 9 | sbi: 10 | scheme: http 11 | registerIPv4: 127.0.0.1 # IP used to register to NRF 12 | bindingIPv4: 127.0.0.1 # IP used to bind the service 13 | port: 29510 14 | DefaultPlmnId: 15 | mcc: "208" 16 | mnc: "93" 17 | serviceNameList: 18 | - nnrf-nfm 19 | - nnrf-disc 20 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/upfcfg.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UPF configuration 4 | 5 | configuration: 6 | # debugLevel: panic|fatal|error|warn|info|debug|trace 7 | debugLevel: info 8 | 9 | pfcp: 10 | - addr: 10.1.1.9 11 | 12 | gtpu: 13 | - addr: 10.200.200.102 14 | # [optional] gtpu.name 15 | # - name: upf.5gc.nctu.me 16 | # [optional] gtpu.ifname 17 | # - ifname: gtpif 18 | 19 | apn_list: 20 | - apn: internet 21 | cidr: 60.60.0.0/24 22 | # [optional] apn_list[*].natifname 23 | # natifname: eth0 24 | -------------------------------------------------------------------------------- /sample/ran_attach_config/upfcfg.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UPF configuration 4 | 5 | configuration: 6 | # debugLevel: panic|fatal|error|warn|info|debug|trace 7 | debugLevel: info 8 | 9 | pfcp: 10 | - addr: 127.0.0.8 11 | 12 | gtpu: 13 | - addr: 192.168.0.1 14 | # [optional] gtpu.name 15 | # - name: upf.5gc.nctu.me 16 | # [optional] gtpu.ifname 17 | # - ifname: gtpif 18 | 19 | apn_list: 20 | - apn: internet 21 | cidr: 60.60.0.0/24 22 | # [optional] apn_list[*].natifname 23 | # natifname: eth0 24 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/upfcfg.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UPF configuration 4 | 5 | configuration: 6 | # debugLevel: panic|fatal|error|warn|info|debug|trace 7 | debugLevel: info 8 | 9 | pfcp: 10 | - addr: 10.200.200.101 11 | 12 | gtpu: 13 | - addr: 10.200.200.102 14 | # [optional] gtpu.name 15 | # - name: upf.5gc.nctu.me 16 | # [optional] gtpu.ifname 17 | # - ifname: gtpif 18 | 19 | apn_list: 20 | - apn: internet 21 | cidr: 60.60.0.0/24 22 | # [optional] apn_list[*].natifname 23 | # natifname: eth0 24 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/upfcfg.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UPF configuration 4 | 5 | configuration: 6 | # debugLevel: panic|fatal|error|warn|info|debug|trace 7 | debugLevel: info 8 | 9 | pfcp: 10 | - addr: 10.200.200.101 11 | 12 | gtpu: 13 | - addr: 10.200.200.102 14 | # [optional] gtpu.name 15 | # - name: upf.5gc.nctu.me 16 | # [optional] gtpu.ifname 17 | # - ifname: gtpif 18 | 19 | apn_list: 20 | - apn: internet 21 | cidr: 60.60.0.0/24 22 | # [optional] apn_list[*].natifname 23 | # natifname: eth0 24 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/list_interfaces.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Arguments: $1: Interface ('grep'-regexp). 4 | # Print the interfaces and their types 5 | 6 | # Static list of types (from `ip link help`): 7 | TYPES=(bond bond_slave bridge dummy gre gretap ifb ip6gre ip6gretap ip6tnl ipip ipoib ipvlan macvlan macvtap nlmon sit vcan veth vlan vti vxlan tun tap) 8 | 9 | iface="$1" 10 | 11 | for type in "${TYPES[@]}"; do 12 | ip link show type "${type}" | grep -E '^[0-9]+:' | cut -d ':' -f 2 | sed 's|^[[:space:]]*||' | while read _if; do 13 | echo "${_if}:${type}" 14 | done | grep "^${iface}" 15 | done -------------------------------------------------------------------------------- /ue_handler/ue_message/message.go: -------------------------------------------------------------------------------- 1 | package ue_message 2 | 3 | import "net" 4 | 5 | type HandlerMessage struct { 6 | Event Event 7 | UDPSendInfo *UDPSendInfoGroup // used only when Event == EventN1UDPMessage 8 | Addr *net.UDPAddr // used only when Event == EventN1UDPMessage 9 | UEInnerIP string // used when Event == EventN1TunnelCPMessage || Event == EventN1TunnelUPMessage 10 | TEID uint32 // used only when Event == EventGTPMessage 11 | Value interface{} 12 | } 13 | 14 | type UDPSendInfoGroup struct { 15 | ChannelID int 16 | Addr *net.UDPAddr 17 | } 18 | -------------------------------------------------------------------------------- /factory/config_config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * UE Configuration Factory 3 | */ 4 | 5 | package factory 6 | 7 | 8 | type Config struct { 9 | Info *Info `yaml:"info"` 10 | Configuration *Configuration `yaml:"configuration"` 11 | } 12 | 13 | type Configuration struct{ 14 | UEConfiguration *UEConfiguration `yaml:"UEConfiguration"` 15 | } 16 | 17 | type Info struct{ 18 | Version string `yaml:"version,omitempty"` 19 | Description string `yaml:"description,omitempty"` 20 | } 21 | 22 | type UEConfiguration struct{ 23 | HttpIPv4Address string `yaml:"HttpIPv4Address,omitempty"` 24 | HttpIPv4Port string `yaml:"HttpIPv4Port,omitempty"` 25 | } -------------------------------------------------------------------------------- /n3iwf_handler/n3iwf_message/message.go: -------------------------------------------------------------------------------- 1 | package n3iwf_message 2 | 3 | import ( 4 | "net" 5 | ) 6 | 7 | type HandlerMessage struct { 8 | Event Event 9 | UDPSendInfo *UDPSendInfoGroup // used only when Event == EventN1UDPMessage 10 | SCTPAddr string // used when Event == EventNGAPMessage || Event == EventSCTPConnectMessage 11 | UEInnerIP string // used when Event == EventN1TunnelCPMessage || Event == EventN1TunnelUPMessage 12 | TEID uint32 // used only when Event == EventGTPMessage 13 | Value interface{} 14 | } 15 | 16 | type UDPSendInfoGroup struct { 17 | ChannelID int 18 | Addr *net.UDPAddr 19 | } 20 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/pcfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: PCF initial local configuration 4 | 5 | configuration: 6 | pcfName: PCF 7 | sbi: 8 | scheme: https 9 | ipv4Addr: pcf 10 | port: 29507 11 | timeFormat: 2019-01-02 15:04:05 12 | defaultBdtRefId: BdtPolicyId- 13 | nrfUri: https://nrf:29510 14 | serviceList: 15 | - serviceName: npcf-am-policy-control 16 | - serviceName: npcf-smpolicycontrol 17 | suppFeat: 3fff 18 | - serviceName: npcf-bdtpolicycontrol 19 | - serviceName: npcf-policyauthorization 20 | suppFeat: 3 21 | - serviceName: npcf-eventexposure 22 | - serviceName: npcf-ue-policy-control 23 | -------------------------------------------------------------------------------- /.github/workflows/ci-workflow.yml: -------------------------------------------------------------------------------- 1 | name: UE-IoT-non3GPP CI 2 | on: 3 | pull_request: 4 | push: 5 | branches: 6 | - master 7 | - develop 8 | 9 | jobs: 10 | test: 11 | name: build and test 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout Repo 15 | uses: actions/checkout@v2 16 | 17 | - name: Setup Go 18 | uses: actions/setup-go@v2 19 | with: 20 | go-version: 1.14.7 21 | 22 | # - name: Install Go Deps 23 | # run: | 24 | # go mod download 25 | # sudo ln -s $GOROOT /usr/local/go 26 | 27 | - name: Build 28 | run: echo "Build UE here" 29 | 30 | - name: Test 31 | run: echo "Implement Test here" 32 | -------------------------------------------------------------------------------- /factory/factory.go: -------------------------------------------------------------------------------- 1 | /* 2 | * UE Configuration Factory 3 | */ 4 | 5 | package factory 6 | 7 | import ( 8 | "fmt" 9 | "io/ioutil" 10 | "gopkg.in/yaml.v2" 11 | "free5gc/src/ue/logger" 12 | ) 13 | 14 | var UeConfig Config 15 | 16 | func checkErr(err error) { 17 | if err != nil { 18 | err = fmt.Errorf("[Configuration] %s", err.Error()) 19 | logger.AppLog.Fatal(err) 20 | } 21 | } 22 | 23 | // TODO: Support configuration update from REST api 24 | func InitConfigFactory(f string) { 25 | content, err := ioutil.ReadFile(f) 26 | checkErr(err) 27 | 28 | UeConfig = Config{} 29 | 30 | err = yaml.Unmarshal([]byte(content), &UeConfig) 31 | checkErr(err) 32 | 33 | logger.InitLog.Infof("Successfully initialize configuration %s", f) 34 | } 35 | -------------------------------------------------------------------------------- /sample/ran_attach_config/pcfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: PCF initial local configuration 4 | 5 | configuration: 6 | pcfName: PCF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 127.0.0.1 # IP used to register to NRF 10 | bindingIPv4: 127.0.0.1 # IP used to bind the service 11 | port: 29507 12 | timeFormat: 2019-01-02 15:04:05 13 | defaultBdtRefId: BdtPolicyId- 14 | nrfUri: http://localhost:29510 15 | serviceList: 16 | - serviceName: npcf-am-policy-control 17 | - serviceName: npcf-smpolicycontrol 18 | suppFeat: 3fff 19 | - serviceName: npcf-bdtpolicycontrol 20 | - serviceName: npcf-policyauthorization 21 | suppFeat: 3 22 | - serviceName: npcf-eventexposure 23 | - serviceName: npcf-ue-policy-control 24 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/pcfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: PCF initial local configuration 4 | 5 | configuration: 6 | pcfName: PCF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 10.1.1.6 # Can also be a kubernetes service IP or domain name. 10 | bindingIPv4: 10.1.1.6 # Can also be an ENV. 11 | port: 29507 12 | timeFormat: 2019-01-02 15:04:05 13 | defaultBdtRefId: BdtPolicyId- 14 | nrfUri: http://10.1.1.10:29510 15 | serviceList: 16 | - serviceName: npcf-am-policy-control 17 | - serviceName: npcf-smpolicycontrol 18 | suppFeat: 3fff 19 | - serviceName: npcf-bdtpolicycontrol 20 | - serviceName: npcf-policyauthorization 21 | suppFeat: 3 22 | - serviceName: npcf-eventexposure 23 | - serviceName: npcf-ue-policy-control 24 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/pcfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: PCF initial local configuration 4 | 5 | configuration: 6 | pcfName: PCF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 10.1.1.6 # Can also be a kubernetes service IP or domain name. 10 | bindingIPv4: 10.1.1.6 # Can also be an ENV. 11 | port: 29507 12 | timeFormat: 2019-01-02 15:04:05 13 | defaultBdtRefId: BdtPolicyId- 14 | nrfUri: http://10.1.1.10:29510 15 | serviceList: 16 | - serviceName: npcf-am-policy-control 17 | - serviceName: npcf-smpolicycontrol 18 | suppFeat: 3fff 19 | - serviceName: npcf-bdtpolicycontrol 20 | - serviceName: npcf-policyauthorization 21 | suppFeat: 3 22 | - serviceName: npcf-eventexposure 23 | - serviceName: npcf-ue-policy-control 24 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/run_ue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # use some fixed parameters for testing (milenage test set 19) 4 | cd ../../../ 5 | go build -o ./bin/ue -x ./src/ue/ue.go 6 | sudo ip netns exec UEns ./bin/ue #--ping=1 #\ 7 | # --plmnid=010203 \ 8 | # --supi=2089300007487 \ 9 | # --op=c9e8763286b5b9ffbdf56e1297d0887b \ 10 | # --k=5122250214c33e723a5dd523fc145fc0 \ 11 | # --opc=981d464c7c52eb6e5036234984ad0bcf \ 12 | # --n3iwfip=192.168.127.1 \ 13 | # --ueip=192.168.127.2 \ 14 | # --mongourl=127.0.0.1:27017 \ 15 | # --createue -------------------------------------------------------------------------------- /ue.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import( 4 | "github.com/sirupsen/logrus" 5 | "github.com/urfave/cli" 6 | "free5gc/src/app" 7 | "free5gc/src/ue/logger" 8 | "free5gc/src/ue/ue_service" 9 | "free5gc/src/ue/version" 10 | "os" 11 | ) 12 | 13 | var UE = &ue_service.UE{} 14 | var appLog *logrus.Entry 15 | 16 | func init() { 17 | appLog = logger.AppLog 18 | } 19 | 20 | func main(){ 21 | app := cli.NewApp() 22 | app.Name = "ue" 23 | app.Usage = "Usage: --uecfg config yaml file" 24 | app.Action = action 25 | app.Flags = UE.GetCliCmd() 26 | 27 | appLog.Infoln(app.Name) 28 | appLog.Infoln("UE version: ", version.GetVersion()) 29 | 30 | if err := app.Run(os.Args); err != nil { 31 | logger.AppLog.Errorf("UE Run error: %v", err) 32 | } 33 | } 34 | 35 | func action(c *cli.Context){ 36 | app.AppInitializeWillInitialize(c.String("free5gccfg")) 37 | UE.Initialize(c) 38 | UE.Start() 39 | } 40 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Setup the network interfaces and namespaces required for ue 4 | ip link set lo up 5 | ip link add ipsec0 type vti 172.16.0.2 remote 172.16.0.1 key 5 6 | ip link set dev ipsec0 up 7 | 8 | 9 | #UENS="UEns" 10 | #EXEC_UENS="ip netns exec ${UENS}" 11 | #ip link add veth1 type veth peer name veth2 12 | #ip netns add ${UENS} 13 | #ip link add veth2 type veth peer name veth3 14 | #ip addr add 192.168.127.1/24 dev veth2 15 | #ip link set veth2 up 16 | #ip link set veth3 netns ${UENS} 17 | #${EXEC_UENS} ip addr add 192.168.127.2/24 dev veth3 18 | #${EXEC_UENS} ip link set lo up 19 | #${EXEC_UENS} ip link set veth3 up 20 | #${EXEC_UENS} ip link add ipsec0 type vti local 192.168.127.2 remote 192.168.127.1 key 5 21 | #${EXEC_UENS} ip link set ipsec0 up 22 | 23 | #sudo ip link add name ipsec0 type vti local 192.168.127.1 remote 0.0.0.0 key 5 24 | #sudo ip addr add 10.0.0.1/24 dev ipsec0 25 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/uerouting.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: Routing information for UE 4 | 5 | ueRoutingInfo: 6 | - SUPI: imsi-2089300007487 7 | AN: 10.1.1.9 8 | PathList: 9 | - DestinationIP: 60.60.0.101 10 | DestinationPort: 8888 11 | UPF: !!seq 12 | - BranchingUPF 13 | - AnchorUPF1 14 | 15 | - DestinationIP: 60.60.0.103 16 | DestinationPort: 9999 17 | UPF: !!seq 18 | - BranchingUPF 19 | - AnchorUPF2 20 | 21 | - SUPI: imsi-2089300007486 22 | AN: 10.200.200.102 23 | PathList: 24 | - DestinationIP: 10.0.0.10 25 | DestinationPort: 8888 26 | UPF: !!seq 27 | - BranchingUPF 28 | - AnchorUPF1 29 | 30 | - DestinationIP: 10.0.0.11 31 | DestinationPort: 9999 32 | UPF: !!seq 33 | - BranchingUPF 34 | - AnchorUPF2 35 | -------------------------------------------------------------------------------- /ue_ike/ike_handler/send.go: -------------------------------------------------------------------------------- 1 | package ike_handler 2 | 3 | import ( 4 | ike_message "free5gc/src/n3iwf/ike/message" 5 | "free5gc/src/ue/n3iwf_handler/n3iwf_message" 6 | "free5gc/src/ue/ue_ike/udp_server" 7 | 8 | //"free5gc/src/ue/n3iwf_ike/udp_server" 9 | ) 10 | 11 | func SendIKEMessageToUE(ueSendInfo *n3iwf_message.UDPSendInfoGroup, message *ike_message.IKEMessage) { 12 | ikeLog.Trace("[IKE] Send IKE message to UE") 13 | ikeLog.Trace("[IKE] Encoding...") 14 | pkt, err := ike_message.Encode(message) 15 | if err != nil { 16 | ikeLog.Errorln(err) 17 | return 18 | } 19 | // As specified in RFC 7296 section 3.1, the IKE message send from/to UDP port 4500 20 | // should prepend a 4 bytes zero 21 | if ueSendInfo.ChannelID == udp_server.ChannelIDForPort4500 { 22 | prependZero := make([]byte, 4) 23 | pkt = append(prependZero, pkt...) 24 | } 25 | ikeLog.Trace("[IKE] Sending...") 26 | udp_server.Send(ueSendInfo, pkt) 27 | } 28 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/uerouting.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: Routing information for UE 4 | 5 | ueRoutingInfo: 6 | - SUPI: imsi-2089300007487 7 | AN: 10.200.200.101 8 | PathList: 9 | - DestinationIP: 60.60.0.101 10 | UPF: !!seq 11 | - BranchingUPF 12 | - AnchorUPF1 13 | 14 | - DestinationIP: 60.60.0.103 15 | UPF: !!seq 16 | - BranchingUPF 17 | - AnchorUPF2 18 | 19 | - SUPI: imsi-2089300007486 20 | AN: 10.200.200.102 21 | PathList: 22 | - DestinationIP: 10.0.0.10 23 | UPF: !!seq 24 | - BranchingUPF 25 | - AnchorUPF1 26 | 27 | - DestinationIP: 10.0.0.11 28 | UPF: !!seq 29 | - BranchingUPF 30 | - AnchorUPF2 31 | 32 | routeProfile: 33 | MEC1: 34 | forwardingPolicyID: 10 35 | 36 | pfdDataForApp: 37 | - applicationId: edge 38 | pfds: 39 | - pfdID: pfd1 40 | flowDescriptions: 41 | - permit out ip from 60.60.0.1 8080 to any 42 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/uerouting.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: Routing information for UE 4 | 5 | ueRoutingInfo: 6 | - SUPI: imsi-2089300007487 7 | AN: 10.200.200.101 8 | PathList: 9 | - DestinationIP: 60.60.0.101 10 | UPF: !!seq 11 | - BranchingUPF 12 | - AnchorUPF1 13 | 14 | - DestinationIP: 60.60.0.103 15 | UPF: !!seq 16 | - BranchingUPF 17 | - AnchorUPF2 18 | 19 | - SUPI: imsi-2089300007486 20 | AN: 10.200.200.102 21 | PathList: 22 | - DestinationIP: 10.0.0.10 23 | UPF: !!seq 24 | - BranchingUPF 25 | - AnchorUPF1 26 | 27 | - DestinationIP: 10.0.0.11 28 | UPF: !!seq 29 | - BranchingUPF 30 | - AnchorUPF2 31 | 32 | routeProfile: 33 | MEC1: 34 | forwardingPolicyID: 10 35 | 36 | pfdDataForApp: 37 | - applicationId: edge 38 | pfds: 39 | - pfdID: pfd1 40 | flowDescriptions: 41 | - permit out ip from 60.60.0.1 8080 to any 42 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/smfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: https 9 | ipv4Addr: smf 10 | port: 29502 11 | tls: 12 | key: free5gc/support/TLS/smf.key 13 | pem: free5gc/support/TLS/smf.pem 14 | serviceNameList: 15 | - nsmf-pdusession 16 | - nsmf-event-exposure 17 | - nsmf-oam 18 | snssai_info: 19 | - sNssai: 20 | sst: 1 21 | sd: 010203 22 | dnnSmfInfoList: 23 | - dnn: internet 24 | - sNssai: 25 | sst: 1 26 | sd: 112233 27 | dnnSmfInfoList: 28 | - dnn: internet 29 | pfcp: 30 | addr: smf 31 | userplane_information: 32 | up_nodes: 33 | gNB1: 34 | type: AN 35 | an_ip: 192.188.2.3 36 | UPF: 37 | type: UPF 38 | node_id: 10.1.1.9 39 | up_resource_ip: 192.188.2.2 40 | links: 41 | - A: gNB1 42 | B: UPF 43 | ue_subnet: 60.60.0.0/16 44 | nrfUri: https://nrf:29510 45 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/test/smfcfg.test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: http 9 | ipv4Addr: 127.0.0.1 10 | port: 29502 11 | tls: 12 | key: free5gc/support/TLS/smf.key 13 | pem: free5gc/support/TLS/smf.pem 14 | serviceNameList: 15 | - nsmf-pdusession 16 | - nsmf-event-exposure 17 | - nsmf-oam 18 | snssai_info: 19 | - sNssai: 20 | sst: 1 21 | sd: 010203 22 | dnnSmfInfoList: 23 | - dnn: internet 24 | - sNssai: 25 | sst: 1 26 | sd: 112233 27 | dnnSmfInfoList: 28 | - dnn: internet 29 | pfcp: 30 | addr: 10.200.200.1 31 | userplane_information: 32 | up_nodes: 33 | gNB1: 34 | type: AN 35 | an_ip: 192.188.2.3 36 | UPF: 37 | type: UPF 38 | node_id: 10.200.200.101 39 | up_resource_ip: 192.188.2.2 40 | links: 41 | - A: gNB1 42 | B: UPF 43 | ue_subnet: 60.60.0.0/16 44 | nrfUri: http://localhost:29510 45 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/test/smfcfg.single.test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: http 9 | ipv4Addr: 127.0.0.1 10 | port: 29502 11 | tls: 12 | key: free5gc/support/TLS/smf.key 13 | pem: free5gc/support/TLS/smf.pem 14 | serviceNameList: 15 | - nsmf-pdusession 16 | - nsmf-event-exposure 17 | - nsmf-oam 18 | snssai_info: 19 | - sNssai: 20 | sst: 1 21 | sd: 010203 22 | dnnSmfInfoList: 23 | - dnn: internet 24 | - sNssai: 25 | sst: 1 26 | sd: 112233 27 | dnnSmfInfoList: 28 | - dnn: internet 29 | pfcp: 30 | addr: 10.200.200.1 31 | userplane_information: 32 | up_nodes: 33 | gNB1: 34 | type: AN 35 | an_ip: 192.188.2.3 36 | UPF: 37 | type: UPF 38 | node_id: 10.200.200.101 39 | up_resource_ip: 192.188.2.2 40 | links: 41 | - A: gNB1 42 | B: UPF 43 | ue_subnet: 60.60.0.0/16 44 | nrfUri: http://localhost:29510 45 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/test/smfcfg.single.test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: https 9 | ipv4Addr: 127.0.0.1 10 | port: 29502 11 | tls: 12 | key: free5gc/support/TLS/smf.key 13 | pem: free5gc/support/TLS/smf.pem 14 | serviceNameList: 15 | - nsmf-pdusession 16 | - nsmf-event-exposure 17 | - nsmf-oam 18 | snssai_info: 19 | - sNssai: 20 | sst: 1 21 | sd: 010203 22 | dnnSmfInfoList: 23 | - dnn: internet 24 | - sNssai: 25 | sst: 1 26 | sd: 112233 27 | dnnSmfInfoList: 28 | - dnn: internet 29 | pfcp: 30 | addr: 10.200.200.1 31 | userplane_information: 32 | up_nodes: 33 | gNB1: 34 | type: AN 35 | an_ip: 192.188.2.3 36 | UPF: 37 | type: UPF 38 | node_id: 10.200.200.101 39 | up_resource_ip: 192.188.2.2 40 | links: 41 | - A: gNB1 42 | B: UPF 43 | ue_subnet: 60.60.0.0/16 44 | nrfUri: https://localhost:29510 45 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/amfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | amfName: AMF 7 | ngapIpList: 8 | - 192.168.0.1 9 | sbi: 10 | scheme: https 11 | ipv4Addr: 10.1.1.2 12 | port: 29518 13 | serviceNameList: 14 | - namf-comm 15 | - namf-evts 16 | - namf-mt 17 | - namf-loc 18 | - namf-oam 19 | servedGuamiList: 20 | - plmnId: 21 | mcc: 208 22 | mnc: 93 23 | amfId: cafe00 24 | supportTaiList: 25 | - plmnId: 26 | mcc: 208 27 | mnc: 93 28 | tac: 1 29 | plmnSupportList: 30 | - plmnId: 31 | mcc: 208 32 | mnc: 93 33 | snssaiList: 34 | - sst: 1 35 | sd: 010203 36 | - sst: 1 37 | sd: 112233 38 | supportDnnList: 39 | - internet 40 | nrfUri: https://nrf:29510 41 | security: 42 | integrityOrder: 43 | - NIA2 44 | - NIA0 45 | cipheringOrder: 46 | - NEA2 47 | - NEA0 48 | networkName: 49 | full: free5GC 50 | short: free 51 | t3502: 720 52 | t3512: 3600 53 | non3gppDeregistrationTimer: 3240 54 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/test/amfcfg.n3test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | amfName: AMF 7 | ngapIpList: 8 | - 10.200.200.1 9 | sbi: 10 | scheme: https 11 | ipv4Addr: 127.0.0.1 12 | port: 29518 13 | serviceNameList: 14 | - namf-comm 15 | - namf-evts 16 | - namf-mt 17 | - namf-loc 18 | - namf-oam 19 | servedGuamiList: 20 | - plmnId: 21 | mcc: 208 22 | mnc: 93 23 | amfId: cafe00 24 | supportTaiList: 25 | - plmnId: 26 | mcc: 208 27 | mnc: 93 28 | tac: 1 29 | plmnSupportList: 30 | - plmnId: 31 | mcc: 208 32 | mnc: 93 33 | snssaiList: 34 | - sst: 1 35 | sd: 010203 36 | - sst: 1 37 | sd: 112233 38 | supportDnnList: 39 | - internet 40 | nrfUri: https://localhost:29510 41 | security: 42 | integrityOrder: 43 | - NIA2 44 | - NIA0 45 | cipheringOrder: 46 | - NEA2 47 | - NEA0 48 | networkName: 49 | full: free5GC 50 | short: free 51 | t3502: 720 52 | t3512: 3600 53 | non3gppDeregistrationTimer: 3240 54 | -------------------------------------------------------------------------------- /sample/ran_attach_config/smfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 127.0.0.1 # IP used to register to NRF 10 | bindingIPv4: 127.0.0.1 # IP used to bind the service 11 | port: 29502 12 | tls: 13 | key: free5gc/support/TLS/smf.key 14 | pem: free5gc/support/TLS/smf.pem 15 | serviceNameList: 16 | - nsmf-pdusession 17 | - nsmf-event-exposure 18 | - nsmf-oam 19 | snssai_info: 20 | - sNssai: 21 | sst: 1 22 | sd: 010203 23 | dnnSmfInfoList: 24 | - dnn: internet 25 | - sNssai: 26 | sst: 1 27 | sd: 112233 28 | dnnSmfInfoList: 29 | - dnn: internet 30 | pfcp: 31 | addr: 127.0.0.1 32 | userplane_information: 33 | up_nodes: 34 | gNB1: 35 | type: AN 36 | an_ip: 192.188.2.3 37 | UPF: 38 | type: UPF 39 | node_id: 127.0.0.8 40 | up_resource_ip: 192.188.2.2 41 | 42 | links: 43 | - A: gNB1 44 | B: UPF 45 | ue_subnet: 60.60.0.0/16 46 | nrfUri: http://localhost:29510 47 | -------------------------------------------------------------------------------- /trigger_initial_registration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ue_addr=${ue_addr:-"127.0.0.1"} 4 | ue_port=${ue_port:-"10000"} 5 | scheme=${scheme:-"https"} 6 | auth_method=${auth_method:-"5G_AKA"} 7 | n3iwf_address=${n3iwf_address:-"192.168.127.1"} 8 | supi_or_suci=${supi_or_suci:-"2089300007487"} 9 | k=${k:-"5122250214c33e723a5dd523fc145fc0"} 10 | opc_type=${opc_type:-"OP"} 11 | opc=${opc:-"c9e8763286b5b9ffbdf56e1297d0887b"} 12 | ike_bind_addr=${ike_bind_addr:-"192.168.127.2"} 13 | 14 | while [ $# -gt 0 ]; do 15 | if [[ $1 == *"--"* ]]; then 16 | param="${1/--/}" 17 | declare $param="$2" 18 | fi 19 | shift 20 | done 21 | 22 | curl --insecure --location --request POST "$scheme://$ue_addr:$ue_port/registration/" \ 23 | --header 'Content-Type: application/json' \ 24 | --data-raw "{ 25 | \"authenticationMethod\": \"$auth_method\", 26 | \"supiOrSuci\": \"$supi_or_suci\", 27 | \"K\": \"$k\", 28 | \"opcType\": \"$opc_type\", 29 | \"opc\": \"$opc\", 30 | \"plmnId\": \"\", 31 | \"servingNetworkName\": \"\", 32 | \"n3IWFIpAddress\": \"$n3iwf_address\", 33 | \"ikeBindAddress\": \"$ike_bind_addr\", 34 | \"SNssai\": { 35 | \"Sst\": 1, 36 | \"Sd\": \"010203\" 37 | } 38 | }" -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/initial_registration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ue_addr=${ue_addr:-"127.0.0.1"} 4 | ue_port=${ue_port:-"10000"} 5 | scheme=${scheme:-"https"} 6 | auth_method=${auth_method:-"5G_AKA"} 7 | n3iwf_address=${n3iwf_address:-"192.168.127.1"} 8 | supi_or_suci=${supi_or_suci:-"2089300007487"} 9 | k=${k:-"5122250214c33e723a5dd523fc145fc0"} 10 | opc_type=${opc_type:-"OP"} 11 | opc=${opc:-"c9e8763286b5b9ffbdf56e1297d0887b"} 12 | ike_bind_addr=${ike_bind_addr:-"192.168.127.2"} 13 | 14 | while [ $# -gt 0 ]; do 15 | if [[ $1 == *"--"* ]]; then 16 | param="${1/--/}" 17 | declare $param="$2" 18 | fi 19 | shift 20 | done 21 | 22 | sudo ip netns exec UEns curl --insecure --location --request POST "$scheme://$ue_addr:$ue_port/registration/" \ 23 | --header 'Content-Type: application/json' \ 24 | --data-raw "{ 25 | \"authenticationMethod\": \"$auth_method\", 26 | \"supiOrSuci\": \"$supi_or_suci\", 27 | \"K\": \"$k\", 28 | \"opcType\": \"$opc_type\", 29 | \"opc\": \"$opc\", 30 | \"plmnId\": \"\", 31 | \"servingNetworkName\": \"\", 32 | \"n3IWFIpAddress\": \"$n3iwf_address\", 33 | \"ikeBindAddress\": \"$ike_bind_addr\", 34 | \"SNssai\": { 35 | \"Sst\": 1, 36 | \"Sd\": \"010203\" 37 | } 38 | }" -------------------------------------------------------------------------------- /sample/ran_attach_config/amfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | amfName: AMF 7 | ngapIpList: 8 | - 192.168.0.1 9 | sbi: 10 | scheme: http 11 | registerIPv4: 127.0.0.1 # IP used to register to NRF 12 | bindingIPv4: 127.0.0.1 # IP used to bind the service 13 | port: 29518 14 | serviceNameList: 15 | - namf-comm 16 | - namf-evts 17 | - namf-mt 18 | - namf-loc 19 | - namf-oam 20 | servedGuamiList: 21 | - plmnId: 22 | mcc: 208 23 | mnc: 93 24 | amfId: cafe00 25 | supportTaiList: 26 | - plmnId: 27 | mcc: 208 28 | mnc: 93 29 | tac: 1 30 | plmnSupportList: 31 | - plmnId: 32 | mcc: 208 33 | mnc: 93 34 | snssaiList: 35 | - sst: 1 36 | sd: 010203 37 | - sst: 1 38 | sd: 112233 39 | supportDnnList: 40 | - internet 41 | nrfUri: http://localhost:29510 42 | security: 43 | integrityOrder: 44 | - NIA2 45 | # - NIA0 46 | cipheringOrder: 47 | - NEA0 48 | # - NEA2 49 | networkName: 50 | full: free5GC 51 | short: free 52 | t3502: 720 53 | t3512: 3600 54 | non3gppDeregistrationTimer: 3240 55 | -------------------------------------------------------------------------------- /ue_handler/handler.go: -------------------------------------------------------------------------------- 1 | package ue_handler 2 | 3 | import ( 4 | "free5gc/src/ue/ue_context" 5 | "time" 6 | 7 | "github.com/sirupsen/logrus" 8 | 9 | "free5gc/src/ue/logger" 10 | "free5gc/src/ue/ue_handler/ue_message" 11 | "free5gc/src/ue/ue_procedures" 12 | ) 13 | 14 | var handlerLog *logrus.Entry 15 | 16 | func init() { 17 | // init pool 18 | handlerLog = logger.HandlerLog 19 | } 20 | 21 | func Handle() { 22 | for { 23 | select { 24 | case msg, ok := <-ue_message.UeChannel: 25 | if ok { 26 | switch msg.Event { 27 | case ue_message.EventRegistrationProcedure: 28 | handlerLog.Infof("Registration Procedure Triggered") 29 | ueContext := ue_context.UE_Self() 30 | ue_procedures.HandleRegistrationProcedure(ueContext) 31 | case ue_message.EventDeregistrationProcedure: 32 | handlerLog.Infof("Start Deregistration Procedure") 33 | ueContext := ue_context.UE_Self() 34 | ue_procedures.HandleDeregistrationProcedure(ueContext) 35 | case ue_message.EventPDUSessionEstablishment: 36 | handlerLog.Infof("Start Deregistration Procedure") 37 | ueContext := ue_context.UE_Self() 38 | ue_procedures.SetupPDUSession(ueContext) 39 | } 40 | } 41 | case <-time.After(1 * time.Second): 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/amfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | amfName: AMF 7 | ngapIpList: 8 | - 172.16.0.1 9 | sbi: 10 | scheme: http 11 | registerIPv4: 10.1.1.2 # Can also be a kubernetes service IP or domain name. 12 | bindingIPv4: 10.1.1.2 # Can also be an ENV. 13 | port: 29518 14 | serviceNameList: 15 | - namf-comm 16 | - namf-evts 17 | - namf-mt 18 | - namf-loc 19 | - namf-oam 20 | servedGuamiList: 21 | - plmnId: 22 | mcc: 208 23 | mnc: 93 24 | amfId: cafe00 25 | supportTaiList: 26 | - plmnId: 27 | mcc: 208 28 | mnc: 93 29 | tac: 1 30 | plmnSupportList: 31 | - plmnId: 32 | mcc: 208 33 | mnc: 93 34 | snssaiList: 35 | - sst: 1 36 | sd: 010203 37 | - sst: 1 38 | sd: 112233 39 | supportDnnList: 40 | - internet 41 | nrfUri: http://10.1.1.10:29510 42 | security: 43 | integrityOrder: 44 | - NIA2 45 | - NIA0 46 | cipheringOrder: 47 | - NEA2 48 | - NEA0 49 | networkName: 50 | full: free5GC 51 | short: free 52 | t3502: 720 53 | t3512: 3600 54 | non3gppDeregistrationTimer: 3240 55 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/amfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | amfName: AMF 7 | ngapIpList: 8 | - 172.16.0.1 9 | sbi: 10 | scheme: http 11 | registerIPv4: 10.1.1.2 # Can also be a kubernetes service IP or domain name. 12 | bindingIPv4: 10.1.1.2 # Can also be an ENV. 13 | port: 29518 14 | serviceNameList: 15 | - namf-comm 16 | - namf-evts 17 | - namf-mt 18 | - namf-loc 19 | - namf-oam 20 | servedGuamiList: 21 | - plmnId: 22 | mcc: 208 23 | mnc: 93 24 | amfId: cafe00 25 | supportTaiList: 26 | - plmnId: 27 | mcc: 208 28 | mnc: 93 29 | tac: 1 30 | plmnSupportList: 31 | - plmnId: 32 | mcc: 208 33 | mnc: 93 34 | snssaiList: 35 | - sst: 1 36 | sd: 010203 37 | - sst: 1 38 | sd: 112233 39 | supportDnnList: 40 | - internet 41 | nrfUri: http://10.1.1.10:29510 42 | security: 43 | integrityOrder: 44 | - NIA2 45 | - NIA0 46 | cipheringOrder: 47 | - NEA2 48 | - NEA0 49 | networkName: 50 | full: free5GC 51 | short: free 52 | t3502: 720 53 | t3512: 3600 54 | non3gppDeregistrationTimer: 3240 55 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/amfcfg.n3test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | amfName: AMF 7 | ngapIpList: 8 | - 172.16.0.1 9 | sbi: 10 | scheme: http 11 | registerIPv4: 10.1.1.2 # Can also be a kubernetes service IP or domain name. 12 | bindingIPv4: 10.1.1.2 # Can also be an ENV. 13 | port: 29518 14 | serviceNameList: 15 | - namf-comm 16 | - namf-evts 17 | - namf-mt 18 | - namf-loc 19 | - namf-oam 20 | servedGuamiList: 21 | - plmnId: 22 | mcc: 208 23 | mnc: 93 24 | amfId: cafe00 25 | supportTaiList: 26 | - plmnId: 27 | mcc: 208 28 | mnc: 93 29 | tac: 1 30 | plmnSupportList: 31 | - plmnId: 32 | mcc: 208 33 | mnc: 93 34 | snssaiList: 35 | - sst: 1 36 | sd: 010203 37 | - sst: 1 38 | sd: 112233 39 | supportDnnList: 40 | - internet 41 | nrfUri: http://10.1.1.10:29510 42 | security: 43 | integrityOrder: 44 | - NIA2 45 | - NIA0 46 | cipheringOrder: 47 | - NEA2 48 | - NEA0 49 | networkName: 50 | full: free5GC 51 | short: free 52 | t3502: 720 53 | t3512: 3600 54 | non3gppDeregistrationTimer: 3240 55 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/amfcfg.n3test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | amfName: AMF 7 | ngapIpList: 8 | - 172.16.0.1 9 | sbi: 10 | scheme: http 11 | registerIPv4: 10.1.1.2 # Can also be a kubernetes service IP or domain name. 12 | bindingIPv4: 10.1.1.2 # Can also be an ENV. 13 | port: 29518 14 | serviceNameList: 15 | - namf-comm 16 | - namf-evts 17 | - namf-mt 18 | - namf-loc 19 | - namf-oam 20 | servedGuamiList: 21 | - plmnId: 22 | mcc: 208 23 | mnc: 93 24 | amfId: cafe00 25 | supportTaiList: 26 | - plmnId: 27 | mcc: 208 28 | mnc: 93 29 | tac: 1 30 | plmnSupportList: 31 | - plmnId: 32 | mcc: 208 33 | mnc: 93 34 | snssaiList: 35 | - sst: 1 36 | sd: 010203 37 | - sst: 1 38 | sd: 112233 39 | supportDnnList: 40 | - internet 41 | nrfUri: http://10.1.1.10:29510 42 | security: 43 | integrityOrder: 44 | - NIA2 45 | - NIA0 46 | cipheringOrder: 47 | - NEA2 48 | - NEA0 49 | networkName: 50 | full: free5GC 51 | short: free 52 | t3502: 720 53 | t3512: 3600 54 | non3gppDeregistrationTimer: 3240 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | my5G-core 2 | 3 | # non3GPP-access 4 | 5 | ![GitHub](https://img.shields.io/github/license/my5G/my5G-non3GPP-access?color=blue) 6 | ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/my5G/my5GCore) 7 | ![GitHub commit activity](https://img.shields.io/github/commit-activity/y/my5G/my5G-non3GPP-access) 8 | ![GitHub last commit](https://img.shields.io/github/last-commit/my5G/my5G-non3GPP-access) 9 | ![GitHub contributors](https://img.shields.io/github/contributors/my5G/my5G-non3GPP-access) 10 | 11 | ---- 12 | ## Description 13 | 14 | non3GPP-access is an open-source implementation to provide untrusted non3GPP access to 5GCN according to 3GPP Release 15. 15 | All the access is done via N3IWF. 16 | 17 | If you have questions or comments, please email us: [my5G team](mailto:my5G.initiative@gmail.com). 18 | 19 | ## Documentation 20 | 21 | For documentation, please reference to [wiki](https://github.com/my5G/my5G-non3GPP-access/wiki). 22 | 23 | ## Contributing 24 | 25 | For contribution, please reference to [guidelines](https://github.com/my5G/template/blob/main/CONTRIBUTING.md). 26 | 27 | ## License 28 | 29 | non3GPP-access is now under [Apache 2.0](https://github.com/my5G/my5G-non3GPP-access/blob/master/LICENSE) license. 30 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/smfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 10.1.1.3 # Can also be a kubernetes service IP or domain name. 10 | bindingIPv4: 10.1.1.3 # Can also be an ENV. 11 | port: 29502 12 | tls: 13 | key: free5gc/support/TLS/smf.key 14 | pem: free5gc/support/TLS/smf.pem 15 | serviceNameList: 16 | - nsmf-pdusession 17 | - nsmf-event-exposure 18 | - nsmf-oam 19 | snssai_info: 20 | - sNssai: 21 | sst: 1 22 | sd: 010203 23 | dnnSmfInfoList: 24 | - dnn: internet 25 | - sNssai: 26 | sst: 1 27 | sd: 112233 28 | dnnSmfInfoList: 29 | - dnn: internet 30 | pfcp: 31 | addr: 10.200.200.1 32 | userplane_information: 33 | up_nodes: 34 | gNB1: 35 | type: AN 36 | an_ip: 192.188.2.3 37 | UPF: 38 | type: UPF 39 | node_id: 10.200.200.101 40 | 41 | links: 42 | - A: gNB1 43 | B: UPF 44 | ue_subnet: 60.60.0.0/16 45 | dnn: 46 | internet: 47 | dns: 48 | ipv4: 8.8.8.8 49 | ipv6: 2001:4860:4860::8888 50 | internet2: 51 | dns: 52 | ipv4: 8.8.4.4 53 | ipv6: 2001:4860:4860::8844 54 | nrfUri: http://10.1.1.10:29510 55 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/smfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 10.1.1.3 # Can also be a kubernetes service IP or domain name. 10 | bindingIPv4: 10.1.1.3 # Can also be an ENV. 11 | port: 29502 12 | tls: 13 | key: free5gc/support/TLS/smf.key 14 | pem: free5gc/support/TLS/smf.pem 15 | serviceNameList: 16 | - nsmf-pdusession 17 | - nsmf-event-exposure 18 | - nsmf-oam 19 | snssai_info: 20 | - sNssai: 21 | sst: 1 22 | sd: 010203 23 | dnnSmfInfoList: 24 | - dnn: internet 25 | - sNssai: 26 | sst: 1 27 | sd: 112233 28 | dnnSmfInfoList: 29 | - dnn: internet 30 | pfcp: 31 | addr: 10.200.200.1 32 | userplane_information: 33 | up_nodes: 34 | gNB1: 35 | type: AN 36 | an_ip: 192.188.2.3 37 | UPF: 38 | type: UPF 39 | node_id: 10.200.200.101 40 | 41 | links: 42 | - A: gNB1 43 | B: UPF 44 | ue_subnet: 60.60.0.0/16 45 | dnn: 46 | internet: 47 | dns: 48 | ipv4: 8.8.8.8 49 | ipv6: 2001:4860:4860::8888 50 | internet2: 51 | dns: 52 | ipv4: 8.8.4.4 53 | ipv6: 2001:4860:4860::8844 54 | nrfUri: http://10.1.1.10:29510 55 | -------------------------------------------------------------------------------- /ue_utils/ping.go: -------------------------------------------------------------------------------- 1 | package ue_utils 2 | 3 | import ( 4 | "github.com/sparrc/go-ping" 5 | "time" 6 | "github.com/sirupsen/logrus" 7 | "free5gc/src/ue/logger" 8 | ) 9 | 10 | var log *logrus.Entry 11 | 12 | func init(){ 13 | log = logger.AppLog 14 | } 15 | 16 | func Ping(srcAddr, destAddr string){ 17 | // Ping remote 18 | pinger, err := ping.NewPinger(destAddr) 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | 23 | // Run with root 24 | pinger.SetPrivileged(true) 25 | 26 | pinger.OnRecv = func(pkt *ping.Packet) { 27 | log.Infof("%d bytes from %s: icmp_seq=%d time=%v\n", 28 | pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt) 29 | } 30 | pinger.OnFinish = func(stats *ping.Statistics) { 31 | log.Infof("\n--- %s ping statistics ---\n", stats.Addr) 32 | log.Infof("%d packets transmitted, %d packets received, %v%% packet loss\n", 33 | stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss) 34 | log.Infof("round-trip min/avg/max/stddev = %v/%v/%v/%v\n", 35 | stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt) 36 | } 37 | 38 | pinger.Count = 5 39 | pinger.Timeout = 10 * time.Second 40 | pinger.Source = "60.60.0.1" 41 | 42 | time.Sleep(3 * time.Second) 43 | 44 | pinger.Run() 45 | 46 | time.Sleep(1 * time.Second) 47 | 48 | stats := pinger.Statistics() 49 | if stats.PacketsSent != stats.PacketsRecv { 50 | log.Fatal("Ping Failed") 51 | }else{ 52 | log.Infoln("Ping Succeed") 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/test/smfcfg.ulcl.test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: http 9 | ipv4Addr: 127.0.0.1 10 | port: 29502 11 | tls: 12 | key: free5gc/support/TLS/smf.key 13 | pem: free5gc/support/TLS/smf.pem 14 | serviceNameList: 15 | - nsmf-pdusession 16 | - nsmf-event-exposure 17 | - nsmf-oam 18 | pfcp: 19 | addr: 10.200.200.1 20 | snssai_info: 21 | - sNssai: 22 | sst: 1 23 | sd: 010203 24 | dnnSmfInfoList: 25 | - dnn: internet 26 | - sNssai: 27 | sst: 1 28 | sd: 112233 29 | dnnSmfInfoList: 30 | - dnn: internet 31 | userplane_information: 32 | up_nodes: 33 | gNB1: 34 | type: AN 35 | an_ip: 192.188.2.3 36 | BranchingUPF: 37 | type: UPF 38 | node_id: 10.200.200.102 39 | up_resource_ip: 192.188.2.2 40 | AnchorUPF1: 41 | type: UPF 42 | node_id: 10.200.200.101 43 | up_resource_ip: 192.188.2.23 44 | AnchorUPF2: 45 | type: UPF 46 | node_id: 10.200.200.103 47 | up_resource_ip: 192.188.2.24 48 | links: 49 | - A: gNB1 50 | B: BranchingUPF 51 | - A: BranchingUPF 52 | B: AnchorUPF1 53 | - A: BranchingUPF 54 | B: AnchorUPF2 55 | ue_subnet: 60.60.0.0/16 56 | nrfUri: http://localhost:29510 57 | ulcl: true 58 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/test/smfcfg.test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: https 9 | ipv4Addr: 127.0.0.1 10 | port: 29502 11 | tls: 12 | key: free5gc/support/TLS/smf.key 13 | pem: free5gc/support/TLS/smf.pem 14 | serviceNameList: 15 | - nsmf-pdusession 16 | - nsmf-event-exposure 17 | - nsmf-oam 18 | pfcp: 19 | addr: 10.200.200.1 20 | snssai_info: 21 | - sNssai: 22 | sst: 1 23 | sd: 010203 24 | dnnSmfInfoList: 25 | - dnn: internet 26 | - sNssai: 27 | sst: 1 28 | sd: 112233 29 | dnnSmfInfoList: 30 | - dnn: internet 31 | userplane_information: 32 | up_nodes: 33 | gNB1: 34 | type: AN 35 | an_ip: 192.188.2.3 36 | BranchingUPF: 37 | type: UPF 38 | node_id: 10.200.200.102 39 | up_resource_ip: 192.188.2.2 40 | AnchorUPF1: 41 | type: UPF 42 | node_id: 10.200.200.101 43 | up_resource_ip: 192.188.2.23 44 | AnchorUPF2: 45 | type: UPF 46 | node_id: 10.200.200.103 47 | up_resource_ip: 192.188.2.24 48 | links: 49 | - A: gNB1 50 | B: BranchingUPF 51 | - A: BranchingUPF 52 | B: AnchorUPF1 53 | - A: BranchingUPF 54 | B: AnchorUPF2 55 | ue_subnet: 60.60.0.0/16 56 | nrfUri: https://localhost:29510 57 | ulcl: true 58 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/test/smfcfg.ulcl.test.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: AMF initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: https 9 | ipv4Addr: 127.0.0.1 10 | port: 29502 11 | tls: 12 | key: free5gc/support/TLS/smf.key 13 | pem: free5gc/support/TLS/smf.pem 14 | serviceNameList: 15 | - nsmf-pdusession 16 | - nsmf-event-exposure 17 | - nsmf-oam 18 | pfcp: 19 | addr: 10.200.200.1 20 | snssai_info: 21 | - sNssai: 22 | sst: 1 23 | sd: 010203 24 | dnnSmfInfoList: 25 | - dnn: internet 26 | - sNssai: 27 | sst: 1 28 | sd: 112233 29 | dnnSmfInfoList: 30 | - dnn: internet 31 | userplane_information: 32 | up_nodes: 33 | gNB1: 34 | type: AN 35 | an_ip: 192.188.2.3 36 | BranchingUPF: 37 | type: UPF 38 | node_id: 10.200.200.102 39 | up_resource_ip: 192.188.2.2 40 | AnchorUPF1: 41 | type: UPF 42 | node_id: 10.200.200.101 43 | up_resource_ip: 192.188.2.23 44 | AnchorUPF2: 45 | type: UPF 46 | node_id: 10.200.200.103 47 | up_resource_ip: 192.188.2.24 48 | links: 49 | - A: gNB1 50 | B: BranchingUPF 51 | - A: BranchingUPF 52 | B: AnchorUPF1 53 | - A: BranchingUPF 54 | B: AnchorUPF2 55 | ue_subnet: 60.60.0.0/16 56 | nrfUri: https://localhost:29510 57 | ulcl: true 58 | -------------------------------------------------------------------------------- /ue_ike/dispatcher.go: -------------------------------------------------------------------------------- 1 | package n3iwf_ike 2 | 3 | import ( 4 | "free5gc/src/n3iwf/logger" 5 | ike_handler "free5gc/src/n3iwf/ike/handler" 6 | ike_message "free5gc/src/n3iwf/ike/message" 7 | "net" 8 | 9 | "github.com/sirupsen/logrus" 10 | ) 11 | 12 | var ikeLog *logrus.Entry 13 | 14 | func init() { 15 | ikeLog = logger.IKELog 16 | } 17 | 18 | func Dispatch(udpConn *net.UDPConn, localAddr, remoteAddr *net.UDPAddr, msg []byte) { 19 | // As specified in RFC 7296 section 3.1, the IKE message send from/to UDP port 4500 20 | // should prepend a 4 bytes zero 21 | if localAddr.Port == 4500 { 22 | for i := 0; i < 4; i++ { 23 | if msg[i] != 0 { 24 | ikeLog.Warn("[IKE] Received an IKE packet that does not prepend 4 bytes zero from UDP port 4500, this packet may be the UDP encapsulated ESP. The packet will not be handled.") 25 | return 26 | } 27 | } 28 | msg = msg[4:] 29 | } 30 | 31 | ikeMessage, err := ike_message.Decode(msg) 32 | if err != nil { 33 | ikeLog.Error(err) 34 | return 35 | } 36 | 37 | switch ikeMessage.ExchangeType { 38 | case ike_message.IKE_SA_INIT: 39 | ike_handler.HandleIKESAINIT(udpConn, localAddr, remoteAddr, ikeMessage) 40 | case ike_message.IKE_AUTH: 41 | ike_handler.HandleIKEAUTH(udpConn, localAddr, remoteAddr, ikeMessage) 42 | case ike_message.CREATE_CHILD_SA: 43 | ike_handler.HandleCREATECHILDSA(udpConn, localAddr, remoteAddr, ikeMessage) 44 | default: 45 | ikeLog.Warnf("Unimplemented IKE message type, exchange type: %d", ikeMessage.ExchangeType) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/free5GC.conf: -------------------------------------------------------------------------------- 1 | db_uri: mongodb://db/free5GC 2 | 3 | #all logging levels 4 | #panic 5 | #fatal 6 | #error 7 | #warn 8 | #info 9 | #debug 10 | #trace 11 | logger: 12 | # network function 13 | AMF: 14 | debugLevel: info 15 | ReportCaller: true 16 | SMF: 17 | debugLevel: info 18 | ReportCaller: true 19 | UDR: 20 | debugLevel: info 21 | ReportCaller: true 22 | UDM: 23 | debugLevel: info 24 | ReportCaller: true 25 | NRF: 26 | debugLevel: info 27 | ReportCaller: true 28 | PCF: 29 | debugLevel: info 30 | ReportCaller: true 31 | AUSF: 32 | debugLevel: info 33 | ReportCaller: true 34 | N3IWF: 35 | debugLevel: info 36 | ReportCaller: true 37 | # library 38 | NAS: 39 | debugLevel: info 40 | ReportCaller: true 41 | FSM: 42 | debugLevel: info 43 | ReportCaller: true 44 | NGAP: 45 | debugLevel: info 46 | ReportCaller: true 47 | NamfComm: 48 | debugLevel: info 49 | ReportCaller: true 50 | NamfEventExposure: 51 | debugLevel: info 52 | ReportCaller: true 53 | NsmfPDUSession: 54 | debugLevel: info 55 | ReportCaller: true 56 | NudrDataRepository: 57 | debugLevel: info 58 | ReportCaller: true 59 | OpenApi: 60 | debugLevel: info 61 | ReportCaller: true 62 | Aper: 63 | debugLevel: info 64 | ReportCaller: true 65 | CommonConsumerTest: 66 | debugLevel: info 67 | ReportCaller: true 68 | # webui 69 | WEBUI: 70 | debugLevel: info 71 | ReportCaller: true 72 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/free5GC.conf: -------------------------------------------------------------------------------- 1 | db_uri: mongodb://localhost/free5GC 2 | 3 | #all logging levels 4 | #panic 5 | #fatal 6 | #error 7 | #warn 8 | #info 9 | #debug 10 | #trace 11 | logger: 12 | # network function 13 | AMF: 14 | debugLevel: info 15 | ReportCaller: true 16 | SMF: 17 | debugLevel: info 18 | ReportCaller: true 19 | UDR: 20 | debugLevel: info 21 | ReportCaller: true 22 | UDM: 23 | debugLevel: info 24 | ReportCaller: true 25 | NRF: 26 | debugLevel: info 27 | ReportCaller: true 28 | PCF: 29 | debugLevel: info 30 | ReportCaller: true 31 | AUSF: 32 | debugLevel: info 33 | ReportCaller: true 34 | N3IWF: 35 | debugLevel: info 36 | ReportCaller: true 37 | # library 38 | NAS: 39 | debugLevel: info 40 | ReportCaller: true 41 | FSM: 42 | debugLevel: info 43 | ReportCaller: true 44 | NGAP: 45 | debugLevel: info 46 | ReportCaller: true 47 | NamfComm: 48 | debugLevel: info 49 | ReportCaller: true 50 | NamfEventExposure: 51 | debugLevel: info 52 | ReportCaller: true 53 | NsmfPDUSession: 54 | debugLevel: info 55 | ReportCaller: true 56 | NudrDataRepository: 57 | debugLevel: info 58 | ReportCaller: true 59 | OpenApi: 60 | debugLevel: info 61 | ReportCaller: true 62 | Aper: 63 | debugLevel: info 64 | ReportCaller: true 65 | CommonConsumerTest: 66 | debugLevel: info 67 | ReportCaller: true 68 | # webui 69 | WEBUI: 70 | debugLevel: info 71 | ReportCaller: true 72 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/my5G-core.conf: -------------------------------------------------------------------------------- 1 | db_uri: mongodb://localhost/free5GC 2 | 3 | #all logging levels 4 | #panic 5 | #fatal 6 | #error 7 | #warn 8 | #info 9 | #debug 10 | #trace 11 | logger: 12 | # network function 13 | AMF: 14 | debugLevel: info 15 | ReportCaller: true 16 | SMF: 17 | debugLevel: info 18 | ReportCaller: true 19 | UDR: 20 | debugLevel: info 21 | ReportCaller: true 22 | UDM: 23 | debugLevel: info 24 | ReportCaller: true 25 | NRF: 26 | debugLevel: info 27 | ReportCaller: true 28 | PCF: 29 | debugLevel: info 30 | ReportCaller: true 31 | AUSF: 32 | debugLevel: info 33 | ReportCaller: true 34 | N3IWF: 35 | debugLevel: info 36 | ReportCaller: true 37 | # library 38 | NAS: 39 | debugLevel: info 40 | ReportCaller: true 41 | FSM: 42 | debugLevel: info 43 | ReportCaller: true 44 | NGAP: 45 | debugLevel: info 46 | ReportCaller: true 47 | NamfComm: 48 | debugLevel: info 49 | ReportCaller: true 50 | NamfEventExposure: 51 | debugLevel: info 52 | ReportCaller: true 53 | NsmfPDUSession: 54 | debugLevel: info 55 | ReportCaller: true 56 | NudrDataRepository: 57 | debugLevel: info 58 | ReportCaller: true 59 | OpenApi: 60 | debugLevel: info 61 | ReportCaller: true 62 | Aper: 63 | debugLevel: info 64 | ReportCaller: true 65 | CommonConsumerTest: 66 | debugLevel: info 67 | ReportCaller: true 68 | # webui 69 | WEBUI: 70 | debugLevel: info 71 | ReportCaller: true 72 | -------------------------------------------------------------------------------- /sample/ran_attach_config/free5GC.conf: -------------------------------------------------------------------------------- 1 | db_uri: mongodb://localhost/free5GC 2 | 3 | #all logging levels 4 | #panic 5 | #fatal 6 | #error 7 | #warn 8 | #info 9 | #debug 10 | #trace 11 | logger: 12 | # network function 13 | AMF: 14 | debugLevel: info 15 | ReportCaller: true 16 | SMF: 17 | debugLevel: info 18 | ReportCaller: true 19 | UDR: 20 | debugLevel: info 21 | ReportCaller: true 22 | UDM: 23 | debugLevel: info 24 | ReportCaller: true 25 | NRF: 26 | debugLevel: info 27 | ReportCaller: true 28 | PCF: 29 | debugLevel: info 30 | ReportCaller: true 31 | AUSF: 32 | debugLevel: info 33 | ReportCaller: true 34 | N3IWF: 35 | debugLevel: info 36 | ReportCaller: true 37 | # library 38 | NAS: 39 | debugLevel: info 40 | ReportCaller: true 41 | FSM: 42 | debugLevel: info 43 | ReportCaller: true 44 | NGAP: 45 | debugLevel: info 46 | ReportCaller: true 47 | NamfComm: 48 | debugLevel: info 49 | ReportCaller: true 50 | NamfEventExposure: 51 | debugLevel: info 52 | ReportCaller: true 53 | NsmfPDUSession: 54 | debugLevel: info 55 | ReportCaller: true 56 | NudrDataRepository: 57 | debugLevel: info 58 | ReportCaller: true 59 | OpenApi: 60 | debugLevel: info 61 | ReportCaller: true 62 | Aper: 63 | debugLevel: info 64 | ReportCaller: true 65 | CommonConsumerTest: 66 | debugLevel: info 67 | ReportCaller: true 68 | # webui 69 | WEBUI: 70 | debugLevel: info 71 | ReportCaller: true 72 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/my5G-core.conf: -------------------------------------------------------------------------------- 1 | db_uri: mongodb://localhost/free5GC 2 | 3 | #all logging levels 4 | #panic 5 | #fatal 6 | #error 7 | #warn 8 | #info 9 | #debug 10 | #trace 11 | logger: 12 | # network function 13 | AMF: 14 | debugLevel: info 15 | ReportCaller: true 16 | SMF: 17 | debugLevel: info 18 | ReportCaller: true 19 | UDR: 20 | debugLevel: info 21 | ReportCaller: true 22 | UDM: 23 | debugLevel: info 24 | ReportCaller: true 25 | NRF: 26 | debugLevel: info 27 | ReportCaller: true 28 | PCF: 29 | debugLevel: info 30 | ReportCaller: true 31 | AUSF: 32 | debugLevel: info 33 | ReportCaller: true 34 | N3IWF: 35 | debugLevel: info 36 | ReportCaller: true 37 | # library 38 | NAS: 39 | debugLevel: info 40 | ReportCaller: true 41 | FSM: 42 | debugLevel: info 43 | ReportCaller: true 44 | NGAP: 45 | debugLevel: info 46 | ReportCaller: true 47 | NamfComm: 48 | debugLevel: info 49 | ReportCaller: true 50 | NamfEventExposure: 51 | debugLevel: info 52 | ReportCaller: true 53 | NsmfPDUSession: 54 | debugLevel: info 55 | ReportCaller: true 56 | NudrDataRepository: 57 | debugLevel: info 58 | ReportCaller: true 59 | OpenApi: 60 | debugLevel: info 61 | ReportCaller: true 62 | Aper: 63 | debugLevel: info 64 | ReportCaller: true 65 | CommonConsumerTest: 66 | debugLevel: info 67 | ReportCaller: true 68 | # webui 69 | WEBUI: 70 | debugLevel: info 71 | ReportCaller: true 72 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/n3iwfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: N3IWF initial local configuration 4 | 5 | configuration: 6 | N3IWFInformation: 7 | GlobalN3IWFID: 8 | PLMNID: 9 | MCC: 10 | 208 11 | MNC: 12 | 93 13 | N3IWFID: 14 | 135 15 | Name: 16 | free5GC_N3IWF 17 | SupportedTAList: 18 | - TAC: 19 | 1 20 | BroadcastPLMNList: 21 | - PLMNID: 22 | MCC: 23 | 208 24 | MNC: 25 | 93 26 | TAISliceSupportList: 27 | - SNSSAI: 28 | SST: 29 | 1 30 | SD: 31 | 010203 32 | - SNSSAI: 33 | SST: 34 | 1 35 | SD: 36 | 112233 37 | AMFAddress: 38 | - IP: 192.168.0.1 39 | 40 | # Bind Interfaces 41 | # IKE interface 42 | IKEBindAddress: 43 | 192.168.127.1 44 | # IPSec virtual interface 45 | IPSecInterfaceAddress: 46 | 10.0.0.1 47 | # IPSec virtual interface mark 48 | IPSecInterfaceMark: 49 | 5 50 | # GTP interface 51 | GTPBindAddress: 52 | 10.200.200.2 53 | 54 | # NAS TCP Listen Port 55 | NASTCPPort: 56 | 20000 57 | 58 | # N3IWF FQDN 59 | FQDN: 60 | n3iwf.free5gc.org 61 | 62 | # Security 63 | # Private Key File Path 64 | PrivateKey: 65 | # Certificate Authority (CA) 66 | CertificateAuthority: 67 | # Certificate 68 | Certificate: 69 | 70 | # IP address that will be allocated to UE in IPSec tunnel 71 | UEIPAddressRange: 72 | 10.0.0.0/24 73 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/n3iwfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: N3IWF initial local configuration 4 | 5 | configuration: 6 | N3IWFInformation: 7 | GlobalN3IWFID: 8 | PLMNID: 9 | MCC: 10 | 208 11 | MNC: 12 | 93 13 | N3IWFID: 14 | 135 15 | Name: 16 | free5GC_N3IWF 17 | SupportedTAList: 18 | - TAC: 19 | 1 20 | BroadcastPLMNList: 21 | - PLMNID: 22 | MCC: 23 | 208 24 | MNC: 25 | 93 26 | TAISliceSupportList: 27 | - SNSSAI: 28 | SST: 29 | 1 30 | SD: 31 | 010203 32 | - SNSSAI: 33 | SST: 34 | 1 35 | SD: 36 | 112233 37 | AMFSCTPAddresses: 38 | - IP: 39 | - 172.16.0.1 40 | 41 | # Bind Interfaces 42 | # IKE interface 43 | IKEBindAddress: 44 | 192.168.127.1 45 | # IPSec virtual interface 46 | IPSecInterfaceAddress: 47 | 10.0.0.1 48 | # IPSec virtual interface mark 49 | IPSecInterfaceMark: 50 | 5 51 | # GTP interface 52 | GTPBindAddress: 53 | 10.200.200.2 54 | 55 | # NAS TCP Listen Port 56 | NASTCPPort: 57 | 20000 58 | 59 | # N3IWF FQDN 60 | FQDN: 61 | n3iwf.free5gc.org 62 | 63 | # Security 64 | # Private Key File Path 65 | PrivateKey: 66 | # Certificate Authority (CA) 67 | CertificateAuthority: 68 | # Certificate 69 | Certificate: 70 | 71 | # IP address that will be allocated to UE in IPSec tunnel 72 | UEIPAddressRange: 73 | 10.0.0.0/24 74 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/n3iwfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: N3IWF initial local configuration 4 | 5 | configuration: 6 | N3IWFInformation: 7 | GlobalN3IWFID: 8 | PLMNID: 9 | MCC: 10 | 208 11 | MNC: 12 | 93 13 | N3IWFID: 14 | 135 15 | Name: 16 | free5GC_N3IWF 17 | SupportedTAList: 18 | - TAC: 19 | 1 20 | BroadcastPLMNList: 21 | - PLMNID: 22 | MCC: 23 | 208 24 | MNC: 25 | 93 26 | TAISliceSupportList: 27 | - SNSSAI: 28 | SST: 29 | 1 30 | SD: 31 | 010203 32 | - SNSSAI: 33 | SST: 34 | 1 35 | SD: 36 | 112233 37 | AMFSCTPAddresses: 38 | - IP: 39 | - 172.16.0.1 40 | 41 | # Bind Interfaces 42 | # IKE interface 43 | IKEBindAddress: 44 | 192.168.127.1 45 | # IPSec virtual interface 46 | IPSecInterfaceAddress: 47 | 10.0.0.1 48 | # IPSec virtual interface mark 49 | IPSecInterfaceMark: 50 | 5 51 | # GTP interface 52 | GTPBindAddress: 53 | 10.200.200.2 54 | 55 | # NAS TCP Listen Port 56 | NASTCPPort: 57 | 20000 58 | 59 | # N3IWF FQDN 60 | FQDN: 61 | n3iwf.free5gc.org 62 | 63 | # Security 64 | # Private Key File Path 65 | PrivateKey: 66 | # Certificate Authority (CA) 67 | CertificateAuthority: 68 | # Certificate 69 | Certificate: 70 | 71 | # IP address that will be allocated to UE in IPSec tunnel 72 | UEIPAddressRange: 73 | 10.0.0.0/24 74 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/udmcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UDM initial local configuration 4 | 5 | configuration: 6 | serviceNameList: 7 | - nudm-sdm 8 | - nudm-uecm 9 | - nudm-ueau 10 | - nudm-ee 11 | - nudm-pp 12 | sbi: 13 | scheme: https 14 | ipv4Addr: udm 15 | port: 29503 16 | tls: 17 | log: free5gc/udmsslkey.log 18 | pem: free5gc/support/TLS/udm.pem 19 | key: free5gc/support/TLS/udm.key 20 | 21 | udrclient: 22 | scheme: https 23 | ipv4Addr: udr 24 | port: 29504 25 | 26 | nrfclient: 27 | scheme: https 28 | ipv4Addr: nrf 29 | port: 29510 30 | nrfUri: https://nrf:29510 31 | 32 | # test data set from TS33501-f60 Annex C.4 33 | # udmProfileAHNPublicKey: 5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650 34 | # udmProfileAHNPrivateKey: c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d 35 | # udmProfileBHNPublicKey: 0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4 36 | # udmProfileBHNPrivateKey: F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA 37 | keys: 38 | udmProfileAHNPublicKey: 5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650 39 | udmProfileAHNPrivateKey: c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d 40 | udmProfileBHNPublicKey: 0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4 41 | udmProfileBHNPrivateKey: F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/run_core.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Script not ready yet 4 | # 5 | 6 | CFG_DIR="$(pwd)/.." 7 | PID_LIST=() 8 | 9 | dirs=$(echo $CFG_DIR | tr "//" "\n" | tac) 10 | arr=($dirs) 11 | CORE_CFG_PATH="${arr[4]}/${arr[3]}/${arr[2]}/my5G-core.conf" 12 | 13 | #echo $CORE_CFG_PATH 14 | #for d in $dirs 15 | #do 16 | # echo "> [$d]" 17 | #done 18 | # 19 | #exit 0 20 | 21 | cd ../../../src/upf/build 22 | mv -f ./config/upfcfg.yaml ./config/upfcfg.yaml.old 23 | cp ../config/upfcfg.example.my5Gcore-basic-config.yaml ./config/upfcfg.yaml 24 | sudo -v 25 | sudo -E ip netns exec UPFns ./bin/free5gc-upfd " -free5gccfg $CORE_CFG_PATH" & 26 | PID_LIST+=($!) 27 | 28 | sleep 1 29 | 30 | cd ../../.. 31 | 32 | 33 | mongo free5gc --eval "db.NfProfile.drop()" 34 | mongo free5gc --eval "db.urilist.drop()" 35 | 36 | ./bin/webconsole -free5gccfg "$CORE_CFG_PATH" -webuicfg "$CFG_DIR/webuicfg.conf" & 37 | PID_LIST+=($!) 38 | 39 | NF_LIST="nrf amf smf udr pcf udm nssf ausf" 40 | 41 | export GIN_MODE=release 42 | 43 | for NF in ${NF_LIST}; do 44 | ./bin/${NF} -free5gccfg "$CORE_CFG_PATH" $(echo " -${NF}cfg $CFG_DIR/${NF}cfg.conf") & 45 | PID_LIST+=($!) 46 | done 47 | 48 | sudo ./bin/n3iwf -free5gccfg "$CORE_CFG_PATH" -n3iwfcfg "$CFG_DIR/n3iwfcfg.conf" & 49 | SUDO_N3IWF_PID=$! 50 | sleep 1 51 | N3IWF_PID=$(pgrep -P $SUDO_N3IWF_PID) 52 | PID_LIST+=($SUDO_N3IWF_PID $N3IWF_PID) 53 | 54 | function terminate() 55 | { 56 | # kill amf first 57 | while $(sudo kill -SIGINT ${PID_LIST[2]} 2>/dev/null); do 58 | sleep 2 59 | done 60 | 61 | for ((idx=${#PID_LIST[@]}-1;idx>=0;idx--)); do 62 | sudo kill -SIGKILL ${PID_LIST[$idx]} 63 | done 64 | } 65 | 66 | trap terminate SIGINT 67 | wait ${PID_LIST} 68 | -------------------------------------------------------------------------------- /sample/ran_attach_config/udmcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UDM initial local configuration 4 | 5 | configuration: 6 | serviceNameList: 7 | - nudm-sdm 8 | - nudm-uecm 9 | - nudm-ueau 10 | - nudm-ee 11 | - nudm-pp 12 | sbi: 13 | scheme: http 14 | registerIPv4: 127.0.0.1 # IP used to register to NRF 15 | bindingIPv4: 127.0.0.1 # IP used to bind the service 16 | port: 29503 17 | tls: 18 | log: free5gc/udmsslkey.log 19 | pem: free5gc/support/TLS/udm.pem 20 | key: free5gc/support/TLS/udm.key 21 | 22 | udrclient: 23 | scheme: http 24 | ipv4Addr: 127.0.0.1 25 | port: 29504 26 | 27 | nrfclient: 28 | scheme: http 29 | ipv4Addr: 127.0.0.1 30 | port: 29510 31 | nrfUri: http://localhost:29510 32 | 33 | # test data set from TS33501-f60 Annex C.4 34 | # udmProfileAHNPublicKey: 5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650 35 | # udmProfileAHNPrivateKey: c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d 36 | # udmProfileBHNPublicKey: 0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4 37 | # udmProfileBHNPrivateKey: F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA 38 | keys: 39 | udmProfileAHNPublicKey: 5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650 40 | udmProfileAHNPrivateKey: c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d 41 | udmProfileBHNPublicKey: 0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4 42 | udmProfileBHNPrivateKey: F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA 43 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/udmcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UDM initial local configuration 4 | 5 | configuration: 6 | serviceNameList: 7 | - nudm-sdm 8 | - nudm-uecm 9 | - nudm-ueau 10 | - nudm-ee 11 | - nudm-pp 12 | sbi: 13 | scheme: http 14 | registerIPv4: 10.1.1.7 # Can also be a kubernetes service IP or domain name. 15 | bindingIPv4: 10.1.1.7 # Can also be an ENV. 16 | port: 29503 17 | tls: 18 | log: free5gc/udmsslkey.log 19 | pem: free5gc/support/TLS/udm.pem 20 | key: free5gc/support/TLS/udm.key 21 | 22 | udrclient: 23 | scheme: http 24 | ipv4Addr: 10.1.1.8 25 | port: 29504 26 | 27 | nrfclient: 28 | scheme: http 29 | ipv4Addr: 10.1.1.10 30 | port: 29510 31 | nrfUri: http://10.1.1.10:29510 32 | 33 | # test data set from TS33501-f60 Annex C.4 34 | # udmProfileAHNPublicKey: 5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650 35 | # udmProfileAHNPrivateKey: c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d 36 | # udmProfileBHNPublicKey: 0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4 37 | # udmProfileBHNPrivateKey: F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA 38 | keys: 39 | udmProfileAHNPublicKey: 5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650 40 | udmProfileAHNPrivateKey: c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d 41 | udmProfileBHNPublicKey: 0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4 42 | udmProfileBHNPrivateKey: F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/udmcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: UDM initial local configuration 4 | 5 | configuration: 6 | serviceNameList: 7 | - nudm-sdm 8 | - nudm-uecm 9 | - nudm-ueau 10 | - nudm-ee 11 | - nudm-pp 12 | sbi: 13 | scheme: http 14 | registerIPv4: 10.1.1.7 # Can also be a kubernetes service IP or domain name. 15 | bindingIPv4: 10.1.1.7 # Can also be an ENV. 16 | port: 29503 17 | tls: 18 | log: free5gc/udmsslkey.log 19 | pem: free5gc/support/TLS/udm.pem 20 | key: free5gc/support/TLS/udm.key 21 | 22 | udrclient: 23 | scheme: http 24 | ipv4Addr: 10.1.1.8 25 | port: 29504 26 | 27 | nrfclient: 28 | scheme: http 29 | ipv4Addr: 10.1.1.10 30 | port: 29510 31 | nrfUri: http://10.1.1.10:29510 32 | 33 | # test data set from TS33501-f60 Annex C.4 34 | # udmProfileAHNPublicKey: 5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650 35 | # udmProfileAHNPrivateKey: c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d 36 | # udmProfileBHNPublicKey: 0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4 37 | # udmProfileBHNPrivateKey: F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA 38 | keys: 39 | udmProfileAHNPublicKey: 5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650 40 | udmProfileAHNPrivateKey: c53c22208b61860b06c62e5406a7b330c2b577aa5558981510d128247d38bd1d 41 | udmProfileBHNPublicKey: 0472DA71976234CE833A6907425867B82E074D44EF907DFB4B3E21C1C2256EBCD15A7DED52FCBB097A4ED250E036C7B9C8C7004C4EEDC4F068CD7BF8D3F900E3B4 42 | udmProfileBHNPrivateKey: F1AB1074477EBCC7F554EA1C5FC368B1616730155E0041AC447D6301975FECDA 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /rest_api/routers.go: -------------------------------------------------------------------------------- 1 | package rest_api 2 | 3 | import ( 4 | "net/http" 5 | "strings" 6 | 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | // Route is the information for every URI. 11 | type Route struct { 12 | // Name is the name of this Route. 13 | Name string 14 | // Method is the string for the HTTP method. ex) GET, POST etc.. 15 | Method string 16 | // Pattern is the pattern of the URI. 17 | Pattern string 18 | // HandlerFunc is the handler function of this route. 19 | HandlerFunc gin.HandlerFunc 20 | } 21 | 22 | // Routes is the list of the generated Route. 23 | type Routes []Route 24 | 25 | // NewRouter returns a new router. 26 | func NewRouter() *gin.Engine { 27 | router := gin.Default() 28 | AddService(router) 29 | return router 30 | } 31 | 32 | func AddService(engine *gin.Engine) *gin.RouterGroup { 33 | group := engine.Group("") 34 | 35 | for _, route := range routes { 36 | switch route.Method { 37 | case "GET": 38 | group.GET(route.Pattern, route.HandlerFunc) 39 | case "POST": 40 | group.POST(route.Pattern, route.HandlerFunc) 41 | case "PUT": 42 | group.PUT(route.Pattern, route.HandlerFunc) 43 | case "DELETE": 44 | group.DELETE(route.Pattern, route.HandlerFunc) 45 | } 46 | } 47 | 48 | return group 49 | } 50 | 51 | // Index is the index handler. 52 | func Index(c *gin.Context) { 53 | c.String(http.StatusOK, "Hello from non3GPP-UE!") 54 | } 55 | 56 | var routes = Routes{ 57 | { 58 | "Index", 59 | "GET", 60 | "", 61 | Index, 62 | }, 63 | { 64 | "Registration", 65 | strings.ToUpper("Post"), 66 | "/registration/", 67 | Registration, 68 | }, 69 | { 70 | "Deregistration", 71 | strings.ToUpper("Get"), 72 | "/deregistration/", 73 | Deregistration, 74 | }, 75 | { 76 | "Ping", 77 | strings.ToUpper("Get"), 78 | "/ping/", 79 | Ping, 80 | }, 81 | { 82 | Name: "Info", 83 | Method: strings.ToUpper("Get"), 84 | Pattern: "/info/", 85 | HandlerFunc: Info, 86 | }, 87 | } 88 | -------------------------------------------------------------------------------- /logger/logger.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "runtime" 7 | "strings" 8 | "github.com/sirupsen/logrus" 9 | ) 10 | 11 | var log *logrus.Logger 12 | var AppLog *logrus.Entry 13 | var InitLog *logrus.Entry 14 | var ContextLog *logrus.Entry 15 | var RunLog *logrus.Entry 16 | var RegistrationLog *logrus.Entry 17 | var DeregistrationLog *logrus.Entry 18 | var HandlerLog *logrus.Entry 19 | var IKELog *logrus.Entry 20 | 21 | func init() { 22 | log = logrus.New() 23 | log.SetReportCaller(true) 24 | 25 | log.Formatter = &logrus.TextFormatter{ 26 | ForceColors: true, 27 | DisableColors: false, 28 | EnvironmentOverrideColors: false, 29 | DisableTimestamp: false, 30 | FullTimestamp: true, 31 | TimestampFormat: "", 32 | DisableSorting: false, 33 | SortingFunc: nil, 34 | DisableLevelTruncation: false, 35 | QuoteEmptyFields: false, 36 | FieldMap: nil, 37 | CallerPrettyfier: func(f *runtime.Frame) (string, string) { 38 | orgFilename, _ := os.Getwd() 39 | repopath := orgFilename 40 | repopath = strings.Replace(repopath, "/bin", "", 1) 41 | filename := strings.Replace(f.File, repopath, "", -1) 42 | return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line) 43 | }, 44 | } 45 | 46 | AppLog = log.WithFields(logrus.Fields{"UE": "app"}) 47 | InitLog = log.WithFields(logrus.Fields{"UE": "init"}) 48 | ContextLog = log.WithFields(logrus.Fields{"UE": "Context"}) 49 | RunLog = log.WithFields(logrus.Fields{"UE": "Run"}) 50 | RegistrationLog = log.WithFields(logrus.Fields{"UE": "Registration"}) 51 | DeregistrationLog = log.WithFields(logrus.Fields{"UE": "Deregistration"}) 52 | HandlerLog = log.WithFields(logrus.Fields{"UE": "Handler"}) 53 | IKELog = log.WithFields(logrus.Fields{"UE": "IKE"}) 54 | } 55 | 56 | func SetLogLevel(level logrus.Level) { 57 | log.SetLevel(level) 58 | } 59 | 60 | func SetReportCaller(bool bool) { 61 | log.SetReportCaller(bool) 62 | } 63 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/test/smfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: initial local configuration 4 | 5 | configuration: 6 | smfName: SMF 7 | sbi: 8 | scheme: https 9 | ipv4Addr: 127.0.0.1 10 | port: 29502 11 | tls: 12 | key: free5gc/support/TLS/smf.key 13 | pem: free5gc/support/TLS/smf.pem 14 | serviceNameList: 15 | - nsmf-pdusession 16 | - nsmf-event-exposure 17 | - nsmf-oam 18 | snssai_info: 19 | - sNssai: 20 | sst: 1 21 | sd: 010203 22 | dnnSmfInfoList: 23 | - dnn: internet 24 | - sNssai: 25 | sst: 1 26 | sd: 112233 27 | dnnSmfInfoList: 28 | - dnn: internet 29 | pfcp: 30 | addr: 127.0.0.2 31 | userplane_information: 32 | up_nodes: 33 | gNB1: 34 | type: AN 35 | an_ip: 192.188.2.3 36 | ANUPF: 37 | type: UPF 38 | node_id: 127.0.0.3 39 | up_resource_ip: 192.188.2.2 40 | IUPF1: 41 | type: UPF 42 | node_id: 127.0.0.4 43 | up_resource_ip: 192.188.2.4 44 | BranchingUPF1: 45 | type: UPF 46 | node_id: 127.0.0.5 47 | up_resource_ip: 192.188.2.5 48 | BranchingUPF2: 49 | type: UPF 50 | node_id: 127.0.0.6 51 | up_resource_ip: 192.188.2.6 52 | AnchorUPF1: 53 | type: UPF 54 | node_id: 127.0.0.7 55 | up_resource_ip: 192.188.2.7 56 | AnchorUPF2: 57 | type: UPF 58 | node_id: 127.0.0.8 59 | up_resource_ip: 192.188.2.8 60 | AnchorUPF3: 61 | type: UPF 62 | node_id: 127.0.0.9 63 | up_resource_ip: 192.188.2.9 64 | AnchorUPF4: 65 | type: UPF 66 | node_id: 127.0.0.10 67 | up_resource_ip: 192.188.2.10 68 | AnchorUPF5: 69 | type: UPF 70 | node_id: 127.0.0.11 71 | up_resource_ip: 192.188.2.11 72 | ANUPF2: 73 | type: UPF 74 | node_id: 127.0.0.12 75 | up_resource_ip: 192.188.2.12 76 | links: 77 | - A: gNB1 78 | B: ANUPF 79 | - A: ANUPF 80 | B: IUPF1 81 | - A: ANUPF 82 | B: BranchingUPF2 83 | - A: IUPF1 84 | B: BranchingUPF1 85 | - A: BranchingUPF1 86 | B: AnchorUPF1 87 | - A: BranchingUPF1 88 | B: AnchorUPF2 89 | - A: BranchingUPF2 90 | B: AnchorUPF3 91 | - A: BranchingUPF2 92 | B: AnchorUPF4 93 | - A: gNB1 94 | B: ANUPF2 95 | - A: ANUPF2 96 | B: AnchorUPF5 97 | ue_subnet: 60.60.0.0/16 98 | nrfUri: https://localhost:29510 99 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | ## Filing issues 4 | 5 | Always try to use the issues templates to reports bug or request new features otherwise your issue could be closed. 6 | 7 | __Sensitive security-related issues should be reported via email__ 8 | 9 | ## Development Workflow 10 | 11 | ![Dev-Workflow](./docs/media/img/dev-workflow.svg) 12 | 13 | ## Issues Management (for Project Members) 14 | 15 | To improve the management of the list of things to-do in the project it is used the kanban board from Github. 16 | 17 | ### Backlog 18 | 19 | All issues created are placed in this column. 20 | 21 | 22 | ### Prioritized 23 | 24 | The issues that have higher priority are moved from Backlog to this column. So developers that are looking for a new issue to work on, should always look at this column before Backlog. 25 | 26 | 27 | ### Development In Progress 28 | 29 | When a developer starts working on an issue, he must move the issue to this column. 30 | The fixes or new features must be implement in a different branch in developers local environment and then a Pull Request must be used to merge the changes. After the changes are done and pushed to the remote repository on Github, the developer must assign at least one reviewer to the Pull Request. The issue will be automatically moved to the column Ready To Test. 31 | 32 | 33 | ### Ready To Test 34 | 35 | When the reviewer is actually going to review the Pull Request, he must move the issue in this column to Testing. 36 | 37 | 38 | ### Testing 39 | 40 | If the reviewer approve the Pull Request, then the Pull Request in this column will be moved automatically to Ready To Merge. 41 | 42 | 43 | 44 | ### Done 45 | 46 | When the Pull Request is merged or closed, the issue and Pull Requests are moved automatically to this column. 47 | 48 | 49 | ![Git Workflow](docs/media/img/git-workflow.png) 50 | 51 | 52 | ## Branch Protection Rules 53 | 54 | * The branches master and develop are protected, so all changes to them, must be done through Pull Requests. 55 | * Tag branches are also protected and can not be changed. 56 | * Pull Requests must be assign at least one reviewer. 57 | * All pipelines must succeed for a Pull Request to be merged. 58 | * Forced pushes are not allowed in protected branches 59 | 60 | 61 | ## Pull Requests 62 | 63 | * In general all Pull Requests should target __develop__ branch. 64 | * Always update the Readme instructions when applicable 65 | 66 | 67 | **Git / Github Tutorials** 68 | * http://try.github.io/ 69 | * https://guides.github.com/ 70 | * https://www.youtube.com/githubguides 71 | * https://guides.github.com/introduction/flow 72 | 73 | -------------------------------------------------------------------------------- /rest_api/api.go: -------------------------------------------------------------------------------- 1 | package rest_api 2 | 3 | import ( 4 | "free5gc/lib/openapi/models" 5 | "free5gc/src/ue/ue_context" 6 | "free5gc/src/ue/ue_handler/ue_message" 7 | "github.com/gin-gonic/gin" 8 | "net/http" 9 | "free5gc/src/ue/ue_procedures" 10 | "free5gc/src/ue/logger" 11 | ) 12 | 13 | type RegistrationData struct { 14 | AuthenticationMethod models.AuthMethod `json:"authenticationMethod" yaml:"authenticationMethod" bson:"authenticationMethod" mapstructure:"AuthenticationMethod"` 15 | SupiOrSuci string `json:"supiOrSuci" yaml:"supiOrSuci" bson:"supiOrSuci" mapstructure:"SupiOrSuci"` 16 | K string `json:"k" yaml:"k" bson:"k" mapstructure:"K"` 17 | OpcType string `json:"opcType" yaml:"opcType" bson:"opcType" mapstructure:"OpcType"` 18 | Opc string `json:"opc" yaml:"opc" bson:"opc" mapstructure:"Opc"` 19 | PlmnId string `json:"plmnid" yaml:"plmnid" bson:"plmnid" mapstructure:"plmnid"` 20 | ServingNetworkName string `json:"servingNetworkName" yaml:"servingNetworkName" bson:"servingNetworkName" mapstructure:"ServingNetworkName"` 21 | N3IWFIpAddress string `json:"n3IWFIpAddress" yaml:"n3IWFIpAddress" bson:"n3IWFIpAddress" mapstructure:"N3IWFIpAddress"` 22 | SNssai *models.Snssai `json:"SNssai" yaml:"SNssai" bson:"SNssai" mapstructure:"SNssai"` 23 | IKEBindAddress string `json:"ikeBindAddress" yaml:"ikeBindAddress" bson:"ikeBindAddress" mapstructure:"IKEBindAddress"` 24 | } 25 | 26 | func Registration(c *gin.Context) { 27 | var regData RegistrationData 28 | err := c.ShouldBindJSON(®Data) 29 | if err != nil { 30 | logger.RegistrationLog.Errorln(err) 31 | problemDetail := "[Request Body] " + err.Error() 32 | rsp := models.ProblemDetails{ 33 | Title: "Malformed request syntax", 34 | Status: http.StatusBadRequest, 35 | Detail: problemDetail, 36 | } 37 | c.JSON(http.StatusBadRequest, rsp) 38 | return 39 | } 40 | 41 | //handlerMsg := udm_message.NewHandlerMessage(udm_message.EventConfirmAuth, req) 42 | //udm_handler.SendMessage(handlerMsg) 43 | //rsp := <-handlerMsg.ResponseChan 44 | // 45 | //HTTPResponse := rsp.HTTPResponse 46 | //c.JSON(HTTPResponse.Status, HTTPResponse.Body) 47 | 48 | // Transfer data to UE Context 49 | ctx := ue_context.UE_Self() 50 | ctx.AuthenticationMethod = regData.AuthenticationMethod 51 | ctx.PermanentKeyValue = regData.K 52 | ctx.SUPIorSUCI = regData.SupiOrSuci 53 | ctx.OpcType = regData.OpcType 54 | ctx.Opc = regData.Opc 55 | //PlmnId 56 | //ServingNetworkName 57 | ctx.N3IWFIpAddress = regData.N3IWFIpAddress 58 | ctx.IKEBindAddress = regData.IKEBindAddress 59 | ctx.SNssai = regData.SNssai 60 | 61 | // if 62 | 63 | // TODO: Execute registration procedure as a new Go routine? 64 | handlerMsg := ue_message.HandlerMessage{ 65 | Event: ue_message.EventRegistrationProcedure, 66 | Value: nil, 67 | } 68 | ue_message.SendMessage(handlerMsg) 69 | c.String(http.StatusOK, "Registration Procedure triggered.") 70 | } 71 | 72 | func Deregistration(c *gin.Context){ 73 | ue_procedures.DeregistrationProcedure(ue_context.UE_Self()) 74 | c.String(http.StatusOK, "Deregistration Procedure executed") 75 | } 76 | 77 | func Ping(c *gin.Context) { 78 | c.JSON(http.StatusOK, gin.H{}) 79 | // TODO: Implement here a ping from UE through the 5GC 80 | } 81 | 82 | func Info(c *gin.Context) { 83 | ctx := ue_context.UE_Self() 84 | c.JSON(http.StatusOK,ctx) 85 | } -------------------------------------------------------------------------------- /test/sample-ue.json: -------------------------------------------------------------------------------- 1 | { 2 | "plmnID":"20893", 3 | "ueId":"imsi-2089300007487", 4 | "AuthenticationSubscription":{ 5 | "authenticationMethod":"5G_AKA", 6 | "permanentKey":{ 7 | "permanentKeyValue":"5122250214c33e723a5dd523fc145fc0", 8 | "encryptionKey":0, 9 | "encryptionAlgorithm":0 10 | }, 11 | "sequenceNumber":"16f3b3f70fc2", 12 | "authenticationManagementField":"8000", 13 | "milenage":{ 14 | "op":{ 15 | "opValue":"c9e8763286b5b9ffbdf56e1297d0887b", 16 | "encryptionKey":0, 17 | "encryptionAlgorithm":0 18 | } 19 | }, 20 | "opc":{ 21 | "opcValue":"981d464c7c52eb6e5036234984ad0bcf", 22 | "encryptionKey":0, 23 | "encryptionAlgorithm":0 24 | } 25 | }, 26 | "AccessAndMobilitySubscriptionData":{ 27 | "gpsis":[ 28 | "msisdn-0900000000" 29 | ], 30 | "subscribedUeAmbr":{ 31 | "uplink":"1000 Kbps", 32 | "downlink":"1000 Kbps" 33 | }, 34 | "nssai":{ 35 | "defaultSingleNssais":[ 36 | { 37 | "sst":1, 38 | "sd":"010203" 39 | }, 40 | { 41 | "sst":1, 42 | "sd":"112233" 43 | } 44 | ], 45 | "singleNssais":[ 46 | { 47 | "sst":1, 48 | "sd":"010203" 49 | }, 50 | { 51 | "sst":1, 52 | "sd":"112233" 53 | } 54 | ] 55 | } 56 | }, 57 | "SessionManagementSubscriptionData":{ 58 | "singleNssai":{ 59 | "sst":1, 60 | "sd":"010203" 61 | }, 62 | "dnnConfigurations":{ 63 | "internet":{ 64 | "pduSessionTypes":{ 65 | "defaultSessionType":"IPV4", 66 | "allowedSessionTypes":[ 67 | "IPV4" 68 | ] 69 | }, 70 | "sscModes":{ 71 | "defaultSscMode":"SSC_MODE_1", 72 | "allowedSscModes":[ 73 | "SSC_MODE_1" 74 | ] 75 | }, 76 | "5gQosProfile":{ 77 | "5qi":9, 78 | "arp":{ 79 | "priorityLevel":8, 80 | "preemptCap":"", 81 | "preemptVuln":"" 82 | }, 83 | "priorityLevel":8 84 | }, 85 | "sessionAmbr":{ 86 | "uplink":"1000 Kbps", 87 | "downlink":"1000 Kbps" 88 | } 89 | } 90 | } 91 | }, 92 | "SmfSelectionSubscriptionData":{ 93 | "subscribedSnssaiInfos":{ 94 | "01010203":{ 95 | "dnnInfos":[ 96 | { 97 | "dnn":"internet" 98 | } 99 | ] 100 | }, 101 | "01112233":{ 102 | "dnnInfos":[ 103 | { 104 | "dnn":"internet" 105 | } 106 | ] 107 | } 108 | } 109 | }, 110 | "AmPolicyData":{ 111 | "subscCats":[ 112 | "free5gc" 113 | ] 114 | }, 115 | "SmPolicyData":{ 116 | "smPolicySnssaiData":{ 117 | "01010203":{ 118 | "snssai":{ 119 | "sst":1, 120 | "sd":"010203" 121 | }, 122 | "smPolicyDnnData":{ 123 | "internet":{ 124 | "dnn":"internet" 125 | } 126 | } 127 | }, 128 | "01112233":{ 129 | "snssai":{ 130 | "sst":1, 131 | "sd":"112233" 132 | }, 133 | "smPolicyDnnData":{ 134 | "internet":{ 135 | "dnn":"internet" 136 | } 137 | } 138 | } 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /ue_procedures/security.go: -------------------------------------------------------------------------------- 1 | package ue_procedures 2 | 3 | import ( 4 | "fmt" 5 | "free5gc/lib/nas" 6 | "free5gc/lib/nas/security" 7 | "reflect" 8 | ) 9 | 10 | func NASEncode(ue *UeRanContext, msg *nas.Message, securityContextAvailable bool, newSecurityContext bool) ( 11 | payload []byte, err error) { 12 | var sequenceNumber uint8 13 | if ue == nil { 14 | err = fmt.Errorf("amfUe is nil") 15 | return 16 | } 17 | if msg == nil { 18 | err = fmt.Errorf("Nas Message is empty") 19 | return 20 | } 21 | 22 | if !securityContextAvailable { 23 | return msg.PlainNasEncode() 24 | } else { 25 | if newSecurityContext { 26 | ue.ULCount.Set(0, 0) 27 | ue.DLCount.Set(0, 0) 28 | } 29 | 30 | sequenceNumber = ue.ULCount.SQN() 31 | payload, err = msg.PlainNasEncode() 32 | if err != nil { 33 | return 34 | } 35 | 36 | // TODO: Support for ue has nas connection in both accessType 37 | if err = security.NASEncrypt(ue.CipheringAlg, ue.KnasEnc, ue.ULCount.Get(), security.Bearer3GPP, 38 | security.DirectionUplink, payload); err != nil { 39 | return 40 | } 41 | // add sequece number 42 | payload = append([]byte{sequenceNumber}, payload[:]...) 43 | mac32 := make([]byte, 4) 44 | _ = mac32 45 | // fmt.Println("sequenceNumber", sequenceNumber) 46 | // fmt.Println("ue.IntegrityAlg", ue.IntegrityAlg) 47 | // fmt.Println("ue.KnasInt", ue.KnasInt) 48 | // fmt.Println("ue.ULCount.Get()", ue.ULCount.Get()) 49 | // fmt.Println("security.Bearer3GPP", security.Bearer3GPP) 50 | // fmt.Println("security.DirectionUplink", security.DirectionUplink) 51 | // fmt.Println("payload", payload) 52 | 53 | mac32, err = security.NASMacCalculate(ue.IntegrityAlg, ue.KnasInt, ue.ULCount.Get(), 54 | security.Bearer3GPP, security.DirectionUplink, payload) 55 | if err != nil { 56 | return 57 | } 58 | 59 | // Add mac value 60 | payload = append(mac32, payload[:]...) 61 | // Add EPD and Security Type 62 | msgSecurityHeader := []byte{msg.SecurityHeader.ProtocolDiscriminator, msg.SecurityHeader.SecurityHeaderType} 63 | payload = append(msgSecurityHeader, payload[:]...) 64 | 65 | // Increase UL Count 66 | ue.ULCount.AddOne() 67 | } 68 | return payload, err 69 | } 70 | 71 | func NASDecode(ue *UeRanContext, securityHeaderType uint8, payload []byte) (msg *nas.Message, err error) { 72 | if ue == nil { 73 | err = fmt.Errorf("amfUe is nil") 74 | return 75 | } 76 | if payload == nil { 77 | err = fmt.Errorf("Nas payload is empty") 78 | return 79 | } 80 | 81 | msg = new(nas.Message) 82 | 83 | if securityHeaderType == nas.SecurityHeaderTypePlainNas { 84 | err = msg.PlainNasDecode(&payload) 85 | return 86 | } else if ue.IntegrityAlg == security.AlgIntegrity128NIA0 { 87 | fmt.Println("decode payload is ", payload) 88 | // remove header 89 | payload = payload[3:] 90 | 91 | if err = security.NASEncrypt(ue.CipheringAlg, ue.KnasEnc, ue.DLCount.Get(), security.Bearer3GPP, 92 | security.DirectionDownlink, payload); err != nil { 93 | return nil, err 94 | } 95 | 96 | err = msg.PlainNasDecode(&payload) 97 | return 98 | } else { 99 | if securityHeaderType == nas.SecurityHeaderTypeIntegrityProtectedWithNew5gNasSecurityContext || 100 | securityHeaderType == nas.SecurityHeaderTypeIntegrityProtectedAndCipheredWithNew5gNasSecurityContext { 101 | ue.DLCount.Set(0, 0) 102 | } 103 | 104 | securityHeader := payload[0:6] 105 | sequenceNumber := payload[6] 106 | receivedMac32 := securityHeader[2:] 107 | // remove security Header except for sequece Number 108 | payload = payload[6:] 109 | 110 | // Caculate ul count 111 | if ue.DLCount.SQN() > sequenceNumber { 112 | ue.DLCount.SetOverflow(ue.DLCount.Overflow() + 1) 113 | } 114 | ue.DLCount.SetSQN(sequenceNumber) 115 | 116 | if ue.IntegrityAlg != security.AlgIntegrity128NIA0 { 117 | mac32, errNas := security.NASMacCalculate(ue.IntegrityAlg, ue.KnasInt, ue.DLCount.Get(), security.Bearer3GPP, 118 | security.DirectionDownlink, payload) 119 | if errNas != nil { 120 | return nil, errNas 121 | } 122 | if !reflect.DeepEqual(mac32, receivedMac32) { 123 | fmt.Printf("NAS MAC verification failed(0x%x != 0x%x)", mac32, receivedMac32) 124 | } else { 125 | fmt.Printf("cmac value: 0x%x\n", mac32) 126 | } 127 | } 128 | 129 | // remove sequece Number 130 | payload = payload[1:] 131 | 132 | // TODO: Support for ue has nas connection in both accessType 133 | if err = security.NASEncrypt(ue.CipheringAlg, ue.KnasEnc, ue.DLCount.Get(), security.Bearer3GPP, 134 | security.DirectionUplink, payload); err != nil { 135 | return nil, err 136 | } 137 | } 138 | err = msg.PlainNasDecode(&payload) 139 | fmt.Println("err", err) 140 | return msg, err 141 | } 142 | -------------------------------------------------------------------------------- /ue_procedures/packet.go: -------------------------------------------------------------------------------- 1 | package ue_procedures 2 | 3 | import ( 4 | "free5gc/lib/nas" 5 | "free5gc/lib/nas/nasMessage" 6 | 7 | // Nausf_UEAU_Client "free5gc/lib/openapi/Nausf_UEAuthentication" 8 | "free5gc/lib/ngap" 9 | "free5gc/src/test/ngapTestpacket" 10 | // "free5gc/lib/openapi/models" 11 | ) 12 | 13 | func GetNGSetupRequest(gnbId []byte, bitlength uint64, name string) ([]byte, error) { 14 | message := ngapTestpacket.BuildNGSetupRequest() 15 | // GlobalRANNodeID 16 | ie := message.InitiatingMessage.Value.NGSetupRequest.ProtocolIEs.List[0] 17 | gnbID := ie.Value.GlobalRANNodeID.GlobalGNBID.GNBID.GNBID 18 | gnbID.Bytes = gnbId 19 | gnbID.BitLength = bitlength 20 | // RANNodeName 21 | ie = message.InitiatingMessage.Value.NGSetupRequest.ProtocolIEs.List[1] 22 | ie.Value.RANNodeName.Value = name 23 | 24 | return ngap.Encoder(message) 25 | } 26 | 27 | func GetInitialUEMessage(ranUeNgapID int64, nasPdu []byte, fiveGSTmsi string) ([]byte, error) { 28 | message := ngapTestpacket.BuildInitialUEMessage(ranUeNgapID, nasPdu, fiveGSTmsi) 29 | return ngap.Encoder(message) 30 | } 31 | 32 | func GetUplinkNASTransport(amfUeNgapID, ranUeNgapID int64, nasPdu []byte) ([]byte, error) { 33 | message := ngapTestpacket.BuildUplinkNasTransport(amfUeNgapID, ranUeNgapID, nasPdu) 34 | return ngap.Encoder(message) 35 | } 36 | 37 | func GetInitialContextSetupResponse(amfUeNgapID int64, ranUeNgapID int64) ([]byte, error) { 38 | message := ngapTestpacket.BuildInitialContextSetupResponseForRegistraionTest(amfUeNgapID, ranUeNgapID) 39 | 40 | return ngap.Encoder(message) 41 | } 42 | 43 | func GetInitialContextSetupResponseForServiceRequest( 44 | amfUeNgapID int64, ranUeNgapID int64, ipv4 string) ([]byte, error) { 45 | message := ngapTestpacket.BuildInitialContextSetupResponse(amfUeNgapID, ranUeNgapID, ipv4, nil) 46 | return ngap.Encoder(message) 47 | } 48 | 49 | func GetPDUSessionResourceSetupResponse(amfUeNgapID int64, ranUeNgapID int64, ipv4 string) ([]byte, error) { 50 | message := ngapTestpacket.BuildPDUSessionResourceSetupResponseForRegistrationTest(amfUeNgapID, ranUeNgapID, ipv4) 51 | return ngap.Encoder(message) 52 | } 53 | func EncodeNasPduWithSecurity(ue *UeRanContext, pdu []byte, securityHeaderType uint8, 54 | securityContextAvailable, newSecurityContext bool) ([]byte, error) { 55 | m := nas.NewMessage() 56 | err := m.PlainNasDecode(&pdu) 57 | if err != nil { 58 | return nil, err 59 | } 60 | m.SecurityHeader = nas.SecurityHeader{ 61 | ProtocolDiscriminator: nasMessage.Epd5GSMobilityManagementMessage, 62 | SecurityHeaderType: securityHeaderType, 63 | } 64 | return NASEncode(ue, m, securityContextAvailable, newSecurityContext) 65 | } 66 | 67 | func GetUEContextReleaseComplete(amfUeNgapID int64, ranUeNgapID int64, pduSessionIDList []int64) ([]byte, error) { 68 | message := ngapTestpacket.BuildUEContextReleaseComplete(amfUeNgapID, ranUeNgapID, pduSessionIDList) 69 | return ngap.Encoder(message) 70 | } 71 | 72 | func GetUEContextReleaseRequest(amfUeNgapID int64, ranUeNgapID int64, pduSessionIDList []int64) ([]byte, error) { 73 | message := ngapTestpacket.BuildUEContextReleaseRequest(amfUeNgapID, ranUeNgapID, pduSessionIDList) 74 | return ngap.Encoder(message) 75 | } 76 | 77 | func GetPDUSessionResourceReleaseResponse(amfUeNgapID int64, ranUeNgapID int64) ([]byte, error) { 78 | message := ngapTestpacket.BuildPDUSessionResourceReleaseResponseForReleaseTest(amfUeNgapID, ranUeNgapID) 79 | return ngap.Encoder(message) 80 | } 81 | func GetPathSwitchRequest(amfUeNgapID int64, ranUeNgapID int64) ([]byte, error) { 82 | message := ngapTestpacket.BuildPathSwitchRequest(amfUeNgapID, ranUeNgapID) 83 | message.InitiatingMessage.Value.PathSwitchRequest.ProtocolIEs.List = 84 | message.InitiatingMessage.Value.PathSwitchRequest.ProtocolIEs.List[0:5] 85 | return ngap.Encoder(message) 86 | } 87 | 88 | func GetHandoverRequired( 89 | amfUeNgapID int64, ranUeNgapID int64, targetGNBID []byte, targetCellID []byte) ([]byte, error) { 90 | message := ngapTestpacket.BuildHandoverRequired(amfUeNgapID, ranUeNgapID, targetGNBID, targetCellID) 91 | return ngap.Encoder(message) 92 | } 93 | 94 | func GetHandoverRequestAcknowledge(amfUeNgapID int64, ranUeNgapID int64) ([]byte, error) { 95 | message := ngapTestpacket.BuildHandoverRequestAcknowledge(amfUeNgapID, ranUeNgapID) 96 | return ngap.Encoder(message) 97 | } 98 | 99 | func GetHandoverNotify(amfUeNgapID int64, ranUeNgapID int64) ([]byte, error) { 100 | message := ngapTestpacket.BuildHandoverNotify(amfUeNgapID, ranUeNgapID) 101 | return ngap.Encoder(message) 102 | } 103 | 104 | func GetPDUSessionResourceSetupResponseForPaging(amfUeNgapID int64, ranUeNgapID int64, ipv4 string) ([]byte, error) { 105 | message := ngapTestpacket.BuildPDUSessionResourceSetupResponseForPaging(amfUeNgapID, ranUeNgapID, ipv4) 106 | return ngap.Encoder(message) 107 | } 108 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/utils/env_manager.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -ne 2 ]] || ([[ $1 != "up" ]] && [[ $1 != "down" ]]); then 4 | echo "Usage: $0 [up|down] [internet_iface]" 5 | exit 1 6 | fi 7 | 8 | HOSTNAMES=( 9 | "10.1.1.2 amf" 10 | "10.1.1.3 smf" 11 | "10.1.1.4 ausf" 12 | "10.1.1.5 nssf" 13 | "10.1.1.6 pcf" 14 | "10.1.1.7 udm" 15 | "10.1.1.8 udr" 16 | "10.1.1.9 upf" 17 | "10.1.1.11 db" 18 | "10.1.1.10 nrf" 19 | ) 20 | 21 | IFACE=$2 22 | 23 | if [[ $1 == "up" ]]; then 24 | echo "Creating network interfaces and namespaces..." 25 | # create network interfaces and add ip addresses 26 | # 5gc network (it's not needed but helps to organize/separate the networks) 27 | 28 | #to create bridge of core: br-5gc 29 | sudo ip link add br-5gc type bridge # bridge for core 30 | 31 | # ip address of components 32 | sudo ip addr add 10.1.1.2/24 dev br-5gc # amf 33 | sudo ip addr add 10.1.1.3/24 dev br-5gc # smf 34 | sudo ip addr add 10.1.1.4/24 dev br-5gc # ausf 35 | sudo ip addr add 10.1.1.5/24 dev br-5gc # nssf 36 | sudo ip addr add 10.1.1.6/24 dev br-5gc # pcf 37 | sudo ip addr add 10.1.1.7/24 dev br-5gc # udm 38 | sudo ip addr add 10.1.1.8/24 dev br-5gc # udr 39 | sudo ip addr add 10.1.1.9/24 dev br-5gc # upf 40 | sudo ip addr add 10.1.1.10/24 dev br-5gc # nrf 41 | sudo ip addr add 10.1.1.11/24 dev br-5gc # mongodb 42 | 43 | # to up bridge br-5gc 44 | sudo ip link set br-5gc up 45 | 46 | # Inteface added to handle N2 interface (it's not needed but helps to organize/separate the networks) 47 | 48 | # to create bridge to handle n2 interface 49 | sudo ip link add br-n2 type bridge 50 | 51 | # ip address of components at n2 interface 52 | sudo ip addr add 172.16.0.1/24 dev br-n2 53 | sudo ip addr add 172.16.0.2/24 dev br-n2 54 | 55 | # Setup network namespace for UPF 56 | sudo ip netns add UPFns 57 | 58 | sudo ip link add veth0 type veth peer name veth1 59 | sudo ip link set veth0 up 60 | sudo ip addr add 60.60.0.1 dev lo 61 | sudo ip addr add 10.200.200.1/24 dev veth0 62 | sudo ip addr add 10.200.200.2/24 dev veth0 63 | 64 | sudo ip link set veth1 netns UPFns 65 | sudo ip netns exec UPFns ip link set lo up 66 | sudo ip netns exec UPFns ip link set veth1 up 67 | sudo ip netns exec UPFns ip addr add 60.60.0.101 dev lo 68 | sudo ip netns exec UPFns ip addr add 10.200.200.101/24 dev veth1 69 | sudo ip netns exec UPFns ip addr add 10.200.200.102/24 dev veth1 70 | 71 | #veth2-veth3 beetween AP and N3IWF 72 | sudo ip link add dev veth2 type veth peer name veth3 73 | 74 | # veth2- ip address:192.168.127.1/24 75 | sudo ip addr add 192.168.127.1/24 dev veth2 76 | sudo ip link set veth2 up 77 | 78 | # veth3 in APns - ip address: 192.168.127.2/24 79 | sudo ip link set veth3 netns APns 80 | sudo ip netns exec APns ip addr add 192.168.127.2/24 dev veth3 81 | sudo ip netns exec APns ip link set veth3 up 82 | 83 | # static route for wlan1 84 | sudo ip netns exec UEns route add -net 192.168.127.0/24 gw 192.168.1.10 dev wlan1 85 | 86 | # static route 87 | sudo ip route add 192.168.1.0/24 via 192.168.127.2 dev veth2 88 | 89 | # settings for ipsec0 90 | sudo ip netns exec UEns ip link set lo up 91 | sudo ip netns exec UEns ip link add ipsec0 type vti local 192.168.1.1 remote 192.168.127.1 key 5 92 | sudo ip netns exec UEns ip link set ipsec0 up 93 | 94 | sudo ip link add name ipsec0 type vti local 192.168.127.1 remote 0.0.0.0 key 5 95 | sudo ip addr add 10.0.0.1/24 dev ipsec0 96 | sudo ip link set ipsec0 up 97 | 98 | sudo ip link add veth4 type veth peer name veth5 99 | sudo ip addr add 10.1.2.1/24 dev veth4 100 | sudo ip link set veth4 up 101 | 102 | sudo ip link set veth5 netns UPFns 103 | sudo ip netns exec UPFns ip addr add 10.1.2.2/24 dev veth5 104 | sudo ip netns exec UPFns ip link set veth5 up 105 | sudo ip netns exec UPFns ip route add default via 10.1.2.1 106 | 107 | sudo ip netns exec UPFns iptables -t nat -A POSTROUTING -o veth5 -j MASQUERADE 108 | sudo iptables -t nat -A POSTROUTING -s 10.1.2.2/24 -o ${IFACE} -j MASQUERADE 109 | sudo iptables -A FORWARD -i ${IFACE} -o veth4 -j ACCEPT 110 | sudo iptables -A FORWARD -o ${IFACE} -i veth4 -j ACCEPT 111 | 112 | echo "Network interfaces and namespaces created." 113 | 114 | elif [[ $1 == "down" ]]; then 115 | echo "Removing network interfaces and namespaces.." 116 | sudo ip link set br-5gc down 117 | sudo ip link delete br-5gc 118 | sudo ip link delete br-n2 119 | sudo ip xfrm policy flush 120 | sudo ip xfrm state flush 121 | sudo ip link del veth2 122 | sudo ip link del veth4 123 | sudo ip link del ipsec0 124 | sudo ip link del veth0 125 | sudo ip netns exec UEns ip link del ipsec0 126 | sudo ip netns del UEns 127 | sudo ip netns del UPFns 128 | sudo ip netns del APns 129 | 130 | sudo rm /dev/mqueue/* 131 | for host in "${HOSTNAMES[@]}"; do 132 | sudo sed -i "/$host/d" /etc/hosts 133 | done 134 | echo "Network interfaces and namespaces removed." 135 | fi 136 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/env_manager.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -ne 2 ]] || ([[ $1 != "up" ]] && [[ $1 != "down" ]]); then 4 | echo "Usage: $0 [up|down] [internet_iface]" 5 | exit 1 6 | fi 7 | 8 | HOSTNAMES=( 9 | "10.1.1.2 amf" 10 | "10.1.1.3 smf" 11 | "10.1.1.4 ausf" 12 | "10.1.1.5 nssf" 13 | "10.1.1.6 pcf" 14 | "10.1.1.7 udm" 15 | "10.1.1.8 udr" 16 | "10.1.1.9 upf" 17 | "10.1.1.11 db" 18 | "10.1.1.10 nrf" 19 | ) 20 | 21 | IFACE=$2 22 | 23 | if [[ $1 == "up" ]]; then 24 | echo "Creating network interfaces and namespaces..." 25 | # create network interfaces and add ip addresses 26 | # 5gc network (it's not needed but helps to organize/separate the networks) 27 | 28 | #to create bridge of core: br-5gc 29 | sudo ip link add br-5gc type bridge # bridge for core 30 | 31 | # ip address of components 32 | sudo ip addr add 10.1.1.2/24 dev br-5gc # amf 33 | sudo ip addr add 10.1.1.3/24 dev br-5gc # smf 34 | sudo ip addr add 10.1.1.4/24 dev br-5gc # ausf 35 | sudo ip addr add 10.1.1.5/24 dev br-5gc # nssf 36 | sudo ip addr add 10.1.1.6/24 dev br-5gc # pcf 37 | sudo ip addr add 10.1.1.7/24 dev br-5gc # udm 38 | sudo ip addr add 10.1.1.8/24 dev br-5gc # udr 39 | sudo ip addr add 10.1.1.9/24 dev br-5gc # upf 40 | sudo ip addr add 10.1.1.10/24 dev br-5gc # nrf 41 | sudo ip addr add 10.1.1.11/24 dev br-5gc # mongodb 42 | 43 | # to up bridge br-5gc 44 | sudo ip link set br-5gc up 45 | 46 | # Inteface added to handle N2 interface (it's not needed but helps to organize/separate the networks) 47 | 48 | # to create bridge to handle n2 interface 49 | sudo ip link add br-n2 type bridge 50 | 51 | # ip address of components at n2 interface 52 | sudo ip addr add 172.16.0.1/24 dev br-n2 53 | sudo ip addr add 172.16.0.2/24 dev br-n2 54 | 55 | # Setup network namespace for UPF 56 | sudo ip netns add UPFns 57 | 58 | sudo ip link add veth0 type veth peer name veth1 59 | sudo ip link set veth0 up 60 | sudo ip addr add 60.60.0.1 dev lo 61 | sudo ip addr add 10.200.200.1/24 dev veth0 62 | sudo ip addr add 10.200.200.2/24 dev veth0 63 | 64 | sudo ip link set veth1 netns UPFns 65 | sudo ip netns exec UPFns ip link set lo up 66 | sudo ip netns exec UPFns ip link set veth1 up 67 | sudo ip netns exec UPFns ip addr add 60.60.0.101 dev lo 68 | sudo ip netns exec UPFns ip addr add 10.200.200.101/24 dev veth1 69 | sudo ip netns exec UPFns ip addr add 10.200.200.102/24 dev veth1 70 | 71 | #veth2-veth3 beetween AP and N3IWF 72 | sudo ip link add dev veth2 type veth peer name veth3 73 | 74 | # veth2- ip address:192.168.127.1/24 75 | sudo ip addr add 192.168.127.1/24 dev veth2 76 | sudo ip link set veth2 up 77 | 78 | # veth3 in APns - ip address: 192.168.127.2/24 79 | sudo ip link set veth3 netns APns 80 | sudo ip netns exec APns ip addr add 192.168.127.2/24 dev veth3 81 | sudo ip netns exec APns ip link set veth3 up 82 | 83 | # default route for wlan1 84 | #sudo ip netns exec UEns route add default gw 192.168.1.10 wlan1 #wlan 1 - interface cliente 85 | sudo ip netns exec UEns route add -net 192.168.127.0/24 gw 192.168.1.10 dev wlan1 86 | 87 | # static route 88 | sudo ip route add 192.168.1.0/24 via 192.168.127.2 dev veth2 89 | 90 | # settings for ipsec0 91 | sudo ip netns exec UEns ip link set lo up 92 | sudo ip netns exec UEns ip link add ipsec0 type vti local 192.168.1.1 remote 192.168.127.1 key 5 93 | sudo ip netns exec UEns ip link set ipsec0 up 94 | 95 | sudo ip link add name ipsec0 type vti local 192.168.127.1 remote 0.0.0.0 key 5 96 | sudo ip addr add 10.0.0.1/24 dev ipsec0 97 | sudo ip link set ipsec0 up 98 | 99 | sudo ip link add veth4 type veth peer name veth5 100 | sudo ip addr add 10.1.2.1/24 dev veth4 101 | sudo ip link set veth4 up 102 | 103 | sudo ip link set veth5 netns UPFns 104 | sudo ip netns exec UPFns ip addr add 10.1.2.2/24 dev veth5 105 | sudo ip netns exec UPFns ip link set veth5 up 106 | sudo ip netns exec UPFns ip route add default via 10.1.2.1 107 | 108 | sudo ip netns exec UPFns iptables -t nat -A POSTROUTING -o veth5 -j MASQUERADE 109 | sudo iptables -t nat -A POSTROUTING -s 10.1.2.2/24 -o ${IFACE} -j MASQUERADE 110 | sudo iptables -A FORWARD -i ${IFACE} -o veth4 -j ACCEPT 111 | sudo iptables -A FORWARD -o ${IFACE} -i veth4 -j ACCEPT 112 | 113 | echo "Network interfaces and namespaces created." 114 | 115 | elif [[ $1 == "down" ]]; then 116 | echo "Removing network interfaces and namespaces.." 117 | sudo ip link set br-5gc down 118 | sudo ip link delete br-5gc 119 | sudo ip link delete br-n2 120 | sudo ip xfrm policy flush 121 | sudo ip xfrm state flush 122 | sudo ip link del veth2 123 | sudo ip link del veth4 124 | sudo ip link del ipsec0 125 | sudo ip link del veth0 126 | sudo ip netns exec UEns ip link del ipsec0 127 | sudo ip netns del UEns 128 | sudo ip netns del UPFns 129 | sudo ip netns del APns 130 | 131 | sudo rm /dev/mqueue/* 132 | for host in "${HOSTNAMES[@]}"; do 133 | sudo sed -i "/$host/d" /etc/hosts 134 | done 135 | echo "Network interfaces and namespaces removed." 136 | fi 137 | -------------------------------------------------------------------------------- /ue_context/context.go: -------------------------------------------------------------------------------- 1 | package ue_context 2 | 3 | import ( 4 | "crypto/rsa" 5 | "free5gc/lib/CommonConsumerTestData/UDM/TestGenAuthData" 6 | "free5gc/lib/openapi/models" 7 | "free5gc/lib/ngap/ngapType" 8 | "free5gc/src/ue/logger" 9 | "free5gc/src/ue/version" 10 | //"free5gc/src/ue/ue_procedures" 11 | "github.com/sirupsen/logrus" 12 | "github.com/vishvananda/netlink" 13 | "golang.org/x/net/ipv4" 14 | "net" 15 | ) 16 | 17 | var ueContext = UEContext{} 18 | var contextLog *logrus.Entry 19 | 20 | func init() { 21 | // init log 22 | contextLog = logger.ContextLog 23 | 24 | // init context 25 | UE_Self().UeId = "1" 26 | UE_Self().CmState = models.CmState_IDLE 27 | UE_Self().RmState = models.RmState_DEREGISTERED 28 | // N3IWF FQDN 29 | UE_Self().FQDN = "" 30 | // Network interface mark for xfrm 31 | UE_Self().Mark = 5 32 | } 33 | 34 | type OpcType string 35 | 36 | // List of AuthMethod 37 | const ( 38 | OP OpcType = "5G_AKA" 39 | OPc OpcType = "EAP_AKA_PRIME" 40 | ) 41 | 42 | type UEContext struct { 43 | Version string 44 | UeId string 45 | HttpIPv4Address string 46 | HttpIPv4Port int 47 | 48 | GUAMI *ngapType.GUAMI // connected AMF global identifier TODO: Discutir 49 | CmState models.CmState // usada no gerenciamento de conexão (interface de sinalização N1 entre UE e AMF) [IDLE|CONNECTED] 50 | RmState models.RmState // usado no gerenciamento de registro do UE junto ao núcleo [REGISTERED|DEREGISTERED] 51 | 52 | IKESA IKESecurityAssociation 53 | ChildSA ChildSecurityAssociation 54 | 55 | // Security and Authentication Data 56 | //UeRanContext *ue_procedures.UeRanContext 57 | 58 | // N3IWF FQDN 59 | FQDN string 60 | 61 | // security data 62 | CertificateAuthority []byte 63 | UECertificate []byte 64 | UEPrivateKey *rsa.PrivateKey 65 | 66 | // Network interface mark for xfrm 67 | Mark uint32 68 | 69 | // UE local address 70 | IKEBindAddress string 71 | IPSecGatewayAddress string 72 | GREBindAddress string 73 | TCPPort uint16 74 | TCPConnection *net.TCPConn 75 | 76 | // Tunnels 77 | GRETunnel netlink.Link 78 | 79 | // N3IWF N1 interface raw socket 80 | N1RawSocket *ipv4.RawConn 81 | 82 | // UDP 83 | UDPSocketAddr *net.UDPAddr 84 | 85 | // subscriber data 86 | SUPIorSUCI string 87 | 88 | UeAuthenticationCtx *models.UeAuthenticationCtx 89 | 90 | // TODO: #LABORA Include Network Slicing Selection Information?? 91 | SNssai *models.Snssai 92 | // TODO: #LABORA Include UE Configuration Information?? (Used in USIM) 93 | 94 | N3IWFIpAddress string 95 | 96 | // data for registration procedure 97 | PermanentKeyValue string 98 | AuthenticationMethod models.AuthMethod 99 | OpcType string 100 | Opc string 101 | } 102 | 103 | func InitUeContext(){ 104 | // TODO: #LABORA implement context initiation tasks here 105 | // inicializa com valores default e tudo desregistrado 106 | ueContext.Version = version.GetVersion() 107 | } 108 | 109 | // Reset UE Context 110 | func (context *UEContext) Reset() { 111 | context.UeId = "" 112 | // TODO: #LABORA implement context reset here 113 | } 114 | 115 | // Create new UE context 116 | func UE_Self() *UEContext { 117 | return &ueContext 118 | } 119 | 120 | func (context *UEContext) SetupUDPSocket(log *logrus.Entry) *net.UDPConn { 121 | // TODO: #LABORA Add check to verify if socket (udp, port and ip) is already being used 122 | bindAddr := context.IKEBindAddress + ":500" 123 | udpAddr, err := net.ResolveUDPAddr("udp", bindAddr) 124 | if err != nil { 125 | log.Fatal("Resolve UDP address failed") 126 | } 127 | udpListener, err := net.ListenUDP("udp", udpAddr) 128 | if err != nil { 129 | log.Fatalf("Listen UDP socket failed: %+v", err) 130 | } 131 | return udpListener 132 | } 133 | 134 | func (context *UEContext) GetAuthSubscription() (authSubs models.AuthenticationSubscription) { 135 | authSubs.PermanentKey = &models.PermanentKey{ 136 | PermanentKeyValue: context.PermanentKeyValue, 137 | } 138 | authSubs.Opc = &models.Opc{ 139 | OpcValue: context.Opc, 140 | } 141 | authSubs.Milenage = &models.Milenage{ 142 | Op: &models.Op{ 143 | OpValue: TestGenAuthData.MilenageTestSet19.OP, 144 | }, 145 | } 146 | authSubs.AuthenticationManagementField = "8000" 147 | 148 | authSubs.SequenceNumber = TestGenAuthData.MilenageTestSet19.SQN 149 | authSubs.AuthenticationMethod = context.AuthenticationMethod 150 | return 151 | } 152 | 153 | // temporário 154 | func (context *UEContext) GetAuthSubscription2() (authSubs models.AuthenticationSubscription) { 155 | authSubs.PermanentKey = &models.PermanentKey{ 156 | PermanentKeyValue: TestGenAuthData.MilenageTestSet19.K, 157 | } 158 | authSubs.Opc = &models.Opc{ 159 | OpcValue: TestGenAuthData.MilenageTestSet19.OPC, 160 | } 161 | authSubs.Milenage = &models.Milenage{ 162 | Op: &models.Op{ 163 | OpValue: TestGenAuthData.MilenageTestSet19.OP, 164 | }, 165 | } 166 | authSubs.AuthenticationManagementField = "8000" 167 | 168 | authSubs.SequenceNumber = TestGenAuthData.MilenageTestSet19.SQN 169 | authSubs.AuthenticationMethod = models.AuthMethod__5_G_AKA 170 | return 171 | } -------------------------------------------------------------------------------- /ue_ike/udp_server/server.go: -------------------------------------------------------------------------------- 1 | package udp_server 2 | 3 | import ( 4 | "net" 5 | "sync" 6 | 7 | "free5gc/src/n3iwf/logger" 8 | n3iwf_context "free5gc/src/n3iwf/context" 9 | "free5gc/src/ue/n3iwf_handler/n3iwf_message" 10 | 11 | "github.com/sirupsen/logrus" 12 | ) 13 | 14 | // IKE daemon listen on UDP 500 and 4500 15 | const ( 16 | maxQueueSize int = 100000 17 | defaultIKEPort500 int = 500 18 | defaultIKEPort4500 int = 4500 19 | ) 20 | 21 | const ( 22 | ChannelIDForPort500 = 1 23 | ChannelIDForPort4500 = 2 24 | ) 25 | 26 | type sendParameters struct { 27 | DstAddr *net.UDPAddr 28 | Length int 29 | Payload []byte 30 | } 31 | 32 | var ikeLog *logrus.Entry 33 | 34 | var sendChanToPort500 chan sendParameters // Chennel ID 1 (channelIDForPort500) 35 | var mtxForChanPort500 sync.Mutex 36 | 37 | var sendChanToPort4500 chan sendParameters // Chennel ID 2 (channelIDForPort4500) 38 | var mtxForChanPort4500 sync.Mutex 39 | 40 | func init() { 41 | // init logger 42 | ikeLog = logger.IKELog 43 | // init channel 44 | sendChanToPort500 = make(chan sendParameters, maxQueueSize) 45 | sendChanToPort4500 = make(chan sendParameters, maxQueueSize) 46 | } 47 | 48 | func Run() { 49 | 50 | listenAddrPort500 := new(net.UDPAddr) 51 | listenAddrPort4500 := new(net.UDPAddr) 52 | 53 | configBindAddr(listenAddrPort500, listenAddrPort4500) 54 | 55 | listenerPort500, err := net.ListenUDP("udp", listenAddrPort500) 56 | if err != nil { 57 | ikeLog.Errorf("[IKE] Listen on UDP socket failed: %+v", err) 58 | return 59 | } 60 | 61 | go reader(ChannelIDForPort500, listenerPort500) 62 | go sender(ChannelIDForPort500, listenerPort500) 63 | 64 | listenerPort4500, err := net.ListenUDP("udp", listenAddrPort4500) 65 | if err != nil { 66 | ikeLog.Errorf("[IKE] Listen on UDP socket failed: %+v", err) 67 | return 68 | } 69 | 70 | go reader(ChannelIDForPort4500, listenerPort4500) 71 | go sender(ChannelIDForPort4500, listenerPort4500) 72 | 73 | } 74 | 75 | func configBindAddr(listenAddrPort500 *net.UDPAddr, listenAddrPort4500 *net.UDPAddr) { 76 | n3iwfSelf := n3iwf_context.N3IWFSelf() 77 | 78 | // Configure UDP port 79 | listenAddrPort500.Port, listenAddrPort4500.Port = defaultIKEPort500, defaultIKEPort4500 80 | 81 | // Configure IP address 82 | ip := net.ParseIP(n3iwfSelf.IKEBindAddress) 83 | if ip != nil { 84 | ikeLog.Tracef("[IKE] Binding %v", ip) 85 | listenAddrPort500.IP, listenAddrPort4500.IP = ip, ip 86 | } else { 87 | ikeLog.Warn("[IKE] Invalid IKE bind IP address, binding 0.0.0.0") 88 | listenAddrPort500.IP, listenAddrPort4500.IP = net.IPv4zero, net.IPv4zero 89 | } 90 | } 91 | 92 | func Send(sendInfo *n3iwf_message.UDPSendInfoGroup, msg []byte) { 93 | if sendInfo.ChannelID == ChannelIDForPort500 { 94 | 95 | sendData := sendParameters{ 96 | DstAddr: sendInfo.Addr, 97 | Length: len(msg), 98 | Payload: msg, 99 | } 100 | 101 | mtxForChanPort500.Lock() 102 | sendChanToPort500 <- sendData 103 | mtxForChanPort500.Unlock() 104 | 105 | } else if sendInfo.ChannelID == ChannelIDForPort4500 { 106 | 107 | sendData := sendParameters{ 108 | DstAddr: sendInfo.Addr, 109 | Length: len(msg), 110 | Payload: msg, 111 | } 112 | 113 | mtxForChanPort4500.Lock() 114 | sendChanToPort4500 <- sendData 115 | mtxForChanPort4500.Unlock() 116 | 117 | } else { 118 | ikeLog.Error("[IKE] Send(): Invalid channel ID") 119 | } 120 | } 121 | 122 | func sender(channelID int, conn *net.UDPConn) { 123 | if channelID == ChannelIDForPort500 { 124 | for { 125 | 126 | sendData := <-sendChanToPort500 127 | 128 | n, err := conn.WriteToUDP(sendData.Payload, sendData.DstAddr) 129 | if err != nil { 130 | ikeLog.Errorf("[IKE] Sending data through UDP failed: %+v", err) 131 | } 132 | if n != sendData.Length { 133 | ikeLog.Warn("[IKE] There is data not being sent") 134 | } 135 | 136 | } 137 | } else if channelID == ChannelIDForPort4500 { 138 | for { 139 | 140 | sendData := <-sendChanToPort4500 141 | 142 | n, err := conn.WriteToUDP(sendData.Payload, sendData.DstAddr) 143 | if err != nil { 144 | ikeLog.Errorf("[IKE] Sending data through UDP failed: %+v", err) 145 | } 146 | if n != sendData.Length { 147 | ikeLog.Warn("[IKE] There is data not being sent") 148 | } 149 | 150 | } 151 | } else { 152 | ikeLog.Error("[IKE] sender(): Invalid channel ID") 153 | } 154 | } 155 | 156 | func reader(channelID int, conn *net.UDPConn) { 157 | 158 | if channelID > ChannelIDForPort4500 { 159 | ikeLog.Error("[IKE] Channel ID out of range") 160 | return 161 | } 162 | 163 | data := make([]byte, 65535) 164 | 165 | for { 166 | 167 | n, remoteAddr, err := conn.ReadFromUDP(data) 168 | if err != nil { 169 | ikeLog.Errorf("[IKE] Read from UDP failed: %+v", err) 170 | continue 171 | } 172 | 173 | sendInfo := &n3iwf_message.UDPSendInfoGroup{ 174 | ChannelID: channelID, 175 | Addr: remoteAddr, 176 | } 177 | 178 | msg := n3iwf_message.HandlerMessage{ 179 | Event: n3iwf_message.EventN1UDPMessage, 180 | UDPSendInfo: sendInfo, 181 | Value: data[:n], 182 | } 183 | 184 | n3iwf_message.SendMessage(msg) 185 | 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /ue_service/ue_init.go: -------------------------------------------------------------------------------- 1 | package ue_service 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "free5gc/lib/http2_util" 7 | "free5gc/lib/path_util" 8 | "free5gc/src/ue/factory" 9 | "free5gc/src/ue/logger" 10 | "free5gc/src/ue/rest_api" 11 | "free5gc/src/ue/ue_context" 12 | "free5gc/src/ue/ue_handler" 13 | "free5gc/src/ue/ue_util" 14 | "github.com/gin-contrib/cors" 15 | "github.com/gin-gonic/gin" 16 | "github.com/sirupsen/logrus" 17 | "github.com/urfave/cli" 18 | "os" 19 | "os/exec" 20 | "os/signal" 21 | "sync" 22 | "syscall" 23 | ) 24 | 25 | type UE struct{} 26 | 27 | type ( 28 | Config struct { 29 | uecfg string 30 | ue_http_addr string 31 | ue_http_port string 32 | } 33 | ) 34 | 35 | var config Config 36 | 37 | var ueCLi = []cli.Flag{ 38 | cli.StringFlag{ 39 | Name: "free5gccfg", 40 | Usage: "common config file", 41 | }, 42 | cli.StringFlag{ 43 | Name: "uecfg", 44 | Usage: "ue config file", 45 | }, 46 | cli.StringFlag{ 47 | Name: "ue_http_addr", 48 | Usage: "ue http binding address", 49 | }, 50 | cli.StringFlag{ 51 | Name: "ue_http_port", 52 | Usage: "ue http binding port", 53 | }, 54 | 55 | } 56 | 57 | var initLog *logrus.Entry 58 | 59 | func init() { 60 | initLog = logger.InitLog 61 | } 62 | 63 | func (*UE) GetCliCmd() (flags []cli.Flag) { 64 | return ueCLi 65 | } 66 | 67 | func (*UE) Initialize(c *cli.Context) { 68 | 69 | config = Config{ 70 | uecfg: c.String("uecfg"), 71 | ue_http_addr: c.String("ue_http_addr"), 72 | ue_http_port: c.String("ue_http_port"), 73 | } 74 | 75 | fmt.Println(c.Args()) 76 | 77 | if config.uecfg != "" { 78 | factory.InitConfigFactory(path_util.Gofree5gcPath(config.uecfg)) 79 | } else { 80 | factory.InitConfigFactory(ue_util.DefaultUeConfigPath) 81 | } 82 | 83 | // override uecfg.conf file is command line arg is informed 84 | if config.ue_http_addr != "" { 85 | factory.UeConfig.Configuration.UEConfiguration.HttpIPv4Address = config.ue_http_addr 86 | } 87 | if config.ue_http_port != "" { 88 | factory.UeConfig.Configuration.UEConfiguration.HttpIPv4Port = config.ue_http_port 89 | } 90 | 91 | // TODO: get these two variables from ue-iot-non3gpp config file 92 | DebugLevel:= "info" 93 | ReportCaller := true 94 | 95 | initLog.Traceln("UE debug level(string):", DebugLevel) 96 | if DebugLevel != "" { 97 | initLog.Infoln("UE debug level(string):", DebugLevel) 98 | level, err := logrus.ParseLevel(DebugLevel) 99 | if err == nil { 100 | logger.SetLogLevel(level) 101 | } 102 | } 103 | 104 | logger.SetReportCaller(ReportCaller) 105 | 106 | } 107 | 108 | func (ue *UE) FilterCli(c *cli.Context) (args []string) { 109 | for _, flag := range ue.GetCliCmd() { 110 | name := flag.GetName() 111 | value := fmt.Sprint(c.Generic(name)) 112 | if value == "" { 113 | continue 114 | } 115 | 116 | args = append(args, "--"+name, value) 117 | } 118 | return args 119 | } 120 | 121 | func (ue *UE) Start() { 122 | initLog.Infoln("Server started") 123 | 124 | router := gin.Default() 125 | router.Use(cors.New(cors.Config{ 126 | AllowMethods: []string{"GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE"}, 127 | AllowHeaders: []string{"Origin", "Content-Length", "Content-Type", "User-Agent", "Referrer", "Host", "Token", "X-Requested-With"}, 128 | ExposeHeaders: []string{"Content-Length"}, 129 | AllowCredentials: true, 130 | AllowAllOrigins: true, 131 | MaxAge: 86400, 132 | })) 133 | 134 | // Add endpoints supported by the UE 135 | rest_api.AddService(router) 136 | 137 | //self := ue_context.UE_Self() 138 | ue_context.InitUeContext() 139 | 140 | go ue_handler.Handle() 141 | 142 | addr := fmt.Sprintf("%s:%s", 143 | factory.UeConfig.Configuration.UEConfiguration.HttpIPv4Address, 144 | factory.UeConfig.Configuration.UEConfiguration.HttpIPv4Port) 145 | 146 | // handle terminate signal 147 | signalChannel := make(chan os.Signal, 1) 148 | signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM) 149 | go func() { 150 | <-signalChannel 151 | ue.Terminate() 152 | os.Exit(0) 153 | }() 154 | 155 | initLog.Infoln(addr) 156 | server, err := http2_util.NewServer(addr, ue_util.UeLogPath, router) 157 | if err == nil && server != nil { 158 | //initLog.Infoln(server.ListenAndServeTLS(ue_util.UePemPath, ue_util.UeKeyPath)) 159 | initLog.Infoln(server.ListenAndServe()) 160 | } else { 161 | initLog.Errorf("Initialize http2 server failed: %+v", err) 162 | } 163 | } 164 | 165 | func (ue *UE) Exec(c *cli.Context) error { 166 | 167 | initLog.Traceln("args:", c.String("uecfg")) 168 | args := ue.FilterCli(c) 169 | initLog.Traceln("filter: ", args) 170 | command := exec.Command("./ue", args...) 171 | 172 | stdout, err := command.StdoutPipe() 173 | if err != nil { 174 | initLog.Fatalln(err) 175 | } 176 | wg := sync.WaitGroup{} 177 | wg.Add(3) 178 | go func() { 179 | in := bufio.NewScanner(stdout) 180 | for in.Scan() { 181 | fmt.Println(in.Text()) 182 | } 183 | wg.Done() 184 | }() 185 | 186 | stderr, err := command.StderrPipe() 187 | if err != nil { 188 | initLog.Fatalln(err) 189 | } 190 | go func() { 191 | in := bufio.NewScanner(stderr) 192 | for in.Scan() { 193 | fmt.Println(in.Text()) 194 | } 195 | wg.Done() 196 | }() 197 | 198 | go func() { 199 | if err := command.Start(); err != nil { 200 | initLog.Errorf("UE Start error: %v", err) 201 | } 202 | wg.Done() 203 | }() 204 | 205 | wg.Wait() 206 | 207 | return err 208 | } 209 | 210 | func (ue *UE) Terminate() { 211 | logger.InitLog.Infof("Terminating UE...") 212 | //ueSelf := ue_context.UE_Self() 213 | // clean resources, removing tunnels and interfaces, send deregistration message if registered 214 | logger.InitLog.Infof("UE terminated") 215 | } 216 | -------------------------------------------------------------------------------- /ue_ike/ike_handler/xfrm.go: -------------------------------------------------------------------------------- 1 | package ike_handler 2 | 3 | import ( 4 | "errors" 5 | n3iwf_context "free5gc/src/n3iwf/context" 6 | ike_message "free5gc/src/n3iwf/ike/message" 7 | 8 | "github.com/vishvananda/netlink" 9 | ) 10 | 11 | type XFRMEncryptionAlgorithmType uint16 12 | 13 | func (xfrmEncryptionAlgorithmType XFRMEncryptionAlgorithmType) String() string { 14 | switch xfrmEncryptionAlgorithmType { 15 | case ike_message.ENCR_DES: 16 | return "cbc(des)" 17 | case ike_message.ENCR_3DES: 18 | return "cbc(des3_ede)" 19 | case ike_message.ENCR_CAST: 20 | return "cbc(cast5)" 21 | case ike_message.ENCR_BLOWFISH: 22 | return "cbc(blowfish)" 23 | case ike_message.ENCR_NULL: 24 | return "ecb(cipher_null)" 25 | case ike_message.ENCR_AES_CBC: 26 | return "cbc(aes)" 27 | case ike_message.ENCR_AES_CTR: 28 | return "rfc3686(ctr(aes))" 29 | default: 30 | return "" 31 | } 32 | } 33 | 34 | type XFRMIntegrityAlgorithmType uint16 35 | 36 | func (xfrmIntegrityAlgorithmType XFRMIntegrityAlgorithmType) String() string { 37 | switch xfrmIntegrityAlgorithmType { 38 | case ike_message.AUTH_HMAC_MD5_96: 39 | return "hmac(md5)" 40 | case ike_message.AUTH_HMAC_SHA1_96: 41 | return "hmac(sha1)" 42 | case ike_message.AUTH_AES_XCBC_96: 43 | return "xcbc(aes)" 44 | default: 45 | return "" 46 | } 47 | } 48 | 49 | func ApplyXFRMRule(n3iwf_is_initiator bool, childSecurityAssociation *n3iwf_context.ChildSecurityAssociation) error { 50 | N3IWFSelf := n3iwf_context.N3IWFSelf() 51 | 52 | // Build XFRM information data structure for incoming traffic. 53 | 54 | // Mark 55 | mark := &netlink.XfrmMark{ 56 | Value: N3IWFSelf.Mark, 57 | } 58 | 59 | // Direction: {private_network} -> this_server 60 | // State 61 | var xfrmEncryptionAlgorithm, xfrmIntegrityAlgorithm *netlink.XfrmStateAlgo 62 | if n3iwf_is_initiator { 63 | xfrmEncryptionAlgorithm = &netlink.XfrmStateAlgo{ 64 | Name: XFRMEncryptionAlgorithmType(childSecurityAssociation.EncryptionAlgorithm).String(), 65 | Key: childSecurityAssociation.ResponderToInitiatorEncryptionKey, 66 | } 67 | if childSecurityAssociation.IntegrityAlgorithm != 0 { 68 | xfrmIntegrityAlgorithm = &netlink.XfrmStateAlgo{ 69 | Name: XFRMIntegrityAlgorithmType(childSecurityAssociation.IntegrityAlgorithm).String(), 70 | Key: childSecurityAssociation.ResponderToInitiatorIntegrityKey, 71 | } 72 | } 73 | } else { 74 | xfrmEncryptionAlgorithm = &netlink.XfrmStateAlgo{ 75 | Name: XFRMEncryptionAlgorithmType(childSecurityAssociation.EncryptionAlgorithm).String(), 76 | Key: childSecurityAssociation.InitiatorToResponderEncryptionKey, 77 | } 78 | if childSecurityAssociation.IntegrityAlgorithm != 0 { 79 | xfrmIntegrityAlgorithm = &netlink.XfrmStateAlgo{ 80 | Name: XFRMIntegrityAlgorithmType(childSecurityAssociation.IntegrityAlgorithm).String(), 81 | Key: childSecurityAssociation.InitiatorToResponderIntegrityKey, 82 | } 83 | } 84 | } 85 | 86 | xfrmState := new(netlink.XfrmState) 87 | 88 | xfrmState.Src = childSecurityAssociation.PeerPublicIPAddr 89 | xfrmState.Dst = childSecurityAssociation.LocalPublicIPAddr 90 | xfrmState.Proto = netlink.XFRM_PROTO_ESP 91 | xfrmState.Mode = netlink.XFRM_MODE_TUNNEL 92 | xfrmState.Spi = int(childSecurityAssociation.SPI) 93 | xfrmState.Mark = mark 94 | xfrmState.Auth = xfrmIntegrityAlgorithm 95 | xfrmState.Crypt = xfrmEncryptionAlgorithm 96 | xfrmState.ESN = childSecurityAssociation.ESN 97 | 98 | // Commit xfrm state to netlink 99 | var err error 100 | if err = netlink.XfrmStateAdd(xfrmState); err != nil { 101 | ikeLog.Errorf("[IKE] Set XFRM rules failed: %+v", err) 102 | return errors.New("Set XFRM state rule failed") 103 | } 104 | 105 | // Policy 106 | xfrmPolicyTemplate := netlink.XfrmPolicyTmpl{ 107 | Src: xfrmState.Src, 108 | Dst: xfrmState.Dst, 109 | Proto: xfrmState.Proto, 110 | Mode: xfrmState.Mode, 111 | Spi: xfrmState.Spi, 112 | } 113 | 114 | xfrmPolicy := new(netlink.XfrmPolicy) 115 | 116 | xfrmPolicy.Src = &childSecurityAssociation.TrafficSelectorRemote 117 | xfrmPolicy.Dst = &childSecurityAssociation.TrafficSelectorLocal 118 | xfrmPolicy.Proto = netlink.Proto(childSecurityAssociation.SelectedIPProtocol) 119 | xfrmPolicy.Dir = netlink.XFRM_DIR_IN 120 | xfrmPolicy.Mark = mark 121 | xfrmPolicy.Tmpls = []netlink.XfrmPolicyTmpl{ 122 | xfrmPolicyTemplate, 123 | } 124 | 125 | // Commit xfrm policy to netlink 126 | if err = netlink.XfrmPolicyAdd(xfrmPolicy); err != nil { 127 | ikeLog.Errorf("[IKE] Set XFRM rules failed: %+v", err) 128 | return errors.New("Set XFRM policy rule failed") 129 | } 130 | 131 | // Direction: this_server -> {private_network} 132 | // State 133 | if n3iwf_is_initiator { 134 | xfrmEncryptionAlgorithm.Key = childSecurityAssociation.InitiatorToResponderEncryptionKey 135 | if childSecurityAssociation.IntegrityAlgorithm != 0 { 136 | xfrmIntegrityAlgorithm.Key = childSecurityAssociation.InitiatorToResponderIntegrityKey 137 | } 138 | } else { 139 | xfrmEncryptionAlgorithm.Key = childSecurityAssociation.ResponderToInitiatorEncryptionKey 140 | if childSecurityAssociation.IntegrityAlgorithm != 0 { 141 | xfrmIntegrityAlgorithm.Key = childSecurityAssociation.ResponderToInitiatorIntegrityKey 142 | } 143 | } 144 | 145 | xfrmState.Src, xfrmState.Dst = xfrmState.Dst, xfrmState.Src 146 | 147 | // Commit xfrm state to netlink 148 | if err = netlink.XfrmStateAdd(xfrmState); err != nil { 149 | ikeLog.Errorf("[IKE] Set XFRM rules failed: %+v", err) 150 | return errors.New("Set XFRM state rule failed") 151 | } 152 | 153 | // Policy 154 | xfrmPolicyTemplate.Src, xfrmPolicyTemplate.Dst = xfrmPolicyTemplate.Dst, xfrmPolicyTemplate.Src 155 | 156 | xfrmPolicy.Src, xfrmPolicy.Dst = xfrmPolicy.Dst, xfrmPolicy.Src 157 | xfrmPolicy.Dir = netlink.XFRM_DIR_OUT 158 | xfrmPolicy.Tmpls = []netlink.XfrmPolicyTmpl{ 159 | xfrmPolicyTemplate, 160 | } 161 | 162 | // Commit xfrm policy to netlink 163 | if err = netlink.XfrmPolicyAdd(xfrmPolicy); err != nil { 164 | ikeLog.Errorf("[IKE] Set XFRM rules failed: %+v", err) 165 | return errors.New("Set XFRM policy rule failed") 166 | } 167 | 168 | return nil 169 | } 170 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/utils/add_test_ue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # run webconsole 4 | #../../../bin/webconsole & 5 | #WC_PID=$! 6 | 7 | 8 | webconsole_addr=${webconsole_addr:-"127.0.0.1"} 9 | webconsole_port=${webconsole_port:-"5000"} 10 | scheme=${scheme:-"http"} 11 | auth_method=${auth_method:-"5G_AKA"} 12 | supi_or_suci=${supi_or_suci:-"2089300007487"} 13 | k=${k:-"5122250214c33e723a5dd523fc145fc0"} 14 | opc_type=${opc_type:-"OP"} 15 | opc=${opc:-"c9e8763286b5b9ffbdf56e1297d0887b"} 16 | plmnId=${plmnId:-"20893"} 17 | 18 | while [ $# -gt 0 ]; do 19 | if [[ $1 == *"--"* ]]; then 20 | param="${1/--/}" 21 | declare $param="$2" 22 | fi 23 | shift 24 | done 25 | 26 | # add test ue 27 | curl --insecure --location --request POST "$scheme://$webconsole_addr:$webconsole_port/api/subscriber/imsi-$supi_or_suci/$plmnId" \ 28 | --header 'Content-Type: application/json' \ 29 | --data-raw '{ 30 | "plmnID": "20893", 31 | "ueId": "imsi-2089300007487", 32 | "AuthenticationSubscription": { 33 | "authenticationManagementField": "8000", 34 | "authenticationMethod": "5G_AKA", 35 | "milenage": { 36 | "op": { 37 | "encryptionAlgorithm": 0, 38 | "encryptionKey": 0, 39 | "opValue": "c9e8763286b5b9ffbdf56e1297d0887b" 40 | } 41 | }, 42 | "opc": { 43 | "encryptionAlgorithm": 0, 44 | "encryptionKey": 0, 45 | "opcValue": "" 46 | }, 47 | "permanentKey": { 48 | "encryptionAlgorithm": 0, 49 | "encryptionKey": 0, 50 | "permanentKeyValue": "5122250214c33e723a5dd523fc145fc0" 51 | }, 52 | "sequenceNumber": "16f3b3f70fc2" 53 | }, 54 | "AccessAndMobilitySubscriptionData": { 55 | "gpsis": [ 56 | "msisdn-0900000000" 57 | ], 58 | "nssai": { 59 | "defaultSingleNssais": [ 60 | { 61 | "sst": 1, 62 | "sd": "010203" 63 | }, 64 | { 65 | "sst": 1, 66 | "sd": "112233" 67 | } 68 | ], 69 | "singleNssais": [ 70 | { 71 | "sst": 1, 72 | "sd": "010203" 73 | }, 74 | { 75 | "sst": 1, 76 | "sd": "112233" 77 | } 78 | ] 79 | }, 80 | "subscribedUeAmbr": { 81 | "downlink": "2 Gbps", 82 | "uplink": "1 Gbps" 83 | } 84 | }, 85 | "SessionManagementSubscriptionDataList": [ 86 | { 87 | "singleNssai": { 88 | "sst": 1, 89 | "sd": "010203" 90 | }, 91 | "dnnConfigurations": { 92 | "internet": { 93 | "sscModes": { 94 | "defaultSscMode": "SSC_MODE_1", 95 | "allowedSscModes": [ 96 | "SSC_MODE_1", 97 | "SSC_MODE_2", 98 | "SSC_MODE_3" 99 | ] 100 | }, 101 | "pduSessionTypes": { 102 | "defaultSessionType": "IPV4", 103 | "allowedSessionTypes": [ 104 | "IPV4" 105 | ] 106 | }, 107 | "sessionAmbr": { 108 | "uplink": "2 Gbps", 109 | "downlink": "1 Gbps" 110 | }, 111 | "5gQosProfile": { 112 | "5qi": 9, 113 | "arp": { 114 | "priorityLevel": 8 115 | }, 116 | "priorityLevel": 8 117 | } 118 | } 119 | } 120 | }, 121 | { 122 | "singleNssai": { 123 | "sst": 1, 124 | "sd": "112233" 125 | }, 126 | "dnnConfigurations": { 127 | "internet": { 128 | "sscModes": { 129 | "defaultSscMode": "SSC_MODE_1", 130 | "allowedSscModes": [ 131 | "SSC_MODE_1", 132 | "SSC_MODE_2", 133 | "SSC_MODE_3" 134 | ] 135 | }, 136 | "pduSessionTypes": { 137 | "defaultSessionType": "IPV4", 138 | "allowedSessionTypes": [ 139 | "IPV4" 140 | ] 141 | }, 142 | "sessionAmbr": { 143 | "uplink": "2 Gbps", 144 | "downlink": "1 Gbps" 145 | }, 146 | "5gQosProfile": { 147 | "5qi": 9, 148 | "arp": { 149 | "priorityLevel": 8 150 | }, 151 | "priorityLevel": 8 152 | } 153 | } 154 | } 155 | } 156 | ], 157 | "SmfSelectionSubscriptionData": { 158 | "subscribedSnssaiInfos": { 159 | "01010203": { 160 | "dnnInfos": [ 161 | { 162 | "dnn": "internet" 163 | } 164 | ] 165 | }, 166 | "01112233": { 167 | "dnnInfos": [ 168 | { 169 | "dnn": "internet" 170 | } 171 | ] 172 | } 173 | } 174 | }, 175 | "AmPolicyData": { 176 | "subscCats": [ 177 | "free5gc" 178 | ] 179 | }, 180 | "SmPolicyData": { 181 | "smPolicySnssaiData": { 182 | "01010203": { 183 | "snssai": { 184 | "sst": 1, 185 | "sd": "010203" 186 | }, 187 | "smPolicyDnnData": { 188 | "internet": { 189 | "dnn": "internet" 190 | } 191 | } 192 | }, 193 | "01112233": { 194 | "snssai": { 195 | "sst": 1, 196 | "sd": "112233" 197 | }, 198 | "smPolicyDnnData": { 199 | "internet": { 200 | "dnn": "internet" 201 | } 202 | } 203 | } 204 | } 205 | } 206 | }' 207 | 208 | # stop webconsole 209 | #sudo kill -SIGINT $WC_PID 2>/dev/null -------------------------------------------------------------------------------- /sample/my5g_wifi_config/utils/add_test_ue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # run webconsole 4 | #../../../bin/webconsole & 5 | #WC_PID=$! 6 | 7 | 8 | webconsole_addr=${webconsole_addr:-"127.0.0.1"} 9 | webconsole_port=${webconsole_port:-"5000"} 10 | scheme=${scheme:-"http"} 11 | auth_method=${auth_method:-"5G_AKA"} 12 | supi_or_suci=${supi_or_suci:-"2089300007487"} 13 | k=${k:-"5122250214c33e723a5dd523fc145fc0"} 14 | opc_type=${opc_type:-"OP"} 15 | opc=${opc:-"c9e8763286b5b9ffbdf56e1297d0887b"} 16 | plmnId=${plmnId:-"20893"} 17 | 18 | while [ $# -gt 0 ]; do 19 | if [[ $1 == *"--"* ]]; then 20 | param="${1/--/}" 21 | declare $param="$2" 22 | fi 23 | shift 24 | done 25 | 26 | # add test ue 27 | curl --insecure --location --request POST "$scheme://$webconsole_addr:$webconsole_port/api/subscriber/imsi-$supi_or_suci/$plmnId" \ 28 | --header 'Content-Type: application/json' \ 29 | --data-raw '{ 30 | "plmnID": "20893", 31 | "ueId": "imsi-2089300007487", 32 | "AuthenticationSubscription": { 33 | "authenticationManagementField": "8000", 34 | "authenticationMethod": "5G_AKA", 35 | "milenage": { 36 | "op": { 37 | "encryptionAlgorithm": 0, 38 | "encryptionKey": 0, 39 | "opValue": "c9e8763286b5b9ffbdf56e1297d0887b" 40 | } 41 | }, 42 | "opc": { 43 | "encryptionAlgorithm": 0, 44 | "encryptionKey": 0, 45 | "opcValue": "" 46 | }, 47 | "permanentKey": { 48 | "encryptionAlgorithm": 0, 49 | "encryptionKey": 0, 50 | "permanentKeyValue": "5122250214c33e723a5dd523fc145fc0" 51 | }, 52 | "sequenceNumber": "16f3b3f70fc2" 53 | }, 54 | "AccessAndMobilitySubscriptionData": { 55 | "gpsis": [ 56 | "msisdn-0900000000" 57 | ], 58 | "nssai": { 59 | "defaultSingleNssais": [ 60 | { 61 | "sst": 1, 62 | "sd": "010203" 63 | }, 64 | { 65 | "sst": 1, 66 | "sd": "112233" 67 | } 68 | ], 69 | "singleNssais": [ 70 | { 71 | "sst": 1, 72 | "sd": "010203" 73 | }, 74 | { 75 | "sst": 1, 76 | "sd": "112233" 77 | } 78 | ] 79 | }, 80 | "subscribedUeAmbr": { 81 | "downlink": "2 Gbps", 82 | "uplink": "1 Gbps" 83 | } 84 | }, 85 | "SessionManagementSubscriptionDataList": [ 86 | { 87 | "singleNssai": { 88 | "sst": 1, 89 | "sd": "010203" 90 | }, 91 | "dnnConfigurations": { 92 | "internet": { 93 | "sscModes": { 94 | "defaultSscMode": "SSC_MODE_1", 95 | "allowedSscModes": [ 96 | "SSC_MODE_1", 97 | "SSC_MODE_2", 98 | "SSC_MODE_3" 99 | ] 100 | }, 101 | "pduSessionTypes": { 102 | "defaultSessionType": "IPV4", 103 | "allowedSessionTypes": [ 104 | "IPV4" 105 | ] 106 | }, 107 | "sessionAmbr": { 108 | "uplink": "2 Gbps", 109 | "downlink": "1 Gbps" 110 | }, 111 | "5gQosProfile": { 112 | "5qi": 9, 113 | "arp": { 114 | "priorityLevel": 8 115 | }, 116 | "priorityLevel": 8 117 | } 118 | } 119 | } 120 | }, 121 | { 122 | "singleNssai": { 123 | "sst": 1, 124 | "sd": "112233" 125 | }, 126 | "dnnConfigurations": { 127 | "internet": { 128 | "sscModes": { 129 | "defaultSscMode": "SSC_MODE_1", 130 | "allowedSscModes": [ 131 | "SSC_MODE_1", 132 | "SSC_MODE_2", 133 | "SSC_MODE_3" 134 | ] 135 | }, 136 | "pduSessionTypes": { 137 | "defaultSessionType": "IPV4", 138 | "allowedSessionTypes": [ 139 | "IPV4" 140 | ] 141 | }, 142 | "sessionAmbr": { 143 | "uplink": "2 Gbps", 144 | "downlink": "1 Gbps" 145 | }, 146 | "5gQosProfile": { 147 | "5qi": 9, 148 | "arp": { 149 | "priorityLevel": 8 150 | }, 151 | "priorityLevel": 8 152 | } 153 | } 154 | } 155 | } 156 | ], 157 | "SmfSelectionSubscriptionData": { 158 | "subscribedSnssaiInfos": { 159 | "01010203": { 160 | "dnnInfos": [ 161 | { 162 | "dnn": "internet" 163 | } 164 | ] 165 | }, 166 | "01112233": { 167 | "dnnInfos": [ 168 | { 169 | "dnn": "internet" 170 | } 171 | ] 172 | } 173 | } 174 | }, 175 | "AmPolicyData": { 176 | "subscCats": [ 177 | "free5gc" 178 | ] 179 | }, 180 | "SmPolicyData": { 181 | "smPolicySnssaiData": { 182 | "01010203": { 183 | "snssai": { 184 | "sst": 1, 185 | "sd": "010203" 186 | }, 187 | "smPolicyDnnData": { 188 | "internet": { 189 | "dnn": "internet" 190 | } 191 | } 192 | }, 193 | "01112233": { 194 | "snssai": { 195 | "sst": 1, 196 | "sd": "112233" 197 | }, 198 | "smPolicyDnnData": { 199 | "internet": { 200 | "dnn": "internet" 201 | } 202 | } 203 | } 204 | } 205 | } 206 | }' 207 | 208 | # stop webconsole 209 | #sudo kill -SIGINT $WC_PID 2>/dev/null -------------------------------------------------------------------------------- /ue_ike/ike_message/types.go: -------------------------------------------------------------------------------- 1 | package ike_message 2 | 3 | // IKE types 4 | type IKEType uint8 5 | 6 | const ( 7 | NoNext = 0 8 | TypeSA = iota + 32 9 | TypeKE 10 | TypeIDi 11 | TypeIDr 12 | TypeCERT 13 | TypeCERTreq 14 | TypeAUTH 15 | TypeNiNr 16 | TypeN 17 | TypeD 18 | TypeV 19 | TypeTSi 20 | TypeTSr 21 | TypeSK 22 | TypeCP 23 | TypeEAP 24 | ) 25 | 26 | // EAP types 27 | type EAPType uint8 28 | 29 | const ( 30 | EAPTypeIdentity = iota + 1 31 | EAPTypeNotification 32 | EAPTypeNak 33 | EAPTypeExpanded = 254 34 | ) 35 | 36 | const ( 37 | EAPCodeRequest = iota + 1 38 | EAPCodeResponse 39 | EAPCodeSuccess 40 | EAPCodeFailure 41 | ) 42 | 43 | // used for SecurityAssociation-Proposal-Transform TransformType 44 | const ( 45 | TypeEncryptionAlgorithm = iota + 1 46 | TypePseudorandomFunction 47 | TypeIntegrityAlgorithm 48 | TypeDiffieHellmanGroup 49 | TypeExtendedSequenceNumbers 50 | ) 51 | 52 | // used for SecurityAssociation-Proposal-Transform AttributeFormat 53 | const ( 54 | AttributeFormatUseTLV = iota 55 | AttributeFormatUseTV 56 | ) 57 | 58 | // used for SecurityAssociation-Proposal-Trandform AttributeType 59 | const ( 60 | AttributeTypeKeyLength = 14 61 | ) 62 | 63 | // used for SecurityAssociation-Proposal-Transform TransformID 64 | const ( 65 | ENCR_DES_IV64 = 1 66 | ENCR_DES = 2 67 | ENCR_3DES = 3 68 | ENCR_RC5 = 4 69 | ENCR_IDEA = 5 70 | ENCR_CAST = 6 71 | ENCR_BLOWFISH = 7 72 | ENCR_3IDEA = 8 73 | ENCR_DES_IV32 = 9 74 | ENCR_NULL = 11 75 | ENCR_AES_CBC = 12 76 | ENCR_AES_CTR = 13 77 | ) 78 | 79 | const ( 80 | PRF_HMAC_MD5 = iota + 1 81 | PRF_HMAC_SHA1 82 | PRF_HMAC_TIGER 83 | ) 84 | 85 | const ( 86 | AUTH_NONE = iota 87 | AUTH_HMAC_MD5_96 88 | AUTH_HMAC_SHA1_96 89 | AUTH_DES_MAC 90 | AUTH_KPDK_MD5 91 | AUTH_AES_XCBC_96 92 | ) 93 | 94 | const ( 95 | DH_NONE = 0 96 | DH_768_BIT_MODP = 1 97 | DH_1024_BIT_MODP = 2 98 | DH_1536_BIT_MODP = 5 99 | DH_2048_BIT_MODP = iota + 10 100 | DH_3072_BIT_MODP 101 | DH_4096_BIT_MODP 102 | DH_6144_BIT_MODP 103 | DH_8192_BIT_MODP 104 | ) 105 | 106 | const ( 107 | ESN_NO = iota 108 | ESN_NEED 109 | ) 110 | 111 | // used for TrafficSelector-Individual Traffic Selector TSType 112 | const ( 113 | TS_IPV4_ADDR_RANGE = 7 114 | TS_IPV6_ADDR_RANGE = 8 115 | ) 116 | 117 | // Exchange Type 118 | const ( 119 | IKE_SA_INIT = iota + 34 120 | IKE_AUTH 121 | CREATE_CHILD_SA 122 | INFORMATIONAL 123 | ) 124 | 125 | // Notify message types 126 | const ( 127 | UNSUPPORTED_CRITICAL_PAYLOAD = 1 128 | INVALID_IKE_SPI = 4 129 | INVALID_MAJOR_VERSION = 5 130 | INVALID_SYNTAX = 7 131 | INVALID_MESSAGE_ID = 9 132 | INVALID_SPI = 11 133 | NO_PROPOSAL_CHOSEN = 14 134 | INVALID_KE_PAYLOAD = 17 135 | AUTHENTICATION_FAILED = 24 136 | SINGLE_PAIR_REQUIRED = 34 137 | NO_ADDITIONAL_SAS = 35 138 | INTERNAL_ADDRESS_FAILURE = 36 139 | FAILED_CP_REQUIRED = 37 140 | TS_UNACCEPTABLE = 38 141 | INVALID_SELECTORS = 39 142 | TEMPORARY_FAILURE = 43 143 | CHILD_SA_NOT_FOUND = 44 144 | INITIAL_CONTACT = 16384 145 | SET_WINDOW_SIZE = 16385 146 | ADDITIONAL_TS_POSSIBLE = 16386 147 | IPCOMP_SUPPORTED = 16387 148 | NAT_DETECTION_SOURCE_IP = 16388 149 | NAT_DETECTION_DESTINATION_IP = 16389 150 | COOKIE = 16390 151 | USE_TRANSPORT_MODE = 16391 152 | HTTP_CERT_LOOKUP_SUPPORTED = 16392 153 | REKEY_SA = 16393 154 | ESP_TFC_PADDING_NOT_SUPPORTED = 16394 155 | NON_FIRST_FRAGMENTS_ALSO = 16395 156 | ) 157 | 158 | // Protocol ID 159 | const ( 160 | TypeNone = iota 161 | TypeIKE 162 | TypeAH 163 | TypeESP 164 | ) 165 | 166 | // Flags 167 | const ( 168 | ResponseBitCheck = 0x20 169 | VersionBitCheck = 0x10 170 | InitiatorBitCheck = 0x08 171 | ) 172 | 173 | // Certificate encoding 174 | const ( 175 | PKCS7WrappedX509Certificate = 1 176 | PGPCertificate = 2 177 | DNSSignedKey = 3 178 | X509CertificateSignature = 4 179 | KerberosToken = 6 180 | CertificateRevocationList = 7 181 | AuthorityRevocationList = 8 182 | SPKICertificate = 9 183 | X509CertificateAttribute = 10 184 | HashAndURLOfX509Certificate = 12 185 | HashAndURLOfX509Bundle = 13 186 | ) 187 | 188 | // ID Types 189 | const ( 190 | ID_IPV4_ADDR = 1 191 | ID_FQDN = 2 192 | ID_RFC822_ADDR = 3 193 | ID_IPV6_ADDR = 5 194 | ID_DER_ASN1_DN = 9 195 | ID_DER_ASN1_GN = 10 196 | ID_KEY_ID = 11 197 | ) 198 | 199 | // Authentication Methods 200 | const ( 201 | RSADigitalSignature = iota + 1 202 | SharedKeyMesageIntegrityCode 203 | DSSDigitalSignature 204 | ) 205 | 206 | // Configuration types 207 | const ( 208 | CFG_REQUEST = 1 209 | CFG_REPLY = 2 210 | CFG_SET = 3 211 | CFG_ACK = 4 212 | ) 213 | 214 | // Configuration attribute types 215 | const ( 216 | INTERNAL_IP4_ADDRESS = 1 217 | INTERNAL_IP4_NETMASK = 2 218 | INTERNAL_IP4_DNS = 3 219 | INTERNAL_IP4_NBNS = 4 220 | INTERNAL_IP4_DHCP = 6 221 | APPLICATION_VERSION = 7 222 | INTERNAL_IP6_ADDRESS = 8 223 | INTERNAL_IP6_DNS = 10 224 | INTERNAL_IP6_DHCP = 12 225 | INTERNAL_IP4_SUBNET = 13 226 | SUPPORTED_ATTRIBUTES = 14 227 | INTERNAL_IP6_SUBNET = 15 228 | ) 229 | 230 | // IP protocols ID, used in individual traffic selector 231 | const ( 232 | IPProtocolAll = 0 233 | IPProtocolICMP = 1 234 | IPProtocolTCP = 6 235 | IPProtocolUDP = 17 236 | IPProtocolGRE = 47 237 | ) 238 | 239 | // Types for EAP-5G 240 | // Used in IKE EAP expanded for vendor ID 241 | const VendorID3GPP = 10415 242 | 243 | // Used in IKE EAP expanded for vendor data 244 | const VendorTypeEAP5G = 3 245 | 246 | // Used in EAP-5G for message ID 247 | const ( 248 | EAP5GType5GStart = 1 249 | EAP5GType5GNAS = 2 250 | EAP5GType5GStop = 4 251 | ) 252 | 253 | // Used in AN-Parameter field for IE types 254 | const ( 255 | ANParametersTypeGUAMI = 1 256 | ANParametersTypeSelectedPLMNID = 2 257 | ANParametersTypeRequestedNSSAI = 3 258 | ANParametersTypeEstablishmentCause = 4 259 | ) 260 | 261 | // Used in IE Establishment Cause field for cause types 262 | const ( 263 | EstablishmentCauseEmergency = 0 264 | EstablishmentCauseHighPriorityAccess = 1 265 | EstablishmentCauseMO_Signalling = 3 266 | EstablishmentCauseMO_Data = 4 267 | EstablishmentCauseMPS_PriorityAccess = 8 268 | EstablishmentCauseMCS_PriorityAccess = 9 269 | ) 270 | 271 | // Spare 272 | const EAP5GSpareValue = 0 273 | 274 | // 3GPP specified IKE Notify 275 | // 3GPP specified IKE Notify Message Types 276 | const ( 277 | Vendor3GPPNotifyType5G_QOS_INFO uint16 = 55501 278 | Vendor3GPPNotifyTypeNAS_IP4_ADDRESS uint16 = 55502 279 | Vendor3GPPNotifyTypeUP_IP4_ADDRESS uint16 = 55504 280 | Vendor3GPPNotifyTypeNAS_TCP_PORT uint16 = 55506 281 | ) 282 | 283 | // Used in NotifyType5G_QOS_INFO 284 | const ( 285 | NotifyType5G_QOS_INFOBitDSCPICheck uint8 = 1 286 | NotifyType5G_QOS_INFOBitDCSICheck uint8 = 1 << 1 287 | ) 288 | -------------------------------------------------------------------------------- /ue_context/ue_n3iwf.go: -------------------------------------------------------------------------------- 1 | package ue_context 2 | 3 | import ( 4 | "encoding/binary" 5 | "errors" 6 | "fmt" 7 | "free5gc/lib/ngap/ngapType" 8 | "free5gc/src/ue/n3iwf_handler/n3iwf_message" 9 | ike_message "free5gc/src/n3iwf/ike/message" 10 | "net" 11 | 12 | gtpv1 "github.com/wmnsk/go-gtp/v1" 13 | ) 14 | 15 | type UeN3IWF struct { 16 | /* UE identity*/ 17 | RanUeNgapId int64 18 | AmfUeNgapId int64 19 | IPAddrv4 string 20 | IPAddrv6 string 21 | PortNumber int32 22 | MaskedIMEISV *ngapType.MaskedIMEISV // TS 38.413 9.3.1.54 23 | Guti string 24 | RRCEstablishmentCause int16 25 | IPSecInnerIP string 26 | 27 | /* PDU Session */ 28 | PduSessionList map[int64]*PDUSession // pduSessionId as key 29 | 30 | /* PDU Session Setup Temporary Data */ 31 | TemporaryPDUSessionSetupData *PDUSessionSetupTemporaryData 32 | 33 | /* Security */ 34 | Kn3iwf []uint8 // 32 bytes (256 bits), value is from NGAP IE "Security Key" 35 | SecurityCapabilities *ngapType.UESecurityCapabilities // TS 38.413 9.3.1.86 36 | 37 | /* IKE Security Association */ 38 | N3IWFIKESecurityAssociation *IKESecurityAssociation 39 | N3IWFChildSecurityAssociation *ChildSecurityAssociation 40 | 41 | /* NAS IKE Connection */ 42 | UDPSendInfoGroup *n3iwf_message.UDPSendInfoGroup 43 | /* NAS TCP Connection */ 44 | TCPConnection net.Conn 45 | 46 | /* Others */ 47 | Guami *ngapType.GUAMI 48 | IndexToRfsp int64 49 | Ambr *ngapType.UEAggregateMaximumBitRate 50 | AllowedNssai *ngapType.AllowedNSSAI 51 | RadioCapability *ngapType.UERadioCapability // TODO: This is for RRC, can be deleted 52 | CoreNetworkAssistanceInformation *ngapType.CoreNetworkAssistanceInformation // TS 38.413 9.3.1.15 53 | IMSVoiceSupported int32 54 | } 55 | 56 | type PDUSession struct { 57 | Id int64 // PDU Session ID 58 | Type *ngapType.PDUSessionType 59 | Ambr *ngapType.PDUSessionAggregateMaximumBitRate 60 | Snssai ngapType.SNSSAI 61 | NetworkInstance *ngapType.NetworkInstance 62 | SecurityCipher bool 63 | SecurityIntegrity bool 64 | MaximumIntegrityDataRateUplink *ngapType.MaximumIntegrityProtectedDataRate 65 | MaximumIntegrityDataRateDownlink *ngapType.MaximumIntegrityProtectedDataRate 66 | GTPConnection *GTPConnectionInfo 67 | QFIList []uint8 68 | QosFlows map[int64]*QosFlow // QosFlowIdentifier as key 69 | } 70 | 71 | type PDUSessionSetupTemporaryData struct { 72 | // Slice of unactivated PDU session 73 | UnactivatedPDUSession []int64 // PDUSessionID as content 74 | // NGAPProcedureCode is used to identify which type of 75 | // response shall be used 76 | NGAPProcedureCode ngapType.ProcedureCode 77 | // PDU session setup list response 78 | SetupListCxtRes *ngapType.PDUSessionResourceSetupListCxtRes 79 | FailedListCxtRes *ngapType.PDUSessionResourceFailedToSetupListCxtRes 80 | SetupListSURes *ngapType.PDUSessionResourceSetupListSURes 81 | FailedListSURes *ngapType.PDUSessionResourceFailedToSetupListSURes 82 | } 83 | 84 | type QosFlow struct { 85 | Identifier int64 86 | Parameters ngapType.QosFlowLevelQosParameters 87 | } 88 | 89 | type GTPConnectionInfo struct { 90 | UPFIPAddr string 91 | UPFUDPAddr net.Addr 92 | IncomingTEID uint32 93 | OutgoingTEID uint32 94 | UserPlaneConnection *gtpv1.UPlaneConn 95 | } 96 | 97 | type IKESecurityAssociation struct { 98 | // SPI 99 | RemoteSPI uint64 100 | LocalSPI uint64 101 | 102 | // Message ID 103 | MessageID uint32 104 | 105 | // Transforms for IKE SA 106 | EncryptionAlgorithm *ike_message.Transform 107 | PseudorandomFunction *ike_message.Transform 108 | IntegrityAlgorithm *ike_message.Transform 109 | DiffieHellmanGroup *ike_message.Transform 110 | ExpandedSequenceNumber *ike_message.Transform 111 | 112 | // Used for key generating 113 | ConcatenatedNonce []byte 114 | DiffieHellmanSharedKey []byte 115 | 116 | // Keys 117 | SK_d []byte // used for child SA key deriving 118 | SK_ai []byte // used by initiator for integrity checking 119 | SK_ar []byte // used by responder for integrity checking 120 | SK_ei []byte // used by initiator for encrypting 121 | SK_er []byte // used by responder for encrypting 122 | SK_pi []byte // used by initiator for IKE authentication 123 | SK_pr []byte // used by responder for IKE authentication 124 | 125 | // State for IKE_AUTH 126 | State uint8 127 | 128 | // Temporary data stored for the use in later exchange 129 | InitiatorID *ike_message.IdentificationInitiator 130 | InitiatorCertificate *ike_message.Certificate 131 | IKEAuthResponseSA *ike_message.SecurityAssociation 132 | TrafficSelectorInitiator *ike_message.TrafficSelectorInitiator 133 | TrafficSelectorResponder *ike_message.TrafficSelectorResponder 134 | LastEAPIdentifier uint8 135 | 136 | // Authentication data 137 | LocalUnsignedAuthentication []byte 138 | RemoteUnsignedAuthentication []byte 139 | 140 | // UE context 141 | ThisUE *UeN3IWF 142 | } 143 | 144 | type ChildSecurityAssociation struct { 145 | // SPI 146 | SPI uint32 147 | 148 | // IP address 149 | PeerPublicIPAddr net.IP 150 | LocalPublicIPAddr net.IP 151 | 152 | // Traffic selector 153 | SelectedIPProtocol uint8 154 | TrafficSelectorLocal net.IPNet 155 | TrafficSelectorRemote net.IPNet 156 | 157 | // Security 158 | EncryptionAlgorithm uint16 159 | InitiatorToResponderEncryptionKey []byte 160 | ResponderToInitiatorEncryptionKey []byte 161 | IntegrityAlgorithm uint16 162 | InitiatorToResponderIntegrityKey []byte 163 | ResponderToInitiatorIntegrityKey []byte 164 | ESN bool 165 | 166 | // UE context 167 | ThisUE *UeN3IWF 168 | } 169 | 170 | func (ue *UeN3IWF) init() { 171 | ue.PduSessionList = make(map[int64]*PDUSession) 172 | } 173 | 174 | func (ue *UeN3IWF) FindPDUSession(pduSessionID int64) *PDUSession { 175 | if pduSession, ok := ue.PduSessionList[pduSessionID]; ok { 176 | return pduSession 177 | } else { 178 | return nil 179 | } 180 | } 181 | 182 | func (ue *UeN3IWF) CreatePDUSession(pduSessionID int64, snssai ngapType.SNSSAI) (*PDUSession, error) { 183 | if _, exists := ue.PduSessionList[pduSessionID]; exists { 184 | return nil, fmt.Errorf("PDU Session[ID:%d] is already exists", pduSessionID) 185 | } 186 | pduSession := &PDUSession{ 187 | Id: pduSessionID, 188 | Snssai: snssai, 189 | QosFlows: make(map[int64]*QosFlow), 190 | } 191 | ue.PduSessionList[pduSessionID] = pduSession 192 | return pduSession, nil 193 | } 194 | 195 | func (ue *UeN3IWF) CreateIKEChildSecurityAssociation(chosenSecurityAssociation *ike_message.SecurityAssociation) (*ChildSecurityAssociation, error) { 196 | childSecurityAssociation := new(ChildSecurityAssociation) 197 | 198 | if chosenSecurityAssociation == nil { 199 | return nil, errors.New("chosenSecurityAssociation is nil") 200 | } 201 | 202 | if len(chosenSecurityAssociation.Proposals) == 0 { 203 | return nil, errors.New("No proposal") 204 | } 205 | 206 | childSecurityAssociation.SPI = binary.BigEndian.Uint32(chosenSecurityAssociation.Proposals[0].SPI) 207 | 208 | if len(chosenSecurityAssociation.Proposals[0].EncryptionAlgorithm) != 0 { 209 | childSecurityAssociation.EncryptionAlgorithm = chosenSecurityAssociation.Proposals[0].EncryptionAlgorithm[0].TransformID 210 | } 211 | if len(chosenSecurityAssociation.Proposals[0].IntegrityAlgorithm) != 0 { 212 | childSecurityAssociation.IntegrityAlgorithm = chosenSecurityAssociation.Proposals[0].IntegrityAlgorithm[0].TransformID 213 | } 214 | if len(chosenSecurityAssociation.Proposals[0].ExtendedSequenceNumbers) != 0 { 215 | if chosenSecurityAssociation.Proposals[0].ExtendedSequenceNumbers[0].TransformID == 0 { 216 | childSecurityAssociation.ESN = false 217 | } else { 218 | childSecurityAssociation.ESN = true 219 | } 220 | } 221 | 222 | // Link UE context 223 | childSecurityAssociation.ThisUE = ue 224 | // Record to N3IWF context 225 | //n3iwfContext.ChildSA[childSecurityAssociation.SPI] = childSecurityAssociation 226 | 227 | ue.N3IWFChildSecurityAssociation = childSecurityAssociation 228 | 229 | return childSecurityAssociation, nil 230 | } 231 | -------------------------------------------------------------------------------- /sample/ran_attach_config/nssfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: NSSF initial local configuration 4 | 5 | configuration: 6 | nssfName: NSSF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 127.0.0.1 # IP used to register to NRF 10 | bindingIPv4: 127.0.0.1 # IP used to bind the service 11 | port: 29531 12 | serviceNameList: 13 | - nnssf-nsselection 14 | - nnssf-nssaiavailability 15 | nrfUri: http://localhost:29510 16 | supportedPlmnList: 17 | - mcc: 208 18 | mnc: 93 19 | supportedNssaiInPlmnList: 20 | - plmnId: 21 | mcc: 208 22 | mnc: 93 23 | supportedSnssaiList: 24 | - sst: 1 25 | sd: 010203 26 | - sst: 1 27 | sd: 112233 28 | - sst: 1 29 | sd: 3 30 | - sst: 2 31 | sd: 1 32 | - sst: 2 33 | sd: 2 34 | nsiList: 35 | - snssai: 36 | sst: 1 37 | nsiInformationList: 38 | - nrfId: http://localhost:29510/nnrf-nfm/v1/nf-instances 39 | nsiId: 10 40 | - snssai: 41 | sst: 1 42 | sd: 1 43 | nsiInformationList: 44 | - nrfId: http://localhost:29510/nnrf-nfm/v1/nf-instances 45 | nsiId: 11 46 | - snssai: 47 | sst: 1 48 | sd: 2 49 | nsiInformationList: 50 | - nrfId: http://localhost:29510/nnrf-nfm/v1/nf-instances 51 | nsiId: 12 52 | - nrfId: http://localhost:29510/nnrf-nfm/v1/nf-instances 53 | nsiId: 12 54 | - snssai: 55 | sst: 1 56 | sd: 3 57 | nsiInformationList: 58 | - nrfId: http://localhost:29510/nnrf-nfm/v1/nf-instances 59 | nsiId: 13 60 | - snssai: 61 | sst: 2 62 | nsiInformationList: 63 | - nrfId: http://localhost:29510/nnrf-nfm/v1/nf-instances 64 | nsiId: 20 65 | - snssai: 66 | sst: 2 67 | sd: 1 68 | nsiInformationList: 69 | - nrfId: http://localhost:29510/nnrf-nfm/v1/nf-instances 70 | nsiId: 21 71 | - snssai: 72 | sst: 1 73 | sd: 010203 74 | nsiInformationList: 75 | - nrfId: http://localhost:29510/nnrf-nfm/v1/nf-instances 76 | nsiId: 22 77 | amfSetList: 78 | - amfSetId: 1 79 | amfList: 80 | - ffa2e8d7-3275-49c7-8631-6af1df1d9d26 81 | - 0e8831c3-6286-4689-ab27-1e2161e15cb1 82 | - a1fba9ba-2e39-4e22-9c74-f749da571d0d 83 | nrfAmfSet: http://localhost:8081/nnrf-nfm/v1/nf-instances 84 | supportedNssaiAvailabilityData: 85 | - tai: 86 | plmnId: 87 | mcc: 466 88 | mnc: 92 89 | tac: 33456 90 | supportedSnssaiList: 91 | - sst: 1 92 | sd: 1 93 | - sst: 1 94 | sd: 2 95 | - sst: 2 96 | sd: 1 97 | - tai: 98 | plmnId: 99 | mcc: 466 100 | mnc: 92 101 | tac: 33457 102 | supportedSnssaiList: 103 | - sst: 1 104 | - sst: 1 105 | sd: 1 106 | - sst: 1 107 | sd: 2 108 | - amfSetId: 2 109 | nrfAmfSet: http://localhost:8084/nnrf-nfm/v1/nf-instances 110 | supportedNssaiAvailabilityData: 111 | - tai: 112 | plmnId: 113 | mcc: 466 114 | mnc: 92 115 | tac: 33456 116 | supportedSnssaiList: 117 | - sst: 1 118 | - sst: 1 119 | sd: 1 120 | - sst: 1 121 | sd: 3 122 | - sst: 2 123 | sd: 1 124 | - tai: 125 | plmnId: 126 | mcc: 466 127 | mnc: 92 128 | tac: 33458 129 | supportedSnssaiList: 130 | - sst: 1 131 | - sst: 1 132 | sd: 1 133 | - sst: 2 134 | amfList: 135 | - nfId: 469de254-2fe5-4ca0-8381-af3f500af77c 136 | supportedNssaiAvailabilityData: 137 | - tai: 138 | plmnId: 139 | mcc: 466 140 | mnc: 92 141 | tac: 33456 142 | supportedSnssaiList: 143 | - sst: 1 144 | - sst: 1 145 | sd: 2 146 | - sst: 2 147 | - tai: 148 | plmnId: 149 | mcc: 466 150 | mnc: 92 151 | tac: 33457 152 | supportedSnssaiList: 153 | - sst: 1 154 | sd: 1 155 | - sst: 1 156 | sd: 2 157 | - nfId: fbe604a8-27b2-417e-bd7c-8a7be2691f8d 158 | supportedNssaiAvailabilityData: 159 | - tai: 160 | plmnId: 161 | mcc: 466 162 | mnc: 92 163 | tac: 33458 164 | supportedSnssaiList: 165 | - sst: 1 166 | - sst: 1 167 | sd: 1 168 | - sst: 1 169 | sd: 3 170 | - sst: 2 171 | - tai: 172 | plmnId: 173 | mcc: 466 174 | mnc: 92 175 | tac: 33459 176 | supportedSnssaiList: 177 | - sst: 1 178 | - sst: 1 179 | sd: 1 180 | - sst: 2 181 | - sst: 2 182 | sd: 1 183 | - nfId: b9e6e2cb-5ce8-4cb6-9173-a266dd9a2f0c 184 | supportedNssaiAvailabilityData: 185 | - tai: 186 | plmnId: 187 | mcc: 466 188 | mnc: 92 189 | tac: 33456 190 | supportedSnssaiList: 191 | - sst: 1 192 | - sst: 1 193 | sd: 1 194 | - sst: 1 195 | sd: 2 196 | - sst: 2 197 | - tai: 198 | plmnId: 199 | mcc: 466 200 | mnc: 92 201 | tac: 33458 202 | supportedSnssaiList: 203 | - sst: 1 204 | - sst: 1 205 | sd: 1 206 | - sst: 2 207 | - sst: 2 208 | sd: 1 209 | taList: 210 | - tai: 211 | plmnId: 212 | mcc: 466 213 | mnc: 92 214 | tac: 33456 215 | accessType: 3GPP_ACCESS 216 | supportedSnssaiList: 217 | - sst: 1 218 | - sst: 1 219 | sd: 1 220 | - sst: 1 221 | sd: 2 222 | - sst: 2 223 | - tai: 224 | plmnId: 225 | mcc: 466 226 | mnc: 92 227 | tac: 33457 228 | accessType: 3GPP_ACCESS 229 | supportedSnssaiList: 230 | - sst: 1 231 | - sst: 1 232 | sd: 1 233 | - sst: 1 234 | sd: 2 235 | - sst: 2 236 | - tai: 237 | plmnId: 238 | mcc: 466 239 | mnc: 92 240 | tac: 33458 241 | accessType: 3GPP_ACCESS 242 | supportedSnssaiList: 243 | - sst: 1 244 | - sst: 1 245 | sd: 1 246 | - sst: 1 247 | sd: 3 248 | - sst: 2 249 | restrictedSnssaiList: 250 | - homePlmnId: 251 | mcc: 310 252 | mnc: 560 253 | sNssaiList: 254 | - sst: 1 255 | sd: 3 256 | - tai: 257 | plmnId: 258 | mcc: 466 259 | mnc: 92 260 | tac: 33459 261 | accessType: 3GPP_ACCESS 262 | supportedSnssaiList: 263 | - sst: 1 264 | - sst: 1 265 | sd: 1 266 | - sst: 2 267 | - sst: 2 268 | sd: 1 269 | restrictedSnssaiList: 270 | - homePlmnId: 271 | mcc: 310 272 | mnc: 560 273 | sNssaiList: 274 | - sst: 2 275 | sd: 1 276 | mappingListFromPlmn: 277 | - operatorName: NTT Docomo 278 | homePlmnId: 279 | mcc: 440 280 | mnc: 10 281 | mappingOfSnssai: 282 | - servingSnssai: 283 | sst: 1 284 | sd: 1 285 | homeSnssai: 286 | sst: 1 287 | sd: 1 288 | - servingSnssai: 289 | sst: 1 290 | sd: 2 291 | homeSnssai: 292 | sst: 1 293 | sd: 3 294 | - servingSnssai: 295 | sst: 1 296 | sd: 3 297 | homeSnssai: 298 | sst: 1 299 | sd: 4 300 | - servingSnssai: 301 | sst: 2 302 | sd: 1 303 | homeSnssai: 304 | sst: 2 305 | sd: 2 306 | - operatorName: AT&T Mobility 307 | homePlmnId: 308 | mcc: 310 309 | mnc: 560 310 | mappingOfSnssai: 311 | - servingSnssai: 312 | sst: 1 313 | sd: 1 314 | homeSnssai: 315 | sst: 1 316 | sd: 2 317 | - servingSnssai: 318 | sst: 1 319 | sd: 2 320 | homeSnssai: 321 | sst: 1 322 | sd: 3 323 | -------------------------------------------------------------------------------- /sample/my5g_docker_config/nssfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: NSSF initial local configuration 4 | 5 | configuration: 6 | nssfName: NSSF 7 | sbi: 8 | scheme: https 9 | ipv4Addr: nssf 10 | port: 29531 11 | serviceNameList: 12 | - nnssf-nsselection 13 | - nnssf-nssaiavailability 14 | nrfUri: https://nrf:29510 15 | supportedPlmnList: 16 | - mcc: 208 17 | mnc: 93 18 | supportedNssaiInPlmnList: 19 | - plmnId: 20 | mcc: 208 21 | mnc: 93 22 | supportedSnssaiList: 23 | - sst: 1 24 | sd: 010203 25 | - sst: 1 26 | sd: 112233 27 | - sst: 1 28 | sd: 3 29 | - sst: 2 30 | sd: 1 31 | - sst: 2 32 | sd: 2 33 | nsiList: 34 | - snssai: 35 | sst: 1 36 | nsiInformationList: 37 | - nrfId: http://free5gc-nrf-10.nctu.me:29510/nnrf-nfm/v1/nf-instances 38 | nsiId: 10 39 | - snssai: 40 | sst: 1 41 | sd: 1 42 | nsiInformationList: 43 | - nrfId: http://free5gc-nrf-11.nctu.me:29510/nnrf-nfm/v1/nf-instances 44 | nsiId: 11 45 | - snssai: 46 | sst: 1 47 | sd: 2 48 | nsiInformationList: 49 | - nrfId: http://free5gc-nrf-12-1.nctu.me:29510/nnrf-nfm/v1/nf-instances 50 | nsiId: 12 51 | - nrfId: http://free5gc-nrf-12-2.nctu.me:29510/nnrf-nfm/v1/nf-instances 52 | nsiId: 12 53 | - snssai: 54 | sst: 1 55 | sd: 3 56 | nsiInformationList: 57 | - nrfId: http://free5gc-nrf-13.nctu.me:29510/nnrf-nfm/v1/nf-instances 58 | nsiId: 13 59 | - snssai: 60 | sst: 2 61 | nsiInformationList: 62 | - nrfId: http://free5gc-nrf-20.nctu.me:29510/nnrf-nfm/v1/nf-instances 63 | nsiId: 20 64 | - snssai: 65 | sst: 2 66 | sd: 1 67 | nsiInformationList: 68 | - nrfId: http://free5gc-nrf-21.nctu.me:29510/nnrf-nfm/v1/nf-instances 69 | nsiId: 21 70 | - snssai: 71 | sst: 1 72 | sd: 010203 73 | nsiInformationList: 74 | - nrfId: https://localhost:29510/nnrf-nfm/v1/nf-instances 75 | nsiId: 22 76 | amfSetList: 77 | - amfSetId: 1 78 | amfList: 79 | - ffa2e8d7-3275-49c7-8631-6af1df1d9d26 80 | - 0e8831c3-6286-4689-ab27-1e2161e15cb1 81 | - a1fba9ba-2e39-4e22-9c74-f749da571d0d 82 | nrfAmfSet: http://free5gc-nrf.nctu.me:8081/nnrf-nfm/v1/nf-instances 83 | supportedNssaiAvailabilityData: 84 | - tai: 85 | plmnId: 86 | mcc: 466 87 | mnc: 92 88 | tac: 33456 89 | supportedSnssaiList: 90 | - sst: 1 91 | sd: 1 92 | - sst: 1 93 | sd: 2 94 | - sst: 2 95 | sd: 1 96 | - tai: 97 | plmnId: 98 | mcc: 466 99 | mnc: 92 100 | tac: 33457 101 | supportedSnssaiList: 102 | - sst: 1 103 | - sst: 1 104 | sd: 1 105 | - sst: 1 106 | sd: 2 107 | - amfSetId: 2 108 | nrfAmfSet: http://free5gc-nrf.nctu.me:8084/nnrf-nfm/v1/nf-instances 109 | supportedNssaiAvailabilityData: 110 | - tai: 111 | plmnId: 112 | mcc: 466 113 | mnc: 92 114 | tac: 33456 115 | supportedSnssaiList: 116 | - sst: 1 117 | - sst: 1 118 | sd: 1 119 | - sst: 1 120 | sd: 3 121 | - sst: 2 122 | sd: 1 123 | - tai: 124 | plmnId: 125 | mcc: 466 126 | mnc: 92 127 | tac: 33458 128 | supportedSnssaiList: 129 | - sst: 1 130 | - sst: 1 131 | sd: 1 132 | - sst: 2 133 | amfList: 134 | - nfId: 469de254-2fe5-4ca0-8381-af3f500af77c 135 | supportedNssaiAvailabilityData: 136 | - tai: 137 | plmnId: 138 | mcc: 466 139 | mnc: 92 140 | tac: 33456 141 | supportedSnssaiList: 142 | - sst: 1 143 | - sst: 1 144 | sd: 2 145 | - sst: 2 146 | - tai: 147 | plmnId: 148 | mcc: 466 149 | mnc: 92 150 | tac: 33457 151 | supportedSnssaiList: 152 | - sst: 1 153 | sd: 1 154 | - sst: 1 155 | sd: 2 156 | - nfId: fbe604a8-27b2-417e-bd7c-8a7be2691f8d 157 | supportedNssaiAvailabilityData: 158 | - tai: 159 | plmnId: 160 | mcc: 466 161 | mnc: 92 162 | tac: 33458 163 | supportedSnssaiList: 164 | - sst: 1 165 | - sst: 1 166 | sd: 1 167 | - sst: 1 168 | sd: 3 169 | - sst: 2 170 | - tai: 171 | plmnId: 172 | mcc: 466 173 | mnc: 92 174 | tac: 33459 175 | supportedSnssaiList: 176 | - sst: 1 177 | - sst: 1 178 | sd: 1 179 | - sst: 2 180 | - sst: 2 181 | sd: 1 182 | - nfId: b9e6e2cb-5ce8-4cb6-9173-a266dd9a2f0c 183 | supportedNssaiAvailabilityData: 184 | - tai: 185 | plmnId: 186 | mcc: 466 187 | mnc: 92 188 | tac: 33456 189 | supportedSnssaiList: 190 | - sst: 1 191 | - sst: 1 192 | sd: 1 193 | - sst: 1 194 | sd: 2 195 | - sst: 2 196 | - tai: 197 | plmnId: 198 | mcc: 466 199 | mnc: 92 200 | tac: 33458 201 | supportedSnssaiList: 202 | - sst: 1 203 | - sst: 1 204 | sd: 1 205 | - sst: 2 206 | - sst: 2 207 | sd: 1 208 | taList: 209 | - tai: 210 | plmnId: 211 | mcc: 466 212 | mnc: 92 213 | tac: 33456 214 | accessType: 3GPP_ACCESS 215 | supportedSnssaiList: 216 | - sst: 1 217 | - sst: 1 218 | sd: 1 219 | - sst: 1 220 | sd: 2 221 | - sst: 2 222 | - tai: 223 | plmnId: 224 | mcc: 466 225 | mnc: 92 226 | tac: 33457 227 | accessType: 3GPP_ACCESS 228 | supportedSnssaiList: 229 | - sst: 1 230 | - sst: 1 231 | sd: 1 232 | - sst: 1 233 | sd: 2 234 | - sst: 2 235 | - tai: 236 | plmnId: 237 | mcc: 466 238 | mnc: 92 239 | tac: 33458 240 | accessType: 3GPP_ACCESS 241 | supportedSnssaiList: 242 | - sst: 1 243 | - sst: 1 244 | sd: 1 245 | - sst: 1 246 | sd: 3 247 | - sst: 2 248 | restrictedSnssaiList: 249 | - homePlmnId: 250 | mcc: 310 251 | mnc: 560 252 | sNssaiList: 253 | - sst: 1 254 | sd: 3 255 | - tai: 256 | plmnId: 257 | mcc: 466 258 | mnc: 92 259 | tac: 33459 260 | accessType: 3GPP_ACCESS 261 | supportedSnssaiList: 262 | - sst: 1 263 | - sst: 1 264 | sd: 1 265 | - sst: 2 266 | - sst: 2 267 | sd: 1 268 | restrictedSnssaiList: 269 | - homePlmnId: 270 | mcc: 310 271 | mnc: 560 272 | sNssaiList: 273 | - sst: 2 274 | sd: 1 275 | mappingListFromPlmn: 276 | - operatorName: NTT Docomo 277 | homePlmnId: 278 | mcc: 440 279 | mnc: 10 280 | mappingOfSnssai: 281 | - servingSnssai: 282 | sst: 1 283 | sd: 1 284 | homeSnssai: 285 | sst: 1 286 | sd: 1 287 | - servingSnssai: 288 | sst: 1 289 | sd: 2 290 | homeSnssai: 291 | sst: 1 292 | sd: 3 293 | - servingSnssai: 294 | sst: 1 295 | sd: 3 296 | homeSnssai: 297 | sst: 1 298 | sd: 4 299 | - servingSnssai: 300 | sst: 2 301 | sd: 1 302 | homeSnssai: 303 | sst: 2 304 | sd: 2 305 | - operatorName: AT&T Mobility 306 | homePlmnId: 307 | mcc: 310 308 | mnc: 560 309 | mappingOfSnssai: 310 | - servingSnssai: 311 | sst: 1 312 | sd: 1 313 | homeSnssai: 314 | sst: 1 315 | sd: 2 316 | - servingSnssai: 317 | sst: 1 318 | sd: 2 319 | homeSnssai: 320 | sst: 1 321 | sd: 3 322 | -------------------------------------------------------------------------------- /sample/my5g_basic_config/nssfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: NSSF initial local configuration 4 | 5 | configuration: 6 | nssfName: NSSF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 10.1.1.5 # Can also be a kubernetes service IP or domain name. 10 | bindingIPv4: 10.1.1.5 # Can also be an ENV. 11 | port: 29531 12 | serviceNameList: 13 | - nnssf-nsselection 14 | - nnssf-nssaiavailability 15 | nrfUri: http://10.1.1.10:29510 16 | supportedPlmnList: 17 | - mcc: 208 18 | mnc: 93 19 | supportedNssaiInPlmnList: 20 | - plmnId: 21 | mcc: 208 22 | mnc: 93 23 | supportedSnssaiList: 24 | - sst: 1 25 | sd: 010203 26 | - sst: 1 27 | sd: 112233 28 | - sst: 1 29 | sd: 3 30 | - sst: 2 31 | sd: 1 32 | - sst: 2 33 | sd: 2 34 | nsiList: 35 | - snssai: 36 | sst: 1 37 | nsiInformationList: 38 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 39 | nsiId: 10 40 | - snssai: 41 | sst: 1 42 | sd: 1 43 | nsiInformationList: 44 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 45 | nsiId: 11 46 | - snssai: 47 | sst: 1 48 | sd: 2 49 | nsiInformationList: 50 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 51 | nsiId: 12 52 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 53 | nsiId: 12 54 | - snssai: 55 | sst: 1 56 | sd: 3 57 | nsiInformationList: 58 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 59 | nsiId: 13 60 | - snssai: 61 | sst: 2 62 | nsiInformationList: 63 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 64 | nsiId: 20 65 | - snssai: 66 | sst: 2 67 | sd: 1 68 | nsiInformationList: 69 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 70 | nsiId: 21 71 | - snssai: 72 | sst: 1 73 | sd: 010203 74 | nsiInformationList: 75 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 76 | nsiId: 22 77 | amfSetList: 78 | - amfSetId: 1 79 | amfList: 80 | - ffa2e8d7-3275-49c7-8631-6af1df1d9d26 81 | - 0e8831c3-6286-4689-ab27-1e2161e15cb1 82 | - a1fba9ba-2e39-4e22-9c74-f749da571d0d 83 | nrfAmfSet: http://10.1.1.10:8081/nnrf-nfm/v1/nf-instances 84 | supportedNssaiAvailabilityData: 85 | - tai: 86 | plmnId: 87 | mcc: 466 88 | mnc: 92 89 | tac: 33456 90 | supportedSnssaiList: 91 | - sst: 1 92 | sd: 1 93 | - sst: 1 94 | sd: 2 95 | - sst: 2 96 | sd: 1 97 | - tai: 98 | plmnId: 99 | mcc: 466 100 | mnc: 92 101 | tac: 33457 102 | supportedSnssaiList: 103 | - sst: 1 104 | - sst: 1 105 | sd: 1 106 | - sst: 1 107 | sd: 2 108 | - amfSetId: 2 109 | nrfAmfSet: http://10.1.1.10:8084/nnrf-nfm/v1/nf-instances 110 | supportedNssaiAvailabilityData: 111 | - tai: 112 | plmnId: 113 | mcc: 466 114 | mnc: 92 115 | tac: 33456 116 | supportedSnssaiList: 117 | - sst: 1 118 | - sst: 1 119 | sd: 1 120 | - sst: 1 121 | sd: 3 122 | - sst: 2 123 | sd: 1 124 | - tai: 125 | plmnId: 126 | mcc: 466 127 | mnc: 92 128 | tac: 33458 129 | supportedSnssaiList: 130 | - sst: 1 131 | - sst: 1 132 | sd: 1 133 | - sst: 2 134 | amfList: 135 | - nfId: 469de254-2fe5-4ca0-8381-af3f500af77c 136 | supportedNssaiAvailabilityData: 137 | - tai: 138 | plmnId: 139 | mcc: 466 140 | mnc: 92 141 | tac: 33456 142 | supportedSnssaiList: 143 | - sst: 1 144 | - sst: 1 145 | sd: 2 146 | - sst: 2 147 | - tai: 148 | plmnId: 149 | mcc: 466 150 | mnc: 92 151 | tac: 33457 152 | supportedSnssaiList: 153 | - sst: 1 154 | sd: 1 155 | - sst: 1 156 | sd: 2 157 | - nfId: fbe604a8-27b2-417e-bd7c-8a7be2691f8d 158 | supportedNssaiAvailabilityData: 159 | - tai: 160 | plmnId: 161 | mcc: 466 162 | mnc: 92 163 | tac: 33458 164 | supportedSnssaiList: 165 | - sst: 1 166 | - sst: 1 167 | sd: 1 168 | - sst: 1 169 | sd: 3 170 | - sst: 2 171 | - tai: 172 | plmnId: 173 | mcc: 466 174 | mnc: 92 175 | tac: 33459 176 | supportedSnssaiList: 177 | - sst: 1 178 | - sst: 1 179 | sd: 1 180 | - sst: 2 181 | - sst: 2 182 | sd: 1 183 | - nfId: b9e6e2cb-5ce8-4cb6-9173-a266dd9a2f0c 184 | supportedNssaiAvailabilityData: 185 | - tai: 186 | plmnId: 187 | mcc: 466 188 | mnc: 92 189 | tac: 33456 190 | supportedSnssaiList: 191 | - sst: 1 192 | - sst: 1 193 | sd: 1 194 | - sst: 1 195 | sd: 2 196 | - sst: 2 197 | - tai: 198 | plmnId: 199 | mcc: 466 200 | mnc: 92 201 | tac: 33458 202 | supportedSnssaiList: 203 | - sst: 1 204 | - sst: 1 205 | sd: 1 206 | - sst: 2 207 | - sst: 2 208 | sd: 1 209 | taList: 210 | - tai: 211 | plmnId: 212 | mcc: 466 213 | mnc: 92 214 | tac: 33456 215 | accessType: 3GPP_ACCESS 216 | supportedSnssaiList: 217 | - sst: 1 218 | - sst: 1 219 | sd: 1 220 | - sst: 1 221 | sd: 2 222 | - sst: 2 223 | - tai: 224 | plmnId: 225 | mcc: 466 226 | mnc: 92 227 | tac: 33457 228 | accessType: 3GPP_ACCESS 229 | supportedSnssaiList: 230 | - sst: 1 231 | - sst: 1 232 | sd: 1 233 | - sst: 1 234 | sd: 2 235 | - sst: 2 236 | - tai: 237 | plmnId: 238 | mcc: 466 239 | mnc: 92 240 | tac: 33458 241 | accessType: 3GPP_ACCESS 242 | supportedSnssaiList: 243 | - sst: 1 244 | - sst: 1 245 | sd: 1 246 | - sst: 1 247 | sd: 3 248 | - sst: 2 249 | restrictedSnssaiList: 250 | - homePlmnId: 251 | mcc: 310 252 | mnc: 560 253 | sNssaiList: 254 | - sst: 1 255 | sd: 3 256 | - tai: 257 | plmnId: 258 | mcc: 466 259 | mnc: 92 260 | tac: 33459 261 | accessType: 3GPP_ACCESS 262 | supportedSnssaiList: 263 | - sst: 1 264 | - sst: 1 265 | sd: 1 266 | - sst: 2 267 | - sst: 2 268 | sd: 1 269 | restrictedSnssaiList: 270 | - homePlmnId: 271 | mcc: 310 272 | mnc: 560 273 | sNssaiList: 274 | - sst: 2 275 | sd: 1 276 | mappingListFromPlmn: 277 | - operatorName: NTT Docomo 278 | homePlmnId: 279 | mcc: 440 280 | mnc: 10 281 | mappingOfSnssai: 282 | - servingSnssai: 283 | sst: 1 284 | sd: 1 285 | homeSnssai: 286 | sst: 1 287 | sd: 1 288 | - servingSnssai: 289 | sst: 1 290 | sd: 2 291 | homeSnssai: 292 | sst: 1 293 | sd: 3 294 | - servingSnssai: 295 | sst: 1 296 | sd: 3 297 | homeSnssai: 298 | sst: 1 299 | sd: 4 300 | - servingSnssai: 301 | sst: 2 302 | sd: 1 303 | homeSnssai: 304 | sst: 2 305 | sd: 2 306 | - operatorName: AT&T Mobility 307 | homePlmnId: 308 | mcc: 310 309 | mnc: 560 310 | mappingOfSnssai: 311 | - servingSnssai: 312 | sst: 1 313 | sd: 1 314 | homeSnssai: 315 | sst: 1 316 | sd: 2 317 | - servingSnssai: 318 | sst: 1 319 | sd: 2 320 | homeSnssai: 321 | sst: 1 322 | sd: 3 323 | -------------------------------------------------------------------------------- /sample/my5g_wifi_config/nssfcfg.conf: -------------------------------------------------------------------------------- 1 | info: 2 | version: 1.0.0 3 | description: NSSF initial local configuration 4 | 5 | configuration: 6 | nssfName: NSSF 7 | sbi: 8 | scheme: http 9 | registerIPv4: 10.1.1.5 # Can also be a kubernetes service IP or domain name. 10 | bindingIPv4: 10.1.1.5 # Can also be an ENV. 11 | port: 29531 12 | serviceNameList: 13 | - nnssf-nsselection 14 | - nnssf-nssaiavailability 15 | nrfUri: http://10.1.1.10:29510 16 | supportedPlmnList: 17 | - mcc: 208 18 | mnc: 93 19 | supportedNssaiInPlmnList: 20 | - plmnId: 21 | mcc: 208 22 | mnc: 93 23 | supportedSnssaiList: 24 | - sst: 1 25 | sd: 010203 26 | - sst: 1 27 | sd: 112233 28 | - sst: 1 29 | sd: 3 30 | - sst: 2 31 | sd: 1 32 | - sst: 2 33 | sd: 2 34 | nsiList: 35 | - snssai: 36 | sst: 1 37 | nsiInformationList: 38 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 39 | nsiId: 10 40 | - snssai: 41 | sst: 1 42 | sd: 1 43 | nsiInformationList: 44 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 45 | nsiId: 11 46 | - snssai: 47 | sst: 1 48 | sd: 2 49 | nsiInformationList: 50 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 51 | nsiId: 12 52 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 53 | nsiId: 12 54 | - snssai: 55 | sst: 1 56 | sd: 3 57 | nsiInformationList: 58 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 59 | nsiId: 13 60 | - snssai: 61 | sst: 2 62 | nsiInformationList: 63 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 64 | nsiId: 20 65 | - snssai: 66 | sst: 2 67 | sd: 1 68 | nsiInformationList: 69 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 70 | nsiId: 21 71 | - snssai: 72 | sst: 1 73 | sd: 010203 74 | nsiInformationList: 75 | - nrfId: http://10.1.1.10:29510/nnrf-nfm/v1/nf-instances 76 | nsiId: 22 77 | amfSetList: 78 | - amfSetId: 1 79 | amfList: 80 | - ffa2e8d7-3275-49c7-8631-6af1df1d9d26 81 | - 0e8831c3-6286-4689-ab27-1e2161e15cb1 82 | - a1fba9ba-2e39-4e22-9c74-f749da571d0d 83 | nrfAmfSet: http://10.1.1.10:8081/nnrf-nfm/v1/nf-instances 84 | supportedNssaiAvailabilityData: 85 | - tai: 86 | plmnId: 87 | mcc: 466 88 | mnc: 92 89 | tac: 33456 90 | supportedSnssaiList: 91 | - sst: 1 92 | sd: 1 93 | - sst: 1 94 | sd: 2 95 | - sst: 2 96 | sd: 1 97 | - tai: 98 | plmnId: 99 | mcc: 466 100 | mnc: 92 101 | tac: 33457 102 | supportedSnssaiList: 103 | - sst: 1 104 | - sst: 1 105 | sd: 1 106 | - sst: 1 107 | sd: 2 108 | - amfSetId: 2 109 | nrfAmfSet: http://10.1.1.10:8084/nnrf-nfm/v1/nf-instances 110 | supportedNssaiAvailabilityData: 111 | - tai: 112 | plmnId: 113 | mcc: 466 114 | mnc: 92 115 | tac: 33456 116 | supportedSnssaiList: 117 | - sst: 1 118 | - sst: 1 119 | sd: 1 120 | - sst: 1 121 | sd: 3 122 | - sst: 2 123 | sd: 1 124 | - tai: 125 | plmnId: 126 | mcc: 466 127 | mnc: 92 128 | tac: 33458 129 | supportedSnssaiList: 130 | - sst: 1 131 | - sst: 1 132 | sd: 1 133 | - sst: 2 134 | amfList: 135 | - nfId: 469de254-2fe5-4ca0-8381-af3f500af77c 136 | supportedNssaiAvailabilityData: 137 | - tai: 138 | plmnId: 139 | mcc: 466 140 | mnc: 92 141 | tac: 33456 142 | supportedSnssaiList: 143 | - sst: 1 144 | - sst: 1 145 | sd: 2 146 | - sst: 2 147 | - tai: 148 | plmnId: 149 | mcc: 466 150 | mnc: 92 151 | tac: 33457 152 | supportedSnssaiList: 153 | - sst: 1 154 | sd: 1 155 | - sst: 1 156 | sd: 2 157 | - nfId: fbe604a8-27b2-417e-bd7c-8a7be2691f8d 158 | supportedNssaiAvailabilityData: 159 | - tai: 160 | plmnId: 161 | mcc: 466 162 | mnc: 92 163 | tac: 33458 164 | supportedSnssaiList: 165 | - sst: 1 166 | - sst: 1 167 | sd: 1 168 | - sst: 1 169 | sd: 3 170 | - sst: 2 171 | - tai: 172 | plmnId: 173 | mcc: 466 174 | mnc: 92 175 | tac: 33459 176 | supportedSnssaiList: 177 | - sst: 1 178 | - sst: 1 179 | sd: 1 180 | - sst: 2 181 | - sst: 2 182 | sd: 1 183 | - nfId: b9e6e2cb-5ce8-4cb6-9173-a266dd9a2f0c 184 | supportedNssaiAvailabilityData: 185 | - tai: 186 | plmnId: 187 | mcc: 466 188 | mnc: 92 189 | tac: 33456 190 | supportedSnssaiList: 191 | - sst: 1 192 | - sst: 1 193 | sd: 1 194 | - sst: 1 195 | sd: 2 196 | - sst: 2 197 | - tai: 198 | plmnId: 199 | mcc: 466 200 | mnc: 92 201 | tac: 33458 202 | supportedSnssaiList: 203 | - sst: 1 204 | - sst: 1 205 | sd: 1 206 | - sst: 2 207 | - sst: 2 208 | sd: 1 209 | taList: 210 | - tai: 211 | plmnId: 212 | mcc: 466 213 | mnc: 92 214 | tac: 33456 215 | accessType: 3GPP_ACCESS 216 | supportedSnssaiList: 217 | - sst: 1 218 | - sst: 1 219 | sd: 1 220 | - sst: 1 221 | sd: 2 222 | - sst: 2 223 | - tai: 224 | plmnId: 225 | mcc: 466 226 | mnc: 92 227 | tac: 33457 228 | accessType: 3GPP_ACCESS 229 | supportedSnssaiList: 230 | - sst: 1 231 | - sst: 1 232 | sd: 1 233 | - sst: 1 234 | sd: 2 235 | - sst: 2 236 | - tai: 237 | plmnId: 238 | mcc: 466 239 | mnc: 92 240 | tac: 33458 241 | accessType: 3GPP_ACCESS 242 | supportedSnssaiList: 243 | - sst: 1 244 | - sst: 1 245 | sd: 1 246 | - sst: 1 247 | sd: 3 248 | - sst: 2 249 | restrictedSnssaiList: 250 | - homePlmnId: 251 | mcc: 310 252 | mnc: 560 253 | sNssaiList: 254 | - sst: 1 255 | sd: 3 256 | - tai: 257 | plmnId: 258 | mcc: 466 259 | mnc: 92 260 | tac: 33459 261 | accessType: 3GPP_ACCESS 262 | supportedSnssaiList: 263 | - sst: 1 264 | - sst: 1 265 | sd: 1 266 | - sst: 2 267 | - sst: 2 268 | sd: 1 269 | restrictedSnssaiList: 270 | - homePlmnId: 271 | mcc: 310 272 | mnc: 560 273 | sNssaiList: 274 | - sst: 2 275 | sd: 1 276 | mappingListFromPlmn: 277 | - operatorName: NTT Docomo 278 | homePlmnId: 279 | mcc: 440 280 | mnc: 10 281 | mappingOfSnssai: 282 | - servingSnssai: 283 | sst: 1 284 | sd: 1 285 | homeSnssai: 286 | sst: 1 287 | sd: 1 288 | - servingSnssai: 289 | sst: 1 290 | sd: 2 291 | homeSnssai: 292 | sst: 1 293 | sd: 3 294 | - servingSnssai: 295 | sst: 1 296 | sd: 3 297 | homeSnssai: 298 | sst: 1 299 | sd: 4 300 | - servingSnssai: 301 | sst: 2 302 | sd: 1 303 | homeSnssai: 304 | sst: 2 305 | sd: 2 306 | - operatorName: AT&T Mobility 307 | homePlmnId: 308 | mcc: 310 309 | mnc: 560 310 | mappingOfSnssai: 311 | - servingSnssai: 312 | sst: 1 313 | sd: 1 314 | homeSnssai: 315 | sst: 1 316 | sd: 2 317 | - servingSnssai: 318 | sst: 1 319 | sd: 2 320 | homeSnssai: 321 | sst: 1 322 | sd: 3 323 | -------------------------------------------------------------------------------- /ue_procedures/ranUe.go: -------------------------------------------------------------------------------- 1 | package ue_procedures 2 | 3 | import ( 4 | "encoding/hex" 5 | "free5gc/lib/CommonConsumerTestData/UDM/TestGenAuthData" 6 | "free5gc/lib/CommonConsumerTestData/UDR/TestRegistrationProcedure" 7 | "free5gc/lib/UeauCommon" 8 | "free5gc/lib/milenage" 9 | "free5gc/lib/nas/nasMessage" 10 | "free5gc/lib/nas/nasType" 11 | "free5gc/lib/nas/security" 12 | "free5gc/lib/openapi/models" 13 | "regexp" 14 | 15 | "github.com/calee0219/fatal" 16 | "golang.org/x/net/ipv4" 17 | ) 18 | 19 | type UeRanContext struct { 20 | Supi string 21 | RanUeNgapId int64 22 | AmfUeNgapId int64 23 | ULCount security.Count 24 | DLCount security.Count 25 | CipheringAlg uint8 26 | IntegrityAlg uint8 27 | KnasEnc [16]uint8 28 | KnasInt [16]uint8 29 | Kamf []uint8 30 | AuthenticationSubs models.AuthenticationSubscription 31 | } 32 | 33 | func CalculateIpv4HeaderChecksum(hdr *ipv4.Header) uint32 { 34 | var Checksum uint32 35 | Checksum += uint32((hdr.Version<<4|(20>>2&0x0f))<<8 | hdr.TOS) 36 | Checksum += uint32(hdr.TotalLen) 37 | Checksum += uint32(hdr.ID) 38 | Checksum += uint32((hdr.FragOff & 0x1fff) | (int(hdr.Flags) << 13)) 39 | Checksum += uint32((hdr.TTL << 8) | (hdr.Protocol)) 40 | 41 | src := hdr.Src.To4() 42 | Checksum += uint32(src[0])<<8 | uint32(src[1]) 43 | Checksum += uint32(src[2])<<8 | uint32(src[3]) 44 | dst := hdr.Dst.To4() 45 | Checksum += uint32(dst[0])<<8 | uint32(dst[1]) 46 | Checksum += uint32(dst[2])<<8 | uint32(dst[3]) 47 | return ^(Checksum&0xffff0000>>16 + Checksum&0xffff) 48 | } 49 | 50 | func GetAuthSubscription(k, opc, op string) models.AuthenticationSubscription { 51 | var authSubs models.AuthenticationSubscription 52 | authSubs.PermanentKey = &models.PermanentKey{ 53 | PermanentKeyValue: k, 54 | } 55 | authSubs.Opc = &models.Opc{ 56 | OpcValue: opc, 57 | } 58 | authSubs.Milenage = &models.Milenage{ 59 | Op: &models.Op{ 60 | OpValue: op, 61 | }, 62 | } 63 | authSubs.AuthenticationManagementField = "8000" 64 | 65 | authSubs.SequenceNumber = TestGenAuthData.MilenageTestSet19.SQN 66 | authSubs.AuthenticationMethod = models.AuthMethod__5_G_AKA 67 | return authSubs 68 | } 69 | 70 | func GetAccessAndMobilitySubscriptionData() (amData models.AccessAndMobilitySubscriptionData) { 71 | return TestRegistrationProcedure.TestAmDataTable[TestRegistrationProcedure.FREE5GC_CASE] 72 | } 73 | 74 | func GetSmfSelectionSubscriptionData() (smfSelData models.SmfSelectionSubscriptionData) { 75 | return TestRegistrationProcedure.TestSmfSelDataTable[TestRegistrationProcedure.FREE5GC_CASE] 76 | } 77 | 78 | func GetSessionManagementSubscriptionData() (smfSelData models.SessionManagementSubscriptionData) { 79 | return TestRegistrationProcedure.TestSmSelDataTable[TestRegistrationProcedure.FREE5GC_CASE] 80 | } 81 | 82 | func GetAmPolicyData() (amPolicyData models.AmPolicyData) { 83 | return TestRegistrationProcedure.TestAmPolicyDataTable[TestRegistrationProcedure.FREE5GC_CASE] 84 | } 85 | 86 | func GetSmPolicyData() (smPolicyData models.SmPolicyData) { 87 | return TestRegistrationProcedure.TestSmPolicyDataTable[TestRegistrationProcedure.FREE5GC_CASE] 88 | } 89 | 90 | func NewUeRanContext(supi string, ranUeNgapId int64, cipheringAlg, integrityAlg uint8) *UeRanContext { 91 | ue := UeRanContext{} 92 | ue.RanUeNgapId = ranUeNgapId 93 | ue.Supi = supi 94 | ue.CipheringAlg = cipheringAlg 95 | ue.IntegrityAlg = integrityAlg 96 | return &ue 97 | } 98 | 99 | func (ue *UeRanContext) DeriveRESstarAndSetKey( 100 | authSubs models.AuthenticationSubscription, rand []byte, snName string) []byte { 101 | 102 | sqn, err := hex.DecodeString(authSubs.SequenceNumber) 103 | if err != nil { 104 | fatal.Fatalf("DecodeString error: %+v", err) 105 | } 106 | 107 | amf, err := hex.DecodeString(authSubs.AuthenticationManagementField) 108 | if err != nil { 109 | fatal.Fatalf("DecodeString error: %+v", err) 110 | } 111 | 112 | // Run milenage 113 | macA, macS := make([]byte, 8), make([]byte, 8) 114 | ck, ik := make([]byte, 16), make([]byte, 16) 115 | res := make([]byte, 8) 116 | ak, akStar := make([]byte, 6), make([]byte, 6) 117 | 118 | opc := make([]byte, 16) 119 | _ = opc 120 | k, err := hex.DecodeString(authSubs.PermanentKey.PermanentKeyValue) 121 | if err != nil { 122 | fatal.Fatalf("DecodeString error: %+v", err) 123 | } 124 | 125 | if authSubs.Opc.OpcValue == "" { 126 | opStr := authSubs.Milenage.Op.OpValue 127 | var op []byte 128 | op, err = hex.DecodeString(opStr) 129 | if err != nil { 130 | fatal.Fatalf("DecodeString error: %+v", err) 131 | } 132 | 133 | opc, err = milenage.GenerateOPC(k, op) 134 | if err != nil { 135 | fatal.Fatalf("milenage GenerateOPC error: %+v", err) 136 | } 137 | } else { 138 | opc, err = hex.DecodeString(authSubs.Opc.OpcValue) 139 | if err != nil { 140 | fatal.Fatalf("DecodeString error: %+v", err) 141 | } 142 | } 143 | 144 | // Generate MAC_A, MAC_S 145 | err = milenage.F1(opc, k, rand, sqn, amf, macA, macS) 146 | if err != nil { 147 | fatal.Fatalf("regexp Compile error: %+v", err) 148 | } 149 | 150 | // Generate RES, CK, IK, AK, AKstar 151 | err = milenage.F2345(opc, k, rand, res, ck, ik, ak, akStar) 152 | if err != nil { 153 | fatal.Fatalf("regexp Compile error: %+v", err) 154 | } 155 | 156 | // derive RES* 157 | key := append(ck, ik...) 158 | FC := UeauCommon.FC_FOR_RES_STAR_XRES_STAR_DERIVATION 159 | P0 := []byte(snName) 160 | P1 := rand 161 | P2 := res 162 | 163 | ue.DerivateKamf(key, snName, sqn, ak) 164 | ue.DerivateAlgKey() 165 | kdfVal_for_resStar := 166 | UeauCommon.GetKDFValue(key, FC, P0, UeauCommon.KDFLen(P0), P1, UeauCommon.KDFLen(P1), P2, UeauCommon.KDFLen(P2)) 167 | return kdfVal_for_resStar[len(kdfVal_for_resStar)/2:] 168 | 169 | } 170 | 171 | func (ue *UeRanContext) DerivateKamf(key []byte, snName string, SQN, AK []byte) { 172 | 173 | FC := UeauCommon.FC_FOR_KAUSF_DERIVATION 174 | P0 := []byte(snName) 175 | SQNxorAK := make([]byte, 6) 176 | for i := 0; i < len(SQN); i++ { 177 | SQNxorAK[i] = SQN[i] ^ AK[i] 178 | } 179 | P1 := SQNxorAK 180 | Kausf := UeauCommon.GetKDFValue(key, FC, P0, UeauCommon.KDFLen(P0), P1, UeauCommon.KDFLen(P1)) 181 | P0 = []byte(snName) 182 | Kseaf := UeauCommon.GetKDFValue(Kausf, UeauCommon.FC_FOR_KSEAF_DERIVATION, P0, UeauCommon.KDFLen(P0)) 183 | 184 | supiRegexp, err := regexp.Compile("(?:imsi|supi)-([0-9]{5,15})") 185 | if err != nil { 186 | fatal.Fatalf("regexp Compile error: %+v", err) 187 | } 188 | groups := supiRegexp.FindStringSubmatch(ue.Supi) 189 | 190 | P0 = []byte(groups[1]) 191 | L0 := UeauCommon.KDFLen(P0) 192 | P1 = []byte{0x00, 0x00} 193 | L1 := UeauCommon.KDFLen(P1) 194 | 195 | ue.Kamf = UeauCommon.GetKDFValue(Kseaf, UeauCommon.FC_FOR_KAMF_DERIVATION, P0, L0, P1, L1) 196 | } 197 | 198 | // Algorithm key Derivation function defined in TS 33.501 Annex A.9 199 | func (ue *UeRanContext) DerivateAlgKey() { 200 | // Security Key 201 | P0 := []byte{security.NNASEncAlg} 202 | L0 := UeauCommon.KDFLen(P0) 203 | P1 := []byte{ue.CipheringAlg} 204 | L1 := UeauCommon.KDFLen(P1) 205 | 206 | kenc := UeauCommon.GetKDFValue(ue.Kamf, UeauCommon.FC_FOR_ALGORITHM_KEY_DERIVATION, P0, L0, P1, L1) 207 | copy(ue.KnasEnc[:], kenc[16:32]) 208 | 209 | // Integrity Key 210 | P0 = []byte{security.NNASIntAlg} 211 | L0 = UeauCommon.KDFLen(P0) 212 | P1 = []byte{ue.IntegrityAlg} 213 | L1 = UeauCommon.KDFLen(P1) 214 | 215 | kint := UeauCommon.GetKDFValue(ue.Kamf, UeauCommon.FC_FOR_ALGORITHM_KEY_DERIVATION, P0, L0, P1, L1) 216 | copy(ue.KnasInt[:], kint[16:32]) 217 | } 218 | 219 | func (ue *UeRanContext) GetUESecurityCapability() (UESecurityCapability *nasType.UESecurityCapability) { 220 | UESecurityCapability = &nasType.UESecurityCapability{ 221 | Iei: nasMessage.RegistrationRequestUESecurityCapabilityType, 222 | Len: 2, 223 | Buffer: []uint8{0x00, 0x00}, 224 | } 225 | switch ue.CipheringAlg { 226 | case security.AlgCiphering128NEA0: 227 | UESecurityCapability.SetEA0_5G(1) 228 | case security.AlgCiphering128NEA1: 229 | UESecurityCapability.SetEA1_128_5G(1) 230 | case security.AlgCiphering128NEA2: 231 | UESecurityCapability.SetEA2_128_5G(1) 232 | case security.AlgCiphering128NEA3: 233 | UESecurityCapability.SetEA3_128_5G(1) 234 | } 235 | 236 | switch ue.IntegrityAlg { 237 | case security.AlgIntegrity128NIA0: 238 | UESecurityCapability.SetIA0_5G(1) 239 | case security.AlgIntegrity128NIA1: 240 | UESecurityCapability.SetIA1_128_5G(1) 241 | case security.AlgIntegrity128NIA2: 242 | UESecurityCapability.SetIA2_128_5G(1) 243 | case security.AlgIntegrity128NIA3: 244 | UESecurityCapability.SetIA3_128_5G(1) 245 | } 246 | 247 | return 248 | } 249 | 250 | func (ue *UeRanContext) Get5GMMCapability() (capability5GMM *nasType.Capability5GMM) { 251 | return &nasType.Capability5GMM{ 252 | Iei: nasMessage.RegistrationRequestCapability5GMMType, 253 | Len: 1, 254 | Octet: [13]uint8{0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 255 | } 256 | } 257 | --------------------------------------------------------------------------------