piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 2 | /* |
| 3 | * @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 4 | * @author (C) 2014 by Piotr Krysik <ptrkrysik@gmail.com> |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 5 | * @section LICENSE |
| 6 | * |
| 7 | * Gr-gsm is free software; you can redistribute it and/or modify |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 8 | * 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. |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 11 | * |
| 12 | * Gr-gsm is distributed in the hope that it will be useful, |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 13 | * 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. |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 16 | * |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 18 | * along with gr-gsm; see the file COPYING. If not, write to |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 19 | * 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> |
ptrkrysik | 3be74a7 | 2014-12-13 10:11:00 +0100 | [diff] [blame] | 28 | #include <grgsm/gsmtap.h> |
Martin Jesper Low Madsen | af76964 | 2015-04-28 22:33:43 +0200 | [diff] [blame] | 29 | #include <grgsm/endian.h> |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 30 | #include <iterator> |
| 31 | #include <algorithm> |
piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 32 | #include "bursts_printer_impl.h" |
piotr | c00ce9c | 2014-08-04 11:21:24 +0200 | [diff] [blame] | 33 | #include <unistd.h> |
piotr | c00ce9c | 2014-08-04 11:21:24 +0200 | [diff] [blame] | 34 | #include <iostream> |
Roman Khassraf | 9a54c7b | 2015-09-13 11:04:42 +0200 | [diff] [blame] | 35 | extern "C" { |
| 36 | #include <osmocom/gsm/a5.h> |
| 37 | } |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 38 | |
| 39 | namespace gr { |
| 40 | namespace gsm { |
piotr | c00ce9c | 2014-08-04 11:21:24 +0200 | [diff] [blame] | 41 | boost::mutex printer_mutex; |
Roman Khassraf | 7faabf3 | 2015-07-24 14:14:16 +0200 | [diff] [blame] | 42 | // 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 | |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 55 | void bursts_printer_impl::bursts_print(pmt::pmt_t msg) |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 56 | { |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 57 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 58 | |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 59 | 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 Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 62 | uint32_t frame_nr = be32toh(header->frame_number); |
Martin Jesper Low Madsen | af76964 | 2015-04-28 22:33:43 +0200 | [diff] [blame] | 63 | |
Roman Khassraf | 7faabf3 | 2015-07-24 14:14:16 +0200 | [diff] [blame] | 64 | if (d_ignore_dummy_bursts && is_dummy_burst(burst, burst_len)) |
| 65 | { |
| 66 | return; |
| 67 | } |
| 68 | |
Jacob Gilbert | 607a09e | 2014-12-13 10:41:20 -0800 | [diff] [blame] | 69 | std::cout << d_prepend_string; |
Martin Jesper Low Madsen | af76964 | 2015-04-28 22:33:43 +0200 | [diff] [blame] | 70 | if (d_prepend_fnr) |
Roman Khassraf | 717b57b | 2015-04-12 18:09:45 +0200 | [diff] [blame] | 71 | { |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 72 | std::cout << frame_nr; |
Martin Jesper Low Madsen | af76964 | 2015-04-28 22:33:43 +0200 | [diff] [blame] | 73 | } |
Roman Khassraf | 717b57b | 2015-04-12 18:09:45 +0200 | [diff] [blame] | 74 | |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 75 | if (d_prepend_fnr && d_prepend_frame_count) |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 76 | { |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 77 | std::cout << " "; |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 78 | } |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 79 | |
| 80 | if (d_prepend_frame_count) |
| 81 | { |
Roman Khassraf | 9a54c7b | 2015-09-13 11:04:42 +0200 | [diff] [blame] | 82 | // calculate fn count using libosmogsm |
| 83 | std::cout << osmo_a5_fn_count(frame_nr); |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | if (d_prepend_fnr || d_prepend_frame_count) |
| 87 | { |
Roman Khassraf | f1111eb | 2015-07-13 13:58:25 +0200 | [diff] [blame] | 88 | std::cout << ": "; |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | if (d_print_payload_only) |
| 92 | { |
| 93 | for (int ii=0; ii<57; ii++) |
| 94 | { |
| 95 | std::cout << std::setprecision(1) << static_cast<int>(burst[ii + 3]); |
| 96 | } |
| 97 | for (int ii=0; ii<57; ii++) |
| 98 | { |
| 99 | std::cout << std::setprecision(1) << static_cast<int>(burst[ii + 88]); |
| 100 | } |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | for(int ii=0; ii<burst_len; ii++) |
| 105 | { |
| 106 | std::cout << std::setprecision(1) << static_cast<int>(burst[ii]); |
| 107 | } |
| 108 | } |
| 109 | |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 110 | std::cout << std::endl; |
| 111 | } |
Martin Jesper Low Madsen | af76964 | 2015-04-28 22:33:43 +0200 | [diff] [blame] | 112 | |
Roman Khassraf | 7faabf3 | 2015-07-24 14:14:16 +0200 | [diff] [blame] | 113 | bool bursts_printer_impl::is_dummy_burst(int8_t *burst, size_t burst_len) |
| 114 | { |
| 115 | if (burst_len != DUMMY_BURST_LEN) |
| 116 | { |
| 117 | return false; |
| 118 | } |
| 119 | for (int i=0; i<DUMMY_BURST_LEN; i++) |
| 120 | { |
| 121 | if (burst[i] != d_dummy_burst[i]) |
| 122 | { |
| 123 | return false; |
| 124 | } |
| 125 | } |
| 126 | return true; |
| 127 | } |
| 128 | |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 129 | bursts_printer::sptr |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 130 | bursts_printer::make(pmt::pmt_t prepend_string, bool prepend_fnr, |
Roman Khassraf | 7faabf3 | 2015-07-24 14:14:16 +0200 | [diff] [blame] | 131 | bool prepend_frame_count, bool print_payload_only, |
| 132 | bool ignore_dummy_bursts) |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 133 | { |
| 134 | return gnuradio::get_initial_sptr |
Roman Khassraf | 7faabf3 | 2015-07-24 14:14:16 +0200 | [diff] [blame] | 135 | (new bursts_printer_impl(prepend_string, prepend_fnr, prepend_frame_count, |
| 136 | print_payload_only, ignore_dummy_bursts)); |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* |
| 140 | * The private constructor |
| 141 | */ |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 142 | bursts_printer_impl::bursts_printer_impl(pmt::pmt_t prepend_string, bool prepend_fnr, |
Roman Khassraf | 7faabf3 | 2015-07-24 14:14:16 +0200 | [diff] [blame] | 143 | bool prepend_frame_count, bool print_payload_only, |
| 144 | bool ignore_dummy_bursts) |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 145 | : gr::block("bursts_printer", |
| 146 | gr::io_signature::make(0, 0, 0), |
| 147 | gr::io_signature::make(0, 0, 0)) |
| 148 | { |
Jacob Gilbert | 607a09e | 2014-12-13 10:41:20 -0800 | [diff] [blame] | 149 | d_prepend_string = prepend_string; |
Roman Khassraf | 717b57b | 2015-04-12 18:09:45 +0200 | [diff] [blame] | 150 | d_prepend_fnr = prepend_fnr; |
Roman Khassraf | 6344496 | 2015-07-13 13:42:57 +0200 | [diff] [blame] | 151 | d_prepend_frame_count = prepend_frame_count; |
| 152 | d_print_payload_only = print_payload_only; |
Roman Khassraf | 7faabf3 | 2015-07-24 14:14:16 +0200 | [diff] [blame] | 153 | d_ignore_dummy_bursts = ignore_dummy_bursts; |
| 154 | |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 155 | message_port_register_in(pmt::mp("bursts")); |
| 156 | set_msg_handler(pmt::mp("bursts"), boost::bind(&bursts_printer_impl::bursts_print, this, _1)); |
| 157 | } |
Martin Jesper Low Madsen | af76964 | 2015-04-28 22:33:43 +0200 | [diff] [blame] | 158 | |
piotr | 6c69287 | 2014-02-08 14:16:26 +0100 | [diff] [blame] | 159 | /* |
| 160 | * Our virtual destructor. |
| 161 | */ |
| 162 | bursts_printer_impl::~bursts_printer_impl() |
| 163 | { |
| 164 | } |
| 165 | |
| 166 | |
| 167 | } /* namespace gsm */ |
| 168 | } /* namespace gr */ |