Roman Khassraf | 7cccb52 | 2015-08-04 12:26:54 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 3 | * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com> |
Roman Khassraf | 7cccb52 | 2015-08-04 12:26:54 +0200 | [diff] [blame] | 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 "dummy_burst_filter_impl.h" |
| 29 | #include <stdio.h> |
| 30 | #include <grgsm/endian.h> |
| 31 | #include <grgsm/gsmtap.h> |
| 32 | |
| 33 | |
| 34 | namespace gr { |
| 35 | namespace gsm { |
| 36 | |
| 37 | // dummy burst defined in gsm 05.02, section 5.2.6 |
| 38 | const int8_t dummy_burst_filter_impl::d_dummy_burst[] = {0,0,0, |
| 39 | 1,1,1,1,1,0,1,1,0,1,1,1,0,1,1,0, |
| 40 | 0,0,0,0,1,0,1,0,0,1,0,0,1,1,1,0, |
| 41 | 0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0, |
| 42 | 0,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0, |
| 43 | 0,1,0,1,1,1,0,0,0,1,0,1,1,1,0,0, |
| 44 | 0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0, |
| 45 | 0,0,1,1,0,0,1,1,0,0,1,1,1,0,0,1, |
| 46 | 1,1,1,0,1,0,0,1,1,1,1,1,0,0,0,1, |
| 47 | 0,0,1,0,1,1,1,1,1,0,1,0,1,0, |
| 48 | 0,0,0 }; |
| 49 | |
| 50 | dummy_burst_filter::sptr |
| 51 | dummy_burst_filter::make() |
| 52 | { |
| 53 | return gnuradio::get_initial_sptr |
| 54 | (new dummy_burst_filter_impl()); |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * The private constructor |
| 59 | */ |
| 60 | dummy_burst_filter_impl::dummy_burst_filter_impl() |
| 61 | : gr::block("dummy_burst_filter", |
| 62 | gr::io_signature::make(0, 0, 0), |
Vadim Yanitskiy | 04536ab | 2017-07-21 10:59:51 +0700 | [diff] [blame] | 63 | gr::io_signature::make(0, 0, 0)), |
| 64 | d_filter_policy(FILTER_POLICY_DEFAULT) |
Roman Khassraf | 7cccb52 | 2015-08-04 12:26:54 +0200 | [diff] [blame] | 65 | { |
| 66 | message_port_register_in(pmt::mp("in")); |
| 67 | message_port_register_out(pmt::mp("out")); |
| 68 | |
| 69 | set_msg_handler(pmt::mp("in"), boost::bind(&dummy_burst_filter_impl::process_burst, this, _1)); |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * Our virtual destructor. |
| 74 | */ |
| 75 | dummy_burst_filter_impl::~dummy_burst_filter_impl() {} |
| 76 | |
| 77 | void dummy_burst_filter_impl::process_burst(pmt::pmt_t msg) |
| 78 | { |
Vadim Yanitskiy | 04536ab | 2017-07-21 10:59:51 +0700 | [diff] [blame] | 79 | if (d_filter_policy == FILTER_POLICY_DROP_ALL) |
| 80 | return; |
| 81 | |
| 82 | if (d_filter_policy == FILTER_POLICY_PASS_ALL) { |
| 83 | message_port_pub(pmt::mp("out"), msg); |
| 84 | return; |
| 85 | } |
| 86 | |
Roman Khassraf | 7cccb52 | 2015-08-04 12:26:54 +0200 | [diff] [blame] | 87 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 88 | int8_t * burst = (int8_t *)(pmt::blob_data(header_plus_burst)) + sizeof(gsmtap_hdr); |
| 89 | size_t burst_len = pmt::blob_length(header_plus_burst) - sizeof(gsmtap_hdr); |
| 90 | |
| 91 | if (!is_dummy_burst(burst, burst_len)) |
| 92 | { |
| 93 | message_port_pub(pmt::mp("out"), msg); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | bool dummy_burst_filter_impl::is_dummy_burst(int8_t *burst, size_t burst_len) |
| 98 | { |
| 99 | if (burst_len != DUMMY_BURST_LEN) |
| 100 | { |
| 101 | return false; |
| 102 | } |
| 103 | for (int i=0; i<DUMMY_BURST_LEN; i++) |
| 104 | { |
| 105 | if (burst[i] != d_dummy_burst[i]) |
| 106 | { |
| 107 | return false; |
| 108 | } |
| 109 | } |
| 110 | return true; |
| 111 | } |
Vadim Yanitskiy | 04536ab | 2017-07-21 10:59:51 +0700 | [diff] [blame] | 112 | |
| 113 | /* Filtering policy */ |
| 114 | filter_policy |
| 115 | dummy_burst_filter_impl::get_policy(void) |
| 116 | { |
| 117 | return d_filter_policy; |
| 118 | } |
| 119 | |
| 120 | filter_policy |
| 121 | dummy_burst_filter_impl::set_policy(filter_policy policy) |
| 122 | { |
| 123 | d_filter_policy = policy; |
| 124 | return d_filter_policy; |
| 125 | } |
Roman Khassraf | 7cccb52 | 2015-08-04 12:26:54 +0200 | [diff] [blame] | 126 | |
| 127 | } /* namespace gsm */ |
| 128 | } /* namespace gr */ |