forked from acouzens/open5gs
update it
This commit is contained in:
parent
b588104b58
commit
8a3037a6fa
|
@ -5,7 +5,7 @@ noinst_LTLIBRARIES = libmme.la
|
|||
libmme_la_SOURCES = \
|
||||
kdf.h kasumi.h snow_3g.h zuc.h \
|
||||
event.h context.h \
|
||||
s1ap_build.h s1ap_conv.h s1ap_path.h \
|
||||
s1ap_build.h s1ap_handler.h s1ap_conv.h s1ap_path.h \
|
||||
nas_conv.h nas_security.h \
|
||||
s11_path.h \
|
||||
sm.h s6a_sm.h
|
||||
|
@ -13,7 +13,7 @@ libmme_la_SOURCES = \
|
|||
nodist_libmme_la_SOURCES = \
|
||||
kdf.c kasumi.c snow_3g.c zuc.c \
|
||||
init.c event.c context.c \
|
||||
s1ap_build.c s1ap_conv.c s1ap_path.c \
|
||||
s1ap_build.c s1ap_handler.c s1ap_conv.c s1ap_path.c \
|
||||
nas_conv.c nas_security.c \
|
||||
s11_path.c \
|
||||
mme_sm.c enb_s1ap_sm.c ue_emm_sm.c s6a_sm.c
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
#define TRACE_MODULE _emm_handler
|
||||
|
||||
#include "core_debug.h"
|
||||
|
||||
#include "3gpp_conv.h"
|
||||
#include "s1ap_message.h"
|
||||
#include "nas_message.h"
|
||||
|
||||
#include "sm.h"
|
||||
#include "context.h"
|
||||
#include "event.h"
|
||||
|
||||
#include "kdf.h"
|
||||
#include "nas_security.h"
|
||||
#include "s1ap_path.h"
|
||||
#include "s1ap_conv.h"
|
||||
#include "nas_conv.h"
|
||||
#include "s6a_sm.h"
|
||||
|
||||
void emm_handle_attach_request(
|
||||
ue_ctx_t *ue, nas_attach_request_t *attach_request)
|
||||
{
|
||||
nas_eps_mobile_identity_t *eps_mobile_identity =
|
||||
&attach_request->eps_mobile_identity;
|
||||
|
||||
switch(eps_mobile_identity->imsi.type_of_identity)
|
||||
{
|
||||
case NAS_EPS_MOBILE_IDENTITY_IMSI:
|
||||
{
|
||||
plmn_id_t *plmn_id = &mme_self()->plmn_id;
|
||||
|
||||
if (attach_request->presencemask &
|
||||
NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT)
|
||||
{
|
||||
nas_tracking_area_identity_t *last_visited_registered_tai =
|
||||
&attach_request->last_visited_registered_tai;
|
||||
|
||||
plmn_id = &last_visited_registered_tai->plmn_id;
|
||||
}
|
||||
nas_imsi_bcd_to_buffer(
|
||||
&eps_mobile_identity->imsi, eps_mobile_identity->length,
|
||||
ue->imsi, &ue->imsi_len);
|
||||
|
||||
memcpy(&ue->ue_network_capability,
|
||||
&attach_request->ue_network_capability,
|
||||
sizeof(attach_request->ue_network_capability));
|
||||
memcpy(&ue->ms_network_capability,
|
||||
&attach_request->ms_network_capability,
|
||||
sizeof(attach_request->ms_network_capability));
|
||||
|
||||
d_assert(ue->imsi, return,);
|
||||
d_info("[NAS] Attach request : UE[%s] --> EMM", ue->imsi);
|
||||
|
||||
s6a_send_auth_info_req(ue, plmn_id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
d_warn("Not implemented(type:%d)",
|
||||
eps_mobile_identity->imsi.type_of_identity);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void emm_handle_authentication_response(
|
||||
ue_ctx_t *ue, nas_authentication_response_t *authentication_response)
|
||||
{
|
||||
nas_authentication_response_parameter_t *authentication_response_parameter =
|
||||
&authentication_response->authentication_response_parameter;
|
||||
|
||||
nas_message_t message;
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
nas_security_mode_command_t *security_mode_command =
|
||||
&message.security_mode_command;
|
||||
nas_security_algorithms_t *selected_nas_security_algorithms =
|
||||
&security_mode_command->selected_nas_security_algorithms;
|
||||
nas_key_set_identifier_t *nas_key_set_identifier =
|
||||
&security_mode_command->nas_key_set_identifier;
|
||||
nas_ue_security_capability_t *replayed_ue_security_capabilities =
|
||||
&security_mode_command->replayed_ue_security_capabilities;
|
||||
|
||||
d_assert(ue, return, "Null param");
|
||||
|
||||
if (authentication_response_parameter->length != ue->xres_len ||
|
||||
memcmp(authentication_response_parameter->res,
|
||||
ue->xres, ue->xres_len) != 0)
|
||||
{
|
||||
d_error("authentication failed");
|
||||
return;
|
||||
}
|
||||
|
||||
d_assert(ue->imsi, return, );
|
||||
d_info("[NAS] Authentication response : UE[%s] --> EMM", ue->imsi);
|
||||
|
||||
memset(&message, 0, sizeof(message));
|
||||
message.h.protocol_discriminator = NAS_PROTOCOL_DISCRIMINATOR_EMM;
|
||||
message.h.message_type = NAS_SECURITY_MODE_COMMAND;
|
||||
|
||||
selected_nas_security_algorithms->type_of_ciphering_algorithm =
|
||||
mme_self()->selected_enc_algorithm;
|
||||
selected_nas_security_algorithms->type_of_integrity_protection_algorithm =
|
||||
mme_self()->selected_int_algorithm;
|
||||
|
||||
nas_key_set_identifier->tsc = 0;
|
||||
nas_key_set_identifier->nas_key_set_identifier = 0;
|
||||
|
||||
replayed_ue_security_capabilities->length =
|
||||
sizeof(replayed_ue_security_capabilities->eea) +
|
||||
sizeof(replayed_ue_security_capabilities->eia) +
|
||||
sizeof(replayed_ue_security_capabilities->uea) +
|
||||
sizeof(replayed_ue_security_capabilities->uia) +
|
||||
sizeof(replayed_ue_security_capabilities->gea);
|
||||
replayed_ue_security_capabilities->eea = ue->ue_network_capability.eea;
|
||||
replayed_ue_security_capabilities->eia = ue->ue_network_capability.eia;
|
||||
replayed_ue_security_capabilities->uea = ue->ue_network_capability.uea;
|
||||
replayed_ue_security_capabilities->uia = ue->ue_network_capability.uia;
|
||||
replayed_ue_security_capabilities->gea =
|
||||
(ue->ms_network_capability.gea1 << 6) |
|
||||
ue->ms_network_capability.extended_gea;
|
||||
|
||||
mme_kdf_nas(MME_KDF_NAS_INT_ALG, mme_self()->selected_int_algorithm,
|
||||
ue->kasme, ue->knas_int);
|
||||
mme_kdf_nas(MME_KDF_NAS_ENC_ALG, mme_self()->selected_enc_algorithm,
|
||||
ue->kasme, ue->knas_enc);
|
||||
|
||||
message.h.security_header_type =
|
||||
NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_NEW_SECURITY_CONTEXT;
|
||||
d_assert(nas_security_encode(&sendbuf, ue, &message) == CORE_OK &&
|
||||
sendbuf,,);
|
||||
nas_send_s1ap_to_enb(ue, sendbuf);
|
||||
|
||||
d_assert(ue->imsi, return,);
|
||||
d_info("[NAS] Security mode command : UE[%s] <-- EMM", ue->imsi);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef __EMM_HANDLER_H__
|
||||
#define __EMM_HANDLER_H__
|
||||
|
||||
#include "context.h"
|
||||
#include "nas_message.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
CORE_DECLARE(void) emm_handle_attach_request(
|
||||
ue_ctx_t *ue, nas_attach_request_t *attach_request);
|
||||
CORE_DECLARE(void) emm_handle_authentication_response(
|
||||
ue_ctx_t *ue, nas_authentication_response_t *authentication_response);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __EMM_HANDLER_H__ */
|
|
@ -7,18 +7,7 @@
|
|||
#include "event.h"
|
||||
|
||||
#include "s1ap_build.h"
|
||||
#include "s1ap_conv.h"
|
||||
#include "s1ap_path.h"
|
||||
#include "nas_message.h"
|
||||
|
||||
static void enb_s1ap_handle_s1_setup_request(
|
||||
enb_ctx_t *enb, s1ap_message_t *message);
|
||||
static void enb_s1ap_handle_initial_ue_message(
|
||||
enb_ctx_t *enb, s1ap_message_t *message);
|
||||
static void enb_s1ap_handle_uplink_nas_transport(
|
||||
enb_ctx_t *enb, s1ap_message_t *message);
|
||||
|
||||
static void enb_s1ap_send_to_ue(ue_ctx_t *ue, S1ap_NAS_PDU_t *nasPdu);
|
||||
#include "s1ap_handler.h"
|
||||
|
||||
void enb_s1ap_state_initial(enb_s1ap_sm_t *s, event_t *e)
|
||||
{
|
||||
|
@ -78,17 +67,17 @@ void enb_s1ap_state_operational(enb_s1ap_sm_t *s, event_t *e)
|
|||
{
|
||||
case S1ap_ProcedureCode_id_S1Setup :
|
||||
{
|
||||
enb_s1ap_handle_s1_setup_request(enb, &message);
|
||||
s1ap_handle_s1_setup_request(enb, &message);
|
||||
break;
|
||||
}
|
||||
case S1ap_ProcedureCode_id_initialUEMessage :
|
||||
{
|
||||
enb_s1ap_handle_initial_ue_message(enb, &message);
|
||||
s1ap_handle_initial_ue_message(enb, &message);
|
||||
break;
|
||||
}
|
||||
case S1ap_ProcedureCode_id_uplinkNASTransport :
|
||||
{
|
||||
enb_s1ap_handle_uplink_nas_transport(enb, &message);
|
||||
s1ap_handle_uplink_nas_transport(enb, &message);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -161,135 +150,3 @@ void enb_s1ap_state_exception(enb_s1ap_sm_t *s, event_t *e)
|
|||
}
|
||||
}
|
||||
|
||||
static void enb_s1ap_handle_s1_setup_request(
|
||||
enb_ctx_t *enb, s1ap_message_t *message)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
S1ap_S1SetupRequestIEs_t *ies = NULL;
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
c_uint32_t enb_id;
|
||||
|
||||
d_assert(enb, return, "Null param");
|
||||
d_assert(enb->s1ap_sock, return, "Null param");
|
||||
d_assert(message, return, "Null param");
|
||||
|
||||
ies = &message->s1ap_S1SetupRequestIEs;
|
||||
d_assert(ies, return, "Null param");
|
||||
|
||||
s1ap_ENB_ID_to_uint32(&ies->global_ENB_ID.eNB_ID, &enb_id);
|
||||
|
||||
#if 0 /* FIXME : does it needed? */
|
||||
if (mme_ctx_enb_find_by_enb_id(enb_id))
|
||||
{
|
||||
S1ap_Cause_t cause;
|
||||
d_error("eNB-id[0x%x] duplicated from [%s]", enb_id,
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf));
|
||||
|
||||
cause.present = S1ap_Cause_PR_protocol;
|
||||
cause.choice.protocol =
|
||||
S1ap_CauseProtocol_message_not_compatible_with_receiver_state;
|
||||
rv = s1ap_build_setup_failure(&sendbuf, cause);
|
||||
}
|
||||
#endif
|
||||
d_assert(enb->s1ap_sock, return,);
|
||||
d_info("[S1AP] S1SetupRequest : eNB[%s:%d] --> MME",
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
enb_id);
|
||||
|
||||
enb->enb_id = enb_id;
|
||||
|
||||
d_assert(s1ap_build_setup_rsp(&sendbuf) == CORE_OK,
|
||||
return, "build error");
|
||||
d_assert(s1ap_send_to_enb(enb, sendbuf) == CORE_OK, , "send error");
|
||||
|
||||
d_assert(enb->s1ap_sock, return,);
|
||||
d_info("[S1AP] S1SetupResponse: eNB[%s:%d] <-- MME",
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
enb_id);
|
||||
}
|
||||
|
||||
static void enb_s1ap_handle_initial_ue_message(
|
||||
enb_ctx_t *enb, s1ap_message_t *message)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
ue_ctx_t *ue = NULL;
|
||||
S1ap_InitialUEMessage_IEs_t *ies = NULL;
|
||||
|
||||
d_assert(enb, return, "Null param");
|
||||
|
||||
ies = &message->s1ap_InitialUEMessage_IEs;
|
||||
d_assert(ies, return, "Null param");
|
||||
|
||||
ue = mme_ctx_ue_find_by_enb_ue_s1ap_id(enb, ies->eNB_UE_S1AP_ID);
|
||||
if (!ue)
|
||||
{
|
||||
ue = mme_ctx_ue_add(enb);
|
||||
d_assert(ue, return, "Null param");
|
||||
|
||||
ue->enb_ue_s1ap_id = ies->eNB_UE_S1AP_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_warn("Duplicated: eNB[0x%x] sends "
|
||||
"Initial-UE Message[eNB-UE-S1AP-ID(%d)]",
|
||||
enb->enb_id, ue->enb_ue_s1ap_id);
|
||||
}
|
||||
|
||||
d_assert(enb->s1ap_sock, mme_ctx_ue_remove(ue);return,);
|
||||
d_info("[S1AP] InitialUEMessage : UE[eNB-UE-S1AP-ID(%d)] --> eNB[%s:%d]",
|
||||
ue->enb_ue_s1ap_id,
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
enb->enb_id);
|
||||
|
||||
fsm_create((fsm_t*)&ue->emm_sm,
|
||||
ue_emm_state_initial, ue_emm_state_final);
|
||||
ue->emm_sm.ctx = ue;
|
||||
|
||||
fsm_init((fsm_t*)&ue->emm_sm, 0);
|
||||
|
||||
enb_s1ap_send_to_ue(ue, &ies->nas_pdu);
|
||||
}
|
||||
|
||||
static void enb_s1ap_handle_uplink_nas_transport(
|
||||
enb_ctx_t *enb, s1ap_message_t *message)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
ue_ctx_t *ue = NULL;
|
||||
S1ap_UplinkNASTransport_IEs_t *ies = NULL;
|
||||
|
||||
ies = &message->s1ap_UplinkNASTransport_IEs;
|
||||
d_assert(ies, return, "Null param");
|
||||
|
||||
ue = mme_ctx_ue_find_by_enb_ue_s1ap_id(enb, ies->eNB_UE_S1AP_ID);
|
||||
d_assert(ue, return, "Null param");
|
||||
|
||||
d_info("[S1AP] uplinkNASTransport : UE[eNB-UE-S1AP-ID(%d)] --> eNB[%s:%d]",
|
||||
ue->enb_ue_s1ap_id,
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
enb->enb_id);
|
||||
|
||||
enb_s1ap_send_to_ue(ue, &ies->nas_pdu);
|
||||
}
|
||||
|
||||
static void enb_s1ap_send_to_ue(ue_ctx_t *ue, S1ap_NAS_PDU_t *nasPdu)
|
||||
{
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
event_t e;
|
||||
|
||||
d_assert(nasPdu, return, "Null param");
|
||||
|
||||
/* The Packet Buffer(pkbuf_t) for NAS message MUST make a HEADROOM.
|
||||
* When calculating AES_CMAC, we need to use the headroom of the packet. */
|
||||
sendbuf = pkbuf_alloc(NAS_HEADROOM, nasPdu->size);
|
||||
d_assert(sendbuf, return, "Null param");
|
||||
memcpy(sendbuf->payload, nasPdu->buf, nasPdu->size);
|
||||
|
||||
event_set(&e, EVT_MSG_UE_EMM);
|
||||
event_set_param1(&e, (c_uintptr_t)ue);
|
||||
event_set_param2(&e, (c_uintptr_t)sendbuf);
|
||||
|
||||
event_send(mme_self()->queue_id, &e);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#define TRACE_MODULE _nas_build
|
||||
|
||||
#include "nas_message.h"
|
||||
#include "s1ap_message.h"
|
||||
|
||||
void nas_send_s1ap_to_enb(ue_ctx_t *ue, pkbuf_t *pkbuf)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
int encoded;
|
||||
s1ap_message_t message;
|
||||
S1ap_DownlinkNASTransport_IEs_t *ies =
|
||||
&message.s1ap_DownlinkNASTransport_IEs;
|
||||
S1ap_NAS_PDU_t *nasPdu = &ies->nas_pdu;
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
|
||||
memset(&message, 0, sizeof(s1ap_message_t));
|
||||
|
||||
ies->mme_ue_s1ap_id = ue->mme_ue_s1ap_id;
|
||||
ies->eNB_UE_S1AP_ID = ue->enb_ue_s1ap_id;
|
||||
|
||||
nasPdu->size = pkbuf->len;
|
||||
nasPdu->buf = core_calloc(nasPdu->size, sizeof(c_uint8_t));
|
||||
memcpy(nasPdu->buf, pkbuf->payload, nasPdu->size);
|
||||
|
||||
message.procedureCode = S1ap_ProcedureCode_id_downlinkNASTransport;
|
||||
message.direction = S1AP_PDU_PR_initiatingMessage;
|
||||
|
||||
encoded = s1ap_encode_pdu(&sendbuf, &message);
|
||||
s1ap_free_pdu(&message);
|
||||
|
||||
d_assert(sendbuf && encoded >= 0,,);
|
||||
d_assert(s1ap_send_to_enb(ue->enb, sendbuf) == CORE_OK,,);
|
||||
pkbuf_free(pkbuf);
|
||||
|
||||
d_assert(ue->enb,,);
|
||||
d_info("[S1AP] downlinkNASTransport : "
|
||||
"UE[eNB-UE-S1AP-ID(%d)] <-- eNB[%s:%d]",
|
||||
ue->enb_ue_s1ap_id,
|
||||
INET_NTOP(&ue->enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
ue->enb->enb_id);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef __NAS_BUILD_H__
|
||||
#define __NAS_BUILD_H__
|
||||
|
||||
#include "core_pkbuf.h"
|
||||
#include "context.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
CORE_DECLARE(void) nas_send_s1ap_to_enb(ue_ctx_t *ue, pkbuf_t *pkbuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __NAS_BUILD_H__ */
|
|
@ -4,6 +4,27 @@
|
|||
#include "context.h"
|
||||
#include "s1ap_build.h"
|
||||
#include "s1ap_conv.h"
|
||||
#include "nas_message.h"
|
||||
|
||||
void s1ap_send_nas_to_emm(ue_ctx_t *ue, S1ap_NAS_PDU_t *nasPdu)
|
||||
{
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
event_t e;
|
||||
|
||||
d_assert(nasPdu, return, "Null param");
|
||||
|
||||
/* The Packet Buffer(pkbuf_t) for NAS message MUST make a HEADROOM.
|
||||
* When calculating AES_CMAC, we need to use the headroom of the packet. */
|
||||
sendbuf = pkbuf_alloc(NAS_HEADROOM, nasPdu->size);
|
||||
d_assert(sendbuf, return, "Null param");
|
||||
memcpy(sendbuf->payload, nasPdu->buf, nasPdu->size);
|
||||
|
||||
event_set(&e, EVT_MSG_UE_EMM);
|
||||
event_set_param1(&e, (c_uintptr_t)ue);
|
||||
event_set_param2(&e, (c_uintptr_t)sendbuf);
|
||||
|
||||
event_send(mme_self()->queue_id, &e);
|
||||
}
|
||||
|
||||
status_t s1ap_build_setup_rsp(pkbuf_t **pkbuf)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
CORE_DECLARE(void) s1ap_send_nas_to_emm(ue_ctx_t *ue, S1ap_NAS_PDU_t *nasPdu);
|
||||
|
||||
CORE_DECLARE(status_t) s1ap_build_setup_rsp(pkbuf_t **pkbuf);
|
||||
CORE_DECLARE(status_t) s1ap_build_setup_failure(
|
||||
pkbuf_t **pkbuf, S1ap_Cause_t cause);
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
#define TRACE_MODULE _s1ap_handler
|
||||
|
||||
#include "core_debug.h"
|
||||
#include "context.h"
|
||||
#include "s1ap_conv.h"
|
||||
#include "s1ap_build.h"
|
||||
#include "s1ap_handler.h"
|
||||
#include "s1ap_path.h"
|
||||
|
||||
void s1ap_handle_s1_setup_request(enb_ctx_t *enb, s1ap_message_t *message)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
S1ap_S1SetupRequestIEs_t *ies = NULL;
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
c_uint32_t enb_id;
|
||||
|
||||
d_assert(enb, return, "Null param");
|
||||
d_assert(enb->s1ap_sock, return, "Null param");
|
||||
d_assert(message, return, "Null param");
|
||||
|
||||
ies = &message->s1ap_S1SetupRequestIEs;
|
||||
d_assert(ies, return, "Null param");
|
||||
|
||||
s1ap_ENB_ID_to_uint32(&ies->global_ENB_ID.eNB_ID, &enb_id);
|
||||
|
||||
#if 0 /* FIXME : does it needed? */
|
||||
if (mme_ctx_enb_find_by_enb_id(enb_id))
|
||||
{
|
||||
S1ap_Cause_t cause;
|
||||
d_error("eNB-id[0x%x] duplicated from [%s]", enb_id,
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf));
|
||||
|
||||
cause.present = S1ap_Cause_PR_protocol;
|
||||
cause.choice.protocol =
|
||||
S1ap_CauseProtocol_message_not_compatible_with_receiver_state;
|
||||
rv = s1ap_build_setup_failure(&sendbuf, cause);
|
||||
}
|
||||
#endif
|
||||
d_assert(enb->s1ap_sock, return,);
|
||||
d_info("[S1AP] S1SetupRequest : eNB[%s:%d] --> MME",
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
enb_id);
|
||||
|
||||
enb->enb_id = enb_id;
|
||||
|
||||
d_assert(s1ap_build_setup_rsp(&sendbuf) == CORE_OK,
|
||||
return, "build error");
|
||||
d_assert(s1ap_send_to_enb(enb, sendbuf) == CORE_OK, , "send error");
|
||||
|
||||
d_assert(enb->s1ap_sock, return,);
|
||||
d_info("[S1AP] S1SetupResponse: eNB[%s:%d] <-- MME",
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
enb_id);
|
||||
}
|
||||
|
||||
void s1ap_handle_initial_ue_message(enb_ctx_t *enb, s1ap_message_t *message)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
ue_ctx_t *ue = NULL;
|
||||
S1ap_InitialUEMessage_IEs_t *ies = NULL;
|
||||
|
||||
d_assert(enb, return, "Null param");
|
||||
|
||||
ies = &message->s1ap_InitialUEMessage_IEs;
|
||||
d_assert(ies, return, "Null param");
|
||||
|
||||
ue = mme_ctx_ue_find_by_enb_ue_s1ap_id(enb, ies->eNB_UE_S1AP_ID);
|
||||
if (!ue)
|
||||
{
|
||||
ue = mme_ctx_ue_add(enb);
|
||||
d_assert(ue, return, "Null param");
|
||||
|
||||
ue->enb_ue_s1ap_id = ies->eNB_UE_S1AP_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_warn("Duplicated: eNB[0x%x] sends "
|
||||
"Initial-UE Message[eNB-UE-S1AP-ID(%d)]",
|
||||
enb->enb_id, ue->enb_ue_s1ap_id);
|
||||
}
|
||||
|
||||
d_assert(enb->s1ap_sock, mme_ctx_ue_remove(ue);return,);
|
||||
d_info("[S1AP] InitialUEMessage : UE[eNB-UE-S1AP-ID(%d)] --> eNB[%s:%d]",
|
||||
ue->enb_ue_s1ap_id,
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
enb->enb_id);
|
||||
|
||||
fsm_create((fsm_t*)&ue->emm_sm,
|
||||
ue_emm_state_initial, ue_emm_state_final);
|
||||
ue->emm_sm.ctx = ue;
|
||||
|
||||
fsm_init((fsm_t*)&ue->emm_sm, 0);
|
||||
|
||||
s1ap_send_nas_to_emm(ue, &ies->nas_pdu);
|
||||
}
|
||||
|
||||
void s1ap_handle_uplink_nas_transport(
|
||||
enb_ctx_t *enb, s1ap_message_t *message)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
ue_ctx_t *ue = NULL;
|
||||
S1ap_UplinkNASTransport_IEs_t *ies = NULL;
|
||||
|
||||
ies = &message->s1ap_UplinkNASTransport_IEs;
|
||||
d_assert(ies, return, "Null param");
|
||||
|
||||
ue = mme_ctx_ue_find_by_enb_ue_s1ap_id(enb, ies->eNB_UE_S1AP_ID);
|
||||
d_assert(ue, return, "Null param");
|
||||
|
||||
d_info("[S1AP] uplinkNASTransport : UE[eNB-UE-S1AP-ID(%d)] --> eNB[%s:%d]",
|
||||
ue->enb_ue_s1ap_id,
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
enb->enb_id);
|
||||
|
||||
s1ap_send_nas_to_emm(ue, &ies->nas_pdu);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef __S1AP_HANDLER_H__
|
||||
#define __S1AP_HANDLER_H__
|
||||
|
||||
#include "s1ap_message.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
CORE_DECLARE(void) s1ap_handle_s1_setup_request(
|
||||
enb_ctx_t *enb, s1ap_message_t *message);
|
||||
CORE_DECLARE(void) s1ap_handle_initial_ue_message(
|
||||
enb_ctx_t *enb, s1ap_message_t *message);
|
||||
CORE_DECLARE(void) s1ap_handle_uplink_nas_transport(
|
||||
enb_ctx_t *enb, s1ap_message_t *message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __S1AP_HANDLER_H__ */
|
|
@ -1,4 +1,4 @@
|
|||
#define TRACE_MODULE _s6a_auth
|
||||
#define TRACE_MODULE _s6a_sm
|
||||
|
||||
#include "core_debug.h"
|
||||
#include "core_pool.h"
|
||||
|
|
|
@ -2,27 +2,14 @@
|
|||
|
||||
#include "core_debug.h"
|
||||
|
||||
#include "3gpp_conv.h"
|
||||
#include "s1ap_message.h"
|
||||
#include "nas_message.h"
|
||||
|
||||
#include "sm.h"
|
||||
#include "context.h"
|
||||
#include "event.h"
|
||||
|
||||
#include "kdf.h"
|
||||
#include "nas_message.h"
|
||||
#include "nas_security.h"
|
||||
#include "s1ap_path.h"
|
||||
#include "s1ap_conv.h"
|
||||
#include "nas_conv.h"
|
||||
#include "s6a_sm.h"
|
||||
|
||||
static void ue_emm_handle_attach_request(
|
||||
ue_ctx_t *ue, nas_attach_request_t *attach_request);
|
||||
static void ue_emm_handle_authentication_response(
|
||||
ue_ctx_t *ue, nas_authentication_response_t *authentication_response);
|
||||
|
||||
static void ue_emm_send_to_enb(ue_ctx_t *ue, pkbuf_t *pkbuf);
|
||||
#include "nas_build.h"
|
||||
#include "emm_handler.h"
|
||||
|
||||
void ue_emm_state_initial(ue_emm_sm_t *s, event_t *e)
|
||||
{
|
||||
|
@ -78,14 +65,14 @@ void ue_emm_state_operational(ue_emm_sm_t *s, event_t *e)
|
|||
{
|
||||
case NAS_ATTACH_REQUEST:
|
||||
{
|
||||
ue_emm_handle_attach_request(
|
||||
emm_handle_attach_request(
|
||||
ue, &message.attach_request);
|
||||
break;
|
||||
}
|
||||
case NAS_AUTHENTICATION_REQUEST:
|
||||
{
|
||||
pkbuf_t *pkbuf = pkbuf_copy(recvbuf);
|
||||
ue_emm_send_to_enb(ue, pkbuf);
|
||||
nas_send_s1ap_to_enb(ue, pkbuf);
|
||||
|
||||
d_assert(ue->imsi, return,);
|
||||
d_info("[NAS] Authentication request : UE[%s] <-- EMM",
|
||||
|
@ -94,7 +81,7 @@ void ue_emm_state_operational(ue_emm_sm_t *s, event_t *e)
|
|||
}
|
||||
case NAS_AUTHENTICATION_RESPONSE:
|
||||
{
|
||||
ue_emm_handle_authentication_response(
|
||||
emm_handle_authentication_response(
|
||||
ue, &message.authentication_response);
|
||||
break;
|
||||
}
|
||||
|
@ -148,159 +135,3 @@ void ue_emm_state_exception(ue_emm_sm_t *s, event_t *e)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ue_emm_handle_attach_request(
|
||||
ue_ctx_t *ue, nas_attach_request_t *attach_request)
|
||||
{
|
||||
nas_eps_mobile_identity_t *eps_mobile_identity =
|
||||
&attach_request->eps_mobile_identity;
|
||||
|
||||
switch(eps_mobile_identity->imsi.type_of_identity)
|
||||
{
|
||||
case NAS_EPS_MOBILE_IDENTITY_IMSI:
|
||||
{
|
||||
plmn_id_t *plmn_id = &mme_self()->plmn_id;
|
||||
|
||||
if (attach_request->presencemask &
|
||||
NAS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT)
|
||||
{
|
||||
nas_tracking_area_identity_t *last_visited_registered_tai =
|
||||
&attach_request->last_visited_registered_tai;
|
||||
|
||||
plmn_id = &last_visited_registered_tai->plmn_id;
|
||||
}
|
||||
nas_imsi_bcd_to_buffer(
|
||||
&eps_mobile_identity->imsi, eps_mobile_identity->length,
|
||||
ue->imsi, &ue->imsi_len);
|
||||
|
||||
memcpy(&ue->ue_network_capability,
|
||||
&attach_request->ue_network_capability,
|
||||
sizeof(attach_request->ue_network_capability));
|
||||
memcpy(&ue->ms_network_capability,
|
||||
&attach_request->ms_network_capability,
|
||||
sizeof(attach_request->ms_network_capability));
|
||||
|
||||
d_assert(ue->imsi, return,);
|
||||
d_info("[NAS] Attach request : UE[%s] --> EMM", ue->imsi);
|
||||
|
||||
s6a_send_auth_info_req(ue, plmn_id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
d_warn("Not implemented(type:%d)",
|
||||
eps_mobile_identity->imsi.type_of_identity);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ue_emm_handle_authentication_response(
|
||||
ue_ctx_t *ue, nas_authentication_response_t *authentication_response)
|
||||
{
|
||||
nas_authentication_response_parameter_t *authentication_response_parameter =
|
||||
&authentication_response->authentication_response_parameter;
|
||||
|
||||
nas_message_t message;
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
nas_security_mode_command_t *security_mode_command =
|
||||
&message.security_mode_command;
|
||||
nas_security_algorithms_t *selected_nas_security_algorithms =
|
||||
&security_mode_command->selected_nas_security_algorithms;
|
||||
nas_key_set_identifier_t *nas_key_set_identifier =
|
||||
&security_mode_command->nas_key_set_identifier;
|
||||
nas_ue_security_capability_t *replayed_ue_security_capabilities =
|
||||
&security_mode_command->replayed_ue_security_capabilities;
|
||||
|
||||
d_assert(ue, return, "Null param");
|
||||
|
||||
if (authentication_response_parameter->length != ue->xres_len ||
|
||||
memcmp(authentication_response_parameter->res,
|
||||
ue->xres, ue->xres_len) != 0)
|
||||
{
|
||||
d_error("authentication failed");
|
||||
return;
|
||||
}
|
||||
|
||||
d_assert(ue->imsi, return, );
|
||||
d_info("[NAS] Authentication response : UE[%s] --> EMM", ue->imsi);
|
||||
|
||||
memset(&message, 0, sizeof(message));
|
||||
message.h.protocol_discriminator = NAS_PROTOCOL_DISCRIMINATOR_EMM;
|
||||
message.h.message_type = NAS_SECURITY_MODE_COMMAND;
|
||||
|
||||
selected_nas_security_algorithms->type_of_ciphering_algorithm =
|
||||
mme_self()->selected_enc_algorithm;
|
||||
selected_nas_security_algorithms->type_of_integrity_protection_algorithm =
|
||||
mme_self()->selected_int_algorithm;
|
||||
|
||||
nas_key_set_identifier->tsc = 0;
|
||||
nas_key_set_identifier->nas_key_set_identifier = 0;
|
||||
|
||||
replayed_ue_security_capabilities->length =
|
||||
sizeof(replayed_ue_security_capabilities->eea) +
|
||||
sizeof(replayed_ue_security_capabilities->eia) +
|
||||
sizeof(replayed_ue_security_capabilities->uea) +
|
||||
sizeof(replayed_ue_security_capabilities->uia) +
|
||||
sizeof(replayed_ue_security_capabilities->gea);
|
||||
replayed_ue_security_capabilities->eea = ue->ue_network_capability.eea;
|
||||
replayed_ue_security_capabilities->eia = ue->ue_network_capability.eia;
|
||||
replayed_ue_security_capabilities->uea = ue->ue_network_capability.uea;
|
||||
replayed_ue_security_capabilities->uia = ue->ue_network_capability.uia;
|
||||
replayed_ue_security_capabilities->gea =
|
||||
(ue->ms_network_capability.gea1 << 6) |
|
||||
ue->ms_network_capability.extended_gea;
|
||||
|
||||
mme_kdf_nas(MME_KDF_NAS_INT_ALG, mme_self()->selected_int_algorithm,
|
||||
ue->kasme, ue->knas_int);
|
||||
mme_kdf_nas(MME_KDF_NAS_ENC_ALG, mme_self()->selected_enc_algorithm,
|
||||
ue->kasme, ue->knas_enc);
|
||||
|
||||
message.h.security_header_type =
|
||||
NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_NEW_SECURITY_CONTEXT;
|
||||
d_assert(nas_security_encode(&sendbuf, ue, &message) == CORE_OK &&
|
||||
sendbuf,,);
|
||||
ue_emm_send_to_enb(ue, sendbuf);
|
||||
|
||||
d_assert(ue->imsi, return,);
|
||||
d_info("[NAS] Security mode command : UE[%s] <-- EMM", ue->imsi);
|
||||
}
|
||||
|
||||
static void ue_emm_send_to_enb(ue_ctx_t *ue, pkbuf_t *pkbuf)
|
||||
{
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
int encoded;
|
||||
s1ap_message_t message;
|
||||
S1ap_DownlinkNASTransport_IEs_t *ies =
|
||||
&message.s1ap_DownlinkNASTransport_IEs;
|
||||
S1ap_NAS_PDU_t *nasPdu = &ies->nas_pdu;
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
|
||||
memset(&message, 0, sizeof(s1ap_message_t));
|
||||
|
||||
ies->mme_ue_s1ap_id = ue->mme_ue_s1ap_id;
|
||||
ies->eNB_UE_S1AP_ID = ue->enb_ue_s1ap_id;
|
||||
|
||||
nasPdu->size = pkbuf->len;
|
||||
nasPdu->buf = core_calloc(nasPdu->size, sizeof(c_uint8_t));
|
||||
memcpy(nasPdu->buf, pkbuf->payload, nasPdu->size);
|
||||
|
||||
message.procedureCode = S1ap_ProcedureCode_id_downlinkNASTransport;
|
||||
message.direction = S1AP_PDU_PR_initiatingMessage;
|
||||
|
||||
encoded = s1ap_encode_pdu(&sendbuf, &message);
|
||||
s1ap_free_pdu(&message);
|
||||
|
||||
d_assert(sendbuf && encoded >= 0,,);
|
||||
d_assert(s1ap_send_to_enb(ue->enb, sendbuf) == CORE_OK,,);
|
||||
pkbuf_free(pkbuf);
|
||||
|
||||
d_assert(ue->enb,,);
|
||||
d_info("[S1AP] downlinkNASTransport : "
|
||||
"UE[eNB-UE-S1AP-ID(%d)] <-- eNB[%s:%d]",
|
||||
ue->enb_ue_s1ap_id,
|
||||
INET_NTOP(&ue->enb->s1ap_sock->remote.sin_addr.s_addr, buf),
|
||||
ue->enb->enb_id);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue