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,18 +22,18 @@
#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;
namespace srslte {
template<class SubH>
template <class SubH>
class pdu
{
public:
@ -52,34 +52,34 @@ 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++) {
for (int i = 0; i < nof_subheaders; i++) {
fprintf(stream, " -- Subheader %d: ", i);
subheaders[i].fprint(stream);
}
}
/* Resets the Read/Write position and remaining PDU length */
void reset() {
void reset()
{
cur_idx = -1;
last_sdu_idx = -1;
rem_len = pdu_len;
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,23 +118,18 @@ 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) {
uint8_t *init_ptr = ptr;
nof_subheaders = 0;
bool ret = false;
void parse_packet(uint8_t* ptr)
{
uint8_t* init_ptr = ptr;
nof_subheaders = 0;
bool ret = false;
do {
if (nof_subheaders < (int)max_subheaders) {
ret = subheaders[nof_subheaders].read_subheader(&ptr);
@ -139,75 +137,69 @@ public:
}
} while (ret && (nof_subheaders + 1) < (int)max_subheaders);
for (int i=0;i<nof_subheaders;i++) {
for (int i = 0; i < nof_subheaders; i++) {
subheaders[i].read_payload(&ptr);
}
}
protected:
std::vector<SubH> subheaders;
uint32_t pdu_len;
uint32_t rem_len;
int cur_idx;
int nof_subheaders;
uint32_t max_subheaders;
bool pdu_is_ul;
uint8_t* buffer_tx;
uint32_t total_sdu_len;
uint32_t sdu_offset_start;
int last_sdu_idx;
uint32_t pdu_len;
uint32_t rem_len;
int cur_idx;
int nof_subheaders;
uint32_t max_subheaders;
bool pdu_is_ul;
uint8_t* buffer_tx;
uint32_t total_sdu_len;
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) {
nof_subheaders = 0;
pdu_len = pdu_len_bytes;
rem_len = pdu_len;
pdu_is_ul = is_ulsch;
buffer_tx = buffer_tx_ptr;
sdu_offset_start = max_subheaders*2 + 13; // Assuming worst-case 2 bytes per sdu subheader + all possible CE
total_sdu_len = 0;
last_sdu_idx = -1;
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;
pdu_is_ul = is_ulsch;
buffer_tx = buffer_tx_ptr;
sdu_offset_start = max_subheaders * 2 + 13; // Assuming worst-case 2 bytes per sdu subheader + all possible CE
total_sdu_len = 0;
last_sdu_idx = -1;
reset();
for (uint32_t i=0;i<max_subheaders;i++) {
for (uint32_t i = 0; i < max_subheaders; i++) {
subheaders[i].parent = this;
subheaders[i].init();
}
}
};
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>
template <class SubH>
class subh
{
public:
subh(){}
virtual ~subh(){}
subh() {}
virtual ~subh() {}
virtual bool read_subheader(uint8_t** ptr) = 0;
virtual void read_payload(uint8_t **ptr) = 0;
virtual void write_subheader(uint8_t** ptr, bool is_last) = 0;
virtual void write_payload(uint8_t **ptr) = 0;
virtual void fprint(FILE *stream) = 0;
virtual bool read_subheader(uint8_t** ptr) = 0;
virtual void read_payload(uint8_t** ptr) = 0;
virtual void write_subheader(uint8_t** ptr, bool is_last) = 0;
virtual void write_payload(uint8_t** ptr) = 0;
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;
@ -219,33 +211,33 @@ public:
bzero(&w_payload_ce, sizeof(w_payload_ce));
}
virtual ~sch_subh(){}
virtual ~sch_subh() {}
/* 3GPP 36.321 (R.10) Combined Tables 6.2.1-1, 6.2.1-2, 6.2.1-4 */
typedef enum {
/* Values of LCID for DL-SCH */
SCELL_ACTIVATION = 0b11011,
CON_RES_ID = 0b11100,
TA_CMD = 0b11101,
DRX_CMD = 0b11110,
CON_RES_ID = 0b11100,
TA_CMD = 0b11101,
DRX_CMD = 0b11110,
/* Values of LCID for UL-SCH */
PHR_REPORT_EXT = 0b11001,
PHR_REPORT = 0b11010,
CRNTI = 0b11011,
TRUNC_BSR = 0b11100,
SHORT_BSR = 0b11101,
LONG_BSR = 0b11110,
PHR_REPORT = 0b11010,
CRNTI = 0b11011,
TRUNC_BSR = 0b11100,
SHORT_BSR = 0b11101,
LONG_BSR = 0b11110,
/* Values of LCID for MCH */
MTCH_MAX_LCID = 0b11100,
MTCH_MAX_LCID = 0b11100,
MCH_SCHED_INFO = 0b11110,
/*MTCH STOP Value*/
MTCH_STOP_EMPTY = 0b11111111111,
/* Common */
PADDING = 0b11111,
SDU = 0b00000
SDU = 0b00000
} cetype;
// Size of MAC CEs
@ -254,12 +246,12 @@ public:
// Reading functions
bool is_sdu();
bool is_var_len_ce();
cetype ce_type();
cetype ce_type();
uint32_t size_plus_header();
void set_payload_size(uint32_t size);
bool read_subheader(uint8_t** ptr);
void read_payload(uint8_t **ptr);
void read_payload(uint8_t** ptr);
uint32_t get_sdu_lcid();
uint32_t get_payload_size();
@ -273,66 +265,62 @@ public:
float get_phr();
int get_bsr(uint32_t buff_size[4]);
bool get_next_mch_sched_info(uint8_t *lcid, uint16_t *mtch_stop);
bool get_next_mch_sched_info(uint8_t* lcid, uint16_t* mtch_stop);
// Writing functions
void write_subheader(uint8_t** ptr, bool is_last);
void write_payload(uint8_t **ptr);
void write_payload(uint8_t** ptr);
int set_sdu(uint32_t lcid, uint32_t nof_bytes, uint8_t *payload);
int set_sdu(uint32_t lcid, uint32_t requested_bytes, read_pdu_interface *sdu_itf);
bool set_c_rnti(uint16_t crnti);
bool set_bsr(uint32_t buff_size[4], sch_subh::cetype format);
bool set_con_res_id(uint64_t con_res_id);
bool set_ta_cmd(uint8_t ta_cmd);
bool set_phr(float phr);
void set_padding();
void set_padding(uint32_t padding_len);
int set_sdu(uint32_t lcid, uint32_t nof_bytes, uint8_t* payload);
int set_sdu(uint32_t lcid, uint32_t requested_bytes, read_pdu_interface* sdu_itf);
bool set_c_rnti(uint16_t crnti);
bool set_bsr(uint32_t buff_size[4], sch_subh::cetype format);
bool set_con_res_id(uint64_t con_res_id);
bool set_ta_cmd(uint8_t ta_cmd);
bool set_phr(float phr);
void set_padding();
void set_padding(uint32_t padding_len);
void init();
void fprint(FILE *stream);
bool set_next_mch_sched_info(uint8_t lcid, uint16_t mtch_stop);
void fprint(FILE* stream);
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;
uint8_t* payload;
uint8_t w_payload_ce[64];
uint8_t nof_mch_sched_ce;
uint8_t cur_mch_sched_ce;
bool F_bit;
subh_type type;
uint32_t lcid;
int nof_bytes;
uint8_t* payload;
uint8_t w_payload_ce[64];
uint8_t nof_mch_sched_ce;
uint8_t cur_mch_sched_ce;
bool F_bit;
subh_type type;
private:
uint32_t sizeof_ce(uint32_t lcid, bool is_ul);
uint32_t sizeof_ce(uint32_t lcid, bool is_ul);
static uint8_t buff_size_table(uint32_t buffer_size);
static uint8_t phr_report_table(float phr_value);
};
class sch_pdu : public pdu<sch_subh>
{
public:
sch_pdu(uint32_t max_subh): pdu(max_subh) {}
sch_pdu(uint32_t max_subh) : pdu(max_subh) {}
void parse_packet(uint8_t *ptr);
uint8_t* write_packet();
uint8_t* write_packet(srslte::log *log_h);
bool has_space_ce(uint32_t nbytes, bool var_len=false);
bool has_space_sdu(uint32_t nbytes);
int get_pdu_len();
int rem_size();
int get_sdu_space();
void parse_packet(uint8_t* ptr);
uint8_t* write_packet();
uint8_t* write_packet(srslte::log* log_h);
bool has_space_ce(uint32_t nbytes, bool var_len = false);
bool has_space_sdu(uint32_t nbytes);
int get_pdu_len();
int rem_size();
int get_sdu_space();
static uint32_t size_header_sdu(uint32_t nbytes);
bool update_space_ce(uint32_t nbytes, bool var_len=false);
bool update_space_sdu(uint32_t nbytes);
void fprint(FILE *stream);
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;
@ -361,49 +350,48 @@ public:
void get_sched_grant(uint8_t grant[RAR_GRANT_LEN]);
// Writing functoins
void write_subheader(uint8_t** ptr, bool is_last);
void write_payload(uint8_t** ptr);
void set_rapid(uint32_t rapid);
void set_ta_cmd(uint32_t ta);
void set_temp_crnti(uint16_t temp_rnti);
void set_sched_grant(uint8_t grant[RAR_GRANT_LEN]);
void write_subheader(uint8_t** ptr, bool is_last);
void write_payload(uint8_t** ptr);
void set_rapid(uint32_t rapid);
void set_ta_cmd(uint32_t ta);
void set_temp_crnti(uint16_t temp_rnti);
void set_sched_grant(uint8_t grant[RAR_GRANT_LEN]);
void init();
void fprint(FILE *stream);
void init();
void fprint(FILE* stream);
private:
uint8_t grant[RAR_GRANT_LEN];
uint32_t ta;
uint16_t temp_rnti;
uint32_t preamble;
uint8_t grant[RAR_GRANT_LEN];
uint32_t ta;
uint16_t temp_rnti;
uint32_t preamble;
rar_subh_type_t type;
};
class rar_pdu : public pdu<rar_subh>
{
public:
rar_pdu(uint32_t max_rars = 16);
void set_backoff(uint8_t bi);
bool has_backoff();
uint8_t get_backoff();
void set_backoff(uint8_t bi);
bool has_backoff();
uint8_t get_backoff();
bool write_packet(uint8_t* ptr);
void fprint(FILE *stream);
bool write_packet(uint8_t* ptr);
void fprint(FILE* stream);
private:
bool has_backoff_indicator;
uint8_t backoff_indicator;
bool has_backoff_indicator;
uint8_t backoff_indicator;
};
class mch_subh : public sch_subh
{
public:
mch_subh():sch_subh(MCH_SUBH_TYPE){}
mch_subh() : sch_subh(MCH_SUBH_TYPE) {}
// Size of MAC CEs
const static int MAC_CE_CONTRES_LEN = 6;
// Size of MAC CEs
const static int MAC_CE_CONTRES_LEN = 6;
};
class mch_pdu : public sch_pdu
@ -412,29 +400,27 @@ 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) {
nof_subheaders = 0;
pdu_len = pdu_len_bytes;
rem_len = pdu_len;
pdu_is_ul = is_ulsch;
buffer_tx = buffer_tx_ptr;
sdu_offset_start = max_subheaders*2 + 13; // Assuming worst-case 2 bytes per sdu subheader + all possible CE
total_sdu_len = 0;
last_sdu_idx = -1;
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;
pdu_is_ul = is_ulsch;
buffer_tx = buffer_tx_ptr;
sdu_offset_start = max_subheaders * 2 + 13; // Assuming worst-case 2 bytes per sdu subheader + all possible CE
total_sdu_len = 0;
last_sdu_idx = -1;
reset();
for (uint32_t i=0;i<max_subheaders;i++) {
for (uint32_t i = 0; i < max_subheaders; i++) {
mch_subh mch_subh1;
subheaders[i] = mch_subh1;
subheaders[i] = mch_subh1;
subheaders[i].parent = this;
subheaders[i].init();
}
}
};
} // 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 {
@ -42,35 +41,36 @@ void sch_pdu::fprint(FILE* stream)
pdu::fprint(stream);
}
void sch_pdu::parse_packet(uint8_t *ptr)
void sch_pdu::parse_packet(uint8_t* ptr)
{
pdu::parse_packet(ptr);
// Correct size for last SDU
if (nof_subheaders > 0) {
uint32_t read_len = 0;
for (int i=0;i<nof_subheaders-1;i++) {
for (int i = 0; i < nof_subheaders - 1; i++) {
read_len += subheaders[i].size_plus_header();
}
int n_sub = pdu_len-read_len-1;
int n_sub = pdu_len - read_len - 1;
if (n_sub >= 0) {
subheaders[nof_subheaders-1].set_payload_size(n_sub);
subheaders[nof_subheaders - 1].set_payload_size(n_sub);
} else {
ERROR("Reading MAC PDU: negative payload for last subheader\n");
}
}
}
uint8_t* sch_pdu::write_packet() {
uint8_t* sch_pdu::write_packet()
{
return write_packet(NULL);
}
/* Writes the MAC PDU in the packet, including the MAC headers and CE payload. Section 6.1.2 */
uint8_t* sch_pdu::write_packet(srslte::log *log_h)
uint8_t* sch_pdu::write_packet(srslte::log* log_h)
{
int init_rem_len=rem_len;
int init_rem_len = rem_len;
sch_subh padding;
padding.set_padding();
@ -85,35 +85,34 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h)
}
/* If last SDU has zero payload, remove it. FIXME: Why happens this?? */
if (subheaders[nof_subheaders-1].get_payload_size() == 0) {
if (subheaders[nof_subheaders - 1].get_payload_size() == 0) {
del_subh();
}
/* Determine if we are transmitting CEs only. */
bool ce_only = last_sdu_idx<0?true:false;
bool ce_only = last_sdu_idx < 0 ? true : false;
/* Determine if we will need multi-byte padding or 1/2 bytes padding */
bool multibyte_padding = false;
uint32_t onetwo_padding = 0;
bool multibyte_padding = false;
uint32_t onetwo_padding = 0;
if (rem_len > 2) {
multibyte_padding = true;
// Add 1 header for padding
rem_len--;
// Add the header for the last SDU
if (!ce_only) {
rem_len -= (subheaders[last_sdu_idx].get_header_size(false)-1); // Becuase we were assuming it was the one
rem_len -= (subheaders[last_sdu_idx].get_header_size(false) - 1); // Becuase we were assuming it was the one
}
} else if (rem_len > 0) {
onetwo_padding = rem_len;
rem_len = 0;
rem_len = 0;
}
/* Determine the header size and CE payload size */
uint32_t header_sz = 0;
uint32_t ce_payload_sz = 0;
for (int i=0;i<nof_subheaders;i++) {
header_sz += subheaders[i].get_header_size(!multibyte_padding && i==last_sdu_idx);
for (int i = 0; i < nof_subheaders; i++) {
header_sz += subheaders[i].get_header_size(!multibyte_padding && i == last_sdu_idx);
if (!subheaders[i].is_sdu()) {
ce_payload_sz += subheaders[i].get_payload_size();
}
@ -133,24 +132,24 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h)
}
/* Start writing header and CE payload before the start of the SDU payload */
uint8_t *ptr = &buffer_tx[sdu_offset_start-header_sz-ce_payload_sz];
uint8_t *pdu_start_ptr = ptr;
uint8_t* ptr = &buffer_tx[sdu_offset_start - header_sz - ce_payload_sz];
uint8_t* pdu_start_ptr = ptr;
// Add single/two byte padding first
for (uint32_t i=0;i<onetwo_padding;i++) {
for (uint32_t i = 0; i < onetwo_padding; i++) {
padding.write_subheader(&ptr, false);
}
// Then write subheaders for MAC CE
for (int i=0;i<nof_subheaders;i++) {
for (int i = 0; i < nof_subheaders; i++) {
if (!subheaders[i].is_sdu()) {
subheaders[i].write_subheader(&ptr, ce_only && !multibyte_padding && i==(nof_subheaders-1));
subheaders[i].write_subheader(&ptr, ce_only && !multibyte_padding && i == (nof_subheaders - 1));
}
}
// Then for SDUs
if (!ce_only) {
for (int i=0;i<nof_subheaders;i++) {
for (int i = 0; i < nof_subheaders; i++) {
if (subheaders[i].is_sdu()) {
subheaders[i].write_subheader(&ptr, !multibyte_padding && i==last_sdu_idx);
subheaders[i].write_subheader(&ptr, !multibyte_padding && i == last_sdu_idx);
}
}
}
@ -162,25 +161,42 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h)
}
// Write CE payloads (SDU payloads already in the buffer)
for (int i=0;i<nof_subheaders;i++) {
for (int i = 0; i < nof_subheaders; i++) {
if (!subheaders[i].is_sdu()) {
subheaders[i].write_payload(&ptr);
}
}
// Set padding to zeros (if any)
if (rem_len > 0) {
bzero(&pdu_start_ptr[pdu_len-rem_len], rem_len*sizeof(uint8_t));
bzero(&pdu_start_ptr[pdu_len - rem_len], rem_len * sizeof(uint8_t));
}
/* 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) {
@ -221,7 +237,7 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h)
return NULL;
}
if ((int)(header_sz + ce_payload_sz) != (int) (ptr - pdu_start_ptr)) {
if ((int)(header_sz + ce_payload_sz) != (int)(ptr - pdu_start_ptr)) {
ERROR("Expected a header and CE payload of %d bytes but wrote %d\n",
header_sz + ce_payload_sz,
(int)(ptr - pdu_start_ptr));
@ -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;
}
@ -263,7 +280,7 @@ bool sch_pdu::update_space_ce(uint32_t nbytes, bool var_len)
{
uint32_t head_len = var_len ? size_header_sdu(nbytes) : 1;
if (has_space_ce(nbytes)) {
rem_len -= nbytes + head_len;
rem_len -= nbytes + head_len;
return true;
} else {
return false;
@ -286,9 +303,9 @@ bool sch_pdu::update_space_sdu(uint32_t nbytes)
int init_rem = rem_len;
if (has_space_sdu(nbytes)) {
if (last_sdu_idx < 0) {
rem_len -= (nbytes+1);
rem_len -= (nbytes + 1);
} else {
rem_len -= (nbytes+1 + (size_header_sdu(subheaders[last_sdu_idx].get_payload_size())-1));
rem_len -= (nbytes + 1 + (size_header_sdu(subheaders[last_sdu_idx].get_payload_size()) - 1));
}
last_sdu_idx = cur_idx;
return true;
@ -303,7 +320,7 @@ int sch_pdu::get_sdu_space()
if (last_sdu_idx < 0) {
ret = rem_len - 1;
} else {
ret = rem_len - (size_header_sdu(subheaders[last_sdu_idx].get_payload_size())-1) - 1;
ret = rem_len - (size_header_sdu(subheaders[last_sdu_idx].get_payload_size()) - 1) - 1;
}
return ret;
}
@ -322,17 +339,19 @@ sch_subh::cetype sch_subh::ce_type()
if (lcid >= PHR_REPORT && type == SCH_SUBH_TYPE) {
return (cetype)lcid;
}
if(lcid >= MCH_SCHED_INFO && type == MCH_SUBH_TYPE) {
if (lcid >= MCH_SCHED_INFO && type == MCH_SUBH_TYPE) {
return (cetype)lcid;
}
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;
}
@ -344,7 +363,7 @@ uint32_t sch_subh::sizeof_ce(uint32_t lcid, bool is_ul)
{
if (type == SCH_SUBH_TYPE) {
if (is_ul) {
switch(lcid) {
switch (lcid) {
case PHR_REPORT:
return 1;
case CRNTI:
@ -359,7 +378,7 @@ uint32_t sch_subh::sizeof_ce(uint32_t lcid, bool is_ul)
return 0;
}
} else {
switch(lcid) {
switch (lcid) {
case CON_RES_ID:
return 6;
case TA_CMD:
@ -375,10 +394,10 @@ uint32_t sch_subh::sizeof_ce(uint32_t lcid, bool is_ul)
}
if (type == MCH_SUBH_TYPE) {
switch (lcid) {
case MCH_SCHED_INFO:
return nof_mch_sched_ce*2;
case PADDING:
return 0;
case MCH_SCHED_INFO:
return nof_mch_sched_ce * 2;
case PADDING:
return 0;
}
}
return 0;
@ -397,20 +416,21 @@ bool sch_subh::is_var_len_ce()
uint16_t sch_subh::get_c_rnti()
{
if (payload) {
return (uint16_t) payload[0]<<8 | payload[1];
return (uint16_t)payload[0] << 8 | payload[1];
} else {
return (uint16_t) w_payload_ce[0]<<8 | w_payload_ce[1];
return (uint16_t)w_payload_ce[0] << 8 | w_payload_ce[1];
}
}
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;
}
}
@ -418,9 +438,9 @@ uint64_t sch_subh::get_con_res_id()
float sch_subh::get_phr()
{
if (payload) {
return (float) (payload[0]&0x3f) - 23;
return (float)(payload[0] & 0x3f) - 23;
} else {
return (float) (w_payload_ce[0]&0x3f) - 23;
return (float)(w_payload_ce[0] & 0x3f) - 23;
}
}
@ -428,19 +448,19 @@ int sch_subh::get_bsr(uint32_t buff_size[4])
{
if (payload) {
uint32_t nonzero_lcg = 0;
if (ce_type()==LONG_BSR) {
buff_size[0] = (payload[0]&0xFC) >> 2;
buff_size[1] = (payload[0]&0x03) << 4 | (payload[1]&0xF0) >> 4;
buff_size[2] = (payload[1]&0x0F) << 4 | (payload[1]&0xC0) >> 6;
buff_size[3] = (payload[2]&0x3F);
if (ce_type() == LONG_BSR) {
buff_size[0] = (payload[0] & 0xFC) >> 2;
buff_size[1] = (payload[0] & 0x03) << 4 | (payload[1] & 0xF0) >> 4;
buff_size[2] = (payload[1] & 0x0F) << 4 | (payload[1] & 0xC0) >> 6;
buff_size[3] = (payload[2] & 0x3F);
} else {
nonzero_lcg = (payload[0]&0xc0) >> 6;
buff_size[nonzero_lcg%4] = payload[0]&0x3f;
nonzero_lcg = (payload[0] & 0xc0) >> 6;
buff_size[nonzero_lcg % 4] = payload[0] & 0x3f;
}
for (int i=0;i<4;i++) {
for (int i = 0; i < 4; i++) {
if (buff_size[i]) {
if (buff_size[i]<63) {
buff_size[i] = btable[1+buff_size[i]];
if (buff_size[i] < 63) {
buff_size[i] = btable[1 + buff_size[i]];
} else {
buff_size[i] = btable[63];
}
@ -452,19 +472,17 @@ int sch_subh::get_bsr(uint32_t buff_size[4])
}
}
bool sch_subh::get_next_mch_sched_info(uint8_t *lcid_, uint16_t *mtch_stop)
bool sch_subh::get_next_mch_sched_info(uint8_t* lcid_, uint16_t* mtch_stop)
{
uint16_t mtch_stop_ce;
if(payload) {
nof_mch_sched_ce = nof_bytes/2;
if (payload) {
nof_mch_sched_ce = nof_bytes / 2;
if (cur_mch_sched_ce < nof_mch_sched_ce) {
*lcid_ = (payload[cur_mch_sched_ce * 2] & 0xF8) >> 3;
*lcid_ = (payload[cur_mch_sched_ce * 2] & 0xF8) >> 3;
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;
}
}
@ -474,7 +492,7 @@ bool sch_subh::get_next_mch_sched_info(uint8_t *lcid_, uint16_t *mtch_stop)
uint8_t sch_subh::get_ta_cmd()
{
if (payload) {
return (uint8_t) payload[0]&0x3f;
return (uint8_t)payload[0] & 0x3f;
} else {
return 0;
}
@ -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);
@ -523,7 +541,7 @@ uint8_t* sch_subh::get_sdu_ptr()
void sch_subh::set_padding(uint32_t padding_len)
{
lcid = PADDING;
lcid = PADDING;
nof_bytes = padding_len;
}
@ -534,20 +552,20 @@ void sch_subh::set_padding()
bool sch_subh::set_bsr(uint32_t buff_size[4], sch_subh::cetype format)
{
uint32_t nonzero_lcg=0;
for (int i=0;i<4;i++) {
uint32_t nonzero_lcg = 0;
for (int i = 0; i < 4; i++) {
if (buff_size[i]) {
nonzero_lcg=i;
nonzero_lcg = i;
}
}
uint32_t ce_size = format==LONG_BSR?3:1;
uint32_t ce_size = format == LONG_BSR ? 3 : 1;
if (((sch_pdu*)parent)->has_space_ce(ce_size)) {
if (format==LONG_BSR) {
w_payload_ce[0] = (buff_size_table(buff_size[0])&0x3f) << 2 | (buff_size_table(buff_size[1])&0xc0)>>6;
w_payload_ce[1] = (buff_size_table(buff_size[1])&0xf) << 4 | (buff_size_table(buff_size[2])&0xf0)>>4;
w_payload_ce[2] = (buff_size_table(buff_size[2])&0x3) << 6 | (buff_size_table(buff_size[3])&0x3f);
if (format == LONG_BSR) {
w_payload_ce[0] = (buff_size_table(buff_size[0]) & 0x3f) << 2 | (buff_size_table(buff_size[1]) & 0xc0) >> 6;
w_payload_ce[1] = (buff_size_table(buff_size[1]) & 0xf) << 4 | (buff_size_table(buff_size[2]) & 0xf0) >> 4;
w_payload_ce[2] = (buff_size_table(buff_size[2]) & 0x3) << 6 | (buff_size_table(buff_size[3]) & 0x3f);
} else {
w_payload_ce[0] = (nonzero_lcg&0x3)<<6 | (buff_size_table(buff_size[nonzero_lcg])&0x3f);
w_payload_ce[0] = (nonzero_lcg & 0x3) << 6 | (buff_size_table(buff_size[nonzero_lcg]) & 0x3f);
}
lcid = format;
((sch_pdu*)parent)->update_space_ce(ce_size);
@ -561,9 +579,9 @@ bool sch_subh::set_bsr(uint32_t buff_size[4], sch_subh::cetype format)
bool sch_subh::set_c_rnti(uint16_t crnti)
{
if (((sch_pdu*)parent)->has_space_ce(2)) {
w_payload_ce[0] = (uint8_t) ((crnti&0xff00)>>8);
w_payload_ce[1] = (uint8_t) ((crnti&0x00ff));
lcid = CRNTI;
w_payload_ce[0] = (uint8_t)((crnti & 0xff00) >> 8);
w_payload_ce[1] = (uint8_t)((crnti & 0x00ff));
lcid = CRNTI;
((sch_pdu*)parent)->update_space_ce(2);
nof_bytes = 2;
return true;
@ -574,13 +592,13 @@ bool sch_subh::set_c_rnti(uint16_t crnti)
bool sch_subh::set_con_res_id(uint64_t con_res_id)
{
if (((sch_pdu*)parent)->has_space_ce(6)) {
w_payload_ce[0] = (uint8_t) ((con_res_id&0xff0000000000)>>40);
w_payload_ce[1] = (uint8_t) ((con_res_id&0x00ff00000000)>>32);
w_payload_ce[2] = (uint8_t) ((con_res_id&0x0000ff000000)>>24);
w_payload_ce[3] = (uint8_t) ((con_res_id&0x000000ff0000)>>16);
w_payload_ce[4] = (uint8_t) ((con_res_id&0x00000000ff00)>>8);
w_payload_ce[5] = (uint8_t) ((con_res_id&0x0000000000ff));
lcid = CON_RES_ID;
w_payload_ce[0] = (uint8_t)((con_res_id & 0xff0000000000) >> 40);
w_payload_ce[1] = (uint8_t)((con_res_id & 0x00ff00000000) >> 32);
w_payload_ce[2] = (uint8_t)((con_res_id & 0x0000ff000000) >> 24);
w_payload_ce[3] = (uint8_t)((con_res_id & 0x000000ff0000) >> 16);
w_payload_ce[4] = (uint8_t)((con_res_id & 0x00000000ff00) >> 8);
w_payload_ce[5] = (uint8_t)((con_res_id & 0x0000000000ff));
lcid = CON_RES_ID;
((sch_pdu*)parent)->update_space_ce(6);
nof_bytes = 6;
return true;
@ -591,8 +609,8 @@ bool sch_subh::set_con_res_id(uint64_t con_res_id)
bool sch_subh::set_phr(float phr)
{
if (((sch_pdu*)parent)->has_space_ce(1)) {
w_payload_ce[0] = phr_report_table(phr)&0x3f;
lcid = PHR_REPORT;
w_payload_ce[0] = phr_report_table(phr) & 0x3f;
lcid = PHR_REPORT;
((sch_pdu*)parent)->update_space_ce(1);
nof_bytes = 1;
return true;
@ -604,8 +622,8 @@ bool sch_subh::set_phr(float phr)
bool sch_subh::set_ta_cmd(uint8_t ta_cmd)
{
if (((sch_pdu*)parent)->has_space_ce(1)) {
w_payload_ce[0] = ta_cmd&0x3f;
lcid = TA_CMD;
w_payload_ce[0] = ta_cmd & 0x3f;
lcid = TA_CMD;
((sch_pdu*)parent)->update_space_ce(1);
nof_bytes = 1;
return true;
@ -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;
@ -631,7 +647,7 @@ bool sch_subh::set_next_mch_sched_info(uint8_t lcid_, uint16_t mtch_stop)
return false;
}
int sch_subh::set_sdu(uint32_t lcid_, uint32_t requested_bytes, read_pdu_interface *sdu_itf)
int sch_subh::set_sdu(uint32_t lcid_, uint32_t requested_bytes, read_pdu_interface* sdu_itf)
{
if (((sch_pdu*)parent)->has_space_sdu(requested_bytes)) {
lcid = lcid_;
@ -645,13 +661,12 @@ 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;
if(nof_bytes > (int32_t)requested_bytes) {
return -1;
if (nof_bytes > (int32_t)requested_bytes) {
return -1;
}
}
@ -663,7 +678,7 @@ int sch_subh::set_sdu(uint32_t lcid_, uint32_t requested_bytes, read_pdu_interfa
}
}
int sch_subh::set_sdu(uint32_t lcid_, uint32_t nof_bytes_, uint8_t *payload)
int sch_subh::set_sdu(uint32_t lcid_, uint32_t nof_bytes_, uint8_t* payload)
{
if (((sch_pdu*)parent)->has_space_sdu(nof_bytes_)) {
lcid = lcid_;
@ -674,31 +689,30 @@ int sch_subh::set_sdu(uint32_t lcid_, uint32_t nof_bytes_, uint8_t *payload)
((sch_pdu*)parent)->update_space_sdu(nof_bytes_);
nof_bytes = nof_bytes_;
return (int) nof_bytes;
return (int)nof_bytes;
} else {
return -1;
}
}
// Section 6.2.1
void sch_subh::write_subheader(uint8_t** ptr, bool is_last)
{
*(*ptr) = (uint8_t) (is_last?0:(1<<5)) | ((uint8_t) lcid & 0x1f);
*(*ptr) = (uint8_t)(is_last ? 0 : (1 << 5)) | ((uint8_t)lcid & 0x1f);
*ptr += 1;
if (is_sdu() || is_var_len_ce()) {
// MAC SDU: R/R/E/LCID/F/L subheader
// 2nd and 3rd octet
if (!is_last) {
if (nof_bytes >= 128) {
*(*ptr) = (uint8_t) 1<<7 | ((nof_bytes & 0x7f00) >> 8);
*(*ptr) = (uint8_t)1 << 7 | ((nof_bytes & 0x7f00) >> 8);
*ptr += 1;
*(*ptr) = (uint8_t) (nof_bytes & 0xff);
*(*ptr) = (uint8_t)(nof_bytes & 0xff);
*ptr += 1;
} else {
*(*ptr) = (uint8_t) (nof_bytes & 0x7f);
*ptr += 1;
}
*(*ptr) = (uint8_t)(nof_bytes & 0x7f);
*ptr += 1;
}
}
}
}
@ -709,7 +723,7 @@ void sch_subh::write_payload(uint8_t** ptr)
// SDU is written directly during subheader creation
} else {
nof_bytes = sizeof_ce(lcid, parent->is_ul());
memcpy(*ptr, w_payload_ce, nof_bytes*sizeof(uint8_t));
memcpy(*ptr, w_payload_ce, nof_bytes * sizeof(uint8_t));
}
*ptr += nof_bytes;
}
@ -717,21 +731,21 @@ void sch_subh::write_payload(uint8_t** ptr)
bool sch_subh::read_subheader(uint8_t** ptr)
{
// Skip R
bool e_bit = (bool) (*(*ptr) & 0x20)?true:false;
lcid = (uint8_t) *(*ptr) & 0x1f;
bool e_bit = (bool)(*(*ptr) & 0x20) ? true : false;
lcid = (uint8_t) * (*ptr) & 0x1f;
*ptr += 1;
if (is_sdu() || is_var_len_ce()) {
if (e_bit) {
F_bit = (bool) (*(*ptr) & 0x80)?true:false;
nof_bytes = (uint32_t)*(*ptr) & 0x7f;
F_bit = (bool)(*(*ptr) & 0x80) ? true : false;
nof_bytes = (uint32_t) * (*ptr) & 0x7f;
*ptr += 1;
if (F_bit) {
nof_bytes = nof_bytes<<8 | ((uint32_t) *(*ptr) & 0xff);
nof_bytes = nof_bytes << 8 | ((uint32_t) * (*ptr) & 0xff);
*ptr += 1;
}
} else {
nof_bytes = 0;
F_bit = 0;
F_bit = 0;
}
} else {
nof_bytes = sizeof_ce(lcid, parent->is_ul());
@ -751,7 +765,7 @@ void sch_subh::fprint(FILE* stream)
fprintf(stream, "SDU LCHID=%d, SDU nof_bytes=%d\n", lcid, nof_bytes);
} else if (type == SCH_SUBH_TYPE) {
if (parent->is_ul()) {
switch(lcid) {
switch (lcid) {
case CRNTI:
fprintf(stream, "C-RNTI CE\n");
break;
@ -771,7 +785,7 @@ void sch_subh::fprint(FILE* stream)
fprintf(stream, "PADDING\n");
}
} else {
switch(lcid) {
switch (lcid) {
case CON_RES_ID:
fprintf(stream, "Contention Resolution ID CE: 0x%lx\n", get_con_res_id());
break;
@ -786,7 +800,7 @@ void sch_subh::fprint(FILE* stream)
}
}
} else if (type == MCH_SUBH_TYPE) {
switch(lcid) {
switch (lcid) {
case MCH_SCHED_INFO:
fprintf(stream, "MCH Scheduling Info CE\n");
break;
@ -796,15 +810,16 @@ 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) {
return 63;
} else {
for (int i=0;i<61;i++) {
if (buffer_size < btable[i+2]) {
return 1+i;
for (int i = 0; i < 61; i++) {
if (buffer_size < btable[i + 2]) {
return 1 + i;
}
}
return 62;
@ -820,7 +835,7 @@ uint8_t sch_subh::phr_report_table(float phr_value)
if (phr_value > 40) {
phr_value = 40;
}
return (uint8_t) floor(phr_value+23);
return (uint8_t)floor(phr_value + 23);
}
void rar_pdu::fprint(FILE* stream)
@ -848,7 +863,7 @@ bool rar_pdu::has_backoff()
void rar_pdu::set_backoff(uint8_t bi)
{
has_backoff_indicator = true;
backoff_indicator = bi;
backoff_indicator = bi;
}
// Section 6.1.5
@ -856,7 +871,7 @@ bool rar_pdu::write_packet(uint8_t* ptr)
{
// Write Backoff Indicator, if any
if (has_backoff_indicator) {
*(ptr) = backoff_indicator&0xf;
*(ptr) = backoff_indicator & 0xf;
if (nof_subheaders > 0) {
*(ptr) |= 1 << 7;
}
@ -864,15 +879,15 @@ bool rar_pdu::write_packet(uint8_t* ptr)
}
// Write RAR subheaders
for (int i=0;i<nof_subheaders;i++) {
subheaders[i].write_subheader(&ptr, i==nof_subheaders-1);
for (int i = 0; i < nof_subheaders; i++) {
subheaders[i].write_subheader(&ptr, i == nof_subheaders - 1);
}
// Write payload
for (int i=0;i<nof_subheaders;i++) {
for (int i = 0; i < nof_subheaders; i++) {
subheaders[i].write_payload(&ptr);
}
// Set padding to zeros (if any)
bzero(ptr, rem_len*sizeof(uint8_t));
bzero(ptr, rem_len * sizeof(uint8_t));
return true;
}
@ -907,7 +922,7 @@ bool rar_subh::has_rapid()
void rar_subh::get_sched_grant(uint8_t grant_[RAR_GRANT_LEN])
{
memcpy(grant_, grant, sizeof(uint8_t)*RAR_GRANT_LEN);
memcpy(grant_, grant, sizeof(uint8_t) * RAR_GRANT_LEN);
}
uint32_t rar_subh::get_ta_cmd()
@ -927,7 +942,7 @@ void rar_subh::set_rapid(uint32_t rapid)
void rar_subh::set_sched_grant(uint8_t grant_[RAR_GRANT_LEN])
{
memcpy(grant, grant_, sizeof(uint8_t)*RAR_GRANT_LEN);
memcpy(grant, grant_, sizeof(uint8_t) * RAR_GRANT_LEN);
}
void rar_subh::set_ta_cmd(uint32_t ta_)
@ -943,19 +958,19 @@ void rar_subh::set_temp_crnti(uint16_t temp_rnti_)
// Section 6.2.2
void rar_subh::write_subheader(uint8_t** ptr, bool is_last)
{
*(*ptr) = (uint8_t) (!is_last<<7 | 1<<6 | (preamble & 0x3f));
*(*ptr) = (uint8_t)(!is_last << 7 | 1 << 6 | (preamble & 0x3f));
*ptr += 1;
}
// Section 6.2.3
void rar_subh::write_payload(uint8_t** ptr)
{
*(*ptr + 0) = (uint8_t) ((ta&0x7f0)>>4);
*(*ptr + 1) = (uint8_t) ((ta&0xf) <<4) | (grant[0]<<3) | (grant[1]<<2) | (grant[2]<<1) | grant[3];
uint8_t *x = &grant[4];
*(*ptr + 2) = (uint8_t) srslte_bit_pack(&x, 8);
*(*ptr + 3) = (uint8_t) srslte_bit_pack(&x, 8);
*(*ptr + 4) = (uint8_t) ((temp_rnti&0xff00) >> 8);
*(*ptr + 5) = (uint8_t) (temp_rnti&0x00ff);
*(*ptr + 0) = (uint8_t)((ta & 0x7f0) >> 4);
*(*ptr + 1) = (uint8_t)((ta & 0xf) << 4) | (grant[0] << 3) | (grant[1] << 2) | (grant[2] << 1) | grant[3];
uint8_t* x = &grant[4];
*(*ptr + 2) = (uint8_t)srslte_bit_pack(&x, 8);
*(*ptr + 3) = (uint8_t)srslte_bit_pack(&x, 8);
*(*ptr + 4) = (uint8_t)((temp_rnti & 0xff00) >> 8);
*(*ptr + 5) = (uint8_t)(temp_rnti & 0x00ff);
*ptr += 6;
}
@ -977,7 +992,7 @@ void rar_subh::read_payload(uint8_t** ptr)
bool rar_subh::read_subheader(uint8_t** ptr)
{
bool e_bit = *(*ptr) & 0x80?true:false;
bool e_bit = *(*ptr) & 0x80 ? true : false;
type = *(*ptr) & 0x40 ? RAPID : BACKOFF;
if (type == RAPID) {
preamble = *(*ptr) & 0x3f;
@ -988,4 +1003,4 @@ bool rar_subh::read_subheader(uint8_t** ptr)
return e_bit;
}
}
} // namespace srslte