Commit 1f43ee67 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update LADN Indication

parent ca60fb3d
......@@ -113,6 +113,7 @@ constexpr uint8_t kIeiRejectedNssaiRr = 0x69;
constexpr uint8_t kIeiEpsNasMessageContainer = 0x70;
constexpr uint8_t kIeiNasMessageContainer = 0x71;
constexpr uint8_t kIeiLadnIndication = 0x74;
constexpr uint8_t kIei5gGuti = 0x77;
constexpr uint8_t kIeiImeisv = 0x77;
constexpr uint8_t kIeiNonImeisvPei = 0x78;
......
......@@ -23,87 +23,93 @@
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "Ie_Const.hpp"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
LADN_Indication::LADN_Indication(uint8_t iei) {
_iei = iei;
length = 0;
LADN = {};
LadnIndication::LadnIndication() : Type6NasIe(kIeiLadnIndication) {
LADN = {};
SetIeName(kLadnIndicationIeName);
}
//------------------------------------------------------------------------------
LADN_Indication::LADN_Indication(const uint8_t iei, std::vector<bstring> ladn) {
_iei = iei;
length = 3;
LadnIndication::LadnIndication(const std::vector<bstring>& ladn)
: Type6NasIe(kIeiLadnIndication) {
int length = 0;
LADN.assign(ladn.begin(), ladn.end());
for (int i = 0; i < ladn.size(); i++) {
length = length + blength(ladn.at(i));
}
SetLengthIndicator(length);
}
//------------------------------------------------------------------------------
LADN_Indication::LADN_Indication() : _iei(), length(), LADN() {}
//------------------------------------------------------------------------------
LADN_Indication::~LADN_Indication() {}
//------------------------------------------------------------------------------
void LADN_Indication::setValue(uint8_t iei) {
_iei = iei;
}
LadnIndication::~LadnIndication() {}
//------------------------------------------------------------------------------
void LADN_Indication::getValue(std::vector<bstring>& ladn) {
void LadnIndication::GetValue(std::vector<bstring>& ladn) {
ladn.assign(LADN.begin(), LADN.end());
}
//------------------------------------------------------------------------------
int LADN_Indication::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding LADN_Indication (IEI 0x%x)", _iei);
int LadnIndication::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if ((len < length + 3) or (len < kLadnIndicationMinimumLength)) {
int ie_len = GetIeLength();
if (len < ie_len) { // Length of the content + IEI/Len
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE");
"Size of the buffer is not enough to store this IE (IE len %d)",
ie_len);
return KEncodeDecodeError;
}
int encoded_size = 0;
if (_iei) {
ENCODE_U8(buf + encoded_size, _iei, encoded_size);
}
ENCODE_U16(buf + encoded_size, length, encoded_size);
// IEI and Length (later)
int len_pos = 0;
int encoded_header_size =
Type6NasIe::Encode(buf + encoded_size, len, len_pos);
if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
encoded_size += encoded_header_size;
for (int i = 0; i < LADN.size(); i++) {
ENCODE_U8(buf + encoded_size, blength(LADN.at(i)), encoded_size);
encoded_size +=
encode_bstring(LADN.at(i), (buf + encoded_size), len - encoded_size);
}
Logger::nas_mm().debug("Encoded LADN_Indication (len %d)", encoded_size);
// Encode length
int encoded_len_ie = 0;
ENCODE_U16(buf + len_pos, encoded_size - GetHeaderLength(), encoded_len_ie);
Logger::nas_mm().debug(
"Encoded %s, len (%d)", GetIeName().c_str(), encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int LADN_Indication::Decode(uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug("Decoding LADN_Indication");
int LadnIndication::Decode(uint8_t* buf, int len, bool is_iei) {
Logger::nas_mm().debug("Decoding EPS_NAS_Message_Container");
int decoded_size = 0;
if (is_option) {
DECODE_U8(buf + decoded_size, _iei, decoded_size);
}
length = 0;
DECODE_U16(buf + decoded_size, length, decoded_size);
Logger::nas_mm().debug("Decoded LADN_Indication (len %d)", length);
int len_ie = length;
uint8_t len_dnn = 0;
bstring dnn;
while (len_ie) {
DECODE_U8(buf + decoded_size, len_dnn, decoded_size);
len_ie--;
decode_bstring(&dnn, len_dnn, (buf + decoded_size), len - decoded_size);
decoded_size += len_dnn;
len_ie -= len_dnn;
// IEI and Length
uint16_t ie_len = 0;
int decoded_header_size = Type6NasIe::Decode(buf + decoded_size, len, is_iei);
if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_header_size;
ie_len = GetLengthIndicator();
uint8_t dnn_len = 0;
bstring dnn = {};
while (ie_len) {
DECODE_U8(buf + decoded_size, dnn_len, decoded_size);
ie_len--;
decode_bstring(&dnn, dnn_len, (buf + decoded_size), len - decoded_size);
decoded_size += dnn_len;
ie_len -= dnn_len;
LADN.insert(LADN.end(), dnn);
}
......@@ -115,6 +121,7 @@ int LADN_Indication::Decode(uint8_t* buf, int len, bool is_option) {
}
}
Logger::nas_mm().debug("Decoded LADN_Indication (len %d)", decoded_size);
Logger::nas_mm().debug(
"Decoded EPS_NAS_Message_Container (len %d)", decoded_size);
return decoded_size;
}
......@@ -22,6 +22,8 @@
#ifndef _LADN_Indication_H_
#define _LADN_Indication_H_
#include "Type6NasIe.hpp"
#include <stdint.h>
#include <iostream>
#include <vector>
......@@ -35,23 +37,23 @@ using namespace std;
constexpr uint8_t kLadnIndicationMinimumLength = 3;
constexpr uint16_t kLadnIndicationMaximumLength = 1715;
constexpr auto kLadnIndicationIeName = "LADN Indication";
namespace nas {
class LADN_Indication {
class LadnIndication : Type6NasIe {
public:
LADN_Indication();
LADN_Indication(uint8_t iei);
LADN_Indication(const uint8_t iei, std::vector<bstring> ladn);
~LADN_Indication();
void setValue(uint8_t iei);
LadnIndication();
LadnIndication(const std::vector<bstring>& ladn);
~LadnIndication();
// void SetValue(const std::vector<bstring>& ladn);
void GetValue(std::vector<bstring>& ladn);
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_option);
void getValue(std::vector<bstring>& ladn);
private:
uint8_t _iei;
uint16_t length;
std::vector<bstring> LADN;
};
......
......@@ -411,13 +411,13 @@ bool RegistrationRequest::getEpsNasMessageContainer(bstring& epsNas) {
//------------------------------------------------------------------------------
void RegistrationRequest::setLADN_Indication(std::vector<bstring> ladnValue) {
ie_ladn_indication = std::make_optional<LADN_Indication>(0x74, ladnValue);
ie_ladn_indication = std::make_optional<LadnIndication>(ladnValue);
}
//------------------------------------------------------------------------------
bool RegistrationRequest::getLadnIndication(std::vector<bstring>& ladnValue) {
if (ie_ladn_indication.has_value()) {
ie_ladn_indication.value().getValue(ladnValue);
ie_ladn_indication.value().GetValue(ladnValue);
return true;
} else {
return false;
......@@ -1036,11 +1036,11 @@ int RegistrationRequest::Decode(uint8_t* buf, int len) {
} break;
case 0x74: { // TODO: verify IEI value (spec Ox79)
Logger::nas_mm().debug("Decoding IEI(0x74)");
LADN_Indication ie_ladn_indication_tmp = {};
LadnIndication ie_ladn_indication_tmp = {};
decoded_size += ie_ladn_indication_tmp.Decode(
buf + decoded_size, len - decoded_size, true);
ie_ladn_indication =
std::optional<LADN_Indication>(ie_ladn_indication_tmp);
std::optional<LadnIndication>(ie_ladn_indication_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI 0x%x", octet);
} break;
......
......@@ -168,7 +168,7 @@ class RegistrationRequest : public NasMmPlainHeader {
std::optional<_5GS_DRX_Parameters> ie_5gs_drx_parameters; // Optional
std::optional<EPS_NAS_Message_Container>
ie_eps_nas_message_container; // Optional
std::optional<LADN_Indication> ie_ladn_indication; // Optional
std::optional<LadnIndication> ie_ladn_indication; // Optional
std::optional<Payload_Container_Type> ie_payload_container_type; // Optional
std::optional<Payload_Container> ie_payload_container; // Optional
std::optional<NetworkSlicingIndication>
......
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