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

Update Allowed PDU Session Status

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