blob: fbd9bd320c65445d08f8545f231db8032fe853a3 [file] [log] [blame]
piotr6c692872014-02-08 14:16:26 +01001/* -*- c++ -*- */
ptrkrysik529895b2014-12-02 18:07:38 +01002/*
3 * @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004 * @author (C) 2014 by Piotr Krysik <ptrkrysik@gmail.com>
ptrkrysik529895b2014-12-02 18:07:38 +01005 * @section LICENSE
6 *
7 * Gr-gsm is free software; you can redistribute it and/or modify
piotr6c692872014-02-08 14:16:26 +01008 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
ptrkrysik529895b2014-12-02 18:07:38 +010011 *
12 * Gr-gsm is distributed in the hope that it will be useful,
piotr6c692872014-02-08 14:16:26 +010013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
ptrkrysik529895b2014-12-02 18:07:38 +010016 *
piotr6c692872014-02-08 14:16:26 +010017 * You should have received a copy of the GNU General Public License
ptrkrysik529895b2014-12-02 18:07:38 +010018 * along with gr-gsm; see the file COPYING. If not, write to
piotr6c692872014-02-08 14:16:26 +010019 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
ptrkrysik3be74a72014-12-13 10:11:00 +010028#include <grgsm/gsmtap.h>
Martin Jesper Low Madsenaf769642015-04-28 22:33:43 +020029#include <grgsm/endian.h>
piotr6d152d92014-02-21 00:02:44 +010030#include <iterator>
31#include <algorithm>
piotrfaacc722014-07-20 23:48:32 +020032#include "bursts_printer_impl.h"
Piotr Krysikeb81b032018-02-27 08:46:17 +010033//#include <unistd.h>
piotrc00ce9c2014-08-04 11:21:24 +020034#include <iostream>
Roman Khassraf9a54c7b2015-09-13 11:04:42 +020035extern "C" {
36 #include <osmocom/gsm/a5.h>
37}
piotr6c692872014-02-08 14:16:26 +010038
39namespace gr {
40 namespace gsm {
piotrc00ce9c2014-08-04 11:21:24 +020041 boost::mutex printer_mutex;
Roman Khassraf7faabf32015-07-24 14:14:16 +020042 // dummy burst defined in gsm 05.02, section 5.2.6
43 const int8_t bursts_printer_impl::d_dummy_burst[] = {0,0,0,
44 1,1,1,1,1,0,1,1,0,1,1,1,0,1,1,0,
45 0,0,0,0,1,0,1,0,0,1,0,0,1,1,1,0,
46 0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,
47 0,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,
48 0,1,0,1,1,1,0,0,0,1,0,1,1,1,0,0,
49 0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0,
50 0,0,1,1,0,0,1,1,0,0,1,1,1,0,0,1,
51 1,1,1,0,1,0,0,1,1,1,1,1,0,0,0,1,
52 0,0,1,0,1,1,1,1,1,0,1,0,1,0,
53 0,0,0 };
54
piotr6d152d92014-02-21 00:02:44 +010055 void bursts_printer_impl::bursts_print(pmt::pmt_t msg)
piotr6c692872014-02-08 14:16:26 +010056 {
ptrkrysik617ba032014-11-21 10:11:05 +010057 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
piotr6c692872014-02-08 14:16:26 +010058
ptrkrysik617ba032014-11-21 10:11:05 +010059 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
60 int8_t * burst = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
61 size_t burst_len=pmt::blob_length(header_plus_burst)-sizeof(gsmtap_hdr);
Roman Khassraf63444962015-07-13 13:42:57 +020062 uint32_t frame_nr = be32toh(header->frame_number);
Martin Jesper Low Madsenaf769642015-04-28 22:33:43 +020063
Roman Khassraf7faabf32015-07-24 14:14:16 +020064 if (d_ignore_dummy_bursts && is_dummy_burst(burst, burst_len))
65 {
66 return;
67 }
68
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +030069 std::ostringstream out;
70 out << d_prepend_string;
Martin Jesper Low Madsenaf769642015-04-28 22:33:43 +020071 if (d_prepend_fnr)
Roman Khassraf717b57b2015-04-12 18:09:45 +020072 {
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +030073 out << frame_nr;
Martin Jesper Low Madsenaf769642015-04-28 22:33:43 +020074 }
Roman Khassraf717b57b2015-04-12 18:09:45 +020075
Roman Khassraf63444962015-07-13 13:42:57 +020076 if (d_prepend_fnr && d_prepend_frame_count)
piotr6c692872014-02-08 14:16:26 +010077 {
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +030078 out << " ";
piotr6c692872014-02-08 14:16:26 +010079 }
Roman Khassraf63444962015-07-13 13:42:57 +020080
81 if (d_prepend_frame_count)
82 {
Roman Khassraf9a54c7b2015-09-13 11:04:42 +020083 // calculate fn count using libosmogsm
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +030084 out << osmo_a5_fn_count(frame_nr);
Roman Khassraf63444962015-07-13 13:42:57 +020085 }
86
87 if (d_prepend_fnr || d_prepend_frame_count)
88 {
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +030089 out << ": ";
Roman Khassraf63444962015-07-13 13:42:57 +020090 }
91
92 if (d_print_payload_only)
93 {
94 for (int ii=0; ii<57; ii++)
95 {
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +030096 out << std::setprecision(1) << static_cast<int>(burst[ii + 3]);
Roman Khassraf63444962015-07-13 13:42:57 +020097 }
98 for (int ii=0; ii<57; ii++)
99 {
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +0300100 out << std::setprecision(1) << static_cast<int>(burst[ii + 88]);
Roman Khassraf63444962015-07-13 13:42:57 +0200101 }
102 }
103 else
104 {
105 for(int ii=0; ii<burst_len; ii++)
106 {
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +0300107 out << std::setprecision(1) << static_cast<int>(burst[ii]);
Roman Khassraf63444962015-07-13 13:42:57 +0200108 }
109 }
110
Vasil Velichkov75ae9cc2018-08-31 00:59:48 +0300111 out << std::endl;
112 std::cout << out.str() << std::flush;
piotr6c692872014-02-08 14:16:26 +0100113 }
Martin Jesper Low Madsenaf769642015-04-28 22:33:43 +0200114
Roman Khassraf7faabf32015-07-24 14:14:16 +0200115 bool bursts_printer_impl::is_dummy_burst(int8_t *burst, size_t burst_len)
116 {
117 if (burst_len != DUMMY_BURST_LEN)
118 {
119 return false;
120 }
121 for (int i=0; i<DUMMY_BURST_LEN; i++)
122 {
123 if (burst[i] != d_dummy_burst[i])
124 {
125 return false;
126 }
127 }
128 return true;
129 }
130
piotr6c692872014-02-08 14:16:26 +0100131 bursts_printer::sptr
Roman Khassraf63444962015-07-13 13:42:57 +0200132 bursts_printer::make(pmt::pmt_t prepend_string, bool prepend_fnr,
Roman Khassraf7faabf32015-07-24 14:14:16 +0200133 bool prepend_frame_count, bool print_payload_only,
134 bool ignore_dummy_bursts)
piotr6c692872014-02-08 14:16:26 +0100135 {
136 return gnuradio::get_initial_sptr
Roman Khassraf7faabf32015-07-24 14:14:16 +0200137 (new bursts_printer_impl(prepend_string, prepend_fnr, prepend_frame_count,
138 print_payload_only, ignore_dummy_bursts));
piotr6c692872014-02-08 14:16:26 +0100139 }
140
141 /*
142 * The private constructor
143 */
Roman Khassraf63444962015-07-13 13:42:57 +0200144 bursts_printer_impl::bursts_printer_impl(pmt::pmt_t prepend_string, bool prepend_fnr,
Roman Khassraf7faabf32015-07-24 14:14:16 +0200145 bool prepend_frame_count, bool print_payload_only,
146 bool ignore_dummy_bursts)
piotr6c692872014-02-08 14:16:26 +0100147 : gr::block("bursts_printer",
148 gr::io_signature::make(0, 0, 0),
149 gr::io_signature::make(0, 0, 0))
150 {
Jacob Gilbert607a09e2014-12-13 10:41:20 -0800151 d_prepend_string = prepend_string;
Roman Khassraf717b57b2015-04-12 18:09:45 +0200152 d_prepend_fnr = prepend_fnr;
Roman Khassraf63444962015-07-13 13:42:57 +0200153 d_prepend_frame_count = prepend_frame_count;
154 d_print_payload_only = print_payload_only;
Roman Khassraf7faabf32015-07-24 14:14:16 +0200155 d_ignore_dummy_bursts = ignore_dummy_bursts;
156
piotr6c692872014-02-08 14:16:26 +0100157 message_port_register_in(pmt::mp("bursts"));
Vadim Yanitskiya1169202021-05-03 19:00:43 +0200158 set_msg_handler(pmt::mp("bursts"), boost::bind(&bursts_printer_impl::bursts_print, this, boost::placeholders::_1));
piotr6c692872014-02-08 14:16:26 +0100159 }
Martin Jesper Low Madsenaf769642015-04-28 22:33:43 +0200160
piotr6c692872014-02-08 14:16:26 +0100161 /*
162 * Our virtual destructor.
163 */
164 bursts_printer_impl::~bursts_printer_impl()
165 {
166 }
167
168
169 } /* namespace gsm */
170} /* namespace gr */