diff --git a/CMakeLists.txt b/CMakeLists.txt index 290754ee3..d495d54a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,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 -Wformat -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 -Wtype-limits -std=c++03") find_package(SSE) if (HAVE_AVX2) @@ -243,7 +243,7 @@ endif(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clan ADD_CXX_COMPILER_FLAG_IF_AVAILABLE("-Werror=incompatible-pointer-types" HAVE_ERROR_INCOMPATIBLE) if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-write-strings -Wno-format-extra-args -Winline -Wno-unused-result -Wno-format -std=c99 -D_GNU_SOURCE") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-write-strings -Winline -Wno-unused-result -Wformat -Wtype-limits -std=c99 -D_GNU_SOURCE") if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0 -DDEBUG_MODE -DBUILD_TYPE_DEBUG") diff --git a/lib/examples/synch_file.c b/lib/examples/synch_file.c index 4d553bd38..c73e8d9dc 100644 --- a/lib/examples/synch_file.c +++ b/lib/examples/synch_file.c @@ -113,7 +113,7 @@ int main(int argc, char **argv) { uint32_t m0, m1; float m0_value, m1_value; uint32_t N_id_2; - uint32_t sss_idx; + int sss_idx; struct timeval tdata[3]; int *exec_time; diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index b47f79d90..79dbdc088 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -129,13 +129,13 @@ public: virtual void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; // Same with hex dump - virtual void error_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void error_hex(const uint8_t *, int, 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))) + virtual void warning_hex(const uint8_t *, int, 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))) + virtual void info_hex(const uint8_t *, int, 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))) + virtual void debug_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) {error("debug_hex not implemented.\n");} protected: diff --git a/lib/include/srslte/common/pdu.h b/lib/include/srslte/common/pdu.h index cc2bb64f5..e9ee1f0e9 100644 --- a/lib/include/srslte/common/pdu.h +++ b/lib/include/srslte/common/pdu.h @@ -258,7 +258,7 @@ public: private: static const int MAX_CE_PAYLOAD_LEN = 8; uint32_t lcid; - int nof_bytes; + uint32_t nof_bytes; uint8_t* payload; uint8_t w_payload_ce[8]; bool F_bit; diff --git a/lib/src/common/pdu.cc b/lib/src/common/pdu.cc index 95d9dde9b..09fae2774 100644 --- a/lib/src/common/pdu.cc +++ b/lib/src/common/pdu.cc @@ -103,8 +103,10 @@ void sch_pdu::parse_packet(uint8_t *ptr) read_len += subheaders[i].size_plus_header(); } - if (pdu_len-read_len-1 >= 0) { - subheaders[nof_subheaders-1].set_payload_size(pdu_len-read_len-1); + int n_sub = pdu_len-read_len-1; + + if (n_sub >= 0) { + subheaders[nof_subheaders-1].set_payload_size(n_sub); } else { fprintf(stderr,"Reading MAC PDU: negative payload for last subheader\n"); } @@ -584,17 +586,22 @@ int sch_subh::set_sdu(uint32_t lcid_, uint32_t requested_bytes, read_pdu_interfa payload = ((sch_pdu*)parent)->get_current_sdu_ptr(); // Copy data and get final number of bytes written to the MAC PDU - uint32_t sdu_sz = sdu_itf->read_pdu(lcid, payload, requested_bytes); + int sdu_sz = sdu_itf->read_pdu(lcid, payload, requested_bytes); - if (sdu_sz < 0 || sdu_sz > requested_bytes) { + if (sdu_sz < 0) { return -1; } if (sdu_sz == 0) { return 0; } + else { + // Save final number of written bytes + nof_bytes = sdu_sz; - // Save final number of written bytes - nof_bytes = sdu_sz; + if(nof_bytes > requested_bytes) { + return -1; + } + } ((sch_pdu*)parent)->add_sdu(nof_bytes); ((sch_pdu*)parent)->update_space_sdu(nof_bytes); diff --git a/lib/src/phy/fec/test/turbocoder_test.c b/lib/src/phy/fec/test/turbocoder_test.c index 8daeebdb8..f8219a4e2 100644 --- a/lib/src/phy/fec/test/turbocoder_test.c +++ b/lib/src/phy/fec/test/turbocoder_test.c @@ -40,7 +40,7 @@ uint32_t long_cb = 0; void usage(char *prog) { printf("Usage: %s\n", prog); - printf("\t-l long_cb [Default check all]\n", long_cb); + printf("\t-l long_cb [Default %u]\n", long_cb); } void parse_args(int argc, char **argv) { diff --git a/lib/src/phy/phch/test/pbch_file_test.c b/lib/src/phy/phch/test/pbch_file_test.c index 6b79db422..dac516859 100644 --- a/lib/src/phy/phch/test/pbch_file_test.c +++ b/lib/src/phy/phch/test/pbch_file_test.c @@ -208,7 +208,7 @@ int main(int argc, char **argv) { /* Get channel estimates for each port */ srslte_chest_dl_estimate(&chest, fft_buffer, ce, 0); - INFO("Decoding PBCH\n", 0); + INFO("Decoding PBCH\n"); for (int i=0;irrc_log->info_hex(k_enb, 32, "Key eNodeB (k_enb)"); // Select algos (TODO: use security capabilities and config preferences) cipher_algo = srslte::CIPHERING_ALGORITHM_ID_EEA0; integ_algo = srslte::INTEGRITY_ALGORITHM_ID_128_EIA1; diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 9df615914..e0b7d93fa 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -47,7 +47,20 @@ 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 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); + +private: + s1ap_nas_transport(); + virtual ~s1ap_nas_transport(); + + srslte::log *m_s1ap_log; + srslte::byte_buffer_pool *m_pool; + + s1ap* m_s1ap; + hss_interface_s1ap* m_hss; + mme_gtpc* m_mme_gtpc; + + //Initial UE messages bool handle_nas_attach_request( uint32_t enb_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, @@ -107,7 +120,6 @@ public: 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_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(ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg); @@ -116,18 +128,6 @@ public: void log_unhandled_attach_request_ies(const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT *attach_req); void log_unhandled_pdn_con_request_ies(const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT *pdn_con_req); void log_unhandled_initial_ue_message_ies(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue); - - -private: - s1ap_nas_transport(); - virtual ~s1ap_nas_transport(); - - srslte::log *m_s1ap_log; - srslte::byte_buffer_pool *m_pool; - - s1ap* m_s1ap; - hss_interface_s1ap* m_hss; - mme_gtpc* m_mme_gtpc; }; } //namespace srsepc #endif // SRSEPC_S1AP_NAS_TRANSPORT_H diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 5500fa561..a509b8a70 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -159,7 +159,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, } //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"); + m_s1ap_log->info_hex(emm_ctx->security_ctxt.k_enb, 32, "Initial Context Setup Request -- Key eNB (k_enb)\n"); srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); if(emm_ctx->state == EMM_STATE_DEREGISTERED) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 1a34c86e2..940271d95 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -674,10 +674,11 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_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); + srslte::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->info_hex(emm_ctx->security_ctxt.k_enb, 32, "Key eNodeB (k_enb)\n"); + 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); @@ -873,8 +874,10 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, 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); + srslte::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->info_hex(emm_ctx->security_ctxt.k_enb, 32, "Key eNodeB (k_enb)\n"); m_s1ap_log->console("UE Ctr TEID %d\n", emm_ctx->sgw_ctrl_fteid.teid); //Save UE ctx to MME UE S1AP id @@ -1029,6 +1032,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 + emm_ctx->security_ctxt.ul_nas_count = 0; // Reset the NAS uplink counter for the right key k_enb derivation pack_security_mode_command(reply_buffer, emm_ctx, ecm_ctx); *reply_flag = true; m_s1ap_log->console("Downlink NAS: Sending NAS Security Mode Command.\n"); @@ -1118,10 +1122,10 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u //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"); + m_s1ap_log->console("Packing EMM Information\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"); + m_s1ap_log->console("Sending EMM Information, bytes %d\n",reply_msg->N_bytes); + m_s1ap_log->info("Sending EMM Information\n"); } emm_ctx->state = EMM_STATE_REGISTERED; return true; @@ -1178,8 +1182,8 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ 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); + m_s1ap_log->info("ID response -- IMSI: %015lu\n", imsi); + m_s1ap_log->console("ID Response -- IMSI: %015lu\n", imsi); //Set UE's context IMSI emm_ctx->imsi=imsi; @@ -1617,15 +1621,15 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_emm_ctx->security_ctxt.k_nas_enc, ue_emm_ctx->security_ctxt.k_nas_int ); - 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 - ); + + m_s1ap_log->info_hex(ue_emm_ctx->security_ctxt.k_nas_enc, 32, "Key NAS Encryption (k_nas_enc)\n"); + m_s1ap_log->info_hex(ue_emm_ctx->security_ctxt.k_nas_int, 32, "Key NAS Integrity (k_nas_int)\n"); + 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); + srslte::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); + m_s1ap_log->console("Generating KeNB with UL NAS COUNT: %d\n", ue_emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->info_hex(ue_emm_ctx->security_ctxt.k_enb, 32, "Key eNodeB (k_enb)\n"); //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],