Commit ca9dadc7 authored by Keliang's avatar Keliang

The version is same as eurecom

parents 460e39a2 aef65b41
......@@ -115,4 +115,3 @@ SortUsingDeclarations: true
# PenaltyBreakTemplateDeclaration (unsigned)
# PenaltyExcessCharacter (unsigned)
# PenaltyReturnTypeOnItsOwnLine (unsigned)
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -28,18 +28,18 @@
#include "amf_app.hpp"
#include <stdexcept>
#include <iostream>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include "itti.hpp"
#include "ngap_app.hpp"
#include "DLNASTransport.hpp"
#include "amf_config.hpp"
#include "amf_n2.hpp"
#include "amf_n1.hpp"
#include "amf_n11.hpp"
#include "amf_n2.hpp"
#include "amf_statistics.hpp"
#include "DLNASTransport.hpp"
#include "ngap_app.hpp"
using namespace ngap;
using namespace nas;
......@@ -56,7 +56,7 @@ amf_n11* amf_n11_inst = nullptr;
extern amf_config amf_cfg;
extern statistics stacs;
void amf_app_task(void*);
void amf_app_task(void *);
uint32_t golbal_tmsi = 1;
//------------------------------------------------------------------------------
......@@ -77,9 +77,9 @@ amf_app::amf_app(const amf_config& amf_cfg) {
throw;
}
timer_id_t tid = itti_inst->timer_setup(
amf_cfg.statistics_interval, 0, TASK_AMF_APP,
TASK_AMF_APP_PERIODIC_STATISTICS, 0);
timer_id_t tid =
itti_inst->timer_setup(amf_cfg.statistics_interval, 0, TASK_AMF_APP,
TASK_AMF_APP_PERIODIC_STATISTICS, 0);
Logger::amf_app().startup("Started timer(%d)", tid);
}
......@@ -89,7 +89,7 @@ void amf_app::allRegistredModulesInit(const amf_modules& modules) {
}
//------------------------------------------------------------------------------
void amf_app_task(void*) {
void amf_app_task(void *) {
const task_id_t task_id = TASK_AMF_APP;
itti_inst->notify_task_ready(task_id);
do {
......@@ -99,25 +99,25 @@ void amf_app_task(void*) {
switch (msg->msg_type) {
case NAS_SIG_ESTAB_REQ: {
Logger::amf_app().debug("Received NAS_SIG_ESTAB_REQ");
itti_nas_signalling_establishment_request* m =
dynamic_cast<itti_nas_signalling_establishment_request*>(msg);
itti_nas_signalling_establishment_request *m =
dynamic_cast<itti_nas_signalling_establishment_request *>(msg);
amf_app_inst->handle_itti_message(ref(*m));
} break;
case N1N2_MESSAGE_TRANSFER_REQ: {
Logger::amf_app().debug("Received N1N2_MESSAGE_TRANSFER_REQ");
itti_n1n2_message_transfer_request* m =
dynamic_cast<itti_n1n2_message_transfer_request*>(msg);
itti_n1n2_message_transfer_request *m =
dynamic_cast<itti_n1n2_message_transfer_request *>(msg);
amf_app_inst->handle_itti_message(ref(*m));
} break;
case TIME_OUT:
if (itti_msg_timeout* to = dynamic_cast<itti_msg_timeout*>(msg)) {
if (itti_msg_timeout *to = dynamic_cast<itti_msg_timeout *>(msg)) {
switch (to->arg1_user) {
case TASK_AMF_APP_PERIODIC_STATISTICS:
tid = itti_inst->timer_setup(
amf_cfg.statistics_interval, 0, TASK_AMF_APP,
TASK_AMF_APP_PERIODIC_STATISTICS, 0);
tid = itti_inst->timer_setup(amf_cfg.statistics_interval, 0,
TASK_AMF_APP,
TASK_AMF_APP_PERIODIC_STATISTICS, 0);
stacs.display();
break;
default:
......@@ -183,20 +183,20 @@ void amf_app::set_ran_amf_id_2_ue_context(
// ITTI handlers
//------------------------------------------------------------------------------
void amf_app::handle_itti_message(
itti_n1n2_message_transfer_request& itti_msg) {
itti_n1n2_message_transfer_request &itti_msg) {
// 1. encode DL NAS TRANSPORT message(NAS message)
DLNASTransport* dl = new DLNASTransport();
DLNASTransport *dl = new DLNASTransport();
dl->setHeader(PLAIN_5GS_MSG);
dl->setPayload_Container_Type(N1_SM_INFORMATION);
dl->setPayload_Container(
(uint8_t*) bdata(itti_msg.n1sm), blength(itti_msg.n1sm));
dl->setPayload_Container((uint8_t *)bdata(itti_msg.n1sm),
blength(itti_msg.n1sm));
dl->setPDUSessionId(itti_msg.pdu_session_id);
uint8_t nas[1024];
int encoded_size = dl->encode2buffer(nas, 1024);
print_buffer("amf_app", "n1n2 transfer", nas, encoded_size);
bstring dl_nas = blk2bstr(nas, encoded_size);
itti_downlink_nas_transfer* dl_msg =
itti_downlink_nas_transfer *dl_msg =
new itti_downlink_nas_transfer(TASK_AMF_APP, TASK_AMF_N1);
dl_msg->dl_nas = dl_nas;
if (!itti_msg.is_n2sm_set) {
......@@ -221,7 +221,7 @@ void amf_app::handle_itti_message(
//------------------------------------------------------------------------------
void amf_app::handle_itti_message(
itti_nas_signalling_establishment_request& itti_msg) {
itti_nas_signalling_establishment_request &itti_msg) {
// 1. generate amf_ue_ngap_id
// 2. establish ue_context associated with amf_ue_ngap_id
// 3. store ue-reated core information
......@@ -253,7 +253,7 @@ void amf_app::handle_itti_message(
uc.get()->tai = itti_msg.tai;
if (itti_msg.rrc_cause != -1)
uc.get()->rrc_estb_cause =
(e_Ngap_RRCEstablishmentCause) itti_msg.rrc_cause;
(e_Ngap_RRCEstablishmentCause)itti_msg.rrc_cause;
if (itti_msg.ueCtxReq == -1)
uc.get()->isUeContextRequest = false;
else
......@@ -270,10 +270,10 @@ void amf_app::handle_itti_message(
Logger::amf_app().debug("Receiving GUTI %s", guti.c_str());
}
itti_uplink_nas_data_ind* itti_n1_msg =
itti_uplink_nas_data_ind *itti_n1_msg =
new itti_uplink_nas_data_ind(TASK_AMF_APP, TASK_AMF_N1);
itti_n1_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_n1_msg->ran_ue_ngap_id = itti_msg.ran_ue_ngap_id;
itti_n1_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_n1_msg->ran_ue_ngap_id = itti_msg.ran_ue_ngap_id;
itti_n1_msg->is_nas_signalling_estab_req = true;
itti_n1_msg->nas_msg = itti_msg.nas_buf;
itti_n1_msg->mcc = itti_msg.tai.mcc;
......@@ -299,8 +299,8 @@ void amf_app::handle_post_sm_context_response_error_400() {
Logger::amf_app().error("Post SM context response error 400");
}
bool amf_app::generate_5g_guti(
uint32_t ranid, long amfid, string& mcc, string& mnc, uint32_t& tmsi) {
bool amf_app::generate_5g_guti(uint32_t ranid, long amfid, string &mcc,
string &mnc, uint32_t &tmsi) {
string ue_context_key =
"app_ue_ranid_" + to_string(ranid) + ":amfid_" + to_string(amfid);
if (!is_ran_amf_id_2_ue_context(ue_context_key)) {
......@@ -309,9 +309,9 @@ bool amf_app::generate_5g_guti(
return false;
}
std::shared_ptr<ue_context> uc;
uc = ran_amf_id_2_ue_context(ue_context_key);
mcc = uc.get()->tai.mcc;
mnc = uc.get()->tai.mnc;
uc = ran_amf_id_2_ue_context(ue_context_key);
mcc = uc.get()->tai.mcc;
mnc = uc.get()->tai.mnc;
tmsi = golbal_tmsi;
golbal_tmsi++;
return true;
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -47,14 +47,14 @@ namespace amf_application {
class amf_app {
public:
explicit amf_app(const amf_config& amf_cfg);
amf_app(amf_app const&) = delete;
void operator=(amf_app const&) = delete;
void allRegistredModulesInit(const amf_modules& modules);
explicit amf_app(const amf_config &amf_cfg);
amf_app(amf_app const &) = delete;
void operator=(amf_app const &) = delete;
void allRegistredModulesInit(const amf_modules &modules);
long generate_amf_ue_ngap_id();
// itti handlers
void handle_itti_message(itti_nas_signalling_establishment_request& itti_msg);
void handle_itti_message(itti_n1n2_message_transfer_request& itti_msg);
void handle_itti_message(itti_nas_signalling_establishment_request &itti_msg);
void handle_itti_message(itti_n1n2_message_transfer_request &itti_msg);
// context management
std::map<long, std::shared_ptr<ue_context>> amf_ue_ngap_id2ue_ctx;
mutable std::shared_mutex m_amf_ue_ngap_id2ue_ctx;
......@@ -75,9 +75,8 @@ class amf_app {
// SMF Client response handlers
void handle_post_sm_context_response_error_400();
// others
bool generate_5g_guti(
uint32_t ranid, long amfid, std::string& mcc, std::string& mnc,
uint32_t& tmsi);
bool generate_5g_guti(uint32_t ranid, long amfid, std::string &mcc,
std::string &mnc, uint32_t &tmsi);
};
} // namespace amf_application
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -37,10 +37,10 @@
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include "logger.hpp"
#include "3gpp_ts24501.hpp"
#include "amf_app.hpp"
#include "if.hpp"
#include "3gpp_ts24501.hpp"
#include "logger.hpp"
extern "C" {
#include <arpa/inet.h>
......@@ -128,7 +128,7 @@ int amf_config::load(const std::string& config_file) {
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
try {
const Setting& guami_list_cfg =
const Setting &guami_list_cfg =
amf_cfg[AMF_CONFIG_STRING_SERVED_GUAMI_LIST];
int count = guami_list_cfg.getLength();
for (int i = 0; i < count; i++) {
......@@ -178,8 +178,8 @@ int amf_config::load(const std::string& config_file) {
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
try {
const Setting& new_if_cfg = amf_cfg[AMF_CONFIG_STRING_INTERFACES];
const Setting& n2_amf_cfg =
const Setting &new_if_cfg = amf_cfg[AMF_CONFIG_STRING_INTERFACES];
const Setting &n2_amf_cfg =
new_if_cfg[AMF_CONFIG_STRING_INTERFACE_NGAP_AMF];
load_interface(n2_amf_cfg, n2);
if (is_Nausf) {
......@@ -189,7 +189,7 @@ int amf_config::load(const std::string& config_file) {
}
const Setting& n11_cfg = new_if_cfg[AMF_CONFIG_STRING_INTERFACE_N11];
load_interface(n11_cfg, n11);
const Setting& smf_addr_pool =
const Setting &smf_addr_pool =
n11_cfg[AMF_CONFIG_STRING_SMF_INSTANCES_POOL];
int count = smf_addr_pool.getLength();
for (int i = 0; i < count; i++) {
......@@ -402,12 +402,12 @@ int amf_config::load_interface(
}
} else {
std::vector<std::string> words;
boost::split(
words, address, boost::is_any_of("/"), boost::token_compress_on);
boost::split(words, address, boost::is_any_of("/"),
boost::token_compress_on);
if (words.size() != 2) {
Logger::amf_app().error(
"Bad value " AMF_CONFIG_STRING_IPV4_ADDRESS " = %s in config file",
address.c_str());
Logger::amf_app().error("Bad value " AMF_CONFIG_STRING_IPV4_ADDRESS
" = %s in config file",
address.c_str());
return RETURNerror;
}
unsigned char buf_in_addr[sizeof(struct in6_addr)]; // you never know...
......@@ -421,9 +421,9 @@ int amf_config::load_interface(
util::trim(words.at(0)).c_str());
return RETURNerror;
}
cfg.network4.s_addr = htons(
ntohs(cfg.addr4.s_addr) &
0xFFFFFFFF << (32 - std::stoi(util::trim(words.at(1)))));
cfg.network4.s_addr =
htons(ntohs(cfg.addr4.s_addr) &
0xFFFFFFFF << (32 - std::stoi(util::trim(words.at(1)))));
}
if_cfg.lookupValue(AMF_CONFIG_STRING_PORT, cfg.port);
......@@ -439,8 +439,8 @@ int amf_config::load_interface(
}
//------------------------------------------------------------------------------
int amf_config::load_thread_sched_params(
const Setting& thread_sched_params_cfg, util::thread_sched_params& cfg) {
int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg,
util::thread_sched_params &cfg) {
try {
thread_sched_params_cfg.lookupValue(
AMF_CONFIG_STRING_THREAD_RD_CPU_ID, cfg.cpu_id);
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -29,18 +29,18 @@
#ifndef _AMF_MODULE_FROM_CONFIG_H_
#define _AMF_MODULE_FROM_CONFIG_H_
#include <libconfig.h++>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <libconfig.h++>
#include "Ngap_ProcedureCode.h"
#include "Ngap_NGAP-PDU.h"
#include "Ngap_ProcedureCode.h"
#define MODULES_CONFIG_STRING_AMF_MODULES "MODULES"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE "NGAP_MESSAGE"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_NAME "MSG_NAME"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE \
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE \
"ProcedureCode"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG "TypeOfMessage"
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -28,31 +28,31 @@
#include "amf_n1.hpp"
#include "amf_app.hpp"
#include "amf_config.hpp"
#include "amf_n11.hpp"
#include "amf_n2.hpp"
#include "AuthenticationFailure.hpp"
#include "AuthenticationRequest.hpp"
#include "AuthenticationResponse.hpp"
#include "AuthenticationFailure.hpp"
#include "comUt.hpp"
#include "DeregistrationRequest.hpp"
#include "DeregistrationAccept.hpp"
#include "itti_msg_n2.hpp"
#include "itti_msg_n11.hpp"
#include "itti.hpp"
#include "logger.hpp"
#include "nas_algorithms.hpp"
#include "SecurityModeCommand.hpp"
#include "RegistrationRequest.hpp"
#include "RegistrationAccept.hpp"
#include "DeregistrationRequest.hpp"
#include "IdentityRequest.hpp"
#include "IdentityResponse.hpp"
#include "RegistrationAccept.hpp"
#include "RegistrationReject.hpp"
#include "ULNASTransport.hpp"
#include "ServiceRequest.hpp"
#include "RegistrationRequest.hpp"
#include "SecurityModeCommand.hpp"
#include "ServiceAccept.hpp"
#include "ServiceRequest.hpp"
#include "String2Value.hpp"
#include "ULNASTransport.hpp"
#include "amf_app.hpp"
#include "amf_config.hpp"
#include "amf_n11.hpp"
#include "amf_n2.hpp"
#include "comUt.hpp"
#include "itti.hpp"
#include "itti_msg_n11.hpp"
#include "itti_msg_n2.hpp"
#include "logger.hpp"
#include "nas_algorithms.hpp"
#include "sha256.hpp"
#include "AuthenticationInfo.h"
......@@ -62,8 +62,8 @@
#include <curl/curl.h>
extern "C" {
#include "dynamic_memory_check.h"
#include "bstrlib.h"
#include "dynamic_memory_check.h"
}
using namespace oai::amf::model;
......@@ -86,10 +86,10 @@ extern int ncc;
Sha256 ctx;
random_state_t random_state;
static uint8_t no_random_delta = 0;
void amf_n1_task(void*);
void amf_n1_task(void *);
//------------------------------------------------------------------------------
void amf_n1_task(void*) {
void amf_n1_task(void *) {
const task_id_t task_id = TASK_AMF_N1;
itti_inst->notify_task_ready(task_id);
do {
......@@ -99,14 +99,14 @@ void amf_n1_task(void*) {
switch (msg->msg_type) {
case UL_NAS_DATA_IND: { // receive nas message buffer from amf_n2
Logger::amf_n1().info("Received UL_NAS_DATA_IND");
itti_uplink_nas_data_ind* m =
dynamic_cast<itti_uplink_nas_data_ind*>(msg);
itti_uplink_nas_data_ind *m =
dynamic_cast<itti_uplink_nas_data_ind *>(msg);
amf_n1_inst->handle_itti_message(ref(*m));
} break;
case DOWNLINK_NAS_TRANSFER: {
Logger::amf_n1().info("Received DOWNLINK_NAS_TRANSFER");
itti_downlink_nas_transfer* m =
dynamic_cast<itti_downlink_nas_transfer*>(msg);
itti_downlink_nas_transfer *m =
dynamic_cast<itti_downlink_nas_transfer *>(msg);
amf_n1_inst->handle_itti_message(ref(*m));
} break;
default:
......@@ -142,18 +142,18 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
}
nas_secu_ctx* secu = nc.get()->security_ctx;
bstring protected_nas;
encode_nas_message_protected(
secu, false, INTEGRITY_PROTECTED_AND_CIPHERED, NAS_MESSAGE_DOWNLINK,
(uint8_t*) bdata(itti_msg.dl_nas), blength(itti_msg.dl_nas),
protected_nas);
encode_nas_message_protected(secu, false, INTEGRITY_PROTECTED_AND_CIPHERED,
NAS_MESSAGE_DOWNLINK,
(uint8_t *)bdata(itti_msg.dl_nas),
blength(itti_msg.dl_nas), protected_nas);
if (itti_msg.is_n2sm_set) {
if (itti_msg.n2sm_info_type.compare("PDU_RES_REL_CMD") ==
0) { // PDU SESSION RESOURCE RELEASE COMMAND
itti_pdu_session_resource_release_command* release_command =
new itti_pdu_session_resource_release_command(
TASK_AMF_N1, TASK_AMF_N2);
release_command->nas = protected_nas;
release_command->n2sm = itti_msg.n2sm;
itti_pdu_session_resource_release_command *release_command =
new itti_pdu_session_resource_release_command(TASK_AMF_N1,
TASK_AMF_N2);
release_command->nas = protected_nas;
release_command->n2sm = itti_msg.n2sm;
release_command->amf_ue_ngap_id = amf_ue_ngap_id;
release_command->ran_ue_ngap_id = ran_ue_ngap_id;
release_command->pdu_session_id = itti_msg.pdu_session_id;
......@@ -167,7 +167,7 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
i->get_msg_name());
}
} else { // PDU SESSION RESOURCE SETUP_REQUEST
itti_pdu_session_resource_setup_request* psrsr =
itti_pdu_session_resource_setup_request *psrsr =
new itti_pdu_session_resource_setup_request(TASK_AMF_N1, TASK_AMF_N2);
psrsr->nas = protected_nas;
psrsr->n2sm = itti_msg.n2sm;
......@@ -185,9 +185,9 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
}
} else {
itti_dl_nas_transport* dnt =
itti_dl_nas_transport *dnt =
new itti_dl_nas_transport(TASK_AMF_N1, TASK_AMF_N2);
dnt->nas = protected_nas;
dnt->nas = protected_nas;
dnt->amf_ue_ngap_id = amf_ue_ngap_id;
dnt->ran_ue_ngap_id = ran_ue_ngap_id;
std::shared_ptr<itti_dl_nas_transport> i =
......@@ -217,8 +217,8 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
".3gppnetwork.org";
Logger::amf_n1().debug("Serving network name %s", snn.c_str());
plmn_t plmn = {};
plmn.mnc = nas_data_ind.mnc;
plmn.mcc = nas_data_ind.mcc;
plmn.mnc = nas_data_ind.mnc;
plmn.mcc = nas_data_ind.mcc;
bstring recved_nas_msg = nas_data_ind.nas_msg;
bstring decoded_plain_msg;
......@@ -242,7 +242,7 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
}
SecurityHeaderType type = {};
if (!check_security_header_type(type, (uint8_t*) bdata(recved_nas_msg))) {
if (!check_security_header_type(type, (uint8_t *)bdata(recved_nas_msg))) {
Logger::amf_n1().error("Not 5GS MOBILITY MANAGEMENT message");
return;
}
......@@ -254,11 +254,11 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
} break;
case IntegrityProtected: {
Logger::amf_n1().debug("Received integrity protected NAS message");
ulCount = *((uint8_t*) bdata(recved_nas_msg) + 6);
Logger::amf_n1().info(
"Integrity protected message: ulCount(%d)", ulCount);
decoded_plain_msg = blk2bstr(
(uint8_t*) bdata(recved_nas_msg) + 7, blength(recved_nas_msg) - 7);
ulCount = *((uint8_t *)bdata(recved_nas_msg) + 6);
Logger::amf_n1().info("Integrity protected message: ulCount(%d)",
ulCount);
decoded_plain_msg = blk2bstr((uint8_t *)bdata(recved_nas_msg) + 7,
blength(recved_nas_msg) - 7);
} break;
case IntegrityProtectedAndCiphered: {
Logger::amf_n1().debug(
......@@ -280,17 +280,17 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
uint32_t mac32 = 0;
if (!nas_message_integrity_protected(
nc.get()->security_ctx, NAS_MESSAGE_UPLINK,
(uint8_t*) bdata(recved_nas_msg) + 6, blength(recved_nas_msg) - 6,
(uint8_t *)bdata(recved_nas_msg) + 6, blength(recved_nas_msg) - 6,
mac32)) {
// IA0_5G
// TODO:
} else {
bool isMatched = false;
uint8_t* buf = (uint8_t*) bdata(recved_nas_msg);
int buf_len = blength(recved_nas_msg);
uint32_t mac32_recv = ntohl((((uint32_t*) (buf + 2))[0]));
Logger::amf_n1().debug(
"Received mac32 (0x%x) from the message", mac32_recv);
bool isMatched = false;
uint8_t *buf = (uint8_t *)bdata(recved_nas_msg);
int buf_len = blength(recved_nas_msg);
uint32_t mac32_recv = ntohl((((uint32_t *)(buf + 2))[0]));
Logger::amf_n1().debug("Received mac32 (0x%x) from the message",
mac32_recv);
if (mac32 == mac32_recv) {
isMatched = true;
Logger::amf_n1().error("Integrity matched");
......@@ -301,9 +301,9 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
return;
} else {
bstring ciphered = blk2bstr(buf + 7, buf_len - 7);
if (!nas_message_cipher_protected(
nc.get()->security_ctx, NAS_MESSAGE_UPLINK, ciphered,
decoded_plain_msg)) {
if (!nas_message_cipher_protected(nc.get()->security_ctx,
NAS_MESSAGE_UPLINK, ciphered,
decoded_plain_msg)) {
Logger::amf_n1().error("Decrypt NAS message failure");
return;
}
......@@ -315,20 +315,19 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
Logger::amf_n1().debug("Received NAS signalling establishment request...");
// dump_nas_message((uint8_t*)bdata(decoded_plain_msg),
// blength(decoded_plain_msg));
print_buffer(
"amf_n1", "Decoded plain NAS Message buffer",
(uint8_t*) bdata(decoded_plain_msg), blength(decoded_plain_msg));
print_buffer("amf_n1", "Decoded plain NAS Message buffer",
(uint8_t *)bdata(decoded_plain_msg),
blength(decoded_plain_msg));
nas_signalling_establishment_request_handle(
type, nc, nas_data_ind.ran_ue_ngap_id, nas_data_ind.amf_ue_ngap_id,
decoded_plain_msg, snn, ulCount);
} else {
Logger::amf_n1().debug("Received uplink NAS message...");
print_buffer(
"amf_n1", "Decoded NAS message buffer",
(uint8_t*) bdata(decoded_plain_msg), blength(decoded_plain_msg));
uplink_nas_msg_handle(
nas_data_ind.ran_ue_ngap_id, nas_data_ind.amf_ue_ngap_id,
decoded_plain_msg, plmn);
print_buffer("amf_n1", "Decoded NAS message buffer",
(uint8_t *)bdata(decoded_plain_msg),
blength(decoded_plain_msg));
uplink_nas_msg_handle(nas_data_ind.ran_ue_ngap_id,
nas_data_ind.amf_ue_ngap_id, decoded_plain_msg, plmn);
}
}
......@@ -352,32 +351,31 @@ void amf_n1::nas_signalling_establishment_request_handle(
set_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id, nc);
nc.get()->ctx_avaliability_ind = false;
// change UE connection status CM-IDLE -> CM-CONNECTED
nc.get()->nas_status = "CM-CONNECTED";
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->nas_status = "CM-CONNECTED";
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->serving_network = snn;
// stacs.UE_connected += 1;
} else {
// Logger::amf_n1().debug("existing nas_context with amf_ue_ngap_id(0x%x)
// --> Update",amf_ue_ngap_id); nc =
// amf_ue_id_2_nas_context(amf_ue_ngap_id);
// --> Update",amf_ue_ngap_id); nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
}
uint8_t* buf = (uint8_t*) bdata(plain_msg);
uint8_t *buf = (uint8_t *)bdata(plain_msg);
uint8_t message_type = *(buf + 2);
Logger::amf_n1().debug("NAS message type 0x%x", message_type);
switch (message_type) {
case REGISTRATION_REQUEST: {
Logger::amf_n1().debug(
"Received registration request message, handling...");
registration_request_handle(
true, nc, ran_ue_ngap_id, amf_ue_ngap_id, snn, plain_msg);
registration_request_handle(true, nc, ran_ue_ngap_id, amf_ue_ngap_id, snn,
plain_msg);
} break;
case SERVICE_REQUEST: {
Logger::amf_n1().debug("Received service request message, handling...");
if (nc.get()) nc.get()->security_ctx->ul_count.seq_num = ulCount;
service_request_handle(
true, nc, ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
nc.get()->security_ctx->ul_count.seq_num = ulCount;
service_request_handle(true, nc, ran_ue_ngap_id, amf_ue_ngap_id,
plain_msg);
} break;
case UE_INIT_DEREGISTER: {
Logger::amf_n1().debug(
......@@ -392,9 +390,9 @@ void amf_n1::nas_signalling_establishment_request_handle(
}
//------------------------------------------------------------------------------
void amf_n1::uplink_nas_msg_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg) {
uint8_t* buf = (uint8_t*) bdata(plain_msg);
void amf_n1::uplink_nas_msg_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
bstring plain_msg) {
uint8_t *buf = (uint8_t *)bdata(plain_msg);
uint8_t message_type = *(buf + 2);
switch (message_type) {
case AUTHENTICATION_RESPONSE: {
......@@ -424,8 +422,8 @@ void amf_n1::uplink_nas_msg_handle(
case UE_INIT_DEREGISTER: {
Logger::amf_n1().debug(
"Received de-registration request message, handling...");
ue_initiate_de_registration_handle(
ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
ue_initiate_de_registration_handle(ran_ue_ngap_id, amf_ue_ngap_id,
plain_msg);
} break;
case IDENTITY_RESPONSE: {
Logger::amf_n1().debug("received identity response messgae , handle ...");
......@@ -443,10 +441,9 @@ void amf_n1::uplink_nas_msg_handle(
}
//------------------------------------------------------------------------------
void amf_n1::uplink_nas_msg_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg,
plmn_t plmn) {
uint8_t* buf = (uint8_t*) bdata(plain_msg);
void amf_n1::uplink_nas_msg_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
bstring plain_msg, plmn_t plmn) {
uint8_t *buf = (uint8_t *)bdata(plain_msg);
uint8_t message_type = *(buf + 2);
switch (message_type) {
case AUTHENTICATION_RESPONSE: {
......@@ -476,8 +473,8 @@ void amf_n1::uplink_nas_msg_handle(
case UE_INIT_DEREGISTER: {
Logger::amf_n1().debug(
"Received de-registration request message, handling...");
ue_initiate_de_registration_handle(
ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
ue_initiate_de_registration_handle(ran_ue_ngap_id, amf_ue_ngap_id,
plain_msg);
} break;
case IDENTITY_RESPONSE: {
Logger::amf_n1().debug("received identity response messgae , handle ...");
......@@ -528,11 +525,11 @@ bool amf_n1::check_security_header_type(
// nas message handlers
//------------------------------------------------------------------------------
void amf_n1::identity_response_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg) {
IdentityResponse* ir = new IdentityResponse();
if (!ir->decodefrombuffer(
NULL, (uint8_t*) bdata(plain_msg), blength(plain_msg))) {
void amf_n1::identity_response_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring plain_msg) {
IdentityResponse *ir = new IdentityResponse();
if (!ir->decodefrombuffer(NULL, (uint8_t *)bdata(plain_msg),
blength(plain_msg))) {
Logger::amf_n1().error("decoding identity response error");
return;
}
......@@ -577,9 +574,9 @@ void amf_n1::service_request_handle(
nas[1] = PLAIN_5GS_MSG;
nas[2] = SERVICE_REJECT;
nas[3] = _5GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED;
itti_dl_nas_transport* dnt =
itti_dl_nas_transport *dnt =
new itti_dl_nas_transport(TASK_AMF_N1, TASK_AMF_N2);
dnt->nas = blk2bstr(nas, 4);
dnt->nas = blk2bstr(nas, 4);
dnt->amf_ue_ngap_id = amf_ue_ngap_id;
dnt->ran_ue_ngap_id = ran_ue_ngap_id;
std::shared_ptr<itti_dl_nas_transport> i =
......@@ -594,9 +591,9 @@ void amf_n1::service_request_handle(
}
set_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id, nc);
nas_secu_ctx* secu = nc.get()->security_ctx;
ServiceRequest* serReq = new ServiceRequest();
serReq->decodefrombuffer(nullptr, (uint8_t*) bdata(nas), blength(nas));
nas_secu_ctx *secu = nc.get()->security_ctx;
ServiceRequest *serReq = new ServiceRequest();
serReq->decodefrombuffer(nullptr, (uint8_t *)bdata(nas), blength(nas));
bdestroy(nas);
ServiceAccept* serApt = new ServiceAccept();
serApt->setHeader(PLAIN_5GS_MSG);
......@@ -645,10 +642,10 @@ void amf_n1::service_request_handle(
new itti_initial_context_setup_request(TASK_AMF_N1, TASK_AMF_N2);
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->nas = protectedNas;
itti_msg->kgnb = kgnb_bs;
itti_msg->is_sr = true; // service request indicator
itti_msg->is_pdu_exist = false;
itti_msg->nas = protectedNas;
itti_msg->kgnb = kgnb_bs;
itti_msg->is_sr = true; // service request indicator
itti_msg->is_pdu_exist = false;
std::shared_ptr<itti_initial_context_setup_request> i =
std::shared_ptr<itti_initial_context_setup_request>(itti_msg);
int ret = itti_inst->send_msg(i);
......@@ -680,9 +677,9 @@ void amf_n1::service_request_handle(
new itti_initial_context_setup_request(TASK_AMF_N1, TASK_AMF_N2);
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->nas = protectedNas;
itti_msg->kgnb = kgnb_bs;
itti_msg->is_sr = true; // service request indicator
itti_msg->nas = protectedNas;
itti_msg->kgnb = kgnb_bs;
itti_msg->is_sr = true; // service request indicator
itti_msg->pdu_session_id = psc.get()->pdu_session_id;
itti_msg->is_pdu_exist = true;
if (psc.get()->isn2sm_avaliable) {
......@@ -705,12 +702,14 @@ void amf_n1::service_request_handle(
}
//------------------------------------------------------------------------------
void amf_n1::registration_request_handle(
bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, std::string snn, bstring reg) {
void amf_n1::registration_request_handle(bool isNasSig,
std::shared_ptr<nas_context> nc,
uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, std::string snn,
bstring reg) {
// Decode registration request message
RegistrationRequest* regReq = new RegistrationRequest();
regReq->decodefrombuffer(nullptr, (uint8_t*) bdata(reg), blength(reg));
RegistrationRequest *regReq = new RegistrationRequest();
regReq->decodefrombuffer(nullptr, (uint8_t *)bdata(reg), blength(reg));
bdestroy(reg); // free buffer
// Check 5gs Mobility Identity (Mandatory IE)
std::string guti;
......@@ -726,9 +725,9 @@ void amf_n1::registration_request_handle(
set_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id, nc);
nc.get()->ctx_avaliability_ind = false;
// change UE connection status CM-IDLE -> CM-CONNECTED
nc.get()->nas_status = "CM-CONNECTED";
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->nas_status = "CM-CONNECTED";
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->serving_network = snn;
}
nc.get()->is_imsi_present = true;
......@@ -761,11 +760,11 @@ void amf_n1::registration_request_handle(
ueItem.connStatus = "5GMM-CONNECTED"; //"CM-CONNECTED";
ueItem.registerStatus =
"5GMM-REG-INITIATED"; // 5GMM-COMMON-PROCEDURE-INITIATED
ueItem.ranid = ran_ue_ngap_id;
ueItem.amfid = amf_ue_ngap_id;
ueItem.imsi = nc.get()->imsi;
ueItem.mcc = uc.get()->cgi.mcc;
ueItem.mnc = uc.get()->cgi.mnc;
ueItem.ranid = ran_ue_ngap_id;
ueItem.amfid = amf_ue_ngap_id;
ueItem.imsi = nc.get()->imsi;
ueItem.mcc = uc.get()->cgi.mcc;
ueItem.mnc = uc.get()->cgi.mnc;
ueItem.cellId = uc.get()->cgi.nrCellID;
stacs.update_ue_info(ueItem);
......@@ -828,13 +827,13 @@ void amf_n1::registration_request_handle(
set_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id, nc);
nc.get()->ctx_avaliability_ind = false;
// change UE connection status CM-IDLE -> CM-CONNECTED
nc.get()->nas_status = "CM-CONNECTED";
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->serving_network = snn;
nc.get()->is_5g_guti_present = true;
nc.get()->nas_status = "CM-CONNECTED";
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->serving_network = snn;
nc.get()->is_5g_guti_present = true;
nc.get()->to_be_register_by_new_suci = true;
nc.get()->ngKsi = 100;
nc.get()->ngKsi = 100;
// supi2amfId[("imsi-"+nc.get()->imsi)] = amf_ue_ngap_id;
// supi2ranId[("imsi-"+nc.get()->imsi)] = ran_ue_ngap_id;
}
......@@ -851,7 +850,7 @@ void amf_n1::registration_request_handle(
supi2ranId[("imsi-" + nc.get()->imsi)] = ran_ue_ngap_id;
// test 5g guti //
nc.get()->is_auth_vectors_present = false;
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;
} else {
......@@ -872,15 +871,11 @@ void amf_n1::registration_request_handle(
return;
}
} else {
Logger::amf_n1().debug("existing nas_context(%p) --> Update", nc.get());
Logger::amf_n1().debug("Existing nas_context --> Update");
// nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
}
// if(nc.get() == nullptr){
// response_registration_reject_msg(_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
// amf_ue_ngap_id); return;
//}
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->serving_network = snn;
// Check 5GS_Registration_type IE (Mandatory IE)
......@@ -919,7 +914,7 @@ void amf_n1::registration_request_handle(
// Get UE Security Capability IE (optional), not included for periodic
// registration updating procedure
uint8_t encrypt_alg = {0};
uint8_t encrypt_alg = {0};
uint8_t integrity_alg = {0};
if (!regReq->getUeSecurityCapability(encrypt_alg, integrity_alg)) {
Logger::amf_n1().warn("No Optional IE UESecurityCapability available");
......@@ -933,7 +928,7 @@ void amf_n1::registration_request_handle(
Logger::amf_n1().warn("No Optional IE RequestedNssai available");
}
delete regReq; // free after getting values from message
nc.get()->requestedNssai = requestedNssai;
nc.get()->requestedNssai = requestedNssai;
nc.get()->ctx_avaliability_ind = true;
// Get Last visited registered TAI(OPtional IE), if provided
......@@ -961,9 +956,8 @@ void amf_n1::registration_request_handle(
if (!amf_cfg.is_emergency_support.compare("false")) {
Logger::amf_n1().error(
"Network doesn't support emergency registration, reject ...");
response_registration_reject_msg(
_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
return;
}
} break;
......@@ -1017,13 +1011,14 @@ void amf_n1::set_guti_2_nas_context(
// to lower layer TASK_N2
//------------------------------------------------------------------------------
void amf_n1::itti_send_dl_nas_buffer_to_task_n2(
bstring& b, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id) {
itti_dl_nas_transport* msg =
void amf_n1::itti_send_dl_nas_buffer_to_task_n2(bstring &b,
uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id) {
itti_dl_nas_transport *msg =
new itti_dl_nas_transport(TASK_AMF_N1, TASK_AMF_N2);
msg->ran_ue_ngap_id = ran_ue_ngap_id;
msg->amf_ue_ngap_id = amf_ue_ngap_id;
msg->nas = b;
msg->nas = b;
std::shared_ptr<itti_dl_nas_transport> i =
std::shared_ptr<itti_dl_nas_transport>(msg);
int ret = itti_inst->send_msg(i);
......@@ -1044,8 +1039,8 @@ void amf_n1::response_registration_reject_msg(
uint8_t buffer[BUFFER_SIZE_1024] = {0};
int encoded_size = registrationRej->encode2buffer(buffer, BUFFER_SIZE_1024);
// dump_nas_message(buffer, encoded_size);
print_buffer(
"amf_n1", "Registration-Reject message buffer", buffer, encoded_size);
print_buffer("amf_n1", "Registration-Reject message buffer", buffer,
encoded_size);
if (!encoded_size) {
Logger::nas_mm().error("Encode Registration-Reject message error");
return;
......@@ -1081,9 +1076,9 @@ void amf_n1::run_registration_procedure(std::shared_ptr<nas_context>& nc) {
handle_auth_vector_successful_result(nc);
} else {
Logger::amf_n1().error("Request authentication vectors failure");
response_registration_reject_msg(
_5GMM_CAUSE_ILLEGAL_UE, nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_ILLEGAL_UE,
nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id); // cause?
}
} else {
Logger::amf_n1().debug(
......@@ -1103,16 +1098,16 @@ void amf_n1::run_registration_procedure(std::shared_ptr<nas_context>& nc) {
Logger::amf_n1().debug("Start to run identification procedure");
nc.get()->is_auth_vectors_present = false;
// ... identification procedure
IdentityRequest* ir = new IdentityRequest();
IdentityRequest *ir = new IdentityRequest();
// itti_msg->cause = 28;//cause nas(2)--deregister
ir->setHeader(PLAIN_5GS_MSG);
ir->set_5GS_Identity_Type(SUCI);
uint8_t buffer[100];
int encoded_size = ir->encode2buffer(buffer, 100);
delete ir;
itti_dl_nas_transport* dnt =
itti_dl_nas_transport *dnt =
new itti_dl_nas_transport(TASK_AMF_N1, TASK_AMF_N2);
dnt->nas = blk2bstr(buffer, encoded_size);
dnt->nas = blk2bstr(buffer, encoded_size);
dnt->amf_ue_ngap_id = nc.get()->amf_ue_ngap_id;
dnt->ran_ue_ngap_id = nc.get()->ran_ue_ngap_id;
std::shared_ptr<itti_dl_nas_transport> i =
......@@ -1390,9 +1385,9 @@ bool amf_n1::authentication_vectors_generator_in_ausf(
memcpy(&inputString[i][0], rand[i], 16);
memcpy(&inputString[i][16], xresStar[i], 16);
unsigned char sha256Out[Sha256::DIGEST_SIZE];
sha256((unsigned char*) inputString[i], 32, sha256Out);
sha256((unsigned char *)inputString[i], 32, sha256Out);
for (int j = 0; j < 16; j++)
nc.get()->_5g_av[i].hxresStar[j] = (uint8_t) sha256Out[j];
nc.get()->_5g_av[i].hxresStar[j] = (uint8_t)sha256Out[j];
memcpy(nc.get()->_5g_av[i].rand, nc.get()->_5g_he_av[i].rand, 16);
memcpy(nc.get()->_5g_av[i].autn, nc.get()->_5g_he_av[i].autn, 16);
uint8_t kseaf[32];
......@@ -1413,9 +1408,9 @@ bool amf_n1::authentication_vectors_generator_in_ausf(
bool amf_n1::authentication_vectors_generator_in_udm(
std::shared_ptr<nas_context>& nc) {
Logger::amf_n1().debug("Generate authentication vectors");
uint8_t* sqn = NULL;
uint8_t* auts = (uint8_t*) bdata(nc.get()->auts);
_5G_HE_AV_t* vector = nc.get()->_5g_he_av;
uint8_t *sqn = NULL;
uint8_t *auts = (uint8_t *)bdata(nc.get()->auts);
_5G_HE_AV_t *vector = nc.get()->_5g_he_av;
// Access to MySQL to fetch UE-related information
if (!connect_to_mysql()) {
Logger::amf_n1().error("Cannot connect to MySQL");
......@@ -1431,7 +1426,7 @@ bool amf_n1::authentication_vectors_generator_in_udm(
generate_random(vector[0].rand, RAND_LENGTH);
mysql_push_rand_sqn(nc.get()->imsi, vector[0].rand, sqn);
mysql_increment_sqn(nc.get()->imsi);
free_wrapper((void**) &sqn);
free_wrapper((void **)&sqn);
}
if (!get_mysql_auth_info(nc.get()->imsi, mysql_resp)) {
Logger::amf_n1().error("Cannot get data from MySQL");
......@@ -1440,19 +1435,18 @@ bool amf_n1::authentication_vectors_generator_in_udm(
sqn = mysql_resp.sqn;
for (int i = 0; i < MAX_5GS_AUTH_VECTORS; i++) {
generate_random(vector[i].rand, RAND_LENGTH);
print_buffer(
"amf_n1", "Generated random rand (5G HE AV)", vector[i].rand, 16);
generate_5g_he_av_in_udm(
mysql_resp.opc, nc.get()->imsi, mysql_resp.key, sqn,
nc.get()->serving_network, vector[i]); // serving network name
print_buffer("amf_n1", "Generated random rand (5G HE AV)",
vector[i].rand, 16);
generate_5g_he_av_in_udm(mysql_resp.opc, nc.get()->imsi, mysql_resp.key,
sqn, nc.get()->serving_network,
vector[i]); // serving network name
}
mysql_push_rand_sqn(
nc.get()->imsi, vector[MAX_5GS_AUTH_VECTORS - 1].rand, sqn);
} else {
Logger::amf_n1().debug("No auts ...");
Logger::amf_n1().debug(
"Receive information from MySQL with IMSI %s",
nc.get()->imsi.c_str());
Logger::amf_n1().debug("Receive information from MySQL with IMSI %s",
nc.get()->imsi.c_str());
// print_buffer("amf_n1", "Received from MYSQL: rand", mysql_resp.rand,
// 16); print_buffer("amf_n1", "Received from MYSQL: opc", mysql_resp.opc,
// 16); print_buffer("amf_n1", "Received from MYSQL: key", mysql_resp.key,
......@@ -1463,9 +1457,9 @@ bool amf_n1::authentication_vectors_generator_in_udm(
// print_buffer("amf_n1", "generated random: rand(5G HE AV)",
// vector[i].rand, 16);
sqn = mysql_resp.sqn;
generate_5g_he_av_in_udm(
mysql_resp.opc, nc.get()->imsi, mysql_resp.key, sqn,
nc.get()->serving_network, vector[i]); // serving network name
generate_5g_he_av_in_udm(mysql_resp.opc, nc.get()->imsi, mysql_resp.key,
sqn, nc.get()->serving_network,
vector[i]); // serving network name
}
mysql_push_rand_sqn(
nc.get()->imsi, vector[MAX_5GS_AUTH_VECTORS - 1].rand, sqn);
......@@ -1478,32 +1472,30 @@ bool amf_n1::authentication_vectors_generator_in_udm(
}
//------------------------------------------------------------------------------
void amf_n1::test_generate_5g_he_av_in_udm(
const uint8_t opc[16], uint8_t key[16], uint8_t sqnak[6],
std::string serving_network, _5G_HE_AV_t& vector) {
void amf_n1::test_generate_5g_he_av_in_udm(const uint8_t opc[16],
uint8_t key[16], uint8_t sqnak[6],
std::string serving_network,
_5G_HE_AV_t &vector) {
uint8_t amf[] = {0x90, 0x01};
uint8_t mac_a[8];
uint8_t ck[16];
uint8_t ik[16];
uint8_t ak[6];
Authentication_5gaka::f2345(
opc, key, vector.rand, vector.xres, ck, ik,
ak); // to compute XRES, CK, IK, AK
Authentication_5gaka::f2345(opc, key, vector.rand, vector.xres, ck, ik,
ak); // to compute XRES, CK, IK, AK
uint8_t sqn[6];
for (int i = 0; i < 6; i++) sqn[i] = sqnak[i] ^ ak[i];
Authentication_5gaka::f1(
opc, key, vector.rand, sqn, amf,
mac_a); // to compute MAC, Figure 7, ts33.102
Authentication_5gaka::f1(opc, key, vector.rand, sqn, amf,
mac_a); // to compute MAC, Figure 7, ts33.102
print_buffer("amf_n1", "sqn^ak", sqnak, 6);
print_buffer("amf_n1", "rand", vector.rand, 16);
print_buffer("amf_n1", "mac_a", mac_a, 8);
annex_a_4_33501(
ck, ik, vector.xres, vector.rand, serving_network, vector.xresStar);
Authentication_5gaka::generate_autn(
sqn, ak, amf, mac_a, vector.autn); // generate AUTN
Authentication_5gaka::derive_kausf(
ck, ik, serving_network, sqn, ak,
vector.kausf); // derive Kausf
annex_a_4_33501(ck, ik, vector.xres, vector.rand, serving_network,
vector.xresStar);
Authentication_5gaka::generate_autn(sqn, ak, amf, mac_a,
vector.autn); // generate AUTN
Authentication_5gaka::derive_kausf(ck, ik, serving_network, sqn, ak,
vector.kausf); // derive Kausf
}
//------------------------------------------------------------------------------
......@@ -1522,8 +1514,8 @@ void amf_n1::generate_random(uint8_t* random_p, ssize_t length) {
int r = 0, mask = 0, shift;
for (int i = 0; i < length; i++) {
if ((i % sizeof(i)) == 0) r = rand();
shift = 8 * (i % sizeof(i));
mask = 0xFF << shift;
shift = 8 * (i % sizeof(i));
mask = 0xFF << shift;
random_p[i] = (r & mask) >> shift;
}
} else {
......@@ -1539,9 +1531,10 @@ void amf_n1::generate_random(uint8_t* random_p, ssize_t length) {
//------------------------------------------------------------------------------
// TODO: read from UDM
void amf_n1::generate_5g_he_av_in_udm(
const uint8_t opc[16], string imsi, uint8_t key[16], uint8_t sqn[6],
std::string serving_network, _5G_HE_AV_t& vector) {
void amf_n1::generate_5g_he_av_in_udm(const uint8_t opc[16], string imsi,
uint8_t key[16], uint8_t sqn[6],
std::string serving_network,
_5G_HE_AV_t &vector) {
Logger::amf_n1().debug("Generate 5g_he_av as in UDM");
uint8_t amf[] = {0x90, 0x01};
uint8_t mac_a[8];
......@@ -1550,23 +1543,20 @@ void amf_n1::generate_5g_he_av_in_udm(
uint8_t ak[6];
uint64_t _imsi = fromString<uint64_t>(imsi);
Authentication_5gaka::f1(
opc, key, vector.rand, sqn, amf,
mac_a); // to compute MAC, Figure 7, ts33.102
Authentication_5gaka::f1(opc, key, vector.rand, sqn, amf,
mac_a); // to compute MAC, Figure 7, ts33.102
// print_buffer("amf_n1", "Result For F1-Alg: mac_a", mac_a, 8);
Authentication_5gaka::f2345(
opc, key, vector.rand, vector.xres, ck, ik,
ak); // to compute XRES, CK, IK, AK
annex_a_4_33501(
ck, ik, vector.xres, vector.rand, serving_network, vector.xresStar);
Authentication_5gaka::f2345(opc, key, vector.rand, vector.xres, ck, ik,
ak); // to compute XRES, CK, IK, AK
annex_a_4_33501(ck, ik, vector.xres, vector.rand, serving_network,
vector.xresStar);
// print_buffer("amf_n1", "Result For KDF: xres*(5G HE AV)", vector.xresStar,
// 16);
Authentication_5gaka::generate_autn(
sqn, ak, amf, mac_a, vector.autn); // generate AUTN
Authentication_5gaka::generate_autn(sqn, ak, amf, mac_a,
vector.autn); // generate AUTN
// print_buffer("amf_n1", "Generated autn(5G HE AV)", vector.autn, 16);
Authentication_5gaka::derive_kausf(
ck, ik, serving_network, sqn, ak,
vector.kausf); // derive Kausf
Authentication_5gaka::derive_kausf(ck, ik, serving_network, sqn, ak,
vector.kausf); // derive Kausf
// print_buffer("amf_n1", "Result For KDF: Kausf(5G HE AV)", vector.kausf,
// 32);
Logger::amf_n1().debug("Generate_5g_he_av_in_udm finished!");
......@@ -1635,9 +1625,9 @@ void amf_n1::handle_auth_vector_successful_result(
if (!start_authentication_procedure(nc, vindex, nc.get()->ngKsi)) {
Logger::amf_n1().error("Start authentication procedure failure, reject...");
Logger::amf_n1().error("Ran_ue_ngap_id 0x%x", nc.get()->ran_ue_ngap_id);
response_registration_reject_msg(
_5GMM_CAUSE_INVALID_MANDATORY_INFO, nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_INVALID_MANDATORY_INFO,
nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id); // cause?
} else {
// update mm state -> COMMON-PROCEDURE-INITIATED
}
......@@ -1649,9 +1639,9 @@ bool amf_n1::start_authentication_procedure(
Logger::amf_n1().debug("****Starting authentication procedure****");
if (check_nas_common_procedure_on_going(nc)) {
Logger::amf_n1().error("Existed NAS common procedure on going, reject...");
response_registration_reject_msg(
_5GMM_CAUSE_INVALID_MANDATORY_INFO, nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_INVALID_MANDATORY_INFO,
nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id); // cause?
return false;
}
......@@ -1663,17 +1653,17 @@ bool amf_n1::start_authentication_procedure(
abba[0] = 0x00;
abba[1] = 0x00;
authReq->setABBA(2, abba);
uint8_t* rand = nc.get()->_5g_av[vindex].rand;
uint8_t *rand = nc.get()->_5g_av[vindex].rand;
if (rand) authReq->setAuthentication_Parameter_RAND(rand);
Logger::amf_n1().debug("Sending Authentication request with rand");
printf("0x");
for (int i = 0; i < 16; i++) printf("%x", rand[i]);
printf("\n");
uint8_t* autn = nc.get()->_5g_av[vindex].autn;
uint8_t *autn = nc.get()->_5g_av[vindex].autn;
if (autn) authReq->setAuthentication_Parameter_AUTN(autn);
uint8_t buffer[1024] = {0};
int encoded_size = authReq->encode2buffer(buffer, 1024);
int encoded_size = authReq->encode2buffer(buffer, 1024);
if (!encoded_size) {
Logger::nas_mm().error("Encode Authentication Request message error");
return false;
......@@ -1681,9 +1671,8 @@ bool amf_n1::start_authentication_procedure(
delete authReq;
}
bstring b = blk2bstr(buffer, encoded_size);
print_buffer(
"amf_n1", "Authentication-Request message buffer", (uint8_t*) bdata(b),
blength(b));
print_buffer("amf_n1", "Authentication-Request message buffer",
(uint8_t *)bdata(b), blength(b));
Logger::amf_n1().debug("amf_ue_ngap_id 0x%x", nc.get()->amf_ue_ngap_id);
itti_send_dl_nas_buffer_to_task_n2(
b, nc.get()->ran_ue_ngap_id, nc.get()->amf_ue_ngap_id);
......@@ -1713,30 +1702,29 @@ bool amf_n1::check_nas_common_procedure_on_going(
}
//------------------------------------------------------------------------------
void amf_n1::authentication_response_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg) {
void amf_n1::authentication_response_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id,
bstring plain_msg) {
std::shared_ptr<nas_context> nc;
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id)) {
Logger::amf_n1().error(
"No existed NAS context for UE with amf_ue_ngap_id (0x%x)",
amf_ue_ngap_id);
response_registration_reject_msg(
_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
return;
}
nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
Logger::amf_n1().info(
"Found nas_context(%p) with amf_ue_ngap_id (0x%x)", nc.get(),
amf_ue_ngap_id);
Logger::amf_n1().info("Found nas_context(%p) with amf_ue_ngap_id (0x%x)",
nc.get(), amf_ue_ngap_id);
// Stop timer? common procedure finished!
nc.get()->is_common_procedure_for_authentication_running = false;
// MM state: COMMON-PROCEDURE-INITIATED -> DEREGISTRED
// Decode AUTHENTICATION RESPONSE message
AuthenticationResponse* auth = new AuthenticationResponse();
auth->decodefrombuffer(
nullptr, (uint8_t*) bdata(plain_msg), blength(plain_msg));
AuthenticationResponse *auth = new AuthenticationResponse();
auth->decodefrombuffer(nullptr, (uint8_t *)bdata(plain_msg),
blength(plain_msg));
bstring resStar;
bool isAuthOk = true;
// Get response RES*
......@@ -1745,27 +1733,25 @@ void amf_n1::authentication_response_handle(
"Cannot receive AuthenticationResponseParameter (RES*)");
} else {
// Get stored XRES*
int secu_index = nc.get()->security_ctx->vector_pointer;
uint8_t* hxresStar = nc.get()->_5g_av[secu_index].hxresStar;
int secu_index = nc.get()->security_ctx->vector_pointer;
uint8_t *hxresStar = nc.get()->_5g_av[secu_index].hxresStar;
// Calculate HRES* from received RES*, then compare with XRES stored in
// nas_context
uint8_t inputstring[32];
uint8_t* res = (uint8_t*) bdata(resStar);
uint8_t *res = (uint8_t *)bdata(resStar);
Logger::amf_n1().debug("Start to calculate HRES* from received RES*");
memcpy(&inputstring[0], nc.get()->_5g_av[secu_index].rand, 16);
memcpy(&inputstring[16], res, blength(resStar));
unsigned char sha256Out[Sha256::DIGEST_SIZE];
sha256((unsigned char*) inputstring, 16 + blength(resStar), sha256Out);
sha256((unsigned char *)inputstring, 16 + blength(resStar), sha256Out);
uint8_t hres[16];
for (int i = 0; i < 16; i++) hres[i] = (uint8_t) sha256Out[i];
print_buffer(
"amf_n1", "Received RES* From Authentication-Response", res, 16);
print_buffer(
"amf_n1", "Stored XRES* in 5G HE AV",
nc.get()->_5g_he_av[secu_index].xresStar, 16);
print_buffer(
"amf_n1", "Stored XRES in 5G HE AV",
nc.get()->_5g_he_av[secu_index].xres, 8);
for (int i = 0; i < 16; i++) hres[i] = (uint8_t)sha256Out[i];
print_buffer("amf_n1", "Received RES* From Authentication-Response", res,
16);
print_buffer("amf_n1", "Stored XRES* in 5G HE AV",
nc.get()->_5g_he_av[secu_index].xresStar, 16);
print_buffer("amf_n1", "Stored XRES in 5G HE AV",
nc.get()->_5g_he_av[secu_index].xres, 8);
print_buffer("amf_n1", "Computed HRES* from RES*", hres, 16);
print_buffer("amf_n1", "Computed HXRES* from XRES*", hxresStar, 16);
for (int i = 0; i < 16; i++) {
......@@ -1778,9 +1764,8 @@ void amf_n1::authentication_response_handle(
Logger::amf_n1().error(
"Authentication failed for UE with amf_ue_ngap_id 0x%x",
amf_ue_ngap_id);
response_registration_reject_msg(
_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
return;
} else {
Logger::amf_n1().debug("Authentication successful by network!");
......@@ -1795,30 +1780,29 @@ void amf_n1::authentication_response_handle(
}
//------------------------------------------------------------------------------
void amf_n1::authentication_failure_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg) {
void amf_n1::authentication_failure_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id,
bstring plain_msg) {
std::shared_ptr<nas_context> nc;
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id)) {
Logger::amf_n1().error(
"No existed NAS context for UE with amf_ue_ngap_id(0x%x)",
amf_ue_ngap_id);
response_registration_reject_msg(
_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
return;
}
nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
nc.get()->is_common_procedure_for_authentication_running = false;
// 1. decode AUTHENTICATION FAILURE message
AuthenticationFailure* authFail = new AuthenticationFailure();
authFail->decodefrombuffer(
NULL, (uint8_t*) bdata(plain_msg), blength(plain_msg));
AuthenticationFailure *authFail = new AuthenticationFailure();
authFail->decodefrombuffer(NULL, (uint8_t *)bdata(plain_msg),
blength(plain_msg));
uint8_t mm_cause = authFail->get5GMmCause();
if (mm_cause == -1) {
Logger::amf_n1().error("Missing mandatory IE 5G_MM_CAUSE");
response_registration_reject_msg(
_5GMM_CAUSE_INVALID_MANDATORY_INFO, ran_ue_ngap_id,
amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_INVALID_MANDATORY_INFO,
ran_ue_ngap_id, amf_ue_ngap_id); // cause?
return;
}
switch (mm_cause) {
......@@ -1832,15 +1816,15 @@ void amf_n1::authentication_failure_handle(
nc.get()->auts = auts;
printf("Received auts: 0x ");
for (int i = 0; i < blength(auts); i++)
printf("%x ", ((uint8_t*) bdata(auts))[i]);
printf("%x ", ((uint8_t *)bdata(auts))[i]);
printf("\n");
if (auth_vectors_generator(nc)) { // all authentication in one(AMF)
handle_auth_vector_successful_result(nc);
} else {
Logger::amf_n1().error("Request authentication vectors failure");
response_registration_reject_msg(
_5GMM_CAUSE_ILLEGAL_UE, nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id); // cause?
response_registration_reject_msg(_5GMM_CAUSE_ILLEGAL_UE,
nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id); // cause?
}
// authentication_failure_synch_failure_handle(nc, auts);
} break;
......@@ -1852,12 +1836,12 @@ bool amf_n1::start_security_mode_control_procedure(
std::shared_ptr<nas_context> nc) {
Logger::amf_n1().debug("Start Security Mode Control procedure");
nc.get()->is_common_procedure_for_security_mode_control_running = true;
bool security_context_is_new = false;
uint8_t amf_nea = EA0_5G;
uint8_t amf_nia = IA0_5G;
bool security_context_is_new = false;
uint8_t amf_nea = EA0_5G;
uint8_t amf_nia = IA0_5G;
// decide which ea/ia alg used by UE, which is supported by network
security_data_t* data = (security_data_t*) calloc(1, sizeof(security_data_t));
nas_secu_ctx* secu_ctx = nc.get()->security_ctx;
security_data_t *data = (security_data_t *)calloc(1, sizeof(security_data_t));
nas_secu_ctx *secu_ctx = nc.get()->security_ctx;
if (!data)
Logger::amf_n1().error("Cannot allocate memory for security_data_t");
......@@ -1870,12 +1854,12 @@ bool amf_n1::start_security_mode_control_procedure(
secu_ctx->nas_algs
.encryption; // emm_ctx->_security.selected_algorithms.encryption;
data->saved_selected_nia = secu_ctx->nas_algs.integrity;
data->saved_ngksi = secu_ctx->ngksi;
data->saved_ngksi = secu_ctx->ngksi;
data->saved_overflow =
secu_ctx->dl_count.overflow; // emm_ctx->_security.dl_count.overflow;
data->saved_seq_num = secu_ctx->dl_count.seq_num;
data->saved_sc_type = secu_ctx->sc_type;
secu_ctx->ngksi = nc.get()->ngKsi;
data->saved_seq_num = secu_ctx->dl_count.seq_num;
data->saved_sc_type = secu_ctx->sc_type;
secu_ctx->ngksi = nc.get()->ngKsi;
secu_ctx->dl_count.overflow = 0;
secu_ctx->dl_count.seq_num = 0;
secu_ctx->ul_count.overflow = 0;
......@@ -1885,14 +1869,14 @@ bool amf_n1::start_security_mode_control_procedure(
amf_nia);
secu_ctx->nas_algs.integrity = amf_nia;
secu_ctx->nas_algs.encryption = amf_nea;
secu_ctx->sc_type = SECURITY_CTX_TYPE_FULL_NATIVE;
Authentication_5gaka::derive_knas(
NAS_INT_ALG, secu_ctx->nas_algs.integrity,
nc.get()->kamf[secu_ctx->vector_pointer], secu_ctx->knas_int);
secu_ctx->sc_type = SECURITY_CTX_TYPE_FULL_NATIVE;
Authentication_5gaka::derive_knas(NAS_INT_ALG, secu_ctx->nas_algs.integrity,
nc.get()->kamf[secu_ctx->vector_pointer],
secu_ctx->knas_int);
Authentication_5gaka::derive_knas(
NAS_ENC_ALG, secu_ctx->nas_algs.encryption,
nc.get()->kamf[secu_ctx->vector_pointer], secu_ctx->knas_enc);
security_context_is_new = true;
security_context_is_new = true;
nc.get()->is_current_security_available = true;
}
......@@ -1913,11 +1897,10 @@ bool amf_n1::start_security_mode_control_procedure(
encode_nas_message_protected(
secu_ctx, security_context_is_new, INTEGRITY_PROTECTED_WITH_NEW_SECU_CTX,
NAS_MESSAGE_DOWNLINK, buffer, encoded_size, intProtctedNas);
print_buffer(
"amf_n1", "Encrypted Security-Mode-Command message buffer",
(uint8_t*) bdata(intProtctedNas), blength(intProtctedNas));
itti_send_dl_nas_buffer_to_task_n2(
intProtctedNas, nc.get()->ran_ue_ngap_id, nc.get()->amf_ue_ngap_id);
print_buffer("amf_n1", "Encrypted Security-Mode-Command message buffer",
(uint8_t *)bdata(intProtctedNas), blength(intProtctedNas));
itti_send_dl_nas_buffer_to_task_n2(intProtctedNas, nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id);
// secu_ctx->dl_count.seq_num ++;
return true;
}
......@@ -1978,8 +1961,8 @@ void amf_n1::security_mode_complete_handle(
amf_cfg.guami.AmfPointer, tmsi);
std::vector<p_tai_t> tai_list = {};
p_tai_t item0 = {};
item0.type = 0x00;
p_tai_t item0 = {};
item0.type = 0x00;
nas_plmn_t plmn;
plmn.mcc = amf_cfg.plmn_list[0].mcc;
plmn.mnc = amf_cfg.plmn_list[0].mnc;
......@@ -1989,11 +1972,11 @@ void amf_n1::security_mode_complete_handle(
regAccept->setTaiList(tai_list);
std::vector<struct SNSSAI_s> nssai = {};
SNSSAI_t snssai = {};
snssai.sst = 1;
snssai.sd = -1;
snssai.mHplmnSst = -1;
snssai.mHplmnSd = -1;
SNSSAI_t snssai = {};
snssai.sst = 1;
snssai.sd = -1;
snssai.mHplmnSst = -1;
snssai.mHplmnSd = -1;
nssai.push_back(snssai);
regAccept->setALLOWED_NSSAI(nssai);
......@@ -2054,7 +2037,7 @@ void amf_n1::security_mode_complete_handle(
set_guti_2_nas_context(guti, nc);
nc.get()->is_common_procedure_for_security_mode_control_running = false;
nas_secu_ctx* secu = nc.get()->security_ctx;
nas_secu_ctx *secu = nc.get()->security_ctx;
// protect nas message
bstring protectedNas;
encode_nas_message_protected(
......@@ -2072,9 +2055,9 @@ void amf_n1::security_mode_complete_handle(
new itti_initial_context_setup_request(TASK_AMF_N1, TASK_AMF_N2);
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->kgnb = kgnb_bs;
itti_msg->nas = protectedNas;
itti_msg->is_sr = false; // TODO: for Setup Request procedure
itti_msg->kgnb = kgnb_bs;
itti_msg->nas = protectedNas;
itti_msg->is_sr = false; // TODO: for Setup Request procedure
std::shared_ptr<itti_initial_context_setup_request> i =
std::shared_ptr<itti_initial_context_setup_request>(itti_msg);
int ret = itti_inst->send_msg(i);
......@@ -2095,9 +2078,9 @@ void amf_n1::security_mode_reject_handle(
//------------------------------------------------------------------------------
void amf_n1::encode_nas_message_protected(
nas_secu_ctx* nsc, bool is_secu_ctx_new, uint8_t security_header_type,
uint8_t direction, uint8_t* input_nas_buf, int input_nas_len,
bstring& protected_nas) {
nas_secu_ctx *nsc, bool is_secu_ctx_new, uint8_t security_header_type,
uint8_t direction, uint8_t *input_nas_buf, int input_nas_len,
bstring &protected_nas) {
Logger::amf_n1().debug("Encoding nas_message_protected...");
uint8_t protected_nas_buf[1024];
int encoded_size = 0;
......@@ -2110,9 +2093,9 @@ void amf_n1::encode_nas_message_protected(
nas_message_cipher_protected(nsc, NAS_MESSAGE_DOWNLINK, input, ciphered);
protected_nas_buf[0] = EPD_5GS_MM_MSG;
protected_nas_buf[1] = INTEGRITY_PROTECTED_AND_CIPHERED;
protected_nas_buf[6] = (uint8_t) nsc->dl_count.seq_num;
memcpy(
&protected_nas_buf[7], (uint8_t*) bdata(ciphered), blength(ciphered));
protected_nas_buf[6] = (uint8_t)nsc->dl_count.seq_num;
memcpy(&protected_nas_buf[7], (uint8_t *)bdata(ciphered),
blength(ciphered));
uint32_t mac32;
if (!(nas_message_integrity_protected(
nsc, NAS_MESSAGE_DOWNLINK, protected_nas_buf + 6,
......@@ -2120,8 +2103,8 @@ void amf_n1::encode_nas_message_protected(
memcpy(protected_nas_buf, input_nas_buf, input_nas_len);
encoded_size = input_nas_len;
} else {
*(uint32_t*) (protected_nas_buf + 2) = htonl(mac32);
encoded_size = 7 + input_nas_len;
*(uint32_t *)(protected_nas_buf + 2) = htonl(mac32);
encoded_size = 7 + input_nas_len;
}
} break;
case INTEGRITY_PROTECTED_WITH_NEW_SECU_CTX: {
......@@ -2130,7 +2113,7 @@ void amf_n1::encode_nas_message_protected(
}
protected_nas_buf[0] = EPD_5GS_MM_MSG;
protected_nas_buf[1] = INTEGRITY_PROTECTED_WITH_NEW_SECU_CTX;
protected_nas_buf[6] = (uint8_t) nsc->dl_count.seq_num;
protected_nas_buf[6] = (uint8_t)nsc->dl_count.seq_num;
memcpy(&protected_nas_buf[7], input_nas_buf, input_nas_len);
uint32_t mac32;
if (!(nas_message_integrity_protected(
......@@ -2140,8 +2123,8 @@ void amf_n1::encode_nas_message_protected(
encoded_size = input_nas_len;
} else {
Logger::amf_n1().debug("mac32: 0x%x", mac32);
*(uint32_t*) (protected_nas_buf + 2) = htonl(mac32);
encoded_size = 7 + input_nas_len;
*(uint32_t *)(protected_nas_buf + 2) = htonl(mac32);
encoded_size = 7 + input_nas_len;
}
} break;
case INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX: {
......@@ -2169,7 +2152,7 @@ bool amf_n1::nas_message_integrity_protected(
"amf_n1", "Parameters for NIA: knas_int", nsc->knas_int,
AUTH_KNAS_INT_SIZE);
stream_cipher.key_length = AUTH_KNAS_INT_SIZE;
stream_cipher.count = *(input_nas);
stream_cipher.count = *(input_nas);
// stream_cipher.count = count;
if (!direction) {
nsc->ul_count.seq_num = stream_cipher.count;
......@@ -2177,13 +2160,13 @@ bool amf_n1::nas_message_integrity_protected(
}
Logger::amf_n1().debug("Parameters for NIA, count: 0x%x", count);
stream_cipher.bearer = 0x01; // 33.501 section 8.1.1
Logger::amf_n1().debug(
"Parameters for NIA, bearer: 0x%x", stream_cipher.bearer);
Logger::amf_n1().debug("Parameters for NIA, bearer: 0x%x",
stream_cipher.bearer);
stream_cipher.direction = direction; // "1" for downlink
Logger::amf_n1().debug("Parameters for NIA, direction: 0x%x", direction);
stream_cipher.message = (uint8_t*) input_nas;
print_buffer(
"amf_n1", "Parameters for NIA, message: ", input_nas, input_nas_len);
stream_cipher.message = (uint8_t *)input_nas;
print_buffer("amf_n1", "Parameters for NIA, message: ", input_nas,
input_nas_len);
stream_cipher.blength = input_nas_len * 8;
switch (nsc->nas_algs.integrity & 0x0f) {
case IA0_5G: {
......@@ -2194,7 +2177,7 @@ bool amf_n1::nas_message_integrity_protected(
Logger::amf_n1().debug("Integrity with algorithms: 128-5G-IA1");
nas_algorithms::nas_stream_encrypt_nia1(&stream_cipher, mac);
print_buffer("amf_n1", "Result for NIA1, mac: ", mac, 4);
mac32 = ntohl(*((uint32_t*) mac));
mac32 = ntohl(*((uint32_t *)mac));
Logger::amf_n1().debug("Result for NIA1, mac32: 0x%x", mac32);
return true;
} break;
......@@ -2202,7 +2185,7 @@ bool amf_n1::nas_message_integrity_protected(
Logger::amf_n1().debug("Integrity with algorithms: 128-5G-IA2");
nas_algorithms::nas_stream_encrypt_nia2(&stream_cipher, mac);
print_buffer("amf_n1", "Result for NIA2, mac: ", mac, 4);
mac32 = ntohl(*((uint32_t*) mac));
mac32 = ntohl(*((uint32_t *)mac));
Logger::amf_n1().debug("Result for NIA2, mac32: 0x%x", mac32);
return true;
} break;
......@@ -2210,11 +2193,11 @@ bool amf_n1::nas_message_integrity_protected(
}
//------------------------------------------------------------------------------
bool amf_n1::nas_message_cipher_protected(
nas_secu_ctx* nsc, uint8_t direction, bstring input_nas,
bstring& output_nas) {
uint8_t* buf = (uint8_t*) bdata(input_nas);
int buf_len = blength(input_nas);
bool amf_n1::nas_message_cipher_protected(nas_secu_ctx *nsc, uint8_t direction,
bstring input_nas,
bstring &output_nas) {
uint8_t *buf = (uint8_t *)bdata(input_nas);
int buf_len = blength(input_nas);
uint32_t count = 0x00000000;
if (direction)
count = 0x00000000 | ((nsc->dl_count.overflow & 0x0000ffff) << 8) |
......@@ -2226,11 +2209,11 @@ bool amf_n1::nas_message_cipher_protected(
uint8_t mac[4];
stream_cipher.key = nsc->knas_enc;
stream_cipher.key_length = AUTH_KNAS_ENC_SIZE;
stream_cipher.count = count;
stream_cipher.bearer = 0x00; // 33.501 section 8.1.1
stream_cipher.direction = direction; // "1" for downlink
stream_cipher.message = (uint8_t*) bdata(input_nas);
stream_cipher.blength = blength(input_nas) << 3;
stream_cipher.count = count;
stream_cipher.bearer = 0x00; // 33.501 section 8.1.1
stream_cipher.direction = direction; // "1" for downlink
stream_cipher.message = (uint8_t *)bdata(input_nas);
stream_cipher.blength = blength(input_nas) << 3;
switch (nsc->nas_algs.encryption & 0x0f) {
case EA0_5G: {
Logger::amf_n1().debug("Cipher protected with EA0_5G");
......@@ -2239,13 +2222,13 @@ bool amf_n1::nas_message_cipher_protected(
} 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));
nas_algorithms::nas_stream_encrypt_nea1(&stream_cipher,
(uint8_t *)bdata(output_nas));
} break;
case EA2_128_5G: {
Logger::amf_n1().debug("Cipher protected with EA2_128_5G");
nas_algorithms::nas_stream_encrypt_nea2(
&stream_cipher, (uint8_t*) bdata(output_nas));
nas_algorithms::nas_stream_encrypt_nea2(&stream_cipher,
(uint8_t *)bdata(output_nas));
} break;
}
}
......@@ -2299,8 +2282,8 @@ void amf_n1::ue_initiate_de_registration_handle(
}
// decode NAS msg
DeregistrationRequest* deregReq = new DeregistrationRequest();
deregReq->decodefrombuffer(NULL, (uint8_t*) bdata(nas), blength(nas));
DeregistrationRequest *deregReq = new DeregistrationRequest();
deregReq->decodefrombuffer(NULL, (uint8_t *)bdata(nas), blength(nas));
/*
_5gs_deregistration_type_t type = {};
deregReq->getDeregistrationType(type);
......@@ -2315,15 +2298,15 @@ void amf_n1::ue_initiate_de_registration_handle(
Logger::amf_n1().debug("5G Mobile Identity %X", mobile_id_type);
switch (mobile_id_type) {
case _5G_GUTI: {
Logger::amf_n1().debug(
"5G Mobile Identity, GUTI %s", deregReq->get_5g_guti().c_str());
Logger::amf_n1().debug("5G Mobile Identity, GUTI %s",
deregReq->get_5g_guti().c_str());
} break;
default: {
}
}
// Prepare DeregistrationAccept
DeregistrationAccept* deregAccept = new DeregistrationAccept();
DeregistrationAccept *deregAccept = new DeregistrationAccept();
deregAccept->setHeader(PLAIN_5GS_MSG);
uint8_t buffer[BUFFER_SIZE_512] = {0};
......@@ -2346,16 +2329,16 @@ void amf_n1::ue_initiate_de_registration_handle(
}
//------------------------------------------------------------------------------
void amf_n1::ul_nas_transport_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas) {
void amf_n1::ul_nas_transport_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring nas) {
// Decode UL_NAS_TRANSPORT message
Logger::amf_n1().debug("Handling UL NAS Transport");
ULNASTransport* ulNas = new ULNASTransport();
ulNas->decodefrombuffer(NULL, (uint8_t*) bdata(nas), blength(nas));
uint8_t payload_type = ulNas->getPayloadContainerType();
ULNASTransport *ulNas = new ULNASTransport();
ulNas->decodefrombuffer(NULL, (uint8_t *)bdata(nas), blength(nas));
uint8_t payload_type = ulNas->getPayloadContainerType();
uint8_t pdu_session_id = ulNas->getPduSessionId();
uint8_t request_type = ulNas->getRequestType();
SNSSAI_t snssai = {};
uint8_t request_type = ulNas->getRequestType();
SNSSAI_t snssai = {};
ulNas->getSnssai(snssai);
bstring dnn = bfromcstr("default");
bstring sm_msg;
......@@ -2363,8 +2346,8 @@ void amf_n1::ul_nas_transport_handle(
} else {
dnn = bfromcstr("default");
}
print_buffer(
"amf_n1", "Decoded DNN bitstring", (uint8_t*) bdata(dnn), blength(dnn));
print_buffer("amf_n1", "Decoded DNN bitstring", (uint8_t *)bdata(dnn),
blength(dnn));
switch (payload_type) {
case N1_SM_INFORMATION: {
if (!ulNas->getPayloadContainer(sm_msg)) {
......@@ -2373,16 +2356,16 @@ void amf_n1::ul_nas_transport_handle(
}
// send_itti_to_smf_services_consumer(ran_ue_ngap_id, amf_ue_ngap_id,
// request_type, pdu_session_id, dnn, sm_msg);
itti_smf_services_consumer* itti_msg =
itti_smf_services_consumer *itti_msg =
new itti_smf_services_consumer(TASK_AMF_N1, TASK_AMF_N11);
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->req_type = request_type;
itti_msg->pdu_sess_id = pdu_session_id;
itti_msg->dnn = dnn;
itti_msg->sm_msg = sm_msg;
itti_msg->snssai.sST = snssai.sst;
itti_msg->snssai.sD = std::to_string(snssai.sd);
itti_msg->req_type = request_type;
itti_msg->pdu_sess_id = pdu_session_id;
itti_msg->dnn = dnn;
itti_msg->sm_msg = sm_msg;
itti_msg->snssai.sST = snssai.sst;
itti_msg->snssai.sD = std::to_string(snssai.sd);
std::shared_ptr<itti_smf_services_consumer> i =
std::shared_ptr<itti_smf_services_consumer>(itti_msg);
int ret = itti_inst->send_msg(i);
......@@ -2397,16 +2380,17 @@ void amf_n1::ul_nas_transport_handle(
}
//------------------------------------------------------------------------------
void amf_n1::ul_nas_transport_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas, plmn_t plmn) {
void amf_n1::ul_nas_transport_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring nas,
plmn_t plmn) {
// Decode UL_NAS_TRANSPORT message
Logger::amf_n1().debug("Handling UL NAS Transport");
ULNASTransport* ulNas = new ULNASTransport();
ulNas->decodefrombuffer(NULL, (uint8_t*) bdata(nas), blength(nas));
uint8_t payload_type = ulNas->getPayloadContainerType();
ULNASTransport *ulNas = new ULNASTransport();
ulNas->decodefrombuffer(NULL, (uint8_t *)bdata(nas), blength(nas));
uint8_t payload_type = ulNas->getPayloadContainerType();
uint8_t pdu_session_id = ulNas->getPduSessionId();
uint8_t request_type = ulNas->getRequestType();
SNSSAI_t snssai = {};
uint8_t request_type = ulNas->getRequestType();
SNSSAI_t snssai = {};
ulNas->getSnssai(snssai);
bstring dnn = bfromcstr("default");
bstring sm_msg;
......@@ -2414,8 +2398,8 @@ void amf_n1::ul_nas_transport_handle(
} else {
dnn = bfromcstr("default");
}
print_buffer(
"amf_n1", "Decoded DNN bitstring", (uint8_t*) bdata(dnn), blength(dnn));
print_buffer("amf_n1", "Decoded DNN bitstring", (uint8_t *)bdata(dnn),
blength(dnn));
switch (payload_type) {
case N1_SM_INFORMATION: {
if (!ulNas->getPayloadContainer(sm_msg)) {
......@@ -2424,18 +2408,18 @@ void amf_n1::ul_nas_transport_handle(
}
// send_itti_to_smf_services_consumer(ran_ue_ngap_id, amf_ue_ngap_id,
// request_type, pdu_session_id, dnn, sm_msg);
itti_smf_services_consumer* itti_msg =
itti_smf_services_consumer *itti_msg =
new itti_smf_services_consumer(TASK_AMF_N1, TASK_AMF_N11);
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->req_type = request_type;
itti_msg->pdu_sess_id = pdu_session_id;
itti_msg->dnn = dnn;
itti_msg->sm_msg = sm_msg;
itti_msg->snssai.sST = snssai.sst;
itti_msg->snssai.sD = std::to_string(snssai.sd);
itti_msg->plmn.mnc = plmn.mnc;
itti_msg->plmn.mcc = plmn.mcc;
itti_msg->req_type = request_type;
itti_msg->pdu_sess_id = pdu_session_id;
itti_msg->dnn = dnn;
itti_msg->sm_msg = sm_msg;
itti_msg->snssai.sST = snssai.sst;
itti_msg->snssai.sD = std::to_string(snssai.sd);
itti_msg->plmn.mnc = plmn.mnc;
itti_msg->plmn.mcc = plmn.mcc;
std::shared_ptr<itti_smf_services_consumer> i =
std::shared_ptr<itti_smf_services_consumer>(itti_msg);
int ret = itti_inst->send_msg(i);
......@@ -2450,17 +2434,19 @@ void amf_n1::ul_nas_transport_handle(
}
//------------------------------------------------------------------------------
void amf_n1::send_itti_to_smf_services_consumer(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, uint8_t request_type,
uint8_t pdu_session_id, bstring dnn, bstring sm_msg) {
itti_smf_services_consumer* itti_msg =
void amf_n1::send_itti_to_smf_services_consumer(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id,
uint8_t request_type,
uint8_t pdu_session_id,
bstring dnn, bstring sm_msg) {
itti_smf_services_consumer *itti_msg =
new itti_smf_services_consumer(TASK_AMF_N1, TASK_AMF_N11);
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->req_type = request_type;
itti_msg->pdu_sess_id = pdu_session_id;
itti_msg->dnn = dnn;
itti_msg->sm_msg = sm_msg;
itti_msg->req_type = request_type;
itti_msg->pdu_sess_id = pdu_session_id;
itti_msg->dnn = dnn;
itti_msg->sm_msg = sm_msg;
std::shared_ptr<itti_smf_services_consumer> i =
std::shared_ptr<itti_smf_services_consumer>(itti_msg);
int ret = itti_inst->send_msg(i);
......@@ -2485,14 +2471,13 @@ void amf_n1::ue_authentication_simulator(uint8_t* rand, uint8_t* autn) {
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
uint8_t key[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
// string serving_network = "5G:mnc011.mcc460.3gppnetwork.org";
string serving_network = "5G:mnc011.mcc110.3gppnetwork.org";
string serving_network = "5G:mnc011.mcc460.3gppnetwork.org";
print_buffer("amf_n1", "[ue] local opc", opc, 16);
print_buffer("amf_n1", "[ue] local key", key, 16);
uint8_t res[8], resStar[16];
uint8_t ck[16], ik[16], ak[6];
Authentication_5gaka::f2345(
opc, key, rand, res, ck, ik, ak); // to compute XRES, CK, IK, AK
Authentication_5gaka::f2345(opc, key, rand, res, ck, ik,
ak); // to compute XRES, CK, IK, AK
print_buffer("amf_n1", "[ue] Result for f2345: res", res, 8);
print_buffer("amf_n1", "[ue] Result for f2345: ck", ck, 16);
print_buffer("amf_n1", "[ue] Result for f2345: ik", ik, 16);
......@@ -2554,28 +2539,28 @@ void amf_n1::run_mobility_registration_update_procedure(
regAccept->setALLOWED_NSSAI(nssai);
// std::string guti = amf_cfg.guami.mcc + amf_cfg.guami.mnc +
// amf_cfg.guami.regionID + amf_cfg.guami.AmfSetID + amf_cfg.guami.AmfPointer
// + "0001";
// amf_cfg.guami.regionID + amf_cfg.guami.AmfSetID + amf_cfg.guami.AmfPointer +
// "0001";
std::string guti = "1234567890"; // TODO: need modify
Logger::amf_n1().debug("Allocated GUTI %s", guti.c_str());
regAccept->set_5GS_Network_Feature_Support(0x00, 0x00);
uint8_t buffer[1024] = {0};
int encoded_size = regAccept->encode2buffer(buffer, 1024);
print_buffer(
"amf_n1", "Registration-Accept Message Buffer", buffer, encoded_size);
int encoded_size = regAccept->encode2buffer(buffer, 1024);
print_buffer("amf_n1", "Registration-Accept Message Buffer", buffer,
encoded_size);
if (!encoded_size) {
Logger::nas_mm().error("Encode Registration-Accept message error");
return;
} else {
delete regAccept;
}
nas_secu_ctx* secu = nc.get()->security_ctx;
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,
buffer, encoded_size, protectedNas);
encode_nas_message_protected(secu, false, INTEGRITY_PROTECTED_AND_CIPHERED,
NAS_MESSAGE_DOWNLINK, buffer, encoded_size,
protectedNas);
string supi = "imsi-" + nc.get()->imsi;
Logger::amf_n1().debug("Key for pdu session context SUPI (%s)", supi.c_str());
......@@ -2598,11 +2583,11 @@ void amf_n1::run_mobility_registration_update_procedure(
new itti_initial_context_setup_request(TASK_AMF_N1, TASK_AMF_N2);
itti_msg->ran_ue_ngap_id = nc.get()->ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = nc.get()->amf_ue_ngap_id;
itti_msg->kgnb = kgnb_bs;
itti_msg->nas = protectedNas;
itti_msg->is_sr = true; // service request indicator
itti_msg->kgnb = kgnb_bs;
itti_msg->nas = protectedNas;
itti_msg->is_sr = true; // service request indicator
itti_msg->pdu_session_id = psc.get()->pdu_session_id;
itti_msg->n2sm = psc.get()->n2sm;
itti_msg->n2sm = psc.get()->n2sm;
std::shared_ptr<itti_initial_context_setup_request> i =
std::shared_ptr<itti_initial_context_setup_request>(itti_msg);
int ret = itti_inst->send_msg(i);
......@@ -2624,8 +2609,8 @@ void amf_n1::set_5gmm_state(
}
//------------------------------------------------------------------------------
void amf_n1::get_5gmm_state(
std::shared_ptr<nas_context> nc, _5gmm_state_t& state) {
void amf_n1::get_5gmm_state(std::shared_ptr<nas_context> nc,
_5gmm_state_t &state) {
// TODO:
state = nc.get()->_5gmm_state;
}
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -29,20 +29,20 @@
#ifndef _AMF_N1_H_
#define _AMF_N1_H_
#include <map>
#include <shared_mutex>
#include <mysql/mysql.h>
#include <stdlib.h>
#include <string.h>
#include <mysql/mysql.h>
#include <map>
#include <shared_mutex>
#include "nas_context.hpp"
#include "pdu_session_context.hpp"
#include "itti_msg_n1.hpp"
#include "bstrlib.h"
#include "3gpp_ts24501.hpp"
#include "amf_statistics.hpp"
#include "amf.hpp"
#include "amf_statistics.hpp"
#include "bstrlib.h"
#include "itti_msg_n1.hpp"
#include "mysql_db.hpp"
#include "nas_context.hpp"
#include "pdu_session_context.hpp"
namespace amf_application {
......@@ -61,8 +61,8 @@ class amf_n1 {
public:
amf_n1();
~amf_n1();
void handle_itti_message(itti_uplink_nas_data_ind&);
void handle_itti_message(itti_downlink_nas_transfer& itti_msg);
void handle_itti_message(itti_uplink_nas_data_ind &);
void handle_itti_message(itti_downlink_nas_transfer &itti_msg);
// nas message decode
void nas_signalling_establishment_request_handle(
SecurityHeaderType type, std::shared_ptr<nas_context> nc,
......@@ -100,7 +100,7 @@ class amf_n1 {
database_t* db_desc;
// procedures
void run_registration_procedure(std::shared_ptr<nas_context>& nc);
void run_registration_procedure(std::shared_ptr<nas_context> &nc);
void run_initial_registration_procedure();
void run_mobility_registration_update_procedure(
std::shared_ptr<nas_context> nc);
......@@ -117,10 +117,10 @@ class amf_n1 {
bool authentication_vectors_generator_in_ausf(
std::shared_ptr<nas_context>& nc);
bool authentication_vectors_generator_in_udm(
std::shared_ptr<nas_context>& nc);
std::shared_ptr<nas_context> &nc);
// mysql handlers in mysql_db.cpp
bool get_mysql_auth_info(std::string imsi, mysql_auth_info_t& resp);
void mysql_push_rand_sqn(std::string imsi, uint8_t* rand_p, uint8_t* sqn);
bool get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp);
void mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p, uint8_t *sqn);
void mysql_increment_sqn(std::string imsi);
bool connect_to_mysql();
void generate_random(uint8_t* random_p, ssize_t length);
......@@ -157,40 +157,42 @@ class amf_n1 {
uint8_t pdu_session_id, bstring dnn, bstring sm_msg);
void set_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t state);
void get_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t& state);
void get_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t &state);
private: // nas message handlers
void ue_initiate_de_registration_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
void registration_request_handle(
bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, std::string snn, bstring reg);
void authentication_response_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg);
void authentication_failure_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg);
void security_mode_complete_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg);
void security_mode_reject_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg);
void ul_nas_transport_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
void ul_nas_transport_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas, plmn_t plmn);
void sha256(unsigned char* message, int msg_len, unsigned char* output);
void service_request_handle(
bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring nas);
void identity_response_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg);
void ue_initiate_de_registration_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring nas);
void registration_request_handle(bool isNasSig,
std::shared_ptr<nas_context> nc,
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
std::string snn, bstring reg);
void authentication_response_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring plain_msg);
void authentication_failure_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring plain_msg);
void security_mode_complete_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring nas_msg);
void security_mode_reject_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
bstring nas_msg);
void ul_nas_transport_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
bstring nas);
void ul_nas_transport_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
bstring nas, plmn_t plmn);
void sha256(unsigned char *message, int msg_len, unsigned char *output);
void service_request_handle(bool isNasSig, std::shared_ptr<nas_context> nc,
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
bstring nas);
void identity_response_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
bstring plain_msg);
// authentication vector
bool generate_authentication_vector();
void itti_send_dl_nas_buffer_to_task_n2(
bstring& b, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id);
void itti_send_dl_nas_buffer_to_task_n2(bstring &b, uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id);
// response message
void response_registration_reject_msg(
uint8_t cause_value, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id);
void response_registration_reject_msg(uint8_t cause_value,
uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id);
};
} // namespace amf_application
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -31,18 +31,18 @@
#include <curl/curl.h>
#include <nlohmann/json.hpp>
#include "3gpp_ts24501.hpp"
#include "amf.hpp"
#include "amf_config.hpp"
#include "amf_n1.hpp"
#include "itti.hpp"
#include "itti_msg_amf_app.hpp"
#include "amf_config.hpp"
#include "nas_context.hpp"
#include "amf.hpp"
#include "3gpp_ts24501.hpp"
// For smf_client
#include "SmContextCreateData.h"
#include "SMContextsCollectionApi.h"
#include "ApiConfiguration.h"
#include "ApiClient.h"
#include "ApiConfiguration.h"
#include "SMContextsCollectionApi.h"
#include "SmContextCreateData.h"
#include "mime_parser.hpp"
extern "C" {
......@@ -59,18 +59,17 @@ using namespace config;
using namespace amf_application;
extern itti_mw* itti_inst;
extern amf_config amf_cfg;
extern amf_n11* amf_n11_inst;
extern amf_n1* amf_n1_inst;
extern void msg_str_2_msg_hex(std::string msg, bstring& b);
extern void convert_string_2_hex(std::string& input, std::string& output);
extern void print_buffer(
const std::string app, const std::string commit, uint8_t* buf, int len);
extern bool multipart_parser(
std::string input, std::string& jsonData, std::string& n1sm,
std::string& n2sm);
extern unsigned char* format_string_as_hex(std::string str);
extern char* bstring2charString(bstring b);
extern amf_n11 *amf_n11_inst;
extern amf_n1 *amf_n1_inst;
extern void msg_str_2_msg_hex(std::string msg, bstring &b);
extern void convert_string_2_hex(std::string &input, std::string &output);
extern void print_buffer(const std::string app, const std::string commit,
uint8_t *buf, int len);
extern bool multipart_parser(std::string input, std::string &jsonData,
std::string &n1sm, std::string &n2sm);
extern unsigned char *format_string_as_hex(std::string str);
extern char *bstring2charString(bstring b);
//------------------------------------------------------------------------------
std::size_t callback(
......@@ -81,9 +80,9 @@ std::size_t callback(
}
//------------------------------------------------------------------------------
void octet_stream_2_hex_stream(uint8_t* buf, int len, std::string& out) {
out = "";
char* tmp = (char*) calloc(1, 2 * len * sizeof(uint8_t) + 1);
void octet_stream_2_hex_stream(uint8_t *buf, int len, std::string &out) {
out = "";
char *tmp = (char *)calloc(1, 2 * len * sizeof(uint8_t) + 1);
for (int i = 0; i < len; i++) {
sprintf(tmp + 2 * i, "%02x", buf[i]);
}
......@@ -96,9 +95,9 @@ void octet_stream_2_hex_stream(uint8_t* buf, int len, std::string& out) {
/** used to run NF(s) consumer, like smf_client ****/
/***************************************************/
void amf_n11_task(void*);
void amf_n11_task(void *);
//------------------------------------------------------------------------------
void amf_n11_task(void*) {
void amf_n11_task(void *) {
const task_id_t task_id = TASK_AMF_N11;
itti_inst->notify_task_ready(task_id);
do {
......@@ -107,22 +106,22 @@ void amf_n11_task(void*) {
switch (msg->msg_type) {
case SMF_SERVICES_CONSUMER: {
Logger::amf_n11().info("Running SMF_SERVICES_CONSUMER");
itti_smf_services_consumer* m =
dynamic_cast<itti_smf_services_consumer*>(msg);
itti_smf_services_consumer *m =
dynamic_cast<itti_smf_services_consumer *>(msg);
amf_n11_inst->handle_itti_message(ref(*m));
} break;
case NSMF_PDU_SESSION_UPDATE_SM_CTX: {
Logger::amf_n11().info(
"Receive Nsmf_PDUSessionUpdateSMContext, handling ...");
itti_nsmf_pdusession_update_sm_context* m =
dynamic_cast<itti_nsmf_pdusession_update_sm_context*>(msg);
itti_nsmf_pdusession_update_sm_context *m =
dynamic_cast<itti_nsmf_pdusession_update_sm_context *>(msg);
amf_n11_inst->handle_itti_message(ref(*m));
} break;
case PDU_SESS_RES_SET_RESP: {
Logger::amf_n11().info(
"Receive PDU Session Resource Setup Response, handling ...");
itti_pdu_session_resource_setup_response* m =
dynamic_cast<itti_pdu_session_resource_setup_response*>(msg);
itti_pdu_session_resource_setup_response *m =
dynamic_cast<itti_pdu_session_resource_setup_response *>(msg);
amf_n11_inst->handle_itti_message(ref(*m));
} break;
default: {
......@@ -149,7 +148,7 @@ amf_n11::~amf_n11() {}
//------------------------------------------------------------------------------
void amf_n11::handle_itti_message(
itti_pdu_session_resource_setup_response& itti_msg) {}
itti_pdu_session_resource_setup_response &itti_msg) {}
//------------------------------------------------------------------------------
void amf_n11::handle_itti_message(
......@@ -198,21 +197,21 @@ void amf_n11::handle_itti_message(
nlohmann::json pdu_session_update_request = {};
// if (itti_msg.is_n2sm_set){
pdu_session_update_request["n2SmInfoType"] = itti_msg.n2sm_info_type;
pdu_session_update_request["n2SmInfo"]["contentId"] = "n2SmMsg";
pdu_session_update_request["n2SmInfoType"] = itti_msg.n2sm_info_type;
pdu_session_update_request["n2SmInfo"]["contentId"] = "n2msg";
std::string json_part = pdu_session_update_request.dump();
std::string n2SmMsg;
octet_stream_2_hex_stream(
(uint8_t*) bdata(itti_msg.n2sm), blength(itti_msg.n2sm), n2SmMsg);
curl_http_client(
remote_uri, json_part, "", n2SmMsg, supi, itti_msg.pdu_session_id);
octet_stream_2_hex_stream((uint8_t *)bdata(itti_msg.n2sm),
blength(itti_msg.n2sm), n2SmMsg);
curl_http_client(remote_uri, json_part, "", n2SmMsg, supi,
itti_msg.pdu_session_id);
}
//------------------------------------------------------------------------------
void amf_n11::handle_itti_message(itti_smf_services_consumer& smf) {
Logger::amf_n11().debug("Handle ITTI_SMF_SERVICES_CONSUMER");
std::shared_ptr<nas_context> nc;
nc = amf_n1_inst->amf_ue_id_2_nas_context(smf.amf_ue_ngap_id);
nc = amf_n1_inst->amf_ue_id_2_nas_context(smf.amf_ue_ngap_id);
std::string supi = "imsi-" + nc.get()->imsi;
std::shared_ptr<pdu_session_context> psc;
......@@ -224,21 +223,21 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer& smf) {
}
pduid2supi[smf.pdu_sess_id] = supi;
psc.get()->amf_ue_ngap_id = nc.get()->amf_ue_ngap_id;
psc.get()->ran_ue_ngap_id = nc.get()->ran_ue_ngap_id;
psc.get()->req_type = smf.req_type;
psc.get()->pdu_session_id = smf.pdu_sess_id;
psc.get()->snssai.sST = smf.snssai.sST;
psc.get()->snssai.sD = smf.snssai.sD;
psc.get()->plmn.mcc = smf.plmn.mcc;
psc.get()->plmn.mnc = smf.plmn.mnc;
psc.get()->amf_ue_ngap_id = nc.get()->amf_ue_ngap_id;
psc.get()->ran_ue_ngap_id = nc.get()->ran_ue_ngap_id;
psc.get()->req_type = smf.req_type;
psc.get()->pdu_session_id = smf.pdu_sess_id;
psc.get()->snssai.sST = smf.snssai.sST;
psc.get()->snssai.sD = smf.snssai.sD;
psc.get()->plmn.mcc = smf.plmn.mcc;
psc.get()->plmn.mnc = smf.plmn.mnc;
// parse binary dnn and store
std::string dnn = "default";
if ((smf.dnn != nullptr) && (blength(smf.dnn) > 0)) {
char* tmp = bstring2charString(smf.dnn);
dnn = tmp;
free_wrapper((void**) &tmp);
char *tmp = bstring2charString(smf.dnn);
dnn = tmp;
free_wrapper((void **)&tmp);
}
Logger::amf_n11().debug("Requested DNN: %s", dnn.c_str());
......@@ -257,8 +256,8 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer& smf) {
switch (smf.req_type & 0x07) {
case PDU_SESSION_INITIAL_REQUEST: {
// get pti
uint8_t* sm_msg = (uint8_t*) bdata(smf.sm_msg);
uint8_t pti = sm_msg[2];
uint8_t *sm_msg = (uint8_t *)bdata(smf.sm_msg);
uint8_t pti = sm_msg[2];
Logger::amf_n11().debug(
"Decoded PTI for PDUSessionEstablishmentRequest(0x%x)", pti);
if (psc.get()->isn1sm_avaliable && psc.get()->isn2sm_avaliable) {
......@@ -267,9 +266,9 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer& smf) {
itti_msg->supi = supi;
uint8_t accept_len = blength(psc.get()->n1sm);
uint8_t* accept = (uint8_t*) calloc(1, accept_len);
memcpy(accept, (uint8_t*) bdata(psc.get()->n1sm), accept_len);
accept[2] = pti;
uint8_t *accept = (uint8_t *)calloc(1, accept_len);
memcpy(accept, (uint8_t *)bdata(psc.get()->n1sm), accept_len);
accept[2] = pti;
itti_msg->n1sm = blk2bstr(accept, accept_len);
free(accept);
itti_msg->is_n1sm_set = true;
......@@ -299,8 +298,8 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer& smf) {
default: {
// send Nsmf_PDUSession_UpdateSM_Context to SMF e.g., for PDU Session
// release request
send_pdu_session_update_sm_context_request(
supi, psc, smf_addr, smf.sm_msg, dnn);
send_pdu_session_update_sm_context_request(supi, psc, smf_addr,
smf.sm_msg, dnn);
}
}
}
......@@ -330,14 +329,14 @@ void amf_n11::send_pdu_session_update_sm_context_request(
Logger::amf_n11().debug("SMF URI: %s", remote_uri.c_str());
nlohmann::json pdu_session_update_request = {};
nlohmann::json pdu_session_update_request = {};
pdu_session_update_request["n1SmMsg"]["contentId"] = "n1SmMsg";
std::string json_part = pdu_session_update_request.dump();
std::string n1SmMsg;
octet_stream_2_hex_stream((uint8_t*) bdata(sm_msg), blength(sm_msg), n1SmMsg);
curl_http_client(
remote_uri, json_part, n1SmMsg, "", supi, psc.get()->pdu_session_id);
octet_stream_2_hex_stream((uint8_t *)bdata(sm_msg), blength(sm_msg), n1SmMsg);
curl_http_client(remote_uri, json_part, n1SmMsg, "", supi,
psc.get()->pdu_session_id);
}
//------------------------------------------------------------------------------
......@@ -349,8 +348,7 @@ void amf_n11::handle_pdu_session_initial_request(
supi.c_str(), psc.get()->pdu_session_id);
// TODO: Remove hardcoded values
std::string remote_uri =
smf_addr + "/nsmf-pdusession/v2/sm-contexts"; // TODO
std::string remote_uri = smf_addr + "/nsmf-pdusession/v2/sm-contexts"; // TODO
nlohmann::json pdu_session_establishment_request;
pdu_session_establishment_request["supi"] = supi.c_str();
pdu_session_establishment_request["pei"] = "imei-200000000000001";
......@@ -364,14 +362,10 @@ void amf_n11::handle_pdu_session_initial_request(
pdu_session_establishment_request["requestType"] =
"INITIAL_REQUEST"; // TODO: from SM_MSG
pdu_session_establishment_request["servingNfId"] = "servingNfId";
// pdu_session_establishment_request["servingNetwork"]["mcc"] =
// psc.get()->plmn
// .mcc;
// pdu_session_establishment_request["servingNetwork"]["mnc"] =
// psc.get()->plmn
// .mnc;
pdu_session_establishment_request["servingNetwork"]["mcc"] = "110";
pdu_session_establishment_request["servingNetwork"]["mnc"] = "011";
pdu_session_establishment_request["servingNetwork"]["mcc"] =
psc.get()->plmn.mcc;
pdu_session_establishment_request["servingNetwork"]["mnc"] =
psc.get()->plmn.mnc;
pdu_session_establishment_request["anType"] = "3GPP_ACCESS"; // TODO
pdu_session_establishment_request["smContextStatusUri"] =
"smContextStatusUri";
......@@ -383,9 +377,9 @@ void amf_n11::handle_pdu_session_initial_request(
std::string json_part = pdu_session_establishment_request.dump();
std::string n1SmMsg;
octet_stream_2_hex_stream((uint8_t*) bdata(sm_msg), blength(sm_msg), n1SmMsg);
curl_http_client(
remote_uri, json_part, n1SmMsg, "", supi, psc.get()->pdu_session_id);
octet_stream_2_hex_stream((uint8_t *)bdata(sm_msg), blength(sm_msg), n1SmMsg);
curl_http_client(remote_uri, json_part, n1SmMsg, "", supi,
psc.get()->pdu_session_id);
}
//------------------------------------------------------------------------------
......@@ -450,7 +444,7 @@ bool amf_n11::smf_selection_from_configuration(std::string& smf_addr) {
}
//------------------------------------------------------------------------------
bool amf_n11::smf_selection_from_context(std::string& smf_addr) {
bool amf_n11::smf_selection_from_context(std::string &smf_addr) {
// TODO:
}
......@@ -459,11 +453,13 @@ bool amf_n11::smf_selection_from_context(std::string& smf_addr) {
void amf_n11::handle_post_sm_context_response_error_400() {}
//------------------------------------------------------------------------------
void amf_n11::handle_post_sm_context_response_error(
long code, std::string cause, bstring n1sm, std::string supi,
uint8_t pdu_session_id) {
print_buffer("amf_n11", "n1 sm", (uint8_t*) bdata(n1sm), blength(n1sm));
itti_n1n2_message_transfer_request* itti_msg =
void amf_n11::handle_post_sm_context_response_error(long code,
std::string cause,
bstring n1sm,
std::string supi,
uint8_t pdu_session_id) {
print_buffer("amf_n11", "n1 sm", (uint8_t *)bdata(n1sm), blength(n1sm));
itti_n1n2_message_transfer_request *itti_msg =
new itti_n1n2_message_transfer_request(TASK_AMF_N11, TASK_AMF_APP);
itti_msg->n1sm = n1sm;
itti_msg->is_n2sm_set = false;
......@@ -486,22 +482,22 @@ void amf_n11::curl_http_client(
Logger::amf_n11().debug("Call SMF service: %s", remoteUri.c_str());
uint8_t number_parts = 0;
mime_parser parser = {};
mime_parser parser = {};
std::string body;
std::shared_ptr<pdu_session_context> psc;
if (is_supi_to_pdu_ctx(supi)) {
psc = supi_to_pdu_ctx(supi);
} else {
Logger::amf_n11().warn(
"PDU Session context for SUPI %s doesn't exit!", supi.c_str());
Logger::amf_n11().warn("PDU Session context for SUPI %s doesn't exit!",
supi.c_str());
// TODO:
}
if ((n1SmMsg.size() > 0) and (n2SmMsg.size() > 0)) {
// prepare the body content for Curl
parser.create_multipart_related_content(
body, jsonData, CURL_MIME_BOUNDARY, n1SmMsg, n2SmMsg);
parser.create_multipart_related_content(body, jsonData, CURL_MIME_BOUNDARY,
n1SmMsg, n2SmMsg);
} else if (n1SmMsg.size() > 0) { // only N1 content
// prepare the body content for Curl
parser.create_multipart_related_content(
......@@ -518,16 +514,16 @@ void amf_n11::curl_http_client(
"Send HTTP message to SMF with body %s", body.c_str());
uint32_t str_len = body.length();
char* body_data = (char*) malloc(str_len + 1);
char *body_data = (char *)malloc(str_len + 1);
memset(body_data, 0, str_len + 1);
memcpy((void*) body_data, (void*) body.c_str(), str_len);
memcpy((void *)body_data, (void *)body.c_str(), str_len);
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl_easy_init();
CURL *curl = curl_easy_init();
if (curl) {
CURLcode res = {};
struct curl_slist* headers = nullptr;
CURLcode res = {};
struct curl_slist *headers = nullptr;
std::string content_type = "content-type: multipart/related; boundary=" +
std::string(CURL_MIME_BOUNDARY);
......@@ -555,18 +551,18 @@ void amf_n11::curl_http_client(
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
// get cause from the response
std::string response = *httpData.get();
std::string response = *httpData.get();
std::string json_data_response = "";
std::string n1sm = "";
std::string n2sm = "";
nlohmann::json response_data = {};
std::string n1sm = "";
std::string n2sm = "";
nlohmann::json response_data = {};
bstring n1sm_hex, n2sm_hex;
Logger::amf_n11().debug("Get response with HTTP code (%d)", httpCode);
if (static_cast<http_response_codes_e>(httpCode) ==
http_response_codes_e::HTTP_RESPONSE_CODE_0) {
Logger::amf_n11().error(
"Cannot get response when calling %s", remoteUri.c_str());
Logger::amf_n11().error("Cannot get response when calling %s",
remoteUri.c_str());
// free curl before returning
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
......@@ -600,22 +596,22 @@ void amf_n11::curl_http_client(
response_data["error"]["cause"] = "504 Gateway Timeout";
}
Logger::amf_n11().debug(
"Get response with jsonData: %s", json_data_response.c_str());
Logger::amf_n11().debug("Get response with jsonData: %s",
json_data_response.c_str());
msg_str_2_msg_hex(
n1sm.substr(0, n1sm.length() - 2),
n1sm_hex); // TODO: pdu session establishment reject bugs from SMF
print_buffer(
"amf_n11", "Get response with n1sm:", (uint8_t*) bdata(n1sm_hex),
blength(n1sm_hex));
print_buffer("amf_n11",
"Get response with n1sm:", (uint8_t *)bdata(n1sm_hex),
blength(n1sm_hex));
std::string cause = response_data["error"]["cause"];
Logger::amf_n11().warn(
"Call Network Function services failure (with cause %s)",
cause.c_str());
if (!cause.compare("DNN_DENIED"))
handle_post_sm_context_response_error(
httpCode, cause, n1sm_hex, supi, pdu_session_id);
handle_post_sm_context_response_error(httpCode, cause, n1sm_hex, supi,
pdu_session_id);
} else { // Response with success code
// Store location of the created context in case of PDU Session
// Establishment
......@@ -649,19 +645,19 @@ void amf_n11::curl_http_client(
if (n1sm.size() > 0) {
msg_str_2_msg_hex(n1sm, n1sm_hex);
print_buffer(
"amf_n11", "Get response n1sm:", (uint8_t*) bdata(n1sm_hex),
blength(n1sm_hex));
itti_msg->n1sm = n1sm_hex;
print_buffer("amf_n11",
"Get response n1sm:", (uint8_t *)bdata(n1sm_hex),
blength(n1sm_hex));
itti_msg->n1sm = n1sm_hex;
itti_msg->is_n1sm_set = true;
}
if (n2sm.size() > 0) {
msg_str_2_msg_hex(n2sm, n2sm_hex);
print_buffer(
"amf_n11", "Get response n2sm:", (uint8_t*) bdata(n2sm_hex),
blength(n2sm_hex));
itti_msg->n2sm = n2sm_hex;
itti_msg->is_n2sm_set = true;
print_buffer("amf_n11",
"Get response n2sm:", (uint8_t *)bdata(n2sm_hex),
blength(n2sm_hex));
itti_msg->n2sm = n2sm_hex;
itti_msg->is_n2sm_set = true;
itti_msg->n2sm_info_type = response_data
["n2SmInfoType"]; // response_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapIeType"];
}
......@@ -684,5 +680,5 @@ void amf_n11::curl_http_client(
}
curl_global_cleanup();
free_wrapper((void**) &body_data);
free_wrapper((void **)&body_data);
}
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -43,7 +43,7 @@ class amf_n11 {
amf_n11();
~amf_n11();
void handle_itti_message(itti_smf_services_consumer&);
void handle_itti_message(itti_smf_services_consumer &);
void handle_pdu_session_initial_request(
std::string supi, std::shared_ptr<pdu_session_context> psc,
std::string smf_addr, bstring sm_msg, std::string dnn);
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -28,28 +28,28 @@
#include "amf_n2.hpp"
#include "amf_n1.hpp"
#include "amf_n11.hpp"
#include "amf_app.hpp"
#include "logger.hpp"
#include "sctp_server.hpp"
#include "itti.hpp"
#include "itti_msg_amf_app.hpp"
#include "amf_config.hpp"
#include "DefaultPagingDRX.hpp"
#include "DownLinkNasTransport.hpp"
#include "InitialContextSetupRequest.hpp"
#include "NGSetupFailure.hpp"
#include "NGSetupResponse.hpp"
#include "Ngap_Cause.h"
#include "Ngap_CauseNas.h"
#include "Ngap_CauseRadioNetwork.h"
#include "Ngap_TimeToWait.h"
#include "PDUSessionResourceHandoverCommandTransfer.hpp"
#include "DownLinkNasTransport.hpp"
#include "InitialContextSetupRequest.hpp"
#include "PduSessionResourceSetupRequest.hpp"
#include "PduSessionResourceReleaseCommand.hpp"
#include "PduSessionResourceSetupRequest.hpp"
#include "UEContextReleaseCommand.hpp"
#include "amf_app.hpp"
#include "amf_config.hpp"
#include "amf_n1.hpp"
#include "amf_n11.hpp"
#include "amf_statistics.hpp"
#include "Ngap_Cause.h"
#include "Ngap_CauseRadioNetwork.h"
#include "Ngap_TimeToWait.h"
#include "Ngap_CauseNas.h"
#include "itti.hpp"
#include "itti_msg_amf_app.hpp"
#include "logger.hpp"
#include "sctp_server.hpp"
extern "C" {
#include "dynamic_memory_check.h"
......@@ -66,8 +66,8 @@ extern amf_n11* amf_n11_inst;
extern amf_config amf_cfg;
extern amf_app* amf_app_inst;
extern statistics stacs;
extern void print_buffer(
const std::string app, const std::string commit, uint8_t* buf, int len);
extern void print_buffer(const std::string app, const std::string commit,
uint8_t* buf, int len);
uint32_t ran_id_Global = 0;
uint32_t AMF_TARGET_ran_id_global = 0;
......@@ -83,7 +83,7 @@ void amf_n2_task(void* args_p) {
itti_inst->notify_task_ready(task_id);
do {
std::shared_ptr<itti_msg> shared_msg = itti_inst->receive_msg(task_id);
auto* msg = shared_msg.get();
auto* msg = shared_msg.get();
switch (msg->msg_type) {
case NEW_SCTP_ASSOCIATION: {
Logger::amf_n2().info("Received NEW_SCTP_ASSOCIATION");
......@@ -207,8 +207,8 @@ void amf_n2::handle_itti_message(itti_new_sctp_association& new_assoc) {
// NG_SETUP_REQUEST Handler
//------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) {
Logger::amf_n2().debug(
"Parameters: assoc_id %d, stream %d", itti_msg.assoc_id, itti_msg.stream);
Logger::amf_n2().debug("Parameters: assoc_id %d, stream %d",
itti_msg.assoc_id, itti_msg.stream);
std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
......@@ -279,10 +279,10 @@ void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) {
void* buffer = calloc(1, 1000);
NGSetupFailureMsg ngSetupFailure;
ngSetupFailure.setMessageType();
ngSetupFailure.setCauseRadioNetwork(
Ngap_CauseRadioNetwork_unspecified, Ngap_TimeToWait_v5s);
int encoded = ngSetupFailure.encode2buffer((uint8_t*) buffer, 1000);
bstring b = blk2bstr(buffer, encoded);
ngSetupFailure.setCauseRadioNetwork(Ngap_CauseRadioNetwork_unspecified,
Ngap_TimeToWait_v5s);
int encoded = ngSetupFailure.encode2buffer((uint8_t*)buffer, 1000);
bstring b = blk2bstr(buffer, encoded);
sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
Logger::amf_n2().error(
"No common PLMN, encoding NG_SETUP_FAILURE with cause (Unknown PLMN)");
......@@ -332,8 +332,8 @@ void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) {
plmn_list.push_back(tmp);
}
ngSetupResp.setPlmnSupportList(plmn_list);
int encoded = ngSetupResp.encode2buffer((uint8_t*) buffer, 1000);
bstring b = blk2bstr(buffer, encoded);
int encoded = ngSetupResp.encode2buffer((uint8_t*)buffer, 1000);
bstring b = blk2bstr(buffer, encoded);
sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
Logger::amf_n2().debug("Sending NG_SETUP_RESPONSE Ok");
gc.get()->ng_state = NGAP_READY;
......@@ -396,7 +396,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
"Failed to get UE NGAP context for ran_ue_ngap_id 0x%x", 21);
} else {
// store information into UE NGAP context
unc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
unc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
unc.get()->sctp_stream_recv = init_ue_msg.stream;
unc.get()->sctp_stream_send == gc.get()->next_sctp_stream;
gc.get()->next_sctp_stream += 1;
......@@ -461,7 +461,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
//------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_ul_nas_transport& ul_nas_transport) {
unsigned long amf_ue_ngap_id = ul_nas_transport.ulNas->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = ul_nas_transport.ulNas->getRanUeNgapId();
uint32_t ran_ue_ngap_id = ul_nas_transport.ulNas->getRanUeNgapId();
std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(ul_nas_transport.assoc_id)) {
Logger::amf_n2().error(
......@@ -498,11 +498,11 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport& ul_nas_transport) {
itti_uplink_nas_data_ind* itti_msg =
new itti_uplink_nas_data_ind(TASK_AMF_N2, TASK_AMF_N1);
itti_msg->is_nas_signalling_estab_req = false;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->is_guti_valid = false;
uint8_t* nas_buf = NULL;
size_t nas_len = 0;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->is_guti_valid = false;
uint8_t* nas_buf = NULL;
size_t nas_len = 0;
if (ul_nas_transport.ulNas->getNasPdu(nas_buf, nas_len)) {
itti_msg->nas_msg = blk2bstr(nas_buf, nas_len);
} else {
......@@ -511,7 +511,7 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport& ul_nas_transport) {
}
// UserLocation
NrCgi_t cgi = {};
Tai_t tai = {};
Tai_t tai = {};
if (ul_nas_transport.ulNas->getUserLocationInfoNR(cgi, tai)) {
itti_msg->mcc = cgi.mcc;
itti_msg->mnc = cgi.mnc;
......@@ -546,14 +546,14 @@ void amf_n2::handle_itti_message(itti_dl_nas_transport& dl_nas_transport) {
"Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return;
}
unc.get()->amf_ue_ngap_id = dl_nas_transport.amf_ue_ngap_id;
unc.get()->ng_ue_state = NGAP_UE_CONNECTED;
unc.get()->amf_ue_ngap_id = dl_nas_transport.amf_ue_ngap_id;
unc.get()->ng_ue_state = NGAP_UE_CONNECTED;
DownLinkNasTransportMsg* ngap_msg = new DownLinkNasTransportMsg();
ngap_msg->setMessageType();
ngap_msg->setAmfUeNgapId(dl_nas_transport.amf_ue_ngap_id);
ngap_msg->setRanUeNgapId(dl_nas_transport.ran_ue_ngap_id);
ngap_msg->setNasPdu(
(uint8_t*) bdata(dl_nas_transport.nas), blength(dl_nas_transport.nas));
ngap_msg->setNasPdu((uint8_t*)bdata(dl_nas_transport.nas),
blength(dl_nas_transport.nas));
uint8_t buffer[1024];
int encoded_size = ngap_msg->encode2buffer(buffer, 1024);
bstring b = blk2bstr(buffer, encoded_size);
......@@ -588,10 +588,10 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request& itti_msg) {
guami.AmfSetID = amf_cfg.guami.AmfSetID;
guami.AmfPointer = amf_cfg.guami.AmfPointer;
msg->setGuami(guami);
msg->setUESecurityCapability(
0xe000, 0xe000, 0xe000, 0xe000); // TODO: remove hardcoded value
msg->setSecurityKey((uint8_t*) bdata(itti_msg.kgnb));
msg->setNasPdu((uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas));
msg->setUESecurityCapability(0xe000, 0xe000, 0xe000,
0xe000); // TODO: remove hardcoded value
msg->setSecurityKey((uint8_t*)bdata(itti_msg.kgnb));
msg->setNasPdu((uint8_t*)bdata(itti_msg.nas), blength(itti_msg.nas));
std::vector<S_Nssai> list;
S_Nssai item;
......@@ -603,8 +603,8 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request& itti_msg) {
bdestroy(itti_msg.kgnb);
if (itti_msg.is_sr) {
bstring ueCapability = gc.get()->ue_radio_cap_ind;
uint8_t* uecap = (uint8_t*) calloc(1, blength(ueCapability) + 1);
memcpy(uecap, (uint8_t*) bdata(ueCapability), blength(ueCapability));
uint8_t* uecap = (uint8_t*)calloc(1, blength(ueCapability) + 1);
memcpy(uecap, (uint8_t*)bdata(ueCapability), blength(ueCapability));
uecap[blength(ueCapability)] = '\0';
msg->setUERadioCapability(uecap, (size_t) blength(ueCapability));
free(uecap);
......@@ -621,7 +621,7 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request& itti_msg) {
bstring n2sm = itti_msg.n2sm;
if (blength(itti_msg.n2sm) != 0) {
item.pduSessionResourceSetupRequestTransfer.buf =
(uint8_t*) bdata(itti_msg.n2sm);
(uint8_t*)bdata(itti_msg.n2sm);
item.pduSessionResourceSetupRequestTransfer.size =
blength(itti_msg.n2sm);
} else {
......@@ -668,22 +668,21 @@ void amf_n2::handle_itti_message(
std::vector<PDUSessionResourceSetupRequestItem_t> list;
PDUSessionResourceSetupRequestItem_t item;
item.pduSessionId = itti_msg.pdu_session_id;
uint8_t* nas_pdu = (uint8_t*) calloc(1, blength(itti_msg.nas) + 1);
memcpy(nas_pdu, (uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas));
uint8_t* nas_pdu = (uint8_t*)calloc(1, blength(itti_msg.nas) + 1);
memcpy(nas_pdu, (uint8_t*)bdata(itti_msg.nas), blength(itti_msg.nas));
nas_pdu[blength(itti_msg.nas)] = '\0';
item.pduSessionNAS_PDU = nas_pdu;
item.sizeofpduSessionNAS_PDU = blength(itti_msg.nas);
item.s_nssai.sst = "01"; // TODO: get from N1N2msgTranferMsg
item.s_nssai.sd = ""; // TODO: get from N1N2msgTranferMsg
item.pduSessionNAS_PDU = nas_pdu;
item.sizeofpduSessionNAS_PDU = blength(itti_msg.nas);
item.s_nssai.sst = "01"; // TODO: get from N1N2msgTranferMsg
item.s_nssai.sd = ""; // TODO: get from N1N2msgTranferMsg
// Get NSSAI from PDU Session Context
std::shared_ptr<nas_context> nc;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(itti_msg.amf_ue_ngap_id))
nc = amf_n1_inst->amf_ue_id_2_nas_context(itti_msg.amf_ue_ngap_id);
else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)",
itti_msg.amf_ue_ngap_id);
Logger::amf_n2().warn("No existed nas_context with amf_ue_ngap_id(0x%x)",
itti_msg.amf_ue_ngap_id);
// TODO:
}
string supi = "imsi-" + nc.get()->imsi;
......@@ -699,27 +698,27 @@ void amf_n2::handle_itti_message(
// item.s_nssai.sd = psc.get()->snssai.sD;
item.pduSessionResourceSetupRequestTransfer.buf =
(uint8_t*) bdata(itti_msg.n2sm);
(uint8_t*)bdata(itti_msg.n2sm);
item.pduSessionResourceSetupRequestTransfer.size = blength(itti_msg.n2sm);
list.push_back(item);
psrsr->setPduSessionResourceSetupRequestList(list);
size_t buffer_size = BUFFER_SIZE_512;
char* buffer = (char*) calloc(1, buffer_size);
int encoded_size = 0;
char* buffer = (char*)calloc(1, buffer_size);
int encoded_size = 0;
psrsr->encode2buffer_new(buffer, encoded_size);
#if DEBUG_IS_ON
Logger::amf_n2().debug("N2 SM buffer data: ");
for (int i = 0; i < encoded_size; i++) printf("%02x ", (char) buffer[i]);
for (int i = 0; i < encoded_size; i++) printf("%02x ", (char)buffer[i]);
#endif
Logger::amf_n2().debug(" (%d bytes) \n", encoded_size);
bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(
gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id,
unc.get()->sctp_stream_send, &b);
// free memory
free_wrapper((void**) &buffer);
free_wrapper((void**)&buffer);
}
//------------------------------------------------------------------------------
......@@ -746,8 +745,8 @@ void amf_n2::handle_itti_message(
release_cmd_msg->setMessageType();
release_cmd_msg->setAmfUeNgapId(itti_msg.amf_ue_ngap_id);
release_cmd_msg->setRanUeNgapId(itti_msg.ran_ue_ngap_id);
uint8_t* nas_pdu = (uint8_t*) calloc(1, blength(itti_msg.nas) + 1);
memcpy(nas_pdu, (uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas));
uint8_t* nas_pdu = (uint8_t*)calloc(1, blength(itti_msg.nas) + 1);
memcpy(nas_pdu, (uint8_t*)bdata(itti_msg.nas), blength(itti_msg.nas));
nas_pdu[blength(itti_msg.nas)] = '\0';
release_cmd_msg->setNasPdu(nas_pdu, blength(itti_msg.nas));
......@@ -756,28 +755,28 @@ void amf_n2::handle_itti_message(
item.pduSessionId = itti_msg.pdu_session_id;
item.pduSessionResourceReleaseCommandTransfer.buf =
(uint8_t*) bdata(itti_msg.n2sm);
(uint8_t*)bdata(itti_msg.n2sm);
item.pduSessionResourceReleaseCommandTransfer.size = blength(itti_msg.n2sm);
list.push_back(item);
release_cmd_msg->setPduSessionResourceToReleaseList(list);
size_t buffer_size = BUFFER_SIZE_512;
char* buffer = (char*) calloc(1, buffer_size);
int encoded_size = 0;
char* buffer = (char*)calloc(1, buffer_size);
int encoded_size = 0;
release_cmd_msg->encode2buffer_new(buffer, encoded_size);
#if DEBUG_IS_ON
Logger::amf_n2().debug("N2 SM buffer data: ");
for (int i = 0; i < encoded_size; i++) printf("%02x ", (char) buffer[i]);
for (int i = 0; i < encoded_size; i++) printf("%02x ", (char)buffer[i]);
#endif
Logger::amf_n2().debug(" (%d bytes) \n", encoded_size);
bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(
gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id,
unc.get()->sctp_stream_send, &b);
// free memory
free_wrapper((void**) &nas_pdu);
free_wrapper((void**) &buffer);
free_wrapper((void**)&nas_pdu);
free_wrapper((void**)&buffer);
}
//------------------------------------------------------------------------------
......@@ -820,11 +819,11 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command& itti_msg) {
ueCtxRelCmd->setUeNgapIdPair(
itti_msg.amf_ue_ngap_id, itti_msg.ran_ue_ngap_id);
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) {
ueCtxRelCmd->setCauseRadioNetwork(
(e_Ngap_CauseRadioNetwork) itti_msg.cause.getValue());
(e_Ngap_CauseRadioNetwork)itti_msg.cause.getValue());
}
uint8_t buffer[200];
int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200);
......@@ -853,7 +852,7 @@ void amf_n2::handle_itti_message(
if (!itti_msg.ueRadioCap->getUERadioCapability(ue_radio_cap, size)) {
Logger::amf_n2().warn("No IE UERadioCapability");
}
gc.get()->ue_radio_cap_ind = blk2bstr(ue_radio_cap, (int) size);
gc.get()->ue_radio_cap_ind = blk2bstr(ue_radio_cap, (int)size);
}
//------------------------------------------------------------------------------
......@@ -865,8 +864,8 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
source_assoc_id = itti_msg.assoc_id;
std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error(
"gnb with assoc_id(%d) is illegal", itti_msg.assoc_id);
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal",
itti_msg.assoc_id);
return;
}
gc = assoc_id_2_gnb_context(itti_msg.assoc_id);
......@@ -878,8 +877,8 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
return;
}
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().error(
"no ue ngap context with ran_ue_ngap_id(%d)", ran_ue_ngap_id);
Logger::amf_n2().error("no ue ngap context with ran_ue_ngap_id(%d)",
ran_ue_ngap_id);
return;
}
unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
......@@ -915,7 +914,7 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
}
GlobalgNBId* TargetGlobalgNBId = new GlobalgNBId();
itti_msg.handvoerRequ->getGlobalRanNodeId(TargetGlobalgNBId);
PlmnId* plmn = new PlmnId();
PlmnId* plmn = new PlmnId();
GNB_ID* gnbid = new GNB_ID();
TargetGlobalgNBId->getGlobalgNBId(plmn, gnbid);
string mcc, mnc;
......@@ -928,14 +927,13 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
TAI* tai = new TAI();
itti_msg.handvoerRequ->getTAI(tai);
PlmnId* plmnOfTAI = new PlmnId();
TAC* tac = new TAC();
TAC* tac = new TAC();
tai->getTAI(plmnOfTAI, tac);
string mccOfselectTAI, mncOfselectTAI;
plmn->getMcc(mccOfselectTAI);
plmn->getMnc(mncOfselectTAI);
printf(
"handover required:Target ID selectedTAI PLmn=mcc%s mnc%s tac=%x\n",
mccOfselectTAI.c_str(), mncOfselectTAI.c_str(), tac->getTac());
printf("handover required:Target ID selectedTAI PLmn=mcc%s mnc%s tac=%x\n",
mccOfselectTAI.c_str(), mncOfselectTAI.c_str(), tac->getTac());
std::vector<PDUSessionResourceItem_t> List_HORqd;
if (!itti_msg.handvoerRequ->getPDUSessionResourceList(List_HORqd)) {
Logger::ngap().error(
......@@ -964,15 +962,15 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
Allowed_Nssai.push_back(s_nssai);
// handoverrequest->setAllowedNSSAI(Allowed_Nssai);
Guami_t guami;
guami.mcc = amf_cfg.guami.mcc;
guami.mnc = amf_cfg.guami.mnc;
guami.regionID = amf_cfg.guami.regionID;
guami.AmfSetID = amf_cfg.guami.AmfSetID;
guami.AmfPointer = amf_cfg.guami.AmfPointer;
PlmnId* m_plmnId = new PlmnId();
guami.mcc = amf_cfg.guami.mcc;
guami.mnc = amf_cfg.guami.mnc;
guami.regionID = amf_cfg.guami.regionID;
guami.AmfSetID = amf_cfg.guami.AmfSetID;
guami.AmfPointer = amf_cfg.guami.AmfPointer;
PlmnId* m_plmnId = new PlmnId();
AMFRegionID* m_aMFRegionID = new AMFRegionID();
AMFSetID* m_aMFSetID = new AMFSetID();
AMFPointer* m_aMFPointer = new AMFPointer();
AMFSetID* m_aMFSetID = new AMFSetID();
AMFPointer* m_aMFPointer = new AMFPointer();
m_plmnId->setMccMnc(guami.mcc, guami.mnc);
m_aMFRegionID->setAMFRegionID(guami.regionID);
m_aMFSetID->setAMFSetID(guami.AmfSetID);
......@@ -984,7 +982,7 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
std::shared_ptr<nas_context> nc =
amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
nas_secu_ctx* secu = nc.get()->security_ctx;
uint8_t* kamf = nc.get()->kamf[secu->vector_pointer];
uint8_t* kamf = nc.get()->kamf[secu->vector_pointer];
uint8_t kgnb[32];
uint32_t ulcount = secu->ul_count.seq_num | (secu->ul_count.overflow << 8);
Logger::amf_n1().debug("uplink count(%d)", secu->ul_count.seq_num);
......@@ -994,6 +992,7 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
bstring knh_bs = blk2bstr(knh, 32);
handoverrequest->setSecurityContext(
ncc /*NCC count*/, (uint8_t*) bdata(knh_bs));
// handoverrequest->setSourceToTarget_TransparentContainer(sourceTotarget);
string supi = "imsi-" + nc.get()->imsi;
std::shared_ptr<pdu_session_context> psc =
......@@ -1004,10 +1003,10 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
item.s_nssai.sst = "01";
item.s_nssai.sd = "";
item.pduSessionNAS_PDU = NULL;
bstring n2sm = psc.get()->n2sm;
bstring n2sm = psc.get()->n2sm;
if (blength(psc.get()->n2sm) != 0) {
item.pduSessionResourceSetupRequestTransfer.buf =
(uint8_t*) bdata(psc.get()->n2sm);
(uint8_t*)bdata(psc.get()->n2sm);
item.pduSessionResourceSetupRequestTransfer.size = blength(psc.get()->n2sm);
} else {
Logger::amf_n2().error("n2sm empty!");
......@@ -1031,15 +1030,15 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
//------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_handover_request_Ack& itti_msg) {
unsigned long amf_ue_ngap_id = itti_msg.handoverrequestAck->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.handoverrequestAck->getRanUeNgapId();
AMF_TARGET_ran_id_global = ran_ue_ngap_id;
uint32_t ran_ue_ngap_id = itti_msg.handoverrequestAck->getRanUeNgapId();
AMF_TARGET_ran_id_global = ran_ue_ngap_id;
Logger::amf_n2().error(
"handover request Ack ran_ue_ngap_id(0x%d) amf_ue_ngap_id(%d)",
ran_ue_ngap_id, amf_ue_ngap_id);
std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error(
"gnb with assoc_id(%d) is illegal", itti_msg.assoc_id);
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal",
itti_msg.assoc_id);
return;
}
gc = assoc_id_2_gnb_context(itti_msg.assoc_id);
......@@ -1060,9 +1059,8 @@ void amf_n2::handle_itti_message(itti_handover_request_Ack& itti_msg) {
cout << list[0].handoverRequestAcknowledgeTransfer.buf << endl;
cout << list[0].handoverRequestAcknowledgeTransfer.size << endl;
memcpy(
buf, list[0].handoverRequestAcknowledgeTransfer.buf,
list[0].handoverRequestAcknowledgeTransfer.size);
memcpy(buf, list[0].handoverRequestAcknowledgeTransfer.buf,
list[0].handoverRequestAcknowledgeTransfer.size);
if (!PDUHandoverRequestAckTransfer->decodefromHandoverRequestAckTransfer(
buf, list[0].handoverRequestAcknowledgeTransfer.size)) {
cout << "decode handoverrequestacktransfer error" << endl;
......@@ -1083,7 +1081,7 @@ void amf_n2::handle_itti_message(itti_handover_request_Ack& itti_msg) {
QosFlowWithDataForwardinglist);
long qosflowidentifiervalue;
qosflowidentifiervalue =
(long) QosFlowWithDataForwardinglist[0].qosFlowIdentifier;
(long)QosFlowWithDataForwardinglist[0].qosFlowIdentifier;
cout << "QFI get is " << qosflowidentifiervalue << endl;
/**************************add-end**************************/
......@@ -1148,7 +1146,6 @@ void amf_n2::handle_itti_message(itti_handover_request_Ack& itti_msg) {
unc = ran_ue_id_2_ue_ngap_context(ran_id_Global);
unc.get()->gnb_assoc_id = source_assoc_id;
}
// std::shared_ptr<ue_ngap_context> ngc =
// ran_ue_id_2_ue_ngap_context(nc.get()->ran_ue_ngap_id);
// std::shared_ptr<ue_ngap_context> ngc =
......@@ -1160,17 +1157,17 @@ void amf_n2::handle_itti_message(itti_handover_request_Ack& itti_msg) {
//------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_handover_notify& itti_msg) {
unsigned long amf_ue_ngap_id = itti_msg.handovernotify->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.handovernotify->getRanUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.handovernotify->getRanUeNgapId();
Logger::amf_n2().error(
"handover notify ran_ue_ngap_id(0x%d) amf_ue_ngap_id(%d)", ran_ue_ngap_id,
amf_ue_ngap_id);
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error(
"gnb with assoc_id(%d) is illegal", itti_msg.assoc_id);
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal",
itti_msg.assoc_id);
return;
}
NrCgi_t NR_CGI = {};
Tai_t TAI = {};
Tai_t TAI = {};
if (!itti_msg.handovernotify->getUserLocationInfoNR(NR_CGI, TAI)) {
Logger::amf_n2().debug("Missing IE UserLocationInformationNR");
return;
......@@ -1219,37 +1216,37 @@ void amf_n2::handle_itti_message(itti_handover_notify& itti_msg) {
//------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_uplinkranstatsutransfer& itti_msg) {
unsigned long amf_ue_ngap_id = itti_msg.uplinkrantransfer->getAmfUeNgapId();
Logger::amf_n2().error(
"uplinkranstatustransfer amf_ue_ngap_id(%d)", amf_ue_ngap_id);
Logger::amf_n2().error("uplinkranstatustransfer amf_ue_ngap_id(%d)",
amf_ue_ngap_id);
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error(
"gnb with assoc_id(%d) is illegal", itti_msg.assoc_id);
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal",
itti_msg.assoc_id);
return;
}
RANStatusTransferTransparentContainer* ran_status_transfer =
(RANStatusTransferTransparentContainer*) calloc(
(RANStatusTransferTransparentContainer*)calloc(
1, sizeof(RANStatusTransferTransparentContainer));
itti_msg.uplinkrantransfer->getRANStatusTransfer_TransparentContainer(
ran_status_transfer);
dRBSubjectList* amf_m_list =
(dRBSubjectList*) calloc(1, sizeof(dRBSubjectList));
(dRBSubjectList*)calloc(1, sizeof(dRBSubjectList));
ran_status_transfer->getdRBSubject_list(amf_m_list);
dRBSubjectItem* amf_m_item =
(dRBSubjectItem*) calloc(1, sizeof(dRBSubjectItem));
(dRBSubjectItem*)calloc(1, sizeof(dRBSubjectItem));
int numofitem = 0;
amf_m_list->getdRBSubjectItem(amf_m_item, numofitem);
dRBStatusDL* amf_DL = (dRBStatusDL*) calloc(1, sizeof(dRBStatusDL));
dRBStatusUL* amf_UL = (dRBStatusUL*) calloc(1, sizeof(dRBStatusUL));
Ngap_DRB_ID_t* amf_dRB_id = (Ngap_DRB_ID_t*) calloc(1, sizeof(Ngap_DRB_ID_t));
dRBStatusDL* amf_DL = (dRBStatusDL*)calloc(1, sizeof(dRBStatusDL));
dRBStatusUL* amf_UL = (dRBStatusUL*)calloc(1, sizeof(dRBStatusUL));
Ngap_DRB_ID_t* amf_dRB_id = (Ngap_DRB_ID_t*)calloc(1, sizeof(Ngap_DRB_ID_t));
amf_m_item->getdRBSubjectItem(amf_dRB_id, amf_UL, amf_DL);
dRBStatusUL18* UL18 = (dRBStatusUL18*) calloc(1, sizeof(dRBStatusUL18));
DRBStatusDL18* DL18 = (DRBStatusDL18*) calloc(1, sizeof(DRBStatusDL18));
dRBStatusUL18* UL18 = (dRBStatusUL18*)calloc(1, sizeof(dRBStatusUL18));
DRBStatusDL18* DL18 = (DRBStatusDL18*)calloc(1, sizeof(DRBStatusDL18));
amf_DL->getDRBStatusDL18(DL18);
amf_UL->getdRBStatusUL(UL18);
COUNTValueForPDCP_SN18* amf_UL_value =
(COUNTValueForPDCP_SN18*) calloc(1, sizeof(COUNTValueForPDCP_SN18));
(COUNTValueForPDCP_SN18*)calloc(1, sizeof(COUNTValueForPDCP_SN18));
COUNTValueForPDCP_SN18* amf_DL_value =
(COUNTValueForPDCP_SN18*) calloc(1, sizeof(COUNTValueForPDCP_SN18));
(COUNTValueForPDCP_SN18*)calloc(1, sizeof(COUNTValueForPDCP_SN18));
UL18->getcountvalue(amf_UL_value);
DL18->getcountvalue(amf_DL_value);
long amf_ul_pdcp;
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -29,13 +29,13 @@
#ifndef _AMF_N2_H_
#define _AMF_N2_H_
#include "ngap_app.hpp"
#include "DownlinkRANStatusTransfer.hpp"
#include "HandoverCommandMsg.hpp"
#include "HandoverRequest.hpp"
#include "PduSessionResourceReleaseCommand.hpp"
#include "itti_msg_n2.hpp"
#include "ngap_app.hpp"
#include "ue_ngap_context.hpp"
#include "PduSessionResourceReleaseCommand.hpp"
#include "HandoverRequest.hpp"
#include "HandoverCommandMsg.hpp"
#include "DownlinkRANStatusTransfer.hpp"
#include "amf.hpp"
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -79,7 +79,7 @@ void statistics::display() {
"UE NGAP ID | AMF UE ID | PLMN |Cell ID|");
int i = 0;
for (auto const& ue : ue_infos) {
for (auto const &ue : ue_infos) {
Logger::amf_app().info(
"|%7d|%22s|%18s|%15s|%16d|%11d|%9s|%7d|", i + 1,
ue.second.registerStatus.c_str(), ue.second.imsi.c_str(),
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -29,8 +29,8 @@
#ifndef _STATISTICS_H_
#define _STATISTICS_H_
#include <vector>
#include <string>
#include <vector>
#include "amf.hpp"
#include "ngap_app.hpp"
......@@ -63,8 +63,8 @@ class statistics {
void display();
statistics();
~statistics();
void update_ue_info(const ue_info_t& ue_info);
void update_5gmm_state(const std::string& imsi, const std::string& state);
void update_ue_info(const ue_info_t &ue_info);
void update_5gmm_state(const std::string &imsi, const std::string &state);
public:
uint32_t gNB_connected;
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -26,9 +26,9 @@
\email: contact@openairinterface.org
*/
#include "amf_config.hpp"
#include "amf_n1.hpp"
#include "logger.hpp"
#include "amf_config.hpp"
using namespace amf_application;
using namespace config;
......@@ -38,9 +38,9 @@ extern amf_config amf_cfg;
//------------------------------------------------------------------------------
bool amf_n1::get_mysql_auth_info(
std::string imsi,
mysql_auth_info_t&
resp) { // openair-cn/tree/v0.5.0/src/oai_hss/db/db_connector.c
MYSQL_RES* res;
mysql_auth_info_t
&resp) { // openair-cn/tree/v0.5.0/src/oai_hss/db/db_connector.c
MYSQL_RES *res;
MYSQL_ROW row;
std::string query;
......@@ -88,7 +88,7 @@ bool amf_n1::get_mysql_auth_info(
//------------------------------------------------------------------------------
bool amf_n1::connect_to_mysql() {
const int mysql_reconnect_val = 1;
db_desc = (database_t*) calloc(1, sizeof(database_t));
db_desc = (database_t *)calloc(1, sizeof(database_t));
if (!db_desc) {
Logger::amf_n1().error(
"An error occurs when allocating memory for DB_DESC");
......@@ -130,8 +130,8 @@ void amf_n1::mysql_push_rand_sqn(
Logger::amf_n1().error("Need sqn and rand");
return;
}
sqn_decimal = ((uint64_t) sqn[0] << 40) | ((uint64_t) sqn[1] << 32) |
((uint64_t) sqn[2] << 24) | (sqn[3] << 16) | (sqn[4] << 8) |
sqn_decimal = ((uint64_t)sqn[0] << 40) | ((uint64_t)sqn[1] << 32) |
((uint64_t)sqn[2] << 24) | (sqn[3] << 16) | (sqn[4] << 8) |
sqn[5];
query_length = sprintf(query, "UPDATE `users` SET `rand`=UNHEX('");
for (int i = 0; i < RAND_LENGTH; i++) {
......
......@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -29,8 +29,8 @@
#ifndef _MYSQL_DB_HANDLERS_H_
#define _MYSQL_DB_HANDLERS_H_
#include <pthread.h>
#include <mysql/mysql.h>
#include <pthread.h>
#include <string>
#define KEY_LENGTH (16)
......@@ -45,7 +45,7 @@ typedef struct {
typedef struct {
// mysql reference connector object
MYSQL* db_conn;
MYSQL *db_conn;
std::string server;
std::string user;
std::string password;
......
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