2019-04-26 12:27:38 -07:00
|
|
|
/*
|
2020-03-13 04:12:52 -07:00
|
|
|
* Copyright 2013-2020 Software Radio Systems Limited
|
2017-05-18 03:52:29 -07:00
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* This file is part of srsLTE.
|
2017-05-18 03:52:29 -07:00
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2017-05-18 03:52:29 -07:00
|
|
|
* 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.
|
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2017-05-18 03:52:29 -07:00
|
|
|
* 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/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-05-31 14:39:17 -07:00
|
|
|
#include "srslte/upper/pdcp.h"
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2017-06-01 03:25:42 -07:00
|
|
|
namespace srslte {
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2020-03-30 10:53:05 -07:00
|
|
|
pdcp::pdcp(srslte::task_handler_interface* task_executor_, const char* logname) :
|
|
|
|
task_executor(task_executor_),
|
|
|
|
pdcp_log(logname)
|
|
|
|
{
|
|
|
|
}
|
2018-07-16 12:17:01 -07:00
|
|
|
|
|
|
|
pdcp::~pdcp()
|
|
|
|
{
|
2020-03-23 06:31:33 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(cache_mutex);
|
|
|
|
valid_lcids_cached.clear();
|
|
|
|
}
|
2018-07-16 12:17:01 -07:00
|
|
|
// destroy all remaining entities
|
|
|
|
for (pdcp_map_t::iterator it = pdcp_array.begin(); it != pdcp_array.end(); ++it) {
|
2019-11-18 10:07:14 -08:00
|
|
|
delete (it->second);
|
2018-07-16 12:17:01 -07:00
|
|
|
}
|
|
|
|
pdcp_array.clear();
|
2018-07-17 06:27:04 -07:00
|
|
|
|
2018-12-30 13:57:33 -08:00
|
|
|
for (pdcp_map_t::iterator it = pdcp_array_mrb.begin(); it != pdcp_array_mrb.end(); ++it) {
|
|
|
|
delete (it->second);
|
|
|
|
}
|
|
|
|
pdcp_array_mrb.clear();
|
2018-01-31 07:48:50 -08:00
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2019-06-27 01:50:47 -07:00
|
|
|
void pdcp::init(srsue::rlc_interface_pdcp* rlc_, srsue::rrc_interface_pdcp* rrc_, srsue::gw_interface_pdcp* gw_)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2019-11-18 10:07:14 -08:00
|
|
|
rlc = rlc_;
|
|
|
|
rrc = rrc_;
|
|
|
|
gw = gw_;
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
|
2019-11-18 10:07:14 -08:00
|
|
|
void pdcp::stop() {}
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2019-11-18 10:07:14 -08:00
|
|
|
void pdcp::reestablish()
|
|
|
|
{
|
2018-07-19 01:23:15 -07:00
|
|
|
for (pdcp_map_t::iterator it = pdcp_array.begin(); it != pdcp_array.end(); ++it) {
|
|
|
|
it->second->reestablish();
|
2017-11-23 10:46:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 08:31:50 -07:00
|
|
|
void pdcp::reestablish(uint32_t lcid)
|
|
|
|
{
|
|
|
|
if (valid_lcid(lcid)) {
|
|
|
|
pdcp_array.at(lcid)->reestablish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 03:52:29 -07:00
|
|
|
void pdcp::reset()
|
|
|
|
{
|
2020-03-23 06:31:33 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(cache_mutex);
|
|
|
|
valid_lcids_cached.clear();
|
|
|
|
}
|
2018-07-25 06:08:35 -07:00
|
|
|
// destroy all bearers
|
2019-11-18 10:07:14 -08:00
|
|
|
for (pdcp_map_t::iterator it = pdcp_array.begin(); it != pdcp_array.end(); /* post increment in erase */) {
|
2018-08-06 06:48:52 -07:00
|
|
|
it->second->reset();
|
2019-11-18 10:07:14 -08:00
|
|
|
delete (it->second);
|
2018-12-14 03:01:44 -08:00
|
|
|
pdcp_array.erase(it++);
|
2018-07-16 12:17:01 -07:00
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
RRC/GW interface
|
|
|
|
*******************************************************************************/
|
2020-03-23 06:31:33 -07:00
|
|
|
|
|
|
|
// NOTE: Called from separate thread
|
2018-07-25 06:09:19 -07:00
|
|
|
bool pdcp::is_lcid_enabled(uint32_t lcid)
|
2017-09-18 05:02:31 -07:00
|
|
|
{
|
2020-03-23 06:31:33 -07:00
|
|
|
std::lock_guard<std::mutex> lock(cache_mutex);
|
|
|
|
return valid_lcids_cached.count(lcid) > 0;
|
2017-09-18 05:02:31 -07:00
|
|
|
}
|
|
|
|
|
2019-05-13 07:34:15 -07:00
|
|
|
void pdcp::write_sdu(uint32_t lcid, unique_byte_buffer_t sdu, bool blocking)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (valid_lcid(lcid)) {
|
2019-04-29 12:16:51 -07:00
|
|
|
pdcp_array.at(lcid)->write_sdu(std::move(sdu), blocking);
|
2018-03-06 03:41:44 -08:00
|
|
|
} else {
|
|
|
|
pdcp_log->warning("Writing sdu: lcid=%d. Deallocating sdu\n", lcid);
|
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
|
2019-05-13 07:34:15 -07:00
|
|
|
void pdcp::write_sdu_mch(uint32_t lcid, unique_byte_buffer_t sdu)
|
2018-05-15 07:57:23 -07:00
|
|
|
{
|
2019-11-18 10:07:14 -08:00
|
|
|
if (valid_mch_lcid(lcid)) {
|
2019-04-29 12:16:51 -07:00
|
|
|
pdcp_array_mrb.at(lcid)->write_sdu(std::move(sdu), true);
|
2018-05-15 07:57:23 -07:00
|
|
|
}
|
|
|
|
}
|
2018-08-03 07:28:06 -07:00
|
|
|
|
2019-07-25 09:31:04 -07:00
|
|
|
void pdcp::add_bearer(uint32_t lcid, pdcp_config_t cfg)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (not valid_lcid(lcid)) {
|
2020-03-30 10:53:05 -07:00
|
|
|
if (not pdcp_array.insert(pdcp_map_pair_t(lcid, new pdcp_entity_lte(rlc, rrc, gw, task_executor, pdcp_log)))
|
|
|
|
.second) {
|
2018-07-16 12:17:01 -07:00
|
|
|
pdcp_log->error("Error inserting PDCP entity in to array\n.");
|
2020-03-23 07:00:12 -07:00
|
|
|
return;
|
2018-07-16 12:17:01 -07:00
|
|
|
}
|
2019-11-18 09:32:38 -08:00
|
|
|
pdcp_array.at(lcid)->init(lcid, cfg);
|
2019-05-23 06:24:05 -07:00
|
|
|
pdcp_log->info("Add %s (lcid=%d, bearer_id=%d, sn_len=%dbits)\n",
|
|
|
|
rrc->get_rb_name(lcid).c_str(),
|
|
|
|
lcid,
|
|
|
|
cfg.bearer_id,
|
|
|
|
cfg.sn_len);
|
2020-03-23 06:31:33 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(cache_mutex);
|
|
|
|
valid_lcids_cached.insert(lcid);
|
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
} else {
|
2018-01-12 05:55:58 -08:00
|
|
|
pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str());
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 09:31:04 -07:00
|
|
|
void pdcp::add_bearer_mrb(uint32_t lcid, pdcp_config_t cfg)
|
2018-05-15 07:57:23 -07:00
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (not valid_mch_lcid(lcid)) {
|
2020-03-30 10:53:05 -07:00
|
|
|
if (not pdcp_array_mrb.insert(pdcp_map_pair_t(lcid, new pdcp_entity_lte(rlc, rrc, gw, task_executor, pdcp_log)))
|
|
|
|
.second) {
|
2018-07-16 12:17:01 -07:00
|
|
|
pdcp_log->error("Error inserting PDCP entity in to array\n.");
|
2020-03-23 07:00:12 -07:00
|
|
|
return;
|
2018-07-16 12:17:01 -07:00
|
|
|
}
|
2019-11-18 10:07:14 -08:00
|
|
|
pdcp_array_mrb.at(lcid)->init(lcid, cfg);
|
2019-05-23 06:24:05 -07:00
|
|
|
pdcp_log->info("Add %s (lcid=%d, bearer_id=%d, sn_len=%dbits)\n",
|
|
|
|
rrc->get_rb_name(lcid).c_str(),
|
|
|
|
lcid,
|
|
|
|
cfg.bearer_id,
|
|
|
|
cfg.sn_len);
|
2018-05-15 07:57:23 -07:00
|
|
|
} else {
|
|
|
|
pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-03 07:28:06 -07:00
|
|
|
void pdcp::del_bearer(uint32_t lcid)
|
|
|
|
{
|
2020-03-23 06:31:33 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(cache_mutex);
|
|
|
|
valid_lcids_cached.erase(lcid);
|
|
|
|
}
|
2018-08-03 07:28:06 -07:00
|
|
|
if (valid_lcid(lcid)) {
|
|
|
|
pdcp_map_t::iterator it = pdcp_array.find(lcid);
|
2019-11-18 10:07:14 -08:00
|
|
|
delete (it->second);
|
2018-08-03 07:28:06 -07:00
|
|
|
pdcp_array.erase(it);
|
|
|
|
pdcp_log->warning("Deleted PDCP bearer %s\n", rrc->get_rb_name(lcid).c_str());
|
|
|
|
} else {
|
|
|
|
pdcp_log->warning("Can't delete bearer %s. Bearer doesn't exist.\n", rrc->get_rb_name(lcid).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 04:10:44 -07:00
|
|
|
void pdcp::change_lcid(uint32_t old_lcid, uint32_t new_lcid)
|
|
|
|
{
|
|
|
|
// make sure old LCID exists and new LCID is still free
|
|
|
|
if (valid_lcid(old_lcid) && not valid_lcid(new_lcid)) {
|
|
|
|
// insert old PDCP entity into new LCID
|
2019-07-23 07:49:34 -07:00
|
|
|
pdcp_map_t::iterator it = pdcp_array.find(old_lcid);
|
|
|
|
pdcp_entity_lte* pdcp_entity = it->second;
|
2018-09-17 04:10:44 -07:00
|
|
|
if (not pdcp_array.insert(pdcp_map_pair_t(new_lcid, pdcp_entity)).second) {
|
|
|
|
pdcp_log->error("Error inserting PDCP entity into array\n.");
|
2020-03-23 07:00:12 -07:00
|
|
|
return;
|
2018-09-17 04:10:44 -07:00
|
|
|
}
|
2020-03-23 06:31:33 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(cache_mutex);
|
|
|
|
valid_lcids_cached.erase(old_lcid);
|
|
|
|
valid_lcids_cached.insert(new_lcid);
|
|
|
|
}
|
2018-09-17 04:10:44 -07:00
|
|
|
// erase from old position
|
|
|
|
pdcp_array.erase(it);
|
|
|
|
pdcp_log->warning("Changed LCID of PDCP bearer from %d to %d\n", old_lcid, new_lcid);
|
|
|
|
} else {
|
2019-07-23 07:49:34 -07:00
|
|
|
pdcp_log->error(
|
|
|
|
"Can't change PDCP of bearer %s from %d to %d. Bearer doesn't exist or new LCID already occupied.\n",
|
|
|
|
rrc->get_rb_name(old_lcid).c_str(),
|
|
|
|
old_lcid,
|
|
|
|
new_lcid);
|
2018-09-17 04:10:44 -07:00
|
|
|
}
|
|
|
|
}
|
2018-08-03 07:28:06 -07:00
|
|
|
|
2020-02-20 07:08:04 -08:00
|
|
|
void pdcp::config_security(uint32_t lcid, as_security_config_t sec_cfg)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (valid_lcid(lcid)) {
|
2020-02-20 07:08:04 -08:00
|
|
|
pdcp_array.at(lcid)->config_security(sec_cfg);
|
2018-07-16 12:17:01 -07:00
|
|
|
}
|
2017-12-01 11:19:38 -08:00
|
|
|
}
|
|
|
|
|
2020-02-20 07:08:04 -08:00
|
|
|
void pdcp::config_security_all(as_security_config_t sec_cfg)
|
2017-12-02 13:43:35 -08:00
|
|
|
{
|
2018-07-19 01:23:15 -07:00
|
|
|
for (pdcp_map_t::iterator it = pdcp_array.begin(); it != pdcp_array.end(); ++it) {
|
2020-02-20 07:08:04 -08:00
|
|
|
it->second->config_security(sec_cfg);
|
2017-12-02 13:43:35 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-01 05:51:51 -08:00
|
|
|
void pdcp::enable_integrity(uint32_t lcid, srslte_direction_t direction)
|
2017-12-01 11:19:38 -08:00
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (valid_lcid(lcid)) {
|
2020-03-01 05:51:51 -08:00
|
|
|
pdcp_array.at(lcid)->enable_integrity(direction);
|
2018-07-16 12:17:01 -07:00
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
|
2020-03-01 05:51:51 -08:00
|
|
|
void pdcp::enable_encryption(uint32_t lcid, srslte_direction_t direction)
|
2017-11-30 09:09:12 -08:00
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (valid_lcid(lcid)) {
|
2020-03-01 05:51:51 -08:00
|
|
|
pdcp_array.at(lcid)->enable_encryption(direction);
|
2018-07-16 12:17:01 -07:00
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
|
2019-12-06 11:39:22 -08:00
|
|
|
bool pdcp::get_bearer_status(uint32_t lcid, uint16_t* dlsn, uint16_t* dlhfn, uint16_t* ulsn, uint16_t* ulhfn)
|
|
|
|
{
|
|
|
|
if (not valid_lcid(lcid)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pdcp_array[lcid]->get_bearer_status(dlsn, dlhfn, ulsn, ulhfn);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-18 03:52:29 -07:00
|
|
|
/*******************************************************************************
|
|
|
|
RLC interface
|
|
|
|
*******************************************************************************/
|
2019-05-13 07:34:15 -07:00
|
|
|
void pdcp::write_pdu(uint32_t lcid, unique_byte_buffer_t pdu)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (valid_lcid(lcid)) {
|
2019-04-29 12:16:51 -07:00
|
|
|
pdcp_array.at(lcid)->write_pdu(std::move(pdu));
|
2018-03-06 03:41:44 -08:00
|
|
|
} else {
|
|
|
|
pdcp_log->warning("Writing pdu: lcid=%d. Deallocating pdu\n", lcid);
|
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
|
2019-05-13 07:34:15 -07:00
|
|
|
void pdcp::write_pdu_bcch_bch(unique_byte_buffer_t sdu)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2019-04-29 12:16:51 -07:00
|
|
|
rrc->write_pdu_bcch_bch(std::move(sdu));
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
2018-07-17 06:27:04 -07:00
|
|
|
|
2019-05-13 07:34:15 -07:00
|
|
|
void pdcp::write_pdu_bcch_dlsch(unique_byte_buffer_t sdu)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2019-04-29 12:16:51 -07:00
|
|
|
rrc->write_pdu_bcch_dlsch(std::move(sdu));
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
|
2019-05-13 07:34:15 -07:00
|
|
|
void pdcp::write_pdu_pcch(unique_byte_buffer_t sdu)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2019-04-29 12:16:51 -07:00
|
|
|
rrc->write_pdu_pcch(std::move(sdu));
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
|
|
|
|
2019-05-13 07:34:15 -07:00
|
|
|
void pdcp::write_pdu_mch(uint32_t lcid, unique_byte_buffer_t sdu)
|
2018-05-15 07:57:23 -07:00
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (0 == lcid) {
|
2019-04-29 12:16:51 -07:00
|
|
|
rrc->write_pdu_mch(lcid, std::move(sdu));
|
2018-05-15 07:57:23 -07:00
|
|
|
} else {
|
2019-04-29 12:16:51 -07:00
|
|
|
gw->write_pdu_mch(lcid, std::move(sdu));
|
2018-05-15 07:57:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 03:52:29 -07:00
|
|
|
bool pdcp::valid_lcid(uint32_t lcid)
|
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (lcid >= SRSLTE_N_RADIO_BEARERS) {
|
2017-06-06 11:34:09 -07:00
|
|
|
pdcp_log->error("Radio bearer id must be in [0:%d] - %d", SRSLTE_N_RADIO_BEARERS, lcid);
|
2017-05-18 03:52:29 -07:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-16 12:17:01 -07:00
|
|
|
|
|
|
|
if (pdcp_array.find(lcid) == pdcp_array.end()) {
|
2017-05-18 03:52:29 -07:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-16 12:17:01 -07:00
|
|
|
|
2017-05-18 03:52:29 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-15 07:57:23 -07:00
|
|
|
bool pdcp::valid_mch_lcid(uint32_t lcid)
|
|
|
|
{
|
2018-07-16 12:17:01 -07:00
|
|
|
if (lcid >= SRSLTE_N_MCH_LCIDS) {
|
2018-05-15 07:57:23 -07:00
|
|
|
pdcp_log->error("Radio bearer id must be in [0:%d] - %d", SRSLTE_N_RADIO_BEARERS, lcid);
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-16 12:17:01 -07:00
|
|
|
|
|
|
|
if (pdcp_array_mrb.find(lcid) == pdcp_array_mrb.end()) {
|
2018-05-15 07:57:23 -07:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-16 12:17:01 -07:00
|
|
|
|
2018-05-15 07:57:23 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-07 05:32:14 -07:00
|
|
|
} // namespace srslte
|