diff --git a/openair3/NAS/COMMON/nr_common.c b/openair3/NAS/COMMON/nr_common.c deleted file mode 100644 index 5f0beb3a66..0000000000 --- a/openair3/NAS/COMMON/nr_common.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Author and copyright: Laurent Thomas, open-cells.com - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#include -#include "openair3/NAS/NR_UE/5GS/NR_NAS_defs.h" -#include -#include - -void servingNetworkName(uint8_t *msg, char * imsiStr, int nmc_size) { - //SNN-network-identifier in TS 24.501 - // TS 24.501: If the MNC of the serving PLMN has two digits, then a zero is added at the beginning. - const char *format="5G:mnc000.mcc000.3gppnetwork.org"; - memcpy(msg,format, strlen(format)); - - if (nmc_size == 2) - memcpy(msg+7, imsiStr+3, 2); - else - memcpy(msg+6, imsiStr+3, 3); - - memcpy(msg+13, imsiStr, 3); -} - -int resToresStar(uint8_t *msg, const uicc_t* uicc) { - // TS 33.220 annex B.2 => FC=0x6B in TS 33.501 annex A.4 - //input S to KDF - uint8_t S[128]= {0}; - S[0]=0x6B; - uint8_t *ptr=S+1; - servingNetworkName(ptr, uicc->imsiStr, uicc->nmc_size); - *(uint16_t *)(ptr+strlen((char *)ptr))=htons(strlen((char *)ptr)); - ptr+=strlen((char *)ptr)+sizeof(uint16_t); - // add rand - memcpy(ptr, uicc->rand, sizeof(uicc->rand) ) ; - *(uint16_t *)(ptr+sizeof(uicc->rand))=htons(sizeof(uicc->rand)); - ptr+=sizeof(uicc->rand)+sizeof(uint16_t); - // add res - memcpy(ptr, uicc->milenage_res, sizeof(uicc->milenage_res) ) ; - *(uint16_t *)(ptr+sizeof(uicc->milenage_res))=htons(sizeof(uicc->milenage_res)); - ptr+=sizeof(uicc->milenage_res)+sizeof(uint16_t); - // S is done - uint8_t ckik[sizeof(uicc->ck) +sizeof(uicc->ik)]; - memcpy(ckik, uicc->ck, sizeof(uicc->ck)); - memcpy(ckik+sizeof(uicc->ck),uicc->ik, sizeof(uicc->ik)); - uint8_t out[32] = {0}; - assert(ptr-S == 32); - //kdf(S, ptr-S, ckik, 32, out, sizeof(out)); - byte_array_t data = {.buf = ckik, .len = 32}; - kdf(S, data, 32, out); - - memcpy(msg, out+16, 16); - return 16; -} diff --git a/openair3/NAS/NR_UE/CMakeLists.txt b/openair3/NAS/NR_UE/CMakeLists.txt index 83d5a2191a..8054d1cdd2 100644 --- a/openair3/NAS/NR_UE/CMakeLists.txt +++ b/openair3/NAS/NR_UE/CMakeLists.txt @@ -1,9 +1,6 @@ add_subdirectory(5GS) -add_library(nr_nas STATIC - nr_nas_msg.c - ../COMMON/nr_common.c -) +add_library(nr_nas STATIC nr_nas_msg.c) target_link_libraries(nr_nas PUBLIC asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) target_link_libraries(nr_nas PUBLIC diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index a8aecf8912..dbf86c6222 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -65,6 +65,21 @@ typedef enum { NAS_SECURITY_BAD_INPUT } security_state_t; +static void servingNetworkName(uint8_t *msg, char *imsiStr, int nmc_size) +{ + // SNN-network-identifier in TS 24.501 + // TS 24.501: If the MNC of the serving PLMN has two digits, then a zero is added at the beginning. + const char *format = "5G:mnc000.mcc000.3gppnetwork.org"; + memcpy(msg, format, strlen(format)); + + if (nmc_size == 2) + memcpy(msg + 7, imsiStr + 3, 2); + else + memcpy(msg + 6, imsiStr + 3, 3); + + memcpy(msg + 13, imsiStr, 3); +} + security_state_t nas_security_rx_process(nr_ue_nas_t *nas, uint8_t *pdu_buffer, int pdu_length) { if (nas->security_container == NULL)