diff --git a/lib/include/srslte/interfaces/epc_interfaces.h b/lib/include/srslte/interfaces/epc_interfaces.h index 1d1d79c34..607675a00 100644 --- a/lib/include/srslte/interfaces/epc_interfaces.h +++ b/lib/include/srslte/interfaces/epc_interfaces.h @@ -21,6 +21,7 @@ #ifndef SRSLTE_EPC_INTERFACES_H #define SRSLTE_EPC_INTERFACES_H #include "srslte/asn1/gtpc_ies.h" +#include namespace srsepc { @@ -54,6 +55,7 @@ public: virtual bool release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) = 0; virtual bool send_initial_context_setup_request(uint64_t imsi, uint16_t erab_to_setup) = 0; virtual bool send_ue_context_release_command(uint32_t mme_ue_s1ap_id) = 0; + virtual bool send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, struct sctp_sndrcvinfo enb_sri) = 0; }; //NAS -> HSS diff --git a/srsepc/hdr/mme/nas.h b/srsepc/hdr/mme/nas.h index 7fc4dfb73..f42725f6f 100644 --- a/srsepc/hdr/mme/nas.h +++ b/srsepc/hdr/mme/nas.h @@ -185,7 +185,7 @@ public: bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); /* Uplink NAS messages handling */ - bool handle_nas_authentication_response( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); + bool handle_nas_authentication_response( srslte::byte_buffer_t *nas_rx); bool handle_nas_security_mode_complete( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_nas_attach_complete( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_esm_information_response( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 318c15382..7219a362a 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -112,7 +112,7 @@ public: //Interfaces virtual bool send_initial_context_setup_request(uint64_t imsi, uint16_t erab_to_setup); virtual bool send_ue_context_release_command(uint32_t mme_ue_s1ap_id); - + virtual bool send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, struct sctp_sndrcvinfo enb_sri); private: s1ap(); virtual ~s1ap(); diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 920c2a1ec..08c88deb6 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -46,7 +46,7 @@ public: 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 handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); - bool send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, struct sctp_sndrcvinfo *enb_sri); + bool send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, struct sctp_sndrcvinfo enb_sri); bool handle_nas_attach_request(uint32_t enb_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, diff --git a/srsepc/src/mme/nas.cc b/srsepc/src/mme/nas.cc index f6efa819e..63f669a47 100644 --- a/srsepc/src/mme/nas.cc +++ b/srsepc/src/mme/nas.cc @@ -482,54 +482,56 @@ nas::handle_guti_attach_request_unknown_ue( uint32_t enb_ue_s1ap_id, * Handle Uplink NAS Transport message * */ - bool -nas::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) +nas::handle_nas_authentication_response(srslte::byte_buffer_t *nas_rx) { - + srslte::byte_buffer_t *nas_tx; LIBLTE_MME_AUTHENTICATION_RESPONSE_MSG_STRUCT auth_resp; - m_nas_log->console("Authentication Response -- IMSI %015lu\n", m_emm_ctx.imsi); + bool ue_valid=true; //Get NAS authentication response - LIBLTE_ERROR_ENUM err = liblte_mme_unpack_authentication_response_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &auth_resp); + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_authentication_response_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_rx, &auth_resp); if(err != LIBLTE_SUCCESS){ m_nas_log->error("Error unpacking NAS authentication response. Error: %s\n", liblte_error_text[err]); return false; } - m_nas_log->console("Authentication Response -- RES 0x%x%x%x%x%x%x%x%x\n", - auth_resp.res[0], auth_resp.res[1], auth_resp.res[2], auth_resp.res[3], - auth_resp.res[4], auth_resp.res[5], auth_resp.res[6], auth_resp.res[7]); - m_nas_log->info("Authentication Response -- RES 0x%x%x%x%x%x%x%x%x\n", - auth_resp.res[0], auth_resp.res[1], auth_resp.res[2], auth_resp.res[3], - auth_resp.res[4], auth_resp.res[5], auth_resp.res[6], auth_resp.res[7]); - bool ue_valid=true; + //Log received authentication response + m_nas_log->console("Authentication Response -- IMSI %015lu\n", m_emm_ctx.imsi); + m_nas_log->info("Authentication Response -- IMSI %015lu\n", m_emm_ctx.imsi); + m_nas_log->info_hex(auth_resp.res,8, "Authentication response -- RES"); + m_nas_log->info_hex(m_sec_ctx.xres,8, "Authentication response -- XRES"); + + //Check UE authentication for(int i=0; i<8;i++){ if( auth_resp.res[i] != m_sec_ctx.xres[i] ) { ue_valid = false; } } + nas_tx = m_pool->allocate(); if(!ue_valid) { - m_nas_log->info_hex(m_sec_ctx.xres,8, "XRES"); + //Authentication rejected m_nas_log->console("UE Authentication Rejected.\n"); m_nas_log->warning("UE Authentication Rejected.\n"); //Send back Athentication Reject - pack_authentication_reject(reply_buffer); - *reply_flag = true; - m_nas_log->console("Downlink NAS: Sending Authentication Reject.\n"); - return false; + pack_authentication_reject(nas_tx); + m_nas_log->info("Downlink NAS: Sending Authentication Reject.\n"); } else { + //Authentication accepted m_nas_log->console("UE Authentication Accepted.\n"); m_nas_log->info("UE Authentication Accepted.\n"); //Send Security Mode Command m_sec_ctx.ul_nas_count = 0; // Reset the NAS uplink counter for the right key k_enb derivation - pack_security_mode_command(reply_buffer); - *reply_flag = true; + pack_security_mode_command(nas_tx); m_nas_log->console("Downlink NAS: Sending NAS Security Mode Command.\n"); } + + //Send reply + m_s1ap->send_downlink_nas_transport(m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri); + m_pool->deallocate(nas_tx); return true; } diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 417f217c4..51c76e17d 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -650,4 +650,9 @@ s1ap::send_ue_context_release_command(uint32_t mme_ue_s1ap_id) return true; } +bool +s1ap::send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, struct sctp_sndrcvinfo enb_sri) +{ + return m_s1ap_nas_transport->send_downlink_nas_transport(enb_ue_s1ap_id, mme_ue_s1ap_id, nas_msg, enb_sri); +} } //namespace srsepc diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 2b9776b58..e1e574240 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -223,7 +223,7 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: m_s1ap_log->info("Uplink NAS: Received Authentication Response\n"); m_s1ap_log->console("Uplink NAS: Received Authentication Response\n"); - nas_ctx->handle_nas_authentication_response(nas_msg, reply_buffer, reply_flag); + nas_ctx->handle_nas_authentication_response(nas_msg); break; // Authentication failure with the option sync failure can be sent not integrity protected case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_FAILURE: @@ -673,7 +673,7 @@ s1ap_nas_transport::handle_nas_tracking_area_update_request(uint32_t m_tmsi, } bool -s1ap_nas_transport::send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, struct sctp_sndrcvinfo *enb_sri) +s1ap_nas_transport::send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, struct sctp_sndrcvinfo enb_sri) { //Allocate Reply buffer srslte::byte_buffer_t *reply_msg = m_pool->allocate(); @@ -709,7 +709,7 @@ s1ap_nas_transport::send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_ m_pool->deallocate(reply_msg); return false; } - m_s1ap->s1ap_tx_pdu(nas_msg,enb_sri); + m_s1ap->s1ap_tx_pdu(nas_msg, &enb_sri); m_pool->deallocate(reply_msg); return true; }