Commit 734434ca authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update 5GMMCapability

parent 5ea14f46
......@@ -84,7 +84,7 @@ class nas_context {
uint8_t ngKsi : 4;
// mobility identity: imsi, supi, 5g-guti, etc
std::string imsi;
uint8_t mmCapability;
uint8_t mmCapability; // TODO: multiple octets
uint8_t ueSecurityCaplen;
uint8_t ueSecurityCapEnc;
uint8_t ueSecurityCapInt;
......
......@@ -28,10 +28,12 @@
using namespace nas;
//------------------------------------------------------------------------------
_5GMMCapability::_5GMMCapability(const uint8_t iei, uint8_t value) {
m_iei = iei;
octet3_ = value;
length = k5gmmCapabilityMinimumLength;
_5GMMCapability::_5GMMCapability(const uint8_t iei, uint8_t octet3) {
iei_ = iei;
octet3_ = octet3;
octet4_ = std::nullopt;
octet5_ = std::nullopt;
length = 1;
}
//------------------------------------------------------------------------------
......@@ -41,36 +43,39 @@ _5GMMCapability::_5GMMCapability() {}
_5GMMCapability::~_5GMMCapability() {}
//------------------------------------------------------------------------------
void _5GMMCapability::setValue(uint8_t iei, uint8_t value) {
m_iei = iei;
octet3_ = value;
void _5GMMCapability::setOctet3(const uint8_t iei, uint8_t octet3) {
iei_ = iei;
octet3_ = octet3;
}
//------------------------------------------------------------------------------
uint8_t _5GMMCapability::getValue() {
uint8_t _5GMMCapability::getOctet3() const {
return octet3_;
}
//------------------------------------------------------------------------------
int _5GMMCapability::encode2Buffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding _5GMMCapability IEI (0x%x)", m_iei);
if (len < length) {
Logger::nas_mm().error("Len is less than %d", length);
Logger::nas_mm().debug("Encoding _5GMMCapability IEI");
int ie_len = iei_ ? (length + 2) : (length + 1); // 1 for IEI, 1 for Length
if (len < ie_len) {
Logger::nas_mm().error("Len is less than %d", ie_len);
return KEncodeDecodeError;
}
int encoded_size = 0;
if (m_iei) {
ENCODE_U8(buf + encoded_size, m_iei, encoded_size);
ENCODE_U8(buf + encoded_size, length - 2, encoded_size);
} else {
ENCODE_U8(buf + encoded_size, length - 1, encoded_size);
// IEI
if (iei_) {
ENCODE_U8(buf + encoded_size, iei_, encoded_size);
}
// Length
ENCODE_U8(buf + encoded_size, length, encoded_size);
// Octet 3
ENCODE_U8(buf + encoded_size, octet3_, encoded_size);
// TODO: Encode spare for the rest
uint8_t spare = 0;
for (int i = 0; i < (length - encoded_size); i++) {
int spare_len = ie_len - encoded_size;
for (int i = 0; i < spare_len; i++) {
ENCODE_U8(buf + encoded_size, spare, encoded_size);
}
......@@ -88,24 +93,25 @@ int _5GMMCapability::decodeFromBuffer(uint8_t* buf, int len, bool is_option) {
}
uint8_t decoded_size = 0;
uint8_t octet = 0;
Logger::nas_mm().debug("Decoding _5GMMCapability IEI (0x%x)", *buf);
Logger::nas_mm().debug("Decoding _5GMMCapability IE");
if (is_option) {
decoded_size++;
DECODE_U8(buf + decoded_size, octet, decoded_size);
iei_ = std::optional<uint8_t>(octet);
}
uint8_t ie_len = 0;
DECODE_U8(buf + decoded_size, ie_len, decoded_size);
length = ie_len + decoded_size;
DECODE_U8(buf + decoded_size, length, decoded_size);
DECODE_U8(buf + decoded_size, octet3_, decoded_size);
// TODO: decode the rest as spare for now
uint8_t spare = 0;
for (int i = 0; i < (ie_len - 1); i++) {
for (int i = 0; i < (length - 1); i++) {
ENCODE_U8(buf + decoded_size, spare, decoded_size);
}
Logger::nas_mm().debug("Decoded _5GMMCapability value(0x%x)", octet3_);
Logger::nas_mm().debug("Decoded _5GMMCapability len(%d)", decoded_size);
Logger::nas_mm().debug(
"Decoded _5GMMCapability Octet3 value (0x%x)", octet3_);
Logger::nas_mm().debug("Decoded _5GMMCapability len (%d)", decoded_size);
return decoded_size;
}
......@@ -32,18 +32,20 @@ namespace nas {
class _5GMMCapability {
public:
_5GMMCapability();
_5GMMCapability(const uint8_t iei, uint8_t value);
_5GMMCapability(const uint8_t iei, uint8_t octet3);
~_5GMMCapability();
void setValue(uint8_t iei, uint8_t value);
uint8_t getValue();
void setOctet3(const uint8_t iei, uint8_t octet3);
uint8_t getOctet3() const;
int encode2Buffer(uint8_t* buf, int len);
int decodeFromBuffer(uint8_t* buf, int len, bool is_option = true);
private:
uint8_t m_iei;
uint8_t iei_;
uint8_t octet3_; // minimum length of 3 octets
std::optional<uint8_t> octet4_;
std::optional<uint8_t> octet5_;
uint8_t length;
};
......
......@@ -57,6 +57,7 @@ NasKeySetIdentifier::~NasKeySetIdentifier(){};
void NasKeySetIdentifier::Set(const bool& high_pos) {
Type1NasIe::Set(high_pos);
}
//------------------------------------------------------------------------------
void NasKeySetIdentifier::SetValue() {
if (tsc_)
......@@ -64,6 +65,7 @@ void NasKeySetIdentifier::SetValue() {
else
value_ = 0x07 & key_id_;
}
//------------------------------------------------------------------------------
void NasKeySetIdentifier::GetValue() {
tsc_ = (0b1000 & value_) >> 3;
......
......@@ -43,10 +43,6 @@ class NasKeySetIdentifier : public Type1NasIe {
// void Set(const bool& tsc, const uint8_t& key_id, const uint8_t& iei);
void Get(bool& tsc, uint8_t& key_id);
// int encode2Buffer(uint8_t* buf, const int& len);
// int decodeFromBuffer(
// uint8_t* buf, const int& len, bool is_option, bool is_high);
void setTypeOfSecurityContext(const bool& type);
bool getTypeOfSecurityContext() const;
......
......@@ -47,7 +47,8 @@ void Type4NasIe::SetIei(const uint8_t& iei) {
//------------------------------------------------------------------------------
bool Type4NasIe::Validate(const int& len) const {
uint8_t actual_lengh = iei_.has_value() ? li_ + 1 : li_;
uint8_t actual_lengh =
iei_.has_value() ? (li_ + 2) : (li_ + 1); // 1 for IEI and 1 for LI
if (len < actual_lengh) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
......@@ -56,3 +57,43 @@ bool Type4NasIe::Validate(const int& len) const {
}
return true;
}
//------------------------------------------------------------------------------
int Type4NasIe::Encode(uint8_t* buf, const int& len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
int encoded_size = 0;
uint8_t octet = 0;
if (iei_.has_value()) {
ENCODE_U8(buf + encoded_size, iei_.value(), encoded_size);
}
ENCODE_U8(buf + encoded_size, li_, encoded_size);
Logger::nas_mm().debug(
"Encoded %s (len %d)", GetIeName().c_str(), encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int Type4NasIe::Decode(
const uint8_t* const buf, const int& len, bool is_iei = false) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
int decoded_size = 0;
uint8_t octet = 0;
if (is_iei) {
DECODE_U8(buf + decoded_size, octet, decoded_size);
iei_ = std::optional<uint8_t>(octet);
}
DECODE_U8(buf + decoded_size, li_, decoded_size);
Logger::nas_mm().debug(
"Decoded %s (len %d)", GetIeName().c_str(), decoded_size);
return decoded_size;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment