mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
6.7 KiB
C
195 lines
6.7 KiB
C
4 years ago
|
/**
|
||
6 years ago
|
*
|
||
4 years ago
|
* \section COPYRIGHT
|
||
6 years ago
|
*
|
||
4 years ago
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
6 years ago
|
*
|
||
4 years ago
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
6 years ago
|
*
|
||
|
*/
|
||
|
|
||
4 years ago
|
#ifndef SRSRAN_PDCP_ENTITY_BASE_H
|
||
|
#define SRSRAN_PDCP_ENTITY_BASE_H
|
||
6 years ago
|
|
||
4 years ago
|
#include "srsran/adt/accumulators.h"
|
||
|
#include "srsran/common/buffer_pool.h"
|
||
|
#include "srsran/common/common.h"
|
||
|
#include "srsran/common/interfaces_common.h"
|
||
|
#include "srsran/common/security.h"
|
||
|
#include "srsran/common/task_scheduler.h"
|
||
|
#include "srsran/common/threads.h"
|
||
|
#include "srsran/common/timers.h"
|
||
|
#include "srsran/interfaces/pdcp_interface_types.h"
|
||
|
#include "srsran/upper/byte_buffer_queue.h"
|
||
|
#include "srsran/upper/pdcp_metrics.h"
|
||
6 years ago
|
|
||
4 years ago
|
namespace srsran {
|
||
6 years ago
|
|
||
|
/****************************************************************************
|
||
|
* Structs and Defines common to both LTE and NR
|
||
|
* Ref: 3GPP TS 36.323 v10.1.0 and TS 38.323 v15.2.0
|
||
|
***************************************************************************/
|
||
|
|
||
|
#define PDCP_PDU_TYPE_PDCP_STATUS_REPORT 0x0
|
||
|
#define PDCP_PDU_TYPE_INTERSPERSED_ROHC_FEEDBACK_PACKET 0x1
|
||
|
|
||
6 years ago
|
// Maximum supported PDCP SDU size is 9000 bytes.
|
||
|
// See TS 38.323 v15.2.0, section 4.3.1
|
||
6 years ago
|
#define PDCP_MAX_SDU_SIZE 9000
|
||
|
|
||
6 years ago
|
typedef enum {
|
||
|
PDCP_D_C_CONTROL_PDU = 0,
|
||
|
PDCP_D_C_DATA_PDU,
|
||
|
PDCP_D_C_N_ITEMS,
|
||
|
} pdcp_d_c_t;
|
||
|
static const char pdcp_d_c_text[PDCP_D_C_N_ITEMS][20] = {"Control PDU", "Data PDU"};
|
||
|
|
||
|
/****************************************************************************
|
||
|
* PDCP Entity interface
|
||
|
* Common interface for LTE and NR PDCP entities
|
||
|
***************************************************************************/
|
||
|
class pdcp_entity_base
|
||
|
{
|
||
|
public:
|
||
4 years ago
|
pdcp_entity_base(task_sched_handle task_sched_, srslog::basic_logger& logger);
|
||
5 years ago
|
pdcp_entity_base(pdcp_entity_base&&) = default;
|
||
6 years ago
|
virtual ~pdcp_entity_base();
|
||
|
virtual void reset() = 0;
|
||
|
virtual void reestablish() = 0;
|
||
|
|
||
|
bool is_active() { return active; }
|
||
6 years ago
|
bool is_srb() { return cfg.rb_type == PDCP_RB_IS_SRB; }
|
||
|
bool is_drb() { return cfg.rb_type == PDCP_RB_IS_DRB; }
|
||
6 years ago
|
|
||
|
// RRC interface
|
||
4 years ago
|
void enable_integrity(srsran_direction_t direction = DIRECTION_TXRX)
|
||
5 years ago
|
{
|
||
|
// if either DL or UL is already enabled, both are enabled
|
||
|
if (integrity_direction == DIRECTION_TX && direction == DIRECTION_RX) {
|
||
|
integrity_direction = DIRECTION_TXRX;
|
||
|
} else if (integrity_direction == DIRECTION_RX && direction == DIRECTION_TX) {
|
||
|
integrity_direction = DIRECTION_TXRX;
|
||
|
} else {
|
||
|
integrity_direction = direction;
|
||
|
}
|
||
4 years ago
|
logger.debug("LCID=%d, integrity=%s", lcid, srsran_direction_text[integrity_direction]);
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
void enable_encryption(srsran_direction_t direction = DIRECTION_TXRX)
|
||
5 years ago
|
{
|
||
|
// if either DL or UL is already enabled, both are enabled
|
||
|
if (encryption_direction == DIRECTION_TX && direction == DIRECTION_RX) {
|
||
|
encryption_direction = DIRECTION_TXRX;
|
||
|
} else if (encryption_direction == DIRECTION_RX && direction == DIRECTION_TX) {
|
||
|
encryption_direction = DIRECTION_TXRX;
|
||
|
} else {
|
||
|
encryption_direction = direction;
|
||
|
}
|
||
4 years ago
|
logger.debug("LCID=%d encryption=%s", lcid, srsran_direction_text[integrity_direction]);
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
void enable_security_timed(srsran_direction_t direction, uint32_t sn)
|
||
5 years ago
|
{
|
||
|
switch (direction) {
|
||
|
case DIRECTION_TX:
|
||
|
enable_security_tx_sn = sn;
|
||
|
break;
|
||
|
case DIRECTION_RX:
|
||
|
enable_security_rx_sn = sn;
|
||
|
break;
|
||
|
default:
|
||
4 years ago
|
logger.error("Timed security activation for direction %s not supported.", srsran_direction_text[direction]);
|
||
5 years ago
|
break;
|
||
|
}
|
||
5 years ago
|
}
|
||
6 years ago
|
|
||
5 years ago
|
void config_security(as_security_config_t sec_cfg_);
|
||
6 years ago
|
|
||
|
// GW/SDAP/RRC interface
|
||
4 years ago
|
virtual void write_sdu(unique_byte_buffer_t sdu, int sn = -1) = 0;
|
||
6 years ago
|
|
||
|
// RLC interface
|
||
4 years ago
|
virtual void write_pdu(unique_byte_buffer_t pdu) = 0;
|
||
|
virtual void notify_delivery(const pdcp_sn_vector_t& pdcp_sns) = 0;
|
||
|
virtual void notify_failure(const pdcp_sn_vector_t& pdcp_sns) = 0;
|
||
5 years ago
|
|
||
4 years ago
|
virtual void get_bearer_state(pdcp_lte_state_t* state) = 0;
|
||
|
virtual void set_bearer_state(const pdcp_lte_state_t& state, bool set_fmc) = 0;
|
||
6 years ago
|
|
||
4 years ago
|
virtual std::map<uint32_t, srsran::unique_byte_buffer_t> get_buffered_pdus() = 0;
|
||
4 years ago
|
|
||
4 years ago
|
virtual void send_status_report() = 0;
|
||
|
|
||
6 years ago
|
// COUNT, HFN and SN helpers
|
||
|
uint32_t HFN(uint32_t count);
|
||
|
uint32_t SN(uint32_t count);
|
||
|
uint32_t COUNT(uint32_t hfn, uint32_t sn);
|
||
6 years ago
|
|
||
4 years ago
|
// Metrics helpers
|
||
|
virtual pdcp_bearer_metrics_t get_metrics() = 0;
|
||
|
virtual void reset_metrics() = 0;
|
||
|
|
||
6 years ago
|
protected:
|
||
4 years ago
|
srslog::basic_logger& logger;
|
||
4 years ago
|
srsran::task_sched_handle task_sched;
|
||
6 years ago
|
|
||
5 years ago
|
bool active = false;
|
||
|
uint32_t lcid = 0;
|
||
4 years ago
|
srsran_direction_t integrity_direction = DIRECTION_NONE;
|
||
|
srsran_direction_t encryption_direction = DIRECTION_NONE;
|
||
6 years ago
|
|
||
5 years ago
|
int32_t enable_security_tx_sn = -1; // TX SN at which security will be enabled
|
||
|
int32_t enable_security_rx_sn = -1; // RX SN at which security will be enabled
|
||
|
|
||
5 years ago
|
pdcp_config_t cfg = {1,
|
||
|
PDCP_RB_IS_DRB,
|
||
|
SECURITY_DIRECTION_DOWNLINK,
|
||
|
SECURITY_DIRECTION_UPLINK,
|
||
|
PDCP_SN_LEN_12,
|
||
5 years ago
|
pdcp_t_reordering_t::ms500,
|
||
4 years ago
|
pdcp_discard_timer_t::infinity,
|
||
|
false};
|
||
6 years ago
|
|
||
4 years ago
|
srsran::as_security_config_t sec_cfg = {};
|
||
6 years ago
|
|
||
5 years ago
|
// Security functions
|
||
6 years ago
|
void integrity_generate(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* mac);
|
||
|
bool integrity_verify(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* mac);
|
||
|
void cipher_encrypt(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* ct);
|
||
|
void cipher_decrypt(uint8_t* ct, uint32_t ct_len, uint32_t count, uint8_t* msg);
|
||
5 years ago
|
|
||
|
// Common packing functions
|
||
4 years ago
|
bool is_control_pdu(const unique_byte_buffer_t& pdu);
|
||
|
pdcp_pdu_type_t get_control_pdu_type(const unique_byte_buffer_t& pdu);
|
||
|
uint32_t read_data_header(const unique_byte_buffer_t& pdu);
|
||
|
void discard_data_header(const unique_byte_buffer_t& pdu);
|
||
4 years ago
|
void write_data_header(const srsran::unique_byte_buffer_t& sdu, uint32_t count);
|
||
4 years ago
|
void extract_mac(const unique_byte_buffer_t& pdu, uint8_t* mac);
|
||
|
void append_mac(const unique_byte_buffer_t& sdu, uint8_t* mac);
|
||
4 years ago
|
|
||
|
// Metrics helpers
|
||
4 years ago
|
pdcp_bearer_metrics_t metrics = {};
|
||
4 years ago
|
srsran::rolling_average<double> tx_pdu_ack_latency_ms;
|
||
6 years ago
|
};
|
||
6 years ago
|
|
||
|
inline uint32_t pdcp_entity_base::HFN(uint32_t count)
|
||
|
{
|
||
6 years ago
|
return (count >> cfg.sn_len);
|
||
6 years ago
|
}
|
||
|
|
||
|
inline uint32_t pdcp_entity_base::SN(uint32_t count)
|
||
|
{
|
||
6 years ago
|
return count & (0xFFFFFFFF >> (32 - cfg.sn_len));
|
||
6 years ago
|
}
|
||
|
|
||
|
inline uint32_t pdcp_entity_base::COUNT(uint32_t hfn, uint32_t sn)
|
||
|
{
|
||
6 years ago
|
return (hfn << cfg.sn_len) | sn;
|
||
6 years ago
|
}
|
||
5 years ago
|
|
||
4 years ago
|
} // namespace srsran
|
||
5 years ago
|
|
||
4 years ago
|
#endif // SRSRAN_PDCP_ENTITY_BASE_H
|