Commit 2668e58a authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Merge branch 'develop' into 'downlink_nas_transport'

# Conflicts:
#   src/secu_algorithms/5gaka/authentication_algorithms_with_5gaka.cpp
parents 7dfa884b 12faa8ab
...@@ -285,7 +285,7 @@ check_install_amf_deps(){ ...@@ -285,7 +285,7 @@ check_install_amf_deps(){
automake \ automake \
bison \ bison \
build-essential \ build-essential \
cmake \ $CMAKE \
daemon \ daemon \
doxygen \ doxygen \
flex \ flex \
......
...@@ -49,6 +49,7 @@ install_fb_folly_from_source(){ ...@@ -49,6 +49,7 @@ install_fb_folly_from_source(){
then then
if [[ "$OS_BASEDISTRO" == "fedora" ]]; then if [[ "$OS_BASEDISTRO" == "fedora" ]]; then
$SUDO $INSTALLER install $OPTION \ $SUDO $INSTALLER install $OPTION \
$CMAKE \
boost-devel \ boost-devel \
libevent-devel \ libevent-devel \
double-conversion-devel \ double-conversion-devel \
...@@ -63,6 +64,7 @@ install_fb_folly_from_source(){ ...@@ -63,6 +64,7 @@ install_fb_folly_from_source(){
ret=$?;[[ $ret -ne 0 ]] && return $ret ret=$?;[[ $ret -ne 0 ]] && return $ret
elif [[ $OS_DISTRO == "ubuntu" ]]; then elif [[ $OS_DISTRO == "ubuntu" ]]; then
$SUDO $INSTALLER install $OPTION \ $SUDO $INSTALLER install $OPTION \
$CMAKE \
g++ \ g++ \
libevent-dev \ libevent-dev \
libdouble-conversion-dev \ libdouble-conversion-dev \
...@@ -126,11 +128,7 @@ install_fb_folly_from_source(){ ...@@ -126,11 +128,7 @@ install_fb_folly_from_source(){
git checkout -f v2019.11.11.00 git checkout -f v2019.11.11.00
fi fi
mkdir _build && cd _build mkdir _build && cd _build
if [[ "$OS_BASEDISTRO" == "fedora" ]]; then $CMAKE ..
cmake3 ..
else
cmake ..
fi
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
make -j $(nproc) make -j $(nproc)
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
......
...@@ -90,6 +90,7 @@ ENV TZ=Europe/Paris ...@@ -90,6 +90,7 @@ ENV TZ=Europe/Paris
RUN yum update -y && \ RUN yum update -y && \
yum install -y --enablerepo="ubi-8-codeready-builder" \ yum install -y --enablerepo="ubi-8-codeready-builder" \
tzdata \ tzdata \
procps-ng \
psmisc \ psmisc \
net-tools \ net-tools \
libevent && \ libevent && \
......
...@@ -494,7 +494,7 @@ void amf_n1::uplink_nas_msg_handle( ...@@ -494,7 +494,7 @@ void amf_n1::uplink_nas_msg_handle(
ran_ue_ngap_id, amf_ue_ngap_id, plain_msg); ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
} break; } break;
case IDENTITY_RESPONSE: { case IDENTITY_RESPONSE: {
Logger::amf_n1().debug("received identity response messgae , handle ..."); Logger::amf_n1().debug("received identity response message , handle ...");
identity_response_handle(ran_ue_ngap_id, amf_ue_ngap_id, plain_msg); identity_response_handle(ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
} break; } break;
case REGISTRATION_COMPLETE: { case REGISTRATION_COMPLETE: {
...@@ -547,7 +547,7 @@ void amf_n1::uplink_nas_msg_handle( ...@@ -547,7 +547,7 @@ void amf_n1::uplink_nas_msg_handle(
ran_ue_ngap_id, amf_ue_ngap_id, plain_msg); ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
} break; } break;
case IDENTITY_RESPONSE: { case IDENTITY_RESPONSE: {
Logger::amf_n1().debug("received identity response messgae , handle ..."); Logger::amf_n1().debug("received identity response message , handle ...");
identity_response_handle(ran_ue_ngap_id, amf_ue_ngap_id, plain_msg); identity_response_handle(ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
} break; } break;
case REGISTRATION_COMPLETE: { case REGISTRATION_COMPLETE: {
...@@ -608,6 +608,23 @@ void amf_n1::identity_response_handle( ...@@ -608,6 +608,23 @@ void amf_n1::identity_response_handle(
supi = imsi.mcc + imsi.mnc + imsi.msin; supi = imsi.mcc + imsi.mnc + imsi.msin;
Logger::amf_n1().debug("identity response : suci (%s)", supi.c_str()); Logger::amf_n1().debug("identity response : suci (%s)", supi.c_str());
} }
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id);
if (amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
std::shared_ptr<ue_context> uc;
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
// Update UE context
if (uc.get() != nullptr) {
uc.get()->supi = "imsi-" + supi;
// associate SUPI with UC
amf_app_inst->set_supi_2_ue_context(uc.get()->supi, uc);
Logger::amf_n1().debug(
"Update UC context, SUPI %s", uc.get()->supi.c_str());
}
}
std::shared_ptr<nas_context> nc; std::shared_ptr<nas_context> nc;
if (is_amf_ue_id_2_nas_context(amf_ue_ngap_id)) { if (is_amf_ue_id_2_nas_context(amf_ue_ngap_id)) {
nc = amf_ue_id_2_nas_context(amf_ue_ngap_id); nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
...@@ -969,6 +986,7 @@ void amf_n1::registration_request_handle( ...@@ -969,6 +986,7 @@ void amf_n1::registration_request_handle(
nc.get()->is_5g_guti_present = true; nc.get()->is_5g_guti_present = true;
nc.get()->to_be_register_by_new_suci = true; nc.get()->to_be_register_by_new_suci = true;
nc.get()->ngKsi = 100 & 0xf; nc.get()->ngKsi = 100 & 0xf;
// nc.get()->imsi =
// supi2amfId[("imsi-"+nc.get()->imsi)] = amf_ue_ngap_id; // supi2amfId[("imsi-"+nc.get()->imsi)] = amf_ue_ngap_id;
// supi2ranId[("imsi-"+nc.get()->imsi)] = ran_ue_ngap_id; // supi2ranId[("imsi-"+nc.get()->imsi)] = ran_ue_ngap_id;
} }
...@@ -2218,54 +2236,55 @@ void amf_n1::registration_complete_handle( ...@@ -2218,54 +2236,55 @@ void amf_n1::registration_complete_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg) { uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg) {
Logger::amf_n1().debug( Logger::amf_n1().debug(
"receiving registration complete, encoding Configuration Update Command"); "receiving registration complete, encoding Configuration Update Command");
/*
time_t tt;
time(&tt);
tt = tt + 8 * 3600; // transform the time zone
tm* t = gmtime(&tt);
uint8_t conf[45] = {0};
uint8_t header[3] = {0x7e, 0x00, 0x54};
uint8_t full_name[18] = {0x43, 0x10, 0x81, 0xc1, 0x76, 0x58,
0x9e, 0x9e, 0xbf, 0xcd, 0x74, 0x90,
0xb3, 0x4c, 0xbf, 0xbf, 0xe5, 0x6b};
uint8_t short_name[11] = {0x45, 0x09, 0x81, 0xc1, 0x76, 0x58,
0x9e, 0x9e, 0xbf, 0xcd, 0x74};
uint8_t time_zone[2] = {0x46, 0x23};
uint8_t time[8] = {0};
time[0] = 0x47;
time[1] = 0x12;
time[2] = ((t->tm_mon + 1) & 0x0f) << 4 | ((t->tm_mon + 1) & 0xf0) >> 4;
time[3] = ((t->tm_mday + 1) & 0x0f) << 4 | ((t->tm_mday + 1) & 0xf0) >> 4;
time[4] = ((t->tm_hour + 1) & 0x0f) << 4 | ((t->tm_hour + 1) & 0xf0) >> 4;
time[5] = ((t->tm_min + 1) & 0x0f) << 4 | ((t->tm_min + 1) & 0xf0) >> 4;
time[6] = ((t->tm_sec + 1) & 0x0f) << 4 | ((t->tm_sec + 1) & 0xf0) >> 4;
time[7] = 0x23;
uint8_t daylight[3] = {0x49, 0x01, 0x00};
memcpy(conf, header, 3);
memcpy(conf + 3, full_name, 18);
memcpy(conf + 21, short_name, 11);
memcpy(conf + 32, time_zone, 2);
memcpy(conf + 34, time, 8);
memcpy(conf + 42, daylight, 3);
std::shared_ptr<nas_context> nc;
if (is_amf_ue_id_2_nas_context(amf_ue_ngap_id))
nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
else {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)", amf_ue_ngap_id);
return;
}
nas_secu_ctx* secu = nc.get()->security_ctx;
// protect nas message
bstring protectedNas;
encode_nas_message_protected(
secu, false, INTEGRITY_PROTECTED_AND_CIPHERED, NAS_MESSAGE_DOWNLINK,
conf, 45, protectedNas);
time_t tt; itti_send_dl_nas_buffer_to_task_n2(
time(&tt); protectedNas, ran_ue_ngap_id, amf_ue_ngap_id);
tt = tt + 8 * 3600; // transform the time zone */
tm* t = gmtime(&tt);
uint8_t conf[45] = {0};
uint8_t header[3] = {0x7e, 0x00, 0x54};
uint8_t full_name[18] = {0x43, 0x10, 0x81, 0xc1, 0x76, 0x58,
0x9e, 0x9e, 0xbf, 0xcd, 0x74, 0x90,
0xb3, 0x4c, 0xbf, 0xbf, 0xe5, 0x6b};
uint8_t short_name[11] = {0x45, 0x09, 0x81, 0xc1, 0x76, 0x58,
0x9e, 0x9e, 0xbf, 0xcd, 0x74};
uint8_t time_zone[2] = {0x46, 0x23};
uint8_t time[8] = {0};
time[0] = 0x47;
time[1] = 0x12;
time[2] = ((t->tm_mon + 1) & 0x0f) << 4 | ((t->tm_mon + 1) & 0xf0) >> 4;
time[3] = ((t->tm_mday + 1) & 0x0f) << 4 | ((t->tm_mday + 1) & 0xf0) >> 4;
time[4] = ((t->tm_hour + 1) & 0x0f) << 4 | ((t->tm_hour + 1) & 0xf0) >> 4;
time[5] = ((t->tm_min + 1) & 0x0f) << 4 | ((t->tm_min + 1) & 0xf0) >> 4;
time[6] = ((t->tm_sec + 1) & 0x0f) << 4 | ((t->tm_sec + 1) & 0xf0) >> 4;
time[7] = 0x23;
uint8_t daylight[3] = {0x49, 0x01, 0x00};
memcpy(conf, header, 3);
memcpy(conf + 3, full_name, 18);
memcpy(conf + 21, short_name, 11);
memcpy(conf + 32, time_zone, 2);
memcpy(conf + 34, time, 8);
memcpy(conf + 42, daylight, 3);
std::shared_ptr<nas_context> nc;
if (is_amf_ue_id_2_nas_context(amf_ue_ngap_id))
nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
else {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)", amf_ue_ngap_id);
return;
}
nas_secu_ctx* secu = nc.get()->security_ctx;
// protect nas message
bstring protectedNas;
encode_nas_message_protected(
secu, false, INTEGRITY_PROTECTED_AND_CIPHERED, NAS_MESSAGE_DOWNLINK, conf,
45, protectedNas);
itti_send_dl_nas_buffer_to_task_n2(
protectedNas, ran_ue_ngap_id, amf_ue_ngap_id);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -2462,44 +2481,13 @@ void amf_n1::run_initial_registration_procedure() {} ...@@ -2462,44 +2481,13 @@ void amf_n1::run_initial_registration_procedure() {}
void amf_n1::ue_initiate_de_registration_handle( void amf_n1::ue_initiate_de_registration_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas) { uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas) {
Logger::amf_n1().debug("Handling UE-initiated De-registration Request"); Logger::amf_n1().debug("Handling UE-initiated De-registration Request");
/*
string guti = "1234567890";//need modify
_5G_GUTI_t Guti;
_5GSMobilityIdentity *ulNas = new _5GSMobilityIdentity();
ulNas->decodefrombuffer((uint8_t*)bdata(nas)+4, blength(nas),false);
ulNas->get5GGUTI(Guti);
delete ulNas;
string amf_region_id = std::to_string(Guti.amf_region_id);
guti = Guti.mcc + Guti.mnc + std::to_string(Guti.amf_region_id) +
std::to_string(Guti.amf_set_id) + std::to_string(Guti.amf_pointer) +
std::to_string(Guti._5g_tmsi); std::shared_ptr<nas_context> nc;
if(!is_guti_2_nas_context(guti))
return;
nc = guti_2_nas_context(guti);
nc.get()-> is_auth_vectors_present = false;
nc.get()-> is_current_security_available = false;
nc.get()->security_ctx->sc_type = SECURITY_CTX_TYPE_NOT_AVAILABLE;
Logger::ngap().debug("sending itti ue context release command to
TASK_AMF_N2"); itti_ue_context_release_command * itti_msg = new
itti_ue_context_release_command(TASK_AMF_N1, TASK_AMF_N2);
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->cause.setChoiceOfCause(Ngap_Cause_PR_nas);
itti_msg->cause.setValue(2);//cause nas(2)--deregister
std::shared_ptr<itti_ue_context_release_command> i =
std::shared_ptr<itti_ue_context_release_command>(itti_msg); int ret =
itti_inst->send_msg(i); if (0 != ret) { Logger::ngap().error("Could not send
ITTI message %s to task TASK_AMF_N2", i->get_msg_name());
}
*/
std::shared_ptr<nas_context> nc; std::shared_ptr<nas_context> nc;
if (is_amf_ue_id_2_nas_context(amf_ue_ngap_id)) if (is_amf_ue_id_2_nas_context(amf_ue_ngap_id))
nc = amf_ue_id_2_nas_context(amf_ue_ngap_id); nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
else { else {
Logger::amf_n1().warn( Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)", amf_ue_ngap_id); "No existed nas_context with amf_ue_ngap_id (0x%x)", amf_ue_ngap_id);
return; return;
} }
...@@ -2537,7 +2525,7 @@ void amf_n1::ue_initiate_de_registration_handle( ...@@ -2537,7 +2525,7 @@ void amf_n1::ue_initiate_de_registration_handle(
print_buffer( print_buffer(
"amf_n1", "De-registration Accept message buffer", buffer, encoded_size); "amf_n1", "De-registration Accept message buffer", buffer, encoded_size);
if (encoded_size < 1) { if (encoded_size < 1) {
Logger::nas_mm().error("Encode De-registration Accept message error"); Logger::nas_mm().error("Encode De-registration Accept message error!");
return; return;
} }
...@@ -2548,6 +2536,29 @@ void amf_n1::ue_initiate_de_registration_handle( ...@@ -2548,6 +2536,29 @@ void amf_n1::ue_initiate_de_registration_handle(
if (nc.get()->is_stacs_available) { if (nc.get()->is_stacs_available) {
stacs.update_5gmm_state(nc.get()->imsi, "5GMM-DEREGISTERED"); stacs.update_5gmm_state(nc.get()->imsi, "5GMM-DEREGISTERED");
} }
// TODO: AMF to AN: N2 UE Context Release Request
// AMF sends N2 UE Release command to NG-RAN with Cause set to Deregistration
// to release N2 signalling connection
Logger::ngap().debug(
"Sending ITTI UE Context Release Command to TASK_AMF_N2");
itti_ue_context_release_command* itti_msg =
new itti_ue_context_release_command(TASK_AMF_N1, TASK_AMF_N2);
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->cause.setChoiceOfCause(Ngap_Cause_PR_nas);
itti_msg->cause.setValue(2); // cause nas(2)--deregister
std::shared_ptr<itti_ue_context_release_command> i =
std::shared_ptr<itti_ue_context_release_command>(itti_msg);
int ret = itti_inst->send_msg(i);
if (0 != ret) {
Logger::ngap().error(
"Could not send ITTI message %s to task TASK_AMF_N2",
i->get_msg_name());
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -152,6 +152,13 @@ void amf_n2_task(void* args_p) { ...@@ -152,6 +152,13 @@ void amf_n2_task(void* args_p) {
dynamic_cast<itti_ue_context_release_command*>(msg); dynamic_cast<itti_ue_context_release_command*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} break; } break;
case UE_CONTEXT_RELEASE_COMPLETE: {
Logger::task_amf_n2().info(
"Received UE_CONTEXT_RELEASE_COMPLETE message, handling");
itti_ue_context_release_complete* m =
dynamic_cast<itti_ue_context_release_complete*>(msg);
amf_n2_inst->handle_itti_message(ref(*m));
} break;
case PDU_SESSION_RESOURCE_RELEASE_COMMAND: { case PDU_SESSION_RESOURCE_RELEASE_COMMAND: {
Logger::task_amf_n2().info( Logger::task_amf_n2().info(
"Received PDU_SESSION_RESOURCE_RELEASE_COMMAND message, handling"); "Received PDU_SESSION_RESOURCE_RELEASE_COMMAND message, handling");
...@@ -957,42 +964,57 @@ void amf_n2::handle_itti_message(itti_ue_context_release_request& itti_msg) { ...@@ -957,42 +964,57 @@ void amf_n2::handle_itti_message(itti_ue_context_release_request& itti_msg) {
} }
void amf_n2::handle_itti_message(itti_ue_context_release_command& itti_msg) { void amf_n2::handle_itti_message(itti_ue_context_release_command& itti_msg) {
Logger::amf_n2().debug("handling ue context release command ..."); Logger::amf_n2().debug("Handling UE Context Release Command ...");
std::shared_ptr<ue_ngap_context> unc; std::shared_ptr<ue_ngap_context> unc;
unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id);
if (unc.get() == nullptr) { if (unc.get() == nullptr) {
Logger::amf_n2().error( Logger::amf_n2().error(
"Illegal ue with ran_ue_ngap_id(0x%x)", itti_msg.ran_ue_ngap_id); "Illegal UE with ran_ue_ngap_id (0x%x)", itti_msg.ran_ue_ngap_id);
return; return;
} }
std::shared_ptr<gnb_context> gc; std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id); gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) { if (gc.get() == nullptr) {
Logger::amf_n2().error( Logger::amf_n2().error(
"Illegal gnb with assoc id(0x%x)", unc.get()->gnb_assoc_id); "Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return; return;
} }
// UEContextReleaseCommandMsg* ueCtxRelCmd = new UEContextReleaseCommandMsg();
std::unique_ptr<UEContextReleaseCommandMsg> ueCtxRelCmd = std::unique_ptr<UEContextReleaseCommandMsg> ueCtxRelCmd =
std::make_unique<UEContextReleaseCommandMsg>(); std::make_unique<UEContextReleaseCommandMsg>();
ueCtxRelCmd->setMessageType(); ueCtxRelCmd->setMessageType();
ueCtxRelCmd->setUeNgapIdPair( ueCtxRelCmd->setUeNgapIdPair(
itti_msg.amf_ue_ngap_id, itti_msg.ran_ue_ngap_id); itti_msg.amf_ue_ngap_id, itti_msg.ran_ue_ngap_id);
if (itti_msg.cause.getChoiceOfCause() == Ngap_Cause_PR_nas) { if (itti_msg.cause.getChoiceOfCause() == Ngap_Cause_PR_nas) {
ueCtxRelCmd->setCauseNas((e_Ngap_CauseNas) itti_msg.cause.getValue()); ueCtxRelCmd->setCauseNas((e_Ngap_CauseNas) itti_msg.cause.getValue());
} }
if (itti_msg.cause.getChoiceOfCause() == Ngap_Cause_PR_radioNetwork) { if (itti_msg.cause.getChoiceOfCause() == Ngap_Cause_PR_radioNetwork) {
ueCtxRelCmd->setCauseRadioNetwork( ueCtxRelCmd->setCauseRadioNetwork(
(e_Ngap_CauseRadioNetwork) itti_msg.cause.getValue()); (e_Ngap_CauseRadioNetwork) itti_msg.cause.getValue());
} }
uint8_t buffer[200];
uint8_t buffer[200]; // TODO: remove hardcoded value
int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200); int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200);
// delete ueCtxRelCmd;
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg( sctp_s_38412.sctp_send_msg(
gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b); gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
return;
}
//------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_ue_context_release_complete& itti_msg) {
Logger::amf_n2().debug("Handling UE Context Release Complete ...");
unsigned long amf_ue_ngap_id = itti_msg.ueCtxRelCmpl->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.ueCtxRelCmpl->getRanUeNgapId();
// TODO: User Location Information IE
// TODO: Information on Recommended Cells & RAN Nodes for Paging IE
// TODO: Process Secondary RAT Usage Information IE if available
// send Nsmf_PDUSession_UpdateSMContext to SMF
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -54,6 +54,7 @@ class amf_n2 : public ngap::ngap_app { ...@@ -54,6 +54,7 @@ class amf_n2 : public ngap::ngap_app {
void handle_itti_message(itti_initial_context_setup_request& itti_msg); void handle_itti_message(itti_initial_context_setup_request& itti_msg);
void handle_itti_message(itti_pdu_session_resource_setup_request& itti_msg); void handle_itti_message(itti_pdu_session_resource_setup_request& itti_msg);
void handle_itti_message(itti_ue_context_release_request& itti_msg); void handle_itti_message(itti_ue_context_release_request& itti_msg);
void handle_itti_message(itti_ue_context_release_complete& itti_msg);
void handle_itti_message(itti_ue_radio_capability_indication& itti_msg); void handle_itti_message(itti_ue_radio_capability_indication& itti_msg);
void handle_itti_message(itti_ue_context_release_command& itti_msg); void handle_itti_message(itti_ue_context_release_command& itti_msg);
void handle_itti_message(itti_pdu_session_resource_release_command& itti_msg); void handle_itti_message(itti_pdu_session_resource_release_command& itti_msg);
......
...@@ -71,6 +71,7 @@ typedef enum { ...@@ -71,6 +71,7 @@ typedef enum {
PDU_SESSION_RESOURCE_SETUP_REQUEST, PDU_SESSION_RESOURCE_SETUP_REQUEST,
PDU_SESSION_RESOURCE_RELEASE_COMMAND, PDU_SESSION_RESOURCE_RELEASE_COMMAND,
UE_CONTEXT_RELEASE_REQUEST, UE_CONTEXT_RELEASE_REQUEST,
UE_CONTEXT_RELEASE_COMPLETE,
UE_RADIO_CAP_IND, UE_RADIO_CAP_IND,
UL_NAS_DATA_IND, // task amf_n1 message id UL_NAS_DATA_IND, // task amf_n1 message id
DOWNLINK_NAS_TRANSFER, DOWNLINK_NAS_TRANSFER,
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "NGReset.hpp" #include "NGReset.hpp"
#include "NGSetupRequest.hpp" #include "NGSetupRequest.hpp"
#include "UEContextReleaseRequest.hpp" #include "UEContextReleaseRequest.hpp"
#include "UEContextReleaseComplete.hpp"
#include "UERadioCapabilityInfoIndication.hpp" #include "UERadioCapabilityInfoIndication.hpp"
#include "UplinkNASTransport.hpp" #include "UplinkNASTransport.hpp"
#include "UplinkRANStatusTransfer.hpp" #include "UplinkRANStatusTransfer.hpp"
...@@ -191,6 +192,16 @@ class itti_ue_context_release_command : public itti_msg_n2 { ...@@ -191,6 +192,16 @@ class itti_ue_context_release_command : public itti_msg_n2 {
Cause cause; Cause cause;
}; };
class itti_ue_context_release_complete : public itti_msg_n2 {
public:
itti_ue_context_release_complete(
const task_id_t origin, const task_id_t destination)
: itti_msg_n2(UE_CONTEXT_RELEASE_COMPLETE, origin, destination) {}
itti_ue_context_release_complete(const itti_ue_context_release_complete& i)
: itti_msg_n2(i) {}
UEContextReleaseCompleteMsg* ueCtxRelCmpl;
};
class itti_ue_radio_capability_indication : public itti_msg_n2 { class itti_ue_radio_capability_indication : public itti_msg_n2 {
public: public:
itti_ue_radio_capability_indication( itti_ue_radio_capability_indication(
......
...@@ -47,8 +47,8 @@ typedef struct Ngap_AssociatedQosFlowItem { ...@@ -47,8 +47,8 @@ typedef struct Ngap_AssociatedQosFlowItem {
} Ngap_AssociatedQosFlowItem_t; } Ngap_AssociatedQosFlowItem_t;
/* Implementation */ /* Implementation */
/* extern asn_TYPE_descriptor_t asn_DEF_Ngap_qosFlowMappingIndication_3; // /* extern asn_TYPE_descriptor_t asn_DEF_Ngap_qosFlowMappingIndication_3;
* (Use -fall-defs-global to expose) */ * // (Use -fall-defs-global to expose) */
extern asn_TYPE_descriptor_t asn_DEF_Ngap_AssociatedQosFlowItem; extern asn_TYPE_descriptor_t asn_DEF_Ngap_AssociatedQosFlowItem;
extern asn_SEQUENCE_specifics_t asn_SPC_Ngap_AssociatedQosFlowItem_specs_1; extern asn_SEQUENCE_specifics_t asn_SPC_Ngap_AssociatedQosFlowItem_specs_1;
extern asn_TYPE_member_t asn_MBR_Ngap_AssociatedQosFlowItem_1[3]; extern asn_TYPE_member_t asn_MBR_Ngap_AssociatedQosFlowItem_1[3];
......
...@@ -44,30 +44,27 @@ asn_SET_OF_specifics_t ...@@ -44,30 +44,27 @@ asn_SET_OF_specifics_t
struct Ngap_PDUSessionResourceFailedToSetupListCxtFail, _asn_ctx), struct Ngap_PDUSessionResourceFailedToSetupListCxtFail, _asn_ctx),
0, /* XER encoding is XMLDelimitedItemList */ 0, /* XER encoding is XMLDelimitedItemList */
}; };
asn_TYPE_descriptor_t asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail = asn_TYPE_descriptor_t asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail = {
{ "PDUSessionResourceFailedToSetupListCxtFail",
"PDUSessionResourceFailedToSetupListCxtFail", "PDUSessionResourceFailedToSetupListCxtFail",
"PDUSessionResourceFailedToSetupListCxtFail", &asn_OP_SEQUENCE_OF,
&asn_OP_SEQUENCE_OF, asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1,
asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1, sizeof(asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1) /
sizeof(asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1) / sizeof(asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1
sizeof( [0]), /* 1 */
asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1 asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1, /* Same
[0]), /* 1 */ as
asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1, /* Same above
as */
above sizeof(asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1) /
*/ sizeof(asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1
sizeof(asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1) / [0]), /* 1 */
sizeof( {&asn_OER_type_Ngap_PDUSessionResourceFailedToSetupListCxtFail_constr_1,
asn_DEF_Ngap_PDUSessionResourceFailedToSetupListCxtFail_tags_1 &asn_PER_type_Ngap_PDUSessionResourceFailedToSetupListCxtFail_constr_1,
[0]), /* 1 */ SEQUENCE_OF_constraint},
{&asn_OER_type_Ngap_PDUSessionResourceFailedToSetupListCxtFail_constr_1, asn_MBR_Ngap_PDUSessionResourceFailedToSetupListCxtFail_1,
&asn_PER_type_Ngap_PDUSessionResourceFailedToSetupListCxtFail_constr_1, 1, /* Single element */
SEQUENCE_OF_constraint}, &asn_SPC_Ngap_PDUSessionResourceFailedToSetupListCxtFail_specs_1 /* Additional
asn_MBR_Ngap_PDUSessionResourceFailedToSetupListCxtFail_1, specs
1, /* Single element */ */
&asn_SPC_Ngap_PDUSessionResourceFailedToSetupListCxtFail_specs_1 /* Additional
specs
*/
}; };
...@@ -118,7 +118,7 @@ static const asn_ioc_cell_t ...@@ -118,7 +118,7 @@ static const asn_ioc_cell_t
//"&criticality", aioc__value, &asn_DEF_Ngap_Criticality, //"&criticality", aioc__value, &asn_DEF_Ngap_Criticality,
//&asn_VAL_9_Ngap_reject }, { "&Value", aioc__type, //&asn_VAL_9_Ngap_reject }, { "&Value", aioc__type,
//&asn_DEF_Ngap_UPTransportLayerInformation }, { "&presence", //&asn_DEF_Ngap_UPTransportLayerInformation }, { "&presence",
//aioc__value, &asn_DEF_Ngap_Presence, &asn_VAL_9_Ngap_optional }, // aioc__value, &asn_DEF_Ngap_Presence, &asn_VAL_9_Ngap_optional },
{"&id", aioc__value, &asn_DEF_Ngap_ProtocolIE_ID, {"&id", aioc__value, &asn_DEF_Ngap_ProtocolIE_ID,
&asn_VAL_10_Ngap_id_DataForwardingNotPossible}, &asn_VAL_10_Ngap_id_DataForwardingNotPossible},
{"&criticality", aioc__value, &asn_DEF_Ngap_Criticality, {"&criticality", aioc__value, &asn_DEF_Ngap_Criticality,
...@@ -58,8 +58,7 @@ void PlmnId::setMccMnc(const std::string mcc, const std::string mnc) { ...@@ -58,8 +58,7 @@ void PlmnId::setMccMnc(const std::string mcc, const std::string mnc) {
int mncValue = fromString<int>(mnc); int mncValue = fromString<int>(mnc);
mcc_digit1 = mccValue / 100; mcc_digit1 = mccValue / 100;
mcc_digit2 = (mccValue - mcc_digit1 * 100) / mcc_digit2 = (mccValue - mcc_digit1 * 100) / 10;
10;
mcc_digit3 = mccValue % 10; mcc_digit3 = mccValue % 10;
if (mncValue > 99) { if (mncValue > 99) {
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "UEContextReleaseComplete.hpp" #include "UEContextReleaseComplete.hpp"
#include <iostream> #include <iostream>
#include <memory>
extern "C" { extern "C" {
#include "asn_codecs.h" #include "asn_codecs.h"
#include "constr_TYPE.h" #include "constr_TYPE.h"
...@@ -89,6 +91,11 @@ void UEContextReleaseCompleteMsg::setAmfUeNgapId(unsigned long id) { ...@@ -89,6 +91,11 @@ void UEContextReleaseCompleteMsg::setAmfUeNgapId(unsigned long id) {
// free_wrapper((void**) &ie); // free_wrapper((void**) &ie);
} }
//------------------------------------------------------------------------------
unsigned long UEContextReleaseCompleteMsg::getAmfUeNgapId() const {
if (amfUeNgapId) return amfUeNgapId->getAMF_UE_NGAP_ID();
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void UEContextReleaseCompleteMsg::setRanUeNgapId(uint32_t ran_ue_ngap_id) { void UEContextReleaseCompleteMsg::setRanUeNgapId(uint32_t ran_ue_ngap_id) {
if (!ranUeNgapId) ranUeNgapId = new RAN_UE_NGAP_ID(); if (!ranUeNgapId) ranUeNgapId = new RAN_UE_NGAP_ID();
...@@ -111,6 +118,11 @@ void UEContextReleaseCompleteMsg::setRanUeNgapId(uint32_t ran_ue_ngap_id) { ...@@ -111,6 +118,11 @@ void UEContextReleaseCompleteMsg::setRanUeNgapId(uint32_t ran_ue_ngap_id) {
// free_wrapper((void**) &ie); // free_wrapper((void**) &ie);
} }
//------------------------------------------------------------------------------
uint32_t UEContextReleaseCompleteMsg::getRanUeNgapId() const {
if (ranUeNgapId) return ranUeNgapId->getRanUeNgapId();
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void UEContextReleaseCompleteMsg::setUserLocationInfoNR( void UEContextReleaseCompleteMsg::setUserLocationInfoNR(
struct NrCgi_s cig, struct Tai_s tai) { struct NrCgi_s cig, struct Tai_s tai) {
...@@ -156,6 +168,40 @@ void UEContextReleaseCompleteMsg::setUserLocationInfoNR( ...@@ -156,6 +168,40 @@ void UEContextReleaseCompleteMsg::setUserLocationInfoNR(
// free_wrapper((void**) &ie); // free_wrapper((void**) &ie);
} }
//------------------------------------------------------------------------------
void UEContextReleaseCompleteMsg::getUserLocationInfoNR(
struct NrCgi_s& cig, struct Tai_s& tai) {
// TODO:
/*
if (userLocationInformation) {
UserLocationInformationNR* informationNR = new
UserLocationInformationNR();
userLocationInformation->getInformation(informationNR);
//std::unique_ptr<NR_CGI> nR_CGI = std::make_unique<NR_CGI>();
NR_CGI* nR_CGI = new NR_CGI();
TAI* tai_nr = new TAI();
informationNR->getInformationNR(nR_CGI, tai_nr);
PlmnId* plmnId_cgi = new PlmnId();
NRCellIdentity* nRCellIdentity = new NRCellIdentity();
nR_CGI->getNR_CGI(plmnId_cgi, nRCellIdentity);
cig.nrCellID = nRCellIdentity->getNRCellIdentity();
plmnId_cgi->getMcc(cig.mcc);
plmnId_cgi->getMnc(cig.mnc);
PlmnId* plmnId = new PlmnId();
TAC* tac = new TAC();
tai_nr->getTAI(plmnId, tac);
plmnId->getMcc(tai.mcc);
plmnId->getMnc(tai.mnc);
tai.tac = tac->getTac() & 0x00ffffff;
}
*/
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int UEContextReleaseCompleteMsg::encode2buffer(uint8_t* buf, int buf_size) { int UEContextReleaseCompleteMsg::encode2buffer(uint8_t* buf, int buf_size) {
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, pdu); asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, pdu);
...@@ -164,3 +210,72 @@ int UEContextReleaseCompleteMsg::encode2buffer(uint8_t* buf, int buf_size) { ...@@ -164,3 +210,72 @@ int UEContextReleaseCompleteMsg::encode2buffer(uint8_t* buf, int buf_size) {
cout << "er.encoded(" << er.encoded << ")" << endl; cout << "er.encoded(" << er.encoded << ")" << endl;
return er.encoded; return er.encoded;
} }
//------------------------------------------------------------------------------
bool UEContextReleaseCompleteMsg::decodefrompdu(Ngap_NGAP_PDU_t* ngap_msg_pdu) {
pdu = ngap_msg_pdu;
if (pdu->present == Ngap_NGAP_PDU_PR_successfulOutcome) {
if (pdu->choice.successfulOutcome &&
pdu->choice.successfulOutcome->procedureCode ==
Ngap_ProcedureCode_id_UEContextRelease &&
pdu->choice.successfulOutcome->criticality == Ngap_Criticality_reject &&
pdu->choice.successfulOutcome->value.present ==
Ngap_SuccessfulOutcome__value_PR_UEContextReleaseComplete) {
ies =
&pdu->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
} else {
cout << "Check UEContextReleaseComplete message error" << endl;
return false;
}
} else {
cout << "typeOfMessage of UEContextReleaseComplete is not SuccessfulOutcome"
<< endl;
return false;
}
// TODO
for (int i = 0; i < ies->protocolIEs.list.count; i++) {
switch (ies->protocolIEs.list.array[i]->id) {
case Ngap_ProtocolIE_ID_id_AMF_UE_NGAP_ID: {
if (ies->protocolIEs.list.array[i]->criticality ==
Ngap_Criticality_ignore &&
ies->protocolIEs.list.array[i]->value.present ==
Ngap_UEContextReleaseComplete_IEs__value_PR_AMF_UE_NGAP_ID) {
amfUeNgapId = new AMF_UE_NGAP_ID();
if (!amfUeNgapId->decodefromAMF_UE_NGAP_ID(
ies->protocolIEs.list.array[i]
->value.choice.AMF_UE_NGAP_ID)) {
cout << "decode AMF_UE_NGAP_ID error" << endl;
return false;
}
} else {
cout << "IE AMF_UE_NGAP_ID is not correct" << endl;
return false;
}
} break;
case Ngap_ProtocolIE_ID_id_RAN_UE_NGAP_ID: {
if (ies->protocolIEs.list.array[i]->criticality ==
Ngap_Criticality_ignore &&
ies->protocolIEs.list.array[i]->value.present ==
Ngap_UEContextReleaseComplete_IEs__value_PR_RAN_UE_NGAP_ID) {
ranUeNgapId = new RAN_UE_NGAP_ID();
if (!ranUeNgapId->decodefromRAN_UE_NGAP_ID(
ies->protocolIEs.list.array[i]
->value.choice.RAN_UE_NGAP_ID)) {
cout << "decode RAN_UE_NGAP_ID error" << endl;
return false;
}
} else {
cout << "IE RAN_UE_NGAP_ID is not correct" << endl;
return false;
}
} break;
// TODO: User Location Information
// TODO: Information on Recommended Cells and RAN Nodes for Paging
// TODO: PDU Session Resource List
// TODO: Criticality Diagnostics
}
}
return true;
}
...@@ -50,9 +50,13 @@ class UEContextReleaseCompleteMsg { ...@@ -50,9 +50,13 @@ class UEContextReleaseCompleteMsg {
public: public:
void setMessageType(); void setMessageType();
void setAmfUeNgapId(unsigned long id); void setAmfUeNgapId(unsigned long id);
unsigned long getAmfUeNgapId() const;
void setRanUeNgapId(uint32_t ran_ue_ngap_id); void setRanUeNgapId(uint32_t ran_ue_ngap_id);
uint32_t getRanUeNgapId() const;
void setUserLocationInfoNR(struct NrCgi_s cig, struct Tai_s tai); void setUserLocationInfoNR(struct NrCgi_s cig, struct Tai_s tai);
void getUserLocationInfoNR(struct NrCgi_s& cig, struct Tai_s& tai);
int encode2buffer(uint8_t* buf, int buf_size); int encode2buffer(uint8_t* buf, int buf_size);
bool decodefrompdu(Ngap_NGAP_PDU_t* ngap_msg_pdu);
private: private:
Ngap_NGAP_PDU_t* pdu; Ngap_NGAP_PDU_t* pdu;
......
...@@ -263,6 +263,25 @@ int ngap_amf_handle_ue_context_release_complete( ...@@ -263,6 +263,25 @@ int ngap_amf_handle_ue_context_release_complete(
struct Ngap_NGAP_PDU* message_p) { struct Ngap_NGAP_PDU* message_p) {
Logger::ngap().debug( Logger::ngap().debug(
"Sending itti ue context release complete to TASK_AMF_N2"); "Sending itti ue context release complete to TASK_AMF_N2");
UEContextReleaseCompleteMsg* ueCtxRelCmpl = new UEContextReleaseCompleteMsg();
if (!ueCtxRelCmpl->decodefrompdu(message_p)) {
Logger::ngap().error("Decoding UEContextReleaseComplete message error");
return -1;
}
itti_ue_context_release_complete* itti_msg =
new itti_ue_context_release_complete(TASK_NGAP, TASK_AMF_N2);
itti_msg->assoc_id = assoc_id;
itti_msg->stream = stream;
itti_msg->ueCtxRelCmpl = ueCtxRelCmpl;
std::shared_ptr<itti_ue_context_release_complete> i =
std::shared_ptr<itti_ue_context_release_complete>(itti_msg);
int ret = itti_inst->send_msg(i);
if (0 != ret) {
Logger::ngap().error(
"Could not send ITTI message %s to task TASK_AMF_N2",
i->get_msg_name());
}
return 0; return 0;
} }
......
...@@ -87,7 +87,7 @@ int sctp_server::create_socket(const char* address, const uint16_t port_num) { ...@@ -87,7 +87,7 @@ int sctp_server::create_socket(const char* address, const uint16_t port_num) {
events_.sctp_association_event = 1; events_.sctp_association_event = 1;
setsockopt( setsockopt(
socket_, IPPROTO_SCTP, SCTP_EVENTS, &events_, socket_, IPPROTO_SCTP, SCTP_EVENTS, &events_,
sizeof(struct sctp_event_subscribe)); 8);
listen(socket_, 5); listen(socket_, 5);
return 0; return 0;
} }
......
...@@ -540,7 +540,7 @@ uint8_t* Authentication_5gaka::sqn_ms_derive( ...@@ -540,7 +540,7 @@ uint8_t* Authentication_5gaka::sqn_ms_derive(
uint8_t* mac_s = NULL; uint8_t* mac_s = NULL;
uint8_t mac_s_computed[MAC_S_LENGTH] = {0}; uint8_t mac_s_computed[MAC_S_LENGTH] = {0};
uint8_t* sqn_ms = NULL; uint8_t* sqn_ms = NULL;
uint8_t amf[2] = {0x00, 0x00}; // TODO: To be verified uint8_t amf[2] = {0x00, 0x00};
int i = 0; int i = 0;
conc_sqn_ms = auts; conc_sqn_ms = auts;
...@@ -560,19 +560,18 @@ uint8_t* Authentication_5gaka::sqn_ms_derive( ...@@ -560,19 +560,18 @@ uint8_t* Authentication_5gaka::sqn_ms_derive(
sqn_ms[i] = ak[i] ^ conc_sqn_ms[i]; sqn_ms[i] = ak[i] ^ conc_sqn_ms[i];
} }
// print_buffer ("sqn_ms_derive() KEY : ", key, 16); print_buffer("amf_n1", "sqn_ms_derive() KEY : ", key, 16);
// print_buffer ("sqn_ms_derive() RAND : ", rand_p, 16); print_buffer("amf_n1", "sqn_ms_derive() RAND : ", rand_p, 16);
// print_buffer ("sqn_ms_derive() AUTS : ", auts, 14); print_buffer("amf_n1", "sqn_ms_derive() AUTS : ", auts, 14);
// print_buffer ("sqn_ms_derive() AK : ", ak, 6); print_buffer("amf_n1", "sqn_ms_derive() AK : ", ak, 6);
// print_buffer ("sqn_ms_derive() SQN_MS : ", sqn_ms, 6); print_buffer("amf_n1", "sqn_ms_derive() SQN_MS : ", sqn_ms, 6);
// print_buffer ("sqn_ms_derive() MAC_S : ", mac_s, 8); print_buffer("amf_n1", "sqn_ms_derive() MAC_S : ", mac_s, 8);
f1star(opc, key, rand_p, sqn_ms, amf, mac_s_computed); f1star(opc, key, rand_p, sqn_ms, amf, mac_s_computed);
// print_buffer ("MAC_S +: ", mac_s_computed, 8); print_buffer("amf_n1", "MAC_S computed : ", mac_s_computed, 8);
if (memcmp(mac_s_computed, mac_s, 8) != 0) { if (memcmp(mac_s_computed, mac_s, 8) != 0) {
Logger::amf_n1().debug( // FPRINTF_ERROR ( "Failed to verify computed SQN_MS\n");
"sqn_ms_derive, failed to verify computed SQN_MS (MAC does not " Logger::amf_n1().warn("Failed to verify computed SQN_MS");
"matched!)");
free(sqn_ms); free(sqn_ms);
return NULL; return NULL;
} }
......
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