Commit 360eb958 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update 5GSTrackingAreaIdList

parent b4e76614
......@@ -18,56 +18,84 @@
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "_5GSTrackingAreaIdList.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "Ie_Const.hpp"
#include "logger.hpp"
#include "String2Value.hpp"
#include "NasUtils.hpp"
using namespace nas;
//------------------------------------------------------------------------------
_5GSTrackingAreaIdList::_5GSTrackingAreaIdList()
: Type4NasIe(kIei5gsTrackingAreaIdentityList), m_tai_list() {
SetLengthIndicator(
k5gsTrackingAreaIdListMinimumLength -
2); // Minimim length - 2 bytes for header
SetIeName(k5gsTrackingAreaIdListIeName);
}
//------------------------------------------------------------------------------
_5GSTrackingAreaIdList::_5GSTrackingAreaIdList(
uint8_t iei, std::vector<p_tai_t> tai_list) {
const std::vector<p_tai_t>& tai_list)
: Type4NasIe(kIei5gsTrackingAreaIdentityList) {
m_tai_list = tai_list;
m_iei = iei;
length = 0; // TODO:
// Don't know Length Indicator for now
SetIeName(k5gsTrackingAreaIdListIeName);
}
//------------------------------------------------------------------------------
int _5GSTrackingAreaIdList::Encode(uint8_t* buf, int len) {
int encoded_size = 0;
int len_pos = 0;
if (m_iei) {
ENCODE_U8(buf + encoded_size, m_iei, encoded_size); // IEI
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
int ie_len = GetIeLength();
if (len < ie_len) {
Logger::nas_mm().error("Len is less than %d", ie_len);
return KEncodeDecodeError;
}
len_pos = encoded_size; // position to encode Length
encoded_size++; // for length octet later on
int encoded_size = 0;
// IEI and Length
int len_pos = 0;
int encoded_header_size =
Type4NasIe::Encode(buf + encoded_size, len, len_pos);
if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
encoded_size += encoded_header_size;
for (int i = 0; i < m_tai_list.size(); i++) {
int item_len = 0;
switch (m_tai_list[i].type) {
case 0x00: {
item_len += encode_00_type(
int encode_00_type_size = encode_00_type(
m_tai_list[i], buf + encoded_size, len - encoded_size);
if (encode_00_type_size == KEncodeDecodeError) break;
item_len += encode_00_type_size;
} break;
case 0x01: {
item_len += encode_01_type(
int encode_01_type_size = encode_01_type(
m_tai_list[i], buf + encoded_size, len - encoded_size);
if (encode_01_type_size == KEncodeDecodeError) break;
item_len += encode_01_type_size;
} break;
case 0x10: {
item_len += encode_10_type(
int encode_10_type_size = encode_10_type(
m_tai_list[i], buf + encoded_size, len - encoded_size);
if (encode_10_type_size == KEncodeDecodeError) break;
item_len += encode_10_type_size;
} break;
}
encoded_size += item_len;
length += item_len;
}
//*(buf + encoded_size - length - 1) = length;
uint8_t encoded_size_ie = 0;
ENCODE_U8(buf + len_pos, length, encoded_size_ie);
// Encode length
int encoded_len_ie = 0;
ENCODE_U8(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;
}
......@@ -75,9 +103,10 @@ int _5GSTrackingAreaIdList::Encode(uint8_t* buf, int len) {
int _5GSTrackingAreaIdList::encode_00_type(
p_tai_t item, uint8_t* buf, int len) {
int encoded_size = 0;
uint8_t octet = 0x00 | ((item.tac_list.size() - 1) &
// Type of list/Number of elements
uint8_t octet = 0x00 | ((item.tac_list.size() - 1) &
0x1f); // see Table 9.11.3.9.1@3GPP TS 24.501 V16.1.0
ENCODE_U8(buf + encoded_size, octet, encoded_size); // IEI
ENCODE_U8(buf + encoded_size, octet, encoded_size);
// Encode PLMN
encoded_size += NasUtils::encodeMccMnc2Buffer(
......@@ -86,15 +115,7 @@ int _5GSTrackingAreaIdList::encode_00_type(
// Encode TAC list
for (int i = 0; i < item.tac_list.size(); i++) {
// TODO: use ENCODE_U24
ENCODE_U24(buf + encoded_size, item.tac_list[i], encoded_size);
/*
octet = (item.tac_list[i] & 0x00ff0000) >> 16;
ENCODE_U8(buf + encoded_size, octet, encoded_size);
octet = (item.tac_list[i] & 0x0000ff00) >> 8;
ENCODE_U8(buf + encoded_size, octet, encoded_size);
octet = (item.tac_list[i] & 0x000000ff) >> 0;
ENCODE_U8(buf + encoded_size, octet, encoded_size);*/
}
return encoded_size;
}
......@@ -103,37 +124,12 @@ ENCODE_U8(buf + encoded_size, octet, encoded_size);*/
int _5GSTrackingAreaIdList::encode_01_type(
p_tai_t item, uint8_t* buf, int len) {
// TODO:
return 1;
return KEncodeDecodeError;
}
//------------------------------------------------------------------------------
int _5GSTrackingAreaIdList::encode_10_type(
p_tai_t item, uint8_t* buf, int len) {
// TODO:
return 1;
}
//------------------------------------------------------------------------------
int _5GSTrackingAreaIdList::encode_mcc_mnc(
nas_plmn_t plmn, uint8_t* buf, int len) {
int encoded_size = 0;
int mcc = fromString<int>(plmn.mcc);
int mnc = fromString<int>(plmn.mnc);
*(buf + encoded_size) =
(0x0f & (mcc / 100)) | ((0x0f & ((mcc % 100) / 10)) << 4);
encoded_size += 1;
if (!(mnc / 100)) {
*(buf + encoded_size) = (0x0f & (mcc % 10)) | 0xf0;
encoded_size += 1;
*(buf + encoded_size) =
(0x0f & ((mnc % 100) / 10)) | ((0x0f & (mnc % 10)) << 4);
encoded_size += 1;
} else {
*(buf + encoded_size) = (0x0f & (mcc % 10)) | ((0x0f & (mnc % 10)) << 4);
encoded_size += 1;
*(buf + encoded_size) =
((0x0f & ((mnc % 100) / 10)) << 4) | (0x0f & (mnc / 100));
encoded_size += 1;
}
return encoded_size;
return KEncodeDecodeError;
}
......@@ -22,30 +22,30 @@
#ifndef _5GS_TRACKING_AREA_ID_LIST_H_
#define _5GS_TRACKING_AREA_ID_LIST_H_
#include "Type4NasIe.hpp"
#include <vector>
#include "struct.hpp"
constexpr uint8_t k5gsTrackingAreaIdListMinimumLength = 9;
constexpr uint8_t k5gsTrackingAreaIdListMaximumLength = 114;
constexpr auto k5gsTrackingAreaIdListIeName = "5GS Tracking Area Identity List";
namespace nas {
class _5GSTrackingAreaIdList {
class _5GSTrackingAreaIdList : public Type4NasIe {
public:
_5GSTrackingAreaIdList(uint8_t iei, std::vector<p_tai_t> tai_list);
_5GSTrackingAreaIdList();
_5GSTrackingAreaIdList(const std::vector<p_tai_t>& tai_list);
int Encode(uint8_t* buf, int len);
private:
uint8_t m_iei;
uint8_t length;
std::vector<p_tai_t> m_tai_list;
private:
int encode_00_type(p_tai_t item, uint8_t* buf, int len);
int encode_01_type(p_tai_t item, uint8_t* buf, int len);
int encode_10_type(p_tai_t item, uint8_t* buf, int len);
int encode_mcc_mnc(nas_plmn_t plmn, uint8_t* buf, int len);
};
} // namespace nas
......
......@@ -63,7 +63,7 @@ RegistrationAccept::RegistrationAccept()
ie_T3324_value = nullptr;
ie_ue_radio_capability_id = nullptr;
ie_pending_nssai = nullptr;
ie_tai_list = nullptr;
ie_tai_list = std::nullopt;
}
//------------------------------------------------------------------------------
......@@ -279,7 +279,7 @@ void RegistrationAccept::setPending_NSSAI(std::vector<struct SNSSAI_s> nssai) {
//------------------------------------------------------------------------------
void RegistrationAccept::setTaiList(std::vector<p_tai_t> tai_list) {
ie_tai_list = new _5GSTrackingAreaIdList(0x54, tai_list);
ie_tai_list = std::make_optional<_5GSTrackingAreaIdList>(tai_list);
}
//------------------------------------------------------------------------------
......@@ -315,10 +315,11 @@ int RegistrationAccept::Encode(uint8_t* buf, int len) {
return 0;
}
}
if (!ie_tai_list) {
if (!ie_tai_list.has_value()) {
Logger::nas_mm().warn("IE ie_tai_list is not available");
} else {
int size = ie_tai_list->Encode(buf + encoded_size, len - encoded_size);
int size =
ie_tai_list.value().Encode(buf + encoded_size, len - encoded_size);
if (size != -1) {
encoded_size += size;
} else {
......@@ -606,19 +607,6 @@ int RegistrationAccept::Encode(uint8_t* buf, int len) {
return 0;
}
}
#if 0
if(!ie_tai_list){
Logger::nas_mm().warn("IE ie_tai_list is not available");
}else{
int size = ie_tai_list->Encode(buf+encoded_size, len-encoded_size);
if(size != -1){
encoded_size += size;
}else{
Logger::nas_mm().error("Encoding ie_tai_list error");
return 0;
}
}
#endif
Logger::nas_mm().debug(
"Encoded RegistrationAccept message len (%d)", encoded_size);
return encoded_size;
......@@ -850,6 +838,20 @@ int RegistrationAccept::Decode(uint8_t* buf, int len) {
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
case kIei5gsTrackingAreaIdentityList: {
Logger::nas_mm().debug(
"Decoding IEI 0x%x", kIei5gsTrackingAreaIdentityList);
_5GSTrackingAreaIdList ie_tai_list_tmp = {};
decoded_size += ie_tai_list_tmp.Decode(
buf + decoded_size, len - decoded_size, true);
ie_tai_list = std::optional<_5GSTrackingAreaIdList>(ie_tai_list_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
default: {
break;
}
}
}
Logger::nas_mm().debug(
......
......@@ -150,7 +150,7 @@ class RegistrationAccept : public NasMmPlainHeader {
std::optional<_5GSMobileIdentity> ie_5g_guti; // Optional
std::optional<PlmnList> ie_equivalent_plmns; // Optional
_5GSTrackingAreaIdList* ie_tai_list; // Optional
std::optional<_5GSTrackingAreaIdList> ie_tai_list; // Optional
NSSAI* ie_allowed_nssai; // Optional
Rejected_NSSAI* ie_rejected_nssai; // Optional
NSSAI* ie_configured_nssai; // 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