Moving many of the functions fron s1ap_nas_transport to it's own NAS class.

master
Pedro Alvarez 7 years ago
parent 41a5788cc7
commit 4c164acbc3

@ -30,7 +30,8 @@
#include "srslte/common/log_filter.h" #include "srslte/common/log_filter.h"
#include "srslte/common/buffer_pool.h" #include "srslte/common/buffer_pool.h"
#include "srslte/asn1/gtpc.h" #include "srslte/asn1/gtpc.h"
#include "s1ap_common.h" #include "nas.h"
namespace srsepc namespace srsepc
{ {
@ -53,7 +54,7 @@ public:
uint32_t get_new_ctrl_teid(); uint32_t get_new_ctrl_teid();
void send_create_session_request(uint64_t imsi); void send_create_session_request(uint64_t imsi);
void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu); void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu);
void send_modify_bearer_request(uint64_t imsi, erab_ctx_t *bearer_ctx); void send_modify_bearer_request(uint64_t imsi, esm_ctx_t *bearer_ctx);
void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu);
void send_release_access_bearers_request(uint64_t imsi); void send_release_access_bearers_request(uint64_t imsi);
void send_delete_session_request(uint64_t imsi); void send_delete_session_request(uint64_t imsi);

@ -18,8 +18,8 @@
* and at http://www.gnu.org/licenses/. * and at http://www.gnu.org/licenses/.
* *
*/ */
#ifndef SRSEPC_S1AP_COMMON_H #ifndef SRSEPC_NAS_H
#define SRSEPC_S1AP_COMMON_H #define SRSEPC_NAS_H
#include "srslte/common/security.h" #include "srslte/common/security.h"
#include "srslte/asn1/gtpc_ies.h" #include "srslte/asn1/gtpc_ies.h"
@ -76,34 +76,30 @@ static const char esm_state_text[ESM_STATE_N_ITEMS][100] = {"CONTEXT INACTIVE",
* EMM, ECM, ESM and EPS Security context definition * EMM, ECM, ESM and EPS Security context definition
*/ */
typedef struct{ typedef struct{
uint64_t imsi; uint64_t imsi;
LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti;
eps_sec_ctx_t security_ctxt;
uint8_t procedure_transaction_id;
emm_state_t state; emm_state_t state;
uint32_t mme_ue_s1ap_id; uint8_t procedure_transaction_id;
uint8_t attach_type; uint8_t attach_type;
struct in_addr ue_ip; struct in_addr ue_ip;
srslte::gtpc_f_teid_ie sgw_ctrl_fteid; srslte::gtpc_f_teid_ie sgw_ctrl_fteid;
} emm_ctx_t; } emm_ctx_t;
typedef struct{ typedef struct{
uint64_t imsi; ecm_state_t state;
uint32_t enb_ue_s1ap_id; uint32_t enb_ue_s1ap_id;
uint32_t mme_ue_s1ap_id; uint32_t mme_ue_s1ap_id;
struct sctp_sndrcvinfo enb_sri; struct sctp_sndrcvinfo enb_sri;
ecm_state_t state;
bool eit; bool eit;
} ecm_ctx_t; } ecm_ctx_t;
typedef struct{ typedef struct{
enum erab_state state;
uint8_t erab_id; uint8_t erab_id;
esm_state_t state;
uint8_t qci; uint8_t qci;
srslte::gtpc_f_teid_ie enb_fteid; srslte::gtpc_f_teid_ie enb_fteid;
srslte::gtpc_f_teid_ie sgw_s1u_fteid; srslte::gtpc_f_teid_ie sgw_s1u_fteid;
srslte::gtpc_pdn_address_allocation_ie pdn_addr_alloc; srslte::gtpc_pdn_address_allocation_ie pdn_addr_alloc;
} erab_ctx_t; } esm_ctx_t;
typedef struct{ typedef struct{
uint8_t eksi; uint8_t eksi;
@ -119,6 +115,7 @@ typedef struct{
LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT ue_network_cap; LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT ue_network_cap;
bool ms_network_cap_present; bool ms_network_cap_present;
LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT ms_network_cap; LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT ms_network_cap;
LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti;
} sec_ctx_t; } sec_ctx_t;
class nas class nas
@ -168,28 +165,28 @@ public:
struct sctp_sndrcvinfo *enb_sri); struct sctp_sndrcvinfo *enb_sri);
/* Uplink NAS messages handling */ /* Uplink NAS messages handling */
bool handle_nas_authentication_response( srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); bool handle_nas_authentication_response( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag);
bool handle_nas_security_mode_complete( srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); 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, ue_ctx_t *ue_ctx, 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, ue_ctx_t* ue_ctx, 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);
bool handle_identity_response( srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_identity_response( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool *reply_flag);
bool handle_tracking_area_update_request( srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_tracking_area_update_request( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool *reply_flag);
bool handle_authentication_failure( srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_authentication_failure( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool *reply_flag);
bool handle_nas_detach_request( srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_nas_detach_request( srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool *reply_flag);
/* Downlink NAS messages packing*/ /* Downlink NAS messages packing*/
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 eksi, uint8_t *autn, uint8_t *rand); 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 eksi, 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); 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, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx); 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_esm_information_request( srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx); 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, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); bool pack_identity_request( srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id);
bool pack_emm_information( ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg); bool pack_emm_information( srslte::byte_buffer_t *reply_msg);
bool pack_service_reject( srslte::byte_buffer_t *reply_msg, uint8_t emm_cause, uint32_t enb_ue_s1ap_id); bool pack_service_reject( srslte::byte_buffer_t *reply_msg, uint8_t emm_cause, uint32_t enb_ue_s1ap_id);
bool 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); bool pack_attach_accept( emm_ctx_t *ue_emm_ctx, 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);
/* Security functions */ /* Security functions */
bool integrity_check( ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); bool integrity_check( emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu);
bool short_integrity_check( ue_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: private:
emm_ctx_t m_emm_ctx; emm_ctx_t m_emm_ctx;

@ -41,7 +41,7 @@
#include <unistd.h> #include <unistd.h>
#include <map> #include <map>
#include <set> #include <set>
#include "s1ap_common.h" #include "nas.h"
#include "s1ap_mngmt_proc.h" #include "s1ap_mngmt_proc.h"
#include "s1ap_nas_transport.h" #include "s1ap_nas_transport.h"
#include "s1ap_ctx_mngmt_proc.h" #include "s1ap_ctx_mngmt_proc.h"
@ -82,12 +82,12 @@ public:
void add_new_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 get_enb_ctx(uint16_t sctp_stream); void get_enb_ctx(uint16_t sctp_stream);
bool add_ue_ctx_to_imsi_map(ue_ctx_t *ue_ctx); bool add_nas_ctx_to_imsi_map(nas *nas_ctx);
bool add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx_t *ue_ctx); bool add_nas_ctx_to_mme_ue_s1ap_id_map(nas *nas_ctx);
bool add_ue_to_enb_set(int32_t enb_assoc, uint32_t mme_ue_s1ap_id); bool add_ue_to_enb_set(int32_t enb_assoc, uint32_t mme_ue_s1ap_id);
ue_ctx_t* find_ue_ctx_from_imsi(uint64_t imsi); nas* find_nas_ctx_from_imsi(uint64_t imsi);
ue_ctx_t* find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); nas* find_nas_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id);
bool release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); bool release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id);
void release_ues_ecm_ctx_in_enb(int32_t enb_assoc); void release_ues_ecm_ctx_in_enb(int32_t enb_assoc);
@ -102,7 +102,7 @@ public:
s1ap_nas_transport* m_s1ap_nas_transport; s1ap_nas_transport* m_s1ap_nas_transport;
s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc; s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc;
std::map<uint32_t, uint64_t> m_tmsi_to_imsi; std::map<uint32_t, uint64_t> m_tmsi_to_imsi;
private: private:
s1ap(); s1ap();
@ -119,8 +119,8 @@ private:
std::map<int32_t, uint16_t> m_sctp_to_enb_id; std::map<int32_t, uint16_t> m_sctp_to_enb_id;
std::map<int32_t,std::set<uint32_t> > m_enb_assoc_to_ue_ids; std::map<int32_t,std::set<uint32_t> > m_enb_assoc_to_ue_ids;
std::map<uint64_t, ue_ctx_t*> m_imsi_to_ue_ctx; std::map<uint64_t, nas*> m_imsi_to_nas_ctx;
std::map<uint32_t, ue_ctx_t*> m_mme_ue_s1ap_id_to_ue_ctx; std::map<uint32_t, nas*> m_mme_ue_s1ap_id_to_nas_ctx;
uint32_t m_next_mme_ue_s1ap_id; uint32_t m_next_mme_ue_s1ap_id;
uint32_t m_next_m_tmsi; uint32_t m_next_m_tmsi;

@ -28,60 +28,9 @@
#include <netinet/sctp.h> #include <netinet/sctp.h>
namespace srsepc{ namespace srsepc{
static const uint8_t MAX_TA=255; //Maximum TA supported static const uint8_t MAX_TA=255; //Maximum TA supported
static const uint8_t MAX_BPLMN=6; //Maximum broadcasted PLMNs per TAC static const uint8_t MAX_BPLMN=6; //Maximum broadcasted PLMNs per TAC
static const uint8_t MAX_ERABS_PER_UE = 16;
// MME EMM states (3GPP 24.301 v10.0.0, section 5.1.3.4)
typedef enum {
EMM_STATE_DEREGISTERED = 0,
EMM_STATE_COMMON_PROCEDURE_INITIATED,
EMM_STATE_REGISTERED,
EMM_STATE_DEREGISTERED_INITIATED,
EMM_STATE_N_ITEMS,
} emm_state_t;
static const char emm_state_text[EMM_STATE_N_ITEMS][100] = {"DEREGISTERED",
"COMMON PROCEDURE INITIATED",
"REGISTERED",
"DEREGISTERED INITIATED"};
// MME ECM states (3GPP 23.401 v10.0.0, section 4.6.3)
typedef enum {
ECM_STATE_IDLE = 0,
ECM_STATE_CONNECTED,
ECM_STATE_N_ITEMS,
} ecm_state_t;
static const char ecm_state_text[ECM_STATE_N_ITEMS][100] = {"IDLE",
"CONNECTED"};
// MME ESM states (3GPP 23.401 v10.0.0, section 4.6.3)
typedef enum {
ESM_BEARER_CONTEXT_INACTIVE = 0,
ESM_BEARER_CONTEXT_ACTIVE_PENDING,
ESM_BEARER_CONTEXT_ACTIVE,
ESM_BEARER_CONTEXT_INACTIVE_PENDING,
ESM_BEARER_CONTEXT_MODIFY_PENDING,
ESM_BEARER_PROCEDURE_TRANSACTION_INACTIVE,
ESM_BEARER_PROCEDURE_TRANSACTION_PENDING,
ESM_STATE_N_ITEMS,
} esm_state_t;
static const char esm_state_text[ESM_STATE_N_ITEMS][100] = {"CONTEXT INACTIVE",
"CONTEXT ACTIVE PENDING",
"CONTEXT ACTIVE",
"CONTEXT_INACTIVE_PENDING",
"CONTEXT_MODIFY_PENDING",
"PROCEDURE_TRANSACTION_INACTIVE"
"PROCEDURE_TRANSACTION_PENDING"};
enum erab_state
{
ERAB_DEACTIVATED,
ERAB_CTX_REQUESTED,
ERAB_CTX_SETUP,
ERAB_ACTIVE
};
typedef struct{ typedef struct{
uint8_t mme_code; uint8_t mme_code;
@ -111,59 +60,6 @@ typedef struct{
struct sctp_sndrcvinfo sri; struct sctp_sndrcvinfo sri;
} enb_ctx_t; } enb_ctx_t;
typedef struct{
uint8_t eksi;
uint8_t k_asme[32];
uint8_t xres[16]; //minimum 6, maximum 16
uint32_t dl_nas_count;
uint32_t ul_nas_count;
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo;
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo;
uint8_t k_nas_enc[32];
uint8_t k_nas_int[32];
uint8_t k_enb[32];
LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT ue_network_cap;
bool ms_network_cap_present;
LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT ms_network_cap;
} eps_sec_ctx_t;
typedef struct{
enum erab_state state;
uint8_t erab_id;
uint8_t qci;
srslte::gtpc_f_teid_ie enb_fteid;
srslte::gtpc_f_teid_ie sgw_s1u_fteid;
srslte::gtpc_pdn_address_allocation_ie pdn_addr_alloc;
} erab_ctx_t;
typedef struct{
uint64_t imsi;
LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti;
eps_sec_ctx_t security_ctxt;
uint8_t procedure_transaction_id;
emm_state_t state;
uint32_t mme_ue_s1ap_id;
uint8_t attach_type;
struct in_addr ue_ip;
srslte::gtpc_f_teid_ie sgw_ctrl_fteid;
} ue_emm_ctx_t;
typedef struct{
uint64_t imsi;
uint32_t enb_ue_s1ap_id;
uint32_t mme_ue_s1ap_id;
struct sctp_sndrcvinfo enb_sri;
ecm_state_t state;
erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE];
bool eit;
} ue_ecm_ctx_t;
typedef struct{
ue_emm_ctx_t emm_ctx;
eps_sec_ctx_t sec_ctx;
ue_ecm_ctx_t ecm_ctx;
} ue_ctx_t;
}//namespace }//namespace
#endif // SRSEPC_S1AP_COMMON_H #endif // SRSEPC_S1AP_COMMON_H

@ -47,11 +47,10 @@ public:
void init(void); void init(void);
//bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); bool send_initial_context_setup_request(emm_ctx_t *emm_ctx, ecm_ctx_t *ecm_ctx, esm_ctx_t *esm_ctx);
bool send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, erab_ctx_t *erab_ctx);
bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); 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 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(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer); bool send_ue_context_release_command(ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer);
bool handle_ue_context_release_complete(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMPLETE_STRUCT *rel_comp); bool handle_ue_context_release_complete(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMPLETE_STRUCT *rel_comp);
private: private:

Loading…
Cancel
Save