From 31ba175b37d6447b020c3221d10eec551292b8c3 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 16 Jul 2018 17:34:24 +0200 Subject: [PATCH 1/4] add public PDCP entity interface --- lib/include/srslte/upper/pdcp_interface.h | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/include/srslte/upper/pdcp_interface.h diff --git a/lib/include/srslte/upper/pdcp_interface.h b/lib/include/srslte/upper/pdcp_interface.h new file mode 100644 index 000000000..d978651cf --- /dev/null +++ b/lib/include/srslte/upper/pdcp_interface.h @@ -0,0 +1,72 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2015 Software Radio Systems Limited + * + * \section LICENSE + * + * This file is part of the srsUE library. + * + * srsUE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsUE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ + +#ifndef SRSLTE_PDCP_INTERFACE_H +#define SRSLTE_PDCP_INTERFACE_H + +#include "srslte/common/buffer_pool.h" +#include "srslte/common/log.h" +#include "srslte/common/common.h" +#include "srslte/interfaces/ue_interfaces.h" +#include "srslte/common/security.h" +#include "srslte/common/threads.h" + + +namespace srslte { + +/**************************************************************************** + * Virtual PDCP interface common for all PDCP entities + ***************************************************************************/ +class pdcp_entity_interface +{ +public: + virtual void init(srsue::rlc_interface_pdcp *rlc_, + srsue::rrc_interface_pdcp *rrc_, + srsue::gw_interface_pdcp *gw_, + srslte::log *log_, + uint32_t lcid_, + srslte_pdcp_config_t cfg_) = 0; + virtual void reset() = 0; + virtual void reestablish() = 0; + virtual bool is_active() = 0; + + // RRC interface + virtual void write_sdu(byte_buffer_t *sdu) = 0; + virtual void config_security(uint8_t *k_enc_, + uint8_t *k_int_, + CIPHERING_ALGORITHM_ID_ENUM cipher_algo_, + INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) = 0; + virtual void enable_integrity() = 0; + virtual void enable_encryption() = 0; + + // RLC interface + void write_pdu(byte_buffer_t *pdu); +}; + +} // namespace srslte + + +#endif // SRSLTE_PDCP_INTERFACE_H From b2572044713fe0c4f8374c1b23912643b98d6d30 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 17 Jul 2018 09:53:33 +0200 Subject: [PATCH 2/4] fix public PDCP interface --- lib/include/srslte/upper/pdcp_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/include/srslte/upper/pdcp_interface.h b/lib/include/srslte/upper/pdcp_interface.h index d978651cf..9182c74ea 100644 --- a/lib/include/srslte/upper/pdcp_interface.h +++ b/lib/include/srslte/upper/pdcp_interface.h @@ -63,7 +63,7 @@ public: virtual void enable_encryption() = 0; // RLC interface - void write_pdu(byte_buffer_t *pdu); + virtual void write_pdu(byte_buffer_t *pdu) = 0; }; } // namespace srslte From 93c11e44168e7e5e3558a334974aea400d3a5a73 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 16 Jul 2018 21:17:01 +0200 Subject: [PATCH 3/4] turn PDCP array into map --- lib/include/srslte/upper/pdcp.h | 17 +-- lib/include/srslte/upper/pdcp_entity.h | 3 +- lib/include/srslte/upper/pdcp_interface.h | 1 + lib/src/upper/pdcp.cc | 133 ++++++++++++++-------- 4 files changed, 100 insertions(+), 54 deletions(-) diff --git a/lib/include/srslte/upper/pdcp.h b/lib/include/srslte/upper/pdcp.h index d4cca957a..84ddc5b5c 100644 --- a/lib/include/srslte/upper/pdcp.h +++ b/lib/include/srslte/upper/pdcp.h @@ -41,7 +41,7 @@ class pdcp { public: pdcp(); - virtual ~pdcp(){} + ~pdcp(); void init(srsue::rlc_interface_pdcp *rlc_, srsue::rrc_interface_pdcp *rrc_, srsue::gw_interface_pdcp *gw_, @@ -79,17 +79,20 @@ public: void write_pdu_bcch_dlsch(byte_buffer_t *sdu); void write_pdu_pcch(byte_buffer_t *sdu); - private: srsue::rlc_interface_pdcp *rlc; srsue::rrc_interface_pdcp *rrc; srsue::gw_interface_pdcp *gw; - log *pdcp_log; - pdcp_entity pdcp_array[SRSLTE_N_RADIO_BEARERS]; - pdcp_entity pdcp_array_mrb[SRSLTE_N_MCH_LCIDS]; - uint32_t lcid; // default LCID that is maintained active by PDCP instance - uint8_t direction; + typedef std::map pdcp_map_t; + typedef std::pair pdcp_map_pair_t; + + log *pdcp_log; + pdcp_map_t pdcp_array, pdcp_array_mrb; + + // default PDCP entity that is maintained active by PDCP instance + srslte_pdcp_config_t default_cnfg; + uint32_t default_lcid; bool valid_lcid(uint32_t lcid); bool valid_mch_lcid(uint32_t lcid); diff --git a/lib/include/srslte/upper/pdcp_entity.h b/lib/include/srslte/upper/pdcp_entity.h index de51ed1de..6586becc0 100644 --- a/lib/include/srslte/upper/pdcp_entity.h +++ b/lib/include/srslte/upper/pdcp_entity.h @@ -33,6 +33,7 @@ #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/security.h" #include "srslte/common/threads.h" +#include "pdcp_interface.h" namespace srslte { @@ -59,7 +60,7 @@ static const char pdcp_d_c_text[PDCP_D_C_N_ITEMS][20] = {"Control PDU", * PDCP Entity interface * Common interface for all PDCP entities ***************************************************************************/ -class pdcp_entity +class pdcp_entity : public pdcp_entity_interface { public: pdcp_entity(); diff --git a/lib/include/srslte/upper/pdcp_interface.h b/lib/include/srslte/upper/pdcp_interface.h index 9182c74ea..915fbe420 100644 --- a/lib/include/srslte/upper/pdcp_interface.h +++ b/lib/include/srslte/upper/pdcp_interface.h @@ -43,6 +43,7 @@ namespace srslte { class pdcp_entity_interface { public: + virtual ~pdcp_entity_interface() {}; virtual void init(srsue::rlc_interface_pdcp *rlc_, srsue::rrc_interface_pdcp *rrc_, srsue::gw_interface_pdcp *gw_, diff --git a/lib/src/upper/pdcp.cc b/lib/src/upper/pdcp.cc index e577a12ce..2d056f631 100644 --- a/lib/src/upper/pdcp.cc +++ b/lib/src/upper/pdcp.cc @@ -35,47 +35,69 @@ pdcp::pdcp() rrc = NULL; gw = NULL; pdcp_log = NULL; - lcid = 0; - direction = 0; + default_lcid = 0; +} + +pdcp::~pdcp() +{ + // destroy all remaining entities + for (pdcp_map_t::iterator it = pdcp_array.begin(); it != pdcp_array.end(); ++it) { + delete(it->second); + } + pdcp_array.clear(); } void pdcp::init(srsue::rlc_interface_pdcp *rlc_, srsue::rrc_interface_pdcp *rrc_, srsue::gw_interface_pdcp *gw_, log *pdcp_log_, uint32_t lcid_, uint8_t direction_) { - rlc = rlc_; - rrc = rrc_; - gw = gw_; - pdcp_log = pdcp_log_; - lcid = lcid_; - direction = direction_; + rlc = rlc_; + rrc = rrc_; + gw = gw_; + pdcp_log = pdcp_log_; + default_lcid = lcid_; // Default config - srslte_pdcp_config_t cnfg; - cnfg.is_control = false; - cnfg.is_data = false; - cnfg.direction = direction_; + default_cnfg.is_control = false; + default_cnfg.is_data = false; + default_cnfg.direction = direction_; - pdcp_array[0].init(rlc, rrc, gw, pdcp_log, lcid, cnfg); + // create default PDCP entity for SRB0 + if (not pdcp_array.insert(pdcp_map_pair_t(0, new pdcp_entity())).second) { + pdcp_log->error("Error inserting PDCP entity in to array\n."); + return; + } + pdcp_array.at(0)->init(rlc, rrc, gw, pdcp_log, default_lcid, default_cnfg); } void pdcp::stop() { + // destroy default entity + if (valid_lcid(0)) { + pdcp_map_t::iterator it; + it = pdcp_array.find(0); + delete(it->second); + pdcp_array.erase(it); + } } void pdcp::reestablish() { - for(uint32_t i=0;ireestablish(); } } } void pdcp::reset() { - for(uint32_t i=0;ireset(); + } } - pdcp_array[0].init(rlc, rrc, gw, pdcp_log, lcid, direction); + if (valid_lcid(0)) { + pdcp_array.at(0)->init(rlc, rrc, gw, pdcp_log, default_lcid, default_cnfg); + } } /******************************************************************************* @@ -83,17 +105,20 @@ void pdcp::reset() *******************************************************************************/ bool pdcp::is_drb_enabled(uint32_t lcid) { - if(lcid >= SRSLTE_N_RADIO_BEARERS) { + if (lcid >= SRSLTE_N_RADIO_BEARERS) { pdcp_log->error("Radio bearer id must be in [0:%d] - %d\n", SRSLTE_N_RADIO_BEARERS, lcid); return false; } - return pdcp_array[lcid].is_active(); + if (pdcp_array.find(lcid) == pdcp_array.end()) { + return false; + } + return pdcp_array.at(lcid)->is_active(); } void pdcp::write_sdu(uint32_t lcid, byte_buffer_t *sdu) { - if(valid_lcid(lcid)) { - pdcp_array[lcid].write_sdu(sdu); + if (valid_lcid(lcid)) { + pdcp_array.at(lcid)->write_sdu(sdu); } else { pdcp_log->warning("Writing sdu: lcid=%d. Deallocating sdu\n", lcid); byte_buffer_pool::get_instance()->deallocate(sdu); @@ -102,18 +127,23 @@ void pdcp::write_sdu(uint32_t lcid, byte_buffer_t *sdu) void pdcp::write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu) { - if(valid_mch_lcid(lcid)){ - pdcp_array_mrb[lcid].write_sdu(sdu); + if (valid_mch_lcid(lcid)){ + pdcp_array_mrb.at(lcid)->write_sdu(sdu); } } void pdcp::add_bearer(uint32_t lcid, srslte_pdcp_config_t cfg) { - if(lcid >= SRSLTE_N_RADIO_BEARERS) { + if (lcid >= SRSLTE_N_RADIO_BEARERS) { pdcp_log->error("Radio bearer id must be in [0:%d] - %d\n", SRSLTE_N_RADIO_BEARERS, lcid); return; } - if (!pdcp_array[lcid].is_active()) { - pdcp_array[lcid].init(rlc, rrc, gw, pdcp_log, lcid, cfg); + + if (not valid_lcid(lcid)) { + if (not pdcp_array.insert(pdcp_map_pair_t(lcid, new pdcp_entity())).second) { + pdcp_log->error("Error inserting PDCP entity in to array\n."); + return; + } + pdcp_array.at(lcid)->init(rlc, rrc, gw, pdcp_log, lcid, cfg); pdcp_log->info("Added bearer %s\n", rrc->get_rb_name(lcid).c_str()); } else { pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str()); @@ -123,12 +153,16 @@ void pdcp::add_bearer(uint32_t lcid, srslte_pdcp_config_t cfg) void pdcp::add_bearer_mrb(uint32_t lcid, srslte_pdcp_config_t cfg) { - if(lcid >= SRSLTE_N_RADIO_BEARERS) { + if (lcid >= SRSLTE_N_RADIO_BEARERS) { pdcp_log->error("Radio bearer id must be in [0:%d] - %d\n", SRSLTE_N_RADIO_BEARERS, lcid); return; } - if (!pdcp_array_mrb[lcid].is_active()) { - pdcp_array_mrb[lcid].init(rlc, rrc, gw, pdcp_log, lcid, cfg); + if (not valid_mch_lcid(lcid)) { + if (pdcp_array_mrb.insert(pdcp_map_pair_t(lcid, new pdcp_entity())).second) { + pdcp_log->error("Error inserting PDCP entity in to array\n."); + return; + } + pdcp_array_mrb.at(lcid)->init(rlc, rrc, gw, pdcp_log, lcid, cfg); pdcp_log->info("Added bearer %s\n", rrc->get_rb_name(lcid).c_str()); } else { pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str()); @@ -141,8 +175,9 @@ void pdcp::config_security(uint32_t lcid, CIPHERING_ALGORITHM_ID_ENUM cipher_algo, INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { - if(valid_lcid(lcid)) - pdcp_array[lcid].config_security(k_enc, k_int, cipher_algo, integ_algo); + if (valid_lcid(lcid)) { + pdcp_array.at(lcid)->config_security(k_enc, k_int, cipher_algo, integ_algo); + } } void pdcp::config_security_all(uint8_t *k_enc, @@ -151,22 +186,24 @@ void pdcp::config_security_all(uint8_t *k_enc, INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { for(uint32_t i=0;iis_active()) { + pdcp_array.at(i)->config_security(k_enc, k_int, cipher_algo, integ_algo); } } } void pdcp::enable_integrity(uint32_t lcid) { - if(valid_lcid(lcid)) - pdcp_array[lcid].enable_integrity(); + if (valid_lcid(lcid)) { + pdcp_array.at(lcid)->enable_integrity(); + } } void pdcp::enable_encryption(uint32_t lcid) { - if(valid_lcid(lcid)) - pdcp_array[lcid].enable_encryption(); + if (valid_lcid(lcid)) { + pdcp_array.at(lcid)->enable_encryption(); + } } /******************************************************************************* @@ -174,8 +211,8 @@ void pdcp::enable_encryption(uint32_t lcid) *******************************************************************************/ void pdcp::write_pdu(uint32_t lcid, byte_buffer_t *pdu) { - if(valid_lcid(lcid)) { - pdcp_array[lcid].write_pdu(pdu); + if (valid_lcid(lcid)) { + pdcp_array.at(lcid)->write_pdu(pdu); } else { pdcp_log->warning("Writing pdu: lcid=%d. Deallocating pdu\n", lcid); byte_buffer_pool::get_instance()->deallocate(pdu); @@ -198,7 +235,7 @@ void pdcp::write_pdu_pcch(byte_buffer_t *sdu) void pdcp::write_pdu_mch(uint32_t lcid, byte_buffer_t *sdu) { - if(0 == lcid) { + if (0 == lcid) { rrc->write_pdu_mch(lcid, sdu); } else { gw->write_pdu_mch(lcid, sdu); @@ -210,27 +247,31 @@ void pdcp::write_pdu_mch(uint32_t lcid, byte_buffer_t *sdu) *******************************************************************************/ bool pdcp::valid_lcid(uint32_t lcid) { - if(lcid >= SRSLTE_N_RADIO_BEARERS) { + if (lcid >= SRSLTE_N_RADIO_BEARERS) { pdcp_log->error("Radio bearer id must be in [0:%d] - %d", SRSLTE_N_RADIO_BEARERS, lcid); return false; } - if(!pdcp_array[lcid].is_active()) { + + if (pdcp_array.find(lcid) == pdcp_array.end()) { pdcp_log->error("PDCP entity for logical channel %d has not been activated\n", lcid); return false; } + return true; } bool pdcp::valid_mch_lcid(uint32_t lcid) { - if(lcid >= SRSLTE_N_MCH_LCIDS) { + if (lcid >= SRSLTE_N_MCH_LCIDS) { pdcp_log->error("Radio bearer id must be in [0:%d] - %d", SRSLTE_N_RADIO_BEARERS, lcid); return false; } - if(!pdcp_array_mrb[lcid].is_active()) { + + if (pdcp_array_mrb.find(lcid) == pdcp_array_mrb.end()) { pdcp_log->error("PDCP entity for logical channel %d has not been activated\n", lcid); return false; } + return true; } From 47a8b1343f6a7677c877823ba5443d3b775c3741 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 17 Jul 2018 15:27:04 +0200 Subject: [PATCH 4/4] add rwlock to PDCP --- lib/include/srslte/upper/pdcp.h | 5 ++- lib/src/upper/pdcp.cc | 65 ++++++++++++++++++++++----------- srsenb/hdr/upper/pdcp.h | 2 +- srsenb/src/upper/pdcp.cc | 2 +- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/lib/include/srslte/upper/pdcp.h b/lib/include/srslte/upper/pdcp.h index 84ddc5b5c..cd284619f 100644 --- a/lib/include/srslte/upper/pdcp.h +++ b/lib/include/srslte/upper/pdcp.h @@ -41,7 +41,7 @@ class pdcp { public: pdcp(); - ~pdcp(); + virtual ~pdcp(); void init(srsue::rlc_interface_pdcp *rlc_, srsue::rrc_interface_pdcp *rrc_, srsue::gw_interface_pdcp *gw_, @@ -78,7 +78,7 @@ public: void write_pdu_bcch_bch(byte_buffer_t *sdu); void write_pdu_bcch_dlsch(byte_buffer_t *sdu); void write_pdu_pcch(byte_buffer_t *sdu); - + private: srsue::rlc_interface_pdcp *rlc; srsue::rrc_interface_pdcp *rrc; @@ -89,6 +89,7 @@ private: log *pdcp_log; pdcp_map_t pdcp_array, pdcp_array_mrb; + pthread_rwlock_t rwlock; // default PDCP entity that is maintained active by PDCP instance srslte_pdcp_config_t default_cnfg; diff --git a/lib/src/upper/pdcp.cc b/lib/src/upper/pdcp.cc index 2d056f631..3f934f73d 100644 --- a/lib/src/upper/pdcp.cc +++ b/lib/src/upper/pdcp.cc @@ -36,15 +36,20 @@ pdcp::pdcp() gw = NULL; pdcp_log = NULL; default_lcid = 0; + pthread_rwlock_init(&rwlock, NULL); } pdcp::~pdcp() { // destroy all remaining entities + pthread_rwlock_wrlock(&rwlock); for (pdcp_map_t::iterator it = pdcp_array.begin(); it != pdcp_array.end(); ++it) { delete(it->second); } pdcp_array.clear(); + + pthread_rwlock_unlock(&rwlock); + pthread_rwlock_destroy(&rwlock); } void pdcp::init(srsue::rlc_interface_pdcp *rlc_, srsue::rrc_interface_pdcp *rrc_, srsue::gw_interface_pdcp *gw_, log *pdcp_log_, uint32_t lcid_, uint8_t direction_) @@ -61,34 +66,34 @@ void pdcp::init(srsue::rlc_interface_pdcp *rlc_, srsue::rrc_interface_pdcp *rrc_ default_cnfg.direction = direction_; // create default PDCP entity for SRB0 - if (not pdcp_array.insert(pdcp_map_pair_t(0, new pdcp_entity())).second) { - pdcp_log->error("Error inserting PDCP entity in to array\n."); - return; - } - pdcp_array.at(0)->init(rlc, rrc, gw, pdcp_log, default_lcid, default_cnfg); + add_bearer(0, default_cnfg); } void pdcp::stop() { // destroy default entity + pthread_rwlock_wrlock(&rwlock); if (valid_lcid(0)) { - pdcp_map_t::iterator it; - it = pdcp_array.find(0); + pdcp_map_t::iterator it = pdcp_array.find(0); delete(it->second); pdcp_array.erase(it); } + pthread_rwlock_unlock(&rwlock); } void pdcp::reestablish() { + pthread_rwlock_rdlock(&rwlock); for (uint32_t i = 0; i < SRSLTE_N_RADIO_BEARERS; i++) { if (valid_lcid(i)) { pdcp_array.at(i)->reestablish(); } } + pthread_rwlock_unlock(&rwlock); } void pdcp::reset() { + pthread_rwlock_rdlock(&rwlock); for (uint32_t i = 0; i < SRSLTE_N_RADIO_BEARERS; i++) { if (valid_lcid(i)) { pdcp_array.at(i)->reset(); @@ -98,6 +103,7 @@ void pdcp::reset() if (valid_lcid(0)) { pdcp_array.at(0)->init(rlc, rrc, gw, pdcp_log, default_lcid, default_cnfg); } + pthread_rwlock_unlock(&rwlock); } /******************************************************************************* @@ -105,39 +111,46 @@ void pdcp::reset() *******************************************************************************/ bool pdcp::is_drb_enabled(uint32_t lcid) { + pthread_rwlock_rdlock(&rwlock); + bool ret = false; + if (lcid >= SRSLTE_N_RADIO_BEARERS) { pdcp_log->error("Radio bearer id must be in [0:%d] - %d\n", SRSLTE_N_RADIO_BEARERS, lcid); - return false; + goto unlock_and_exit; } if (pdcp_array.find(lcid) == pdcp_array.end()) { - return false; + goto unlock_and_exit; } - return pdcp_array.at(lcid)->is_active(); + ret = pdcp_array.at(lcid)->is_active(); + +unlock_and_exit: + pthread_rwlock_unlock(&rwlock); + return ret; } void pdcp::write_sdu(uint32_t lcid, byte_buffer_t *sdu) { + pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { pdcp_array.at(lcid)->write_sdu(sdu); } else { pdcp_log->warning("Writing sdu: lcid=%d. Deallocating sdu\n", lcid); byte_buffer_pool::get_instance()->deallocate(sdu); } + pthread_rwlock_unlock(&rwlock); } void pdcp::write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu) { + pthread_rwlock_rdlock(&rwlock); if (valid_mch_lcid(lcid)){ pdcp_array_mrb.at(lcid)->write_sdu(sdu); } + pthread_rwlock_unlock(&rwlock); } void pdcp::add_bearer(uint32_t lcid, srslte_pdcp_config_t cfg) { - if (lcid >= SRSLTE_N_RADIO_BEARERS) { - pdcp_log->error("Radio bearer id must be in [0:%d] - %d\n", SRSLTE_N_RADIO_BEARERS, lcid); - return; - } - + pthread_rwlock_rdlock(&rwlock); if (not valid_lcid(lcid)) { if (not pdcp_array.insert(pdcp_map_pair_t(lcid, new pdcp_entity())).second) { pdcp_log->error("Error inserting PDCP entity in to array\n."); @@ -148,17 +161,15 @@ void pdcp::add_bearer(uint32_t lcid, srslte_pdcp_config_t cfg) } else { pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str()); } + pthread_rwlock_unlock(&rwlock); } void pdcp::add_bearer_mrb(uint32_t lcid, srslte_pdcp_config_t cfg) { - if (lcid >= SRSLTE_N_RADIO_BEARERS) { - pdcp_log->error("Radio bearer id must be in [0:%d] - %d\n", SRSLTE_N_RADIO_BEARERS, lcid); - return; - } + pthread_rwlock_rdlock(&rwlock); if (not valid_mch_lcid(lcid)) { - if (pdcp_array_mrb.insert(pdcp_map_pair_t(lcid, new pdcp_entity())).second) { + if (not pdcp_array_mrb.insert(pdcp_map_pair_t(lcid, new pdcp_entity())).second) { pdcp_log->error("Error inserting PDCP entity in to array\n."); return; } @@ -167,6 +178,7 @@ void pdcp::add_bearer_mrb(uint32_t lcid, srslte_pdcp_config_t cfg) } else { pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str()); } + pthread_rwlock_unlock(&rwlock); } void pdcp::config_security(uint32_t lcid, @@ -175,9 +187,11 @@ void pdcp::config_security(uint32_t lcid, CIPHERING_ALGORITHM_ID_ENUM cipher_algo, INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { + pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { pdcp_array.at(lcid)->config_security(k_enc, k_int, cipher_algo, integ_algo); } + pthread_rwlock_unlock(&rwlock); } void pdcp::config_security_all(uint8_t *k_enc, @@ -185,25 +199,31 @@ void pdcp::config_security_all(uint8_t *k_enc, CIPHERING_ALGORITHM_ID_ENUM cipher_algo, INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { + pthread_rwlock_rdlock(&rwlock); for(uint32_t i=0;iis_active()) { pdcp_array.at(i)->config_security(k_enc, k_int, cipher_algo, integ_algo); } } + pthread_rwlock_unlock(&rwlock); } void pdcp::enable_integrity(uint32_t lcid) { + pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { pdcp_array.at(lcid)->enable_integrity(); } + pthread_rwlock_unlock(&rwlock); } void pdcp::enable_encryption(uint32_t lcid) { + pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { pdcp_array.at(lcid)->enable_encryption(); } + pthread_rwlock_unlock(&rwlock); } /******************************************************************************* @@ -211,18 +231,21 @@ void pdcp::enable_encryption(uint32_t lcid) *******************************************************************************/ void pdcp::write_pdu(uint32_t lcid, byte_buffer_t *pdu) { + pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { pdcp_array.at(lcid)->write_pdu(pdu); } else { pdcp_log->warning("Writing pdu: lcid=%d. Deallocating pdu\n", lcid); byte_buffer_pool::get_instance()->deallocate(pdu); } + pthread_rwlock_unlock(&rwlock); } void pdcp::write_pdu_bcch_bch(byte_buffer_t *sdu) { rrc->write_pdu_bcch_bch(sdu); } + void pdcp::write_pdu_bcch_dlsch(byte_buffer_t *sdu) { rrc->write_pdu_bcch_dlsch(sdu); @@ -243,7 +266,7 @@ void pdcp::write_pdu_mch(uint32_t lcid, byte_buffer_t *sdu) } /******************************************************************************* - Helpers + Helpers (Lock must be hold when calling those) *******************************************************************************/ bool pdcp::valid_lcid(uint32_t lcid) { diff --git a/srsenb/hdr/upper/pdcp.h b/srsenb/hdr/upper/pdcp.h index 9624958e4..ce6b01ca6 100644 --- a/srsenb/hdr/upper/pdcp.h +++ b/srsenb/hdr/upper/pdcp.h @@ -39,7 +39,7 @@ class pdcp : public pdcp_interface_rlc, public pdcp_interface_rrc { public: - + virtual ~pdcp() {}; void init(rlc_interface_pdcp *rlc_, rrc_interface_pdcp *rrc_, gtpu_interface_pdcp *gtpu_, srslte::log *pdcp_log_); void stop(); diff --git a/srsenb/src/upper/pdcp.cc b/srsenb/src/upper/pdcp.cc index 6f07e4ece..7f62477f9 100644 --- a/srsenb/src/upper/pdcp.cc +++ b/srsenb/src/upper/pdcp.cc @@ -56,7 +56,7 @@ void pdcp::add_user(uint16_t rnti) { pthread_rwlock_rdlock(&rwlock); if (users.count(rnti) == 0) { - srslte::pdcp *obj = new srslte::pdcp; + srslte::pdcp *obj = new srslte::pdcp; obj->init(&users[rnti].rlc_itf, &users[rnti].rrc_itf, &users[rnti].gtpu_itf, log_h, RB_ID_SRB0, SECURITY_DIRECTION_DOWNLINK); users[rnti].rlc_itf.rnti = rnti; users[rnti].gtpu_itf.rnti = rnti;