Commit af488084 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update PLMN List

parent 0870f6ba
...@@ -29,15 +29,15 @@ ...@@ -29,15 +29,15 @@
using namespace nas; using namespace nas;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
PLMN_List::PLMN_List(uint8_t iei) { PLMN_List::PLMN_List(uint8_t iei) : Type4NasIe(iei) {
_iei = iei; SetLengthIndicator(0);
length = 2; SetIeName(kPlmnListIeName);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
PLMN_List::PLMN_List() { PLMN_List::PLMN_List() : Type4NasIe() {
_iei = 0; SetLengthIndicator(0);
length = 2; SetIeName(kPlmnListIeName);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -45,14 +45,16 @@ PLMN_List::~PLMN_List() {} ...@@ -45,14 +45,16 @@ PLMN_List::~PLMN_List() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void PLMN_List::set(uint8_t iei, const std::vector<nas_plmn_t>& list) { void PLMN_List::set(uint8_t iei, const std::vector<nas_plmn_t>& list) {
_iei = iei; plmn_list = list;
plmn_list = list; int length = 0;
if (list.size() > 0) if (list.size() > 0)
length = length =
kPlmnListMinimumLength + kPlmnListMinimumLength +
(list.size() - 1) * (list.size() - 1) *
3; // 3 - size of each PLMN 3; // 3 - size of each PLMN
// size of the first PLMN is included in kPlmnListMinimumLength // size of the first PLMN is included in kPlmnListMinimumLength
SetLengthIndicator(length);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -62,39 +64,49 @@ void PLMN_List::getPLMNList(std::vector<nas_plmn_t>& list) { ...@@ -62,39 +64,49 @@ void PLMN_List::getPLMNList(std::vector<nas_plmn_t>& list) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int PLMN_List::Encode(uint8_t* buf, int len) { int PLMN_List::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding PLMN_List"); Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (len < length) { int ie_len = GetIeLength();
Logger::nas_mm().error(
"Buffer length is less than the length of this IE (%d octet)", length); if (len < ie_len) {
Logger::nas_mm().error("Len is less than %d", ie_len);
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); // IEI int encoded_header_size = Type4NasIe::Encode(buf + encoded_size, len);
} if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
// Length encoded_size += encoded_header_size;
ENCODE_U8(buf + encoded_size, length, encoded_size);
for (auto it : plmn_list) for (auto it : plmn_list)
encoded_size += NasUtils::encodeMccMnc2Buffer( encoded_size += NasUtils::encodeMccMnc2Buffer(
it.mcc, it.mnc, buf + encoded_size, len - encoded_size); it.mcc, it.mnc, buf + encoded_size, len - encoded_size);
Logger::nas_mm().debug("Encoded PLMN_List (len %d)", encoded_size); Logger::nas_mm().debug(
"Encoded %s, len (%d)", GetIeName().c_str(), encoded_size);
return encoded_size; return encoded_size;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int PLMN_List::Decode(uint8_t* buf, int len, bool is_option) { int PLMN_List::Decode(uint8_t* buf, int len, bool is_iei) {
Logger::nas_mm().debug("Decoding PLMN_List"); Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
int decoded_size = 0;
if (is_option) { if (len < kPlmnListMinimumLength) {
DECODE_U8(buf + decoded_size, _iei, decoded_size); // IEI Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kPlmnListMinimumLength);
return KEncodeDecodeError;
} }
// Length
DECODE_U8(buf + decoded_size, length, decoded_size); int decoded_size = 0;
uint8_t len_ie = length;
// IEI and Length
int decoded_header_size = Type4NasIe::Decode(buf + decoded_size, len, true);
if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_header_size;
uint8_t len_ie = GetLengthIndicator();
while (len_ie > 0) { while (len_ie > 0) {
nas_plmn_t nas_plmn = {}; nas_plmn_t nas_plmn = {};
uint8_t size = NasUtils::decodeMccMncFromBuffer( uint8_t size = NasUtils::decodeMccMncFromBuffer(
...@@ -106,6 +118,7 @@ int PLMN_List::Decode(uint8_t* buf, int len, bool is_option) { ...@@ -106,6 +118,7 @@ int PLMN_List::Decode(uint8_t* buf, int len, bool is_option) {
break; break;
} }
} }
Logger::nas_mm().debug("Decoded PLMN_List (len %d)", decoded_size); Logger::nas_mm().debug(
"Decoded %s, len (%d)", GetIeName().c_str(), decoded_size);
return decoded_size; return decoded_size;
} }
...@@ -22,16 +22,19 @@ ...@@ -22,16 +22,19 @@
#ifndef _PLMN_LIST_H_ #ifndef _PLMN_LIST_H_
#define _PLMN_LIST_H_ #define _PLMN_LIST_H_
#include "Type4NasIe.hpp"
#include "struct.hpp" #include "struct.hpp"
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
constexpr uint8_t kPlmnListMinimumLength = 5; constexpr uint8_t kPlmnListMinimumLength = 5;
constexpr uint8_t kPlmnListMaximumLength = 47; constexpr uint8_t kPlmnListMaximumLength = 47;
constexpr auto kPlmnListIeName = "PLMN List";
namespace nas { namespace nas {
class PLMN_List { class PLMN_List : public Type4NasIe {
public: public:
PLMN_List(); PLMN_List();
PLMN_List(uint8_t iei); PLMN_List(uint8_t iei);
...@@ -44,8 +47,6 @@ class PLMN_List { ...@@ -44,8 +47,6 @@ class PLMN_List {
void getPLMNList(std::vector<nas_plmn_t>& list); void getPLMNList(std::vector<nas_plmn_t>& list);
private: private:
uint8_t _iei;
uint8_t length;
std::vector<nas_plmn_t> plmn_list; std::vector<nas_plmn_t> plmn_list;
}; };
} // namespace nas } // 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