Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* |
| 3 | * @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 4 | * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com> |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 5 | * @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 | |
iZsh | 6698793 | 2015-08-16 14:42:18 +0200 | [diff] [blame] | 32 | #define BURST_SIZE 148 |
| 33 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 34 | namespace 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 46 | * |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 47 | */ |
| 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 53 | |
| 54 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 55 | // for (int ii=0; ii<3; ii++) |
| 56 | // { |
| 57 | // d_bursts_stolen[ii] = false; |
| 58 | // } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 59 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 60 | 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 72 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 73 | 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 Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 80 | uint32_t fn_mod13 = frame_nr % 13; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 81 | int8_t * burst_bits = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr); |
| 82 | |
| 83 | if(header->timeslot == d_timeslot){ |
iZsh | 6698793 | 2015-08-16 14:42:18 +0200 | [diff] [blame] | 84 | 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 Khassraf | 1591cde | 2016-11-20 21:50:23 +0100 | [diff] [blame] | 90 | new_hdr->sub_type = GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_F; |
iZsh | 6698793 | 2015-08-16 14:42:18 +0200 | [diff] [blame] | 91 | |
| 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 Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 95 | //distinguishing uplink and downlink bursts |
| 96 | bool uplink_burst = (be16toh(header->arfcn) & 0x4000) ? true : false; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 97 | |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 98 | if(uplink_burst) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 99 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 100 | 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 108 | |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 109 | } |
| 110 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 111 | |
Vasil Velichkov | 1828a31 | 2018-05-07 15:55:39 +0300 | [diff] [blame] | 112 | 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 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 124 | |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 125 | 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 Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 147 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 148 | if((d_frame_numbers_sacch[jj]-d_frame_numbers_sacch[jj-1]) != 26) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 149 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 150 | frames_are_consecutive = false; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 151 | } |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 152 | } |
| 153 | if(frames_are_consecutive) |
| 154 | { |
| 155 | //send bursts to the output |
| 156 | for(int jj=0; jj<4; jj++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 157 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 158 | message_port_pub(pmt::mp("acch_bursts"), d_bursts_sacch[jj]); |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 163 | } |
| 164 | else |
| 165 | { |
| 166 | if (fn_mod13 <= 3) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 167 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 168 | // add to b1 and b3 |
| 169 | d_bursts[0][fn_mod13] = msg_out; |
| 170 | d_bursts[2][fn_mod13 + 4] = msg_out; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 171 | |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 172 | // 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 Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 205 | } |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 206 | else if (fn_mod13 == 3) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 207 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 208 | tch_burst_nr = 2; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 211 | //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 Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 216 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 217 | if (((d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj-1]) != 1) && frames_are_consecutive) |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 218 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 219 | 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 Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 223 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 224 | frames_are_consecutive = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 225 | } |
| 226 | } |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 227 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 228 | |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 229 | if(frames_are_consecutive) |
| 230 | { |
| 231 | //send bursts to the output |
| 232 | for(int jj=0; jj<8; jj++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 233 | { |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 234 | message_port_pub(pmt::mp("tch_bursts"), d_bursts[tch_burst_nr][jj]); |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 235 | } |
Your Name | 4e89883 | 2016-07-19 17:21:58 +0430 | [diff] [blame] | 236 | // useless |
| 237 | // d_bursts_stolen[tch_burst_nr] = false; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | } /* namespace gsm */ |
| 243 | } /* namespace gr */ |
| 244 | |