From f4fd6034ba50af27523a400184267423776424a0 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 26 Apr 2019 17:23:50 +0100 Subject: [PATCH] Starting to add separate functions for PDCP handling for UM DRBs and AM DRBs --- lib/include/srslte/upper/pdcp_entity.h | 36 ++++++------ lib/src/upper/pdcp_entity.cc | 80 +++++++++++++++++++------- 2 files changed, 78 insertions(+), 38 deletions(-) diff --git a/lib/include/srslte/upper/pdcp_entity.h b/lib/include/srslte/upper/pdcp_entity.h index e7cea074c..0a658c9b2 100644 --- a/lib/include/srslte/upper/pdcp_entity.h +++ b/lib/include/srslte/upper/pdcp_entity.h @@ -94,27 +94,33 @@ private: srsue::rrc_interface_pdcp *rrc; srsue::gw_interface_pdcp *gw; - bool active; - uint32_t lcid; + bool active; + uint32_t lcid; srslte_pdcp_config_t cfg; - uint8_t sn_len_bytes; - bool do_integrity; - bool do_encryption; - - uint32_t rx_count; - uint32_t tx_count; - uint8_t k_rrc_enc[32]; - uint8_t k_rrc_int[32]; - uint8_t k_up_enc[32]; - - uint32_t rx_hfn; - uint32_t next_pdcp_rx_sn; + uint8_t sn_len_bytes; + bool do_integrity; + bool do_encryption; + + uint32_t rx_count; + uint32_t tx_count; + uint8_t k_rrc_enc[32]; + uint8_t k_rrc_int[32]; + uint8_t k_up_enc[32]; + + uint32_t rx_hfn; + uint32_t next_pdcp_rx_sn; + uint32_t reordering_window; CIPHERING_ALGORITHM_ID_ENUM cipher_algo; INTEGRITY_ALGORITHM_ID_ENUM integ_algo; + uint32_t maximum_pdcp_sn; + pthread_mutex_t mutex; + void handle_um_drb_pdu(srslte::byte_buffer_t *pdu); + void handle_am_drb_pdu(srslte::byte_buffer_t *pdu); + void integrity_generate(uint8_t *msg, uint32_t msg_len, uint8_t *mac); @@ -148,6 +154,4 @@ void pdcp_pack_data_pdu_long_sn(uint32_t sn, byte_buffer_t *sdu); void pdcp_unpack_data_pdu_long_sn(byte_buffer_t *sdu, uint32_t *sn); } // namespace srslte - - #endif // SRSLTE_PDCP_ENTITY_H diff --git a/lib/src/upper/pdcp_entity.cc b/lib/src/upper/pdcp_entity.cc index 71b16073e..30ce75c2a 100644 --- a/lib/src/upper/pdcp_entity.cc +++ b/lib/src/upper/pdcp_entity.cc @@ -74,6 +74,15 @@ void pdcp_entity::init(srsue::rlc_interface_pdcp *rlc_, // set length of SN field in bytes sn_len_bytes = (cfg.sn_len == 5) ? 1 : 2; + + if (cfg.is_control) { + reordering_window = 0; + } else if (cfg.is_data) { + reordering_window = 2048; + } + + maximum_pdcp_sn = (1 << cfg.sn_len) - 1; + log->info("Init %s with bearer ID: %d\n", rrc->get_rb_name(lcid).c_str(), cfg.bearer_id); } // Reestablishment procedure: 36.323 5.2 @@ -196,29 +205,12 @@ void pdcp_entity::write_pdu(unique_byte_buffer_t pdu) if (cfg.is_data) { // Handle DRB messages - uint32_t sn; - if (12 == cfg.sn_len) { - pdcp_unpack_data_pdu_long_sn(pdu.get(), &sn); + if (rlc->rb_is_um(lcid)) { + handle_um_drb_pdu(pdu); } else { - pdcp_unpack_data_pdu_short_sn(pdu.get(), &sn); - } - - if (sn < next_pdcp_rx_sn) { - rx_hfn++; + handle_am_drb_pdu(pdu); } - - uint32_t count = (rx_hfn << cfg.sn_len) | sn; - if (do_encryption) { - cipher_decrypt(pdu->msg, - count, - pdu->N_bytes, - pdu->msg); - log->debug_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", rrc->get_rb_name(lcid).c_str()); - } - next_pdcp_rx_sn = sn + 1; - - log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn); - gw->write_pdu(lcid, std::move(pdu)); + gw->write_pdu(lcid, pdu); } else { // Handle SRB messages if (cfg.is_control) { @@ -236,7 +228,7 @@ void pdcp_entity::write_pdu(unique_byte_buffer_t pdu) sn, pdu->N_bytes - 4, &(pdu->msg[pdu->N_bytes - 4]))) { - log->error_hex(pdu->msg, pdu->N_bytes, "%s Dropping PDU", rrc->get_rb_name(lcid).c_str()); + log->error_hex(pdu->msg, pdu->N_bytes, "%s Dropping PDU", rrc->get_rb_name(lcid).c_str()); goto exit; } } @@ -252,6 +244,50 @@ exit: pthread_mutex_unlock(&mutex); } +/**************************************************************************** + * Rx data/control handler functions + * Ref: 3GPP TS 36.323 v10.1.0 Section 5.1.2 + ***************************************************************************/ +// DRBs mapped on RLC UM (5.1.2.1.3) +void pdcp_entity::handle_um_drb_pdu(srslte::byte_buffer_t* pdu) +{ + uint32_t sn; + if (12 == cfg.sn_len) { + pdcp_unpack_data_pdu_long_sn(pdu, &sn); + } else { + pdcp_unpack_data_pdu_short_sn(pdu, &sn); + } + + if (sn < next_pdcp_rx_sn) { + rx_hfn++; + } + + uint32_t count = (rx_hfn << cfg.sn_len) | sn; + if (do_encryption) { + cipher_decrypt(pdu->msg, count, pdu->N_bytes, pdu->msg); + log->debug_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", rrc->get_rb_name(lcid).c_str()); + } + + next_pdcp_rx_sn = sn + 1; + if (next_pdcp_rx_sn > maximum_pdcp_sn) { + next_pdcp_rx_sn = 0; + rx_hfn++; + } + + log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn); + return; +} + +// DRBs mapped on RLC AM, without re-ordering (5.1.2.1.2) +void pdcp_entity::handle_am_drb_pdu(srslte::byte_buffer_t* pdu) +{ + handle_um_drb_pdu(pdu); //FIXME!!! + return; +} + +/**************************************************************************** + * Security functions + ***************************************************************************/ void pdcp_entity::integrity_generate( uint8_t *msg, uint32_t msg_len, uint8_t *mac)