Clang-formated PDCP NR PR.

master
Pedro Alvarez 6 years ago committed by Andre Puschmann
parent 964db869a6
commit 491695ab77

@ -88,7 +88,7 @@ public:
hdr_len_bytes = ceil((float)sn_len / 8); hdr_len_bytes = ceil((float)sn_len / 8);
} }
uint8_t bearer_id; uint8_t bearer_id;
pdcp_rb_type_t rb_type; pdcp_rb_type_t rb_type;
uint8_t tx_direction; uint8_t tx_direction;
uint8_t rx_direction; uint8_t rx_direction;

@ -22,8 +22,8 @@
#ifndef SRSLTE_PDCP_H #ifndef SRSLTE_PDCP_H
#define SRSLTE_PDCP_H #define SRSLTE_PDCP_H
#include "srslte/common/log.h"
#include "srslte/common/common.h" #include "srslte/common/common.h"
#include "srslte/common/log.h"
#include "srslte/interfaces/ue_interfaces.h" #include "srslte/interfaces/ue_interfaces.h"
#include "srslte/upper/pdcp_entity_lte.h" #include "srslte/upper/pdcp_entity_lte.h"
@ -76,7 +76,7 @@ private:
srsue::rrc_interface_pdcp* rrc = nullptr; srsue::rrc_interface_pdcp* rrc = nullptr;
srsue::gw_interface_pdcp* gw = nullptr; srsue::gw_interface_pdcp* gw = nullptr;
typedef std::map<uint16_t, pdcp_entity_lte*> pdcp_map_t; typedef std::map<uint16_t, pdcp_entity_lte*> pdcp_map_t;
typedef std::pair<uint16_t, pdcp_entity_lte*> pdcp_map_pair_t; typedef std::pair<uint16_t, pdcp_entity_lte*> pdcp_map_pair_t;
log* pdcp_log = nullptr; log* pdcp_log = nullptr;

@ -84,9 +84,9 @@ public:
uint32_t HFN(uint32_t count); uint32_t HFN(uint32_t count);
uint32_t SN(uint32_t count); uint32_t SN(uint32_t count);
uint32_t COUNT(uint32_t hfn, uint32_t sn); uint32_t COUNT(uint32_t hfn, uint32_t sn);
protected: protected:
srslte::log* log = nullptr; srslte::log* log = nullptr;
bool active = false; bool active = false;
uint32_t lcid = 0; uint32_t lcid = 0;
@ -119,7 +119,7 @@ inline uint32_t pdcp_entity_base::HFN(uint32_t count)
inline uint32_t pdcp_entity_base::SN(uint32_t count) inline uint32_t pdcp_entity_base::SN(uint32_t count)
{ {
return count & (0xFFFFFFFF >> (32 -cfg.sn_len)); return count & (0xFFFFFFFF >> (32 - cfg.sn_len));
} }
inline uint32_t pdcp_entity_base::COUNT(uint32_t hfn, uint32_t sn) inline uint32_t pdcp_entity_base::COUNT(uint32_t hfn, uint32_t sn)

@ -23,14 +23,13 @@
#define SRSLTE_PDCP_ENTITY_LTE_H #define SRSLTE_PDCP_ENTITY_LTE_H
#include "srslte/common/buffer_pool.h" #include "srslte/common/buffer_pool.h"
#include "srslte/common/log.h"
#include "srslte/common/common.h" #include "srslte/common/common.h"
#include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/log.h"
#include "srslte/common/security.h" #include "srslte/common/security.h"
#include "srslte/common/threads.h" #include "srslte/common/threads.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "srslte/upper/pdcp_entity_base.h" #include "srslte/upper/pdcp_entity_base.h"
namespace srslte { namespace srslte {
/**************************************************************************** /****************************************************************************
@ -41,10 +40,10 @@ namespace srslte {
#define PDCP_CONTROL_MAC_I 0x00000000 #define PDCP_CONTROL_MAC_I 0x00000000
/**************************************************************************** /****************************************************************************
* LTE PDCP Entity * LTE PDCP Entity
* Class for LTE PDCP entities * Class for LTE PDCP entities
***************************************************************************/ ***************************************************************************/
class pdcp_entity_lte final: public pdcp_entity_base class pdcp_entity_lte final : public pdcp_entity_base
{ {
public: public:
pdcp_entity_lte(); pdcp_entity_lte();

@ -22,13 +22,13 @@
#ifndef SRSLTE_PDCP_ENTITY_NR_H #ifndef SRSLTE_PDCP_ENTITY_NR_H
#define SRSLTE_PDCP_ENTITY_NR_H #define SRSLTE_PDCP_ENTITY_NR_H
#include "pdcp_entity_base.h"
#include "srslte/common/buffer_pool.h" #include "srslte/common/buffer_pool.h"
#include "srslte/common/log.h"
#include "srslte/common/common.h" #include "srslte/common/common.h"
#include "srslte/common/interfaces_common.h" #include "srslte/common/interfaces_common.h"
#include "srslte/common/log.h"
#include "srslte/common/security.h" #include "srslte/common/security.h"
#include "srslte/common/threads.h" #include "srslte/common/threads.h"
#include "pdcp_entity_base.h"
namespace srslte { namespace srslte {
@ -76,7 +76,7 @@ private:
// Packing/Unpacking Helper functions // Packing/Unpacking Helper functions
void read_data_header(const unique_byte_buffer_t& sdu, uint32_t* rcvd_sn); void read_data_header(const unique_byte_buffer_t& sdu, uint32_t* rcvd_sn);
void write_data_header(const unique_byte_buffer_t& sdu, uint32_t sn); void write_data_header(const unique_byte_buffer_t& sdu, uint32_t sn);
void extract_mac(const unique_byte_buffer_t &sdu, uint8_t* mac); void extract_mac(const unique_byte_buffer_t& sdu, uint8_t* mac);
void append_mac(const unique_byte_buffer_t& sdu, uint8_t* mac); void append_mac(const unique_byte_buffer_t& sdu, uint8_t* mac);
}; };

@ -183,8 +183,8 @@ void pdcp::change_lcid(uint32_t old_lcid, uint32_t new_lcid)
// make sure old LCID exists and new LCID is still free // make sure old LCID exists and new LCID is still free
if (valid_lcid(old_lcid) && not valid_lcid(new_lcid)) { if (valid_lcid(old_lcid) && not valid_lcid(new_lcid)) {
// insert old PDCP entity into new LCID // insert old PDCP entity into new LCID
pdcp_map_t::iterator it = pdcp_array.find(old_lcid); pdcp_map_t::iterator it = pdcp_array.find(old_lcid);
pdcp_entity_lte *pdcp_entity = it->second; pdcp_entity_lte* pdcp_entity = it->second;
if (not pdcp_array.insert(pdcp_map_pair_t(new_lcid, pdcp_entity)).second) { if (not pdcp_array.insert(pdcp_map_pair_t(new_lcid, pdcp_entity)).second) {
pdcp_log->error("Error inserting PDCP entity into array\n."); pdcp_log->error("Error inserting PDCP entity into array\n.");
goto exit; goto exit;
@ -193,7 +193,11 @@ void pdcp::change_lcid(uint32_t old_lcid, uint32_t new_lcid)
pdcp_array.erase(it); pdcp_array.erase(it);
pdcp_log->warning("Changed LCID of PDCP bearer from %d to %d\n", old_lcid, new_lcid); pdcp_log->warning("Changed LCID of PDCP bearer from %d to %d\n", old_lcid, new_lcid);
} else { } else {
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); 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);
} }
exit: exit:
pthread_rwlock_unlock(&rwlock); pthread_rwlock_unlock(&rwlock);

@ -50,19 +50,18 @@ void pdcp_entity_base::config_security(uint8_t* k_rrc_enc_,
integrity_algorithm_id_text[integ_algo], integrity_algorithm_id_text[integ_algo],
ciphering_algorithm_id_text[cipher_algo]); ciphering_algorithm_id_text[cipher_algo]);
log->debug_hex(k_rrc_enc, 32,"K_rrc_enc"); log->debug_hex(k_rrc_enc, 32, "K_rrc_enc");
log->debug_hex(k_up_enc, 32,"K_up_enc"); log->debug_hex(k_up_enc, 32, "K_up_enc");
log->debug_hex(k_rrc_int, 32,"K_rrc_int"); log->debug_hex(k_rrc_int, 32, "K_rrc_int");
log->debug_hex(k_up_int, 32,"K_up_int"); log->debug_hex(k_up_int, 32, "K_up_int");
} }
/**************************************************************************** /****************************************************************************
* Security functions * Security functions
***************************************************************************/ ***************************************************************************/
void pdcp_entity_base::integrity_generate(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* mac) void pdcp_entity_base::integrity_generate(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* mac)
{ {
uint8_t *k_int; uint8_t* k_int;
// If control plane use RRC integrity key. If data use user plane key // If control plane use RRC integrity key. If data use user plane key
if (is_srb()) { if (is_srb()) {
@ -71,30 +70,17 @@ void pdcp_entity_base::integrity_generate(uint8_t* msg, uint32_t msg_len, uint32
k_int = k_up_int; k_int = k_up_int;
} }
switch(integ_algo) switch (integ_algo) {
{ case INTEGRITY_ALGORITHM_ID_EIA0:
case INTEGRITY_ALGORITHM_ID_EIA0: break;
break; case INTEGRITY_ALGORITHM_ID_128_EIA1:
case INTEGRITY_ALGORITHM_ID_128_EIA1: security_128_eia1(&k_int[16], count, cfg.bearer_id - 1, cfg.tx_direction, msg, msg_len, mac);
security_128_eia1(&k_int[16], break;
count, case INTEGRITY_ALGORITHM_ID_128_EIA2:
cfg.bearer_id - 1, security_128_eia2(&k_int[16], count, cfg.bearer_id - 1, cfg.tx_direction, msg, msg_len, mac);
cfg.tx_direction, break;
msg, default:
msg_len, break;
mac);
break;
case INTEGRITY_ALGORITHM_ID_128_EIA2:
security_128_eia2(&k_int[16],
count,
cfg.bearer_id - 1,
cfg.tx_direction,
msg,
msg_len,
mac);
break;
default:
break;
} }
log->debug("Integrity gen input: COUNT %d, Bearer ID %d, Direction %s\n", log->debug("Integrity gen input: COUNT %d, Bearer ID %d, Direction %s\n",
@ -107,9 +93,9 @@ void pdcp_entity_base::integrity_generate(uint8_t* msg, uint32_t msg_len, uint32
bool pdcp_entity_base::integrity_verify(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* mac) bool pdcp_entity_base::integrity_verify(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* mac)
{ {
uint8_t mac_exp[4] = {}; uint8_t mac_exp[4] = {};
bool is_valid = true; bool is_valid = true;
uint8_t *k_int; uint8_t* k_int;
// If control plane use RRC integrity key. If data use user plane key // If control plane use RRC integrity key. If data use user plane key
if (is_srb()) { if (is_srb()) {
@ -157,7 +143,7 @@ bool pdcp_entity_base::integrity_verify(uint8_t* msg, uint32_t msg_len, uint32_t
void pdcp_entity_base::cipher_encrypt(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* ct) void pdcp_entity_base::cipher_encrypt(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* ct)
{ {
byte_buffer_t ct_tmp; byte_buffer_t ct_tmp;
uint8_t *k_enc; uint8_t* k_enc;
// If control plane use RRC encrytion key. If data use user plane key // If control plane use RRC encrytion key. If data use user plane key
if (is_srb()) { if (is_srb()) {
@ -192,7 +178,7 @@ void pdcp_entity_base::cipher_encrypt(uint8_t* msg, uint32_t msg_len, uint32_t c
void pdcp_entity_base::cipher_decrypt(uint8_t* ct, uint32_t ct_len, uint32_t count, uint8_t* msg) void pdcp_entity_base::cipher_decrypt(uint8_t* ct, uint32_t ct_len, uint32_t count, uint8_t* msg)
{ {
byte_buffer_t msg_tmp; byte_buffer_t msg_tmp;
uint8_t *k_enc; uint8_t* k_enc;
// If control plane use RRC encrytion key. If data use user plane key // If control plane use RRC encrytion key. If data use user plane key
if (is_srb()) { if (is_srb()) {
@ -207,22 +193,20 @@ void pdcp_entity_base::cipher_decrypt(uint8_t* ct, uint32_t ct_len, uint32_t cou
(cfg.rx_direction == SECURITY_DIRECTION_DOWNLINK) ? "Downlink" : "Uplink"); (cfg.rx_direction == SECURITY_DIRECTION_DOWNLINK) ? "Downlink" : "Uplink");
log->debug_hex(ct, ct_len, "Cipher decrypt input msg"); log->debug_hex(ct, ct_len, "Cipher decrypt input msg");
switch(cipher_algo) switch (cipher_algo) {
{ case CIPHERING_ALGORITHM_ID_EEA0:
case CIPHERING_ALGORITHM_ID_EEA0: break;
break; case CIPHERING_ALGORITHM_ID_128_EEA1:
case CIPHERING_ALGORITHM_ID_128_EEA1: security_128_eea1(&k_enc[16], count, cfg.bearer_id - 1, cfg.rx_direction, ct, ct_len, msg_tmp.msg);
security_128_eea1(&k_enc[16], count, cfg.bearer_id - 1, cfg.rx_direction, ct, ct_len, msg_tmp.msg); memcpy(msg, msg_tmp.msg, ct_len);
memcpy(msg, msg_tmp.msg, ct_len); break;
break; case CIPHERING_ALGORITHM_ID_128_EEA2:
case CIPHERING_ALGORITHM_ID_128_EEA2: security_128_eea2(&k_enc[16], count, cfg.bearer_id - 1, cfg.rx_direction, ct, ct_len, msg_tmp.msg);
security_128_eea2(&k_enc[16], count, cfg.bearer_id - 1, cfg.rx_direction, ct, ct_len, msg_tmp.msg); memcpy(msg, msg_tmp.msg, ct_len);
memcpy(msg, msg_tmp.msg, ct_len); break;
break; default:
default: break;
break;
} }
log->debug_hex(msg, ct_len,"Cipher decrypt output msg"); log->debug_hex(msg, ct_len, "Cipher decrypt output msg");
}
} }
} // namespace srslte

@ -33,7 +33,7 @@ void pdcp_entity_lte::init(srsue::rlc_interface_pdcp* rlc_,
srsue::gw_interface_pdcp* gw_, srsue::gw_interface_pdcp* gw_,
srslte::log* log_, srslte::log* log_,
uint32_t lcid_, uint32_t lcid_,
srslte_pdcp_config_t cfg_) srslte_pdcp_config_t cfg_)
{ {
rlc = rlc_; rlc = rlc_;
rrc = rrc_; rrc = rrc_;
@ -83,10 +83,10 @@ void pdcp_entity_lte::reestablish()
rx_hfn = 0; rx_hfn = 0;
next_pdcp_rx_sn = 0; next_pdcp_rx_sn = 0;
} else { } else {
tx_count = 0; tx_count = 0;
rx_count = 0; rx_count = 0;
rx_hfn = 0; rx_hfn = 0;
next_pdcp_rx_sn = 0; next_pdcp_rx_sn = 0;
last_submitted_pdcp_rx_sn = maximum_pdcp_sn; last_submitted_pdcp_rx_sn = maximum_pdcp_sn;
} }
} }
@ -104,18 +104,20 @@ void pdcp_entity_lte::reset()
// GW/RRC interface // GW/RRC interface
void pdcp_entity_lte::write_sdu(unique_byte_buffer_t sdu, bool blocking) void pdcp_entity_lte::write_sdu(unique_byte_buffer_t sdu, bool blocking)
{ {
log->info_hex(sdu->msg, sdu->N_bytes, log->info_hex(sdu->msg,
"TX %s SDU, SN: %d, do_integrity = %s, do_encryption = %s", sdu->N_bytes,
rrc->get_rb_name(lcid).c_str(), tx_count, "TX %s SDU, SN: %d, do_integrity = %s, do_encryption = %s",
(do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false"); rrc->get_rb_name(lcid).c_str(),
tx_count,
(do_integrity) ? "true" : "false",
(do_encryption) ? "true" : "false");
mutex.lock(); mutex.lock();
if (is_srb()) { if (is_srb()) {
pdcp_pack_control_pdu(tx_count, sdu.get()); pdcp_pack_control_pdu(tx_count, sdu.get());
if (do_integrity) { if (do_integrity) {
integrity_generate( integrity_generate(sdu->msg, sdu->N_bytes - 4, tx_count, &sdu->msg[sdu->N_bytes - 4]);
sdu->msg, sdu->N_bytes - 4, tx_count, &sdu->msg[sdu->N_bytes - 4]);
} }
} }
@ -176,8 +178,7 @@ void pdcp_entity_lte::write_pdu(unique_byte_buffer_t pdu)
} }
if (do_integrity) { if (do_integrity) {
if (not integrity_verify( if (not integrity_verify(pdu->msg, pdu->N_bytes - 4, sn, &(pdu->msg[pdu->N_bytes - 4]))) {
pdu->msg, pdu->N_bytes - 4, sn, &(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; goto exit;
} }
@ -199,7 +200,7 @@ exit:
* Ref: 3GPP TS 36.323 v10.1.0 Section 5.1.2 * Ref: 3GPP TS 36.323 v10.1.0 Section 5.1.2
***************************************************************************/ ***************************************************************************/
// DRBs mapped on RLC UM (5.1.2.1.3) // DRBs mapped on RLC UM (5.1.2.1.3)
void pdcp_entity_lte::handle_um_drb_pdu(const srslte::unique_byte_buffer_t &pdu) void pdcp_entity_lte::handle_um_drb_pdu(const srslte::unique_byte_buffer_t& pdu)
{ {
uint32_t sn; uint32_t sn;
if (12 == cfg.sn_len) { if (12 == cfg.sn_len) {
@ -229,7 +230,7 @@ void pdcp_entity_lte::handle_um_drb_pdu(const srslte::unique_byte_buffer_t &pdu)
} }
// DRBs mapped on RLC AM, without re-ordering (5.1.2.1.2) // DRBs mapped on RLC AM, without re-ordering (5.1.2.1.2)
void pdcp_entity_lte::handle_am_drb_pdu(const srslte::unique_byte_buffer_t &pdu) void pdcp_entity_lte::handle_am_drb_pdu(const srslte::unique_byte_buffer_t& pdu)
{ {
uint32_t sn, count; uint32_t sn, count;
pdcp_unpack_data_pdu_long_sn(pdu.get(), &sn); pdcp_unpack_data_pdu_long_sn(pdu.get(), &sn);
@ -257,14 +258,14 @@ void pdcp_entity_lte::handle_am_drb_pdu(const srslte::unique_byte_buffer_t &pdu)
} else if ((int32_t)(next_pdcp_rx_sn - sn) > (int32_t)reordering_window) { } else if ((int32_t)(next_pdcp_rx_sn - sn) > (int32_t)reordering_window) {
log->debug("(Next_PDCP_RX_SN - SN) is larger than re-ordering window.\n"); log->debug("(Next_PDCP_RX_SN - SN) is larger than re-ordering window.\n");
rx_hfn++; rx_hfn++;
count = (rx_hfn << cfg.sn_len) | sn; count = (rx_hfn << cfg.sn_len) | sn;
next_pdcp_rx_sn = sn + 1; next_pdcp_rx_sn = sn + 1;
} else if (sn_diff_next_pdcp_rx_sn >= (int32_t)reordering_window) { } else if (sn_diff_next_pdcp_rx_sn >= (int32_t)reordering_window) {
log->debug("(SN - Next_PDCP_RX_SN) is larger or equal than re-ordering window.\n"); log->debug("(SN - Next_PDCP_RX_SN) is larger or equal than re-ordering window.\n");
count = ((rx_hfn - 1) << cfg.sn_len) | sn; count = ((rx_hfn - 1) << cfg.sn_len) | sn;
} else if (sn >= next_pdcp_rx_sn) { } else if (sn >= next_pdcp_rx_sn) {
log->debug("SN is larger or equal than Next_PDCP_RX_SN.\n"); log->debug("SN is larger or equal than Next_PDCP_RX_SN.\n");
count = (rx_hfn << cfg.sn_len) | sn; count = (rx_hfn << cfg.sn_len) | sn;
next_pdcp_rx_sn = sn + 1; next_pdcp_rx_sn = sn + 1;
if (next_pdcp_rx_sn > maximum_pdcp_sn) { if (next_pdcp_rx_sn > maximum_pdcp_sn) {
next_pdcp_rx_sn = 0; next_pdcp_rx_sn = 0;
@ -293,7 +294,6 @@ uint32_t pdcp_entity_lte::get_dl_count()
return rx_count; return rx_count;
} }
uint32_t pdcp_entity_lte::get_ul_count() uint32_t pdcp_entity_lte::get_ul_count()
{ {
return tx_count; return tx_count;
@ -303,8 +303,7 @@ uint32_t pdcp_entity_lte::get_ul_count()
* Pack/Unpack helper functions * Pack/Unpack helper functions
* Ref: 3GPP TS 36.323 v10.1.0 * Ref: 3GPP TS 36.323 v10.1.0
***************************************************************************/ ***************************************************************************/
void pdcp_pack_control_pdu(uint32_t sn, byte_buffer_t* sdu)
void pdcp_pack_control_pdu(uint32_t sn, byte_buffer_t *sdu)
{ {
// Make room and add header // Make room and add header
sdu->msg--; sdu->msg--;
@ -314,12 +313,11 @@ void pdcp_pack_control_pdu(uint32_t sn, byte_buffer_t *sdu)
// Add MAC // Add MAC
sdu->msg[sdu->N_bytes++] = (PDCP_CONTROL_MAC_I >> 24) & 0xFF; sdu->msg[sdu->N_bytes++] = (PDCP_CONTROL_MAC_I >> 24) & 0xFF;
sdu->msg[sdu->N_bytes++] = (PDCP_CONTROL_MAC_I >> 16) & 0xFF; sdu->msg[sdu->N_bytes++] = (PDCP_CONTROL_MAC_I >> 16) & 0xFF;
sdu->msg[sdu->N_bytes++] = (PDCP_CONTROL_MAC_I >> 8) & 0xFF; sdu->msg[sdu->N_bytes++] = (PDCP_CONTROL_MAC_I >> 8) & 0xFF;
sdu->msg[sdu->N_bytes++] = PDCP_CONTROL_MAC_I & 0xFF; sdu->msg[sdu->N_bytes++] = PDCP_CONTROL_MAC_I & 0xFF;
} }
void pdcp_unpack_control_pdu(byte_buffer_t *pdu, uint32_t *sn) void pdcp_unpack_control_pdu(byte_buffer_t* pdu, uint32_t* sn)
{ {
// Strip header // Strip header
*sn = *pdu->msg & 0x1F; *sn = *pdu->msg & 0x1F;
@ -332,7 +330,7 @@ void pdcp_unpack_control_pdu(byte_buffer_t *pdu, uint32_t *sn)
// TODO: integrity check MAC // TODO: integrity check MAC
} }
void pdcp_pack_data_pdu_short_sn(uint32_t sn, byte_buffer_t *sdu) void pdcp_pack_data_pdu_short_sn(uint32_t sn, byte_buffer_t* sdu)
{ {
// Make room and add header // Make room and add header
sdu->msg--; sdu->msg--;
@ -340,30 +338,29 @@ void pdcp_pack_data_pdu_short_sn(uint32_t sn, byte_buffer_t *sdu)
sdu->msg[0] = (PDCP_D_C_DATA_PDU << 7) | (sn & 0x7F); sdu->msg[0] = (PDCP_D_C_DATA_PDU << 7) | (sn & 0x7F);
} }
void pdcp_unpack_data_pdu_short_sn(byte_buffer_t *sdu, uint32_t *sn) void pdcp_unpack_data_pdu_short_sn(byte_buffer_t* sdu, uint32_t* sn)
{ {
// Strip header // Strip header
*sn = sdu->msg[0] & 0x7F; *sn = sdu->msg[0] & 0x7F;
sdu->msg++; sdu->msg++;
sdu->N_bytes--; sdu->N_bytes--;
} }
void pdcp_pack_data_pdu_long_sn(uint32_t sn, byte_buffer_t *sdu) void pdcp_pack_data_pdu_long_sn(uint32_t sn, byte_buffer_t* sdu)
{ {
// Make room and add header // Make room and add header
sdu->msg -= 2; sdu->msg -= 2;
sdu->N_bytes += 2; sdu->N_bytes += 2;
sdu->msg[0] = (PDCP_D_C_DATA_PDU << 7) | ((sn >> 8) & 0x0F); sdu->msg[0] = (PDCP_D_C_DATA_PDU << 7) | ((sn >> 8) & 0x0F);
sdu->msg[1] = sn & 0xFF; sdu->msg[1] = sn & 0xFF;
} }
void pdcp_unpack_data_pdu_long_sn(byte_buffer_t *sdu, uint32_t *sn) void pdcp_unpack_data_pdu_long_sn(byte_buffer_t* sdu, uint32_t* sn)
{ {
// Strip header // Strip header
*sn = (sdu->msg[0] & 0x0F) << 8; *sn = (sdu->msg[0] & 0x0F) << 8;
*sn |= sdu->msg[1]; *sn |= sdu->msg[1];
sdu->msg += 2; sdu->msg += 2;
sdu->N_bytes -= 2; sdu->N_bytes -= 2;
} }
} // namespace srslte
}

@ -20,8 +20,8 @@
*/ */
#include "srslte/upper/pdcp_entity_nr.h" #include "srslte/upper/pdcp_entity_nr.h"
#include "srslte/common/security.h"
#include "srslte/common/int_helpers.h" #include "srslte/common/int_helpers.h"
#include "srslte/common/security.h"
namespace srslte { namespace srslte {
@ -68,16 +68,18 @@ void pdcp_entity_nr::reset()
// SDAP/RRC interface // SDAP/RRC interface
void pdcp_entity_nr::write_sdu(unique_byte_buffer_t sdu, bool blocking) void pdcp_entity_nr::write_sdu(unique_byte_buffer_t sdu, bool blocking)
{ {
log->info_hex(sdu->msg, sdu->N_bytes, log->info_hex(sdu->msg,
"TX %s SDU, do_integrity = %s, do_encryption = %s", sdu->N_bytes,
rrc->get_rb_name(lcid).c_str(), "TX %s SDU, do_integrity = %s, do_encryption = %s",
(do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false"); rrc->get_rb_name(lcid).c_str(),
(do_integrity) ? "true" : "false",
(do_encryption) ? "true" : "false");
// Start discard timer TODO // Start discard timer TODO
// Perform header compression TODO // Perform header compression TODO
// Integrity protection // Integrity protection
uint8_t mac[4]; uint8_t mac[4];
integrity_generate(sdu->msg, sdu->N_bytes, tx_next, mac); integrity_generate(sdu->msg, sdu->N_bytes, tx_next, mac);
// Ciphering // Ciphering
@ -88,7 +90,7 @@ void pdcp_entity_nr::write_sdu(unique_byte_buffer_t sdu, bool blocking)
// Append MAC-I // Append MAC-I
append_mac(sdu, mac); append_mac(sdu, mac);
// Increment TX_NEXT // Increment TX_NEXT
tx_next++; tx_next++;
@ -150,10 +152,10 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu)
// TODO Store PDU in reception buffer // TODO Store PDU in reception buffer
// Update RX_NEXT // Update RX_NEXT
if(rcvd_count >= rx_next){ if (rcvd_count >= rx_next) {
rx_next = rcvd_count + 1; rx_next = rcvd_count + 1;
} }
// TODO if out-of-order configured, submit to upper layer // TODO if out-of-order configured, submit to upper layer
if (rcvd_count == rx_deliv) { if (rcvd_count == rx_deliv) {
@ -163,21 +165,21 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu)
} else { } else {
gw->write_pdu(lcid, std::move(pdu)); gw->write_pdu(lcid, std::move(pdu));
} }
// Update RX_DELIV // Update RX_DELIV
rx_deliv = rcvd_count + 1; // TODO needs to be corrected when queueing is implemented rx_deliv = rcvd_count + 1; // TODO needs to be corrected when queueing is implemented
printf("New RX_deliv %d, rcvd_count %d\n", rx_deliv, rcvd_count); printf("New RX_deliv %d, rcvd_count %d\n", rx_deliv, rcvd_count);
} }
// Not clear how to update RX_DELIV without reception buffer (TODO) // Not clear how to update RX_DELIV without reception buffer (TODO)
// TODO handle reordering timers // TODO handle reordering timers
} }
void pdcp_entity_nr::read_data_header(const unique_byte_buffer_t& pdu, uint32_t *rcvd_sn) void pdcp_entity_nr::read_data_header(const unique_byte_buffer_t& pdu, uint32_t* rcvd_sn)
{ {
// Check PDU is long enough to extract header // Check PDU is long enough to extract header
if(pdu->N_bytes <= cfg.hdr_len_bytes){ if (pdu->N_bytes <= cfg.hdr_len_bytes) {
log->error("PDU too small to extract header\n"); log->error("PDU too small to extract header\n");
return; return;
} }
@ -230,7 +232,7 @@ void pdcp_entity_nr::write_data_header(const srslte::unique_byte_buffer_t& sdu,
} }
} }
void pdcp_entity_nr::extract_mac(const unique_byte_buffer_t &pdu, uint8_t* mac) void pdcp_entity_nr::extract_mac(const unique_byte_buffer_t& pdu, uint8_t* mac)
{ {
// Check enough space for MAC // Check enough space for MAC
if (pdu->N_bytes < 4) { if (pdu->N_bytes < 4) {
@ -243,7 +245,7 @@ void pdcp_entity_nr::extract_mac(const unique_byte_buffer_t &pdu, uint8_t* mac)
pdu->N_bytes -= 4; pdu->N_bytes -= 4;
} }
void pdcp_entity_nr::append_mac(const unique_byte_buffer_t &sdu, uint8_t* mac) void pdcp_entity_nr::append_mac(const unique_byte_buffer_t& sdu, uint8_t* mac)
{ {
// Check enough space for MAC // Check enough space for MAC
if (sdu->N_bytes + 4 > sdu->get_tailroom()) { if (sdu->N_bytes + 4 > sdu->get_tailroom()) {
@ -255,5 +257,4 @@ void pdcp_entity_nr::append_mac(const unique_byte_buffer_t &sdu, uint8_t* mac)
memcpy(&sdu->msg[sdu->N_bytes], mac, 4); memcpy(&sdu->msg[sdu->N_bytes], mac, 4);
sdu->N_bytes += 4; sdu->N_bytes += 4;
} }
} // namespace srslte } // namespace srslte

@ -81,7 +81,7 @@ public:
} }
private: private:
srslte::log* log; srslte::log* log;
srslte::unique_byte_buffer_t last_pdcp_pdu; srslte::unique_byte_buffer_t last_pdcp_pdu;
bool rb_is_um(uint32_t lcid) { return false; } bool rb_is_um(uint32_t lcid) { return false; }
@ -109,7 +109,7 @@ class gw_dummy : public srsue::gw_interface_pdcp
public: public:
gw_dummy(srslte::log* log_) : log(log_) {} gw_dummy(srslte::log* log_) : log(log_) {}
void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {} void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {}
uint32_t rx_count = 0; uint32_t rx_count = 0;
void get_last_pdu(const srslte::unique_byte_buffer_t& pdu) void get_last_pdu(const srslte::unique_byte_buffer_t& pdu)
@ -126,24 +126,30 @@ public:
} }
private: private:
srslte::log* log; srslte::log* log;
srslte::unique_byte_buffer_t last_pdu; srslte::unique_byte_buffer_t last_pdu;
}; };
/* /*
* Genric function to test transmission of in-sequence packets * Genric function to test transmission of in-sequence packets
*/ */
int test_tx(uint32_t n_packets, uint8_t pdcp_sn_len, srslte::unique_byte_buffer_t pdu_exp, srslte::byte_buffer_pool* pool, srslte::log* log) int test_tx(uint32_t n_packets,
uint8_t pdcp_sn_len,
srslte::unique_byte_buffer_t pdu_exp,
srslte::byte_buffer_pool* pool,
srslte::log* log)
{ {
srslte::pdcp_entity_nr pdcp; srslte::pdcp_entity_nr pdcp;
srslte::srslte_pdcp_config_t cfg = {1, srslte::PDCP_RB_IS_DRB, SECURITY_DIRECTION_UPLINK, SECURITY_DIRECTION_DOWNLINK, pdcp_sn_len}; srslte::srslte_pdcp_config_t cfg = {
1, srslte::PDCP_RB_IS_DRB, SECURITY_DIRECTION_UPLINK, SECURITY_DIRECTION_DOWNLINK, pdcp_sn_len};
rlc_dummy rlc(log); rlc_dummy rlc(log);
rrc_dummy rrc(log); rrc_dummy rrc(log);
gw_dummy gw(log); gw_dummy gw(log);
pdcp.init(&rlc, &rrc, &gw, log, 0, cfg); pdcp.init(&rlc, &rrc, &gw, log, 0, cfg);
pdcp.config_security(k_enc, k_int, k_enc, k_int, srslte::CIPHERING_ALGORITHM_ID_128_EEA2, srslte::INTEGRITY_ALGORITHM_ID_128_EIA2); pdcp.config_security(
k_enc, k_int, k_enc, k_int, srslte::CIPHERING_ALGORITHM_ID_128_EEA2, srslte::INTEGRITY_ALGORITHM_ID_128_EIA2);
pdcp.enable_integrity(); pdcp.enable_integrity();
pdcp.enable_encryption(); pdcp.enable_encryption();
@ -186,7 +192,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
srslte::unique_byte_buffer_t pdu_exp_sn0_len12 = allocate_unique_buffer(*pool); srslte::unique_byte_buffer_t pdu_exp_sn0_len12 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn0_len12->msg, pdu1, PDU1_LEN); memcpy(pdu_exp_sn0_len12->msg, pdu1, PDU1_LEN);
pdu_exp_sn0_len12->N_bytes = PDU1_LEN; pdu_exp_sn0_len12->N_bytes = PDU1_LEN;
//TESTASSERT(test_tx(1, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn0_len12), pool, log) == 0); TESTASSERT(test_tx(1, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn0_len12), pool, log) == 0);
/* /*
* TX Test 2: PDCP Entity with SN LEN = 12 * TX Test 2: PDCP Entity with SN LEN = 12
@ -198,7 +204,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
srslte::unique_byte_buffer_t pdu_exp_sn2048_len12 = allocate_unique_buffer(*pool); srslte::unique_byte_buffer_t pdu_exp_sn2048_len12 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn2048_len12->msg, pdu2, PDU2_LEN); memcpy(pdu_exp_sn2048_len12->msg, pdu2, PDU2_LEN);
pdu_exp_sn2048_len12->N_bytes = PDU2_LEN; pdu_exp_sn2048_len12->N_bytes = PDU2_LEN;
//TESTASSERT(test_tx(2049, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn2048_len12), pool, log) == 0); TESTASSERT(test_tx(2049, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn2048_len12), pool, log) == 0);
/* /*
* TX Test 3: PDCP Entity with SN LEN = 12 * TX Test 3: PDCP Entity with SN LEN = 12
@ -210,7 +216,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
srslte::unique_byte_buffer_t pdu_exp_sn4096_len12 = allocate_unique_buffer(*pool); srslte::unique_byte_buffer_t pdu_exp_sn4096_len12 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn4096_len12->msg, pdu3, PDU3_LEN); memcpy(pdu_exp_sn4096_len12->msg, pdu3, PDU3_LEN);
pdu_exp_sn4096_len12->N_bytes = PDU3_LEN; pdu_exp_sn4096_len12->N_bytes = PDU3_LEN;
//TESTASSERT(test_tx(4097, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn4096_len12), pool, log) == 0); TESTASSERT(test_tx(4097, srslte::PDCP_SN_LEN_12, std::move(pdu_exp_sn4096_len12), pool, log) == 0);
/* /*
* TX Test 4: PDCP Entity with SN LEN = 18 * TX Test 4: PDCP Entity with SN LEN = 18
@ -324,7 +330,6 @@ int run_all_tests(srslte::byte_buffer_pool* pool)
return 0; return 0;
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
run_all_tests(srslte::byte_buffer_pool::get_instance()); run_all_tests(srslte::byte_buffer_pool::get_instance());

@ -3145,11 +3145,11 @@ void rrc::handle_con_reest(rrc_conn_reest_s* setup)
void rrc::add_srb(srb_to_add_mod_s* srb_cnfg) void rrc::add_srb(srb_to_add_mod_s* srb_cnfg)
{ {
// Setup PDCP // Setup PDCP
srslte_pdcp_config_t pdcp_cfg = {.bearer_id = srb_cnfg->srb_id, srslte_pdcp_config_t pdcp_cfg = {.bearer_id = srb_cnfg->srb_id,
.rb_type = PDCP_RB_IS_SRB, .rb_type = PDCP_RB_IS_SRB,
.tx_direction = SECURITY_DIRECTION_UPLINK, .tx_direction = SECURITY_DIRECTION_UPLINK,
.rx_direction = SECURITY_DIRECTION_DOWNLINK, .rx_direction = SECURITY_DIRECTION_DOWNLINK,
.sn_len = PDCP_SN_LEN_5}; .sn_len = PDCP_SN_LEN_5};
pdcp->add_bearer(srb_cnfg->srb_id, pdcp_cfg); pdcp->add_bearer(srb_cnfg->srb_id, pdcp_cfg);
if (RB_ID_SRB2 == srb_cnfg->srb_id) { if (RB_ID_SRB2 == srb_cnfg->srb_id) {
pdcp->config_security(srb_cnfg->srb_id, k_rrc_enc, k_rrc_int, k_up_enc, cipher_algo, integ_algo); pdcp->config_security(srb_cnfg->srb_id, k_rrc_enc, k_rrc_int, k_up_enc, cipher_algo, integ_algo);
@ -3222,11 +3222,11 @@ void rrc::add_drb(drb_to_add_mod_s* drb_cnfg)
} }
// Setup PDCP // Setup PDCP
srslte_pdcp_config_t pdcp_cfg = {.bearer_id = drb_cnfg->drb_id, srslte_pdcp_config_t pdcp_cfg = {.bearer_id = drb_cnfg->drb_id,
.rb_type = PDCP_RB_IS_DRB, .rb_type = PDCP_RB_IS_DRB,
.tx_direction = SECURITY_DIRECTION_UPLINK, .tx_direction = SECURITY_DIRECTION_UPLINK,
.rx_direction = SECURITY_DIRECTION_DOWNLINK, .rx_direction = SECURITY_DIRECTION_DOWNLINK,
.sn_len = PDCP_SN_LEN_12}; .sn_len = PDCP_SN_LEN_12};
if (drb_cnfg->pdcp_cfg.rlc_um_present) { if (drb_cnfg->pdcp_cfg.rlc_um_present) {
if (drb_cnfg->pdcp_cfg.rlc_um.pdcp_sn_size == pdcp_cfg_s::rlc_um_s_::pdcp_sn_size_e_::len7bits) { if (drb_cnfg->pdcp_cfg.rlc_um.pdcp_sn_size == pdcp_cfg_s::rlc_um_s_::pdcp_sn_size_e_::len7bits) {
pdcp_cfg.sn_len = 7; pdcp_cfg.sn_len = 7;

Loading…
Cancel
Save