add mutex in pdcp entity

write_sdu and write_pdu are not re-entrant because all functions
that deal with the counters, e.g. integrity check and generate,
must be protected because MAC threads may call them at the same time.

this addresses issue #254
master
Andre Puschmann 6 years ago
parent bdbdef41c0
commit 955f5dd37a

@ -64,6 +64,7 @@ class pdcp_entity : public pdcp_entity_interface
{ {
public: public:
pdcp_entity(); pdcp_entity();
~pdcp_entity();
void init(srsue::rlc_interface_pdcp *rlc_, void init(srsue::rlc_interface_pdcp *rlc_,
srsue::rrc_interface_pdcp *rrc_, srsue::rrc_interface_pdcp *rrc_,
srsue::gw_interface_pdcp *gw_, srsue::gw_interface_pdcp *gw_,
@ -112,6 +113,8 @@ private:
CIPHERING_ALGORITHM_ID_ENUM cipher_algo; CIPHERING_ALGORITHM_ID_ENUM cipher_algo;
INTEGRITY_ALGORITHM_ID_ENUM integ_algo; INTEGRITY_ALGORITHM_ID_ENUM integ_algo;
pthread_mutex_t mutex;
void integrity_generate(uint8_t *msg, void integrity_generate(uint8_t *msg,
uint32_t msg_len, uint32_t msg_len,
uint8_t *mac); uint8_t *mac);

@ -46,6 +46,12 @@ pdcp_entity::pdcp_entity()
rx_count = 0; rx_count = 0;
cipher_algo = CIPHERING_ALGORITHM_ID_EEA0; cipher_algo = CIPHERING_ALGORITHM_ID_EEA0;
integ_algo = INTEGRITY_ALGORITHM_ID_EIA0; integ_algo = INTEGRITY_ALGORITHM_ID_EIA0;
pthread_mutex_init(&mutex, NULL);
}
pdcp_entity::~pdcp_entity()
{
pthread_mutex_destroy(&mutex);
} }
void pdcp_entity::init(srsue::rlc_interface_pdcp *rlc_, void pdcp_entity::init(srsue::rlc_interface_pdcp *rlc_,
@ -119,6 +125,8 @@ void pdcp_entity::write_sdu(byte_buffer_t *sdu, bool blocking)
rrc->get_rb_name(lcid).c_str(), tx_count, rrc->get_rb_name(lcid).c_str(), tx_count,
(do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false"); (do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false");
pthread_mutex_lock(&mutex);
if (cfg.is_control) { if (cfg.is_control) {
pdcp_pack_control_pdu(tx_count, sdu); pdcp_pack_control_pdu(tx_count, sdu);
if(do_integrity) { if(do_integrity) {
@ -144,6 +152,8 @@ void pdcp_entity::write_sdu(byte_buffer_t *sdu, bool blocking)
} }
tx_count++; tx_count++;
pthread_mutex_unlock(&mutex);
rlc->write_sdu(lcid, sdu, blocking); rlc->write_sdu(lcid, sdu, blocking);
} }
@ -183,6 +193,8 @@ void pdcp_entity::write_pdu(byte_buffer_t *pdu)
return; return;
} }
pthread_mutex_lock(&mutex);
// Handle DRB messages // Handle DRB messages
if (cfg.is_data) { if (cfg.is_data) {
uint32_t sn; uint32_t sn;
@ -231,6 +243,7 @@ void pdcp_entity::write_pdu(byte_buffer_t *pdu)
} }
exit: exit:
rx_count++; rx_count++;
pthread_mutex_unlock(&mutex);
} }
void pdcp_entity::integrity_generate( uint8_t *msg, void pdcp_entity::integrity_generate( uint8_t *msg,

Loading…
Cancel
Save