diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index ecb9b314f2..c03c6ad3dd 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -595,7 +595,6 @@ Message("CPU_Affinity flag is ${CPU_AFFINITY}") ############################################################## # ???!!! TO BE DOCUMENTED OPTIONS !!!??? ############################################################## -add_boolean_option(ENABLE_SECURITY True "Enable LTE integrity and ciphering between RRC UE and eNB") add_boolean_option(ENABLE_USE_MME True "eNB connected to MME (INTERFACE S1-C), not standalone eNB") add_boolean_option(NO_RRM True "DO WE HAVE A RADIO RESSOURCE MANAGER: NO") add_boolean_option(RRC_DEFAULT_RAB_IS_AM False "set the RLC mode to AM for the default bearer") diff --git a/cmake_targets/epc_test/CMakeLists.template b/cmake_targets/epc_test/CMakeLists.template index e046bb7539..7a097fffb0 100644 --- a/cmake_targets/epc_test/CMakeLists.template +++ b/cmake_targets/epc_test/CMakeLists.template @@ -9,7 +9,6 @@ set ( EMIT_ASN_DEBUG False ) set ( ENABLE_ITTI True ) set ( ENABLE_NAS_UE_LOGGING True ) set ( ENABLE_NEW_MULTICAST True ) -set ( ENABLE_SECURITY True ) set ( ENABLE_STANDALONE_EPC False) set ( ENABLE_USE_CPU_EXECUTION_TIME True ) set ( ENABLE_USE_MME True ) diff --git a/cmake_targets/oaisim_build_oai/CMakeLists.template b/cmake_targets/oaisim_build_oai/CMakeLists.template index 22faac75b5..cffbddc93c 100644 --- a/cmake_targets/oaisim_build_oai/CMakeLists.template +++ b/cmake_targets/oaisim_build_oai/CMakeLists.template @@ -8,7 +8,6 @@ set ( ENABLE_ITTI True ) set ( ENABLE_NAS_UE_LOGGING True ) set ( ENABLE_NEW_MULTICAST True ) set ( ENABLE_RAL False ) -set ( ENABLE_SECURITY True ) set ( ENABLE_STANDALONE_EPC False) set ( ENABLE_USE_CPU_EXECUTION_TIME True ) set ( ENABLE_USE_MME True ) diff --git a/cmake_targets/oaisim_mme_build_oai/CMakeLists.template b/cmake_targets/oaisim_mme_build_oai/CMakeLists.template index b18b23ee9a..eac29006da 100644 --- a/cmake_targets/oaisim_mme_build_oai/CMakeLists.template +++ b/cmake_targets/oaisim_mme_build_oai/CMakeLists.template @@ -8,7 +8,6 @@ set ( ENABLE_ITTI True ) set ( ENABLE_NAS_UE_LOGGING False ) set ( ENABLE_NEW_MULTICAST False ) set ( ENABLE_RAL False ) -set ( ENABLE_SECURITY False ) set ( ENABLE_STANDALONE_EPC False ) set ( ENABLE_USE_CPU_EXECUTION_TIME False ) set ( ENABLE_USE_MME False ) diff --git a/cmake_targets/oaisim_noS1_build_oai/CMakeLists.template b/cmake_targets/oaisim_noS1_build_oai/CMakeLists.template index bc416cff55..343e928090 100644 --- a/cmake_targets/oaisim_noS1_build_oai/CMakeLists.template +++ b/cmake_targets/oaisim_noS1_build_oai/CMakeLists.template @@ -7,7 +7,6 @@ set ( ENABLE_ITTI True ) set ( ENABLE_NAS_UE_LOGGING False ) set ( ENABLE_NEW_MULTICAST True ) set ( ENABLE_RAL False ) -set ( ENABLE_SECURITY False ) set ( ENABLE_STANDALONE_EPC False) set ( ENABLE_USE_CPU_EXECUTION_TIME True ) set ( ENABLE_USE_MME False ) diff --git a/cmake_targets/s1c_mme_test/CMakeLists.template b/cmake_targets/s1c_mme_test/CMakeLists.template index 9f1ff3e360..e62df04bc6 100644 --- a/cmake_targets/s1c_mme_test/CMakeLists.template +++ b/cmake_targets/s1c_mme_test/CMakeLists.template @@ -9,7 +9,6 @@ set ( ENABLE_NAS_UE_LOGGING True ) set ( ENABLE_NEW_MULTICAST True ) set ( ENABLE_PDCP_NETLINK_FIFO False ) set ( ENABLE_RAL False ) -set ( ENABLE_SECURITY True ) set ( ENABLE_STANDALONE_EPC False) set ( ENABLE_USE_CPU_EXECUTION_TIME True ) set ( ENABLE_USE_MME True ) diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c index a5ec0b7a21..684bc109ac 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c @@ -50,9 +50,7 @@ #include "common/utils/LOG/vcd_signal_dumper.h" #include "msc.h" #include "targets/COMMON/openairinterface5g_limits.h" -#if defined(ENABLE_SECURITY) - #include "UTIL/OSA/osa_defs.h" -#endif +#include "UTIL/OSA/osa_defs.h" #if defined(ENABLE_ITTI) #include "intertask_interface.h" @@ -299,8 +297,6 @@ boolean_t pdcp_data_req( pdcp_pdu_p->data[pdcp_header_len + sdu_buffer_sizeP + i] = 0x00;// pdu_header.mac_i[i]; } -#if defined(ENABLE_SECURITY) - if ((pdcp_p->security_activated != 0) && (((pdcp_p->cipheringAlgorithm) != 0) || ((pdcp_p->integrityProtAlgorithm) != 0))) { @@ -326,7 +322,6 @@ boolean_t pdcp_data_req( } } -#endif /* Print octets of outgoing data in hexadecimal form */ LOG_D(PDCP, "Following content with size %d will be sent over RLC (PDCP PDU header is the first two bytes)\n", pdcp_pdu_size); @@ -455,6 +450,10 @@ pdcp_data_ind( MessageDef *message_p = NULL; uint8_t *gtpu_buffer_p = NULL; #endif + uint32_t rx_hfn_for_count; + int pdcp_sn_for_count; + int security_ok; + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_DATA_IND,VCD_FUNCTION_IN); LOG_DUMPMSG(PDCP,DEBUG_PDCP,(char *)sdu_buffer_pP->data,sdu_buffer_sizeP, "[MSG] PDCP UL %s PDU on rb_id %d\n", (srb_flagP)? "CONTROL" : "DATA", rb_idP); @@ -542,10 +541,10 @@ pdcp_data_ind( } else { // DRB pdcp_tailer_len = 0; - if (pdcp_p->seq_num_size == PDCP_SN_7BIT) { + if (pdcp_p->seq_num_size == 7) { pdcp_header_len = PDCP_USER_PLANE_DATA_PDU_SHORT_SN_HEADER_SIZE; sequence_number = pdcp_get_sequence_number_of_pdu_with_short_sn((unsigned char *)sdu_buffer_pP->data); - } else if (pdcp_p->seq_num_size == PDCP_SN_12BIT) { + } else if (pdcp_p->seq_num_size == 12) { pdcp_header_len = PDCP_USER_PLANE_DATA_PDU_LONG_SN_HEADER_SIZE; sequence_number = pdcp_get_sequence_number_of_pdu_with_long_sn((unsigned char *)sdu_buffer_pP->data); } else { @@ -554,6 +553,7 @@ pdcp_data_ind( PROTOCOL_PDCP_CTXT_FMT"wrong sequence number (%d) for this pdcp entity \n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p), pdcp_p->seq_num_size); + exit(1); } //uint8_t dc = pdcp_get_dc_filed((unsigned char*)sdu_buffer_pP->data); @@ -579,30 +579,16 @@ pdcp_data_ind( return FALSE; } - if (pdcp_is_rx_seq_number_valid(sequence_number, pdcp_p, srb_flagP) == TRUE) { - LOG_T(PDCP, "Incoming PDU has a sequence number (%d) in accordance with RX window\n", sequence_number); - /* if (dc == PDCP_DATA_PDU ) - LOG_D(PDCP, "Passing piggybacked SDU to NAS driver...\n"); - else - LOG_D(PDCP, "Passing piggybacked SDU to RRC ...\n");*/ - } else { - oo_flag=1; - LOG_W(PDCP, - PROTOCOL_PDCP_CTXT_FMT"Incoming PDU has an unexpected sequence number (%d), RX window synchronisation have probably been lost!\n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p), - sequence_number); - /* - * XXX Till we implement in-sequence delivery and duplicate discarding - * mechanism all out-of-order packets will be delivered to RRC/IP - */ - LOG_W(PDCP, "Ignoring PDU...\n"); - free_mem_block(sdu_buffer_pP, __func__); - return FALSE; - } - // SRB1/2: control-plane data if (srb_flagP) { -#if defined(ENABLE_SECURITY) + /* process as described in 36.323 5.1.2.2 */ + if (sequence_number < pdcp_p->next_pdcp_rx_sn) { + rx_hfn_for_count = pdcp_p->rx_hfn + 1; + pdcp_sn_for_count = sequence_number; + } else { + rx_hfn_for_count = pdcp_p->rx_hfn; + pdcp_sn_for_count = sequence_number; + } if (pdcp_p->security_activated == 1) { if (ctxt_pP->enb_flag == ENB_FLAG_NO) { @@ -611,23 +597,45 @@ pdcp_data_ind( start_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); } - pdcp_validate_security(ctxt_pP, - pdcp_p, - srb_flagP, - rb_idP, - pdcp_header_len, - sequence_number, - sdu_buffer_pP->data, - sdu_buffer_sizeP - pdcp_tailer_len); + security_ok = pdcp_validate_security(ctxt_pP, + pdcp_p, + srb_flagP, + rb_idP, + pdcp_header_len, + rx_hfn_for_count, + pdcp_sn_for_count, + sdu_buffer_pP->data, + sdu_buffer_sizeP - pdcp_tailer_len) == 0; if (ctxt_pP->enb_flag == ENB_FLAG_NO) { stop_meas(&eNB_pdcp_stats[ctxt_pP->module_id].validate_security); } else { stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); } + } else { + security_ok = 1; + } + + if (security_ok == 0) { + LOG_W(PDCP, + PROTOCOL_PDCP_CTXT_FMT"security not validated for incoming PDCP SRB PDU\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p)); + LOG_W(PDCP, "Ignoring PDU...\n"); + free_mem_block(sdu_buffer_pP, __func__); + /* TODO: indicate integrity verification failure to upper layer */ + return FALSE; + } + + if (sequence_number < pdcp_p->next_pdcp_rx_sn) + pdcp_p->rx_hfn++; + + pdcp_p->next_pdcp_rx_sn = sequence_number + 1; + + if (pdcp_p->next_pdcp_rx_sn > pdcp_p->maximum_pdcp_rx_sn) { + pdcp_p->next_pdcp_rx_sn = 0; + pdcp_p->rx_hfn++; } -#endif //rrc_lite_data_ind(module_id, //Modified MW - L2 Interface MSC_LOG_TX_MESSAGE( (ctxt_pP->enb_flag == ENB_FLAG_NO)? MSC_PDCP_UE:MSC_PDCP_ENB, @@ -651,40 +659,168 @@ pdcp_data_ind( VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_DATA_IND,VCD_FUNCTION_OUT); return TRUE; - } + } /* if (srb_flagP) */ /* * DRBs */ payload_offset=pdcp_header_len;// PDCP_USER_PLANE_DATA_PDU_LONG_SN_HEADER_SIZE; -#if defined(ENABLE_SECURITY) - if (pdcp_p->security_activated == 1) { - if (ctxt_pP->enb_flag == ENB_FLAG_NO) { - start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].validate_security); - } else { - start_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); + switch (pdcp_p->rlc_mode) { + case RLC_MODE_AM: { + /* process as described in 36.323 5.1.2.1.2 */ + int reordering_window; + + if (pdcp_p->seq_num_size == 7) + reordering_window = REORDERING_WINDOW_SN_7BIT; + else + reordering_window = REORDERING_WINDOW_SN_12BIT; + + if (sequence_number - pdcp_p->last_submitted_pdcp_rx_sn > reordering_window || + (pdcp_p->last_submitted_pdcp_rx_sn - sequence_number >= 0 && + pdcp_p->last_submitted_pdcp_rx_sn - sequence_number < reordering_window)) { + /* TODO: specs say to decipher and do header decompression */ + LOG_W(PDCP, + PROTOCOL_PDCP_CTXT_FMT"discard PDU, out of\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p)); + LOG_W(PDCP, "Ignoring PDU...\n"); + free_mem_block(sdu_buffer_pP, __func__); + /* TODO: indicate integrity verification failure to upper layer */ + return FALSE; + + } else if (pdcp_p->next_pdcp_rx_sn - sequence_number > reordering_window) { + pdcp_p->rx_hfn++; + rx_hfn_for_count = pdcp_p->rx_hfn; + pdcp_sn_for_count = sequence_number; + pdcp_p->next_pdcp_rx_sn = sequence_number + 1; + + } else if (sequence_number - pdcp_p->next_pdcp_rx_sn >= reordering_window) { + rx_hfn_for_count = pdcp_p->rx_hfn - 1; + pdcp_sn_for_count = sequence_number; + + } else if (sequence_number >= pdcp_p->next_pdcp_rx_sn) { + rx_hfn_for_count = pdcp_p->rx_hfn; + pdcp_sn_for_count = sequence_number; + pdcp_p->next_pdcp_rx_sn = sequence_number + 1; + if (pdcp_p->next_pdcp_rx_sn > pdcp_p->maximum_pdcp_rx_sn) { + pdcp_p->next_pdcp_rx_sn = 0; + pdcp_p->rx_hfn++; + } + + } else { /* sequence_number < pdcp_p->next_pdcp_rx_sn */ + rx_hfn_for_count = pdcp_p->rx_hfn; + pdcp_sn_for_count = sequence_number; } - pdcp_validate_security( - ctxt_pP, - pdcp_p, - srb_flagP, - rb_idP, - pdcp_header_len, - sequence_number, - sdu_buffer_pP->data, - sdu_buffer_sizeP - pdcp_tailer_len); + if (pdcp_p->security_activated == 1) { + if (ctxt_pP->enb_flag == ENB_FLAG_NO) { + start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].validate_security); + } else { + start_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); + } - if (ctxt_pP->enb_flag == ENB_FLAG_NO) { - stop_meas(&eNB_pdcp_stats[ctxt_pP->module_id].validate_security); + security_ok = pdcp_validate_security(ctxt_pP, + pdcp_p, + srb_flagP, + rb_idP, + pdcp_header_len, + rx_hfn_for_count, + pdcp_sn_for_count, + sdu_buffer_pP->data, + sdu_buffer_sizeP - pdcp_tailer_len) == 0; + + if (ctxt_pP->enb_flag == ENB_FLAG_NO) { + stop_meas(&eNB_pdcp_stats[ctxt_pP->module_id].validate_security); + } else { + stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); + } } else { - stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); + security_ok = 1; } - } -#endif - } else { + if (security_ok == 0) { + LOG_W(PDCP, + PROTOCOL_PDCP_CTXT_FMT"security not validated for incoming PDPC DRB RLC/AM PDU\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p)); + LOG_W(PDCP, "Ignoring PDU...\n"); + free_mem_block(sdu_buffer_pP, __func__); + /* TODO: indicate integrity verification failure to upper layer */ + return FALSE; + } + + /* TODO: specs say we have to store this PDU in a list and then deliver + * stored packets to upper layers according to a well defined + * procedure. The code below that deals with delivery is today + * too complex to do this properly, so we only send the current + * received packet. This is not correct and has to be fixed + * some day. + * In the meantime, let's pretend the last submitted PDCP SDU + * is the current one. + * TODO: we also have to deal with re-establishment PDU (control PDUs) + * that contain no SDU. + */ + + pdcp_p->last_submitted_pdcp_rx_sn = sequence_number; + + break; + } /* case RLC_MODE_AM */ + + case RLC_MODE_UM: + /* process as described in 36.323 5.1.2.1.3 */ + if (sequence_number < pdcp_p->next_pdcp_rx_sn) { + pdcp_p->rx_hfn++; + } + rx_hfn_for_count = pdcp_p->rx_hfn; + pdcp_sn_for_count = sequence_number; + pdcp_p->next_pdcp_rx_sn = sequence_number + 1; + if (pdcp_p->next_pdcp_rx_sn > pdcp_p->maximum_pdcp_rx_sn) { + pdcp_p->next_pdcp_rx_sn = 0; + pdcp_p->rx_hfn++; + } + + if (pdcp_p->security_activated == 1) { + if (ctxt_pP->enb_flag == ENB_FLAG_NO) { + start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].validate_security); + } else { + start_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); + } + + security_ok = pdcp_validate_security(ctxt_pP, + pdcp_p, + srb_flagP, + rb_idP, + pdcp_header_len, + rx_hfn_for_count, + pdcp_sn_for_count, + sdu_buffer_pP->data, + sdu_buffer_sizeP - pdcp_tailer_len) == 0; + + if (ctxt_pP->enb_flag == ENB_FLAG_NO) { + stop_meas(&eNB_pdcp_stats[ctxt_pP->module_id].validate_security); + } else { + stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); + } + } else { + security_ok = 1; + } + + if (security_ok == 0) { + LOG_W(PDCP, + PROTOCOL_PDCP_CTXT_FMT"security not validated for incoming PDPC DRB RLC/UM PDU\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p)); + LOG_W(PDCP, "Ignoring PDU...\n"); + free_mem_block(sdu_buffer_pP, __func__); + /* TODO: indicate integrity verification failure to upper layer */ + return FALSE; + } + + break; + + default: + LOG_E(PDCP, "bad RLC mode, cannot happen.\n"); + exit(1); + } /* switch (pdcp_p->rlc_mode) */ + } else { /* MBMS_flagP == 0 */ payload_offset=0; } @@ -1569,22 +1705,23 @@ pdcp_config_req_asn1 ( pdcp_pP->status_report = rb_reportP; if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) { - pdcp_pP->seq_num_size = PDCP_SN_12BIT; + pdcp_pP->seq_num_size = 12; + pdcp_pP->maximum_pdcp_rx_sn = (1 << 12) - 1; } else if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) { - pdcp_pP->seq_num_size = PDCP_SN_7BIT; + pdcp_pP->seq_num_size = 7; + pdcp_pP->maximum_pdcp_rx_sn = (1 << 7) - 1; } else { - pdcp_pP->seq_num_size = PDCP_SN_5BIT; + pdcp_pP->seq_num_size = 5; + pdcp_pP->maximum_pdcp_rx_sn = (1 << 5) - 1; } pdcp_pP->rlc_mode = rlc_modeP; pdcp_pP->next_pdcp_tx_sn = 0; pdcp_pP->next_pdcp_rx_sn = 0; - pdcp_pP->next_pdcp_rx_sn_before_integrity = 0; pdcp_pP->tx_hfn = 0; pdcp_pP->rx_hfn = 0; pdcp_pP->last_submitted_pdcp_rx_sn = 4095; pdcp_pP->first_missing_pdu = -1; - pdcp_pP->rx_hfn_offset = 0; LOG_I(PDCP, PROTOCOL_PDCP_CTXT_FMT" Action ADD LCID %d (%s id %d) " "configured with SN size %d bits and RLC %s\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h index 69157b6398..3a96c2fee4 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h @@ -164,13 +164,12 @@ typedef struct pdcp_s { */ pdcp_sn_t next_pdcp_tx_sn; pdcp_sn_t next_pdcp_rx_sn; - pdcp_sn_t next_pdcp_rx_sn_before_integrity; + pdcp_sn_t maximum_pdcp_rx_sn; /* * TX and RX Hyper Frame Numbers */ pdcp_hfn_t tx_hfn; pdcp_hfn_t rx_hfn; - pdcp_hfn_offset_t rx_hfn_offset; // related to sn mismatch /* * SN of the last PDCP SDU delivered to upper layers @@ -479,14 +478,6 @@ typedef struct { #define REORDERING_WINDOW_SN_7BIT 64 #define REORDERING_WINDOW_SN_12BIT 2048 -/* - * SN size - */ -#define PDCP_SN_5BIT 5 -#define PDCP_SN_7BIT 7 -#define PDCP_SN_12BIT 12 - - signed int pdcp_2_nas_irq; pdcp_stats_t UE_pdcp_stats[MAX_MOBILES_PER_ENB]; pdcp_stats_t eNB_pdcp_stats[NUMBER_OF_eNB_MAX]; diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_primitives.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp_primitives.h index 8e57f84b0a..8b5ebe7287 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_primitives.h +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_primitives.h @@ -173,7 +173,6 @@ int pdcp_netlink_dequeue_element(const protocol_ctxt_t* const ctxt_pP, void pdcp_config_set_security(const protocol_ctxt_t* const ctxt_pP, pdcp_t *pdcp_pP, rb_id_t rb_idP, uint16_t lc_idP, uint8_t security_modeP, uint8_t *kRRCenc_pP, uint8_t *kRRCint_pP, uint8_t *kUPenc_pP); -#if defined(ENABLE_SECURITY) int pdcp_apply_security(const protocol_ctxt_t* const ctxt_pP, pdcp_t *pdcp_entity, srb_flag_t srb_flagP, @@ -188,10 +187,10 @@ int pdcp_validate_security(const protocol_ctxt_t* const ctxt_pP, srb_flag_t srb_flagP, rb_id_t rb_id, uint8_t pdcp_header_len, - uint16_t current_sn, + uint32_t hfn, + int sn, uint8_t *pdcp_pdu_buffer, uint16_t sdu_buffer_size); -#endif /* defined(ENABLE_SECURITY) */ #endif /** @}*/ diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c index 83293a709d..1528373e98 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c @@ -40,13 +40,6 @@ #include "msc.h" #include "pdcp_primitives.h" -#if defined(ENABLE_SECURITY) - -static -uint32_t pdcp_get_next_count_tx(pdcp_t *const pdcp_pP, const srb_flag_t srb_flagP, const uint16_t pdcp_sn); -static -uint32_t pdcp_get_next_count_rx(pdcp_t *const pdcp_pP, const srb_flag_t srb_flagP, const uint16_t pdcp_sn); - //----------------------------------------------------------------------------- static uint32_t pdcp_get_next_count_tx( @@ -79,26 +72,25 @@ static uint32_t pdcp_get_next_count_rx( pdcp_t * const pdcp_pP, const srb_flag_t srb_flagP, - const uint16_t pdcp_sn) + const uint32_t hfn, + const int sn) { uint32_t count; /* For RX COUNT = RX_HFN << length of SN | pdcp SN of received PDU */ if (srb_flagP) { /* 5 bits length SN */ - count = (((pdcp_pP->rx_hfn + pdcp_pP->rx_hfn_offset) << 5) | (pdcp_sn & 0x001F)); + count = (hfn << 5) | (sn & 0x001F); } else { - if (pdcp_pP->seq_num_size == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) { + if (pdcp_pP->seq_num_size == 7) { /* 7 bits length SN */ - count = (((pdcp_pP->rx_hfn + pdcp_pP->rx_hfn_offset) << 7) | (pdcp_sn & 0x007F)); + count = (hfn << 7) | (sn & 0x007F); } else { // default /* 12 bits length SN */ - count = (((pdcp_pP->rx_hfn + pdcp_pP->rx_hfn_offset) << 12) | (pdcp_sn & 0x0FFF)); + count = (hfn << 12) | (sn & 0x0FFF); } } - // reset the hfn offset - pdcp_pP->rx_hfn_offset =0; LOG_D(PDCP, "[OSA] RX COUNT = 0x%08x\n", count); return count; @@ -182,7 +174,8 @@ pdcp_validate_security( const srb_flag_t srb_flagP, const rb_id_t rb_id, const uint8_t pdcp_header_len, - const uint16_t current_sn, + const uint32_t hfn, + const int sn, uint8_t *const pdcp_pdu_buffer, const uint16_t sdu_buffer_size ) @@ -201,7 +194,7 @@ pdcp_validate_security( decrypt_params.direction = (pdcp_pP->is_ue == 1) ? SECU_DIRECTION_DOWNLINK : SECU_DIRECTION_UPLINK ; decrypt_params.bearer = rb_id - 1; - decrypt_params.count = pdcp_get_next_count_rx(pdcp_pP, srb_flagP, current_sn); + decrypt_params.count = pdcp_get_next_count_rx(pdcp_pP, srb_flagP, hfn, sn); decrypt_params.message = &pdcp_pdu_buffer[pdcp_header_len]; decrypt_params.blength = (sdu_buffer_size - pdcp_header_len) << 3; decrypt_params.key_length = 16; @@ -246,5 +239,3 @@ pdcp_validate_security( return 0; } - -#endif /* ENABLE_SECURITY */ diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.c index c6deb49441..cdc583ef21 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.c @@ -140,152 +140,6 @@ boolean_t pdcp_advance_rx_window(pdcp_t* pdcp_entity) return TRUE; } -/** - * Checks if incoming PDU has a sequence number in accordance with the RX window - * @return 1 if SN is okay, 0 otherwise - * XXX Reordering window should also be handled here - */ -boolean_t pdcp_is_rx_seq_number_valid(uint16_t seq_num, pdcp_t* pdcp_entity,srb_flag_t srb_flagP) -{ - - uint16_t reordering_window = 0; - - LOG_D(PDCP, "Incoming RX Sequence number is %04d\n", seq_num); - - if (pdcp_is_seq_num_size_valid(pdcp_entity) == FALSE || pdcp_is_seq_num_valid(seq_num, pdcp_entity->seq_num_size) == FALSE) { - return FALSE; - } - - /* - * Mark received sequence numbers to keep track of missing ones - * (and to build PDCP Control PDU for PDCP status report) - */ - if (pdcp_mark_current_pdu_as_received(seq_num, pdcp_entity) == TRUE) { - LOG_D(PDCP, "Received sequence number successfuly marked\n"); - } else { - LOG_W(PDCP, "Cannot mark received sequence number on the bitmap!\n"); - } - - /* - * RX Procedures for SRB and DRBs as described in sec 5.1.2 of 36.323 - */ - - if (srb_flagP) { // SRB - - if (seq_num < pdcp_entity->next_pdcp_rx_sn) { - // decipher and verify the integrity of the PDU (if applicable) using COUNT based on RX_HFN + 1 and the received PDCP SN - pdcp_entity->rx_hfn++; - pdcp_entity->rx_hfn_offset = 0; - } else { - // decipher and verify the integrity of the PDU (if applicable) using COUNT based using COUNT based on RX_HFN and the received PDCP SN - pdcp_entity->rx_hfn_offset = 0; - } - - // Assume that integrity verification is applicable and the integrity verification is passed successfully; - // or assume that integrity verification is not applicable: - - // same the old next_pdcp_rx_sn to revert otherwise - pdcp_entity->next_pdcp_rx_sn_before_integrity = pdcp_entity->next_pdcp_rx_sn; - - if (seq_num != pdcp_entity->next_pdcp_rx_sn) { - LOG_D(PDCP,"Re-adjusting the sequence number to %d\n", seq_num); - } - - //set Next_PDCP_RX_SN to the received PDCP SN +1 ; - pdcp_entity->next_pdcp_rx_sn = seq_num; - pdcp_advance_rx_window(pdcp_entity); // + 1, and check if it is larger than Maximum_PDCP_SN: - - } else { // DRB - - if (pdcp_entity->seq_num_size == PDCP_SN_7BIT) { - reordering_window = REORDERING_WINDOW_SN_7BIT; - } else { - reordering_window = REORDERING_WINDOW_SN_12BIT; - } - - switch (pdcp_entity->rlc_mode) { - case RLC_MODE_AM: - if ((seq_num - pdcp_entity->last_submitted_pdcp_rx_sn > reordering_window) || - ((0 <= pdcp_entity->last_submitted_pdcp_rx_sn - seq_num) && - (pdcp_entity->last_submitted_pdcp_rx_sn - seq_num < reordering_window) )) { - - if (seq_num > pdcp_entity->next_pdcp_rx_sn) { - /* - * decipher the PDCP PDU as specified in the subclause 5.6, using COUNT based on RX_HFN - 1 and the received PDCP SN; - */ - pdcp_entity->rx_hfn_offset = -1; - } else { - /* - * decipher the PDCP PDU as specified in the subclause 5.6, using COUNT based on RX_HFN and the received PDCP SN; - */ - pdcp_entity->rx_hfn_offset = 0; - } - - // discard this PDCP SDU; - LOG_W(PDCP, "Out of the reordering window (Incoming SN:%d, Expected SN:%d): discard this PDCP SDU\n", - seq_num, pdcp_entity->next_pdcp_rx_sn); - return FALSE; - } else if (pdcp_entity->next_pdcp_rx_sn - seq_num > reordering_window) { - pdcp_entity->rx_hfn++; - // use COUNT based on RX_HFN and the received PDCP SN for deciphering the PDCP PDU; - pdcp_entity->rx_hfn_offset = 0; - pdcp_entity->next_pdcp_rx_sn++; - } else if (seq_num - pdcp_entity->next_pdcp_rx_sn >= reordering_window ) { - // use COUNT based on RX_HFN – 1 and the received PDCP SN for deciphering the PDCP PDU; - pdcp_entity->rx_hfn_offset = -1; - } else if (seq_num >= pdcp_entity->next_pdcp_rx_sn ) { - // use COUNT based on RX_HFN and the received PDCP SN for deciphering the PDCP PDU; - pdcp_entity->rx_hfn_offset = 0; - //set Next_PDCP_RX_SN to the received PDCP SN +1 ; - pdcp_entity->next_pdcp_rx_sn = seq_num; - pdcp_advance_rx_window(pdcp_entity); // + 1, anc check if it is larger than Maximum_PDCP_SN: - LOG_D(PDCP,"Re-adjusting the sequence number to %d\n", seq_num); - } else if (seq_num < pdcp_entity->next_pdcp_rx_sn) { - // use COUNT based on RX_HFN and the received PDCP SN for deciphering the PDCP PDU; - pdcp_entity->rx_hfn_offset = 0; - } - - break; - - case RLC_MODE_UM : - if (seq_num < pdcp_entity->next_pdcp_rx_sn) { - pdcp_entity->rx_hfn++; - } - - // decipher the PDCP Data PDU using COUNT based on RX_HFN and the received PDCP SN as specified in the subclause 5.6; - //set Next_PDCP_RX_SN to the received PDCP SN +1 ; - pdcp_entity->next_pdcp_rx_sn = seq_num; - pdcp_advance_rx_window(pdcp_entity); // + 1, and check if it is larger than Maximum_PDCP_SN: - - break; - - case RLC_MODE_TM : - default: - LOG_W(PDCP,"RLC mode %d not supported\n",pdcp_entity->rlc_mode); - return FALSE; - } - } - - /* - if (seq_num == pdcp_entity->next_pdcp_rx_sn) { - LOG_I(PDCP, "Next expected SN (%d) arrived, advancing RX window\n", seq_num); - - return pdcp_advance_rx_window(pdcp_entity); - } else { - LOG_E(PDCP, "Incoming SN is not the one we expected to receive! (Incoming:%d, Expected:%d)\n", \ - seq_num, pdcp_entity->next_pdcp_rx_sn); - - - // Update first missing PDU (used in PDCP Control PDU for PDCP status report, see 6.2.6) - if (pdcp_entity->first_missing_pdu != -1) - pdcp_entity->first_missing_pdu = pdcp_entity->next_pdcp_rx_sn; - - return FALSE; - } - */ - return TRUE; -} - boolean_t pdcp_mark_current_pdu_as_received(uint16_t seq_num, pdcp_t* pdcp_entity) { /* diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.h index ec59a4b4fe..172c9810e6 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.h +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.h @@ -59,11 +59,6 @@ uint16_t pdcp_get_next_tx_seq_number(pdcp_t* pdcp_entity); * Advances the RX window state of given PDCP entity upon successfull receipt of a SDU */ boolean_t pdcp_advance_rx_window(pdcp_t* pdcp_entity); -/** - * Checks if incoming PDU has a sequence number in accordance with the RX window - * @return TRUE if it is valid, FALSE otherwise - */ -boolean_t pdcp_is_rx_seq_number_valid(uint16_t seq_num, pdcp_t* pdcp_entity,srb_flag_t srb_flagP); /** * Updates missing PDU bitmap with incoming sequence number * @return TRUE if successful, FALSE otherwise diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.c b/openair2/RRC/LTE/MESSAGES/asn1_msg.c index b8cfad9cca..09c051a62d 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg.c +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.c @@ -3724,7 +3724,6 @@ do_RRCConnectionReestablishment( rrc->carrier[CC_id].dl_CarrierFreq, earfcn_dl, is_rel8_only == true ? "true": "false"); -#if defined(ENABLE_SECURITY) if (ue_context_pP->ue_context.nh_ncc >= 0) { derive_keNB_star(ue_context_pP->ue_context.nh, pci, earfcn_dl, is_rel8_only, KeNB_star); @@ -3738,9 +3737,6 @@ do_RRCConnectionReestablishment( // copy KeNB_star to ue_context_pP->ue_context.kenb memcpy (ue_context_pP->ue_context.kenb, KeNB_star, 32); ue_context_pP->ue_context.kenb_ncc = 0; -#else - rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.nextHopChainingCount = 0; -#endif rrcConnectionReestablishment->criticalExtensions.choice.c1.choice.rrcConnectionReestablishment_r8.nonCriticalExtension = NULL; if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { diff --git a/openair2/RRC/LTE/defs_NB_IoT.h b/openair2/RRC/LTE/defs_NB_IoT.h index 160d92a610..6d36fa1959 100644 --- a/openair2/RRC/LTE/defs_NB_IoT.h +++ b/openair2/RRC/LTE/defs_NB_IoT.h @@ -273,10 +273,8 @@ typedef struct eNB_RRC_UE_NB_IoT_s { SRB_INFO_TABLE_ENTRY_NB_IoT Srb1; SRB_INFO_TABLE_ENTRY_NB_IoT Srb1bis; -#if defined(ENABLE_SECURITY) /* KeNB as derived from KASME received from EPC */ uint8_t kenb[32]; -#endif /* Used integrity/ciphering algorithms--> maintained the same for NB-IoT */ e_LTE_CipheringAlgorithm_r12 ciphering_algorithm; //Specs. TS 36.331 V14.1.0 pag 432 Change position of chipering enumerative w.r.t previous version @@ -555,10 +553,8 @@ typedef struct UE_RRC_INST_NB_IoT_s { obj_hash_table_t *ral_meas_thresholds; ral_transaction_id_t scan_transaction_id; #endif -#if defined(ENABLE_SECURITY) // KeNB as computed from parameters within USIM card // uint8_t kenb[32]; -#endif // Used integrity/ciphering algorithms // CipheringAlgorithm_r12_t ciphering_algorithm; diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c index 49f9e16740..e527314f43 100644 --- a/openair2/RRC/LTE/rrc_UE.c +++ b/openair2/RRC/LTE/rrc_UE.c @@ -69,9 +69,7 @@ #include "rrc_UE_ral.h" #endif -#if defined(ENABLE_SECURITY) - #include "UTIL/OSA/osa_defs.h" -#endif +#include "UTIL/OSA/osa_defs.h" #include "pdcp.h" #include "plmn_data.h" @@ -428,7 +426,6 @@ void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index ) { //----------------------------------------------------------------------------- void openair_rrc_ue_init_security( const protocol_ctxt_t *const ctxt_pP ) { -#if defined(ENABLE_SECURITY) // uint8_t *kRRCenc; // uint8_t *kRRCint; char ascii_buffer[65]; @@ -442,7 +439,6 @@ void openair_rrc_ue_init_security( const protocol_ctxt_t *const ctxt_pP ) { LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT"[OSA] kenb = %s\n", PROTOCOL_RRC_CTXT_ARGS(ctxt_pP), ascii_buffer); -#endif } //----------------------------------------------------------------------------- @@ -1309,12 +1305,10 @@ rrc_ue_process_radioResourceConfigDedicated( if (radioResourceConfigDedicated->srb_ToAddModList) { uint8_t *kRRCenc = NULL; uint8_t *kRRCint = NULL; -#if defined(ENABLE_SECURITY) derive_key_rrc_enc(UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm, UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCenc); derive_key_rrc_int(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm, UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCint); -#endif // Refresh SRBs rrc_pdcp_config_asn1_req(ctxt_pP, radioResourceConfigDedicated->srb_ToAddModList, @@ -1487,10 +1481,8 @@ rrc_ue_process_radioResourceConfigDedicated( } uint8_t *kUPenc = NULL; -#if defined(ENABLE_SECURITY) derive_key_up_enc(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm, UE_rrc_inst[ctxt_pP->module_id].kenb, &kUPenc); -#endif MSC_LOG_TX_MESSAGE( MSC_RRC_UE, MSC_PDCP_UE, @@ -1665,7 +1657,6 @@ rrc_ue_process_securityModeCommand( ul_dcch_msg.message.choice.c1.present = LTE_UL_DCCH_MessageType__c1_PR_securityModeFailure; } -#if defined(ENABLE_SECURITY) uint8_t *kRRCenc = NULL; uint8_t *kUPenc = NULL; uint8_t *kRRCint = NULL; @@ -1715,8 +1706,6 @@ rrc_ue_process_securityModeCommand( LOG_I(RRC, "Could not get PDCP instance where key=0x%ld\n", key); } -#endif //#if defined(ENABLE_SECURITY) - if (securityModeCommand->criticalExtensions.present == LTE_SecurityModeCommand__criticalExtensions_PR_c1) { if (securityModeCommand->criticalExtensions.choice.c1.present != LTE_SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8) LOG_W(RRC,"securityModeCommand->criticalExtensions.choice.c1.present (%d) != SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8\n", diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h index 6b616546bf..07665e354a 100644 --- a/openair2/RRC/LTE/rrc_defs.h +++ b/openair2/RRC/LTE/rrc_defs.h @@ -554,13 +554,11 @@ typedef struct eNB_RRC_UE_s { int UE_Capability_size; ImsiMobileIdentity_t imsi; -#if defined(ENABLE_SECURITY) /* KeNB as derived from KASME received from EPC */ uint8_t kenb[32]; int8_t kenb_ncc; uint8_t nh[32]; int8_t nh_ncc; -#endif /* Used integrity/ciphering algorithms */ LTE_CipheringAlgorithm_r12_t ciphering_algorithm; e_LTE_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm; @@ -838,12 +836,10 @@ typedef struct UE_RRC_INST_s { float rsrq_db[7]; float rsrp_db_filtered[7]; float rsrq_db_filtered[7]; -#if defined(ENABLE_SECURITY) /* KeNB as computed from parameters within USIM card */ uint8_t kenb[32]; uint8_t nh[32]; int8_t nh_ncc; -#endif /* Used integrity/ciphering algorithms */ LTE_CipheringAlgorithm_r12_t ciphering_algorithm; diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c index 5a30ad4822..10228fade6 100644 --- a/openair2/RRC/LTE/rrc_eNB.c +++ b/openair2/RRC/LTE/rrc_eNB.c @@ -75,9 +75,7 @@ #include "OCG.h" #include "OCG_extern.h" -#if defined(ENABLE_SECURITY) - #include "UTIL/OSA/osa_defs.h" -#endif +#include "UTIL/OSA/osa_defs.h" #if defined(ENABLE_USE_MME) #include "rrc_eNB_S1AP.h" @@ -844,9 +842,7 @@ rrc_eNB_free_mem_UE_context( } //HANDOVER_INFO *handover_info; -#if defined(ENABLE_SECURITY) //uint8_t kenb[32]; -#endif //e_SecurityAlgorithmConfig__cipheringAlgorithm ciphering_algorithm; //e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm; //uint8_t Status; @@ -6312,7 +6308,6 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete( LTE_DRB_Identity_t *drb_id_p = NULL; T(T_ENB_RRC_CONNECTION_RECONFIGURATION_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame), T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti)); -#if defined(ENABLE_SECURITY) /* Derive the keys from kenb */ if (DRB_configList != NULL) { @@ -6324,7 +6319,6 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete( ue_context_pP->ue_context.kenb, &kRRCenc); derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm, ue_context_pP->ue_context.kenb, &kRRCint); -#endif // Refresh SRBs/DRBs MSC_LOG_TX_MESSAGE( MSC_RRC_ENB, diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.c b/openair2/RRC/LTE/rrc_eNB_S1AP.c index 5bfa8c443b..000db7a570 100644 --- a/openair2/RRC/LTE/rrc_eNB_S1AP.c +++ b/openair2/RRC/LTE/rrc_eNB_S1AP.c @@ -52,9 +52,7 @@ #include "../../S1AP/s1ap_eNB.h" #endif -#if defined(ENABLE_SECURITY) - #include "UTIL/OSA/osa_defs.h" -#endif +#include "UTIL/OSA/osa_defs.h" #include "msc.h" #include "LTE_UERadioAccessCapabilityInformation.h" @@ -493,7 +491,6 @@ static void process_eNB_security_key ( ) //------------------------------------------------------------------------------ { -#if defined(ENABLE_SECURITY) char ascii_buffer[65]; uint8_t i; /* Saves the security key */ @@ -507,7 +504,6 @@ static void process_eNB_security_key ( ascii_buffer[2 * i] = '\0'; LOG_I (RRC, "[eNB %d][UE %x] Saved security key %s\n", ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ascii_buffer); -#endif } @@ -520,7 +516,6 @@ rrc_pdcp_config_security( ) //------------------------------------------------------------------------------ { -#if defined(ENABLE_SECURITY) LTE_SRB_ToAddModList_t *SRB_configList = ue_context_pP->ue_context.SRB_configList; uint8_t *kRRCenc = NULL; uint8_t *kRRCint = NULL; @@ -578,8 +573,6 @@ rrc_pdcp_config_security( PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), DCCH); } - -#endif } //------------------------------------------------------------------------------ diff --git a/targets/Makefile.common b/targets/Makefile.common index ac0771770b..ecd5f3821a 100644 --- a/targets/Makefile.common +++ b/targets/Makefile.common @@ -45,7 +45,6 @@ ifeq ($(OPENSSL_FOUND), 0) @(warning "openssl library is not installed on your system, openssl lib needed, continuing with security disabled") SECU=0 else -CFLAGS += -DENABLE_SECURITY LIBS += $(OPENSSL_LIBS) $(NETTLE_LIBS) endif endif