diff --git a/CMakeLists.txt b/CMakeLists.txt index bec61464a..857765c44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,10 +203,12 @@ endif(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-write-strings -Wno-format-extra-args -Winline -Wno-unused-result -Wno-format -std=c99 -D_GNU_SOURCE -g") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable") if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") find_package(SSE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -DDEBUG_MODE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -std=c++03") if(HAVE_AVX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mfpmath=sse -mavx -DLV_HAVE_AVX -DLV_HAVE_SSE") elseif(HAVE_SSE) @@ -214,14 +216,18 @@ if(CMAKE_COMPILER_IS_GNUCC) endif(HAVE_AVX) else(${CMAKE_BUILD_TYPE} STREQUAL "Debug") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++03") find_package(SSE) if (HAVE_AVX2) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mfpmath=sse -mavx2 -Ofast -funroll-loops -DLV_HAVE_AVX -DLV_HAVE_SSE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mfpmath=sse -mavx2 -DLV_HAVE_AVX -DLV_HAVE_SSE") else (HAVE_AVX2) if(HAVE_AVX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mfpmath=sse -mavx -Ofast -funroll-loops -DLV_HAVE_AVX -DLV_HAVE_SSE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mfpmath=sse -mavx -DLV_HAVE_AVX -DLV_HAVE_SSE") elseif(HAVE_SSE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mfpmath=sse -msse4.1 -Ofast -funroll-loops -DLV_HAVE_SSE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mfpmath=sse -msse4.1 -DLV_HAVE_SSE") endif(HAVE_AVX) endif (HAVE_AVX2) @@ -289,6 +295,19 @@ include_directories(${PROJECT_SOURCE_DIR}/lib/include) # Includes needed by all code previously resided in srsUE include_directories(${PROJECT_SOURCE_DIR}/lib/include/srslte) +######################################################################## +# Add headers to cmake project (useful for IDEs) +######################################################################## +set(HEADERS_ALL "") +file(GLOB headers *) +foreach(_header ${headers}) + if(IS_DIRECTORY ${_header}) + file(GLOB_RECURSE tmp "${_header}/*.h") + list(APPEND HEADERS_ALL ${tmp}) + endif(IS_DIRECTORY ${_header}) +endforeach() +add_custom_target(add_srslte_headers SOURCES ${HEADERS_ALL}) + ######################################################################## # Add the subdirectories ######################################################################## diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 55a029469..dc2c96809 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -26,19 +26,6 @@ INSTALL(DIRECTORY include/ FILES_MATCHING PATTERN "*.h" ) -######################################################################## -# Add headers to cmake project (useful for IDEs) -######################################################################## -set(HEADERS_ALL "") -file(GLOB headers *) -FOREACH (_header ${headers}) - if(IS_DIRECTORY ${_header}) - file(GLOB_RECURSE tmp "${_header}/*.h") - list(APPEND HEADERS_ALL ${tmp}) - endif(IS_DIRECTORY ${_header}) -ENDFOREACH() -add_custom_target (add_srslte_headers SOURCES ${HEADERS_ALL}) - ######################################################################## # Find Dependencies ######################################################################## diff --git a/lib/include/srslte/asn1/liblte_common.h b/lib/include/srslte/asn1/liblte_common.h index 71e0bb76f..36fb32190 100644 --- a/lib/include/srslte/asn1/liblte_common.h +++ b/lib/include/srslte/asn1/liblte_common.h @@ -121,8 +121,12 @@ struct LIBLTE_BYTE_MSG_STRUCT{ } LIBLTE_BYTE_MSG_STRUCT & operator= (const LIBLTE_BYTE_MSG_STRUCT & buf) { + // avoid self assignment + if (&buf == this) + return *this; N_bytes = buf.N_bytes; memcpy(msg, buf.msg, N_bytes); + return *this; } uint32 get_headroom() { @@ -152,8 +156,12 @@ struct LIBLTE_BIT_MSG_STRUCT{ memcpy(msg, buf.msg, N_bits); } LIBLTE_BIT_MSG_STRUCT & operator= (const LIBLTE_BIT_MSG_STRUCT & buf){ + // avoid self assignment + if (&buf == this) + return *this; N_bits = buf.N_bits; memcpy(msg, buf.msg, N_bits); + return *this; } uint32 get_headroom() { diff --git a/lib/include/srslte/asn1/liblte_rrc.h b/lib/include/srslte/asn1/liblte_rrc.h index 71fe37f99..5a8515dbb 100644 --- a/lib/include/srslte/asn1/liblte_rrc.h +++ b/lib/include/srslte/asn1/liblte_rrc.h @@ -4494,7 +4494,7 @@ typedef enum{ }LIBLTE_RRC_MAX_RETX_THRESHOLD_ENUM; static const char liblte_rrc_max_retx_threshold_text[LIBLTE_RRC_MAX_RETX_THRESHOLD_N_ITEMS][20] = { "t1", "t2", "t3", "t4", "t6", "t8", "t16", "t32"}; -static const int32 liblte_rrc_max_retx_threshold_num[LIBLTE_RRC_MAX_RETX_THRESHOLD_N_ITEMS] = { 1, 2, 3, 4, +static const uint32_t liblte_rrc_max_retx_threshold_num[LIBLTE_RRC_MAX_RETX_THRESHOLD_N_ITEMS] = { 1, 2, 3, 4, 6, 8, 16, 32}; typedef enum{ LIBLTE_RRC_T_REORDERING_MS0 = 0, diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index 231afefe0..8058d1f51 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -57,7 +57,7 @@ public: buffer_pool(uint32_t nof_buffers = POOL_SIZE) { pthread_mutex_init(&mutex, NULL); - for(int i=0;i 0) { + if (nof_subheaders < (int)max_subheaders - 1 && rem_len > 0) { nof_subheaders++; next(); return true; @@ -148,7 +148,7 @@ protected: uint32_t pdu_len; uint32_t rem_len; int cur_idx; - int nof_subheaders; + int nof_subheaders; uint32_t max_subheaders; bool pdu_is_ul; uint8_t* buffer_tx; @@ -169,7 +169,7 @@ private: total_sdu_len = 0; last_sdu_idx = -1; reset(); - for (int i=0;istep(); } } void stop_all() { - for (int i=0;istop(); } } void run_all() { - for (int i=0;irun(); } } void reset_all() { - for (int i=0;ireset(); } } diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index dcb6e2734..2dba1da26 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -134,7 +134,7 @@ private: int32_t t_poll_retx; // Poll retx timeout (ms) int32_t poll_pdu; // Insert poll bit after this many PDUs int32_t poll_byte; // Insert poll bit after this much data (KB) - int32_t max_retx_thresh; // Max number of retx + uint32_t max_retx_thresh; // Max number of retx // RX configs int32_t t_reordering; // Timer used by rx to detect PDU loss (ms) diff --git a/lib/include/srslte/upper/rlc_common.h b/lib/include/srslte/upper/rlc_common.h index bb353a6ae..f43973d41 100644 --- a/lib/include/srslte/upper/rlc_common.h +++ b/lib/include/srslte/upper/rlc_common.h @@ -126,7 +126,7 @@ struct rlc_amd_pdu_header_t{ lsf = h.lsf; so = h.so; N_li = h.N_li; - for(int i=0;i= nbytes; + int s = get_sdu_space(); + + if (s < 0) { + return false; + } else { + return (uint32_t)s >= nbytes; + } } bool sch_pdu::update_space_sdu(uint32_t nbytes) @@ -495,7 +501,7 @@ bool sch_subh::set_bsr(uint32_t buff_size[4], sch_subh::cetype format) w_payload_ce[1] = (buff_size_table(buff_size[1])&0xf) << 4 | (buff_size_table(buff_size[2])&0xf0)>>4; w_payload_ce[2] = (buff_size_table(buff_size[2])&0x3) << 6 | (buff_size_table(buff_size[3])&0x3f); } else { - w_payload_ce[0] = (nonzero_lcg&0x3)<<6 | buff_size_table(buff_size[nonzero_lcg])&0x3f; + w_payload_ce[0] = (nonzero_lcg&0x3)<<6 | (buff_size_table(buff_size[nonzero_lcg])&0x3f); } lcid = format; ((sch_pdu*)parent)->update_space_ce(ce_size); @@ -569,7 +575,7 @@ 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 - int sdu_sz = sdu_itf->read_pdu(lcid, payload, requested_bytes); + uint32_t sdu_sz = sdu_itf->read_pdu(lcid, payload, requested_bytes); if (sdu_sz < 0 || sdu_sz > requested_bytes) { return -1; @@ -652,7 +658,7 @@ bool sch_subh::read_subheader(uint8_t** ptr) nof_bytes = (uint32_t)*(*ptr) & 0x7f; *ptr += 1; if (F_bit) { - nof_bytes = nof_bytes<<8 | (uint32_t) *(*ptr) & 0xff; + nof_bytes = nof_bytes<<8 | ((uint32_t) *(*ptr) & 0xff); *ptr += 1; } } else { @@ -807,7 +813,7 @@ void rar_subh::set_temp_crnti(uint16_t temp_rnti_) // Section 6.2.2 void rar_subh::write_subheader(uint8_t** ptr, bool is_last) { - *(*ptr) = (uint8_t) (!is_last<<7 | 1<<6 | preamble & 0x3f); + *(*ptr) = (uint8_t) (!is_last<<7 | 1<<6 | (preamble & 0x3f)); *ptr += 1; } // Section 6.2.3 diff --git a/lib/src/common/thread_pool.cc b/lib/src/common/thread_pool.cc index 330a38043..aa9362227 100644 --- a/lib/src/common/thread_pool.cc +++ b/lib/src/common/thread_pool.cc @@ -84,7 +84,7 @@ thread_pool::thread_pool(uint32_t max_workers_) : { max_workers = max_workers_; - for (int i=0;isf_idx, q->cell.id, cfg->nbits.nof_bits)) { return SRSLTE_ERROR; } - srslte_scrambling_bytes(&q->users[rnti]->seq[cfg->sf_idx], (uint8_t*) q->e, cfg->nbits.nof_bits); + srslte_scrambling_bytes(&seq, (uint8_t*) q->e, cfg->nbits.nof_bits); srslte_sequence_free(&seq); } else { srslte_scrambling_bytes(&q->users[rnti]->seq[cfg->sf_idx], (uint8_t*) q->e, cfg->nbits.nof_bits); diff --git a/lib/src/phy/rf/rf_soapy_imp.c b/lib/src/phy/rf/rf_soapy_imp.c index 89a26c124..8fcf57c24 100644 --- a/lib/src/phy/rf/rf_soapy_imp.c +++ b/lib/src/phy/rf/rf_soapy_imp.c @@ -36,422 +36,400 @@ #include #include -//#include "lime/LimeSuite.h" typedef struct { - - SoapySDRKwargs args; - SoapySDRDevice *device; - SoapySDRRange *ranges; - - SoapySDRStream *rxStream; - SoapySDRStream *txStream; - - + SoapySDRKwargs args; + SoapySDRDevice *device; + SoapySDRRange *ranges; + SoapySDRStream *rxStream; + SoapySDRStream *txStream; } rf_soapy_handler_t; + int soapy_error(void *h) { - + return 0; } + void rf_soapy_get_freq_range(void *h) { - + } + void rf_soapy_suppress_handler(const char *x) { - // not supported + // not supported } + void rf_soapy_msg_handler(const char *msg) { - // not supported + // not supported } + void rf_soapy_suppress_stdout(void *h) { - // not supported + // not supported } + void rf_soapy_register_error_handler(void *notused, srslte_rf_error_handler_t new_handler) { - // not supported + // not supported } -static bool isLocked(rf_soapy_handler_t *handler, char *sensor_name, void *value_h) -{ - // not supported - return true; -} char* rf_soapy_devname(void* h) { - + return "soapy"; } bool rf_soapy_rx_wait_lo_locked(void *h) { - // not supported + printf("TODO: implement rf_soapy_rx_wait_lo_locked()\n"); return true; } + void rf_soapy_set_tx_cal(void *h, srslte_rf_cal_t *cal) { + printf("TODO: implement rf_soapy_rx_wait_lo_locked()\n"); // not supported } -void rf_soapy_set_rx_cal(void *h, srslte_rf_cal_t *cal) + +void rf_soapy_set_rx_cal(void *h, srslte_rf_cal_t *cal) { - // not supported + printf("TODO: implement rf_soapy_set_rx_cal()\n"); } + int rf_soapy_start_rx_stream(void *h) { - //printf("starting SOAPY rx stream \n"); - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - //SoapySDRStream *rxStream; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if(SoapySDRDevice_activateStream(handler->device, handler->rxStream, 0, 0, 0)!=0)//start streaming - return SRSLTE_ERROR; - - - return SRSLTE_SUCCESS; + if (SoapySDRDevice_activateStream(handler->device, handler->rxStream, 0, 0, 0) != 0) + return SRSLTE_ERROR; + + return SRSLTE_SUCCESS; } int rf_soapy_start_tx_stream(void *h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - //SoapySDRStream *rxStream; - if (SoapySDRDevice_setupStream(handler->device, &(handler->txStream), SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) - { - printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; - } - if(SoapySDRDevice_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0) - return SRSLTE_ERROR; - - - return SRSLTE_SUCCESS; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (SoapySDRDevice_setupStream(handler->device, &(handler->txStream), SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) { + printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } + + if(SoapySDRDevice_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0) + return SRSLTE_ERROR; + + return SRSLTE_SUCCESS; } + int rf_soapy_stop_rx_stream(void *h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if(SoapySDRDevice_deactivateStream(handler->device, handler->rxStream, 0, 0) != 0) - return SRSLTE_ERROR; - - - - return SRSLTE_SUCCESS; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (SoapySDRDevice_deactivateStream(handler->device, handler->rxStream, 0, 0) != 0) + return SRSLTE_ERROR; + + return SRSLTE_SUCCESS; } + + int rf_soapy_stop_tx_stream(void *h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - - if(SoapySDRDevice_deactivateStream(handler->device, handler->txStream, 0, 0) != 0) - return SRSLTE_ERROR; - - - - return SRSLTE_SUCCESS; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if(SoapySDRDevice_deactivateStream(handler->device, handler->txStream, 0, 0) != 0) + return SRSLTE_ERROR; + + return SRSLTE_SUCCESS; } + void rf_soapy_flush_buffer(void *h) { - int n; + int n; cf_t tmp1[1024]; cf_t tmp2[1024]; void *data[2] = {tmp1, tmp2}; do { n = rf_soapy_recv_with_time_multi(h, data, 1024, 0, NULL, NULL); - } while (n > 0); + } while (n > 0); } + bool rf_soapy_has_rssi(void *h) { - + printf("TODO: implement rf_soapy_has_rssi()\n"); + return false; } + float rf_soapy_get_rssi(void *h) { - + printf("TODO: implement rf_soapy_get_rssi()\n"); + return 0.0; } + //TODO: add multi-channel support int rf_soapy_open_multi(char *args, void **h, uint32_t nof_rx_antennas) -{//SoapySDRKwargs soapy_args = {}; - size_t length; - const SoapySDRKwargs *soapy_args = SoapySDRDevice_enumerate(NULL, &length); - - if(length == 0) - { - return SRSLTE_ERROR; - } - - for (size_t i = 0; i < length; i++) - { - printf("Soapy Has Found device #%d: ", (int)i); - for (size_t j = 0; j < soapy_args[i].size; j++) - { - printf("%s=%s, ", soapy_args[i].keys[j], soapy_args[i].vals[j]); - } - printf("\n"); - } - - // SoapySDRrgs_set(&soapy_args, "driver", "rtlsdr"); - SoapySDRDevice *sdr = SoapySDRDevice_make(&(soapy_args[0])); - - if(sdr == NULL) - { - printf("failed to create SOAPY object\n"); - return SRSLTE_ERROR; - - } - - //SoapySDRKwargs_clear(&soapy_args); - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) malloc(sizeof(rf_soapy_handler_t)); - *h = handler; - handler->device = sdr; - - - - //size_t channels[1]; - //channels[0] = 0; - - if (SoapySDRDevice_setupStream(handler->device, &(handler->rxStream), SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) +{ + size_t length; + const SoapySDRKwargs *soapy_args = SoapySDRDevice_enumerate(NULL, &length); + + if (length == 0) { + printf("No Soapy devices found.\n"); + return SRSLTE_ERROR; + } + + for (size_t i = 0; i < length; i++) { + printf("Soapy Has Found device #%d: ", (int)i); + for (size_t j = 0; j < soapy_args[i].size; j++) { - printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; + printf("%s=%s, ", soapy_args[i].keys[j], soapy_args[i].vals[j]); } - - - - return SRSLTE_SUCCESS; - + printf("\n"); + } + + SoapySDRDevice *sdr = SoapySDRDevice_make(&(soapy_args[0])); + if (sdr == NULL) { + printf("failed to create SOAPY object\n"); + return SRSLTE_ERROR; + } + + // create handler + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) malloc(sizeof(rf_soapy_handler_t)); + bzero(handler, sizeof(rf_soapy_handler_t)); + *h = handler; + handler->device = sdr; + + if (SoapySDRDevice_setupStream(handler->device, &(handler->rxStream), SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) { + printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } + + return SRSLTE_SUCCESS; } + int rf_soapy_open(char *args, void **h) { - return rf_soapy_open_multi(args, h, 1); + return rf_soapy_open_multi(args, h, 1); } int rf_soapy_close(void *h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - SoapySDRDevice_closeStream(handler->device, handler->txStream); - SoapySDRDevice_closeStream(handler->device, handler->rxStream); - SoapySDRDevice_unmake(handler->device); + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (handler->txStream) { + rf_soapy_stop_tx_stream(handler); + SoapySDRDevice_closeStream(handler->device, handler->txStream); + } + + if (handler->rxStream) { + rf_soapy_stop_rx_stream(handler); + SoapySDRDevice_closeStream(handler->device, handler->rxStream); + } + + SoapySDRDevice_unmake(handler->device); + free(handler); + + return SRSLTE_SUCCESS; } void rf_soapy_set_master_clock_rate(void *h, double rate) { // Allow the soapy to automatically set the appropriate clock rate - - printf("SET MASTER CLOCK RATE\n"); + // TODO: implement this function } -bool rf_soapy_is_master_clock_dynamic(void *h) + +bool rf_soapy_is_master_clock_dynamic(void *h) { - + printf("TODO: implement rf_soapy_is_master_clock_dynamic()\n"); + return false; } + double rf_soapy_set_rx_srate(void *h, double rate) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if (SoapySDRDevice_setSampleRate(handler->device, SOAPY_SDR_RX, 0, rate) != 0) - { - printf("setSampleRate fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; - } - - double ret = SoapySDRDevice_getSampleRate(handler->device, SOAPY_SDR_RX,0); - printf("Sampling rate is set to %f.3 : \n",ret); - return ret; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (SoapySDRDevice_setSampleRate(handler->device, SOAPY_SDR_RX, 0, rate) != 0) { + printf("setSampleRate fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } + return SoapySDRDevice_getSampleRate(handler->device, SOAPY_SDR_RX,0); } double rf_soapy_set_tx_srate(void *h, double rate) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if (SoapySDRDevice_setSampleRate(handler->device, SOAPY_SDR_TX, 0, rate) != 0) - { - printf("setSampleRate fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; - } - double ret = SoapySDRDevice_getSampleRate(handler->device, SOAPY_SDR_TX,0); - printf("Sampling rate is set to %f.3 : \n",ret); - return ret; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (SoapySDRDevice_setSampleRate(handler->device, SOAPY_SDR_TX, 0, rate) != 0) { + printf("setSampleRate fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } + return SoapySDRDevice_getSampleRate(handler->device, SOAPY_SDR_TX,0); } + double rf_soapy_set_rx_gain(void *h, double gain) { - - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if (SoapySDRDevice_setGain(handler->device, SOAPY_SDR_RX, 0, gain) != 0) - { - printf("setGain fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; - } - double ret = rf_soapy_get_rx_gain(h); - printf("gain has been set to %f.2 \n",ret); - return ret; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (SoapySDRDevice_setGain(handler->device, SOAPY_SDR_RX, 0, gain) != 0) + { + printf("setGain fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } + return rf_soapy_get_rx_gain(h); } + double rf_soapy_set_tx_gain(void *h, double gain) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if (SoapySDRDevice_setGain(handler->device, SOAPY_SDR_TX, 0, gain) != 0) - { - printf("setGain fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; - } - double ret = rf_soapy_get_rx_gain(h); - printf("gain has been set to %f.2 \n",ret); - return ret; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (SoapySDRDevice_setGain(handler->device, SOAPY_SDR_TX, 0, gain) != 0) + { + printf("setGain fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } + return rf_soapy_get_rx_gain(h); } + double rf_soapy_get_rx_gain(void *h) { - - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - return SoapySDRDevice_getGain(handler->device,SOAPY_SDR_RX,0); - + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + return SoapySDRDevice_getGain(handler->device,SOAPY_SDR_RX,0); } + double rf_soapy_get_tx_gain(void *h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - return SoapySDRDevice_getGain(handler->device,SOAPY_SDR_TX,0); + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + return SoapySDRDevice_getGain(handler->device,SOAPY_SDR_TX,0); } + double rf_soapy_set_rx_freq(void *h, double freq) { - - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if (SoapySDRDevice_setFrequency(handler->device, SOAPY_SDR_RX, 0, freq, NULL) != 0) - { - printf("setFrequency fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; - } - - double ret = SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_RX, 0); - printf("Frequency has been set to %f : \n",ret); - return ret; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (SoapySDRDevice_setFrequency(handler->device, SOAPY_SDR_RX, 0, freq, NULL) != 0) + { + printf("setFrequency fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } + return SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_RX, 0); } double rf_soapy_set_tx_freq(void *h, double freq) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if (SoapySDRDevice_setFrequency(handler->device, SOAPY_SDR_TX, 0, freq, NULL) != 0) - { - printf("setFrequency fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; - } - double ret = SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_RX, 0); - printf("Frequency has been set to %f : \n",ret); - return ret; - + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + if (SoapySDRDevice_setFrequency(handler->device, SOAPY_SDR_TX, 0, freq, NULL) != 0) + { + printf("setFrequency fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } + return SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_RX, 0); } void rf_soapy_get_time(void *h, time_t *secs, double *frac_secs) { - + } //TODO: add multi-channel support int rf_soapy_recv_with_time_multi(void *h, - void **data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs) -{ - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - //void *buffs[] = {buff}; //array of buffers - - int flags; //flags set by receive operation - - int num_channels = 1; // temp - - int trials = 0; - int ret = 0; - long long timeNs; //timestamp for receive buffer - int n = 0; - do{ - - size_t rx_samples = nsamples; - - if (rx_samples > nsamples - n) - { - rx_samples = nsamples - n; - } - void *buffs_ptr[4]; - for (int i=0;idevice, handler->rxStream,buffs_ptr , rx_samples, &flags, &timeNs, 1000000); - - if(ret < 0) - return SRSLTE_ERROR; - n += ret; - trials++; - }while (n < nsamples && trials < 100); - - - //*secs = timeNs / 1000000000; - //*frac_secs = (timeNs % 1000000000)/1000000000; - // printf("ret=%d, flags=%d, timeNs=%lld\n", ret, flags, timeNs); - return n; + void **data, + uint32_t nsamples, + bool blocking, + time_t *secs, + double *frac_secs) +{ + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + //void *buffs[] = {buff}; //array of buffers + + int flags; //flags set by receive operation + + int num_channels = 1; // temp + + int trials = 0; + int ret = 0; + long long timeNs; //timestamp for receive buffer + int n = 0; + do { + size_t rx_samples = nsamples; - + if (rx_samples > nsamples - n) + { + rx_samples = nsamples - n; + } + void *buffs_ptr[4]; + for (int i=0; idevice, handler->rxStream, buffs_ptr , rx_samples, &flags, &timeNs, 1000000); + if(ret < 0) { + // continue when getting overflows + if (ret == SOAPY_SDR_OVERFLOW) { + fprintf(stderr, "O"); + fflush(stderr); + continue; + } else { + return SRSLTE_ERROR; + } + } + + n += ret; + trials++; + } while (n < nsamples && trials < 100); + + + //*secs = timeNs / 1000000000; + //*frac_secs = (timeNs % 1000000000)/1000000000; + // printf("ret=%d, flags=%d, timeNs=%lld\n", ret, flags, timeNs); + return n; } int rf_soapy_recv_with_time(void *h, - void *data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs) + void *data, + uint32_t nsamples, + bool blocking, + time_t *secs, + double *frac_secs) { - return rf_soapy_recv_with_time_multi(h, &data, nsamples, blocking, secs, frac_secs); + return rf_soapy_recv_with_time_multi(h, &data, nsamples, blocking, secs, frac_secs); } - -int rf_soapy_send_timed(void *h, - void *data, - int nsamples, - time_t secs, - double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst) -{ - - int flags; - long long timeNs; - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - timeNs = secs * 1000000000; - timeNs = timeNs + (frac_secs * 1000000000); - int ret = SoapySDRDevice_writeStream(handler->device, handler->txStream, &data, nsamples, &flags, timeNs, 100000); - - - - if(ret != nsamples) - return SRSLTE_ERROR; - - - - return ret; +int rf_soapy_send_timed(void *h, + void *data, + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst) +{ + int flags; + long long timeNs; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + timeNs = secs * 1000000000; + timeNs = timeNs + (frac_secs * 1000000000); + int ret = SoapySDRDevice_writeStream(handler->device, handler->txStream, data, nsamples, &flags, timeNs, 100000); + if(ret != nsamples) + return SRSLTE_ERROR; + + return ret; } - - - - diff --git a/lib/src/phy/rf/rf_soapy_imp.h b/lib/src/phy/rf/rf_soapy_imp.h index fff5ddd9c..23b59a8b3 100644 --- a/lib/src/phy/rf/rf_soapy_imp.h +++ b/lib/src/phy/rf/rf_soapy_imp.h @@ -30,12 +30,12 @@ #include "srslte/phy/rf/rf.h" -SRSLTE_API int rf_soapy_open( char *args, - void **handler); +SRSLTE_API int rf_soapy_open(char *args, + void **handler); -SRSLTE_API int rf_soapy_open_multi( char *args, - void **handler, - uint32_t nof_rx_antennas); +SRSLTE_API int rf_soapy_open_multi(char *args, + void **handler, + uint32_t nof_rx_antennas); SRSLTE_API char* rf_soapy_devname(void *h); @@ -58,20 +58,20 @@ SRSLTE_API float rf_soapy_get_rssi(void *h); SRSLTE_API bool rf_soapy_rx_wait_lo_locked(void *h); SRSLTE_API void rf_soapy_set_master_clock_rate(void *h, - double rate); + double rate); SRSLTE_API bool rf_soapy_is_master_clock_dynamic(void *h); SRSLTE_API double rf_soapy_set_rx_srate(void *h, - double freq); + double freq); SRSLTE_API double rf_soapy_set_rx_gain(void *h, - double gain); + double gain); SRSLTE_API double rf_soapy_get_rx_gain(void *h); SRSLTE_API double rf_soapy_set_tx_gain(void *h, - double gain); + double gain); SRSLTE_API double rf_soapy_get_tx_gain(void *h); diff --git a/lib/src/phy/utils/vector.c b/lib/src/phy/utils/vector.c index 2c42886e9..a5921aeda 100644 --- a/lib/src/phy/utils/vector.c +++ b/lib/src/phy/utils/vector.c @@ -698,7 +698,7 @@ void srslte_vec_arg_cf(cf_t *x, float *arg, uint32_t len) { uint32_t srslte_vec_max_fi(float *x, uint32_t len) { #ifdef HAVE_VOLK_MAX_FUNCTION - uint32_t target=0; + uint16_t target=0; volk_32f_index_max_16u(&target,x,len); return target; @@ -763,7 +763,7 @@ void srslte_vec_max_fff(float *x, float *y, float *z, uint32_t len) { uint32_t srslte_vec_max_abs_ci(cf_t *x, uint32_t len) { #ifdef HAVE_VOLK_MAX_ABS_FUNCTION - uint32_t target=0; + uint16_t target=0; volk_32fc_index_max_16u(&target,x,len); return target; diff --git a/lib/src/upper/gw.cc b/lib/src/upper/gw.cc index c35cbb549..54c400825 100644 --- a/lib/src/upper/gw.cc +++ b/lib/src/upper/gw.cc @@ -115,7 +115,7 @@ void gw::write_pdu(uint32_t lcid, srslte::byte_buffer_t *pdu) gw_log->warning("TUN/TAP not up - dropping gw RX message\n"); }else{ int n = write(tun_fd, pdu->msg, pdu->N_bytes); - if(pdu->N_bytes != n) + if(n > 0 && (pdu->N_bytes != (uint32_t)n)) { gw_log->warning("DL TUN/TAP write failure\n"); } diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 5a2106271..a80376b9b 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -372,9 +372,9 @@ void rlc_am::check_reordering_timeout() bool rlc_am::poll_required() { - if(poll_pdu > 0 && pdu_without_poll > poll_pdu) + if(poll_pdu > 0 && pdu_without_poll > (uint32_t)poll_pdu) return true; - if(poll_byte > 0 && byte_without_poll > poll_byte) + if(poll_byte > 0 && byte_without_poll > (uint32_t)poll_byte) return true; if(poll_retx()) return true; @@ -402,7 +402,7 @@ int rlc_am::prepare_status() int rlc_am::build_status_pdu(uint8_t *payload, uint32_t nof_bytes) { int pdu_len = rlc_am_packed_length(&status); - if(nof_bytes >= pdu_len) + if(pdu_len > 0 && nof_bytes >= (uint32_t)pdu_len) { log->info("%s Tx status PDU - %s\n", rb_id_text[lcid], rlc_am_to_string(&status).c_str()); @@ -432,7 +432,7 @@ int rlc_am::build_retx_pdu(uint8_t *payload, uint32_t nof_bytes) } // Is resegmentation needed? - if(retx.is_segment || required_buffer_size(retx) > nof_bytes) { + if(retx.is_segment || required_buffer_size(retx) > (int)nof_bytes) { log->debug("%s build_retx_pdu - resegmentation required\n", rb_id_text[lcid]); return build_segment(payload, nof_bytes, retx); } @@ -506,7 +506,7 @@ int rlc_am::build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t r uint32_t upper = 0; uint32_t li = 0; - for(int i=0; i= retx.so_end) break; @@ -561,7 +561,7 @@ int rlc_am::build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t r debug_state(); int pdu_len = (ptr-payload) + len; - if(pdu_len > nof_bytes) { + if(pdu_len > (int)nof_bytes) { log->error("%s Retx PDU segment length error. Available: %d, Used: %d\n", rb_id_text[lcid], nof_bytes, pdu_len); log->debug("%s Retx PDU segment length error. Header len: %d, Payload len: %d, N_li: %d\n", @@ -784,8 +784,8 @@ void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_h if( vr_x == vr_r || (RX_MOD_BASE(vr_x) < RX_MOD_BASE(vr_r) || - RX_MOD_BASE(vr_x) > RX_MOD_BASE(vr_mr) && - vr_x != vr_mr) + (RX_MOD_BASE(vr_x) > RX_MOD_BASE(vr_mr) && + vr_x != vr_mr)) ) { reordering_timeout.reset(); @@ -902,7 +902,7 @@ void rlc_am::handle_control_pdu(uint8_t *payload, uint32_t nof_bytes) std::map::iterator it; bool nack = false; - for(int j=0;jmsg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, len); @@ -1076,7 +1076,7 @@ bool rlc_am::add_segment_and_check(rlc_amd_rx_pdu_segments_t *pdu, rlc_amd_rx_pd if(it->header.N_li > 0) { header.li[header.N_li++] = it->header.li[0] + carryover; count += it->header.li[0]; - for(int i=1; iheader.N_li; i++) { + for(uint32_t i=1; iheader.N_li; i++) { header.li[header.N_li++] = it->header.li[i]; count += it->header.li[i]; } @@ -1134,7 +1134,7 @@ int rlc_am::required_buffer_size(rlc_amd_retx_t retx) uint32_t upper = 0; uint32_t li = 0; - for(int i=0; i= retx.so_end) break; @@ -1448,7 +1448,7 @@ std::string rlc_am_to_string(rlc_status_pdu_t *status) if(status->N_nack > 0) { ss << ", NACK_SN = "; - for(int i=0; iN_nack; i++) + for(uint32_t i=0; iN_nack; i++) { if(status->nacks[i].has_so) { ss << "[" << status->nacks[i].nack_sn << " " << status->nacks[i].so_start \ diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 08b8a492e..ea01a6f7f 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -295,7 +295,8 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) // Check for SDU segment if(tx_sdu) { - to_move = ((pdu_space-head_len) >= tx_sdu->N_bytes) ? tx_sdu->N_bytes : pdu_space-head_len; + uint32_t space = pdu_space-head_len; + to_move = space >= tx_sdu->N_bytes ? tx_sdu->N_bytes : space; log->debug("%s adding remainder of SDU segment - %d bytes of %d remaining\n", rb_id_text[lcid], to_move, tx_sdu->N_bytes); memcpy(pdu_ptr, tx_sdu->msg, to_move); @@ -323,7 +324,8 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) header.li[header.N_li++] = last_li; head_len = rlc_um_packed_length(&header); tx_sdu_queue.read(&tx_sdu); - to_move = ((pdu_space-head_len) >= tx_sdu->N_bytes) ? tx_sdu->N_bytes : pdu_space-head_len; + uint32_t space = pdu_space-head_len; + to_move = space >= tx_sdu->N_bytes ? tx_sdu->N_bytes : space; log->debug("%s adding new SDU segment - %d bytes of %d remaining\n", rb_id_text[lcid], to_move, tx_sdu->N_bytes); memcpy(pdu_ptr, tx_sdu->msg, to_move); @@ -445,14 +447,14 @@ void rlc_um::reassemble_rx_sdus() rx_sdu->reset(); }else{ // Handle any SDU segments - for(int i=0; imsg[rx_sdu->N_bytes], rx_window[vr_ur].buf->msg, len); rx_sdu->N_bytes += len; rx_window[vr_ur].buf->msg += len; rx_window[vr_ur].buf->N_bytes -= len; - if(pdu_lost && !rlc_um_start_aligned(rx_window[vr_ur].header.fi) || vr_ur != ((vr_ur_in_rx_sdu+1)%rx_mod)) { + if((pdu_lost && !rlc_um_start_aligned(rx_window[vr_ur].header.fi)) || (vr_ur != ((vr_ur_in_rx_sdu+1)%rx_mod))) { log->warning("Dropping remainder of lost PDU (lower edge middle segments, vr_ur=%d, vr_ur_in_rx_sdu=%d)\n", vr_ur, vr_ur_in_rx_sdu); rx_sdu->reset(); } else { @@ -497,7 +499,7 @@ void rlc_um::reassemble_rx_sdus() while(rx_window.end() != rx_window.find(vr_ur)) { // Handle any SDU segments - for(int i=0; imsg[rx_sdu->N_bytes], rx_window[vr_ur].buf->msg, len); @@ -506,7 +508,7 @@ void rlc_um::reassemble_rx_sdus() rx_sdu->N_bytes += len; rx_window[vr_ur].buf->msg += len; rx_window[vr_ur].buf->N_bytes -= len; - if(pdu_lost && !rlc_um_start_aligned(rx_window[vr_ur].header.fi) || vr_ur != ((vr_ur_in_rx_sdu+1)%rx_mod)) { + if((pdu_lost && !rlc_um_start_aligned(rx_window[vr_ur].header.fi)) || (vr_ur != ((vr_ur_in_rx_sdu+1)%rx_mod))) { log->warning("Dropping remainder of lost PDU (update vr_ur middle segments, vr_ur=%d, vr_ur_in_rx_sdu=%d)\n", vr_ur, vr_ur_in_rx_sdu); rx_sdu->reset(); } else { diff --git a/lib/src/upper/rrc.cc b/lib/src/upper/rrc.cc index 141b54a4a..c33890d82 100644 --- a/lib/src/upper/rrc.cc +++ b/lib/src/upper/rrc.cc @@ -282,7 +282,7 @@ void rrc::write_pdu_bcch_dlsch(byte_buffer_t *pdu) liblte_rrc_si_window_length_num[sib1.si_window_length], liblte_rrc_si_periodicity_num[sib1.sched_info[0].si_periodicity]); std::stringstream ss; - for(int i=0;iinfo("Received paging (%d/%d) for UE 0x%x\n", i+1, pcch_msg.paging_record_list_size, pcch_msg.paging_record_list[i].ue_identity.s_tmsi); @@ -396,7 +396,7 @@ void rrc::send_con_request() // Byte align and pack the message bits for PDCP if((bit_buf.N_bits % 8) != 0) { - for(int i=0; i<8-(bit_buf.N_bits % 8); i++) + for(uint32_t i=0; i<8-(bit_buf.N_bits % 8); i++) bit_buf.msg[bit_buf.N_bits + i] = 0; bit_buf.N_bits += 8 - (bit_buf.N_bits % 8); } @@ -409,7 +409,7 @@ void rrc::send_con_request() uint64_t uecri=0; uint8_t *ue_cri_ptr = (uint8_t*) &uecri; uint32_t nbytes = 6; - for (int i=0;imsg[i]; } rrc_log->debug("Setting UE contention resolution ID: %d\n", uecri); @@ -490,7 +490,7 @@ void rrc::send_con_restablish_request() // Byte align and pack the message bits for PDCP if((bit_buf.N_bits % 8) != 0) { - for(int i=0; i<8-(bit_buf.N_bits % 8); i++) + for(uint32_t i=0; i<8-(bit_buf.N_bits % 8); i++) bit_buf.msg[bit_buf.N_bits + i] = 0; bit_buf.N_bits += 8 - (bit_buf.N_bits % 8); } @@ -502,7 +502,7 @@ void rrc::send_con_restablish_request() uint64_t uecri=0; uint8_t *ue_cri_ptr = (uint8_t*) &uecri; uint32_t nbytes = 6; - for (int i=0;imsg[i]; } rrc_log->debug("Setting UE contention resolution ID: %d\n", uecri); @@ -527,7 +527,7 @@ void rrc::send_con_restablish_complete() // Byte align and pack the message bits for PDCP if((bit_buf.N_bits % 8) != 0) { - for(int i=0; i<8-(bit_buf.N_bits % 8); i++) + for(uint32_t i=0; i<8-(bit_buf.N_bits % 8); i++) bit_buf.msg[bit_buf.N_bits + i] = 0; bit_buf.N_bits += 8 - (bit_buf.N_bits % 8); } @@ -558,7 +558,7 @@ void rrc::send_con_setup_complete(byte_buffer_t *nas_msg) // Byte align and pack the message bits for PDCP if((bit_buf.N_bits % 8) != 0) { - for(int i=0; i<8-(bit_buf.N_bits % 8); i++) + for(uint32_t i=0; i<8-(bit_buf.N_bits % 8); i++) bit_buf.msg[bit_buf.N_bits + i] = 0; bit_buf.N_bits += 8 - (bit_buf.N_bits % 8); } @@ -592,7 +592,7 @@ void rrc::send_ul_info_transfer(uint32_t lcid, byte_buffer_t *sdu) // Byte align and pack the message bits for PDCP if((bit_buf.N_bits % 8) != 0) { - for(int i=0; i<8-(bit_buf.N_bits % 8); i++) + for(uint32_t i=0; i<8-(bit_buf.N_bits % 8); i++) bit_buf.msg[bit_buf.N_bits + i] = 0; bit_buf.N_bits += 8 - (bit_buf.N_bits % 8); } @@ -616,7 +616,7 @@ void rrc::send_security_mode_complete(uint32_t lcid, byte_buffer_t *pdu) // Byte align and pack the message bits for PDCP if((bit_buf.N_bits % 8) != 0) { - for(int i=0; i<8-(bit_buf.N_bits % 8); i++) + for(uint32_t i=0; i<8-(bit_buf.N_bits % 8); i++) bit_buf.msg[bit_buf.N_bits + i] = 0; bit_buf.N_bits += 8 - (bit_buf.N_bits % 8); } @@ -640,7 +640,7 @@ void rrc::send_rrc_con_reconfig_complete(uint32_t lcid, byte_buffer_t *pdu) // Byte align and pack the message bits for PDCP if((bit_buf.N_bits % 8) != 0) { - for(int i=0; i<8-(bit_buf.N_bits % 8); i++) + for(uint32_t i=0; i<8-(bit_buf.N_bits % 8); i++) bit_buf.msg[bit_buf.N_bits + i] = 0; bit_buf.N_bits += 8 - (bit_buf.N_bits % 8); } @@ -727,7 +727,7 @@ void rrc::send_rrc_ue_cap_info(uint32_t lcid, byte_buffer_t *pdu) // Byte align and pack the message bits for PDCP if((bit_buf.N_bits % 8) != 0) { - for(int i=0; i<8-(bit_buf.N_bits % 8); i++) + for(uint32_t i=0; i<8-(bit_buf.N_bits % 8); i++) bit_buf.msg[bit_buf.N_bits + i] = 0; bit_buf.N_bits += 8 - (bit_buf.N_bits % 8); } @@ -823,7 +823,7 @@ void rrc::parse_dl_dcch(uint32_t lcid, byte_buffer_t *pdu) break; case LIBLTE_RRC_DL_DCCH_MSG_TYPE_UE_CAPABILITY_ENQUIRY: transaction_id = dl_dcch_msg.msg.ue_cap_enquiry.rrc_transaction_id; - for(int i=0; irlf_timers_and_constants_present) { //TODO } - for(int i=0; isrb_to_add_mod_list_size; i++) { + for(uint32_t i=0; isrb_to_add_mod_list_size; i++) { // TODO: handle SRB modification add_srb(&cnfg->srb_to_add_mod_list[i]); } - for(int i=0; idrb_to_release_list_size; i++) { + for(uint32_t i=0; idrb_to_release_list_size; i++) { release_drb(cnfg->drb_to_release_list[i]); } - for(int i=0; idrb_to_add_mod_list_size; i++) { + for(uint32_t i=0; idrb_to_add_mod_list_size; i++) { // TODO: handle DRB modification add_drb(&cnfg->drb_to_add_mod_list[i]); } diff --git a/lib/test/common/log_filter_test.cc b/lib/test/common/log_filter_test.cc index dd1f34fff..eac0f5f0e 100644 --- a/lib/test/common/log_filter_test.cc +++ b/lib/test/common/log_filter_test.cc @@ -52,6 +52,7 @@ void* thread_loop(void *a) { filter.info("Thread %d: %d", args->thread_id, i); filter.debug("Thread %d: %d", args->thread_id, i); } + return NULL; } void* thread_loop_hex(void *a) { diff --git a/lib/test/upper/rlc_am_control_test.cc b/lib/test/upper/rlc_am_control_test.cc index 7f400ef28..93c09828a 100644 --- a/lib/test/upper/rlc_am_control_test.cc +++ b/lib/test/upper/rlc_am_control_test.cc @@ -47,7 +47,7 @@ int main(int argc, char **argv) { assert(s.N_nack == 0); rlc_am_write_status_pdu(&s, &b2); assert(b2.N_bytes == PDU1_LEN); - for(int i=0;i workers; - phch_common workers_common; - phch_recv sf_recv; - prach prach_buffer; - - srslte_cell_t cell; - - phy_cfg_t config; - phy_args_t *args; - - /* Current time advance */ - uint32_t n_ta; - - bool init_(srslte::radio *radio_handler, mac_interface_phy *mac, srslte::log *log_h, bool do_agc, uint32_t nof_workers); - void set_default_args(phy_args_t *args); - bool check_args(phy_args_t *args); - -}; - -} // namespace srsue - -#endif // UEPHY_H diff --git a/srsue/hdr/ue.h b/srsue/hdr/ue.h index b3c760ad5..6071e072c 100644 --- a/srsue/hdr/ue.h +++ b/srsue/hdr/ue.h @@ -160,7 +160,7 @@ public: private: static ue *instance; ue(); - ~ue(); + virtual ~ue(); srslte::radio_multi radio; srsue::phy phy; diff --git a/srsue/src/mac/demux.cc b/srsue/src/mac/demux.cc index 98f74a8e5..dc7bea2a0 100644 --- a/srsue/src/mac/demux.cc +++ b/srsue/src/mac/demux.cc @@ -158,7 +158,7 @@ void demux::process_sch_pdu(srslte::sch_pdu *pdu_msg) if (pdu_msg->get()->get_sdu_lcid() == 0) { uint8_t *x = pdu_msg->get()->get_sdu_ptr(); uint32_t sum = 0; - for (int i=0;iget()->get_payload_size();i++) { + for (uint32_t i=0;iget()->get_payload_size();i++) { sum += x[i]; } if (sum == 0) { diff --git a/srsue/src/mac/dl_harq.cc b/srsue/src/mac/dl_harq.cc index 27dc881e5..ffe1fb8eb 100644 --- a/srsue/src/mac/dl_harq.cc +++ b/srsue/src/mac/dl_harq.cc @@ -197,7 +197,7 @@ bool dl_harq_entity::dl_harq_process::is_sps() bool dl_harq_entity::dl_harq_process::calc_is_new_transmission(mac_interface_phy::mac_grant_t grant) { bool is_new_tb = true; - if (srslte_tti_interval(grant.tti, cur_grant.tti) <= 8 && grant.n_bytes == cur_grant.n_bytes || + if ((srslte_tti_interval(grant.tti, cur_grant.tti) <= 8 && (grant.n_bytes == cur_grant.n_bytes)) || pid == HARQ_BCCH_PID) { is_new_tb = false; diff --git a/srsue/src/mac/mux.cc b/srsue/src/mac/mux.cc index a927f9d72..58ba3d57f 100644 --- a/srsue/src/mac/mux.cc +++ b/srsue/src/mac/mux.cc @@ -68,7 +68,7 @@ void mux::reset() bool mux::is_pending_any_sdu() { - for (int i=0;iget_buffer_state(lch[i].id)) { return true; } @@ -82,7 +82,7 @@ bool mux::is_pending_sdu(uint32_t lch_id) { int mux::find_lchid(uint32_t lcid) { - for (int i=0;i= 0) { lch[i].Bj += lch[i].PBR; } - if (lch[i].Bj >= lch[i].BSD) { + if (lch[i].Bj >= (int)lch[i].BSD) { lch[i].Bj = lch[i].BSD*lch[i].PBR; } } @@ -197,14 +198,14 @@ uint8_t* mux::pdu_get(uint8_t *payload, uint32_t pdu_sz, uint32_t tx_tti, uint32 } // Update buffer states for all logical channels int sdu_space = pdu_msg.get_sdu_space(); - for (int i=0;iget_buffer_state(lch[i].id); lch[i].sched_len = 0; } // data from any Logical Channel, except data from UL-CCCH; // first only those with positive Bj - for (int i=0;i= 0) { lch[i].Bj -= lch[i].sched_len; @@ -213,7 +214,7 @@ uint8_t* mux::pdu_get(uint8_t *payload, uint32_t pdu_sz, uint32_t tx_tti, uint32 } // If resources remain, allocate regardless of their Bj value - for (int i=0;i 0) { - for (int i=lch.size()-1;i--;i>=0) { + for (int i=(int)lch.size()-1;i>=0;i--) { if (lch[i].sched_len > 0) { lch[i].sched_len = -1; break; @@ -229,7 +230,7 @@ uint8_t* mux::pdu_get(uint8_t *payload, uint32_t pdu_sz, uint32_t tx_tti, uint32 } } // Now allocate the SDUs from the RLC - for (int i=0;iinfo("Allocating scheduled lch=%d len=%d\n", lch[i].id, lch[i].sched_len); allocate_sdu(lch[i].id, &pdu_msg, lch[i].sched_len); diff --git a/srsue/src/mac/proc_bsr.cc b/srsue/src/mac/proc_bsr.cc index 1f4c40c31..db2e12c15 100644 --- a/srsue/src/mac/proc_bsr.cc +++ b/srsue/src/mac/proc_bsr.cc @@ -222,14 +222,14 @@ void bsr_proc::step(uint32_t tti) } int periodic = liblte_rrc_periodic_bsr_timer_num[mac_cfg->main.ulsch_cnfg.periodic_bsr_timer]; - if (periodic != timers_db->get(mac::BSR_TIMER_PERIODIC)->get_timeout() && periodic > 0) + if (periodic > 0 && (uint32_t)periodic != timers_db->get(mac::BSR_TIMER_PERIODIC)->get_timeout()) { timers_db->get(mac::BSR_TIMER_PERIODIC)->set(this, periodic); timers_db->get(mac::BSR_TIMER_PERIODIC)->run(); Info("BSR: Configured timer periodic %d ms\n", periodic); } int retx = liblte_rrc_retransmission_bsr_timer_num[mac_cfg->main.ulsch_cnfg.retx_bsr_timer]; - if (retx != timers_db->get(mac::BSR_TIMER_RETX)->get_timeout() && retx > 0) + if (retx > 0 && (uint32_t)retx != timers_db->get(mac::BSR_TIMER_RETX)->get_timeout()) { timers_db->get(mac::BSR_TIMER_RETX)->set(this, retx); timers_db->get(mac::BSR_TIMER_RETX)->run(); @@ -279,6 +279,8 @@ char* bsr_proc::bsr_format_tostring(bsr_format_t format) { return (char*) "Short"; case bsr_proc::TRUNC_BSR: return (char*) "Truncated"; + default: + return (char*) "Short"; } } @@ -290,7 +292,7 @@ bool bsr_proc::need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t *bsr) if (triggered_bsr_type == PERIODIC || triggered_bsr_type == REGULAR) { /* Check if grant + MAC SDU headers is enough to accomodate all pending data */ int total_data = 0; - for (int i=0;iget_buffer_state(i))+rlc->get_buffer_state(i); } total_data--; // Because last SDU has no size header @@ -300,7 +302,7 @@ bool bsr_proc::need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t *bsr) */ generate_bsr(bsr, 0); bsr_sz = bsr->format==LONG_BSR?3:1; - if (total_data <= grant_size && total_data + 1 + bsr_sz > grant_size) { + if (total_data <= (int)grant_size && total_data + 1 + bsr_sz > grant_size) { Debug("Grant is not enough to accomodate the BSR MAC CE\n"); } else { Debug("BSR: Including Regular BSR: grant_size=%d, total_data=%d, bsr_sz=%d\n", @@ -390,7 +392,8 @@ void bsr_proc::set_priority(uint32_t lcid, uint32_t priority) { } uint32_t bsr_proc::find_max_priority_lcid() { - uint32_t max_prio = 0, max_idx = 0; + int32_t max_prio = 0; + uint32_t max_idx = 0; for (int i=0;i max_prio) { max_prio = priorities[i]; diff --git a/srsue/src/mac/proc_ra.cc b/srsue/src/mac/proc_ra.cc index 88e1a74e5..495c9945f 100644 --- a/srsue/src/mac/proc_ra.cc +++ b/srsue/src/mac/proc_ra.cc @@ -450,7 +450,7 @@ void ra_proc::step_contention_resolution() { { // Random Access with transmission of MAC C-RNTI CE if ((!started_by_pdcch && pdcch_to_crnti_received == PDCCH_CRNTI_UL_GRANT) || - started_by_pdcch && pdcch_to_crnti_received != PDCCH_CRNTI_NOT_RECEIVED) + (started_by_pdcch && pdcch_to_crnti_received != PDCCH_CRNTI_NOT_RECEIVED)) { rDebug("PDCCH for C-RNTI received\n"); timers_db->get(mac::CONTENTION_TIMER)->stop(); @@ -515,6 +515,7 @@ void ra_proc::step(uint32_t tti_) case COMPLETION: step_completition(); case COMPLETION_DONE: + case RA_PROBLEM: break; } } diff --git a/srsue/src/mac/proc_sr.cc b/srsue/src/mac/proc_sr.cc index 0aa7fb77e..afd2b7b5a 100644 --- a/srsue/src/mac/proc_sr.cc +++ b/srsue/src/mac/proc_sr.cc @@ -57,7 +57,7 @@ bool sr_proc::need_tx(uint32_t tti) { int last_tx_tti = phy_h->sr_last_tx_tti(); if (last_tx_tti >= 0) { - if (tti > last_tx_tti) { + if (tti > (uint32_t)last_tx_tti) { if (tti - last_tx_tti > 8) { return true; } diff --git a/srsue/src/mac/ul_harq.cc b/srsue/src/mac/ul_harq.cc index 43cafef65..06bcbfd1b 100644 --- a/srsue/src/mac/ul_harq.cc +++ b/srsue/src/mac/ul_harq.cc @@ -95,7 +95,7 @@ void ul_harq_entity::set_ack(uint32_t tti, bool ack) { tti_harq += 10240; } uint32_t pid_harq = pidof(tti_harq); - if (proc[pid_harq].has_grant() && proc[pid_harq].last_tx_tti() <= tti_harq) { + if (proc[pid_harq].has_grant() && (proc[pid_harq].last_tx_tti() <= (uint32_t)tti_harq)) { proc[pid_harq].set_harq_feedback(ack); } } @@ -228,7 +228,7 @@ void ul_harq_entity::ul_harq_process::run_tti(uint32_t tti_tx, mac_interface_phy { - int max_retx; + uint32_t max_retx; if (is_msg3) { max_retx = harq_entity->mac_cfg->rach.max_harq_msg3_tx; } else { @@ -238,7 +238,7 @@ void ul_harq_entity::ul_harq_process::run_tti(uint32_t tti_tx, mac_interface_phy // Receive and route HARQ feedbacks if (grant) { - if ((!grant->rnti_type == SRSLTE_RNTI_TEMP && grant->ndi != get_ndi()) || + if ((!(grant->rnti_type == SRSLTE_RNTI_TEMP) && grant->ndi != get_ndi()) || (grant->rnti_type == SRSLTE_RNTI_USER && !has_grant()) || grant->is_from_rar) { diff --git a/srsue/src/phy/phch_common.cc b/srsue/src/phy/phch_common.cc index 0fe112ec4..3c3987863 100644 --- a/srsue/src/phy/phch_common.cc +++ b/srsue/src/phy/phch_common.cc @@ -84,7 +84,7 @@ void phch_common::init(phy_interface_rrc::phy_cfg_t *_config, phy_args_t *_args, is_first_tx = true; sr_last_tx_tti = -1; - for (int i=0;i= ul_rnti_start && ul_rnti_start >= 0 || ul_rnti_start < 0) && - (tti < ul_rnti_end && ul_rnti_end >= 0 || ul_rnti_end < 0)) + if ((((int)tti >= ul_rnti_start && ul_rnti_start >= 0) || ul_rnti_start < 0) && + (((int)tti < ul_rnti_end && ul_rnti_end >= 0) || ul_rnti_end < 0)) { return true; } else { @@ -106,8 +106,8 @@ bool phch_common::ul_rnti_active(uint32_t tti) { bool phch_common::dl_rnti_active(uint32_t tti) { Debug("tti=%d, dl_rnti_start=%d, dl_rnti_end=%d, dl_rnti=0x%x\n", tti, dl_rnti_start, dl_rnti_end, dl_rnti); - if (((tti >= dl_rnti_start && dl_rnti_start >= 0) || dl_rnti_start < 0) && - ((tti < dl_rnti_end && dl_rnti_end >= 0) || dl_rnti_end < 0)) + if ((((int)tti >= dl_rnti_start && dl_rnti_start >= 0) || dl_rnti_start < 0) && + (((int)tti < dl_rnti_end && dl_rnti_end >= 0) || dl_rnti_end < 0)) { bool ret = true; // FIXME: This scheduling decision belongs to RRC @@ -325,7 +325,7 @@ void phch_common::reset_ul() { is_first_tx = true; is_first_of_burst = true; - for (int i=0;iget_nof_workers();i++) { + for (uint32_t i=0;iget_nof_workers();i++) { if (!((phch_worker*) workers_pool->get_worker(i))->init_cell(cell)) { Error("Error setting cell: initiating PHCH worker\n"); return false; @@ -180,7 +180,7 @@ bool phch_recv::init_cell() { void phch_recv::free_cell() { if (cell_is_set) { - for (int i=0;iget_nof_workers();i++) { + for (uint32_t i=0;iget_nof_workers();i++) { ((phch_worker*) workers_pool->get_worker(i))->free_cell(); } prach_buffer->free_cell(); @@ -402,7 +402,7 @@ void phch_recv::run_thread() worker = (phch_worker*) workers_pool->wait_worker(tti); sync_res = 0; if (worker) { - for (int i=0;iget_buffer(i); } diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index e0ed424f0..5f842c0f9 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -93,7 +93,7 @@ bool phch_worker::init_cell(srslte_cell_t cell_) memcpy(&cell, &cell_, sizeof(srslte_cell_t)); // ue_sync in phy.cc requires a buffer for 3 subframes - for (int i=0;iargs->nof_rx_ant;i++) { + for (uint32_t i=0;iargs->nof_rx_ant;i++) { signal_buffer[i] = (cf_t*) srslte_vec_malloc(3 * sizeof(cf_t) * SRSLTE_SF_LEN_PRB(cell.nof_prb)); if (!signal_buffer[i]) { Error("Allocating memory\n"); @@ -121,7 +121,7 @@ bool phch_worker::init_cell(srslte_cell_t cell_) void phch_worker::free_cell() { if (cell_initiated) { - for (int i=0;iargs->nof_rx_ant;i++) { + for (uint32_t i=0;iargs->nof_rx_ant;i++) { if (signal_buffer[i]) { free(signal_buffer[i]); } @@ -950,7 +950,7 @@ void phch_worker::start_plot() { } int phch_worker::read_ce_abs(float *ce_abs) { - int i=0; + uint32_t i=0; int sz = srslte_symbol_sz(cell.nof_prb); bzero(ce_abs, sizeof(float)*sz); int g = (sz - 12*cell.nof_prb)/2; diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index bd11a5490..3b76cb983 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -118,7 +118,7 @@ bool phy::init(srslte::radio_multi* radio_handler_, mac_interface_phy *mac, rrc_ nof_workers = args->nof_phy_threads; // Add workers to workers pool and start threads - for (int i=0;iworker_cpu_mask); } @@ -141,14 +141,14 @@ void phy::set_agc_enable(bool enabled) void phy::start_trace() { - for (int i=0;i( &(ostringstream() << i) )->str(); workers[i].write_trace(filename + "_" + i_str); } @@ -200,7 +200,7 @@ void phy::configure_prach_params() void phy::configure_ul_params(bool pregen_disabled) { Info("PHY: Configuring UL parameters\n"); - for (int i=0;iconfigure_ul_params(); // Setup radio bearers - for (int i=0;irr_cnfg.srb_to_add_mod_list_size;i++) { + for (uint32_t i=0;irr_cnfg.srb_to_add_mod_list_size;i++) { if (msg->rr_cnfg.srb_to_add_mod_list[i].lc_default_cnfg_present) { printf("Setting up Default Configuration for SRB%d \n", msg->rr_cnfg.srb_to_add_mod_list[i].srb_id); switch(msg->rr_cnfg.srb_to_add_mod_list[i].srb_id) { @@ -315,7 +315,7 @@ public: uint8_t *ue_cri_ptr = (uint8_t*) &uecri; uint32_t nbytes = bit_msg.N_bits/8; uint8_t *ptr = bit_msg.msg; - for (int i=0;iconsole("SIB1 received, CellID=%d, %s\n", @@ -250,13 +250,13 @@ public: // Send Msg3 sdu->N_bytes = 10; - for (int i=0;iN_bytes;i++) { + for (uint32_t i=0;iN_bytes;i++) { sdu->msg[i] = i+1; } uint64_t uecri = 0; uint8_t *ue_cri_ptr = (uint8_t*) &uecri; uint32_t nbytes = 6; - for (int i=0;imsg[i]; } log_h->info("Setting UE contention resolution ID: %d\n", uecri); @@ -274,7 +274,7 @@ public: void write_pdu(uint32_t lcid, srslte::byte_buffer_t *sdu) { - int n=0; + uint32_t n=0; switch(lcid) { case LCID: n = write(tun_fd, sdu->msg, sdu->N_bytes);