Commit 63c70695 authored by luhan's avatar luhan

Merge branch 'master' of http://git.opensource5g.org/openxg/amf

parents e595da59 b44be750
......@@ -950,6 +950,7 @@ void amf_n1::registration_request_handle(bool isNasSig,
}
nc.get()->ueSecurityCapEnc = encrypt_alg;
nc.get()->ueSecurityCapInt = integrity_alg;
nc.get()->ueSecurityCaplen = regReq->ie_ue_security_capability->getLenght();
// Get Requested NSSAI (Optional IE), if provided
std::vector<SNSSAI_t> requestedNssai = {};
......@@ -2001,6 +2002,12 @@ bool amf_n1::start_security_mode_control_procedure(
smc->setngKSI(NAS_KEY_SET_IDENTIFIER_NATIVE, nc.get()->ngKsi & 0x07);
smc->setUE_Security_Capability(nc.get()->ueSecurityCapEnc,
nc.get()->ueSecurityCapInt);
if (smc->ie_ue_security_capability != NULL) {
smc->ie_ue_security_capability->setLenght(nc.get()->ueSecurityCaplen);
} else {
Logger::amf_n1().error("smc->ie_ue_security_capability is NULL");
}
smc->setIMEISV_Request(0xe1);
smc->setAdditional_5G_Security_Information(true, false);
uint8_t buffer[1024];
......@@ -2309,12 +2316,14 @@ bool amf_n1::nas_message_integrity_protected(nas_secu_ctx *nsc,
int input_nas_len,
uint32_t &mac32) {
uint32_t count = 0x00000000;
if (direction)
if (direction) {
count = 0x00000000 | ((nsc->dl_count.overflow & 0x0000ffff) << 8) |
((nsc->dl_count.seq_num & 0x000000ff));
else
} else {
Logger::amf_n1().debug("nsc->ul_count.overflow %x", nsc->ul_count.overflow);
count = 0x00000000 | ((nsc->ul_count.overflow & 0x0000ffff) << 8) |
((nsc->ul_count.seq_num & 0x000000ff));
}
nas_stream_cipher_t stream_cipher = {0};
uint8_t mac[4];
stream_cipher.key = nsc->knas_int;
......@@ -2322,6 +2331,7 @@ bool amf_n1::nas_message_integrity_protected(nas_secu_ctx *nsc,
AUTH_KNAS_INT_SIZE);
stream_cipher.key_length = AUTH_KNAS_INT_SIZE;
stream_cipher.count = *(input_nas);
stream_cipher.bearer = 0x01;
// stream_cipher.count = count;
if (!direction) {
nsc->ul_count.seq_num = stream_cipher.count;
......@@ -2391,8 +2401,19 @@ bool amf_n1::nas_message_cipher_protected(nas_secu_ctx *nsc, uint8_t direction,
} break;
case EA1_128_5G: {
Logger::amf_n1().debug("Cipher protected with EA1_128_5G");
nas_algorithms::nas_stream_encrypt_nea1(&stream_cipher,
(uint8_t *)bdata(output_nas));
Logger::amf_n1().debug("stream_cipher.blength %d", stream_cipher.blength);
Logger::amf_n1().debug("stream_cipher.message %x",
stream_cipher.message[0]);
print_buffer("amf_n1", "stream_cipher.key ", stream_cipher.key, 16);
Logger::amf_n1().debug("stream_cipher.count %x", stream_cipher.count);
uint8_t *ciphered =
(uint8_t *)malloc(((stream_cipher.blength + 31) / 32) * 4);
nas_algorithms::nas_stream_encrypt_nea1(&stream_cipher, ciphered);
output_nas = blk2bstr(ciphered, ((stream_cipher.blength + 31) / 32) * 4);
// output_nas = blk2bstr(ciphered, blength(input_nas));
free(ciphered);
} break;
case EA2_128_5G: {
Logger::amf_n1().debug("Cipher protected with EA2_128_5G");
......@@ -2471,7 +2492,8 @@ void amf_n1::ue_initiate_de_registration_handle(uint32_t ran_ue_ngap_id,
Logger::amf_n1().debug("5G Mobile Identity, GUTI %s",
deregReq->get_5g_guti().c_str());
} break;
default: {}
default: {
}
}
// Prepare DeregistrationAccept
......
......@@ -42,6 +42,7 @@ nas_context::nas_context() {
is_common_procedure_for_security_mode_control_running = false;
is_common_procedure_for_nas_transport_running = false;
auts = NULL;
ueSecurityCaplen = 0;
}
//------------------------------------------------------------------------------
......
......@@ -73,6 +73,7 @@ class nas_context {
// mobility identity: imsi, supi, 5g-guti, etc
std::string imsi;
uint8_t mmCapability;
uint8_t ueSecurityCaplen;
uint8_t ueSecurityCapEnc;
uint8_t ueSecurityCapInt;
std::vector<nas::SNSSAI_t> requestedNssai;
......
......@@ -31,9 +31,7 @@
using namespace nas;
//------------------------------------------------------------------------------
UESecurityCapability::UESecurityCapability(uint8_t iei) {
_iei = iei;
}
UESecurityCapability::UESecurityCapability(uint8_t iei) { _iei = iei; }
//------------------------------------------------------------------------------
UESecurityCapability::UESecurityCapability() {}
......@@ -42,36 +40,43 @@ UESecurityCapability::UESecurityCapability() {}
UESecurityCapability::~UESecurityCapability() {}
//------------------------------------------------------------------------------
UESecurityCapability::UESecurityCapability(
const uint8_t iei, uint8_t _5gg_EASel, uint8_t _5gg_IASel) {
UESecurityCapability::UESecurityCapability(const uint8_t iei,
uint8_t _5gg_EASel,
uint8_t _5gg_IASel) {
_iei = iei;
_5g_EASel = _5gg_EASel;
_5g_IASel = _5gg_IASel;
length = 4;
length = 2;
}
//------------------------------------------------------------------------------
void UESecurityCapability::setEASel(uint8_t sel) {
_5g_EASel = sel;
}
void UESecurityCapability::setEASel(uint8_t sel) { _5g_EASel = sel; }
//------------------------------------------------------------------------------
void UESecurityCapability::setIASel(uint8_t sel) {
_5g_IASel = sel;
}
void UESecurityCapability::setIASel(uint8_t sel) { _5g_IASel = sel; }
//------------------------------------------------------------------------------
uint8_t UESecurityCapability::getEASel() {
return _5g_EASel;
}
uint8_t UESecurityCapability::getEASel() { return _5g_EASel; }
//------------------------------------------------------------------------------
uint8_t UESecurityCapability::getIASel() {
return _5g_IASel;
uint8_t UESecurityCapability::getIASel() { return _5g_IASel; }
//------------------------------------------------------------------------------
void UESecurityCapability::setLenght(uint8_t len) {
if ((len > 0) && (len <= 4)) {
length = len;
} else {
Logger::nas_mm().debug("Set UESecurityCapability Lenght faile %d", len);
Logger::nas_mm().debug(
"UESecurityCapability Lenght is set to the default value %d", length);
}
}
//------------------------------------------------------------------------------
int UESecurityCapability::encode2buffer(uint8_t* buf, int len) {
uint8_t UESecurityCapability::getLenght() { return length; }
//------------------------------------------------------------------------------
int UESecurityCapability::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("Encoding UESecurityCapability IEI 0x%x", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
......@@ -81,27 +86,40 @@ int UESecurityCapability::encode2buffer(uint8_t* buf, int len) {
if (_iei) {
*(buf + encoded_size) = _iei;
encoded_size++;
*(buf + encoded_size) = length - 2;
*(buf + encoded_size) = length;
encoded_size++;
*(buf + encoded_size) = _5g_EASel;
encoded_size++;
*(buf + encoded_size) = _5g_IASel;
encoded_size++;
if (length == 4) {
*(buf + encoded_size) = 0xf0;
encoded_size++;
*(buf + encoded_size) = 0xf0;
encoded_size++;
}
} else {
*(buf + encoded_size) = length - 2;
*(buf + encoded_size) = length;
encoded_size++;
*(buf + encoded_size) = _5g_EASel;
encoded_size++;
*(buf + encoded_size) = _5g_IASel;
encoded_size++;
if (length == 4) {
*(buf + encoded_size) = 0xf0;
encoded_size++;
*(buf + encoded_size) = 0xf0;
encoded_size++;
}
}
Logger::nas_mm().debug("encoded UESecurityCapability (len %d)", encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int UESecurityCapability::decodefrombuffer(
uint8_t* buf, int len, bool is_option) {
int UESecurityCapability::decodefrombuffer(uint8_t *buf, int len,
bool is_option) {
Logger::nas_mm().debug("Decoding UESecurityCapability IEI 0x%x", *buf);
int decoded_size = 0;
if (is_option) {
......@@ -112,10 +130,10 @@ int UESecurityCapability::decodefrombuffer(
_5g_EASel = *(buf + decoded_size);
decoded_size++;
_5g_IASel = *(buf + decoded_size);
decoded_size ++;
if(length == 4)
decoded_size += 2;//to do: decoding EEA EIA
Logger::nas_mm().debug(
"UESecurityCapability EA 0x%d,IA 0x%d", _5g_EASel, _5g_IASel);
decoded_size++;
if (length == 4)
decoded_size += 2; // to do: decoding EEA EIA
Logger::nas_mm().debug("UESecurityCapability EA 0x%d,IA 0x%d", _5g_EASel,
_5g_IASel);
return decoded_size;
}
......@@ -34,20 +34,22 @@
namespace nas {
class UESecurityCapability {
public:
public:
UESecurityCapability(uint8_t iei);
UESecurityCapability();
~UESecurityCapability();
UESecurityCapability(
const uint8_t iei, uint8_t _5gg_EASel, uint8_t _5gg_IASel);
UESecurityCapability(const uint8_t iei, uint8_t _5gg_EASel,
uint8_t _5gg_IASel);
void setEASel(uint8_t sel);
void setIASel(uint8_t sel);
uint8_t getEASel();
uint8_t getIASel();
int encode2buffer(uint8_t* buf, int len);
int decodefrombuffer(uint8_t* buf, int len, bool is_option);
void setLenght(uint8_t len);
uint8_t getLenght();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
private:
private:
uint8_t _iei;
uint8_t length;
uint8_t _5g_EASel;
......
......@@ -53,8 +53,8 @@ ULNASTransport::~ULNASTransport() {}
//------------------------------------------------------------------------------
void ULNASTransport::setHeader(uint8_t security_header_type) {
plain_header = new NasMmPlainHeader();
plain_header->setHeader(
EPD_5GS_MM_MSG, security_header_type, UL_NAS_TRANSPORT);
plain_header->setHeader(EPD_5GS_MM_MSG, security_header_type,
UL_NAS_TRANSPORT);
}
//------------------------------------------------------------------------------
......@@ -78,14 +78,14 @@ void ULNASTransport::setPayload_Container(
}
//------------------------------------------------------------------------------
bool ULNASTransport::getPayloadContainer(bstring& content) {
bool ULNASTransport::getPayloadContainer(bstring &content) {
ie_payload_container->getValue(content);
return true;
}
//------------------------------------------------------------------------------
bool ULNASTransport::getPayloadContainer(
std::vector<PayloadContainerEntry>& content) {
std::vector<PayloadContainerEntry> &content) {
if (ie_payload_container) {
ie_payload_container->getValue(content);
return 0;
......@@ -140,7 +140,7 @@ void ULNASTransport::setS_NSSAI(SNSSAI_s snssai) {
}
//------------------------------------------------------------------------------
bool ULNASTransport::getSnssai(SNSSAI_s& snssai) {
bool ULNASTransport::getSnssai(SNSSAI_s &snssai) {
if (ie_s_nssai) {
ie_s_nssai->getValue(snssai);
return 0;
......@@ -150,12 +150,10 @@ bool ULNASTransport::getSnssai(SNSSAI_s& snssai) {
}
//------------------------------------------------------------------------------
void ULNASTransport::setDNN(bstring dnn) {
ie_dnn = new DNN(0x25, dnn);
}
void ULNASTransport::setDNN(bstring dnn) { ie_dnn = new DNN(0x25, dnn); }
//------------------------------------------------------------------------------
bool ULNASTransport::getDnn(bstring& dnn) {
bool ULNASTransport::getDnn(bstring &dnn) {
if (ie_dnn) {
ie_dnn->getValue(dnn);
return true;
......@@ -181,14 +179,15 @@ void ULNASTransport::setRelease_Assistance_Indication(uint8_t value) {
}
//------------------------------------------------------------------------------
int ULNASTransport::encode2buffer(uint8_t* buf, int len) {
int ULNASTransport::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding ULNASTransport message");
int encoded_size = 0;
if (!plain_header) {
Logger::nas_mm().error("Mandatory IE missing Header");
return 0;
}
if (!(plain_header->encode2buffer(buf, len))) return 0;
if (!(plain_header->encode2buffer(buf, len)))
return 0;
encoded_size += 3;
if (!ie_payload_container_type) {
Logger::nas_mm().warn("IE ie_payload_container_type is not available");
......@@ -204,8 +203,8 @@ int ULNASTransport::encode2buffer(uint8_t* buf, int len) {
if (!ie_payload_container) {
Logger::nas_mm().warn("IE ie_payload_container is not available");
} else {
if (int size = ie_payload_container->encode2buffer(
buf + encoded_size, len - encoded_size)) {
if (int size = ie_payload_container->encode2buffer(buf + encoded_size,
len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error("encoding ie_payload_container error");
......@@ -238,8 +237,8 @@ int ULNASTransport::encode2buffer(uint8_t* buf, int len) {
if (!ie_request_type) {
Logger::nas_mm().warn("IE ie_request_type is not available");
} else {
if (int size = ie_request_type->encode2buffer(
buf + encoded_size, len - encoded_size)) {
if (int size = ie_request_type->encode2buffer(buf + encoded_size,
len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error("encoding ie ie_request_type error");
......@@ -304,14 +303,14 @@ int ULNASTransport::encode2buffer(uint8_t* buf, int len) {
return 0;
}
}
Logger::nas_mm().debug(
"encoded ULNASTransport message len(%d)", encoded_size);
Logger::nas_mm().debug("encoded ULNASTransport message len(%d)",
encoded_size);
return 1;
}
//------------------------------------------------------------------------------
int ULNASTransport::decodefrombuffer(
NasMmPlainHeader* header, uint8_t* buf, int len) {
int ULNASTransport::decodefrombuffer(NasMmPlainHeader *header, uint8_t *buf,
int len) {
Logger::nas_mm().debug("Decoding ULNASTransport message");
int decoded_size = 3;
plain_header = header;
......@@ -325,6 +324,7 @@ int ULNASTransport::decodefrombuffer(
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);
bool flag = false;
while ((octet != 0x0)) {
switch ((octet & 0xf0) >> 4) {
case 0x8: {
......@@ -351,6 +351,9 @@ int ULNASTransport::decodefrombuffer(
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
default: {
flag = true;
}
}
switch (octet) {
case 0x12: {
......@@ -372,16 +375,16 @@ int ULNASTransport::decodefrombuffer(
case 0x22: {
Logger::nas_mm().debug("Decoding IEI (0x22)");
ie_s_nssai = new S_NSSAI();
decoded_size += ie_s_nssai->decodefrombuffer(
buf + decoded_size, len - decoded_size, true);
decoded_size += ie_s_nssai->decodefrombuffer(buf + decoded_size,
len - decoded_size, true);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
case 0x25: {
Logger::nas_mm().debug("Decoding IEI (0x25)");
ie_dnn = new DNN();
decoded_size += ie_dnn->decodefrombuffer(
buf + decoded_size, len - decoded_size, true);
decoded_size += ie_dnn->decodefrombuffer(buf + decoded_size,
len - decoded_size, true);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
......@@ -393,8 +396,17 @@ int ULNASTransport::decodefrombuffer(
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
default: {
if (flag) {
Logger::nas_mm().debug("Unknown IEI (0x%x)", octet);
decoded_size++;
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
}
}
}
flag = false;
}
Logger::nas_mm().debug(
"decoded ULNASTransport message len(%d)", decoded_size);
Logger::nas_mm().debug("decoded ULNASTransport message len(%d)",
decoded_size);
}
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