From fae584dc91669f2600cd020ac97275786dcf9292 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 2 Nov 2017 15:07:28 +0000 Subject: [PATCH] Packed authentication request message. Code needs cleanup and testing. --- srsepc/hdr/mme/s1ap.h | 1 + srsepc/hdr/mme/s1ap_nas_transport.h | 2 +- srsepc/src/mme/s1ap.cc | 70 ++++++++++++++++++++++++++-- srsepc/src/mme/s1ap_nas_transport.cc | 24 ++-------- 4 files changed, 72 insertions(+), 25 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index a3dd63ffe..2ab1d74c1 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -82,6 +82,7 @@ private: hss *m_hss; int m_s1mme; std::map m_active_enbs; + uint32_t m_next_mme_ue_s1ap_id; s1ap_mngmt_proc m_s1ap_mngmt_proc; s1ap_nas_transport m_s1ap_nas_transport; diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 878da369e..db7c8c829 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -40,7 +40,7 @@ public: void set_log(srslte::log *s1ap_logger); bool unpack_initial_ue_message(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, uint64_t *imsi); - bool pack_authentication_request(); + bool pack_authentication_request(uint8_t *autn,uint8_t *rand); private: srslte::log *m_s1ap_log; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index ce25a26ec..8ec436cd7 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -32,7 +32,8 @@ namespace srsepc{ s1ap::s1ap(): - m_s1mme(-1) + m_s1mme(-1), + m_next_mme_ue_s1ap_id(0) { } @@ -183,6 +184,7 @@ s1ap::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, st 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)) @@ -247,6 +249,8 @@ s1ap::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *msg LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT attach_req; LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT pdn_con_req; + /*Get info from initial UE message*/ + uint32_t enb_ue_s1ap_id = msg->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; /*Get NAS Attach Request Message*/ uint8_t pd, msg_type; @@ -369,10 +373,70 @@ s1ap::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *msg return false; } - m_s1ap_nas_transport.pack_authentication_request(); + //Pack NAS Authentication Request in Downlink NAS Transport msg + srslte::byte_buffer_t *nas_buffer; + srslte::byte_buffer_t *reply_msg = m_pool->allocate(); + + //Setup initiating message + LIBLTE_S1AP_S1AP_PDU_STRUCT tx_pdu; + tx_pdu.ext = false; + tx_pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE; + + LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *init = &tx_pdu.choice.initiatingMessage; + init->procedureCode = LIBLTE_S1AP_PROC_ID_DOWNLINKNASTRANSPORT; + init->choice_type = LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_DOWNLINKNASTRANSPORT; + + //Setup Dw NAS message + LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; + dw_nas->ext=false; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = m_next_mme_ue_s1ap_id++; + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = enb_ue_s1ap_id; + dw_nas->HandoverRestrictionList_present=false; + dw_nas->SubscriberProfileIDforRFP_present=false; + /* + typedef struct{ + bool ext; + LIBLTE_S1AP_MME_UE_S1AP_ID_STRUCT MME_UE_S1AP_ID; + LIBLTE_S1AP_ENB_UE_S1AP_ID_STRUCT eNB_UE_S1AP_ID; + LIBLTE_S1AP_NAS_PDU_STRUCT NAS_PDU; + LIBLTE_S1AP_HANDOVERRESTRICTIONLIST_STRUCT HandoverRestrictionList; + bool HandoverRestrictionList_present; + LIBLTE_S1AP_SUBSCRIBERPROFILEIDFORRFP_STRUCT SubscriberProfileIDforRFP; + bool SubscriberProfileIDforRFP_present; + }LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT; + */ + + LIBLTE_MME_AUTHENTICATION_REQUEST_MSG_STRUCT auth_req; + memcpy(auth_req.autn , autn, 16); + memcpy(auth_req.rand, rand, 16); + auth_req.nas_ksi.tsc_flag=LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; + auth_req.nas_ksi.nas_ksi=0; + + + // NAS_PDU + nas_buffer = m_pool->allocate(); + err = liblte_mme_pack_authentication_request_msg(&auth_req, (LIBLTE_BYTE_MSG_STRUCT *) reply_msg); + if(err != LIBLTE_SUCCESS) + { + m_s1ap_log->console("Error packing Athentication Request"); + return false; + } + + memcpy(dw_nas->NAS_PDU.buffer, reply_msg->msg, reply_msg->N_bytes); + dw_nas->NAS_PDU.n_octets = reply_msg->N_bytes; + + //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; + } + + m_pool->deallocate(reply_msg); + //TODO Start T3460 Timer! return true; - } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 18c2ad072..bf8a8d0a4 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -59,28 +59,10 @@ s1ap_nas_transport::pack_authentication_request(uint8_t *autn,uint8_t *rand) LIBLTE_MME_AUTHENTICATION_REQUEST_MSG_STRUCT pdu; memcpy(pdu.autn , autn, 16); memcpy(pdu.rand, rand, 16); - pdu.tsg_flag=LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; - pdu.nas_ksi=0; - + pdu.nas_ksi.tsc_flag=LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; + pdu.nas_ksi.nas_ksi=0; + return true; - - //typedef struct{ - // LIBLTE_MME_NAS_KEY_SET_ID_STRUCT nas_ksi; - // uint8 autn[16]; - // uint8 rand[16]; - //}LIBLTE_MME_AUTHENTICATION_REQUEST_MSG_STRUCT; - - //typedef struct{ - // LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_ENUM tsc_flag; - // uint8 nas_ksi; - //}LIBLTE_MME_NAS_KEY_SET_ID_STRUCT; - - //typedef enum{ - // LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE = 0, - // LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_MAPPED, - // LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_N_ITEMS, - //}LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_ENUM; - } } //namespace srsepc