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

Code cleanup

parent caebfeeb
......@@ -59,6 +59,23 @@ ABBA::ABBA(uint8_t iei, uint8_t length, uint8_t* value) : Type4NasIe(iei) {
//------------------------------------------------------------------------------
ABBA::~ABBA() {}
//------------------------------------------------------------------------------
void ABBA::Set(uint8_t length, uint8_t* value) {
for (int i = 0; i < length; i++) {
this->value_[i] = value[i];
}
SetLengthIndicator(length);
}
//------------------------------------------------------------------------------
void ABBA::Set(uint8_t iei, uint8_t length, uint8_t* value) {
SetIei(iei);
for (int i = 0; i < length; i++) {
this->value_[i] = value[i];
}
SetLengthIndicator(length);
}
//------------------------------------------------------------------------------
int ABBA::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
......
......@@ -38,9 +38,11 @@ class ABBA : public Type4NasIe {
ABBA(uint8_t iei, uint8_t length, uint8_t* value);
~ABBA();
void Set(uint8_t length, uint8_t* value);
void Set(uint8_t iei, uint8_t length, uint8_t* value);
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_option);
// uint8_t GetValue() const;
private:
uint8_t value_[256]; // TODO:
......
......@@ -29,7 +29,6 @@ using namespace nas;
//------------------------------------------------------------------------------
AuthenticationRequest::AuthenticationRequest()
: NasMmPlainHeader(EPD_5GS_MM_MSG, AUTHENTICATION_REQUEST) {
ie_abba = NULL;
ie_authentication_parameter_rand = NULL;
ie_authentication_parameter_autn = NULL;
ie_eap_message = NULL;
......@@ -52,7 +51,7 @@ void AuthenticationRequest::setngKSI(uint8_t tsc, uint8_t key_set_id) {
//------------------------------------------------------------------------------
void AuthenticationRequest::setABBA(uint8_t length, uint8_t* value) {
ie_abba = new ABBA(length, value);
ie_abba.Set(length, value);
}
//------------------------------------------------------------------------------
......@@ -96,20 +95,16 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) {
// Spare half octet
encoded_size++; // 1/2 octet + 1/2 octet from ie_ngKSI
if (!ie_abba) {
Logger::nas_mm().warn("IE ie_abba is not available");
// ABBA
size = ie_abba.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else {
int size = ie_abba->Encode(buf + encoded_size, len - encoded_size);
if (size != 0) {
Logger::nas_mm().debug(
"0x%x, 0x%x, 0x%x", (buf + encoded_size)[0], (buf + encoded_size)[1],
(buf + encoded_size)[2]);
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_abba error");
return 0;
}
Logger::nas_mm().error("Encoding ie_abba error");
return 0;
}
// Authentication parameter RAND
if (!ie_authentication_parameter_rand) {
Logger::nas_mm().warn(
"IE ie_authentication_parameter_rand is not available");
......@@ -123,6 +118,7 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) {
return 0;
}
}
// Authentication parameter AUTN
if (!ie_authentication_parameter_autn) {
Logger::nas_mm().warn(
"IE ie_authentication_parameter_autn is not available");
......@@ -136,6 +132,7 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) {
return 0;
}
}
// EAP message
if (!ie_eap_message) {
Logger::nas_mm().warn("IE ie_eap_message is not available");
} else {
......@@ -163,10 +160,10 @@ int AuthenticationRequest::Decode(uint8_t* buf, int len) {
buf + decoded_size, len - decoded_size, false,
false); // length 1/2, low position
decoded_size++; // 1/2 octet from ie_ngKSI, 1/2 from Spare half octet
ie_abba = new ABBA();
decoded_size +=
ie_abba->Decode(buf + decoded_size, len - decoded_size, false);
// ABBA
decoded_size += ie_abba.Decode(buf + decoded_size, len - decoded_size, false);
Logger::nas_mm().debug("Decoded_size %d", decoded_size);
uint8_t octet = *(buf + decoded_size);
Logger::nas_mm().debug("First option IEI 0x%x", octet);
while ((octet != 0x0)) {
......
......@@ -43,11 +43,11 @@ class AuthenticationRequest : public NasMmPlainHeader {
void setAuthentication_Parameter_AUTN(uint8_t* value);
public:
NasKeySetIdentifier ie_ngKSI;
ABBA* ie_abba;
Authentication_Parameter_RAND* ie_authentication_parameter_rand;
Authentication_Parameter_AUTN* ie_authentication_parameter_autn;
EAP_Message* ie_eap_message;
NasKeySetIdentifier ie_ngKSI; // Mandatory
ABBA ie_abba; // Mandatory
Authentication_Parameter_RAND* ie_authentication_parameter_rand; // Optional
Authentication_Parameter_AUTN* ie_authentication_parameter_autn; // Optional
EAP_Message* ie_eap_message; // Optional
};
} // 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