blob: bf1ff8f1f6fa9e759fff9e247a99c689aae5fc97 [file] [log] [blame]
Roman Khassraffb6bc502015-04-14 15:44:40 +02001/* -*- c++ -*- */
2/*
3 * @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004 * @author (C) 2015 by 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 {
Your Name4e898832016-07-19 17:21:58 +043055// for (int ii=0; ii<3; ii++)
56// {
57 // d_bursts_stolen[ii] = false;
58 // }
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;
Roman Khassraffb6bc502015-04-14 15:44:40 +020081 int8_t * burst_bits = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr);
82
83 if(header->timeslot == d_timeslot){
iZsh66987932015-08-16 14:42:18 +020084 int8_t new_msg[sizeof(gsmtap_hdr)+BURST_SIZE];
85 gsmtap_hdr * new_hdr = (gsmtap_hdr*)new_msg;
86 memcpy(new_msg, header, sizeof(gsmtap_hdr)+BURST_SIZE);
87
88 new_hdr->sub_type = GSMTAP_CHANNEL_TCH_F;
89 if (fn_mod13 == 12)
Roman Khassraf1591cde2016-11-20 21:50:23 +010090 new_hdr->sub_type = GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_F;
iZsh66987932015-08-16 14:42:18 +020091
92 pmt::pmt_t msg_binary_blob = pmt::make_blob(new_msg,sizeof(gsmtap_hdr)+BURST_SIZE);
93 pmt::pmt_t msg_out = pmt::cons(pmt::PMT_NIL, msg_binary_blob);
94
Your Name4e898832016-07-19 17:21:58 +043095 //distinguishing uplink and downlink bursts
96 bool uplink_burst = (be16toh(header->arfcn) & 0x4000) ? true : false;
Roman Khassraf650ce782015-05-20 12:48:04 +020097
Your Name4e898832016-07-19 17:21:58 +043098 if(uplink_burst)
Roman Khassraffb6bc502015-04-14 15:44:40 +020099 {
Your Name4e898832016-07-19 17:21:58 +0430100 sacch_tch_demapper(fn_mod13, fn_mod26, frame_nr,d_bursts_sacch_ul,
101 d_frame_numbers_sacch_ul, d_bursts_ul, d_frame_numbers_ul, msg_out);
102 }
103 else
104 {
105 sacch_tch_demapper(fn_mod13, fn_mod26, frame_nr,d_bursts_sacch_dl,
106 d_frame_numbers_sacch_dl, d_bursts_dl, d_frame_numbers_dl, msg_out);
107 }
Roman Khassraf650ce782015-05-20 12:48:04 +0200108
Your Name4e898832016-07-19 17:21:58 +0430109 }
110 }
Roman Khassraf650ce782015-05-20 12:48:04 +0200111
Your Name4e898832016-07-19 17:21:58 +0430112 void tch_f_chans_demapper_impl::sacch_tch_demapper(uint32_t fn_mod13, u_int32_t fn_mod26, uint32_t frame_nr,
113 pmt::pmt_t *d_bursts_sacch,
114 uint32_t *d_frame_numbers_sacch, pmt::pmt_t d_bursts[3][8],
115 uint32_t d_frame_numbers[3][8], pmt::pmt_t msg_out)
116 {
117 bool frames_are_consecutive = true;
118 if (fn_mod13 == 12)
119 {
120 // position of SACCH burst based on timeslot
121 // see specification gsm 05.02
122 uint32_t index;
123 bool is_sacch = false;
Roman Khassraf650ce782015-05-20 12:48:04 +0200124
Your Name4e898832016-07-19 17:21:58 +0430125 if (d_timeslot % 2 == 0 && fn_mod26 == 12)
126 {
127 index = (((frame_nr - 12) / 26) - (d_timeslot / 2)) % 4;
128 is_sacch = true;
129 }
130 else if (d_timeslot % 2 == 1 && fn_mod26 == 25)
131 {
132 index = (((frame_nr - 25) / 26) - ((d_timeslot - 1) / 2)) % 4;
133 is_sacch = true;
134 }
135
136 if (is_sacch)
137 {
138 d_bursts_sacch[index] = msg_out;
139 d_frame_numbers_sacch[index] = frame_nr;
140
141 if (index == 3)
142 {
143 //check for a situation where some bursts were lost
144 //in this situation frame numbers won't be consecutive
145 frames_are_consecutive = true;
146 for(int jj=1; jj<4; jj++)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200147 {
Your Name4e898832016-07-19 17:21:58 +0430148 if((d_frame_numbers_sacch[jj]-d_frame_numbers_sacch[jj-1]) != 26)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200149 {
Your Name4e898832016-07-19 17:21:58 +0430150 frames_are_consecutive = false;
Roman Khassraffb6bc502015-04-14 15:44:40 +0200151 }
Your Name4e898832016-07-19 17:21:58 +0430152 }
153 if(frames_are_consecutive)
154 {
155 //send bursts to the output
156 for(int jj=0; jj<4; jj++)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200157 {
Your Name4e898832016-07-19 17:21:58 +0430158 message_port_pub(pmt::mp("acch_bursts"), d_bursts_sacch[jj]);
Roman Khassraffb6bc502015-04-14 15:44:40 +0200159 }
160 }
161 }
162 }
Your Name4e898832016-07-19 17:21:58 +0430163 }
164 else
165 {
166 if (fn_mod13 <= 3)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200167 {
Your Name4e898832016-07-19 17:21:58 +0430168 // add to b1 and b3
169 d_bursts[0][fn_mod13] = msg_out;
170 d_bursts[2][fn_mod13 + 4] = msg_out;
Roman Khassraf650ce782015-05-20 12:48:04 +0200171
Your Name4e898832016-07-19 17:21:58 +0430172 // set framenumber for later checking of continuity
173 d_frame_numbers[0][fn_mod13] = frame_nr;
174 d_frame_numbers[2][fn_mod13 + 4] = frame_nr;
175 }
176 else if (fn_mod13 >= 4 && fn_mod13 <= 7)
177 {
178 // add to b1 and b2
179 d_bursts[0][fn_mod13] = msg_out;
180 d_bursts[1][fn_mod13 - 4] = msg_out;
181
182 // set framenumber for later checking of continuity
183 d_frame_numbers[0][fn_mod13] = frame_nr;
184 d_frame_numbers[1][fn_mod13 - 4] = frame_nr;
185 }
186 else if (fn_mod13 >= 8 && fn_mod13 <= 11)
187 {
188 // add to b2 and b3
189 d_bursts[1][fn_mod13 - 4] = msg_out;
190 d_bursts[2][fn_mod13 - 8] = msg_out;
191
192 // set framenumber for later checking of continuity
193 d_frame_numbers[1][fn_mod13 - 4] = frame_nr;
194 d_frame_numbers[2][fn_mod13 - 8] = frame_nr;
195 }
196
197 // send burst 1 or burst 2 to output
198 if (fn_mod13 == 3 || fn_mod13 == 7 || fn_mod13 == 11)
199 {
200 int tch_burst_nr = 0;
201
202 if (fn_mod13 == 11)
203 {
204 tch_burst_nr = 1;
Roman Khassraffb6bc502015-04-14 15:44:40 +0200205 }
Your Name4e898832016-07-19 17:21:58 +0430206 else if (fn_mod13 == 3)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200207 {
Your Name4e898832016-07-19 17:21:58 +0430208 tch_burst_nr = 2;
Roman Khassraf155a7442015-05-08 19:52:01 +0200209 }
210
Your Name4e898832016-07-19 17:21:58 +0430211 //check for a situation where some bursts were lost
212 //in this situation frame numbers won't be consecutive
213 frames_are_consecutive = true;
214
215 for(int jj=1; jj<8; jj++)
Roman Khassraf155a7442015-05-08 19:52:01 +0200216 {
Your Name4e898832016-07-19 17:21:58 +0430217 if (((d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj-1]) != 1) && frames_are_consecutive)
Roman Khassraf155a7442015-05-08 19:52:01 +0200218 {
Your Name4e898832016-07-19 17:21:58 +0430219 frames_are_consecutive = false;
220 // burst 3 has 1 sacch burst in between
221 if (tch_burst_nr == 2 && jj == 4
222 && d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj - 1] == 2)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200223 {
Your Name4e898832016-07-19 17:21:58 +0430224 frames_are_consecutive = true;
Roman Khassraffb6bc502015-04-14 15:44:40 +0200225 }
226 }
Your Name4e898832016-07-19 17:21:58 +0430227 }
Roman Khassraf650ce782015-05-20 12:48:04 +0200228
Your Name4e898832016-07-19 17:21:58 +0430229 if(frames_are_consecutive)
230 {
231 //send bursts to the output
232 for(int jj=0; jj<8; jj++)
Roman Khassraffb6bc502015-04-14 15:44:40 +0200233 {
Your Name4e898832016-07-19 17:21:58 +0430234 message_port_pub(pmt::mp("tch_bursts"), d_bursts[tch_burst_nr][jj]);
Roman Khassraf155a7442015-05-08 19:52:01 +0200235 }
Your Name4e898832016-07-19 17:21:58 +0430236 // useless
237// d_bursts_stolen[tch_burst_nr] = false;
Roman Khassraffb6bc502015-04-14 15:44:40 +0200238 }
239 }
240 }
241 }
242 } /* namespace gsm */
243} /* namespace gr */
244