Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* |
| 3 | * @file |
Roman Khassraf | 05bfb82 | 2015-05-22 11:46:00 +0200 | [diff] [blame] | 4 | * @author 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 | |
| 32 | namespace gr { |
| 33 | namespace gsm { |
| 34 | |
| 35 | tch_f_chans_demapper::sptr |
| 36 | tch_f_chans_demapper::make(unsigned int timeslot_nr) |
| 37 | { |
| 38 | return gnuradio::get_initial_sptr |
| 39 | (new tch_f_chans_demapper_impl(timeslot_nr)); |
| 40 | } |
| 41 | |
| 42 | /* |
| 43 | * The private constructor |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 44 | * |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 45 | */ |
| 46 | tch_f_chans_demapper_impl::tch_f_chans_demapper_impl(unsigned int timeslot_nr) |
| 47 | : gr::block("tch_f_chans_demapper", |
| 48 | gr::io_signature::make(0, 0, 0), |
| 49 | gr::io_signature::make(0, 0, 0)), |
| 50 | d_timeslot(timeslot_nr) |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 51 | |
| 52 | { |
| 53 | for (int ii=0; ii<3; ii++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 54 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 55 | d_bursts_stolen[ii] = false; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 56 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 57 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 58 | message_port_register_in(pmt::mp("bursts")); |
| 59 | set_msg_handler(pmt::mp("bursts"), boost::bind(&tch_f_chans_demapper_impl::filter_tch_chans, this, _1)); |
| 60 | message_port_register_out(pmt::mp("tch_bursts")); |
| 61 | message_port_register_out(pmt::mp("acch_bursts")); |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Our virtual destructor. |
| 66 | */ |
| 67 | tch_f_chans_demapper_impl::~tch_f_chans_demapper_impl() |
| 68 | { |
| 69 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 70 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 71 | void tch_f_chans_demapper_impl::filter_tch_chans(pmt::pmt_t msg) |
| 72 | { |
| 73 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 74 | gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
| 75 | |
| 76 | uint32_t frame_nr = be32toh(header->frame_number); |
| 77 | uint32_t fn_mod26 = frame_nr % 26; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 78 | uint32_t fn_mod13 = frame_nr % 13; |
| 79 | bool frames_are_consecutive = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 80 | int8_t * burst_bits = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr); |
| 81 | |
| 82 | if(header->timeslot == d_timeslot){ |
| 83 | header->sub_type = GSMTAP_CHANNEL_TCH_F; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 84 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 85 | if (fn_mod13 == 12) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 86 | { |
| 87 | header->sub_type = GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_F; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 88 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 89 | // position of SACCH burst based on timeslot |
| 90 | // see specification gsm 05.02 |
| 91 | uint32_t index; |
| 92 | bool is_sacch = false; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 93 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 94 | if (d_timeslot % 2 == 0 && fn_mod26 == 12) |
| 95 | { |
| 96 | index = (((frame_nr - 12) / 26) - (d_timeslot / 2)) % 4; |
| 97 | is_sacch = true; |
| 98 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 99 | else if (d_timeslot % 2 == 1 && fn_mod26 == 25) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 100 | { |
| 101 | index = (((frame_nr - 25) / 26) - ((d_timeslot - 1) / 2)) % 4; |
| 102 | is_sacch = true; |
| 103 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 104 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 105 | if (is_sacch) |
| 106 | { |
| 107 | d_bursts_sacch[index] = msg; |
| 108 | d_frame_numbers_sacch[index] = frame_nr; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 109 | |
| 110 | if (index == 3) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 111 | { |
| 112 | //check for a situation where some bursts were lost |
| 113 | //in this situation frame numbers won't be consecutive |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 114 | frames_are_consecutive = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 115 | for(int jj=1; jj<4; jj++) |
| 116 | { |
| 117 | if((d_frame_numbers_sacch[jj]-d_frame_numbers_sacch[jj-1]) != 26) |
| 118 | { |
| 119 | frames_are_consecutive = false; |
| 120 | } |
| 121 | } |
| 122 | if(frames_are_consecutive) |
| 123 | { |
| 124 | //send bursts to the output |
| 125 | for(int jj=0; jj<4; jj++) |
| 126 | { |
| 127 | message_port_pub(pmt::mp("acch_bursts"), d_bursts_sacch[jj]); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | else |
| 134 | { |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 135 | if (fn_mod13 <= 3) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 136 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 137 | // add to b1 and b3 |
| 138 | d_bursts[0][fn_mod13] = msg; |
| 139 | d_bursts[2][fn_mod13 + 4] = msg; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 140 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 141 | // set framenumber |
| 142 | d_frame_numbers[0][fn_mod13] = frame_nr; |
| 143 | d_frame_numbers[2][fn_mod13 + 4] = frame_nr; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 144 | } |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 145 | else if (fn_mod13 >= 4 && fn_mod13 <= 7) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 146 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 147 | // add to b1 and b2 |
| 148 | d_bursts[0][fn_mod13] = msg; |
| 149 | d_bursts[1][fn_mod13 - 4] = msg; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 150 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 151 | // set framenumber |
| 152 | d_frame_numbers[0][fn_mod13] = frame_nr; |
| 153 | d_frame_numbers[1][fn_mod13 - 4] = frame_nr; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 154 | } |
| 155 | else if (fn_mod13 >= 8 && fn_mod13 <= 11) |
| 156 | { |
| 157 | // add to b2 and b3 |
| 158 | d_bursts[1][fn_mod13 - 4] = msg; |
| 159 | d_bursts[2][fn_mod13 - 8] = msg; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 160 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 161 | // set framenumber |
| 162 | d_frame_numbers[1][fn_mod13 - 4] = frame_nr; |
| 163 | d_frame_numbers[2][fn_mod13 - 8] = frame_nr; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | // send burst 1 or burst 2 to output |
| 167 | if (fn_mod13 == 3 || fn_mod13 == 7 || fn_mod13 == 11) |
| 168 | { |
| 169 | int tch_burst_nr = 0; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 170 | |
| 171 | if (fn_mod13 == 11) |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 172 | { |
| 173 | tch_burst_nr = 1; |
| 174 | } |
| 175 | else if (fn_mod13 == 3) |
| 176 | { |
| 177 | tch_burst_nr = 2; |
| 178 | } |
| 179 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 180 | //check for a situation where some bursts were lost |
| 181 | //in this situation frame numbers won't be consecutive |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 182 | frames_are_consecutive = true; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 183 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 184 | for(int jj=1; jj<8; jj++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 185 | { |
Roman Khassraf | 4de8e4a | 2015-05-22 10:02:20 +0200 | [diff] [blame] | 186 | if (((d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj-1]) != 1) && frames_are_consecutive) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 187 | { |
| 188 | frames_are_consecutive = false; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 189 | // burst 3 has 1 sacch burst in between |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 190 | if (tch_burst_nr == 2 && jj == 4 |
| 191 | && d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj - 1] == 2) |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 192 | { |
| 193 | frames_are_consecutive = true; |
| 194 | } |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 195 | } |
| 196 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 197 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 198 | if(frames_are_consecutive) |
| 199 | { |
| 200 | //send bursts to the output |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 201 | for(int jj=0; jj<8; jj++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 202 | { |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 203 | message_port_pub(pmt::mp("tch_bursts"), d_bursts[tch_burst_nr][jj]); |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 204 | } |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 205 | d_bursts_stolen[tch_burst_nr] = false; |
| 206 | } |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | } /* namespace gsm */ |
| 212 | } /* namespace gr */ |
| 213 | |