mirror of https://github.com/pvnis/srsRAN_4G.git
Merge branch 'next'
commit
6d62e15d2a
@ -0,0 +1,97 @@
|
||||
# Copyright (c) 2011 Milo Yip (miloyip@gmail.com)
|
||||
# Copyright (c) 2013 Rafal Jeczalik (rjeczalik@gmail.com)
|
||||
# Distributed under the MIT License (see license.txt file)
|
||||
|
||||
# -----------------------------------------------------------------------------------
|
||||
#
|
||||
# Finds the rapidjson library
|
||||
#
|
||||
# -----------------------------------------------------------------------------------
|
||||
#
|
||||
# Variables used by this module, they can change the default behaviour.
|
||||
# Those variables need to be either set before calling find_package
|
||||
# or exported as environment variables before running CMake:
|
||||
#
|
||||
# RAPIDJSON_INCLUDEDIR - Set custom include path, useful when rapidjson headers are
|
||||
# outside system paths
|
||||
# RAPIDJSON_USE_SSE2 - Configure rapidjson to take advantage of SSE2 capabilities
|
||||
# RAPIDJSON_USE_SSE42 - Configure rapidjson to take advantage of SSE4.2 capabilities
|
||||
#
|
||||
# -----------------------------------------------------------------------------------
|
||||
#
|
||||
# Variables defined by this module:
|
||||
#
|
||||
# RAPIDJSON_FOUND - True if rapidjson was found
|
||||
# RAPIDJSON_INCLUDE_DIRS - Path to rapidjson include directory
|
||||
# RAPIDJSON_CXX_FLAGS - Extra C++ flags required for compilation with rapidjson
|
||||
#
|
||||
# -----------------------------------------------------------------------------------
|
||||
#
|
||||
# Example usage:
|
||||
#
|
||||
# set(RAPIDJSON_USE_SSE2 ON)
|
||||
# set(RAPIDJSON_INCLUDEDIR "/opt/github.com/rjeczalik/rapidjson/include")
|
||||
#
|
||||
# find_package(rapidjson REQUIRED)
|
||||
#
|
||||
# include_directories("${RAPIDJSON_INCLUDE_DIRS}")
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RAPIDJSON_CXX_FLAGS}")
|
||||
# add_executable(foo foo.cc)
|
||||
#
|
||||
# -----------------------------------------------------------------------------------
|
||||
|
||||
foreach(opt RAPIDJSON_INCLUDEDIR RAPIDJSON_USE_SSE2 RAPIDJSON_USE_SSE42)
|
||||
if(${opt} AND DEFINED ENV{${opt}} AND NOT ${opt} STREQUAL "$ENV{${opt}}")
|
||||
message(WARNING "Conflicting ${opt} values: ignoring environment variable and using CMake cache entry.")
|
||||
elseif(DEFINED ENV{${opt}} AND NOT ${opt})
|
||||
set(${opt} "$ENV{${opt}}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
find_path(
|
||||
RAPIDJSON_INCLUDE_DIRS
|
||||
NAMES rapidjson/rapidjson.h
|
||||
PATHS ${RAPIDJSON_INCLUDEDIR}
|
||||
DOC "Include directory for the rapidjson library."
|
||||
)
|
||||
|
||||
mark_as_advanced(RAPIDJSON_INCLUDE_DIRS)
|
||||
|
||||
if(RAPIDJSON_INCLUDE_DIRS)
|
||||
set(RAPIDJSON_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(RAPIDJSON_FOUND)
|
||||
|
||||
if(RAPIDJSON_USE_SSE42)
|
||||
set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE42")
|
||||
if(MSVC)
|
||||
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE4.2")
|
||||
else()
|
||||
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse4.2")
|
||||
endif()
|
||||
else()
|
||||
if(RAPIDJSON_USE_SSE2)
|
||||
set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE2")
|
||||
if(MSVC)
|
||||
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE2")
|
||||
else()
|
||||
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse2")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
mark_as_advanced(RAPIDJSON_CXX_FLAGS)
|
||||
|
||||
if(RAPIDJSON_FOUND)
|
||||
if(NOT rapidjson_FIND_QUIETLY)
|
||||
message(STATUS "Found rapidjson header files in ${RAPIDJSON_INCLUDE_DIRS}")
|
||||
if(DEFINED RAPIDJSON_CXX_FLAGS)
|
||||
message(STATUS "Found rapidjson C++ extra compilation flags: ${RAPIDJSON_CXX_FLAGS}")
|
||||
endif()
|
||||
endif()
|
||||
elseif(RapidJSON_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find rapidjson")
|
||||
else()
|
||||
message(STATUS "Optional package rapidjson was not found")
|
||||
endif()
|
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
###################################################################
|
||||
#
|
||||
# This file is part of srsLTE.
|
||||
#
|
||||
# srsLTE is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# srsLTE is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# A copy of the GNU Affero General Public License can be found in
|
||||
# the LICENSE file in the top-level directory of this distribution
|
||||
# and at http://www.gnu.org/licenses/.
|
||||
#
|
||||
###################################################################
|
||||
|
||||
RELEASE=19.06
|
||||
DISTRO=disco
|
||||
COMMIT=eda7ca69a09933526e9318bcf553af0dc0b81598
|
||||
REL_FLAG=releases
|
||||
|
||||
echo 'Packaging srsLTE release' $RELEASE 'for Ubuntu' $DISTRO
|
||||
|
||||
# Make build dir for the package
|
||||
BUILD_DIR=~/build-area/srslte_$RELEASE/$REL_FLAG/$DISTRO
|
||||
mkdir -p $BUILD_DIR
|
||||
|
||||
# Make tarball of the package source
|
||||
pushd ~/srsLTE
|
||||
git archive $COMMIT -o $BUILD_DIR/srslte_$DISTRO.tar.gz
|
||||
popd
|
||||
|
||||
# Copy original tarball
|
||||
cp ~/build-area/srslte_$RELEASE/$REL_FLAG/srslte_$RELEASE.orig.tar.gz $BUILD_DIR
|
||||
|
||||
mkdir $BUILD_DIR/srsLTE
|
||||
pushd $BUILD_DIR/srsLTE
|
||||
tar -vxzf ../srslte_$DISTRO.tar.gz
|
||||
popd
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_MAC_NR_PCAP_H
|
||||
#define SRSLTE_MAC_NR_PCAP_H
|
||||
|
||||
#include "srslte/common/pcap.h"
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
namespace srslte {
|
||||
|
||||
class mac_nr_pcap
|
||||
{
|
||||
public:
|
||||
mac_nr_pcap();
|
||||
~mac_nr_pcap();
|
||||
void enable(const bool& enable_);
|
||||
void open(const std::string& filename, const uint16_t& ue_id = 0);
|
||||
void close();
|
||||
|
||||
void set_ue_id(const uint16_t& ue_id);
|
||||
|
||||
void write_dl_crnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t crnti, uint8_t harqid, uint32_t tti);
|
||||
void write_ul_crnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti);
|
||||
void write_dl_ra_rnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti);
|
||||
void write_dl_bch(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti);
|
||||
void write_dl_pch(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti);
|
||||
void write_dl_si_rnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti);
|
||||
|
||||
private:
|
||||
bool enable_write = false;
|
||||
std::string filename;
|
||||
FILE* pcap_file = nullptr;
|
||||
uint32_t ue_id = 0;
|
||||
void pack_and_write(uint8_t* pdu,
|
||||
uint32_t pdu_len_bytes,
|
||||
uint32_t tti,
|
||||
uint16_t crnti_,
|
||||
uint8_t harqid,
|
||||
uint8_t direction,
|
||||
uint8_t rnti_type);
|
||||
};
|
||||
|
||||
} // namespace srslte
|
||||
|
||||
#endif // SRSLTE_MAC_NR_PCAP_H
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_MAC_NR_PDU_H
|
||||
#define SRSLTE_MAC_NR_PDU_H
|
||||
|
||||
#include "srslte/common/common.h"
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
namespace srslte {
|
||||
|
||||
class mac_nr_sch_pdu;
|
||||
|
||||
class mac_nr_sch_subpdu
|
||||
{
|
||||
public:
|
||||
// 3GPP 38.321 v15.3.0 Combined Tables 6.2.1-1, 6.2.1-2
|
||||
typedef enum {
|
||||
// Values for DL-SCH
|
||||
DRX_CMD = 0b111100,
|
||||
TA_CMD = 0b111101,
|
||||
CON_RES_ID = 0b111110,
|
||||
|
||||
// Values for UL-SCH
|
||||
CRNTI = 0b111010,
|
||||
SHORT_TRUNC_BSR = 0b111011,
|
||||
LONG_TRUNC_BSR = 0b111100,
|
||||
|
||||
SHORT_BSR = 0b111101,
|
||||
LONG_BSR = 0b111110,
|
||||
|
||||
// Common
|
||||
CCCH = 0b000000,
|
||||
PADDING = 0b111111,
|
||||
} nr_lcid_sch_t;
|
||||
|
||||
mac_nr_sch_subpdu(mac_nr_sch_pdu* parent_);
|
||||
|
||||
nr_lcid_sch_t get_type();
|
||||
bool is_sdu();
|
||||
bool is_var_len_ce();
|
||||
|
||||
uint32_t read_subheader(const uint8_t* ptr);
|
||||
uint32_t get_total_length();
|
||||
uint32_t get_sdu_length();
|
||||
uint32_t get_lcid();
|
||||
uint8_t* get_sdu();
|
||||
|
||||
void set_sdu(const uint32_t lcid_, const uint8_t* payload_, const uint32_t len_);
|
||||
|
||||
void set_padding(const uint32_t len_);
|
||||
|
||||
uint32_t write_subpdu(const uint8_t* start_);
|
||||
|
||||
private:
|
||||
uint32_t sizeof_ce(uint32_t lcid, bool is_ul);
|
||||
|
||||
// protected:
|
||||
uint32_t lcid = 0;
|
||||
int header_length = 0;
|
||||
int sdu_length = 0;
|
||||
bool F_bit = false;
|
||||
uint8_t* sdu = nullptr;
|
||||
|
||||
mac_nr_sch_pdu* parent = nullptr;
|
||||
};
|
||||
|
||||
class mac_nr_sch_pdu
|
||||
{
|
||||
public:
|
||||
mac_nr_sch_pdu(bool ulsch_ = false) : ulsch(ulsch_) {}
|
||||
|
||||
void pack();
|
||||
void unpack(const uint8_t* payload, const uint32_t& len);
|
||||
uint32_t get_num_subpdus();
|
||||
const mac_nr_sch_subpdu& get_subpdu(const uint32_t& index);
|
||||
bool is_ulsch();
|
||||
|
||||
void init_tx(byte_buffer_t* buffer_, uint32_t pdu_len_, bool is_ulsch_ = false);
|
||||
|
||||
uint32_t add_sdu(const uint32_t lcid_, const uint8_t* payload_, const uint32_t len_);
|
||||
|
||||
uint32_t get_remaing_len();
|
||||
|
||||
private:
|
||||
uint32_t size_header_sdu(const uint32_t nbytes);
|
||||
|
||||
bool ulsch = false;
|
||||
std::vector<mac_nr_sch_subpdu> subpdus;
|
||||
|
||||
byte_buffer_t* buffer = nullptr;
|
||||
uint32_t pdu_len = 0;
|
||||
uint32_t remaining_len = 0;
|
||||
};
|
||||
|
||||
} // namespace srslte
|
||||
|
||||
#endif // SRSLTE_MAC_NR_PDU_H
|
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: multiqueue.h
|
||||
* Description: General-purpose non-blocking multiqueue. It behaves as a list
|
||||
* of bounded/unbounded queues.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSLTE_MULTIQUEUE_H
|
||||
#define SRSLTE_MULTIQUEUE_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
namespace srslte {
|
||||
|
||||
template <typename myobj>
|
||||
class multiqueue_handler
|
||||
{
|
||||
// NOTE: needed to create a queue wrapper to make its move ctor noexcept.
|
||||
// otherwise we couldnt use the resize method of std::vector<queue<myobj>> if myobj is move-only
|
||||
class queue_wrapper : private std::queue<myobj>
|
||||
{
|
||||
public:
|
||||
queue_wrapper() = default;
|
||||
queue_wrapper(queue_wrapper&& other) noexcept : std::queue<myobj>(std::move(other)) {}
|
||||
using std::queue<myobj>::push;
|
||||
using std::queue<myobj>::pop;
|
||||
using std::queue<myobj>::size;
|
||||
using std::queue<myobj>::empty;
|
||||
using std::queue<myobj>::front;
|
||||
|
||||
std::condition_variable cv_full;
|
||||
bool active = true;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit multiqueue_handler(uint32_t capacity_ = std::numeric_limits<uint32_t>::max()) : capacity(capacity_) {}
|
||||
~multiqueue_handler() { reset(); }
|
||||
|
||||
void reset()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
running = false;
|
||||
while (nof_threads_waiting > 0) {
|
||||
uint32_t size = queues.size();
|
||||
lock.unlock();
|
||||
cv_empty.notify_one();
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
queues[i].cv_full.notify_all();
|
||||
}
|
||||
lock.lock();
|
||||
// wait for all threads to unblock
|
||||
cv_exit.wait(lock);
|
||||
}
|
||||
queues.clear();
|
||||
}
|
||||
|
||||
int add_queue()
|
||||
{
|
||||
uint32_t qidx = 0;
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (not running) {
|
||||
return -1;
|
||||
}
|
||||
for (; qidx < queues.size() and queues[qidx].active; ++qidx)
|
||||
;
|
||||
if (qidx == queues.size()) {
|
||||
// create new queue
|
||||
queues.emplace_back();
|
||||
} else {
|
||||
queues[qidx].active = true;
|
||||
}
|
||||
return (int)qidx;
|
||||
}
|
||||
|
||||
int nof_queues()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
uint32_t count = 0;
|
||||
for (uint32_t i = 0; i < queues.size(); ++i) {
|
||||
count += queues[i].active ? 1 : 0;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
template <typename FwdRef>
|
||||
void push(int q_idx, FwdRef&& value)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
while (is_queue_active_(q_idx) and queues[q_idx].size() >= capacity) {
|
||||
nof_threads_waiting++;
|
||||
queues[q_idx].cv_full.wait(lock);
|
||||
nof_threads_waiting--;
|
||||
}
|
||||
if (not is_queue_active_(q_idx)) {
|
||||
cv_exit.notify_one();
|
||||
return;
|
||||
}
|
||||
queues[q_idx].push(std::forward<FwdRef>(value));
|
||||
}
|
||||
cv_empty.notify_one();
|
||||
}
|
||||
|
||||
bool try_push(int q_idx, const myobj& value)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (not is_queue_active_(q_idx) or queues[q_idx].size() >= capacity) {
|
||||
return false;
|
||||
}
|
||||
queues[q_idx].push(value);
|
||||
}
|
||||
cv_empty.notify_one();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<bool, myobj> try_push(int q_idx, myobj&& value)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mutex);
|
||||
if (not is_queue_active_(q_idx) or queues[q_idx].size() >= capacity) {
|
||||
return {false, std::move(value)};
|
||||
}
|
||||
queues[q_idx].push(std::move(value));
|
||||
}
|
||||
cv_empty.notify_one();
|
||||
return {true, std::move(value)};
|
||||
}
|
||||
|
||||
int wait_pop(myobj* value)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
while (running) {
|
||||
// Round-robin for all queues
|
||||
for (const queue_wrapper& q : queues) {
|
||||
spin_idx = (spin_idx + 1) % queues.size();
|
||||
if (is_queue_active_(spin_idx) and not queues[spin_idx].empty()) {
|
||||
if (value) {
|
||||
*value = std::move(queues[spin_idx].front());
|
||||
}
|
||||
queues[spin_idx].pop();
|
||||
if (nof_threads_waiting > 0) {
|
||||
lock.unlock();
|
||||
queues[spin_idx].cv_full.notify_one();
|
||||
}
|
||||
return spin_idx;
|
||||
}
|
||||
}
|
||||
nof_threads_waiting++;
|
||||
cv_empty.wait(lock);
|
||||
nof_threads_waiting--;
|
||||
}
|
||||
cv_exit.notify_one();
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool empty(int qidx)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mutex);
|
||||
return queues[qidx].empty();
|
||||
}
|
||||
|
||||
size_t size(int qidx)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mutex);
|
||||
return queues[qidx].size();
|
||||
}
|
||||
|
||||
const myobj& front(int qidx)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mutex);
|
||||
return queues[qidx].front();
|
||||
}
|
||||
|
||||
void erase_queue(int qidx)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mutex);
|
||||
if (is_queue_active_(qidx)) {
|
||||
queues[qidx].active = false;
|
||||
while (not queues[qidx].empty()) {
|
||||
queues[qidx].pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool is_queue_active(int qidx)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mutex);
|
||||
return is_queue_active_(qidx);
|
||||
}
|
||||
|
||||
private:
|
||||
bool is_queue_active_(int qidx) const { return running and queues[qidx].active; }
|
||||
|
||||
std::mutex mutex;
|
||||
std::condition_variable cv_empty, cv_exit;
|
||||
uint32_t spin_idx = 0;
|
||||
bool running = true;
|
||||
std::vector<queue_wrapper> queues;
|
||||
uint32_t capacity = 0;
|
||||
uint32_t nof_threads_waiting = 0;
|
||||
};
|
||||
|
||||
} // namespace srslte
|
||||
|
||||
#endif // SRSLTE_MULTIQUEUE_H
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
/*! \brief Base class for implementing socket handlers using
|
||||
* the netsource object.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_NETSOURE_HANDLER_H
|
||||
#define SRSLTE_NETSOURE_HANDLER_H
|
||||
|
||||
#include "srslte/common/log.h"
|
||||
#include "srslte/common/threads.h"
|
||||
#include "srslte/phy/io/netsource.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
class netsource_handler : public thread
|
||||
{
|
||||
public:
|
||||
netsource_handler(const std::string name_) : thread(name_) { rx_buf = unique_byte_array_t(new byte_array_t); }
|
||||
|
||||
~netsource_handler(){};
|
||||
|
||||
void stop()
|
||||
{
|
||||
run_enable = false;
|
||||
int cnt = 0;
|
||||
while (running && cnt < 100) {
|
||||
usleep(10000);
|
||||
cnt++;
|
||||
}
|
||||
if (running) {
|
||||
thread_cancel();
|
||||
}
|
||||
wait_thread_finish();
|
||||
}
|
||||
|
||||
virtual void run_thread() = 0;
|
||||
|
||||
bool run_enable = true;
|
||||
bool running = false;
|
||||
bool initialized = false;
|
||||
|
||||
std::string net_ip = "0.0.0.0";
|
||||
uint32_t net_port = 0;
|
||||
|
||||
const static uint32_t RX_BUF_SIZE = 1024 * 1024;
|
||||
typedef std::array<uint8_t, RX_BUF_SIZE> byte_array_t;
|
||||
typedef std::unique_ptr<byte_array_t> unique_byte_array_t;
|
||||
unique_byte_array_t rx_buf;
|
||||
|
||||
srslte_netsource_t net_source;
|
||||
|
||||
srslte::log* log = nullptr;
|
||||
};
|
||||
|
||||
#endif // SRSLTE_NETSOURE_HANDLER_H
|
@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#ifndef SRSLTE_RESUMABLE_PROCEDURES_H
|
||||
#define SRSLTE_RESUMABLE_PROCEDURES_H
|
||||
|
||||
namespace srslte {
|
||||
|
||||
enum class proc_state_t { on_going, success, error, inactive };
|
||||
enum class proc_outcome_t { repeat, yield, success, error };
|
||||
|
||||
/**************************************************************************************
|
||||
* class: proc_impl_t
|
||||
* Provides an polymorphic interface for resumable procedures. This base can then be used
|
||||
* by a task dispatch queue via the method "run()".
|
||||
* Every procedure starts in inactive state, and finishes with success or error.
|
||||
* With methods:
|
||||
* - run() - executes a procedure, returning true if the procedure is still running
|
||||
* or false, if it has completed
|
||||
* - step() - method overriden by child class that will be called by run(). step()
|
||||
* executes a procedure "action" based on its current internal state,
|
||||
* and return a proc_outcome_t variable with possible values:
|
||||
* - yield - the procedure performed the action but hasn't completed yet.
|
||||
* - repeat - the same as yield, but explicitly asking that run() should
|
||||
* recall step() again (probably the procedure state has changed)
|
||||
* - error - the procedure has finished unsuccessfully
|
||||
* - success - the procedure has completed successfully
|
||||
* - stop() - called automatically when a procedure has finished. Useful for actions
|
||||
* upon procedure completion, like sending back a response.
|
||||
* - set_proc_state() / is_#() - setter and getters for current procedure state
|
||||
************************************************************************************/
|
||||
class proc_impl_t
|
||||
{
|
||||
public:
|
||||
proc_impl_t() : proc_state(proc_state_t::inactive) {}
|
||||
virtual ~proc_impl_t() = default;
|
||||
virtual proc_outcome_t step() = 0;
|
||||
virtual void stop() {} // may be overloaded
|
||||
|
||||
bool run()
|
||||
{
|
||||
proc_outcome_t outcome = proc_outcome_t::repeat;
|
||||
while (is_running() and outcome == proc_outcome_t::repeat) {
|
||||
outcome = step();
|
||||
if (outcome == proc_outcome_t::error) {
|
||||
set_proc_state(proc_state_t::error);
|
||||
} else if (outcome == proc_outcome_t::success) {
|
||||
set_proc_state(proc_state_t::success);
|
||||
}
|
||||
}
|
||||
return is_running();
|
||||
}
|
||||
|
||||
void set_proc_state(proc_state_t new_state)
|
||||
{
|
||||
proc_state = new_state;
|
||||
if (proc_state == proc_state_t::error or proc_state == proc_state_t::success) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
bool is_error() const { return proc_state == proc_state_t::error; }
|
||||
bool is_success() const { return proc_state == proc_state_t::success; }
|
||||
bool is_running() const { return proc_state == proc_state_t::on_going; }
|
||||
bool is_complete() const { return is_success() or is_error(); }
|
||||
bool is_active() const { return proc_state != proc_state_t::inactive; }
|
||||
|
||||
private:
|
||||
proc_state_t proc_state;
|
||||
};
|
||||
|
||||
/**************************************************************************************
|
||||
* class: proc_t<T>
|
||||
* Handles the lifetime, of a procedure T that derives from proc_impl_t, including
|
||||
* its alloc, initialization, and reset back to initial state once the procedure has been
|
||||
* completed and the user has extracted its results.
|
||||
* Can only be re-launched when a procedure T becomes inactive.
|
||||
* It uses a unique_ptr<T> to allow the use of procedures that are forward declared.
|
||||
* It provides the following methods:
|
||||
* - run() - calls proc_impl_t::run(). See above.
|
||||
* - launch() - initializes the procedure T by calling T::init(...). Handles the case
|
||||
* of failed initialization, and forbids the initialization of procedures
|
||||
* that are already active.
|
||||
* - pop() - extracts the result of the procedure if it has finished, and sets
|
||||
* proc_t<T> back to inactive
|
||||
* - trigger_event(Event) - used for handling external events. The procedure T will
|
||||
* have to define a method "trigger_event(Event)" as well,
|
||||
* specifying how each event type should be handled.
|
||||
************************************************************************************/
|
||||
template <class T>
|
||||
class proc_t
|
||||
{
|
||||
public:
|
||||
explicit proc_t() : proc_impl_ptr(new T()) {}
|
||||
T* get() { return proc_impl_ptr.get(); }
|
||||
bool is_active() const { return proc_impl_ptr->is_active(); }
|
||||
bool is_complete() const { return proc_impl_ptr->is_complete(); }
|
||||
T* release() { return proc_impl_ptr.release(); }
|
||||
bool run() { return proc_impl_ptr->run(); }
|
||||
void clear()
|
||||
{
|
||||
// Destructs the current object, and calls default ctor (which sets proc back to inactive and ready for another run)
|
||||
proc_impl_ptr->~T();
|
||||
new (proc_impl_ptr.get()) T();
|
||||
}
|
||||
|
||||
template <class Event>
|
||||
void trigger_event(Event&& e)
|
||||
{
|
||||
if (proc_impl_ptr->is_running()) {
|
||||
proc_outcome_t outcome = proc_impl_ptr->trigger_event(std::forward<Event>(e));
|
||||
if (outcome == proc_outcome_t::error) {
|
||||
proc_impl_ptr->set_proc_state(proc_state_t::error);
|
||||
} else if (outcome == proc_outcome_t::success) {
|
||||
proc_impl_ptr->set_proc_state(proc_state_t::success);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T pop()
|
||||
{
|
||||
if (not proc_impl_ptr->is_complete()) {
|
||||
return T();
|
||||
}
|
||||
T ret(std::move(*proc_impl_ptr));
|
||||
clear();
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
bool launch(Args&&... args)
|
||||
{
|
||||
if (is_active()) {
|
||||
// if already active
|
||||
return false;
|
||||
}
|
||||
proc_impl_ptr->set_proc_state(proc_state_t::on_going);
|
||||
proc_outcome_t init_ret = proc_impl_ptr->init(std::forward<Args>(args)...);
|
||||
switch (init_ret) {
|
||||
case proc_outcome_t::error:
|
||||
proc_impl_ptr->set_proc_state(proc_state_t::error); // call stop as an error
|
||||
clear();
|
||||
return false;
|
||||
case proc_outcome_t::success:
|
||||
proc_impl_ptr->set_proc_state(proc_state_t::success);
|
||||
break;
|
||||
case proc_outcome_t::repeat:
|
||||
run(); // call run right away
|
||||
break;
|
||||
case proc_outcome_t::yield:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<T> proc_impl_ptr;
|
||||
};
|
||||
|
||||
/**************************************************************************************
|
||||
* class: func_proc_t
|
||||
* A proc_impl_t used to store lambda functions and other function pointers as a step()
|
||||
* method, avoiding this way, always having to create a new class per procedure.
|
||||
************************************************************************************/
|
||||
class func_proc_t : public proc_impl_t
|
||||
{
|
||||
public:
|
||||
proc_outcome_t init(std::function<proc_outcome_t()> step_func_)
|
||||
{
|
||||
step_func = std::move(step_func_);
|
||||
return proc_outcome_t::yield;
|
||||
}
|
||||
|
||||
proc_outcome_t step() final { return step_func(); }
|
||||
|
||||
private:
|
||||
std::function<proc_outcome_t()> step_func;
|
||||
};
|
||||
|
||||
/**************************************************************************************
|
||||
* class: func_proc_t
|
||||
* A helper proc_impl_t whose step()/stop() are no op, but has a trigger_event() that
|
||||
* signals that the method has finished and store a result of type OutcomeType.
|
||||
************************************************************************************/
|
||||
template <class OutcomeType>
|
||||
class query_proc_t : public proc_impl_t
|
||||
{
|
||||
public:
|
||||
proc_outcome_t init() { return proc_outcome_t::yield; }
|
||||
proc_outcome_t step() final { return proc_outcome_t::yield; }
|
||||
|
||||
proc_outcome_t trigger_event(const OutcomeType& outcome_)
|
||||
{
|
||||
outcome = outcome_;
|
||||
return proc_outcome_t::success;
|
||||
}
|
||||
|
||||
const OutcomeType& result() const { return outcome; }
|
||||
|
||||
private:
|
||||
OutcomeType outcome;
|
||||
};
|
||||
|
||||
/**************************************************************************************
|
||||
* class: callback_list_t
|
||||
* Stores procedures that derive from proc_impl_t. Its run() method calls sequentially
|
||||
* all the stored procedures run() method, and removes the procedures if they have
|
||||
* completed.
|
||||
* There are different ways to add a procedure to the list:
|
||||
* - add_proc(...) - adds a proc_t<T>, and once the procedure has completed, takes it
|
||||
* out of the container without resetting it back to its initial state
|
||||
* or deleting. This is useful, if the user wants to extract the
|
||||
* procedure result via proc_t<T>::pop()
|
||||
* - consume_proc(...) - receives a proc_t<T> as a rvalue, and calls the proc_t<T>
|
||||
* destructor once the procedure has ended. Useful, for procedures
|
||||
* for which the user is not interested in the result, or reusing
|
||||
* - defer_proc(...) - same as add_proc(...), but once the procedure has finished, it
|
||||
* automatically sets the procedure back to its initial state.
|
||||
* Useful if the user is not interested in handling the result
|
||||
* - defer_task(...) - same as consume_proc(...) but takes a function pointer that
|
||||
* specifies a proc_impl_t step() function
|
||||
************************************************************************************/
|
||||
class callback_list_t
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(proc_impl_t*)> proc_deleter_t;
|
||||
typedef std::unique_ptr<proc_impl_t, proc_deleter_t> callback_obj_t;
|
||||
template <class T>
|
||||
struct recycle_deleter_t {
|
||||
void operator()(proc_impl_t* p)
|
||||
{
|
||||
if (p != nullptr) {
|
||||
T* Tp = static_cast<T*>(p);
|
||||
Tp->~T();
|
||||
new (Tp) T();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void add_proc(proc_t<T>& proc)
|
||||
{
|
||||
if (proc.is_complete()) {
|
||||
return;
|
||||
}
|
||||
callback_obj_t ptr(proc.get(), [](proc_impl_t* p) { /* do nothing */ });
|
||||
callbacks.push_back(std::move(ptr));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void consume_proc(proc_t<T>&& proc)
|
||||
{
|
||||
if (proc.is_complete()) {
|
||||
return;
|
||||
}
|
||||
callback_obj_t ptr(proc.release(), std::default_delete<proc_impl_t>());
|
||||
callbacks.push_back(std::move(ptr));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void defer_proc(proc_t<T>& proc)
|
||||
{
|
||||
if (proc.is_complete()) {
|
||||
proc.pop();
|
||||
return;
|
||||
}
|
||||
callback_obj_t ptr(proc.get(), recycle_deleter_t<T>());
|
||||
callbacks.push_back(std::move(ptr));
|
||||
}
|
||||
|
||||
bool defer_task(std::function<proc_outcome_t()> step_func)
|
||||
{
|
||||
proc_t<func_proc_t> proc;
|
||||
if (not proc.launch(std::move(step_func))) {
|
||||
return false;
|
||||
}
|
||||
consume_proc(std::move(proc));
|
||||
return true;
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
// Calls run for all callbacks. Remove the ones that have finished. The proc dtor is called.
|
||||
callbacks.remove_if([](callback_obj_t& elem) { return not elem->run(); });
|
||||
}
|
||||
|
||||
size_t size() const { return callbacks.size(); }
|
||||
|
||||
private:
|
||||
std::list<callback_obj_t> callbacks;
|
||||
};
|
||||
|
||||
} // namespace srslte
|
||||
|
||||
#endif // SRSLTE_RESUMABLE_PROCEDURES_H
|
@ -0,0 +1,48 @@
|
||||
/*---------------------------------------------------------
|
||||
|
||||
zuc.h
|
||||
Adapted from ETSI/SAGE specifications:
|
||||
"Specification of the 3GPP Confidentiality
|
||||
and Integrity Algorithms 128-EEA3 & 128-EIA3.
|
||||
Document 2: ZUC Specification"
|
||||
|
||||
---------------------------------------------------------*/
|
||||
|
||||
#ifndef SRSLTE_ZUC_H
|
||||
#define SRSLTE_ZUC_H
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned int u32;
|
||||
|
||||
/* the state registers of LFSR */
|
||||
typedef struct {
|
||||
u32 LFSR_S0;
|
||||
u32 LFSR_S1;
|
||||
u32 LFSR_S2;
|
||||
u32 LFSR_S3;
|
||||
u32 LFSR_S4;
|
||||
u32 LFSR_S5;
|
||||
u32 LFSR_S6;
|
||||
u32 LFSR_S7;
|
||||
u32 LFSR_S8;
|
||||
u32 LFSR_S9;
|
||||
u32 LFSR_S10;
|
||||
u32 LFSR_S11;
|
||||
u32 LFSR_S12;
|
||||
u32 LFSR_S13;
|
||||
u32 LFSR_S14;
|
||||
u32 LFSR_S15;
|
||||
/* the registers of F */
|
||||
u32 F_R1;
|
||||
u32 F_R2;
|
||||
/* the outputs of BitReorganization */
|
||||
u32 BRC_X0;
|
||||
u32 BRC_X1;
|
||||
u32 BRC_X2;
|
||||
u32 BRC_X3;
|
||||
} zuc_state_t;
|
||||
|
||||
void zuc_initialize(zuc_state_t* state, u8* k, u8* iv);
|
||||
void zuc_generate_keystream(zuc_state_t* state, int key_stream_len, u32* p_keystream);
|
||||
|
||||
#endif // SRSLTE_ZUC_H
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_HST_H_
|
||||
#define SRSLTE_HST_H_
|
||||
|
||||
#include <srslte/srslte.h>
|
||||
|
||||
typedef struct {
|
||||
// System parameters
|
||||
uint32_t srate_hz; // Sampling rate
|
||||
|
||||
// Model Parameters
|
||||
float fd_hz; // Maximum Doppler Frequency
|
||||
float ds_m; // eNb distance [m]
|
||||
float dmin_m; // eNb Rail-track distance [m]
|
||||
float period_s; // 2 * Ds / speed [s]
|
||||
float init_time_s; // Time offset [s]
|
||||
|
||||
// State
|
||||
float fs_hz; // Last doppler dispersion [Hz]
|
||||
} srslte_channel_hst_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SRSLTE_API int srslte_channel_hst_init(srslte_channel_hst_t* q, float fd_hz, float period_d, float init_time_s);
|
||||
|
||||
SRSLTE_API void srslte_channel_hst_update_srate(srslte_channel_hst_t* q, uint32_t srate);
|
||||
|
||||
SRSLTE_API void
|
||||
srslte_channel_hst_execute(srslte_channel_hst_t* q, cf_t* in, cf_t* out, uint32_t len, const srslte_timestamp_t* ts);
|
||||
|
||||
SRSLTE_API void srslte_channel_hst_free(srslte_channel_hst_t* q);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SRSLTE_HST_H_
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: npss.h
|
||||
*
|
||||
* Description: Narrowband Primary synchronization signal (NPSS) generation and detection.
|
||||
*
|
||||
* The srslte_npss_synch_t object provides functions for fast
|
||||
* computation of the crosscorrelation between the NPSS and received
|
||||
* signal and CFO estimation. Also, the function srslte_npss_synch_tperiodic()
|
||||
* is designed to be called periodically every subframe, taking
|
||||
* care of the correct data alignment with respect to the NPSS sequence.
|
||||
*
|
||||
* The object is designed to work with signals sampled at ?.? Mhz
|
||||
* centered at the carrier frequency. Thus, downsampling is required
|
||||
* if the signal is sampled at higher frequencies.
|
||||
*
|
||||
* Reference: 3GPP TS 36.211 version 13.2.0 Release 13 Sec. 10.x.x
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSLTE_NPSS_H
|
||||
#define SRSLTE_NPSS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "srslte/config.h"
|
||||
#include "srslte/phy/common/phy_common.h"
|
||||
#include "srslte/phy/utils/convolution.h"
|
||||
|
||||
#define CONVOLUTION_FFT
|
||||
|
||||
#define SRSLTE_NPSS_RETURN_PSR
|
||||
|
||||
#define SRSLTE_NPSS_LEN 11
|
||||
#define SRSLTE_NPSS_NUM_OFDM_SYMS 11
|
||||
#define SRSLTE_NPSS_TOT_LEN (SRSLTE_NPSS_LEN * SRSLTE_NPSS_NUM_OFDM_SYMS)
|
||||
|
||||
#define SRSLTE_NPSS_CORR_FILTER_LEN \
|
||||
((SRSLTE_NPSS_NUM_OFDM_SYMS * SRSLTE_NBIOT_FFT_SIZE) + \
|
||||
(SRSLTE_NPSS_NUM_OFDM_SYMS - 1) * SRSLTE_CP_LEN_NORM(1, SRSLTE_NBIOT_FFT_SIZE) + \
|
||||
SRSLTE_CP_LEN_NORM(0, SRSLTE_NBIOT_FFT_SIZE))
|
||||
|
||||
// The below value corresponds to the time-domain representation of the first
|
||||
// three OFDM-symbols plus cyclic prefix that are not transmitted in the sub-frame
|
||||
// carrying the NPSS
|
||||
#define SRSLTE_NPSS_CORR_OFFSET (SRSLTE_SF_LEN(SRSLTE_NBIOT_FFT_SIZE) - SRSLTE_NPSS_CORR_FILTER_LEN)
|
||||
|
||||
// CFO estimation based on the NPSS is done using the second slot of the sub-frame
|
||||
#define SRSLTE_NPSS_CFO_OFFSET (SRSLTE_SF_LEN(SRSLTE_NBIOT_FFT_SIZE) / 2 - SRSLTE_NPSS_CORR_OFFSET)
|
||||
#define SRSLTE_NPSS_CFO_NUM_SYMS 6 // number of symbols for CFO estimation
|
||||
#define SRSLTE_NPSS_CFO_NUM_SAMPS \
|
||||
((SRSLTE_NPSS_CFO_NUM_SYMS * SRSLTE_NBIOT_FFT_SIZE) + \
|
||||
(SRSLTE_NPSS_CFO_NUM_SYMS - 1) * SRSLTE_CP_LEN_NORM(1, SRSLTE_NBIOT_FFT_SIZE) + \
|
||||
SRSLTE_CP_LEN_NORM(0, SRSLTE_NBIOT_FFT_SIZE)) // resulting number of samples
|
||||
|
||||
// NPSS processing options
|
||||
#define SRSLTE_NPSS_ACCUMULATE_ABS // If enabled, accumulates the correlation absolute value on consecutive calls to
|
||||
// srslte_pss_synch_find_pss
|
||||
|
||||
#define SRSLTE_NPSS_ABS_SQUARE // If enabled, compute abs square, otherwise computes absolute value only
|
||||
|
||||
#define SRSLTE_NPSS_RETURN_PSR // If enabled returns peak to side-lobe ratio, otherwise returns absolute peak value
|
||||
|
||||
/* Low-level API */
|
||||
typedef struct SRSLTE_API {
|
||||
#ifdef CONVOLUTION_FFT
|
||||
srslte_conv_fft_cc_t conv_fft;
|
||||
#endif
|
||||
|
||||
uint32_t frame_size, max_frame_size;
|
||||
uint32_t fft_size, max_fft_size;
|
||||
|
||||
cf_t* npss_signal_time;
|
||||
cf_t* tmp_input;
|
||||
cf_t* conv_output;
|
||||
float* conv_output_abs;
|
||||
float ema_alpha;
|
||||
float* conv_output_avg;
|
||||
float peak_value;
|
||||
} srslte_npss_synch_t;
|
||||
|
||||
// Basic functionality
|
||||
SRSLTE_API int srslte_npss_synch_init(srslte_npss_synch_t* q, uint32_t frame_size, uint32_t fft_size);
|
||||
|
||||
SRSLTE_API void srslte_npss_synch_reset(srslte_npss_synch_t* q);
|
||||
|
||||
SRSLTE_API int srslte_npss_synch_resize(srslte_npss_synch_t* q, uint32_t frame_size, uint32_t fft_size);
|
||||
|
||||
SRSLTE_API void srslte_npss_synch_set_ema_alpha(srslte_npss_synch_t* q, float alpha);
|
||||
|
||||
SRSLTE_API void srslte_npss_synch_free(srslte_npss_synch_t* q);
|
||||
|
||||
SRSLTE_API int srslte_npss_sync_find(srslte_npss_synch_t* q, cf_t* input, float* corr_peak_value);
|
||||
|
||||
// Internal functions
|
||||
SRSLTE_API int srslte_npss_corr_init(cf_t* npss_signal_time, uint32_t fft_size, uint32_t frame_size);
|
||||
|
||||
SRSLTE_API int srslte_npss_generate(cf_t* signal);
|
||||
|
||||
SRSLTE_API void srslte_npss_put_subframe(
|
||||
srslte_npss_synch_t* q, cf_t* npss_signal, cf_t* sf, const uint32_t nof_prb, const uint32_t nbiot_prb_offset);
|
||||
|
||||
#endif // SRSLTE_NPSS_H
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: nsss.h
|
||||
*
|
||||
* Description: Narrowband secondary synchronization signal (NSSS)
|
||||
* generation and detection.
|
||||
*
|
||||
*
|
||||
* Reference: 3GPP TS 36.211 version 13.2.0 Release 13 Sec. 10.2.7.2
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSLTE_NSSS_H
|
||||
#define SRSLTE_NSSS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "srslte/config.h"
|
||||
#include "srslte/phy/common/phy_common.h"
|
||||
#include "srslte/phy/dft/dft.h"
|
||||
#include "srslte/phy/utils/convolution.h"
|
||||
|
||||
#define SRSLTE_NSSS_NSYMB 11
|
||||
#define SRSLTE_NSSS_NSC 12
|
||||
#define SRSLTE_NSSS_LEN (SRSLTE_NSSS_NSYMB * SRSLTE_NSSS_NSC)
|
||||
#define SRSLTE_NSSS_NUM_SEQ 4
|
||||
#define SRSLTE_NSSS_TOT_LEN (SRSLTE_NSSS_NUM_SEQ * SRSLTE_NSSS_LEN)
|
||||
|
||||
#define SRSLTE_NSSS_CORR_FILTER_LEN 1508
|
||||
#define SRSLTE_NSSS_CORR_OFFSET 412
|
||||
|
||||
#define SRSLTE_NUM_PCI 504
|
||||
|
||||
#define SRSLTE_NSSS_PERIOD 2
|
||||
#define SRSLTE_NSSS_NUM_SF_DETECT (SRSLTE_NSSS_PERIOD)
|
||||
|
||||
// b_q_m table from 3GPP TS 36.211 v13.2.0 table 10.2.7.2.1-1
|
||||
static const int b_q_m[SRSLTE_NSSS_NUM_SEQ][128] = {
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1,
|
||||
1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1,
|
||||
1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1,
|
||||
1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1},
|
||||
{1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1,
|
||||
-1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1,
|
||||
-1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1,
|
||||
-1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1,
|
||||
1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1},
|
||||
{1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1,
|
||||
-1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1,
|
||||
-1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1,
|
||||
1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1,
|
||||
-1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1}};
|
||||
|
||||
/* Low-level API */
|
||||
typedef struct SRSLTE_API {
|
||||
uint32_t input_size;
|
||||
uint32_t subframe_sz;
|
||||
uint32_t fft_size, max_fft_size;
|
||||
srslte_conv_fft_cc_t conv_fft;
|
||||
|
||||
cf_t* nsss_signal_time[SRSLTE_NUM_PCI];
|
||||
cf_t* tmp_input;
|
||||
cf_t* conv_output;
|
||||
float* conv_output_abs;
|
||||
float peak_values[SRSLTE_NUM_PCI];
|
||||
float corr_peak_threshold;
|
||||
} srslte_nsss_synch_t;
|
||||
|
||||
SRSLTE_API int srslte_nsss_synch_init(srslte_nsss_synch_t* q, uint32_t input_size, uint32_t fft_size);
|
||||
|
||||
SRSLTE_API void srslte_nsss_synch_free(srslte_nsss_synch_t* q);
|
||||
|
||||
SRSLTE_API int srslte_nsss_synch_resize(srslte_nsss_synch_t* q, uint32_t fft_size);
|
||||
|
||||
SRSLTE_API int srslte_nsss_sync_find(
|
||||
srslte_nsss_synch_t* q, cf_t* input, float* corr_peak_value, uint32_t* cell_id, uint32_t* sfn_partial);
|
||||
|
||||
void srslte_nsss_sync_find_pci(srslte_nsss_synch_t* q, cf_t* input, uint32_t cell_id);
|
||||
|
||||
SRSLTE_API int srslte_nsss_corr_init(srslte_nsss_synch_t* q);
|
||||
|
||||
SRSLTE_API void srslte_nsss_generate(cf_t* signal, uint32_t cell_id);
|
||||
|
||||
SRSLTE_API void srslte_nsss_put_subframe(srslte_nsss_synch_t* q,
|
||||
cf_t* nsss,
|
||||
cf_t* subframe,
|
||||
const int nf,
|
||||
const uint32_t nof_prb,
|
||||
const uint32_t nbiot_prb_offset);
|
||||
|
||||
#endif // SRSLTE_NSSS_H
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_REFSIGNAL_DL_SYNC_H_
|
||||
#define SRSLTE_REFSIGNAL_DL_SYNC_H_
|
||||
|
||||
#include <srslte/phy/ch_estimation/refsignal_dl.h>
|
||||
#include <srslte/phy/dft/ofdm.h>
|
||||
#include <srslte/phy/utils/convolution.h>
|
||||
|
||||
typedef struct {
|
||||
srslte_refsignal_t refsignal;
|
||||
srslte_ofdm_t ifft;
|
||||
cf_t* ifft_buffer_in;
|
||||
cf_t* ifft_buffer_out;
|
||||
cf_t* sequences[SRSLTE_NOF_SF_X_FRAME];
|
||||
cf_t* correlation;
|
||||
srslte_conv_fft_cc_t conv_fft_cc;
|
||||
|
||||
// Results
|
||||
bool found;
|
||||
float rsrp_dBfs;
|
||||
float rssi_dBfs;
|
||||
float rsrq_dB;
|
||||
float cfo_Hz;
|
||||
uint32_t peak_index;
|
||||
} srslte_refsignal_dl_sync_t;
|
||||
|
||||
SRSLTE_API int srslte_refsignal_dl_sync_init(srslte_refsignal_dl_sync_t* q);
|
||||
|
||||
SRSLTE_API int srslte_refsignal_dl_sync_set_cell(srslte_refsignal_dl_sync_t* q, srslte_cell_t cell);
|
||||
|
||||
SRSLTE_API void srslte_refsignal_dl_sync_free(srslte_refsignal_dl_sync_t* q);
|
||||
|
||||
SRSLTE_API void srslte_refsignal_dl_sync_run(srslte_refsignal_dl_sync_t* q, cf_t* buffer, uint32_t nsamples);
|
||||
|
||||
SRSLTE_API void srslte_refsignal_dl_sync_measure_sf(
|
||||
srslte_refsignal_dl_sync_t* q, cf_t* buffer, uint32_t sf_idx, float* rsrp, float* rssi, float* cfo);
|
||||
|
||||
#endif // SRSLTE_REFSIGNAL_DL_SYNC_H_
|
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: sync_nbiot.h
|
||||
*
|
||||
* Description: Time and frequency synchronization using the NPSS and NSSS signals.
|
||||
*
|
||||
* The object is designed to work with signals sampled at 1.92 Mhz
|
||||
* centered at the carrier frequency. Thus, downsampling is required
|
||||
* if the signal is sampled at higher frequencies.
|
||||
*
|
||||
* Correlation peak is detected comparing the maximum at the output
|
||||
* of the correlator with a threshold.
|
||||
*
|
||||
* Reference: 3GPP TS 36.211 version 13.2.0 Release 13
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSLTE_SYNC_NBIOT_H
|
||||
#define SRSLTE_SYNC_NBIOT_H
|
||||
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "srslte/config.h"
|
||||
#include "srslte/phy/sync/npss.h"
|
||||
#include "srslte/phy/sync/nsss.h"
|
||||
#include "srslte/phy/sync/sync.h"
|
||||
#include "srslte/phy/ue/ue_sync.h"
|
||||
|
||||
#define MAX_NUM_CFO_CANDITATES 50
|
||||
|
||||
typedef struct SRSLTE_API {
|
||||
srslte_npss_synch_t npss;
|
||||
srslte_nsss_synch_t nsss;
|
||||
srslte_cp_synch_t cp_synch;
|
||||
uint32_t n_id_ncell;
|
||||
|
||||
float threshold;
|
||||
float peak_value;
|
||||
uint32_t fft_size;
|
||||
uint32_t frame_size;
|
||||
uint32_t max_frame_size;
|
||||
uint32_t max_offset;
|
||||
bool enable_cfo_estimation;
|
||||
bool enable_cfo_cand_test;
|
||||
float cfo_cand[MAX_NUM_CFO_CANDITATES];
|
||||
int cfo_num_cand;
|
||||
int cfo_cand_idx;
|
||||
float mean_cfo;
|
||||
float current_cfo_tol;
|
||||
cf_t* shift_buffer;
|
||||
cf_t* cfo_output;
|
||||
int cfo_i;
|
||||
bool find_cfo_i;
|
||||
bool find_cfo_i_initiated;
|
||||
float cfo_ema_alpha;
|
||||
uint32_t nof_symbols;
|
||||
uint32_t cp_len;
|
||||
srslte_cfo_t cfocorr;
|
||||
srslte_cp_t cp;
|
||||
} srslte_sync_nbiot_t;
|
||||
|
||||
SRSLTE_API int
|
||||
srslte_sync_nbiot_init(srslte_sync_nbiot_t* q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_free(srslte_sync_nbiot_t* q);
|
||||
|
||||
SRSLTE_API int
|
||||
srslte_sync_nbiot_resize(srslte_sync_nbiot_t* q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size);
|
||||
|
||||
SRSLTE_API srslte_sync_find_ret_t srslte_sync_nbiot_find(srslte_sync_nbiot_t* q,
|
||||
cf_t* input,
|
||||
uint32_t find_offset,
|
||||
uint32_t* peak_position);
|
||||
|
||||
SRSLTE_API float cfo_estimate_nbiot(srslte_sync_nbiot_t* q, cf_t* input);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_set_threshold(srslte_sync_nbiot_t* q, float threshold);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_set_cfo_enable(srslte_sync_nbiot_t* q, bool enable);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_set_cfo_cand_test_enable(srslte_sync_nbiot_t* q, bool enable);
|
||||
|
||||
SRSLTE_API int srslte_sync_nbiot_set_cfo_cand(srslte_sync_nbiot_t* q, const float* cand, const int num);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_set_cfo_tol(srslte_sync_nbiot_t* q, float tol);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_set_cfo_ema_alpha(srslte_sync_nbiot_t* q, float alpha);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_set_npss_ema_alpha(srslte_sync_nbiot_t* q, float alpha);
|
||||
|
||||
SRSLTE_API int srslte_sync_nbiot_find_cell_id(srslte_sync_nbiot_t* q, cf_t* input);
|
||||
|
||||
SRSLTE_API int srslte_sync_nbiot_get_cell_id(srslte_sync_nbiot_t* q);
|
||||
|
||||
SRSLTE_API float srslte_sync_nbiot_get_cfo(srslte_sync_nbiot_t* q);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_set_cfo(srslte_sync_nbiot_t* q, float cfo);
|
||||
|
||||
SRSLTE_API bool srslte_sync_nbiot_nsss_detected(srslte_sync_nbiot_t* q);
|
||||
|
||||
SRSLTE_API float srslte_sync_nbiot_get_peak_value(srslte_sync_nbiot_t* q);
|
||||
|
||||
SRSLTE_API void srslte_sync_nbiot_reset(srslte_sync_nbiot_t* q);
|
||||
|
||||
#endif // SRSLTE_SYNC_NBIOT_H
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_PDCP_ENTITY_H
|
||||
#define SRSLTE_PDCP_ENTITY_H
|
||||
|
||||
#include "srslte/common/buffer_pool.h"
|
||||
#include "srslte/common/log.h"
|
||||
#include "srslte/common/common.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include "srslte/common/security.h"
|
||||
#include "srslte/common/threads.h"
|
||||
#include "pdcp_interface.h"
|
||||
|
||||
|
||||
namespace srslte {
|
||||
|
||||
/****************************************************************************
|
||||
* Structs and Defines
|
||||
* Ref: 3GPP TS 36.323 v10.1.0
|
||||
***************************************************************************/
|
||||
|
||||
#define PDCP_CONTROL_MAC_I 0x00000000
|
||||
|
||||
#define PDCP_PDU_TYPE_PDCP_STATUS_REPORT 0x0
|
||||
#define PDCP_PDU_TYPE_INTERSPERSED_ROHC_FEEDBACK_PACKET 0x1
|
||||
|
||||
typedef enum{
|
||||
PDCP_D_C_CONTROL_PDU = 0,
|
||||
PDCP_D_C_DATA_PDU,
|
||||
PDCP_D_C_N_ITEMS,
|
||||
}pdcp_d_c_t;
|
||||
static const char pdcp_d_c_text[PDCP_D_C_N_ITEMS][20] = {"Control PDU",
|
||||
"Data PDU"};
|
||||
|
||||
/****************************************************************************
|
||||
* PDCP Entity interface
|
||||
* Common interface for all PDCP entities
|
||||
***************************************************************************/
|
||||
class pdcp_entity : public pdcp_entity_interface
|
||||
{
|
||||
public:
|
||||
pdcp_entity();
|
||||
~pdcp_entity();
|
||||
void init(srsue::rlc_interface_pdcp *rlc_,
|
||||
srsue::rrc_interface_pdcp *rrc_,
|
||||
srsue::gw_interface_pdcp *gw_,
|
||||
srslte::log *log_,
|
||||
uint32_t lcid_,
|
||||
srslte_pdcp_config_t cfg_);
|
||||
void reset();
|
||||
void reestablish();
|
||||
|
||||
bool is_active();
|
||||
|
||||
// RRC interface
|
||||
void write_sdu(unique_byte_buffer_t sdu, bool blocking);
|
||||
void config_security(uint8_t *k_rrc_enc_,
|
||||
uint8_t *k_rrc_int_,
|
||||
uint8_t *k_up_enc_,
|
||||
CIPHERING_ALGORITHM_ID_ENUM cipher_algo_,
|
||||
INTEGRITY_ALGORITHM_ID_ENUM integ_algo_);
|
||||
void enable_integrity();
|
||||
void enable_encryption();
|
||||
uint32_t get_dl_count();
|
||||
uint32_t get_ul_count();
|
||||
|
||||
// RLC interface
|
||||
void write_pdu(unique_byte_buffer_t pdu);
|
||||
|
||||
private:
|
||||
byte_buffer_pool* pool = byte_buffer_pool::get_instance();
|
||||
srslte::log* log = nullptr;
|
||||
|
||||
srsue::rlc_interface_pdcp* rlc = nullptr;
|
||||
srsue::rrc_interface_pdcp* rrc = nullptr;
|
||||
srsue::gw_interface_pdcp* gw = nullptr;
|
||||
|
||||
bool active = false;
|
||||
uint32_t lcid = 0;
|
||||
srslte_pdcp_config_t cfg = {};
|
||||
uint8_t sn_len_bytes = 0;
|
||||
bool do_integrity = false;
|
||||
bool do_encryption = false;
|
||||
|
||||
uint32_t rx_count = 0;
|
||||
uint32_t tx_count = 0;
|
||||
uint8_t k_rrc_enc[32] = {};
|
||||
uint8_t k_rrc_int[32] = {};
|
||||
uint8_t k_up_enc[32] = {};
|
||||
|
||||
uint32_t rx_hfn = 0;
|
||||
uint32_t next_pdcp_rx_sn = 0;
|
||||
uint32_t reordering_window = 0;
|
||||
uint32_t last_submitted_pdcp_rx_sn = 0;
|
||||
uint32_t maximum_pdcp_sn = 0;
|
||||
|
||||
CIPHERING_ALGORITHM_ID_ENUM cipher_algo = CIPHERING_ALGORITHM_ID_EEA0;
|
||||
INTEGRITY_ALGORITHM_ID_ENUM integ_algo = INTEGRITY_ALGORITHM_ID_EIA0;
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
void handle_um_drb_pdu(const srslte::unique_byte_buffer_t& pdu);
|
||||
void handle_am_drb_pdu(const srslte::unique_byte_buffer_t& pdu);
|
||||
|
||||
void integrity_generate(uint8_t* msg, uint32_t msg_len, uint8_t* mac);
|
||||
bool integrity_verify(uint8_t* msg, uint32_t count, uint32_t msg_len, uint8_t* mac);
|
||||
void cipher_encrypt(uint8_t* msg, uint32_t msg_len, uint8_t* ct);
|
||||
void cipher_decrypt(uint8_t* ct, uint32_t count, uint32_t ct_len, uint8_t* msg);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Pack/Unpack helper functions
|
||||
* Ref: 3GPP TS 36.323 v10.1.0
|
||||
***************************************************************************/
|
||||
|
||||
void pdcp_pack_control_pdu(uint32_t sn, byte_buffer_t *sdu);
|
||||
void pdcp_unpack_control_pdu(byte_buffer_t *sdu, uint32_t *sn);
|
||||
|
||||
void pdcp_pack_data_pdu_short_sn(uint32_t sn, byte_buffer_t *sdu);
|
||||
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 srslte
|
||||
#endif // SRSLTE_PDCP_ENTITY_H
|
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_PDCP_ENTITY_BASE_H
|
||||
#define SRSLTE_PDCP_ENTITY_BASE_H
|
||||
|
||||
#include "srslte/common/buffer_pool.h"
|
||||
#include "srslte/common/common.h"
|
||||
#include "srslte/common/log.h"
|
||||
#include "srslte/common/security.h"
|
||||
#include "srslte/common/threads.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include <mutex>
|
||||
|
||||
namespace srslte {
|
||||
|
||||
/****************************************************************************
|
||||
* Structs and Defines common to both LTE and NR
|
||||
* Ref: 3GPP TS 36.323 v10.1.0 and TS 38.323 v15.2.0
|
||||
***************************************************************************/
|
||||
|
||||
#define PDCP_PDU_TYPE_PDCP_STATUS_REPORT 0x0
|
||||
#define PDCP_PDU_TYPE_INTERSPERSED_ROHC_FEEDBACK_PACKET 0x1
|
||||
|
||||
// Maximum supported PDCP SDU size is 9000 bytes.
|
||||
// See TS 38.323 v15.2.0, section 4.3.1
|
||||
#define PDCP_MAX_SDU_SIZE 9000
|
||||
|
||||
typedef enum {
|
||||
PDCP_D_C_CONTROL_PDU = 0,
|
||||
PDCP_D_C_DATA_PDU,
|
||||
PDCP_D_C_N_ITEMS,
|
||||
} pdcp_d_c_t;
|
||||
static const char pdcp_d_c_text[PDCP_D_C_N_ITEMS][20] = {"Control PDU", "Data PDU"};
|
||||
|
||||
/****************************************************************************
|
||||
* PDCP Entity interface
|
||||
* Common interface for LTE and NR PDCP entities
|
||||
***************************************************************************/
|
||||
class pdcp_entity_base
|
||||
{
|
||||
public:
|
||||
pdcp_entity_base();
|
||||
virtual ~pdcp_entity_base();
|
||||
virtual void reset() = 0;
|
||||
virtual void reestablish() = 0;
|
||||
|
||||
bool is_active() { return active; }
|
||||
bool is_srb() { return cfg.rb_type == PDCP_RB_IS_SRB; }
|
||||
bool is_drb() { return cfg.rb_type == PDCP_RB_IS_DRB; }
|
||||
|
||||
// RRC interface
|
||||
void enable_integrity() { do_integrity = true; }
|
||||
void enable_encryption() { do_encryption = true; }
|
||||
|
||||
void config_security(uint8_t* k_rrc_enc_,
|
||||
uint8_t* k_rrc_int_,
|
||||
uint8_t* k_up_enc_,
|
||||
uint8_t* k_up_int_, // NR Only, pass nullptr in LTE
|
||||
CIPHERING_ALGORITHM_ID_ENUM cipher_algo_,
|
||||
INTEGRITY_ALGORITHM_ID_ENUM integ_algo_);
|
||||
|
||||
// GW/SDAP/RRC interface
|
||||
void write_sdu(unique_byte_buffer_t sdu, bool blocking);
|
||||
|
||||
// RLC interface
|
||||
void write_pdu(unique_byte_buffer_t pdu);
|
||||
|
||||
// COUNT, HFN and SN helpers
|
||||
uint32_t HFN(uint32_t count);
|
||||
uint32_t SN(uint32_t count);
|
||||
uint32_t COUNT(uint32_t hfn, uint32_t sn);
|
||||
|
||||
protected:
|
||||
srslte::log* log = nullptr;
|
||||
|
||||
bool active = false;
|
||||
uint32_t lcid = 0;
|
||||
bool do_integrity = false;
|
||||
bool do_encryption = false;
|
||||
|
||||
pdcp_config_t cfg = {1, PDCP_RB_IS_DRB, SECURITY_DIRECTION_DOWNLINK, SECURITY_DIRECTION_UPLINK, PDCP_SN_LEN_12};
|
||||
|
||||
std::mutex mutex;
|
||||
|
||||
uint8_t k_rrc_enc[32] = {};
|
||||
uint8_t k_rrc_int[32] = {};
|
||||
uint8_t k_up_enc[32] = {};
|
||||
uint8_t k_up_int[32] = {};
|
||||
|
||||
CIPHERING_ALGORITHM_ID_ENUM cipher_algo = CIPHERING_ALGORITHM_ID_EEA0;
|
||||
INTEGRITY_ALGORITHM_ID_ENUM integ_algo = INTEGRITY_ALGORITHM_ID_EIA0;
|
||||
|
||||
void integrity_generate(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* mac);
|
||||
bool integrity_verify(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* mac);
|
||||
void cipher_encrypt(uint8_t* msg, uint32_t msg_len, uint32_t count, uint8_t* ct);
|
||||
void cipher_decrypt(uint8_t* ct, uint32_t ct_len, uint32_t count, uint8_t* msg);
|
||||
};
|
||||
|
||||
inline uint32_t pdcp_entity_base::HFN(uint32_t count)
|
||||
{
|
||||
return (count >> cfg.sn_len);
|
||||
}
|
||||
|
||||
inline uint32_t pdcp_entity_base::SN(uint32_t count)
|
||||
{
|
||||
return count & (0xFFFFFFFF >> (32 - cfg.sn_len));
|
||||
}
|
||||
|
||||
inline uint32_t pdcp_entity_base::COUNT(uint32_t hfn, uint32_t sn)
|
||||
{
|
||||
return (hfn << cfg.sn_len) | sn;
|
||||
}
|
||||
} // namespace srslte
|
||||
#endif // SRSLTE_PDCP_ENTITY_BASE_H
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_PDCP_ENTITY_LTE_H
|
||||
#define SRSLTE_PDCP_ENTITY_LTE_H
|
||||
|
||||
#include "srslte/common/buffer_pool.h"
|
||||
#include "srslte/common/common.h"
|
||||
#include "srslte/common/log.h"
|
||||
#include "srslte/common/security.h"
|
||||
#include "srslte/common/threads.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include "srslte/upper/pdcp_entity_base.h"
|
||||
|
||||
namespace srslte {
|
||||
|
||||
/****************************************************************************
|
||||
* Structs and Defines
|
||||
* Ref: 3GPP TS 36.323 v10.1.0
|
||||
***************************************************************************/
|
||||
|
||||
#define PDCP_CONTROL_MAC_I 0x00000000
|
||||
|
||||
/****************************************************************************
|
||||
* LTE PDCP Entity
|
||||
* Class for LTE PDCP entities
|
||||
***************************************************************************/
|
||||
class pdcp_entity_lte final : public pdcp_entity_base
|
||||
{
|
||||
public:
|
||||
pdcp_entity_lte();
|
||||
~pdcp_entity_lte();
|
||||
void init(srsue::rlc_interface_pdcp* rlc_,
|
||||
srsue::rrc_interface_pdcp* rrc_,
|
||||
srsue::gw_interface_pdcp* gw_,
|
||||
srslte::log* log_,
|
||||
uint32_t lcid_,
|
||||
pdcp_config_t cfg_);
|
||||
void reset();
|
||||
void reestablish();
|
||||
|
||||
// GW/RRC interface
|
||||
void write_sdu(unique_byte_buffer_t sdu, bool blocking);
|
||||
|
||||
uint32_t get_dl_count();
|
||||
uint32_t get_ul_count();
|
||||
|
||||
// RLC interface
|
||||
void write_pdu(unique_byte_buffer_t pdu);
|
||||
|
||||
private:
|
||||
srsue::rlc_interface_pdcp* rlc = nullptr;
|
||||
srsue::rrc_interface_pdcp* rrc = nullptr;
|
||||
srsue::gw_interface_pdcp* gw = nullptr;
|
||||
|
||||
uint32_t rx_count = 0;
|
||||
uint32_t tx_count = 0;
|
||||
|
||||
uint32_t rx_hfn = 0;
|
||||
uint32_t next_pdcp_rx_sn = 0;
|
||||
uint32_t reordering_window = 0;
|
||||
uint32_t last_submitted_pdcp_rx_sn = 0;
|
||||
uint32_t maximum_pdcp_sn = 0;
|
||||
|
||||
void handle_um_drb_pdu(const srslte::unique_byte_buffer_t& pdu);
|
||||
void handle_am_drb_pdu(const srslte::unique_byte_buffer_t& pdu);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Pack/Unpack helper functions
|
||||
* Ref: 3GPP TS 36.323 v10.1.0
|
||||
***************************************************************************/
|
||||
|
||||
void pdcp_pack_control_pdu(uint32_t sn, byte_buffer_t* sdu);
|
||||
void pdcp_unpack_control_pdu(byte_buffer_t* sdu, uint32_t* sn);
|
||||
|
||||
void pdcp_pack_data_pdu_short_sn(uint32_t sn, byte_buffer_t* sdu);
|
||||
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 srslte
|
||||
#endif // SRSLTE_PDCP_ENTITY_LTE_H
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_PDCP_ENTITY_NR_H
|
||||
#define SRSLTE_PDCP_ENTITY_NR_H
|
||||
|
||||
#include "pdcp_entity_base.h"
|
||||
#include "srslte/common/buffer_pool.h"
|
||||
#include "srslte/common/common.h"
|
||||
#include "srslte/common/interfaces_common.h"
|
||||
#include "srslte/common/log.h"
|
||||
#include "srslte/common/security.h"
|
||||
#include "srslte/common/threads.h"
|
||||
|
||||
namespace srslte {
|
||||
|
||||
/****************************************************************************
|
||||
* NR PDCP Entity
|
||||
* PDCP entity for 5G NR
|
||||
***************************************************************************/
|
||||
class pdcp_entity_nr : public pdcp_entity_base
|
||||
{
|
||||
public:
|
||||
pdcp_entity_nr();
|
||||
~pdcp_entity_nr();
|
||||
void init(srsue::rlc_interface_pdcp* rlc_,
|
||||
srsue::rrc_interface_pdcp* rrc_,
|
||||
srsue::gw_interface_pdcp* gw_,
|
||||
srslte::log* log_,
|
||||
uint32_t lcid_,
|
||||
pdcp_config_t cfg_);
|
||||
void reset();
|
||||
void reestablish();
|
||||
|
||||
// RRC interface
|
||||
void write_sdu(unique_byte_buffer_t sdu, bool blocking);
|
||||
|
||||
uint32_t get_dl_count();
|
||||
uint32_t get_ul_count();
|
||||
|
||||
// RLC interface
|
||||
void write_pdu(unique_byte_buffer_t pdu);
|
||||
|
||||
private:
|
||||
srsue::rlc_interface_pdcp* rlc = nullptr;
|
||||
srsue::rrc_interface_pdcp* rrc = nullptr;
|
||||
srsue::gw_interface_pdcp* gw = nullptr;
|
||||
|
||||
// State variables: 3GPP TS 38.323 v15.2.0, section 7.1
|
||||
uint32_t tx_next = 0; // COUNT value of next SDU to be transmitted.
|
||||
uint32_t rx_next = 0; // COUNT value of next SDU expected to be received.
|
||||
uint32_t rx_deliv = 0; // COUNT value of first SDU not delivered to upper layers, but still waited for.
|
||||
uint32_t rx_reord = 0; // COUNT value following the COUNT value of PDCP Data PDU which triggered t-Reordering.
|
||||
|
||||
// Constants: 3GPP TS 38.323 v15.2.0, section 7.2
|
||||
uint32_t window_size = 0;
|
||||
|
||||
// Packing/Unpacking Helper functions
|
||||
uint32_t read_data_header(const unique_byte_buffer_t& sdu);
|
||||
void write_data_header(const unique_byte_buffer_t& sdu, uint32_t sn);
|
||||
void extract_mac(const unique_byte_buffer_t& sdu, uint8_t* mac);
|
||||
void append_mac(const unique_byte_buffer_t& sdu, uint8_t* mac);
|
||||
};
|
||||
|
||||
} // namespace srslte
|
||||
#endif // SRSLTE_PDCP_ENTITY_NR_H
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_PDCP_INTERFACE_H
|
||||
#define SRSLTE_PDCP_INTERFACE_H
|
||||
|
||||
#include "srslte/common/buffer_pool.h"
|
||||
#include "srslte/common/log.h"
|
||||
#include "srslte/common/common.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include "srslte/common/security.h"
|
||||
#include "srslte/common/threads.h"
|
||||
|
||||
|
||||
namespace srslte {
|
||||
|
||||
/****************************************************************************
|
||||
* Virtual PDCP interface common for all PDCP entities
|
||||
***************************************************************************/
|
||||
class pdcp_entity_interface
|
||||
{
|
||||
public:
|
||||
virtual ~pdcp_entity_interface() {};
|
||||
virtual void init(srsue::rlc_interface_pdcp *rlc_,
|
||||
srsue::rrc_interface_pdcp *rrc_,
|
||||
srsue::gw_interface_pdcp *gw_,
|
||||
srslte::log *log_,
|
||||
uint32_t lcid_,
|
||||
srslte_pdcp_config_t cfg_) = 0;
|
||||
virtual void reset() = 0;
|
||||
virtual void reestablish() = 0;
|
||||
virtual bool is_active() = 0;
|
||||
|
||||
// RRC interface
|
||||
virtual void write_sdu(unique_byte_buffer_t sdu, bool blocking) = 0;
|
||||
virtual void config_security(uint8_t *k_rrc_enc_,
|
||||
uint8_t *k_rrc_int_,
|
||||
uint8_t *k_up_enc_,
|
||||
CIPHERING_ALGORITHM_ID_ENUM cipher_algo_,
|
||||
INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) = 0;
|
||||
virtual void enable_integrity() = 0;
|
||||
virtual void enable_encryption() = 0;
|
||||
virtual uint32_t get_dl_count() = 0;
|
||||
virtual uint32_t get_ul_count() = 0;
|
||||
|
||||
// RLC interface
|
||||
virtual void write_pdu(unique_byte_buffer_t pdu) = 0;
|
||||
};
|
||||
|
||||
} // namespace srslte
|
||||
|
||||
|
||||
#endif // SRSLTE_PDCP_INTERFACE_H
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srslte/common/mac_nr_pcap.h"
|
||||
#include "srslte/srslte.h"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace srslte {
|
||||
|
||||
mac_nr_pcap::mac_nr_pcap() {}
|
||||
|
||||
mac_nr_pcap::~mac_nr_pcap()
|
||||
{
|
||||
if (pcap_file) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void mac_nr_pcap::enable(const bool& enable_)
|
||||
{
|
||||
enable_write = enable_;
|
||||
}
|
||||
void mac_nr_pcap::open(const std::string& filename_, const uint16_t& ue_id_)
|
||||
{
|
||||
fprintf(stdout, "Opening MAC-NR PCAP with DLT=%d\n", UDP_DLT);
|
||||
filename = filename_;
|
||||
pcap_file = LTE_PCAP_Open(UDP_DLT, filename.c_str());
|
||||
ue_id = ue_id_;
|
||||
enable_write = true;
|
||||
}
|
||||
void mac_nr_pcap::close()
|
||||
{
|
||||
enable_write = false;
|
||||
fprintf(stdout, "Saving MAC-NR PCAP to %s\n", filename.c_str());
|
||||
LTE_PCAP_Close(pcap_file);
|
||||
pcap_file = nullptr;
|
||||
}
|
||||
|
||||
void mac_nr_pcap::set_ue_id(const uint16_t& ue_id_)
|
||||
{
|
||||
ue_id = ue_id_;
|
||||
}
|
||||
|
||||
void mac_nr_pcap::pack_and_write(uint8_t* pdu,
|
||||
uint32_t pdu_len_bytes,
|
||||
uint32_t tti,
|
||||
uint16_t crnti,
|
||||
uint8_t harqid,
|
||||
uint8_t direction,
|
||||
uint8_t rnti_type)
|
||||
{
|
||||
if (enable_write) {
|
||||
mac_nr_context_info_t context = {};
|
||||
context.radioType = FDD_RADIO;
|
||||
context.direction = direction;
|
||||
context.rntiType = rnti_type;
|
||||
context.rnti = crnti;
|
||||
context.ueid = ue_id;
|
||||
context.harqid = harqid;
|
||||
context.system_frame_number = tti / 10;
|
||||
context.sub_frame_number = tti % 10;
|
||||
|
||||
if (pdu) {
|
||||
NR_PCAP_MAC_WritePDU(pcap_file, &context, pdu, pdu_len_bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mac_nr_pcap::write_dl_crnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti)
|
||||
{
|
||||
pack_and_write(pdu, pdu_len_bytes, tti, rnti, harqid, DIRECTION_DOWNLINK, C_RNTI);
|
||||
}
|
||||
|
||||
void mac_nr_pcap::write_ul_crnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti)
|
||||
{
|
||||
pack_and_write(pdu, pdu_len_bytes, tti, rnti, harqid, DIRECTION_UPLINK, C_RNTI);
|
||||
}
|
||||
|
||||
void mac_nr_pcap::write_dl_ra_rnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti)
|
||||
{
|
||||
pack_and_write(pdu, pdu_len_bytes, tti, rnti, harqid, DIRECTION_DOWNLINK, RA_RNTI);
|
||||
}
|
||||
|
||||
void mac_nr_pcap::write_dl_bch(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti)
|
||||
{
|
||||
pack_and_write(pdu, pdu_len_bytes, tti, rnti, harqid, DIRECTION_DOWNLINK, NO_RNTI);
|
||||
}
|
||||
|
||||
void mac_nr_pcap::write_dl_pch(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti)
|
||||
{
|
||||
pack_and_write(pdu, pdu_len_bytes, tti, rnti, harqid, DIRECTION_DOWNLINK, P_RNTI);
|
||||
}
|
||||
|
||||
void mac_nr_pcap::write_dl_si_rnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t rnti, uint8_t harqid, uint32_t tti)
|
||||
{
|
||||
pack_and_write(pdu, pdu_len_bytes, tti, rnti, harqid, DIRECTION_DOWNLINK, SI_RNTI);
|
||||
}
|
||||
|
||||
} // namespace srslte
|
@ -0,0 +1,275 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srslte/common/mac_nr_pdu.h"
|
||||
|
||||
namespace srslte {
|
||||
|
||||
mac_nr_sch_subpdu::mac_nr_sch_subpdu(mac_nr_sch_pdu* parent_) : parent(parent_) {}
|
||||
|
||||
mac_nr_sch_subpdu::nr_lcid_sch_t mac_nr_sch_subpdu::get_type()
|
||||
{
|
||||
if (lcid >= 32) {
|
||||
return (nr_lcid_sch_t)lcid;
|
||||
}
|
||||
|
||||
return CCCH;
|
||||
}
|
||||
|
||||
bool mac_nr_sch_subpdu::is_sdu()
|
||||
{
|
||||
return get_type() == CCCH;
|
||||
}
|
||||
|
||||
bool mac_nr_sch_subpdu::is_var_len_ce()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// return length of PDU
|
||||
uint32_t mac_nr_sch_subpdu::read_subheader(const uint8_t* ptr)
|
||||
{
|
||||
// Skip R, read F bit and LCID
|
||||
F_bit = (bool)(*ptr & 0x40) ? true : false;
|
||||
lcid = (uint8_t)*ptr & 0x3f;
|
||||
ptr++;
|
||||
header_length = 1;
|
||||
|
||||
if (is_sdu() || is_var_len_ce()) {
|
||||
// Read first length byte
|
||||
sdu_length = (uint32_t)*ptr;
|
||||
ptr++;
|
||||
header_length++;
|
||||
|
||||
if (F_bit) {
|
||||
// add second length byte
|
||||
sdu_length = sdu_length << 8 | ((uint32_t)*ptr & 0xff);
|
||||
ptr++;
|
||||
header_length++;
|
||||
}
|
||||
} else {
|
||||
sdu_length = sizeof_ce(lcid, parent->is_ulsch());
|
||||
}
|
||||
sdu = (uint8_t*)ptr;
|
||||
return header_length;
|
||||
}
|
||||
|
||||
void mac_nr_sch_subpdu::set_sdu(const uint32_t lcid_, const uint8_t* payload_, const uint32_t len_)
|
||||
{
|
||||
lcid = lcid_;
|
||||
sdu = const_cast<uint8_t*>(payload_);
|
||||
sdu_length = len_;
|
||||
header_length = 2;
|
||||
|
||||
if (sdu_length >= 256) {
|
||||
F_bit = true;
|
||||
header_length += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void mac_nr_sch_subpdu::set_padding(const uint32_t len_)
|
||||
{
|
||||
lcid = PADDING;
|
||||
// 1 Byte R/LCID MAC subheader
|
||||
sdu_length = len_ - 1;
|
||||
header_length = 1;
|
||||
}
|
||||
|
||||
// Section 6.1.2
|
||||
uint32_t mac_nr_sch_subpdu::write_subpdu(const uint8_t* start_)
|
||||
{
|
||||
uint8_t* ptr = const_cast<uint8_t*>(start_);
|
||||
*ptr = (uint8_t)((F_bit ? 1 : 0) << 6) | ((uint8_t)lcid & 0x3f);
|
||||
ptr += 1;
|
||||
|
||||
if (header_length == 3) {
|
||||
// 3 Byte R/F/LCID/L MAC subheader with 16-bit L field
|
||||
*ptr = ((sdu_length & 0xff00) >> 8);
|
||||
ptr += 1;
|
||||
*ptr = static_cast<uint8_t>(sdu_length);
|
||||
ptr += 1;
|
||||
|
||||
} else if (header_length == 2) {
|
||||
// 2 Byte R/F/LCID/L MAC subheader with 8-bit L field
|
||||
*ptr = static_cast<uint8_t>(sdu_length);
|
||||
ptr += 1;
|
||||
} else if (header_length == 1) {
|
||||
// do nothing
|
||||
} else {
|
||||
fprintf(stderr, "Error while packing PDU. Unsupported header length (%d)\n", header_length);
|
||||
}
|
||||
|
||||
// copy SDU payload
|
||||
if (sdu) {
|
||||
memcpy(ptr, sdu, sdu_length);
|
||||
} else {
|
||||
// clear memory
|
||||
memset(ptr, 0, sdu_length);
|
||||
}
|
||||
|
||||
ptr += sdu_length;
|
||||
|
||||
// return total length of subpdu
|
||||
return ptr - start_;
|
||||
}
|
||||
|
||||
uint32_t mac_nr_sch_subpdu::get_total_length()
|
||||
{
|
||||
return (header_length + sdu_length);
|
||||
}
|
||||
|
||||
uint32_t mac_nr_sch_subpdu::get_sdu_length()
|
||||
{
|
||||
return sdu_length;
|
||||
}
|
||||
|
||||
uint32_t mac_nr_sch_subpdu::get_lcid()
|
||||
{
|
||||
return lcid;
|
||||
}
|
||||
|
||||
uint8_t* mac_nr_sch_subpdu::get_sdu()
|
||||
{
|
||||
return sdu;
|
||||
}
|
||||
|
||||
uint32_t mac_nr_sch_subpdu::sizeof_ce(uint32_t lcid, bool is_ul)
|
||||
{
|
||||
if (is_ul) {
|
||||
switch (lcid) {
|
||||
case CRNTI:
|
||||
return 2;
|
||||
case SHORT_TRUNC_BSR:
|
||||
return 1;
|
||||
case SHORT_BSR:
|
||||
return 1;
|
||||
case PADDING:
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
switch (lcid) {
|
||||
case CON_RES_ID:
|
||||
return 6;
|
||||
case TA_CMD:
|
||||
return 1;
|
||||
case DRX_CMD:
|
||||
return 0;
|
||||
case PADDING:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mac_nr_sch_pdu::pack()
|
||||
{
|
||||
// SDUs are written in place, only add padding if needed
|
||||
if (remaining_len) {
|
||||
mac_nr_sch_subpdu padding_subpdu(this);
|
||||
padding_subpdu.set_padding(remaining_len);
|
||||
padding_subpdu.write_subpdu(buffer->msg + buffer->N_bytes);
|
||||
|
||||
// update length
|
||||
buffer->N_bytes += padding_subpdu.get_total_length();
|
||||
remaining_len -= padding_subpdu.get_total_length();
|
||||
subpdus.push_back(padding_subpdu);
|
||||
}
|
||||
}
|
||||
|
||||
void mac_nr_sch_pdu::unpack(const uint8_t* payload, const uint32_t& len)
|
||||
{
|
||||
uint32_t offset = 0;
|
||||
while (offset < len) {
|
||||
mac_nr_sch_subpdu sch_pdu(this);
|
||||
sch_pdu.read_subheader(payload + offset);
|
||||
offset += sch_pdu.get_total_length();
|
||||
subpdus.push_back(sch_pdu);
|
||||
}
|
||||
if (offset != len) {
|
||||
fprintf(stderr, "Error parsing NR MAC PDU (len=%d, offset=%d)\n", len, offset);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t mac_nr_sch_pdu::get_num_subpdus()
|
||||
{
|
||||
return subpdus.size();
|
||||
}
|
||||
|
||||
const mac_nr_sch_subpdu& mac_nr_sch_pdu::get_subpdu(const uint32_t& index)
|
||||
{
|
||||
return subpdus.at(index);
|
||||
}
|
||||
|
||||
bool mac_nr_sch_pdu::is_ulsch()
|
||||
{
|
||||
return ulsch;
|
||||
}
|
||||
|
||||
void mac_nr_sch_pdu::init_tx(byte_buffer_t* buffer_, uint32_t pdu_len_, bool ulsch_)
|
||||
{
|
||||
buffer = buffer_;
|
||||
pdu_len = pdu_len_;
|
||||
remaining_len = pdu_len_;
|
||||
ulsch = ulsch_;
|
||||
}
|
||||
|
||||
uint32_t mac_nr_sch_pdu::size_header_sdu(const uint32_t nbytes)
|
||||
{
|
||||
if (nbytes < 256) {
|
||||
return 2;
|
||||
} else {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t mac_nr_sch_pdu::get_remaing_len()
|
||||
{
|
||||
return remaining_len;
|
||||
}
|
||||
|
||||
uint32_t mac_nr_sch_pdu::add_sdu(const uint32_t lcid_, const uint8_t* payload_, const uint32_t len_)
|
||||
{
|
||||
int header_size = size_header_sdu(len_);
|
||||
|
||||
if (header_size + len_ > remaining_len) {
|
||||
printf("Header and SDU exceed space in PDU (%d > %d).\n", header_size + len_, remaining_len);
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
mac_nr_sch_subpdu sch_pdu(this);
|
||||
sch_pdu.set_sdu(lcid_, payload_, len_);
|
||||
uint32_t length = sch_pdu.write_subpdu(buffer->msg + buffer->N_bytes);
|
||||
|
||||
if (length != sch_pdu.get_total_length()) {
|
||||
fprintf(stderr, "Error writing subPDU (Length error: %d != %d)\n", length, sch_pdu.get_total_length());
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
// update length and advance payload pointer
|
||||
buffer->N_bytes += length;
|
||||
remaining_len -= length;
|
||||
|
||||
subpdus.push_back(sch_pdu);
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace srslte
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue