blob: 9f27fcde70f7155e8980b352ee6a221e8d4f83c3 [file] [log] [blame]
Roman Khassraf8b64d872015-08-06 17:30:04 +02001/* -*- c++ -*- */
2/* @file
3 * @author Roman Khassraf <rkhassraf@gmail.com>
4 * @section LICENSE
5 *
6 * Gr-gsm is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * Gr-gsm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with gr-gsm; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
28#include "burst_sdcch_subslot_filter_impl.h"
29#include <stdio.h>
30#include <grgsm/endian.h>
31#include <grgsm/gsmtap.h>
32
33
34namespace gr {
35 namespace gsm {
36
37 burst_sdcch_subslot_filter::sptr
38 burst_sdcch_subslot_filter::make(subslot_filter_mode mode, unsigned int subslot)
39 {
40 return gnuradio::get_initial_sptr
41 (new burst_sdcch_subslot_filter_impl(mode, subslot));
42 }
43
44 /*
45 * The private constructor
46 */
47 burst_sdcch_subslot_filter_impl::burst_sdcch_subslot_filter_impl(subslot_filter_mode mode, unsigned int subslot)
48 : gr::block("burst_sdcch_subslot_filter",
49 gr::io_signature::make(0, 0, 0),
50 gr::io_signature::make(0, 0, 0)),
51 d_mode(mode),
52 d_subslot(subslot)
53 {
54 message_port_register_in(pmt::mp("in"));
55 message_port_register_out(pmt::mp("out"));
56
57 set_msg_handler(pmt::mp("in"), boost::bind(&burst_sdcch_subslot_filter_impl::process_burst, this, _1));
58 }
59
60 /*
61 * Our virtual destructor.
62 */
63 burst_sdcch_subslot_filter_impl::~burst_sdcch_subslot_filter_impl() {}
64
65 void burst_sdcch_subslot_filter_impl::process_burst(pmt::pmt_t msg)
66 {
67 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
68 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
69
70 uint32_t frame_nr = be32toh(header->frame_number);
71 uint32_t fn_mod102 = frame_nr % 102;
72
73 int8_t subslot;
74
75 if (d_mode == SS_FILTER_SDCCH8)
76 {
77 subslot = d_subslots_sdcch8[fn_mod102];
78 }
79 else if (d_mode == SS_FILTER_SDCCH4)
80 {
81 subslot = d_subslots_sdcch4[fn_mod102];
82 }
83
84 if ((subslot == -1) || (d_mode == SS_FILTER_SDCCH4 && subslot > 3))
85 {
86 return;
87 }
88
89 if (subslot == d_subslot)
90 {
91 message_port_pub(pmt::mp("out"), msg);
92 }
93 }
94 } /* namespace gsm */
95} /* namespace gr */