diff --git a/CHANGELOG b/CHANGELOG index 5a57af260..7a3a03e8a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ Change Log for Releases ============================== +## 18.03.1 + * Fixed compilation for NEON + * Fixed logging and RLC AM issue + +## 18.03 + * Many bug-fixes and improved stability and performance in all parts + ## 17.12 * Added support for MIMO 2x2 in srsENB (i.e. TM3/TM4) * Added srsEPC, a light-weight core network implementation diff --git a/CMakeLists.txt b/CMakeLists.txt index 98023d7b5..290754ee3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,6 @@ include(SRSLTEVersion) #sets version information include(SRSLTEPackage) #setup cpack include(CTest) -set(CTEST_MEMORYCHECK_COMMAND valgrind) -set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full" ) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in" @@ -171,7 +169,6 @@ if(ENABLE_SRSUE OR ENABLE_SRSENB OR ENABLE_SRSEPC) set(BOOST_REQUIRED_COMPONENTS program_options - system ) if(UNIX AND EXISTS "/usr/lib64") list(APPEND BOOST_LIBRARYDIR "/usr/lib64") #fedora 64-bit fix @@ -229,7 +226,7 @@ macro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE flag have) endmacro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable -std=c++03") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable -Wformat -std=c++03") find_package(SSE) if (HAVE_AVX2) diff --git a/CTestConfig.cmake b/CTestConfig.cmake index 1c4aa5735..d8e316006 100644 --- a/CTestConfig.cmake +++ b/CTestConfig.cmake @@ -11,3 +11,4 @@ set(CTEST_DROP_METHOD "http") set(CTEST_DROP_SITE "my.cdash.org") set(CTEST_DROP_LOCATION "/submit.php?project=srsLTE") set(CTEST_DROP_SITE_CDASH TRUE) +set(VALGRIND_COMMAND_OPTIONS "--trace-children=yes --leak-check=full --show-reachable=yes --vex-guest-max-insns=25") \ No newline at end of file diff --git a/README.md b/README.md index 1567c7c71..a8f186a62 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Build Instructions For example, on Ubuntu 17.04, one can install the required libraries with: ``` -sudo apt-get install cmake libfftw3-dev libmbedtls-dev libboost-program-options-dev libboost-thread-dev libconfig++-dev libsctp-dev +sudo apt-get install cmake libfftw3-dev libmbedtls-dev libboost-program-options-dev libconfig++-dev libsctp-dev ``` Note that depending on your flavor and version of Linux, the actual package names may be different. diff --git a/cmake/modules/SRSLTEVersion.cmake b/cmake/modules/SRSLTEVersion.cmake index fec6ab21f..11b2e79e9 100644 --- a/cmake/modules/SRSLTEVersion.cmake +++ b/cmake/modules/SRSLTEVersion.cmake @@ -18,7 +18,7 @@ # and at http://www.gnu.org/licenses/. # -SET(SRSLTE_VERSION_MAJOR 17) -SET(SRSLTE_VERSION_MINOR 12) -SET(SRSLTE_VERSION_PATCH 0) +SET(SRSLTE_VERSION_MAJOR 18) +SET(SRSLTE_VERSION_MINOR 3) +SET(SRSLTE_VERSION_PATCH 1) SET(SRSLTE_VERSION_STRING "${SRSLTE_VERSION_MAJOR}.${SRSLTE_VERSION_MINOR}.${SRSLTE_VERSION_PATCH}") diff --git a/lib/include/srslte/asn1/gtpc.h b/lib/include/srslte/asn1/gtpc.h index aca57a4bf..3c2a3247f 100644 --- a/lib/include/srslte/asn1/gtpc.h +++ b/lib/include/srslte/asn1/gtpc.h @@ -21,8 +21,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef GTPC_V2_H -#define GTPC_V2_H +#ifndef SRSLTE_GTPC_H +#define SRSLTE_GTPC_H #include #include "srslte/asn1/gtpc_msg.h" @@ -52,16 +52,15 @@ const uint8_t GTPC_V2 = 2; * n+2 | Sequence | * n+3 | Spare | ***************************************************************************/ - - typedef struct gtpc_header - { - uint8_t version; - bool piggyback; - bool teid_present; - uint8_t type; - uint64_t teid; - uint64_t sequence; - } gtpc_header_t; +typedef struct gtpc_header +{ + uint8_t version; + bool piggyback; + bool teid_present; + uint8_t type; + uint64_t teid; + uint64_t sequence; +}gtpc_header_t; /**************************************************************************** * GTP-C v2 Payload @@ -69,16 +68,17 @@ const uint8_t GTPC_V2 = 2; * * Union that hold the different structures for the possible message types. ***************************************************************************/ - typedef union gtpc_msg_choice { struct gtpc_create_session_request create_session_request; struct gtpc_create_session_response create_session_response; struct gtpc_modify_bearer_request modify_bearer_request; struct gtpc_modify_bearer_response modify_bearer_response; + struct gtpc_release_access_bearers_request release_access_bearers_request; + struct gtpc_release_access_bearers_response release_access_bearers_response; struct gtpc_delete_session_request delete_session_request; struct gtpc_delete_session_response delete_session_response; -} gtpc_msg_choice_t; +}gtpc_msg_choice_t; /**************************************************************************** * GTP-C v2 Message @@ -88,15 +88,10 @@ typedef union gtpc_msg_choice * of one GTP-C header and one union of structures, which can hold * all the possible GTP-C messages ***************************************************************************/ - typedef struct gtpc_pdu { struct gtpc_header header; union gtpc_msg_choice choice; -} gtpc_pdu_t; - - - -}; - -#endif +}gtpc_pdu_t; +}//namespace +#endif // SRSLTE_GTPC_H diff --git a/lib/include/srslte/asn1/gtpc_ies.h b/lib/include/srslte/asn1/gtpc_ies.h index 35b5e6498..0ddcfaacb 100644 --- a/lib/include/srslte/asn1/gtpc_ies.h +++ b/lib/include/srslte/asn1/gtpc_ies.h @@ -22,8 +22,8 @@ * */ -#ifndef GTPC_IES_H -#define GTPC_IES_H +#ifndef SRSLTE_GTPC_IES_H +#define SRSLTE_GTPC_IES_H #include "srslte/phy/io/netsource.h" @@ -400,7 +400,8 @@ enum gtpc_interface_type S2B_U_PGW_GTP_U_INTERFACE }; -struct gtpc_f_teid_ie + +typedef struct gtpc_f_teid_ie { bool ipv4_present; bool ipv6_present; @@ -408,7 +409,7 @@ struct gtpc_f_teid_ie uint32_t teid; in_addr_t ipv4; struct in6_addr ipv6; //FIXME -}; +} gtp_fteid_t; //TODO //TODO IEs between 8.22 and 8.28 missing @@ -425,4 +426,4 @@ struct gtpc_f_teid_ie //locally, according to the rules of TS 29.274 v10.14.0 Section 7. } //namespace -#endif //GTPC_IES_H +#endif // SRSLTE_GTPC_IES_H diff --git a/lib/include/srslte/asn1/gtpc_msg.h b/lib/include/srslte/asn1/gtpc_msg.h index 4271b064d..61591d7c4 100644 --- a/lib/include/srslte/asn1/gtpc_msg.h +++ b/lib/include/srslte/asn1/gtpc_msg.h @@ -21,8 +21,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef GTPC_V2_MSG_H -#define GTPC_V2_MSG_H +#ifndef SRSLTE_GTPC_MSG_H +#define SRSLTE_GTPC_MSG_H #include "srslte/asn1/gtpc_ies.h" @@ -410,5 +410,36 @@ struct gtpc_delete_session_response //Private extension }; +/**************************************************************************** + * + * GTP-C v2 Release Access Bearers Request + * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.21.1-1 + * + ***************************************************************************/ +struct gtpc_release_access_bearers_request +{ + bool list_of_rabs_present; + //Linked EPS Bearer ID + bool originating_node_present; + //Indication Flags + //Private Extension +}; + + /**************************************************************************** + * + * GTP-C v2 Delete Session Response + * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.22.1-1 + * + ***************************************************************************/ + + struct gtpc_release_access_bearers_response + { + struct gtpc_cause_ie cause; + //Recovery + //Private extension + }; + + + } //namespace -#endif //GTPC_V2_MSG_H +#endif // SRSLTE_GTPC_MSG_H diff --git a/lib/include/srslte/asn1/liblte_common.h b/lib/include/srslte/asn1/liblte_common.h index 36fb32190..21d962748 100644 --- a/lib/include/srslte/asn1/liblte_common.h +++ b/lib/include/srslte/asn1/liblte_common.h @@ -33,8 +33,8 @@ *******************************************************************************/ -#ifndef __LIBLTE_COMMON_H__ -#define __LIBLTE_COMMON_H__ +#ifndef SRSLTE_LIBLTE_COMMON_H +#define SRSLTE_LIBLTE_COMMON_H /******************************************************************************* INCLUDES @@ -244,4 +244,4 @@ void liblte_align_up(uint8_t **ptr, uint32_t align); *********************************************************************/ void liblte_align_up_zero(uint8_t **ptr, uint32_t align); -#endif /* __LIBLTE_COMMON_H__ */ +#endif // SRSLTE_LIBLTE_COMMON_H diff --git a/lib/include/srslte/asn1/liblte_mme.h b/lib/include/srslte/asn1/liblte_mme.h index 78e2cae69..31b1a49df 100644 --- a/lib/include/srslte/asn1/liblte_mme.h +++ b/lib/include/srslte/asn1/liblte_mme.h @@ -35,8 +35,8 @@ *******************************************************************************/ -#ifndef __LIBLTE_MME_H__ -#define __LIBLTE_MME_H__ +#ifndef SRSLTE_LIBLTE_MME_H +#define SRSLTE_LIBLTE_MME_H /******************************************************************************* INCLUDES @@ -175,6 +175,7 @@ typedef struct{ uint8 imsi[15]; uint8 imei[15]; uint8 imeisv[16]; + uint32 tmsi; }LIBLTE_MME_MOBILE_ID_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mobile_id, @@ -4037,4 +4038,4 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_pdn_disconnect_request_msg(LIBLTE_MME_PDN_DISC LIBLTE_ERROR_ENUM liblte_mme_unpack_pdn_disconnect_request_msg(LIBLTE_BYTE_MSG_STRUCT *msg, LIBLTE_MME_PDN_DISCONNECT_REQUEST_MSG_STRUCT *pdn_discon_req); -#endif /* __LIBLTE_MME_H__ */ +#endif // SRSLTE_LIBLTE_MME_H diff --git a/lib/include/srslte/asn1/liblte_rrc.h b/lib/include/srslte/asn1/liblte_rrc.h index e0fb43aef..4fdff34e2 100644 --- a/lib/include/srslte/asn1/liblte_rrc.h +++ b/lib/include/srslte/asn1/liblte_rrc.h @@ -51,8 +51,8 @@ *******************************************************************************/ -#ifndef __LIBLTE_RRC_H__ -#define __LIBLTE_RRC_H__ +#ifndef SRSLTE_LIBLTE_RRC_H +#define SRSLTE_LIBLTE_RRC_H /******************************************************************************* INCLUDES @@ -7013,4 +7013,4 @@ LIBLTE_ERROR_ENUM liblte_rrc_pack_ul_dcch_msg(LIBLTE_RRC_UL_DCCH_MSG_STRUCT *ul_ LIBLTE_ERROR_ENUM liblte_rrc_unpack_ul_dcch_msg(LIBLTE_BIT_MSG_STRUCT *msg, LIBLTE_RRC_UL_DCCH_MSG_STRUCT *ul_dcch_msg); -#endif /* __LIBLTE_RRC_H__ */ +#endif // SRSLTE_LIBLTE_RRC_H diff --git a/lib/include/srslte/asn1/liblte_s1ap.h b/lib/include/srslte/asn1/liblte_s1ap.h index 077ddac66..0874ec753 100644 --- a/lib/include/srslte/asn1/liblte_s1ap.h +++ b/lib/include/srslte/asn1/liblte_s1ap.h @@ -4,8 +4,8 @@ /* ********************************************************************************/ -#ifndef LIBLTE_S1AP_H -#define LIBLTE_S1AP_H +#ifndef SRSLTE_LIBLTE_S1AP_H +#define SRSLTE_LIBLTE_S1AP_H /******************************************************************************* /* Warnings/Todos @@ -10352,4 +10352,4 @@ LIBLTE_ERROR_ENUM liblte_s1ap_pack_s1ap_pdu( LIBLTE_ERROR_ENUM liblte_s1ap_unpack_s1ap_pdu( LIBLTE_BYTE_MSG_STRUCT *msg, LIBLTE_S1AP_S1AP_PDU_STRUCT *s1ap_pdu); -#endif // LIBLTE_S1AP_H +#endif // SRSLTE_LIBLTE_S1AP_H diff --git a/lib/include/srslte/build_info.h.in b/lib/include/srslte/build_info.h.in index 90dac1dbb..5409ab077 100644 --- a/lib/include/srslte/build_info.h.in +++ b/lib/include/srslte/build_info.h.in @@ -25,8 +25,8 @@ * */ -#ifndef BUILD_INFO_ -#define BUILD_INFO_ +#ifndef SRSLTE_BUILD_INFO_H_IN +#define SRSLTE_BUILD_INFO_H_IN # ifdef __cplusplus extern "C" { diff --git a/lib/include/srslte/common/bcd_helpers.h b/lib/include/srslte/common/bcd_helpers.h index 10bed4347..b145a2d5a 100644 --- a/lib/include/srslte/common/bcd_helpers.h +++ b/lib/include/srslte/common/bcd_helpers.h @@ -24,8 +24,8 @@ * */ -#ifndef BCD_HELPERS -#define BCD_HELPERS +#ifndef SRSLTE_BCD_HELPERS_H +#define SRSLTE_BCD_HELPERS_H #include #include @@ -194,4 +194,4 @@ inline void s1ap_mccmnc_to_plmn(uint16_t mcc, uint16_t mnc, uint32_t *plmn) } // namespace srslte -#endif // BCD_HELPERS +#endif // SRSLTE_BCD_HELPERS_H diff --git a/lib/include/srslte/common/block_queue.h b/lib/include/srslte/common/block_queue.h index b4b312b60..b04a91985 100644 --- a/lib/include/srslte/common/block_queue.h +++ b/lib/include/srslte/common/block_queue.h @@ -24,8 +24,8 @@ * */ -#ifndef BLOCK_QUEUE -#define BLOCK_QUEUE +#ifndef SRSLTE_BLOCK_QUEUE_H +#define SRSLTE_BLOCK_QUEUE_H #include #include @@ -94,4 +94,4 @@ private: } -#endif \ No newline at end of file +#endif // SRSLTE_BLOCK_QUEUE_H \ No newline at end of file diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index 76634a697..1895c8330 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -24,8 +24,8 @@ * */ -#ifndef BUFFER_POOL_H -#define BUFFER_POOL_H +#ifndef SRSLTE_BUFFER_POOL_H +#define SRSLTE_BUFFER_POOL_H #include #include @@ -187,4 +187,4 @@ private: } // namespace srsue -#endif // BUFFER_POOL_H +#endif // SRSLTE_BUFFER_POOL_H diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index 8089634b7..754b7423d 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -24,8 +24,8 @@ * */ -#ifndef COMMON_H -#define COMMON_H +#ifndef SRSLTE_COMMON_H +#define SRSLTE_COMMON_H /******************************************************************************* INCLUDES @@ -147,6 +147,11 @@ public: { return msg-buffer; } + // Returns the remaining space from what is reported to be the length of msg + uint32_t get_tailroom() + { + return (sizeof(buffer) - (msg-buffer) - N_bytes); + } long get_latency_us() { #ifdef ENABLE_TIMESTAMP @@ -234,6 +239,6 @@ private: }; -} // namespace srsue +} // namespace srslte -#endif // COMMON_H +#endif // SRSLTE_COMMON_H diff --git a/lib/include/srslte/common/config.h b/lib/include/srslte/common/config.h index 3231355fa..ed95631cd 100644 --- a/lib/include/srslte/common/config.h +++ b/lib/include/srslte/common/config.h @@ -24,8 +24,8 @@ * */ -#ifndef CONFIG_H -#define CONFIG_H +#ifndef SRSLTE_CONFIG_H +#define SRSLTE_CONFIG_H // Generic helper definitions for shared library support #if defined _WIN32 || defined __CYGWIN__ @@ -54,4 +54,4 @@ // cf_t definition typedef _Complex float cf_t; -#endif // CONFIG_H +#endif // SRSLTE_CONFIG_H diff --git a/lib/include/srslte/common/interfaces_common.h b/lib/include/srslte/common/interfaces_common.h index e7de90ea1..50eb024b5 100644 --- a/lib/include/srslte/common/interfaces_common.h +++ b/lib/include/srslte/common/interfaces_common.h @@ -24,8 +24,8 @@ * */ -#ifndef INTERFACE_COMMON_H -#define INTERFACE_COMMON_H +#ifndef SRSLTE_INTERFACES_COMMON_H +#define SRSLTE_INTERFACES_COMMON_H #include "srslte/common/timers.h" #include "srslte/common/security.h" @@ -96,4 +96,4 @@ public: } -#endif +#endif // SRSLTE_INTERFACES_COMMON_H diff --git a/lib/include/srslte/common/liblte_security.h b/lib/include/srslte/common/liblte_security.h index 02cc42ca8..8dc31f341 100644 --- a/lib/include/srslte/common/liblte_security.h +++ b/lib/include/srslte/common/liblte_security.h @@ -29,8 +29,8 @@ *******************************************************************************/ -#ifndef __LIBLTE_SECURITY_H__ -#define __LIBLTE_SECURITY_H__ +#ifndef SRSLTE_LIBLTE_SECURITY_H +#define SRSLTE_LIBLTE_SECURITY_H /******************************************************************************* INCLUDES @@ -345,4 +345,4 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f5_star(uint8 *k, uint8 *rand, uint8 *ak); -#endif /* __LIBLTE_SECURITY_H__ */ +#endif // SRSLTE_LIBLTE_SECURITY_H diff --git a/lib/include/srslte/common/liblte_ssl.h b/lib/include/srslte/common/liblte_ssl.h index d96c728ab..2ac4e794f 100644 --- a/lib/include/srslte/common/liblte_ssl.h +++ b/lib/include/srslte/common/liblte_ssl.h @@ -1,5 +1,5 @@ -#ifndef __LIBLTE_SSL_H__ -#define __LIBLTE_SSL_H__ +#ifndef SRSLTE_LIBLTE_SSL_H +#define SRSLTE_LIBLTE_SSL_H #ifdef HAVE_POLARSSL @@ -62,4 +62,4 @@ void sha256(const unsigned char *key, size_t keylen, #endif // HAVE_MBEDTLS -#endif // __LIBLTE_SSL_H__ +#endif // SRSLTE_LIBLTE_SSL_H diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index 360482c47..b47f79d90 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef LOG_H -#define LOG_H +#ifndef SRSLTE_LOG_H +#define SRSLTE_LOG_H #include #include @@ -122,17 +122,21 @@ public: } // Pure virtual methods for logging - virtual void console(std::string message, ...) = 0; - virtual void error(std::string message, ...) = 0; - virtual void warning(std::string message, ...) = 0; - virtual void info(std::string message, ...) = 0; - virtual void debug(std::string message, ...) = 0; + virtual void console(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void error(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void warning(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void info(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; // Same with hex dump - virtual void error_hex(uint8_t *hex, int size, std::string message, ...){error("error_hex not implemented.\n");} - virtual void warning_hex(uint8_t *hex, int size, std::string message, ...){error("warning_hex not implemented.\n");} - virtual void info_hex(uint8_t *hex, int size, std::string message, ...){error("info_hex not implemented.\n");} - virtual void debug_hex(uint8_t *hex, int size, std::string message, ...){error("debug_hex not implemented.\n");} + virtual void error_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + {error("error_hex not implemented.\n");} + virtual void warning_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + {error("warning_hex not implemented.\n");} + virtual void info_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + {error("info_hex not implemented.\n");} + virtual void debug_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + {error("debug_hex not implemented.\n");} protected: std::string get_service_name() { return service_name; } @@ -149,5 +153,5 @@ protected: } // namespace srslte -#endif // LOG_H +#endif // SRSLTE_LOG_H diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index 7e4014190..1296fbbbd 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -32,8 +32,8 @@ * common logger object. *****************************************************************************/ -#ifndef LOG_FILTER_H -#define LOG_FILTER_H +#ifndef SRSLTE_LOG_FILTER_H +#define SRSLTE_LOG_FILTER_H #include #include @@ -57,16 +57,16 @@ public: void init(std::string layer, logger *logger_, bool tti=false); - void console(std::string message, ...); - void error(std::string message, ...); - void warning(std::string message, ...); - void info(std::string message, ...); - void debug(std::string message, ...); + void console(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void error(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void warning(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void info(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))); - void error_hex(uint8_t *hex, int size, std::string message, ...); - void warning_hex(uint8_t *hex, int size, std::string message, ...); - void info_hex(uint8_t *hex, int size, std::string message, ...); - void debug_hex(uint8_t *hex, int size, std::string message, ...); + void error_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); + void warning_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); + void info_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); + void debug_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); class time_itf { public: @@ -89,13 +89,13 @@ private: logger_stdout def_logger_stdout; - void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg); - void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg, uint8_t *hex, int size); + void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, const char *msg); + void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, const char *msg, const uint8_t *hex, int size); void all_log_line(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string file, int line, char *msg); std::string now_time(); - std::string hex_string(uint8_t *hex, int size); + std::string hex_string(const uint8_t *hex, int size); }; } // namespace srsue -#endif // LOG_FILTER_H +#endif // SRSLTE_LOG_FILTER_H diff --git a/lib/include/srslte/common/logger.h b/lib/include/srslte/common/logger.h index 95e52922c..ed352cd5f 100644 --- a/lib/include/srslte/common/logger.h +++ b/lib/include/srslte/common/logger.h @@ -29,8 +29,8 @@ * Description: Interface for logging output *****************************************************************************/ -#ifndef LOGGER_H -#define LOGGER_H +#ifndef SRSLTE_LOGGER_H +#define SRSLTE_LOGGER_H #include #include @@ -45,4 +45,4 @@ public: } // namespace srslte -#endif // LOGGER_H +#endif // SRSLTE_LOGGER_H diff --git a/lib/include/srslte/common/logger_file.h b/lib/include/srslte/common/logger_file.h index d67a83220..f0bd5a15b 100644 --- a/lib/include/srslte/common/logger_file.h +++ b/lib/include/srslte/common/logger_file.h @@ -32,8 +32,8 @@ * increase queue size. If empty, consumer blocks. *****************************************************************************/ -#ifndef LOGGER_FILE_H -#define LOGGER_FILE_H +#ifndef SRSLTE_LOGGER_FILE_H +#define SRSLTE_LOGGER_FILE_H #include #include @@ -74,6 +74,6 @@ private: std::deque buffer; }; -} // namespace srsue +} // namespace srslte -#endif // LOGGER_H +#endif // SRSLTE_LOGGER_FILE_H diff --git a/lib/include/srslte/common/logger_stdout.h b/lib/include/srslte/common/logger_stdout.h index b76faadaf..4aab21d6b 100644 --- a/lib/include/srslte/common/logger_stdout.h +++ b/lib/include/srslte/common/logger_stdout.h @@ -29,8 +29,8 @@ * Description: Interface for logging output *****************************************************************************/ -#ifndef LOGGER_STDOUT_H -#define LOGGER_STDOUT_H +#ifndef SRSLTE_LOGGER_STDOUT_H +#define SRSLTE_LOGGER_STDOUT_H #include #include @@ -51,4 +51,4 @@ namespace srslte { } // namespace srslte -#endif // LOGGER_H +#endif // SRSLTE_LOGGER_STDOUT_H diff --git a/lib/include/srslte/common/mac_pcap.h b/lib/include/srslte/common/mac_pcap.h index 26a8f20bb..b403c8c49 100644 --- a/lib/include/srslte/common/mac_pcap.h +++ b/lib/include/srslte/common/mac_pcap.h @@ -24,8 +24,8 @@ * */ -#ifndef MACPCAP_H -#define MACPCAP_H +#ifndef SRSLTE_MAC_PCAP_H +#define SRSLTE_MAC_PCAP_H #include #include "srslte/common/pcap.h" @@ -59,6 +59,6 @@ private: uint16_t crnti_, uint8_t direction, uint8_t rnti_type); }; -} // namespace srsue +} // namespace srslte -#endif // MACPCAP_H +#endif // SRSLTE_MAC_PCAP_H diff --git a/lib/include/srslte/common/metrics_hub.h b/lib/include/srslte/common/metrics_hub.h index 05ab4c5fa..a73f3d90e 100644 --- a/lib/include/srslte/common/metrics_hub.h +++ b/lib/include/srslte/common/metrics_hub.h @@ -5,8 +5,8 @@ * to get metrics *****************************************************************************/ -#ifndef METRICS_HUB_H -#define METRICS_HUB_H +#ifndef SRSLTE_METRICS_HUB_H +#define SRSLTE_METRICS_HUB_H #include #include "srslte/common/threads.h" @@ -79,4 +79,4 @@ private: } // namespace srslte -#endif // METRICS_HUB_H +#endif // SRSLTE_METRICS_HUB_H diff --git a/lib/include/srslte/common/msg_queue.h b/lib/include/srslte/common/msg_queue.h index e8b8c742a..0dcdc2a55 100644 --- a/lib/include/srslte/common/msg_queue.h +++ b/lib/include/srslte/common/msg_queue.h @@ -30,8 +30,8 @@ * Reference: *****************************************************************************/ -#ifndef MSG_QUEUE_H -#define MSG_QUEUE_H +#ifndef SRSLTE_MSG_QUEUE_H +#define SRSLTE_MSG_QUEUE_H #include "srslte/common/common.h" #include @@ -149,7 +149,7 @@ private: uint32_t tail; }; -} // namespace srsue +} // namespace srslte -#endif // MSG_QUEUE_H +#endif // SRSLTE_MSG_QUEUE_H diff --git a/lib/include/srslte/common/nas_pcap.h b/lib/include/srslte/common/nas_pcap.h index 68fcabb73..061ba5010 100644 --- a/lib/include/srslte/common/nas_pcap.h +++ b/lib/include/srslte/common/nas_pcap.h @@ -1,5 +1,5 @@ -#ifndef NAS_PCAP_H -#define NAS_PCAP_H +#ifndef SRSLTE_NAS_PCAP_H +#define SRSLTE_NAS_PCAP_H #include "srslte/common/pcap.h" @@ -20,6 +20,6 @@ private: void pack_and_write(uint8_t* pdu, uint32_t pdu_len_bytes); }; -} //namespace srsue +} //namespace srslte -#endif // NAS_PCAP_H +#endif // SRSLTE_NAS_PCAP_H diff --git a/lib/include/srslte/common/pcap.h b/lib/include/srslte/common/pcap.h index ce4fcf541..d52547312 100644 --- a/lib/include/srslte/common/pcap.h +++ b/lib/include/srslte/common/pcap.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPCAP_H -#define UEPCAP_H +#ifndef SRSLTE_PCAP_H +#define SRSLTE_PCAP_H #include #include @@ -247,4 +247,4 @@ inline int LTE_PCAP_NAS_WritePDU(FILE *fd, NAS_Context_Info_t *context, return 1; } -#endif /* UEPCAP_H */ +#endif // SRSLTE_PCAP_H diff --git a/lib/include/srslte/common/pdu.h b/lib/include/srslte/common/pdu.h index 5d0f5a235..cc2bb64f5 100644 --- a/lib/include/srslte/common/pdu.h +++ b/lib/include/srslte/common/pdu.h @@ -24,8 +24,8 @@ * */ -#ifndef MACPDU_H -#define MACPDU_H +#ifndef SRSLTE_PDU_H +#define SRSLTE_PDU_H #include #include "srslte/common/log.h" @@ -338,6 +338,6 @@ private: uint8_t backoff_indicator; }; -} // namespace srsue +} // namespace srslte -#endif // MACPDU_H +#endif // SRSLTE_PDU_H diff --git a/lib/include/srslte/common/pdu_queue.h b/lib/include/srslte/common/pdu_queue.h index 40e0f2dd2..a0c2b1da9 100644 --- a/lib/include/srslte/common/pdu_queue.h +++ b/lib/include/srslte/common/pdu_queue.h @@ -24,8 +24,8 @@ * */ -#ifndef PDUPROC_H -#define PDUPROC_H +#ifndef SRSLTE_PDU_QUEUE_H +#define SRSLTE_PDU_QUEUE_H #include "srslte/common/log.h" #include "srslte/common/block_queue.h" @@ -79,7 +79,7 @@ private: } // namespace srslte -#endif // PDUPROC_H +#endif // SRSLTE_PDU_QUEUE_H diff --git a/lib/include/srslte/common/security.h b/lib/include/srslte/common/security.h index 9ba2616d1..80b4c0c0e 100644 --- a/lib/include/srslte/common/security.h +++ b/lib/include/srslte/common/security.h @@ -24,8 +24,8 @@ * */ -#ifndef SECURITY_H -#define SECURITY_H +#ifndef SRSLTE_SECURITY_H +#define SRSLTE_SECURITY_H /****************************************************************************** * Common security header - wraps ciphering/integrity check algorithms. @@ -175,6 +175,6 @@ uint8_t security_milenage_f5_star( uint8_t *k, uint8_t *ak); -} // namespace srsue +} // namespace srslte -#endif // SECURITY_H +#endif // SRSLTE_SECURITY_H diff --git a/lib/include/srslte/common/snow_3g.h b/lib/include/srslte/common/snow_3g.h index c20e6a626..d4c742bb7 100644 --- a/lib/include/srslte/common/snow_3g.h +++ b/lib/include/srslte/common/snow_3g.h @@ -9,6 +9,8 @@ * and Integrity Algorithms UEA2 & UIA2. * Document 2: SNOW 3G Specification" *---------------------------------------------------------*/ +#ifndef SRSLTE_SNOW_3G_H +#define SRSLTE_SNOW_3G_H #include #include @@ -69,3 +71,4 @@ void snow3g_f8( u8 *key, u32 count, u32 bearer, u32 dir, \ u8* snow3g_f9( u8* key, u32 count, u32 fresh, u32 dir, \ u8 *data, u64 length); +#endif // SRSLTE_SNOW_3G_H \ No newline at end of file diff --git a/lib/include/srslte/common/task_dispatcher.h b/lib/include/srslte/common/task_dispatcher.h index 5a86fc311..c1d223a2b 100644 --- a/lib/include/srslte/common/task_dispatcher.h +++ b/lib/include/srslte/common/task_dispatcher.h @@ -30,8 +30,8 @@ * Reference: *****************************************************************************/ -#ifndef TASK_DISPATCHER_H -#define TASK_DISPATCHER_H +#ifndef SRSLTE_TASK_DISPATCHER_H +#define SRSLTE_TASK_DISPATCHER_H #include #include @@ -56,6 +56,6 @@ private: bool running; }; -} // namespace srsue +} // namespace srslte -#endif // TASK_DISPATCHER_H +#endif // SRSLTE_TASK_DISPATCHER_H diff --git a/lib/include/srslte/common/thread_pool.h b/lib/include/srslte/common/thread_pool.h index 812ee2433..865fc10d9 100644 --- a/lib/include/srslte/common/thread_pool.h +++ b/lib/include/srslte/common/thread_pool.h @@ -31,8 +31,8 @@ * Reference: *****************************************************************************/ -#ifndef THREAD_POOL_H -#define THREAD_POOL_H +#ifndef SRSLTE_THREAD_POOL_H +#define SRSLTE_THREAD_POOL_H #include #include @@ -102,4 +102,4 @@ private: }; } -#endif +#endif // SRSLTE_THREAD_POOL_H diff --git a/lib/include/srslte/common/threads.h b/lib/include/srslte/common/threads.h index 3a2b78d2b..c6791ae7f 100644 --- a/lib/include/srslte/common/threads.h +++ b/lib/include/srslte/common/threads.h @@ -24,6 +24,7 @@ * */ + #include #include #include @@ -46,8 +47,8 @@ #ifdef __cplusplus } -#ifndef THREADS_ -#define THREADS_ +#ifndef SRSLTE_THREADS_H +#define SRSLTE_THREADS_H class thread { @@ -159,7 +160,7 @@ private: -#endif // THREADS_ +#endif // SRSLTE_THREADS_H #endif // __cplusplus diff --git a/lib/include/srslte/common/timeout.h b/lib/include/srslte/common/timeout.h index 4174b0237..bca09da31 100644 --- a/lib/include/srslte/common/timeout.h +++ b/lib/include/srslte/common/timeout.h @@ -31,8 +31,8 @@ * Reference: *****************************************************************************/ -#ifndef TIMEOUT_H -#define TIMEOUT_H +#ifndef SRSLTE_TIMEOUT_H +#define SRSLTE_TIMEOUT_H #include #include @@ -126,6 +126,6 @@ private: int duration_msec; }; -} // namespace srsue +} // namespace srslte -#endif // TIMEOUT_H +#endif // SRSLTE_TIMEOUT_H diff --git a/lib/include/srslte/common/timers.h b/lib/include/srslte/common/timers.h index 9809cc260..1b2bc1f83 100644 --- a/lib/include/srslte/common/timers.h +++ b/lib/include/srslte/common/timers.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef TIMERS_H -#define TIMERS_H +#ifndef SRSLTE_TIMERS_H +#define SRSLTE_TIMERS_H #include #include @@ -173,4 +173,4 @@ private: } // namespace srslte -#endif // TIMERS_H +#endif // SRSLTE_TIMERS_H diff --git a/lib/include/srslte/common/trace.h b/lib/include/srslte/common/trace.h index 64d55e460..00c7739f6 100644 --- a/lib/include/srslte/common/trace.h +++ b/lib/include/srslte/common/trace.h @@ -30,8 +30,8 @@ * Reference: *****************************************************************************/ -#ifndef TRACE_H -#define TRACE_H +#ifndef SRSLTE_TRACE_H +#define SRSLTE_TRACE_H #include #include @@ -98,4 +98,4 @@ private: } // namespace srslte -#endif // TRACE_H +#endif // SRSLTE_TRACE_H diff --git a/lib/include/srslte/common/tti_sync.h b/lib/include/srslte/common/tti_sync.h index fd62f442b..dd018f889 100644 --- a/lib/include/srslte/common/tti_sync.h +++ b/lib/include/srslte/common/tti_sync.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef TTISYNC_H -#define TTISYNC_H +#ifndef SRSLTE_TTI_SYNC_H +#define SRSLTE_TTI_SYNC_H #include @@ -77,4 +77,4 @@ class tti_sync } // namespace srsue -#endif // TTISYNC_H +#endif // SRSLTE_TTI_SYNC_H diff --git a/lib/include/srslte/common/tti_sync_cv.h b/lib/include/srslte/common/tti_sync_cv.h index 887ac4f04..2ba975faa 100644 --- a/lib/include/srslte/common/tti_sync_cv.h +++ b/lib/include/srslte/common/tti_sync_cv.h @@ -30,8 +30,8 @@ * Reference: *****************************************************************************/ -#ifndef TTISYNC_CV_H -#define TTISYNC_CV_H +#ifndef SRSLTE_TTI_SYNC_CV_H +#define SRSLTE_TTI_SYNC_CV_H #include #include "srslte/common/tti_sync.h" @@ -54,6 +54,6 @@ class tti_sync_cv : public tti_sync pthread_mutex_t mutex; }; -} // namespace srsue +} // namespace srslte -#endif // TTISYNC_CV_H +#endif // SRSLTE_TTI_SYNC_CV_H diff --git a/lib/include/srslte/config.h b/lib/include/srslte/config.h index 1e9d27aac..02c43777f 100644 --- a/lib/include/srslte/config.h +++ b/lib/include/srslte/config.h @@ -24,8 +24,8 @@ * */ -#ifndef CONFIG_H -#define CONFIG_H +#ifndef SRSLTE_CONFIG_H +#define SRSLTE_CONFIG_H // Generic helper definitions for shared library support #if defined _WIN32 || defined __CYGWIN__ @@ -64,4 +64,4 @@ typedef _Complex float cf_t; typedef _Complex short int c16_t; #endif /* ENABLE_C16 */ -#endif // CONFIG_H +#endif // SRSLTE_CONFIG_H diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index cd7d10020..cad5c5eb1 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -36,8 +36,8 @@ #include -#ifndef ENBINTERFACES_H -#define ENBINTERFACES_H +#ifndef SRSLTE_ENB_INTERFACES_H +#define SRSLTE_ENB_INTERFACES_H namespace srsenb { @@ -272,4 +272,4 @@ public: } -#endif +#endif // SRSLTE_ENB_INTERFACES_H diff --git a/lib/include/srslte/interfaces/enb_metrics_interface.h b/lib/include/srslte/interfaces/enb_metrics_interface.h index ee00e3453..4e540ab78 100644 --- a/lib/include/srslte/interfaces/enb_metrics_interface.h +++ b/lib/include/srslte/interfaces/enb_metrics_interface.h @@ -24,18 +24,18 @@ * */ -#ifndef ENB_METRICS_INTERFACE_H -#define ENB_METRICS_INTERFACE_H +#ifndef SRSLTE_ENB_METRICS_INTERFACE_H +#define SRSLTE_ENB_METRICS_INTERFACE_H #include -#include "upper/common_enb.h" -#include "upper/s1ap_metrics.h" -#include "upper/rrc_metrics.h" -#include "../../../../srsue/hdr/upper/gw_metrics.h" +#include "srsenb/hdr/upper/common_enb.h" +#include "srsenb/hdr/upper/s1ap_metrics.h" +#include "srsenb/hdr/upper/rrc_metrics.h" +#include "srsue/hdr/upper/gw_metrics.h" #include "srslte/upper/rlc_metrics.h" -#include "mac/mac_metrics.h" -#include "phy/phy_metrics.h" +#include "srsenb/hdr/mac/mac_metrics.h" +#include "srsenb/hdr/phy/phy_metrics.h" namespace srsenb { @@ -64,4 +64,4 @@ public: } // namespace srsenb -#endif // ENB_METRICS_INTERFACE_H +#endif // SRSLTE_ENB_METRICS_INTERFACE_H diff --git a/lib/include/srslte/interfaces/epc_interfaces.h b/lib/include/srslte/interfaces/epc_interfaces.h index 21646628a..60238b7f9 100644 --- a/lib/include/srslte/interfaces/epc_interfaces.h +++ b/lib/include/srslte/interfaces/epc_interfaces.h @@ -1,5 +1,5 @@ -#ifndef EPC_INTERFACE_H -#define EPC_INTERFACE_H +#ifndef SRSLTE_EPC_INTERFACES_H +#define SRSLTE_EPC_INTERFACES_H #include "srslte/srslte.h" @@ -15,4 +15,4 @@ public: }; } -#endif // ENB_METRICS_INTERFACE_H +#endif // SRSLTE_EPC_INTERFACES_H diff --git a/lib/include/srslte/interfaces/sched_interface.h b/lib/include/srslte/interfaces/sched_interface.h index 562499dfb..5160b4490 100644 --- a/lib/include/srslte/interfaces/sched_interface.h +++ b/lib/include/srslte/interfaces/sched_interface.h @@ -26,8 +26,8 @@ #include "srslte/srslte.h" -#ifndef SCHED_INTERFACE_H -#define SCHED_INTERFACE_H +#ifndef SRSLTE_SCHED_INTERFACE_H +#define SRSLTE_SCHED_INTERFACE_H namespace srsenb { @@ -248,4 +248,4 @@ public: } -#endif +#endif // SRSLTE_SCHED_INTERFACE_H diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index 0ddebee47..ce0810cca 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -30,8 +30,8 @@ * to other layers. *****************************************************************************/ -#ifndef INTERFACES_H -#define INTERFACES_H +#ifndef SRSLTE_UE_INTERFACES_H +#define SRSLTE_UE_INTERFACES_H #include @@ -608,6 +608,6 @@ public: }; -} // namespace srslte +} // namespace srsue -#endif // INTERFACES_H +#endif // SRSLTE_UE_INTERFACES_H diff --git a/lib/include/srslte/phy/agc/agc.h b/lib/include/srslte/phy/agc/agc.h index 0a6bba8c1..ab7bb2ed7 100644 --- a/lib/include/srslte/phy/agc/agc.h +++ b/lib/include/srslte/phy/agc/agc.h @@ -33,8 +33,8 @@ * Reference: *********************************************************************************************/ -#ifndef AGC_ -#define AGC_ +#ifndef SRSLTE_AGC_H +#define SRSLTE_AGC_H #include #include @@ -101,4 +101,4 @@ SRSLTE_API void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len); -#endif // AGC_ +#endif // SRSLTE_AGC_H diff --git a/lib/include/srslte/phy/ch_estimation/chest_common.h b/lib/include/srslte/phy/ch_estimation/chest_common.h index 8eb63aa73..276d9c55e 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_common.h +++ b/lib/include/srslte/phy/ch_estimation/chest_common.h @@ -24,8 +24,8 @@ * */ -#ifndef CHEST_ -#define CHEST_ +#ifndef SRSLTE_CHEST_COMMON_H +#define SRSLTE_CHEST_COMMON_H #include #include "srslte/config.h" @@ -51,5 +51,5 @@ SRSLTE_API float srslte_chest_estimate_noise_pilots(cf_t *noisy, SRSLTE_API void srslte_chest_set_triangle_filter(float *fil, int filter_len); -#endif +#endif // SRSLTE_CHEST_COMMON_H diff --git a/lib/include/srslte/phy/ch_estimation/chest_dl.h b/lib/include/srslte/phy/ch_estimation/chest_dl.h index e7cc28bed..a521d653e 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_dl.h +++ b/lib/include/srslte/phy/ch_estimation/chest_dl.h @@ -38,8 +38,8 @@ * Reference: *********************************************************************************************/ -#ifndef CHEST_DL_ -#define CHEST_DL_ +#ifndef SRSLTE_CHEST_DL_H +#define SRSLTE_CHEST_DL_H #include @@ -193,4 +193,4 @@ SRSLTE_API float srslte_chest_dl_get_rsrp(srslte_chest_dl_t *q); SRSLTE_API float srslte_chest_dl_get_rsrp_neighbour(srslte_chest_dl_t *q); -#endif +#endif // SRSLTE_CHEST_DL_H diff --git a/lib/include/srslte/phy/ch_estimation/chest_ul.h b/lib/include/srslte/phy/ch_estimation/chest_ul.h index 0571fec8c..df5c11db6 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_ul.h +++ b/lib/include/srslte/phy/ch_estimation/chest_ul.h @@ -36,8 +36,8 @@ * Reference: *********************************************************************************************/ -#ifndef CHEST_UL_ -#define CHEST_UL_ +#ifndef SRSLTE_CHEST_UL_H +#define SRSLTE_CHEST_UL_H #include @@ -118,4 +118,4 @@ SRSLTE_API float srslte_chest_ul_get_noise_estimate(srslte_chest_ul_t *q); SRSLTE_API float srslte_chest_ul_get_snr(srslte_chest_ul_t *q); -#endif +#endif // SRSLTE_CHEST_UL_H diff --git a/lib/include/srslte/phy/ch_estimation/refsignal_dl.h b/lib/include/srslte/phy/ch_estimation/refsignal_dl.h index 9263073a9..6167d8d4e 100644 --- a/lib/include/srslte/phy/ch_estimation/refsignal_dl.h +++ b/lib/include/srslte/phy/ch_estimation/refsignal_dl.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.10 *********************************************************************************************/ -#ifndef SRSLTE_REFSIGNAL_DL_ -#define SRSLTE_REFSIGNAL_DL_ +#ifndef SRSLTE_REFSIGNAL_DL_H +#define SRSLTE_REFSIGNAL_DL_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -118,4 +118,4 @@ SRSLTE_API int srslte_refsignal_mbsfn_gen_seq(srslte_refsignal_t * q, uint32_t N_mbsfn_id); -#endif +#endif // SRSLTE_REFSIGNAL_DL_H diff --git a/lib/include/srslte/phy/ch_estimation/refsignal_ul.h b/lib/include/srslte/phy/ch_estimation/refsignal_ul.h index 9e1da9e50..7b393e8d9 100644 --- a/lib/include/srslte/phy/ch_estimation/refsignal_ul.h +++ b/lib/include/srslte/phy/ch_estimation/refsignal_ul.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.5 *********************************************************************************************/ -#ifndef SRSLTE_REFSIGNAL_UL_ -#define SRSLTE_REFSIGNAL_UL_ +#ifndef SRSLTE_REFSIGNAL_UL_H +#define SRSLTE_REFSIGNAL_UL_H #include "srslte/config.h" #include "srslte/phy/phch/pucch.h" @@ -209,4 +209,4 @@ SRSLTE_API uint32_t srslte_refsignal_srs_rb_L_cs(uint32_t bw_cfg, SRSLTE_API uint32_t srslte_refsignal_srs_M_sc(srslte_refsignal_ul_t *q); -#endif +#endif // SRSLTE_REFSIGNAL_UL_H diff --git a/lib/include/srslte/phy/channel/ch_awgn.h b/lib/include/srslte/phy/channel/ch_awgn.h index ace971961..3dbabcda7 100644 --- a/lib/include/srslte/phy/channel/ch_awgn.h +++ b/lib/include/srslte/phy/channel/ch_awgn.h @@ -37,8 +37,8 @@ #include "srslte/config.h" -#ifndef CH_AWGN_ -#define CH_AWGN_ +#ifndef SRSLTE_CH_AWGN_H +#define SRSLTE_CH_AWGN_H SRSLTE_API void srslte_ch_awgn_c(const cf_t* input, cf_t* output, @@ -54,4 +54,4 @@ SRSLTE_API float srslte_ch_awgn_get_variance(float ebno_db, float rate); -#endif +#endif // SRSLTE_CH_AWGN_H diff --git a/lib/include/srslte/phy/common/phy_common.h b/lib/include/srslte/phy/common/phy_common.h index c55713cfc..82c2dfaa8 100644 --- a/lib/include/srslte/phy/common/phy_common.h +++ b/lib/include/srslte/phy/common/phy_common.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 *********************************************************************************************/ -#ifndef _LTEBASE_ -#define _LTEBASE_ +#ifndef SRSLTE_PHY_COMMON_H +#define SRSLTE_PHY_COMMON_H #include #include @@ -305,4 +305,4 @@ SRSLTE_API char *srslte_mimotype2str(srslte_mimo_type_t mimo_type); SRSLTE_API uint32_t srslte_tti_interval(uint32_t tti1, uint32_t tti2); -#endif +#endif // SRSLTE_PHY_COMMON_H diff --git a/lib/include/srslte/phy/common/phy_logger.h b/lib/include/srslte/phy/common/phy_logger.h index d02efbb47..2f0805df8 100644 --- a/lib/include/srslte/phy/common/phy_logger.h +++ b/lib/include/srslte/phy/common/phy_logger.h @@ -29,8 +29,8 @@ * Description: Interface for logging output *****************************************************************************/ -#ifndef PHY_LOGGER_H -#define PHY_LOGGER_H +#ifndef SRSLTE_PHY_LOGGER_H +#define SRSLTE_PHY_LOGGER_H #include #include @@ -56,4 +56,4 @@ void srslte_phy_log_register_handler(void *ctx, phy_log_handler_t handler); } #endif // C++ -#endif // LOGGER_H +#endif // SRSLTE_PHY_LOGGER_H diff --git a/lib/include/srslte/phy/common/sequence.h b/lib/include/srslte/phy/common/sequence.h index 62934c7e0..346be1cda 100644 --- a/lib/include/srslte/phy/common/sequence.h +++ b/lib/include/srslte/phy/common/sequence.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.2 *********************************************************************************************/ -#ifndef LTESEQ_ -#define LTESEQ_ +#ifndef SRSLTE_SEQUENCE_H +#define SRSLTE_SEQUENCE_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -100,4 +100,4 @@ SRSLTE_API int srslte_sequence_pmch(srslte_sequence_t *seq, uint32_t mbsfn_id, uint32_t len); -#endif +#endif // SRSLTE_SEQUENCE_H diff --git a/lib/include/srslte/phy/common/timestamp.h b/lib/include/srslte/phy/common/timestamp.h index 8dd960b69..f4c505b4a 100644 --- a/lib/include/srslte/phy/common/timestamp.h +++ b/lib/include/srslte/phy/common/timestamp.h @@ -34,8 +34,8 @@ * Reference: *********************************************************************************************/ -#ifndef TIMESTAMP_ -#define TIMESTAMP_ +#ifndef SRSLTE_TIMESTAMP_H +#define SRSLTE_TIMESTAMP_H #include #include @@ -65,4 +65,4 @@ SRSLTE_API double srslte_timestamp_real(srslte_timestamp_t *t); SRSLTE_API uint32_t srslte_timestamp_uint32(srslte_timestamp_t *t); -#endif // TIMESTAMP_ +#endif // SRSLTE_TIMESTAMP_H diff --git a/lib/include/srslte/phy/dft/dft.h b/lib/include/srslte/phy/dft/dft.h index afe8024d2..e62362d8c 100644 --- a/lib/include/srslte/phy/dft/dft.h +++ b/lib/include/srslte/phy/dft/dft.h @@ -25,8 +25,8 @@ */ -#ifndef DFT_H_ -#define DFT_H_ +#ifndef SRSLTE_DFT_H +#define SRSLTE_DFT_H #include #include "srslte/config.h" @@ -157,5 +157,5 @@ SRSLTE_API void srslte_dft_run_r(srslte_dft_plan_t *plan, const float *in, float *out); -#endif // DFT_H_ +#endif // SRSLTE_DFT_H diff --git a/lib/include/srslte/phy/dft/dft_precoding.h b/lib/include/srslte/phy/dft/dft_precoding.h index 022593aa7..c1eb20ec6 100644 --- a/lib/include/srslte/phy/dft/dft_precoding.h +++ b/lib/include/srslte/phy/dft/dft_precoding.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.3.3 *********************************************************************************************/ -#ifndef DFTPREC_ -#define DFTPREC_ +#ifndef SRSLTE_DFT_PRECODING_H +#define SRSLTE_DFT_PRECODING_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -68,4 +68,4 @@ SRSLTE_API int srslte_dft_precoding(srslte_dft_precoding_t *q, uint32_t nof_prb, uint32_t nof_symbols); -#endif +#endif // SRSLTE_DFT_PRECODING_H diff --git a/lib/include/srslte/phy/dft/ofdm.h b/lib/include/srslte/phy/dft/ofdm.h index e48c240b9..6f31ed3ab 100644 --- a/lib/include/srslte/phy/dft/ofdm.h +++ b/lib/include/srslte/phy/dft/ofdm.h @@ -25,8 +25,8 @@ */ -#ifndef LTEFFT_ -#define LTEFFT_ +#ifndef SRSLTE_OFDM_H +#define SRSLTE_OFDM_H /********************************************************************************************** * File: ofdm.h @@ -158,4 +158,4 @@ SRSLTE_API void srslte_ofdm_set_non_mbsfn_region(srslte_ofdm_t *q, uint8_t non_mbsfn_region); -#endif +#endif // SRSLTE_OFDM_H diff --git a/lib/include/srslte/phy/enb/enb_dl.h b/lib/include/srslte/phy/enb/enb_dl.h index 232dc459c..2b11bd6e3 100644 --- a/lib/include/srslte/phy/enb/enb_dl.h +++ b/lib/include/srslte/phy/enb/enb_dl.h @@ -35,8 +35,8 @@ * Reference: *****************************************************************************/ -#ifndef ENBDL_H -#define ENBDL_H +#ifndef SRSLTE_ENB_DL_H +#define SRSLTE_ENB_DL_H #include @@ -195,4 +195,4 @@ SRSLTE_API void srslte_enb_dl_save_signal(srslte_enb_dl_t *q, uint16_t rnti, uint32_t cfi); -#endif +#endif // SRSLTE_ENB_DL_H diff --git a/lib/include/srslte/phy/enb/enb_ul.h b/lib/include/srslte/phy/enb/enb_ul.h index 8699a2a37..49d174807 100644 --- a/lib/include/srslte/phy/enb/enb_ul.h +++ b/lib/include/srslte/phy/enb/enb_ul.h @@ -35,8 +35,8 @@ * Reference: *****************************************************************************/ -#ifndef ENBUL_H -#define ENBUL_H +#ifndef SRSLTE_ENB_UL_H +#define SRSLTE_ENB_UL_H #include @@ -153,4 +153,4 @@ SRSLTE_API int srslte_enb_ul_detect_prach(srslte_enb_ul_t *q, float *peak2avg); -#endif +#endif // SRSLTE_ENB_UL_H diff --git a/lib/include/srslte/phy/fec/cbsegm.h b/lib/include/srslte/phy/fec/cbsegm.h index f89cb089d..7eee8320d 100644 --- a/lib/include/srslte/phy/fec/cbsegm.h +++ b/lib/include/srslte/phy/fec/cbsegm.h @@ -29,8 +29,8 @@ #include "srslte/config.h" -#ifndef CBSEGM_H -#define CBSEGM_H +#ifndef SRSLTE_CBSEGM_H +#define SRSLTE_CBSEGM_H #define SRSLTE_NOF_TC_CB_SIZES 188 @@ -56,4 +56,4 @@ SRSLTE_API bool srslte_cbsegm_cbsize_isvalid(uint32_t size); SRSLTE_API int srslte_cbsegm_cbindex(uint32_t long_cb); -#endif +#endif // SRSLTE_CBSEGM_H diff --git a/lib/include/srslte/phy/fec/convcoder.h b/lib/include/srslte/phy/fec/convcoder.h index 1d51cbcbc..99dfd333e 100644 --- a/lib/include/srslte/phy/fec/convcoder.h +++ b/lib/include/srslte/phy/fec/convcoder.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.1 *********************************************************************************************/ -#ifndef CONVCODER_ -#define CONVCODER_ +#ifndef SRSLTE_CONVCODER_H +#define SRSLTE_CONVCODER_H #include #include "srslte/config.h" @@ -53,4 +53,4 @@ SRSLTE_API int srslte_convcoder_encode(srslte_convcoder_t *q, uint32_t frame_length); -#endif +#endif // SRSLTE_CONVCODER_H diff --git a/lib/include/srslte/phy/fec/crc.h b/lib/include/srslte/phy/fec/crc.h index 89b4a122f..030e7c6bb 100644 --- a/lib/include/srslte/phy/fec/crc.h +++ b/lib/include/srslte/phy/fec/crc.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.1 *********************************************************************************************/ -#ifndef CRC_ -#define CRC_ +#ifndef SRSLTE_CRC_H +#define SRSLTE_CRC_H #include "srslte/config.h" #include @@ -73,4 +73,4 @@ SRSLTE_API uint32_t srslte_crc_checksum(srslte_crc_t *h, uint8_t *data, int len); -#endif +#endif // SRSLTE_CRC_H diff --git a/lib/include/srslte/phy/fec/rm_conv.h b/lib/include/srslte/phy/fec/rm_conv.h index 92e640e3a..9681ce827 100644 --- a/lib/include/srslte/phy/fec/rm_conv.h +++ b/lib/include/srslte/phy/fec/rm_conv.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.4.2 *********************************************************************************************/ -#ifndef RM_CONV_ -#define RM_CONV_ +#ifndef SRSLTE_RM_CONV_H +#define SRSLTE_RM_CONV_H #include "srslte/config.h" @@ -63,4 +63,4 @@ SRSLTE_API int srslte_rm_conv_rx_s(int16_t *input, int16_t *output, uint32_t out_len); -#endif +#endif // SRSLTE_RM_CONV_H diff --git a/lib/include/srslte/phy/fec/rm_turbo.h b/lib/include/srslte/phy/fec/rm_turbo.h index 182b49fb8..26f98944c 100644 --- a/lib/include/srslte/phy/fec/rm_turbo.h +++ b/lib/include/srslte/phy/fec/rm_turbo.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.4.1 *********************************************************************************************/ -#ifndef RM_TURBO_ -#define RM_TURBO_ +#ifndef SRSLTE_RM_TURBO_H +#define SRSLTE_RM_TURBO_H #include "srslte/config.h" @@ -85,4 +85,4 @@ SRSLTE_API int srslte_rm_turbo_rx_lut(int16_t *input, uint32_t rv_idx); -#endif +#endif // SRSLTE_RM_TURBO_H diff --git a/lib/include/srslte/phy/fec/softbuffer.h b/lib/include/srslte/phy/fec/softbuffer.h index 3949134d8..864fc1439 100644 --- a/lib/include/srslte/phy/fec/softbuffer.h +++ b/lib/include/srslte/phy/fec/softbuffer.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef SOFTBUFFER_ -#define SOFTBUFFER_ +#ifndef SRSLTE_SOFTBUFFER_H +#define SRSLTE_SOFTBUFFER_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -82,4 +82,4 @@ SRSLTE_API void srslte_softbuffer_tx_free(srslte_softbuffer_tx_t *p); -#endif +#endif // SRSLTE_SOFTBUFFER_H diff --git a/lib/include/srslte/phy/fec/tc_interl.h b/lib/include/srslte/phy/fec/tc_interl.h index ad46edd8f..c0ffaae58 100644 --- a/lib/include/srslte/phy/fec/tc_interl.h +++ b/lib/include/srslte/phy/fec/tc_interl.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2.3 *********************************************************************************************/ -#ifndef _TC_INTERL_H -#define _TC_INTERL_H +#ifndef SRSLTE_TC_INTERL_H +#define SRSLTE_TC_INTERL_H #include "srslte/config.h" #include @@ -55,4 +55,4 @@ SRSLTE_API int srslte_tc_interl_init(srslte_tc_interl_t *h, SRSLTE_API void srslte_tc_interl_free(srslte_tc_interl_t *h); -#endif +#endif // SRSLTE_TC_INTERL_H diff --git a/lib/include/srslte/phy/fec/turbocoder.h b/lib/include/srslte/phy/fec/turbocoder.h index 119e4f641..485e83ff3 100644 --- a/lib/include/srslte/phy/fec/turbocoder.h +++ b/lib/include/srslte/phy/fec/turbocoder.h @@ -35,8 +35,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBOCODER_ -#define TURBOCODER_ +#ifndef SRSLTE_TURBOCODER_H +#define SRSLTE_TURBOCODER_H #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -75,5 +75,5 @@ SRSLTE_API int srslte_tcod_encode_lut(srslte_tcod_t *h, SRSLTE_API void srslte_tcod_gentable(); -#endif +#endif // SRSLTE_TURBOCODER_H diff --git a/lib/include/srslte/phy/fec/turbodecoder.h b/lib/include/srslte/phy/fec/turbodecoder.h index ac05422bc..d882118aa 100644 --- a/lib/include/srslte/phy/fec/turbodecoder.h +++ b/lib/include/srslte/phy/fec/turbodecoder.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_ -#define TURBODECODER_ +#ifndef SRSLTE_TURBODECODER_H +#define SRSLTE_TURBODECODER_H #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -117,4 +117,4 @@ SRSLTE_API int srslte_tdec_run_all_par(srslte_tdec_t * h, uint32_t nof_iterations, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_gen.h b/lib/include/srslte/phy/fec/turbodecoder_gen.h index 4a023396c..2fefc22cc 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_gen.h +++ b/lib/include/srslte/phy/fec/turbodecoder_gen.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_GEN_ -#define TURBODECODER_GEN_ +#ifndef SRSLTE_TURBODECODER_GEN_H +#define SRSLTE_TURBODECODER_GEN_H #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -96,4 +96,4 @@ SRSLTE_API int srslte_tdec_gen_run_all(srslte_tdec_gen_t * h, uint32_t nof_iterations, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_GEN_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_simd.h b/lib/include/srslte/phy/fec/turbodecoder_simd.h index a899a5964..35c8beef9 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_simd.h +++ b/lib/include/srslte/phy/fec/turbodecoder_simd.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_SSE_ -#define TURBODECODER_SSE_ +#ifndef SRSLTE_TURBODECODER_SIMD_H +#define SRSLTE_TURBODECODER_SIMD_H #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -119,4 +119,4 @@ SRSLTE_API int srslte_tdec_simd_run_all(srslte_tdec_simd_t * h, uint32_t nof_iterations, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_SIMD_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_simd_inter.h b/lib/include/srslte/phy/fec/turbodecoder_simd_inter.h index c80785809..054fbc3cb 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_simd_inter.h +++ b/lib/include/srslte/phy/fec/turbodecoder_simd_inter.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_SSE_INTER_ -#define TURBODECODER_SSE_INTER_ +#ifndef SRSLTE_TURBODECODER_SIMD_INTER_H +#define SRSLTE_TURBODECODER_SIMD_INTER_H /** This is an simd inter-frame parallel turbo decoder. Parallizes 8 code-blocks using SSE @@ -116,4 +116,4 @@ SRSLTE_API int srslte_tdec_simd_inter_run_all(srslte_tdec_simd_inter_t * h, uint32_t nof_cb, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_SIMD_INTER_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_sse.h b/lib/include/srslte/phy/fec/turbodecoder_sse.h index 8b9f24372..9678fba9a 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_sse.h +++ b/lib/include/srslte/phy/fec/turbodecoder_sse.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_SSE_ -#define TURBODECODER_SSE_ +#ifndef SRSLTE_TURBODECODER_SSE_ +#define SRSLTE_TURBODECODER_SSE_ #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -98,4 +98,4 @@ SRSLTE_API int srslte_tdec_sse_run_all(srslte_tdec_sse_t * h, uint32_t nof_iterations, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_SSE_ diff --git a/lib/include/srslte/phy/fec/viterbi.h b/lib/include/srslte/phy/fec/viterbi.h index 689b636e9..0f6f0cd50 100644 --- a/lib/include/srslte/phy/fec/viterbi.h +++ b/lib/include/srslte/phy/fec/viterbi.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef VITERBI_ -#define VITERBI_ +#ifndef SRSLTE_VITERBI_H +#define SRSLTE_VITERBI_H #include #include "srslte/config.h" @@ -119,4 +119,4 @@ SRSLTE_API int srslte_viterbi_init_avx2(srslte_viterbi_t *q, -#endif +#endif // SRSLTE_VITERBI_H diff --git a/lib/include/srslte/phy/io/binsource.h b/lib/include/srslte/phy/io/binsource.h index a89a305ea..733449b25 100644 --- a/lib/include/srslte/phy/io/binsource.h +++ b/lib/include/srslte/phy/io/binsource.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef BINSOURCE_ -#define BINSOURCE_ +#ifndef SRSLTE_BINSOURCE_H +#define SRSLTE_BINSOURCE_H #include @@ -68,4 +68,4 @@ SRSLTE_API int srslte_binsource_generate(srslte_binsource_t* q, uint8_t *bits, int nbits); -#endif // BINSOURCE_ +#endif // SRSLTE_BINSOURCE_H diff --git a/lib/include/srslte/phy/io/filesink.h b/lib/include/srslte/phy/io/filesink.h index 921f1e440..b6fee3adf 100644 --- a/lib/include/srslte/phy/io/filesink.h +++ b/lib/include/srslte/phy/io/filesink.h @@ -34,8 +34,8 @@ * Reference: *****************************************************************************/ -#ifndef FILESINK_ -#define FILESINK_ +#ifndef SRSLTE_FILESINK_H +#define SRSLTE_FILESINK_H #include #include @@ -64,4 +64,4 @@ SRSLTE_API int srslte_filesink_write_multi(srslte_filesink_t *q, int nsamples, int nchannels); -#endif // FILESINK_ +#endif // SRSLTE_FILESINK_H diff --git a/lib/include/srslte/phy/io/filesource.h b/lib/include/srslte/phy/io/filesource.h index f515d7034..d4ad81f94 100644 --- a/lib/include/srslte/phy/io/filesource.h +++ b/lib/include/srslte/phy/io/filesource.h @@ -34,8 +34,8 @@ * Reference: *****************************************************************************/ -#ifndef FILESOURCE_ -#define FILESOURCE_ +#ifndef SRSLTE_FILESOURCE_H +#define SRSLTE_FILESOURCE_H #include #include @@ -67,4 +67,4 @@ SRSLTE_API int srslte_filesource_read_multi(srslte_filesource_t *q, int nsamples, int nof_channels); -#endif // FILESOURCE_ +#endif // SRSLTE_FILESOURCE_H diff --git a/lib/include/srslte/phy/io/format.h b/lib/include/srslte/phy/io/format.h index 81bf1f702..22c0e3973 100644 --- a/lib/include/srslte/phy/io/format.h +++ b/lib/include/srslte/phy/io/format.h @@ -25,8 +25,8 @@ */ -#ifndef FORMAT_ -#define FORMAT_ +#ifndef SRSLTE_FORMAT_H +#define SRSLTE_FORMAT_H typedef enum { SRSLTE_FLOAT, @@ -37,4 +37,4 @@ typedef enum { SRSLTE_COMPLEX_SHORT_BIN } srslte_datatype_t; -#endif // FORMAT_ +#endif // SRSLTE_FORMAT_H diff --git a/lib/include/srslte/phy/io/netsink.h b/lib/include/srslte/phy/io/netsink.h index 3339716c1..246c520bf 100644 --- a/lib/include/srslte/phy/io/netsink.h +++ b/lib/include/srslte/phy/io/netsink.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef NETSINK_ -#define NETSINK_ +#ifndef SRSLTE_NETSINK_H +#define SRSLTE_NETSINK_H #include #include @@ -71,4 +71,4 @@ SRSLTE_API int srslte_netsink_write(srslte_netsink_t *q, SRSLTE_API int srslte_netsink_set_nonblocking(srslte_netsink_t *q); -#endif // UDPSINK_ +#endif // SRSLTE_NETSINK_H diff --git a/lib/include/srslte/phy/io/netsource.h b/lib/include/srslte/phy/io/netsource.h index e10d8d644..ee0ca69da 100644 --- a/lib/include/srslte/phy/io/netsource.h +++ b/lib/include/srslte/phy/io/netsource.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef NETSOURCE_ -#define NETSOURCE_ +#ifndef SRSLTE_NETSOURCE_H +#define SRSLTE_NETSOURCE_H #include #include @@ -75,4 +75,4 @@ SRSLTE_API int srslte_netsource_read(srslte_netsource_t *q, SRSLTE_API int srslte_netsource_set_timeout(srslte_netsource_t *q, uint32_t microseconds); -#endif // UDPSOURCE_ +#endif // SRSLTE_NETSOURCE_H diff --git a/lib/include/srslte/phy/mimo/layermap.h b/lib/include/srslte/phy/mimo/layermap.h index 5daf51c14..d6328a7ad 100644 --- a/lib/include/srslte/phy/mimo/layermap.h +++ b/lib/include/srslte/phy/mimo/layermap.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.3.3 *****************************************************************************/ -#ifndef LAYERMAP_H_ -#define LAYERMAP_H_ +#ifndef SRSLTE_LAYERMAP_H +#define SRSLTE_LAYERMAP_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -91,4 +91,4 @@ SRSLTE_API int srslte_layerdemap_type(cf_t *x[SRSLTE_MAX_LAYERS], int nof_symbols[SRSLTE_MAX_CODEWORDS], srslte_mimo_type_t type); -#endif // LAYERMAP_H_ +#endif // SRSLTE_LAYERMAP_H diff --git a/lib/include/srslte/phy/mimo/precoding.h b/lib/include/srslte/phy/mimo/precoding.h index 27395085c..d363231e2 100644 --- a/lib/include/srslte/phy/mimo/precoding.h +++ b/lib/include/srslte/phy/mimo/precoding.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.3.4 *****************************************************************************/ -#ifndef PRECODING_H_ -#define PRECODING_H_ +#ifndef SRSLTE_PRECODING_H +#define SRSLTE_PRECODING_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -137,4 +137,4 @@ SRSLTE_API int srslte_precoding_cn(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], float *cn); -#endif /* PRECODING_H_ */ +#endif // SRSLTE_PRECODING_H diff --git a/lib/include/srslte/phy/modem/demod_hard.h b/lib/include/srslte/phy/modem/demod_hard.h index 6da2b7b4d..689bcca42 100644 --- a/lib/include/srslte/phy/modem/demod_hard.h +++ b/lib/include/srslte/phy/modem/demod_hard.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.1 *****************************************************************************/ -#ifndef DEMOD_HARD_ -#define DEMOD_HARD_ +#ifndef SRSLTE_DEMOD_HARD_H +#define SRSLTE_DEMOD_HARD_H #include #include @@ -57,4 +57,4 @@ SRSLTE_API int srslte_demod_hard_demodulate(srslte_demod_hard_t* q, uint8_t *bits, uint32_t nsymbols); -#endif // DEMOD_HARD_ +#endif // SRSLTE_DEMOD_HARD_H diff --git a/lib/include/srslte/phy/modem/demod_soft.h b/lib/include/srslte/phy/modem/demod_soft.h index 7ac4f0702..9ad065edc 100644 --- a/lib/include/srslte/phy/modem/demod_soft.h +++ b/lib/include/srslte/phy/modem/demod_soft.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.1 *****************************************************************************/ -#ifndef DEMOD_SOFT_ -#define DEMOD_SOFT_ +#ifndef SRSLTE_DEMOD_SOFT_H +#define SRSLTE_DEMOD_SOFT_H #include #include @@ -53,4 +53,4 @@ SRSLTE_API int srslte_demod_soft_demodulate_s(srslte_mod_t modulation, short* llr, int nsymbols); -#endif // DEMOD_SOFT_ +#endif // SRSLTE_DEMOD_SOFT_H diff --git a/lib/include/srslte/phy/modem/mod.h b/lib/include/srslte/phy/modem/mod.h index 66aa997cb..a2f8299a1 100644 --- a/lib/include/srslte/phy/modem/mod.h +++ b/lib/include/srslte/phy/modem/mod.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.1 *****************************************************************************/ -#ifndef MOD_ -#define MOD_ +#ifndef SRSLTE_MOD_H +#define SRSLTE_MOD_H #include #include @@ -52,4 +52,4 @@ SRSLTE_API int srslte_mod_modulate_bytes(srslte_modem_table_t* q, cf_t* symbols, uint32_t nbits); -#endif // MOD_ +#endif // SRSLTE_MOD_H diff --git a/lib/include/srslte/phy/modem/modem_table.h b/lib/include/srslte/phy/modem/modem_table.h index 20b0a0f88..09cea5e10 100644 --- a/lib/include/srslte/phy/modem/modem_table.h +++ b/lib/include/srslte/phy/modem/modem_table.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.1 *****************************************************************************/ -#ifndef MODEM_TABLE_ -#define MODEM_TABLE_ +#ifndef SRSLTE_MODEM_TABLE_H +#define SRSLTE_MODEM_TABLE_H #include #include @@ -83,4 +83,4 @@ SRSLTE_API int srslte_modem_table_lte(srslte_modem_table_t* q, SRSLTE_API void srslte_modem_table_bytes(srslte_modem_table_t* q); -#endif // MODEM_TABLE_ +#endif // SRSLTE_MODEM_TABLE_H diff --git a/lib/include/srslte/phy/phch/cqi.h b/lib/include/srslte/phy/phch/cqi.h index b8cc80ece..4363ccaa7 100644 --- a/lib/include/srslte/phy/phch/cqi.h +++ b/lib/include/srslte/phy/phch/cqi.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.2.2.6, 5.2.3.3 *****************************************************************************/ -#ifndef CQI_ -#define CQI_ +#ifndef SRSLTE_CQI_H +#define SRSLTE_CQI_H #include @@ -179,4 +179,4 @@ SRSLTE_API int srslte_cqi_hl_get_no_subbands(int num_prbs); SRSLTE_API void srslte_cqi_to_str(const uint8_t *cqi_value, int cqi_len, char *str, int str_len); -#endif // CQI_ +#endif // SRSLTE_CQI_H diff --git a/lib/include/srslte/phy/phch/dci.h b/lib/include/srslte/phy/phch/dci.h index 79a79c4df..1a7bfbb0f 100644 --- a/lib/include/srslte/phy/phch/dci.h +++ b/lib/include/srslte/phy/phch/dci.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.3.3 *****************************************************************************/ -#ifndef DCI_ -#define DCI_ +#ifndef SRSLTE_DCI_H +#define SRSLTE_DCI_H #include diff --git a/lib/include/srslte/phy/phch/pbch.h b/lib/include/srslte/phy/phch/pbch.h index 4dc7ec727..1e0af67cd 100644 --- a/lib/include/srslte/phy/phch/pbch.h +++ b/lib/include/srslte/phy/phch/pbch.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.6 *****************************************************************************/ -#ifndef PBCH_ -#define PBCH_ +#ifndef SRSLTE_PBCH_H +#define SRSLTE_PBCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -115,4 +115,4 @@ SRSLTE_API void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg); -#endif // PBCH_ +#endif // SRSLTE_PBCH_H diff --git a/lib/include/srslte/phy/phch/pcfich.h b/lib/include/srslte/phy/phch/pcfich.h index fbbb82c88..554a150a7 100644 --- a/lib/include/srslte/phy/phch/pcfich.h +++ b/lib/include/srslte/phy/phch/pcfich.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.7 *****************************************************************************/ -#ifndef PCFICH_ -#define PCFICH_ +#ifndef SRSLTE_PCFICH_H +#define SRSLTE_PCFICH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -108,4 +108,4 @@ SRSLTE_API int srslte_pcfich_encode(srslte_pcfich_t *q, cf_t *sf_symbols[SRSLTE_MAX_PORTS], uint32_t subframe); -#endif +#endif // SRSLTE_PCFICH_H diff --git a/lib/include/srslte/phy/phch/pdcch.h b/lib/include/srslte/phy/phch/pdcch.h index 423204996..14f7b07ab 100644 --- a/lib/include/srslte/phy/phch/pdcch.h +++ b/lib/include/srslte/phy/phch/pdcch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.8 *****************************************************************************/ -#ifndef PDCCH_ -#define PDCCH_ +#ifndef SRSLTE_PDCCH_H +#define SRSLTE_PDCCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -186,4 +186,4 @@ SRSLTE_API uint32_t srslte_pdcch_common_locations_ncce(uint32_t nof_cce, uint32_t max_candidates); -#endif +#endif // SRSLTE_PDCCH_H diff --git a/lib/include/srslte/phy/phch/pdsch.h b/lib/include/srslte/phy/phch/pdsch.h index 1889078e6..8a733c992 100644 --- a/lib/include/srslte/phy/phch/pdsch.h +++ b/lib/include/srslte/phy/phch/pdsch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.4 *****************************************************************************/ -#ifndef PDSCH_ -#define PDSCH_ +#ifndef SRSLTE_PDSCH_H +#define SRSLTE_PDSCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -170,4 +170,4 @@ SRSLTE_API float srslte_pdsch_last_noi(srslte_pdsch_t *q); SRSLTE_API uint32_t srslte_pdsch_last_noi_cw(srslte_pdsch_t *q, uint32_t cw_idx); -#endif +#endif // SRSLTE_PDSCH_H diff --git a/lib/include/srslte/phy/phch/pdsch_cfg.h b/lib/include/srslte/phy/phch/pdsch_cfg.h index 569d1ef7e..3e4849014 100644 --- a/lib/include/srslte/phy/phch/pdsch_cfg.h +++ b/lib/include/srslte/phy/phch/pdsch_cfg.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.4 *****************************************************************************/ -#ifndef PDSCHCFG_ -#define PDSCHCFG_ +#ifndef SRSLTE_PDSCH_CFG_H +#define SRSLTE_PDSCH_CFG_H #include "srslte/phy/phch/ra.h" #include "srslte/phy/fec/softbuffer.h" @@ -58,5 +58,5 @@ typedef struct SRSLTE_API { bool tb_cw_swap; } srslte_pdsch_cfg_t; -#endif +#endif // SRSLTE_PDSCH_CFG_H diff --git a/lib/include/srslte/phy/phch/phich.h b/lib/include/srslte/phy/phch/phich.h index 0645e22b1..d131dc637 100644 --- a/lib/include/srslte/phy/phch/phich.h +++ b/lib/include/srslte/phy/phch/phich.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.9 *****************************************************************************/ -#ifndef PHICH_ -#define PHICH_ +#ifndef SRSLTE_PHICH_H +#define SRSLTE_PHICH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -124,4 +124,4 @@ SRSLTE_API uint32_t srslte_phich_ngroups(srslte_phich_t *q); SRSLTE_API uint32_t srslte_phich_nsf(srslte_phich_t *q); -#endif // PHICH_ +#endif // SRSLTE_PHICH_H diff --git a/lib/include/srslte/phy/phch/pmch.h b/lib/include/srslte/phy/phch/pmch.h index dfff956f1..7d352e62a 100644 --- a/lib/include/srslte/phy/phch/pmch.h +++ b/lib/include/srslte/phy/phch/pmch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.5 *****************************************************************************/ -#ifndef PMCH_ -#define PMCH_ +#ifndef SRSLTE_PMCH_H +#define SRSLTE_PMCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -149,4 +149,4 @@ SRSLTE_API float srslte_pmch_average_noi(srslte_pmch_t *q); SRSLTE_API uint32_t srslte_pmch_last_noi(srslte_pmch_t *q); -#endif +#endif // SRSLTE_PMCH_H diff --git a/lib/include/srslte/phy/phch/prach.h b/lib/include/srslte/phy/phch/prach.h index 3e3df01bb..087c52957 100644 --- a/lib/include/srslte/phy/phch/prach.h +++ b/lib/include/srslte/phy/phch/prach.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.7 *****************************************************************************/ -#ifndef PRACH_ -#define PRACH_ +#ifndef SRSLTE_PRACH_H +#define SRSLTE_PRACH_H #include #include @@ -174,4 +174,4 @@ SRSLTE_API int srslte_prach_free(srslte_prach_t *p); SRSLTE_API int srslte_prach_print_seqs(srslte_prach_t *p); -#endif // PRACH_ +#endif // SRSLTE_PRACH_H diff --git a/lib/include/srslte/phy/phch/pucch.h b/lib/include/srslte/phy/phch/pucch.h index 29785c09a..fbb185c91 100644 --- a/lib/include/srslte/phy/phch/pucch.h +++ b/lib/include/srslte/phy/phch/pucch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.4 *****************************************************************************/ -#ifndef PUCCH_ -#define PUCCH_ +#ifndef SRSLTE_PUCCH_H +#define SRSLTE_PUCCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -211,4 +211,4 @@ SRSLTE_API bool srslte_n_pucch_isvalid(srslte_pucch_t *q, SRSLTE_API void srslte_pucch_cfg_default(srslte_pucch_cfg_t *cfg); -#endif +#endif // SRSLTE_PUCCH_H diff --git a/lib/include/srslte/phy/phch/pusch.h b/lib/include/srslte/phy/phch/pusch.h index 01db068a5..a5b8f04ae 100644 --- a/lib/include/srslte/phy/phch/pusch.h +++ b/lib/include/srslte/phy/phch/pusch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.3 *****************************************************************************/ -#ifndef PUSCH_ -#define PUSCH_ +#ifndef SRSLTE_PUSCH_H +#define SRSLTE_PUSCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -149,4 +149,4 @@ SRSLTE_API float srslte_pusch_average_noi(srslte_pusch_t *q); SRSLTE_API uint32_t srslte_pusch_last_noi(srslte_pusch_t *q); -#endif +#endif // SRSLTE_PUSCH_H diff --git a/lib/include/srslte/phy/phch/pusch_cfg.h b/lib/include/srslte/phy/phch/pusch_cfg.h index 5d743d94c..ed3239cab 100644 --- a/lib/include/srslte/phy/phch/pusch_cfg.h +++ b/lib/include/srslte/phy/phch/pusch_cfg.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.4 *****************************************************************************/ -#ifndef PUSCHCFG_ -#define PUSCHCFG_ +#ifndef SRSLTE_PUSCH_CFG_H +#define SRSLTE_PUSCH_CFG_H #include "srslte/phy/phch/ra.h" #include "srslte/phy/fec/softbuffer.h" @@ -57,5 +57,5 @@ typedef struct SRSLTE_API { uint32_t last_O_cqi; } srslte_pusch_cfg_t; -#endif +#endif // SRSLTE_PUSCH_CFG_H diff --git a/lib/include/srslte/phy/phch/ra.h b/lib/include/srslte/phy/phch/ra.h index 80097f78e..085f62b40 100644 --- a/lib/include/srslte/phy/phch/ra.h +++ b/lib/include/srslte/phy/phch/ra.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.213 version 10.0.1 Release 10 *****************************************************************************/ -#ifndef RB_ALLOC_H_ -#define RB_ALLOC_H_ +#ifndef SRSLTE_RA_H +#define SRSLTE_RA_H #include #include @@ -300,4 +300,4 @@ SRSLTE_API int srslte_dl_fill_ra_mcs_pmch(srslte_ra_mcs_t *mcs, uint32_t nprb); SRSLTE_API int srslte_dl_fill_ra_mcs(srslte_ra_mcs_t *mcs, uint32_t nprb); -#endif /* RB_ALLOC_H_ */ +#endif // SRSLTE_RA_H \ No newline at end of file diff --git a/lib/include/srslte/phy/phch/regs.h b/lib/include/srslte/phy/phch/regs.h index 8dd103f21..91e6f3338 100644 --- a/lib/include/srslte/phy/phch/regs.h +++ b/lib/include/srslte/phy/phch/regs.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 *****************************************************************************/ -#ifndef _REGS_H_ -#define _REGS_H_ +#ifndef SRSLTE_REGS_H +#define SRSLTE_REGS_H #include #include "srslte/config.h" @@ -136,6 +136,6 @@ SRSLTE_API int srslte_regs_pdcch_get_offset(srslte_regs_t *h, uint32_t start_reg, uint32_t nof_regs); -#endif // REGS_H_ +#endif // SRSLTE_REGS_H diff --git a/lib/include/srslte/phy/phch/sch.h b/lib/include/srslte/phy/phch/sch.h index e8066e4cd..4ef0328e7 100644 --- a/lib/include/srslte/phy/phch/sch.h +++ b/lib/include/srslte/phy/phch/sch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 *****************************************************************************/ -#ifndef SCH_ -#define SCH_ +#ifndef SRSLTE_SCH_H +#define SRSLTE_SCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -159,4 +159,4 @@ SRSLTE_API uint32_t srslte_sch_find_Ioffset_cqi(float beta); SRSLTE_API uint32_t srslte_sch_find_Ioffset_ri(float beta); -#endif +#endif // SRSLTE_SCH_H diff --git a/lib/include/srslte/phy/phch/uci.h b/lib/include/srslte/phy/phch/uci.h index ebbd98238..4f211ff1a 100644 --- a/lib/include/srslte/phy/phch/uci.h +++ b/lib/include/srslte/phy/phch/uci.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.2.3, 5.2.4 *****************************************************************************/ -#ifndef UCI_ -#define UCI_ +#ifndef SRSLTE_UCI_H +#define SRSLTE_UCI_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -153,4 +153,4 @@ SRSLTE_API int srslte_uci_decode_ack_ri(srslte_pusch_cfg_t *cfg, bool is_ri); -#endif +#endif // SRSLTE_UCI_H diff --git a/lib/include/srslte/phy/resampling/decim.h b/lib/include/srslte/phy/resampling/decim.h index 22445f1b2..1394c645a 100644 --- a/lib/include/srslte/phy/resampling/decim.h +++ b/lib/include/srslte/phy/resampling/decim.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef DECIM_H -#define DECIM_H +#ifndef SRSLTE_DECIM_H +#define SRSLTE_DECIM_H #include "srslte/config.h" @@ -48,4 +48,4 @@ SRSLTE_API void srslte_decim_f(float *input, int M, int len); -#endif // DECIM_H +#endif // SRSLTE_DECIM_H diff --git a/lib/include/srslte/phy/resampling/interp.h b/lib/include/srslte/phy/resampling/interp.h index 508b6e957..8cdb8218a 100644 --- a/lib/include/srslte/phy/resampling/interp.h +++ b/lib/include/srslte/phy/resampling/interp.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef INTERP_H -#define INTERP_H +#ifndef SRSLTE_INTERP_H +#define SRSLTE_INTERP_H #include #include @@ -133,4 +133,4 @@ SRSLTE_API void srslte_interp_linear_offset(srslte_interp_lin_t *q, uint32_t off_end); -#endif // INTERP_H +#endif // SRSLTE_INTERP_H diff --git a/lib/include/srslte/phy/resampling/resample_arb.h b/lib/include/srslte/phy/resampling/resample_arb.h index 4ebb8dc08..76d873041 100644 --- a/lib/include/srslte/phy/resampling/resample_arb.h +++ b/lib/include/srslte/phy/resampling/resample_arb.h @@ -34,8 +34,8 @@ * fredric j. harris *****************************************************************************/ -#ifndef RESAMPLE_ARB_ -#define RESAMPLE_ARB_ +#ifndef SRSLTE_RESAMPLE_ARB_H +#define SRSLTE_RESAMPLE_ARB_H #include #include @@ -65,4 +65,4 @@ SRSLTE_API int srslte_resample_arb_compute(srslte_resample_arb_t *q, cf_t *output, int n_in); -#endif //RESAMPLE_ARB_ +#endif // SRSLTE_RESAMPLE_ARB_ diff --git a/lib/include/srslte/phy/rf/rf.h b/lib/include/srslte/phy/rf/rf.h index da1600b66..664d273ff 100644 --- a/lib/include/srslte/phy/rf/rf.h +++ b/lib/include/srslte/phy/rf/rf.h @@ -24,8 +24,8 @@ * */ -#ifndef RF_H -#define RF_H +#ifndef SRSLTE_RF_H +#define SRSLTE_RF_H #include #include @@ -213,5 +213,5 @@ SRSLTE_API int srslte_rf_send_multi(srslte_rf_t *rf, bool is_start_of_burst, bool is_end_of_burst); -#endif +#endif // SRSLTE_RF_H diff --git a/lib/include/srslte/phy/rf/rf_utils.h b/lib/include/srslte/phy/rf/rf_utils.h index 7dddb20f4..4cfe16461 100644 --- a/lib/include/srslte/phy/rf/rf_utils.h +++ b/lib/include/srslte/phy/rf/rf_utils.h @@ -24,6 +24,8 @@ * */ +#ifndef SRSLTE_RF_UTILS_H +#define SRSLTE_RF_UTILS_H #include "srslte/srslte.h" #include "srslte/phy/rf/rf.h" @@ -62,4 +64,5 @@ SRSLTE_API int rf_search_and_decode_mib(srslte_rf_t *rf, srslte_cell_t *cell, float *cfo); +#endif // SRSLTE_RF_UTILS_H diff --git a/lib/include/srslte/phy/scrambling/scrambling.h b/lib/include/srslte/phy/scrambling/scrambling.h index 4fa74790a..c38bbe8c9 100644 --- a/lib/include/srslte/phy/scrambling/scrambling.h +++ b/lib/include/srslte/phy/scrambling/scrambling.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.3.1, 6.3.1 *****************************************************************************/ -#ifndef SCRAMBLING_ -#define SCRAMBLING_ +#ifndef SRSLTE_SCRAMBLING_H +#define SRSLTE_SCRAMBLING_H #include "srslte/config.h" #include "srslte/phy/common/sequence.h" @@ -76,4 +76,4 @@ SRSLTE_API void srslte_scrambling_c_offset(srslte_sequence_t *s, int offset, int len); -#endif // SCRAMBLING_ +#endif // SRSLTE_SCRAMBLING_H diff --git a/lib/include/srslte/phy/sync/cfo.h b/lib/include/srslte/phy/sync/cfo.h index 506732b74..b28d57d33 100644 --- a/lib/include/srslte/phy/sync/cfo.h +++ b/lib/include/srslte/phy/sync/cfo.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef CFO_ -#define CFO_ +#ifndef SRSLTE_CFO_H +#define SRSLTE_CFO_H #include @@ -67,4 +67,4 @@ SRSLTE_API void srslte_cfo_correct(srslte_cfo_t *h, cf_t *output, float freq); -#endif // CFO_ +#endif // SRSLTE_CFO_H diff --git a/lib/include/srslte/phy/sync/cp.h b/lib/include/srslte/phy/sync/cp.h index d9da03722..511efb426 100644 --- a/lib/include/srslte/phy/sync/cp.h +++ b/lib/include/srslte/phy/sync/cp.h @@ -24,8 +24,8 @@ * */ -#ifndef CP_ -#define CP_ +#ifndef SRSLTE_CP_H +#define SRSLTE_CP_H #include #include @@ -55,4 +55,4 @@ SRSLTE_API uint32_t srslte_cp_synch(srslte_cp_synch_t *q, SRSLTE_API cf_t srslte_cp_synch_corr_output(srslte_cp_synch_t *q, uint32_t offset); -#endif // CP_ +#endif // SRSLTE_CP_H diff --git a/lib/include/srslte/phy/sync/pss.h b/lib/include/srslte/phy/sync/pss.h index 922bc0286..520e2bcec 100644 --- a/lib/include/srslte/phy/sync/pss.h +++ b/lib/include/srslte/phy/sync/pss.h @@ -42,8 +42,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.11.1 *****************************************************************************/ -#ifndef PSS_ -#define PSS_ +#ifndef SRSLTE_PSS_H +#define SRSLTE_PSS_H #include #include @@ -176,4 +176,4 @@ SRSLTE_API int srslte_pss_chest(srslte_pss_t *q, SRSLTE_API float srslte_pss_cfo_compute(srslte_pss_t* q, const cf_t *pss_recv); -#endif // PSS_ +#endif // SRSLTE_PSS_H diff --git a/lib/include/srslte/phy/sync/sfo.h b/lib/include/srslte/phy/sync/sfo.h index f6f94c9a3..a42ced471 100644 --- a/lib/include/srslte/phy/sync/sfo.h +++ b/lib/include/srslte/phy/sync/sfo.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef SFO_ -#define SFO_ +#ifndef SRSLTE_SFO_H +#define SRSLTE_SFO_H #include "srslte/config.h" @@ -46,4 +46,4 @@ SRSLTE_API float srslte_sfo_estimate_period(int *t0, int len, float period); -#endif // SFO_ +#endif // SRSLTE_SFO_H diff --git a/lib/include/srslte/phy/sync/sss.h b/lib/include/srslte/phy/sync/sss.h index 9f77d1ce6..a0062d63b 100644 --- a/lib/include/srslte/phy/sync/sss.h +++ b/lib/include/srslte/phy/sync/sss.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.11.2 *****************************************************************************/ -#ifndef SSS_ -#define SSS_ +#ifndef SRSLTE_SSS_H +#define SRSLTE_SSS_H #include #include @@ -153,5 +153,5 @@ SRSLTE_API void srslte_sss_set_symbol_sz(srslte_sss_t *q, SRSLTE_API void srslte_sss_set_subframe_sz(srslte_sss_t *q, uint32_t subframe_sz); -#endif // SSS_ +#endif // SRSLTE_SSS_H diff --git a/lib/include/srslte/phy/sync/sync.h b/lib/include/srslte/phy/sync/sync.h index 232bc5fc4..f99bfc17a 100644 --- a/lib/include/srslte/phy/sync/sync.h +++ b/lib/include/srslte/phy/sync/sync.h @@ -42,8 +42,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.11.1, 6.11.2 *****************************************************************************/ -#ifndef SYNC_ -#define SYNC_ +#ifndef SRSLTE_SYNC_H +#define SRSLTE_SYNC_H #include #include @@ -240,5 +240,5 @@ SRSLTE_API bool srslte_sync_sss_detected(srslte_sync_t *q); SRSLTE_API void srslte_sync_cp_en(srslte_sync_t *q, bool enabled); -#endif // SYNC_ +#endif // SRSLTE_SYNC_H diff --git a/lib/include/srslte/phy/ue/ue_cell_search.h b/lib/include/srslte/phy/ue/ue_cell_search.h index bcabe1728..e99e916d4 100644 --- a/lib/include/srslte/phy/ue/ue_cell_search.h +++ b/lib/include/srslte/phy/ue/ue_cell_search.h @@ -40,8 +40,8 @@ * Reference: *****************************************************************************/ -#ifndef UE_CELLSEARCH_ -#define UE_CELLSEARCH_ +#ifndef SRSLTE_UE_CELL_SEARCH_H +#define SRSLTE_UE_CELL_SEARCH_H #include @@ -110,5 +110,5 @@ SRSLTE_API int srslte_ue_cellsearch_set_nof_valid_frames(srslte_ue_cellsearch_t -#endif // SYNC_FRAME_ +#endif // SRSLTE_UE_CELL_SEARCH_H diff --git a/lib/include/srslte/phy/ue/ue_dl.h b/lib/include/srslte/phy/ue/ue_dl.h index c5b0da52a..197a650b1 100644 --- a/lib/include/srslte/phy/ue/ue_dl.h +++ b/lib/include/srslte/phy/ue/ue_dl.h @@ -35,8 +35,8 @@ * Reference: *****************************************************************************/ -#ifndef UEDL_H -#define UEDL_H +#ifndef SRSLTE_UE_DL_H +#define SRSLTE_UE_DL_H #include @@ -254,4 +254,4 @@ SRSLTE_API void srslte_ue_dl_save_signal(srslte_ue_dl_t *q, uint32_t cfi); -#endif +#endif // SRSLTE_UE_DL_H diff --git a/lib/include/srslte/phy/ue/ue_mib.h b/lib/include/srslte/phy/ue/ue_mib.h index ee52b31d4..38f27d024 100644 --- a/lib/include/srslte/phy/ue/ue_mib.h +++ b/lib/include/srslte/phy/ue/ue_mib.h @@ -43,8 +43,8 @@ * Reference: *****************************************************************************/ -#ifndef UE_MIB_ -#define UE_MIB_ +#ifndef SRSLTE_UE_MIB_H +#define SRSLTE_UE_MIB_H #include @@ -129,5 +129,5 @@ SRSLTE_API int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q, -#endif // SYNC_FRAME_ +#endif // SRSLTE_UE_MIB_H diff --git a/lib/include/srslte/phy/ue/ue_phy.h b/lib/include/srslte/phy/ue/ue_phy.h index 369b96027..0a8217594 100644 --- a/lib/include/srslte/phy/ue/ue_phy.h +++ b/lib/include/srslte/phy/ue/ue_phy.h @@ -35,8 +35,8 @@ #include "srslte/srslte.h" #include "srslte/phy/utils/queue.h" -#ifndef UEPHY_H -#define UEPHY_H +#ifndef SRSLTE_UE_PHY_H +#define SRSLTE_UE_PHY_H #define SYNC_MODE_CV 0 #define SYNC_MODE_CALLBACK 1 @@ -165,4 +165,4 @@ private: }; } -#endif +#endif // SRSLTE_UE_PHY_H diff --git a/lib/include/srslte/phy/ue/ue_sync.h b/lib/include/srslte/phy/ue/ue_sync.h index a5e126e5f..3d9807aea 100644 --- a/lib/include/srslte/phy/ue/ue_sync.h +++ b/lib/include/srslte/phy/ue/ue_sync.h @@ -46,8 +46,8 @@ * Reference: *****************************************************************************/ -#ifndef UE_SYNC_ -#define UE_SYNC_ +#ifndef SRSLTE_UE_SYNC_H +#define SRSLTE_UE_SYNC_H #include @@ -255,5 +255,5 @@ SRSLTE_API void srslte_ue_sync_get_last_timestamp(srslte_ue_sync_t *q, srslte_timestamp_t *timestamp); -#endif // SYNC_FRAME_ +#endif // SRSLTE_UE_SYNC_H diff --git a/lib/include/srslte/phy/ue/ue_ul.h b/lib/include/srslte/phy/ue/ue_ul.h index 617833a61..98dae48b4 100644 --- a/lib/include/srslte/phy/ue/ue_ul.h +++ b/lib/include/srslte/phy/ue/ue_ul.h @@ -35,8 +35,8 @@ * Reference: *****************************************************************************/ -#ifndef UEUL_H -#define UEUL_H +#ifndef SRSLTE_UE_UL_H +#define SRSLTE_UE_UL_H #include "srslte/phy/common/phy_common.h" #include "srslte/phy/ch_estimation/chest_dl.h" @@ -210,4 +210,4 @@ SRSLTE_API bool srslte_ue_ul_srs_tx_enabled(srslte_refsignal_srs_cfg_t *srs_cfg, uint32_t tti); -#endif +#endif // SRSLTE_UE_UL_H diff --git a/lib/include/srslte/phy/utils/bit.h b/lib/include/srslte/phy/utils/bit.h index e4289b790..29fca8e9e 100644 --- a/lib/include/srslte/phy/utils/bit.h +++ b/lib/include/srslte/phy/utils/bit.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef BIT_ -#define BIT_ +#ifndef SRSLTE_BIT_H +#define SRSLTE_BIT_H #include #include @@ -108,5 +108,5 @@ SRSLTE_API uint32_t srslte_bit_diff(uint8_t *x, SRSLTE_API uint32_t srslte_bit_count(uint32_t n); -#endif // BIT_ +#endif // SRSLTE_BIT_H diff --git a/lib/include/srslte/phy/utils/cexptab.h b/lib/include/srslte/phy/utils/cexptab.h index f615ede22..b96b330a9 100644 --- a/lib/include/srslte/phy/utils/cexptab.h +++ b/lib/include/srslte/phy/utils/cexptab.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef CEXPTAB_ -#define CEXPTAB_ +#ifndef SRSLTE_CEXPTAB_H +#define SRSLTE_CEXPTAB_H #include #include @@ -58,4 +58,4 @@ SRSLTE_API void srslte_cexptab_gen_direct(cf_t *x, float freq, uint32_t len); -#endif // CEXPTAB_ +#endif // SRSLTE_CEXPTAB_H diff --git a/lib/include/srslte/phy/utils/convolution.h b/lib/include/srslte/phy/utils/convolution.h index a93dfb955..3f0cad7aa 100644 --- a/lib/include/srslte/phy/utils/convolution.h +++ b/lib/include/srslte/phy/utils/convolution.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef CONVOLUTION_H_ -#define CONVOLUTION_H_ +#ifndef SRSLTE_CONVOLUTION_H +#define SRSLTE_CONVOLUTION_H #include "srslte/config.h" #include "srslte/phy/dft/dft.h" @@ -94,4 +94,4 @@ SRSLTE_API uint32_t srslte_conv_same_cc(cf_t *input, uint32_t input_len, uint32_t filter_len); -#endif // CONVOLUTION_H_ +#endif // SRSLTE_CONVOLUTION_H diff --git a/lib/include/srslte/phy/utils/debug.h b/lib/include/srslte/phy/utils/debug.h index 52290ca11..9a07272b6 100644 --- a/lib/include/srslte/phy/utils/debug.h +++ b/lib/include/srslte/phy/utils/debug.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef DEBUG_H -#define DEBUG_H +#ifndef SRSLTE_DEBUG_H +#define SRSLTE_DEBUG_H #include #include "srslte/config.h" @@ -80,4 +80,4 @@ SRSLTE_API extern int handler_registered; void srslte_debug_handle_crash(int argc, char **argv); -#endif // DEBUG_H +#endif // SRSLTE_DEBUG_H diff --git a/lib/include/srslte/phy/utils/filter.h b/lib/include/srslte/phy/utils/filter.h index 70e00363c..a126e171b 100644 --- a/lib/include/srslte/phy/utils/filter.h +++ b/lib/include/srslte/phy/utils/filter.h @@ -32,8 +32,9 @@ * Reference: *****************************************************************************/ -#ifndef FILTER_H -#define FILTER_H +#ifndef SRSLTE_FILTER_H +#define SRSLTE_FILTER_H + #include #include #include "srslte/config.h" @@ -57,4 +58,4 @@ void srslte_filt_decim_cc_free(srslte_filt_cc_t *q); void srslte_filt_decim_cc_execute(srslte_filt_cc_t *q, cf_t *input, cf_t *downsampled_input, cf_t *output, int size); void srslte_downsample_cc(cf_t *input, cf_t *output, int M, int size) ; -#endif // FILTER_H \ No newline at end of file +#endif // SRSLTE_FILTER_H \ No newline at end of file diff --git a/lib/include/srslte/phy/utils/mat.h b/lib/include/srslte/phy/utils/mat.h index 339cfea23..a0f11abe3 100644 --- a/lib/include/srslte/phy/utils/mat.h +++ b/lib/include/srslte/phy/utils/mat.h @@ -103,4 +103,4 @@ SRSLTE_API void srslte_mat_2x2_mmse_avx(__m256 y0, __m256 y1, #endif /* LV_HAVE_AVX */ -#endif /* SRSLTE_MAT_H */ +#endif // SRSLTE_MAT_H diff --git a/lib/include/srslte/phy/utils/ringbuffer.h b/lib/include/srslte/phy/utils/ringbuffer.h index a93ebf181..b7a852155 100644 --- a/lib/include/srslte/phy/utils/ringbuffer.h +++ b/lib/include/srslte/phy/utils/ringbuffer.h @@ -1,6 +1,6 @@ -#ifndef RINGBUFFER_H -#define RINGBUFFER_H +#ifndef SRSLTE_RINGBUFFER_H +#define SRSLTE_RINGBUFFER_H #include "srslte/config.h" #include @@ -40,6 +40,6 @@ SRSLTE_API int srslte_ringbuffer_read(srslte_ringbuffer_t *q, SRSLTE_API void srslte_ringbuffer_stop(srslte_ringbuffer_t *q); -#endif +#endif // SRSLTE_RINGBUFFER_H diff --git a/lib/include/srslte/phy/utils/simd.h b/lib/include/srslte/phy/utils/simd.h index 3223c18a7..f6d7a0a44 100644 --- a/lib/include/srslte/phy/utils/simd.h +++ b/lib/include/srslte/phy/utils/simd.h @@ -24,8 +24,8 @@ * */ -#ifndef SRSLTE_SIMD_H_H -#define SRSLTE_SIMD_H_H +#ifndef SRSLTE_SIMD_H +#define SRSLTE_SIMD_H #ifdef LV_HAVE_SSE /* AVX, AVX2, FMA, AVX512 are in this group */ #ifndef __OPTIMIZE__ @@ -706,7 +706,11 @@ static inline void srslte_simd_cf_storeu(float *re, float *im, simd_cf_t simdreg } static inline simd_f_t srslte_simd_cf_re(simd_cf_t in) { +#ifdef HAVE_NEON + simd_f_t out = in.val[0]; +#else simd_f_t out = in.re; +#endif /*HAVE_NEON*/ #ifndef LV_HAVE_AVX512 #ifdef LV_HAVE_AVX2 /* Permute for AVX registers (mis SSE registers) */ @@ -1636,4 +1640,4 @@ static inline simd_b_t srslte_simd_b_xor(simd_b_t a, simd_b_t b) { #endif /*SRSLTE_SIMD_B_SIZE */ -#endif //SRSLTE_SIMD_H_H +#endif // SRSLTE_SIMD_H diff --git a/lib/include/srslte/phy/utils/vector.h b/lib/include/srslte/phy/utils/vector.h index fbf000a70..1fcbe4235 100644 --- a/lib/include/srslte/phy/utils/vector.h +++ b/lib/include/srslte/phy/utils/vector.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef VECTOR_ -#define VECTOR_ +#ifndef SRSLTE_VECTOR_H +#define SRSLTE_VECTOR_H #ifdef __cplusplus extern "C" { @@ -159,4 +159,4 @@ SRSLTE_API void srslte_vec_interleave_add(const cf_t *x, const cf_t *y, cf_t *z, } #endif -#endif // VECTOR_ +#endif // SRSLTE_VECTOR_H diff --git a/lib/include/srslte/phy/utils/vector_simd.h b/lib/include/srslte/phy/utils/vector_simd.h index 8139d0e78..11c6ce1cd 100644 --- a/lib/include/srslte/phy/utils/vector_simd.h +++ b/lib/include/srslte/phy/utils/vector_simd.h @@ -24,8 +24,8 @@ * */ -#ifndef VECTORSIMD_ -#define VECTORSIMD_ +#ifndef SRSLTE_VECTOR_SIMD_H +#define SRSLTE_VECTOR_SIMD_H #ifdef __cplusplus extern "C" { @@ -139,4 +139,4 @@ SRSLTE_API uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len); } #endif -#endif +#endif // SRSLTE_VECTOR_SIMD_H diff --git a/lib/include/srslte/radio/radio.h b/lib/include/srslte/radio/radio.h index 143927730..26775777b 100644 --- a/lib/include/srslte/radio/radio.h +++ b/lib/include/srslte/radio/radio.h @@ -30,8 +30,8 @@ #include "srslte/phy/rf/rf.h" #include "srslte/common/trace.h" -#ifndef RADIO_H -#define RADIO_H +#ifndef SRSLTE_RADIO_H +#define SRSLTE_RADIO_H typedef struct { float tx_corr_dc_gain; @@ -180,4 +180,4 @@ namespace srslte { }; } -#endif +#endif // SRSLTE_RADIO_H diff --git a/lib/include/srslte/radio/radio_multi.h b/lib/include/srslte/radio/radio_multi.h index d83237619..efb1e31b6 100644 --- a/lib/include/srslte/radio/radio_multi.h +++ b/lib/include/srslte/radio/radio_multi.h @@ -34,8 +34,8 @@ extern "C" { #include "srslte/radio/radio.h" -#ifndef RADIO_MULTI_H -#define RADIO_MULTI_H +#ifndef SRSLTE_RADIO_MULTI_H +#define SRSLTE_RADIO_MULTI_H namespace srslte { @@ -51,4 +51,4 @@ namespace srslte { }; } -#endif +#endif // SRSLTE_RADIO_MULTI_H diff --git a/lib/include/srslte/srslte.h b/lib/include/srslte/srslte.h index 36af629d7..f87a1bf2c 100644 --- a/lib/include/srslte/srslte.h +++ b/lib/include/srslte/srslte.h @@ -25,8 +25,8 @@ */ -#ifndef _LTE_ -#define _LTE_ +#ifndef SRSLTE_SRSLTE_H +#define SRSLTE_SRSLTE_H #ifdef __cplusplus extern "C" { @@ -128,4 +128,4 @@ #undef I // Fix complex.h #define I nastiness when using C++ #endif -#endif +#endif // SRSLTE_SRSLTE_H diff --git a/lib/include/srslte/upper/pdcp.h b/lib/include/srslte/upper/pdcp.h index 584b231a3..436f35edd 100644 --- a/lib/include/srslte/upper/pdcp.h +++ b/lib/include/srslte/upper/pdcp.h @@ -24,8 +24,8 @@ * */ -#ifndef PDCP_H -#define PDCP_H +#ifndef SRSLTE_PDCP_H +#define SRSLTE_PDCP_H #include "srslte/common/log.h" #include "srslte/common/common.h" @@ -89,7 +89,7 @@ private: bool valid_lcid(uint32_t lcid); }; -} // namespace srsue +} // namespace srslte -#endif // PDCP_H +#endif // SRSLTE_PDCP_H diff --git a/lib/include/srslte/upper/pdcp_entity.h b/lib/include/srslte/upper/pdcp_entity.h index 0894b6578..e8a5d9561 100644 --- a/lib/include/srslte/upper/pdcp_entity.h +++ b/lib/include/srslte/upper/pdcp_entity.h @@ -24,8 +24,8 @@ * */ -#ifndef PDCP_ENTITY_H -#define PDCP_ENTITY_H +#ifndef SRSLTE_PDCP_ENTITY_H +#define SRSLTE_PDCP_ENTITY_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -144,7 +144,7 @@ void pdcp_unpack_data_pdu_short_sn(byte_buffer_t *sdu, uint32_t *sn); void pdcp_pack_data_pdu_long_sn(uint32_t sn, byte_buffer_t *sdu); void pdcp_unpack_data_pdu_long_sn(byte_buffer_t *sdu, uint32_t *sn); -} // namespace srsue +} // namespace srslte -#endif // PDCP_ENTITY_H +#endif // SRSLTE_PDCP_ENTITY_H diff --git a/lib/include/srslte/upper/rlc.h b/lib/include/srslte/upper/rlc.h index e9036a011..c4d57b9bb 100644 --- a/lib/include/srslte/upper/rlc.h +++ b/lib/include/srslte/upper/rlc.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_H -#define RLC_H +#ifndef SRSLTE_RLC_H +#define SRSLTE_RLC_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -105,4 +105,4 @@ private: } // namespace srsue -#endif // RLC_H +#endif // SRSLTE_RLC_H diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index 7601baefa..894f96ac5 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_AM_H -#define RLC_AM_H +#ifndef SRSLTE_RLC_AM_H +#define SRSLTE_RLC_AM_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -220,7 +220,7 @@ std::string rlc_am_to_string(rlc_status_pdu_t *status); bool rlc_am_start_aligned(uint8_t fi); bool rlc_am_end_aligned(uint8_t fi); -} // namespace srsue +} // namespace srslte -#endif // RLC_AM_H +#endif // SRSLTE_RLC_AM_H diff --git a/lib/include/srslte/upper/rlc_common.h b/lib/include/srslte/upper/rlc_common.h index 494cc6174..9be390d31 100644 --- a/lib/include/srslte/upper/rlc_common.h +++ b/lib/include/srslte/upper/rlc_common.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_COMMON_H -#define RLC_COMMON_H +#ifndef SRSLTE_RLC_COMMON_H +#define SRSLTE_RLC_COMMON_H #include "srslte/upper/rlc_interface.h" @@ -176,4 +176,4 @@ public: } // namespace srslte -#endif // RLC_COMMON_H +#endif // SRSLTE_RLC_COMMON_H diff --git a/lib/include/srslte/upper/rlc_entity.h b/lib/include/srslte/upper/rlc_entity.h index de4a396fe..cd30d5999 100644 --- a/lib/include/srslte/upper/rlc_entity.h +++ b/lib/include/srslte/upper/rlc_entity.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_ENTITY_H -#define RLC_ENTITY_H +#ifndef SRSLTE_RLC_ENTITY_H +#define SRSLTE_RLC_ENTITY_H #include "srslte/common/log.h" #include "srslte/common/common.h" @@ -82,7 +82,7 @@ private: rlc_common *rlc; }; -} // namespace srsue +} // namespace srslte -#endif // RLC_ENTITY_H +#endif // SRSLTE_RLC_ENTITY_H diff --git a/lib/include/srslte/upper/rlc_interface.h b/lib/include/srslte/upper/rlc_interface.h index feddac1cc..8c869ceb9 100644 --- a/lib/include/srslte/upper/rlc_interface.h +++ b/lib/include/srslte/upper/rlc_interface.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_INTERFACE_H -#define RLC_INTERFACE_H +#ifndef SRSLTE_RLC_INTERFACE_H +#define SRSLTE_RLC_INTERFACE_H // for custom constructors #include "srslte/asn1/liblte_rrc.h" @@ -123,4 +123,4 @@ public: } // namespace srslte -#endif // RLC_INTERFACE_H +#endif // SRSLTE_RLC_INTERFACE_H diff --git a/lib/include/srslte/upper/rlc_metrics.h b/lib/include/srslte/upper/rlc_metrics.h index 0089ab5a6..ab6e83c02 100644 --- a/lib/include/srslte/upper/rlc_metrics.h +++ b/lib/include/srslte/upper/rlc_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_RLC_METRICS_H -#define UE_RLC_METRICS_H +#ifndef SRSLTE_RLC_METRICS_H +#define SRSLTE_RLC_METRICS_H namespace srslte { @@ -36,6 +36,6 @@ struct rlc_metrics_t float ul_tput_mbps; }; -} // namespace srsue +} // namespace srslte -#endif // UE_RLC_METRICS_H +#endif // SRSLTE_RLC_METRICS_H diff --git a/lib/include/srslte/upper/rlc_tm.h b/lib/include/srslte/upper/rlc_tm.h index 4a55e33dd..5408cb835 100644 --- a/lib/include/srslte/upper/rlc_tm.h +++ b/lib/include/srslte/upper/rlc_tm.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_TM_H -#define RLC_TM_H +#ifndef SRSLTE_RLC_TM_H +#define SRSLTE_RLC_TM_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -78,4 +78,4 @@ private: } // namespace srsue -#endif // RLC_TM_H +#endif // SRSLTE_RLC_TM_H diff --git a/lib/include/srslte/upper/rlc_um.h b/lib/include/srslte/upper/rlc_um.h index 6d8eb6d08..8e6f527e2 100644 --- a/lib/include/srslte/upper/rlc_um.h +++ b/lib/include/srslte/upper/rlc_um.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_UM_H -#define RLC_UM_H +#ifndef SRSLTE_RLC_UM_H +#define SRSLTE_RLC_UM_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -153,4 +153,4 @@ bool rlc_um_end_aligned(uint8_t fi); } // namespace srsue -#endif // RLC_UM_H +#endif // SRSLTE_RLC_UM_H diff --git a/lib/include/srslte/version.h.in b/lib/include/srslte/version.h.in index 65a172725..f50a6f9bf 100644 --- a/lib/include/srslte/version.h.in +++ b/lib/include/srslte/version.h.in @@ -25,8 +25,8 @@ * */ -#ifndef VERSION_ -#define VERSION_ +#ifndef SRSLTE_VERSION_H_IN +#define SRSLTE_VERSION_H_IN // the configured options and settings for SRSLTE #define SRSLTE_VERSION_MAJOR @SRSLTE_VERSION_MAJOR@ diff --git a/lib/src/asn1/liblte_mme.cc b/lib/src/asn1/liblte_mme.cc index ea7729519..6d9dedcdc 100644 --- a/lib/src/asn1/liblte_mme.cc +++ b/lib/src/asn1/liblte_mme.cc @@ -296,9 +296,10 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mob uint8 **ie_ptr) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; - uint8 *id; + uint8 *id = NULL; + uint32 id32 = 0; uint32 i; - uint8 length; + uint8 length = 0; bool odd = false; if(mobile_id != NULL && @@ -317,6 +318,11 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mob id = mobile_id->imeisv; length = 9; odd = false; + }else if(LIBLTE_MME_MOBILE_ID_TYPE_TMSI == mobile_id->type_of_id){ + id32 = mobile_id->tmsi; + length = 4; + odd = false; + } }else{ // FIXME: Not handling these IDs return(err); @@ -325,30 +331,48 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mob // Length **ie_ptr = length; *ie_ptr += 1; - - // | Identity digit 1 | odd/even | Id type | - if(odd) + if(LIBLTE_MME_MOBILE_ID_TYPE_TMSI != mobile_id->type_of_id) { - **ie_ptr = (id[0] << 4) | (1 << 3) | mobile_id->type_of_id; - }else{ - **ie_ptr = (id[0] << 4) | (0 << 3) | mobile_id->type_of_id; - } - *ie_ptr += 1; + // | Identity digit 1 | odd/even | Id type | + if(odd) + { + **ie_ptr = (id[0] << 4) | (1 << 3) | mobile_id->type_of_id; + }else{ + **ie_ptr = (id[0] << 4) | (0 << 3) | mobile_id->type_of_id; + } + *ie_ptr += 1; - // | Identity digit p+1 | Identity digit p | - for(i=0; i<7; i++) - { - (*ie_ptr)[i] = (id[i*2+2] << 4) | id[i*2+1]; - } - *ie_ptr += 7; - if(!odd) - { - **ie_ptr = 0xF0 | id[15]; - *ie_ptr += 1; - } + + // | Identity digit p+1 | Identity digit p | + for(i=0; i<7; i++) + { + (*ie_ptr)[i] = (id[i*2+2] << 4) | id[i*2+1]; + } + *ie_ptr += 7; + if(!odd) + { + **ie_ptr = 0xF0 | id[15]; + *ie_ptr += 1; + } - err = LIBLTE_SUCCESS; - } + err = LIBLTE_SUCCESS; + } + else{ + + **ie_ptr = (0xFF << 4) | (0 << 3) | mobile_id->type_of_id; + *ie_ptr += 1; + //4-Byte based ids + **ie_ptr = (id32 >> 24) & 0xFF; + *ie_ptr += 1; + **ie_ptr = (id32 >> 16) & 0xFF; + *ie_ptr += 1; + **ie_ptr = (id32 >> 8) & 0xFF; + *ie_ptr += 1; + **ie_ptr = id32 & 0xFF; + *ie_ptr += 1; + + err = LIBLTE_SUCCESS; + } return(err); } diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index 8b72a3c2b..a86a36f1e 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -68,7 +68,7 @@ void log_filter::init(std::string layer, logger *logger_, bool tti) void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, - char *msg) + const char *msg) { if(logger_h) { std::stringstream ss; @@ -97,8 +97,8 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, - char *msg, - uint8_t *hex, + const char *msg, + const uint8_t *hex, int size) { if(logger_h) { @@ -135,100 +135,100 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, } } -void log_filter::console(std::string message, ...) { +void log_filter::console(const char * message, ...) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) printf("%s",args_msg); // Print directly to stdout va_end(args); free(args_msg); } -void log_filter::error(std::string message, ...) { +void log_filter::error(const char * message, ...) { if (level >= LOG_LEVEL_ERROR) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_ERROR, tti, args_msg); va_end(args); free(args_msg); } } -void log_filter::warning(std::string message, ...) { +void log_filter::warning(const char * message, ...) { if (level >= LOG_LEVEL_WARNING) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_WARNING, tti, args_msg); va_end(args); free(args_msg); } } -void log_filter::info(std::string message, ...) { +void log_filter::info(const char * message, ...) { if (level >= LOG_LEVEL_INFO) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_INFO, tti, args_msg); va_end(args); free(args_msg); } } -void log_filter::debug(std::string message, ...) { +void log_filter::debug(const char * message, ...) { if (level >= LOG_LEVEL_DEBUG) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_DEBUG, tti, args_msg); va_end(args); free(args_msg); } } -void log_filter::error_hex(uint8_t *hex, int size, std::string message, ...) { +void log_filter::error_hex(const uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_ERROR) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_ERROR, tti, args_msg, hex, size); va_end(args); free(args_msg); } } -void log_filter::warning_hex(uint8_t *hex, int size, std::string message, ...) { +void log_filter::warning_hex(const uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_WARNING) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_WARNING, tti, args_msg, hex, size); va_end(args); free(args_msg); } } -void log_filter::info_hex(uint8_t *hex, int size, std::string message, ...) { +void log_filter::info_hex(const uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_INFO) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_INFO, tti, args_msg, hex, size); va_end(args); free(args_msg); } } -void log_filter::debug_hex(uint8_t *hex, int size, std::string message, ...) { +void log_filter::debug_hex(const uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_DEBUG) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_DEBUG, tti, args_msg, hex, size); va_end(args); free(args_msg); @@ -277,7 +277,7 @@ std::string log_filter::now_time() return std::string(buffer); } -std::string log_filter::hex_string(uint8_t *hex, int size) +std::string log_filter::hex_string(const uint8_t *hex, int size) { std::stringstream ss; int c = 0; diff --git a/lib/src/common/pdu.cc b/lib/src/common/pdu.cc index 80db7627d..95d9dde9b 100644 --- a/lib/src/common/pdu.cc +++ b/lib/src/common/pdu.cc @@ -124,7 +124,6 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h) if (nof_subheaders <= 0 && nof_subheaders < (int)max_subheaders) { log_h->error("Trying to write packet with invalid number of subheaders (nof_subheaders=%d).\n", nof_subheaders); - log_h->console("Trying to write packet with invalid number of subheaders (nof_subheaders=%d).\n", nof_subheaders); return NULL; } diff --git a/lib/src/phy/rf/rf_uhd_imp.c b/lib/src/phy/rf/rf_uhd_imp.c index 1331495e9..618d4577f 100644 --- a/lib/src/phy/rf/rf_uhd_imp.c +++ b/lib/src/phy/rf/rf_uhd_imp.c @@ -35,6 +35,8 @@ #include "srslte/phy/rf/rf.h" #include "uhd_c_api.h" +#define HAVE_ASYNC_THREAD 0 + typedef struct { char *devname; uhd_usrp_handle usrp; @@ -87,6 +89,7 @@ static void log_late(rf_uhd_handler_t *h, bool is_rx) { } } +#if HAVE_ASYNC_THREAD static void log_underflow(rf_uhd_handler_t *h) { if (h->uhd_error_handler) { srslte_rf_error_t error; @@ -95,6 +98,7 @@ static void log_underflow(rf_uhd_handler_t *h) { h->uhd_error_handler(error); } } +#endif static void log_rx_error(rf_uhd_handler_t *h) { if (h->uhd_error_handler) { @@ -109,6 +113,7 @@ static void log_rx_error(rf_uhd_handler_t *h) { } } +#if HAVE_ASYNC_THREAD static void* async_thread(void *h) { rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h; uhd_async_metadata_handle md; @@ -135,6 +140,7 @@ static void* async_thread(void *h) { uhd_async_metadata_free(&md); return NULL; } +#endif void rf_uhd_suppress_stdout(void *h) { rf_uhd_register_msg_handler_c(suppress_handler); @@ -570,13 +576,14 @@ int rf_uhd_open_multi(char *args, void **h, uint32_t nof_channels) rf_uhd_set_rx_gain(handler, max_gain*0.7); uhd_meta_range_free(&gain_range); +#if HAVE_ASYNC_THREAD // Start low priority thread to receive async commands - /* handler->async_thread_running = true; if (pthread_create(&handler->async_thread, NULL, async_thread, handler)) { perror("pthread_create"); return -1; - }*/ + } +#endif /* Restore priorities */ uhd_set_thread_priority(0, false); diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 5c7cb72ea..895fd74b8 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -130,8 +130,10 @@ void rlc_am::reset() pool->deallocate(tx_sdu); tx_sdu = NULL; } - if(rx_sdu) - rx_sdu->reset(); + if(rx_sdu) { + pool->deallocate(rx_sdu); + rx_sdu = NULL; + } vt_a = 0; vt_ms = RLC_AM_WINDOW_SIZE; @@ -342,7 +344,7 @@ int rlc_am::read_pdu(uint8_t *payload, uint32_t nof_bytes) pthread_mutex_lock(&mutex); log->debug("MAC opportunity - %d bytes\n", nof_bytes); - log->debug("tx_window size - %d PDUs\n", tx_window.size()); + log->debug("tx_window size - %zu PDUs\n", tx_window.size()); // Tx STATUS if requested if(do_status && !status_prohibited()) { @@ -698,7 +700,7 @@ int rlc_am::build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t r if(pdu_len > (int)nof_bytes) { log->error("%s Retx PDU segment length error. Available: %d, Used: %d\n", rrc->get_rb_name(lcid).c_str(), nof_bytes, pdu_len); - log->debug("%s Retx PDU segment length error. Header len: %d, Payload len: %d, N_li: %d\n", + log->debug("%s Retx PDU segment length error. Header len: %ld, Payload len: %d, N_li: %d\n", rrc->get_rb_name(lcid).c_str(), (ptr-payload), len, new_header.N_li); } return pdu_len; @@ -827,6 +829,12 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) rrc->get_rb_name(lcid).c_str(), to_move, pdu_space, head_len); } + // Make sure, at least one SDU (segment) has been added until this point + if (pdu->N_bytes == 0) { + log->error("Generated empty RLC PDU.\n"); + return 0; + } + if(tx_sdu) header.fi |= RLC_FI_FIELD_NOT_END_ALIGNED; // Last byte does not correspond to last byte of SDU @@ -848,7 +856,6 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) // Set SN header.sn = vt_s; vt_s = (vt_s + 1)%MOD; - log->info("%s PDU scheduled for tx. SN: %d (%d B)\n", rrc->get_rb_name(lcid).c_str(), header.sn, pdu->N_bytes); // Place PDU in tx_window, write header and TX tx_window[header.sn].buf = pdu; @@ -859,6 +866,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) uint8_t *ptr = payload; rlc_am_write_data_pdu_header(&header, &ptr); memcpy(ptr, pdu->msg, pdu->N_bytes); + log->info_hex(payload, pdu->N_bytes, "%s PDU scheduled for tx. SN: %d (%d B)\n", rrc->get_rb_name(lcid).c_str(), header.sn, pdu->N_bytes); debug_state(); return (ptr-payload) + pdu->N_bytes; @@ -868,8 +876,8 @@ void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_h { std::map::iterator it; - log->info_hex(payload, nof_bytes, "%s Rx data PDU SN: %d", - rrc->get_rb_name(lcid).c_str(), header.sn); + log->info_hex(payload, nof_bytes, "%s Rx data PDU SN: %d (%d B), %s", + rrc->get_rb_name(lcid).c_str(), header.sn, nof_bytes, rlc_fi_field_text[header.fi]); if(!inside_rx_window(header.sn)) { if(header.p) { @@ -1157,38 +1165,55 @@ void rlc_am::reassemble_rx_sdus() #endif } } + // Iterate through rx_window, assembling and delivering SDUs while(rx_window.end() != rx_window.find(vr_r)) { // Handle any SDU segments for(uint32_t i=0; imsg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, len); - rx_sdu->N_bytes += len; - rx_window[vr_r].buf->msg += len; - rx_window[vr_r].buf->N_bytes -= len; - log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU", rrc->get_rb_name(lcid).c_str()); - rx_sdu->set_timestamp(); - pdcp->write_pdu(lcid, rx_sdu); - rx_sdu = pool_allocate; - if (!rx_sdu) { + uint32_t len = rx_window[vr_r].header.li[i]; + if (rx_sdu->get_tailroom() >= len) { + memcpy(&rx_sdu->msg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, len); + rx_sdu->N_bytes += len; + rx_window[vr_r].buf->msg += len; + rx_window[vr_r].buf->N_bytes -= len; + log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU (%d B)", rrc->get_rb_name(lcid).c_str(), rx_sdu->N_bytes); + rx_sdu->set_timestamp(); + pdcp->write_pdu(lcid, rx_sdu); + + rx_sdu = pool_allocate; + if (!rx_sdu) { #ifdef RLC_AM_BUFFER_DEBUG - log->console("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); - exit(-1); + log->console("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); + exit(-1); #else - log->error("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); - return; + log->error("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); + return; #endif + } + } else { + log->error("Cannot fit RLC PDU in SDU buffer, dropping both.\n"); + pool->deallocate(rx_sdu); + pool->deallocate(rx_window[vr_r].buf); + rx_window.erase(vr_r); } } // Handle last segment - memcpy(&rx_sdu->msg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, rx_window[vr_r].buf->N_bytes); - rx_sdu->N_bytes += rx_window[vr_r].buf->N_bytes; - if(rlc_am_end_aligned(rx_window[vr_r].header.fi)) - { - log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU", rrc->get_rb_name(lcid).c_str()); + uint32_t len = rx_window[vr_r].buf->N_bytes; + if (rx_sdu->get_tailroom() >= len) { + memcpy(&rx_sdu->msg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, len); + rx_sdu->N_bytes += rx_window[vr_r].buf->N_bytes; + } else { + log->error("Cannot fit RLC PDU in SDU buffer, dropping both.\n"); + pool->deallocate(rx_sdu); + pool->deallocate(rx_window[vr_r].buf); + rx_window.erase(vr_r); + } + + if(rlc_am_end_aligned(rx_window[vr_r].header.fi)) { + log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU (%d B)", rrc->get_rb_name(lcid).c_str(), rx_sdu->N_bytes); rx_sdu->set_timestamp(); pdcp->write_pdu(lcid, rx_sdu); rx_sdu = pool_allocate; @@ -1250,7 +1275,7 @@ void rlc_am::print_rx_segments() for(it=rx_segments.begin();it!=rx_segments.end();it++) { std::list::iterator segit; for(segit = it->second.segments.begin(); segit != it->second.segments.end(); segit++) { - ss << " SN:" << segit->header.sn << " SO:" << segit->header.so << " N:" << segit->buf->N_bytes << std::endl; + ss << " SN:" << segit->header.sn << " SO:" << segit->header.so << " N:" << segit->buf->N_bytes << " N_li: " << segit->header.N_li << std::endl; } } log->debug("%s\n", ss.str().c_str()); diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 6bbefaf78..6bad2a2cb 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -173,7 +173,7 @@ uint32_t rlc_um::get_bearer() void rlc_um::write_sdu(byte_buffer_t *sdu) { tx_sdu_queue.write(sdu); - log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (% B ,tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); + log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (%d B ,tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); } /**************************************************************************** diff --git a/srsenb/CMakeLists.txt b/srsenb/CMakeLists.txt index c836f36d5..f36987915 100644 --- a/srsenb/CMakeLists.txt +++ b/srsenb/CMakeLists.txt @@ -35,7 +35,7 @@ endif() include_directories( ${Boost_INCLUDE_DIRS} ${SEC_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR}/srsenb/hdr + ${PROJECT_SOURCE_DIR} ) link_directories( diff --git a/srsenb/hdr/cfg_parser.h b/srsenb/hdr/cfg_parser.h index 56b5e6e63..d399ddae3 100644 --- a/srsenb/hdr/cfg_parser.h +++ b/srsenb/hdr/cfg_parser.h @@ -24,8 +24,8 @@ * */ -#ifndef CFG_PARSER_H -#define CFG_PARSER_H +#ifndef SRSENB_CFG_PARSER_H +#define SRSENB_CFG_PARSER_H #include "enb.h" diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index ff314977a..745096daa 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -30,8 +30,8 @@ * layers and helpers. *****************************************************************************/ -#ifndef ENB_H -#define ENB_H +#ifndef SRSENB_ENB_H +#define SRSENB_ENB_H #include #include @@ -188,7 +188,7 @@ private: srslte::logger *logger; srslte::log_filter rf_log; - std::vector phy_log; + std::vector phy_log; srslte::log_filter mac_log; srslte::log_filter rlc_log; srslte::log_filter pdcp_log; @@ -219,5 +219,5 @@ private: } // namespace srsenb -#endif // UE_H +#endif // SRSENB_ENB_H diff --git a/srsenb/hdr/mac/mac.h b/srsenb/hdr/mac/mac.h index c99b733fb..5f541b443 100644 --- a/srsenb/hdr/mac/mac.h +++ b/srsenb/hdr/mac/mac.h @@ -24,8 +24,8 @@ * */ -#ifndef MAC_H -#define MAC_H +#ifndef SRSENB_MAC_H +#define SRSENB_MAC_H #include #include "srslte/common/log.h" @@ -36,10 +36,10 @@ #include "srslte/common/threads.h" #include "srslte/common/tti_sync_cv.h" #include "srslte/common/mac_pcap.h" -#include "mac/scheduler.h" -#include "mac/scheduler_metric.h" +#include "scheduler.h" +#include "scheduler_metric.h" #include "srslte/interfaces/enb_metrics_interface.h" -#include "mac/ue.h" +#include "ue.h" namespace srsenb { @@ -211,6 +211,6 @@ private: }; -} // namespace srsue +} // namespace srsenb -#endif // MAC_H +#endif // SRSENB_MAC_H diff --git a/srsenb/hdr/mac/mac_metrics.h b/srsenb/hdr/mac/mac_metrics.h index e11eda350..d63734d2a 100644 --- a/srsenb/hdr/mac/mac_metrics.h +++ b/srsenb/hdr/mac/mac_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef ENB_MAC_METRICS_H -#define ENB_MAC_METRICS_H +#ifndef SRSENB_MAC_METRICS_H +#define SRSENB_MAC_METRICS_H namespace srsenb { @@ -51,4 +51,4 @@ struct mac_metrics_t } // namespace srsenb -#endif // ENB_MAC_METRICS_H +#endif // SRSENB_MAC_METRICS_H diff --git a/srsenb/hdr/mac/scheduler.h b/srsenb/hdr/mac/scheduler.h index c3ca7d624..d964726d9 100644 --- a/srsenb/hdr/mac/scheduler.h +++ b/srsenb/hdr/mac/scheduler.h @@ -24,8 +24,8 @@ * */ -#ifndef SCHED_H -#define SCHED_H +#ifndef SRSENB_SCHEDULER_H +#define SRSENB_SCHEDULER_H #include #include "srslte/common/log.h" @@ -100,8 +100,8 @@ public: uint32_t get_ul_buffer(uint16_t rnti); uint32_t get_dl_buffer(uint16_t rnti); - int dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue); - int dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code); + int dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue); + int dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code); int dl_ant_info(uint16_t rnti, LIBLTE_RRC_ANTENNA_INFO_DEDICATED_STRUCT *dedicated); int dl_ack_info(uint32_t tti, uint16_t rnti, uint32_t tb_idx, bool ack); @@ -217,7 +217,7 @@ private: bool configured; - pthread_mutex_t mutex; + pthread_mutex_t mutex, mutex2; }; @@ -228,4 +228,4 @@ private: } -#endif +#endif // SRSENB_SCHEDULER_H diff --git a/srsenb/hdr/mac/scheduler_harq.h b/srsenb/hdr/mac/scheduler_harq.h index ec2aa43c0..7002653e3 100644 --- a/srsenb/hdr/mac/scheduler_harq.h +++ b/srsenb/hdr/mac/scheduler_harq.h @@ -24,8 +24,8 @@ * */ -#ifndef SCHED_HARQ_H -#define SCHED_HARQ_H +#ifndef SRSENB_SCHEDULER_HARQ_H +#define SRSENB_SCHEDULER_HARQ_H #include #include "srslte/common/log.h" @@ -125,4 +125,4 @@ private: } -#endif +#endif // SRSENB_SCHEDULER_HARQ_H diff --git a/srsenb/hdr/mac/scheduler_metric.h b/srsenb/hdr/mac/scheduler_metric.h index eda0b31ed..11e77b455 100644 --- a/srsenb/hdr/mac/scheduler_metric.h +++ b/srsenb/hdr/mac/scheduler_metric.h @@ -24,10 +24,10 @@ * */ -#ifndef SCHED_METRIC_H -#define SCHED_METRIC_H +#ifndef SRSENB_SCHEDULER_METRIC_H +#define SRSENB_SCHEDULER_METRIC_H -#include "mac/scheduler.h" +#include "scheduler.h" namespace srsenb { @@ -84,5 +84,5 @@ private: } -#endif +#endif // SRSENB_SCHEDULER_METRIC_H diff --git a/srsenb/hdr/mac/scheduler_ue.h b/srsenb/hdr/mac/scheduler_ue.h index 448e01954..90db552a6 100644 --- a/srsenb/hdr/mac/scheduler_ue.h +++ b/srsenb/hdr/mac/scheduler_ue.h @@ -24,8 +24,8 @@ * */ -#ifndef SCHED_UE_H -#define SCHED_UE_H +#ifndef SRSENB_SCHEDULER_UE_H +#define SRSENB_SCHEDULER_UE_H #include #include "srslte/common/log.h" @@ -194,4 +194,4 @@ private: } -#endif +#endif // SRSENB_SCHEDULER_UE_H diff --git a/srsenb/hdr/mac/ue.h b/srsenb/hdr/mac/ue.h index 3b81a10ec..e7fbd0c10 100644 --- a/srsenb/hdr/mac/ue.h +++ b/srsenb/hdr/mac/ue.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_H -#define UE_H +#ifndef SRSENB_UE_H +#define SRSENB_UE_H #include "srslte/common/log.h" #include "srslte/common/pdu.h" @@ -34,7 +34,7 @@ #include "srslte/interfaces/enb_interfaces.h" #include "srslte/interfaces/sched_interface.h" #include -#include "mac/mac_metrics.h" +#include "mac_metrics.h" namespace srsenb { @@ -167,5 +167,5 @@ private: } -#endif +#endif // SRSENB_UE_H diff --git a/srsenb/hdr/metrics_stdout.h b/srsenb/hdr/metrics_stdout.h index 563a866d3..f5af14e25 100644 --- a/srsenb/hdr/metrics_stdout.h +++ b/srsenb/hdr/metrics_stdout.h @@ -30,8 +30,8 @@ * Description: Metrics class printing to stdout. *****************************************************************************/ -#ifndef METRICS_STDOUT_H -#define METRICS_STDOUT_H +#ifndef SRSENB_METRICS_STDOUT_H +#define SRSENB_METRICS_STDOUT_H #include #include @@ -71,4 +71,4 @@ private: } // namespace srsenb -#endif // METRICS_STDOUT_H +#endif // SRSENB_METRICS_STDOUT_H diff --git a/srsenb/hdr/parser.h b/srsenb/hdr/parser.h index 492249e18..90425203f 100644 --- a/srsenb/hdr/parser.h +++ b/srsenb/hdr/parser.h @@ -24,8 +24,8 @@ * */ -#ifndef PARSER_H -#define PARSER_H +#ifndef SRSENB_PARSER_H +#define SRSENB_PARSER_H #include #include diff --git a/srsenb/hdr/phy/phch_common.h b/srsenb/hdr/phy/phch_common.h index 5ce9237bf..6adc926f3 100644 --- a/srsenb/hdr/phy/phch_common.h +++ b/srsenb/hdr/phy/phch_common.h @@ -24,8 +24,8 @@ * */ -#ifndef ENBPHCHCOMMON_H -#define ENBPHCHCOMMON_H +#ifndef SRSENB_PHCH_COMMON_H +#define SRSENB_PHCH_COMMON_H #include #include "srslte/interfaces/enb_interfaces.h" @@ -133,4 +133,4 @@ private: } // namespace srsenb -#endif // UEPHY_H +#endif // SRSENB_PHCH_COMMON_H diff --git a/srsenb/hdr/phy/phch_worker.h b/srsenb/hdr/phy/phch_worker.h index 789e2593a..9821a2d1e 100644 --- a/srsenb/hdr/phy/phch_worker.h +++ b/srsenb/hdr/phy/phch_worker.h @@ -24,13 +24,13 @@ * */ -#ifndef ENBPHYWORKER_H -#define ENBPHYWORKER_H +#ifndef SRSENB_PHCH_WORKER_H +#define SRSENB_PHCH_WORKER_H #include #include "srslte/srslte.h" -#include "phy/phch_common.h" +#include "phch_common.h" #define LOG_EXECTIME @@ -137,5 +137,5 @@ private: } // namespace srsenb -#endif // ENBPHYWORKER_H +#endif // SRSENB_PHCH_WORKER_H diff --git a/srsenb/hdr/phy/phy.h b/srsenb/hdr/phy/phy.h index a1616c268..74b28be11 100644 --- a/srsenb/hdr/phy/phy.h +++ b/srsenb/hdr/phy/phy.h @@ -24,13 +24,14 @@ * */ -#ifndef ENBPHY_H -#define ENBPHY_H +#ifndef SRSENB_PHY_H +#define SRSENB_PHY_H #include "srslte/common/log.h" -#include "phy/txrx.h" -#include "phy/phch_worker.h" -#include "phy/phch_common.h" +#include "srslte/common/log_filter.h" +#include "txrx.h" +#include "phch_worker.h" +#include "phch_common.h" #include "srslte/radio/radio.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/common/task_dispatcher.h" @@ -54,8 +55,8 @@ class phy : public phy_interface_mac, public: phy(); - bool init(phy_args_t *args, phy_cfg_t *common_cfg, srslte::radio *radio_handler, mac_interface_phy *mac, srslte::log* log_h); - bool init(phy_args_t *args, phy_cfg_t *common_cfg, srslte::radio *radio_handler, mac_interface_phy *mac, std::vector log_vec); + bool init(phy_args_t *args, phy_cfg_t *common_cfg, srslte::radio *radio_handler, mac_interface_phy *mac, srslte::log_filter* log_h); + bool init(phy_args_t *args, phy_cfg_t *common_cfg, srslte::radio *radio_handler, mac_interface_phy *mac, std::vector log_vec); void stop(); /* MAC->PHY interface */ @@ -98,4 +99,4 @@ private: } // namespace srsenb -#endif // UEPHY_H +#endif // SRSENB_PHY_H diff --git a/srsenb/hdr/phy/phy_metrics.h b/srsenb/hdr/phy/phy_metrics.h index ad3b96698..5a45baf5f 100644 --- a/srsenb/hdr/phy/phy_metrics.h +++ b/srsenb/hdr/phy/phy_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef ENB_PHY_METRICS_H -#define ENB_PHY_METRICS_H +#ifndef SRSENB_PHY_METRICS_H +#define SRSENB_PHY_METRICS_H namespace srsenb { @@ -56,4 +56,4 @@ struct phy_metrics_t } // namespace srsenb -#endif // ENB_PHY_METRICS_H +#endif // SRSENB_PHY_METRICS_H diff --git a/srsenb/hdr/phy/prach_worker.h b/srsenb/hdr/phy/prach_worker.h index dd1149dd4..8ca70aa60 100644 --- a/srsenb/hdr/phy/prach_worker.h +++ b/srsenb/hdr/phy/prach_worker.h @@ -24,8 +24,8 @@ * */ -#ifndef PRACH_WORKER_H -#define PRACH_WORKER_H +#ifndef SRSENB_PRACH_WORKER_H +#define SRSENB_PRACH_WORKER_H #include "srslte/interfaces/enb_interfaces.h" #include "srslte/common/log.h" @@ -85,4 +85,4 @@ private: uint32_t sf_cnt; }; } -#endif // PRACH_WORKER_H +#endif // SRSENB_PRACH_WORKER_H diff --git a/srsenb/hdr/phy/txrx.h b/srsenb/hdr/phy/txrx.h index 035f81f9c..69a119900 100644 --- a/srsenb/hdr/phy/txrx.h +++ b/srsenb/hdr/phy/txrx.h @@ -24,15 +24,15 @@ * */ -#ifndef ENBTXRX_H -#define ENBTXRX_H +#ifndef SRSENB_TXRX_H +#define SRSENB_TXRX_H #include "srslte/common/log.h" #include "srslte/common/threads.h" #include "srslte/common/thread_pool.h" #include "srslte/radio/radio.h" -#include "phy/phch_common.h" -#include "phy/prach_worker.h" +#include "phch_common.h" +#include "prach_worker.h" namespace srsenb { @@ -73,4 +73,4 @@ private: } // namespace srsenb -#endif // UEPHY_H +#endif // SRSENB_TXRX_H diff --git a/srsenb/hdr/upper/common_enb.h b/srsenb/hdr/upper/common_enb.h index d04869c54..2e0b28917 100644 --- a/srsenb/hdr/upper/common_enb.h +++ b/srsenb/hdr/upper/common_enb.h @@ -24,8 +24,8 @@ * */ -#ifndef COMMON_ENB_H -#define COMMON_ENB_H +#ifndef SRSENB_COMMON_ENB_H +#define SRSENB_COMMON_ENB_H /******************************************************************************* INCLUDES @@ -181,4 +181,4 @@ inline void uint16_to_uint8(uint16_t i, uint8_t *buf) } // namespace srsenb -#endif // COMMON_ENB_H +#endif // SRSENB_COMMON_ENB_H diff --git a/srsenb/hdr/upper/gtpu.h b/srsenb/hdr/upper/gtpu.h index 6958773b6..892068757 100644 --- a/srsenb/hdr/upper/gtpu.h +++ b/srsenb/hdr/upper/gtpu.h @@ -29,13 +29,13 @@ #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" -#include "upper/common_enb.h" +#include "common_enb.h" #include "srslte/common/threads.h" #include "srslte/srslte.h" #include "srslte/interfaces/enb_interfaces.h" -#ifndef GTPU_H -#define GTPU_H +#ifndef SRSENB_GTPU_H +#define SRSENB_GTPU_H namespace srsenb { @@ -127,4 +127,4 @@ private: } // namespace srsenb -#endif // GTPU_H +#endif // SRSENB_GTPU_H diff --git a/srsenb/hdr/upper/pdcp.h b/srsenb/hdr/upper/pdcp.h index 8c5b05275..45907e1f8 100644 --- a/srsenb/hdr/upper/pdcp.h +++ b/srsenb/hdr/upper/pdcp.h @@ -29,8 +29,8 @@ #include "srslte/interfaces/enb_interfaces.h" #include "srslte/upper/pdcp.h" -#ifndef PDCP_ENB_H -#define PDCP_ENB_H +#ifndef SRSENB_PDCP_H +#define SRSENB_PDCP_H namespace srsenb { @@ -113,4 +113,4 @@ private: } -#endif // PDCP_ENB_H +#endif // SRSENB_PDCP_H diff --git a/srsenb/hdr/upper/rlc.h b/srsenb/hdr/upper/rlc.h index b937cd216..98c3edfb3 100644 --- a/srsenb/hdr/upper/rlc.h +++ b/srsenb/hdr/upper/rlc.h @@ -29,8 +29,8 @@ #include "srslte/interfaces/enb_interfaces.h" #include "srslte/upper/rlc.h" -#ifndef RLC_ENB_H -#define RLC_ENB_H +#ifndef SRSENB_RLC_H +#define SRSENB_RLC_H namespace srsenb { @@ -96,4 +96,4 @@ private: } -#endif // RLC_H +#endif // SRSENB_RLC_H diff --git a/srsenb/hdr/upper/rrc.h b/srsenb/hdr/upper/rrc.h index 2935fd29f..cadb4af43 100644 --- a/srsenb/hdr/upper/rrc.h +++ b/srsenb/hdr/upper/rrc.h @@ -24,8 +24,8 @@ * */ -#ifndef RRC_H -#define RRC_H +#ifndef SRSENB_RRC_H +#define SRSENB_RRC_H #include #include @@ -36,7 +36,7 @@ #include "srslte/common/timeout.h" #include "srslte/common/log.h" #include "srslte/interfaces/enb_interfaces.h" -#include "upper/common_enb.h" +#include "common_enb.h" #include "rrc_metrics.h" namespace srsenb { @@ -364,4 +364,4 @@ private: } // namespace srsenb -#endif // RRC_H +#endif // SRSENB_RRC_H diff --git a/srsenb/hdr/upper/rrc_metrics.h b/srsenb/hdr/upper/rrc_metrics.h index bce3ec95f..7c388da01 100644 --- a/srsenb/hdr/upper/rrc_metrics.h +++ b/srsenb/hdr/upper/rrc_metrics.h @@ -24,10 +24,10 @@ * */ -#ifndef ENB_RRC_METRICS_H -#define ENB_RRC_METRICS_H +#ifndef SRSENB_RRC_METRICS_H +#define SRSENB_RRC_METRICS_H -#include "upper/common_enb.h" +#include "common_enb.h" namespace srsenb { @@ -55,4 +55,4 @@ struct rrc_metrics_t } // namespace srsenb -#endif // ENB_S1AP_METRICS_H +#endif // SRSENB_RRC_METRICS_H diff --git a/srsenb/hdr/upper/s1ap.h b/srsenb/hdr/upper/s1ap.h index 714035638..35369790f 100644 --- a/srsenb/hdr/upper/s1ap.h +++ b/srsenb/hdr/upper/s1ap.h @@ -24,8 +24,8 @@ * */ -#ifndef S1AP_H -#define S1AP_H +#ifndef SRSENB_S1AP_H +#define SRSENB_S1AP_H #include @@ -35,7 +35,7 @@ #include "srslte/common/msg_queue.h" #include "srslte/common/threads.h" #include "srslte/interfaces/enb_interfaces.h" -#include "upper/common_enb.h" +#include "common_enb.h" #include "srslte/asn1/liblte_s1ap.h" #include "s1ap_metrics.h" @@ -148,4 +148,4 @@ private: } // namespace srsenb -#endif // S1AP_H +#endif // SRSENB_S1AP_H diff --git a/srsenb/hdr/upper/s1ap_metrics.h b/srsenb/hdr/upper/s1ap_metrics.h index f77dc699c..b73b0afa0 100644 --- a/srsenb/hdr/upper/s1ap_metrics.h +++ b/srsenb/hdr/upper/s1ap_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef ENB_S1AP_METRICS_H -#define ENB_S1AP_METRICS_H +#ifndef SRSENB_S1AP_METRICS_H +#define SRSENB_S1AP_METRICS_H namespace srsenb { @@ -43,4 +43,4 @@ struct s1ap_metrics_t } // namespace srsenb -#endif // ENB_S1AP_METRICS_H +#endif // SRSENB_S1AP_METRICS_H diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index e440081d0..e91aea7bf 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -25,33 +25,32 @@ */ #include -#include -#include -#include "enb.h" +#include "srsenb/hdr/enb.h" namespace srsenb { enb* enb::instance = NULL; -boost::mutex enb_instance_mutex; - +pthread_mutex_t enb_instance_mutex = PTHREAD_MUTEX_INITIALIZER; enb* enb::get_instance(void) { - boost::mutex::scoped_lock lock(enb_instance_mutex); + pthread_mutex_lock(&enb_instance_mutex); if(NULL == instance) { - instance = new enb(); + instance = new enb(); } + pthread_mutex_unlock(&enb_instance_mutex); return(instance); } void enb::cleanup(void) { srslte_dft_exit(); srslte::byte_buffer_pool::cleanup(); - boost::mutex::scoped_lock lock(enb_instance_mutex); + pthread_mutex_lock(&enb_instance_mutex); if(NULL != instance) { delete instance; instance = NULL; } + pthread_mutex_unlock(&enb_instance_mutex); } enb::enb() : started(false) { @@ -66,6 +65,9 @@ enb::enb() : started(false) { enb::~enb() { + for (uint32_t i = 0; i < phy_log.size(); i++) { + delete (phy_log[i]); + } } bool enb::init(all_args_t *args_) @@ -88,7 +90,7 @@ bool enb::init(all_args_t *args_) char tmp[16]; sprintf(tmp, "PHY%d",i); mylog->init(tmp, logger, true); - phy_log.push_back((void*) mylog); + phy_log.push_back(mylog); } mac_log.init("MAC ", logger, true); rlc_log.init("RLC ", logger); @@ -294,7 +296,7 @@ void enb::handle_rf_msg(srslte_rf_error_t error) str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); str.erase(std::remove(str.begin(), str.end(), '\r'), str.end()); str.push_back('\n'); - rf_log.info(str); + rf_log.info("%s\n", str.c_str()); } } diff --git a/srsenb/src/enb_cfg_parser.cc b/srsenb/src/enb_cfg_parser.cc index 669d2586b..af2ade941 100644 --- a/srsenb/src/enb_cfg_parser.cc +++ b/srsenb/src/enb_cfg_parser.cc @@ -26,10 +26,10 @@ #include "srslte/asn1/liblte_common.h" #include "srslte/asn1/liblte_rrc.h" -#include "cfg_parser.h" +#include "srsenb/hdr/cfg_parser.h" #include "srslte/srslte.h" -#include "parser.h" +#include "srsenb/hdr/parser.h" #include "enb_cfg_parser.h" namespace srsenb { @@ -1072,7 +1072,9 @@ int field_qci::parse(libconfig::Setting &root) parser::field_enum_num sn_field_len ("sn_field_length", &rlc_cfg->sn_field_len, liblte_rrc_sn_field_length_num, LIBLTE_RRC_SN_FIELD_LENGTH_N_ITEMS); - sn_field_len.parse(q["rlc_config"]["ul_um"]); + if (sn_field_len.parse(q["rlc_config"]["ul_um"])) { + fprintf(stderr, "Error can't find sn_field_length in section ul_um\n"); + } } if (q["rlc_config"].exists("dl_um")) { @@ -1085,12 +1087,16 @@ int field_qci::parse(libconfig::Setting &root) parser::field_enum_num sn_field_len ("sn_field_length", &rlc_cfg->sn_field_len, liblte_rrc_sn_field_length_num, LIBLTE_RRC_SN_FIELD_LENGTH_N_ITEMS); - sn_field_len.parse(q["rlc_config"]["dl_um"]); + if (sn_field_len.parse(q["rlc_config"]["dl_um"])) { + fprintf(stderr, "Error can't find sn_field_length in section dl_um\n"); + } parser::field_enum_num t_reordering ("t_reordering", &rlc_cfg->t_reordering, liblte_rrc_t_reordering_num, LIBLTE_RRC_T_REORDERING_N_ITEMS); - t_reordering.parse(q["rlc_config"]["dl_um"]); + if (t_reordering.parse(q["rlc_config"]["dl_um"])) { + fprintf(stderr, "Error can't find t_reordering in section dl_um\n"); + } } // Parse RLC-AM section @@ -1100,22 +1106,30 @@ int field_qci::parse(libconfig::Setting &root) parser::field_enum_num t_poll_retx ("t_poll_retx", &rlc_cfg->t_poll_retx, liblte_rrc_t_poll_retransmit_num, LIBLTE_RRC_T_POLL_RETRANSMIT_N_ITEMS); - t_poll_retx.parse(q["rlc_config"]["ul_am"]); + if (t_poll_retx.parse(q["rlc_config"]["ul_am"])) { + fprintf(stderr, "Error can't find t_poll_retx in section ul_am\n"); + } parser::field_enum_num poll_pdu ("poll_pdu", &rlc_cfg->poll_pdu, liblte_rrc_poll_pdu_num, LIBLTE_RRC_POLL_PDU_N_ITEMS); - poll_pdu.parse(q["rlc_config"]["ul_am"]); + if (poll_pdu.parse(q["rlc_config"]["ul_am"])) { + fprintf(stderr, "Error can't find poll_pdu in section ul_am\n"); + } parser::field_enum_num poll_byte ("poll_byte", &rlc_cfg->poll_byte, liblte_rrc_poll_byte_num, LIBLTE_RRC_POLL_BYTE_N_ITEMS); - poll_byte.parse(q["rlc_config"]["ul_am"]); + if (poll_byte.parse(q["rlc_config"]["ul_am"])) { + fprintf(stderr, "Error can't find poll_byte in section ul_am\n"); + } parser::field_enum_num max_retx_thresh ("max_retx_thresh", &rlc_cfg->max_retx_thresh, liblte_rrc_max_retx_threshold_num, LIBLTE_RRC_MAX_RETX_THRESHOLD_N_ITEMS); - max_retx_thresh.parse(q["rlc_config"]["ul_am"]); + if (max_retx_thresh.parse(q["rlc_config"]["ul_am"])) { + fprintf(stderr, "Error can't find max_retx_thresh in section ul_am\n"); + } } if (q["rlc_config"].exists("dl_am")) { @@ -1124,12 +1138,16 @@ int field_qci::parse(libconfig::Setting &root) parser::field_enum_num t_reordering ("t_reordering", &rlc_cfg->t_reordering, liblte_rrc_t_reordering_num, LIBLTE_RRC_T_REORDERING_N_ITEMS); - t_reordering.parse(q["rlc_config"]["dl_am"]); + if (t_reordering.parse(q["rlc_config"]["dl_am"])) { + fprintf(stderr, "Error can't find t_reordering in section dl_am\n"); + } parser::field_enum_num t_status_prohibit ("t_status_prohibit", &rlc_cfg->t_status_prohibit, liblte_rrc_t_status_prohibit_num, LIBLTE_RRC_T_STATUS_PROHIBIT_N_ITEMS); - t_status_prohibit.parse(q["rlc_config"]["dl_am"]); + if (t_status_prohibit.parse(q["rlc_config"]["dl_am"])) { + fprintf(stderr, "Error can't find t_status_prohibit in section dl_am\n"); + } } @@ -1141,17 +1159,23 @@ int field_qci::parse(libconfig::Setting &root) LIBLTE_RRC_UL_SPECIFIC_PARAMETERS_STRUCT *lc_cfg = &cfg[qci].lc_cfg; parser::field priority ("priority", &lc_cfg->priority); - priority.parse(q["logical_channel_config"]); + if (priority.parse(q["logical_channel_config"])) { + fprintf(stderr, "Error can't find logical_channel_config in section priority\n"); + } parser::field_enum_num prioritized_bit_rate ("prioritized_bit_rate", &lc_cfg->prioritized_bit_rate, liblte_rrc_prioritized_bit_rate_num, LIBLTE_RRC_PRIORITIZED_BIT_RATE_N_ITEMS); - prioritized_bit_rate.parse(q["logical_channel_config"]); + if (prioritized_bit_rate.parse(q["logical_channel_config"])) { + fprintf(stderr, "Error can't find prioritized_bit_rate in section logical_channel_config\n"); + } parser::field_enum_num bucket_size_duration ("bucket_size_duration", &lc_cfg->bucket_size_duration, liblte_rrc_bucket_size_duration_num, LIBLTE_RRC_BUCKET_SIZE_DURATION_N_ITEMS); - bucket_size_duration.parse(q["logical_channel_config"]); + if (bucket_size_duration.parse(q["logical_channel_config"])) { + fprintf(stderr, "Error can't find bucket_size_duration in section logical_channel_config\n"); + } parser::field log_chan_group ("log_chan_group", &lc_cfg->log_chan_group); if (log_chan_group.parse(q["logical_channel_config"])) { diff --git a/srsenb/src/enb_cfg_parser.h b/srsenb/src/enb_cfg_parser.h index d68fb87d8..912c9bf19 100644 --- a/srsenb/src/enb_cfg_parser.h +++ b/srsenb/src/enb_cfg_parser.h @@ -33,9 +33,9 @@ #include #include #include -#include "parser.h" +#include "srsenb/hdr/parser.h" -#include "upper/rrc.h" +#include "srsenb/hdr/upper/rrc.h" #include "srslte/asn1/liblte_rrc.h" namespace srsenb { diff --git a/srsenb/src/mac/mac.cc b/srsenb/src/mac/mac.cc index 8b76cc4f3..463da2e25 100644 --- a/srsenb/src/mac/mac.cc +++ b/srsenb/src/mac/mac.cc @@ -36,7 +36,7 @@ #include #include "srslte/common/log.h" -#include "mac/mac.h" +#include "srsenb/hdr/mac/mac.h" //#define WRITE_SIB_PCAP diff --git a/srsenb/src/mac/scheduler.cc b/srsenb/src/mac/scheduler.cc index 51f161d4a..53b3cd939 100644 --- a/srsenb/src/mac/scheduler.cc +++ b/srsenb/src/mac/scheduler.cc @@ -28,7 +28,7 @@ #include "srslte/srslte.h" #include "srslte/common/pdu.h" -#include "mac/scheduler.h" +#include "srsenb/hdr/mac/scheduler.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) @@ -64,6 +64,7 @@ sched::sched() : bc_aggr_level(0), rar_aggr_level(0), avail_rbg(0), P(0), start_ } pthread_mutex_init(&mutex, NULL); + pthread_mutex_init(&mutex2, NULL); reset(); } @@ -71,6 +72,7 @@ sched::~sched() { srslte_regs_free(®s); pthread_mutex_destroy(&mutex); + pthread_mutex_destroy(&mutex2); } void sched::init(rrc_interface_mac *rrc_, srslte::log* log) @@ -173,13 +175,15 @@ int sched::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t *ue_cfg) int sched::ue_rem(uint16_t rnti) { pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db.erase(rnti); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } + pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex); return ret; } @@ -217,13 +221,15 @@ int sched::bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, sched_interface::ue_bear int sched::bearer_ue_rem(uint16_t rnti, uint32_t lc_id) { pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db[rnti].rem_bearer(lc_id); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } + pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex); return ret; } @@ -254,32 +260,42 @@ uint32_t sched::get_ul_buffer(uint16_t rnti) return ret; } +/* \Warning: This function is not mutexed because it can produce late changes on the buffer state while + * the scheduler is already allocating data, resulting in empty grants. + * Ideally we would like the scheduler to query the RLC for buffer states in order to get the most updated + * buffer state with the minimum overhead. However, the current architecture is designed to be compliant + * with the FAPI interface + * + * We add a new mutex used only in ue_rem to avoid the UE being removed in between the access to + * ue_db.count() and the access to the std::map. + */ int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue) { - pthread_mutex_lock(&mutex); - int ret = 0; - if (ue_db.count(rnti)) { + pthread_mutex_lock(&mutex2); + int ret = 0; + if (ue_db.count(rnti)) { ue_db[rnti].dl_buffer_state(lc_id, tx_queue, retx_queue); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } - pthread_mutex_unlock(&mutex); - return ret; + pthread_mutex_unlock(&mutex2); + return ret; } +/* \Warning Read comment in dl_rlc_buffer_state() */ int sched::dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code) { - pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db[rnti].mac_buffer_state(ce_code); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } - pthread_mutex_unlock(&mutex); - return ret; + pthread_mutex_unlock(&mutex2); + return ret; } int sched::dl_ant_info(uint16_t rnti, LIBLTE_RRC_ANTENNA_INFO_DEDICATED_STRUCT *dl_ant_info) { @@ -676,10 +692,11 @@ int sched::dl_sched_data(dl_sched_data_t data[MAX_DATA_LIST]) int nof_data_elems = 0; for(std::map::iterator iter=ue_db.begin(); iter!=ue_db.end(); ++iter) { - sched_ue *user = (sched_ue*) &iter->second; - uint16_t rnti = (uint16_t) iter->first; + sched_ue *user = (sched_ue*) &iter->second; + uint16_t rnti = (uint16_t) iter->first; - dl_harq_proc *h = dl_metric->get_user_allocation(user); + uint32_t data_before = user->get_pending_dl_new_data(current_tti); + dl_harq_proc *h = dl_metric->get_user_allocation(user); srslte_dci_format_t dci_format = user->get_dci_format(); data[nof_data_elems].dci_format = dci_format; @@ -706,10 +723,12 @@ int sched::dl_sched_data(dl_sched_data_t data[MAX_DATA_LIST]) Error("DCI format (%d) not implemented\n", dci_format); } if (tbs > 0) { - log_h->info("SCHED: DL %s rnti=0x%x, pid=%d, mask=0x%x, dci=%d,%d, n_rtx=%d, tbs=%d, buffer=%d, tb_en={%s,%s}\n", + log_h->info("SCHED: DL %s rnti=0x%x, pid=%d, mask=0x%x, dci=%d,%d, n_rtx=%d, tbs=%d, buffer=%d/%d, tb_en={%s,%s}\n", !is_newtx?"retx":"tx", rnti, h->get_id(), h->get_rbgmask(), data[nof_data_elems].dci_location.L, data[nof_data_elems].dci_location.ncce, h->nof_retx(0) + h->nof_retx(1), - tbs, user->get_pending_dl_new_data(current_tti), data[nof_data_elems].dci.tb_en[0]?"y":"n", + tbs, + data_before, user->get_pending_dl_new_data(current_tti), + data[nof_data_elems].dci.tb_en[0]?"y":"n", data[nof_data_elems].dci.tb_en[1]?"y":"n"); nof_data_elems++; } else { diff --git a/srsenb/src/mac/scheduler_harq.cc b/srsenb/src/mac/scheduler_harq.cc index ad7986436..c860c7a14 100644 --- a/srsenb/src/mac/scheduler_harq.cc +++ b/srsenb/src/mac/scheduler_harq.cc @@ -28,7 +28,7 @@ #include "srslte/srslte.h" #include "srslte/common/pdu.h" -#include "mac/scheduler.h" +#include "srsenb/hdr/mac/scheduler.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/mac/scheduler_metric.cc b/srsenb/src/mac/scheduler_metric.cc index f6fb9d9df..a15faebbd 100644 --- a/srsenb/src/mac/scheduler_metric.cc +++ b/srsenb/src/mac/scheduler_metric.cc @@ -25,8 +25,8 @@ */ #include -#include "mac/scheduler_harq.h" -#include "mac/scheduler_metric.h" +#include "srsenb/hdr/mac/scheduler_harq.h" +#include "srsenb/hdr/mac/scheduler_metric.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) @@ -148,9 +148,7 @@ dl_harq_proc* dl_metric_rr::get_user_allocation(sched_ue *user) if (pending_data || (h && !h->is_empty())) { #endif if (nof_users_with_data) { - if (nof_users_with_data == 2) { - } - if ((current_tti%nof_users_with_data) != user->ue_idx) { + if ((current_tti%nof_users_with_data) != user->ue_idx) { return NULL; } } diff --git a/srsenb/src/mac/scheduler_ue.cc b/srsenb/src/mac/scheduler_ue.cc index 6948f922a..6cb4462e8 100644 --- a/srsenb/src/mac/scheduler_ue.cc +++ b/srsenb/src/mac/scheduler_ue.cc @@ -28,8 +28,8 @@ #include "srslte/srslte.h" #include "srslte/common/pdu.h" -#include "mac/scheduler_ue.h" -#include "mac/scheduler.h" +#include "srsenb/hdr/mac/scheduler_ue.h" +#include "srsenb/hdr/mac/scheduler.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/mac/ue.cc b/srsenb/src/mac/ue.cc index d6fe07d0a..39e8c88e2 100644 --- a/srsenb/src/mac/ue.cc +++ b/srsenb/src/mac/ue.cc @@ -28,7 +28,7 @@ #include #include "srslte/interfaces/enb_interfaces.h" -#include "mac/ue.h" +#include "srsenb/hdr/mac/ue.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index 3aedda25a..45dd028b0 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -36,8 +36,8 @@ #include #include -#include "enb.h" -#include "metrics_stdout.h" +#include "srsenb/hdr/enb.h" +#include "srsenb/hdr/metrics_stdout.h" using namespace std; using namespace srsenb; diff --git a/srsenb/src/metrics_stdout.cc b/srsenb/src/metrics_stdout.cc index 5687f25e1..ca9137a24 100644 --- a/srsenb/src/metrics_stdout.cc +++ b/srsenb/src/metrics_stdout.cc @@ -24,7 +24,7 @@ * */ -#include "metrics_stdout.h" +#include "srsenb/hdr/metrics_stdout.h" #include #include diff --git a/srsenb/src/parser.cc b/srsenb/src/parser.cc index 82e088ab2..8a85789e9 100644 --- a/srsenb/src/parser.cc +++ b/srsenb/src/parser.cc @@ -24,7 +24,7 @@ * */ -#include "parser.h" +#include "srsenb/hdr/parser.h" #include namespace srsenb { diff --git a/srsenb/src/phy/phch_common.cc b/srsenb/src/phy/phch_common.cc index 99bfc3d29..ce8026ca5 100644 --- a/srsenb/src/phy/phch_common.cc +++ b/srsenb/src/phy/phch_common.cc @@ -27,7 +27,7 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/txrx.h" +#include "srsenb/hdr/phy/txrx.h" #include diff --git a/srsenb/src/phy/phch_worker.cc b/srsenb/src/phy/phch_worker.cc index 8013a7d5c..8b6a731e2 100644 --- a/srsenb/src/phy/phch_worker.cc +++ b/srsenb/src/phy/phch_worker.cc @@ -29,7 +29,7 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/phch_worker.h" +#include "srsenb/hdr/phy/phch_worker.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) @@ -227,7 +227,7 @@ void phch_worker::set_conf_dedicated_ack(uint16_t rnti, bool ack){ if (ue_db.count(rnti)) { ue_db[rnti].dedicated_ack = ack; } else { - Error("Setting dedicated ack: rnti=0x%x does not exist\n"); + Error("Setting dedicated ack: rnti=0x%x does not exist\n", rnti); } pthread_mutex_unlock(&mutex); } @@ -309,7 +309,7 @@ void phch_worker::set_config_dedicated(uint16_t rnti, ue_db[rnti].dedicated.pdsch_cnfg_ded = dedicated->pdsch_cnfg_ded; } } else { - Error("Setting config dedicated: rnti=0x%x does not exist\n"); + Error("Setting config dedicated: rnti=0x%x does not exist\n", rnti); } pthread_mutex_unlock(&mutex); } @@ -602,8 +602,8 @@ int phch_worker::decode_pusch(srslte_enb_ul_pusch_t *grants, uint32_t nof_pusch) } */ log_h->info_hex(grants[i].data, phy_grant.mcs.tbs / 8, - "PUSCH: rnti=0x%x, prb=(%d,%d), tbs=%d, mcs=%d, rv=%d, snr=%.1f dB, n_iter=%d, crc=%s%s%s%s%s%s%s\n", - rnti, phy_grant.n_prb[0], phy_grant.n_prb[0] + phy_grant.L_prb, + "PUSCH: rnti=0x%x, prb=(%d,%d), tbs=%d, mcs=%d, idx=%d, rv=%d, snr=%.1f dB, n_iter=%d, crc=%s%s%s%s%s%s%s%s\n", + rnti, phy_grant.n_prb[0], phy_grant.n_prb[0], phy_grant.L_prb, phy_grant.mcs.tbs / 8, phy_grant.mcs.idx, grants[i].grant.rv_idx, snr_db, srslte_pusch_last_noi(&enb_ul.pusch), diff --git a/srsenb/src/phy/phy.cc b/srsenb/src/phy/phy.cc index d47998fa9..120a3c7b5 100644 --- a/srsenb/src/phy/phy.cc +++ b/srsenb/src/phy/phy.cc @@ -34,7 +34,7 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/phy.h" +#include "srsenb/hdr/phy/phy.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) @@ -92,12 +92,12 @@ void phy::parse_config(phy_cfg_t* cfg) bool phy::init(phy_args_t *args, phy_cfg_t *cfg, srslte::radio* radio_handler_, - mac_interface_phy *mac, - srslte::log* log_h) + mac_interface_phy *mac, + srslte::log_filter* log_h) { - std::vector log_vec; + std::vector log_vec; for (int i=0;inof_phy_threads;i++) { - log_vec.push_back((void*)log_h); + log_vec.push_back(log_h); } init(args, cfg, radio_handler_, mac, log_vec); return true; @@ -107,7 +107,7 @@ bool phy::init(phy_args_t *args, phy_cfg_t *cfg, srslte::radio* radio_handler_, mac_interface_phy *mac, - std::vector log_vec) + std::vector log_vec) { mlockall(MCL_CURRENT | MCL_FUTURE); diff --git a/srsenb/src/phy/prach_worker.cc b/srsenb/src/phy/prach_worker.cc index b4bd7da3f..a42849bbe 100644 --- a/srsenb/src/phy/prach_worker.cc +++ b/srsenb/src/phy/prach_worker.cc @@ -25,7 +25,7 @@ */ #include "srslte/srslte.h" -#include "phy/prach_worker.h" +#include "srsenb/hdr/phy/prach_worker.h" namespace srsenb { diff --git a/srsenb/src/phy/txrx.cc b/srsenb/src/phy/txrx.cc index fbc96ea72..7f6503b06 100644 --- a/srsenb/src/phy/txrx.cc +++ b/srsenb/src/phy/txrx.cc @@ -29,8 +29,8 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/txrx.h" -#include "phy/phch_worker.h" +#include "srsenb/hdr/phy/txrx.h" +#include "srsenb/hdr/phy/phch_worker.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) @@ -125,7 +125,7 @@ void txrx::run_thread() srslte_timestamp_copy(&tx_time, &rx_time); srslte_timestamp_add(&tx_time, 0, HARQ_DELAY_MS*1e-3); - Debug("Settting TTI=%d, tx_mutex=%d, tx_time=%d:%f to worker %d\n", + Debug("Settting TTI=%d, tx_mutex=%d, tx_time=%ld:%f to worker %d\n", tti, tx_mutex_cnt, tx_time.full_secs, tx_time.frac_secs, worker->get_id()); diff --git a/srsenb/src/upper/gtpu.cc b/srsenb/src/upper/gtpu.cc index 2336f9047..0b0df8de2 100644 --- a/srsenb/src/upper/gtpu.cc +++ b/srsenb/src/upper/gtpu.cc @@ -24,7 +24,7 @@ * */ -#include "upper/gtpu.h" +#include "srsenb/hdr/upper/gtpu.h" #include #include #include diff --git a/srsenb/src/upper/pdcp.cc b/srsenb/src/upper/pdcp.cc index d3ed88c4e..99289ec4d 100644 --- a/srsenb/src/upper/pdcp.cc +++ b/srsenb/src/upper/pdcp.cc @@ -24,8 +24,8 @@ * */ -#include "upper/pdcp.h" -#include "upper/common_enb.h" +#include "srsenb/hdr/upper/pdcp.h" +#include "srsenb/hdr/upper/common_enb.h" namespace srsenb { diff --git a/srsenb/src/upper/rlc.cc b/srsenb/src/upper/rlc.cc index 0b7babbac..72d269c6c 100644 --- a/srsenb/src/upper/rlc.cc +++ b/srsenb/src/upper/rlc.cc @@ -24,8 +24,8 @@ * */ -#include "upper/rlc.h" -#include "upper/common_enb.h" +#include "srsenb/hdr/upper/rlc.h" +#include "srsenb/hdr/upper/common_enb.h" namespace srsenb { diff --git a/srsenb/src/upper/rrc.cc b/srsenb/src/upper/rrc.cc index f1ae51016..f47656c6d 100644 --- a/srsenb/src/upper/rrc.cc +++ b/srsenb/src/upper/rrc.cc @@ -26,10 +26,9 @@ #include "srslte/interfaces/sched_interface.h" #include "srslte/asn1/liblte_rrc.h" -#include "upper/rrc.h" +#include "srsenb/hdr/upper/rrc.h" #include "srslte/srslte.h" #include "srslte/asn1/liblte_mme.h" -#include "upper/rrc.h" using srslte::byte_buffer_t; using srslte::bit_buffer_t; @@ -225,7 +224,7 @@ void rrc::add_user(uint16_t rnti) pdcp->add_user(rnti); rrc_log->info("Added new user rnti=0x%x\n", rnti); } else { - rrc_log->error("Adding user rnti=0x%x (already exists)\n"); + rrc_log->error("Adding user rnti=0x%x (already exists)\n", rnti); } pthread_mutex_unlock(&user_mutex); } @@ -584,7 +583,7 @@ void rrc::parse_ul_ccch(uint16_t rnti, byte_buffer_t *pdu) if (users[rnti].is_idle()) { old_rnti = ul_ccch_msg.msg.rrc_con_reest_req.ue_id.c_rnti; if (users.count(old_rnti)) { - rrc_log->error("Not supported: ConnectionReestablishment. Sending Connection Reject\n", old_rnti); + rrc_log->error("Not supported: ConnectionReestablishment for rnti=0x%x. Sending Connection Reject\n", old_rnti); users[rnti].send_connection_reest_rej(); rem_user_thread(old_rnti); } else { @@ -649,7 +648,7 @@ void rrc::run_thread() pthread_mutex_lock(&user_mutex); break; default: - rrc_log->error("Rx PDU with invalid bearer id: %s", p.lcid); + rrc_log->error("Rx PDU with invalid bearer id: %d", p.lcid); break; } } else { @@ -799,7 +798,7 @@ bool rrc::ue::is_timeout() int64_t deadline = deadline_s*1e6 + deadline_us; int64_t elapsed = t[0].tv_sec*1e6 + t[0].tv_usec; if (elapsed > deadline && elapsed > 0) { - parent->rrc_log->warning("User rnti=0x%x expired %s deadline: %d:%d>%d:%d us\n", + parent->rrc_log->warning("User rnti=0x%x expired %s deadline: %ld:%ld>%d:%d us\n", rnti, deadline_str, t[0].tv_sec, t[0].tv_usec, deadline_s, deadline_us); @@ -1069,6 +1068,9 @@ void rrc::ue::notify_s1ap_ue_ctxt_setup_complete() { LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT res; res.ext = false; + res.E_RABFailedToSetupListCtxtSURes_present = false; + res.CriticalityDiagnostics_present = false; + res.E_RABSetupListCtxtSURes.len = 0; res.E_RABFailedToSetupListCtxtSURes.len = 0; diff --git a/srsenb/src/upper/s1ap.cc b/srsenb/src/upper/s1ap.cc index a3d937a57..b48e8a248 100644 --- a/srsenb/src/upper/s1ap.cc +++ b/srsenb/src/upper/s1ap.cc @@ -24,8 +24,8 @@ * */ -#include "upper/s1ap.h" -#include "upper/common_enb.h" +#include "srsenb/hdr/upper/s1ap.h" +#include "srsenb/hdr/upper/common_enb.h" #include #include diff --git a/srsenb/test/mac/scheduler_test.cc b/srsenb/test/mac/scheduler_test.cc index 73dd531b0..50d4cb409 100644 --- a/srsenb/test/mac/scheduler_test.cc +++ b/srsenb/test/mac/scheduler_test.cc @@ -26,8 +26,8 @@ #include -#include "mac/mac.h" -#include "phy/phy.h" +#include "srsenb/hdr/mac/mac.h" +#include "srsenb/hdr/phy/phy.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/interfaces/sched_interface.h" diff --git a/srsenb/test/upper/ip_test.cc b/srsenb/test/upper/ip_test.cc index 8052ed4d7..9361a9901 100644 --- a/srsenb/test/upper/ip_test.cc +++ b/srsenb/test/upper/ip_test.cc @@ -36,8 +36,8 @@ #include #include -#include "mac/mac.h" -#include "phy/phy.h" +#include "srsenb/hdr/mac/mac.h" +#include "srsenb/hdr/phy/phy.h" #include "srslte/common/threads.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/common/common.h" diff --git a/srsenb/test/upper/plmn_test.cc b/srsenb/test/upper/plmn_test.cc index ddf68d130..c8e9bdd69 100644 --- a/srsenb/test/upper/plmn_test.cc +++ b/srsenb/test/upper/plmn_test.cc @@ -8,7 +8,7 @@ */ #include -#include "upper/common_enb.h" +#include "srsenb/hdr/upper/common_enb.h" #include "srslte/asn1/liblte_rrc.h" void rrc_plmn_test() diff --git a/srsepc/CMakeLists.txt b/srsepc/CMakeLists.txt index 0006e5191..2b54d4a1e 100644 --- a/srsepc/CMakeLists.txt +++ b/srsepc/CMakeLists.txt @@ -35,7 +35,7 @@ endif() include_directories( ${Boost_INCLUDE_DIRS} ${SEC_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR}/srsepc/hdr + ${PROJECT_SOURCE_DIR} ) link_directories( diff --git a/srsepc/epc.conf.example b/srsepc/epc.conf.example index b32a6984a..02ef797ef 100644 --- a/srsepc/epc.conf.example +++ b/srsepc/epc.conf.example @@ -10,8 +10,9 @@ # tac: 16-bit Tracking Area Code. # mcc: Mobile Country Code # mnc: Mobile Network Code -# mme_bindx_addr: IP subnet to listen for eNB S1 connnections -# apn: Set Access Point Name (APN) +# apn: Set Access Point Name (APN) +# mme_bind_addr: IP bind addr to listen for eNB S1-MME connnections +# dns_addr: DNS server address for the UEs # ##################################################################### [mme] @@ -21,7 +22,8 @@ tac = 0x0007 mcc = 001 mnc = 01 mme_bind_addr = 127.0.1.100 -apn = test123 +apn = srsapn +dns_addr = 8.8.8.8 ##################################################################### # HSS configuration diff --git a/srsepc/hdr/hss/hss.h b/srsepc/hdr/hss/hss.h index 818feae49..97e2d45c1 100644 --- a/srsepc/hdr/hss/hss.h +++ b/srsepc/hdr/hss/hss.h @@ -30,8 +30,8 @@ * interfaces and helpers. *****************************************************************************/ -#ifndef HSS_H -#define HSS_H +#ifndef SRSEPC_HSS_H +#define SRSEPC_HSS_H #include #include "srslte/common/log.h" @@ -124,4 +124,4 @@ private: } // namespace srsepc -#endif // MME_H +#endif // SRSEPC_HSS_H diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index c0eac0685..599059260 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -30,8 +30,8 @@ * interfaces and helpers. *****************************************************************************/ -#ifndef MME_H -#define MME_H +#ifndef SRSEPC_MME_H +#define SRSEPC_MME_H #include #include "srslte/common/log.h" @@ -89,4 +89,4 @@ private: } // namespace srsepc -#endif // MME_H +#endif // SRSEPC_MME_H diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index f2804e22b..ad2181c85 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -23,15 +23,14 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef MME_GTPC_H -#define MME_GTPC_H +#ifndef SRSEPC_MME_GTPC_H +#define SRSEPC_MME_GTPC_H #include "srslte/common/log.h" #include "srslte/common/log_filter.h" #include "srslte/common/buffer_pool.h" -#include #include "srslte/asn1/gtpc.h" -#include "mme/s1ap_common.h" +#include "s1ap_common.h" namespace srsepc { @@ -42,17 +41,22 @@ class mme_gtpc { public: + typedef struct gtpc_ctx{ + srslte::gtp_fteid_t mme_ctr_fteid; + srslte::gtp_fteid_t sgw_ctr_fteid; + }gtpc_ctx_t; static mme_gtpc* get_instance(void); static void cleanup(void); bool init(srslte::log_filter *mme_gtpc_log); uint32_t get_new_ctrl_teid(); - void send_create_session_request(uint64_t imsi, uint32_t mme_s1ap_id); + void send_create_session_request(uint64_t imsi); void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu); - void send_modify_bearer_request(erab_ctx_t *bearer_ctx); + void send_modify_bearer_request(uint64_t imsi, erab_ctx_t *bearer_ctx); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); - void send_delete_session_request(ue_ctx_t *ue_ctx); + void send_release_access_bearers_request(uint64_t imsi); + void send_delete_session_request(uint64_t imsi); private: @@ -68,9 +72,10 @@ private: in_addr_t m_mme_gtpc_ip; uint32_t m_next_ctrl_teid; - std::map m_teid_to_mme_s1ap_id; + std::map m_mme_ctr_teid_to_imsi; + std::map m_imsi_to_gtpc_ctx; }; } -#endif +#endif // SRSEPC_MME_GTPC_H diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 963e8d51f..5036c18cd 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -23,8 +23,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_H -#define S1AP_H +#ifndef SRSEPC_S1AP_H +#define SRSEPC_S1AP_H #include "srslte/asn1/gtpc.h" #include "srslte/asn1/liblte_s1ap.h" @@ -40,12 +40,12 @@ #include #include #include -#include "mme/s1ap_common.h" -#include "mme/s1ap_mngmt_proc.h" -#include "mme/s1ap_nas_transport.h" -#include "mme/s1ap_ctx_mngmt_proc.h" -#include "mme/mme_gtpc.h" -#include "hss/hss.h" +#include "s1ap_common.h" +#include "s1ap_mngmt_proc.h" +#include "s1ap_nas_transport.h" +#include "s1ap_ctx_mngmt_proc.h" +#include "mme_gtpc.h" +#include "srsepc/hdr/hss/hss.h" namespace srsepc{ @@ -65,13 +65,12 @@ public: int get_s1_mme(); void delete_enb_ctx(int32_t assoc_id); - void delete_ues_in_enb(uint16_t enb_id); bool handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb_sri); bool handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri); bool handle_successful_outcome(LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *msg); - void activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi); + void activate_eps_bearer(uint64_t imsi, uint8_t ebi); void print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx); @@ -79,20 +78,41 @@ public: uint32_t get_next_mme_ue_s1ap_id(); enb_ctx_t* find_enb_ctx(uint16_t enb_id); void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); - ue_ctx_t* find_ue_ctx(uint32_t mme_ue_s1ap_id); - void add_new_ue_ctx(const ue_ctx_t &ue_ctx); - bool delete_ue_ctx(ue_ctx_t *ue_ctx); - uint32_t allocate_m_tmsi(uint32_t mme_ue_s1ap_id); + bool add_ue_ctx_to_imsi_map(ue_ctx_t *ue_ctx); + bool add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx_t *ue_ctx); + + ue_ctx_t* find_ue_ctx_from_imsi(uint64_t imsi); + ue_ctx_t* find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); + + bool release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); + void release_ues_ecm_ctx_in_enb(uint16_t enb_id); + bool delete_ue_ctx(uint64_t imsi); + + //ue_ctx_t* find_ue_ctx(uint32_t mme_ue_s1ap_id); + //void add_new_ue_ctx(const ue_ctx_t &ue_ctx); + + //void add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx); + //void add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx); + //ue_emm_ctx_t* find_ue_emm_ctx_from_imsi(uint64_t imsi); + //ue_ecm_ctx_t* find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); + //bool delete_ue_emm_ctx(uint64_t imsi); + //bool delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); + //void delete_ues_ecm_ctx_in_enb(uint16_t enb_id); + + //void store_tmp_ue_emm_ctx(const ue_emm_ctx_t &ue_ecm_ctx); + //bool get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr); + + uint32_t allocate_m_tmsi(uint64_t imsi); s1ap_args_t m_s1ap_args; srslte::log_filter *m_s1ap_log; s1ap_mngmt_proc* m_s1ap_mngmt_proc; - s1ap_nas_transport* m_s1ap_nas_transport; - s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc; + s1ap_nas_transport* m_s1ap_nas_transport; + s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc; - std::map m_tmsi_to_s1ap_id; + std::map m_tmsi_to_imsi; private: s1ap(); @@ -107,12 +127,20 @@ private: int m_s1mme; std::map m_active_enbs; std::map m_sctp_to_enb_id; - std::map m_active_ues; std::map > m_enb_id_to_ue_ids; + + + std::map m_imsi_to_ue_ctx; + std::map m_mme_ue_s1ap_id_to_ue_ctx; + + //std::map m_imsi_to_ue_emm_ctx; + //std::map m_mme_ue_s1ap_id_to_ue_ecm_ctx; + //std::map m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx; + uint32_t m_next_mme_ue_s1ap_id; uint32_t m_next_m_tmsi; - //FIXME the GTP-C should be moved to the MME class, the the packaging of GTP-C messages is done. + //FIXME the GTP-C should be moved to the MME class, when the packaging of GTP-C messages is done. mme_gtpc *m_mme_gtpc; }; @@ -125,4 +153,4 @@ s1ap::get_plmn() } //namespace srsepc -#endif //S1AP_H +#endif // SRSEPC_S1AP_H diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 65c16f8c9..a71daada8 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -18,8 +18,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_COMMON_H -#define S1AP_COMMON_H +#ifndef SRSEPC_S1AP_COMMON_H +#define SRSEPC_S1AP_COMMON_H #include "srslte/common/security.h" #include "srslte/asn1/gtpc_ies.h" @@ -33,6 +33,47 @@ 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_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, @@ -41,6 +82,7 @@ enum erab_state ERAB_ACTIVE }; + typedef struct{ uint8_t mme_code; uint16_t mme_group; @@ -49,6 +91,7 @@ typedef struct{ uint16_t mnc; // BCD-coded with 0xF filler std::string mme_bind_addr; std::string mme_name; + std::string dns_addr; std::string mme_apn; } s1ap_args_t; @@ -75,29 +118,49 @@ typedef struct{ srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo; uint8_t k_nas_enc[32]; uint8_t k_nas_int[32]; -} eps_security_ctx_t; + 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; srslte::gtpc_f_teid_ie enb_fteid; - srslte::gtpc_f_teid_ie sgw_ctrl_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; - uint16_t enb_id; struct sctp_sndrcvinfo enb_sri; - eps_security_ctx_t security_ctxt; + ecm_state_t state; erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; - LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT ue_network_cap; - bool ms_network_cap_present; - LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT ms_network_cap; bool eit; - uint8_t procedure_transaction_id; - uint8_t attach_type; +} ue_ecm_ctx_t; + + +typedef struct{ + ue_emm_ctx_t emm_ctx; + eps_sec_ctx_t sec_ctx; + ue_ecm_ctx_t ecm_ctx; + erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; } ue_ctx_t; }//namespace -#endif + +#endif // SRSEPC_S1AP_COMMON_H diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 2eaca64ab..e6182269f 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -23,14 +23,14 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_CTX_MNGMT_PROC_H -#define S1AP_CTX_MNGMT_PROC_H +#ifndef SRSEPC_S1AP_CTX_MNGMT_PROC_H +#define SRSEPC_S1AP_CTX_MNGMT_PROC_H #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/common.h" -#include "mme/s1ap_common.h" +#include "s1ap_common.h" #include "srslte/common/log_filter.h" -#include "mme/mme_gtpc.h" +#include "mme_gtpc.h" #include "srslte/common/buffer_pool.h" namespace srsepc{ @@ -47,9 +47,12 @@ public: 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(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(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_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 handle_ue_context_release_complete(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMPLETE_STRUCT *rel_comp); private: s1ap_ctx_mngmt_proc(); @@ -67,4 +70,4 @@ private: } //namespace srsepc -#endif //S1AP_MNGMT_PROC +#endif // SRSEPC_S1AP_CTX_MNGMT_PROC_H diff --git a/srsepc/hdr/mme/s1ap_mngmt_proc.h b/srsepc/hdr/mme/s1ap_mngmt_proc.h index 7f5771676..859a647e4 100644 --- a/srsepc/hdr/mme/s1ap_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_mngmt_proc.h @@ -23,12 +23,12 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_MNGMT_PROC_H -#define S1AP_MNGMT_PROC_H +#ifndef SRSEPC_S1AP_MNGMT_PROC_H +#define SRSEPC_S1AP_MNGMT_PROC_H #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/common.h" -#include "mme/s1ap_common.h" +#include "s1ap_common.h" #include "srslte/common/log_filter.h" namespace srsepc{ @@ -65,4 +65,4 @@ private: } //namespace srsepc -#endif //S1AP_MNGMT_PROC +#endif // SRSEPC_S1AP_MNGMT_PROC_H diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index e958c8dbc..9df615914 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -23,15 +23,15 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_NAS_TRANSPORT_H -#define S1AP_NAS_TRANSPORT_H +#ifndef SRSEPC_S1AP_NAS_TRANSPORT_H +#define SRSEPC_S1AP_NAS_TRANSPORT_H #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/buffer_pool.h" -#include "mme/s1ap_common.h" +#include "s1ap_common.h" #include "srslte/asn1/gtpc.h" -#include "hss/hss.h" -#include "mme/mme_gtpc.h" +#include "srsepc/hdr/hss/hss.h" +#include "mme_gtpc.h" namespace srsepc{ @@ -47,9 +47,9 @@ public: bool handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + //Initial UE messages bool handle_nas_attach_request( uint32_t enb_ue_s1ap_id, - const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, - const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); @@ -62,28 +62,55 @@ public: bool handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); + + bool handle_nas_service_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri); + + bool handle_nas_detach_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri); + + bool handle_nas_tracking_area_update_request( uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri); + 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_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_attach_complete(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, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); bool handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, 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_msg, bool *reply_flag); - bool handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, 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_nas_detach_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + + bool integrity_check(ue_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 pack_authentication_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t next_mme_ue_s1ap_id, 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 unpack_authentication_response(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, LIBLTE_MME_AUTHENTICATION_RESPONSE_MSG_STRUCT *auth_resp); - bool pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx); - bool pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx); + 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_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_attach_accept(ue_ctx_t *ue_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(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_identity_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); - bool pack_emm_information(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_service_reject(srslte::byte_buffer_t *reply_msg, uint8_t emm_cause, uint32_t enb_ue_s1ap_id); void log_unhandled_attach_request_ies(const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT *attach_req); @@ -102,7 +129,5 @@ private: hss_interface_s1ap* m_hss; mme_gtpc* m_mme_gtpc; }; - } //namespace srsepc - -#endif //S1AP_NAS_TRANSPORT +#endif // SRSEPC_S1AP_NAS_TRANSPORT_H diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 095b4d9b0..98ad59403 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -30,8 +30,8 @@ * interfaces and helpers. *****************************************************************************/ -#ifndef SPGW_H -#define SPGW_H +#ifndef SRSEPC_SPGW_H +#define SRSEPC_SPGW_H #include #include "srslte/common/log.h" @@ -76,6 +76,7 @@ public: void handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu); void handle_modify_bearer_request(struct srslte::gtpc_pdu *mb_req_pdu, struct srslte::gtpc_pdu *mb_resp_pdu); void handle_delete_session_request(struct srslte::gtpc_pdu *del_req_pdu, struct srslte::gtpc_pdu *del_resp_pdu); + void handle_release_access_bearers_request(struct srslte::gtpc_pdu *rel_req_pdu, struct srslte::gtpc_pdu *rel_resp_pdu); void handle_sgi_pdu(srslte::byte_buffer_t *msg); void handle_s1u_pdu(srslte::byte_buffer_t *msg); @@ -94,6 +95,10 @@ private: uint64_t get_new_user_teid(); in_addr_t get_new_ue_ipv4(); + spgw_tunnel_ctx_t* create_gtp_ctx(struct srslte::gtpc_create_session_request *cs_req); + bool delete_gtp_ctx(uint32_t ctrl_teid); + + bool m_running; srslte::byte_buffer_pool *m_pool; mme_gtpc *m_mme_gtpc; @@ -112,11 +117,17 @@ private: sockaddr_in m_s1u_addr; pthread_mutex_t m_mutex; + + std::map m_imsi_to_ctr_teid; //IMSI to control TEID map. Important to check if UE is previously connected std::map m_teid_to_tunnel_ctx; //Map control TEID to tunnel ctx. Usefull to get reply ctrl TEID, UE IP, etc. std::map m_ip_to_teid; //Map IP to User-plane TEID for downlink traffic uint32_t m_h_next_ue_ip; + /*Time*/ + struct timeval m_t_last_dl; + struct timeval m_t_last_ul; + /*Logs*/ srslte::log_filter *m_spgw_log; @@ -124,4 +135,4 @@ private: } // namespace srsepc -#endif // SGW_H +#endif // SRSEPC_SPGW_H diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index c9a13f93a..9a8db0e3a 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -28,8 +28,8 @@ #include #include #include -#include -#include "hss/hss.h" +#include // for printing uint64_t +#include "srsepc/hdr/hss/hss.h" #include "srslte/common/security.h" using namespace srslte; @@ -37,7 +37,7 @@ using namespace srslte; namespace srsepc{ hss* hss::m_instance = NULL; -boost::mutex hss_instance_mutex; +pthread_mutex_t hss_instance_mutex = PTHREAD_MUTEX_INITIALIZER; hss::hss() { @@ -52,22 +52,24 @@ hss::~hss() hss* hss::get_instance(void) -{ - boost::mutex::scoped_lock lock(hss_instance_mutex); +{ + pthread_mutex_lock(&hss_instance_mutex); if(NULL == m_instance) { m_instance = new hss(); } + pthread_mutex_unlock(&hss_instance_mutex); return(m_instance); } void hss::cleanup(void) { - boost::mutex::scoped_lock lock(hss_instance_mutex); + pthread_mutex_lock(&hss_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&hss_instance_mutex); } int @@ -563,7 +565,7 @@ hss::increment_sqn(uint64_t imsi) sqn++; - m_hss_log->debug("Incremented SQN (IMSI: %015lu) SQN: %d\n", imsi, sqn); + m_hss_log->debug("Incremented SQN (IMSI: %" PRIu64 ") SQN: %" PRIu64 "\n", imsi, sqn); for(int i = 0; i < 6; i++){ ue_ctx->sqn[i] = p[5-i]; diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 1736279c4..e2c006750 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -28,9 +28,9 @@ #include #include #include "srslte/common/bcd_helpers.h" -#include "mme/mme.h" -#include "hss/hss.h" -#include "spgw/spgw.h" +#include "srsepc/hdr/mme/mme.h" +#include "srsepc/hdr/hss/hss.h" +#include "srsepc/hdr/spgw/spgw.h" using namespace std; using namespace srsepc; @@ -52,7 +52,6 @@ typedef struct { int spgw_hex_limit; std::string hss_level; int hss_hex_limit; - std::string all_level; int all_hex_limit; std::string filename; @@ -84,6 +83,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { string mme_apn; string spgw_bind_addr; string sgi_if_addr; + string dns_addr; string hss_db_file; string hss_auth_algo; string log_filename; @@ -106,6 +106,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { ("mme.mcc", bpo::value(&mcc)->default_value("001"), "Mobile Country Code") ("mme.mnc", bpo::value(&mnc)->default_value("01"), "Mobile Network Code") ("mme.mme_bind_addr", bpo::value(&mme_bind_addr)->default_value("127.0.0.1"),"IP address of MME for S1 connnection") + ("mme.dns_addr", bpo::value(&dns_addr)->default_value("8.8.8.8"),"IP address of the DNS server for the UEs") ("mme.apn", bpo::value(&mme_apn)->default_value(""), "Set Access Point Name (APN) for data services") ("hss.db_file", bpo::value(&hss_db_file)->default_value("ue_db.csv"),".csv file that stores UE's keys") ("hss.auth_algo", bpo::value(&hss_auth_algo)->default_value("milenage"),"HSS uthentication algorithm.") @@ -206,6 +207,8 @@ parse_args(all_args_t *args, int argc, char* argv[]) { } args->mme_args.s1ap_args.mme_bind_addr = mme_bind_addr; + args->mme_args.s1ap_args.mme_name = mme_name; + args->mme_args.s1ap_args.dns_addr = dns_addr; args->mme_args.s1ap_args.mme_apn = mme_apn; args->spgw_args.gtpu_bind_addr = spgw_bind_addr; args->spgw_args.sgi_if_addr = sgi_if_addr; diff --git a/srsepc/src/mme/mme.cc b/srsepc/src/mme/mme.cc index eb247164c..1a385d8dc 100644 --- a/srsepc/src/mme/mme.cc +++ b/srsepc/src/mme/mme.cc @@ -29,13 +29,12 @@ #include #include #include -#include -#include "mme/mme.h" +#include "srsepc/hdr/mme/mme.h" namespace srsepc{ mme* mme::m_instance = NULL; -boost::mutex mme_instance_mutex; +pthread_mutex_t mme_instance_mutex = PTHREAD_MUTEX_INITIALIZER; mme::mme(): m_running(false) @@ -52,21 +51,23 @@ mme::~mme() mme* mme::get_instance(void) { - boost::mutex::scoped_lock lock(mme_instance_mutex); + pthread_mutex_lock(&mme_instance_mutex); if(NULL == m_instance) { m_instance = new mme(); } + pthread_mutex_unlock(&mme_instance_mutex); return(m_instance); } void mme::cleanup(void) { - boost::mutex::scoped_lock lock(mme_instance_mutex); + pthread_mutex_lock(&mme_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&mme_instance_mutex); } int diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 4e5d2ad7d..7c30bfa3b 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -25,15 +25,17 @@ */ #include +#include // for printing uint64_t #include "srslte/asn1/gtpc.h" -#include "mme/mme_gtpc.h" -#include "mme/s1ap.h" -#include "spgw/spgw.h" +#include "srsepc/hdr/mme/mme_gtpc.h" +#include "srsepc/hdr/mme/s1ap.h" +#include "srsepc/hdr/spgw/spgw.h" namespace srsepc{ mme_gtpc* mme_gtpc::m_instance = NULL; -boost::mutex mme_gtpc_instance_mutex; +pthread_mutex_t mme_gtpc_instance_mutex = PTHREAD_MUTEX_INITIALIZER; + mme_gtpc::mme_gtpc() { @@ -46,21 +48,23 @@ mme_gtpc::~mme_gtpc() mme_gtpc* mme_gtpc::get_instance(void) { - boost::mutex::scoped_lock lock(mme_gtpc_instance_mutex); + pthread_mutex_lock(&mme_gtpc_instance_mutex); if(NULL == m_instance) { m_instance = new mme_gtpc(); } + pthread_mutex_unlock(&mme_gtpc_instance_mutex); return(m_instance); } void mme_gtpc::cleanup(void) { - boost::mutex::scoped_lock lock(mme_gtpc_instance_mutex); + pthread_mutex_lock(&mme_gtpc_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&mme_gtpc_instance_mutex); } @@ -88,7 +92,7 @@ mme_gtpc::get_new_ctrl_teid() return m_next_ctrl_teid++; //FIXME Use a Id pool? } void -mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id) +mme_gtpc::send_create_session_request(uint64_t imsi) { m_mme_gtpc_log->info("Sending Create Session Request.\n"); m_mme_gtpc_log->console("Sending Create Session Request.\n"); @@ -96,7 +100,6 @@ mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id) struct srslte::gtpc_create_session_request *cs_req = &cs_req_pdu.choice.create_session_request; struct srslte::gtpc_pdu cs_resp_pdu; - //Initialize GTP-C message to zero bzero(&cs_req_pdu, sizeof(struct srslte::gtpc_pdu)); @@ -113,21 +116,47 @@ mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id) cs_req->sender_f_teid.teid = get_new_ctrl_teid(); cs_req->sender_f_teid.ipv4 = m_mme_gtpc_ip; - m_mme_gtpc_log->info("Next control TEID: %lu \n", m_next_ctrl_teid); - m_mme_gtpc_log->info("Allocated control TEID: %lu \n", cs_req->sender_f_teid.teid); - m_mme_gtpc_log->console("Creating Session Response -- IMSI: %015lu \n", imsi); - m_mme_gtpc_log->console("Creating Session Response -- MME control TEID: %lu \n", cs_req->sender_f_teid.teid); + m_mme_gtpc_log->info("Next MME control TEID: %d\n", m_next_ctrl_teid); + m_mme_gtpc_log->info("Allocated MME control TEID: %d\n", cs_req->sender_f_teid.teid); + m_mme_gtpc_log->console("Creating Session Response -- IMSI: %" PRIu64 "\n", imsi); + m_mme_gtpc_log->console("Creating Session Response -- MME control TEID: %d\n", cs_req->sender_f_teid.teid); + // APN strncpy(cs_req->apn, m_s1ap->m_s1ap_args.mme_apn.c_str(), sizeof(cs_req->apn)-1); cs_req->apn[sizeof(cs_req->apn)-1] = 0; // RAT Type //cs_req->rat_type = srslte::GTPC_RAT_TYPE::EUTRAN; - //Save RX Control TEID - m_teid_to_mme_s1ap_id.insert(std::pair(cs_req->sender_f_teid.teid, mme_ue_s1ap_id)); + //Check whether this UE is already registed + std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); + if(it != m_imsi_to_gtpc_ctx.end()) + { + m_mme_gtpc_log->warning("Create Session Request being called for an UE with an active GTP-C connection.\n"); + m_mme_gtpc_log->warning("Deleting previous GTP-C connection.\n"); + std::map::iterator jt = m_mme_ctr_teid_to_imsi.find(it->second.mme_ctr_fteid.teid); + if(jt == m_mme_ctr_teid_to_imsi.end()) + { + m_mme_gtpc_log->error("Could not find IMSI from MME Ctrl TEID. MME Ctr TEID: %d\n", it->second.mme_ctr_fteid.teid); + } + else + { + m_mme_ctr_teid_to_imsi.erase(jt); + } + m_imsi_to_gtpc_ctx.erase(it); + //No need to send delete session request to the SPGW. + //The create session request will be interpreted as a new request and SPGW will delete locally in existing context. + } + //Save RX Control TEID + m_mme_ctr_teid_to_imsi.insert(std::pair(cs_req->sender_f_teid.teid, imsi)); + + //Save GTP-C context + gtpc_ctx_t gtpc_ctx; + bzero(>pc_ctx,sizeof(gtpc_ctx_t)); + gtpc_ctx.mme_ctr_fteid = cs_req->sender_f_teid; + m_imsi_to_gtpc_ctx.insert(std::pair(imsi,gtpc_ctx)); m_spgw->handle_create_session_request(cs_req, &cs_resp_pdu); - + } void @@ -139,7 +168,7 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) if (cs_resp_pdu->header.type != srslte::GTPC_MSG_TYPE_CREATE_SESSION_RESPONSE) { m_mme_gtpc_log->warning("Could not create GTPC session. Not a create session response\n"); - //TODO Handle err + //TODO Handle error return; } if (cs_resp->cause.cause_value != srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED){ @@ -147,41 +176,100 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) //TODO Handle error return; } - - //Get MME_UE_S1AP_ID from the control TEID - std::map::iterator id_it = m_teid_to_mme_s1ap_id.find(cs_resp_pdu->header.teid); - if(id_it == m_teid_to_mme_s1ap_id.end()) + + //Get IMSI from the control TEID + std::map::iterator id_it = m_mme_ctr_teid_to_imsi.find(cs_resp_pdu->header.teid); + if(id_it == m_mme_ctr_teid_to_imsi.end()) { - //Could not find MME UE S1AP TEID - m_mme_gtpc_log->warning("Could not find MME UE S1AP TEID.\n"); + m_mme_gtpc_log->warning("Could not find IMSI from Ctrl TEID.\n"); return; } - uint32_t mme_s1ap_id = id_it->second; + uint64_t imsi = id_it->second; + + m_mme_gtpc_log->info("MME GTPC Ctrl TEID %" PRIu64 ", IMSI %" PRIu64 "\n", cs_resp_pdu->header.teid, imsi); //Get S-GW Control F-TEID - srslte::gtpc_f_teid_ie sgw_ctrl_fteid; - sgw_ctrl_fteid.teid = cs_resp_pdu->header.teid; - sgw_ctrl_fteid.ipv4 = 0; //FIXME This is not used for now. In the future it will be obtained from the socket addr_info + srslte::gtp_fteid_t sgw_ctr_fteid; + sgw_ctr_fteid.teid = cs_resp_pdu->header.teid; + sgw_ctr_fteid.ipv4 = 0; //FIXME This is not used for now. In the future it will be obtained from the socket addr_info - m_mme_gtpc_log->console("Create Session Response -- SPGW control TEID %d\n", sgw_ctrl_fteid.teid); + //Get S-GW S1-u F-TEID + if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){ + m_mme_gtpc_log->error("Did not receive SGW S1-U F-TEID in create session response\n"); + return; + } + m_mme_gtpc_log->console("Create Session Response -- SPGW control TEID %d\n", sgw_ctr_fteid.teid); + m_mme_gtpc_log->info("Create Session Response -- SPGW control TEID %d\n", sgw_ctr_fteid.teid); in_addr s1u_addr; s1u_addr.s_addr = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4; m_mme_gtpc_log->console("Create Session Response -- SPGW S1-U Address: %s\n", inet_ntoa(s1u_addr)); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(mme_s1ap_id, cs_resp, sgw_ctrl_fteid); + m_mme_gtpc_log->info("Create Session Response -- SPGW S1-U Address: %s\n", inet_ntoa(s1u_addr)); + + //Check UE Ipv4 address was allocated + if(cs_resp->paa_present != true) + { + m_mme_gtpc_log->error("PDN Adress Allocation not present\n"); + return; + } + if(cs_resp->paa.pdn_type != srslte::GTPC_PDN_TYPE_IPV4) + { + m_mme_gtpc_log->error("IPv6 not supported yet\n"); + return; + } + + //Save create session response info to E-RAB context + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(imsi); + if(ue_ctx == NULL){ + m_mme_gtpc_log->error("Could not find UE context. IMSI %015lu\n", imsi); + return; + } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + //Save UE IP to nas ctxt + emm_ctx->ue_ip.s_addr = cs_resp->paa.ipv4; + m_mme_gtpc_log->console("SPGW Allocated IP %s to ISMI %015lu\n",inet_ntoa(emm_ctx->ue_ip),emm_ctx->imsi); + //Save SGW ctrl F-TEID in GTP-C context + std::map::iterator it_g = m_imsi_to_gtpc_ctx.find(imsi); + if(it_g == m_imsi_to_gtpc_ctx.end()) + { + //Could not find GTP-C Context + m_mme_gtpc_log->error("Could not find GTP-C context\n"); + return; + } + gtpc_ctx_t *gtpc_ctx = &it_g->second; + gtpc_ctx->sgw_ctr_fteid = sgw_ctr_fteid; + + //Set EPS bearer context + //FIXME default EPS bearer is hard-coded + int default_bearer=5; + erab_ctx_t *erab_ctx = &ecm_ctx->erabs_ctx[default_bearer]; + erab_ctx->pdn_addr_alloc= cs_resp->paa; + erab_ctx->sgw_s1u_fteid = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid; + + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, erab_ctx); + return; } void -mme_gtpc::send_modify_bearer_request(erab_ctx_t *erab_ctx) +mme_gtpc::send_modify_bearer_request(uint64_t imsi, erab_ctx_t *erab_ctx) { m_mme_gtpc_log->info("Sending GTP-C Modify bearer request\n"); srslte::gtpc_pdu mb_req_pdu; - srslte::gtpc_f_teid_ie *enb_fteid = &erab_ctx->enb_fteid; - srslte::gtpc_f_teid_ie *sgw_ctrl_fteid = &erab_ctx->sgw_ctrl_fteid; + srslte::gtp_fteid_t *enb_fteid = &erab_ctx->enb_fteid; + + std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); + if(it == m_imsi_to_gtpc_ctx.end()) + { + m_mme_gtpc_log->error("Modify bearer request for UE without GTP-C connection\n"); + return; + } + srslte::gtp_fteid_t sgw_ctr_fteid = it->second.sgw_ctr_fteid; srslte::gtpc_header *header = &mb_req_pdu.header; header->teid_present = true; - header->teid = sgw_ctrl_fteid->teid; + header->teid = sgw_ctr_fteid.teid; header->type = srslte::GTPC_MSG_TYPE_MODIFY_BEARER_REQUEST; srslte::gtpc_modify_bearer_request *mb_req = &mb_req_pdu.choice.modify_bearer_request; @@ -189,7 +277,7 @@ mme_gtpc::send_modify_bearer_request(erab_ctx_t *erab_ctx) mb_req->eps_bearer_context_to_modify.s1_u_enb_f_teid.ipv4 = enb_fteid->ipv4; mb_req->eps_bearer_context_to_modify.s1_u_enb_f_teid.teid = enb_fteid->teid; - m_mme_gtpc_log->info("GTP-C Modify bearer request -- S-GW Control TEID %d\n", sgw_ctrl_fteid->teid ); + m_mme_gtpc_log->info("GTP-C Modify bearer request -- S-GW Control TEID %d\n", sgw_ctr_fteid.teid ); struct in_addr addr; addr.s_addr = enb_fteid->ipv4; m_mme_gtpc_log->info("GTP-C Modify bearer request -- S1-U TEID 0x%x, IP %s\n", enb_fteid->teid, inet_ntoa(addr) ); @@ -205,54 +293,93 @@ void mme_gtpc::handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu) { uint32_t mme_ctrl_teid = mb_resp_pdu->header.teid; - std::map::iterator mme_s1ap_id_it = m_teid_to_mme_s1ap_id.find(mme_ctrl_teid); - if(mme_s1ap_id_it == m_teid_to_mme_s1ap_id.end()) + std::map::iterator imsi_it = m_mme_ctr_teid_to_imsi.find(mme_ctrl_teid); + if(imsi_it == m_mme_ctr_teid_to_imsi.end()) { - m_mme_gtpc_log->error("Could not find MME S1AP Id from control TEID\n"); + m_mme_gtpc_log->error("Could not find IMSI from control TEID\n"); return; } uint8_t ebi = mb_resp_pdu->choice.modify_bearer_response.eps_bearer_context_modified.ebi; m_mme_gtpc_log->debug("Activating EPS bearer with id %d\n", ebi); - m_s1ap->activate_eps_bearer(mme_s1ap_id_it->second,ebi); + m_s1ap->activate_eps_bearer(imsi_it->second,ebi); return; } void -mme_gtpc::send_delete_session_request(ue_ctx_t *ue_ctx) +mme_gtpc::send_delete_session_request(uint64_t imsi) { - m_mme_gtpc_log->info("Sending GTP-C Delete Session Request request\n"); + m_mme_gtpc_log->info("Sending GTP-C Delete Session Request request. IMSI %" PRIu64 "\n",imsi); srslte::gtpc_pdu del_req_pdu; - srslte::gtpc_f_teid_ie *sgw_ctrl_fteid = NULL; - - //FIXME the UE control TEID sould be stored in the UE ctxt, not in the E-RAB ctxt - //Maybe a mme_s1ap_id to ctrl teid map as well? - - for(int i = 0; i::iterator it_ctx = m_imsi_to_gtpc_ctx.find(imsi); + if(it_ctx == m_imsi_to_gtpc_ctx.end()) { - if(ue_ctx->erabs_ctx[i].state != ERAB_DEACTIVATED) - { - sgw_ctrl_fteid = &ue_ctx->erabs_ctx[i].sgw_ctrl_fteid; - break; - } + m_mme_gtpc_log->error("Could not find GTP-C context to remove\n"); + return; } - //FIXME: add proper error handling - assert(sgw_ctrl_fteid != NULL); - + sgw_ctr_fteid = it_ctx->second.sgw_ctr_fteid; + mme_ctr_fteid = it_ctx->second.mme_ctr_fteid; srslte::gtpc_header *header = &del_req_pdu.header; header->teid_present = true; - header->teid = sgw_ctrl_fteid->teid; + header->teid = sgw_ctr_fteid.teid; header->type = srslte::GTPC_MSG_TYPE_DELETE_SESSION_REQUEST; srslte::gtpc_delete_session_request *del_req = &del_req_pdu.choice.delete_session_request; del_req->cause.cause_value = srslte::GTPC_CAUSE_VALUE_ISR_DEACTIVATION; - m_mme_gtpc_log->info("GTP-C Delete Session Request -- S-GW Control TEID %d\n", sgw_ctrl_fteid->teid ); + m_mme_gtpc_log->info("GTP-C Delete Session Request -- S-GW Control TEID %d\n", sgw_ctr_fteid.teid ); srslte::gtpc_pdu del_resp_pdu; m_spgw->handle_delete_session_request(&del_req_pdu, &del_resp_pdu); //TODO Handle delete session response + + //Delete GTP-C context + std::map::iterator it_imsi = m_mme_ctr_teid_to_imsi.find(mme_ctr_fteid.teid); + if(it_imsi == m_mme_ctr_teid_to_imsi.end()) + { + m_mme_gtpc_log->error("Could not find IMSI from MME ctr TEID"); + } + else + { + m_mme_ctr_teid_to_imsi.erase(it_imsi); + } + m_imsi_to_gtpc_ctx.erase(it_ctx); + return; +} + +void +mme_gtpc::send_release_access_bearers_request(uint64_t imsi) +{ + m_mme_gtpc_log->info("Sending GTP-C Delete Access Bearers Request\n"); + srslte::gtpc_pdu rel_req_pdu; + srslte::gtp_fteid_t sgw_ctr_fteid; + + //Get S-GW Ctr TEID + std::map::iterator it_ctx = m_imsi_to_gtpc_ctx.find(imsi); + if(it_ctx == m_imsi_to_gtpc_ctx.end()) + { + m_mme_gtpc_log->error("Could not find GTP-C context to remove\n"); + return; + } + sgw_ctr_fteid = it_ctx->second.sgw_ctr_fteid; + + //Set GTP-C header + srslte::gtpc_header *header = &rel_req_pdu.header; + header->teid_present = true; + header->teid = sgw_ctr_fteid.teid; + header->type = srslte::GTPC_MSG_TYPE_RELEASE_ACCESS_BEARERS_REQUEST; + + srslte::gtpc_release_access_bearers_request *rel_req = &rel_req_pdu.choice.release_access_bearers_request; + m_mme_gtpc_log->info("GTP-C Release Access Berarers Request -- S-GW Control TEID %d\n", sgw_ctr_fteid.teid ); + + srslte::gtpc_pdu rel_resp_pdu; + m_spgw->handle_release_access_bearers_request(&rel_req_pdu, &rel_resp_pdu); + + //The GTP-C connection will not be torn down, just the user plane bearers. return; } } //namespace srsepc diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 80d8b6d74..ccd2536c1 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -26,15 +26,16 @@ #include #include +#include // for printing uint64_t #include "srslte/common/bcd_helpers.h" -#include "mme/s1ap.h" +#include "srsepc/hdr/mme/s1ap.h" #include "srslte/asn1/gtpc.h" #include "srslte/common/liblte_security.h" namespace srsepc{ s1ap* s1ap::m_instance = NULL; -boost::mutex s1ap_instance_mutex; +pthread_mutex_t s1ap_instance_mutex = PTHREAD_MUTEX_INITIALIZER; s1ap::s1ap(): m_s1mme(-1), @@ -51,21 +52,24 @@ s1ap::~s1ap() s1ap* s1ap::get_instance(void) { - boost::mutex::scoped_lock lock(s1ap_instance_mutex); - if(NULL == m_instance) { + + pthread_mutex_lock(&s1ap_instance_mutex); + if(m_instance == NULL) { m_instance = new s1ap(); } + pthread_mutex_unlock(&s1ap_instance_mutex); return(m_instance); } void s1ap::cleanup(void) { - boost::mutex::scoped_lock lock(s1ap_instance_mutex); + pthread_mutex_lock(&s1ap_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&s1ap_instance_mutex); } int @@ -83,17 +87,15 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log, hss_interface_s1 m_hss = hss_; //Init message handlers - m_s1ap_mngmt_proc = s1ap_mngmt_proc::get_instance(); //Managment procedures + m_s1ap_mngmt_proc = s1ap_mngmt_proc::get_instance(); //Managment procedures m_s1ap_mngmt_proc->init(); - m_s1ap_nas_transport = s1ap_nas_transport::get_instance(); //NAS Transport procedures + m_s1ap_nas_transport = s1ap_nas_transport::get_instance(); //NAS Transport procedures m_s1ap_nas_transport->init(m_hss); m_s1ap_ctx_mngmt_proc = s1ap_ctx_mngmt_proc::get_instance(); //Context Management Procedures m_s1ap_ctx_mngmt_proc->init(); - //Get pointer to GTP-C class m_mme_gtpc = mme_gtpc::get_instance(); - //Initialize S1-MME m_s1mme = enb_listen(); @@ -107,16 +109,23 @@ s1ap::stop() if (m_s1mme != -1){ close(m_s1mme); } - std::map::iterator it = m_active_enbs.begin(); - while(it!=m_active_enbs.end()) + std::map::iterator enb_it = m_active_enbs.begin(); + while(enb_it!=m_active_enbs.end()) { - m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", it->second->enb_id); - m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", it->second->enb_id); - delete_ues_in_enb(it->second->enb_id); - delete it->second; - m_active_enbs.erase(it++); + m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", enb_it->second->enb_id); + m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_it->second->enb_id); + delete enb_it->second; + m_active_enbs.erase(enb_it++); } + std::map::iterator ue_it = m_imsi_to_ue_ctx.begin(); + while(ue_it!=m_imsi_to_ue_ctx.end()) + { + m_s1ap_log->info("Deleting UE EMM context. IMSI: %015lu\n", ue_it->first); + m_s1ap_log->console("Deleting UE EMM context. IMSI: %015lu\n", ue_it->first); + delete ue_it->second; + m_imsi_to_ue_ctx.erase(ue_it++); + } //Cleanup message handlers s1ap_mngmt_proc::cleanup(); s1ap_nas_transport::cleanup(); @@ -124,56 +133,19 @@ s1ap::stop() return; } -void -s1ap::delete_enb_ctx(int32_t assoc_id) -{ - std::map::iterator it_assoc = m_sctp_to_enb_id.find(assoc_id); - uint16_t enb_id = it_assoc->second; - - std::map::iterator it_ctx = m_active_enbs.find(enb_id); - if(it_ctx == m_active_enbs.end() || it_assoc == m_sctp_to_enb_id.end()) - { - m_s1ap_log->error("Could not find eNB to delete. Association: %d\n",assoc_id); - return; - } - - m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", enb_id); - m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_id); - - //Delete connected UEs ctx - delete_ues_in_enb(enb_id); - - //Delete eNB - delete it_ctx->second; - m_active_enbs.erase(it_ctx); - m_sctp_to_enb_id.erase(it_assoc); - return; -} - -void -s1ap::delete_ues_in_enb(uint16_t enb_id) -{ - //delete UEs ctx - std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); - std::set::iterator ue_id = ues_in_enb->second.begin(); - while(ue_id != ues_in_enb->second.end() ) - { - std::map::iterator ue_ctx = m_active_ues.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - delete ue_ctx->second; //delete UE context - m_active_ues.erase(ue_ctx); //remove from general MME map - ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set - } - -} - int s1ap::get_s1_mme() { return m_s1mme; } +uint32_t +s1ap::get_next_mme_ue_s1ap_id() +{ + return m_next_mme_ue_s1ap_id++; +} + + int s1ap::enb_listen() { @@ -258,7 +230,7 @@ s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb } -bool +bool s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri) { bool reply_flag = false; @@ -282,7 +254,8 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru m_s1ap_ctx_mngmt_proc->handle_ue_context_release_request(&msg->choice.UEContextReleaseRequest, enb_sri, reply_buffer, &reply_flag); break; default: - m_s1ap_log->error("Unhandled intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); + m_s1ap_log->error("Unhandled S1AP intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); + m_s1ap_log->console("Unhandled S1APintiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); } //Send Reply to eNB if(reply_flag == true) @@ -290,7 +263,8 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru ssize_t n_sent = sctp_send(m_s1mme,reply_buffer->msg, reply_buffer->N_bytes, enb_sri, 0); if(n_sent == -1) { - m_s1ap_log->console("Failed to send S1 Setup Setup Reply\n"); + m_s1ap_log->console("Failed to send S1AP Initiating Reply.\n"); + m_s1ap_log->error("Failed to send S1AP Initiating Reply. \n"); m_pool->deallocate(reply_buffer); return false; } @@ -306,46 +280,28 @@ s1ap::handle_successful_outcome(LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *msg) case LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_INITIALCONTEXTSETUPRESPONSE: m_s1ap_log->info("Received Initial Context Setup Response.\n"); return m_s1ap_ctx_mngmt_proc->handle_initial_context_setup_response(&msg->choice.InitialContextSetupResponse); + case LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_UECONTEXTRELEASECOMPLETE: + m_s1ap_log->info("Received UE Context Release Complete\n"); + return m_s1ap_ctx_mngmt_proc->handle_ue_context_release_complete(&msg->choice.UEContextReleaseComplete); default: m_s1ap_log->error("Unhandled successful outcome message: %s\n", liblte_s1ap_successfuloutcome_choice_text[msg->choice_type]); } return true; } - -bool -s1ap::delete_ue_ctx(ue_ctx_t *ue_ctx) +//eNB Context Managment +void +s1ap::add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo *enb_sri) { - uint32_t mme_ue_s1ap_id = ue_ctx->mme_ue_s1ap_id; - std::map::iterator ue_ctx_it = m_active_ues.find(mme_ue_s1ap_id); - if(ue_ctx_it == m_active_ues.end() ) - { - m_s1ap_log->info("UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); - return false; - } + m_s1ap_log->info("Adding new eNB context. eNB ID %d\n", enb_ctx.enb_id); + std::set ue_set; + enb_ctx_t *enb_ptr = new enb_ctx_t; + memcpy(enb_ptr,&enb_ctx,sizeof(enb_ctx_t)); + m_active_enbs.insert(std::pair(enb_ptr->enb_id,enb_ptr)); + m_sctp_to_enb_id.insert(std::pair(enb_sri->sinfo_assoc_id, enb_ptr->enb_id)); + m_enb_id_to_ue_ids.insert(std::pair >(enb_ptr->enb_id,ue_set)); - //Delete UE within eNB UE set - std::map::iterator it = m_sctp_to_enb_id.find(ue_ctx->enb_sri.sinfo_assoc_id); - if(it == m_sctp_to_enb_id.end() ) - { - m_s1ap_log->error("Could not find eNB for this request.\n"); - return false; - } - uint16_t enb_id = it->second; - std::map >::iterator ue_set = m_enb_id_to_ue_ids.find(enb_id); - if(ue_set == m_enb_id_to_ue_ids.end()) - { - m_s1ap_log->error("Could not find the eNB's UEs.\n"); - return false; - } - ue_set->second.erase(mme_ue_s1ap_id); - - //Delete UE context - delete ue_ctx; - m_active_ues.erase(ue_ctx_it); - m_s1ap_log->info("Deleted UE Context.\n"); - - return true; + return; } enb_ctx_t* @@ -363,26 +319,105 @@ s1ap::find_enb_ctx(uint16_t enb_id) } void -s1ap::add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo *enb_sri) +s1ap::delete_enb_ctx(int32_t assoc_id) { - m_s1ap_log->info("Adding new eNB context. eNB ID %d\n", enb_ctx.enb_id); - std::set ue_set; - enb_ctx_t *enb_ptr = new enb_ctx_t; - memcpy(enb_ptr,&enb_ctx,sizeof(enb_ctx_t)); - m_active_enbs.insert(std::pair(enb_ptr->enb_id,enb_ptr)); - m_sctp_to_enb_id.insert(std::pair(enb_sri->sinfo_assoc_id, enb_ptr->enb_id)); - m_enb_id_to_ue_ids.insert(std::pair >(enb_ptr->enb_id,ue_set)); + std::map::iterator it_assoc = m_sctp_to_enb_id.find(assoc_id); + uint16_t enb_id = it_assoc->second; + std::map::iterator it_ctx = m_active_enbs.find(enb_id); + if(it_ctx == m_active_enbs.end() || it_assoc == m_sctp_to_enb_id.end()) + { + m_s1ap_log->error("Could not find eNB to delete. Association: %d\n",assoc_id); + return; + } + + m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", enb_id); + m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_id); + + //Delete connected UEs ctx + release_ues_ecm_ctx_in_enb(enb_id); + + //Delete eNB + delete it_ctx->second; + m_active_enbs.erase(it_ctx); + m_sctp_to_enb_id.erase(it_assoc); return; } -ue_ctx_t* -s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) + +//UE Context Management +bool +s1ap::add_ue_ctx_to_imsi_map(ue_ctx_t *ue_ctx) { - std::map::iterator it = m_active_ues.find(mme_ue_s1ap_id); - if(it == m_active_ues.end()) + std::map::iterator ctx_it = m_imsi_to_ue_ctx.find(ue_ctx->emm_ctx.imsi); + if(ctx_it != m_imsi_to_ue_ctx.end()) + { + m_s1ap_log->error("UE Context already exists. IMSI %015lu",ue_ctx->emm_ctx.imsi); + return false; + } + if(ue_ctx->ecm_ctx.mme_ue_s1ap_id != 0) + { + std::map::iterator ctx_it2 = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + if(ctx_it2 != m_mme_ue_s1ap_id_to_ue_ctx.end() && ctx_it2->second != ue_ctx) { - return NULL; + m_s1ap_log->error("Context identified with IMSI does not match context identified by MME UE S1AP Id.\n"); + return false; + } + } + m_imsi_to_ue_ctx.insert(std::pair(ue_ctx->emm_ctx.imsi, ue_ctx)); + m_s1ap_log->debug("Saved UE context corresponding to IMSI %015lu\n",ue_ctx->emm_ctx.imsi); + return true; +} + +bool +s1ap::add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx_t *ue_ctx) +{ + if(ue_ctx->ecm_ctx.mme_ue_s1ap_id == 0) + { + m_s1ap_log->error("Could not add UE context to MME UE S1AP map. MME UE S1AP ID 0 is not valid."); + return false; + } + std::map::iterator ctx_it = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + if(ctx_it != m_mme_ue_s1ap_id_to_ue_ctx.end()) + { + m_s1ap_log->error("UE Context already exists. MME UE S1AP Id %015lu",ue_ctx->emm_ctx.imsi); + return false; + } + if(ue_ctx->ecm_ctx.imsi != 0) + { + std::map::iterator ctx_it2 = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + if(ctx_it2 != m_mme_ue_s1ap_id_to_ue_ctx.end() && ctx_it2->second != ue_ctx) + { + m_s1ap_log->error("Context identified with MME UE S1AP Id does not match context identified by IMSI.\n"); + return false; + } + } + m_mme_ue_s1ap_id_to_ue_ctx.insert(std::pair(ue_ctx->ecm_ctx.mme_ue_s1ap_id, ue_ctx)); + m_s1ap_log->debug("Saved UE context corresponding to MME UE S1AP Id %d\n",ue_ctx->ecm_ctx.mme_ue_s1ap_id); + return true; +} + +ue_ctx_t* +s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) +{ + std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ctx.find(mme_ue_s1ap_id); + if(it == m_mme_ue_s1ap_id_to_ue_ctx.end()) + { + return NULL; + } + else + { + return it->second; + } +} + +ue_ctx_t* +s1ap::find_ue_ctx_from_imsi(uint64_t imsi) +{ + std::map::iterator it = m_imsi_to_ue_ctx.find(imsi); + if(it == m_imsi_to_ue_ctx.end()) + { + return NULL; } else { @@ -391,58 +426,128 @@ s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) } void -s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) +s1ap::release_ues_ecm_ctx_in_enb(uint16_t enb_id) { - ue_ctx_t *ue_ptr = new ue_ctx_t; - memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); - m_active_ues.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); - - std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); - uint16_t enb_id = it_enb->second; - std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); - if(it_ue_id==m_enb_id_to_ue_ids.end()) + //delete UEs ctx + std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); + std::set::iterator ue_id = ues_in_enb->second.begin(); + while(ue_id != ues_in_enb->second.end() ) { - m_s1ap_log->error("Could not find eNB's UEs\n"); - return; + std::map::iterator ue_ctx = m_mme_ue_s1ap_id_to_ue_ctx.find(*ue_id); + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->second->ecm_ctx; + m_s1ap_log->info("Releasing UE ECM context. UE-MME S1AP Id: %d\n", ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->console("Releasing UE ECM context. UE-MME S1AP Id: %d\n", ecm_ctx->mme_ue_s1ap_id); + ues_in_enb->second.erase(ecm_ctx->mme_ue_s1ap_id); + ecm_ctx->state = ECM_STATE_IDLE; + ecm_ctx->mme_ue_s1ap_id = 0; + ecm_ctx->enb_ue_s1ap_id = 0; } - it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); - return; } -uint32_t -s1ap::get_next_mme_ue_s1ap_id() +bool +s1ap::release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) { - return m_next_mme_ue_s1ap_id++; + ue_ctx_t *ue_ctx = find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ctx == NULL) + { + m_s1ap_log->error("Cannot release UE ECM context, UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + return false; + } + ue_ecm_ctx_t* ecm_ctx = &ue_ctx->ecm_ctx; + + //Delete UE within eNB UE set + std::map::iterator it = m_sctp_to_enb_id.find(ecm_ctx->enb_sri.sinfo_assoc_id); + if(it == m_sctp_to_enb_id.end() ) + { + m_s1ap_log->error("Could not find eNB for UE release request.\n"); + return false; + } + uint16_t enb_id = it->second; + std::map >::iterator ue_set = m_enb_id_to_ue_ids.find(enb_id); + if(ue_set == m_enb_id_to_ue_ids.end()) + { + m_s1ap_log->error("Could not find the eNB's UEs.\n"); + return false; + } + ue_set->second.erase(mme_ue_s1ap_id); + + //Release UE ECM context + m_mme_ue_s1ap_id_to_ue_ctx.erase(mme_ue_s1ap_id); + ecm_ctx->state = ECM_STATE_IDLE; + ecm_ctx->mme_ue_s1ap_id = 0; + ecm_ctx->enb_ue_s1ap_id = 0; + + m_s1ap_log->info("Released UE ECM Context.\n"); + return true; } +bool +s1ap::delete_ue_ctx(uint64_t imsi) +{ + ue_ctx_t *ue_ctx = find_ue_ctx_from_imsi(imsi); + if(ue_ctx == NULL) + { + m_s1ap_log->info("Cannot delete UE context, UE not found. IMSI: %" PRIu64 "\n", imsi); + return false; + } + + //Make sure to release ECM ctx + if(ue_ctx->ecm_ctx.mme_ue_s1ap_id != 0) + { + release_ue_ecm_ctx(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + } + + //Delete UE context + m_imsi_to_ue_ctx.erase(imsi); + delete ue_ctx; + m_s1ap_log->info("Deleted UE Context.\n"); + return true; +} + + + + +//UE Bearer Managment void -s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi) +s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) { - std::map::iterator ue_ctx_it = m_active_ues.find(mme_s1ap_id); - if(ue_ctx_it == m_active_ues.end()) + std::map::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); + if(ue_ctx_it == m_imsi_to_ue_ctx.end()) { - m_s1ap_log->error("Could not find UE context\n"); - return; + m_s1ap_log->error("Could not activate EPS bearer: Could not find UE context\n"); + return; } - ue_ctx_t * ue_ctx = ue_ctx_it->second; - if (ue_ctx->erabs_ctx[ebi].state != ERAB_CTX_SETUP) + //Make sure NAS is active + uint32_t mme_ue_s1ap_id = ue_ctx_it->second->ecm_ctx.mme_ue_s1ap_id; + std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ctx.find(mme_ue_s1ap_id); + if(it == m_mme_ue_s1ap_id_to_ue_ctx.end()) { - m_s1ap_log->error("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d, state %d\n",mme_s1ap_id,ebi,ue_ctx->erabs_ctx[ebi].state); - m_s1ap_log->console("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d\n",mme_s1ap_id,ebi,ue_ctx->erabs_ctx[ebi].state); + m_s1ap_log->error("Could not activate EPS bearer: ECM context seems to be missing\n"); return; } - ue_ctx->erabs_ctx[ebi].state = ERAB_ACTIVE; - m_s1ap_log->info("Activated EPS Bearer\n"); + ue_ecm_ctx_t * ecm_ctx = &ue_ctx_it->second->ecm_ctx; + if (ecm_ctx->erabs_ctx[ebi].state != ERAB_CTX_SETUP) + { + m_s1ap_log->error("Could not be activate EPS Bearer, bearer in wrong state: MME S1AP Id %d, EPS Bearer id %d, state %d\n", mme_ue_s1ap_id, ebi, ecm_ctx->erabs_ctx[ebi].state); + m_s1ap_log->console("Could not be activate EPS Bearer, bearer in wrong state: MME S1AP Id %d, EPS Bearer id %d, state %d\n", mme_ue_s1ap_id, ebi, ecm_ctx->erabs_ctx[ebi].state); + return; + } + + ecm_ctx->erabs_ctx[ebi].state = ERAB_ACTIVE; + ecm_ctx->state = ECM_STATE_CONNECTED; + m_s1ap_log->info("Activated EPS Bearer: Bearer id %d\n",ebi); return; } uint32_t -s1ap::allocate_m_tmsi(uint32_t mme_ue_s1ap_id) +s1ap::allocate_m_tmsi(uint64_t imsi) { - //uint32_t m_tmsi = m_next_m_tmsi++; - //m_tmsi_to_s1ap_id.insert(std::pair(m_tmsi,mme_ue_s1ap_id)); - uint32_t m_tmsi = 0x0123; + uint32_t m_tmsi = m_next_m_tmsi; + m_next_m_tmsi = (m_next_m_tmsi + 1) % UINT32_MAX; + + m_tmsi_to_imsi.insert(std::pair(m_tmsi,imsi)); + m_s1ap_log->debug("Allocated M-TMSI 0x%x to IMSI %015lu,\n",m_tmsi,imsi); return m_tmsi; } @@ -478,3 +583,4 @@ s1ap::print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx) } } //namespace srsepc + diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 7dffe3c35..5500fa561 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -26,15 +26,15 @@ //#include "srslte/upper/s1ap_common.h" #include "srslte/common/bcd_helpers.h" -#include "mme/s1ap.h" -#include "mme/s1ap_ctx_mngmt_proc.h" +#include "srsepc/hdr/mme/s1ap.h" +#include "srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h" #include "srslte/common/liblte_security.h" namespace srsepc{ s1ap_ctx_mngmt_proc* s1ap_ctx_mngmt_proc::m_instance = NULL; -boost::mutex s1ap_ctx_mngmt_proc_instance_mutex; +pthread_mutex_t s1ap_ctx_mngmt_proc_instance_mutex = PTHREAD_MUTEX_INITIALIZER; s1ap_ctx_mngmt_proc::s1ap_ctx_mngmt_proc() @@ -48,21 +48,23 @@ s1ap_ctx_mngmt_proc::~s1ap_ctx_mngmt_proc() s1ap_ctx_mngmt_proc* s1ap_ctx_mngmt_proc::get_instance(void) { - boost::mutex::scoped_lock lock(s1ap_ctx_mngmt_proc_instance_mutex); + pthread_mutex_lock(&s1ap_ctx_mngmt_proc_instance_mutex); if(NULL == m_instance) { m_instance = new s1ap_ctx_mngmt_proc(); } + pthread_mutex_unlock(&s1ap_ctx_mngmt_proc_instance_mutex); return(m_instance); } void s1ap_ctx_mngmt_proc::cleanup(void) { - boost::mutex::scoped_lock lock(s1ap_ctx_mngmt_proc_instance_mutex); + pthread_mutex_lock(&s1ap_ctx_mngmt_proc_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&s1ap_ctx_mngmt_proc_instance_mutex); } void @@ -77,8 +79,11 @@ s1ap_ctx_mngmt_proc::init(void) } bool -s1ap_ctx_mngmt_proc::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) +s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, + ue_ecm_ctx_t *ecm_ctx, + erab_ctx_t *erab_ctx) { + int s1mme = m_s1ap->get_s1_mme(); //Prepare reply PDU @@ -92,58 +97,50 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT *in_ctxt_req = &init->choice.InitialContextSetupRequest; - LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt = &in_ctxt_req->E_RABToBeSetupListCtxtSUReq.buffer[0]; //FIXME support more than one erab + LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctx_req = &in_ctxt_req->E_RABToBeSetupListCtxtSUReq.buffer[0]; //FIXME support more than one erab srslte::byte_buffer_t *reply_buffer = m_pool->allocate(); m_s1ap_log->info("Preparing to send Initial Context Setup request\n"); - //Find UE Context - ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); - if(ue_ctx == NULL) - { - m_s1ap_log->error("Could not find UE to send Setup Context Request. MME S1AP Id: %d", mme_ue_s1ap_id); - return false; - } - //Add MME and eNB S1AP Ids - in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->mme_ue_s1ap_id; - in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->enb_ue_s1ap_id; + in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ecm_ctx->mme_ue_s1ap_id; + in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ecm_ctx->enb_ue_s1ap_id; //Set UE-AMBR - in_ctxt_req->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateDL.BitRate=1000000000;//2^32-1 + in_ctxt_req->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateDL.BitRate=1000000000; in_ctxt_req->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateUL.BitRate=1000000000;//FIXME Get UE-AMBR from HSS //Setup eRAB context in_ctxt_req->E_RABToBeSetupListCtxtSUReq.len = 1; - erab_ctxt->e_RAB_ID.E_RAB_ID = cs_resp->eps_bearer_context_created.ebi; + erab_ctx_req->e_RAB_ID.E_RAB_ID = erab_ctx->erab_id; //Setup E-RAB QoS parameters - erab_ctxt->e_RABlevelQoSParameters.qCI.QCI = 9; - erab_ctxt->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel.PriorityLevel = 15 ;//Lowest - erab_ctxt->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability = LIBLTE_S1AP_PRE_EMPTIONCAPABILITY_SHALL_NOT_TRIGGER_PRE_EMPTION; - erab_ctxt->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability = LIBLTE_S1AP_PRE_EMPTIONVULNERABILITY_PRE_EMPTABLE; + erab_ctx_req->e_RABlevelQoSParameters.qCI.QCI = 9; + erab_ctx_req->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel.PriorityLevel = 15 ;//Lowest + erab_ctx_req->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability = LIBLTE_S1AP_PRE_EMPTIONCAPABILITY_SHALL_NOT_TRIGGER_PRE_EMPTION; + erab_ctx_req->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability = LIBLTE_S1AP_PRE_EMPTIONVULNERABILITY_PRE_EMPTABLE; - erab_ctxt->e_RABlevelQoSParameters.gbrQosInformation_present=false; + erab_ctx_req->e_RABlevelQoSParameters.gbrQosInformation_present=false; //Set E-RAB S-GW F-TEID - if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){ - m_s1ap_log->error("Did not receive S1-U TEID in create session response\n"); - return false; - } - erab_ctxt->transportLayerAddress.n_bits = 32; //IPv4 - uint32_t sgw_s1u_ip = htonl(cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4); + //if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){ + // m_s1ap_log->error("Did not receive S1-U TEID in create session response\n"); + // return false; + //} + erab_ctx_req->transportLayerAddress.n_bits = 32; //IPv4 + uint32_t sgw_s1u_ip = htonl(erab_ctx->sgw_s1u_fteid.ipv4); //uint32_t sgw_s1u_ip = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4; - uint8_t *tmp_ptr = erab_ctxt->transportLayerAddress.buffer; + uint8_t *tmp_ptr = erab_ctx_req->transportLayerAddress.buffer; liblte_value_2_bits(sgw_s1u_ip, &tmp_ptr, 32);//FIXME consider ipv6 - uint32_t tmp_teid = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.teid; - memcpy(erab_ctxt->gTP_TEID.buffer, &tmp_teid, sizeof(uint32_t)); + uint32_t sgw_s1u_teid = erab_ctx->sgw_s1u_fteid.teid; + memcpy(erab_ctx_req->gTP_TEID.buffer, &sgw_s1u_teid, sizeof(uint32_t)); //Set UE security capabilities and k_enb bzero(in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer,sizeof(uint8_t)*16); bzero(in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer,sizeof(uint8_t)*16); for(int i = 0; i<3; i++) { - if(ue_ctx->ue_network_cap.eea[i+1] == true) + if(emm_ctx->security_ctxt.ue_network_cap.eea[i+1] == true) { in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer[i] = 1; //EEA supported } @@ -151,7 +148,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, { in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer[i] = 0; //EEA not supported } - if(ue_ctx->ue_network_cap.eia[i+1] == true) + if(emm_ctx->security_ctxt.ue_network_cap.eia[i+1] == true) { in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[i] = 1; //EEA supported } @@ -159,35 +156,30 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, { in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[i] = 0; //EEA not supported } - // in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[0] = 1; //EIA1 } - uint8_t key_enb[32]; - liblte_security_generate_k_enb(ue_ctx->security_ctxt.k_asme, ue_ctx->security_ctxt.ul_nas_count, key_enb); - liblte_unpack(key_enb, 32, in_ctxt_req->SecurityKey.buffer); - m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_ctx->security_ctxt.ul_nas_count); - //Set Attach accepted and activat default bearer NAS messages - if(cs_resp->paa_present != true) - { - m_s1ap_log->error("PAA not present\n"); - return false; - } - if(cs_resp->paa.pdn_type != srslte::GTPC_PDN_TYPE_IPV4) - { - m_s1ap_log->error("IPv6 not supported yet\n"); - return false; - } - srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); - m_s1ap_nas_transport->pack_attach_accept(ue_ctx, erab_ctxt, &cs_resp->paa, nas_buffer); + //Get K eNB + liblte_unpack(emm_ctx->security_ctxt.k_enb, 32, in_ctxt_req->SecurityKey.buffer); + m_s1ap_log->info_hex(emm_ctx->security_ctxt.k_enb, 32, "Initial Context Setup Request -- Key eNB\n"); + + srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); + if(emm_ctx->state == EMM_STATE_DEREGISTERED) + { + //Attach procedure initiated from an attach request + m_s1ap_log->console("Adding attach accept to Initial Context Setup Request\n"); + m_s1ap_log->info("Adding attach accept to Initial Context Setup Request\n"); + m_s1ap_nas_transport->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctx_req, &erab_ctx->pdn_addr_alloc, nas_buffer); + } + - LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); if(err != LIBLTE_SUCCESS) { m_s1ap_log->error("Could not pack Initial Context Setup Request Message\n"); return false; } - //Send Reply to eNB - ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ue_ctx->enb_sri, 0); + + //Send Reply to eNB + ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ecm_ctx->enb_sri, 0); if(n_sent == -1) { m_s1ap_log->error("Failed to send Initial Context Setup Request\n"); @@ -195,16 +187,18 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, } //Change E-RAB state to Context Setup Requested and save S-GW control F-TEID - ue_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; - ue_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.teid = sgw_ctrl_fteid.teid; - ue_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.ipv4 = sgw_ctrl_fteid.ipv4; + ecm_ctx->erabs_ctx[erab_ctx_req->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; + //ecm_ctx->erabs_ctx[erab_ctx_req->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.teid = sgw_ctrl_fteid.teid; + //ecm_ctx->erabs_ctx[erab_ctx_req->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.ipv4 = sgw_ctrl_fteid.ipv4; struct in_addr addr; addr.s_addr = htonl(sgw_s1u_ip); - m_s1ap_log->info("Sent Intial Context Setup Request. E-RAB id %d \n",erab_ctxt->e_RAB_ID.E_RAB_ID); - m_s1ap_log->info("Initial Context -- S1-U TEID 0x%x. IP %s \n", tmp_teid,inet_ntoa(addr)); - m_s1ap_log->console("Sent Intial Context Setup Request, E-RAB id %d\n",erab_ctxt->e_RAB_ID.E_RAB_ID); - m_s1ap_log->console("Initial Context -- S1-U TEID 0x%x. IP %s \n", tmp_teid,inet_ntoa(addr)); + m_s1ap_log->info("Sent Intial Context Setup Request. E-RAB id %d \n",erab_ctx_req->e_RAB_ID.E_RAB_ID); + m_s1ap_log->info("Initial Context -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid,inet_ntoa(addr)); + m_s1ap_log->console("Initial Context Setup Request -- eNB UE S1AP Id %d, MME UE S1AP Id %d\n",in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID, in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID); + m_s1ap_log->console("Initial Context Setup Request -- E-RAB id %d\n",erab_ctx_req->e_RAB_ID.E_RAB_ID); + m_s1ap_log->console("Initial Context Setup Request -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid,inet_ntoa(addr)); + m_s1ap_log->console("Initial Context Setup Request -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid,inet_ntoa(addr)); m_pool->deallocate(reply_buffer); m_pool->deallocate(nas_buffer); @@ -214,23 +208,25 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, bool s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp) { - uint32_t mme_ue_s1ap_id = in_ctxt_resp->MME_UE_S1AP_ID.MME_UE_S1AP_ID; - ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); if (ue_ctx == NULL) { m_s1ap_log->error("Could not find UE's context in active UE's map\n"); return false; } + ue_emm_ctx_t * emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t * ecm_ctx = &ue_ctx->ecm_ctx; + m_s1ap_log->console("Received Initial Context Setup Response\n"); //Setup E-RABs for(uint32_t i=0; iE_RABSetupListCtxtSURes.len;i++) { uint8_t erab_id = in_ctxt_resp->E_RABSetupListCtxtSURes.buffer[i].e_RAB_ID.E_RAB_ID; - erab_ctx_t *erab_ctx = &ue_ctx->erabs_ctx[erab_id]; + erab_ctx_t *erab_ctx = &ecm_ctx->erabs_ctx[erab_id]; if (erab_ctx->state != ERAB_CTX_REQUESTED) { - m_s1ap_log->error("E-RAB requested was not active %d\n",erab_id); + m_s1ap_log->error("E-RAB requested was not previously requested %d\n",erab_id); return false; } //Mark E-RAB with context setup @@ -255,6 +251,12 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I m_s1ap_log->console("E-RAB Context -- eNB TEID 0x%x; eNB GTP-U Address %s\n", erab_ctx->enb_fteid.teid, enb_addr_str); } + if(emm_ctx->state == EMM_STATE_REGISTERED) + { + m_s1ap_log->console("Initial Context Setup Response triggered from Service Request.\n"); + m_s1ap_log->console("Sending Modify Bearer Request.\n"); + m_mme_gtpc->send_modify_bearer_request(emm_ctx->imsi, &ecm_ctx->erabs_ctx[5]); + } return true; } @@ -262,41 +264,155 @@ bool s1ap_ctx_mngmt_proc::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) { + LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT ue_rel_req; + uint32_t mme_ue_s1ap_id = ue_rel->MME_UE_S1AP_ID.MME_UE_S1AP_ID; m_s1ap_log->info("Received UE Context Release Request. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); m_s1ap_log->console("Received UE Context Release Request. MME-UE S1AP Id %d\n", mme_ue_s1ap_id); - ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); + ue_ctx_t * ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); if(ue_ctx == NULL) { - m_s1ap_log->info("UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->info("No UE context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("No UE context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); return false; } + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; - //Delete any context at the SPGW - bool active = false; - for(int i=0;istate == ECM_STATE_CONNECTED) { - if(ue_ctx->erabs_ctx[i].state != ERAB_DEACTIVATED) + //There are active E-RABs, send release access mearers request + m_s1ap_log->console("There are active E-RABs, send release access mearers request"); + m_s1ap_log->info("There are active E-RABs, send release access mearers request"); + + //The handle_release_access_bearers_response function will make sure to mark E-RABS DEACTIVATED + //It will release the UEs downstream S1-u and keep the upstream S1-U connection active. + m_mme_gtpc->send_release_access_bearers_request(ecm_ctx->imsi); + + //Send release context command to enb, so that it can release it's bearers + send_ue_context_release_command(ecm_ctx,reply_buffer); + } + else + { + //No ECM Context to release + m_s1ap_log->info("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); + //Make sure E-RABS are merked as DEACTIVATED. + for(int i=0;ierabs_ctx[i].state = ERAB_DEACTIVATED; - break; + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; } } - if(active == true) - { - //There are active E-RABs, send delete session request - m_mme_gtpc->send_delete_session_request(ue_ctx); - } - //m_s1ap->delete_ue_ctx(ue_ctx); - for(int i=0;ierabs_ctx[i].state = ERAB_DEACTIVATED; - } + //Delete UE context - m_s1ap_log->info("Deleted UE Context.\n"); + ecm_ctx->state = ECM_STATE_IDLE; + ecm_ctx->enb_ue_s1ap_id = 0; + ecm_ctx->mme_ue_s1ap_id = 0; + m_s1ap_log->info("UE is ECM IDLE.\n"); + m_s1ap_log->console("UE is ECM IDLE.\n"); return true; } +bool +s1ap_ctx_mngmt_proc::send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer) +{ + + int s1mme = m_s1ap->get_s1_mme(); + + //Prepare reply PDU + LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; + bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); + pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE; + + LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *init = &pdu.choice.initiatingMessage; + init->procedureCode = LIBLTE_S1AP_PROC_ID_UECONTEXTRELEASE; + init->choice_type = LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UECONTEXTRELEASECOMMAND; + + LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMMAND_STRUCT *ctx_rel_cmd = &init->choice.UEContextReleaseCommand; + + ctx_rel_cmd->UE_S1AP_IDs.choice_type = LIBLTE_S1AP_UE_S1AP_IDS_CHOICE_UE_S1AP_ID_PAIR; + ctx_rel_cmd->UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID.MME_UE_S1AP_ID = ecm_ctx->mme_ue_s1ap_id; + ctx_rel_cmd->UE_S1AP_IDs.choice.uE_S1AP_ID_pair.eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ecm_ctx->enb_ue_s1ap_id; + + ctx_rel_cmd->Cause.choice_type = LIBLTE_S1AP_CAUSE_CHOICE_NAS; + ctx_rel_cmd->Cause.choice.nas.ext = false; + ctx_rel_cmd->Cause.choice.nas.e = LIBLTE_S1AP_CAUSENAS_NORMAL_RELEASE; + + LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); + if(err != LIBLTE_SUCCESS) + { + m_s1ap_log->error("Could not pack Initial Context Setup Request Message\n"); + return false; + } + //Send Reply to eNB + int n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ecm_ctx->enb_sri, 0); + if(n_sent == -1) + { + m_s1ap_log->error("Failed to send Initial Context Setup Request\n"); + return false; + } + + + return true; +} + +bool +s1ap_ctx_mngmt_proc::handle_ue_context_release_complete(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMPLETE_STRUCT *rel_comp) +{ + /* + typedef struct{ + bool ext; + LIBLTE_S1AP_MME_UE_S1AP_ID_STRUCT MME_UE_S1AP_ID; + LIBLTE_S1AP_ENB_UE_S1AP_ID_STRUCT eNB_UE_S1AP_ID; + LIBLTE_S1AP_CRITICALITYDIAGNOSTICS_STRUCT CriticalityDiagnostics; + bool CriticalityDiagnostics_present; + LIBLTE_S1AP_USERLOCATIONINFORMATION_STRUCT UserLocationInformation; + bool UserLocationInformation_present; + }LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMPLETE_STRUCT; + */ + + uint32_t mme_ue_s1ap_id = rel_comp->MME_UE_S1AP_ID.MME_UE_S1AP_ID; + m_s1ap_log->info("Received UE Context Release Complete. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("Received UE Context Release Complete. MME-UE S1AP Id %d\n", mme_ue_s1ap_id); + + ue_ctx_t * ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ctx == NULL) + { + m_s1ap_log->info("No UE context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("No UE context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + return false; + } + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + //Delete user plane context at the SPGW (but keep GTP-C connection). + if (ecm_ctx->state == ECM_STATE_CONNECTED) + { + //There are active E-RABs, send release access mearers request + m_s1ap_log->console("There are active E-RABs, send release access mearers request"); + m_s1ap_log->info("There are active E-RABs, send release access mearers request"); + m_mme_gtpc->send_release_access_bearers_request(ecm_ctx->imsi); + //The handle_releease_access_bearers_response function will make sure to mark E-RABS DEACTIVATED + //It will release the UEs downstream S1-u and keep the upstream S1-U connection active. + } + else + { + //No ECM Context to release + m_s1ap_log->info("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); + //Make sure E-RABS are merked as DEACTIVATED. + for(int i=0;ierabs_ctx[i].state = ERAB_DEACTIVATED; + } + } + + //Delete UE context + m_s1ap->release_ue_ecm_ctx(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + m_s1ap_log->info("UE Context Release Completed.\n"); + m_s1ap_log->console("UE Context Release Completed.\n"); + return true; +} + + } //namespace srsepc diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index 8fa469ec3..079eca100 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -26,13 +26,13 @@ //#include "srslte/upper/s1ap_common.h" #include "srslte/common/bcd_helpers.h" -#include "mme/s1ap.h" -#include "mme/s1ap_mngmt_proc.h" +#include "srsepc/hdr/mme/s1ap.h" +#include "srsepc/hdr/mme/s1ap_mngmt_proc.h" namespace srsepc{ s1ap_mngmt_proc* s1ap_mngmt_proc::m_instance = NULL; -boost::mutex s1ap_mngmt_proc_instance_mutex; +pthread_mutex_t s1ap_mngmt_proc_instance_mutex = PTHREAD_MUTEX_INITIALIZER; s1ap_mngmt_proc::s1ap_mngmt_proc() @@ -46,21 +46,23 @@ s1ap_mngmt_proc::~s1ap_mngmt_proc() s1ap_mngmt_proc* s1ap_mngmt_proc::get_instance(void) { - boost::mutex::scoped_lock lock(s1ap_mngmt_proc_instance_mutex); + pthread_mutex_lock(&s1ap_mngmt_proc_instance_mutex); if(NULL == m_instance) { m_instance = new s1ap_mngmt_proc(); } + pthread_mutex_unlock(&s1ap_mngmt_proc_instance_mutex); return(m_instance); } void s1ap_mngmt_proc::cleanup(void) { - boost::mutex::scoped_lock lock(s1ap_mngmt_proc_instance_mutex); + pthread_mutex_lock(&s1ap_mngmt_proc_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&s1ap_mngmt_proc_instance_mutex); } void @@ -102,6 +104,7 @@ s1ap_mngmt_proc::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRU { //eNB already registered //TODO replace enb_ctx + m_s1ap_log->warning("eNB Already registered\n"); } else { @@ -218,11 +221,11 @@ s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buff succ->procedureCode = LIBLTE_S1AP_PROC_ID_S1SETUP; succ->criticality = LIBLTE_S1AP_CRITICALITY_IGNORE; succ->choice_type = LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_S1SETUPRESPONSE; - + LIBLTE_S1AP_MESSAGE_S1SETUPRESPONSE_STRUCT* s1_resp=(LIBLTE_S1AP_MESSAGE_S1SETUPRESPONSE_STRUCT*)&succ->choice; s1_resp->ext=false; - + //MME Name s1_resp->MMEname_present=true; s1_resp->MMEname.ext=false; @@ -234,7 +237,7 @@ s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buff LIBLTE_S1AP_SERVEDGUMMEISITEM_STRUCT *serv_gummei = &s1_resp->ServedGUMMEIs.buffer[0]; serv_gummei->ext=false; - //serv_gummei->iE_Extensions=false; + serv_gummei->iE_Extensions_present = false; uint32_t plmn=0; srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &plmn); @@ -257,7 +260,9 @@ s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buff //Relay Unsupported s1_resp->MMERelaySupportIndicator_present=false; - + + s1_resp->CriticalityDiagnostics_present = false; + liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)msg); return true; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 5f791caa5..687ced63b 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -25,14 +25,17 @@ */ #include -#include "mme/s1ap.h" -#include "mme/s1ap_nas_transport.h" +#include +#include // for printing uint64_t +#include "srsepc/hdr/mme/s1ap.h" +#include "srsepc/hdr/mme/s1ap_nas_transport.h" #include "srslte/common/security.h" +#include "srslte/common/liblte_security.h" namespace srsepc{ s1ap_nas_transport* s1ap_nas_transport::m_instance = NULL; -boost::mutex s1ap_nas_transport_instance_mutex; +pthread_mutex_t s1ap_nas_transport_instance_mutex = PTHREAD_MUTEX_INITIALIZER; s1ap_nas_transport::s1ap_nas_transport() { @@ -47,21 +50,23 @@ s1ap_nas_transport::~s1ap_nas_transport() s1ap_nas_transport* s1ap_nas_transport::get_instance(void) { - boost::mutex::scoped_lock lock(s1ap_nas_transport_instance_mutex); + pthread_mutex_lock(&s1ap_nas_transport_instance_mutex); if(NULL == m_instance) { m_instance = new s1ap_nas_transport(); } + pthread_mutex_unlock(&s1ap_nas_transport_instance_mutex); return(m_instance); } void s1ap_nas_transport::cleanup(void) { - boost::mutex::scoped_lock lock(s1ap_nas_transport_instance_mutex); + pthread_mutex_lock(&s1ap_nas_transport_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&s1ap_nas_transport_instance_mutex); } void @@ -79,12 +84,6 @@ s1ap_nas_transport::init(hss_interface_s1ap * hss_) bool s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { - LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT attach_req; - LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT pdn_con_req; - LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT service_req; - - m_s1ap_log->console("Received Initial UE Message.\n"); - m_s1ap_log->info("Received Initial UE Message.\n"); //Get info from initial UE message uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; @@ -93,40 +92,82 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA log_unhandled_initial_ue_message_ies(init_ue); /*Check whether NAS Attach Request or Service Request*/ - uint8_t pd, msg_type; + bool mac_valid = false; + uint8_t pd, msg_type, sec_hdr_type; srslte::byte_buffer_t *nas_msg = m_pool->allocate(); memcpy(nas_msg->msg, &init_ue->NAS_PDU.buffer, init_ue->NAS_PDU.n_octets); nas_msg->N_bytes = init_ue->NAS_PDU.n_octets; + liblte_mme_parse_msg_header((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &pd, &msg_type); if(msg_type == LIBLTE_MME_MSG_TYPE_ATTACH_REQUEST) { - //Get NAS Attach Request and PDN connectivity request messages - LIBLTE_ERROR_ENUM err = liblte_mme_unpack_attach_request_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &attach_req); - if(err != LIBLTE_SUCCESS){ - m_s1ap_log->error("Error unpacking NAS attach request. Error: %s\n", liblte_error_text[err]); - m_pool->deallocate(nas_msg); - return false; - } - /*Get PDN Connectivity Request*/ - err = liblte_mme_unpack_pdn_connectivity_request_msg(&attach_req.esm_msg, &pdn_con_req); - if(err != LIBLTE_SUCCESS){ - m_s1ap_log->error("Error unpacking NAS PDN Connectivity Request. Error: %s\n", liblte_error_text[err]); - m_pool->deallocate(nas_msg); - return false; - } - handle_nas_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, reply_buffer, reply_flag, enb_sri); + m_s1ap_log->info("Received Attach Request \n"); + m_s1ap_log->console("Received Attach Request \n"); + handle_nas_attach_request(enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); } else if(msg_type == LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST) { m_s1ap_log->info("Received Service Request \n"); m_s1ap_log->console("Received Service Request \n"); - liblte_mme_unpack_service_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &service_req); + if(!init_ue->S_TMSI_present) + { + m_s1ap_log->error("Service request -- S-TMSI not present\n"); + m_s1ap_log->console("Service request -- S-TMSI not present\n" ); + return false; + } + uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; + uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; + m_s1ap_log->info("Service request -- S-TMSI 0x%x\n", ntohl(*m_tmsi)); + m_s1ap_log->console("Service request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); + m_s1ap_log->info("Service request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + m_s1ap_log->console("Service request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + handle_nas_service_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); + return true; + } + else if(msg_type == LIBLTE_MME_MSG_TYPE_DETACH_REQUEST) + { + m_s1ap_log->console("Received Initial UE message -- Detach Request\n"); + m_s1ap_log->info("Received Initial UE message -- Detach Request\n"); + if(!init_ue->S_TMSI_present) + { + m_s1ap_log->error("Detach request -- S-TMSI not present\n"); + m_s1ap_log->console("Detach request -- S-TMSI not present\n" ); + return false; + } + uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; + uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; + m_s1ap_log->info("Detach Request -- S-TMSI 0x%x\n", ntohl(*m_tmsi)); + m_s1ap_log->console("Detach Request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); + m_s1ap_log->info("Detach Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + m_s1ap_log->console("Detach Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); - m_s1ap_log->info("Service Request not implemented. Sending Service Reject."); - m_s1ap_log->console("Service Request not implemented. Sending Service Reject."); - /* Force UE to re-attach */ - pack_service_reject(reply_buffer, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED, enb_ue_s1ap_id); - *reply_flag = true; + handle_nas_detach_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); + return true; + } + else if(msg_type == LIBLTE_MME_MSG_TYPE_TRACKING_AREA_UPDATE_REQUEST) + { + m_s1ap_log->console("Received Initial UE message -- Tracking Area Update Request\n"); + m_s1ap_log->info("Received Initial UE message -- Tracking Area Update Request\n"); + if(!init_ue->S_TMSI_present) + { + m_s1ap_log->error("Tracking Area Update Request -- S-TMSI not present\n"); + m_s1ap_log->console("Tracking Area Update Request -- S-TMSI not present\n" ); + return false; + } + uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; + uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; + m_s1ap_log->info("Tracking Area Update Request -- S-TMSI 0x%x\n", ntohl(*m_tmsi)); + m_s1ap_log->console("Tracking Area Update Request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); + m_s1ap_log->info("Tracking Area Update Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + m_s1ap_log->console("Tracking Area Update Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + + handle_nas_tracking_area_update_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); + return true; + } + else + { + m_s1ap_log->info("Unhandled Initial UE Message 0x%x\n",msg_type); + m_s1ap_log->console("Unhandled Initial UE Message 0x%x \n", msg_type); } m_pool->deallocate(nas_msg); @@ -136,94 +177,189 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA bool s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { - - bool ue_valid = true; + uint8_t pd, msg_type, sec_hdr_type; uint32_t enb_ue_s1ap_id = ul_xport->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; uint32_t mme_ue_s1ap_id = ul_xport->MME_UE_S1AP_ID.MME_UE_S1AP_ID; + bool mac_valid = false; - ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); + //Get UE ECM context + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); if(ue_ctx == NULL) { - //TODO UE not registered, send error message. - m_s1ap_log->warning("Received uplink NAS, but could not find UE context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + m_s1ap_log->warning("Received uplink NAS, but could not find UE ECM context. MME-UE S1AP id: %d\n",mme_ue_s1ap_id); return false; } - m_s1ap_log->debug("Received uplink NAS and found UE. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + m_s1ap_log->debug("Received uplink NAS and found UE ECM context. MME-UE S1AP id: %d\n",mme_ue_s1ap_id); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; - //Get NAS message type - uint8_t pd, msg_type; + //Parse NAS message header srslte::byte_buffer_t *nas_msg = m_pool->allocate(); - memcpy(nas_msg->msg, &ul_xport->NAS_PDU.buffer, ul_xport->NAS_PDU.n_octets); nas_msg->N_bytes = ul_xport->NAS_PDU.n_octets; liblte_mme_parse_msg_header((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &pd, &msg_type); - switch (msg_type) { + // Parse the message security header + liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)nas_msg, &pd, &sec_hdr_type); + + //Find UE EMM context if message is security protected. + if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) + { + //Make sure EMM context is set-up, to do integrity check/de-chiphering + if(emm_ctx->imsi == 0) + { + //No EMM context found. + //Perhaps a temporary context is being created? + //This can happen with integrity protected identity reponse messages + if( !(msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY)) + { + m_s1ap_log->warning("Uplink NAS: could not find security context for integrity protected message. MME-UE S1AP id: %d\n",mme_ue_s1ap_id); + m_pool->deallocate(nas_msg); + return false; + } + } + } + + if( sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS || + (msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) || + (msg_type == LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY)) + { + //Only identity response and authentication response are valid as plain NAS. + //Sometimes authentication response and identity are sent as integrity protected, + //but these messages are sent when the securty context is not setup yet, so we cannot integrity check it. + //FIXME Double-check + switch(msg_type) + { + case LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE: + m_s1ap_log->info("Uplink NAS: Received Identity Response\n"); + m_s1ap_log->console("Uplink NAS: Received Identity Response\n"); + handle_identity_response(nas_msg, ue_ctx, reply_buffer, reply_flag); + break; case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: m_s1ap_log->info("Uplink NAS: Received Authentication Response\n"); m_s1ap_log->console("Uplink NAS: Received Authentication Response\n"); handle_nas_authentication_response(nas_msg, ue_ctx, reply_buffer, reply_flag); break; - case LIBLTE_MME_MSG_TYPE_SECURITY_MODE_COMPLETE: + default: + m_s1ap_log->warning("Unhandled Plain NAS message 0x%x\n", msg_type ); + m_s1ap_log->console("Unhandled Plain NAS message 0x%x\n", msg_type ); + m_pool->deallocate(nas_msg); + return false; + } + //Increment UL NAS count. + emm_ctx->security_ctxt.ul_nas_count++; + } + else if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_WITH_NEW_EPS_SECURITY_CONTEXT || sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT) + { + switch (msg_type) { + case LIBLTE_MME_MSG_TYPE_SECURITY_MODE_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Security Mode Complete\n"); m_s1ap_log->console("Uplink NAS: Received Security Mode Complete\n"); - handle_nas_security_mode_complete(nas_msg, ue_ctx, reply_buffer, reply_flag); + emm_ctx->security_ctxt.ul_nas_count = 0; + emm_ctx->security_ctxt.dl_nas_count = 0; + mac_valid = integrity_check(emm_ctx,nas_msg); + if(mac_valid){ + handle_nas_security_mode_complete(nas_msg, ue_ctx, reply_buffer, reply_flag); + } else { + m_s1ap_log->warning("Invalid MAC in Security Mode Command Complete message.\n" ); + } break; + default: + m_s1ap_log->warning("Unhandled NAS message with new EPS security context 0x%x\n", msg_type ); + m_s1ap_log->warning("Unhandled NAS message with new EPS security context 0x%x\n", msg_type ); + } + } + else if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY || sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED) + { + //Integrity protected NAS message, possibly chiphered. + emm_ctx->security_ctxt.ul_nas_count++; + mac_valid = integrity_check(emm_ctx,nas_msg); + if(!mac_valid){ + m_s1ap_log->warning("Invalid MAC in NAS message type 0x%x.\n", msg_type); + m_pool->deallocate(nas_msg); + return false; + } + switch (msg_type) { case LIBLTE_MME_MSG_TYPE_ATTACH_COMPLETE: - m_s1ap_log->info("Uplink NAS: Received Attach Complete\n"); - m_s1ap_log->console("Uplink NAS: Received Attach Complete\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Received Attach Complete\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Received Attach Complete\n"); handle_nas_attach_complete(nas_msg, ue_ctx, reply_buffer, reply_flag); - ue_ctx->security_ctxt.ul_nas_count++; break; case LIBLTE_MME_MSG_TYPE_ESM_INFORMATION_RESPONSE: - m_s1ap_log->info("Uplink NAS: Received ESM Information Response\n"); - m_s1ap_log->console("Uplink NAS: Received ESM Information Response\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Received ESM Information Response\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Received ESM Information Response\n"); handle_esm_information_response(nas_msg, ue_ctx, reply_buffer, reply_flag); - ue_ctx->security_ctxt.ul_nas_count++; - break; - case LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE: - m_s1ap_log->info("Uplink NAS: Received Identity Response\n"); - m_s1ap_log->console("Uplink NAS: Received Identity Response\n"); - handle_identity_response(nas_msg, ue_ctx, reply_buffer, reply_flag); - //ue_ctx->security_ctxt.ul_nas_count++; break; case LIBLTE_MME_MSG_TYPE_TRACKING_AREA_UPDATE_REQUEST: - m_s1ap_log->info("Uplink NAS: Tracking Area Update Request\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Tracking Area Update Request\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Tracking Area Update Request\n"); handle_tracking_area_update_request(nas_msg, ue_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_FAILURE: - m_s1ap_log->info("Uplink NAS: Authentication Failure\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Authentication Failure\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Authentication Failure\n"); handle_authentication_failure(nas_msg, ue_ctx, reply_buffer, reply_flag); - ue_ctx->security_ctxt.ul_nas_count++; + break; + case LIBLTE_MME_MSG_TYPE_DETACH_REQUEST: + m_s1ap_log->info("Integrity Protected UL NAS: Detach Request\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Detach Request\n"); + handle_nas_detach_request(nas_msg, ue_ctx, reply_buffer, reply_flag); break; default: - m_s1ap_log->warning("Unhandled NAS message 0x%x\n", msg_type ); - m_s1ap_log->console("Unhandled NAS message 0x%x\n", msg_type ); - return false; //FIXME (nas_msg deallocate needs to be called) + m_s1ap_log->warning("Unhandled NAS integrity protected message 0x%x\n", msg_type ); + m_s1ap_log->console("Unhandled NAS integrity protected message 0x%x\n", msg_type ); + m_pool->deallocate(nas_msg); + return false; + } } + else + { + m_s1ap_log->error("Unhandled security header type in Uplink NAS Transport: %d\n", sec_hdr_type); + m_pool->deallocate(nas_msg); + return false; + } + if(*reply_flag == true) { - m_s1ap_log->info("DL NAS: Sent Downlink NAS message\n"); - m_s1ap_log->console("DL NAS: Sent Downlink NAS Message\n"); + m_s1ap_log->console("DL NAS: Sent Downlink NAS Message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count,emm_ctx->security_ctxt.ul_nas_count ); + m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count, emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->info("DL NAS: MME UE S1AP id %d\n",ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->console("DL NAS: MME UE S1AP id %d\n",ecm_ctx->mme_ue_s1ap_id); } m_pool->deallocate(nas_msg); - return true; } bool s1ap_nas_transport::handle_nas_attach_request(uint32_t enb_ue_s1ap_id, - const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, - const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri) { + LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT attach_req; + LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT pdn_con_req; + + //Get NAS Attach Request and PDN connectivity request messages + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_attach_request_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &attach_req); + if(err != LIBLTE_SUCCESS){ + m_s1ap_log->error("Error unpacking NAS attach request. Error: %s\n", liblte_error_text[err]); + m_pool->deallocate(nas_msg); + return false; + } + /*Get PDN Connectivity Request*/ + err = liblte_mme_unpack_pdn_connectivity_request_msg(&attach_req.esm_msg, &pdn_con_req); + if(err != LIBLTE_SUCCESS){ + m_s1ap_log->error("Error unpacking NAS PDN Connectivity Request. Error: %s\n", liblte_error_text[err]); + m_pool->deallocate(nas_msg); + return false; + } + //Get attach type from attach request if(attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) - { + { m_s1ap_log->console("Attach Request -- IMSI-style attach request\n"); m_s1ap_log->info("Attach Request -- IMSI-style attach request\n"); handle_nas_imsi_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, reply_buffer, reply_flag, enb_sri); @@ -232,7 +368,7 @@ s1ap_nas_transport::handle_nas_attach_request(uint32_t enb_ue_s1ap_id, { m_s1ap_log->console("Attach Request -- GUTI-style attach request\n"); m_s1ap_log->info("Attach Request -- GUTI-style attach request\n"); - handle_nas_guti_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, reply_buffer, reply_flag, enb_sri); + handle_nas_guti_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, nas_msg, reply_buffer, reply_flag, enb_sri); } else { @@ -256,48 +392,73 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, uint8_t xres[8]; ue_ctx_t ue_ctx; - ue_ctx.imsi = 0; - ue_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - ue_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ue_emm_ctx_t *emm_ctx = &ue_ctx.emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx.ecm_ctx; + //Set UE's EMM context + uint64_t imsi = 0; + for(int i=0;i<=14;i++){ + imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); + } + + //Check if UE is + ue_ctx_t *old_ctx = m_s1ap->find_ue_ctx_from_imsi(imsi); + if(old_ctx!=NULL) + { + m_s1ap_log->console("Attach Request -- UE is already attached."); + m_s1ap_log->info("Attach Request -- UE is already attached."); + //Detaching previoulsy attached UE. + m_mme_gtpc->send_delete_session_request(imsi); + if(old_ctx->ecm_ctx.mme_ue_s1ap_id!=0) + { + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(&old_ctx->ecm_ctx, reply_buffer); + } + m_s1ap->delete_ue_ctx(imsi); + } + + emm_ctx->imsi = imsi; + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + emm_ctx->state = EMM_STATE_DEREGISTERED; //Save UE network capabilities - memcpy(&ue_ctx.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); - ue_ctx.ms_network_cap_present = attach_req.ms_network_cap_present; + memcpy(&emm_ctx->security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + emm_ctx->security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; if(attach_req.ms_network_cap_present) { - memcpy(&ue_ctx.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&emm_ctx->security_ctxt.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); } uint8_t eps_bearer_id = pdn_con_req.eps_bearer_id; //TODO: Unused - ue_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; + emm_ctx->procedure_transaction_id = pdn_con_req.proc_transaction_id; - //Save whether ESM information transfer is necessary - ue_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; - //m_s1ap_log->console("EPS Bearer id: %d\n", eps_bearer_id); //Initialize NAS count - ue_ctx.security_ctxt.ul_nas_count = 0; - ue_ctx.security_ctxt.dl_nas_count = 0; - //Add eNB info to UE ctxt - memcpy(&ue_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + emm_ctx->security_ctxt.ul_nas_count = 0; + emm_ctx->security_ctxt.dl_nas_count = 0; + + //Set UE ECM context + ecm_ctx->imsi = emm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; + + //Set eNB information + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + + //Save whether secure ESM information transfer is necessary + ecm_ctx->eit = pdn_con_req.esm_info_transfer_flag_present; + //Initialize E-RABs for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { - ue_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ctx.erabs_ctx[i].erab_id = i; + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; } - //IMSI style attach - ue_ctx.imsi = 0; - for(int i=0;i<=14;i++){ - ue_ctx.imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); - } - - m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); - m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); - + //Log Attach Request information + m_s1ap_log->console("Attach request -- IMSI: %015lu\n", emm_ctx->imsi); + m_s1ap_log->info("Attach request -- IMSI: %015lu\n", emm_ctx->imsi); + m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->info("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); m_s1ap_log->console("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); m_s1ap_log->info("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); - m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id); m_s1ap_log->console("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", attach_req.ue_network_cap.eea[0], attach_req.ue_network_cap.eea[1], @@ -322,20 +483,25 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, m_s1ap_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); //Save attach request type - ue_ctx.attach_type = attach_req.eps_attach_type; + emm_ctx->attach_type = attach_req.eps_attach_type; //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(ue_ctx.imsi, ue_ctx.security_ctxt.k_asme, autn, rand, ue_ctx.security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(emm_ctx->imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) { - m_s1ap_log->console("User not found. IMSI %015lu\n",ue_ctx.imsi); - m_s1ap_log->info("User not found. IMSI %015lu\n",ue_ctx.imsi); + m_s1ap_log->console("User not found. IMSI %015lu\n",emm_ctx->imsi); + m_s1ap_log->info("User not found. IMSI %015lu\n",emm_ctx->imsi); return false; } - m_s1ap->add_new_ue_ctx(ue_ctx); + //Save the UE context + ue_ctx_t *new_ctx = new ue_ctx_t; + memcpy(new_ctx,&ue_ctx,sizeof(ue_ctx_t)); + m_s1ap->add_ue_ctx_to_imsi_map(new_ctx); + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(new_ctx); + //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_buffer, ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id, autn, rand); - + pack_authentication_request(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); + //Send reply to eNB *reply_flag = true; m_s1ap_log->info("Downlink NAS: Sending Authentication Request\n"); @@ -344,105 +510,465 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, } bool -s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, +s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri) { + //Parse the message security header + uint8 pd = 0; + uint8 sec_hdr_type = 0; + liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)nas_msg, &pd, &sec_hdr_type); + + bool integrity_valid = false; + if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) + { + m_s1ap_log->info("Attach request -- GUTI-stlye attach request is not integrity protected\n"); + m_s1ap_log->console("Attach request -- GUTI-stlye attach request is not integrity protected\n"); + } + else{ + m_s1ap_log->info("Attach request -- GUTI-stlye attach request is integrity protected\n"); + m_s1ap_log->console("Attach request -- GUTI-stlye attach request is integrity protected\n"); + } + + //GUTI style attach uint32_t m_tmsi = attach_req.eps_mobile_id.guti.m_tmsi; - std::map::iterator it = m_s1ap->m_tmsi_to_s1ap_id.find(m_tmsi); - if(it == m_s1ap->m_tmsi_to_s1ap_id.end()) + std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); + if(it == m_s1ap->m_tmsi_to_imsi.end()) { + + m_s1ap_log->console("Attach Request -- Could not find M-TMSI 0x%x\n", m_tmsi); + m_s1ap_log->info("Attach Request -- Could not find M-TMSI 0x%x\n", m_tmsi); + //Could not find IMSI from M-TMSI, send Id request ue_ctx_t ue_ctx; - ue_ctx.imsi = 0; - ue_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - ue_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ue_emm_ctx_t *emm_ctx = &ue_ctx.emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx.ecm_ctx; + + //We do not know the IMSI of the UE yet + //The IMSI will be set when the identity response is received + //Set EMM ctx + emm_ctx->imsi = 0; + emm_ctx->state = EMM_STATE_DEREGISTERED; + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); //Save UE network capabilities - memcpy(&ue_ctx.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); - ue_ctx.ms_network_cap_present = attach_req.ms_network_cap_present; + memcpy(&emm_ctx->security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + emm_ctx->security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; if(attach_req.ms_network_cap_present) { - memcpy(&ue_ctx.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&emm_ctx->security_ctxt.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); } + //Initialize NAS count + emm_ctx->security_ctxt.ul_nas_count = 0; + emm_ctx->security_ctxt.dl_nas_count = 0; + emm_ctx->procedure_transaction_id = pdn_con_req.proc_transaction_id; + + //Set ECM context + ecm_ctx->imsi = 0; + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; + uint8_t eps_bearer_id = pdn_con_req.eps_bearer_id; //TODO: Unused - ue_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; //Save attach request type - ue_ctx.attach_type = attach_req.eps_attach_type; + emm_ctx->attach_type = attach_req.eps_attach_type; //Save whether ESM information transfer is necessary - ue_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; + ecm_ctx->eit = pdn_con_req.esm_info_transfer_flag_present; //m_s1ap_log->console("EPS Bearer id: %d\n", eps_bearer_id); - //Initialize NAS count - ue_ctx.security_ctxt.ul_nas_count = 0; - ue_ctx.security_ctxt.dl_nas_count = 0; //Add eNB info to UE ctxt - memcpy(&ue_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); //Initialize E-RABs for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { - ue_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ctx.erabs_ctx[i].erab_id = i; + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; } - m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); - m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); - m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id); + m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ecm_ctx->imsi); + m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ecm_ctx->imsi); + m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); m_s1ap_log->console("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", - attach_req.ue_network_cap.eea[0], - attach_req.ue_network_cap.eea[1], - attach_req.ue_network_cap.eea[2], - attach_req.ue_network_cap.eea[3], - attach_req.ue_network_cap.eea[4], - attach_req.ue_network_cap.eea[5], - attach_req.ue_network_cap.eea[6], - attach_req.ue_network_cap.eea[7]); + attach_req.ue_network_cap.eea[0], attach_req.ue_network_cap.eea[1], attach_req.ue_network_cap.eea[2], attach_req.ue_network_cap.eea[3], + attach_req.ue_network_cap.eea[4], attach_req.ue_network_cap.eea[5], attach_req.ue_network_cap.eea[6], attach_req.ue_network_cap.eea[7]); m_s1ap_log->console("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", - attach_req.ue_network_cap.eia[0], - attach_req.ue_network_cap.eia[1], - attach_req.ue_network_cap.eia[2], - attach_req.ue_network_cap.eia[3], - attach_req.ue_network_cap.eia[4], - attach_req.ue_network_cap.eia[5], - attach_req.ue_network_cap.eia[6], - attach_req.ue_network_cap.eia[7]); + attach_req.ue_network_cap.eia[0], attach_req.ue_network_cap.eia[1], attach_req.ue_network_cap.eia[2], attach_req.ue_network_cap.eia[3], + attach_req.ue_network_cap.eia[4], attach_req.ue_network_cap.eia[5], attach_req.ue_network_cap.eia[6], attach_req.ue_network_cap.eia[7]); m_s1ap_log->console("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); m_s1ap_log->console("PDN Connectivity Request -- EPS Bearer Identity requested: %d\n", pdn_con_req.eps_bearer_id); m_s1ap_log->console("PDN Connectivity Request -- Procedure Transaction Id: %d\n", pdn_con_req.proc_transaction_id); m_s1ap_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); m_s1ap_log->console("Could not find M-TMSI=0x%x. Sending ID request\n",m_tmsi); - m_s1ap_log->info("Could not find M-TMSI=0x%d. Sending Id Request\n", m_tmsi); - m_s1ap->add_new_ue_ctx(ue_ctx); - pack_identity_request(reply_buffer, ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id); + m_s1ap_log->info("Could not find M-TMSI=0x%x. Sending Id Request\n", m_tmsi); + //m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + + //Store temporary ue context + ue_ctx_t *new_ctx = new ue_ctx_t; + memcpy(new_ctx,&ue_ctx,sizeof(ue_ctx_t)); + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(new_ctx); + + pack_identity_request(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); *reply_flag = true; return true; } else{ + m_s1ap_log->console("Attach Request -- Found M-TMSI: %d\n",m_tmsi); - ue_ctx_t *ue_ctx_ptr = m_s1ap->find_ue_ctx(it->second); - if(ue_ctx_ptr!=NULL) + m_s1ap_log->console("Attach Request -- IMSI: %015lu\n",it->second); + //Get UE EMM context + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); + if(ue_ctx!=NULL) { - //Save attach request type - ue_ctx_ptr->attach_type = attach_req.eps_attach_type; - m_s1ap_log->console("Found UE context. IMSI: %015lu\n",ue_ctx_ptr->imsi); - m_mme_gtpc->send_create_session_request(ue_ctx_ptr->imsi, ue_ctx_ptr->mme_ue_s1ap_id); - *reply_flag = false; //No reply needed - return true; + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + m_s1ap_log->console("Found UE context. IMSI: %015lu, old eNB UE S1ap Id %d, old MME UE S1AP Id %d\n",emm_ctx->imsi, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + //Check NAS integrity + bool msg_valid = false; + emm_ctx->security_ctxt.ul_nas_count++; + msg_valid = integrity_check(emm_ctx,nas_msg); + if(msg_valid == true && emm_ctx->state == EMM_STATE_DEREGISTERED) + { + m_s1ap_log->console("GUTI Attach Integrity valid. UL count %d, DL count %d\n",emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.dl_nas_count); + + //Create new MME UE S1AP Identity + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + ecm_ctx->imsi = ecm_ctx->imsi; + + emm_ctx->procedure_transaction_id = pdn_con_req.proc_transaction_id; + //Save Attach type + emm_ctx->attach_type = attach_req.eps_attach_type; + + //Set eNB information + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + //Save whether secure ESM information transfer is necessary + ecm_ctx->eit = pdn_con_req.esm_info_transfer_flag_present; + + //Initialize E-RABs + for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) + { + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; + } + + //Store context based on MME UE S1AP id + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); + + //Re-generate K_eNB + liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->console("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + + m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ecm_ctx->imsi); + m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ecm_ctx->imsi); + m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->console("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", + attach_req.ue_network_cap.eea[0], attach_req.ue_network_cap.eea[1], attach_req.ue_network_cap.eea[2], attach_req.ue_network_cap.eea[3], + attach_req.ue_network_cap.eea[4], attach_req.ue_network_cap.eea[5], attach_req.ue_network_cap.eea[6], attach_req.ue_network_cap.eea[7]); + m_s1ap_log->console("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", + attach_req.ue_network_cap.eia[0], attach_req.ue_network_cap.eia[1], attach_req.ue_network_cap.eia[2], attach_req.ue_network_cap.eia[3], + attach_req.ue_network_cap.eia[4], attach_req.ue_network_cap.eia[5], attach_req.ue_network_cap.eia[6], attach_req.ue_network_cap.eia[7]); + m_s1ap_log->console("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); + m_s1ap_log->console("PDN Connectivity Request -- EPS Bearer Identity requested: %d\n", pdn_con_req.eps_bearer_id); + m_s1ap_log->console("PDN Connectivity Request -- Procedure Transaction Id: %d\n", pdn_con_req.proc_transaction_id); + m_s1ap_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); + + //Create session request + m_s1ap_log->console("GUTI Attach -- NAS Integrity OK.\n"); + if(ecm_ctx->eit) + { + m_s1ap_log->console("Secure ESM information transfer requested.\n"); + m_s1ap_log->info("Secure ESM information transfer requested.\n"); + pack_esm_information_request(reply_buffer, emm_ctx, ecm_ctx); + *reply_flag = true; + } + else + { + m_mme_gtpc->send_create_session_request(emm_ctx->imsi); + *reply_flag = false; //No reply needed + } + return true; + } + else + { + if(emm_ctx->state != EMM_STATE_DEREGISTERED) + { + m_s1ap_log->error("Received GUTI-Attach Request from attached user.\n"); + m_s1ap_log->console("Received GUTI-Attach Request from attached user.\n"); + + //Delete previous Ctx, restart authentication + //Detaching previoulsy attached UE. + m_mme_gtpc->send_delete_session_request(emm_ctx->imsi); + if(ecm_ctx->mme_ue_s1ap_id!=0) + { + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx, reply_buffer); + } + } + emm_ctx->security_ctxt.ul_nas_count = 0; + emm_ctx->security_ctxt.dl_nas_count = 0; + + //Create new MME UE S1AP Identity + uint32_t new_mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + + //Make sure context from previous NAS connections is not present + if(ecm_ctx->mme_ue_s1ap_id!=0) + { + m_s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); + } + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; + //Set EMM as de-registered + emm_ctx->state = EMM_STATE_DEREGISTERED; + //Save Attach type + emm_ctx->attach_type = attach_req.eps_attach_type; + + //Set UE ECM context + ecm_ctx->imsi = ecm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; + + //Set eNB information + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + //Save whether secure ESM information transfer is necessary + ecm_ctx->eit = pdn_con_req.esm_info_transfer_flag_present; + + //Initialize E-RABs + for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) + { + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; + } + //Store context based on MME UE S1AP id + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); + + //NAS integrity failed. Re-start authentication process. + m_s1ap_log->console("GUTI Attach request NAS integrity failed.\n"); + m_s1ap_log->console("RE-starting authentication procedure.\n"); + uint8_t autn[16]; + uint8_t rand[16]; + //Get Authentication Vectors from HSS + if(!m_hss->gen_auth_info_answer(emm_ctx->imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) + { + m_s1ap_log->console("User not found. IMSI %015lu\n",emm_ctx->imsi); + m_s1ap_log->info("User not found. IMSI %015lu\n",emm_ctx->imsi); + return false; + } + pack_authentication_request(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); + + //Send reply to eNB + *reply_flag = true; + m_s1ap_log->info("Downlink NAS: Sent Authentication Request\n"); + m_s1ap_log->console("Downlink NAS: Sent Authentication Request\n"); + return true; + } } else { m_s1ap_log->error("Found M-TMSI but could not find UE context\n"); + m_s1ap_log->console("Error: Found M-TMSI but could not find UE context\n"); return false; } } return true; } +bool +s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri) +{ + + bool mac_valid = false; + LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT service_req; + + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_service_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &service_req); + if(err !=LIBLTE_SUCCESS) + { + m_s1ap_log->error("Could not unpack service request\n"); + return false; + } + + std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); + if(it == m_s1ap->m_tmsi_to_imsi.end()) + { + m_s1ap_log->console("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + m_s1ap_log->error("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + pack_service_reject(reply_buffer, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED, enb_ue_s1ap_id); + *reply_flag = true; + return true; + } + + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); + if(ue_ctx == NULL || ue_ctx->emm_ctx.state != EMM_STATE_REGISTERED) + { + m_s1ap_log->console("UE is not EMM-Registered.\n"); + m_s1ap_log->error("UE is not EMM-Registered.\n"); + pack_service_reject(reply_buffer, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED, enb_ue_s1ap_id); + *reply_flag = true; + return true; + } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + emm_ctx->security_ctxt.ul_nas_count++; + mac_valid = short_integrity_check(emm_ctx,nas_msg); + if(mac_valid) + { + m_s1ap_log->console("Service Request -- Short MAC valid\n"); + m_s1ap_log->info("Service Request -- Short MAC valid\n"); + if(ecm_ctx->state == ECM_STATE_CONNECTED) + { + m_s1ap_log->error("Service Request -- User is ECM CONNECTED\n"); + + //Release previous context + m_s1ap_log->info("Service Request -- Releasing previouse ECM context. eNB S1AP Id %d, MME UE S1AP Id %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + m_s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); + } + + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + + //UE not connect. Connect normally. + m_s1ap_log->console("Service Request -- User is ECM DISCONNECTED\n"); + m_s1ap_log->info("Service Request -- User is ECM DISCONNECTED\n"); + //Create ECM context + ecm_ctx->imsi = emm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + emm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; + //Set eNB information + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + + //Save whether secure ESM information transfer is necessary + ecm_ctx->eit = false; + + //Get UE IP, and uplink F-TEID + if(emm_ctx->ue_ip.s_addr == 0 ) + { + m_s1ap_log->error("UE has no valid IP assigned upon reception of service request"); + } + + m_s1ap_log->console("UE previously assigned IP: %s",inet_ntoa(emm_ctx->ue_ip)); + + //Re-generate K_eNB + liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->console("UE Ctr TEID %d\n", emm_ctx->sgw_ctrl_fteid.teid); + + //Save UE ctx to MME UE S1AP id + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx,&ecm_ctx->erabs_ctx[5]); + } + else + { + m_s1ap_log->console("Service Request -- Short MAC invalid. Ignoring service request\n"); + m_s1ap_log->console("Service Request -- Short MAC invalid. Ignoring service request\n"); + } + return true; +} + +bool +s1ap_nas_transport::handle_nas_detach_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri) +{ + bool mac_valid = false; + LIBLTE_MME_DETACH_REQUEST_MSG_STRUCT detach_req; + + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_detach_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &detach_req); + if(err !=LIBLTE_SUCCESS) + { + m_s1ap_log->error("Could not unpack detach request\n"); + return false; + } + + std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); + if(it == m_s1ap->m_tmsi_to_imsi.end()) + { + m_s1ap_log->console("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + m_s1ap_log->error("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + return true; + } + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + m_mme_gtpc->send_delete_session_request(emm_ctx->imsi); + emm_ctx->state = EMM_STATE_DEREGISTERED; + emm_ctx->security_ctxt.ul_nas_count++; + + m_s1ap_log->console("Received. M-TMSI 0x%x\n", m_tmsi); + //Received detach request as an initial UE message + //eNB created new ECM context to send the detach request; this needs to be cleared. + ecm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx, reply_buffer); + return true; +} + +//FIXME re-factor to reduce code duplication +bool +s1ap_nas_transport::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +{ + + m_s1ap_log->console("Detach request -- IMSI %015lu", ue_ctx->emm_ctx.imsi); + m_s1ap_log->info("Detach request -- IMSI %015lu", ue_ctx->emm_ctx.imsi); + LIBLTE_MME_DETACH_REQUEST_MSG_STRUCT detach_req; + + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_detach_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &detach_req); + if(err !=LIBLTE_SUCCESS) + { + m_s1ap_log->error("Could not unpack detach request\n"); + return false; + } + + m_mme_gtpc->send_delete_session_request(ue_ctx->emm_ctx.imsi); + ue_ctx->emm_ctx.state = EMM_STATE_DEREGISTERED; + if(ue_ctx->ecm_ctx.mme_ue_s1ap_id!=0) + { + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(&ue_ctx->ecm_ctx, reply_msg); + } + return true; +} + +bool +s1ap_nas_transport::handle_nas_tracking_area_update_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri) +{ + m_s1ap_log->console("Warning: Tracking area update requests are not handled yet.\n"); + m_s1ap_log->warning("Tracking area update requests are not handled yet.\n"); + + std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); + if(it == m_s1ap->m_tmsi_to_imsi.end()) + { + m_s1ap_log->console("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + m_s1ap_log->error("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + return true; + } + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + emm_ctx->security_ctxt.ul_nas_count++;//Increment the NAS count, not to break the security ctx + return true; +} bool s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) { @@ -450,7 +976,9 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na LIBLTE_MME_AUTHENTICATION_RESPONSE_MSG_STRUCT auth_resp; bool ue_valid=true; - m_s1ap_log->console("Authentication Response -- IMSI %015lu\n", ue_ctx->imsi); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + m_s1ap_log->console("Authentication Response -- IMSI %015lu\n", emm_ctx->imsi); //Get NAS authentication response LIBLTE_ERROR_ENUM err = liblte_mme_unpack_authentication_response_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &auth_resp); @@ -467,25 +995,19 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na for(int i=0; i<8;i++) { - if(auth_resp.res[i] != ue_ctx->security_ctxt.xres[i]) + if(auth_resp.res[i] != emm_ctx->security_ctxt.xres[i]) { ue_valid = false; } } if(!ue_valid) { - std::cout<security_ctxt.xres[i]; - } - std::cout<info_hex(emm_ctx->security_ctxt.xres,8, "XRES"); m_s1ap_log->console("UE Authentication Rejected.\n"); m_s1ap_log->warning("UE Authentication Rejected.\n"); - //Send back Authentication Reject - pack_authentication_reject(reply_buffer, ue_ctx->enb_ue_s1ap_id, ue_ctx->mme_ue_s1ap_id); + + //Send back Athentication Reject + pack_authentication_reject(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); *reply_flag = true; m_s1ap_log->console("Downlink NAS: Sending Authentication Reject.\n"); return false; @@ -495,7 +1017,7 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na m_s1ap_log->console("UE Authentication Accepted.\n"); m_s1ap_log->info("UE Authentication Accepted.\n"); //Send Security Mode Command - pack_security_mode_command(reply_buffer, ue_ctx); + pack_security_mode_command(reply_buffer, emm_ctx, ecm_ctx); *reply_flag = true; m_s1ap_log->console("Downlink NAS: Sending NAS Security Mode Command.\n"); } @@ -505,6 +1027,10 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na bool s1ap_nas_transport::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) { + + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + LIBLTE_MME_SECURITY_MODE_COMPLETE_MSG_STRUCT sm_comp; //Get NAS authentication response @@ -514,19 +1040,17 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas return false; } - //TODO Check integrity - //TODO Handle imeisv if(sm_comp.imeisv_present) { m_s1ap_log->warning("IMEI-SV present but not handled"); } - m_s1ap_log->info("Security Mode Command Complete -- IMSI: %lu\n", ue_ctx->imsi); - m_s1ap_log->console("Security Mode Command Complete -- IMSI: %lu\n", ue_ctx->imsi); - if(ue_ctx->eit == true) + m_s1ap_log->info("Security Mode Command Complete -- IMSI: %lu\n", emm_ctx->imsi); + m_s1ap_log->console("Security Mode Command Complete -- IMSI: %lu\n", emm_ctx->imsi); + if(ecm_ctx->eit == true) { - pack_esm_information_request(reply_buffer, ue_ctx); + pack_esm_information_request(reply_buffer, emm_ctx, ecm_ctx); m_s1ap_log->console("Sending ESM information request\n"); m_s1ap_log->info("Sending ESM information request\n"); *reply_flag = true; @@ -535,12 +1059,13 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas { //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ctx->imsi, ue_ctx->mme_ue_s1ap_id); + m_mme_gtpc->send_create_session_request(emm_ctx->imsi); *reply_flag = false; //No reply needed } return true; } + bool s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { @@ -565,7 +1090,10 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u return false; } - m_s1ap_log->console("Unpacked Attached Complete Message\n"); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + m_s1ap_log->console("Unpacked Attached Complete Message. IMSI %" PRIu64 "\n", emm_ctx->imsi); m_s1ap_log->console("Unpacked Activate Default EPS Bearer message. EPS Bearer id %d\n",act_bearer.eps_bearer_id); //ue_ctx->erabs_ctx[act_bearer->eps_bearer_id].enb_fteid; if(act_bearer.eps_bearer_id < 5 || act_bearer.eps_bearer_id > 15) @@ -573,7 +1101,17 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u m_s1ap_log->error("EPS Bearer ID out of range\n"); return false; } - m_mme_gtpc->send_modify_bearer_request(&ue_ctx->erabs_ctx[act_bearer.eps_bearer_id]); + if(emm_ctx->state == EMM_STATE_DEREGISTERED) + { + //Attach requested from attach request + m_mme_gtpc->send_modify_bearer_request(emm_ctx->imsi, &ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); + //Send reply to eNB + m_s1ap_log->console("Packing EMM infromationi\n"); + *reply_flag = pack_emm_information(ue_ctx, reply_msg); + m_s1ap_log->console("Sending EMM infromation, bytes %d\n",reply_msg->N_bytes); + m_s1ap_log->info("Sending EMM infromation\n"); + } + emm_ctx->state = EMM_STATE_REGISTERED; return true; } @@ -591,18 +1129,18 @@ s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_m m_s1ap_log->info("ESM Info: EPS bearer id %d\n",esm_info_resp.eps_bearer_id); if(esm_info_resp.apn_present) { - m_s1ap_log->info("ESM Info: APN %s\n",esm_info_resp.eps_bearer_id); - m_s1ap_log->console("ESM Info: APN %s\n",esm_info_resp.eps_bearer_id); + m_s1ap_log->info("ESM Info: APN %d\n",esm_info_resp.eps_bearer_id); + m_s1ap_log->console("ESM Info: APN %d\n",esm_info_resp.eps_bearer_id); } if(esm_info_resp.protocol_cnfg_opts_present) { - m_s1ap_log->info("ESM Info: %d Protocol Configuration Options %s\n",esm_info_resp.protocol_cnfg_opts.N_opts); - m_s1ap_log->console("ESM Info: %d Protocol Configuration Options %s\n",esm_info_resp.protocol_cnfg_opts.N_opts); + m_s1ap_log->info("ESM Info: %d Protocol Configuration Options\n",esm_info_resp.protocol_cnfg_opts.N_opts); + m_s1ap_log->console("ESM Info: %d Protocol Configuration Options\n",esm_info_resp.protocol_cnfg_opts.N_opts); } //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ctx->imsi, ue_ctx->mme_ue_s1ap_id); + m_mme_gtpc->send_create_session_request(ue_ctx->emm_ctx.imsi); return true; } @@ -624,20 +1162,30 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ for(int i=0;i<=14;i++){ imsi += id_resp.mobile_id.imsi[i]*std::pow(10,14-i); } + + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + m_s1ap_log->info("Id Response -- IMSI: %015lu\n", imsi); m_s1ap_log->console("Id Response -- IMSI: %015lu\n", imsi); - ue_ctx->imsi = imsi; + + //Set UE's context IMSI + emm_ctx->imsi=imsi; + ecm_ctx->imsi = imsi; //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(imsi, ue_ctx->security_ctxt.k_asme, autn, rand, ue_ctx->security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) { m_s1ap_log->console("User not found. IMSI %015lu\n",imsi); m_s1ap_log->info("User not found. IMSI %015lu\n",imsi); return false; } - + + //Store UE context im IMSI map + m_s1ap->add_ue_ctx_to_imsi_map(ue_ctx); + //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_msg, ue_ctx->enb_ue_s1ap_id, ue_ctx->mme_ue_s1ap_id, autn, rand); + pack_authentication_request(reply_msg, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); //Send reply to eNB *reply_flag = true; @@ -653,13 +1201,6 @@ bool s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { - /* - LIBLTE_ERROR_ENUM err = liblte_mme_unpack_tracking_area_update_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &tau_req); - if(err != LIBLTE_SUCCESS){ - m_s1ap_log->error("Error unpacking NAS authentication response. Error: %s\n", liblte_error_text[err]); - return false; - } - */ m_s1ap_log->console("Warning: Tracking Area Update Request messages not handled yet.\n"); m_s1ap_log->warning("Warning: Tracking Area Update Request messages not handled yet.\n"); //Setup initiating message @@ -676,51 +1217,127 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->mme_ue_s1ap_id; - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->ecm_ctx.mme_ue_s1ap_id; + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->ecm_ctx.enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; //m_s1ap_log->console("Tracking area accept to MME-UE S1AP Id %d\n", ue_ctx->mme_ue_s1ap_id); - LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT tau_acc; - /*typedef struct{ - LIBLTE_MME_GPRS_TIMER_STRUCT t3412; - LIBLTE_MME_EPS_MOBILE_ID_STRUCT guti; - LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_STRUCT tai_list; - LIBLTE_MME_EPS_BEARER_CONTEXT_STATUS_STRUCT eps_bearer_context_status; - LIBLTE_MME_LOCATION_AREA_ID_STRUCT lai; - LIBLTE_MME_MOBILE_ID_STRUCT ms_id; - LIBLTE_MME_GPRS_TIMER_STRUCT t3402; - LIBLTE_MME_GPRS_TIMER_STRUCT t3423; - LIBLTE_MME_PLMN_LIST_STRUCT equivalent_plmns; - LIBLTE_MME_EMERGENCY_NUMBER_LIST_STRUCT emerg_num_list; - LIBLTE_MME_EPS_NETWORK_FEATURE_SUPPORT_STRUCT eps_network_feature_support; - LIBLTE_MME_GPRS_TIMER_3_STRUCT t3412_ext; - LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_ENUM additional_update_result; - uint8 eps_update_result; - uint8 emm_cause; - bool t3412_present; - bool guti_present; - bool tai_list_present; - bool eps_bearer_context_status_present; - bool lai_present; - bool ms_id_present; - bool emm_cause_present; - bool t3402_present; - bool t3423_present; - bool equivalent_plmns_present; - bool emerg_num_list_present; - bool eps_network_feature_support_present; - bool additional_update_result_present; - bool t3412_ext_present; -}LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT; -*/ - //Send reply to eNB - //*reply_flag = true; + + //Get decimal MCC and MNC + uint32_t mcc = 0; + mcc += 0x000F & m_s1ap->m_s1ap_args.mcc; + mcc += 10*( (0x00F0 & m_s1ap->m_s1ap_args.mcc) >> 4); + mcc += 100*( (0x0F00 & m_s1ap->m_s1ap_args.mcc) >> 8); + + uint32_t mnc = 0; + if( 0xFF00 == (m_s1ap->m_s1ap_args.mnc & 0xFF00 )) + { + //Two digit MNC + mnc += 0x000F & m_s1ap->m_s1ap_args.mnc; + mnc += 10*((0x00F0 & m_s1ap->m_s1ap_args.mnc) >> 4); + } + else + { + //Three digit MNC + mnc += 0x000F & m_s1ap->m_s1ap_args.mnc; + mnc += 10*((0x00F0 & m_s1ap->m_s1ap_args.mnc) >> 4); + mnc += 100*((0x0F00 & m_s1ap->m_s1ap_args.mnc) >> 8); + } + + //T3412 Timer + tau_acc.t3412_present = true; + tau_acc.t3412.unit = LIBLTE_MME_GPRS_TIMER_UNIT_1_MINUTE; // GPRS 1 minute unit + tau_acc.t3412.value = 30; // 30 minute periodic timer + + //GUTI + tau_acc.guti_present=true; + tau_acc.guti.type_of_id = 6; //110 -> GUTI + tau_acc.guti.guti.mcc = mcc; + tau_acc.guti.guti.mnc = mnc; + tau_acc.guti.guti.mme_group_id = m_s1ap->m_s1ap_args.mme_group; + tau_acc.guti.guti.mme_code = m_s1ap->m_s1ap_args.mme_code; + tau_acc.guti.guti.m_tmsi = 0xF000; + m_s1ap_log->debug("Allocated GUTI: MCC %d, MNC %d, MME Group Id %d, MME Code 0x%x, M-TMSI 0x%x\n", + tau_acc.guti.guti.mcc, + tau_acc.guti.guti.mnc, + tau_acc.guti.guti.mme_group_id, + tau_acc.guti.guti.mme_code, + tau_acc.guti.guti.m_tmsi); + + //Unused Options + tau_acc.t3402_present = false; + tau_acc.t3423_present = false; + tau_acc.equivalent_plmns_present = false; + tau_acc.emerg_num_list_present = false; + tau_acc.eps_network_feature_support_present = false; + tau_acc.additional_update_result_present = false; + tau_acc.t3412_ext_present = false; return true; } +bool +s1ap_nas_transport::short_integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu) +{ + uint8_t exp_mac[4]; + uint8_t *mac = &pdu->msg[2]; + int i; + + srslte::security_128_eia1(&emm_ctx->security_ctxt.k_nas_int[16], + emm_ctx->security_ctxt.ul_nas_count, + 0, + SECURITY_DIRECTION_UPLINK, + &pdu->msg[0], + 2, + &exp_mac[0]); + + // Check if expected mac equals the sent mac + for(i=0; i<2; i++){ + if(exp_mac[i+2] != mac[i]){ + m_s1ap_log->warning("Short integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " + "Received: count=%d, [%02x %02x]\n", + emm_ctx->security_ctxt.ul_nas_count, exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], + pdu->msg[1] & 0x1F, mac[0], mac[1]); + return false; + } + } + m_s1ap_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", + emm_ctx->security_ctxt.ul_nas_count, pdu->msg[1] & 0x1F); + return true; +} + + +bool +s1ap_nas_transport::integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu) +{ + uint8_t exp_mac[4]; + uint8_t *mac = &pdu->msg[1]; + int i; + + srslte::security_128_eia1(&emm_ctx->security_ctxt.k_nas_int[16], + emm_ctx->security_ctxt.ul_nas_count, + 0, + SECURITY_DIRECTION_UPLINK, + &pdu->msg[5], + pdu->N_bytes-5, + &exp_mac[0]); + + // Check if expected mac equals the sent mac + for(i=0; i<4; i++){ + if(exp_mac[i] != mac[i]){ + m_s1ap_log->warning("Integrity check failure. UL Local: count=%d, [%02x %02x %02x %02x], " + "Received: UL count=%d, [%02x %02x %02x %02x]\n", + emm_ctx->security_ctxt.ul_nas_count, exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], + pdu->msg[5], mac[0], mac[1], mac[2], mac[3]); + return false; + } + } + m_s1ap_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", + emm_ctx->security_ctxt.ul_nas_count, pdu->msg[5]); + return true; +} + bool s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) @@ -736,6 +1353,8 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg return false; } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; switch(auth_fail.emm_cause){ case 20: @@ -753,22 +1372,21 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg m_s1ap_log->error("Missing fail parameter\n"); return false; } - if(!m_hss->resync_sqn(ue_ctx->imsi, auth_fail.auth_fail_param)) + if(!m_hss->resync_sqn(emm_ctx->imsi, auth_fail.auth_fail_param)) { - m_s1ap_log->console("Resynchronization failed. IMSI %015lu\n", ue_ctx->imsi); - m_s1ap_log->info("Resynchronization failed. IMSI %015lu\n", ue_ctx->imsi); + m_s1ap_log->console("Resynchronization failed. IMSI %015lu\n", emm_ctx->imsi); + m_s1ap_log->info("Resynchronization failed. IMSI %015lu\n", emm_ctx->imsi); return false; } //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(ue_ctx->imsi, ue_ctx->security_ctxt.k_asme, autn, rand, ue_ctx->security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(emm_ctx->imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) { - m_s1ap_log->console("User not found. IMSI %015lu\n", ue_ctx->imsi); - m_s1ap_log->info("User not found. IMSI %015lu\n", ue_ctx->imsi); + m_s1ap_log->console("User not found. IMSI %015lu\n", emm_ctx->imsi); + m_s1ap_log->info("User not found. IMSI %015lu\n", emm_ctx->imsi); return false; } - //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_msg, ue_ctx->enb_ue_s1ap_id, ue_ctx->mme_ue_s1ap_id, autn, rand); + pack_authentication_request(reply_msg, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); //Send reply to eNB *reply_flag = true; @@ -777,11 +1395,15 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg //TODO Start T3460 Timer! break; - } - return true; - + } + return true; } - + /* +bool +s1ap_nas_transport::handle_detach_request(nas_msg, ue_ctx, reply_buffer, reply_flag) +{ + return true; + }*/ /*Packing/Unpacking helper functions*/ bool s1ap_nas_transport::pack_authentication_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t next_mme_ue_s1ap_id, uint8_t *autn, uint8_t *rand) @@ -919,7 +1541,7 @@ s1ap_nas_transport::unpack_authentication_response(LIBLTE_S1AP_MESSAGE_UPLINKNAS } bool -s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx) +s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); @@ -937,8 +1559,8 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->mme_ue_s1ap_id; - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id; + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; @@ -952,14 +1574,14 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, sm_cmd.nas_ksi.nas_ksi=0; //Replay UE security cap - memcpy(sm_cmd.ue_security_cap.eea,ue_ctx->ue_network_cap.eea,8*sizeof(bool)); - memcpy(sm_cmd.ue_security_cap.eia,ue_ctx->ue_network_cap.eia,8*sizeof(bool)); - sm_cmd.ue_security_cap.uea_present = ue_ctx->ue_network_cap.uea_present; - memcpy(sm_cmd.ue_security_cap.uea,ue_ctx->ue_network_cap.uea,8*sizeof(bool)); - sm_cmd.ue_security_cap.uia_present = ue_ctx->ue_network_cap.uia_present; - memcpy(sm_cmd.ue_security_cap.uia,ue_ctx->ue_network_cap.uia,8*sizeof(bool)); - sm_cmd.ue_security_cap.gea_present = ue_ctx->ms_network_cap_present; - memcpy(sm_cmd.ue_security_cap.gea,ue_ctx->ms_network_cap.gea,8*sizeof(bool)); + memcpy(sm_cmd.ue_security_cap.eea,ue_emm_ctx->security_ctxt.ue_network_cap.eea,8*sizeof(bool)); + memcpy(sm_cmd.ue_security_cap.eia,ue_emm_ctx->security_ctxt.ue_network_cap.eia,8*sizeof(bool)); + sm_cmd.ue_security_cap.uea_present = ue_emm_ctx->security_ctxt.ue_network_cap.uea_present; + memcpy(sm_cmd.ue_security_cap.uea,ue_emm_ctx->security_ctxt.ue_network_cap.uea,8*sizeof(bool)); + sm_cmd.ue_security_cap.uia_present = ue_emm_ctx->security_ctxt.ue_network_cap.uia_present; + memcpy(sm_cmd.ue_security_cap.uia,ue_emm_ctx->security_ctxt.ue_network_cap.uia,8*sizeof(bool)); + sm_cmd.ue_security_cap.gea_present = ue_emm_ctx->security_ctxt.ms_network_cap_present; + memcpy(sm_cmd.ue_security_cap.gea,ue_emm_ctx->security_ctxt.ms_network_cap.gea,8*sizeof(bool)); sm_cmd.imeisv_req_present=false; sm_cmd.nonce_ue_present=false; @@ -967,28 +1589,35 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, uint8_t sec_hdr_type=3; - ue_ctx->security_ctxt.dl_nas_count = 0; - LIBLTE_ERROR_ENUM err = liblte_mme_pack_security_mode_command_msg(&sm_cmd,sec_hdr_type, ue_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + // ue_emm_ctx->security_ctxt.dl_nas_count = 0; + LIBLTE_ERROR_ENUM err = liblte_mme_pack_security_mode_command_msg(&sm_cmd,sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { m_s1ap_log->console("Error packing Authentication Request\n"); return false; } - //Generate MAC for integrity protection - //FIXME Write wrapper to support EIA1, EIA2, etc. - //TODO which is the RB ID? Standard says a constant, but which? + //Generate EPS security context uint8_t mac[4]; - - srslte::security_generate_k_nas( ue_ctx->security_ctxt.k_asme, + srslte::security_generate_k_nas( ue_emm_ctx->security_ctxt.k_asme, srslte::CIPHERING_ALGORITHM_ID_EEA0, srslte::INTEGRITY_ALGORITHM_ID_128_EIA1, - ue_ctx->security_ctxt.k_nas_enc, - ue_ctx->security_ctxt.k_nas_int + ue_emm_ctx->security_ctxt.k_nas_enc, + ue_emm_ctx->security_ctxt.k_nas_int ); - - srslte::security_128_eia1 (&ue_ctx->security_ctxt.k_nas_int[16], - ue_ctx->security_ctxt.dl_nas_count, + srslte::security_generate_k_nas( ue_emm_ctx->security_ctxt.k_asme, + srslte::CIPHERING_ALGORITHM_ID_EEA0, + srslte::INTEGRITY_ALGORITHM_ID_128_EIA1, + ue_emm_ctx->security_ctxt.k_nas_enc, + ue_emm_ctx->security_ctxt.k_nas_int + ); + uint8_t key_enb[32]; + liblte_security_generate_k_enb(ue_emm_ctx->security_ctxt.k_asme, ue_emm_ctx->security_ctxt.ul_nas_count, ue_emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); + //Generate MAC for integrity protection + //FIXME Write wrapper to support EIA1, EIA2, etc. + srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], + ue_emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], @@ -1014,7 +1643,7 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, } bool -s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx) +s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); @@ -1032,19 +1661,20 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->mme_ue_s1ap_id;//FIXME Change name - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id;//FIXME Change name + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; LIBLTE_MME_ESM_INFORMATION_REQUEST_MSG_STRUCT esm_info_req; - esm_info_req.eps_bearer_id = 0; - esm_info_req.proc_transaction_id = ue_ctx->procedure_transaction_id; + esm_info_req.eps_bearer_id=0; + esm_info_req.proc_transaction_id = ue_emm_ctx->procedure_transaction_id; + uint8_t sec_hdr_type=2; - ue_ctx->security_ctxt.dl_nas_count++; + ue_emm_ctx->security_ctxt.dl_nas_count++; - LIBLTE_ERROR_ENUM err = srslte_mme_pack_esm_information_request_msg(&esm_info_req, sec_hdr_type,ue_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + LIBLTE_ERROR_ENUM err = srslte_mme_pack_esm_information_request_msg(&esm_info_req, sec_hdr_type,ue_emm_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { m_s1ap_log->error("Error packing ESM information request\n"); @@ -1053,8 +1683,8 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms } uint8_t mac[4]; - srslte::security_128_eia1 (&ue_ctx->security_ctxt.k_nas_int[16], - ue_ctx->security_ctxt.dl_nas_count, + srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], + ue_emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], @@ -1081,7 +1711,7 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms } bool -s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer) { +s1ap_nas_transport::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) { LIBLTE_MME_ATTACH_ACCEPT_MSG_STRUCT attach_accept; LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT act_def_eps_bearer_context_req; //bzero(&act_def_eps_bearer_context_req,sizeof(LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT)); @@ -1110,8 +1740,8 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE } //Attach accept - attach_accept.eps_attach_result = ue_ctx->attach_type; - //Mandatory + attach_accept.eps_attach_result = ue_emm_ctx->attach_type; + //FIXME: Set t3412 from config attach_accept.t3412.unit = LIBLTE_MME_GPRS_TIMER_UNIT_1_MINUTE; // GPRS 1 minute unit attach_accept.t3412.value = 30; // 30 minute periodic timer @@ -1128,7 +1758,7 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE attach_accept.guti.guti.mnc = mnc; attach_accept.guti.guti.mme_group_id = m_s1ap->m_s1ap_args.mme_group; attach_accept.guti.guti.mme_code = m_s1ap->m_s1ap_args.mme_code; - attach_accept.guti.guti.m_tmsi = m_s1ap->allocate_m_tmsi(ue_ctx->mme_ue_s1ap_id); + attach_accept.guti.guti.m_tmsi = m_s1ap->allocate_m_tmsi(ue_emm_ctx->imsi); m_s1ap_log->debug("Allocated GUTI: MCC %d, MNC %d, MME Group Id %d, MME Code 0x%x, M-TMSI 0x%x\n", attach_accept.guti.guti.mcc, attach_accept.guti.guti.mnc, @@ -1136,10 +1766,23 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE attach_accept.guti.guti.mme_code, attach_accept.guti.guti.m_tmsi); - //Make sure all unused options are set to false - attach_accept.lai_present=false; - attach_accept.ms_id_present=false; + //Set EMM cause to no CS available attach_accept.emm_cause_present=false; + //attach_accept.emm_cause_present=true; + //attach_accept.emm_cause=18; + + //Set up LAI for combined EPS/IMSI attach + //attach_accept.lai_present=false; + attach_accept.lai_present=true; + attach_accept.lai.mcc = mcc; + attach_accept.lai.mnc = mnc; + attach_accept.lai.lac = 001; + + attach_accept.ms_id_present=true; + attach_accept.ms_id.type_of_id = LIBLTE_MME_MOBILE_ID_TYPE_TMSI; + attach_accept.ms_id.tmsi = attach_accept.guti.guti.m_tmsi; + + //Make sure all unused options are set to false attach_accept.t3402_present=false; attach_accept.t3423_present=false; attach_accept.equivalent_plmns_present=false; @@ -1161,20 +1804,20 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE act_def_eps_bearer_context_req.eps_qos.mbr_dl = 254; //FIXME act_def_eps_bearer_context_req.eps_qos.mbr_ul_ext = 250; //FIXME act_def_eps_bearer_context_req.eps_qos.mbr_dl_ext = 250; //FIXME check + //set apn - //act_def_eps_bearer_context_req.apn act_def_eps_bearer_context_req.apn.apn = m_s1ap->m_s1ap_args.mme_apn; - act_def_eps_bearer_context_req.proc_transaction_id = ue_ctx->procedure_transaction_id; //FIXME + act_def_eps_bearer_context_req.proc_transaction_id = ue_emm_ctx->procedure_transaction_id; //FIXME //Set DNS server act_def_eps_bearer_context_req.protocol_cnfg_opts_present = true; act_def_eps_bearer_context_req.protocol_cnfg_opts.N_opts = 1; act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].id = 0x0d; act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].len = 4; - act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[0] = 8; - act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[1] = 8; - act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[2] = 8; - act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[3] = 8; + + struct sockaddr_in dns_addr; + inet_pton(AF_INET, m_s1ap->m_s1ap_args.dns_addr.c_str(), &(dns_addr.sin_addr)); + memcpy(act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents,&dns_addr.sin_addr.s_addr, 4); //Make sure all unused options are set to false act_def_eps_bearer_context_req.negotiated_qos_present = false; @@ -1186,13 +1829,13 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE act_def_eps_bearer_context_req.connectivity_type_present = false; uint8_t sec_hdr_type =2; - ue_ctx->security_ctxt.dl_nas_count++; + ue_emm_ctx->security_ctxt.dl_nas_count++; liblte_mme_pack_activate_default_eps_bearer_context_request_msg(&act_def_eps_bearer_context_req, &attach_accept.esm_msg); - liblte_mme_pack_attach_accept_msg(&attach_accept, sec_hdr_type, ue_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + liblte_mme_pack_attach_accept_msg(&attach_accept, sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); //Integrity protect NAS message uint8_t mac[4]; - srslte::security_128_eia1 (&ue_ctx->security_ctxt.k_nas_int[16], - ue_ctx->security_ctxt.dl_nas_count, + srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], + ue_emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], @@ -1263,10 +1906,12 @@ s1ap_nas_transport::pack_identity_request(srslte::byte_buffer_t *reply_msg, uint } bool -s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id) +s1ap_nas_transport::pack_emm_information( ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_msg) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; //Setup initiating message LIBLTE_S1AP_S1AP_PDU_STRUCT tx_pdu; bzero(&tx_pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); @@ -1281,14 +1926,14 @@ s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint3 //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = mme_ue_s1ap_id;//FIXME Change name - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ecm_ctx->mme_ue_s1ap_id;//FIXME Change name + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ecm_ctx->enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; LIBLTE_MME_EMM_INFORMATION_MSG_STRUCT emm_info; emm_info.full_net_name_present = true; - emm_info.full_net_name.name = std::string("srsLTE"); + emm_info.full_net_name.name = std::string("Software Radio Systems LTE"); emm_info.full_net_name.add_ci = LIBLTE_MME_ADD_CI_DONT_ADD; emm_info.short_net_name_present = true; emm_info.short_net_name.name = std::string("srsLTE"); @@ -1298,25 +1943,19 @@ s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint3 emm_info.utc_and_local_time_zone_present = false; emm_info.net_dst_present = false; - //Integrity check - ue_ctx_t * ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); - if(ue_ctx == NULL) - { - return false; - } uint8_t sec_hdr_type =2; - ue_ctx->security_ctxt.dl_nas_count++; - LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, ue_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + emm_ctx->security_ctxt.dl_nas_count++; + LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { - m_s1ap_log->error("Error packing Identity Request\n"); - m_s1ap_log->console("Error packing Identity REquest\n"); + m_s1ap_log->error("Error packing EMM Information\n"); + m_s1ap_log->console("Error packing EMM Information\n"); return false; } uint8_t mac[4]; - srslte::security_128_eia1 (&ue_ctx->security_ctxt.k_nas_int[16], - ue_ctx->security_ctxt.dl_nas_count, + srslte::security_128_eia1 (&emm_ctx->security_ctxt.k_nas_int[16], + emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], @@ -1325,9 +1964,20 @@ s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint3 ); memcpy(&nas_buffer->msg[1],mac,4); + //Copy NAS PDU to Downlink NAS Trasport message buffer + memcpy(dw_nas->NAS_PDU.buffer, nas_buffer->msg, nas_buffer->N_bytes); + dw_nas->NAS_PDU.n_octets = nas_buffer->N_bytes; + //Pack Downlink NAS Transport Message + err = liblte_s1ap_pack_s1ap_pdu(&tx_pdu, (LIBLTE_BYTE_MSG_STRUCT *) reply_msg); + if(err != LIBLTE_SUCCESS) + { + m_s1ap_log->error("Error packing Dw NAS Transport: EMM Info\n"); + m_s1ap_log->console("Error packing Downlink NAS Transport: EMM Info\n"); + return false; + } - m_s1ap_log->info("Packed \n"); + m_s1ap_log->info("Packed UE EMM information\n"); return true; } diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index add16b2c4..cbd3e524b 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -34,14 +33,15 @@ #include #include #include -#include "spgw/spgw.h" -#include "mme/mme_gtpc.h" +#include // for printing uint64_t +#include "srsepc/hdr/spgw/spgw.h" +#include "srsepc/hdr/mme/mme_gtpc.h" #include "srslte/upper/gtpu.h" namespace srsepc{ spgw* spgw::m_instance = NULL; -boost::mutex spgw_instance_mutex; +pthread_mutex_t spgw_instance_mutex = PTHREAD_MUTEX_INITIALIZER; const uint16_t SPGW_BUFFER_SIZE = 2500; @@ -63,21 +63,23 @@ spgw::~spgw() spgw* spgw::get_instance(void) { - boost::mutex::scoped_lock lock(spgw_instance_mutex); + pthread_mutex_lock(&spgw_instance_mutex); if(NULL == m_instance) { m_instance = new spgw(); } + pthread_mutex_unlock(&spgw_instance_mutex); return(m_instance); } void spgw::cleanup(void) { - boost::mutex::scoped_lock lock(spgw_instance_mutex); + pthread_mutex_lock(&spgw_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&spgw_instance_mutex); } int @@ -144,8 +146,8 @@ spgw::stop() std::map::iterator it = m_teid_to_tunnel_ctx.begin(); //Map control TEID to tunnel ctx. Usefull to get reply ctrl TEID, UE IP, etc. while(it!=m_teid_to_tunnel_ctx.end()) { - m_spgw_log->info("Deleting SP-GW Tunnel. IMSI: %lu\n", it->second->imsi); - m_spgw_log->console("Deleting SP-GW Tunnel. IMSI: %lu\n", it->second->imsi); + m_spgw_log->info("Deleting SP-GW GTP-C Tunnel. IMSI: %lu\n", it->second->imsi); + m_spgw_log->console("Deleting SP-GW GTP-C Tunnel. IMSI: %lu\n", it->second->imsi); delete it->second; m_teid_to_tunnel_ctx.erase(it++); } @@ -224,6 +226,9 @@ spgw::init_sgi_if(spgw_args_t *args) return srslte::ERROR_CANT_START; } + //Set initial time of setup + gettimeofday(&m_t_last_dl, NULL); + m_sgi_up = true; return(srslte::ERROR_NONE); } @@ -297,15 +302,11 @@ spgw::run_thread() if (FD_ISSET(m_s1u, &set)) { msg->N_bytes = recvfrom(m_s1u, msg->msg, SRSLTE_MAX_BUFFER_SIZE_BYTES, 0, &src_addr, &addrlen ); - //m_spgw_log->console("Received PDU from S1-U. Bytes %d\n", msg->N_bytes); - //m_spgw_log->debug("Received PDU from S1-U. Bytes %d\n", msg->N_bytes); handle_s1u_pdu(msg); } if (FD_ISSET(m_sgi_if, &set)) { msg->N_bytes = read(sgi, msg->msg, SRSLTE_MAX_BUFFER_SIZE_BYTES); - //m_spgw_log->console("Received PDU from SGi. Bytes %d\n", msg->N_bytes); - //m_spgw_log->debug("Received PDU from SGi. Bytes %d\n", msg->N_bytes); handle_sgi_pdu(msg); } } @@ -328,6 +329,8 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) bool ip_found = false; srslte::gtpc_f_teid_ie enb_fteid; + struct timeval t_now, t_delta; + version = msg->msg[0]>>4; ((uint8_t*)&dest_ip)[0] = msg->msg[16]; ((uint8_t*)&dest_ip)[1] = msg->msg[17]; @@ -380,8 +383,10 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) m_spgw_log->error("Error sending packet to eNB\n"); return; } - //m_spgw_log->console("Sent packet to %s:%d. Bytes=%d/%d\n",inet_ntoa(enb_addr.sin_addr), GTPU_RX_PORT,n,msg->N_bytes); - + else if((unsigned int) n!=msg->N_bytes) + { + m_spgw_log->error("Mis-match between packet bytes and sent bytes: Sent: %d, Packet: %d \n",n,msg->N_bytes); + } return; } @@ -397,7 +402,7 @@ spgw::handle_s1u_pdu(srslte::byte_buffer_t *msg) int n = write(m_sgi_if, msg->msg, msg->N_bytes); if(n<0) { - m_spgw_log->error("Could not write to TUN interface.\n",n); + m_spgw_log->error("Could not write to TUN interface.\n"); } else { @@ -405,6 +410,10 @@ spgw::handle_s1u_pdu(srslte::byte_buffer_t *msg) } return; } + +/* + * Helper Functions + */ uint64_t spgw::get_new_ctrl_teid() { @@ -424,61 +433,115 @@ spgw::get_new_ue_ipv4() return ntohl(m_h_next_ue_ip);//FIXME Tmp hack } -void -spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu) +spgw_tunnel_ctx_t* +spgw::create_gtp_ctx(struct srslte::gtpc_create_session_request *cs_req) { - srslte::gtpc_header *header = &cs_resp_pdu->header; - srslte::gtpc_create_session_response *cs_resp = &cs_resp_pdu->choice.create_session_response; - - - m_spgw_log->info("Received Create Session Request\n"); - //Setup uplink control TEID + //Setup uplink control TEID uint64_t spgw_uplink_ctrl_teid = get_new_ctrl_teid(); //Setup uplink user TEID uint64_t spgw_uplink_user_teid = get_new_user_teid(); //Allocate UE IP in_addr_t ue_ip = get_new_ue_ipv4(); - + //in_addr_t ue_ip = inet_addr("172.16.0.2"); uint8_t default_bearer_id = 5; + m_spgw_log->console("SPGW: Allocated Ctrl TEID %" PRIu64 "\n", spgw_uplink_ctrl_teid); + m_spgw_log->console("SPGW: Allocated User TEID %" PRIu64 "\n", spgw_uplink_user_teid); + struct in_addr ue_ip_; + ue_ip_.s_addr=ue_ip; + m_spgw_log->console("SPGW: Allocate UE IP %s\n", inet_ntoa(ue_ip_)); + + //Save the UE IP to User TEID map spgw_tunnel_ctx_t *tunnel_ctx = new spgw_tunnel_ctx_t; + bzero(tunnel_ctx,sizeof(spgw_tunnel_ctx_t)); + tunnel_ctx->imsi = cs_req->imsi; tunnel_ctx->ebi = default_bearer_id; tunnel_ctx->up_user_fteid.teid = spgw_uplink_user_teid; tunnel_ctx->up_user_fteid.ipv4 = m_s1u_addr.sin_addr.s_addr; tunnel_ctx->dw_ctrl_fteid.teid = cs_req->sender_f_teid.teid; tunnel_ctx->dw_ctrl_fteid.ipv4 = cs_req->sender_f_teid.ipv4; - + tunnel_ctx->up_ctrl_fteid.teid = spgw_uplink_ctrl_teid; tunnel_ctx->ue_ipv4 = ue_ip; m_teid_to_tunnel_ctx.insert(std::pair(spgw_uplink_ctrl_teid,tunnel_ctx)); + m_imsi_to_ctr_teid.insert(std::pair(cs_req->imsi,spgw_uplink_ctrl_teid)); + return tunnel_ctx; +} + +bool +spgw::delete_gtp_ctx(uint32_t ctrl_teid) +{ + spgw_tunnel_ctx_t *tunnel_ctx; + if(!m_teid_to_tunnel_ctx.count(ctrl_teid)){ + m_spgw_log->error("Could not find GTP context to delete.\n"); + return false; + } + tunnel_ctx = m_teid_to_tunnel_ctx[ctrl_teid]; + + //Remove GTP-U connections, if any. + if(m_ip_to_teid.count(tunnel_ctx->ue_ipv4)) + { + pthread_mutex_lock(&m_mutex); + m_ip_to_teid.erase(tunnel_ctx->ue_ipv4); + pthread_mutex_unlock(&m_mutex); + } + //Remove Ctrl TEID from IMSI to control TEID map + m_imsi_to_ctr_teid.erase(tunnel_ctx->imsi); + + //Remove GTP context from control TEID mapping + m_teid_to_tunnel_ctx.erase(ctrl_teid); + delete tunnel_ctx; + return true; +} + +void +spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu) +{ + m_spgw_log->info("Received Create Session Request\n"); + spgw_tunnel_ctx_t *tunnel_ctx; + int default_bearer_id = 5; + //Check if IMSI has active GTP-C and/or GTP-U + bool gtpc_present = m_imsi_to_ctr_teid.count(cs_req->imsi); + if(gtpc_present) + { + m_spgw_log->console("SPGW: GTP-C context for IMSI %015lu already exists.\n", cs_req->imsi); + delete_gtp_ctx(m_imsi_to_ctr_teid[cs_req->imsi]); + m_spgw_log->console("SPGW: Deleted previous context.\n"); + } + + m_spgw_log->info("Creating new GTP-C context\n"); + tunnel_ctx = create_gtp_ctx(cs_req); //Create session response message + srslte::gtpc_header *header = &cs_resp_pdu->header; + srslte::gtpc_create_session_response *cs_resp = &cs_resp_pdu->choice.create_session_response; + //Setup GTP-C header header->piggyback = false; header->teid_present = true; - header->teid = cs_req->sender_f_teid.teid; //Send create session requesponse to the CS Request TEID + header->teid = tunnel_ctx->dw_ctrl_fteid.teid; //Send create session requesponse to the UE's MME Ctrl TEID header->type = srslte::GTPC_MSG_TYPE_CREATE_SESSION_RESPONSE; + //Initialize to zero bzero(cs_resp,sizeof(struct srslte::gtpc_create_session_response)); //Setup Cause cs_resp->cause.cause_value = srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED; //Setup sender F-TEID (ctrl) cs_resp->sender_f_teid.ipv4_present = true; - cs_resp->sender_f_teid.teid = spgw_uplink_ctrl_teid; - cs_resp->sender_f_teid.ipv4 = 0;//FIXME This is not relevant, as the GTP-C is not transmitted over sockets yet. + cs_resp->sender_f_teid = tunnel_ctx->up_ctrl_fteid; + //Bearer context created cs_resp->eps_bearer_context_created.ebi = default_bearer_id; cs_resp->eps_bearer_context_created.cause.cause_value = srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED; cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present=true; - cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.teid = spgw_uplink_user_teid; - cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4 = m_s1u_addr.sin_addr.s_addr; + cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid = tunnel_ctx->up_user_fteid; //Fill in the PAA cs_resp->paa_present = true; cs_resp->paa.pdn_type = srslte::GTPC_PDN_TYPE_IPV4; cs_resp->paa.ipv4_present = true; - cs_resp->paa.ipv4 = ue_ip; + cs_resp->paa.ipv4 = tunnel_ctx->ue_ipv4; m_spgw_log->info("Sending Create Session Response\n"); m_mme_gtpc->handle_create_session_response(cs_resp_pdu); return; @@ -523,8 +586,10 @@ spgw::handle_modify_bearer_request(struct srslte::gtpc_pdu *mb_req_pdu, struct s m_spgw_log->info("eNB Rx User TEID 0x%x, eNB Rx User IP %s\n", tunnel_ctx->dw_user_fteid.teid, inet_ntoa(addr3)); //Setup IP to F-TEID map + //bool ret = false; pthread_mutex_lock(&m_mutex); - m_ip_to_teid.insert(std::pair(tunnel_ctx->ue_ipv4, tunnel_ctx->dw_user_fteid)); + m_ip_to_teid[tunnel_ctx->ue_ipv4]=tunnel_ctx->dw_user_fteid; + //ret = m_ip_to_teid.insert(std::pair(tunnel_ctx->ue_ipv4, tunnel_ctx->dw_user_fteid)); pthread_mutex_unlock(&m_mutex); //Setting up Modify bearer response PDU @@ -559,7 +624,7 @@ spgw::handle_delete_session_request(struct srslte::gtpc_pdu *del_req_pdu, struct //Delete data tunnel pthread_mutex_lock(&m_mutex); - std::map::iterator data_it = m_ip_to_teid.find(tunnel_ctx->ue_ipv4); + std::map::iterator data_it = m_ip_to_teid.find(tunnel_ctx->ue_ipv4); if(data_it != m_ip_to_teid.end()) { m_ip_to_teid.erase(data_it); @@ -571,4 +636,31 @@ spgw::handle_delete_session_request(struct srslte::gtpc_pdu *del_req_pdu, struct return; } +void +spgw::handle_release_access_bearers_request(struct srslte::gtpc_pdu *rel_req_pdu, struct srslte::gtpc_pdu *rel_resp_pdu) +{ + //Find tunel ctxt + uint32_t ctrl_teid = rel_req_pdu->header.teid; + std::map::iterator tunnel_it = m_teid_to_tunnel_ctx.find(ctrl_teid); + if(tunnel_it == m_teid_to_tunnel_ctx.end()) + { + m_spgw_log->warning("Could not find TEID %d to release bearers from\n",ctrl_teid); + return; + } + spgw_tunnel_ctx_t *tunnel_ctx = tunnel_it->second; + in_addr_t ue_ipv4 = tunnel_ctx->ue_ipv4; + + //Delete data tunnel + pthread_mutex_lock(&m_mutex); + std::map::iterator data_it = m_ip_to_teid.find(tunnel_ctx->ue_ipv4); + if(data_it != m_ip_to_teid.end()) + { + m_ip_to_teid.erase(data_it); + } + pthread_mutex_unlock(&m_mutex); + + //Do NOT delete control tunnel + return; +} + } //namespace srsepc diff --git a/srsue/CMakeLists.txt b/srsue/CMakeLists.txt index 85f391d6b..07a5f6b8f 100644 --- a/srsue/CMakeLists.txt +++ b/srsue/CMakeLists.txt @@ -31,7 +31,7 @@ endif() include_directories( ${Boost_INCLUDE_DIRS} ${SEC_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR}/srsue/hdr + ${PROJECT_SOURCE_DIR} ) link_directories( diff --git a/srsue/hdr/mac/demux.h b/srsue/hdr/mac/demux.h index fb38990ec..c738a0fd3 100644 --- a/srsue/hdr/mac/demux.h +++ b/srsue/hdr/mac/demux.h @@ -24,8 +24,8 @@ * */ -#ifndef DEMUX_H -#define DEMUX_H +#ifndef SRSUE_DEMUX_H +#define SRSUE_DEMUX_H #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/pdu_queue.h" @@ -86,7 +86,7 @@ private: } // namespace srsue -#endif // DEMUX_H +#endif // SRSUE_DEMUX_H diff --git a/srsue/hdr/mac/dl_harq.h b/srsue/hdr/mac/dl_harq.h index cfdfdfc5f..37eadad91 100644 --- a/srsue/hdr/mac/dl_harq.h +++ b/srsue/hdr/mac/dl_harq.h @@ -24,8 +24,8 @@ * */ -#ifndef DL_HARQ_H -#define DL_HARQ_H +#ifndef SRSUE_DL_HARQ_H +#define SRSUE_DL_HARQ_H #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) @@ -34,8 +34,8 @@ #include "srslte/common/log.h" #include "srslte/common/timers.h" -#include "mac/demux.h" -#include "mac/dl_sps.h" +#include "demux.h" +#include "dl_sps.h" #include "srslte/common/mac_pcap.h" #include "srslte/interfaces/ue_interfaces.h" @@ -447,4 +447,4 @@ private: } // namespace srsue -#endif // DL_HARQ_H +#endif // SRSUE_DL_HARQ_H diff --git a/srsue/hdr/mac/dl_sps.h b/srsue/hdr/mac/dl_sps.h index 8ec83cb52..dd6328fdc 100644 --- a/srsue/hdr/mac/dl_sps.h +++ b/srsue/hdr/mac/dl_sps.h @@ -24,8 +24,8 @@ * */ -#ifndef DL_SPS_H -#define DL_SPS_H +#ifndef SRSUE_DL_SPS_H +#define SRSUE_DL_SPS_H #include "srslte/common/log.h" #include "srslte/common/timers.h" @@ -50,4 +50,4 @@ private: } // namespace srsue -#endif // DL_SPS_H +#endif // SRSUE_DL_SPS_H diff --git a/srsue/hdr/mac/mac.h b/srsue/hdr/mac/mac.h index 4bf888e49..4f5014532 100644 --- a/srsue/hdr/mac/mac.h +++ b/srsue/hdr/mac/mac.h @@ -24,20 +24,20 @@ * */ -#ifndef MAC_H -#define MAC_H +#ifndef SRSUE_MAC_H +#define SRSUE_MAC_H #include "srslte/common/log.h" -#include "mac/dl_harq.h" -#include "mac/ul_harq.h" +#include "dl_harq.h" +#include "ul_harq.h" #include "srslte/common/timers.h" -#include "mac/mac_metrics.h" -#include "mac/proc_ra.h" -#include "mac/proc_sr.h" -#include "mac/proc_bsr.h" -#include "mac/proc_phr.h" -#include "mac/mux.h" -#include "mac/demux.h" +#include "mac_metrics.h" +#include "proc_ra.h" +#include "proc_sr.h" +#include "proc_bsr.h" +#include "proc_phr.h" +#include "mux.h" +#include "demux.h" #include "srslte/common/mac_pcap.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/tti_sync_cv.h" @@ -180,4 +180,4 @@ private: } // namespace srsue -#endif // MAC_H +#endif // SRSUE_MAC_H diff --git a/srsue/hdr/mac/mac_metrics.h b/srsue/hdr/mac/mac_metrics.h index 91ce29cab..a201d2a7f 100644 --- a/srsue/hdr/mac/mac_metrics.h +++ b/srsue/hdr/mac/mac_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_MAC_METRICS_H -#define UE_MAC_METRICS_H +#ifndef SRSUE_MAC_METRICS_H +#define SRSUE_MAC_METRICS_H namespace srsue { @@ -43,4 +43,4 @@ struct mac_metrics_t } // namespace srsue -#endif // UE_MAC_METRICS_H +#endif // SRSUE_MAC_METRICS_H diff --git a/srsue/hdr/mac/mux.h b/srsue/hdr/mac/mux.h index 17a854711..2e621360f 100644 --- a/srsue/hdr/mac/mux.h +++ b/srsue/hdr/mac/mux.h @@ -24,8 +24,8 @@ * */ -#ifndef MUX_H -#define MUX_H +#ifndef SRSUE_MUX_H +#define SRSUE_MUX_H #include @@ -34,8 +34,8 @@ #include "srslte/common/log.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/pdu.h" -#include "mac/proc_bsr.h" -#include "mac/proc_phr.h" +#include "proc_bsr.h" +#include "proc_phr.h" /* Logical Channel Multiplexing and Prioritization + Msg3 Buffer */ @@ -114,5 +114,5 @@ private: } // namespace srsue -#endif // MUX_H +#endif // SRSUE_MUX_H diff --git a/srsue/hdr/mac/proc.h b/srsue/hdr/mac/proc.h index 3fa864cb0..f3601385d 100644 --- a/srsue/hdr/mac/proc.h +++ b/srsue/hdr/mac/proc.h @@ -24,8 +24,8 @@ * */ -#ifndef PROC_H -#define PROC_H +#ifndef SRSUE_PROC_H +#define SRSUE_PROC_H #include @@ -56,4 +56,4 @@ private: } // namespace srsue -#endif // PROC_H +#endif // SRSUE_PROC_H diff --git a/srsue/hdr/mac/proc_bsr.h b/srsue/hdr/mac/proc_bsr.h index 656e9a7a3..9592df667 100644 --- a/srsue/hdr/mac/proc_bsr.h +++ b/srsue/hdr/mac/proc_bsr.h @@ -24,8 +24,8 @@ * */ -#ifndef PROCBSR_H -#define PROCBSR_H +#ifndef SRSUE_PROC_BSR_H +#define SRSUE_PROC_BSR_H #include @@ -88,4 +88,4 @@ private: } // namespace srsue -#endif // PROCBSR_H +#endif // SRSUE_PROC_BSR_H diff --git a/srsue/hdr/mac/proc_phr.h b/srsue/hdr/mac/proc_phr.h index 240a7bab7..b12280220 100644 --- a/srsue/hdr/mac/proc_phr.h +++ b/srsue/hdr/mac/proc_phr.h @@ -24,8 +24,8 @@ * */ -#ifndef PROCPHR_H -#define PROCPHR_H +#ifndef SRSUE_PROC_PHR_H +#define SRSUE_PROC_PHR_H #include #include "srslte/common/timers.h" @@ -74,4 +74,4 @@ private: } // namespace srsue -#endif // PROCPHR_H +#endif // SRSUE_PROC_PHR_H diff --git a/srsue/hdr/mac/proc_ra.h b/srsue/hdr/mac/proc_ra.h index de8a0671d..833173b75 100644 --- a/srsue/hdr/mac/proc_ra.h +++ b/srsue/hdr/mac/proc_ra.h @@ -24,15 +24,15 @@ * */ -#ifndef PROCRA_H -#define PROCRA_H +#ifndef SRSUE_PROC_RA_H +#define SRSUE_PROC_RA_H #include #include "srslte/common/log.h" #include "srslte/common/timers.h" -#include "mac/mux.h" -#include "mac/demux.h" +#include "mux.h" +#include "demux.h" #include "srslte/common/pdu.h" #include "srslte/common/mac_pcap.h" @@ -216,4 +216,4 @@ private: } // namespace srsue -#endif // PROCRA_H +#endif // SRSUE_PROC_RA_H diff --git a/srsue/hdr/mac/proc_sr.h b/srsue/hdr/mac/proc_sr.h index 9425481dd..878f92fb5 100644 --- a/srsue/hdr/mac/proc_sr.h +++ b/srsue/hdr/mac/proc_sr.h @@ -24,8 +24,8 @@ * */ -#ifndef PROCSR_H -#define PROCSR_H +#ifndef SRSUE_PROC_SR_H +#define SRSUE_PROC_SR_H #include #include "srslte/interfaces/ue_interfaces.h" @@ -64,4 +64,4 @@ private: } // namespace srsue -#endif // PROCSR_H +#endif // SRSUE_PROC_SR_H diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index ee9bc6279..6fb27be8a 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -24,8 +24,8 @@ * */ -#ifndef ULHARQ_H -#define ULHARQ_H +#ifndef SRSUE_UL_HARQ_H +#define SRSUE_UL_HARQ_H #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) @@ -34,8 +34,8 @@ #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/log.h" -#include "mac/mux.h" -#include "mac/ul_sps.h" +#include "mux.h" +#include "ul_sps.h" #include "srslte/common/mac_pcap.h" #include "srslte/common/timers.h" #include "srslte/common/interfaces_common.h" @@ -429,4 +429,4 @@ private: } // namespace srsue -#endif // ULHARQ_H +#endif // SRSUE_UL_HARQ_H diff --git a/srsue/hdr/mac/ul_sps.h b/srsue/hdr/mac/ul_sps.h index 59af7f507..985b8470f 100644 --- a/srsue/hdr/mac/ul_sps.h +++ b/srsue/hdr/mac/ul_sps.h @@ -24,8 +24,8 @@ * */ -#ifndef ULSPS_H -#define ULSPS_H +#ifndef SRSUE_UL_SPS_H +#define SRSUE_UL_SPS_H #include "srslte/common/log.h" #include "srslte/common/timers.h" @@ -50,4 +50,4 @@ private: } // namespace srsue -#endif // ULSPS_H +#endif // SRSUE_UL_SPS_H diff --git a/srsue/hdr/metrics_csv.h b/srsue/hdr/metrics_csv.h index 72a9dc050..f07b0c119 100644 --- a/srsue/hdr/metrics_csv.h +++ b/srsue/hdr/metrics_csv.h @@ -29,8 +29,8 @@ * Description: Metrics class writing to CSV file. *****************************************************************************/ -#ifndef METRICS_CSV_H -#define METRICS_CSV_H +#ifndef SRSUE_METRICS_CSV_H +#define SRSUE_METRICS_CSV_H #include #include @@ -64,4 +64,4 @@ private: } // namespace srsue -#endif // METRICS_CSV_H +#endif // SRSUE_METRICS_CSV_H diff --git a/srsue/hdr/metrics_stdout.h b/srsue/hdr/metrics_stdout.h index 01f28f35e..2b0df9ca3 100644 --- a/srsue/hdr/metrics_stdout.h +++ b/srsue/hdr/metrics_stdout.h @@ -29,8 +29,8 @@ * Description: Metrics class printing to stdout. *****************************************************************************/ -#ifndef METRICS_STDOUT_H -#define METRICS_STDOUT_H +#ifndef SRSUE_METRICS_STDOUT_H +#define SRSUE_METRICS_STDOUT_H #include #include @@ -64,4 +64,4 @@ private: } // namespace srsue -#endif // METRICS_STDOUT_H +#endif // SRSUE_METRICS_STDOUT_H diff --git a/srsue/hdr/phy/phch_common.h b/srsue/hdr/phy/phch_common.h index 698b3de94..32289a6b0 100644 --- a/srsue/hdr/phy/phch_common.h +++ b/srsue/hdr/phy/phch_common.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPHYWORKERCOMMON_H -#define UEPHYWORKERCOMMON_H +#ifndef SRSUE_PHCH_COMMON_H +#define SRSUE_PHCH_COMMON_H #define TX_MODE_CONTINUOUS 1 @@ -37,7 +37,7 @@ #include "srslte/interfaces/ue_interfaces.h" #include "srslte/radio/radio.h" #include "srslte/common/log.h" -#include "phy/phy_metrics.h" +#include "phy_metrics.h" namespace srsue { @@ -187,4 +187,4 @@ private: } // namespace srsue -#endif // UEPHYWORKERCOMMON_H +#endif // SRSUE_PDCH_COMMON_H diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index 19b8ad17d..4cabf660f 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPHYRECV_H -#define UEPHYRECV_H +#ifndef SRSUE_PHCH_RECV_H +#define SRSUE_PHCH_RECV_H #include #include @@ -36,9 +36,9 @@ #include "srslte/common/thread_pool.h" #include "srslte/common/tti_sync_cv.h" #include "srslte/radio/radio_multi.h" -#include "phy/prach.h" -#include "phy/phch_worker.h" -#include "phy/phch_common.h" +#include "prach.h" +#include "phch_worker.h" +#include "phch_common.h" #include "srslte/interfaces/ue_interfaces.h" namespace srsue { @@ -444,4 +444,4 @@ private: } // namespace srsue -#endif // UEPHYRECV_H +#endif // SRSUE_PHCH_RECV_H diff --git a/srsue/hdr/phy/phch_worker.h b/srsue/hdr/phy/phch_worker.h index 28c4715ad..53848905b 100644 --- a/srsue/hdr/phy/phch_worker.h +++ b/srsue/hdr/phy/phch_worker.h @@ -24,14 +24,14 @@ * */ -#ifndef UEPHYWORKER_H -#define UEPHYWORKER_H +#ifndef SRSUE_PHCH_WORKER_H +#define SRSUE_PHCH_WORKER_H #include #include "srslte/srslte.h" #include "srslte/common/thread_pool.h" #include "srslte/common/trace.h" -#include "phy/phch_common.h" +#include "phch_common.h" #define LOG_EXECTIME @@ -185,5 +185,5 @@ private: } // namespace srsue -#endif // UEPHYWORKER_H +#endif // SRSUE_PHCH_WORKER_H diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index e05fbfd4c..a1a7c2a66 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -24,16 +24,16 @@ * */ -#ifndef UEPHY_H -#define UEPHY_H +#ifndef SRSUE_PHY_H +#define SRSUE_PHY_H #include "srslte/srslte.h" #include "srslte/common/log_filter.h" -#include "phy/phy_metrics.h" -#include "phy/phch_recv.h" -#include "phy/prach.h" -#include "phy/phch_worker.h" -#include "phy/phch_common.h" +#include "phy_metrics.h" +#include "phch_recv.h" +#include "prach.h" +#include "phch_worker.h" +#include "phch_common.h" #include "srslte/radio/radio.h" #include "srslte/common/task_dispatcher.h" #include "srslte/common/trace.h" @@ -184,4 +184,4 @@ private: } // namespace srsue -#endif // UEPHY_H +#endif // SRSUE_PHY_H diff --git a/srsue/hdr/phy/phy_metrics.h b/srsue/hdr/phy/phy_metrics.h index eafff2183..ce53c096c 100644 --- a/srsue/hdr/phy/phy_metrics.h +++ b/srsue/hdr/phy/phy_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_PHY_METRICS_H -#define UE_PHY_METRICS_H +#ifndef SRSUE_PHY_METRICS_H +#define SRSUE_PHY_METRICS_H namespace srsue { @@ -65,4 +65,4 @@ struct phy_metrics_t } // namespace srsue -#endif // UE_PHY_METRICS_H +#endif // SRSUE_PHY_METRICS_H diff --git a/srsue/hdr/phy/prach.h b/srsue/hdr/phy/prach.h index 09be0c9b2..651203eb7 100644 --- a/srsue/hdr/phy/prach.h +++ b/srsue/hdr/phy/prach.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPRACH_H -#define UEPRACH_H +#ifndef SRSUE_PRACH_H +#define SRSUE_PRACH_H #include @@ -87,4 +87,4 @@ namespace srsue { } // namespace srsue -#endif // UEPRACH_H +#endif // SRSUE_PRACH_H diff --git a/srsue/hdr/ue.h b/srsue/hdr/ue.h index c7cb7c9c8..a305df931 100644 --- a/srsue/hdr/ue.h +++ b/srsue/hdr/ue.h @@ -30,8 +30,8 @@ * layers and helpers. *****************************************************************************/ -#ifndef UE_H -#define UE_H +#ifndef SRSUE_UE_H +#define SRSUE_UE_H #include #include @@ -122,5 +122,5 @@ private: } // namespace srsue -#endif // UE_H +#endif // SRSUE_UE_H diff --git a/srsue/hdr/ue_base.h b/srsue/hdr/ue_base.h index 863d3b71b..e3acf4cff 100644 --- a/srsue/hdr/ue_base.h +++ b/srsue/hdr/ue_base.h @@ -29,8 +29,8 @@ * Description: Base class for UEs. *****************************************************************************/ -#ifndef UE_BASE_H -#define UE_BASE_H +#ifndef SRSUE_UE_BASE_H +#define SRSUE_UE_BASE_H #include #include @@ -185,5 +185,5 @@ private: } // namespace srsue -#endif // UE_BASE_H +#endif // SRSUE_UE_BASE_H diff --git a/srsue/hdr/ue_metrics_interface.h b/srsue/hdr/ue_metrics_interface.h index 20ee6f031..968b0de5a 100644 --- a/srsue/hdr/ue_metrics_interface.h +++ b/srsue/hdr/ue_metrics_interface.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_METRICS_INTERFACE_H -#define UE_METRICS_INTERFACE_H +#ifndef SRSUE_UE_METRICS_INTERFACE_H +#define SRSUE_UE_METRICS_INTERFACE_H #include @@ -62,4 +62,4 @@ public: } // namespace srsue -#endif // UE_METRICS_INTERFACE_H +#endif // SRSUE_UE_METRICS_INTERFACE_H diff --git a/srsue/hdr/upper/gw.h b/srsue/hdr/upper/gw.h index aa5b2c70f..10ab50e56 100644 --- a/srsue/hdr/upper/gw.h +++ b/srsue/hdr/upper/gw.h @@ -24,8 +24,8 @@ * */ -#ifndef GW_H -#define GW_H +#ifndef SRSUE_GW_H +#define SRSUE_GW_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -94,4 +94,4 @@ private: } // namespace srsue -#endif // GW_H +#endif // SRSUE_GW_H diff --git a/srsue/hdr/upper/gw_metrics.h b/srsue/hdr/upper/gw_metrics.h index e596046c9..cce3af7ad 100644 --- a/srsue/hdr/upper/gw_metrics.h +++ b/srsue/hdr/upper/gw_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_GW_METRICS_H -#define UE_GW_METRICS_H +#ifndef SRSUE_GW_METRICS_H +#define SRSUE_GW_METRICS_H namespace srsue { @@ -38,4 +38,4 @@ struct gw_metrics_t } // namespace srsue -#endif // UE_GW_METRICS_H +#endif // SRSUE_GW_METRICS_H diff --git a/srsue/hdr/upper/nas.h b/srsue/hdr/upper/nas.h index 463040fa1..ee9838dd4 100644 --- a/srsue/hdr/upper/nas.h +++ b/srsue/hdr/upper/nas.h @@ -24,8 +24,8 @@ * */ -#ifndef NAS_H -#define NAS_H +#ifndef SRSUE_NAS_H +#define SRSUE_NAS_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -216,4 +216,4 @@ private: } // namespace srsue -#endif // NAS_H +#endif // SRSUE_NAS_H diff --git a/srsue/hdr/upper/rrc.h b/srsue/hdr/upper/rrc.h index bc27aa324..5209c44d7 100644 --- a/srsue/hdr/upper/rrc.h +++ b/srsue/hdr/upper/rrc.h @@ -24,8 +24,8 @@ * */ -#ifndef RRC_H -#define RRC_H +#ifndef SRSUE_RRC_H +#define SRSUE_RRC_H #include "pthread.h" @@ -614,4 +614,4 @@ private: } // namespace srsue -#endif // RRC_H +#endif // SRSUE_RRC_H diff --git a/srsue/hdr/upper/rrc_common.h b/srsue/hdr/upper/rrc_common.h index 2339a08a2..f79a98bed 100644 --- a/srsue/hdr/upper/rrc_common.h +++ b/srsue/hdr/upper/rrc_common.h @@ -24,8 +24,8 @@ * */ -#ifndef RRC_COMMON_H -#define RRC_COMMON_H +#ifndef SRSUE_RRC_COMMON_H +#define SRSUE_RRC_COMMON_H namespace srsue { @@ -42,4 +42,4 @@ static const char rrc_state_text[RRC_STATE_N_ITEMS][100] = {"IDLE", } // namespace srsue -#endif // RRC_COMMON_H +#endif // SRSUE_RRC_COMMON_H diff --git a/srsue/hdr/upper/usim.h b/srsue/hdr/upper/usim.h index e37f58218..a5f703781 100644 --- a/srsue/hdr/upper/usim.h +++ b/srsue/hdr/upper/usim.h @@ -24,8 +24,8 @@ * */ -#ifndef USIM_H -#define USIM_H +#ifndef SRSUE_USIM_H +#define SRSUE_USIM_H #include #include "srslte/common/log.h" @@ -151,4 +151,4 @@ private: } // namespace srsue -#endif // USIM_H +#endif // SRSUE_USIM_H diff --git a/srsue/src/mac/demux.cc b/srsue/src/mac/demux.cc index 3ddd98b69..3e0d2f44f 100644 --- a/srsue/src/mac/demux.cc +++ b/srsue/src/mac/demux.cc @@ -30,8 +30,8 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/mac.h" -#include "mac/demux.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/mac/demux.h" #include "srslte/interfaces/ue_interfaces.h" namespace srsue { diff --git a/srsue/src/mac/mac.cc b/srsue/src/mac/mac.cc index 4372085d7..14f895257 100644 --- a/srsue/src/mac/mac.cc +++ b/srsue/src/mac/mac.cc @@ -35,7 +35,7 @@ #include #include "srslte/common/log.h" -#include "mac/mac.h" +#include "srsue/hdr/mac/mac.h" #include "srslte/common/pcap.h" diff --git a/srsue/src/mac/mux.cc b/srsue/src/mac/mux.cc index 33d048957..6d1edbebf 100644 --- a/srsue/src/mac/mux.cc +++ b/srsue/src/mac/mux.cc @@ -29,8 +29,8 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/mux.h" -#include "mac/mac.h" +#include "srsue/hdr/mac/mux.h" +#include "srsue/hdr/mac/mac.h" #include #include diff --git a/srsue/src/mac/proc_bsr.cc b/srsue/src/mac/proc_bsr.cc index f68b6eee8..19b214a74 100644 --- a/srsue/src/mac/proc_bsr.cc +++ b/srsue/src/mac/proc_bsr.cc @@ -29,9 +29,9 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/proc_bsr.h" -#include "mac/mac.h" -#include "mac/mux.h" +#include "srsue/hdr/mac/proc_bsr.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/mac/mux.h" namespace srsue { diff --git a/srsue/src/mac/proc_phr.cc b/srsue/src/mac/proc_phr.cc index 54c1ec1ce..69a5c0de3 100644 --- a/srsue/src/mac/proc_phr.cc +++ b/srsue/src/mac/proc_phr.cc @@ -29,9 +29,9 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/proc_phr.h" -#include "mac/mac.h" -#include "mac/mux.h" +#include "srsue/hdr/mac/proc_phr.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/mac/mux.h" #include "srslte/interfaces/ue_interfaces.h" @@ -91,7 +91,7 @@ void phr_proc::timer_expired(uint32_t timer_id) { } else if (timer_id == timer_prohibit_id) { int pathloss_db = liblte_rrc_dl_pathloss_change_num[mac_cfg->main.phr_cnfg.dl_pathloss_change]; if (pathloss_changed()) { - Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%f (timer expired)\n", last_pathloss_db); + Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%d (timer expired)\n", last_pathloss_db); phr_is_triggered = true; } } else { @@ -132,7 +132,7 @@ void phr_proc::step(uint32_t tti) } if (pathloss_changed() && timers_db->get(timer_prohibit_id)->is_expired()) { - Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%f\n", last_pathloss_db); + Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%d\n", last_pathloss_db); phr_is_triggered = true; } } diff --git a/srsue/src/mac/proc_ra.cc b/srsue/src/mac/proc_ra.cc index 3860fd809..d5efbea4f 100644 --- a/srsue/src/mac/proc_ra.cc +++ b/srsue/src/mac/proc_ra.cc @@ -33,9 +33,9 @@ #include #include -#include "mac/proc_ra.h" -#include "mac/mac.h" -#include "mac/mux.h" +#include "srsue/hdr/mac/proc_ra.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/mac/mux.h" /* Random access procedure as specified in Section 5.1 of 36.321 */ diff --git a/srsue/src/mac/proc_sr.cc b/srsue/src/mac/proc_sr.cc index cb31a1c6d..57cd8bdd5 100644 --- a/srsue/src/mac/proc_sr.cc +++ b/srsue/src/mac/proc_sr.cc @@ -29,7 +29,7 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/proc_sr.h" +#include "srsue/hdr/mac/proc_sr.h" namespace srsue { diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 63d0e12ab..f0c733172 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -36,10 +36,10 @@ #include #include -#include "ue.h" +#include "srsue/hdr/ue.h" #include "srslte/srslte.h" -#include "metrics_stdout.h" -#include "metrics_csv.h" +#include "srsue/hdr/metrics_stdout.h" +#include "srsue/hdr/metrics_csv.h" #include "srslte/common/metrics_hub.h" #include "srslte/version.h" diff --git a/srsue/src/metrics_csv.cc b/srsue/src/metrics_csv.cc index 54702dc26..360c678f5 100644 --- a/srsue/src/metrics_csv.cc +++ b/srsue/src/metrics_csv.cc @@ -25,7 +25,7 @@ * */ -#include "metrics_csv.h" +#include "srsue/hdr/metrics_csv.h" #include #include diff --git a/srsue/src/metrics_stdout.cc b/srsue/src/metrics_stdout.cc index c8f373284..5d33f967d 100644 --- a/srsue/src/metrics_stdout.cc +++ b/srsue/src/metrics_stdout.cc @@ -25,7 +25,7 @@ * */ -#include "metrics_stdout.h" +#include "srsue/hdr/metrics_stdout.h" #include #include diff --git a/srsue/src/phy/phch_common.cc b/srsue/src/phy/phch_common.cc index 29e1e3541..5b081ac3c 100644 --- a/srsue/src/phy/phch_common.cc +++ b/srsue/src/phy/phch_common.cc @@ -27,7 +27,7 @@ #include #include #include "srslte/srslte.h" -#include "phy/phch_common.h" +#include "srsue/hdr/phy/phch_common.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 58883aefe..fc36760e0 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -28,8 +28,8 @@ #include #include "srslte/srslte.h" #include "srslte/common/log.h" -#include "phy/phch_worker.h" -#include "phy/phch_recv.h" +#include "srsue/hdr/phy/phch_worker.h" +#include "srsue/hdr/phy/phch_recv.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) @@ -192,7 +192,7 @@ phy_interface_rrc::cell_search_ret_t phch_recv::cell_search(phy_interface_rrc::p pthread_mutex_lock(&rrc_mutex); // Move state to IDLE - Info("Cell Search: Start EARFCN index=%d/%d\n", cellsearch_earfcn_index, earfcn.size()); + Info("Cell Search: Start EARFCN index=%u/%lu\n", cellsearch_earfcn_index, earfcn.size()); phy_state.go_idle(); if (current_earfcn != (int) earfcn[cellsearch_earfcn_index]) { @@ -1544,7 +1544,7 @@ void phch_recv::intra_measure::rem_cell(int pci) { if (active_pci.size() == 0) { receive_enabled = false; } - Info("INTRA: Stopping intra-frequency measurement for pci=%d. Number of cells: %d\n", pci, active_pci.size()); + Info("INTRA: Stopping intra-frequency measurement for pci=%d. Number of cells: %zu\n", pci, active_pci.size()); } else { Warning("INTRA: Requested to stop non-existing intra-frequency measurement for PCI=%d\n", pci); } diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 911429690..e19912a1d 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -26,7 +26,7 @@ #include #include -#include "phy/phch_worker.h" +#include "srsue/hdr/phy/phch_worker.h" #include "srslte/srslte.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/asn1/liblte_rrc.h" @@ -1110,7 +1110,8 @@ void phch_worker::encode_pusch(srslte_ra_ul_grant_t *grant, uint8_t *payload, ui srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); uint8_t dummy[2] = {0,0}; - log_h->info("PUSCH: tti_tx=%d, alloc=(%d,%d), tbs=%d, mcs=%d, rv=%d%s%s%s, cfo=%.1f KHz%s%s%s\n", + log_h->info_hex(payload, grant->mcs.tbs/8, + "PUSCH: tti_tx=%d, alloc=(%d,%d), tbs=%d, mcs=%d, rv=%d%s%s%s, cfo=%.1f KHz%s%s%s\n", (tti + HARQ_DELAY_MS) % 10240, grant->n_prb[0], grant->n_prb[0] + grant->L_prb, grant->mcs.tbs / 8, grant->mcs.idx, rv, diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index 06f802f9b..f0187b3f6 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -36,7 +36,7 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/phy.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsue/src/phy/prach.cc b/srsue/src/phy/prach.cc index fdf925642..5025e6b5d 100644 --- a/srsue/src/phy/prach.cc +++ b/srsue/src/phy/prach.cc @@ -30,8 +30,8 @@ #include "srslte/srslte.h" #include "srslte/common/log.h" -#include "phy/prach.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/prach.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/interfaces/ue_interfaces.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) @@ -201,7 +201,7 @@ void prach::send(srslte::radio *radio_handler, float cfo, float pathloss, srslte float scale = sqrtf(pow(10,tx_power/10)/digital_power); srslte_vec_sc_prod_cfc(signal_buffer, scale, signal_buffer, len); - log_h->console("PRACH: Pathloss=%.2f dB, Target power %.2f dBm, TX_power %.2f dBm, TX_gain %.1f dB\n", + log_h->console("PRACH: Pathloss=%.2f dB, Target power %.2f dBm, TX_power %.2f dBm, TX_gain %.1f dB, scale %.2f\n", pathloss, target_power_dbm, tx_power, radio_handler->get_tx_gain(), scale); } else { diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index f313477d2..6c87b3c17 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -25,7 +25,7 @@ */ -#include "ue.h" +#include "srsue/hdr/ue.h" #include "srslte/srslte.h" #include #include diff --git a/srsue/src/ue_base.cc b/srsue/src/ue_base.cc index a4264a099..b3fc56132 100644 --- a/srsue/src/ue_base.cc +++ b/srsue/src/ue_base.cc @@ -24,8 +24,8 @@ * */ -#include "ue_base.h" -#include "ue.h" +#include "srsue/hdr/ue_base.h" +#include "srsue/hdr/ue.h" #include "srslte/srslte.h" #include "srslte/build_info.h" #include @@ -104,7 +104,7 @@ void ue_base::handle_rf_msg(srslte_rf_error_t error) str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); str.erase(std::remove(str.begin(), str.end(), '\r'), str.end()); str.push_back('\n'); - rf_log.info(str); + rf_log.info("%s\n", str.c_str()); } } diff --git a/srsue/src/upper/gw.cc b/srsue/src/upper/gw.cc index f75d44e0f..0201cfe14 100644 --- a/srsue/src/upper/gw.cc +++ b/srsue/src/upper/gw.cc @@ -25,7 +25,7 @@ */ -#include "../../hdr/upper/gw.h" +#include "srsue/hdr/upper/gw.h" #include #include diff --git a/srsue/src/upper/nas.cc b/srsue/src/upper/nas.cc index 7f42f9e4c..243d58177 100644 --- a/srsue/src/upper/nas.cc +++ b/srsue/src/upper/nas.cc @@ -31,7 +31,7 @@ #include #include #include "srslte/asn1/liblte_rrc.h" -#include "upper/nas.h" +#include "srsue/hdr/upper/nas.h" #include "srslte/common/security.h" #include "srslte/common/bcd_helpers.h" @@ -417,30 +417,39 @@ void nas::integrity_generate(uint8_t *key_128, bool nas::integrity_check(byte_buffer_t *pdu) { - uint8_t exp_mac[4]; - uint8_t *mac = &pdu->msg[1]; - int i; - - integrity_generate(&k_nas_int[16], - ctxt.rx_count, - SECURITY_DIRECTION_DOWNLINK, - &pdu->msg[5], - pdu->N_bytes-5, - &exp_mac[0]); - - // Check if expected mac equals the sent mac - for(i=0; i<4; i++){ - if(exp_mac[i] != mac[i]){ - nas_log->warning("Integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " - "Received: count=%d, [%02x %02x %02x %02x]\n", - ctxt.rx_count, exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], - pdu->msg[5], mac[0], mac[1], mac[2], mac[3]); - return false; - } + if (!pdu) { + nas_log->error("Invalid PDU\n"); + return NULL; + } + if (pdu->N_bytes > 5) { + uint8_t exp_mac[4]; + uint8_t *mac = &pdu->msg[1]; + int i; + + integrity_generate(&k_nas_int[16], + ctxt.rx_count, + SECURITY_DIRECTION_DOWNLINK, + &pdu->msg[5], + pdu->N_bytes-5, + &exp_mac[0]); + + // Check if expected mac equals the sent mac + for(i=0; i<4; i++){ + if(exp_mac[i] != mac[i]){ + nas_log->warning("Integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " + "Received: count=%d, [%02x %02x %02x %02x]\n", + ctxt.rx_count, exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], + pdu->msg[5], mac[0], mac[1], mac[2], mac[3]); + return false; + } + } + nas_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", + ctxt.rx_count, pdu->msg[5]); + return true; + } else { + nas_log->error("Invalid integrity check PDU size (%d)\n", pdu->N_bytes); + return false; } - nas_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", - ctxt.rx_count, pdu->msg[5]); - return true; } void nas::cipher_encrypt(byte_buffer_t *pdu) @@ -526,6 +535,17 @@ bool nas::check_cap_replay(LIBLTE_MME_UE_SECURITY_CAPABILITIES_STRUCT *caps) ******************************************************************************/ void nas::parse_attach_accept(uint32_t lcid, byte_buffer_t *pdu) { + + if (!pdu) { + nas_log->error("Invalid PDU\n"); + return; + } + + if (pdu->N_bytes <= 5) { + nas_log->error("Invalid attach accept PDU size (%d)\n", pdu->N_bytes); + return; + } + LIBLTE_MME_ATTACH_ACCEPT_MSG_STRUCT attach_accept; LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT act_def_eps_bearer_context_req; LIBLTE_MME_ATTACH_COMPLETE_MSG_STRUCT attach_complete; @@ -737,7 +757,7 @@ void nas::parse_identity_request(uint32_t lcid, byte_buffer_t *pdu) { usim->get_imei_vec(id_resp.mobile_id.imei, 15); break; default: - nas_log->error("Unhandled ID type: %d\n"); + nas_log->error("Unhandled ID type: %d\n", id_req.id_type); pool->deallocate(pdu); return; } @@ -754,6 +774,17 @@ void nas::parse_identity_request(uint32_t lcid, byte_buffer_t *pdu) { void nas::parse_security_mode_command(uint32_t lcid, byte_buffer_t *pdu) { + + if (!pdu) { + nas_log->error("Invalid PDU\n"); + return; + } + + if (pdu->N_bytes <= 5) { + nas_log->error("Invalid security mode command PDU size (%d)\n", pdu->N_bytes); + return; + } + LIBLTE_MME_SECURITY_MODE_COMMAND_MSG_STRUCT sec_mode_cmd; LIBLTE_MME_SECURITY_MODE_COMPLETE_MSG_STRUCT sec_mode_comp; @@ -935,12 +966,16 @@ void nas::gen_attach_request(byte_buffer_t *msg) { (LIBLTE_BYTE_MSG_STRUCT *) msg); // Add MAC - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &msg->msg[5], - msg->N_bytes - 5, - &msg->msg[1]); + if (msg->N_bytes > 5) { + integrity_generate(&k_nas_int[16], + ctxt.tx_count, + SECURITY_DIRECTION_UPLINK, + &msg->msg[5], + msg->N_bytes - 5, + &msg->msg[1]); + } else { + nas_log->error("Invalid PDU size %d\n", msg->N_bytes); + } } else { attach_req.eps_mobile_id.type_of_id = LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI; usim->get_imsi_vec(attach_req.eps_mobile_id.imsi, 15); diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 3d63c6b8e..cb30c5eef 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -30,8 +30,9 @@ #include #include #include +#include // for printing uint64_t #include -#include "upper/rrc.h" +#include "srsue/hdr/upper/rrc.h" #include "srslte/asn1/liblte_rrc.h" #include "srslte/common/security.h" #include "srslte/common/bcd_helpers.h" @@ -485,7 +486,7 @@ void rrc::new_phy_meas(float rsrp, float rsrq, uint32_t tti, int earfcn_i, int p */ void rrc::process_phy_meas() { while(!phy_meas_q.empty()) { - rrc_log->debug("MEAS: Processing measurement. %d measurements in queue\n", phy_meas_q.size()); + rrc_log->debug("MEAS: Processing measurement. %lu measurements in queue\n", phy_meas_q.size()); process_new_phy_meas(phy_meas_q.front()); phy_meas_q.pop(); } @@ -862,7 +863,7 @@ void rrc::set_serving_cell(uint32_t cell_idx) { // Set new serving cell serving_cell = new_serving_cell; - rrc_log->info("Setting serving cell idx=%d, earfcn=%d, PCI=%d, nof_neighbours=%d\n", + rrc_log->info("Setting serving cell idx=%d, earfcn=%d, PCI=%d, nof_neighbours=%lu\n", cell_idx, serving_cell->get_earfcn(), serving_cell->get_pci(), neighbour_cells.size()); } else { @@ -945,7 +946,7 @@ bool rrc::add_neighbour_cell(cell_t *new_cell) { if (ret) { neighbour_cells.push_back(new_cell); } - rrc_log->info("Added neighbour cell EARFCN=%d, PCI=%d, nof_neighbours=%d\n", + rrc_log->info("Added neighbour cell EARFCN=%d, PCI=%d, nof_neighbours=%zd\n", new_cell->get_earfcn(), new_cell->get_pci(), neighbour_cells.size()); sort_neighbour_cells(); return ret; @@ -1723,7 +1724,7 @@ void rrc::send_ul_ccch_msg() ue_cri_ptr[nbytes - i - 1] = pdu->msg[i]; } - rrc_log->debug("Setting UE contention resolution ID: %d\n", uecri); + rrc_log->debug("Setting UE contention resolution ID: %" PRIu64 "\n", uecri); mac->set_contention_id(uecri); rrc_log->info("Sending %s\n", liblte_rrc_ul_ccch_msg_type_text[ul_ccch_msg.msg_type]); @@ -1763,7 +1764,7 @@ void rrc::write_pdu(uint32_t lcid, byte_buffer_t *pdu) { parse_dl_dcch(lcid, pdu); break; default: - rrc_log->error("RX PDU with invalid bearer id: %s", lcid); + rrc_log->error("RX PDU with invalid bearer id: %d", lcid); break; } } @@ -2333,8 +2334,8 @@ bool rrc::apply_rr_config_dedicated(LIBLTE_RRC_RR_CONFIG_DEDICATED_STRUCT *cnfg) N310 = liblte_rrc_n310_num[cnfg->rlf_timers_and_constants.n310]; N311 = liblte_rrc_n311_num[cnfg->rlf_timers_and_constants.n311]; - rrc_log->info("Updated Constants and Timers: N310=%d, N311=%d, t300=%d, t301=%d, t310=%d, t311=%d\n", - N310, N311, mac_timers->timer_get(t301)->get_timeout(), + rrc_log->info("Updated Constants and Timers: N310=%d, N311=%d, t300=%u, t301=%u, t310=%u, t311=%u\n", + N310, N311, mac_timers->timer_get(t300)->get_timeout(), mac_timers->timer_get(t301)->get_timeout(), mac_timers->timer_get(t310)->get_timeout(), mac_timers->timer_get(t311)->get_timeout()); } for (uint32_t i = 0; i < cnfg->srb_to_add_mod_list_size; i++) { @@ -3004,8 +3005,8 @@ bool rrc::rrc_meas::parse_meas_config(LIBLTE_RRC_MEAS_CONFIG_STRUCT *cfg) log_h->info("MEAS: Added measObjectId=%d, earfcn=%d, q_offset=%f, pci=%d, offset_cell=%f\n", cfg->meas_obj_to_add_mod_list.meas_obj_list[i].meas_obj_id, dst_obj->earfcn, dst_obj->q_offset, - dst_obj->cells[src_obj->cells_to_add_mod_list[j].cell_idx].q_offset, - dst_obj->cells[src_obj->cells_to_add_mod_list[j].cell_idx].pci); + dst_obj->cells[src_obj->cells_to_add_mod_list[j].cell_idx].pci, + dst_obj->cells[src_obj->cells_to_add_mod_list[j].cell_idx].q_offset); } @@ -3086,7 +3087,7 @@ bool rrc::rrc_meas::parse_meas_config(LIBLTE_RRC_MEAS_CONFIG_STRUCT *cfg) remove_meas_id(cfg->meas_id_to_remove_list[i]); } - log_h->info("nof active measId=%d\n", active.size()); + log_h->info("nof active measId=%zd\n", active.size()); // Measurement identity addition/modification 5.5.2.3 if (cfg->meas_id_to_add_mod_list_present) { @@ -3102,8 +3103,9 @@ bool rrc::rrc_meas::parse_meas_config(LIBLTE_RRC_MEAS_CONFIG_STRUCT *cfg) } active[measId->meas_id].object_id = measId->meas_obj_id; active[measId->meas_id].report_id = measId->rep_cnfg_id; - log_h->info("MEAS: %s measId=%d, measObjectId=%d, reportConfigId=%d, nof_values=%d\n", + log_h->info("MEAS: %s measId=%d, measObjectId=%d, reportConfigId=%d, timer_id=%u, nof_values=%lu\n", is_new?"Added":"Updated", measId->meas_id, measId->meas_obj_id, measId->rep_cnfg_id, + active[measId->meas_id].periodic_timer, active[measId->meas_id].cell_values.size()); } } diff --git a/srsue/src/upper/usim.cc b/srsue/src/upper/usim.cc index b9f4fda0e..ca9075edb 100644 --- a/srsue/src/upper/usim.cc +++ b/srsue/src/upper/usim.cc @@ -26,7 +26,7 @@ #include -#include "upper/usim.h" +#include "srsue/hdr/upper/usim.h" #include "srslte/common/bcd_helpers.h" using namespace srslte; @@ -49,8 +49,8 @@ void usim::init(usim_args_t *args, srslte::log *usim_log_) if(32 == args->op.length()) { str_to_hex(args->op, op); } else { - usim_log->error("Invalid length for OP: %d should be %d", args->op.length(), 32); - usim_log->console("Invalid length for OP: %d should be %d", args->op.length(), 32); + usim_log->error("Invalid length for OP: %zu should be %d", args->op.length(), 32); + usim_log->console("Invalid length for OP: %zu should be %d", args->op.length(), 32); } if(15 == args->imsi.length()) { @@ -61,8 +61,8 @@ void usim::init(usim_args_t *args, srslte::log *usim_log_) imsi += imsi_c[i] - '0'; } } else { - usim_log->error("Invalid length for ISMI: %d should be %d", args->imsi.length(), 15); - usim_log->console("Invalid length for IMSI: %d should be %d", args->imsi.length(), 15); + usim_log->error("Invalid length for ISMI: %zu should be %d", args->imsi.length(), 15); + usim_log->console("Invalid length for IMSI: %zu should be %d", args->imsi.length(), 15); } if(15 == args->imei.length()) { @@ -73,15 +73,15 @@ void usim::init(usim_args_t *args, srslte::log *usim_log_) imei += imei_c[i] - '0'; } } else { - usim_log->error("Invalid length for IMEI: %d should be %d", args->imei.length(), 15); - usim_log->console("Invalid length for IMEI: %d should be %d", args->imei.length(), 15); + usim_log->error("Invalid length for IMEI: %zu should be %d", args->imei.length(), 15); + usim_log->console("Invalid length for IMEI: %zu should be %d", args->imei.length(), 15); } if(32 == args->k.length()) { str_to_hex(args->k, k); } else { - usim_log->error("Invalid length for K: %d should be %d", args->k.length(), 32); - usim_log->console("Invalid length for K: %d should be %d", args->k.length(), 32); + usim_log->error("Invalid length for K: %zu should be %d", args->k.length(), 32); + usim_log->console("Invalid length for K: %zu should be %d", args->k.length(), 32); } auth_algo = auth_algo_milenage; diff --git a/srsue/test/mac/mac_test.cc b/srsue/test/mac/mac_test.cc index f8d3a1f80..e3d457872 100644 --- a/srsue/test/mac/mac_test.cc +++ b/srsue/test/mac/mac_test.cc @@ -30,10 +30,10 @@ #include "srslte/asn1/liblte_rrc.h" #include "srslte/radio/radio_multi.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/log_filter.h" -#include "mac/mac.h" +#include "srsue/hdr/mac/mac.h" #include "srslte/common/mac_pcap.h" diff --git a/srsue/test/metrics_test.cc b/srsue/test/metrics_test.cc index 52a5f98f9..4a23a55cf 100644 --- a/srsue/test/metrics_test.cc +++ b/srsue/test/metrics_test.cc @@ -29,10 +29,10 @@ #include #include #include -#include "ue_metrics_interface.h" +#include "srsue/hdr/ue_metrics_interface.h" #include "srslte/common/metrics_hub.h" -#include "metrics_stdout.h" -#include "metrics_csv.h" +#include "srsue/hdr/metrics_stdout.h" +#include "srsue/hdr/metrics_csv.h" using namespace srsue; diff --git a/srsue/test/phy/ue_itf_test_prach.cc b/srsue/test/phy/ue_itf_test_prach.cc index 9b8cd54c3..9ae63d049 100644 --- a/srsue/test/phy/ue_itf_test_prach.cc +++ b/srsue/test/phy/ue_itf_test_prach.cc @@ -27,7 +27,7 @@ #include #include "srslte/phy/utils/debug.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/log_filter.h" #include "srslte/radio/radio_multi.h" diff --git a/srsue/test/phy/ue_itf_test_sib1.cc b/srsue/test/phy/ue_itf_test_sib1.cc index c73758cc6..bf1f9bbe7 100644 --- a/srsue/test/phy/ue_itf_test_sib1.cc +++ b/srsue/test/phy/ue_itf_test_sib1.cc @@ -27,7 +27,7 @@ #include #include "srslte/phy/utils/debug.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/common/log_filter.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/radio/radio_multi.h" diff --git a/srsue/test/upper/ip_test.cc b/srsue/test/upper/ip_test.cc index afed88ebc..a4f9743cc 100644 --- a/srsue/test/upper/ip_test.cc +++ b/srsue/test/upper/ip_test.cc @@ -16,15 +16,15 @@ #include #include "srslte/phy/utils/debug.h" -#include "mac/mac.h" -#include "phy/phy.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/common/threads.h" #include "srslte/common/common.h" #include "srslte/common/buffer_pool.h" #include "srslte/common/logger_file.h" #include "srslte/common/log_filter.h" #include "srslte/upper/rlc.h" -#include "upper/rrc.h" +#include "srsue/hdr/upper/rrc.h" #include "srslte/radio/radio_multi.h" #define START_TUNTAP diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index 107a577b6..2a51392ed 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -26,11 +26,11 @@ #include #include -#include "upper/usim.h" -#include "upper/nas.h" +#include "srsue/hdr/upper/usim.h" +#include "srsue/hdr/upper/nas.h" #include "srslte/upper/rlc.h" -#include "upper/rrc.h" -#include "mac/mac.h" +#include "srsue/hdr/upper/rrc.h" +#include "srsue/hdr/mac/mac.h" #include "srslte/common/log_filter.h" #include "srslte/upper/pdcp_entity.h" #include "srslte/upper/pdcp.h" diff --git a/srsue/test/upper/usim_test.cc b/srsue/test/upper/usim_test.cc index bf60e124c..225bee36d 100644 --- a/srsue/test/upper/usim_test.cc +++ b/srsue/test/upper/usim_test.cc @@ -25,7 +25,7 @@ */ #include -#include "upper/usim.h" +#include "srsue/hdr/upper/usim.h" #include "srslte/common/log_filter.h" #include