@ -31,9 +31,9 @@
using srslte : : s1ap_mccmnc_to_plmn ;
using srslte : : s1ap_mccmnc_to_plmn ;
using srslte : : uint32_to_uint8 ;
using srslte : : uint32_to_uint8 ;
# define procError(fmt, ...) s1ap_ptr-> s1ap_log-> error("Proc \"%s\" - " fmt, name(), ##__VA_ARGS__)
# define procError(fmt, ...) s1ap_ptr-> logger. error("Proc \"%s\" - " fmt, name(), ##__VA_ARGS__)
# define procWarning(fmt, ...) s1ap_ptr-> s1ap_log-> warning("Proc \"%s\" - " fmt, name(), ##__VA_ARGS__)
# define procWarning(fmt, ...) s1ap_ptr-> logger. warning("Proc \"%s\" - " fmt, name(), ##__VA_ARGS__)
# define procInfo(fmt, ...) s1ap_ptr-> s1ap_log-> info("Proc \"%s\" - " fmt, name(), ##__VA_ARGS__)
# define procInfo(fmt, ...) s1ap_ptr-> logger. info("Proc \"%s\" - " fmt, name(), ##__VA_ARGS__)
using namespace asn1 : : s1ap ;
using namespace asn1 : : s1ap ;
@ -62,9 +62,9 @@ srslte::proc_outcome_t s1ap::ue::ho_prep_proc_t::init(uint32_t
target_eci = target_eci_ ;
target_eci = target_eci_ ;
target_plmn = target_plmn_ ;
target_plmn = target_plmn_ ;
procInfo ( " Sending HandoverRequired to MME id=%d \n " , ue_ptr - > ctxt . mme_ue_s1ap_id ) ;
procInfo ( " Sending HandoverRequired to MME id=%d " , ue_ptr - > ctxt . mme_ue_s1ap_id ) ;
if ( not ue_ptr - > send_ho_required ( target_eci , target_plmn , std : : move ( rrc_container_ ) ) ) {
if ( not ue_ptr - > send_ho_required ( target_eci , target_plmn , std : : move ( rrc_container_ ) ) ) {
procError ( " Failed to send HORequired to cell 0x%x \n " , target_eci ) ;
procError ( " Failed to send HORequired to cell 0x%x " , target_eci ) ;
return srslte : : proc_outcome_t : : error ;
return srslte : : proc_outcome_t : : error ;
}
}
@ -76,7 +76,7 @@ srslte::proc_outcome_t s1ap::ue::ho_prep_proc_t::init(uint32_t
srslte : : proc_outcome_t s1ap : : ue : : ho_prep_proc_t : : react ( ts1_reloc_prep_expired e )
srslte : : proc_outcome_t s1ap : : ue : : ho_prep_proc_t : : react ( ts1_reloc_prep_expired e )
{
{
// do nothing for now
// do nothing for now
procError ( " timer TS1Relocprep has expired. \n " ) ;
procError ( " timer TS1Relocprep has expired. " ) ;
return srslte : : proc_outcome_t : : error ;
return srslte : : proc_outcome_t : : error ;
}
}
srslte : : proc_outcome_t s1ap : : ue : : ho_prep_proc_t : : react ( const ho_prep_fail_s & msg )
srslte : : proc_outcome_t s1ap : : ue : : ho_prep_proc_t : : react ( const ho_prep_fail_s & msg )
@ -84,7 +84,7 @@ srslte::proc_outcome_t s1ap::ue::ho_prep_proc_t::react(const ho_prep_fail_s& msg
ue_ptr - > ts1_reloc_prep . stop ( ) ;
ue_ptr - > ts1_reloc_prep . stop ( ) ;
std : : string cause = s1ap_ptr - > get_cause ( msg . protocol_ies . cause . value ) ;
std : : string cause = s1ap_ptr - > get_cause ( msg . protocol_ies . cause . value ) ;
procError ( " HO preparation Failure. Cause: %s \n " , cause . c_str ( ) ) ;
procError ( " HO preparation Failure. Cause: %s " , cause . c_str ( ) ) ;
srslte : : console ( " HO preparation Failure. Cause: %s \n " , cause . c_str ( ) ) ;
srslte : : console ( " HO preparation Failure. Cause: %s \n " , cause . c_str ( ) ) ;
return srslte : : proc_outcome_t : : error ;
return srslte : : proc_outcome_t : : error ;
@ -104,18 +104,18 @@ srslte::proc_outcome_t s1ap::ue::ho_prep_proc_t::react(const asn1::s1ap::ho_cmd_
if ( msg . ext or msg . protocol_ies . target_to_source_transparent_container_secondary_present or
if ( msg . ext or msg . protocol_ies . target_to_source_transparent_container_secondary_present or
msg . protocol_ies . handov_type . value . value ! = handov_type_opts : : intralte or
msg . protocol_ies . handov_type . value . value ! = handov_type_opts : : intralte or
msg . protocol_ies . crit_diagnostics_present or msg . protocol_ies . nas_security_paramsfrom_e_utran_present ) {
msg . protocol_ies . crit_diagnostics_present or msg . protocol_ies . nas_security_paramsfrom_e_utran_present ) {
procWarning ( " Not handling HandoverCommand extensions and non-intraLTE params \n " ) ;
procWarning ( " Not handling HandoverCommand extensions and non-intraLTE params " ) ;
}
}
// Check for E-RABs that could not be admitted in the target
// Check for E-RABs that could not be admitted in the target
if ( msg . protocol_ies . erab_to_release_list_ho_cmd_present ) {
if ( msg . protocol_ies . erab_to_release_list_ho_cmd_present ) {
procWarning ( " Not handling E-RABtoReleaseList \n " ) ;
procWarning ( " Not handling E-RABtoReleaseList " ) ;
// TODO
// TODO
}
}
// Check for E-RABs subject to being forwarded
// Check for E-RABs subject to being forwarded
if ( msg . protocol_ies . erab_subjectto_data_forwarding_list_present ) {
if ( msg . protocol_ies . erab_subjectto_data_forwarding_list_present ) {
procWarning ( " Not handling E-RABSubjecttoDataForwardingList \n " ) ;
procWarning ( " Not handling E-RABSubjecttoDataForwardingList " ) ;
// TODO
// TODO
}
}
@ -125,17 +125,17 @@ srslte::proc_outcome_t s1ap::ue::ho_prep_proc_t::react(const asn1::s1ap::ho_cmd_
msg . protocol_ies . target_to_source_transparent_container . value . size ( ) ) ;
msg . protocol_ies . target_to_source_transparent_container . value . size ( ) ) ;
asn1 : : s1ap : : targetenb_to_sourceenb_transparent_container_s container ;
asn1 : : s1ap : : targetenb_to_sourceenb_transparent_container_s container ;
if ( container . unpack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
if ( container . unpack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
procError ( " Failed to decode TargeteNBToSourceeNBTransparentContainer \n " ) ;
procError ( " Failed to decode TargeteNBToSourceeNBTransparentContainer " ) ;
return srslte : : proc_outcome_t : : error ;
return srslte : : proc_outcome_t : : error ;
}
}
if ( container . ie_exts_present or container . ext ) {
if ( container . ie_exts_present or container . ext ) {
procWarning ( " Not handling extensions \n " ) ;
procWarning ( " Not handling extensions " ) ;
}
}
// Create a unique buffer out of transparent container to pass to RRC
// Create a unique buffer out of transparent container to pass to RRC
rrc_container = srslte : : allocate_unique_buffer ( * s1ap_ptr - > pool , false ) ;
rrc_container = srslte : : allocate_unique_buffer ( * s1ap_ptr - > pool , false ) ;
if ( rrc_container = = nullptr ) {
if ( rrc_container = = nullptr ) {
procError ( " Fatal Error: Couldn't allocate buffer. \n " ) ;
procError ( " Fatal Error: Couldn't allocate buffer. " ) ;
return srslte : : proc_outcome_t : : error ;
return srslte : : proc_outcome_t : : error ;
}
}
memcpy ( rrc_container - > msg , container . rrc_container . data ( ) , container . rrc_container . size ( ) ) ;
memcpy ( rrc_container - > msg , container . rrc_container . data ( ) , container . rrc_container . size ( ) ) ;
@ -150,7 +150,7 @@ void s1ap::ue::ho_prep_proc_t::then(const srslte::proc_state_t& result)
s1ap_ptr - > rrc - > ho_preparation_complete ( ue_ptr - > ctxt . rnti , false , { } ) ;
s1ap_ptr - > rrc - > ho_preparation_complete ( ue_ptr - > ctxt . rnti , false , { } ) ;
} else {
} else {
s1ap_ptr - > rrc - > ho_preparation_complete ( ue_ptr - > ctxt . rnti , true , std : : move ( rrc_container ) ) ;
s1ap_ptr - > rrc - > ho_preparation_complete ( ue_ptr - > ctxt . rnti , true , std : : move ( rrc_container ) ) ;
procInfo ( " Completed with success \n " ) ;
procInfo ( " Completed with success " ) ;
}
}
}
}
@ -160,23 +160,23 @@ void s1ap::ue::ho_prep_proc_t::then(const srslte::proc_state_t& result)
srslte : : proc_outcome_t s1ap : : s1_setup_proc_t : : init ( )
srslte : : proc_outcome_t s1ap : : s1_setup_proc_t : : init ( )
{
{
procInfo ( " Starting new MME connection. \n " ) ;
procInfo ( " Starting new MME connection. " ) ;
return start_mme_connection ( ) ;
return start_mme_connection ( ) ;
}
}
srslte : : proc_outcome_t s1ap : : s1_setup_proc_t : : start_mme_connection ( )
srslte : : proc_outcome_t s1ap : : s1_setup_proc_t : : start_mme_connection ( )
{
{
if ( not s1ap_ptr - > running ) {
if ( not s1ap_ptr - > running ) {
procInfo ( " S1AP is not running anymore. \n " ) ;
procInfo ( " S1AP is not running anymore. " ) ;
return srslte : : proc_outcome_t : : error ;
return srslte : : proc_outcome_t : : error ;
}
}
if ( s1ap_ptr - > mme_connected ) {
if ( s1ap_ptr - > mme_connected ) {
procInfo ( " eNB S1AP is already connected to MME \n " ) ;
procInfo ( " eNB S1AP is already connected to MME " ) ;
return srslte : : proc_outcome_t : : success ;
return srslte : : proc_outcome_t : : success ;
}
}
if ( not s1ap_ptr - > connect_mme ( ) ) {
if ( not s1ap_ptr - > connect_mme ( ) ) {
procInfo ( " Failed to initiate SCTP socket. Attempting reconnection in %d seconds \n " ,
procInfo ( " Failed to initiate SCTP socket. Attempting reconnection in %d seconds " ,
s1ap_ptr - > mme_connect_timer . duration ( ) / 1000 ) ;
s1ap_ptr - > mme_connect_timer . duration ( ) / 1000 ) ;
srslte : : console ( " Failed to initiate SCTP socket. Attempting reconnection in %d seconds \n " ,
srslte : : console ( " Failed to initiate SCTP socket. Attempting reconnection in %d seconds \n " ,
s1ap_ptr - > mme_connect_timer . duration ( ) / 1000 ) ;
s1ap_ptr - > mme_connect_timer . duration ( ) / 1000 ) ;
@ -185,14 +185,14 @@ srslte::proc_outcome_t s1ap::s1_setup_proc_t::start_mme_connection()
}
}
if ( not s1ap_ptr - > setup_s1 ( ) ) {
if ( not s1ap_ptr - > setup_s1 ( ) ) {
procError ( " S1 setup failed. Exiting... \n " ) ;
procError ( " S1 setup failed. Exiting... " ) ;
srslte : : console ( " S1 setup failed \n " ) ;
srslte : : console ( " S1 setup failed \n " ) ;
s1ap_ptr - > running = false ;
s1ap_ptr - > running = false ;
return srslte : : proc_outcome_t : : error ;
return srslte : : proc_outcome_t : : error ;
}
}
s1ap_ptr - > s1setup_timeout . run ( ) ;
s1ap_ptr - > s1setup_timeout . run ( ) ;
procInfo ( " S1SetupRequest sent. Waiting for response... \n " ) ;
procInfo ( " S1SetupRequest sent. Waiting for response... " ) ;
return srslte : : proc_outcome_t : : yield ;
return srslte : : proc_outcome_t : : yield ;
}
}
@ -202,10 +202,10 @@ srslte::proc_outcome_t s1ap::s1_setup_proc_t::react(const srsenb::s1ap::s1_setup
s1ap_ptr - > s1setup_timeout . stop ( ) ;
s1ap_ptr - > s1setup_timeout . stop ( ) ;
}
}
if ( event . success ) {
if ( event . success ) {
procInfo ( " S1Setup procedure completed successfully \n " ) ;
procInfo ( " S1Setup procedure completed successfully " ) ;
return srslte : : proc_outcome_t : : success ;
return srslte : : proc_outcome_t : : success ;
}
}
procError ( " S1Setup failed. Exiting... \n " ) ;
procError ( " S1Setup failed. Exiting... " ) ;
srslte : : console ( " S1setup failed \n " ) ;
srslte : : console ( " S1setup failed \n " ) ;
return srslte : : proc_outcome_t : : error ;
return srslte : : proc_outcome_t : : error ;
}
}
@ -214,7 +214,7 @@ void s1ap::s1_setup_proc_t::then(const srslte::proc_state_t& result) const
{
{
if ( result . is_error ( ) ) {
if ( result . is_error ( ) ) {
s1ap_ptr - > s1ap_socket . reset ( ) ;
s1ap_ptr - > s1ap_socket . reset ( ) ;
procInfo ( " S1AP socket closed. \n " ) ;
procInfo ( " S1AP socket closed. " ) ;
}
}
}
}
@ -222,15 +222,16 @@ void s1ap::s1_setup_proc_t::then(const srslte::proc_state_t& result) const
* S1AP class
* S1AP class
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
s1ap : : s1ap ( srslte : : task_sched_handle task_sched_ ) : s1setup_proc ( this ) , task_sched ( task_sched_ ) { }
s1ap : : s1ap ( srslte : : task_sched_handle task_sched_ , srslog : : basic_logger & logger ) :
s1setup_proc ( this ) , logger ( logger ) , task_sched ( task_sched_ )
{ }
int s1ap : : init ( s1ap_args_t args_ , rrc_interface_s1ap * rrc_ , srsenb : : stack_interface_s1ap_lte * stack_ )
int s1ap : : init ( s1ap_args_t args_ , rrc_interface_s1ap * rrc_ , srsenb : : stack_interface_s1ap_lte * stack_ )
{
{
rrc = rrc_ ;
rrc = rrc_ ;
args = args_ ;
args = args_ ;
s1ap_log = srslte : : logmap : : get ( " S1AP " ) ;
stack = stack_ ;
stack = stack_ ;
pool = srslte : : byte_buffer_pool : : get_instance ( ) ;
pool = srslte : : byte_buffer_pool : : get_instance ( ) ;
build_tai_cgi ( ) ;
build_tai_cgi ( ) ;
@ -238,7 +239,7 @@ int s1ap::init(s1ap_args_t args_, rrc_interface_s1ap* rrc_, srsenb::stack_interf
mme_connect_timer = task_sched . get_unique_timer ( ) ;
mme_connect_timer = task_sched . get_unique_timer ( ) ;
auto mme_connect_run = [ this ] ( uint32_t tid ) {
auto mme_connect_run = [ this ] ( uint32_t tid ) {
if ( not s1setup_proc . launch ( ) ) {
if ( not s1setup_proc . launch ( ) ) {
s1ap_log- > error ( " Failed to initiate S1Setup procedure. \n " ) ;
logger. error ( " Failed to initiate S1Setup procedure. " ) ;
}
}
} ;
} ;
mme_connect_timer . set ( 10000 , mme_connect_run ) ;
mme_connect_timer . set ( 10000 , mme_connect_run ) ;
@ -255,7 +256,7 @@ int s1ap::init(s1ap_args_t args_, rrc_interface_s1ap* rrc_, srsenb::stack_interf
running = true ;
running = true ;
// starting MME connection
// starting MME connection
if ( not s1setup_proc . launch ( ) ) {
if ( not s1setup_proc . launch ( ) ) {
s1ap_log- > error ( " Failed to initiate S1Setup procedure. \n " ) ;
logger. error ( " Failed to initiate S1Setup procedure. " ) ;
}
}
return SRSLTE_SUCCESS ;
return SRSLTE_SUCCESS ;
@ -306,7 +307,7 @@ void s1ap::initial_ue(uint16_t rnti, asn1::s1ap::rrc_establishment_cause_e cause
ue_ptr - > ctxt . rnti = rnti ;
ue_ptr - > ctxt . rnti = rnti ;
ue * u = users . add_user ( std : : move ( ue_ptr ) ) ;
ue * u = users . add_user ( std : : move ( ue_ptr ) ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
s1ap_log- > error ( " Failed to add rnti=0x%x \n " , rnti ) ;
logger. error ( " Failed to add rnti=0x%x " , rnti ) ;
return ;
return ;
}
}
u - > send_initialuemessage ( cause , std : : move ( pdu ) , false ) ;
u - > send_initialuemessage ( cause , std : : move ( pdu ) , false ) ;
@ -322,7 +323,7 @@ void s1ap::initial_ue(uint16_t rnti,
ue_ptr - > ctxt . rnti = rnti ;
ue_ptr - > ctxt . rnti = rnti ;
ue * u = users . add_user ( std : : move ( ue_ptr ) ) ;
ue * u = users . add_user ( std : : move ( ue_ptr ) ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
s1ap_log- > error ( " Failed to add rnti=0x%x \n " , rnti ) ;
logger. error ( " Failed to add rnti=0x%x " , rnti ) ;
return ;
return ;
}
}
u - > send_initialuemessage ( cause , std : : move ( pdu ) , true , m_tmsi , mmec ) ;
u - > send_initialuemessage ( cause , std : : move ( pdu ) , true , m_tmsi , mmec ) ;
@ -330,11 +331,11 @@ void s1ap::initial_ue(uint16_t rnti,
void s1ap : : write_pdu ( uint16_t rnti , srslte : : unique_byte_buffer_t pdu )
void s1ap : : write_pdu ( uint16_t rnti , srslte : : unique_byte_buffer_t pdu )
{
{
s1ap_log- > info_hex ( pdu - > msg , pdu - > N_bytes , " Received RRC SDU " ) ;
logger. info ( pdu - > msg , pdu - > N_bytes , " Received RRC SDU " ) ;
ue * u = users . find_ue_rnti ( rnti ) ;
ue * u = users . find_ue_rnti ( rnti ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
s1ap_log- > info ( " The rnti=0x%x does not exist \n " , rnti ) ;
logger. info ( " The rnti=0x%x does not exist " , rnti ) ;
return ;
return ;
}
}
u - > send_ulnastransport ( std : : move ( pdu ) ) ;
u - > send_ulnastransport ( std : : move ( pdu ) ) ;
@ -342,7 +343,7 @@ void s1ap::write_pdu(uint16_t rnti, srslte::unique_byte_buffer_t pdu)
bool s1ap : : user_release ( uint16_t rnti , asn1 : : s1ap : : cause_radio_network_e cause_radio )
bool s1ap : : user_release ( uint16_t rnti , asn1 : : s1ap : : cause_radio_network_e cause_radio )
{
{
s1ap_log- > info ( " User inactivity - RNTI:0x%x \n " , rnti ) ;
logger. info ( " User inactivity - RNTI:0x%x " , rnti ) ;
ue * u = users . find_ue_rnti ( rnti ) ;
ue * u = users . find_ue_rnti ( rnti ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
@ -350,7 +351,7 @@ bool s1ap::user_release(uint16_t rnti, asn1::s1ap::cause_radio_network_e cause_r
}
}
if ( u - > was_uectxtrelease_requested ( ) ) {
if ( u - > was_uectxtrelease_requested ( ) ) {
s1ap_log- > warning ( " UE context for RNTI:0x%x is in zombie state. Releasing... \n " , rnti ) ;
logger. warning ( " UE context for RNTI:0x%x is in zombie state. Releasing... " , rnti ) ;
users . erase ( u ) ;
users . erase ( u ) ;
rrc - > release_complete ( rnti ) ;
rrc - > release_complete ( rnti ) ;
return false ;
return false ;
@ -372,13 +373,13 @@ bool s1ap::user_exists(uint16_t rnti)
void s1ap : : user_mod ( uint16_t old_rnti , uint16_t new_rnti )
void s1ap : : user_mod ( uint16_t old_rnti , uint16_t new_rnti )
{
{
s1ap_log- > info ( " Modifying user context. Old rnti: 0x%x, new rnti: 0x%x \n " , old_rnti , new_rnti ) ;
logger. info ( " Modifying user context. Old rnti: 0x%x, new rnti: 0x%x " , old_rnti , new_rnti ) ;
if ( not user_exists ( old_rnti ) ) {
if ( not user_exists ( old_rnti ) ) {
s1ap_log- > error ( " Old rnti does not exist, aborting. \n " ) ;
logger. error ( " Old rnti does not exist, aborting. " ) ;
return ;
return ;
}
}
if ( user_exists ( new_rnti ) ) {
if ( user_exists ( new_rnti ) ) {
s1ap_log- > error ( " New rnti already exists, aborting. \n " ) ;
logger. error ( " New rnti already exists, aborting. " ) ;
return ;
return ;
}
}
users . find_ue_rnti ( old_rnti ) - > ctxt . rnti = new_rnti ;
users . find_ue_rnti ( old_rnti ) - > ctxt . rnti = new_rnti ;
@ -401,7 +402,7 @@ void s1ap::ue_erab_setup_complete(uint16_t rnti, const asn1::s1ap::erab_setup_re
{
{
ue * u = users . find_ue_rnti ( rnti ) ;
ue * u = users . find_ue_rnti ( rnti ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
s1ap_log- > error ( " rnti 0x%x not found \n " , rnti ) ;
logger. error ( " rnti 0x%x not found " , rnti ) ;
return ;
return ;
}
}
u - > send_erab_setup_response ( res ) ;
u - > send_erab_setup_response ( res ) ;
@ -423,7 +424,7 @@ bool s1ap::is_mme_connected()
bool s1ap : : connect_mme ( )
bool s1ap : : connect_mme ( )
{
{
s1ap_log- > info ( " Connecting to MME %s:%d \n " , args . mme_addr . c_str ( ) , MME_PORT ) ;
logger. info ( " Connecting to MME %s:%d " , args . mme_addr . c_str ( ) , int ( MME_PORT ) ) ;
// Init SCTP socket and bind it
// Init SCTP socket and bind it
if ( not srslte : : net_utils : : sctp_init_client (
if ( not srslte : : net_utils : : sctp_init_client (
@ -439,7 +440,7 @@ bool s1ap::connect_mme()
// Assign a handler to rx MME packets (going to run in a different thread)
// Assign a handler to rx MME packets (going to run in a different thread)
stack - > add_mme_socket ( s1ap_socket . fd ( ) ) ;
stack - > add_mme_socket ( s1ap_socket . fd ( ) ) ;
s1ap_log- > info ( " SCTP socket established with MME \n " ) ;
logger. info ( " SCTP socket established with MME " ) ;
return true ;
return true ;
}
}
@ -492,21 +493,21 @@ bool s1ap::handle_mme_rx_msg(srslte::unique_byte_buffer_t pdu,
if ( flags & MSG_NOTIFICATION ) {
if ( flags & MSG_NOTIFICATION ) {
// Received notification
// Received notification
union sctp_notification * notification = ( union sctp_notification * ) pdu - > msg ;
union sctp_notification * notification = ( union sctp_notification * ) pdu - > msg ;
s1ap_log- > debug ( " SCTP Notification %d \n " , notification - > sn_header . sn_type ) ;
logger. debug ( " SCTP Notification %d " , notification - > sn_header . sn_type ) ;
if ( notification - > sn_header . sn_type = = SCTP_SHUTDOWN_EVENT ) {
if ( notification - > sn_header . sn_type = = SCTP_SHUTDOWN_EVENT ) {
s1ap_log- > info ( " SCTP Association Shutdown. Association: %d \n " , sri . sinfo_assoc_id ) ;
logger. info ( " SCTP Association Shutdown. Association: %d " , sri . sinfo_assoc_id ) ;
srslte : : console ( " SCTP Association Shutdown. Association: %d \n " , sri . sinfo_assoc_id ) ;
srslte : : console ( " SCTP Association Shutdown. Association: %d \n " , sri . sinfo_assoc_id ) ;
stack - > remove_mme_socket ( s1ap_socket . get_socket ( ) ) ;
stack - > remove_mme_socket ( s1ap_socket . get_socket ( ) ) ;
s1ap_socket . reset ( ) ;
s1ap_socket . reset ( ) ;
} else if ( notification - > sn_header . sn_type = = SCTP_PEER_ADDR_CHANGE & &
} else if ( notification - > sn_header . sn_type = = SCTP_PEER_ADDR_CHANGE & &
notification - > sn_paddr_change . spc_state = = SCTP_ADDR_UNREACHABLE ) {
notification - > sn_paddr_change . spc_state = = SCTP_ADDR_UNREACHABLE ) {
s1ap_log- > info ( " SCTP peer addres unreachable. Association: %d \n " , sri . sinfo_assoc_id ) ;
logger. info ( " SCTP peer addres unreachable. Association: %d " , sri . sinfo_assoc_id ) ;
srslte : : console ( " SCTP peer address unreachable. Association: %d \n " , sri . sinfo_assoc_id ) ;
srslte : : console ( " SCTP peer address unreachable. Association: %d \n " , sri . sinfo_assoc_id ) ;
stack - > remove_mme_socket ( s1ap_socket . get_socket ( ) ) ;
stack - > remove_mme_socket ( s1ap_socket . get_socket ( ) ) ;
s1ap_socket . reset ( ) ;
s1ap_socket . reset ( ) ;
}
}
} else if ( pdu - > N_bytes = = 0 ) {
} else if ( pdu - > N_bytes = = 0 ) {
s1ap_log- > error ( " SCTP return 0 bytes. Closing socket \n " ) ;
logger. error ( " SCTP return 0 bytes. Closing socket " ) ;
s1ap_socket . reset ( ) ;
s1ap_socket . reset ( ) ;
}
}
@ -514,12 +515,12 @@ bool s1ap::handle_mme_rx_msg(srslte::unique_byte_buffer_t pdu,
if ( not s1ap_socket . is_init ( ) ) {
if ( not s1ap_socket . is_init ( ) ) {
mme_connected = false ;
mme_connected = false ;
if ( not s1setup_proc . launch ( ) ) {
if ( not s1setup_proc . launch ( ) ) {
s1ap_log- > error ( " Failed to initiate MME connection procedure. \n " ) ;
logger. error ( " Failed to initiate MME connection procedure. " ) ;
}
}
return false ;
return false ;
}
}
s1ap_log- > info_hex ( pdu - > msg , pdu - > N_bytes , " Received S1AP PDU " ) ;
logger. info ( pdu - > msg , pdu - > N_bytes , " Received S1AP PDU " ) ;
handle_s1ap_rx_pdu ( pdu . get ( ) ) ;
handle_s1ap_rx_pdu ( pdu . get ( ) ) ;
return true ;
return true ;
}
}
@ -535,7 +536,7 @@ bool s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t* pdu)
asn1 : : cbit_ref bref ( pdu - > msg , pdu - > N_bytes ) ;
asn1 : : cbit_ref bref ( pdu - > msg , pdu - > N_bytes ) ;
if ( rx_pdu . unpack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
if ( rx_pdu . unpack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
s1ap_log- > error ( " Failed to unpack received PDU \n " ) ;
logger. error ( " Failed to unpack received PDU " ) ;
return false ;
return false ;
}
}
@ -547,7 +548,7 @@ bool s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t* pdu)
case s1ap_pdu_c : : types_opts : : unsuccessful_outcome :
case s1ap_pdu_c : : types_opts : : unsuccessful_outcome :
return handle_unsuccessfuloutcome ( rx_pdu . unsuccessful_outcome ( ) ) ;
return handle_unsuccessfuloutcome ( rx_pdu . unsuccessful_outcome ( ) ) ;
default :
default :
s1ap_log- > error ( " Unhandled PDU type %d \n " , rx_pdu . type ( ) . value ) ;
logger. error ( " Unhandled PDU type %d " , rx_pdu . type ( ) . value ) ;
return false ;
return false ;
}
}
@ -578,7 +579,7 @@ bool s1ap::handle_initiatingmessage(const init_msg_s& msg)
case s1ap_elem_procs_o : : init_msg_c : : types_opts : : mme_status_transfer :
case s1ap_elem_procs_o : : init_msg_c : : types_opts : : mme_status_transfer :
return handle_mme_status_transfer ( msg . value . mme_status_transfer ( ) ) ;
return handle_mme_status_transfer ( msg . value . mme_status_transfer ( ) ) ;
default :
default :
s1ap_log- > error ( " Unhandled initiating message: %s \n " , msg . value . type ( ) . to_string ( ) . c_str ( ) ) ;
logger. error ( " Unhandled initiating message: %s " , msg . value . type ( ) . to_string ( ) . c_str ( ) ) ;
}
}
return true ;
return true ;
}
}
@ -591,10 +592,10 @@ bool s1ap::handle_successfuloutcome(const successful_outcome_s& msg)
case s1ap_elem_procs_o : : successful_outcome_c : : types_opts : : ho_cmd :
case s1ap_elem_procs_o : : successful_outcome_c : : types_opts : : ho_cmd :
return handle_s1hocommand ( msg . value . ho_cmd ( ) ) ;
return handle_s1hocommand ( msg . value . ho_cmd ( ) ) ;
case s1ap_elem_procs_o : : successful_outcome_c : : types_opts : : ho_cancel_ack :
case s1ap_elem_procs_o : : successful_outcome_c : : types_opts : : ho_cancel_ack :
s1ap_log- > info ( " Received %s \n " , msg . value . type ( ) . to_string ( ) . c_str ( ) ) ;
logger. info ( " Received %s " , msg . value . type ( ) . to_string ( ) . c_str ( ) ) ;
return true ;
return true ;
default :
default :
s1ap_log- > error ( " Unhandled successful outcome message: %s \n " , msg . value . type ( ) . to_string ( ) . c_str ( ) ) ;
logger. error ( " Unhandled successful outcome message: %s " , msg . value . type ( ) . to_string ( ) . c_str ( ) ) ;
}
}
return true ;
return true ;
}
}
@ -607,14 +608,14 @@ bool s1ap::handle_unsuccessfuloutcome(const unsuccessful_outcome_s& msg)
case s1ap_elem_procs_o : : unsuccessful_outcome_c : : types_opts : : ho_prep_fail :
case s1ap_elem_procs_o : : unsuccessful_outcome_c : : types_opts : : ho_prep_fail :
return handle_hopreparationfailure ( msg . value . ho_prep_fail ( ) ) ;
return handle_hopreparationfailure ( msg . value . ho_prep_fail ( ) ) ;
default :
default :
s1ap_log- > error ( " Unhandled unsuccessful outcome message: %s \n " , msg . value . type ( ) . to_string ( ) . c_str ( ) ) ;
logger. error ( " Unhandled unsuccessful outcome message: %s " , msg . value . type ( ) . to_string ( ) . c_str ( ) ) ;
}
}
return true ;
return true ;
}
}
bool s1ap : : handle_s1setupresponse ( const asn1 : : s1ap : : s1_setup_resp_s & msg )
bool s1ap : : handle_s1setupresponse ( const asn1 : : s1ap : : s1_setup_resp_s & msg )
{
{
s1ap_log- > info ( " Received S1SetupResponse \n " ) ;
logger. info ( " Received S1SetupResponse " ) ;
s1setupresponse = msg ;
s1setupresponse = msg ;
mme_connected = true ;
mme_connected = true ;
s1_setup_proc_t : : s1setupresult res ;
s1_setup_proc_t : : s1setupresult res ;
@ -625,9 +626,9 @@ bool s1ap::handle_s1setupresponse(const asn1::s1ap::s1_setup_resp_s& msg)
bool s1ap : : handle_dlnastransport ( const dl_nas_transport_s & msg )
bool s1ap : : handle_dlnastransport ( const dl_nas_transport_s & msg )
{
{
s1ap_log- > info ( " Received DownlinkNASTransport \n " ) ;
logger. info ( " Received DownlinkNASTransport " ) ;
if ( msg . ext ) {
if ( msg . ext ) {
s1ap_log- > warning ( " Not handling S1AP message extensio n\ n" ) ;
logger. warning ( " Not handling S1AP message extensio n" ) ;
}
}
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
@ -635,15 +636,15 @@ bool s1ap::handle_dlnastransport(const dl_nas_transport_s& msg)
}
}
if ( msg . protocol_ies . ho_restrict_list_present ) {
if ( msg . protocol_ies . ho_restrict_list_present ) {
s1ap_log- > warning ( " Not handling HandoverRestrictionList \n " ) ;
logger. warning ( " Not handling HandoverRestrictionList " ) ;
}
}
if ( msg . protocol_ies . subscriber_profile_idfor_rfp_present ) {
if ( msg . protocol_ies . subscriber_profile_idfor_rfp_present ) {
s1ap_log- > warning ( " Not handling SubscriberProfileIDforRFP \n " ) ;
logger. warning ( " Not handling SubscriberProfileIDforRFP " ) ;
}
}
srslte : : unique_byte_buffer_t pdu = srslte : : allocate_unique_buffer ( * pool ) ;
srslte : : unique_byte_buffer_t pdu = srslte : : allocate_unique_buffer ( * pool ) ;
if ( pdu = = nullptr ) {
if ( pdu = = nullptr ) {
s1ap_log- > error ( " Fatal Error: Couldn't allocate buffer in s1ap::run_thread(). \n " ) ;
logger. error ( " Fatal Error: Couldn't allocate buffer in s1ap::run_thread(). " ) ;
return false ;
return false ;
}
}
memcpy ( pdu - > msg , msg . protocol_ies . nas_pdu . value . data ( ) , msg . protocol_ies . nas_pdu . value . size ( ) ) ;
memcpy ( pdu - > msg , msg . protocol_ies . nas_pdu . value . data ( ) , msg . protocol_ies . nas_pdu . value . size ( ) ) ;
@ -654,9 +655,9 @@ bool s1ap::handle_dlnastransport(const dl_nas_transport_s& msg)
bool s1ap : : handle_initialctxtsetuprequest ( const init_context_setup_request_s & msg )
bool s1ap : : handle_initialctxtsetuprequest ( const init_context_setup_request_s & msg )
{
{
s1ap_log- > info ( " Received InitialContextSetupRequest \n " ) ;
logger. info ( " Received InitialContextSetupRequest " ) ;
if ( msg . ext ) {
if ( msg . ext ) {
s1ap_log- > warning ( " Not handling S1AP message extensio n\ n" ) ;
logger. warning ( " Not handling S1AP message extensio n" ) ;
}
}
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
@ -687,7 +688,7 @@ bool s1ap::handle_initialctxtsetuprequest(const init_context_setup_request_s& ms
bool s1ap : : handle_paging ( const asn1 : : s1ap : : paging_s & msg )
bool s1ap : : handle_paging ( const asn1 : : s1ap : : paging_s & msg )
{
{
if ( msg . ext ) {
if ( msg . ext ) {
s1ap_log- > warning ( " Not handling S1AP message extensio n\ n" ) ;
logger. warning ( " Not handling S1AP message extensio n" ) ;
}
}
uint32_t ueid = msg . protocol_ies . ue_id_idx_value . value . to_number ( ) ;
uint32_t ueid = msg . protocol_ies . ue_id_idx_value . value . to_number ( ) ;
rrc - > add_paging_id ( ueid , msg . protocol_ies . ue_paging_id . value ) ;
rrc - > add_paging_id ( ueid , msg . protocol_ies . ue_paging_id . value ) ;
@ -696,9 +697,9 @@ bool s1ap::handle_paging(const asn1::s1ap::paging_s& msg)
bool s1ap : : handle_erabsetuprequest ( const erab_setup_request_s & msg )
bool s1ap : : handle_erabsetuprequest ( const erab_setup_request_s & msg )
{
{
s1ap_log- > info ( " Received ERABSetupRequest \n " ) ;
logger. info ( " Received ERABSetupRequest " ) ;
if ( msg . ext ) {
if ( msg . ext ) {
s1ap_log- > warning ( " Not handling S1AP message extensio n\ n" ) ;
logger. warning ( " Not handling S1AP message extensio n" ) ;
}
}
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
@ -711,12 +712,12 @@ bool s1ap::handle_erabsetuprequest(const erab_setup_request_s& msg)
bool s1ap : : handle_erabmodifyrequest ( const erab_modify_request_s & msg )
bool s1ap : : handle_erabmodifyrequest ( const erab_modify_request_s & msg )
{
{
s1ap_log- > info ( " Received ERABModifyRequest \n " ) ;
logger. info ( " Received ERABModifyRequest " ) ;
std : : vector < uint16_t > erab_successful_modified = { } ;
std : : vector < uint16_t > erab_successful_modified = { } ;
std : : vector < uint16_t > erab_failed_to_modify = { } ;
std : : vector < uint16_t > erab_failed_to_modify = { } ;
if ( msg . ext ) {
if ( msg . ext ) {
s1ap_log- > warning ( " Not handling S1AP message extensio n\ n" ) ;
logger. warning ( " Not handling S1AP message extensio n" ) ;
}
}
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
@ -728,7 +729,7 @@ bool s1ap::handle_erabmodifyrequest(const erab_modify_request_s& msg)
// Send E-RAB modify response back to the MME
// Send E-RAB modify response back to the MME
if ( not u - > send_erab_modify_response ( erab_successful_modified , erab_failed_to_modify ) ) {
if ( not u - > send_erab_modify_response ( erab_successful_modified , erab_failed_to_modify ) ) {
s1ap_log- > info ( " Failed to send ERABReleaseResponse \n " ) ;
logger. info ( " Failed to send ERABReleaseResponse " ) ;
return false ;
return false ;
}
}
@ -737,12 +738,12 @@ bool s1ap::handle_erabmodifyrequest(const erab_modify_request_s& msg)
bool s1ap : : handle_erabreleasecommand ( const erab_release_cmd_s & msg )
bool s1ap : : handle_erabreleasecommand ( const erab_release_cmd_s & msg )
{
{
s1ap_log- > info ( " Received ERABReleaseCommand \n " ) ;
logger. info ( " Received ERABReleaseCommand " ) ;
std : : vector < uint16_t > erab_successful_release = { } ;
std : : vector < uint16_t > erab_successful_release = { } ;
std : : vector < uint16_t > erab_failed_to_release = { } ;
std : : vector < uint16_t > erab_failed_to_release = { } ;
if ( msg . ext ) {
if ( msg . ext ) {
s1ap_log- > warning ( " Not handling S1AP message extensio n\ n" ) ;
logger. warning ( " Not handling S1AP message extensio n" ) ;
}
}
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
@ -754,7 +755,7 @@ bool s1ap::handle_erabreleasecommand(const erab_release_cmd_s& msg)
// Send E-RAB release response back to the MME
// Send E-RAB release response back to the MME
if ( not u - > send_erab_release_response ( erab_successful_release , erab_failed_to_release ) ) {
if ( not u - > send_erab_release_response ( erab_successful_release , erab_failed_to_release ) ) {
s1ap_log- > info ( " Failed to send ERABReleaseResponse \n " ) ;
logger. info ( " Failed to send ERABReleaseResponse " ) ;
return false ;
return false ;
}
}
@ -763,7 +764,7 @@ bool s1ap::handle_erabreleasecommand(const erab_release_cmd_s& msg)
bool s1ap : : handle_uecontextmodifyrequest ( const ue_context_mod_request_s & msg )
bool s1ap : : handle_uecontextmodifyrequest ( const ue_context_mod_request_s & msg )
{
{
s1ap_log- > info ( " Received UeContextModificationRequest \n " ) ;
logger. info ( " Received UeContextModificationRequest " ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
return false ;
return false ;
@ -796,9 +797,9 @@ bool s1ap::handle_uecontextmodifyrequest(const ue_context_mod_request_s& msg)
bool s1ap : : handle_uectxtreleasecommand ( const ue_context_release_cmd_s & msg )
bool s1ap : : handle_uectxtreleasecommand ( const ue_context_release_cmd_s & msg )
{
{
s1ap_log- > info ( " Received UEContextReleaseCommand \n " ) ;
logger. info ( " Received UEContextReleaseCommand " ) ;
if ( msg . ext ) {
if ( msg . ext ) {
s1ap_log- > warning ( " Not handling S1AP message extensio n\ n" ) ;
logger. warning ( " Not handling S1AP message extensio n" ) ;
}
}
ue * u = nullptr ;
ue * u = nullptr ;
@ -806,10 +807,10 @@ bool s1ap::handle_uectxtreleasecommand(const ue_context_release_cmd_s& msg)
auto & idpair = msg . protocol_ies . ue_s1ap_ids . value . ue_s1ap_id_pair ( ) ;
auto & idpair = msg . protocol_ies . ue_s1ap_ids . value . ue_s1ap_id_pair ( ) ;
if ( idpair . ext ) {
if ( idpair . ext ) {
s1ap_log- > warning ( " Not handling S1AP message extensio n\ n" ) ;
logger. warning ( " Not handling S1AP message extensio n" ) ;
}
}
if ( idpair . ie_exts_present ) {
if ( idpair . ie_exts_present ) {
s1ap_log- > warning ( " Not handling S1AP message iE_Extensions \n " ) ;
logger. warning ( " Not handling S1AP message iE_Extensions " ) ;
}
}
u = find_s1apmsg_user ( idpair . enb_ue_s1ap_id , idpair . mme_ue_s1ap_id ) ;
u = find_s1apmsg_user ( idpair . enb_ue_s1ap_id , idpair . mme_ue_s1ap_id ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
@ -819,7 +820,7 @@ bool s1ap::handle_uectxtreleasecommand(const ue_context_release_cmd_s& msg)
uint32_t mme_ue_id = msg . protocol_ies . ue_s1ap_ids . value . mme_ue_s1ap_id ( ) ;
uint32_t mme_ue_id = msg . protocol_ies . ue_s1ap_ids . value . mme_ue_s1ap_id ( ) ;
u = users . find_ue_mmeid ( mme_ue_id ) ;
u = users . find_ue_mmeid ( mme_ue_id ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
s1ap_log- > warning ( " UE for mme_ue_s1ap_id:%d not found - discarding message \n " , mme_ue_id ) ;
logger. warning ( " UE for mme_ue_s1ap_id:%d not found - discarding message " , mme_ue_id ) ;
return false ;
return false ;
}
}
}
}
@ -828,7 +829,7 @@ bool s1ap::handle_uectxtreleasecommand(const ue_context_release_cmd_s& msg)
rrc - > release_erabs ( rnti ) ;
rrc - > release_erabs ( rnti ) ;
u - > send_uectxtreleasecomplete ( ) ;
u - > send_uectxtreleasecomplete ( ) ;
users . erase ( u ) ;
users . erase ( u ) ;
s1ap_log- > info ( " UE context for RNTI:0x%x released \n " , rnti ) ;
logger. info ( " UE context for RNTI:0x%x released " , rnti ) ;
rrc - > release_complete ( rnti ) ;
rrc - > release_complete ( rnti ) ;
return true ;
return true ;
}
}
@ -836,14 +837,14 @@ bool s1ap::handle_uectxtreleasecommand(const ue_context_release_cmd_s& msg)
bool s1ap : : handle_s1setupfailure ( const asn1 : : s1ap : : s1_setup_fail_s & msg )
bool s1ap : : handle_s1setupfailure ( const asn1 : : s1ap : : s1_setup_fail_s & msg )
{
{
std : : string cause = get_cause ( msg . protocol_ies . cause . value ) ;
std : : string cause = get_cause ( msg . protocol_ies . cause . value ) ;
s1ap_log- > error ( " S1 Setup Failure. Cause: %s \n " , cause . c_str ( ) ) ;
logger. error ( " S1 Setup Failure. Cause: %s " , cause . c_str ( ) ) ;
srslte : : console ( " S1 Setup Failure. Cause: %s \n " , cause . c_str ( ) ) ;
srslte : : console ( " S1 Setup Failure. Cause: %s \n " , cause . c_str ( ) ) ;
return true ;
return true ;
}
}
bool s1ap : : handle_hopreparationfailure ( const ho_prep_fail_s & msg )
bool s1ap : : handle_hopreparationfailure ( const ho_prep_fail_s & msg )
{
{
s1ap_log- > info ( " Received HO Preparation Failure \n " ) ;
logger. info ( " Received HO Preparation Failure " ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
return false ;
return false ;
@ -854,7 +855,7 @@ bool s1ap::handle_hopreparationfailure(const ho_prep_fail_s& msg)
bool s1ap : : handle_s1hocommand ( const asn1 : : s1ap : : ho_cmd_s & msg )
bool s1ap : : handle_s1hocommand ( const asn1 : : s1ap : : ho_cmd_s & msg )
{
{
s1ap_log- > info ( " Received S1 HO Command \n " ) ;
logger. info ( " Received S1 HO Command " ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
if ( u = = nullptr ) {
if ( u = = nullptr ) {
return false ;
return false ;
@ -871,7 +872,7 @@ bool s1ap::handle_ho_request(const asn1::s1ap::ho_request_s& msg)
{
{
uint16_t rnti = SRSLTE_INVALID_RNTI ;
uint16_t rnti = SRSLTE_INVALID_RNTI ;
s1ap_log- > info ( " Received S1 HO Request \n " ) ;
logger. info ( " Received S1 HO Request " ) ;
srslte : : console ( " Received S1 HO Request \n " ) ;
srslte : : console ( " Received S1 HO Request \n " ) ;
auto on_scope_exit = srslte : : make_scope_exit ( [ this , & rnti , msg ] ( ) {
auto on_scope_exit = srslte : : make_scope_exit ( [ this , & rnti , msg ] ( ) {
@ -883,14 +884,14 @@ bool s1ap::handle_ho_request(const asn1::s1ap::ho_request_s& msg)
if ( msg . ext or msg . protocol_ies . ho_restrict_list_present or
if ( msg . ext or msg . protocol_ies . ho_restrict_list_present or
msg . protocol_ies . handov_type . value . value ! = handov_type_opts : : intralte ) {
msg . protocol_ies . handov_type . value . value ! = handov_type_opts : : intralte ) {
s1ap_log- > error ( " Not handling S1AP non-intra LTE handovers and extensions \n " ) ;
logger. error ( " Not handling S1AP non-intra LTE handovers and extensions " ) ;
return false ;
return false ;
}
}
// Confirm the UE does not exist in TeNB
// Confirm the UE does not exist in TeNB
if ( users . find_ue_mmeid ( msg . protocol_ies . mme_ue_s1ap_id . value . value ) ! = nullptr ) {
if ( users . find_ue_mmeid ( msg . protocol_ies . mme_ue_s1ap_id . value . value ) ! = nullptr ) {
s1ap_log- > error ( " The provided MME_UE_S1AP_ID=% " PRIu64 " is already connected to the cell \n " ,
logger. error ( " The provided MME_UE_S1AP_ID=% " PRIu64 " is already connected to the cell " ,
msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
return false ;
return false ;
}
}
@ -907,7 +908,7 @@ bool s1ap::handle_ho_request(const asn1::s1ap::ho_request_s& msg)
asn1 : : cbit_ref bref { msg . protocol_ies . source_to_target_transparent_container . value . data ( ) ,
asn1 : : cbit_ref bref { msg . protocol_ies . source_to_target_transparent_container . value . data ( ) ,
msg . protocol_ies . source_to_target_transparent_container . value . size ( ) } ;
msg . protocol_ies . source_to_target_transparent_container . value . size ( ) } ;
if ( container . unpack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
if ( container . unpack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
s1ap_log- > error ( " Failed to unpack SourceToTargetTransparentContainer \n " ) ;
logger. error ( " Failed to unpack SourceToTargetTransparentContainer " ) ;
return false ;
return false ;
}
}
@ -972,7 +973,7 @@ bool s1ap::send_ho_req_ack(const asn1::s1ap::ho_request_s& msg,
auto & pdu = ho_cmd ; // reuse pdu
auto & pdu = ho_cmd ; // reuse pdu
asn1 : : bit_ref bref { pdu - > msg , pdu - > get_tailroom ( ) } ;
asn1 : : bit_ref bref { pdu - > msg , pdu - > get_tailroom ( ) } ;
if ( transparent_container . pack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
if ( transparent_container . pack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
s1ap_log- > error ( " Failed to pack TargeteNBToSourceeNBTransparentContainer \n " ) ;
logger. error ( " Failed to pack TargeteNBToSourceeNBTransparentContainer " ) ;
return false ;
return false ;
}
}
container . target_to_source_transparent_container . value . resize ( bref . distance_bytes ( ) ) ;
container . target_to_source_transparent_container . value . resize ( bref . distance_bytes ( ) ) ;
@ -983,7 +984,7 @@ bool s1ap::send_ho_req_ack(const asn1::s1ap::ho_request_s& msg,
bool s1ap : : handle_mme_status_transfer ( const asn1 : : s1ap : : mme_status_transfer_s & msg )
bool s1ap : : handle_mme_status_transfer ( const asn1 : : s1ap : : mme_status_transfer_s & msg )
{
{
s1ap_log- > info ( " Received S1 MMEStatusTransfer \n " ) ;
logger. info ( " Received S1 MMEStatusTransfer " ) ;
srslte : : console ( " Received S1 MMEStatusTransfer \n " ) ;
srslte : : console ( " Received S1 MMEStatusTransfer \n " ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
ue * u = find_s1apmsg_user ( msg . protocol_ies . enb_ue_s1ap_id . value . value , msg . protocol_ies . mme_ue_s1ap_id . value . value ) ;
@ -1114,7 +1115,7 @@ bool s1ap::ue::send_uectxtreleaserequest(const cause_c& cause)
}
}
if ( ! ctxt . mme_ue_s1ap_id_present ) {
if ( ! ctxt . mme_ue_s1ap_id_present ) {
s1ap_log- > error ( " Cannot send UE context release request without a MME-UE-S1AP-Id allocated. \n " ) ;
logger. error ( " Cannot send UE context release request without a MME-UE-S1AP-Id allocated. " ) ;
return false ;
return false ;
}
}
@ -1367,7 +1368,7 @@ bool s1ap::send_ho_required(uint16_t rnti,
// launch procedure
// launch procedure
if ( not u - > ho_prep_proc . launch ( target_eci , target_plmn , std : : move ( rrc_container ) ) ) {
if ( not u - > ho_prep_proc . launch ( target_eci , target_plmn , std : : move ( rrc_container ) ) ) {
s1ap_log- > error ( " Failed to initiate an HandoverPreparation procedure for user rnti=0x%x \n " , u - > ctxt . rnti ) ;
logger. error ( " Failed to initiate an HandoverPreparation procedure for user rnti=0x%x " , u - > ctxt . rnti ) ;
return false ;
return false ;
}
}
return true ;
return true ;
@ -1405,13 +1406,13 @@ bool s1ap::send_enb_status_transfer_proc(uint16_t rnti, std::vector<bearer_statu
// // TODO: caps->UERadioCapability.
// // TODO: caps->UERadioCapability.
// liblte_s1ap_pack_s1ap_pdu(&tx_pdu, (LIBLTE_BYTE_MSG_STRUCT*)&msg);
// liblte_s1ap_pack_s1ap_pdu(&tx_pdu, (LIBLTE_BYTE_MSG_STRUCT*)&msg);
// s1ap_log-> info_hex(msg.msg, msg.N_bytes, "Sending UERadioCapabilityInfo for RNTI:0x%x", rnti);
// logger. info_hex(msg.msg, msg.N_bytes, "Sending UERadioCapabilityInfo for RNTI:0x%x", rnti);
// ssize_t n_sent = sctp_sendmsg(socket_fd, msg.msg, msg.N_bytes,
// ssize_t n_sent = sctp_sendmsg(socket_fd, msg.msg, msg.N_bytes,
// (struct sockaddr*)&mme_addr, sizeof(struct sockaddr_in),
// (struct sockaddr*)&mme_addr, sizeof(struct sockaddr_in),
// htonl(PPID), 0, ue_ctxt_map[rnti]->stream_id, 0, 0);
// htonl(PPID), 0, ue_ctxt_map[rnti]->stream_id, 0, 0);
// if(n_sent == -1) {
// if(n_sent == -1) {
// s1ap_log-> error("Failed to send UplinkNASTransport for RNTI:0x%x\n ", rnti);
// logger. error("Failed to send UplinkNASTransport for RNTI:0x%x", rnti);
// return false;
// return false;
// }
// }
@ -1455,17 +1456,15 @@ s1ap::ue* s1ap::user_list::add_user(std::unique_ptr<s1ap::ue> user)
{
{
// Check for ID repetitions
// Check for ID repetitions
if ( find_ue_rnti ( user - > ctxt . rnti ) ! = nullptr ) {
if ( find_ue_rnti ( user - > ctxt . rnti ) ! = nullptr ) {
srslte : : logmap : : get ( " S1AP " ) - > error ( " The user to be added with rnti=0x%x already exists \n " , user - > ctxt . rnti ) ;
srslte : : logmap : : get ( " S1AP " ) - > error ( " The user to be added with rnti=0x%x already exists " , user - > ctxt . rnti ) ;
return nullptr ;
return nullptr ;
}
}
if ( find_ue_enbid ( user - > ctxt . enb_ue_s1ap_id ) ! = nullptr ) {
if ( find_ue_enbid ( user - > ctxt . enb_ue_s1ap_id ) ! = nullptr ) {
srslte : : logmap : : get ( " S1AP " ) - > error ( " The user to be added with enb id=%d already exists \n " ,
srslte : : logmap : : get ( " S1AP " ) - > error ( " The user to be added with enb id=%d already exists " , user - > ctxt . enb_ue_s1ap_id ) ;
user - > ctxt . enb_ue_s1ap_id ) ;
return nullptr ;
return nullptr ;
}
}
if ( find_ue_mmeid ( user - > ctxt . mme_ue_s1ap_id ) ! = nullptr ) {
if ( find_ue_mmeid ( user - > ctxt . mme_ue_s1ap_id ) ! = nullptr ) {
srslte : : logmap : : get ( " S1AP " ) - > error ( " The user to be added with mme id=%d already exists \n " ,
srslte : : logmap : : get ( " S1AP " ) - > error ( " The user to be added with mme id=%d already exists " , user - > ctxt . mme_ue_s1ap_id ) ;
user - > ctxt . mme_ue_s1ap_id ) ;
return nullptr ;
return nullptr ;
}
}
auto p = users . insert ( std : : make_pair ( user - > ctxt . enb_ue_s1ap_id , std : : move ( user ) ) ) ;
auto p = users . insert ( std : : make_pair ( user - > ctxt . enb_ue_s1ap_id , std : : move ( user ) ) ) ;
@ -1476,7 +1475,7 @@ void s1ap::user_list::erase(ue* ue_ptr)
{
{
auto it = users . find ( ue_ptr - > ctxt . enb_ue_s1ap_id ) ;
auto it = users . find ( ue_ptr - > ctxt . enb_ue_s1ap_id ) ;
if ( it = = users . end ( ) ) {
if ( it = = users . end ( ) ) {
srslte : : logmap : : get ( " S1AP " ) - > error ( " User to be erased does not exist \n " ) ;
srslte : : logmap : : get ( " S1AP " ) - > error ( " User to be erased does not exist " ) ;
return ;
return ;
}
}
users . erase ( it ) ;
users . erase ( it ) ;
@ -1490,7 +1489,7 @@ bool s1ap::sctp_send_s1ap_pdu(const asn1::s1ap::s1ap_pdu_c& tx_pdu, uint32_t rnt
{
{
srslte : : unique_byte_buffer_t buf = srslte : : allocate_unique_buffer ( * pool , false ) ;
srslte : : unique_byte_buffer_t buf = srslte : : allocate_unique_buffer ( * pool , false ) ;
if ( buf = = nullptr ) {
if ( buf = = nullptr ) {
s1ap_log- > error ( " Fatal Error: Couldn't allocate buffer for %s. \n " , procedure_name ) ;
logger. error ( " Fatal Error: Couldn't allocate buffer for %s. " , procedure_name ) ;
return false ;
return false ;
}
}
asn1 : : bit_ref bref ( buf - > msg , buf - > get_tailroom ( ) ) ;
asn1 : : bit_ref bref ( buf - > msg , buf - > get_tailroom ( ) ) ;
@ -1503,9 +1502,9 @@ bool s1ap::sctp_send_s1ap_pdu(const asn1::s1ap::s1ap_pdu_c& tx_pdu, uint32_t rnt
}
}
if ( rnti ! = SRSLTE_INVALID_RNTI ) {
if ( rnti ! = SRSLTE_INVALID_RNTI ) {
s1ap_log- > info_hex ( buf - > msg , buf - > N_bytes , " Sending %s for rnti=0x%x " , procedure_name , rnti ) ;
logger. info ( buf - > msg , buf - > N_bytes , " Sending %s for rnti=0x%x " , procedure_name , rnti ) ;
} else {
} else {
s1ap_log- > info_hex ( buf - > msg , buf - > N_bytes , " Sending %s to MME " , procedure_name ) ;
logger. info ( buf - > msg , buf - > N_bytes , " Sending %s to MME " , procedure_name ) ;
}
}
uint16_t streamid = rnti = = SRSLTE_INVALID_RNTI ? NONUE_STREAM_ID : users . find_ue_rnti ( rnti ) - > stream_id ;
uint16_t streamid = rnti = = SRSLTE_INVALID_RNTI ? NONUE_STREAM_ID : users . find_ue_rnti ( rnti ) - > stream_id ;
@ -1521,9 +1520,9 @@ bool s1ap::sctp_send_s1ap_pdu(const asn1::s1ap::s1ap_pdu_c& tx_pdu, uint32_t rnt
0 ) ;
0 ) ;
if ( n_sent = = - 1 ) {
if ( n_sent = = - 1 ) {
if ( rnti > 0 ) {
if ( rnti > 0 ) {
s1ap_log- > error ( " Failed to send %s for rnti=0x%x \n " , procedure_name , rnti ) ;
logger. error ( " Failed to send %s for rnti=0x%x " , procedure_name , rnti ) ;
} else {
} else {
s1ap_log- > error ( " Failed to send %s \n " , procedure_name ) ;
logger. error ( " Failed to send %s " , procedure_name ) ;
}
}
return false ;
return false ;
}
}
@ -1540,11 +1539,11 @@ s1ap::ue* s1ap::find_s1apmsg_user(uint32_t enb_id, uint32_t mme_id)
{
{
ue * user_ptr = users . find_ue_enbid ( enb_id ) ;
ue * user_ptr = users . find_ue_enbid ( enb_id ) ;
if ( user_ptr = = nullptr ) {
if ( user_ptr = = nullptr ) {
s1ap_log- > warning ( " enb_ue_s1ap_id=%d not found - discarding message \n " , enb_id ) ;
logger. warning ( " enb_ue_s1ap_id=%d not found - discarding message " , enb_id ) ;
return nullptr ;
return nullptr ;
}
}
if ( user_ptr - > ctxt . mme_ue_s1ap_id_present and user_ptr - > ctxt . mme_ue_s1ap_id ! = mme_id ) {
if ( user_ptr - > ctxt . mme_ue_s1ap_id_present and user_ptr - > ctxt . mme_ue_s1ap_id ! = mme_id ) {
s1ap_log- > warning ( " MME_UE_S1AP_ID has changed - old:%d, new:%d \n " , user_ptr - > ctxt . mme_ue_s1ap_id , mme_id ) ;
logger. warning ( " MME_UE_S1AP_ID has changed - old:%d, new:%d " , user_ptr - > ctxt . mme_ue_s1ap_id , mme_id ) ;
}
}
user_ptr - > ctxt . mme_ue_s1ap_id_present = true ;
user_ptr - > ctxt . mme_ue_s1ap_id_present = true ;
user_ptr - > ctxt . mme_ue_s1ap_id = mme_id ;
user_ptr - > ctxt . mme_ue_s1ap_id = mme_id ;
@ -1586,7 +1585,7 @@ void s1ap::start_pcap(srslte::s1ap_pcap* pcap_)
/* s1ap::ue Class
/* s1ap::ue Class
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
s1ap : : ue : : ue ( s1ap * s1ap_ptr_ ) : s1ap_ptr ( s1ap_ptr_ ) , s1ap_log( s1ap_ptr_ - > s1ap_log ) , ho_prep_proc ( this )
s1ap : : ue : : ue ( s1ap * s1ap_ptr_ ) : s1ap_ptr ( s1ap_ptr_ ) , ho_prep_proc( this ) , logger ( s1ap_ptr - > logger )
{
{
ctxt . enb_ue_s1ap_id = s1ap_ptr - > next_enb_ue_s1ap_id + + ;
ctxt . enb_ue_s1ap_id = s1ap_ptr - > next_enb_ue_s1ap_id + + ;
gettimeofday ( & ctxt . init_timestamp , nullptr ) ;
gettimeofday ( & ctxt . init_timestamp , nullptr ) ;
@ -1665,7 +1664,7 @@ bool s1ap::ue::send_ho_required(uint32_t target_eci,
uint8_t buffer [ 4096 ] ;
uint8_t buffer [ 4096 ] ;
asn1 : : bit_ref bref ( buffer , sizeof ( buffer ) ) ;
asn1 : : bit_ref bref ( buffer , sizeof ( buffer ) ) ;
if ( transparent_cntr . pack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
if ( transparent_cntr . pack ( bref ) ! = asn1 : : SRSASN_SUCCESS ) {
s1ap_log- > error ( " Failed to pack transparent container of HO Required message \n " ) ;
logger. error ( " Failed to pack transparent container of HO Required message " ) ;
return false ;
return false ;
}
}
container . source_to_target_transparent_container . value . resize ( bref . distance_bytes ( ) ) ;
container . source_to_target_transparent_container . value . resize ( bref . distance_bytes ( ) ) ;
@ -1704,7 +1703,7 @@ bool s1ap::ue::send_enb_status_transfer_proc(std::vector<bearer_status_info>& be
// asn1::json_writer jw;
// asn1::json_writer jw;
// asn1bearer.to_json(jw);
// asn1bearer.to_json(jw);
// printf("Bearer to add %s \n ", jw.to_string().c_str());
// printf("Bearer to add %s ", jw.to_string().c_str());
}
}
return s1ap_ptr - > sctp_send_s1ap_pdu ( tx_pdu , ctxt . rnti , " ENBStatusTransfer " ) ;
return s1ap_ptr - > sctp_send_s1ap_pdu ( tx_pdu , ctxt . rnti , " ENBStatusTransfer " ) ;