Small PDCP fixes:

- Moved most the initialization of the pdcp_entity to the header.
  - Initilize some variables in gtpu_ntoa.
  - Removed debug print.
  - Format eNB GTP-u debugging code.
master
Pedro Alvarez 5 years ago committed by Andre Puschmann
parent 1c51d2ca9a
commit 498f1b8e4b

@ -87,58 +87,44 @@ public:
void write_pdu(unique_byte_buffer_t pdu);
private:
byte_buffer_pool *pool;
srslte::log *log;
srsue::rlc_interface_pdcp *rlc;
srsue::rrc_interface_pdcp *rrc;
srsue::gw_interface_pdcp *gw;
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;
uint32_t reordering_window;
uint32_t last_submitted_pdcp_rx_sn;
CIPHERING_ALGORITHM_ID_ENUM cipher_algo;
INTEGRITY_ALGORITHM_ID_ENUM integ_algo;
uint32_t maximum_pdcp_sn;
byte_buffer_pool* pool = byte_buffer_pool::get_instance();
srslte::log* log = nullptr;
srsue::rlc_interface_pdcp* rlc = nullptr;
srsue::rrc_interface_pdcp* rrc = nullptr;
srsue::gw_interface_pdcp* gw = nullptr;
bool active = false;
uint32_t lcid = 0;
srslte_pdcp_config_t cfg = {};
uint8_t sn_len_bytes = 0;
bool do_integrity = false;
bool do_encryption = false;
uint32_t rx_count = 0;
uint32_t tx_count = 0;
uint8_t k_rrc_enc[32] = {};
uint8_t k_rrc_int[32] = {};
uint8_t k_up_enc[32] = {};
uint32_t rx_hfn = 0;
uint32_t next_pdcp_rx_sn = 0;
uint32_t reordering_window = 0;
uint32_t last_submitted_pdcp_rx_sn = 0;
uint32_t maximum_pdcp_sn = 0;
CIPHERING_ALGORITHM_ID_ENUM cipher_algo = CIPHERING_ALGORITHM_ID_EEA0;
INTEGRITY_ALGORITHM_ID_ENUM integ_algo = INTEGRITY_ALGORITHM_ID_EIA0;
pthread_mutex_t mutex;
void handle_um_drb_pdu(const srslte::unique_byte_buffer_t& pdu);
void handle_am_drb_pdu(const srslte::unique_byte_buffer_t& pdu);
void integrity_generate(uint8_t *msg,
uint32_t msg_len,
uint8_t *mac);
bool integrity_verify(uint8_t *msg,
uint32_t count,
uint32_t msg_len,
uint8_t *mac);
void cipher_encrypt(uint8_t *msg,
uint32_t msg_len,
uint8_t *ct);
void cipher_decrypt(uint8_t *ct,
uint32_t count,
uint32_t ct_len,
uint8_t *msg);
void integrity_generate(uint8_t* msg, uint32_t msg_len, uint8_t* mac);
bool integrity_verify(uint8_t* msg, uint32_t count, uint32_t msg_len, uint8_t* mac);
void cipher_encrypt(uint8_t* msg, uint32_t msg_len, uint8_t* ct);
void cipher_decrypt(uint8_t* ct, uint32_t count, uint32_t ct_len, uint8_t* msg);
};
/****************************************************************************

@ -143,9 +143,9 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte:
// Helper function to return a string from IPv4 address for easy printing
std::string gtpu_ntoa(uint32_t addr)
{
char tmp_str[INET_ADDRSTRLEN + 1];
bzero(tmp_str, sizeof(tmp_str));
struct in_addr tmp_addr;
char tmp_str[INET_ADDRSTRLEN + 1] = {};
struct in_addr tmp_addr = {};
tmp_addr.s_addr = addr;
const char* tmp_ptr = inet_ntop(AF_INET, &tmp_addr, tmp_str, INET_ADDRSTRLEN);
if (tmp_ptr == NULL) {

@ -24,24 +24,9 @@
namespace srslte {
pdcp_entity::pdcp_entity() : active(false), tx_count(0)
pdcp_entity::pdcp_entity()
{
pool = byte_buffer_pool::get_instance();
log = NULL;
rlc = NULL;
rrc = NULL;
gw = NULL;
lcid = 0;
sn_len_bytes = 0;
do_integrity = false;
do_encryption = false;
tx_count = 0;
rx_count = 0;
rx_hfn = 0;
next_pdcp_rx_sn = 0;
cipher_algo = CIPHERING_ALGORITHM_ID_EEA0;
integ_algo = INTEGRITY_ALGORITHM_ID_EIA0;
pthread_mutex_init(&mutex, NULL);
pthread_mutex_init(&mutex, nullptr);
}
pdcp_entity::~pdcp_entity()
@ -49,12 +34,12 @@ pdcp_entity::~pdcp_entity()
pthread_mutex_destroy(&mutex);
}
void pdcp_entity::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_)
void pdcp_entity::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_)
{
rlc = rlc_;
rrc = rrc_;
@ -465,13 +450,12 @@ void pdcp_entity::cipher_encrypt(uint8_t *msg,
k_enc = k_up_enc;
}
log->debug("Cipher encript input:\n");
log->debug("Cipher encrypt input:\n");
log->debug_hex(&k_enc[16], 16, " K_enc");
log->debug(" Local count: %d\n", tx_count);
log->debug(" TX HFN: %d COUNT %d\n", (tx_count >> cfg.sn_len), (tx_count << (32-cfg.sn_len)) >> (32-cfg.sn_len));
log->debug(" Bearer ID: %d\n", cfg.bearer_id);
log->debug(" Direction: %s\n", (cfg.direction == SECURITY_DIRECTION_DOWNLINK) ? "Downlink" : "Uplink");
log->debug("Encripting COUNT %d \n", tx_count);
switch(cipher_algo)
{
@ -515,7 +499,7 @@ void pdcp_entity::cipher_decrypt(uint8_t *ct,
} else {
k_enc = k_up_enc;
}
log->info("Decripting COUNT %d \n", count);
switch(cipher_algo)
{
case CIPHERING_ALGORITHM_ID_EEA0:

@ -117,11 +117,12 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t
gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d, n_bytes=%d", rnti, lcid, pdu->N_bytes);
// Check valid IP version
struct iphdr* ip_pkt = (struct iphdr*)pdu->msg;
struct iphdr* ip_pkt = (struct iphdr*)pdu->msg;
if (ip_pkt->version != 4 && ip_pkt->version != 6) {
gtpu_log->error("Invalid IP version to SPGW\n");
return;
} else if (ip_pkt->version == 4) {
if(ntohs(ip_pkt->tot_len) != pdu->N_bytes){
if (ntohs(ip_pkt->tot_len) != pdu->N_bytes) {
gtpu_log->error("IP Len and PDU N_bytes mismatch\n");
}
gtpu_log->debug("S1-U PDU -- IP version %d, Total length %d\n", ip_pkt->version, ntohs(ip_pkt->tot_len));
@ -129,7 +130,6 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t
gtpu_log->debug("S1-U PDU -- IP dst addr %s\n", srslte::gtpu_ntoa(ip_pkt->daddr).c_str());
}
gtpu_header_t header;
header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL;
header.message_type = GTPU_MSG_DATA_PDU;

Loading…
Cancel
Save