fixes to include the findings from PR #550

master
Francisco Paisana 6 years ago committed by Andre Puschmann
parent 62a4fa1c93
commit 416f9896ec

@ -320,8 +320,8 @@ public:
enumerated() { EnumType::value = EnumType::nulltype; }
enumerated(typename EnumType::options o) { EnumType::value = o; }
SRSASN_CODE pack(bit_ref& bref) const { return pack_enum(bref, EnumType::value); }
SRSASN_CODE unpack(bit_ref& bref) { return unpack_enum(EnumType::value, bref); }
SRSASN_CODE pack(bit_ref& bref) const { return pack_enum(bref, *this); }
SRSASN_CODE unpack(bit_ref& bref) { return unpack_enum(*this, bref); }
EnumType& operator=(EnumType v)
{
EnumType::value = v;
@ -348,6 +348,17 @@ struct UnalignedIntegerPacker {
SRSASN_CODE unpack(IntType& n, bit_ref& bref) const;
};
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) {}
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); }
};
template <class IntType>
SRSASN_CODE pack_align_integer(bit_ref& bref, IntType n, IntType lb, IntType ub);
template <typename IntType>
@ -578,8 +589,8 @@ public:
fixed_bitstring(const std::string& s)
{
if (s.size() != N) {
srsasn_log_print(LOG_LEVEL_ERROR, "The provided string size=%d does not match the bit string size=%d\n", s.size(),
N);
srsasn_log_print(
LOG_LEVEL_ERROR, "The provided string size=%d does not match the bit string size=%d\n", s.size(), N);
}
memset(&octets_[0], 0, nof_octets());
for (uint32_t i = 0; i < N; ++i)
@ -774,6 +785,15 @@ struct SeqOfPacker {
uint32_t ub;
};
template <class ItemType, uint32_t lb, uint32_t ub>
struct dyn_seq_of : public dyn_array<ItemType> {
SeqOfPacker<Packer> packer;
dyn_seq_of() : packer(lb, ub, Packer()) {}
dyn_seq_of(const dyn_array<ItemType>& other) : dyn_array<ItemType>(other), packer(lb, ub, Packer()) {}
SRSASN_CODE pack(bit_ref& bref) const { return packer.pack(bref, *this); }
SRSASN_CODE unpack(bit_ref& bref) { return packer.unpack(*this, bref); }
};
/*********************
choice utils
*********************/

@ -62,12 +62,15 @@ inline void assert_choice_type(uint32_t val, uint32_t choice_id)
}
}
inline void assert_choice_type(const std::string& access_type, const std::string& current_type,
const std::string& choice_type)
inline void
assert_choice_type(const std::string& access_type, const std::string& current_type, const std::string& choice_type)
{
if (access_type != current_type) {
rrc_log_print(LOG_LEVEL_ERROR, "Invalid field access for choice type \"%s\" (\"%s\"!=\"%s\")\n",
choice_type.c_str(), access_type.c_str(), current_type.c_str());
rrc_log_print(LOG_LEVEL_ERROR,
"Invalid field access for choice type \"%s\" (\"%s\"!=\"%s\")\n",
choice_type.c_str(),
access_type.c_str(),
current_type.c_str());
}
}
@ -91,7 +94,8 @@ ItemType convert_enum_idx(ItemType* array, uint32_t nof_types, uint32_t enum_val
if (enum_val == nof_types) {
rrc_log_print(LOG_LEVEL_ERROR, "The enum of type %s was not initialized.\n", enum_type);
} else {
rrc_log_print(LOG_LEVEL_ERROR, "The enum value=%d of type %s is not valid.\n", enum_val, enum_type);
rrc_log_print(
LOG_LEVEL_ERROR, "The provided enum value=%d of type %s cannot be converted.\n", enum_val, enum_type);
}
return 0;
}
@ -42562,8 +42566,8 @@ struct location_info_r10_s {
}
dyn_octstring& ellipsoid_point_with_altitude_and_uncertainty_ellipsoid_r11()
{
assert_choice_type("ellipsoidPointWithAltitudeAndUncertaintyEllipsoid-r11", type_.to_string(),
"locationCoordinates-r10");
assert_choice_type(
"ellipsoidPointWithAltitudeAndUncertaintyEllipsoid-r11", type_.to_string(), "locationCoordinates-r10");
return c.get<dyn_octstring>();
}
dyn_octstring& ellipsoid_arc_r11()
@ -42598,8 +42602,8 @@ struct location_info_r10_s {
}
const dyn_octstring& ellipsoid_point_with_altitude_and_uncertainty_ellipsoid_r11() const
{
assert_choice_type("ellipsoidPointWithAltitudeAndUncertaintyEllipsoid-r11", type_.to_string(),
"locationCoordinates-r10");
assert_choice_type(
"ellipsoidPointWithAltitudeAndUncertaintyEllipsoid-r11", type_.to_string(), "locationCoordinates-r10");
return c.get<dyn_octstring>();
}
const dyn_octstring& ellipsoid_arc_r11() const

@ -252,8 +252,8 @@ SRSASN_CODE pack_enum(bit_ref& bref, uint32_t enum_val, uint32_t nbits, uint32_t
SRSASN_CODE pack_enum(bit_ref& bref, uint32_t e, uint32_t nof_types, uint32_t nof_exts, bool has_ext)
{
if (e >= nof_types) {
srsasn_log_print(LOG_LEVEL_ERROR, "The provided enum is not within the range of possible values (%d>=%d)\n", e,
nof_types);
srsasn_log_print(
LOG_LEVEL_ERROR, "The provided enum is not within the range of possible values (%d>=%d)\n", e, nof_types);
return SRSASN_ERROR_ENCODE_FAIL;
}
SRSASN_CODE ret;
@ -288,8 +288,8 @@ ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, bit_
ret.code = bref.unpack(ret.val, nof_bits);
}
if (ret.val >= nof_types) {
srsasn_log_print(LOG_LEVEL_ERROR, "The provided enum is not within the range of possible values (%d>=%d)\n",
ret.val, nof_types);
srsasn_log_print(
LOG_LEVEL_ERROR, "The provided enum is not within the range of possible values (%d>=%d)\n", ret.val, nof_types);
ret.code = SRSASN_ERROR_DECODE_FAIL;
}
return ret;
@ -710,11 +710,11 @@ dyn_octstring& dyn_octstring::from_string(const std::string& hexstr)
SRSASN_CODE pack_common_bitstring(bit_ref& bref, const uint8_t* buf, uint32_t nbits)
{
uint32_t n_octs = (uint32_t)ceilf(nbits / 8.0f);
if (n_octs == 0) {
srsasn_log_print(LOG_LEVEL_ERROR, "Invalid number of octets (%d)\n", n_octs);
return SRSASN_ERROR_DECODE_FAIL;
if (nbits == 0) {
srsasn_log_print(LOG_LEVEL_ERROR, "Invalid bitstring size=%d\n", nbits);
return SRSASN_ERROR_ENCODE_FAIL;
}
uint32_t n_octs = (uint32_t)ceilf(nbits / 8.0f);
uint32_t offset = ((nbits - 1) % 8) + 1;
HANDLE_CODE(bref.pack(buf[n_octs - 1], offset));
for (uint32_t i = 1; i < n_octs; ++i) {
@ -725,11 +725,11 @@ SRSASN_CODE pack_common_bitstring(bit_ref& bref, const uint8_t* buf, uint32_t nb
SRSASN_CODE unpack_common_bitstring(uint8_t* buf, bit_ref& bref, uint32_t nbits)
{
uint32_t n_octs = (uint32_t)ceilf(nbits / 8.0f);
if (n_octs == 0) {
srsasn_log_print(LOG_LEVEL_ERROR, "Invalid number of octets (%d)\n", n_octs);
if (nbits == 0) {
srsasn_log_print(LOG_LEVEL_ERROR, "Invalid bitstring size=%d\n", nbits);
return SRSASN_ERROR_DECODE_FAIL;
}
uint32_t n_octs = (uint32_t)ceilf(nbits / 8.0f);
uint32_t offset = ((nbits - 1) % 8) + 1;
HANDLE_CODE(bref.unpack(buf[n_octs - 1], offset));
for (uint32_t i = 1; i < n_octs; ++i) {
@ -858,8 +858,8 @@ SRSASN_CODE dyn_bitstring::pack(bit_ref& bref, uint32_t lb, uint32_t ub) const
}
if (ub > 0) {
if (ub < len) {
srsasn_log_print(LOG_LEVEL_ERROR, "asn1 error: dynamic bitstring length=%d is higher than set upper bound=%d\n",
len, ub);
srsasn_log_print(
LOG_LEVEL_ERROR, "asn1 error: dynamic bitstring length=%d is higher than set upper bound=%d\n", len, ub);
return SRSASN_ERROR_ENCODE_FAIL;
}
uint32_t len_bits = ceilf(log2(ub - lb));
@ -960,8 +960,6 @@ SRSASN_CODE ext_groups_header::pack_group_flags(bit_ref& bref) const
srsasn_log_print(LOG_LEVEL_ERROR, "Exceeded maximum number of groups (%d>%d)\n", nof_groups, groups.size());
return SRSASN_ERROR_ENCODE_FAIL;
}
// NOTE: nof_groups is cached
for (uint32_t i = 0; i < nof_groups; ++i) {
HANDLE_CODE(bref.pack(groups[i], 1));
}
@ -1024,8 +1022,10 @@ varlength_field_pack_guard::~varlength_field_pack_guard()
// check how many bytes were written in total
uint32_t nof_bytes = bref_tracker->distance(bref0) / (uint32_t)8;
if (nof_bytes > sizeof(buffer)) {
srsasn_log_print(LOG_LEVEL_ERROR, "The packed variable sized field is too long for the reserved buffer (%d > %d)\n",
nof_bytes, sizeof(buffer));
srsasn_log_print(LOG_LEVEL_ERROR,
"The packed variable sized field is too long for the reserved buffer (%d > %d)\n",
nof_bytes,
sizeof(buffer));
}
// go back in time to pack length

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save