Continuing to cleanup. Moved initial ue message to nas_transport

This commit is contained in:
Pedro Alvarez 2017-12-20 15:28:10 +00:00
parent 18f864d21d
commit d3e1e7d853
5 changed files with 132 additions and 76 deletions

View File

@ -92,8 +92,10 @@ public:
void print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx);
uint32_t get_plmn();
uint32_t get_next_mme_ue_s1ap_id();
enb_ctx_t* find_enb_ctx(uint16_t enb_id);
void add_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri);
void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri);
void add_new_ue_ctx(const ue_ctx_t &ue_ctx);
s1ap_args_t m_s1ap_args;
srslte::log_filter *m_s1ap_log;

View File

@ -30,6 +30,7 @@
#include "srslte/common/buffer_pool.h"
#include "mme/s1ap_common.h"
#include "srslte/asn1/gtpc.h"
#include "hss/hss.h"
namespace srsepc{
@ -42,7 +43,8 @@ public:
static void cleanup(void);
void init(void);
void set_log(srslte::log *s1ap_logger);
bool handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag);
bool unpack_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT *attach_req, LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT *pdn_con_req);
bool pack_authentication_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t next_mme_ue_s1ap_id, uint8_t *autn,uint8_t *rand);
bool pack_authentication_reject(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id);
@ -63,8 +65,8 @@ private:
srslte::log *m_s1ap_log;
srslte::byte_buffer_pool *m_pool;
s1ap* m_parent;
s1ap* m_s1ap;
hss* m_hss;
};
} //namespace srsepc

View File

@ -264,7 +264,8 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru
break;
case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_INITIALUEMESSAGE:
m_s1ap_log->info("Received Initial UE Message.\n");
return handle_initial_ue_message(&msg->choice.InitialUEMessage, enb_sri);
m_s1ap_nas_transport->handle_initial_ue_message(&msg->choice.InitialUEMessage, enb_sri, reply_buffer, &reply_flag);
break;
case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UPLINKNASTRANSPORT:
m_s1ap_log->info("Received Uplink NAS Transport Message.\n");
return handle_uplink_nas_transport(&msg->choice.UplinkNASTransport, enb_sri);
@ -302,66 +303,6 @@ s1ap::handle_successful_outcome(LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *msg)
return true;
}
/*
bool
s1ap::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri)
{
std::string mnc_str, mcc_str;
enb_ctx_t enb_ctx;
srslte::byte_buffer_t reply_msg;
LIBLTE_S1AP_S1AP_PDU_STRUCT reply_pdu;
if(!m_s1ap_mngmt_proc->unpack_s1_setup_request(msg, &enb_ctx))
{
m_s1ap_log->error("Malformed S1 Setup Request\n");
return false;
}
//Log S1 Setup Request Info
m_s1ap_log->console("Received S1 Setup Request. Association: %d\n",enb_sri->sinfo_assoc_id);
print_enb_ctx_info(enb_ctx);
//Check matching PLMNs
if(enb_ctx.plmn!=m_plmn){
m_s1ap_log->console("Sending S1 Setup Failure - Unkown PLMN\n");
m_s1ap_log->info("Sending S1 Setup Failure - Unkown PLMN\n");
m_s1ap_mngmt_proc->pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_UNKNOWN_PLMN,&reply_msg);
}
else{
std::map<uint16_t,enb_ctx_t*>::iterator it = m_active_enbs.find(enb_ctx.enb_id);
if(it != m_active_enbs.end())
{
//eNB already registered
//TODO replace enb_ctx
}
else
{
//new eNB
std::set<uint32_t> ue_set;
enb_ctx_t *enb_ptr = new enb_ctx_t;
memcpy(enb_ptr,&enb_ctx,sizeof(enb_ctx));
m_active_enbs.insert(std::pair<uint16_t,enb_ctx_t*>(enb_ptr->enb_id,enb_ptr));
m_sctp_to_enb_id.insert(std::pair<int32_t,uint16_t>(enb_sri->sinfo_assoc_id, enb_ptr->enb_id));
m_enb_id_to_ue_ids.insert(std::pair<uint16_t,std::set<uint32_t> >(enb_ptr->enb_id,ue_set));
}
m_s1ap_mngmt_proc->pack_s1_setup_response(m_s1ap_args, &reply_msg);
m_s1ap_log->console("Sending S1 Setup Response\n");
m_s1ap_log->info("Sending S1 Setup Response\n");
}
//Send Reply to eNB
ssize_t n_sent = sctp_send(m_s1mme,reply_msg.msg, reply_msg.N_bytes, enb_sri, 0);
if(n_sent == -1)
{
m_s1ap_log->console("Failed to send S1 Setup Setup Reply");
return false;
}
return true;
}
*/
bool
s1ap::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri)
{
@ -438,10 +379,8 @@ s1ap::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *ini
ue_ctx.erabs_ctx[i].erab_id = i;
}
printf("UL NAS count %d\n", ue_ctx.security_ctxt.ul_nas_count);
ue_ctx_t *ue_ptr = new ue_ctx_t;
memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx));
printf("UL NAS count %d\n",(int) ue_ptr->security_ctxt.ul_nas_count);
m_active_ues.insert(std::pair<uint32_t,ue_ctx_t*>(ue_ptr->mme_ue_s1ap_id,ue_ptr));
std::map<int32_t,uint16_t>::iterator it_enb = m_sctp_to_enb_id.find(enb_sri->sinfo_assoc_id);
@ -1042,7 +981,7 @@ s1ap::find_enb_ctx(uint16_t enb_id)
}
void
s1ap::add_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo *enb_sri)
s1ap::add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo *enb_sri)
{
m_s1ap_log->info("Adding new eNB context. eNB ID %d\n", enb_ctx.enb_id);
std::set<uint32_t> ue_set;
@ -1051,6 +990,33 @@ s1ap::add_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo *enb_sr
m_active_enbs.insert(std::pair<uint16_t,enb_ctx_t*>(enb_ptr->enb_id,enb_ptr));
m_sctp_to_enb_id.insert(std::pair<int32_t,uint16_t>(enb_sri->sinfo_assoc_id, enb_ptr->enb_id));
m_enb_id_to_ue_ids.insert(std::pair<uint16_t,std::set<uint32_t> >(enb_ptr->enb_id,ue_set));
return;
}
void
s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx)
{
ue_ctx_t *ue_ptr = new ue_ctx_t;
memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx));
m_active_ues.insert(std::pair<uint32_t,ue_ctx_t*>(ue_ptr->mme_ue_s1ap_id,ue_ptr));
std::map<int32_t,uint16_t>::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id);
uint16_t enb_id = it_enb->second;
std::map<uint16_t,std::set<uint32_t> >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id);
if(it_ue_id==m_enb_id_to_ue_ids.end())
{
m_s1ap_log->error("Could not find eNB's UEs\n");
return;
}
it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id);
return;
}
uint32_t
s1ap::get_next_mme_ue_s1ap_id()
{
return m_next_mme_ue_s1ap_id++;
}
void

View File

@ -86,7 +86,7 @@ s1ap_mngmt_proc::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRU
}
//Log S1 Setup Request Info
m_s1ap_log->console("Received S1 Setup Request.");
m_s1ap_log->console("Received S1 Setup Request.\n");
m_s1ap->print_enb_ctx_info(std::string("S1 Setup Request"),enb_ctx);
//Check matching PLMNs
@ -106,7 +106,7 @@ s1ap_mngmt_proc::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRU
else
{
//new eNB
m_s1ap->add_enb_ctx(enb_ctx,enb_sri);
m_s1ap->add_new_enb_ctx(enb_ctx,enb_sri);
}
pack_s1_setup_response(m_s1ap_args, reply_buffer);

View File

@ -66,19 +66,105 @@ s1ap_nas_transport::cleanup(void)
void
s1ap_nas_transport::init(void)
{
m_parent = s1ap::get_instance();
m_s1ap_log = m_parent->m_s1ap_log;
m_s1ap = s1ap::get_instance();
m_s1ap_log = m_s1ap->m_s1ap_log;
m_pool = srslte::byte_buffer_pool::get_instance();
m_hss = hss::get_instance();
}
void
s1ap_nas_transport::set_log(srslte::log *s1ap_log)
bool
s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag)
{
m_s1ap_log=s1ap_log;
return;
LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT attach_req;
LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT pdn_con_req;
uint64_t imsi;
uint8_t k_asme[32];
uint8_t autn[16];
uint8_t rand[6];
uint8_t xres[8];
ue_ctx_t ue_ctx;
m_s1ap_log->console("Received Initial UE Message.\n");
m_s1ap_log->info("Received Initial UE Message.\n");
//Get info from initial UE message
ue_ctx.enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID;
//Log unhandled Initial UE message IEs
log_unhandled_initial_ue_message_ies(init_ue);
//Get NAS Attach Request and PDN connectivity request messages
if(!unpack_initial_ue_message(init_ue, &attach_req,&pdn_con_req))
{
//Could not decode the attach request and the PDN connectivity request.
m_s1ap_log->error("Could not unpack NAS Attach Request and PDN connectivity request.\n");
return false;
}
//Get IMSI
imsi = 0;
for(int i=0;i<=14;i++){
imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i);
}
m_s1ap_log->console("Attach request from IMSI: %015lu\n", imsi);
m_s1ap_log->info("Attach request from IMSI: %015lu\n", imsi);
//Get UE network capabilities
memcpy(&ue_ctx.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT));
ue_ctx.ms_network_cap_present = attach_req.ms_network_cap_present;
if(attach_req.ms_network_cap_present)
{
memcpy(&ue_ctx.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT));
}
//FIXME use this info
uint8_t eps_bearer_id = pdn_con_req.eps_bearer_id; //TODO: Unused
ue_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id;
//Save whether ESM information transfer is necessary
ue_ctx.eit = pdn_con_req.esm_info_transfer_flag_present;
m_s1ap_log->console("EPS Bearer id: %d\n", eps_bearer_id);
//Initialize NAS count
ue_ctx.security_ctxt.ul_nas_count = 0;
ue_ctx.security_ctxt.dl_nas_count = 0;
//Add eNB info to UE ctxt
memcpy(&ue_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo));
//Get Authentication Vectors from HSS
if(!m_hss->gen_auth_info_answer(imsi, ue_ctx.security_ctxt.k_asme, autn, rand, ue_ctx.security_ctxt.xres))
{
m_s1ap_log->console("User not found. IMSI %015lu\n",imsi);
m_s1ap_log->info("User not found. IMSI %015lu\n",imsi);
return false;
}
//Save UE context
ue_ctx.imsi = imsi;
ue_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id();
for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++)
{
ue_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED;
ue_ctx.erabs_ctx[i].erab_id = i;
}
m_s1ap->add_new_ue_ctx(ue_ctx);
//Pack NAS Authentication Request in Downlink NAS Transport msg
pack_authentication_request(reply_buffer, ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id, autn, rand);
//Send reply to eNB
*reply_flag = true;
m_s1ap_log->info("DL NAS: Sent Athentication Request\n");
//TODO Start T3460 Timer!
return true;
}
/*Packing/Unpacking helper functions*/
bool
s1ap_nas_transport::unpack_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue,
LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT *attach_req,