Fixing nas.cc

master
Pedro Alvarez 7 years ago
parent 85672d4a3f
commit b25c12a084

@ -1,14 +1,35 @@
/*
* \section LICENSE
*
* This file is part of srsLTE.
*
* srsLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#ifndef SRSLTE_EPC_INTERFACES_H
#define SRSLTE_EPC_INTERFACES_H
#include "srslte/srslte.h"
#include "srslte/common/common.h"
namespace srsepc {
/*
* S1AP Interfaces
*/
//GTP-C -> NAS
class gtpc_interface_nas
{
public:
virtual bool send_delete_session_request(uint64_t imsi) = 0;
};
//GTP-C -> S1AP
class s1ap_interface_gtpc
{
@ -21,6 +42,7 @@ class s1ap_interface_nas
{
public:
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;
};
//S1AP -> HSS

@ -21,11 +21,13 @@
#ifndef SRSEPC_NAS_H
#define SRSEPC_NAS_H
#include <netinet/sctp.h>
#include "srslte/common/security.h"
#include "srslte/asn1/gtpc_ies.h"
#include "srslte/asn1/liblte_s1ap.h"
#include "srslte/asn1/liblte_mme.h"
#include <netinet/sctp.h>
#include "srslte/interfaces/epc_interfaces.h"
namespace srsepc{
@ -185,7 +187,7 @@ public:
/* Downlink NAS messages packing*/
bool pack_authentication_request (srslte::byte_buffer_t *reply_msg);
bool pack_authentication_reject (srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id);
bool pack_security_mode_command (srslte::byte_buffer_t *reply_msg, emm_ctx_t *ue_emm_ctx, ecm_ctx_t *ue_ecm_ctx);
bool pack_security_mode_command (srslte::byte_buffer_t *reply_msg);
bool pack_esm_information_request (srslte::byte_buffer_t *reply_msg, emm_ctx_t *ue_emm_ctx, ecm_ctx_t *ue_ecm_ctx);
bool pack_identity_request (srslte::byte_buffer_t *reply_msg);
bool pack_emm_information (srslte::byte_buffer_t *reply_msg);
@ -201,7 +203,12 @@ public:
ecm_ctx_t m_ecm_ctx;
esm_ctx_t m_esm_ctx[MAX_ERABS_PER_UE];
sec_ctx_t m_sec_ctx;
private:
srslte::log *m_nas_log;
gtpc_interface_nas *m_gtpc;
s1ap_interface_nas *m_s1ap;
};
}//namespace
#endif // SRSEPC_S1AP_COMMON_H
#endif // SRSEPC_NAS_H

@ -55,76 +55,73 @@ nas::~nas() {}
//FIXME re-factor to reduce code duplication for messages that can be both initiating messages and uplink NAS messages
bool
nas::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag)
nas::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_msg, bool *reply_flag)
{
m_s1ap_log->console("Detach request -- IMSI %015lu\n", ue_ctx->emm_ctx.imsi);
m_s1ap_log->info("Detach request -- IMSI %015lu\n", ue_ctx->emm_ctx.imsi);
m_nas_log->console("Detach request -- IMSI %015lu\n", m_emm_ctx.imsi);
m_nas_log->info("Detach request -- IMSI %015lu\n", m_emm_ctx.imsi);
LIBLTE_MME_DETACH_REQUEST_MSG_STRUCT detach_req;
LIBLTE_ERROR_ENUM err = liblte_mme_unpack_detach_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &detach_req);
if(err !=LIBLTE_SUCCESS) {
m_s1ap_log->error("Could not unpack detach request\n");
m_nas_log->error("Could not unpack detach request\n");
return false;
}
m_mme_gtpc->send_delete_session_request(ue_ctx->emm_ctx.imsi);
ue_ctx->emm_ctx.state = EMM_STATE_DEREGISTERED;
if(ue_ctx->ecm_ctx.mme_ue_s1ap_id!=0) {
m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(&ue_ctx->ecm_ctx, reply_msg);
m_gtpc->send_delete_session_request(m_emm_ctx.imsi);
m_emm_ctx.state = EMM_STATE_DEREGISTERED;
if (m_ecm_ctx.mme_ue_s1ap_id!=0) {
m_s1ap->send_ue_context_release_command(m_ecm_ctx.mme_ue_s1ap_id);
}
return true;
}
bool
nas::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag)
nas::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag)
{
LIBLTE_MME_AUTHENTICATION_RESPONSE_MSG_STRUCT auth_resp;
bool ue_valid=true;
ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx;
ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx;
m_s1ap_log->console("Authentication Response -- IMSI %015lu\n", emm_ctx->imsi);
m_nas_log->console("Authentication Response -- IMSI %015lu\n", m_emm_ctx.imsi);
//Get NAS authentication response
LIBLTE_ERROR_ENUM err = liblte_mme_unpack_authentication_response_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &auth_resp);
if(err != LIBLTE_SUCCESS){
m_s1ap_log->error("Error unpacking NAS authentication response. Error: %s\n", liblte_error_text[err]);
m_nas_log->error("Error unpacking NAS authentication response. Error: %s\n", liblte_error_text[err]);
return false;
}
m_s1ap_log->console("Authentication Response -- RES 0x%x%x%x%x%x%x%x%x\n",
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_s1ap_log->info("Authentication Response -- RES 0x%x%x%x%x%x%x%x%x\n",
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;
for(int i=0; i<8;i++){
if( auth_resp.res[i] != emm_ctx->security_ctxt.xres[i] ) {
if( auth_resp.res[i] != m_sec_ctx.xres[i] ) {
ue_valid = false;
}
}
if(!ue_valid) {
m_s1ap_log->info_hex(emm_ctx->security_ctxt.xres,8, "XRES");
m_s1ap_log->console("UE Authentication Rejected.\n");
m_s1ap_log->warning("UE Authentication Rejected.\n");
m_nas_log->info_hex(m_sec_ctx.xres,8, "XRES");
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, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id);
pack_authentication_reject(reply_buffer, m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id);
*reply_flag = true;
m_s1ap_log->console("Downlink NAS: Sending Authentication Reject.\n");
m_nas_log->console("Downlink NAS: Sending Authentication Reject.\n");
return false;
} else {
m_s1ap_log->console("UE Authentication Accepted.\n");
m_s1ap_log->info("UE Authentication Accepted.\n");
m_nas_log->console("UE Authentication Accepted.\n");
m_nas_log->info("UE Authentication Accepted.\n");
//Send Security Mode Command
emm_ctx->security_ctxt.ul_nas_count = 0; // Reset the NAS uplink counter for the right key k_enb derivation
pack_security_mode_command(reply_buffer, emm_ctx, ecm_ctx);
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;
m_s1ap_log->console("Downlink NAS: Sending NAS Security Mode Command.\n");
m_nas_log->console("Downlink NAS: Sending NAS Security Mode Command.\n");
}
return true;
}

@ -611,7 +611,7 @@ s1ap::print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx)
/*
* Interfaces
*/
// NAS -> S1AP interfaces
// GTP-C || NAS -> S1AP interface
bool
s1ap::send_initial_context_setup_request(uint64_t imsi, uint16_t erab_to_setup)
{

Loading…
Cancel
Save