diff --git a/srsepc/hdr/mme/nas.h b/srsepc/hdr/mme/nas.h index 0aefc407b..cfdbb6d8a 100644 --- a/srsepc/hdr/mme/nas.h +++ b/srsepc/hdr/mme/nas.h @@ -188,11 +188,11 @@ public: bool integrity_check( emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); bool short_integrity_check( emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); -private: + /* UE Context*/ emm_ctx_t m_emm_ctx; ecm_ctx_t m_ecm_ctx; esm_ctx_t m_esm_ctx[MAX_ERABS_PER_UE]; - sec_ctx_t sec_ctx; + sec_ctx_t m_sec_ctx; }; }//namespace diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index a61a9de02..8c4995b53 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -47,7 +47,7 @@ public: void init(void); - bool send_initial_context_setup_request(nas *nas_ctx); + bool send_initial_context_setup_request(nas *nas_ctx, uint16_t erab_to_setup); bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); bool handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool send_ue_context_release_command(ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer); diff --git a/srsepc/src/mme/nas.cc b/srsepc/src/mme/nas.cc index 93984e777..31cc8c6e2 100644 --- a/srsepc/src/mme/nas.cc +++ b/srsepc/src/mme/nas.cc @@ -100,7 +100,7 @@ nas::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, struct sctp_sndrcvinfo *enb_sri) { uint8_t k_asme[32]; - uint8_t autn[16]; + uint8_t autn[16]; uint8_t rand[16]; uint8_t xres[8]; @@ -114,7 +114,7 @@ nas::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); } - //Check if UE is + //Check if UE is already atached ue_ctx_t *old_ctx = m_s1ap->find_ue_ctx_from_imsi(imsi); if(old_ctx!=NULL) { @@ -227,13 +227,13 @@ nas::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, } bool -s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, - const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, - const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, - srslte::byte_buffer_t *nas_msg, - srslte::byte_buffer_t *reply_buffer, - bool* reply_flag, - struct sctp_sndrcvinfo *enb_sri) +nas::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri) { //Parse the message security header uint8 pd = 0; @@ -1301,14 +1301,14 @@ nas::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t * dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; - //Pack NAS PDU + //Pack NAS PDU LIBLTE_MME_SECURITY_MODE_COMMAND_MSG_STRUCT sm_cmd; - + sm_cmd.selected_nas_sec_algs.type_of_eea = LIBLTE_MME_TYPE_OF_CIPHERING_ALGORITHM_EEA0; sm_cmd.selected_nas_sec_algs.type_of_eia = LIBLTE_MME_TYPE_OF_INTEGRITY_ALGORITHM_128_EIA1; sm_cmd.nas_ksi.tsc_flag=LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; - sm_cmd.nas_ksi.nas_ksi=ue_emm_ctx->security_ctxt.eksi; + sm_cmd.nas_ksi.nas_ksi=ue_emm_ctx->security_ctxt.eksi; //Replay UE security cap memcpy(sm_cmd.ue_security_cap.eea,ue_emm_ctx->security_ctxt.ue_network_cap.eea,8*sizeof(bool)); @@ -1358,7 +1358,7 @@ nas::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t * &nas_buffer->msg[5], nas_buffer->N_bytes - 5, mac - ); + ); memcpy(&nas_buffer->msg[1],mac,4); //Copy NAS PDU to Downlink NAS Trasport message buffer @@ -1378,7 +1378,7 @@ nas::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t * } bool -s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx) +nas::pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); @@ -1409,8 +1409,7 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms ue_emm_ctx->security_ctxt.dl_nas_count++; LIBLTE_ERROR_ENUM err = srslte_mme_pack_esm_information_request_msg(&esm_info_req, sec_hdr_type,ue_emm_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); - if(err != LIBLTE_SUCCESS) - { + if (err != LIBLTE_SUCCESS) { m_s1ap_log->error("Error packing ESM information request\n"); m_s1ap_log->console("Error packing ESM information request\n"); return false; @@ -1427,7 +1426,7 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms ); memcpy(&nas_buffer->msg[1],mac,4); - + //Copy NAS PDU to Downlink NAS Trasport message buffer memcpy(dw_nas->NAS_PDU.buffer, nas_buffer->msg, nas_buffer->N_bytes); dw_nas->NAS_PDU.n_octets = nas_buffer->N_bytes; @@ -1446,12 +1445,11 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms } bool -s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer) { +nas::pack_attach_accept(LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer) +{ + m_nas_log->info("Packing Attach Accept\n"); LIBLTE_MME_ATTACH_ACCEPT_MSG_STRUCT attach_accept; LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT act_def_eps_bearer_context_req; - //bzero(&act_def_eps_bearer_context_req,sizeof(LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT)); - - m_s1ap_log->info("Packing Attach Accept\n"); //Get decimal MCC and MNC uint32_t mcc = 0; diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 2b79b5e1a..41aa28856 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -79,7 +79,7 @@ s1ap_ctx_mngmt_proc::init(void) } bool -s1ap_ctx_mngmt_proc::send_initial_context_setup_request(nas *nas_ctx) +s1ap_ctx_mngmt_proc::send_initial_context_setup_request(nas *nas_ctx, uint16_t erab_to_setup) { //Prepare reply PDU LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; @@ -93,6 +93,12 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(nas *nas_ctx) LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT *in_ctxt_req = &init->choice.InitialContextSetupRequest; m_s1ap_log->info("Preparing to send Initial Context Setup request\n"); + //Get UE Context/E-RAB Context to setup + emm_ctx_t *emm_ctx = &nas_ctx->m_emm_ctx; + ecm_ctx_t *ecm_ctx = &nas_ctx->m_ecm_ctx; + esm_ctx_t *esm_ctx = &nas_ctx->m_esm_ctx[erab_to_setup]; + sec_ctx_t *sec_ctx = &nas_ctx->m_sec_ctx; + //Add MME and eNB S1AP Ids in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ecm_ctx->mme_ue_s1ap_id; in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ecm_ctx->enb_ue_s1ap_id; @@ -148,7 +154,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(nas *nas_ctx) //Attach procedure initiated from an attach request m_s1ap_log->console("Adding attach accept to Initial Context Setup Request\n"); m_s1ap_log->info("Adding attach accept to Initial Context Setup Request\n"); - nas_ctx->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctx_req, &erab_ctx->pdn_addr_alloc, nas_buffer); + nas_ctx->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctx_req, &esm_ctx->pdn_addr_alloc, nas_buffer); } srslte::byte_buffer_t *reply_buffer = m_pool->allocate(); @@ -163,7 +169,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(nas *nas_ctx) } //Change E-RAB state to Context Setup Requested and save S-GW control F-TEID - ecm_ctx->erabs_ctx[erab_ctx_req->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; + esm_ctx->state = ERAB_CTX_REQUESTED; struct in_addr addr; addr.s_addr = htonl(sgw_s1u_ip);