blob: 1da65e9e0a4d4fefe3f5969b03e7c502e666969d [file] [log] [blame]
piotrab663c82014-08-06 14:14:15 +02001/* -*- c++ -*- */
ptrkrysik529895b2014-12-02 18:07:38 +01002/*
3 * @file
4 * @author Piotr Krysik <ptrkrysik@gmail.com>
5 * @section LICENSE
6 *
7 * Gr-gsm is free software; you can redistribute it and/or modify
piotrab663c82014-08-06 14:14:15 +02008 * 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,
piotrab663c82014-08-06 14:14:15 +020013 * 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 *
piotrab663c82014-08-06 14:14:15 +020017 * 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
piotrab663c82014-08-06 14:14:15 +020019 * 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>
ptrkrysik402c1fa2014-12-03 22:09:29 +010028#include <stdio.h>
piotrab663c82014-08-06 14:14:15 +020029#include "message_printer_impl.h"
ptrkrysik3be74a72014-12-13 10:11:00 +010030#include "grgsm/gsmtap.h"
Roman Khassrafdfe70092015-09-13 10:59:56 +020031extern "C" {
32 #include <osmocom/gsm/a5.h>
33}
piotrab663c82014-08-06 14:14:15 +020034
35namespace gr {
36 namespace gsm {
37
38 void message_printer_impl::message_print(pmt::pmt_t msg)
39 {
ptrkrysik617ba032014-11-21 10:11:05 +010040 pmt::pmt_t message_plus_header_blob = pmt::cdr(msg);
41 uint8_t * message_plus_header = (uint8_t *)pmt::blob_data(message_plus_header_blob);
42 size_t message_plus_header_len=pmt::blob_length(message_plus_header_blob);
ptrkrysik617ba032014-11-21 10:11:05 +010043 gsmtap_hdr * header = (gsmtap_hdr *)message_plus_header;
Roman Khassrafdfe70092015-09-13 10:59:56 +020044 uint32_t frame_nr = be32toh(header->frame_number);
ptrkrysik617ba032014-11-21 10:11:05 +010045
Jacob Gilberte89aee12014-12-13 10:32:21 -080046 std::cout << d_prepend_string;
Roman Khassrafdfe70092015-09-13 10:59:56 +020047 if (d_prepend_fnr)
48 {
49 std::cout << frame_nr;
50 }
51
52 if (d_prepend_fnr && d_prepend_frame_count)
53 {
54 std::cout << " ";
55 }
56
57 if (d_prepend_frame_count)
58 {
59 // calculate fn count using libosmogsm
60 std::cout << osmo_a5_fn_count(frame_nr);
61 }
62
63 if (d_prepend_fnr || d_prepend_frame_count)
64 {
65 std::cout << ": ";
66 }
Roman Khassraf2bf49e42015-07-26 13:47:26 +020067
68 int start_index = sizeof(gsmtap_hdr);
69
70 if (d_print_gsmtap_header)
71 {
72 start_index = 0;
73 }
74
75 for(int ii=start_index; ii<message_plus_header_len; ii++)
piotrab663c82014-08-06 14:14:15 +020076 {
ptrkrysik617ba032014-11-21 10:11:05 +010077 printf(" %02x", message_plus_header[ii]);
piotrab663c82014-08-06 14:14:15 +020078 }
79 std::cout << std::endl;
80 }
81
82 message_printer::sptr
Roman Khassrafdfe70092015-09-13 10:59:56 +020083 message_printer::make(pmt::pmt_t prepend_string, bool prepend_fnr,
84 bool prepend_frame_count, bool print_gsmtap_header)
piotrab663c82014-08-06 14:14:15 +020085 {
86 return gnuradio::get_initial_sptr
Roman Khassrafdfe70092015-09-13 10:59:56 +020087 (new message_printer_impl(prepend_string, prepend_fnr,
88 prepend_frame_count, print_gsmtap_header));
piotrab663c82014-08-06 14:14:15 +020089 }
90
91 /*
92 * The private constructor
93 */
Roman Khassrafdfe70092015-09-13 10:59:56 +020094 message_printer_impl::message_printer_impl(pmt::pmt_t prepend_string, bool prepend_fnr,
95 bool prepend_frame_count, bool print_gsmtap_header)
piotrab663c82014-08-06 14:14:15 +020096 : gr::block("message_printer",
97 gr::io_signature::make(0, 0, 0),
98 gr::io_signature::make(0, 0, 0))
99 {
Jacob Gilberte89aee12014-12-13 10:32:21 -0800100 d_prepend_string = prepend_string;
Roman Khassrafdfe70092015-09-13 10:59:56 +0200101 d_prepend_fnr = prepend_fnr;
102 d_prepend_frame_count = prepend_frame_count;
Roman Khassraf2bf49e42015-07-26 13:47:26 +0200103 d_print_gsmtap_header = print_gsmtap_header;
piotrab663c82014-08-06 14:14:15 +0200104 message_port_register_in(pmt::mp("msgs"));
105 set_msg_handler(pmt::mp("msgs"), boost::bind(&message_printer_impl::message_print, this, _1));
piotrab663c82014-08-06 14:14:15 +0200106 }
107
108 /*
109 * Our virtual destructor.
110 */
111 message_printer_impl::~message_printer_impl()
112 {
113 }
114 } /* namespace gsm */
115} /* namespace gr */
116