Commit 6e336ecb authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Code cleanup for Registration Request

parent 9f43c107
......@@ -1050,7 +1050,7 @@ void amf_n1::registration_request_handle(
// Check 5gs Mobility Identity (Mandatory IE)
std::string guti = {};
uint8_t mobility_id_type = registration_request->getMobilityIdentityType();
uint8_t mobility_id_type = registration_request->getMobileIdentityType();
switch (mobility_id_type) {
case SUCI: {
nas::SUCI_imsi_t imsi = {};
......
......@@ -56,7 +56,7 @@ 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);
return 0;
return KEncodeDecodeError;
}
int encoded_size = 0;
......@@ -80,12 +80,10 @@ int _5GMMCapability::encode2Buffer(uint8_t* buf, int len) {
//------------------------------------------------------------------------------
int _5GMMCapability::decodeFromBuffer(uint8_t* buf, int len, bool is_option) {
if ((len < k5gmmCapabilityMinimumLength) or
(len > k5gmmCapabilityMaximumLength)) {
if (len < k5gmmCapabilityMinimumLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum/or greater than the maximum "
"length of this IE (Min %d octet, Max %d octet)",
k5gmmCapabilityMinimumLength, k5gmmCapabilityMaximumLength);
"Buffer length is less than the minimum length of this IE (%d octet)",
k5gmmCapabilityMinimumLength);
return KEncodeDecodeError;
}
......
......@@ -19,16 +19,12 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "UESecurityCapability.hpp"
#include "logger.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
using namespace nas;
//------------------------------------------------------------------------------
......@@ -62,7 +58,7 @@ UESecurityCapability::UESecurityCapability(
_5g_IASel = _5gg_IASel;
EEASel = 0;
EIASel = 0;
length = 2;
length = kUESecurityCapabilityMinimumLength;
}
//------------------------------------------------------------------------------
......@@ -74,7 +70,7 @@ UESecurityCapability::UESecurityCapability(
_5g_IASel = _5gg_IASel;
EEASel = _EEASel;
EIASel = _EIASel;
length = 4;
length = kUESecurityCapabilityMaximumLength;
}
//------------------------------------------------------------------------------
......@@ -119,7 +115,8 @@ uint8_t UESecurityCapability::getEIASel() {
//------------------------------------------------------------------------------
void UESecurityCapability::setLength(uint8_t len) {
if ((len > 0) && (len <= 4)) {
if ((len >= kUESecurityCapabilityMinimumLength) &&
(len <= kUESecurityCapabilityMaximumLength)) {
length = len;
} else {
Logger::nas_mm().debug("Set UESecurityCapability Length fail %d", len);
......@@ -136,66 +133,64 @@ uint8_t UESecurityCapability::getLength() {
//------------------------------------------------------------------------------
int UESecurityCapability::encode2Buffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding UESecurityCapability IEI 0x%x", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
if (len < (length + 2)) { // Length of the content + IEI/Len
Logger::nas_mm().error(
"Size of the buffer is not enough to store this IE (IE len %d)",
length + 2);
return KEncodeDecodeError;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei;
encoded_size++;
*(buf + encoded_size) = length;
encoded_size++;
*(buf + encoded_size) = _5g_EASel;
encoded_size++;
*(buf + encoded_size) = _5g_IASel;
encoded_size++;
if (length == 4) {
*(buf + encoded_size) = EEASel; // 0xf0; //TODO: remove hardcoded value
encoded_size++;
*(buf + encoded_size) = EIASel; // 0x70; //TODO: remove hardcoded value
encoded_size++;
}
} else {
*(buf + encoded_size) = length;
encoded_size++;
*(buf + encoded_size) = _5g_EASel;
encoded_size++;
*(buf + encoded_size) = _5g_IASel;
encoded_size++;
if (length == 4) {
*(buf + encoded_size) = EEASel; // 0xf0; //TODO: remove hardcoded value
encoded_size++;
*(buf + encoded_size) = EIASel; // 0x70; //TODO: remove hardcoded value
encoded_size++;
}
ENCODE_U8(buf + encoded_size, _iei, encoded_size);
}
// Length
ENCODE_U8(buf + encoded_size, length, encoded_size);
// EA
ENCODE_U8(buf + encoded_size, _5g_EASel, encoded_size);
// IA
ENCODE_U8(buf + encoded_size, _5g_IASel, encoded_size);
if (length == 4) {
// EEA
ENCODE_U8(buf + encoded_size, EEASel, encoded_size);
// EIA
ENCODE_U8(buf + encoded_size, EIASel, encoded_size);
}
Logger::nas_mm().debug("encoded UESecurityCapability (len %d)", encoded_size);
Logger::nas_mm().debug("Encoded UESecurityCapability (len %d)", encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int UESecurityCapability::decodeFromBuffer(
uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug("Decoding UESecurityCapability IEI 0x%x", *buf);
Logger::nas_mm().debug("Decoding UESecurityCapability");
if (len < kUESecurityCapabilityMinimumLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kUESecurityCapabilityMinimumLength);
return KEncodeDecodeError;
}
int decoded_size = 0;
if (is_option) {
decoded_size++;
DECODE_U8(buf + decoded_size, _iei, decoded_size);
}
length = *(buf + decoded_size);
decoded_size++;
_5g_EASel = *(buf + decoded_size);
decoded_size++;
_5g_IASel = *(buf + decoded_size);
decoded_size++;
// Length
DECODE_U8(buf + decoded_size, length, decoded_size);
// EA
DECODE_U8(buf + decoded_size, _5g_EASel, decoded_size);
// IA
DECODE_U8(buf + decoded_size, _5g_IASel, decoded_size);
if (length >= 4) {
EEASel = *(buf + decoded_size);
decoded_size++;
EIASel = *(buf + decoded_size);
decoded_size++;
decoded_size += (length - 4); // TODO: decoding EEA EIA
// EEA
DECODE_U8(buf + decoded_size, EEASel, decoded_size);
// EIA
DECODE_U8(buf + decoded_size, EIASel, decoded_size);
decoded_size += (length - 4); // TODO: Spare
}
Logger::nas_mm().debug(
"UESecurityCapability (length %d) EA 0x%x,IA 0x%x, EEA 0x%x, EIA 0x%x,",
......
......@@ -19,18 +19,14 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _UESecurityCapability_H
#define _UESecurityCapability_H
#ifndef _UE_SECURITY_CAPABILITY_H
#define _UE_SECURITY_CAPABILITY_H
#include <stdint.h>
constexpr uint8_t kUESecurityCapabilityMinimumLength = 2;
constexpr uint8_t kUESecurityCapabilityMaximumLength = 4;
namespace nas {
class UESecurityCapability {
......@@ -60,7 +56,7 @@ class UESecurityCapability {
private:
uint8_t _iei;
uint8_t length;
uint8_t length; // Length of UE security capability contents
uint8_t _5g_EASel;
uint8_t _5g_IASel;
uint8_t EEASel;
......
This diff is collapsed.
......@@ -51,7 +51,8 @@ class RegistrationRequest : public NasMmPlainHeader {
void setngKSI(uint8_t tsc, uint8_t key_set_id);
bool getngKSI(uint8_t& ng_ksi);
uint8_t getMobilityIdentityType();
uint8_t getMobileIdentityType();
// TODO: SetMobileIdentityType(uint8_t);
void setSUCI_SUPI_format_IMSI(
const string mcc, const string mnc, const string routingInd,
......@@ -149,11 +150,11 @@ class RegistrationRequest : public NasMmPlainHeader {
// NasMmPlainHeader* plain_header;
_5GSRegistrationType ie_5gsregistrationtype; // Mandatory
NasKeySetIdentifier ie_ngKSI; // Mandatory
_5GSMobileIdentity ie_5gs_mobility_id; // Mandatory
_5GSMobileIdentity ie_5gs_mobile_identity; // Mandatory
std::optional<NasKeySetIdentifier> ie_non_current_native_nas_ksi; // Optional
std::optional<_5GMMCapability> ie_5g_mm_capability; // Optional
UESecurityCapability* ie_ue_security_capability; // Optional
std::optional<UESecurityCapability> ie_ue_security_capability; // Optional
NSSAI* ie_requested_NSSAI; // Optional
// TODO: Last visited registered TAI
UENetworkCapability* ie_s1_ue_network_capability; // Optional
......
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