fixed group extensions, removed extra presence flag for copy_ptr<T> types as it was just a source of bugs.

master
Francisco Paisana 5 years ago committed by Andre Puschmann
parent bf35f83a5e
commit 116dc0a57b

@ -23,6 +23,7 @@
#define SRSASN_COMMON_UTILS_H
#include <algorithm>
#include <array>
#include <cmath>
#include <cstring>
#include <sstream>
@ -80,8 +81,13 @@ ValOrError unpack_bits(uint8_t*& ptr, uint8_t& offset, uint8_t* max_ptr, uint32_
class bit_ref
{
public:
bit_ref();
bit_ref(uint8_t* start_ptr_, uint32_t max_size_);
bit_ref() = default;
bit_ref(uint8_t* start_ptr_, uint32_t max_size_) :
ptr(start_ptr_),
start_ptr(start_ptr_),
max_ptr(max_size_ + start_ptr_)
{
}
int distance(const bit_ref& other) const;
int distance(uint8_t* ref_ptr) const;
@ -102,10 +108,10 @@ public:
void set(uint8_t* start_ptr_, uint32_t max_size_);
private:
uint8_t* ptr;
uint8_t offset;
uint8_t* start_ptr;
uint8_t* max_ptr;
uint8_t* ptr = nullptr;
uint8_t offset = 0;
uint8_t* start_ptr = nullptr;
uint8_t* max_ptr = nullptr;
};
/*********************
@ -116,7 +122,7 @@ class dyn_array
{
public:
typedef T item_type;
dyn_array() : data_(NULL), size_(0), cap_(0) {}
dyn_array() = default;
dyn_array(uint32_t new_size) : size_(new_size), cap_(new_size) { data_ = new T[size_]; }
dyn_array(const dyn_array<T>& other)
{
@ -183,8 +189,9 @@ public:
const T* data() const { return &data_[0]; }
private:
T* data_;
uint32_t size_, cap_;
T* data_ = nullptr;
uint32_t size_ = 0;
uint32_t cap_ = 0;
};
template <class T, uint32_t MAX_N>
@ -219,24 +226,6 @@ private:
uint32_t current_size;
};
template <class T, uint32_t N>
class fixed_array
{
public:
typedef T item_type;
static uint32_t size() { return N; }
T& operator[](uint32_t idx) { return data_[idx]; }
const T& operator[](uint32_t idx) const { return data_[idx]; }
bool operator==(const fixed_array<T, N>& other) const { return std::equal(data_, data_ + size(), other.data_); }
T& back() { return data_[size() - 1]; }
const T& back() const { return data_[size() - 1]; }
T* data() { return &data_[0]; }
const T* data() const { return &data_[0]; }
private:
T data_[N];
};
/*********************
ext packing
*********************/
@ -341,9 +330,9 @@ template <class IntType>
SRSASN_CODE unpack_unalign_integer(IntType& n, bit_ref& bref, IntType lb, IntType ub);
template <class IntType>
struct UnalignedIntegerPacker {
UnalignedIntegerPacker(IntType, IntType);
IntType lb;
IntType ub;
UnalignedIntegerPacker(IntType lb_, IntType ub_) : lb(lb_), ub(ub_) {}
const IntType lb;
const IntType ub;
SRSASN_CODE pack(bit_ref& bref, IntType n) const;
SRSASN_CODE unpack(IntType& n, bit_ref& bref) const;
};
@ -351,12 +340,11 @@ struct UnalignedIntegerPacker {
template <class IntType, IntType lb, IntType ub>
struct unaligned_integer {
IntType value;
const UnalignedIntegerPacker<IntType> packer;
unaligned_integer() : packer(lb, ub) {}
unaligned_integer(IntType value_) : value(value_), packer(lb, ub) {}
unaligned_integer() = default;
unaligned_integer(IntType value_) : value(value_) {}
operator IntType() { return value; }
SRSASN_CODE pack(bit_ref& bref) const { return packer.pack(bref, value); }
SRSASN_CODE unpack(bit_ref& bref) { return packer.unpack(value, bref); }
SRSASN_CODE pack(bit_ref& bref) const { return pack_unalign_integer(bref, value, lb, ub); }
SRSASN_CODE unpack(bit_ref& bref) { return unpack_unalign_integer(value, bref, lb, ub); }
};
template <class IntType>
@ -486,7 +474,7 @@ public:
SRSASN_CODE unpack(bit_ref& bref);
private:
fixed_array<uint8_t, N> octets_;
std::array<uint8_t, N> octets_;
};
template <uint32_t N>
@ -520,7 +508,7 @@ SRSASN_CODE fixed_octstring<N>::unpack(bit_ref& bref)
class dyn_octstring
{
public:
dyn_octstring() {}
dyn_octstring() = default;
dyn_octstring(uint32_t new_size) : octets_(new_size) {}
const uint8_t& operator[](uint32_t idx) const { return octets_[idx]; }
@ -621,7 +609,7 @@ public:
SRSASN_CODE unpack(bit_ref& bref, bool& ext) { return unpack_fixed_bitstring(data(), ext, bref, N); }
private:
fixed_array<uint8_t, (uint32_t)((N + 7) / 8)> octets_; // ceil(N/8.0)
std::array<uint8_t, (uint32_t)((N + 7) / 8)> octets_; // ceil(N/8.0)
};
/*********************
@ -874,16 +862,15 @@ template <class T>
class copy_ptr
{
public:
copy_ptr() : ptr(NULL) {}
explicit copy_ptr(T* ptr_) :
explicit copy_ptr(T* ptr_ = nullptr) :
ptr(ptr_) {} // it takes hold of the pointer (including destruction). You should use make_copy_ptr() in most cases
// instead of this ctor
copy_ptr(const copy_ptr<T>& other) { ptr = other.make_obj_(); } // it allocates new memory for the new object
copy_ptr(const copy_ptr<T>& other) { ptr = (other.ptr == nullptr) ? nullptr : new T(*other.ptr); }
~copy_ptr() { destroy_(); }
copy_ptr<T>& operator=(const copy_ptr<T>& other)
{
if (this != &other) {
acquire(other.make_obj_());
reset((other.ptr == nullptr) ? nullptr : new T(*other.ptr));
}
return *this;
}
@ -897,15 +884,23 @@ public:
T* release()
{
T* ret = ptr;
ptr = NULL;
ptr = nullptr;
return ret;
}
void acquire(T* ptr_)
void reset(T* ptr_ = nullptr)
{
destroy_();
ptr = ptr_;
}
void reset() { acquire(NULL); }
void set_present(bool flag = true)
{
if (flag) {
reset(new T());
} else {
reset();
}
}
bool is_present() const { return get() != nullptr; }
private:
void destroy_()
@ -914,7 +909,6 @@ private:
delete ptr;
}
}
T* make_obj_() const { return (ptr == NULL) ? NULL : new T(*ptr); }
T* ptr;
};
@ -931,19 +925,13 @@ copy_ptr<T> make_copy_ptr(const T& t)
class ext_groups_header
{
public:
ext_groups_header(uint32_t max_nof_groups, uint32_t nof_nogroups_ = 0);
ext_groups_header();
bool& operator[](uint32_t idx);
SRSASN_CODE pack_nof_groups(bit_ref& bref) const;
SRSASN_CODE pack_group_flags(bit_ref& bref) const;
SRSASN_CODE pack(bit_ref& bref) const;
SRSASN_CODE unpack_nof_groups(bit_ref& bref);
SRSASN_CODE unpack_group_flags(bit_ref& bref);
SRSASN_CODE unpack(bit_ref& bref);
private:
mutable uint32_t nof_groups;
const uint32_t nof_nogroups;
bounded_array<bool, 20> groups;
};

File diff suppressed because it is too large Load Diff

@ -565,9 +565,8 @@ public:
phr_cfg.db_pathloss_change = cfg.phr_cfg.setup().dl_pathloss_change.to_number();
}
}
if (cfg.mac_main_cfg_v1020_present) {
typedef asn1::rrc::mac_main_cfg_s::mac_main_cfg_v1020_s_ mac_main_cfg_v1020_t;
mac_main_cfg_v1020_t* mac_main_cfg_v1020 = cfg.mac_main_cfg_v1020.get();
if (cfg.mac_main_cfg_v1020.is_present()) {
asn1::rrc::mac_main_cfg_s::mac_main_cfg_v1020_s_* mac_main_cfg_v1020 = cfg.mac_main_cfg_v1020.get();
phr_cfg.extended = mac_main_cfg_v1020->extended_phr_r10_present;
}
if (cfg.ul_sch_cfg_present) {

@ -83,16 +83,6 @@ void log_error_code(SRSASN_CODE code, const char* filename, int line)
bit_ref
*********************/
bit_ref::bit_ref() : ptr(NULL), offset(0), start_ptr(NULL), max_ptr(NULL) {}
bit_ref::bit_ref(uint8_t* start_ptr_, uint32_t max_size_) :
ptr(start_ptr_),
offset(0),
start_ptr(start_ptr_),
max_ptr(max_size_ + start_ptr_)
{
}
int bit_ref::distance(const bit_ref& other) const
{
return ((int)offset - (int)other.offset) + 8 * ((int)(ptr - other.ptr));
@ -370,10 +360,6 @@ template SRSASN_CODE unpack_unalign_integer<uint16_t>(uint16_t& n, bit_ref& bref
template SRSASN_CODE unpack_unalign_integer<uint32_t>(uint32_t& n, bit_ref& bref, uint32_t lb, uint32_t ub);
template SRSASN_CODE unpack_unalign_integer<uint64_t>(uint64_t& n, bit_ref& bref, uint64_t lb, uint64_t ub);
template <class IntType>
UnalignedIntegerPacker<IntType>::UnalignedIntegerPacker(IntType lb_, IntType ub_) : lb(lb_), ub(ub_)
{
}
template <class IntType>
SRSASN_CODE UnalignedIntegerPacker<IntType>::pack(bit_ref& bref, IntType n) const
{
@ -921,86 +907,56 @@ void log_invalid_choice_id(uint32_t val, const char* choice_type)
ext group
*********************/
ext_groups_header::ext_groups_header(uint32_t max_nof_groups, uint32_t nof_nogroups_) : nof_nogroups(nof_nogroups_)
ext_groups_header::ext_groups_header()
{
if (max_nof_groups > 20) {
srsasn_log_print(LOG_LEVEL_ERROR, "increase the size of ext group packer/unpacker\n");
}
groups.resize(max_nof_groups);
for (uint32_t i = 0; i < groups.size(); ++i) {
groups[i] = false;
}
nof_groups = groups.size() + 1; // unset
groups.resize(20);
std::fill(groups.data(), groups.data() + groups.size(), false);
}
bool& ext_groups_header::operator[](uint32_t idx)
{
if (idx >= groups.size()) {
uint32_t prev_size = groups.size();
groups.resize(idx + 1);
std::fill(&groups[prev_size], &groups[groups.size()], false);
}
return groups[idx];
}
SRSASN_CODE ext_groups_header::pack_nof_groups(bit_ref& bref) const
SRSASN_CODE ext_groups_header::pack(bit_ref& bref) const
{
nof_groups = 0;
for (uint32_t i = 0; i < groups.size(); ++i) {
// pack number of groups
int32_t i = groups.size() - 1;
for (; i >= 0; --i) {
if (groups[i]) {
nof_groups = i + 1;
}
break;
}
if (nof_groups > groups.size()) {
srsasn_log_print(LOG_LEVEL_ERROR, "Exceeded maximum number of groups (%d>%d)\n", nof_groups, groups.size());
return SRSASN_ERROR_ENCODE_FAIL;
}
HANDLE_CODE(pack_norm_small_integer(bref, nof_groups + nof_nogroups - 1));
return SRSASN_SUCCESS;
}
uint32_t nof_groups = (uint32_t)i + 1u;
HANDLE_CODE(pack_norm_small_integer(bref, nof_groups - 1));
SRSASN_CODE ext_groups_header::pack_group_flags(bit_ref& bref) const
{
if (nof_groups > groups.size()) {
srsasn_log_print(LOG_LEVEL_ERROR, "Exceeded maximum number of groups (%d>%d)\n", nof_groups, groups.size());
return SRSASN_ERROR_ENCODE_FAIL;
}
for (uint32_t i = 0; i < nof_groups; ++i) {
HANDLE_CODE(bref.pack(groups[i], 1));
// pack each group presence flag
for (uint32_t j = 0; j < nof_groups; ++j) {
HANDLE_CODE(bref.pack(groups[j], 1));
}
return SRSASN_SUCCESS;
}
SRSASN_CODE ext_groups_header::pack(bit_ref& bref) const
{
HANDLE_CODE(pack_nof_groups(bref));
return pack_group_flags(bref);
}
SRSASN_CODE ext_groups_header::unpack_nof_groups(bit_ref& bref)
SRSASN_CODE ext_groups_header::unpack(bit_ref& bref)
{
// unpack nof of ext groups
uint32_t nof_groups;
HANDLE_CODE(unpack_norm_small_integer(nof_groups, bref));
nof_groups += 1 - nof_nogroups;
if (nof_groups > groups.size()) {
srsasn_log_print(LOG_LEVEL_ERROR, "Exceeded maximum number of groups (%d>%d)\n", nof_groups, groups.size());
return SRSASN_ERROR_DECODE_FAIL;
}
return SRSASN_SUCCESS;
}
nof_groups += 1;
groups.resize(nof_groups);
SRSASN_CODE ext_groups_header::unpack_group_flags(bit_ref& bref)
{
if (nof_groups > groups.size()) {
srsasn_log_print(LOG_LEVEL_ERROR, "Exceeded maximum number of groups (%d>%d)\n", nof_groups, groups.size());
return SRSASN_ERROR_DECODE_FAIL;
}
// unpack each group presence flag
for (uint32_t i = 0; i < nof_groups; ++i) {
HANDLE_CODE(bref.unpack(groups[i], 1));
}
return SRSASN_SUCCESS;
}
SRSASN_CODE ext_groups_header::unpack(bit_ref& bref)
{
HANDLE_CODE(unpack_nof_groups(bref));
return unpack_group_flags(bref);
}
/*********************
Open Field
*********************/

File diff suppressed because it is too large Load Diff

@ -1546,7 +1546,7 @@ void rrc::ue::send_connection_setup(bool is_setup)
rr_cfg->drb_to_add_mod_list_present = false;
rr_cfg->drb_to_release_list_present = false;
rr_cfg->rlf_timers_and_consts_r9_present = false;
rr_cfg->rlf_timers_and_consts_r9.set_present(false);
rr_cfg->sps_cfg_present = false;
// rr_cfg->rlf_timers_and_constants_present = false;

@ -979,7 +979,7 @@ srslte_cqi_report_mode_t cc_worker::aperiodic_mode(cqi_report_mode_aperiodic_e m
void cc_worker::parse_antenna_info(phys_cfg_ded_s* dedicated)
{
if (dedicated->ant_info_r10_present) {
if (dedicated->ant_info_r10.is_present()) {
// Parse Release 10
ant_info_ded_r10_s::tx_mode_r10_e_::options tx_mode =
dedicated->ant_info_r10->explicit_value_r10().tx_mode_r10.value;
@ -1057,7 +1057,7 @@ void cc_worker::parse_pucch_config(phy_interface_rrc_lte::phy_cfg_t* phy_cfg)
ue_ul_cfg.ul_cfg.pucch.tdd_ack_bundle = false;
}
if (dedicated->pucch_cfg_ded_v1020_present) {
if (dedicated->pucch_cfg_ded_v1020.is_present()) {
pucch_cfg_ded_v1020_s* pucch_cfg_ded = dedicated->pucch_cfg_ded_v1020.get();
if (pucch_cfg_ded->pucch_format_r10_present) {
@ -1230,7 +1230,7 @@ void cc_worker::set_pcell_config(phy_interface_rrc_lte::phy_cfg_t* phy_cfg)
ue_dl_cfg.cfg.cqi_report.aperiodic_configured = true;
ue_dl_cfg.cfg.cqi_report.aperiodic_mode = aperiodic_mode(dedicated->cqi_report_cfg.cqi_report_mode_aperiodic);
}
if (dedicated->cqi_report_cfg_pcell_v1250_present) {
if (dedicated->cqi_report_cfg_pcell_v1250.is_present()) {
auto cqi_report_cfg_pcell_v1250 = dedicated->cqi_report_cfg_pcell_v1250.get();
if (cqi_report_cfg_pcell_v1250->alt_cqi_table_r12_present) {
ue_dl_cfg.pdsch_use_tbs_index_alt = true;
@ -1392,7 +1392,7 @@ void cc_worker::set_scell_config(asn1::rrc::scell_to_add_mod_r10_s* phy_cfg)
}
}
if (phys_cfg_ded_scell_r10->cqi_report_cfg_scell_v1250_present) {
if (phys_cfg_ded_scell_r10->cqi_report_cfg_scell_v1250.is_present()) {
auto cqi_report_cfg_scell = phys_cfg_ded_scell_r10->cqi_report_cfg_scell_v1250.get();
// Enable/disable PDSCH 256QAM

@ -461,7 +461,7 @@ void phy::set_config_scell(asn1::rrc::scell_to_add_mod_r10_s* scell_config)
// Parse radio resource
if (scell_config->rr_cfg_common_scell_r10_present) {
rr_cfg_common_scell_r10_s* rr_cfg = &scell_config->rr_cfg_common_scell_r10;
cell.frame_type = (rr_cfg->tdd_cfg_v1130_present) ? SRSLTE_TDD : SRSLTE_FDD;
cell.frame_type = (rr_cfg->tdd_cfg_v1130.is_present()) ? SRSLTE_TDD : SRSLTE_FDD;
cell.nof_prb = rr_cfg->non_ul_cfg_r10.dl_bw_r10.to_number();
cell.nof_ports = rr_cfg->non_ul_cfg_r10.ant_info_common_r10.ant_ports_count.to_number();
cell.phich_length = (srslte_phich_length_t)rr_cfg->non_ul_cfg_r10.phich_cfg_r10.phich_dur.value;

@ -1632,7 +1632,7 @@ void rrc::handle_sib2()
} else if (args.release >= 12 && sib2->rr_cfg_common.pusch_cfg_common.pusch_cfg_basic.enable64_qam) {
if (args.ue_category_ul == 5 || args.ue_category_ul == 13) {
// ASN1 Generator simplifies enable64QAM-v1270 because it is an enumeration that is always true
current_phy_cfg.common.rrc_enable_64qam = sib2->rr_cfg_common.pusch_cfg_common_v1270_present;
current_phy_cfg.common.rrc_enable_64qam = sib2->rr_cfg_common.pusch_cfg_common_v1270.is_present();
} else {
current_phy_cfg.common.rrc_enable_64qam = false;
}
@ -2497,15 +2497,8 @@ void rrc::apply_phy_config_dedicated(const phys_cfg_ded_s& phy_cnfg)
current_cfg->pucch_cfg_ded = phy_cnfg.pucch_cfg_ded;
}
if (phy_cnfg.cqi_report_cfg_pcell_v1250_present) {
current_cfg->cqi_report_cfg_pcell_v1250_present = true;
current_cfg->cqi_report_cfg_pcell_v1250 = phy_cnfg.cqi_report_cfg_pcell_v1250;
}
if (phy_cnfg.pucch_cfg_ded_v1020_present) {
current_cfg->pucch_cfg_ded_v1020_present = true;
current_cfg->pucch_cfg_ded_v1020 = phy_cnfg.pucch_cfg_ded_v1020;
}
if (phy_cnfg.pusch_cfg_ded_present) {
current_cfg->pusch_cfg_ded_present = true;
@ -2632,7 +2625,7 @@ bool rrc::apply_rr_config_dedicated(rr_cfg_ded_s* cnfg)
if (cnfg->sps_cfg_present) {
//TODO
}
if (cnfg->rlf_timers_and_consts_r9_present and cnfg->rlf_timers_and_consts_r9->type() == setup_e::setup) {
if (cnfg->rlf_timers_and_consts_r9.is_present() and cnfg->rlf_timers_and_consts_r9->type() == setup_e::setup) {
mac_timers->timer_get(t301)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t301_r9.to_number());
mac_timers->timer_get(t310)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t310_r9.to_number());
mac_timers->timer_get(t311)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t311_r9.to_number());

Loading…
Cancel
Save