Added nas 5g msg packing and unpacking

master
David Rupprecht 4 years ago committed by David Rupprecht
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

@ -61,5 +61,10 @@ add_library(ngap_nr_asn1 STATIC ngap.cc)
target_compile_options(ngap_nr_asn1 PRIVATE "-Os") target_compile_options(ngap_nr_asn1 PRIVATE "-Os")
target_link_libraries(ngap_nr_asn1 asn1_utils srsran_common) target_link_libraries(ngap_nr_asn1 asn1_utils srsran_common)
INSTALL(TARGETS ngap_nr_asn1 DESTINATION ${LIBRARY_DIR}) INSTALL(TARGETS ngap_nr_asn1 DESTINATION ${LIBRARY_DIR})
# NAS 5G
add_library(nas_5g_msg STATIC nas_5g_msg.cc nas_5g_ies.cc nas_5g_utils.cc)
target_compile_options(nas_5g_msg PRIVATE "-Os")
target_link_libraries(nas_5g_msg asn1_utils srsran_common)
INSTALL(TARGETS nas_5g_msg DESTINATION ${LIBRARY_DIR})

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

@ -59,3 +59,6 @@ target_link_libraries(rrc_asn1_decoder rrc_asn1)
add_executable(nas_decoder nas_decoder.cc) add_executable(nas_decoder nas_decoder.cc)
target_link_libraries(nas_decoder srsran_asn1) target_link_libraries(nas_decoder srsran_asn1)
add_executable(nas_5g_msg_test nas_5g_msg_test.cc)
target_link_libraries(nas_5g_msg_test nas_5g_msg)

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