Commit 90bc9a46 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update Allowed PDU Session Status

parent 11db0623
......@@ -90,8 +90,9 @@ constexpr uint8_t kIeiNetworkSlicingIndication = 0x09; // 9-(4 higher bits)
constexpr uint8_t kIeiMicoIndication = 0x0B; // B-(4 higher bits)
constexpr uint8_t kIei5gmmCapability = 0x10;
constexpr uint8_t kIeiUeStatus = 0x2b;
constexpr uint8_t kIei5gmmCapability = 0x10;
constexpr uint8_t kIeiAllowedPduSessionStatus = 0x25;
constexpr uint8_t kIeiUeStatus = 0x2b;
constexpr uint8_t kIeiUeSecurityCapability = 0x2e;
constexpr uint8_t kIeiUeNetworkCapability = 0x17;
......
......@@ -113,7 +113,7 @@ int _5GMMCapability::Decode(uint8_t* buf, int len, bool is_iei) {
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 < (li_ - 1); i++) {
for (int i = 0; i < (GetLengthIndicator() - 1); i++) {
DECODE_U8(buf + decoded_size, spare, decoded_size);
}
......
......@@ -264,17 +264,17 @@ int _5GSMobileIdentity::EncodeSuci(uint8_t* buf, int len) {
// Routing Indicator
encoded_size += EncodeRoutingIndicator(
supi_format_imsi_.value().routingIndicator, buf + encoded_size,
supi_format_imsi_.value().routing_indicator, buf + encoded_size,
len - encoded_size);
// Protection Scheme
ENCODE_U8(
buf + encoded_size, 0x0f & supi_format_imsi_.value().protectionSchemeId,
buf + encoded_size, 0x0f & supi_format_imsi_.value().protection_scheme_id,
encoded_size);
// Home Network Public Key Identifier
ENCODE_U8(
buf + encoded_size, supi_format_imsi_.value().homeNetworkPKI,
buf + encoded_size, supi_format_imsi_.value().home_network_pki,
encoded_size);
// MSIN
......@@ -339,7 +339,7 @@ int _5GSMobileIdentity::DecodeSuci(uint8_t* buf, int len, int ie_len) {
if (!digit[0] && digit[1] == 0x0f && digit[2] == 0x0f &&
digit[3] == 0x0f) {
supi_format_imsi_tmp.routingIndicator =
supi_format_imsi_tmp.routing_indicator =
std::nullopt; // No Routing Indicator is configured
Logger::nas_mm().debug("No Routing Indicator is configured");
} else {
......@@ -354,19 +354,19 @@ int _5GSMobileIdentity::DecodeSuci(uint8_t* buf, int len, int ie_len) {
"Decoded Routing Indicator is not BCD coding");
}
supi_format_imsi_tmp.routingIndicator =
supi_format_imsi_tmp.routing_indicator =
std::optional<std::string>(result);
Logger::nas_mm().debug(
"Decoded Routing Indicator %s",
supi_format_imsi_tmp.routingIndicator.value().c_str());
supi_format_imsi_tmp.routing_indicator.value().c_str());
}
// Protection scheme Id
DECODE_U8(buf + decoded_size, octet, decoded_size);
supi_format_imsi_tmp.protectionSchemeId = 0x0f & octet;
supi_format_imsi_tmp.protection_scheme_id = 0x0f & octet;
// Home network public key identifier
DECODE_U8(buf + decoded_size, octet, decoded_size);
supi_format_imsi_tmp.homeNetworkPKI = octet;
supi_format_imsi_tmp.home_network_pki = octet;
// MSIN
std::string msin = {};
......@@ -421,11 +421,11 @@ void _5GSMobileIdentity::SetSuciWithSupiImsi(
supi_format_imsi_tmp.supi_format = SUPI_FORMAT_IMSI;
supi_format_imsi_tmp.mcc = mcc;
supi_format_imsi_tmp.mnc = mnc;
supi_format_imsi_tmp.routingIndicator =
supi_format_imsi_tmp.routing_indicator =
std::optional<std::string>(routing_ind);
supi_format_imsi_tmp.protectionSchemeId = protection_sch_id;
supi_format_imsi_tmp.homeNetworkPKI = HOME_NETWORK_PKI_0_WHEN_PSI_0;
supi_format_imsi_tmp.msin = msin;
supi_format_imsi_tmp.protection_scheme_id = protection_sch_id;
supi_format_imsi_tmp.home_network_pki = HOME_NETWORK_PKI_0_WHEN_PSI_0;
supi_format_imsi_tmp.msin = msin;
SetLengthIndicator(10 + ceil(msin.length() / 2));
supi_format_imsi_ = std::optional<SUCI_imsi_t>(supi_format_imsi_tmp);
......
......@@ -68,9 +68,9 @@ typedef struct SUCI_imsi_s {
uint8_t supi_format : 3;
std::string mcc;
std::string mnc;
std::optional<std::string> routingIndicator; //"1234"
uint8_t protectionSchemeId : 4; // 0000
uint8_t homeNetworkPKI; // 00000000
std::optional<std::string> routing_indicator; //"1234"
uint8_t protection_scheme_id : 4; // 0000
uint8_t home_network_pki; // 00000000
std::string msin; // two types of coding; BCD & hexadecimal
} SUCI_imsi_t; // SUPI format "IMSI"
......
......@@ -21,6 +21,7 @@
#include "AllowedPDUSessionStatus.hpp"
#include "Ie_Const.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
......@@ -28,74 +29,95 @@
using namespace nas;
//------------------------------------------------------------------------------
AllowedPDUSessionStatus::AllowedPDUSessionStatus(uint8_t iei) {
_iei = iei;
length = 0;
AllowedPDUSessionStatus::AllowedPDUSessionStatus()
: Type4NasIe(kIeiAllowedPduSessionStatus) {
_value = 0;
SetLengthIndicator(2);
SetIeName(kAllowedPDUSessionStatusIeName);
}
//------------------------------------------------------------------------------
AllowedPDUSessionStatus::AllowedPDUSessionStatus(
const uint8_t iei, uint16_t value) {
_iei = iei;
AllowedPDUSessionStatus::AllowedPDUSessionStatus(uint16_t value)
: Type4NasIe(kIeiAllowedPduSessionStatus) {
_value = value;
length = 4;
SetLengthIndicator(2);
SetIeName(kAllowedPDUSessionStatusIeName);
}
//------------------------------------------------------------------------------
AllowedPDUSessionStatus::AllowedPDUSessionStatus()
: _iei(), length(), _value() {}
//------------------------------------------------------------------------------
AllowedPDUSessionStatus::~AllowedPDUSessionStatus() {}
//------------------------------------------------------------------------------
void AllowedPDUSessionStatus::setValue(uint8_t iei, uint16_t value) {
_iei = iei;
void AllowedPDUSessionStatus::SetValue(uint16_t value) {
_value = value;
}
uint16_t AllowedPDUSessionStatus::getValue() {
//------------------------------------------------------------------------------
uint16_t AllowedPDUSessionStatus::GetValue() const {
return _value;
}
//------------------------------------------------------------------------------
int AllowedPDUSessionStatus::encode2Buffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding AllowedPDUSessionStatus (IEI 0x%x)", _iei);
int AllowedPDUSessionStatus::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
int ie_len = GetIeLength();
if ((len < kAllowedPDUSessionStatusMinimumLength) or (len < length + 2)) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kAllowedPDUSessionStatusMinimumLength);
if (len < ie_len) {
Logger::nas_mm().error("Len is less than %d", ie_len);
return KEncodeDecodeError;
}
int encoded_size = 0;
if (_iei) {
ENCODE_U8(buf + encoded_size, _iei, encoded_size);
}
// IEI and Length
int encoded_header_size = Type4NasIe::Encode(buf + encoded_size, len);
if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
encoded_size += encoded_header_size;
ENCODE_U8(buf + encoded_size, length, encoded_size);
ENCODE_U16(buf + encoded_size, _value, encoded_size);
// TODO: Encode spare for the rest
uint8_t spare = 0;
int spare_len = ie_len - encoded_size;
for (int i = 0; i < spare_len; i++) {
ENCODE_U8(buf + encoded_size, spare, encoded_size);
}
Logger::nas_mm().debug(
"Encoded AllowedPDUSessionStatus (len %d)", encoded_size);
"Decoded %s, len (%d)", GetIeName().c_str(), encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int AllowedPDUSessionStatus::decodeFromBuffer(
uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug("Decoding AllowedPDUSessionStatus");
int decoded_size = 0;
if (is_option) {
DECODE_U8(buf + decoded_size, _iei, decoded_size);
int AllowedPDUSessionStatus::Decode(uint8_t* buf, int len, bool is_iei) {
if (len < kAllowedPDUSessionStatusMinimumLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kAllowedPDUSessionStatusMinimumLength);
return KEncodeDecodeError;
}
DECODE_U8(buf + decoded_size, length, decoded_size);
uint8_t decoded_size = 0;
uint8_t octet = 0;
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
// IEI and Length
int decoded_header_size = Type4NasIe::Decode(buf + decoded_size, len, is_iei);
// decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_iei);
if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_header_size;
DECODE_U16(buf + decoded_size, _value, decoded_size);
// TODO: decode the rest as spare for now
uint8_t spare = 0;
int spare_len = GetLengthIndicator() - sizeof(uint16_t);
for (int i = 0; i < spare_len; i++) {
DECODE_U8(buf + decoded_size, spare, decoded_size);
}
Logger::nas_mm().debug(
"Decoded AllowedPDUSessionStatus (value 0x%4x)", _value);
"Decoded %s (value 0x%4x)", GetIeName().c_str(), _value);
Logger::nas_mm().debug(
"Decoded AllowedPDUSessionStatus (len %d)", decoded_size);
"Decoded %s, len (%d)", GetIeName().c_str(), decoded_size);
return decoded_size;
}
......@@ -22,27 +22,29 @@
#ifndef _ALLOWED_PDU_SESSION_STATUS_H_
#define _ALLOWED_PDU_SESSION_STATUS_H_
#include "Type4NasIe.hpp"
#include <stdint.h>
constexpr uint8_t kAllowedPDUSessionStatusMinimumLength = 4;
constexpr uint8_t kAllowedPDUSessionStatusMaximumLength = 34;
constexpr auto kAllowedPDUSessionStatusIeName = "Allowed PDU Session Status";
namespace nas {
class AllowedPDUSessionStatus {
class AllowedPDUSessionStatus : public Type4NasIe {
public:
AllowedPDUSessionStatus();
AllowedPDUSessionStatus(uint8_t iei);
AllowedPDUSessionStatus(const uint8_t iei, uint16_t value);
AllowedPDUSessionStatus(uint16_t value);
~AllowedPDUSessionStatus();
void setValue(uint8_t iei, uint16_t value);
int encode2Buffer(uint8_t* buf, int len);
int decodeFromBuffer(uint8_t* buf, int len, bool is_option);
uint16_t getValue();
void SetValue(uint16_t value);
uint16_t GetValue() const;
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_iei);
private:
uint8_t _iei;
uint8_t length;
uint16_t _value;
// TODO: spare
};
......
......@@ -352,14 +352,14 @@ bool RegistrationRequest::getUeStatus(uint8_t& n1ModeReg, uint8_t& s1ModeReg) {
//------------------------------------------------------------------------------
void RegistrationRequest::setAllowedPDUSessionStatus(uint16_t value) {
ie_allowed_PDU_session_status = std::make_optional<AllowedPDUSessionStatus>(
0x25, value); // TODO: remove hardcoded value
ie_allowed_PDU_session_status =
std::make_optional<AllowedPDUSessionStatus>(value);
}
//------------------------------------------------------------------------------
uint16_t RegistrationRequest::getAllowedPduSessionStatus() {
if (ie_allowed_PDU_session_status.has_value()) {
return ie_allowed_PDU_session_status.value().getValue();
return ie_allowed_PDU_session_status.value().GetValue();
} else {
return 0;
}
......@@ -704,7 +704,7 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) {
if (!ie_allowed_PDU_session_status.has_value()) {
Logger::nas_mm().warn("IE ie_allowed_PDU_session_status is not available");
} else {
if (int size = ie_allowed_PDU_session_status.value().encode2Buffer(
if (int size = ie_allowed_PDU_session_status.value().Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
......@@ -998,7 +998,7 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) {
case 0x25: {
Logger::nas_mm().debug("Decoding IEI(0x25)");
AllowedPDUSessionStatus ie_allowed_PDU_session_status_tmp = {};
decoded_size += ie_allowed_PDU_session_status_tmp.decodeFromBuffer(
decoded_size += ie_allowed_PDU_session_status_tmp.Decode(
buf + decoded_size, len - decoded_size, true);
ie_allowed_PDU_session_status = std::optional<AllowedPDUSessionStatus>(
ie_allowed_PDU_session_status_tmp);
......
......@@ -84,7 +84,7 @@ void ServiceRequest::setPDU_session_status(uint16_t value) {
//------------------------------------------------------------------------------
void ServiceRequest::setAllowed_PDU_Session_Status(uint16_t value) {
ie_allowed_PDU_session_status = new AllowedPDUSessionStatus(0x25, value);
ie_allowed_PDU_session_status = new AllowedPDUSessionStatus(value);
}
//------------------------------------------------------------------------------
......@@ -161,7 +161,7 @@ int ServiceRequest::encode2Buffer(uint8_t* buf, int len) {
if (!ie_allowed_PDU_session_status) {
Logger::nas_mm().warn("IE ie_allowed_PDU_session_status is not available");
} else {
size = ie_allowed_PDU_session_status->encode2Buffer(
size = ie_allowed_PDU_session_status->Encode(
buf + encoded_size, len - encoded_size);
if (size != 0) {
encoded_size += size;
......@@ -223,11 +223,12 @@ int ServiceRequest::decodeFromBuffer(
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
case 0x25: {
case kIeiAllowedPduSessionStatus: {
Logger::nas_mm().debug(
"Decoding ie_allowed_PDU_session_status (IEI: 0x25)");
"Decoding ie_allowed_PDU_session_status, IEI 0x%x",
kIeiAllowedPduSessionStatus);
ie_allowed_PDU_session_status = new AllowedPDUSessionStatus();
decoded_size += ie_allowed_PDU_session_status->decodeFromBuffer(
decoded_size += ie_allowed_PDU_session_status->Decode(
buf + decoded_size, len - decoded_size, true);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
......@@ -279,7 +280,7 @@ uint16_t ServiceRequest::getPduSessionStatus() {
//------------------------------------------------------------------------------
uint16_t ServiceRequest::getAllowedPduSessionStatus() {
if (ie_allowed_PDU_session_status) {
return ie_allowed_PDU_session_status->getValue();
return ie_allowed_PDU_session_status->GetValue();
} else {
return 0;
}
......
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