pdu: fix formatting

This commit is contained in:
Andre Puschmann 2019-05-30 09:35:33 +02:00
parent 77d4197364
commit 709e769d0d
2 changed files with 453 additions and 452 deletions

View File

@ -22,11 +22,11 @@
#ifndef SRSLTE_PDU_H
#define SRSLTE_PDU_H
#include <stdint.h>
#include "srslte/common/log.h"
#include "srslte/common/interfaces_common.h"
#include <vector>
#include "srslte/common/log.h"
#include <stdint.h>
#include <stdio.h>
#include <vector>
/* MAC PDU Packing/Unpacking functions. Section 6 of 36.321 */
class subh;
@ -52,7 +52,8 @@ public:
{
}
void fprint(FILE *stream) {
void fprint(FILE* stream)
{
fprintf(stream, "Number of Subheaders: %d\n", nof_subheaders);
for (int i = 0; i < nof_subheaders; i++) {
fprintf(stream, " -- Subheader %d: ", i);
@ -61,25 +62,24 @@ public:
}
/* Resets the Read/Write position and remaining PDU length */
void reset() {
void reset()
{
cur_idx = -1;
last_sdu_idx = -1;
rem_len = pdu_len;
}
void init_rx(uint32_t pdu_len_bytes, bool is_ulsch = false) {
init_(NULL, pdu_len_bytes, is_ulsch);
}
void init_rx(uint32_t pdu_len_bytes, bool is_ulsch = false) { init_(NULL, pdu_len_bytes, is_ulsch); }
void init_tx(uint8_t *payload, uint32_t pdu_len_bytes, bool is_ulsch = false) {
void init_tx(uint8_t* payload, uint32_t pdu_len_bytes, bool is_ulsch = false)
{
init_(payload, pdu_len_bytes, is_ulsch);
}
uint32_t nof_subh() {
return nof_subheaders;
}
uint32_t nof_subh() { return nof_subheaders; }
bool new_subh() {
bool new_subh()
{
if (nof_subheaders < (int)max_subheaders - 1 && rem_len > 0) {
nof_subheaders++;
next();
@ -89,7 +89,8 @@ public:
}
}
bool next() {
bool next()
{
if (cur_idx < nof_subheaders - 1) {
cur_idx++;
return true;
@ -98,7 +99,8 @@ public:
}
}
void del_subh() {
void del_subh()
{
if (nof_subheaders > 0) {
nof_subheaders--;
}
@ -107,7 +109,8 @@ public:
}
}
SubH* get() {
SubH* get()
{
if (cur_idx >= 0) {
return &subheaders[cur_idx];
} else {
@ -115,20 +118,15 @@ public:
}
}
bool is_ul() {
return pdu_is_ul;
}
bool is_ul() { return pdu_is_ul; }
uint8_t* get_current_sdu_ptr() {
return &buffer_tx[total_sdu_len+sdu_offset_start];
}
uint8_t* get_current_sdu_ptr() { return &buffer_tx[total_sdu_len + sdu_offset_start]; }
void add_sdu(uint32_t sdu_sz) {
total_sdu_len += sdu_sz;
}
void add_sdu(uint32_t sdu_sz) { total_sdu_len += sdu_sz; }
// Section 6.1.2
void parse_packet(uint8_t *ptr) {
void parse_packet(uint8_t* ptr)
{
uint8_t* init_ptr = ptr;
nof_subheaders = 0;
bool ret = false;
@ -144,7 +142,6 @@ public:
}
}
protected:
std::vector<SubH> subheaders;
uint32_t pdu_len;
@ -158,9 +155,9 @@ protected:
uint32_t sdu_offset_start;
int last_sdu_idx;
/* Prepares the PDU for parsing or writing by setting the number of subheaders to 0 and the pdu length */
virtual void init_(uint8_t *buffer_tx_ptr, uint32_t pdu_len_bytes, bool is_ulsch) {
virtual void init_(uint8_t* buffer_tx_ptr, uint32_t pdu_len_bytes, bool is_ulsch)
{
nof_subheaders = 0;
pdu_len = pdu_len_bytes;
rem_len = pdu_len;
@ -177,13 +174,7 @@ protected:
}
};
typedef enum {
SCH_SUBH_TYPE = 0,
MCH_SUBH_TYPE = 1,
RAR_SUBH_TYPE = 2
} subh_type;
typedef enum { SCH_SUBH_TYPE = 0, MCH_SUBH_TYPE = 1, RAR_SUBH_TYPE = 2 } subh_type;
template <class SubH>
class subh
@ -199,15 +190,16 @@ public:
virtual void fprint(FILE* stream) = 0;
pdu<SubH>* parent;
private:
virtual void init() = 0;
};
class sch_subh : public subh<sch_subh>
{
public:
sch_subh(subh_type type_ = SCH_SUBH_TYPE) {
sch_subh(subh_type type_ = SCH_SUBH_TYPE)
{
lcid = 0;
nof_bytes = 0;
payload = NULL;
@ -294,9 +286,7 @@ public:
bool set_next_mch_sched_info(uint8_t lcid, uint16_t mtch_stop);
protected:
static const int MAX_CE_PAYLOAD_LEN = 8;
uint32_t lcid;
int nof_bytes;
@ -313,7 +303,6 @@ private:
static uint8_t phr_report_table(float phr_value);
};
class sch_pdu : public pdu<sch_subh>
{
public:
@ -332,7 +321,6 @@ public:
bool update_space_ce(uint32_t nbytes, bool var_len = false);
bool update_space_sdu(uint32_t nbytes);
void fprint(FILE* stream);
};
class rar_subh : public subh<rar_subh>
@ -340,7 +328,8 @@ class rar_subh : public subh<rar_subh>
public:
typedef enum { BACKOFF = 0, RAPID } rar_subh_type_t;
rar_subh() {
rar_subh()
{
bzero(&grant, sizeof(grant));
ta = 0;
temp_rnti = 0;
@ -382,7 +371,6 @@ private:
class rar_pdu : public pdu<rar_subh>
{
public:
rar_pdu(uint32_t max_rars = 16);
void set_backoff(uint8_t bi);
@ -412,9 +400,9 @@ public:
mch_pdu(uint32_t max_subh) : sch_pdu(max_subh) {}
private:
/* Prepares the PDU for parsing or writing by setting the number of subheaders to 0 and the pdu length */
virtual void init_(uint8_t *buffer_tx_ptr, uint32_t pdu_len_bytes, bool is_ulsch) {
virtual void init_(uint8_t* buffer_tx_ptr, uint32_t pdu_len_bytes, bool is_ulsch)
{
nof_subheaders = 0;
pdu_len = pdu_len_bytes;
rem_len = pdu_len;
@ -433,8 +421,6 @@ private:
}
};
} // namespace srsue
} // namespace srslte
#endif // MACPDU_H

View File

@ -19,20 +19,19 @@
*
*/
#include <strings.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "srslte/common/pdu.h"
#include "srslte/srslte.h"
// Table 6.1.3.1-1 Buffer size levels for BSR
static uint32_t btable[64] = {
0, 1, 10, 12, 14, 17, 19, 22, 26, 31, 36, 42, 49, 57, 67, 78, 91, 107, 125, 146, 171, 200, 234, 274, 321, 376, 440, 515, 603, 706, 826, 967, 1132,
1326, 1552, 1817, 2127, 2490, 2915, 3413, 3995, 4667, 5476, 6411, 7505, 8787, 10287, 12043, 14099, 16507, 19325, 22624, 26487, 31009, 36304,
42502, 49759, 58255, 68201, 79846, 93479, 109439, 128125, 150000};
0, 1, 10, 12, 14, 17, 19, 22, 26, 31, 36, 42, 49, 57, 67, 78,
91, 107, 125, 146, 171, 200, 234, 274, 321, 376, 440, 515, 603, 706, 826, 967,
1132, 1326, 1552, 1817, 2127, 2490, 2915, 3413, 3995, 4667, 5476, 6411, 7505, 8787, 10287, 12043,
14099, 16507, 19325, 22624, 26487, 31009, 36304, 42502, 49759, 58255, 68201, 79846, 93479, 109439, 128125, 150000};
namespace srslte {
@ -63,7 +62,8 @@ void sch_pdu::parse_packet(uint8_t *ptr)
}
}
uint8_t* sch_pdu::write_packet() {
uint8_t* sch_pdu::write_packet()
{
return write_packet(NULL);
}
@ -108,7 +108,6 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h)
rem_len = 0;
}
/* Determine the header size and CE payload size */
uint32_t header_sz = 0;
uint32_t ce_payload_sz = 0;
@ -174,13 +173,30 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h)
/* Sanity check and print if error */
if (log_h) {
log_h->debug("Wrote PDU: pdu_len=%d, header_and_ce=%d (%d+%d), nof_subh=%d, last_sdu=%d, sdu_len=%d, onepad=%d, multi=%d\n",
pdu_len, header_sz+ce_payload_sz, header_sz, ce_payload_sz,
nof_subheaders, last_sdu_idx, total_sdu_len, onetwo_padding, rem_len);
log_h->debug(
"Wrote PDU: pdu_len=%d, header_and_ce=%d (%d+%d), nof_subh=%d, last_sdu=%d, sdu_len=%d, onepad=%d, multi=%d\n",
pdu_len,
header_sz + ce_payload_sz,
header_sz,
ce_payload_sz,
nof_subheaders,
last_sdu_idx,
total_sdu_len,
onetwo_padding,
rem_len);
} else {
printf("Wrote PDU: pdu_len=%d, header_and_ce=%d (%d+%d), nof_subh=%d, last_sdu=%d, sdu_len=%d, onepad=%d, multi=%d, init_rem_len=%d\n",
pdu_len, header_sz+ce_payload_sz, header_sz, ce_payload_sz,
nof_subheaders, last_sdu_idx, total_sdu_len, onetwo_padding, rem_len, init_rem_len);
printf("Wrote PDU: pdu_len=%d, header_and_ce=%d (%d+%d), nof_subh=%d, last_sdu=%d, sdu_len=%d, onepad=%d, "
"multi=%d, init_rem_len=%d\n",
pdu_len,
header_sz + ce_payload_sz,
header_sz,
ce_payload_sz,
nof_subheaders,
last_sdu_idx,
total_sdu_len,
onetwo_padding,
rem_len,
init_rem_len);
}
if (rem_len + header_sz + ce_payload_sz + total_sdu_len != pdu_len) {
@ -231,7 +247,8 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h)
return pdu_start_ptr;
}
int sch_pdu::rem_size() {
int sch_pdu::rem_size()
{
return rem_len;
}
@ -328,11 +345,13 @@ sch_subh::cetype sch_subh::ce_type()
return (cetype)SDU;
}
void sch_subh::set_payload_size(uint32_t size) {
void sch_subh::set_payload_size(uint32_t size)
{
nof_bytes = size;
}
uint32_t sch_subh::size_plus_header() {
uint32_t sch_subh::size_plus_header()
{
if (is_sdu() || is_var_len_ce()) {
return sch_pdu::size_header_sdu(nof_bytes) + nof_bytes;
}
@ -406,11 +425,12 @@ uint16_t sch_subh::get_c_rnti()
uint64_t sch_subh::get_con_res_id()
{
if (payload) {
return ((uint64_t) payload[5]) | (((uint64_t) payload[4])<<8) | (((uint64_t) payload[3])<<16) | (((uint64_t) payload[2])<<24) |
(((uint64_t) payload[1])<<32) | (((uint64_t) payload[0])<<40);
return ((uint64_t)payload[5]) | (((uint64_t)payload[4]) << 8) | (((uint64_t)payload[3]) << 16) |
(((uint64_t)payload[2]) << 24) | (((uint64_t)payload[1]) << 32) | (((uint64_t)payload[0]) << 40);
} else {
return ((uint64_t) w_payload_ce[5]) | (((uint64_t) w_payload_ce[4])<<8) | (((uint64_t) w_payload_ce[3])<<16) | (((uint64_t) w_payload_ce[2])<<24) |
(((uint64_t) w_payload_ce[1])<<32) | (((uint64_t) w_payload_ce[0])<<40);
return ((uint64_t)w_payload_ce[5]) | (((uint64_t)w_payload_ce[4]) << 8) | (((uint64_t)w_payload_ce[3]) << 16) |
(((uint64_t)w_payload_ce[2]) << 24) | (((uint64_t)w_payload_ce[1]) << 32) |
(((uint64_t)w_payload_ce[0]) << 40);
return 0;
}
}
@ -462,9 +482,7 @@ bool sch_subh::get_next_mch_sched_info(uint8_t *lcid_, uint16_t *mtch_stop)
mtch_stop_ce = ((uint16_t)(payload[cur_mch_sched_ce * 2] & 0x07)) << 8;
mtch_stop_ce += payload[cur_mch_sched_ce * 2 + 1];
cur_mch_sched_ce++;
*mtch_stop = (mtch_stop_ce == srslte::mch_subh::MTCH_STOP_EMPTY)
? (0)
: (mtch_stop_ce);
*mtch_stop = (mtch_stop_ce == srslte::mch_subh::MTCH_STOP_EMPTY) ? (0) : (mtch_stop_ce);
return true;
}
}
@ -495,14 +513,14 @@ uint32_t sch_subh::get_sdu_lcid()
return lcid;
}
uint32_t sch_subh::get_payload_size()
{
return nof_bytes;
}
uint32_t sch_subh::get_header_size(bool is_last) {
uint32_t sch_subh::get_header_size(bool is_last)
{
if (!is_last) {
if (is_sdu()) {
return sch_pdu::size_header_sdu(nof_bytes);
@ -617,10 +635,8 @@ bool sch_subh::set_ta_cmd(uint8_t ta_cmd)
bool sch_subh::set_next_mch_sched_info(uint8_t lcid_, uint16_t mtch_stop)
{
if (((sch_pdu*)parent)->has_space_ce(2, true)) {
uint16_t mtch_stop_ce =
(mtch_stop) ? (mtch_stop) : (srslte::mch_subh::MTCH_STOP_EMPTY);
w_payload_ce[nof_mch_sched_ce * 2] =
(lcid_ & 0x1F) << 3 | (uint8_t)((mtch_stop_ce & 0x0700) >> 8);
uint16_t mtch_stop_ce = (mtch_stop) ? (mtch_stop) : (srslte::mch_subh::MTCH_STOP_EMPTY);
w_payload_ce[nof_mch_sched_ce * 2] = (lcid_ & 0x1F) << 3 | (uint8_t)((mtch_stop_ce & 0x0700) >> 8);
w_payload_ce[nof_mch_sched_ce * 2 + 1] = (uint8_t)(mtch_stop_ce & 0xff);
nof_mch_sched_ce++;
lcid = MCH_SCHED_INFO;
@ -645,8 +661,7 @@ int sch_subh::set_sdu(uint32_t lcid_, uint32_t requested_bytes, read_pdu_interfa
}
if (sdu_sz == 0) {
return 0;
}
else {
} else {
// Save final number of written bytes
nof_bytes = sdu_sz;
@ -680,7 +695,6 @@ int sch_subh::set_sdu(uint32_t lcid_, uint32_t nof_bytes_, uint8_t *payload)
}
}
// Section 6.2.1
void sch_subh::write_subheader(uint8_t** ptr, bool is_last)
{
@ -796,7 +810,8 @@ void sch_subh::fprint(FILE* stream)
}
}
uint8_t sch_subh::buff_size_table(uint32_t buffer_size) {
uint8_t sch_subh::buff_size_table(uint32_t buffer_size)
{
if (buffer_size == 0) {
return 0;
} else if (buffer_size > 150000) {
@ -988,4 +1003,4 @@ bool rar_subh::read_subheader(uint8_t** ptr)
return e_bit;
}
}
} // namespace srslte