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