blob: a54ed3fd508cff363e883d0449e9377a0f01f50a [file] [log] [blame]
Roman Khassraffb6bc502015-04-14 15:44:40 +02001/* -*- c++ -*- */
2/*
3 * @file
Roman Khassraf05bfb822015-05-22 11:46:00 +02004 * @author Roman Khassraf <rkhassraf@gmail.com>
Roman Khassraffb6bc502015-04-14 15:44:40 +02005 * @section LICENSE
6 *
7 * Gr-gsm is free software; you can redistribute it and/or modify
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.
11 *
12 * Gr-gsm is distributed in the hope that it will be useful,
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with gr-gsm; see the file COPYING. If not, write to
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>
28#include "tch_f_chans_demapper_impl.h"
29#include <grgsm/endian.h>
30#include <grgsm/gsmtap.h>
31
iZsh66987932015-08-16 14:42:18 +020032#define BURST_SIZE 148
33
Roman Khassraffb6bc502015-04-14 15:44:40 +020034namespace gr {
35 namespace gsm {
36
37 tch_f_chans_demapper::sptr
38 tch_f_chans_demapper::make(unsigned int timeslot_nr)
39 {
40 return gnuradio::get_initial_sptr
41 (new tch_f_chans_demapper_impl(timeslot_nr));
42 }
43
44 /*
45 * The private constructor
Roman Khassraf650ce782015-05-20 12:48:04 +020046 *
Roman Khassraffb6bc502015-04-14 15:44:40 +020047 */
48 tch_f_chans_demapper_impl::tch_f_chans_demapper_impl(unsigned int timeslot_nr)
49 : gr::block("tch_f_chans_demapper",
50 gr::io_signature::make(0, 0, 0),
51 gr::io_signature::make(0, 0, 0)),
52 d_timeslot(timeslot_nr)
Roman Khassraf650ce782015-05-20 12:48:04 +020053
54 {
55 for (int ii=0; ii<3; ii++)
Roman Khassraffb6bc502015-04-14 15:44:40 +020056 {
Roman Khassraf155a7442015-05-08 19:52:01 +020057 d_bursts_stolen[ii] = false;
Roman Khassraffb6bc502015-04-14 15:44:40 +020058 }
Roman Khassraf650ce782015-05-20 12:48:04 +020059
Roman Khassraffb6bc502015-04-14 15:44:40 +020060 message_port_register_in(pmt::mp("bursts"));
61 set_msg_handler(pmt::mp("bursts"), boost::bind(&tch_f_chans_demapper_impl::filter_tch_chans, this, _1));
62 message_port_register_out(pmt::mp("tch_bursts"));
63 message_port_register_out(pmt::mp("acch_bursts"));
64 }
65
66 /*
67 * Our virtual destructor.
68 */
69 tch_f_chans_demapper_impl::~tch_f_chans_demapper_impl()
70 {
71 }
Roman Khassraf650ce782015-05-20 12:48:04 +020072
Roman Khassraffb6bc502015-04-14 15:44:40 +020073 void tch_f_chans_demapper_impl::filter_tch_chans(pmt::pmt_t msg)
74 {
75 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
76 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
77
78 uint32_t frame_nr = be32toh(header->frame_number);
79 uint32_t fn_mod26 = frame_nr % 26;
Roman Khassraf155a7442015-05-08 19:52:01 +020080 uint32_t fn_mod13 = frame_nr % 13;
81 bool frames_are_consecutive = true;
Roman Khassraffb6bc502015-04-14 15:44:40 +020082 int8_t * burst_bits = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
83
84 if(header->timeslot == d_timeslot){
iZsh66987932015-08-16 14:42:18 +020085 int8_t new_msg[sizeof(gsmtap_hdr)+BURST_SIZE];
86 gsmtap_hdr * new_hdr = (gsmtap_hdr*)new_msg;
87 memcpy(new_msg, header, sizeof(gsmtap_hdr)+BURST_SIZE);
88
89 new_hdr->sub_type = GSMTAP_CHANNEL_TCH_F;
90 if (fn_mod13 == 12)
91 header->sub_type = GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_F;
92
93 pmt::pmt_t msg_binary_blob = pmt::make_blob(new_msg,sizeof(gsmtap_hdr)+BURST_SIZE);
94 pmt::pmt_t msg_out = pmt::cons(pmt::PMT_NIL, msg_binary_blob);
95
Roman Khassraf650ce782015-05-20 12:48:04 +020096
Roman Khassraf155a7442015-05-08 19:52:01 +020097 if (fn_mod13 == 12)
Roman Khassraffb6bc502015-04-14 15:44:40 +020098 {
Roman Khassraffb6bc502015-04-14 15:44:40 +020099 // position of SACCH burst based on timeslot
100 // see specification gsm 05.02
101 uint32_t index;
102 bool is_sacch = false;
Roman Khassraf650ce782015-05-20 12:48:04 +0200103
Roman Khassraffb6bc502015-04-14 15:44:40 +0200104 if (d_timeslot % 2 == 0 && fn_mod26 == 12)
105 {
106 index = (((frame_nr - 12) / 26) - (d_timeslot / 2)) % 4;
107 is_sacch = true;
108 }
Roman Khassraf650ce782015-05-20 12:48:04 +0200109 else if (d_timeslot % 2 == 1 && fn_mod26 == 25)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200110 {
111 index = (((frame_nr - 25) / 26) - ((d_timeslot - 1) / 2)) % 4;
112 is_sacch = true;
113 }
Roman Khassraf650ce782015-05-20 12:48:04 +0200114
Roman Khassraffb6bc502015-04-14 15:44:40 +0200115 if (is_sacch)
116 {
iZsh66987932015-08-16 14:42:18 +0200117 d_bursts_sacch[index] = msg_out;
Roman Khassraffb6bc502015-04-14 15:44:40 +0200118 d_frame_numbers_sacch[index] = frame_nr;
Roman Khassraf650ce782015-05-20 12:48:04 +0200119
120 if (index == 3)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200121 {
122 //check for a situation where some bursts were lost
123 //in this situation frame numbers won't be consecutive
Roman Khassraf155a7442015-05-08 19:52:01 +0200124 frames_are_consecutive = true;
Roman Khassraffb6bc502015-04-14 15:44:40 +0200125 for(int jj=1; jj<4; jj++)
126 {
127 if((d_frame_numbers_sacch[jj]-d_frame_numbers_sacch[jj-1]) != 26)
128 {
129 frames_are_consecutive = false;
130 }
131 }
132 if(frames_are_consecutive)
133 {
134 //send bursts to the output
135 for(int jj=0; jj<4; jj++)
136 {
137 message_port_pub(pmt::mp("acch_bursts"), d_bursts_sacch[jj]);
138 }
139 }
140 }
141 }
142 }
143 else
144 {
Roman Khassraf650ce782015-05-20 12:48:04 +0200145 if (fn_mod13 <= 3)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200146 {
Roman Khassraf155a7442015-05-08 19:52:01 +0200147 // add to b1 and b3
iZsh66987932015-08-16 14:42:18 +0200148 d_bursts[0][fn_mod13] = msg_out;
149 d_bursts[2][fn_mod13 + 4] = msg_out;
Roman Khassraf650ce782015-05-20 12:48:04 +0200150
Roman Khassraf155a7442015-05-08 19:52:01 +0200151 // set framenumber
152 d_frame_numbers[0][fn_mod13] = frame_nr;
153 d_frame_numbers[2][fn_mod13 + 4] = frame_nr;
Roman Khassraffb6bc502015-04-14 15:44:40 +0200154 }
Roman Khassraf155a7442015-05-08 19:52:01 +0200155 else if (fn_mod13 >= 4 && fn_mod13 <= 7)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200156 {
Roman Khassraf155a7442015-05-08 19:52:01 +0200157 // add to b1 and b2
iZsh66987932015-08-16 14:42:18 +0200158 d_bursts[0][fn_mod13] = msg_out;
159 d_bursts[1][fn_mod13 - 4] = msg_out;
Roman Khassraf650ce782015-05-20 12:48:04 +0200160
Roman Khassraf155a7442015-05-08 19:52:01 +0200161 // set framenumber
162 d_frame_numbers[0][fn_mod13] = frame_nr;
163 d_frame_numbers[1][fn_mod13 - 4] = frame_nr;
Roman Khassraf155a7442015-05-08 19:52:01 +0200164 }
165 else if (fn_mod13 >= 8 && fn_mod13 <= 11)
166 {
167 // add to b2 and b3
iZsh66987932015-08-16 14:42:18 +0200168 d_bursts[1][fn_mod13 - 4] = msg_out;
169 d_bursts[2][fn_mod13 - 8] = msg_out;
Roman Khassraf650ce782015-05-20 12:48:04 +0200170
Roman Khassraf155a7442015-05-08 19:52:01 +0200171 // set framenumber
172 d_frame_numbers[1][fn_mod13 - 4] = frame_nr;
173 d_frame_numbers[2][fn_mod13 - 8] = frame_nr;
Roman Khassraf155a7442015-05-08 19:52:01 +0200174 }
175
176 // send burst 1 or burst 2 to output
177 if (fn_mod13 == 3 || fn_mod13 == 7 || fn_mod13 == 11)
178 {
179 int tch_burst_nr = 0;
Roman Khassraf650ce782015-05-20 12:48:04 +0200180
181 if (fn_mod13 == 11)
Roman Khassraf155a7442015-05-08 19:52:01 +0200182 {
183 tch_burst_nr = 1;
184 }
185 else if (fn_mod13 == 3)
186 {
187 tch_burst_nr = 2;
188 }
189
Roman Khassraffb6bc502015-04-14 15:44:40 +0200190 //check for a situation where some bursts were lost
191 //in this situation frame numbers won't be consecutive
Roman Khassraf155a7442015-05-08 19:52:01 +0200192 frames_are_consecutive = true;
Roman Khassraf650ce782015-05-20 12:48:04 +0200193
Roman Khassraf155a7442015-05-08 19:52:01 +0200194 for(int jj=1; jj<8; jj++)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200195 {
Roman Khassraf4de8e4a2015-05-22 10:02:20 +0200196 if (((d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj-1]) != 1) && frames_are_consecutive)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200197 {
198 frames_are_consecutive = false;
Roman Khassraf155a7442015-05-08 19:52:01 +0200199 // burst 3 has 1 sacch burst in between
Roman Khassraf650ce782015-05-20 12:48:04 +0200200 if (tch_burst_nr == 2 && jj == 4
201 && d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj - 1] == 2)
Roman Khassraf155a7442015-05-08 19:52:01 +0200202 {
203 frames_are_consecutive = true;
204 }
Roman Khassraffb6bc502015-04-14 15:44:40 +0200205 }
206 }
Roman Khassraf650ce782015-05-20 12:48:04 +0200207
Roman Khassraffb6bc502015-04-14 15:44:40 +0200208 if(frames_are_consecutive)
209 {
210 //send bursts to the output
Roman Khassraf155a7442015-05-08 19:52:01 +0200211 for(int jj=0; jj<8; jj++)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200212 {
Roman Khassraf650ce782015-05-20 12:48:04 +0200213 message_port_pub(pmt::mp("tch_bursts"), d_bursts[tch_burst_nr][jj]);
Roman Khassraffb6bc502015-04-14 15:44:40 +0200214 }
Roman Khassraf155a7442015-05-08 19:52:01 +0200215 d_bursts_stolen[tch_burst_nr] = false;
216 }
Roman Khassraffb6bc502015-04-14 15:44:40 +0200217 }
218 }
219 }
220 }
221 } /* namespace gsm */
222} /* namespace gr */
223