mirror of https://github.com/pvnis/srsRAN_4G.git
Added nas 5g msg packing and unpacking
parent
e460739152
commit
724af2b060
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,87 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 Software Radio Systems Limited
|
||||
*
|
||||
* By using this file, you agree to the terms and conditions set
|
||||
* forth in the LICENSE file which can be found at the top level of
|
||||
* the distribution.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSRAN_NAS_5G_UTILS_H
|
||||
#define SRSRAN_NAS_5G_UTILS_H
|
||||
|
||||
#include "srsran/asn1/asn1_utils.h"
|
||||
#include "srsran/common/byte_buffer.h"
|
||||
#include "srsran/config.h"
|
||||
|
||||
using namespace asn1;
|
||||
namespace srsran {
|
||||
namespace nas_5g {
|
||||
|
||||
struct ecies_scheme_profile_a_out {
|
||||
uint8_t ecc_ephemeral_key[33];
|
||||
std::vector<uint8_t> ciphertext;
|
||||
uint8_t mac_tag[8];
|
||||
};
|
||||
|
||||
struct ecies_scheme_profile_b_out {
|
||||
uint8_t ecc_ephemeral_key[32];
|
||||
std::vector<uint8_t> ciphertext;
|
||||
uint8_t mac_tag[8];
|
||||
};
|
||||
|
||||
template <typename Enum, int bl>
|
||||
SRSASN_CODE unpack_enum(asn1::cbit_ref& bref, Enum* e)
|
||||
{
|
||||
uint32_t tmp = {};
|
||||
HANDLE_CODE(bref.unpack(tmp, bl));
|
||||
*e = static_cast<Enum>(tmp);
|
||||
return SRSASN_SUCCESS;
|
||||
}
|
||||
|
||||
template <typename Enum, int bl>
|
||||
SRSASN_CODE pack_enum(asn1::bit_ref& bref, Enum e)
|
||||
{
|
||||
uint32_t tmp = static_cast<uint32_t>(e);
|
||||
HANDLE_CODE(bref.pack(tmp, bl));
|
||||
return SRSASN_SUCCESS;
|
||||
}
|
||||
|
||||
template <class EnumType, uint32_t bit_length_>
|
||||
class nas_enumerated : public EnumType
|
||||
{
|
||||
public:
|
||||
static const uint32_t bit_length = bit_length_;
|
||||
|
||||
nas_enumerated() {}
|
||||
nas_enumerated(typename EnumType::options o) { EnumType::value = o; }
|
||||
SRSASN_CODE pack(asn1::bit_ref& bref) const
|
||||
{
|
||||
uint32_t tmp = static_cast<uint32_t>(EnumType::value);
|
||||
HANDLE_CODE(bref.pack(tmp, bit_length));
|
||||
return SRSASN_SUCCESS;
|
||||
}
|
||||
SRSASN_CODE unpack(asn1::cbit_ref& bref)
|
||||
{
|
||||
uint32_t tmp = {};
|
||||
HANDLE_CODE(bref.unpack(tmp, bit_length));
|
||||
*this = static_cast<typename EnumType::options>(tmp);
|
||||
return SRSASN_SUCCESS;
|
||||
}
|
||||
EnumType& operator=(EnumType v)
|
||||
{
|
||||
EnumType::value = v;
|
||||
return *this;
|
||||
}
|
||||
operator typename EnumType::options() const { return EnumType::value; }
|
||||
};
|
||||
|
||||
SRSASN_CODE unpack_mcc_mnc(uint8_t* mcc_bytes, uint8_t* mnc_bytes, asn1::cbit_ref& bref);
|
||||
SRSASN_CODE pack_mcc_mnc(uint8_t* mcc_bytes, uint8_t* mnc_bytes, asn1::bit_ref& bref);
|
||||
|
||||
} // namespace nas_5g
|
||||
} // namespace srsran
|
||||
#endif // MANUAL_H
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,56 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2021 Software Radio Systems Limited
|
||||
*
|
||||
* By using this file, you agree to the terms and conditions set
|
||||
* forth in the LICENSE file which can be found at the top level of
|
||||
* the distribution.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srsran/asn1/nas_5g_utils.h"
|
||||
|
||||
#include "srsran/asn1/asn1_utils.h"
|
||||
#include "srsran/common/buffer_pool.h"
|
||||
#include "srsran/common/common.h"
|
||||
#include "srsran/config.h"
|
||||
|
||||
#include <array>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
namespace srsran {
|
||||
namespace nas_5g {
|
||||
|
||||
SRSASN_CODE unpack_mcc_mnc(uint8_t* mcc_bytes, uint8_t* mnc_bytes, asn1::cbit_ref& bref)
|
||||
{
|
||||
// MCC digit 2 | MCC digit 1 | octet 5
|
||||
// MNC digit 3 | MCC digit 3 | octet 6
|
||||
// MNC digit 2 | MNC digit 1 | octet 7
|
||||
HANDLE_CODE(bref.unpack(mcc_bytes[1], 4));
|
||||
HANDLE_CODE(bref.unpack(mcc_bytes[0], 4));
|
||||
HANDLE_CODE(bref.unpack(mnc_bytes[2], 4));
|
||||
HANDLE_CODE(bref.unpack(mcc_bytes[2], 4));
|
||||
HANDLE_CODE(bref.unpack(mnc_bytes[1], 4));
|
||||
HANDLE_CODE(bref.unpack(mnc_bytes[0], 4));
|
||||
return SRSASN_SUCCESS;
|
||||
}
|
||||
|
||||
SRSASN_CODE pack_mcc_mnc(uint8_t* mcc_bytes, uint8_t* mnc_bytes, asn1::bit_ref& bref)
|
||||
{
|
||||
// MCC digit 2 | MCC digit 1 | octet 5
|
||||
// MNC digit 3 | MCC digit 3 | octet 6
|
||||
// MNC digit 2 | MNC digit 1 | octet 7
|
||||
HANDLE_CODE(bref.pack(mcc_bytes[1], 4));
|
||||
HANDLE_CODE(bref.pack(mcc_bytes[0], 4));
|
||||
HANDLE_CODE(bref.pack(mnc_bytes[2], 4));
|
||||
HANDLE_CODE(bref.pack(mcc_bytes[2], 4));
|
||||
HANDLE_CODE(bref.pack(mnc_bytes[1], 4));
|
||||
HANDLE_CODE(bref.pack(mnc_bytes[0], 4));
|
||||
return SRSASN_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace nas_5g
|
||||
} // namespace srsran
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue