created cbit_ref for unpacking const buffers

master
Francisco Paisana 5 years ago
parent 58e555e86c
commit 5ae3afd2b8

@ -87,45 +87,59 @@ struct ValOrError {
ValOrError() : val(0), code(SRSASN_SUCCESS) {} ValOrError() : val(0), code(SRSASN_SUCCESS) {}
ValOrError(uint32_t val_, SRSASN_CODE code_) : val(val_), code(code_) {} ValOrError(uint32_t val_, SRSASN_CODE code_) : val(val_), code(code_) {}
}; };
ValOrError unpack_bits(uint8_t*& ptr, uint8_t& offset, uint8_t* max_ptr, uint32_t n_bits); template <typename T, typename Ptr>
SRSASN_CODE unpack_bits(T& val, Ptr& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
class bit_ref template <typename Ptr = uint8_t*>
class bit_ref_impl
{ {
public: public:
bit_ref() = default; bit_ref_impl() = default;
bit_ref(uint8_t* start_ptr_, uint32_t max_size_) : bit_ref_impl(Ptr start_ptr_, uint32_t max_size_) :
ptr(start_ptr_), ptr(start_ptr_),
start_ptr(start_ptr_), start_ptr(start_ptr_),
max_ptr(max_size_ + start_ptr_) max_ptr(max_size_ + start_ptr_)
{ {
} }
int distance(const bit_ref& other) const; int distance(const bit_ref_impl<Ptr>& other) const;
int distance(uint8_t* ref_ptr) const; int distance(const uint8_t* ref_ptr) const;
int distance() const; int distance() const;
int distance_bytes(uint8_t* ref_ptr) const; int distance_bytes(uint8_t* ref_ptr) const;
int distance_bytes() const; int distance_bytes() const;
SRSASN_CODE pack(uint32_t val, uint32_t n_bits);
SRSASN_CODE pack_bytes(const uint8_t* buf, uint32_t n_bytes);
template <class T> template <class T>
SRSASN_CODE unpack(T& val, uint32_t n_bits) SRSASN_CODE unpack(T& val, uint32_t n_bits)
{ {
ValOrError ret = unpack_bits(ptr, offset, max_ptr, n_bits); return unpack_bits(val, ptr, offset, max_ptr, n_bits);
val = ret.val;
return ret.code;
} }
SRSASN_CODE unpack_bytes(uint8_t* buf, uint32_t n_bytes); SRSASN_CODE unpack_bytes(uint8_t* buf, uint32_t n_bytes);
SRSASN_CODE align_bytes(); SRSASN_CODE align_bytes();
SRSASN_CODE align_bytes_zero();
SRSASN_CODE advance_bits(uint32_t n_bits); SRSASN_CODE advance_bits(uint32_t n_bits);
void set(uint8_t* start_ptr_, uint32_t max_size_); void set(Ptr start_ptr_, uint32_t max_size_);
private: protected:
uint8_t* ptr = nullptr; Ptr ptr = nullptr;
uint8_t offset = 0; uint8_t offset = 0;
uint8_t* start_ptr = nullptr; const uint8_t* start_ptr = nullptr;
uint8_t* max_ptr = nullptr; const uint8_t* max_ptr = nullptr;
};
// read only bit_ref
using cbit_ref = bit_ref_impl<const uint8_t*>;
// write+read bit_ref version
class bit_ref : public bit_ref_impl<uint8_t*>
{
using base_t = bit_ref_impl<uint8_t*>;
public:
bit_ref() = default;
bit_ref(uint8_t* start_ptr_, uint32_t max_size_) : bit_ref_impl(start_ptr_, max_size_) {}
SRSASN_CODE pack(uint32_t val, uint32_t n_bits);
SRSASN_CODE pack_bytes(const uint8_t* buf, uint32_t n_bytes);
SRSASN_CODE align_bytes_zero();
}; };
/********************* /*********************
@ -360,7 +374,7 @@ SRSASN_CODE unpack_unsupported_ext_flag(bool& ext, bit_ref& bref);
struct asn1_null_t { struct asn1_null_t {
SRSASN_CODE pack(bit_ref& bref) const { return SRSASN_SUCCESS; } SRSASN_CODE pack(bit_ref& bref) const { return SRSASN_SUCCESS; }
SRSASN_CODE unpack(bit_ref& bref) const { return SRSASN_SUCCESS; } SRSASN_CODE unpack(cbit_ref& bref) const { return SRSASN_SUCCESS; }
}; };
/************************ /************************
@ -370,14 +384,14 @@ struct asn1_null_t {
SRSASN_CODE pack_enum(bit_ref& bref, uint32_t enum_val, uint32_t nbits); SRSASN_CODE pack_enum(bit_ref& bref, uint32_t enum_val, uint32_t nbits);
SRSASN_CODE pack_enum(bit_ref& bref, uint32_t enum_val, uint32_t nbits, uint32_t nof_noext); SRSASN_CODE pack_enum(bit_ref& bref, uint32_t enum_val, uint32_t nbits, uint32_t nof_noext);
SRSASN_CODE pack_enum(bit_ref& bref, uint32_t e, uint32_t nof_types, uint32_t nof_exts, bool has_ext); SRSASN_CODE pack_enum(bit_ref& bref, uint32_t e, uint32_t nof_types, uint32_t nof_exts, bool has_ext);
ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, bit_ref& bref); ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, cbit_ref& bref);
template <typename EnumType> template <typename EnumType>
SRSASN_CODE pack_enum(bit_ref& bref, EnumType e) SRSASN_CODE pack_enum(bit_ref& bref, EnumType e)
{ {
return pack_enum(bref, e, EnumType::nof_types, EnumType::nof_exts, EnumType::has_ext); return pack_enum(bref, e, EnumType::nof_types, EnumType::nof_exts, EnumType::has_ext);
} }
template <typename EnumType> template <typename EnumType>
SRSASN_CODE unpack_enum(EnumType& e, bit_ref& bref) SRSASN_CODE unpack_enum(EnumType& e, cbit_ref& bref)
{ {
ValOrError ret = unpack_enum(EnumType::nof_types, EnumType::nof_exts, EnumType::has_ext, bref); ValOrError ret = unpack_enum(EnumType::nof_types, EnumType::nof_exts, EnumType::has_ext, bref);
e = (typename EnumType::options)ret.val; e = (typename EnumType::options)ret.val;
@ -391,7 +405,7 @@ struct EnumPacker {
return pack_enum(bref, e); return pack_enum(bref, e);
} }
template <class EnumType> template <class EnumType>
SRSASN_CODE unpack(EnumType& e, bit_ref& bref) SRSASN_CODE unpack(EnumType& e, cbit_ref& bref)
{ {
return unpack_enum(e, bref); return unpack_enum(e, bref);
} }
@ -440,7 +454,7 @@ public:
enumerated() { EnumType::value = EnumType::nulltype; } enumerated() { EnumType::value = EnumType::nulltype; }
enumerated(typename EnumType::options o) { EnumType::value = o; } enumerated(typename EnumType::options o) { EnumType::value = o; }
SRSASN_CODE pack(bit_ref& bref) const { return pack_enum(bref, *this); } SRSASN_CODE pack(bit_ref& bref) const { return pack_enum(bref, *this); }
SRSASN_CODE unpack(bit_ref& bref) { return unpack_enum(*this, bref); } SRSASN_CODE unpack(cbit_ref& bref) { return unpack_enum(*this, bref); }
EnumType& operator=(EnumType v) EnumType& operator=(EnumType v)
{ {
EnumType::value = v; EnumType::value = v;
@ -457,19 +471,19 @@ public:
template <class IntType> template <class IntType>
SRSASN_CODE pack_constrained_whole_number(bit_ref& bref, IntType n, IntType lb, IntType ub, bool aligned); SRSASN_CODE pack_constrained_whole_number(bit_ref& bref, IntType n, IntType lb, IntType ub, bool aligned);
template <class IntType> template <class IntType>
SRSASN_CODE unpack_constrained_whole_number(IntType& n, bit_ref& bref, IntType lb, IntType ub, bool aligned); SRSASN_CODE unpack_constrained_whole_number(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool aligned);
/* X.691 - Section 10.6 - Normally small non-negative whole Number */ /* X.691 - Section 10.6 - Normally small non-negative whole Number */
template <typename UintType> template <typename UintType>
SRSASN_CODE pack_norm_small_non_neg_whole_number(bit_ref& bref, UintType n); SRSASN_CODE pack_norm_small_non_neg_whole_number(bit_ref& bref, UintType n);
template <typename UintType> template <typename UintType>
SRSASN_CODE unpack_norm_small_non_neg_whole_number(UintType& n, bit_ref& bref); SRSASN_CODE unpack_norm_small_non_neg_whole_number(UintType& n, cbit_ref& bref);
/* X.691 - Section 10.8 - Unconstrained Whole Number */ /* X.691 - Section 10.8 - Unconstrained Whole Number */
template <typename IntType> template <typename IntType>
SRSASN_CODE pack_unconstrained_whole_number(bit_ref& bref, IntType n, bool aligned); SRSASN_CODE pack_unconstrained_whole_number(bit_ref& bref, IntType n, bool aligned);
template <typename IntType> template <typename IntType>
SRSASN_CODE unpack_unconstrained_whole_number(IntType& n, bit_ref& bref, bool aligned); SRSASN_CODE unpack_unconstrained_whole_number(IntType& n, cbit_ref& bref, bool aligned);
/************************ /************************
length determinant length determinant
@ -479,11 +493,11 @@ SRSASN_CODE unpack_unconstrained_whole_number(IntType& n, bit_ref& bref, bool al
template <typename IntType> template <typename IntType>
SRSASN_CODE pack_length(bit_ref& bref, IntType n, IntType lb, IntType ub, bool aligned = false); SRSASN_CODE pack_length(bit_ref& bref, IntType n, IntType lb, IntType ub, bool aligned = false);
template <typename IntType> template <typename IntType>
SRSASN_CODE unpack_length(IntType& n, bit_ref& bref, IntType lb, IntType ub, bool aligned = false); SRSASN_CODE unpack_length(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool aligned = false);
// Pack as a small non-negative whole number // Pack as a small non-negative whole number
SRSASN_CODE pack_length(bit_ref& ref, uint32_t val, bool aligned = false); SRSASN_CODE pack_length(bit_ref& ref, uint32_t val, bool aligned = false);
SRSASN_CODE unpack_length(uint32_t& val, bit_ref& ref, bool aligned = false); SRSASN_CODE unpack_length(uint32_t& val, cbit_ref& ref, bool aligned = false);
/************************ /************************
Integer Integer
@ -497,23 +511,23 @@ SRSASN_CODE pack_integer(bit_ref& bref,
bool has_ext = false, bool has_ext = false,
bool aligned = false); bool aligned = false);
template <typename IntType> template <typename IntType>
SRSASN_CODE unpack_integer(IntType& n, SRSASN_CODE unpack_integer(IntType& n,
bit_ref& bref, cbit_ref& bref,
IntType lb = std::numeric_limits<IntType>::min(), IntType lb = std::numeric_limits<IntType>::min(),
IntType ub = std::numeric_limits<IntType>::max(), IntType ub = std::numeric_limits<IntType>::max(),
bool has_ext = false, bool has_ext = false,
bool aligned = false); bool aligned = false);
// unconstrained case // unconstrained case
template <typename IntType> template <typename IntType>
SRSASN_CODE pack_unconstrained_integer(bit_ref& bref, IntType n, bool has_ext = false, bool aligned = false); SRSASN_CODE pack_unconstrained_integer(bit_ref& bref, IntType n, bool has_ext = false, bool aligned = false);
template <typename IntType> template <typename IntType>
SRSASN_CODE unpack_unconstrained_integer(IntType& n, bit_ref& bref, bool has_ext = false, bool aligned = false); SRSASN_CODE unpack_unconstrained_integer(IntType& n, cbit_ref& bref, bool has_ext = false, bool aligned = false);
template <class IntType> template <class IntType>
struct integer_packer { struct integer_packer {
integer_packer(IntType lb_, IntType ub_, bool has_ext_ = false, bool aligned_ = false); integer_packer(IntType lb_, IntType ub_, bool has_ext_ = false, bool aligned_ = false);
SRSASN_CODE pack(bit_ref& bref, IntType n); SRSASN_CODE pack(bit_ref& bref, IntType n);
SRSASN_CODE unpack(IntType& n, bit_ref& bref); SRSASN_CODE unpack(IntType& n, cbit_ref& bref);
IntType lb; IntType lb;
IntType ub; IntType ub;
bool has_ext; bool has_ext;
@ -535,7 +549,7 @@ public:
integer(IntType value_) : value(value_) {} integer(IntType value_) : value(value_) {}
operator IntType() { return value; } operator IntType() { return value; }
SRSASN_CODE pack(bit_ref& bref) const { return pack_integer(bref, value, lb, ub, has_ext, is_aligned); } SRSASN_CODE pack(bit_ref& bref) const { return pack_integer(bref, value, lb, ub, has_ext, is_aligned); }
SRSASN_CODE unpack(bit_ref& bref) { return unpack_integer(value, bref, lb, ub, has_ext, is_aligned); } SRSASN_CODE unpack(cbit_ref& bref) { return unpack_integer(value, bref, lb, ub, has_ext, is_aligned); }
}; };
/************************ /************************
@ -551,7 +565,7 @@ struct BitPacker {
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
template <typename T> template <typename T>
SRSASN_CODE unpack(T& tounpack, bit_ref& bref) SRSASN_CODE unpack(T& tounpack, cbit_ref& bref)
{ {
return bref.unpack(tounpack, nof_bits); return bref.unpack(tounpack, nof_bits);
} }
@ -565,7 +579,7 @@ struct Packer {
return topack.pack(bref); return topack.pack(bref);
} }
template <typename T> template <typename T>
SRSASN_CODE unpack(T& tounpack, bit_ref& bref) SRSASN_CODE unpack(T& tounpack, cbit_ref& bref)
{ {
return tounpack.unpack(bref); return tounpack.unpack(bref);
} }
@ -615,7 +629,7 @@ public:
} }
SRSASN_CODE pack(bit_ref& bref) const; SRSASN_CODE pack(bit_ref& bref) const;
SRSASN_CODE unpack(bit_ref& bref); SRSASN_CODE unpack(cbit_ref& bref);
private: private:
std::array<uint8_t, N> octets_; std::array<uint8_t, N> octets_;
@ -641,10 +655,10 @@ SRSASN_CODE fixed_octstring<N, aligned>::pack(bit_ref& bref) const
} }
template <uint32_t N, bool aligned> template <uint32_t N, bool aligned>
SRSASN_CODE fixed_octstring<N, aligned>::unpack(bit_ref& bref) SRSASN_CODE fixed_octstring<N, aligned>::unpack(cbit_ref& bref)
{ {
if (aligned and N > 2) { if (aligned and N > 2) {
bref.align_bytes_zero(); bref.align_bytes();
} }
for (uint32_t i = 0; i < size(); ++i) { for (uint32_t i = 0; i < size(); ++i) {
HANDLE_CODE(bref.unpack(octets_[i], 8)); HANDLE_CODE(bref.unpack(octets_[i], 8));
@ -674,7 +688,7 @@ public:
const uint8_t* data() const { return &octets_[0]; } const uint8_t* data() const { return &octets_[0]; }
SRSASN_CODE pack(bit_ref& ie_ref) const; SRSASN_CODE pack(bit_ref& ie_ref) const;
SRSASN_CODE unpack(bit_ref& ie_ref); SRSASN_CODE unpack(cbit_ref& ie_ref);
std::string to_string() const; std::string to_string() const;
unbounded_octstring<Al>& from_string(const std::string& hexstr); unbounded_octstring<Al>& from_string(const std::string& hexstr);
uint64_t to_number() const { return octstring_to_number(&octets_[0], size()); } uint64_t to_number() const { return octstring_to_number(&octets_[0], size()); }
@ -713,8 +727,9 @@ inline void set(uint8_t* ptr, uint32_t idx, bool value)
} }
SRSASN_CODE SRSASN_CODE
pack(bit_ref& bref, const uint8_t* data, uint32_t size, uint32_t lb, uint32_t ub, bool has_ext, bool is_aligned); pack(bit_ref& bref, const uint8_t* data, uint32_t size, uint32_t lb, uint32_t ub, bool has_ext, bool is_aligned);
SRSASN_CODE unpack_length_prefix(uint32_t& len, bit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool is_aligned); SRSASN_CODE
SRSASN_CODE unpack_bitfield(uint8_t* buf, bit_ref& bref, uint32_t n, uint32_t lb, uint32_t ub, bool is_aligned); unpack_length_prefix(uint32_t& len, cbit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool is_aligned);
SRSASN_CODE unpack_bitfield(uint8_t* buf, cbit_ref& bref, uint32_t n, uint32_t lb, uint32_t ub, bool is_aligned);
uint64_t to_number(const uint8_t* ptr, uint32_t nbits); uint64_t to_number(const uint8_t* ptr, uint32_t nbits);
void from_number(uint8_t* ptr, uint64_t number, uint32_t nbits); void from_number(uint8_t* ptr, uint64_t number, uint32_t nbits);
@ -798,7 +813,7 @@ public:
{ {
return bitstring_utils::pack(bref, data(), length(), lb, ub, has_ext, is_aligned); return bitstring_utils::pack(bref, data(), length(), lb, ub, has_ext, is_aligned);
} }
SRSASN_CODE unpack(bit_ref& bref) SRSASN_CODE unpack(cbit_ref& bref)
{ {
// X.691, subclause 15.11 // X.691, subclause 15.11
uint32_t nbits; uint32_t nbits;
@ -846,7 +861,7 @@ SRSASN_CODE pack_fixed_seq_of(bit_ref& bref, const T* item_array, uint32_t nof_i
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
template <class T, class ItemUnpacker> template <class T, class ItemUnpacker>
SRSASN_CODE unpack_fixed_seq_of(T* item_array, bit_ref& bref, uint32_t nof_items, ItemUnpacker unpacker) SRSASN_CODE unpack_fixed_seq_of(T* item_array, cbit_ref& bref, uint32_t nof_items, ItemUnpacker unpacker)
{ {
for (uint32_t i = 0; i < nof_items; ++i) { for (uint32_t i = 0; i < nof_items; ++i) {
HANDLE_CODE(unpacker.unpack(item_array[i], bref)); HANDLE_CODE(unpacker.unpack(item_array[i], bref));
@ -854,7 +869,7 @@ SRSASN_CODE unpack_fixed_seq_of(T* item_array, bit_ref& bref, uint32_t nof_items
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
template <class T> template <class T>
SRSASN_CODE unpack_fixed_seq_of(T* item_array, bit_ref& bref, uint32_t nof_items) SRSASN_CODE unpack_fixed_seq_of(T* item_array, cbit_ref& bref, uint32_t nof_items)
{ {
for (uint32_t i = 0; i < nof_items; ++i) { for (uint32_t i = 0; i < nof_items; ++i) {
HANDLE_CODE(item_array[i].unpack(bref)); HANDLE_CODE(item_array[i].unpack(bref));
@ -911,7 +926,7 @@ SRSASN_CODE pack_dyn_seq_of(bit_ref& bref, const ArrayType& seqof, uint32_t lb,
template <class ArrayType, class ItemUnpacker> template <class ArrayType, class ItemUnpacker>
SRSASN_CODE unpack_dyn_seq_of(ArrayType& seqof, SRSASN_CODE unpack_dyn_seq_of(ArrayType& seqof,
bit_ref& bref, cbit_ref& bref,
uint32_t lb, uint32_t lb,
uint32_t ub, uint32_t ub,
ItemUnpacker unpacker, ItemUnpacker unpacker,
@ -927,7 +942,7 @@ SRSASN_CODE unpack_dyn_seq_of(ArrayType& seqof,
} }
template <class ArrayType> template <class ArrayType>
SRSASN_CODE unpack_dyn_seq_of(ArrayType& seqof, bit_ref& bref, uint32_t lb, uint32_t ub, bool aligned = false) SRSASN_CODE unpack_dyn_seq_of(ArrayType& seqof, cbit_ref& bref, uint32_t lb, uint32_t ub, bool aligned = false)
{ {
uint32_t nof_items; uint32_t nof_items;
HANDLE_CODE(unpack_length(nof_items, bref, lb, ub, aligned)); HANDLE_CODE(unpack_length(nof_items, bref, lb, ub, aligned));
@ -947,7 +962,7 @@ struct SeqOfPacker {
return pack_dyn_seq_of(bref, topack, lb, ub, packer); return pack_dyn_seq_of(bref, topack, lb, ub, packer);
} }
template <typename T> template <typename T>
SRSASN_CODE unpack(T& tounpack, bit_ref& bref) SRSASN_CODE unpack(T& tounpack, cbit_ref& bref)
{ {
return unpack_dyn_seq_of(tounpack, bref, lb, ub, packer); return unpack_dyn_seq_of(tounpack, bref, lb, ub, packer);
} }
@ -962,7 +977,7 @@ struct dyn_seq_of : public dyn_array<ItemType> {
dyn_seq_of(const dyn_array<ItemType>& other) : dyn_array<ItemType>(other) {} dyn_seq_of(const dyn_array<ItemType>& other) : dyn_array<ItemType>(other) {}
dyn_seq_of(const bounded_array<ItemType, ub>& other) : dyn_array<ItemType>(&other[0], other.size()) {} dyn_seq_of(const bounded_array<ItemType, ub>& other) : dyn_array<ItemType>(&other[0], other.size()) {}
SRSASN_CODE pack(bit_ref& bref) const { return pack_dyn_seq_of(bref, *this, lb, ub, aligned); } SRSASN_CODE pack(bit_ref& bref) const { return pack_dyn_seq_of(bref, *this, lb, ub, aligned); }
SRSASN_CODE unpack(bit_ref& bref) { return unpack_dyn_seq_of(*this, bref, lb, ub, aligned); } SRSASN_CODE unpack(cbit_ref& bref) { return unpack_dyn_seq_of(*this, bref, lb, ub, aligned); }
}; };
/********************* /*********************
@ -973,7 +988,8 @@ struct dyn_seq_of : public dyn_array<ItemType> {
namespace asn_string_utils { namespace asn_string_utils {
SRSASN_CODE SRSASN_CODE
pack(bit_ref& bref, const std::string& s, size_t lb, size_t ub, size_t alb, size_t aub, bool ext, bool aligned); pack(bit_ref& bref, const std::string& s, size_t lb, size_t ub, size_t alb, size_t aub, bool ext, bool aligned);
SRSASN_CODE unpack(std::string& s, bit_ref& bref, size_t lb, size_t ub, size_t alb, size_t aub, bool ext, bool aligned); SRSASN_CODE
unpack(std::string& s, cbit_ref& bref, size_t lb, size_t ub, size_t alb, size_t aub, bool ext, bool aligned);
} // namespace asn_string_utils } // namespace asn_string_utils
template <uint32_t LB, template <uint32_t LB,
@ -986,7 +1002,7 @@ class asn_string
{ {
public: public:
SRSASN_CODE pack(bit_ref& bref) const { return asn_string_utils::pack(bref, str, LB, UB, ALB, AUB, ext, aligned); } SRSASN_CODE pack(bit_ref& bref) const { return asn_string_utils::pack(bref, str, LB, UB, ALB, AUB, ext, aligned); }
SRSASN_CODE unpack(bit_ref& bref) { return asn_string_utils::unpack(str, bref, LB, UB, ALB, AUB, ext, aligned); } SRSASN_CODE unpack(cbit_ref& bref) { return asn_string_utils::unpack(str, bref, LB, UB, ALB, AUB, ext, aligned); }
char& operator[](std::size_t idx) { return str[idx]; } char& operator[](std::size_t idx) { return str[idx]; }
const char& operator[](std::size_t idx) const { return str[idx]; } const char& operator[](std::size_t idx) const { return str[idx]; }
void resize(std::size_t newsize) { str.resize(newsize); } void resize(std::size_t newsize) { str.resize(newsize); }
@ -1161,13 +1177,13 @@ public:
void resize(uint32_t new_size); void resize(uint32_t new_size);
bool& operator[](uint32_t idx); bool& operator[](uint32_t idx);
SRSASN_CODE unpack(bit_ref& bref); SRSASN_CODE unpack(cbit_ref& bref);
private: private:
ext_array<bool> groups; ext_array<bool> groups;
const uint32_t nof_supported_groups; const uint32_t nof_supported_groups;
uint32_t nof_unpacked_groups = 0; uint32_t nof_unpacked_groups = 0;
bit_ref* bref_tracker = nullptr; cbit_ref* bref_tracker = nullptr;
}; };
/********************* /*********************
@ -1191,13 +1207,13 @@ private:
class varlength_field_unpack_guard class varlength_field_unpack_guard
{ {
public: public:
explicit varlength_field_unpack_guard(bit_ref& bref, bool align = false); explicit varlength_field_unpack_guard(cbit_ref& bref, bool align = false);
~varlength_field_unpack_guard(); ~varlength_field_unpack_guard();
private: private:
bit_ref bref0; cbit_ref bref0;
bit_ref* bref_tracker = nullptr; cbit_ref* bref_tracker = nullptr;
uint32_t len = 0; uint32_t len = 0;
}; };
/******************* /*******************
@ -1240,8 +1256,9 @@ int test_pack_unpack_consistency(const Msg& msg)
uint8_t buf[2048], buf2[2048]; uint8_t buf[2048], buf2[2048];
bzero(buf, sizeof(buf)); bzero(buf, sizeof(buf));
bzero(buf2, sizeof(buf2)); bzero(buf2, sizeof(buf2));
Msg msg2; Msg msg2;
asn1::bit_ref bref(&buf[0], sizeof(buf)), bref2(&buf[0], sizeof(buf)), bref3(&buf2[0], sizeof(buf2)); asn1::bit_ref bref(&buf[0], sizeof(buf)), bref3(&buf2[0], sizeof(buf2));
asn1::cbit_ref bref2(&buf[0], sizeof(buf));
if (msg.pack(bref) != asn1::SRSASN_SUCCESS) { if (msg.pack(bref) != asn1::SRSASN_SUCCESS) {
log_error_code(SRSASN_ERROR_ENCODE_FAIL, __FILE__, __LINE__); log_error_code(SRSASN_ERROR_ENCODE_FAIL, __FILE__, __LINE__);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -102,23 +102,28 @@ void log_error_code(SRSASN_CODE code, const char* filename, int line)
bit_ref bit_ref
*********************/ *********************/
int bit_ref::distance(const bit_ref& other) const template <typename Ptr>
int bit_ref_impl<Ptr>::distance(const bit_ref_impl<Ptr>& other) const
{ {
return ((int)offset - (int)other.offset) + 8 * ((int)(ptr - other.ptr)); return ((int)offset - (int)other.offset) + 8 * ((int)(ptr - other.ptr));
} }
int bit_ref::distance(uint8_t* ref_ptr) const template <typename Ptr>
int bit_ref_impl<Ptr>::distance(const uint8_t* ref_ptr) const
{ {
return (int)offset + 8 * ((int)(ptr - ref_ptr)); return (int)offset + 8 * ((int)(ptr - ref_ptr));
} }
int bit_ref::distance() const template <typename Ptr>
int bit_ref_impl<Ptr>::distance() const
{ {
return (int)offset + 8 * ((int)(ptr - start_ptr)); return (int)offset + 8 * ((int)(ptr - start_ptr));
} }
int bit_ref::distance_bytes(uint8_t* ref_ptr) const template <typename Ptr>
int bit_ref_impl<Ptr>::distance_bytes(uint8_t* ref_ptr) const
{ {
return ((int)(ptr - ref_ptr)) + ((offset) ? 1 : 0); return ((int)(ptr - ref_ptr)) + ((offset) ? 1 : 0);
} }
int bit_ref::distance_bytes() const template <typename Ptr>
int bit_ref_impl<Ptr>::distance_bytes() const
{ {
return ((int)(ptr - start_ptr)) + ((offset) ? 1 : 0); return ((int)(ptr - start_ptr)) + ((offset) ? 1 : 0);
} }
@ -137,7 +142,7 @@ SRSASN_CODE bit_ref::pack(uint32_t val, uint32_t n_bits)
} }
mask = ((1u << n_bits) - 1u); mask = ((1u << n_bits) - 1u);
val = val & mask; val = val & mask;
uint8_t keepmask = ((uint8_t)-1) - (uint8_t)((1 << (8 - offset)) - 1); uint8_t keepmask = ((uint8_t)-1) - (uint8_t)((1u << (8u - offset)) - 1u);
if ((uint32_t)(8 - offset) > n_bits) { if ((uint32_t)(8 - offset) > n_bits) {
uint8_t bit = (uint8_t)(val << (8u - offset - n_bits)); uint8_t bit = (uint8_t)(val << (8u - offset - n_bits));
*ptr = ((*ptr) & keepmask) + bit; *ptr = ((*ptr) & keepmask) + bit;
@ -154,56 +159,73 @@ SRSASN_CODE bit_ref::pack(uint32_t val, uint32_t n_bits)
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
SRSASN_CODE bit_ref::pack_bytes(const uint8_t* buf, uint32_t n_bytes) template <typename T, typename Ptr>
{ SRSASN_CODE unpack_bits(T& val, Ptr& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits)
if (n_bytes == 0) {
return SRSASN_SUCCESS;
}
if (ptr + n_bytes >= max_ptr) {
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
if (offset == 0) {
// Aligned case
memcpy(ptr, buf, n_bytes);
ptr += n_bytes;
} else {
for (uint32_t i = 0; i < n_bytes; ++i) {
pack(buf[i], 8);
}
}
return SRSASN_SUCCESS;
}
ValOrError unpack_bits(uint8_t*& ptr, uint8_t& offset, uint8_t* max_ptr, uint32_t n_bits)
{ {
if (n_bits > 32) { if (n_bits > sizeof(T) * 8) {
srsasn_log_print(LOG_LEVEL_ERROR, "This method only supports unpacking up to 32 bits\n"); srsasn_log_print(LOG_LEVEL_ERROR, "This method only supports unpacking up to %d bits\n", (int)sizeof(T) * 8);
return {0, SRSASN_ERROR_DECODE_FAIL}; return SRSASN_ERROR_DECODE_FAIL;
} }
uint32_t val = 0; val = 0;
while (n_bits > 0) { while (n_bits > 0) {
if (ptr >= max_ptr) { if (ptr >= max_ptr) {
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n"); srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
return ValOrError(val, SRSASN_ERROR_DECODE_FAIL); return SRSASN_ERROR_DECODE_FAIL;
} }
if ((uint32_t)(8 - offset) > n_bits) { if ((uint32_t)(8 - offset) > n_bits) {
uint8_t mask = (uint8_t)(1u << (8u - offset)) - (uint8_t)(1u << (8u - offset - n_bits)); uint8_t mask = (uint8_t)(1u << (8u - offset)) - (uint8_t)(1u << (8u - offset - n_bits));
val += ((uint32_t)((*ptr) & mask)) >> ((uint8_t)8 - offset - n_bits); val += ((uint32_t)((*ptr) & mask)) >> (8u - offset - n_bits);
offset += n_bits; offset += n_bits;
n_bits = 0; n_bits = 0;
} else { } else {
uint8_t mask = (uint8_t)((1u << (8u - offset)) - 1); uint8_t mask = (uint8_t)((1u << (8u - offset)) - 1u);
val += ((uint32_t)((*ptr) & mask)) << (n_bits - 8 + offset); val += ((uint32_t)((*ptr) & mask)) << (n_bits - 8 + offset);
n_bits -= 8 - offset; n_bits -= 8 - offset;
offset = 0; offset = 0;
ptr++; ptr++;
} }
} }
return ValOrError(val, SRSASN_SUCCESS); return SRSASN_SUCCESS;
} }
SRSASN_CODE bit_ref::unpack_bytes(uint8_t* buf, uint32_t n_bytes) template SRSASN_CODE
unpack_bits<bool, uint8_t*>(bool& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
template SRSASN_CODE unpack_bits<bool, const uint8_t*>(bool& val,
const uint8_t*& ptr,
uint8_t& offset,
const uint8_t* max_ptr,
uint32_t n_bits);
template SRSASN_CODE
unpack_bits<uint8_t, uint8_t*>(uint8_t& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
template SRSASN_CODE unpack_bits<uint8_t, const uint8_t*>(uint8_t& val,
const uint8_t*& ptr,
uint8_t& offset,
const uint8_t* max_ptr,
uint32_t n_bits);
template SRSASN_CODE
unpack_bits<uint16_t, uint8_t*>(uint16_t& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
template SRSASN_CODE unpack_bits<uint16_t, const uint8_t*>(uint16_t& val,
const uint8_t*& ptr,
uint8_t& offset,
const uint8_t* max_ptr,
uint32_t n_bits);
template SRSASN_CODE
unpack_bits<uint32_t, uint8_t*>(uint32_t& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
template SRSASN_CODE unpack_bits<uint32_t, const uint8_t*>(uint32_t& val,
const uint8_t*& ptr,
uint8_t& offset,
const uint8_t* max_ptr,
uint32_t n_bits);
template SRSASN_CODE
unpack_bits<uint64_t, uint8_t*>(uint64_t& val, uint8_t*& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits);
template SRSASN_CODE unpack_bits<uint64_t, const uint8_t*>(uint64_t& val,
const uint8_t*& ptr,
uint8_t& offset,
const uint8_t* max_ptr,
uint32_t n_bits);
template <typename Ptr>
SRSASN_CODE bit_ref_impl<Ptr>::unpack_bytes(uint8_t* buf, uint32_t n_bytes)
{ {
if (n_bytes == 0) { if (n_bytes == 0) {
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
@ -224,7 +246,8 @@ SRSASN_CODE bit_ref::unpack_bytes(uint8_t* buf, uint32_t n_bytes)
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
SRSASN_CODE bit_ref::align_bytes() template <typename Ptr>
SRSASN_CODE bit_ref_impl<Ptr>::align_bytes()
{ {
if (offset == 0) if (offset == 0)
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
@ -237,22 +260,8 @@ SRSASN_CODE bit_ref::align_bytes()
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
SRSASN_CODE bit_ref::align_bytes_zero() template <typename Ptr>
{ SRSASN_CODE bit_ref_impl<Ptr>::advance_bits(uint32_t n_bits)
if (offset == 0)
return SRSASN_SUCCESS;
if (ptr >= max_ptr) {
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
uint8_t mask = (uint8_t)(256u - (1u << (8u - offset)));
*ptr &= mask;
offset = 0;
ptr++;
return SRSASN_SUCCESS;
}
SRSASN_CODE bit_ref::advance_bits(uint32_t n_bits)
{ {
uint32_t extra_bits = (offset + n_bits) % 8; uint32_t extra_bits = (offset + n_bits) % 8;
uint32_t bytes_required = ceilf((offset + n_bits) / 8.0f); uint32_t bytes_required = ceilf((offset + n_bits) / 8.0f);
@ -267,7 +276,8 @@ SRSASN_CODE bit_ref::advance_bits(uint32_t n_bits)
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
void bit_ref::set(uint8_t* start_ptr_, uint32_t max_size_) template <typename Ptr>
void bit_ref_impl<Ptr>::set(Ptr start_ptr_, uint32_t max_size_)
{ {
ptr = start_ptr_; ptr = start_ptr_;
offset = 0; offset = 0;
@ -275,6 +285,45 @@ void bit_ref::set(uint8_t* start_ptr_, uint32_t max_size_)
max_ptr = max_size_ + start_ptr_; max_ptr = max_size_ + start_ptr_;
} }
template class asn1::bit_ref_impl<uint8_t*>;
template class asn1::bit_ref_impl<const uint8_t*>;
SRSASN_CODE bit_ref::pack_bytes(const uint8_t* buf, uint32_t n_bytes)
{
if (n_bytes == 0) {
return SRSASN_SUCCESS;
}
if (ptr + n_bytes >= max_ptr) {
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
if (offset == 0) {
// Aligned case
memcpy(ptr, buf, n_bytes);
ptr += n_bytes;
} else {
for (uint32_t i = 0; i < n_bytes; ++i) {
pack(buf[i], 8);
}
}
return SRSASN_SUCCESS;
}
SRSASN_CODE bit_ref::align_bytes_zero()
{
if (offset == 0)
return SRSASN_SUCCESS;
if (ptr >= max_ptr) {
srsasn_log_print(LOG_LEVEL_ERROR, "Buffer size limit was achieved\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
uint8_t mask = (uint8_t)(256u - (1u << (8u - offset)));
*ptr &= mask;
offset = 0;
ptr++;
return SRSASN_SUCCESS;
}
/********************* /*********************
ext packing ext packing
*********************/ *********************/
@ -343,7 +392,7 @@ SRSASN_CODE pack_enum(bit_ref& bref, uint32_t e, uint32_t nof_types, uint32_t no
return ret; return ret;
} }
ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, bit_ref& bref) ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, cbit_ref& bref)
{ {
ValOrError ret; ValOrError ret;
if (has_ext) { if (has_ext) {
@ -457,7 +506,7 @@ pack_constrained_whole_number<uint64_t>(bit_ref& bref, uint64_t n, uint64_t lb,
* @return success or failure * @return success or failure
*/ */
template <class IntType> template <class IntType>
SRSASN_CODE unpack_constrained_whole_number(IntType& n, bit_ref& bref, IntType lb, IntType ub, bool aligned) SRSASN_CODE unpack_constrained_whole_number(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool aligned)
{ {
if (ub < lb) { if (ub < lb) {
srsasn_log_print(LOG_LEVEL_ERROR, "The condition lb <= ub (%ld <= %ld) was not met\n", (long)lb, (long)ub); srsasn_log_print(LOG_LEVEL_ERROR, "The condition lb <= ub (%ld <= %ld) was not met\n", (long)lb, (long)ub);
@ -504,21 +553,21 @@ SRSASN_CODE unpack_constrained_whole_number(IntType& n, bit_ref& bref, IntType l
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
template SRSASN_CODE template SRSASN_CODE
unpack_constrained_whole_number<int8_t>(int8_t& n, bit_ref& bref, int8_t lb, int8_t ub, bool aligned); unpack_constrained_whole_number<int8_t>(int8_t& n, cbit_ref& bref, int8_t lb, int8_t ub, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_constrained_whole_number<int16_t>(int16_t& n, bit_ref& bref, int16_t lb, int16_t ub, bool aligned); unpack_constrained_whole_number<int16_t>(int16_t& n, cbit_ref& bref, int16_t lb, int16_t ub, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_constrained_whole_number<int32_t>(int32_t& n, bit_ref& bref, int32_t lb, int32_t ub, bool aligned); unpack_constrained_whole_number<int32_t>(int32_t& n, cbit_ref& bref, int32_t lb, int32_t ub, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_constrained_whole_number<int64_t>(int64_t& n, bit_ref& bref, int64_t lb, int64_t ub, bool aligned); unpack_constrained_whole_number<int64_t>(int64_t& n, cbit_ref& bref, int64_t lb, int64_t ub, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_constrained_whole_number<uint8_t>(uint8_t& n, bit_ref& bref, uint8_t lb, uint8_t ub, bool aligned); unpack_constrained_whole_number<uint8_t>(uint8_t& n, cbit_ref& bref, uint8_t lb, uint8_t ub, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_constrained_whole_number<uint16_t>(uint16_t& n, bit_ref& bref, uint16_t lb, uint16_t ub, bool aligned); unpack_constrained_whole_number<uint16_t>(uint16_t& n, cbit_ref& bref, uint16_t lb, uint16_t ub, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_constrained_whole_number<uint32_t>(uint32_t& n, bit_ref& bref, uint32_t lb, uint32_t ub, bool aligned); unpack_constrained_whole_number<uint32_t>(uint32_t& n, cbit_ref& bref, uint32_t lb, uint32_t ub, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_constrained_whole_number<uint64_t>(uint64_t& n, bit_ref& bref, uint64_t lb, uint64_t ub, bool aligned); unpack_constrained_whole_number<uint64_t>(uint64_t& n, cbit_ref& bref, uint64_t lb, uint64_t ub, bool aligned);
/** /**
* X.691 - Section 10.6 * X.691 - Section 10.6
@ -541,7 +590,7 @@ SRSASN_CODE pack_norm_small_non_neg_whole_number(bit_ref& bref, UintType n)
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
template <typename UintType> template <typename UintType>
SRSASN_CODE unpack_norm_small_non_neg_whole_number(UintType& n, bit_ref& bref) SRSASN_CODE unpack_norm_small_non_neg_whole_number(UintType& n, cbit_ref& bref)
{ {
bool ext; bool ext;
SRSASN_CODE ret = bref.unpack(ext, 1); SRSASN_CODE ret = bref.unpack(ext, 1);
@ -558,10 +607,10 @@ template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint8_t>(bit_ref& bref
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint16_t>(bit_ref& bref, uint16_t n); template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint16_t>(bit_ref& bref, uint16_t n);
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint32_t>(bit_ref& bref, uint32_t n); template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint32_t>(bit_ref& bref, uint32_t n);
template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint64_t>(bit_ref& bref, uint64_t n); template SRSASN_CODE pack_norm_small_non_neg_whole_number<uint64_t>(bit_ref& bref, uint64_t n);
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint8_t>(uint8_t& n, bit_ref& bref); template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint8_t>(uint8_t& n, cbit_ref& bref);
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint16_t>(uint16_t& n, bit_ref& bref); template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint16_t>(uint16_t& n, cbit_ref& bref);
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint32_t>(uint32_t& n, bit_ref& bref); template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint32_t>(uint32_t& n, cbit_ref& bref);
template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint64_t>(uint64_t& n, bit_ref& bref); template SRSASN_CODE unpack_norm_small_non_neg_whole_number<uint64_t>(uint64_t& n, cbit_ref& bref);
template <typename IntType> template <typename IntType>
IntType unconstrained_whole_number_length(IntType n) IntType unconstrained_whole_number_length(IntType n)
@ -590,7 +639,7 @@ SRSASN_CODE pack_unconstrained_whole_number(bit_ref& bref, IntType n, bool align
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
template <typename IntType> template <typename IntType>
SRSASN_CODE unpack_unconstrained_whole_number(IntType& n, bit_ref& bref, bool aligned) SRSASN_CODE unpack_unconstrained_whole_number(IntType& n, cbit_ref& bref, bool aligned)
{ {
// TODO: Test // TODO: Test
uint32_t len; uint32_t len;
@ -606,18 +655,18 @@ template SRSASN_CODE pack_unconstrained_whole_number<int8_t>(bit_ref& bref, int8
template SRSASN_CODE pack_unconstrained_whole_number<int16_t>(bit_ref& bref, int16_t n, bool aligned); template SRSASN_CODE pack_unconstrained_whole_number<int16_t>(bit_ref& bref, int16_t n, bool aligned);
template SRSASN_CODE pack_unconstrained_whole_number<int32_t>(bit_ref& bref, int32_t n, bool aligned); template SRSASN_CODE pack_unconstrained_whole_number<int32_t>(bit_ref& bref, int32_t n, bool aligned);
template SRSASN_CODE pack_unconstrained_whole_number<int64_t>(bit_ref& bref, int64_t n, bool aligned); template SRSASN_CODE pack_unconstrained_whole_number<int64_t>(bit_ref& bref, int64_t n, bool aligned);
template SRSASN_CODE unpack_unconstrained_whole_number<int8_t>(int8_t& n, bit_ref& bref, bool aligned); template SRSASN_CODE unpack_unconstrained_whole_number<int8_t>(int8_t& n, cbit_ref& bref, bool aligned);
template SRSASN_CODE unpack_unconstrained_whole_number<int16_t>(int16_t& n, bit_ref& bref, bool aligned); template SRSASN_CODE unpack_unconstrained_whole_number<int16_t>(int16_t& n, cbit_ref& bref, bool aligned);
template SRSASN_CODE unpack_unconstrained_whole_number<int32_t>(int32_t& n, bit_ref& bref, bool aligned); template SRSASN_CODE unpack_unconstrained_whole_number<int32_t>(int32_t& n, cbit_ref& bref, bool aligned);
template SRSASN_CODE unpack_unconstrained_whole_number<int64_t>(int64_t& n, bit_ref& bref, bool aligned); template SRSASN_CODE unpack_unconstrained_whole_number<int64_t>(int64_t& n, cbit_ref& bref, bool aligned);
template SRSASN_CODE pack_unconstrained_whole_number<uint8_t>(bit_ref& bref, uint8_t n, bool aligned); template SRSASN_CODE pack_unconstrained_whole_number<uint8_t>(bit_ref& bref, uint8_t n, bool aligned);
template SRSASN_CODE pack_unconstrained_whole_number<uint16_t>(bit_ref& bref, uint16_t n, bool aligned); template SRSASN_CODE pack_unconstrained_whole_number<uint16_t>(bit_ref& bref, uint16_t n, bool aligned);
template SRSASN_CODE pack_unconstrained_whole_number<uint32_t>(bit_ref& bref, uint32_t n, bool aligned); template SRSASN_CODE pack_unconstrained_whole_number<uint32_t>(bit_ref& bref, uint32_t n, bool aligned);
template SRSASN_CODE pack_unconstrained_whole_number<uint64_t>(bit_ref& bref, uint64_t n, bool aligned); template SRSASN_CODE pack_unconstrained_whole_number<uint64_t>(bit_ref& bref, uint64_t n, bool aligned);
template SRSASN_CODE unpack_unconstrained_whole_number<uint8_t>(uint8_t& n, bit_ref& bref, bool aligned); template SRSASN_CODE unpack_unconstrained_whole_number<uint8_t>(uint8_t& n, cbit_ref& bref, bool aligned);
template SRSASN_CODE unpack_unconstrained_whole_number<uint16_t>(uint16_t& n, bit_ref& bref, bool aligned); template SRSASN_CODE unpack_unconstrained_whole_number<uint16_t>(uint16_t& n, cbit_ref& bref, bool aligned);
template SRSASN_CODE unpack_unconstrained_whole_number<uint32_t>(uint32_t& n, bit_ref& bref, bool aligned); template SRSASN_CODE unpack_unconstrained_whole_number<uint32_t>(uint32_t& n, cbit_ref& bref, bool aligned);
template SRSASN_CODE unpack_unconstrained_whole_number<uint64_t>(uint64_t& n, bit_ref& bref, bool aligned); template SRSASN_CODE unpack_unconstrained_whole_number<uint64_t>(uint64_t& n, cbit_ref& bref, bool aligned);
/********************* /*********************
varlength_packing varlength_packing
@ -638,18 +687,18 @@ template SRSASN_CODE pack_length<int32_t>(bit_ref& bref, int32_t n, int32_t lb,
template SRSASN_CODE pack_length<int64_t>(bit_ref& bref, int64_t n, int64_t lb, int64_t ub, bool aligned); template SRSASN_CODE pack_length<int64_t>(bit_ref& bref, int64_t n, int64_t lb, int64_t ub, bool aligned);
template <typename IntType> template <typename IntType>
SRSASN_CODE unpack_length(IntType& n, bit_ref& bref, IntType lb, IntType ub, bool aligned) SRSASN_CODE unpack_length(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool aligned)
{ {
return unpack_constrained_whole_number(n, bref, lb, ub, aligned); return unpack_constrained_whole_number(n, bref, lb, ub, aligned);
} }
template SRSASN_CODE unpack_length<uint8_t>(uint8_t& n, bit_ref& bref, uint8_t lb, uint8_t ub, bool aligned); template SRSASN_CODE unpack_length<uint8_t>(uint8_t& n, cbit_ref& bref, uint8_t lb, uint8_t ub, bool aligned);
template SRSASN_CODE unpack_length<uint16_t>(uint16_t& n, bit_ref& bref, uint16_t lb, uint16_t ub, bool aligned); template SRSASN_CODE unpack_length<uint16_t>(uint16_t& n, cbit_ref& bref, uint16_t lb, uint16_t ub, bool aligned);
template SRSASN_CODE unpack_length<uint32_t>(uint32_t& n, bit_ref& bref, uint32_t lb, uint32_t ub, bool aligned); template SRSASN_CODE unpack_length<uint32_t>(uint32_t& n, cbit_ref& bref, uint32_t lb, uint32_t ub, bool aligned);
template SRSASN_CODE unpack_length<uint64_t>(uint64_t& n, bit_ref& bref, uint64_t lb, uint64_t ub, bool aligned); template SRSASN_CODE unpack_length<uint64_t>(uint64_t& n, cbit_ref& bref, uint64_t lb, uint64_t ub, bool aligned);
template SRSASN_CODE unpack_length<int8_t>(int8_t& n, bit_ref& bref, int8_t lb, int8_t ub, bool aligned); template SRSASN_CODE unpack_length<int8_t>(int8_t& n, cbit_ref& bref, int8_t lb, int8_t ub, bool aligned);
template SRSASN_CODE unpack_length<int16_t>(int16_t& n, bit_ref& bref, int16_t lb, int16_t ub, bool aligned); template SRSASN_CODE unpack_length<int16_t>(int16_t& n, cbit_ref& bref, int16_t lb, int16_t ub, bool aligned);
template SRSASN_CODE unpack_length<int32_t>(int32_t& n, bit_ref& bref, int32_t lb, int32_t ub, bool aligned); template SRSASN_CODE unpack_length<int32_t>(int32_t& n, cbit_ref& bref, int32_t lb, int32_t ub, bool aligned);
template SRSASN_CODE unpack_length<int64_t>(int64_t& n, bit_ref& bref, int64_t lb, int64_t ub, bool aligned); template SRSASN_CODE unpack_length<int64_t>(int64_t& n, cbit_ref& bref, int64_t lb, int64_t ub, bool aligned);
/** /**
* X.691 - Section 10.9 * X.691 - Section 10.9
@ -693,7 +742,7 @@ SRSASN_CODE pack_length(bit_ref& bref, uint32_t val, bool aligned)
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
SRSASN_CODE unpack_length(uint32_t& val, bit_ref& bref, bool aligned) SRSASN_CODE unpack_length(uint32_t& val, cbit_ref& bref, bool aligned)
{ {
bool ext; bool ext;
if (not aligned) { if (not aligned) {
@ -803,7 +852,7 @@ template SRSASN_CODE pack_unconstrained_integer<int32_t>(bit_ref& bref, int32_t
template SRSASN_CODE pack_unconstrained_integer<int64_t>(bit_ref& bref, int64_t n, bool has_ext, bool aligned); template SRSASN_CODE pack_unconstrained_integer<int64_t>(bit_ref& bref, int64_t n, bool has_ext, bool aligned);
template <typename IntType> template <typename IntType>
SRSASN_CODE unpack_integer(IntType& n, bit_ref& bref, IntType lb, IntType ub, bool has_ext, bool aligned) SRSASN_CODE unpack_integer(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool has_ext, bool aligned)
{ {
bool within_bounds = true; bool within_bounds = true;
if (has_ext) { if (has_ext) {
@ -833,32 +882,33 @@ SRSASN_CODE unpack_integer(IntType& n, bit_ref& bref, IntType lb, IntType ub, bo
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
template SRSASN_CODE template SRSASN_CODE
unpack_integer<uint8_t>(uint8_t& n, bit_ref& bref, uint8_t lb, uint8_t ub, bool has_ext, bool aligned); unpack_integer<uint8_t>(uint8_t& n, cbit_ref& bref, uint8_t lb, uint8_t ub, bool has_ext, bool aligned);
template SRSASN_CODE
unpack_integer<uint16_t>(uint16_t& n, cbit_ref& bref, uint16_t lb, uint16_t ub, bool has_ext, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_integer<uint16_t>(uint16_t& n, bit_ref& bref, uint16_t lb, uint16_t ub, bool has_ext, bool aligned); unpack_integer<uint32_t>(uint32_t& n, cbit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_integer<uint32_t>(uint32_t& n, bit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool aligned); unpack_integer<uint64_t>(uint64_t& n, cbit_ref& bref, uint64_t lb, uint64_t ub, bool has_ext, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_integer<uint64_t>(uint64_t& n, bit_ref& bref, uint64_t lb, uint64_t ub, bool has_ext, bool aligned); unpack_integer<int8_t>(int8_t& n, cbit_ref& bref, int8_t lb, int8_t ub, bool has_ext, bool aligned);
template SRSASN_CODE unpack_integer<int8_t>(int8_t& n, bit_ref& bref, int8_t lb, int8_t ub, bool has_ext, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_integer<int16_t>(int16_t& n, bit_ref& bref, int16_t lb, int16_t ub, bool has_ext, bool aligned); unpack_integer<int16_t>(int16_t& n, cbit_ref& bref, int16_t lb, int16_t ub, bool has_ext, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_integer<int32_t>(int32_t& n, bit_ref& bref, int32_t lb, int32_t ub, bool has_ext, bool aligned); unpack_integer<int32_t>(int32_t& n, cbit_ref& bref, int32_t lb, int32_t ub, bool has_ext, bool aligned);
template SRSASN_CODE template SRSASN_CODE
unpack_integer<int64_t>(int64_t& n, bit_ref& bref, int64_t lb, int64_t ub, bool has_ext, bool aligned); unpack_integer<int64_t>(int64_t& n, cbit_ref& bref, int64_t lb, int64_t ub, bool has_ext, bool aligned);
// unconstrained specialization case // unconstrained specialization case
template <typename IntType> template <typename IntType>
SRSASN_CODE unpack_unconstrained_integer(IntType& n, bit_ref& bref, bool has_ext, bool aligned) SRSASN_CODE unpack_unconstrained_integer(IntType& n, cbit_ref& bref, bool has_ext, bool aligned)
{ {
return unpack_integer( return unpack_integer(
n, bref, std::numeric_limits<IntType>::min(), std::numeric_limits<IntType>::max(), has_ext, aligned); n, bref, std::numeric_limits<IntType>::min(), std::numeric_limits<IntType>::max(), has_ext, aligned);
} }
template SRSASN_CODE unpack_unconstrained_integer<int8_t>(int8_t& n, bit_ref& bref, bool has_ext, bool aligned); template SRSASN_CODE unpack_unconstrained_integer<int8_t>(int8_t& n, cbit_ref& bref, bool has_ext, bool aligned);
template SRSASN_CODE unpack_unconstrained_integer<int16_t>(int16_t& n, bit_ref& bref, bool has_ext, bool aligned); template SRSASN_CODE unpack_unconstrained_integer<int16_t>(int16_t& n, cbit_ref& bref, bool has_ext, bool aligned);
template SRSASN_CODE unpack_unconstrained_integer<int32_t>(int32_t& n, bit_ref& bref, bool has_ext, bool aligned); template SRSASN_CODE unpack_unconstrained_integer<int32_t>(int32_t& n, cbit_ref& bref, bool has_ext, bool aligned);
template SRSASN_CODE unpack_unconstrained_integer<int64_t>(int64_t& n, bit_ref& bref, bool has_ext, bool aligned); template SRSASN_CODE unpack_unconstrained_integer<int64_t>(int64_t& n, cbit_ref& bref, bool has_ext, bool aligned);
// standalone packer // standalone packer
template <class IntType> template <class IntType>
@ -876,7 +926,7 @@ SRSASN_CODE integer_packer<IntType>::pack(bit_ref& bref, IntType n)
return pack_integer(bref, n, lb, ub, has_ext, aligned); return pack_integer(bref, n, lb, ub, has_ext, aligned);
} }
template <class IntType> template <class IntType>
SRSASN_CODE integer_packer<IntType>::unpack(IntType& n, bit_ref& bref) SRSASN_CODE integer_packer<IntType>::unpack(IntType& n, cbit_ref& bref)
{ {
return unpack_integer(n, bref, lb, ub, has_ext, aligned); return unpack_integer(n, bref, lb, ub, has_ext, aligned);
} }
@ -962,7 +1012,7 @@ SRSASN_CODE unbounded_octstring<Al>::pack(bit_ref& bref) const
} }
template <bool Al> template <bool Al>
SRSASN_CODE unbounded_octstring<Al>::unpack(bit_ref& bref) SRSASN_CODE unbounded_octstring<Al>::unpack(cbit_ref& bref)
{ {
uint32_t len; uint32_t len;
HANDLE_CODE(unpack_length(len, bref, aligned)); HANDLE_CODE(unpack_length(len, bref, aligned));
@ -1070,7 +1120,7 @@ pack(bit_ref& bref, const uint8_t* data, uint32_t len, uint32_t lb, uint32_t ub,
/** /**
* Unpack ASN1 bitstring length prefix. Accommodates for cases: fixed/unbounded/bounded, aligned/unaligned, with/out ext * Unpack ASN1 bitstring length prefix. Accommodates for cases: fixed/unbounded/bounded, aligned/unaligned, with/out ext
*/ */
SRSASN_CODE unpack_length_prefix(uint32_t& len, bit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool is_aligned) SRSASN_CODE unpack_length_prefix(uint32_t& len, cbit_ref& bref, uint32_t lb, uint32_t ub, bool has_ext, bool is_aligned)
{ {
bool ext = false; bool ext = false;
if (has_ext) { if (has_ext) {
@ -1100,7 +1150,7 @@ SRSASN_CODE unpack_length_prefix(uint32_t& len, bit_ref& bref, uint32_t lb, uint
} }
// for both fixed, constrained and unconstrained scenarios // for both fixed, constrained and unconstrained scenarios
SRSASN_CODE unpack_bitfield(uint8_t* buf, bit_ref& bref, uint32_t n, uint32_t lb, uint32_t ub, bool is_aligned) SRSASN_CODE unpack_bitfield(uint8_t* buf, cbit_ref& bref, uint32_t n, uint32_t lb, uint32_t ub, bool is_aligned)
{ {
if (n > ASN_64K) { if (n > ASN_64K) {
srsasn_log_print(LOG_LEVEL_ERROR, "bitstrings longer than 64K not supported\n"); srsasn_log_print(LOG_LEVEL_ERROR, "bitstrings longer than 64K not supported\n");
@ -1235,7 +1285,7 @@ pack(bit_ref& bref, const std::string& s, size_t lb, size_t ub, size_t alb, size
return SRSASN_SUCCESS; return SRSASN_SUCCESS;
} }
SRSASN_CODE unpack(std::string& s, bit_ref& bref, size_t lb, size_t ub, size_t alb, size_t aub, bool ext, bool aligned) SRSASN_CODE unpack(std::string& s, cbit_ref& bref, size_t lb, size_t ub, size_t alb, size_t aub, bool ext, bool aligned)
{ {
size_t b = asn_string_utils::get_nof_bits_per_char(lb, ub, aligned); size_t b = asn_string_utils::get_nof_bits_per_char(lb, ub, aligned);
bool octet_aligned = asn_string_utils::is_octet_aligned(b, alb, aub, aligned); bool octet_aligned = asn_string_utils::is_octet_aligned(b, alb, aub, aligned);
@ -1258,7 +1308,7 @@ SRSASN_CODE unpack(std::string& s, bit_ref& bref, size_t lb, size_t ub, size_t a
s.resize(n); s.resize(n);
} }
if (octet_aligned) { if (octet_aligned) {
bref.align_bytes_zero(); bref.align_bytes();
} }
for (uint32_t i = 0; i < s.size(); ++i) { for (uint32_t i = 0; i < s.size(); ++i) {
HANDLE_CODE(bref.unpack(s[i], b)); HANDLE_CODE(bref.unpack(s[i], b));
@ -1334,7 +1384,7 @@ ext_groups_unpacker_guard::~ext_groups_unpacker_guard()
} }
} }
SRSASN_CODE ext_groups_unpacker_guard::unpack(bit_ref& bref) SRSASN_CODE ext_groups_unpacker_guard::unpack(cbit_ref& bref)
{ {
bref_tracker = &bref; bref_tracker = &bref;
// unpack nof of ext groups // unpack nof of ext groups
@ -1387,7 +1437,7 @@ varlength_field_pack_guard::~varlength_field_pack_guard()
*bref_tracker = brefstart; *bref_tracker = brefstart;
} }
varlength_field_unpack_guard::varlength_field_unpack_guard(bit_ref& bref, bool align) varlength_field_unpack_guard::varlength_field_unpack_guard(cbit_ref& bref, bool align)
{ {
unpack_length(len, bref, align); unpack_length(len, bref, align);
bref0 = bref; bref0 = bref;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -31,8 +31,8 @@ srslte::log_filter ngap_log("NGAP");
int test_amf_upd() int test_amf_upd()
{ {
uint8_t ngap_msg[] = {0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x11}; uint8_t ngap_msg[] = {0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x11};
bit_ref bref(&ngap_msg[0], sizeof(ngap_msg)); cbit_ref bref(&ngap_msg[0], sizeof(ngap_msg));
// 0000000A00000100010003000011 // 0000000A00000100010003000011
ngap_pdu_c pdu; ngap_pdu_c pdu;
@ -70,7 +70,7 @@ int test_ngsetup_request()
0x00, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x15, 0x40, 0x01, 0x60}; 0x00, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x15, 0x40, 0x01, 0x60};
// 00150030000004001b00090000f1105000000001005240060180676e62310066000d00000000750000f110000000080015400160 // 00150030000004001b00090000f1105000000001005240060180676e62310066000d00000000750000f110000000080015400160
bit_ref bref(ngap_msg, sizeof(ngap_msg)); cbit_ref bref(ngap_msg, sizeof(ngap_msg));
ngap_pdu_c pdu; ngap_pdu_c pdu;
TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS);
@ -127,7 +127,7 @@ int test_ngsetup_response()
0x01, 0x05, 0x00, 0x50, 0x00, 0x08, 0x00, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x00, 0x08}; 0x01, 0x05, 0x00, 0x50, 0x00, 0x08, 0x00, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x00, 0x08};
// 2015005e0000040001003a1b80616d66312e636c7573746572312e6e6574322e616d662e3567632e6d6e633030312e6d63633030312e336770706e6574776f726b2e6f726700600008000000f1103808970056400105005000080000f11000000008 // 2015005e0000040001003a1b80616d66312e636c7573746572312e6e6574322e616d662e3567632e6d6e633030312e6d63633030312e336770706e6574776f726b2e6f726700600008000000f1103808970056400105005000080000f11000000008
bit_ref bref(ngap_msg, sizeof(ngap_msg)); cbit_ref bref(ngap_msg, sizeof(ngap_msg));
ngap_pdu_c pdu; ngap_pdu_c pdu;
TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS);
@ -174,7 +174,7 @@ int test_init_ue_msg()
0x00, 0x00, 0x00, 0x10, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x75, 0x00, 0x5a, 0x40, 0x01, 0x18}; 0x00, 0x00, 0x00, 0x10, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x75, 0x00, 0x5a, 0x40, 0x01, 0x18};
// 000f4080a20000040055000200010026007d7c7e00417100760100f110000001014d436f77425159444b325675417945416e363648396b7a485461465a4b30353741497237412b6e6c736149587852334e6973364c566f75466942343ddfabf5cd652eb2541491484d41432d53484100858bbb1f42f1256f9a37531a772a2cf2b78ff160488402ed489399b6b737420079000f4000f110000000001000f110000075005a400118 // 000f4080a20000040055000200010026007d7c7e00417100760100f110000001014d436f77425159444b325675417945416e363648396b7a485461465a4b30353741497237412b6e6c736149587852334e6973364c566f75466942343ddfabf5cd652eb2541491484d41432d53484100858bbb1f42f1256f9a37531a772a2cf2b78ff160488402ed489399b6b737420079000f4000f110000000001000f110000075005a400118
bit_ref bref(ngap_msg, sizeof(ngap_msg)); cbit_ref bref(ngap_msg, sizeof(ngap_msg));
ngap_pdu_c pdu; ngap_pdu_c pdu;
TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS);
@ -209,7 +209,7 @@ int test_dl_nas_transport()
0xe2, 0x82, 0x84, 0x7c, 0x9f, 0x4c, 0xe5, 0xc1, 0x94, 0x51}; 0xe2, 0x82, 0x84, 0x7c, 0x9f, 0x4c, 0xe5, 0xc1, 0x94, 0x51};
// 0004403e000003000a000200010055000200010026002b2a7e00560002000021681cd489650fdcc7c70eca8fa9be44702010c7f0791fa852e282847c9f4ce5c19451 // 0004403e000003000a000200010055000200010026002b2a7e00560002000021681cd489650fdcc7c70eca8fa9be44702010c7f0791fa852e282847c9f4ce5c19451
bit_ref bref(ngap_msg, sizeof(ngap_msg)); cbit_ref bref(ngap_msg, sizeof(ngap_msg));
ngap_pdu_c pdu; ngap_pdu_c pdu;
TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS);
@ -237,7 +237,7 @@ int test_ul_ran_status_transfer()
0x0f, 0x40, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x75}; 0x0f, 0x40, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x75};
// 002e403c000004000a0002000100550002000100260016157e00572d105e86219e7dda9995e3850384cfbea53b0079400f4000f110000000001000f110000075 // 002e403c000004000a0002000100550002000100260016157e00572d105e86219e7dda9995e3850384cfbea53b0079400f4000f110000000001000f110000075
bit_ref bref(ngap_msg, sizeof(ngap_msg)); cbit_ref bref(ngap_msg, sizeof(ngap_msg));
ngap_pdu_c pdu; ngap_pdu_c pdu;
TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS);
@ -261,7 +261,7 @@ int test_ue_context_release()
0x04, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0f, 0x40, 0x01, 0x48}; 0x04, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0f, 0x40, 0x01, 0x48};
// 002900100000020072000400010001000f400148 // 002900100000020072000400010001000f400148
bit_ref bref(ngap_msg, sizeof(ngap_msg)); cbit_ref bref(ngap_msg, sizeof(ngap_msg));
ngap_pdu_c pdu; ngap_pdu_c pdu;
TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS);
@ -282,7 +282,7 @@ int test_ue_context_release_complete()
0x20, 0x29, 0x00, 0x0f, 0x00, 0x00, 0x02, 0x00, 0x0a, 0x40, 0x02, 0x00, 0x01, 0x00, 0x55, 0x40, 0x02, 0x00, 0x01}; 0x20, 0x29, 0x00, 0x0f, 0x00, 0x00, 0x02, 0x00, 0x0a, 0x40, 0x02, 0x00, 0x01, 0x00, 0x55, 0x40, 0x02, 0x00, 0x01};
// 2029000f000002000a40020001005540020001 // 2029000f000002000a40020001005540020001
bit_ref bref(ngap_msg, sizeof(ngap_msg)); cbit_ref bref(ngap_msg, sizeof(ngap_msg));
ngap_pdu_c pdu; ngap_pdu_c pdu;
TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS);
@ -309,7 +309,7 @@ int test_session_res_setup_request()
0x00, 0x86, 0x00, 0x01, 0x10, 0x00, 0x88, 0x00, 0x07, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00}; 0x00, 0x86, 0x00, 0x01, 0x10, 0x00, 0x88, 0x00, 0x07, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00};
// 001d006c000004000a000200010055000200010026002e2d7e00680100252e0100c2110006010003300101060603e80603e8290501c0a80c7b25080764656661756c741201004a0027000001000021000003008b000a01f0c0a811d20000000100860001100088000700010000090000 // 001d006c000004000a000200010055000200010026002e2d7e00680100252e0100c2110006010003300101060603e80603e8290501c0a80c7b25080764656661756c741201004a0027000001000021000003008b000a01f0c0a811d20000000100860001100088000700010000090000
bit_ref bref(ngap_msg, sizeof(ngap_msg)); cbit_ref bref(ngap_msg, sizeof(ngap_msg));
ngap_pdu_c pdu; ngap_pdu_c pdu;
TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(pdu.unpack(bref) == SRSASN_SUCCESS);
@ -328,7 +328,8 @@ int test_session_res_setup_request()
TESTASSERT(item.pdu_session_res_setup_request_transfer.to_string() == TESTASSERT(item.pdu_session_res_setup_request_transfer.to_string() ==
"000003008b000a01f0c0a811d20000000100860001100088000700010000090000"); "000003008b000a01f0c0a811d20000000100860001100088000700010000090000");
bit_ref bref2(item.pdu_session_res_setup_request_transfer.data(), item.pdu_session_res_setup_request_transfer.size()); cbit_ref bref2(item.pdu_session_res_setup_request_transfer.data(),
item.pdu_session_res_setup_request_transfer.size());
pdu_session_res_setup_request_transfer_s req; pdu_session_res_setup_request_transfer_s req;
TESTASSERT(req.unpack(bref2) == SRSASN_SUCCESS); TESTASSERT(req.unpack(bref2) == SRSASN_SUCCESS);
TESTASSERT(req.protocol_ies.ul_ngu_up_tnl_info.id == 139); TESTASSERT(req.protocol_ies.ul_ngu_up_tnl_info.id == 139);

@ -100,8 +100,8 @@ int test_mib_msg()
{ {
uint8_t rrc_msg[] = {0x94, 0x64, 0xC0}; uint8_t rrc_msg[] = {0x94, 0x64, 0xC0};
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bit_ref bref0(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref0(&rrc_msg[0], sizeof(rrc_msg));
bcch_bch_msg_s bcch_bch_msg; bcch_bch_msg_s bcch_bch_msg;
bcch_bch_msg.unpack(bref); bcch_bch_msg.unpack(bref);
@ -139,8 +139,8 @@ int test_bcch_dl_sch_msg()
uint8_t rrc_msg[] = {0x00, 0x01, 0x49, 0x00, 0x12, 0x50, 0x40, 0x08, 0x00, 0x09, 0x40, 0x00, 0xA0, uint8_t rrc_msg[] = {0x00, 0x01, 0x49, 0x00, 0x12, 0x50, 0x40, 0x08, 0x00, 0x09, 0x40, 0x00, 0xA0,
0x3F, 0x01, 0x00, 0x0A, 0x7F, 0xC9, 0x80, 0x01, 0x04, 0x28, 0x6C, 0x00, 0x0C}; 0x3F, 0x01, 0x00, 0x0A, 0x7F, 0xC9, 0x80, 0x01, 0x04, 0x28, 0x6C, 0x00, 0x0C};
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bit_ref bref0(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref0(&rrc_msg[0], sizeof(rrc_msg));
bcch_dl_sch_msg_s bcch_msg; bcch_dl_sch_msg_s bcch_msg;
bcch_msg.unpack(bref); bcch_msg.unpack(bref);
@ -217,8 +217,8 @@ int test_bcch_dl_sch_msg2()
// 406404e100070019b018c06010A940 // 406404e100070019b018c06010A940
uint8_t rrc_msg[] = {0x40, 0x64, 0x04, 0xe1, 0x00, 0x07, 0x00, 0x19, 0xb0, 0x18, 0xc0, 0x60, 0x10, 0xA9, 0x40}; uint8_t rrc_msg[] = {0x40, 0x64, 0x04, 0xe1, 0x00, 0x07, 0x00, 0x19, 0xb0, 0x18, 0xc0, 0x60, 0x10, 0xA9, 0x40};
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bit_ref bref0(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref0(&rrc_msg[0], sizeof(rrc_msg));
bcch_dl_sch_msg_s bcch_msg; bcch_dl_sch_msg_s bcch_msg;
bcch_msg.unpack(bref); bcch_msg.unpack(bref);
@ -252,7 +252,7 @@ int test_bcch_dl_sch_msg3()
0x00, 0x05, 0x00, 0x20, 0x5D, 0x6A, 0xAA, 0xF0, 0x42, 0x00, 0xC0, 0x1D, 0xDC, 0x00, 0x05, 0x00, 0x20, 0x5D, 0x6A, 0xAA, 0xF0, 0x42, 0x00, 0xC0, 0x1D, 0xDC,
0x80, 0x1C, 0x48, 0x80, 0x03, 0x00, 0x10, 0xA7, 0x13, 0x22, 0x85, 0x00}; 0x80, 0x1C, 0x48, 0x80, 0x03, 0x00, 0x10, 0xA7, 0x13, 0x22, 0x85, 0x00};
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bcch_dl_sch_msg_s bcch_msg; bcch_dl_sch_msg_s bcch_msg;
bcch_msg.unpack(bref); bcch_msg.unpack(bref);
@ -265,15 +265,15 @@ int test_bcch_dl_sch_msg3()
bit_ref bref2(&rrc_msg2[0], sizeof(rrc_msg2)); bit_ref bref2(&rrc_msg2[0], sizeof(rrc_msg2));
bcch_msg.pack(bref2); bcch_msg.pack(bref2);
bref = bit_ref(&rrc_msg2[0], sizeof(rrc_msg2)); bref = cbit_ref(&rrc_msg2[0], sizeof(rrc_msg2));
bcch_msg.unpack(bref); bcch_msg.unpack(bref);
TESTASSERT(bref.distance(rrc_msg2) == bref2.distance(rrc_msg2)); TESTASSERT(bref.distance(rrc_msg2) == bref2.distance(rrc_msg2));
bref = bit_ref(&rrc_msg[0], sizeof(rrc_msg)); bit_ref bref3(&rrc_msg[0], sizeof(rrc_msg));
bcch_msg.pack(bref); bcch_msg.pack(bref3);
TESTASSERT(bref.distance(rrc_msg) == bref2.distance(rrc_msg2)); TESTASSERT(bref3.distance(rrc_msg) == bref2.distance(rrc_msg2));
TESTASSERT(memcmp(rrc_msg2, rrc_msg, bref.distance_bytes(rrc_msg)) == 0); TESTASSERT(memcmp(rrc_msg2, rrc_msg, bref3.distance_bytes(rrc_msg)) == 0);
TESTASSERT(test_pack_unpack_consistency(bcch_msg) == SRSASN_SUCCESS); TESTASSERT(test_pack_unpack_consistency(bcch_msg) == SRSASN_SUCCESS);
@ -285,8 +285,8 @@ int test_dl_dcch_msg()
// 20021008000C406000 // 20021008000C406000
uint8_t rrc_msg[] = {0x20, 0x02, 0x10, 0x08, 0x00, 0x0C, 0x40, 0x60, 0x00}; uint8_t rrc_msg[] = {0x20, 0x02, 0x10, 0x08, 0x00, 0x0C, 0x40, 0x60, 0x00};
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bit_ref bref0(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref0(&rrc_msg[0], sizeof(rrc_msg));
dl_dcch_msg_s dl_dcch_msg; dl_dcch_msg_s dl_dcch_msg;
dl_dcch_msg.unpack(bref); dl_dcch_msg.unpack(bref);
@ -340,8 +340,8 @@ int ue_rrc_conn_recfg_r15_v10_test()
0x16, 0xcd, 0xa8, 0x14, 0x1a, 0x00, 0x20, 0xc8, 0x28, 0x70, 0x00, 0xb0, 0x01, 0xef, 0xb0, 0x00, 0x24, 0xa0, 0x82, 0x16, 0xcd, 0xa8, 0x14, 0x1a, 0x00, 0x20, 0xc8, 0x28, 0x70, 0x00, 0xb0, 0x01, 0xef, 0xb0, 0x00, 0x24, 0xa0, 0x82,
0x12, 0x02, 0x05, 0x02, 0x4a, 0x04, 0xe3, 0xf0, 0xd0, 0x00, 0x00}; 0x12, 0x02, 0x05, 0x02, 0x4a, 0x04, 0xe3, 0xf0, 0xd0, 0x00, 0x00};
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bit_ref bref0(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref0(&rrc_msg[0], sizeof(rrc_msg));
dl_dcch_msg_s dl_dcch_msg; dl_dcch_msg_s dl_dcch_msg;
dl_dcch_msg.unpack(bref); dl_dcch_msg.unpack(bref);
@ -516,8 +516,8 @@ int ue_rrc_conn_recfg_r15_v10_test()
int failed_dl_ccch_unpack() int failed_dl_ccch_unpack()
{ {
uint8_t rrc_msg[] = {0xa5, 0xa8, 0xd8, 0x10, 0x0e, 0xc8, 0x02}; uint8_t rrc_msg[] = {0xa5, 0xa8, 0xd8, 0x10, 0x0e, 0xc8, 0x02};
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
asn1::rrc::dl_ccch_msg_s msg; asn1::rrc::dl_ccch_msg_s msg;
@ -536,7 +536,7 @@ int unrecognized_ext_group_test()
// 0081198c3791901022c12940480082003267298a5aa8310018012e38038428c5b09d4b4800 // 0081198c3791901022c12940480082003267298a5aa8310018012e38038428c5b09d4b4800
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bcch_dl_sch_msg_s dl_sch_msg; bcch_dl_sch_msg_s dl_sch_msg;
dl_sch_msg.unpack(bref); dl_sch_msg.unpack(bref);
@ -565,7 +565,7 @@ int v2x_test()
0x02, 0x88, 0x38, 0x02, 0x38, 0x00, 0x0F, 0x4C, 0x70, 0x11, 0xC0, 0x00, 0x52, 0x0E, 0x00, 0x8E, 0x00}; 0x02, 0x88, 0x38, 0x02, 0x38, 0x00, 0x0F, 0x4C, 0x70, 0x11, 0xC0, 0x00, 0x52, 0x0E, 0x00, 0x8E, 0x00};
// 2098035E5B5FB000000040A0000000BFFFFE5402540697FFFFCA804A92880100060130008184E08C0010C22000000000000282300E0222AC044102162C58B162C102162C58B162C102162C58B162C102162C58B162C102162C58B162C102162C58B162C102162C58B162C102162C58B162C0A28004307219E8343219E83432089C420E008E001910700470012C8380238001E41C011C0007A0E008E0007931C047000288380238000F4C7011C000520E008E00 // 2098035E5B5FB000000040A0000000BFFFFE5402540697FFFFCA804A92880100060130008184E08C0010C22000000000000282300E0222AC044102162C58B162C102162C58B162C102162C58B162C102162C58B162C102162C58B162C102162C58B162C102162C58B162C102162C58B162C0A28004307219E8343219E83432089C420E008E001910700470012C8380238001E41C011C0007A0E008E0007931C047000288380238000F4C7011C000520E008E00
bit_ref bref(rrc_msg, sizeof(rrc_msg)); cbit_ref bref(rrc_msg, sizeof(rrc_msg));
sl_v2x_precfg_r14_s sl_preconf{}; sl_v2x_precfg_r14_s sl_preconf{};
TESTASSERT(sl_preconf.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(sl_preconf.unpack(bref) == SRSASN_SUCCESS);
@ -592,7 +592,7 @@ int test_rrc_conn_reconf_r15_2()
0x30, 0x38, 0x1F, 0xFA, 0x9C, 0x08, 0x3E, 0xA2, 0x5F, 0x1C, 0xE1, 0xD0, 0x84}; 0x30, 0x38, 0x1F, 0xFA, 0x9C, 0x08, 0x3E, 0xA2, 0x5F, 0x1C, 0xE1, 0xD0, 0x84};
// 201615C8400003C2841810A804D79514A20102189A018014810ACB840800AD6DC40608AF6DC7A0C08200000C38602030C3000010044010C23C2A06203011102813DA4E96DA8083A100A48300327B0895AE0016A900E080848C82BBB1B4BA188336B7319818988336B1B19A1B1B0233B839398280857F8080AF037F7F7D7D7F7F2805FB327B08C00001F83E3CB1B200C030381FFA9C083EA25F1CE1D084 // 201615C8400003C2841810A804D79514A20102189A018014810ACB840800AD6DC40608AF6DC7A0C08200000C38602030C3000010044010C23C2A06203011102813DA4E96DA8083A100A48300327B0895AE0016A900E080848C82BBB1B4BA188336B7319818988336B1B19A1B1B0233B839398280857F8080AF037F7F7D7D7F7F2805FB327B08C00001F83E3CB1B200C030381FFA9C083EA25F1CE1D084
bit_ref bref(rrc_msg, sizeof(rrc_msg)); cbit_ref bref(rrc_msg, sizeof(rrc_msg));
dl_dcch_msg_s recfg_msg; dl_dcch_msg_s recfg_msg;
TESTASSERT(recfg_msg.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(recfg_msg.unpack(bref) == SRSASN_SUCCESS);

@ -35,7 +35,7 @@ int unpack_test_served_gummeis_with_multiple_plmns()
0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10,
0x00, 0xf1, 0x10, 0x00, 0x00, 0x88, 0x88, 0x00, 0x7b, 0x00, 0x57, 0x40, 0x01, 0xff}; 0x00, 0xf1, 0x10, 0x00, 0x00, 0x88, 0x88, 0x00, 0x7b, 0x00, 0x57, 0x40, 0x01, 0xff};
asn1::bit_ref bref(pdu, sizeof(pdu)); asn1::cbit_ref bref(pdu, sizeof(pdu));
asn1::s1ap::s1ap_pdu_c input_pdu; asn1::s1ap::s1ap_pdu_c input_pdu;
TESTASSERT(input_pdu.unpack(bref) == SRSASN_SUCCESS); TESTASSERT(input_pdu.unpack(bref) == SRSASN_SUCCESS);

@ -46,8 +46,7 @@ int rrc_conn_setup_test1()
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
// 6012980bfdd204fa183ed5e6c25990c1a60001314042508000f8 // 6012980bfdd204fa183ed5e6c25990c1a60001314042508000f8
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bit_ref bref0(&rrc_msg[0], sizeof(rrc_msg));
dl_ccch_msg_s dl_ccch_msg; dl_ccch_msg_s dl_ccch_msg;
dl_ccch_msg.unpack(bref); dl_ccch_msg.unpack(bref);
@ -82,7 +81,7 @@ int rrc_conn_setup_test1()
if (dl_ccch_msg.pack(bref2) != SRSASN_SUCCESS) { if (dl_ccch_msg.pack(bref2) != SRSASN_SUCCESS) {
return -1; return -1;
} }
TESTASSERT(bref.distance(bref0) == bref2.distance(&rrc_msg2[0])); TESTASSERT(bref.distance() == bref2.distance());
TESTASSERT(memcmp(rrc_msg2, rrc_msg, rrc_msg_len) == 0); TESTASSERT(memcmp(rrc_msg2, rrc_msg, rrc_msg_len) == 0);
return 0; return 0;

@ -48,7 +48,7 @@ int rrc_conn_reconfig_ho_test1()
// 20 1b 3f 80 00 00 00 01 a9 08 80 00 00 29 00 97 80 00 00 00 01 04 22 14 00 f8 02 0a c0 60 00 a0 0c 80 42 02 9f 43 // 20 1b 3f 80 00 00 00 01 a9 08 80 00 00 29 00 97 80 00 00 00 01 04 22 14 00 f8 02 0a c0 60 00 a0 0c 80 42 02 9f 43
// 07 da bc f8 4b 32 18 34 c0 00 2d 68 08 5e 18 00 16 80 00 // 07 da bc f8 4b 32 18 34 c0 00 2d 68 08 5e 18 00 16 80 00
bit_ref bref(rrc_msg, sizeof(rrc_msg)); cbit_ref bref(rrc_msg, sizeof(rrc_msg));
dl_dcch_msg_s dl_dcch_msg; dl_dcch_msg_s dl_dcch_msg;
dl_dcch_msg.unpack(bref); dl_dcch_msg.unpack(bref);
@ -61,7 +61,7 @@ int rrc_conn_reconfig_ho_test1()
mob_reconf = dl_dcch_msg.msg.c1().rrc_conn_recfg(); mob_reconf = dl_dcch_msg.msg.c1().rrc_conn_recfg();
// decode same message and assign again // decode same message and assign again
bit_ref bref2(rrc_msg, sizeof(rrc_msg)); cbit_ref bref2(rrc_msg, sizeof(rrc_msg));
dl_dcch_msg_s dl_dcch_msg2; dl_dcch_msg_s dl_dcch_msg2;
dl_dcch_msg2.unpack(bref2); dl_dcch_msg2.unpack(bref2);
TESTASSERT(dl_dcch_msg2.msg.type() == dl_dcch_msg_type_c::types::c1); TESTASSERT(dl_dcch_msg2.msg.type() == dl_dcch_msg_type_c::types::c1);

@ -48,8 +48,7 @@ int basic_test()
uint32_t known_reference_len = sizeof(known_reference); uint32_t known_reference_len = sizeof(known_reference);
// 0d8fdfffffffe22ffc385e61eca80000020210002005e61eca8000004042 // 0d8fdfffffffe22ffc385e61eca80000020210002005e61eca8000004042
asn1::bit_ref bref(&known_reference[0], sizeof(known_reference)); asn1::cbit_ref bref(&known_reference[0], sizeof(known_reference));
asn1::bit_ref bref0(&known_reference[0], sizeof(known_reference));
asn1::rrc::mcch_msg_s mcch_msg; asn1::rrc::mcch_msg_s mcch_msg;
mcch_msg.unpack(bref); mcch_msg.unpack(bref);
@ -123,7 +122,7 @@ int basic_test()
bzero(rrc_msg2, sizeof(rrc_msg2)); bzero(rrc_msg2, sizeof(rrc_msg2));
asn1::bit_ref bref2(&rrc_msg2[0], sizeof(rrc_msg2)); asn1::bit_ref bref2(&rrc_msg2[0], sizeof(rrc_msg2));
mcch_msg.pack(bref2); mcch_msg.pack(bref2);
TESTASSERT(bref.distance(bref0) == bref2.distance(&rrc_msg2[0])); TESTASSERT(bref.distance() == bref2.distance());
TESTASSERT(memcmp(rrc_msg2, known_reference, known_reference_len) == 0); TESTASSERT(memcmp(rrc_msg2, known_reference, known_reference_len) == 0);
return 0; return 0;

@ -49,8 +49,7 @@ int basic_test()
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
// 0810493C0D978983C084208208210001BC48 // 0810493C0D978983C084208208210001BC48
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bit_ref bref0(&rrc_msg[0], sizeof(rrc_msg));
ul_dcch_msg_s ul_dcch_msg; ul_dcch_msg_s ul_dcch_msg;
ul_dcch_msg.unpack(bref); ul_dcch_msg.unpack(bref);
@ -93,7 +92,7 @@ int basic_test()
bzero(rrc_msg2, rrc_msg_len); bzero(rrc_msg2, rrc_msg_len);
bit_ref bref2(&rrc_msg2[0], sizeof(rrc_msg2)); bit_ref bref2(&rrc_msg2[0], sizeof(rrc_msg2));
ul_dcch_msg.pack(bref2); ul_dcch_msg.pack(bref2);
TESTASSERT(bref.distance(bref0) == bref2.distance(&rrc_msg2[0])); TESTASSERT(bref.distance() == bref2.distance());
TESTASSERT(memcmp(rrc_msg2, rrc_msg, rrc_msg_len) == 0); TESTASSERT(memcmp(rrc_msg2, rrc_msg, rrc_msg_len) == 0);
return 0; return 0;

@ -610,8 +610,8 @@ void rrc::parse_ul_ccch(uint16_t rnti, srslte::unique_byte_buffer_t pdu)
uint16_t old_rnti = 0; uint16_t old_rnti = 0;
if (pdu) { if (pdu) {
ul_ccch_msg_s ul_ccch_msg; ul_ccch_msg_s ul_ccch_msg;
asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref bref(pdu->msg, pdu->N_bytes);
if (ul_ccch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or if (ul_ccch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or
ul_ccch_msg.msg.type().value != ul_ccch_msg_type_c::types_opts::c1) { ul_ccch_msg.msg.type().value != ul_ccch_msg_type_c::types_opts::c1) {
rrc_log->error("Failed to unpack UL-CCCH message\n"); rrc_log->error("Failed to unpack UL-CCCH message\n");
@ -1073,8 +1073,8 @@ void rrc::ue::parse_ul_dcch(uint32_t lcid, srslte::unique_byte_buffer_t pdu)
{ {
set_activity(); set_activity();
ul_dcch_msg_s ul_dcch_msg; ul_dcch_msg_s ul_dcch_msg;
asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref bref(pdu->msg, pdu->N_bytes);
if (ul_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or if (ul_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or
ul_dcch_msg.msg.type().value != ul_dcch_msg_type_c::types_opts::c1) { ul_dcch_msg.msg.type().value != ul_dcch_msg_type_c::types_opts::c1) {
parent->rrc_log->error("Failed to unpack UL-DCCH message\n"); parent->rrc_log->error("Failed to unpack UL-DCCH message\n");
@ -1234,8 +1234,8 @@ bool rrc::ue::handle_ue_cap_info(ue_cap_info_s* msg)
parent->rrc_log->warning("Not handling UE capability information for RAT type %s\n", parent->rrc_log->warning("Not handling UE capability information for RAT type %s\n",
msg_r8->ue_cap_rat_container_list[i].rat_type.to_string().c_str()); msg_r8->ue_cap_rat_container_list[i].rat_type.to_string().c_str());
} else { } else {
asn1::bit_ref bref(msg_r8->ue_cap_rat_container_list[0].ue_cap_rat_container.data(), asn1::cbit_ref bref(msg_r8->ue_cap_rat_container_list[0].ue_cap_rat_container.data(),
msg_r8->ue_cap_rat_container_list[0].ue_cap_rat_container.size()); msg_r8->ue_cap_rat_container_list[0].ue_cap_rat_container.size());
if (eutra_capabilities.unpack(bref) != asn1::SRSASN_SUCCESS) { if (eutra_capabilities.unpack(bref) != asn1::SRSASN_SUCCESS) {
parent->rrc_log->error("Failed to unpack EUTRA capabilities message\n"); parent->rrc_log->error("Failed to unpack EUTRA capabilities message\n");
return false; return false;

@ -951,7 +951,7 @@ srslte::proc_outcome_t rrc::ue::rrc_mobility::sourceenb_ho_proc_t::react(ho_prep
/* unpack RRC HOCmd struct and perform sanity checks */ /* unpack RRC HOCmd struct and perform sanity checks */
asn1::rrc::ho_cmd_s rrchocmd; asn1::rrc::ho_cmd_s rrchocmd;
{ {
asn1::bit_ref bref(e.rrc_container->msg, e.rrc_container->N_bytes); asn1::cbit_ref bref(e.rrc_container->msg, e.rrc_container->N_bytes);
if (rrchocmd.unpack(bref) != asn1::SRSASN_SUCCESS) { if (rrchocmd.unpack(bref) != asn1::SRSASN_SUCCESS) {
procError("Unpacking of RRC HOCommand was unsuccessful\n"); procError("Unpacking of RRC HOCommand was unsuccessful\n");
parent->rrc_log->error_hex(e.rrc_container->msg, e.rrc_container->N_bytes, "Received container:\n"); parent->rrc_log->error_hex(e.rrc_container->msg, e.rrc_container->N_bytes, "Received container:\n");
@ -966,8 +966,8 @@ srslte::proc_outcome_t rrc::ue::rrc_mobility::sourceenb_ho_proc_t::react(ho_prep
/* unpack DL-DCCH message containing the RRCRonnectionReconf (with MobilityInfo) to be sent to the UE */ /* unpack DL-DCCH message containing the RRCRonnectionReconf (with MobilityInfo) to be sent to the UE */
asn1::rrc::dl_dcch_msg_s dl_dcch_msg; asn1::rrc::dl_dcch_msg_s dl_dcch_msg;
{ {
asn1::bit_ref bref(&rrchocmd.crit_exts.c1().ho_cmd_r8().ho_cmd_msg[0], asn1::cbit_ref bref(&rrchocmd.crit_exts.c1().ho_cmd_r8().ho_cmd_msg[0],
rrchocmd.crit_exts.c1().ho_cmd_r8().ho_cmd_msg.size()); rrchocmd.crit_exts.c1().ho_cmd_r8().ho_cmd_msg.size());
if (dl_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS) { if (dl_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS) {
procError("Unpacking of RRC DL-DCCH message with HO Command was unsuccessful.\n"); procError("Unpacking of RRC DL-DCCH message with HO Command was unsuccessful.\n");
return srslte::proc_outcome_t::error; return srslte::proc_outcome_t::error;

@ -116,8 +116,8 @@ srslte::proc_outcome_t s1ap::ue::ho_prep_proc_t::react(const asn1::s1ap::ho_cmd_
// In case of intra-system Handover, Target to Source Transparent Container IE shall be encoded as // In case of intra-system Handover, Target to Source Transparent Container IE shall be encoded as
// Target eNB to Source eNB Transparent Container IE // Target eNB to Source eNB Transparent Container IE
uint8_t* buf = const_cast<uint8_t*>(msg.protocol_ies.target_to_source_transparent_container.value.data()); asn1::cbit_ref bref(msg.protocol_ies.target_to_source_transparent_container.value.data(),
asn1::bit_ref bref(buf, msg.protocol_ies.target_to_source_transparent_container.value.size()); msg.protocol_ies.target_to_source_transparent_container.value.size());
asn1::s1ap::targetenb_to_sourceenb_transparent_container_s container; asn1::s1ap::targetenb_to_sourceenb_transparent_container_s container;
if (container.unpack(bref) != asn1::SRSASN_SUCCESS) { if (container.unpack(bref) != asn1::SRSASN_SUCCESS) {
procError("Failed to decode TargeteNBToSourceeNBTransparentContainer\n"); procError("Failed to decode TargeteNBToSourceeNBTransparentContainer\n");
@ -501,8 +501,8 @@ bool s1ap::handle_mme_rx_msg(srslte::unique_byte_buffer_t pdu,
bool s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t* pdu) bool s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t* pdu)
{ {
s1ap_pdu_c rx_pdu; s1ap_pdu_c rx_pdu;
asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref bref(pdu->msg, pdu->N_bytes);
if (rx_pdu.unpack(bref) != asn1::SRSASN_SUCCESS) { if (rx_pdu.unpack(bref) != asn1::SRSASN_SUCCESS) {
s1ap_log->error("Failed to unpack received PDU\n"); s1ap_log->error("Failed to unpack received PDU\n");

@ -92,7 +92,7 @@ int test_erab_setup(bool qci_exists)
byte_buf.N_bytes = sizeof(drb2_erab_setup_request_fail); byte_buf.N_bytes = sizeof(drb2_erab_setup_request_fail);
memcpy(byte_buf.msg, drb2_erab_setup_request_fail, byte_buf.N_bytes); memcpy(byte_buf.msg, drb2_erab_setup_request_fail, byte_buf.N_bytes);
} }
asn1::bit_ref bref(byte_buf.msg, byte_buf.N_bytes); asn1::cbit_ref bref(byte_buf.msg, byte_buf.N_bytes);
TESTASSERT(s1ap_pdu.unpack(bref) == asn1::SRSASN_SUCCESS); TESTASSERT(s1ap_pdu.unpack(bref) == asn1::SRSASN_SUCCESS);
rrc.setup_ue_erabs(rnti, s1ap_pdu.init_msg().value.erab_setup_request()); rrc.setup_ue_erabs(rnti, s1ap_pdu.init_msg().value.erab_setup_request());

@ -43,8 +43,7 @@ int rrc_plmn_test()
uint8_t byte_buf[4]; uint8_t byte_buf[4];
// 2-digit MNC test // 2-digit MNC test
asn1::bit_ref bref_out(&ref[0], sizeof(ref)); asn1::cbit_ref bref_out(&ref[0], sizeof(ref));
asn1::bit_ref bref_out0(&ref[0], sizeof(ref));
plmn_out.unpack(bref_out); plmn_out.unpack(bref_out);
@ -71,7 +70,7 @@ int rrc_plmn_test()
asn1::bit_ref bref_in0(&byte_buf[0], sizeof(byte_buf)); asn1::bit_ref bref_in0(&byte_buf[0], sizeof(byte_buf));
plmn_out.pack(bref_in); plmn_out.pack(bref_in);
TESTASSERT(bref_in.distance(&byte_buf[0]) == bref_out.distance(bref_out0)); TESTASSERT(bref_in.distance() == bref_out.distance());
TESTASSERT(memcmp(&ref[0], &byte_buf[0], sizeof(ref)) == 0); TESTASSERT(memcmp(&ref[0], &byte_buf[0], sizeof(ref)) == 0);
// 3-digit MNC test // 3-digit MNC test
@ -82,7 +81,7 @@ int rrc_plmn_test()
TESTASSERT(bref_in.distance(bref_in0) == (1 + 3 * 4 + 1 + 3 * 4)); TESTASSERT(bref_in.distance(bref_in0) == (1 + 3 * 4 + 1 + 3 * 4));
TESTASSERT(memcmp(&byte_buf[0], &ref2[0], sizeof(ref)) == 0); TESTASSERT(memcmp(&byte_buf[0], &ref2[0], sizeof(ref)) == 0);
bref_out = asn1::bit_ref(&ref2[0], sizeof(ref2)); bref_out = asn1::cbit_ref(&ref2[0], sizeof(ref2));
plmn_out.unpack(bref_out); plmn_out.unpack(bref_out);
TESTASSERT(plmn_in.mcc_present == plmn_out.mcc_present); TESTASSERT(plmn_in.mcc_present == plmn_out.mcc_present);
TESTASSERT(plmn_in.mcc == plmn_out.mcc); TESTASSERT(plmn_in.mcc == plmn_out.mcc);

@ -333,7 +333,7 @@ int test_mobility_class(mobility_test_params test_params)
TESTASSERT(s1ap.last_ho_required.target_eci == cell2.eci); TESTASSERT(s1ap.last_ho_required.target_eci == cell2.eci);
TESTASSERT(s1ap.last_ho_required.target_plmn.to_string() == "00101"); TESTASSERT(s1ap.last_ho_required.target_plmn.to_string() == "00101");
{ {
asn1::bit_ref bref(s1ap.last_ho_required.rrc_container->msg, s1ap.last_ho_required.rrc_container->N_bytes); asn1::cbit_ref bref(s1ap.last_ho_required.rrc_container->msg, s1ap.last_ho_required.rrc_container->N_bytes);
asn1::rrc::ho_prep_info_s hoprep; asn1::rrc::ho_prep_info_s hoprep;
TESTASSERT(hoprep.unpack(bref) == asn1::SRSASN_SUCCESS); TESTASSERT(hoprep.unpack(bref) == asn1::SRSASN_SUCCESS);
ho_prep_info_r8_ies_s& hoprepr8 = hoprep.crit_exts.c1().ho_prep_info_r8(); ho_prep_info_r8_ies_s& hoprepr8 = hoprep.crit_exts.c1().ho_prep_info_r8();

@ -138,7 +138,7 @@ void copy_msg_to_buffer(srslte::unique_byte_buffer_t& pdu, uint8_t* msg, size_t
pdu = srslte::allocate_unique_buffer(*pool, true); pdu = srslte::allocate_unique_buffer(*pool, true);
memcpy(pdu->msg, msg, nof_bytes); memcpy(pdu->msg, msg, nof_bytes);
pdu->N_bytes = nof_bytes; pdu->N_bytes = nof_bytes;
}; }
int bring_rrc_to_reconf_state(srsenb::rrc& rrc, srslte::timer_handler& timers, uint16_t rnti) int bring_rrc_to_reconf_state(srsenb::rrc& rrc, srslte::timer_handler& timers, uint16_t rnti)
{ {
@ -177,7 +177,7 @@ int bring_rrc_to_reconf_state(srsenb::rrc& rrc, srslte::timer_handler& timers, u
srslte::byte_buffer_t byte_buf; srslte::byte_buffer_t byte_buf;
byte_buf.N_bytes = sizeof(s1ap_init_ctxt_setup_req); byte_buf.N_bytes = sizeof(s1ap_init_ctxt_setup_req);
memcpy(byte_buf.msg, s1ap_init_ctxt_setup_req, byte_buf.N_bytes); memcpy(byte_buf.msg, s1ap_init_ctxt_setup_req, byte_buf.N_bytes);
asn1::bit_ref bref(byte_buf.msg, byte_buf.N_bytes); asn1::cbit_ref bref(byte_buf.msg, byte_buf.N_bytes);
TESTASSERT(s1ap_pdu.unpack(bref) == asn1::SRSASN_SUCCESS); TESTASSERT(s1ap_pdu.unpack(bref) == asn1::SRSASN_SUCCESS);
rrc.setup_ue_ctxt(rnti, s1ap_pdu.init_msg().value.init_context_setup_request()); rrc.setup_ue_ctxt(rnti, s1ap_pdu.init_msg().value.init_context_setup_request());
timers.step_all(); timers.step_all();

@ -1374,7 +1374,7 @@ void rrc::cell_search_completed(const phy_interface_rrc_lte::cell_search_ret_t&
void rrc::write_pdu_bcch_bch(unique_byte_buffer_t pdu) void rrc::write_pdu_bcch_bch(unique_byte_buffer_t pdu)
{ {
asn1::rrc::bcch_bch_msg_s bch_msg; asn1::rrc::bcch_bch_msg_s bch_msg;
asn1::bit_ref bch_bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref bch_bref(pdu->msg, pdu->N_bytes);
asn1::SRSASN_CODE err = bch_msg.unpack(bch_bref); asn1::SRSASN_CODE err = bch_msg.unpack(bch_bref);
if (err != asn1::SRSASN_SUCCESS) { if (err != asn1::SRSASN_SUCCESS) {
rrc_log->error("Could not unpack BCCH-BCH message.\n"); rrc_log->error("Could not unpack BCCH-BCH message.\n");
@ -1400,7 +1400,7 @@ void rrc::parse_pdu_bcch_dlsch(unique_byte_buffer_t pdu)
mac->bcch_stop_rx(); mac->bcch_stop_rx();
asn1::rrc::bcch_dl_sch_msg_s dlsch_msg; asn1::rrc::bcch_dl_sch_msg_s dlsch_msg;
asn1::bit_ref dlsch_bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref dlsch_bref(pdu->msg, pdu->N_bytes);
asn1::SRSASN_CODE err = dlsch_msg.unpack(dlsch_bref); asn1::SRSASN_CODE err = dlsch_msg.unpack(dlsch_bref);
if (err != asn1::SRSASN_SUCCESS or dlsch_msg.msg.type().value != bcch_dl_sch_msg_type_c::types_opts::c1) { if (err != asn1::SRSASN_SUCCESS or dlsch_msg.msg.type().value != bcch_dl_sch_msg_type_c::types_opts::c1) {
rrc_log->error("Could not unpack BCCH DL-SCH message.\n"); rrc_log->error("Could not unpack BCCH DL-SCH message.\n");
@ -1598,8 +1598,8 @@ void rrc::process_pcch(unique_byte_buffer_t pdu)
return; return;
} }
pcch_msg_s pcch_msg; pcch_msg_s pcch_msg;
asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref bref(pdu->msg, pdu->N_bytes);
if (pcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or pcch_msg.msg.type().value != pcch_msg_type_c::types_opts::c1) { if (pcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or pcch_msg.msg.type().value != pcch_msg_type_c::types_opts::c1) {
rrc_log->error_hex(pdu->buffer, pdu->N_bytes, "Failed to unpack PCCH message (%d B)\n", pdu->N_bytes); rrc_log->error_hex(pdu->buffer, pdu->N_bytes, "Failed to unpack PCCH message (%d B)\n", pdu->N_bytes);
return; return;
@ -1644,7 +1644,7 @@ void rrc::write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu)
void rrc::parse_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) void rrc::parse_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu)
{ {
asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref bref(pdu->msg, pdu->N_bytes);
if (serving_cell->mcch.unpack(bref) != asn1::SRSASN_SUCCESS or if (serving_cell->mcch.unpack(bref) != asn1::SRSASN_SUCCESS or
serving_cell->mcch.msg.type().value != mcch_msg_type_c::types_opts::c1) { serving_cell->mcch.msg.type().value != mcch_msg_type_c::types_opts::c1) {
rrc_log->error("Failed to unpack MCCH message\n"); rrc_log->error("Failed to unpack MCCH message\n");
@ -1756,7 +1756,7 @@ void rrc::process_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu)
void rrc::parse_dl_ccch(unique_byte_buffer_t pdu) void rrc::parse_dl_ccch(unique_byte_buffer_t pdu)
{ {
asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref bref(pdu->msg, pdu->N_bytes);
asn1::rrc::dl_ccch_msg_s dl_ccch_msg; asn1::rrc::dl_ccch_msg_s dl_ccch_msg;
if (dl_ccch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or if (dl_ccch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or
dl_ccch_msg.msg.type().value != dl_ccch_msg_type_c::types_opts::c1) { dl_ccch_msg.msg.type().value != dl_ccch_msg_type_c::types_opts::c1) {
@ -1807,7 +1807,7 @@ void rrc::parse_dl_ccch(unique_byte_buffer_t pdu)
void rrc::parse_dl_dcch(uint32_t lcid, unique_byte_buffer_t pdu) void rrc::parse_dl_dcch(uint32_t lcid, unique_byte_buffer_t pdu)
{ {
asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::cbit_ref bref(pdu->msg, pdu->N_bytes);
asn1::rrc::dl_dcch_msg_s dl_dcch_msg; asn1::rrc::dl_dcch_msg_s dl_dcch_msg;
if (dl_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or if (dl_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or
dl_dcch_msg.msg.type().value != dl_dcch_msg_type_c::types_opts::c1) { dl_dcch_msg.msg.type().value != dl_dcch_msg_type_c::types_opts::c1) {

@ -114,8 +114,7 @@ int basic_test()
0x20, 0x60, 0x18, 0x07, 0x97, 0x09, 0x1f, 0xc3, 0x06, 0x00, 0x81, 0x00, 0x00, 0x11}; 0x20, 0x60, 0x18, 0x07, 0x97, 0x09, 0x1f, 0xc3, 0x06, 0x00, 0x81, 0x00, 0x00, 0x11};
uint32_t rrc_msg_len = sizeof(rrc_msg); uint32_t rrc_msg_len = sizeof(rrc_msg);
bit_ref bref(&rrc_msg[0], sizeof(rrc_msg)); cbit_ref bref(&rrc_msg[0], sizeof(rrc_msg));
bit_ref bref0(&rrc_msg[0], sizeof(rrc_msg));
dl_dcch_msg.unpack(bref); dl_dcch_msg.unpack(bref);
@ -140,13 +139,13 @@ int basic_test()
dl_dcch_msg.pack(bref2); dl_dcch_msg.pack(bref2);
// //
bref = bit_ref(&rrc_msg2[0], rrc_msg_len); bref = cbit_ref(&rrc_msg2[0], rrc_msg_len);
dl_dcch_msg.unpack(bref); dl_dcch_msg.unpack(bref);
bref = bit_ref(&rrc_msg[0], rrc_msg_len); bit_ref bref_pack(&rrc_msg[0], rrc_msg_len);
dl_dcch_msg.pack(bref); dl_dcch_msg.pack(bref_pack);
uint32_t nof_bytes = (uint32_t)bref.distance_bytes(&rrc_msg[0]); uint32_t nof_bytes = (uint32_t)bref.distance_bytes();
TESTASSERT(bref.distance(&rrc_msg[0]) == bref2.distance(&rrc_msg2[0])); TESTASSERT(bref_pack.distance() == bref2.distance());
TESTASSERT(memcmp(rrc_msg2, rrc_msg, nof_bytes) == 0); TESTASSERT(memcmp(rrc_msg2, rrc_msg, nof_bytes) == 0);
printf("done\n"); printf("done\n");

Loading…
Cancel
Save