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

Code cleanup for NAS MM Header

parent ee09cb41
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef FILE_3GPP_24_007_SEEN
#define FILE_3GPP_24_007_SEEN
#include <stdint.h>
// Extended Protocol Discriminator (EPD)
constexpr uint8_t kEpd5gsSessionManagementMessage = 0b00101110;
constexpr uint8_t kEpd5gsMobilityManagementMessage = 0b01111110;
#endif
......@@ -22,6 +22,8 @@
#ifndef _3GPP_TS_24501_H_
#define _3GPP_TS_24501_H_
#include "3gpp24.007.hpp"
#include <string>
#include <vector>
......@@ -185,4 +187,6 @@ static const std::vector<std::string> nas_ciphering_algorithm_list_e2str = {
#define NAS_MESSAGE_MIN_LENGTH 3
constexpr uint8_t KEncodeDecodeError = 0;
#endif
......@@ -19,6 +19,7 @@
* contact@openairinterface.org
*/
#include "NasMmPlainHeader.hpp"
#include "5GMMCapability.hpp"
#include "5GSMobilityIdentity.hpp"
#include "5GSRegistrationType.hpp"
......@@ -78,6 +79,5 @@
#include "_5GS_Registration_Result.hpp"
#include "_5GS_Tracking_Area_Identity.hpp"
#include "_5GS_Update_Type.hpp"
#include "nas_mm_plain_header.hpp"
#include "struct.hpp"
#include "Ie_Const.hpp"
......@@ -19,26 +19,54 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "ExtendedProtocolDiscriminator.hpp"
#include "3gpp_ts24501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
void ExtendedProtocolDiscriminator::setValue(const uint8_t epd) {
m_epd = epd;
ExtendedProtocolDiscriminator::ExtendedProtocolDiscriminator() {}
//------------------------------------------------------------------------------
ExtendedProtocolDiscriminator::~ExtendedProtocolDiscriminator() {}
//------------------------------------------------------------------------------
void ExtendedProtocolDiscriminator::Set(const uint8_t& epd) {
epd_ = epd;
}
//------------------------------------------------------------------------------
uint8_t ExtendedProtocolDiscriminator::getValue() {
return m_epd;
void ExtendedProtocolDiscriminator::Get(uint8_t& epd) const {
epd = epd_;
}
//------------------------------------------------------------------------------
void ExtendedProtocolDiscriminator::encode2buffer(uint8_t* buf, int len) {}
uint8_t ExtendedProtocolDiscriminator::Get() const {
return epd_;
}
//------------------------------------------------------------------------------
uint32_t ExtendedProtocolDiscriminator::Encode(uint8_t* buf, uint32_t len) {
if (len < kEdpIeSize) {
Logger::nas_mm().error("Buffer length is less than %d octet", kEdpIeSize);
return KEncodeDecodeError;
}
uint32_t encoded_size = 0;
ENCODE_U8(buf, epd_, encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
uint32_t ExtendedProtocolDiscriminator::Decode(
const uint8_t* const buf, uint32_t len) {
if (len < kEdpIeSize) {
Logger::nas_mm().error("Buffer length is less than %s octet", kEdpIeSize);
return KEncodeDecodeError;
}
uint32_t decoded_size = 0;
DECODE_U8(buf, epd_, decoded_size);
return decoded_size;
}
......@@ -19,28 +19,29 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _EPD_H_
#define _EPD_H_
#ifndef EXTENDED_PROTOCOL_DISCRIMINATOR_H_
#define EXTENDED_PROTOCOL_DISCRIMINATOR_H_
#include <stdint.h>
constexpr uint8_t kEdpIeSize = 1;
namespace nas {
class ExtendedProtocolDiscriminator {
public:
void encode2buffer(uint8_t* buf, int len);
void setValue(const uint8_t epd);
uint8_t getValue();
ExtendedProtocolDiscriminator();
virtual ~ExtendedProtocolDiscriminator();
void Set(const uint8_t& epd);
void Get(uint8_t& epd) const;
uint8_t Get() const;
uint32_t Encode(uint8_t* buf, uint32_t len);
uint32_t Decode(const uint8_t* const buf, uint32_t len);
private:
uint8_t m_epd;
uint8_t epd_;
};
} // namespace nas
......
......@@ -32,7 +32,7 @@
#include <vector>
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -19,23 +19,55 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "NasMessageType.hpp"
#include "3gpp_ts24501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
void NasMessageType::setValue(const uint8_t type) {
m_type = type;
NasMessageType::NasMessageType() {}
//------------------------------------------------------------------------------
NasMessageType::~NasMessageType() {}
//------------------------------------------------------------------------------
void NasMessageType::Set(const uint8_t& message_type) {
message_type_ = message_type;
}
//------------------------------------------------------------------------------
void NasMessageType::Get(uint8_t& message_type) const {
message_type = message_type_;
}
//------------------------------------------------------------------------------
uint8_t NasMessageType::Get() const {
return message_type_;
}
//------------------------------------------------------------------------------
uint32_t NasMessageType::Encode(uint8_t* buf, uint32_t len) {
if (len < kNasMessageTypeIeSize) {
Logger::nas_mm().error(
"Buffer length is less than %d octet", kNasMessageTypeIeSize);
return KEncodeDecodeError;
}
uint32_t encoded_size = 0;
ENCODE_U8(buf, message_type_, encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
uint8_t NasMessageType::getValue() {
return m_type;
uint32_t NasMessageType::Decode(const uint8_t* const buf, uint32_t len) {
if (len < kNasMessageTypeIeSize) {
Logger::nas_mm().error(
"Buffer length is less than %s octet", kNasMessageTypeIeSize);
return KEncodeDecodeError;
}
uint32_t decoded_size = 0;
DECODE_U8(buf, message_type_, decoded_size);
return decoded_size;
}
......@@ -19,27 +19,29 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _MESSAGE_TYPE_H_
#define _MESSAGE_TYPE_H_
#include <stdint.h>
constexpr uint8_t kNasMessageTypeIeSize = 1;
namespace nas {
class NasMessageType {
public:
void setValue(const uint8_t type);
uint8_t getValue();
NasMessageType();
virtual ~NasMessageType();
void Set(const uint8_t& message_type);
void Get(uint8_t& message_type) const;
uint8_t Get() const;
uint32_t Encode(uint8_t* buf, uint32_t len);
uint32_t Decode(const uint8_t* const buf, uint32_t len);
private:
uint8_t m_type;
uint8_t message_type_;
};
} // namespace nas
......
......@@ -33,7 +33,7 @@
#include <iostream>
#include <vector>
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
extern "C" {
#include "TLVDecoder.h"
#include "TLVEncoder.h"
......
......@@ -31,7 +31,7 @@
#include <stdint.h>
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
#include <optional>
namespace nas {
......
......@@ -19,23 +19,64 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "SecurityHeaderType.hpp"
#include "3gpp_ts24501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
void SecurityHeaderType::setValue(const uint8_t value) {
secu_header_type = 0x0f & value;
SecurityHeaderType::SecurityHeaderType() {}
//------------------------------------------------------------------------------
SecurityHeaderType::~SecurityHeaderType() {}
//------------------------------------------------------------------------------
void SecurityHeaderType::Set(
const uint8_t& secu_header_type, const uint8_t& spare) {
secu_header_type_ = 0x0f & secu_header_type;
spare_ = spare & 0xf0;
}
//------------------------------------------------------------------------------
void SecurityHeaderType::Get(uint8_t& secu_header_type) const {
secu_header_type = secu_header_type_ & 0x0f;
}
//------------------------------------------------------------------------------
uint8_t SecurityHeaderType::getValue() {
return secu_header_type & 0x0f;
uint8_t SecurityHeaderType::Get() const {
return (secu_header_type_ & 0x0f);
}
//------------------------------------------------------------------------------
uint32_t SecurityHeaderType::Encode(uint8_t* buf, uint32_t len) {
if (len < kSecurityHeaderIeSize) {
Logger::nas_mm().error(
"Buffer length is less than %d octet", kSecurityHeaderIeSize);
return KEncodeDecodeError;
}
uint8_t value = (secu_header_type_ & 0x0f) | (spare_ & 0xf0);
uint32_t encoded_size = 0;
ENCODE_U8(buf, value, encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
uint32_t SecurityHeaderType::Decode(const uint8_t* const buf, uint32_t len) {
if (len < kSecurityHeaderIeSize) {
Logger::nas_mm().error(
"Buffer length is less than %s octet", kSecurityHeaderIeSize);
return KEncodeDecodeError;
}
uint8_t value;
uint32_t decoded_size = 0;
DECODE_U8(buf, value, decoded_size);
secu_header_type_ = 0x0f & value;
spare_ = value & 0xf0;
return decoded_size;
}
......@@ -19,27 +19,30 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _SECURITY_HEADER_TYPE_H_
#define _SECURITY_HEADER_TYPE_H_
#include <stdint.h>
constexpr uint8_t kSecurityHeaderIeSize = 1;
namespace nas {
class SecurityHeaderType {
public:
void setValue(const uint8_t value);
uint8_t getValue();
SecurityHeaderType();
virtual ~SecurityHeaderType();
void Set(const uint8_t& secu_header_type, const uint8_t& spare = 0);
void Get(uint8_t& secu_header_type) const;
uint8_t Get() const;
uint32_t Encode(uint8_t* buf, uint32_t len);
uint32_t Decode(const uint8_t* const buf, uint32_t len);
private:
uint8_t secu_header_type : 4;
uint8_t spare_ : 4;
uint8_t secu_header_type_ : 4;
};
} // namespace nas
......
......@@ -29,7 +29,7 @@
#ifndef _AuthenticationFailure_H_
#define _AuthenticationFailure_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _AuthenticationReject_H_
#define _AuthenticationReject_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _AuthenticationRequest_H_
#define _AuthenticationRequest_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _AuthenticationResponse_H_
#define _AuthenticationResponse_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _AuthenticationResult_H_
#define _AuthenticationResult_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _DLNASTransport_H_
#define _DLNASTransport_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _DEREGISTRATION_ACCEPT_H_
#define _DEREGISTRATION_ACCEPT_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _DEREGISTRATION_REQUEST_H_
#define _DEREGISTRATION_REQUEST_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
using namespace std;
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _IdentityRequest_H_
#define _IdentityRequest_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _IdentityResponse_H_
#define _IdentityResponse_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -19,85 +19,118 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "nas_mm_plain_header.hpp"
#include "3gpp_ts24501.hpp"
#include "common_defs.h"
#include "logger.hpp"
#include "NasMmPlainHeader.hpp"
using namespace nas;
//------------------------------------------------------------------------------
void NasMmPlainHeader::setEpdIE(const uint8_t epd) {
ie_epd.setValue(epd);
void NasMmPlainHeader::SetEpd(const uint8_t epd) {
epd_.Set(epd);
}
//------------------------------------------------------------------------------
uint8_t NasMmPlainHeader::getEpdIE() {
return ie_epd.getValue();
uint8_t NasMmPlainHeader::GetEpd() {
return epd_.Get();
}
//------------------------------------------------------------------------------
void NasMmPlainHeader::setSecurityHeaderTypeIE(const uint8_t type) {
ie_secu_header_type.setValue(type);
void NasMmPlainHeader::SetSecurityHeaderType(const uint8_t type) {
secu_header_type_.Set(type);
}
//------------------------------------------------------------------------------
uint8_t NasMmPlainHeader::getSecurityHeaderTypeIE() {
return ie_secu_header_type.getValue();
uint8_t NasMmPlainHeader::GetSecurityHeaderType() {
return secu_header_type_.Get();
}
//------------------------------------------------------------------------------
void NasMmPlainHeader::setMessageTypeIE(const uint8_t type) {
ie_msg_type.setValue(type);
void NasMmPlainHeader::SetMessageType(const uint8_t type) {
msg_type_.Set(type);
}
//------------------------------------------------------------------------------
uint8_t NasMmPlainHeader::getMessageType() {
return msg_type;
uint8_t NasMmPlainHeader::GetMessageType() {
return msg_type_.Get();
}
//------------------------------------------------------------------------------
void NasMmPlainHeader::setHeader(
uint8_t epd_, uint8_t security_header_type, uint8_t msg_type_) {
epd = epd_;
secu_header_type = security_header_type;
msg_type = msg_type_;
const uint8_t& epd, const uint8_t& security_header_type,
const uint8_t& msg_type) {
epd_.Set(epd);
secu_header_type_.Set(security_header_type);
msg_type_.Set(msg_type);
}
//------------------------------------------------------------------------------
int NasMmPlainHeader::encode2buffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding NasMmPlainHeader");
if (len < 3) {
if (len < kNasMmPlainHeaderLength) {
Logger::nas_mm().error("buffer length is less than 3 octets");
return 0;
return KEncodeDecodeError;
} else {
*(buf++) = epd;
*(buf++) = secu_header_type;
*(buf++) = msg_type;
Logger::nas_mm().debug("Encoded NasMmPlainHeader (len 3 octets)");
return 3;
uint32_t encoded_size = 0;
uint32_t size = 0;
if ((size = epd_.Encode(buf + encoded_size, len - encoded_size)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Encode NAS MM Header IE error");
return KEncodeDecodeError;
}
encoded_size += size;
if ((size = secu_header_type_.Encode(
buf + encoded_size, len - encoded_size)) == KEncodeDecodeError) {
Logger::nas_mm().error("Encode NAS MM Header IE error");
return KEncodeDecodeError;
}
encoded_size += size;
if ((size = msg_type_.Encode(buf + encoded_size, len - encoded_size)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Encode NAS MM Header IE error");
return KEncodeDecodeError;
}
encoded_size += size;
Logger::nas_mm().debug(
"Encoded NasMmPlainHeader (len %d octets)", encoded_size);
return encoded_size;
}
}
//------------------------------------------------------------------------------
int NasMmPlainHeader::decodefrombuffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("decoding NasMmPlainHeader");
if (len < 3) {
Logger::nas_mm().error(
"[decoding nas mm header error][buffer length is less than 3 octets]");
return 0;
int NasMmPlainHeader::decodefrombuffer(const uint8_t* const buf, int len) {
Logger::nas_mm().debug("Decoding NasMmPlainHeader");
uint32_t decoded_size = 0;
if (len < kNasMmPlainHeaderLength) {
Logger::nas_mm().error("Buffer length is less than 3 octets");
return KEncodeDecodeError;
} else {
epd = *(buf++);
secu_header_type = *(buf++);
msg_type = *(buf++);
uint32_t size = 0;
if ((size = epd_.Decode(buf + decoded_size, len - decoded_size)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
if ((size = secu_header_type_.Decode(
buf + decoded_size, len - decoded_size)) == KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
if ((size = msg_type_.Decode(buf + decoded_size, len - decoded_size)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
}
Logger::nas_mm().debug("decoded NasMmPlainHeader len(3 octets)");
return 3;
Logger::nas_mm().debug(
"decoded NasMmPlainHeader len (%d octets)", decoded_size);
return decoded_size;
}
......@@ -19,13 +19,6 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _NAS_MM_PLAIN_HEADER_H_
#define _NAS_MM_PLAIN_HEADER_H_
......@@ -33,27 +26,33 @@
#include "NasMessageType.hpp"
#include "SecurityHeaderType.hpp"
constexpr uint8_t kNasMmPlainHeaderLength = 3;
namespace nas {
class NasMmPlainHeader {
public:
void setHeader(uint8_t epd_, uint8_t security_header_type, uint8_t msg_type_);
void setHeader(
const uint8_t& epd, const uint8_t& security_header_type,
const uint8_t& msg_type);
int encode2buffer(uint8_t* buf, int len);
int decodefrombuffer(uint8_t* buf, int len);
void setEpdIE(const uint8_t epd);
void setSecurityHeaderTypeIE(const uint8_t type);
void setMessageTypeIE(const uint8_t type);
uint8_t getEpdIE();
uint8_t getSecurityHeaderTypeIE();
uint8_t getMessageType();
int decodefrombuffer(const uint8_t* const buf, int len);
void SetEpd(const uint8_t epd);
uint8_t GetEpd();
void SetSecurityHeaderType(const uint8_t type);
uint8_t GetSecurityHeaderType();
void SetMessageType(const uint8_t type);
uint8_t GetMessageType();
private:
ExtendedProtocolDiscriminator ie_epd;
SecurityHeaderType ie_secu_header_type;
NasMessageType ie_msg_type;
uint8_t epd;
uint8_t secu_header_type;
uint8_t msg_type;
ExtendedProtocolDiscriminator epd_; // Mandatory
// TODO: Spare half octet (1/2 octet)
SecurityHeaderType secu_header_type_; // Mandatory (1/2 octet)
NasMessageType msg_type_; // Mandatory
};
} // namespace nas
......
......@@ -29,7 +29,7 @@
#ifndef _RegistrationAccept_H_
#define _RegistrationAccept_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _RegistrationComplete_H_
#define _RegistrationComplete_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _RegistrationReject_H_
#define _RegistrationReject_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -36,7 +36,7 @@
#include <string>
#include <vector>
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
using namespace std;
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _SecurityModeCommand_H_
#define _SecurityModeCommand_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _SecurityModeComplete_H_
#define _SecurityModeComplete_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -29,7 +29,7 @@
#ifndef _SecurityModeReject_H_
#define _SecurityModeReject_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -33,7 +33,7 @@
#include <string>
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
......@@ -32,7 +32,7 @@
#include <string>
#include "bstrlib.h"
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
using namespace std;
......
......@@ -29,7 +29,7 @@
#ifndef _ULNASTransport_H_
#define _ULNASTransport_H_
#include "nas_ie_header.hpp"
#include "NasIeHeader.hpp"
namespace nas {
......
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