piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [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 | ab663c8 | 2014-08-06 14:14:15 +0200 | [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 | ab663c8 | 2014-08-06 14:14:15 +0200 | [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 | ab663c8 | 2014-08-06 14:14:15 +0200 | [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 | ab663c8 | 2014-08-06 14:14:15 +0200 | [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 | 402c1fa | 2014-12-03 22:09:29 +0100 | [diff] [blame] | 28 | #include <stdio.h> |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 29 | #include "message_printer_impl.h" |
ptrkrysik | 3be74a7 | 2014-12-13 10:11:00 +0100 | [diff] [blame] | 30 | #include "grgsm/gsmtap.h" |
Piotr Krysik | 29bcd39 | 2015-09-20 13:15:51 +0200 | [diff] [blame] | 31 | #include <grgsm/endian.h> |
| 32 | |
| 33 | |
Roman Khassraf | dfe7009 | 2015-09-13 10:59:56 +0200 | [diff] [blame] | 34 | extern "C" { |
| 35 | #include <osmocom/gsm/a5.h> |
| 36 | } |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 37 | |
| 38 | namespace gr { |
| 39 | namespace gsm { |
| 40 | |
| 41 | void message_printer_impl::message_print(pmt::pmt_t msg) |
| 42 | { |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 43 | pmt::pmt_t message_plus_header_blob = pmt::cdr(msg); |
| 44 | uint8_t * message_plus_header = (uint8_t *)pmt::blob_data(message_plus_header_blob); |
| 45 | size_t message_plus_header_len=pmt::blob_length(message_plus_header_blob); |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 46 | gsmtap_hdr * header = (gsmtap_hdr *)message_plus_header; |
Roman Khassraf | dfe7009 | 2015-09-13 10:59:56 +0200 | [diff] [blame] | 47 | uint32_t frame_nr = be32toh(header->frame_number); |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 48 | |
Jacob Gilbert | e89aee1 | 2014-12-13 10:32:21 -0800 | [diff] [blame] | 49 | std::cout << d_prepend_string; |
Roman Khassraf | dfe7009 | 2015-09-13 10:59:56 +0200 | [diff] [blame] | 50 | if (d_prepend_fnr) |
| 51 | { |
| 52 | std::cout << frame_nr; |
| 53 | } |
| 54 | |
| 55 | if (d_prepend_fnr && d_prepend_frame_count) |
| 56 | { |
| 57 | std::cout << " "; |
| 58 | } |
| 59 | |
| 60 | if (d_prepend_frame_count) |
| 61 | { |
| 62 | // calculate fn count using libosmogsm |
| 63 | std::cout << osmo_a5_fn_count(frame_nr); |
| 64 | } |
| 65 | |
| 66 | if (d_prepend_fnr || d_prepend_frame_count) |
| 67 | { |
| 68 | std::cout << ": "; |
| 69 | } |
Roman Khassraf | 2bf49e4 | 2015-07-26 13:47:26 +0200 | [diff] [blame] | 70 | |
| 71 | int start_index = sizeof(gsmtap_hdr); |
| 72 | |
| 73 | if (d_print_gsmtap_header) |
| 74 | { |
| 75 | start_index = 0; |
| 76 | } |
| 77 | |
| 78 | for(int ii=start_index; ii<message_plus_header_len; ii++) |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 79 | { |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 80 | printf(" %02x", message_plus_header[ii]); |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 81 | } |
| 82 | std::cout << std::endl; |
| 83 | } |
| 84 | |
| 85 | message_printer::sptr |
Roman Khassraf | dfe7009 | 2015-09-13 10:59:56 +0200 | [diff] [blame] | 86 | message_printer::make(pmt::pmt_t prepend_string, bool prepend_fnr, |
| 87 | bool prepend_frame_count, bool print_gsmtap_header) |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 88 | { |
| 89 | return gnuradio::get_initial_sptr |
Roman Khassraf | dfe7009 | 2015-09-13 10:59:56 +0200 | [diff] [blame] | 90 | (new message_printer_impl(prepend_string, prepend_fnr, |
| 91 | prepend_frame_count, print_gsmtap_header)); |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* |
| 95 | * The private constructor |
| 96 | */ |
Roman Khassraf | dfe7009 | 2015-09-13 10:59:56 +0200 | [diff] [blame] | 97 | message_printer_impl::message_printer_impl(pmt::pmt_t prepend_string, bool prepend_fnr, |
| 98 | bool prepend_frame_count, bool print_gsmtap_header) |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 99 | : gr::block("message_printer", |
| 100 | gr::io_signature::make(0, 0, 0), |
| 101 | gr::io_signature::make(0, 0, 0)) |
| 102 | { |
Jacob Gilbert | e89aee1 | 2014-12-13 10:32:21 -0800 | [diff] [blame] | 103 | d_prepend_string = prepend_string; |
Roman Khassraf | dfe7009 | 2015-09-13 10:59:56 +0200 | [diff] [blame] | 104 | d_prepend_fnr = prepend_fnr; |
| 105 | d_prepend_frame_count = prepend_frame_count; |
Roman Khassraf | 2bf49e4 | 2015-07-26 13:47:26 +0200 | [diff] [blame] | 106 | d_print_gsmtap_header = print_gsmtap_header; |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 107 | message_port_register_in(pmt::mp("msgs")); |
| 108 | set_msg_handler(pmt::mp("msgs"), boost::bind(&message_printer_impl::message_print, this, _1)); |
piotr | ab663c8 | 2014-08-06 14:14:15 +0200 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
| 112 | * Our virtual destructor. |
| 113 | */ |
| 114 | message_printer_impl::~message_printer_impl() |
| 115 | { |
| 116 | } |
| 117 | } /* namespace gsm */ |
| 118 | } /* namespace gr */ |
| 119 | |