Commit fec5f8fd authored by Niuhaiwen's avatar Niuhaiwen

stateless-procedure-code-available

parent 8866f3e9
......@@ -143,6 +143,26 @@ amf_n1::~amf_n1() {}
void amf_n1::handle_itti_message(itti_downlink_nas_transfer &itti_msg) {
long amf_ue_ngap_id = itti_msg.amf_ue_ngap_id;
uint32_t ran_ue_ngap_id = itti_msg.ran_ue_ngap_id;
std::shared_ptr<nas_context> nc;
Logger::amf_n1().debug("try to get sequence_number");
nlohmann::json udsf_response;
std::string record_id = "amf_ue_ngap_id=\'" + to_string(amf_ue_ngap_id) + "\'";
std::string udsf_url = "http://10.103.239.53:7123/nudsf-dr/v1/amfdata/"+ std::string("nas_context/records/") + record_id;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_n1().debug("No existing nas_context from UDSF using amf_ue_ngap_id (%d) ...", amf_ue_ngap_id);
}else if(udsf_response.dump().length()<8){
Logger::amf_n1().debug("No existing nas_context from UDSF using amf_ue_ngap_id (%d) .....", amf_ue_ngap_id);
}else{
Logger::amf_n1().debug("udsf_response %s",udsf_response.dump().c_str());
nc = std::shared_ptr<nas_context>(new nas_context());
nc.get()->nas_context_from_json(udsf_response);
set_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id, nc);
Logger::amf_n1().debug("GET nas_context (%p) from UDSF using amf_ue_ngap_id (%d) .....", nc.get(), amf_ue_ngap_id);
}
#if 0
std::shared_ptr<nas_context> nc;
if (is_amf_ue_id_2_nas_context(amf_ue_ngap_id))
nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
......@@ -151,7 +171,10 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer &itti_msg) {
amf_ue_ngap_id);
return;
}
#endif
nas_secu_ctx *secu = nc.get()->security_ctx;
print_buffer("amf_n1","dukl kas_int:",secu->knas_int, 16);
Logger::amf_n1().debug("dukl dl.seq %d", secu->dl_count.seq_num);
bstring protected_nas;
encode_nas_message_protected(secu, false, INTEGRITY_PROTECTED_AND_CIPHERED,
NAS_MESSAGE_DOWNLINK,
......@@ -2787,6 +2810,7 @@ bool amf_n1::start_authentication_procedure(std::shared_ptr<nas_context> nc,
//Update nas_context into UDSF
http_update_nas_context_into_udsf(nc);
Logger::amf_n1().debug("dukl start_authentication_procedure dl.seq %d",nc.get()->security_ctx->dl_count.seq_num);
itti_send_dl_nas_buffer_to_task_n2(b, nc.get()->ran_ue_ngap_id,
nc.get()->amf_ue_ngap_id);
......@@ -3061,6 +3085,7 @@ bool amf_n1::start_security_mode_control_procedure(
Authentication_5gaka::derive_knas(
NAS_ENC_ALG, secu_ctx->nas_algs.encryption,
nc.get()->kamf[secu_ctx->vector_pointer], secu_ctx->knas_enc);
print_buffer("amf_n1","dukl in SMC, Knas_int", secu_ctx->knas_int, 16);
security_context_is_new = true;
nc.get()->is_current_security_available = true;
#if 0
......@@ -3143,6 +3168,7 @@ bool amf_n1::start_security_mode_control_procedure(
nc.get()->amf_ue_ngap_id);
// secu_ctx->dl_count.seq_num ++;
http_update_nas_context_into_udsf(nc);
Logger::amf_n1().debug("dukl security_mode_command dl.seq %d",nc.get()->security_ctx->dl_count.seq_num);
return true;
}
......@@ -3334,6 +3360,10 @@ void amf_n1::security_mode_complete_handle(uint32_t ran_ue_ngap_id,
itti_msg->nas = protectedNas;
itti_msg->is_sr = false; // TODO: for Setup Request procedure
http_update_nas_context_into_udsf(nc);
Logger::amf_n1().debug("dukl security mode complete dl.seq %d",nc.get()->security_ctx->dl_count.seq_num);
#if 0
/****************************hsx add*****************************/
std::string udsf_url = "http://10.28.234.76:7123/nudsf-dr/v1/amfdata/" + std::string("nas_context/records/") + to_string(nc.get()->amf_ue_ngap_id) ;
nlohmann::json udsf_response;
......@@ -3344,7 +3374,7 @@ void amf_n1::security_mode_complete_handle(uint32_t ran_ue_ngap_id,
amf_n2_inst->curl_http_client_udsf(udsf_url,udsf_nas_context.dump(),"PUT",udsf_response);
/****************************hsx add*****************************/
#endif
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);
......@@ -3410,7 +3440,7 @@ void amf_n1::registration_complete_handle(uint32_t ran_ue_ngap_id,
}
nas_secu_ctx *secu = nc.get()->security_ctx;
#if 0
//向UDSF 同步全部NAS消息
/********************** hxs add *******************************/
string auts;
......@@ -3668,10 +3698,13 @@ void amf_n1::registration_complete_handle(uint32_t ran_ue_ngap_id,
amf_n2_inst->curl_http_client_udsf(udsf_url,udsf_nas_context.dump(),"PUT",udsf_response);
/********************** hxs add *******************************/
#endif
// protect nas message
bstring protectedNas;
encode_nas_message_protected(secu, false, INTEGRITY_PROTECTED_AND_CIPHERED,
NAS_MESSAGE_DOWNLINK, conf, 45, protectedNas);
http_update_nas_context_into_udsf(nc);
Logger::amf_n1().debug("dukl registration complete complete dl.seq %d",nc.get()->security_ctx->dl_count.seq_num);
itti_send_dl_nas_buffer_to_task_n2(protectedNas, ran_ue_ngap_id,
amf_ue_ngap_id);
......@@ -4565,7 +4598,7 @@ void amf_n1::http_update_nas_context_into_udsf(std::shared_ptr<nas_context> nc){
{{"Content-ID", "is_common_procedure_for_nas_transport_running"},{"Content-Type", "varchar(32)"},{"content", to_string(nc.get()->is_common_procedure_for_nas_transport_running)}},
{{"Content-ID", "Href"},{"Content-Type", "varchar(1024)"},{"content", nc.get()->Href}},
//{{"Content-ID", "is_current_security_available"},{"Content-Type", "varchar(32)"},{"content", to_string(nc.get()->is_current_security_available)}},
{{"Content-ID", "is_current_security_available"},{"Content-Type", "varchar(32)"},{"content", to_string(nc.get()->is_current_security_available)}},
{{"Content-ID", "registration_attempt_counter"},{"Content-Type", "varchar(32)"},{"content", to_string(nc.get()->registration_attempt_counter)}},
{{"Content-ID", "is_imsi_present"},{"Content-Type", "varchar(32)"},{"content", to_string(nc.get()->is_imsi_present)}},
......
......@@ -529,7 +529,7 @@ bool amf_n2::curl_http_client_udsf(std::string remoteUrl,std::string jsonData,st
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
std::string response = *httpData.get();
Logger::amf_n2().debug("response from udsf =(%d) %s ",response.length(),response.c_str());
//Logger::amf_n2().debug("response from udsf =(%d) %s ",response.length(),response.c_str());
nlohmann::json response_data = {};
Logger::amf_n2().debug("Send message to UDSF, response from UDSF, HTTP Code: %d", httpCode);
if (static_cast<http_response_codes_e>(httpCode) ==http_response_codes_e::HTTP_RESPONSE_CODE_0) {
......@@ -545,7 +545,7 @@ bool amf_n2::curl_http_client_udsf(std::string remoteUrl,std::string jsonData,st
try {
//response_data = nlohmann::json::parse(response);
udsf_response = nlohmann::json::parse(response);
Logger::amf_n2().debug("UDSF RESPONSE in curl_http_client_udsf:\n %s", udsf_response.dump().c_str());
//Logger::amf_n2().debug("UDSF RESPONSE in curl_http_client_udsf:\n %s", udsf_response.dump().c_str());
//Logger::amf_n2().debug("Get response with jsonData: %s", response_data.dump().c_str());
} catch (nlohmann::json::exception &e) {
Logger::amf_n11().warn("Could not get Json content from usdf the response");
......
......@@ -248,7 +248,7 @@ void nas_context::nas_context_security_ctx_from_json(nlohmann::json j)
s = it_security_ctx->at("spare");
security_ctx_udsf.dl_count.spare = atoi(s.c_str());
i++;
//printf("---------security_ctx_udsf-------%x\n",security_ctx_udsf.dl_count.seq_num);
printf("---------security_ctx_udsf-------%x\n",security_ctx_udsf.dl_count.seq_num);
}
if(it_security_ctx->at("Content-ID") == "nas_algs")
{
......@@ -376,7 +376,7 @@ void nas_context::nas_context_kamf_from_json(nlohmann::json j)
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get_value nas_context_security_ctx_from_json from json kamf is error");
Logger::amf_server().error("get_value nas_context_kamf_from_jsons from json kamf is error");
}
bool nas_context::nas_context_is_stacs_available_from_json(nlohmann::json j)
......@@ -398,7 +398,7 @@ bool nas_context::nas_context_is_stacs_available_from_json(nlohmann::json j)
Logger::amf_server().error("get_value nas_context_is_stacs_available_from_json from json is error");
}
/*int nas_context::nas_context__5gmm_state_from_json(nlohmann::json j)
int nas_context::nas_context__5gmm_state_from_json(nlohmann::json j)
{
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
......@@ -414,8 +414,8 @@ bool nas_context::nas_context_is_stacs_available_from_json(nlohmann::json j)
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get value from json is error");
}*/
Logger::amf_server().error("get value nas_context__5gmm_state_from_json from json is error");
}
uint8_t nas_context::nas_context_registration_type_from_json(nlohmann::json j)
......@@ -943,9 +943,139 @@ std::string nas_context::nas_context_guti_from_json(nlohmann::json j)
}
// void nas_context__vector_from_json(nlohmann::json j);
void nas_context::nas_context__vector_from_json(nlohmann::json j)
{
printf("------------nas_context__vector_from_json----\n");
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
std::set<nlohmann::json> block_set = record.getBlocks();
std::set<nlohmann::json>::iterator it_block;
for(it_block=block_set.begin();it_block!=block_set.end();)
{
if(it_block->at("Content-ID") == "_vector")
{
auc_vector_t _vector_udsf;
//string s;
nlohmann::json j;
int i=0;
std::set<nlohmann::json> _vector_set ;
if(it_block->find("content")!=it_block->end())
{
it_block->at("content").get_to(_vector_set);
}
std::set<nlohmann::json>::iterator it_security_ctx;
for(it_security_ctx=_vector_set.begin();it_security_ctx!=_vector_set.end();)
{
string s;
s = it_security_ctx->at("rand_new");
_vector_udsf.rand_new = atoi(s.c_str());
i++;
s = it_security_ctx->at("rand");
std::memcpy(_vector_udsf.rand, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<16;uu++)
printf("-----------rand----uint8---%x\n",_vector_udsf.rand[uu]);
i++;
s = it_security_ctx->at("xres");
std::memcpy(_vector_udsf.xres, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<16;uu++)
printf("-----------xres----uint8---%x\n",_vector_udsf.xres[uu]);
i++;
s = it_security_ctx->at("autn");
std::memcpy(_vector_udsf.autn, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<16;uu++)
printf("-----------autn----uint8---%x\n",_vector_udsf.autn[uu]);
i++;
s = it_security_ctx->at("kasme");
std::memcpy(_vector_udsf.kasme, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<32;uu++)
printf("-----------kasme----uint8---%x\n",_vector_udsf.kasme[uu]);
i++;
if(i==5)
{
return ;
}
_vector_set.erase(it_security_ctx++);
}
Logger::amf_server().error("get_value from json is error 000000000");
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get_value nas_context__vector_from_json from json is error");
}
// void nas_context__5g_he_av_from_json(nlohmann::json j);
// void nas_context__5g_av_from_json(nlohmann::json j);
void nas_context::nas_context__5g_av_from_json(nlohmann::json j)
{
printf("------------nas_context__5g_av_from_json----\n");
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
std::set<nlohmann::json> block_set = record.getBlocks();
std::set<nlohmann::json>::iterator it_block;
for(it_block=block_set.begin();it_block!=block_set.end();)
{
if(it_block->at("Content-ID") == "_5g_av")
{
_5G_AV_t _5g_av_udsf;
//string s;
nlohmann::json j;
int i=0;
std::set<nlohmann::json> _5g_av_set ;
if(it_block->find("content")!=it_block->end())
{
it_block->at("content").get_to(_5g_av_set);
}
std::set<nlohmann::json>::iterator it_security_ctx;
for(it_security_ctx=_5g_av_set.begin();it_security_ctx!=_5g_av_set.end();)
{
string s;
s = it_security_ctx->at("avType");
_5g_av_udsf.avType = atoi(s.c_str());
i++;
s = it_security_ctx->at("rand");
std::memcpy(_5g_av_udsf.rand, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<16;uu++)
printf("-----------rand----uint8---%x\n",_5g_av_udsf.rand[uu]);
i++;
s = it_security_ctx->at("hxres");
std::memcpy(_5g_av_udsf.hxres, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<16;uu++)
printf("-----------hxres----uint8---%x\n",_5g_av_udsf.hxres[uu]);
i++;
s = it_security_ctx->at("hxresStar");
std::memcpy(_5g_av_udsf.hxresStar, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<16;uu++)
printf("-----------hxresStar----uint8---%x\n",_5g_av_udsf.hxresStar[uu]);
i++;
s = it_security_ctx->at("autn");
std::memcpy(_5g_av_udsf.autn, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<16;uu++)
printf("-----------autn----uint8---%x\n",_5g_av_udsf.autn[uu]);
i++;
s = it_security_ctx->at("kseaf");
std::memcpy(_5g_av_udsf.kseaf, format_string_as_hex(s),s.length()/2+1);
for(int uu=0;uu<32;uu++)
printf("-----------kseaf----uint8---%x\n",_5g_av_udsf.kseaf[uu]);
i++;
if(i==6)
{
return ;
}
_5g_av_set.erase(it_security_ctx++);
}
Logger::amf_server().error("get_value from json is error 000000000");
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get_value nas_context__5g_av_from_json from json is error");
}
// void nas_context__security_from_json(nlohmann::json j);
// void nas_context_security_ctx_from_json(nlohmann::json j);
// void nas_context_requestedNssai_from_json(nlohmann::json j);
......@@ -976,22 +1106,41 @@ bool nas_context::nas_context_from_json(nlohmann::json j)
//nas_context_requestedNssai_from_json( j);
serving_network = nas_context_serving_network_from_json(j);
nas_context_auts_from_json(j);
Logger::amf_n1().debug("------------------------1 --------------------------");
is_specific_procedure_for_registration_running = nas_context_is_specific_procedure_for_registration_running_from_json(j);
Logger::amf_n1().debug("------------------------2 --------------------------");
is_specific_procedure_for_deregistration_running = nas_context_is_specific_procedure_for_deregistration_running_from_json(j);
Logger::amf_n1().debug("------------------------3 --------------------------");
is_specific_procedure_for_eCell_inactivity_running = nas_context_is_specific_procedure_for_eCell_inactivity_running_from_json(j);
Logger::amf_n1().debug("------------------------4 --------------------------");
is_common_procedure_for_authentication_running = nas_context_is_common_procedure_for_authentication_running_from_json(j);
Logger::amf_n1().debug("------------------------5 --------------------------");
is_common_procedure_for_identification_running = nas_context_is_common_procedure_for_identification_running_from_json(j);
Logger::amf_n1().debug("------------------------6 --------------------------");
//is_common_procedure_for_security_mode_control_running = nas_context_is_common_procedure_for_security_mode_control_running_from_json(j);
Logger::amf_n1().debug("------------------------7 --------------------------");
is_common_procedure_for_nas_transport_running = nas_context_is_common_procedure_for_nas_transport_running_from_json(j);
Logger::amf_n1().debug("------------------------8 --------------------------");
Logger::amf_n1().debug("------------------------9 --------------------------");
Href = nas_context_Href_from_json(j);
Logger::amf_n1().debug("------------------------10 --------------------------");
//kamf = nas_context_kamf_from_json(j);
Logger::amf_n1().debug("------------------------11 --------------------------");
is_current_security_available = nas_context_is_current_security_available_from_json(j);
Logger::amf_n1().debug("------------------------12 --------------------------");
nas_context__vector_from_json(j);
Logger::amf_n1().debug("------------------------13 --------------------------");
nas_context__5g_av_from_json(j);
Logger::amf_n1().debug("------------------------14 --------------------------");
nas_context_security_ctx_from_json(j);
nas_context_kamf_from_json(j);
Logger::amf_n1().debug("------------------------15 --------------------------");
nas_context_kamf_from_json(j);
registration_attempt_counter = nas_context_registration_attempt_counter_from_json(j);
is_imsi_present = nas_context_is_imsi_present_from_json(j);
return true;
}
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