From 993055342d9076da075ee7962113165228c560f3 Mon Sep 17 00:00:00 2001 From: Piotr Krysik Date: Sat, 5 May 2018 12:38:11 +0200 Subject: Moving trx burst interface to trx directory and to new 'Transceiver' cathegory in gnuradio-companion --- grc/CMakeLists.txt | 1 + grc/gsm_block_tree.xml | 5 +- grc/misc_utils/CMakeLists.txt | 1 - grc/misc_utils/gsm_trx_burst_if.xml | 58 -------- grc/trx/CMakeLists.txt | 23 ++++ grc/trx/gsm_trx_burst_if.xml | 58 ++++++++ include/grgsm/CMakeLists.txt | 1 + include/grgsm/misc_utils/CMakeLists.txt | 1 - include/grgsm/misc_utils/trx_burst_if.h | 59 -------- include/grgsm/misc_utils/udp_socket.h | 69 ++++++++++ include/grgsm/trx/CMakeLists.txt | 26 ++++ include/grgsm/trx/trx_burst_if.h | 59 ++++++++ lib/CMakeLists.txt | 1 + lib/misc_utils/CMakeLists.txt | 1 - lib/misc_utils/trx_burst_if_impl.cc | 231 -------------------------------- lib/misc_utils/trx_burst_if_impl.h | 54 -------- lib/misc_utils/udp_socket.cc | 2 +- lib/misc_utils/udp_socket.h | 69 ---------- lib/trx/CMakeLists.txt | 23 ++++ lib/trx/trx_burst_if_impl.cc | 231 ++++++++++++++++++++++++++++++++ lib/trx/trx_burst_if_impl.h | 54 ++++++++ 21 files changed, 551 insertions(+), 476 deletions(-) delete mode 100644 grc/misc_utils/gsm_trx_burst_if.xml create mode 100644 grc/trx/CMakeLists.txt create mode 100644 grc/trx/gsm_trx_burst_if.xml delete mode 100644 include/grgsm/misc_utils/trx_burst_if.h create mode 100644 include/grgsm/misc_utils/udp_socket.h create mode 100644 include/grgsm/trx/CMakeLists.txt create mode 100644 include/grgsm/trx/trx_burst_if.h delete mode 100644 lib/misc_utils/trx_burst_if_impl.cc delete mode 100644 lib/misc_utils/trx_burst_if_impl.h delete mode 100644 lib/misc_utils/udp_socket.h create mode 100644 lib/trx/CMakeLists.txt create mode 100644 lib/trx/trx_burst_if_impl.cc create mode 100644 lib/trx/trx_burst_if_impl.h diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index c3646a2..ae06065 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -24,6 +24,7 @@ add_subdirectory(receiver) add_subdirectory(flow_control) add_subdirectory(misc_utils) add_subdirectory(transmitter) +add_subdirectory(trx) install(FILES gsm_block_tree.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/gsm_block_tree.xml b/grc/gsm_block_tree.xml index 7415bf0..2e502d0 100644 --- a/grc/gsm_block_tree.xml +++ b/grc/gsm_block_tree.xml @@ -29,6 +29,10 @@ gsm_preprocess_tx_burst gsm_gen_test_ab + + Transceiver + gsm_trx_burst_if + Logical channels demapping gsm_universal_ctrl_chans_demapper @@ -75,7 +79,6 @@ gsm_clock_offset_corrector_tagged gsm_msg_to_tag gsm_tmsi_dumper - gsm_trx_burst_if gsm_burst_to_fn_time diff --git a/grc/misc_utils/CMakeLists.txt b/grc/misc_utils/CMakeLists.txt index 78f66c9..bad53e6 100644 --- a/grc/misc_utils/CMakeLists.txt +++ b/grc/misc_utils/CMakeLists.txt @@ -32,7 +32,6 @@ install(FILES gsm_burst_file_source.xml gsm_message_file_sink.xml gsm_message_file_source.xml - gsm_trx_burst_if.xml gsm_msg_to_tag.xml gsm_controlled_fractional_resampler_cc.xml gsm_burst_to_fn_time.xml diff --git a/grc/misc_utils/gsm_trx_burst_if.xml b/grc/misc_utils/gsm_trx_burst_if.xml deleted file mode 100644 index 99427b3..0000000 --- a/grc/misc_utils/gsm_trx_burst_if.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - TRX Burst Interface - gsm_trx_burst_if - import grgsm - grgsm.trx_burst_if($remote_addr, $base_port) - - - base_port - base_port - 5700 - string - - - - remote_addr - remote_addr - 127.0.0.1 - string - - - - bursts - message - 1 - - - - bursts - message - 1 - - - - OsmoTRX like UDP burst interface for external applications. - - There are two UDP connections, where each message carries - one radio burst with header. Give a base port B (5700 by default). - One connection at port P=B+100+2 is used for sending received bursts - to an external application. Another one at port P=B+2 is used to - obtain to be transmitted bursts. - - Received burst format: - 1 byte timeslot index - 4 bytes GSM frame number, big endian - 1 byte RSSI in -dBm - 2 bytes correlator timing offset in 1/256 symbol steps, - 2's-comp, big endian - 148 bytes soft symbol estimates, 0 -> definite "0", - 255 -> definite "1" - - To be transmitted burst format: - 1 byte timeslot index - 4 bytes GSM frame number, big endian - 1 byte transmit level wrt ARFCN max, -dB (attenuation) - 148 bytes output symbol values, 0 & 1 - - diff --git a/grc/trx/CMakeLists.txt b/grc/trx/CMakeLists.txt new file mode 100644 index 0000000..ac4ae13 --- /dev/null +++ b/grc/trx/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright 2011,2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +install(FILES + gsm_trx_burst_if.xml + DESTINATION share/gnuradio/grc/blocks +) diff --git a/grc/trx/gsm_trx_burst_if.xml b/grc/trx/gsm_trx_burst_if.xml new file mode 100644 index 0000000..99427b3 --- /dev/null +++ b/grc/trx/gsm_trx_burst_if.xml @@ -0,0 +1,58 @@ + + + TRX Burst Interface + gsm_trx_burst_if + import grgsm + grgsm.trx_burst_if($remote_addr, $base_port) + + + base_port + base_port + 5700 + string + + + + remote_addr + remote_addr + 127.0.0.1 + string + + + + bursts + message + 1 + + + + bursts + message + 1 + + + + OsmoTRX like UDP burst interface for external applications. + + There are two UDP connections, where each message carries + one radio burst with header. Give a base port B (5700 by default). + One connection at port P=B+100+2 is used for sending received bursts + to an external application. Another one at port P=B+2 is used to + obtain to be transmitted bursts. + + Received burst format: + 1 byte timeslot index + 4 bytes GSM frame number, big endian + 1 byte RSSI in -dBm + 2 bytes correlator timing offset in 1/256 symbol steps, + 2's-comp, big endian + 148 bytes soft symbol estimates, 0 -> definite "0", + 255 -> definite "1" + + To be transmitted burst format: + 1 byte timeslot index + 4 bytes GSM frame number, big endian + 1 byte transmit level wrt ARFCN max, -dB (attenuation) + 148 bytes output symbol values, 0 & 1 + + diff --git a/include/grgsm/CMakeLists.txt b/include/grgsm/CMakeLists.txt index 2f76929..2982ef1 100644 --- a/include/grgsm/CMakeLists.txt +++ b/include/grgsm/CMakeLists.txt @@ -37,3 +37,4 @@ add_subdirectory(misc_utils) add_subdirectory(qa_utils) add_subdirectory(flow_control) add_subdirectory(transmitter) +add_subdirectory(trx) diff --git a/include/grgsm/misc_utils/CMakeLists.txt b/include/grgsm/misc_utils/CMakeLists.txt index 23fe980..f8d8cbc 100644 --- a/include/grgsm/misc_utils/CMakeLists.txt +++ b/include/grgsm/misc_utils/CMakeLists.txt @@ -35,7 +35,6 @@ install(FILES message_printer.h tmsi_dumper.h msg_to_tag.h - trx_burst_if.h burst_to_fn_time.h controlled_fractional_resampler_cc.h time_spec.h diff --git a/include/grgsm/misc_utils/trx_burst_if.h b/include/grgsm/misc_utils/trx_burst_if.h deleted file mode 100644 index 0e7a35a..0000000 --- a/include/grgsm/misc_utils/trx_burst_if.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- c++ -*- */ -/* @file - * @author Vadim Yanitskiy - * @section LICENSE - * - * Gr-gsm is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * Gr-gsm 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gr-gsm; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef INCLUDED_GRGSM_TRX_BURST_IF_H -#define INCLUDED_GRGSM_TRX_BURST_IF_H - -#include -#include - -namespace gr { - namespace gsm { - - /*! - * \brief <+description of block+> - * \ingroup grgsm - * - */ - class GRGSM_API trx_burst_if : virtual public gr::block - { - public: - typedef boost::shared_ptr sptr; - - /*! - * \brief Return a shared_ptr to a new instance of grgsm::trx_burst_if. - * - * To avoid accidental use of raw pointers, grgsm::trx_burst_if's - * constructor is in a private implementation - * class. grgsm::trx_burst_if::make is the public interface for - * creating new instances. - */ - static sptr make( - const std::string &remote_addr, - const std::string &base_port); - }; - - } // namespace gsm -} // namespace gr - -#endif /* INCLUDED_GRGSM_TRX_BURST_IF_H */ - diff --git a/include/grgsm/misc_utils/udp_socket.h b/include/grgsm/misc_utils/udp_socket.h new file mode 100644 index 0000000..15b2c66 --- /dev/null +++ b/include/grgsm/misc_utils/udp_socket.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GRGSM_TRX_UDP_SOCKET_H +#define INCLUDED_GRGSM_TRX_UDP_SOCKET_H + +#include + +#include +#include +#include +#include +#include + +namespace gr { + namespace gsm { + + class udp_socket + { + private: + boost::asio::io_service d_io_service; + std::vector d_rxbuf; + gr::thread::thread d_thread; + bool d_started; + bool d_finished; + + boost::asio::ip::udp::endpoint d_udp_endpoint_rx; + boost::asio::ip::udp::endpoint d_udp_endpoint_tx; + boost::shared_ptr d_udp_socket; + + void handle_udp_read(const boost::system::error_code& error, + size_t bytes_transferred); + void run_io_service(void); + + public: + udp_socket( + const std::string &remote_addr, + const std::string &src_port, + const std::string &dst_port, + size_t mtu); + ~udp_socket(); + + void udp_send(uint8_t *data, size_t len); + boost::function udp_rx_handler; + }; + + } /* namespace gsm */ +} /* namespace gr */ + +#endif /* INCLUDED_GRGSM_TRX_UDP_SOCKET_H */ diff --git a/include/grgsm/trx/CMakeLists.txt b/include/grgsm/trx/CMakeLists.txt new file mode 100644 index 0000000..a9847dd --- /dev/null +++ b/include/grgsm/trx/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright 2011,2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +# Install public header files +######################################################################## +install(FILES + trx_burst_if.h + DESTINATION include/grgsm/trx +) diff --git a/include/grgsm/trx/trx_burst_if.h b/include/grgsm/trx/trx_burst_if.h new file mode 100644 index 0000000..0e7a35a --- /dev/null +++ b/include/grgsm/trx/trx_burst_if.h @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* @file + * @author Vadim Yanitskiy + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef INCLUDED_GRGSM_TRX_BURST_IF_H +#define INCLUDED_GRGSM_TRX_BURST_IF_H + +#include +#include + +namespace gr { + namespace gsm { + + /*! + * \brief <+description of block+> + * \ingroup grgsm + * + */ + class GRGSM_API trx_burst_if : virtual public gr::block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * \brief Return a shared_ptr to a new instance of grgsm::trx_burst_if. + * + * To avoid accidental use of raw pointers, grgsm::trx_burst_if's + * constructor is in a private implementation + * class. grgsm::trx_burst_if::make is the public interface for + * creating new instances. + */ + static sptr make( + const std::string &remote_addr, + const std::string &base_port); + }; + + } // namespace gsm +} // namespace gr + +#endif /* INCLUDED_GRGSM_TRX_BURST_IF_H */ + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 923de48..518edc4 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -71,6 +71,7 @@ add_subdirectory(misc_utils) add_subdirectory(qa_utils) add_subdirectory(receiver) add_subdirectory(transmitter) +add_subdirectory(trx) ######################################################################## # Setup library diff --git a/lib/misc_utils/CMakeLists.txt b/lib/misc_utils/CMakeLists.txt index c81a92d..63effe5 100644 --- a/lib/misc_utils/CMakeLists.txt +++ b/lib/misc_utils/CMakeLists.txt @@ -36,7 +36,6 @@ add_sources( time_spec.cc fn_time.cc udp_socket.cc - trx_burst_if_impl.cc burst_to_fn_time_impl.cc ) diff --git a/lib/misc_utils/trx_burst_if_impl.cc b/lib/misc_utils/trx_burst_if_impl.cc deleted file mode 100644 index 8f458b0..0000000 --- a/lib/misc_utils/trx_burst_if_impl.cc +++ /dev/null @@ -1,231 +0,0 @@ -/* -*- c++ -*- */ -/* @file - * @author Vadim Yanitskiy - * @section LICENSE - * - * Gr-gsm is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * Gr-gsm 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gr-gsm; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include "udp_socket.h" -#include "trx_burst_if_impl.h" - -#define BURST_SIZE 148 -#define DATA_IF_MTU 160 - -/** - * 41-bit RACH synchronization sequence - * GSM 05.02 Chapter 5.2.7 Access burst (AB) - */ -static uint8_t rach_synch_seq[] = { - 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, - 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, -}; - -namespace gr { - namespace gsm { - - trx_burst_if::sptr - trx_burst_if::make( - const std::string &remote_addr, - const std::string &base_port) - { - int base_port_int = boost::lexical_cast (base_port); - - return gnuradio::get_initial_sptr - (new trx_burst_if_impl(remote_addr, base_port_int)); - } - - /* - * The private constructor - */ - trx_burst_if_impl::trx_burst_if_impl( - const std::string &remote_addr, - int base_port - ) : gr::block("trx_burst_if", - gr::io_signature::make(0, 0, 0), - gr::io_signature::make(0, 0, 0)) - { - message_port_register_in(pmt::mp("bursts")); - message_port_register_out(pmt::mp("bursts")); - - // Bind a port handler - set_msg_handler(pmt::mp("bursts"), - boost::bind(&trx_burst_if_impl::handle_dl_burst, this, _1)); - - // Prepare port numbers - std::string data_src_port = boost::lexical_cast (base_port + 2); - std::string data_dst_port = boost::lexical_cast (base_port + 102); - - // Init DATA interface - d_data_sock = new udp_socket(remote_addr, - data_src_port, data_dst_port, DATA_IF_MTU); - - // Bind DATA interface handler - d_data_sock->udp_rx_handler = boost::bind( - &trx_burst_if_impl::handle_ul_burst, this, _1, _2); - } - - /* - * Our virtual destructor. - */ - trx_burst_if_impl::~trx_burst_if_impl() - { - // Release all UDP sockets and free memory - delete d_data_sock; - } - - /* - * Check if burst is a RACH burst - */ - bool trx_burst_if_impl::detect_rach(uint8_t *burst) - { - // Compare synchronization sequence - for (int i = 0; i < 41; i++) - if (burst[i + 8] != rach_synch_seq[i]) - return false; - - // Make sure TB and GP are filled by 0x00 - for (int i = 0; i < 63; i++) - if (burst[i + 85] != 0x00) - return false; - - return true; - } - - /* - * Create an UDP payload with burst bits - * and some channel data. - */ - void - trx_burst_if_impl::burst_pack(pmt::pmt_t msg, uint8_t *buf) - { - pmt::pmt_t header_plus_burst = pmt::cdr(msg); - - // Extract GSMTAP header from message - gsmtap_hdr *header = (gsmtap_hdr *) - pmt::blob_data(header_plus_burst); - - // Pack timeslot index - buf[0] = header->timeslot; - - // Extract frame number - uint32_t frame_nr = be32toh(header->frame_number); - - // Pack frame number - buf[1] = (frame_nr >> 24) & 0xff; - buf[2] = (frame_nr >> 16) & 0xff; - buf[3] = (frame_nr >> 8) & 0xff; - buf[4] = (frame_nr >> 0) & 0xff; - - // Pack RSSI (-dBm) - buf[5] = -(uint8_t) header->signal_dbm; - - // Pack correlator timing offset (TOA) - // FIXME: where to find this value? - buf[6] = 0; - buf[7] = 0; - - // Extract bits {0..1} from message - // Despite GR-GSM uses int8_t, they are not real sbits {-127..127} - uint8_t *burst = (uint8_t *) - (pmt::blob_data(header_plus_burst)) + sizeof(gsmtap_hdr); - - // Convert to transceiver interface specific bits {255..0} - for (int i = 0; i < 148; i++) - buf[8 + i] = burst[i] ? 255 : 0; - - // Fill two unused bytes - buf[156] = 0x00; - buf[157] = 0x00; - } - - void - trx_burst_if_impl::handle_dl_burst(pmt::pmt_t msg) - { - // 8 bytes of header + 148 bytes of burst - // + two unused, but required bytes - // otherwise bursts would be rejected - uint8_t buf[158]; - - // Compose a new UDP payload with burst - burst_pack(msg, buf); - - // Send a burst - d_data_sock->udp_send(buf, 158); - } - - void - trx_burst_if_impl::handle_ul_burst(uint8_t *payload, size_t len) - { - // Check length according to the protocol - if (len != 154) - return; - - /* Make sure TS index is correct */ - if (payload[0] >= 8) - return; - - /* Unpack and check frame number */ - uint32_t fn = (payload[1] << 24) - | (payload[2] << 16) - | (payload[3] << 8) - | payload[4]; - - if (fn >= 2715648) - return; - - // Prepare a buffer for GSMTAP header and burst - uint8_t buf[sizeof(gsmtap_hdr) + BURST_SIZE]; - - // Set up pointer to GSMTAP header structure - struct gsmtap_hdr *header = (struct gsmtap_hdr *) buf; - memset(header, 0x00, sizeof(struct gsmtap_hdr)); - - // Fill in basic info - header->version = GSMTAP_VERSION; - header->hdr_len = sizeof(gsmtap_hdr) / 4; - header->type = GSMTAP_TYPE_UM_BURST; - - // Set timeslot index and frame number - header->timeslot = payload[0]; - header->frame_number = htobe32(fn); - - // Check if one is a RACH burst - header->sub_type = detect_rach(payload + 6) ? - GSMTAP_BURST_ACCESS : GSMTAP_BURST_NORMAL; - - // Copy burst bits (0 & 1) for source message - memcpy(buf + sizeof(gsmtap_hdr), payload + 6, BURST_SIZE); - - // Create a pmt blob - pmt::pmt_t blob = pmt::make_blob(buf, sizeof(gsmtap_hdr) + BURST_SIZE); - pmt::pmt_t msg = pmt::cons(pmt::PMT_NIL, blob); - - /* Send a message to the output */ - message_port_pub(pmt::mp("bursts"), msg); - } - - } /* namespace gsm */ -} /* namespace gr */ diff --git a/lib/misc_utils/trx_burst_if_impl.h b/lib/misc_utils/trx_burst_if_impl.h deleted file mode 100644 index 35f939c..0000000 --- a/lib/misc_utils/trx_burst_if_impl.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- c++ -*- */ -/* @file - * @author Vadim Yanitskiy - * @section LICENSE - * - * Gr-gsm is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * Gr-gsm 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gr-gsm; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef INCLUDED_GRGSM_TRX_BURST_IF_IMPL_H -#define INCLUDED_GRGSM_TRX_BURST_IF_IMPL_H - -#include - -#include -#include - -namespace gr { - namespace gsm { - - class trx_burst_if_impl : public trx_burst_if - { - private: - udp_socket *d_data_sock; - - bool detect_rach(uint8_t *burst); - void burst_pack(pmt::pmt_t msg, uint8_t *buf); - - public: - trx_burst_if_impl(const std::string &remote_addr, int base_port); - ~trx_burst_if_impl(); - - void handle_dl_burst(pmt::pmt_t msg); - void handle_ul_burst(uint8_t *payload, size_t len); - }; - - } // namespace gsm -} // namespace gr - -#endif /* INCLUDED_GRGSM_TRX_BURST_IF_IMPL_H */ - diff --git a/lib/misc_utils/udp_socket.cc b/lib/misc_utils/udp_socket.cc index 5c689c7..73393a0 100644 --- a/lib/misc_utils/udp_socket.cc +++ b/lib/misc_utils/udp_socket.cc @@ -30,7 +30,7 @@ #include #include -#include "udp_socket.h" +#include "grgsm/misc_utils/udp_socket.h" using boost::asio::ip::udp; diff --git a/lib/misc_utils/udp_socket.h b/lib/misc_utils/udp_socket.h deleted file mode 100644 index 15b2c66..0000000 --- a/lib/misc_utils/udp_socket.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GRGSM_TRX_UDP_SOCKET_H -#define INCLUDED_GRGSM_TRX_UDP_SOCKET_H - -#include - -#include -#include -#include -#include -#include - -namespace gr { - namespace gsm { - - class udp_socket - { - private: - boost::asio::io_service d_io_service; - std::vector d_rxbuf; - gr::thread::thread d_thread; - bool d_started; - bool d_finished; - - boost::asio::ip::udp::endpoint d_udp_endpoint_rx; - boost::asio::ip::udp::endpoint d_udp_endpoint_tx; - boost::shared_ptr d_udp_socket; - - void handle_udp_read(const boost::system::error_code& error, - size_t bytes_transferred); - void run_io_service(void); - - public: - udp_socket( - const std::string &remote_addr, - const std::string &src_port, - const std::string &dst_port, - size_t mtu); - ~udp_socket(); - - void udp_send(uint8_t *data, size_t len); - boost::function udp_rx_handler; - }; - - } /* namespace gsm */ -} /* namespace gr */ - -#endif /* INCLUDED_GRGSM_TRX_UDP_SOCKET_H */ diff --git a/lib/trx/CMakeLists.txt b/lib/trx/CMakeLists.txt new file mode 100644 index 0000000..32694b2 --- /dev/null +++ b/lib/trx/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright 2011,2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +add_sources( + trx_burst_if_impl.cc +) + diff --git a/lib/trx/trx_burst_if_impl.cc b/lib/trx/trx_burst_if_impl.cc new file mode 100644 index 0000000..e3fcc89 --- /dev/null +++ b/lib/trx/trx_burst_if_impl.cc @@ -0,0 +1,231 @@ +/* -*- c++ -*- */ +/* @file + * @author Vadim Yanitskiy + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "grgsm/misc_utils/udp_socket.h" +#include "trx_burst_if_impl.h" + +#define BURST_SIZE 148 +#define DATA_IF_MTU 160 + +/** + * 41-bit RACH synchronization sequence + * GSM 05.02 Chapter 5.2.7 Access burst (AB) + */ +static uint8_t rach_synch_seq[] = { + 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, + 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, +}; + +namespace gr { + namespace gsm { + + trx_burst_if::sptr + trx_burst_if::make( + const std::string &remote_addr, + const std::string &base_port) + { + int base_port_int = boost::lexical_cast (base_port); + + return gnuradio::get_initial_sptr + (new trx_burst_if_impl(remote_addr, base_port_int)); + } + + /* + * The private constructor + */ + trx_burst_if_impl::trx_burst_if_impl( + const std::string &remote_addr, + int base_port + ) : gr::block("trx_burst_if", + gr::io_signature::make(0, 0, 0), + gr::io_signature::make(0, 0, 0)) + { + message_port_register_in(pmt::mp("bursts")); + message_port_register_out(pmt::mp("bursts")); + + // Bind a port handler + set_msg_handler(pmt::mp("bursts"), + boost::bind(&trx_burst_if_impl::handle_dl_burst, this, _1)); + + // Prepare port numbers + std::string data_src_port = boost::lexical_cast (base_port + 2); + std::string data_dst_port = boost::lexical_cast (base_port + 102); + + // Init DATA interface + d_data_sock = new udp_socket(remote_addr, + data_src_port, data_dst_port, DATA_IF_MTU); + + // Bind DATA interface handler + d_data_sock->udp_rx_handler = boost::bind( + &trx_burst_if_impl::handle_ul_burst, this, _1, _2); + } + + /* + * Our virtual destructor. + */ + trx_burst_if_impl::~trx_burst_if_impl() + { + // Release all UDP sockets and free memory + delete d_data_sock; + } + + /* + * Check if burst is a RACH burst + */ + bool trx_burst_if_impl::detect_rach(uint8_t *burst) + { + // Compare synchronization sequence + for (int i = 0; i < 41; i++) + if (burst[i + 8] != rach_synch_seq[i]) + return false; + + // Make sure TB and GP are filled by 0x00 + for (int i = 0; i < 63; i++) + if (burst[i + 85] != 0x00) + return false; + + return true; + } + + /* + * Create an UDP payload with burst bits + * and some channel data. + */ + void + trx_burst_if_impl::burst_pack(pmt::pmt_t msg, uint8_t *buf) + { + pmt::pmt_t header_plus_burst = pmt::cdr(msg); + + // Extract GSMTAP header from message + gsmtap_hdr *header = (gsmtap_hdr *) + pmt::blob_data(header_plus_burst); + + // Pack timeslot index + buf[0] = header->timeslot; + + // Extract frame number + uint32_t frame_nr = be32toh(header->frame_number); + + // Pack frame number + buf[1] = (frame_nr >> 24) & 0xff; + buf[2] = (frame_nr >> 16) & 0xff; + buf[3] = (frame_nr >> 8) & 0xff; + buf[4] = (frame_nr >> 0) & 0xff; + + // Pack RSSI (-dBm) + buf[5] = -(uint8_t) header->signal_dbm; + + // Pack correlator timing offset (TOA) + // FIXME: where to find this value? + buf[6] = 0; + buf[7] = 0; + + // Extract bits {0..1} from message + // Despite GR-GSM uses int8_t, they are not real sbits {-127..127} + uint8_t *burst = (uint8_t *) + (pmt::blob_data(header_plus_burst)) + sizeof(gsmtap_hdr); + + // Convert to transceiver interface specific bits {255..0} + for (int i = 0; i < 148; i++) + buf[8 + i] = burst[i] ? 255 : 0; + + // Fill two unused bytes + buf[156] = 0x00; + buf[157] = 0x00; + } + + void + trx_burst_if_impl::handle_dl_burst(pmt::pmt_t msg) + { + // 8 bytes of header + 148 bytes of burst + // + two unused, but required bytes + // otherwise bursts would be rejected + uint8_t buf[158]; + + // Compose a new UDP payload with burst + burst_pack(msg, buf); + + // Send a burst + d_data_sock->udp_send(buf, 158); + } + + void + trx_burst_if_impl::handle_ul_burst(uint8_t *payload, size_t len) + { + // Check length according to the protocol + if (len != 154) + return; + + /* Make sure TS index is correct */ + if (payload[0] >= 8) + return; + + /* Unpack and check frame number */ + uint32_t fn = (payload[1] << 24) + | (payload[2] << 16) + | (payload[3] << 8) + | payload[4]; + + if (fn >= 2715648) + return; + + // Prepare a buffer for GSMTAP header and burst + uint8_t buf[sizeof(gsmtap_hdr) + BURST_SIZE]; + + // Set up pointer to GSMTAP header structure + struct gsmtap_hdr *header = (struct gsmtap_hdr *) buf; + memset(header, 0x00, sizeof(struct gsmtap_hdr)); + + // Fill in basic info + header->version = GSMTAP_VERSION; + header->hdr_len = sizeof(gsmtap_hdr) / 4; + header->type = GSMTAP_TYPE_UM_BURST; + + // Set timeslot index and frame number + header->timeslot = payload[0]; + header->frame_number = htobe32(fn); + + // Check if one is a RACH burst + header->sub_type = detect_rach(payload + 6) ? + GSMTAP_BURST_ACCESS : GSMTAP_BURST_NORMAL; + + // Copy burst bits (0 & 1) for source message + memcpy(buf + sizeof(gsmtap_hdr), payload + 6, BURST_SIZE); + + // Create a pmt blob + pmt::pmt_t blob = pmt::make_blob(buf, sizeof(gsmtap_hdr) + BURST_SIZE); + pmt::pmt_t msg = pmt::cons(pmt::PMT_NIL, blob); + + /* Send a message to the output */ + message_port_pub(pmt::mp("bursts"), msg); + } + + } /* namespace gsm */ +} /* namespace gr */ diff --git a/lib/trx/trx_burst_if_impl.h b/lib/trx/trx_burst_if_impl.h new file mode 100644 index 0000000..35f939c --- /dev/null +++ b/lib/trx/trx_burst_if_impl.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* @file + * @author Vadim Yanitskiy + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef INCLUDED_GRGSM_TRX_BURST_IF_IMPL_H +#define INCLUDED_GRGSM_TRX_BURST_IF_IMPL_H + +#include + +#include +#include + +namespace gr { + namespace gsm { + + class trx_burst_if_impl : public trx_burst_if + { + private: + udp_socket *d_data_sock; + + bool detect_rach(uint8_t *burst); + void burst_pack(pmt::pmt_t msg, uint8_t *buf); + + public: + trx_burst_if_impl(const std::string &remote_addr, int base_port); + ~trx_burst_if_impl(); + + void handle_dl_burst(pmt::pmt_t msg); + void handle_ul_burst(uint8_t *payload, size_t len); + }; + + } // namespace gsm +} // namespace gr + +#endif /* INCLUDED_GRGSM_TRX_BURST_IF_IMPL_H */ + -- cgit v1.2.3