change queue read and other functions apis

This commit is contained in:
Francisco Paisana 2019-05-02 11:36:46 +01:00 committed by Andre Puschmann
parent f469e2178b
commit f4aa03154d
7 changed files with 31 additions and 33 deletions

View File

@ -124,7 +124,7 @@ public:
while (try_pop(item));
}
myobj& front() { return q.front(); }
const myobj& front() const { return q.front(); }
size_t size() {
return q.size();

View File

@ -57,7 +57,7 @@ public:
bool try_write(unique_byte_buffer msg) { return queue.try_push(std::move(msg)); }
void read(unique_byte_buffer* msg) { *msg = std::move(queue.wait_pop()); }
unique_byte_buffer read() { return queue.wait_pop(); }
bool try_read(unique_byte_buffer* msg) { return queue.try_pop(msg); }
@ -78,7 +78,7 @@ public:
uint32_t size_tail_bytes()
{
if (!queue.empty()) {
unique_byte_buffer& m = queue.front();
const unique_byte_buffer& m = queue.front();
if (m.get()) {
return m->N_bytes;
}

View File

@ -270,8 +270,7 @@ void rlc_am::rlc_am_tx::empty_queue()
// deallocate all SDUs in transmit queue
while(tx_sdu_queue.size() > 0) {
unique_byte_buffer buf;
tx_sdu_queue.read(&buf);
unique_byte_buffer buf = tx_sdu_queue.read();
}
// deallocate SDU that is currently processed
@ -862,7 +861,7 @@ int rlc_am::rlc_am_tx::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
header.N_li--;
break;
}
tx_sdu_queue.read(&tx_sdu);
tx_sdu = tx_sdu_queue.read();
to_move = ((pdu_space-head_len) >= tx_sdu->N_bytes) ? tx_sdu->N_bytes : pdu_space-head_len;
memcpy(pdu_ptr, tx_sdu->msg, to_move);
last_li = to_move;

View File

@ -271,8 +271,7 @@ void rlc_um::rlc_um_tx::empty_queue()
// deallocate all SDUs in transmit queue
while(tx_sdu_queue.size() > 0) {
unique_byte_buffer buf;
tx_sdu_queue.read(&buf);
unique_byte_buffer buf = tx_sdu_queue.read();
}
// deallocate SDU that is currently processed
@ -436,7 +435,7 @@ int rlc_um::rlc_um_tx::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
if(last_li > 0)
header.li[header.N_li++] = last_li;
head_len = rlc_um_packed_length(&header);
tx_sdu_queue.read(&tx_sdu);
tx_sdu = tx_sdu_queue.read();
uint32_t space = pdu_space-head_len;
to_move = space >= tx_sdu->N_bytes ? tx_sdu->N_bytes : space;
log->debug("%s adding new SDU segment - %d bytes of %d remaining\n",

View File

@ -59,7 +59,7 @@ int main(int argc, char **argv) {
for(uint32_t i=0;i<NMSGS;i++)
{
q.read(&b);
b = q.read();
memcpy(&r, b->msg, 4);
if(r != i)
result = false;

View File

@ -161,9 +161,9 @@ private:
uint8_t *msg,
uint32_t msg_len,
uint8_t *mac);
bool integrity_check(srslte::unique_byte_buffer& pdu);
void cipher_encrypt(srslte::unique_byte_buffer& pdu);
void cipher_decrypt(srslte::unique_byte_buffer& pdu);
bool integrity_check(srslte::byte_buffer_t* pdu);
void cipher_encrypt(srslte::byte_buffer_t* pdu);
void cipher_decrypt(srslte::byte_buffer_t* pdu);
void set_k_enb_count(uint32_t count);
bool check_cap_replay(LIBLTE_MME_UE_SECURITY_CAPABILITIES_STRUCT *caps);
@ -184,8 +184,8 @@ private:
void parse_emm_status(uint32_t lcid, srslte::unique_byte_buffer pdu);
// Packet generators
void gen_attach_request(srslte::unique_byte_buffer& msg);
void gen_service_request(srslte::unique_byte_buffer& msg);
void gen_attach_request(srslte::byte_buffer_t* msg);
void gen_service_request(srslte::byte_buffer_t* msg);
// Senders
void send_identity_response(uint32_t lcid, uint8 id_type);

View File

@ -264,9 +264,9 @@ bool nas::rrc_connect() {
}
if (state == EMM_STATE_REGISTERED) {
gen_service_request(dedicatedInfoNAS);
gen_service_request(dedicatedInfoNAS.get());
} else {
gen_attach_request(dedicatedInfoNAS);
gen_attach_request(dedicatedInfoNAS.get());
}
// Provide UE-Identity to RRC if have one
@ -352,9 +352,9 @@ void nas::write_pdu(uint32_t lcid, unique_byte_buffer pdu)
break;
case LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY:
case LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED:
if((integrity_check(pdu))) {
if ((integrity_check(pdu.get()))) {
if (sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED) {
cipher_decrypt(pdu);
cipher_decrypt(pdu.get());
}
break;
} else {
@ -506,7 +506,7 @@ void nas::integrity_generate(uint8_t *key_128,
// This function depends to a valid k_nas_int.
// This key is generated in the security mode command.
bool nas::integrity_check(unique_byte_buffer& pdu)
bool nas::integrity_check(byte_buffer_t* pdu)
{
if (!pdu) {
nas_log->error("Invalid PDU\n");
@ -543,7 +543,7 @@ bool nas::integrity_check(unique_byte_buffer& pdu)
}
}
void nas::cipher_encrypt(unique_byte_buffer& pdu)
void nas::cipher_encrypt(byte_buffer_t* pdu)
{
byte_buffer_t pdu_tmp;
switch(ctxt.cipher_algo)
@ -576,7 +576,7 @@ void nas::cipher_encrypt(unique_byte_buffer& pdu)
}
}
void nas::cipher_decrypt(unique_byte_buffer& pdu)
void nas::cipher_decrypt(byte_buffer_t* pdu)
{
byte_buffer_t tmp_pdu;
switch(ctxt.cipher_algo)
@ -846,7 +846,7 @@ void nas::parse_attach_accept(uint32_t lcid, unique_byte_buffer pdu)
pcap->write_nas(pdu->msg, pdu->N_bytes);
}
cipher_encrypt(pdu);
cipher_encrypt(pdu.get());
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
SECURITY_DIRECTION_UPLINK,
@ -1022,7 +1022,7 @@ void nas::parse_security_mode_command(uint32_t lcid, unique_byte_buffer pdu)
nas_log->debug("Generating integrity check. integ_algo:%d, count_dl:%d, lcid:%d\n",
ctxt.integ_algo, ctxt.rx_count, lcid);
if (integrity_check(pdu) != true) {
if (integrity_check(pdu.get()) != true) {
nas_log->warning("Sending Security Mode Reject due to integrity check failure\n");
send_security_mode_reject(LIBLTE_MME_EMM_CAUSE_MAC_FAILURE);
return;
@ -1053,7 +1053,7 @@ void nas::parse_security_mode_command(uint32_t lcid, unique_byte_buffer pdu)
if(pcap != NULL) {
pcap->write_nas(pdu->msg, pdu->N_bytes);
}
cipher_encrypt(pdu);
cipher_encrypt(pdu.get());
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
SECURITY_DIRECTION_UPLINK,
@ -1153,7 +1153,7 @@ void nas::parse_emm_status(uint32_t lcid, unique_byte_buffer pdu)
* Senders
******************************************************************************/
void nas::gen_attach_request(unique_byte_buffer& msg)
void nas::gen_attach_request(byte_buffer_t* msg)
{
if (!msg) {
nas_log->error("Fatal Error: Couldn't allocate PDU in gen_attach_request().\n");
@ -1210,7 +1210,7 @@ void nas::gen_attach_request(unique_byte_buffer& msg)
"m_tmsi: %x, mcc: %x, mnc: %x, mme_group_id: %x, mme_code: %x\n",
ctxt.guti.m_tmsi, ctxt.guti.mcc, ctxt.guti.mnc, ctxt.guti.mme_group_id, ctxt.guti.mme_code);
liblte_mme_pack_attach_request_msg(
&attach_req, LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY, ctxt.tx_count, (LIBLTE_BYTE_MSG_STRUCT*)msg.get());
&attach_req, LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY, ctxt.tx_count, (LIBLTE_BYTE_MSG_STRUCT*)msg);
// Add MAC
if (msg->N_bytes > 5) {
@ -1229,7 +1229,7 @@ void nas::gen_attach_request(unique_byte_buffer& msg)
attach_req.nas_ksi.nas_ksi = 0;
usim->get_imsi_vec(attach_req.eps_mobile_id.imsi, 15);
nas_log->info("Requesting IMSI attach (IMSI=%s)\n", usim->get_imsi_str().c_str());
liblte_mme_pack_attach_request_msg(&attach_req, (LIBLTE_BYTE_MSG_STRUCT*)msg.get());
liblte_mme_pack_attach_request_msg(&attach_req, (LIBLTE_BYTE_MSG_STRUCT*)msg);
}
if(pcap != NULL) {
@ -1242,7 +1242,7 @@ void nas::gen_attach_request(unique_byte_buffer& msg)
}
}
void nas::gen_service_request(unique_byte_buffer& msg)
void nas::gen_service_request(byte_buffer_t* msg)
{
if (!msg) {
nas_log->error("Fatal Error: Couldn't allocate PDU in gen_service_request().\n");
@ -1377,7 +1377,7 @@ void nas::send_detach_request(bool switch_off)
// Add MAC
if (pdu->N_bytes > 5) {
if (rrc->is_connected()) {
cipher_encrypt(pdu);
cipher_encrypt(pdu.get());
}
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
@ -1432,7 +1432,7 @@ void nas::send_detach_accept()
// Encrypt and add MAC
if (pdu->N_bytes > 5) {
cipher_encrypt(pdu);
cipher_encrypt(pdu.get());
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
SECURITY_DIRECTION_UPLINK,
@ -1470,7 +1470,7 @@ void nas::send_authentication_response(const uint8_t* res, const size_t res_len,
}
if (sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED && pdu->N_bytes > 5) {
cipher_encrypt(pdu);
cipher_encrypt(pdu.get());
integrity_generate(&k_nas_int[16],
ctxt.tx_count,
SECURITY_DIRECTION_UPLINK,
@ -1689,7 +1689,7 @@ void nas::send_esm_information_response(const uint8 proc_transaction_id) {
pcap->write_nas(pdu->msg, pdu->N_bytes);
}
cipher_encrypt(pdu);
cipher_encrypt(pdu.get());
if (pdu->N_bytes > 5) {
integrity_generate(&k_nas_int[16],
ctxt.tx_count,