blob: c9e461a0faa4c5dfc7619b04c7790a6e86155058 [file] [log] [blame]
ptrkrysik6dded652014-11-19 11:32:05 +01001/* -*- 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
ptrkrysik6dded652014-11-19 11:32:05 +01008 * 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,
ptrkrysik6dded652014-11-19 11:32:05 +010013 * 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 *
ptrkrysik6dded652014-11-19 11:32:05 +010017 * 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
ptrkrysik6dded652014-11-19 11:32:05 +010019 * 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>
28#include "universal_ctrl_chans_demapper_impl.h"
ptrkrysik3be74a72014-12-13 10:11:00 +010029#include <grgsm/endian.h>
30#include <grgsm/gsmtap.h>
ptrkrysik6dded652014-11-19 11:32:05 +010031
32namespace gr {
33 namespace gsm {
34
35 universal_ctrl_chans_demapper::sptr
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010036 universal_ctrl_chans_demapper::make(unsigned int timeslot_nr, const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types)
ptrkrysik6dded652014-11-19 11:32:05 +010037 {
38 return gnuradio::get_initial_sptr
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010039 (new universal_ctrl_chans_demapper_impl(timeslot_nr, starts_fn_mod51, channel_types));
ptrkrysik6dded652014-11-19 11:32:05 +010040 }
41
42 /*
43 * The private constructor
44 */
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010045 universal_ctrl_chans_demapper_impl::universal_ctrl_chans_demapper_impl(unsigned int timeslot_nr, const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types)
ptrkrysik6dded652014-11-19 11:32:05 +010046 : gr::block("universal_ctrl_chans_demapper",
47 gr::io_signature::make(0, 0, 0),
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010048 gr::io_signature::make(0, 0, 0)),
49 d_timeslot(timeslot_nr)
50
ptrkrysik6dded652014-11-19 11:32:05 +010051 {
52
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010053
ptrkrysik6dded652014-11-19 11:32:05 +010054 for(int ii=0; ii<51; ii++)
55 {
56 d_starts_fn_mod51[ii]=0;
57 d_channel_types[ii]=0;
Roman Khassrafe571e962015-04-12 15:35:41 +020058 d_subslots[ii] = 0;
59 d_subslots[ii+51] = 0;
ptrkrysik6dded652014-11-19 11:32:05 +010060 }
61
62 std::vector<int>::const_iterator s;
63 std::vector<int>::const_iterator ch_type;
64
65 for(s=starts_fn_mod51.begin(), ch_type=channel_types.begin();s != starts_fn_mod51.end(); s++)
66 {
Roman Khassraf939edef2015-04-12 15:20:38 +020067 if((*s >= 0) and (*s <= (51-4)))
ptrkrysik6dded652014-11-19 11:32:05 +010068 {
69 for(int ii=0; ii<4; ii++){
70 d_starts_fn_mod51[*s+ii] = *s;
71 if(ch_type!=channel_types.end())
72 {
73 d_channel_types[*s+ii] = *ch_type;
74 }
75 }
76 if(ch_type!=channel_types.end())
77 {
78 ch_type++;
79 }
80 }
81 }
82
Roman Khassrafe571e962015-04-12 15:35:41 +020083 std::set<int> distinct_channels(channel_types.begin(), channel_types.end());
84 std::set<int>::iterator it;
85 unsigned int subslot;
86
87 for (it=distinct_channels.begin(); it != distinct_channels.end(); it++)
88 {
89 subslot = 0;
90 for(s=starts_fn_mod51.begin();s != starts_fn_mod51.end(); s++)
91 {
92 if ((d_channel_types[*s] == *it) and (*s >= 0) and (*s <= (51-4)))
93 {
94 for(int ii=0; ii<4; ii++)
95 {
96 d_subslots[*s+ii] = subslot;
97 d_subslots[*s+ii+51] = subslot;
98 }
99 subslot++;
100 }
101 }
102
103 if (*it == GSMTAP_CHANNEL_ACCH or
104 *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH) or
105 *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH4) or
106 *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH8) or
107 *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_F) or
108 *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_H)
109 )
110 {
111 for(s=starts_fn_mod51.begin();s != starts_fn_mod51.end(); s++)
112 {
113 if ((d_channel_types[*s] == *it) and (*s >= 0) and (*s <= (51-4)))
114 {
115 for(int ii=0; ii<4; ii++)
116 {
117 d_subslots[*s+ii+51] = subslot;
118 }
119 subslot++;
120 }
121 }
122 }
123 }
124
ptrkrysik6dded652014-11-19 11:32:05 +0100125
126 message_port_register_in(pmt::mp("bursts"));
127 set_msg_handler(pmt::mp("bursts"), boost::bind(&universal_ctrl_chans_demapper_impl::filter_ctrl_chans, this, _1));
128 message_port_register_out(pmt::mp("bursts"));
129 }
130
131 /*
132 * Our virtual destructor.
133 */
134 universal_ctrl_chans_demapper_impl::~universal_ctrl_chans_demapper_impl()
135 {
136 }
137
138 void universal_ctrl_chans_demapper_impl::filter_ctrl_chans(pmt::pmt_t msg)
139 {
ptrkrysik617ba032014-11-21 10:11:05 +0100140 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
141 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
ptrkrysik6dded652014-11-19 11:32:05 +0100142
ptrkrysik617ba032014-11-21 10:11:05 +0100143 uint32_t frame_nr = be32toh(header->frame_number);
ptrkrysik6dded652014-11-19 11:32:05 +0100144 uint32_t fn_mod51 = frame_nr % 51;
145 uint32_t fn51_start = d_starts_fn_mod51[fn_mod51];
146 uint32_t fn51_stop = fn51_start + 3;
147 uint32_t ch_type = d_channel_types[fn_mod51];
Roman Khassraf275a0872015-04-12 15:17:47 +0200148
ptrkrysik6dded652014-11-19 11:32:05 +0100149 if(header->timeslot==d_timeslot){
Roman Khassraf275a0872015-04-12 15:17:47 +0200150 header->sub_type = ch_type;
Roman Khassrafe571e962015-04-12 15:35:41 +0200151 header->sub_slot = d_subslots[fn_mod51 + (51 * (frame_nr % 2))];
Roman Khassraf275a0872015-04-12 15:17:47 +0200152
ptrkrysik6dded652014-11-19 11:32:05 +0100153 if(fn_mod51>=fn51_start && fn_mod51<=fn51_stop)
154 {
155 uint32_t ii = fn_mod51 - fn51_start;
156 d_frame_numbers[ii] = frame_nr;
157 d_bursts[ii] = msg;
158 }
159
160 if(fn_mod51==fn51_stop)
161 {
162 //check for a situation where some bursts were lost
163 //in this situation frame numbers won't be consecutive
164 bool frames_are_consecutive = true;
165 for(int jj=1; jj<4; jj++)
166 {
167 if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1)
168 {
169 frames_are_consecutive = false;
170 }
171 }
172 if(frames_are_consecutive)
173 {
174 //send bursts to the output
175 for(int jj=0; jj<4; jj++)
176 {
177 message_port_pub(pmt::mp("bursts"), d_bursts[jj]);
178 }
179 }
180 }
181 }
182 }
183 } /* namespace gsm */
184} /* namespace gr */
185