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 | |
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 | { |
| 55 | for (int ii=0; ii<3; ii++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 56 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 57 | d_bursts_stolen[ii] = false; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 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; |
| 81 | bool frames_are_consecutive = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 82 | int8_t * burst_bits = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr); |
| 83 | |
| 84 | if(header->timeslot == d_timeslot){ |
iZsh | 6698793 | 2015-08-16 14:42:18 +0200 | [diff] [blame] | 85 | 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 96 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 97 | if (fn_mod13 == 12) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 98 | { |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 99 | // position of SACCH burst based on timeslot |
| 100 | // see specification gsm 05.02 |
| 101 | uint32_t index; |
| 102 | bool is_sacch = false; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 103 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 104 | 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 109 | else if (d_timeslot % 2 == 1 && fn_mod26 == 25) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 110 | { |
| 111 | index = (((frame_nr - 25) / 26) - ((d_timeslot - 1) / 2)) % 4; |
| 112 | is_sacch = true; |
| 113 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 114 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 115 | if (is_sacch) |
| 116 | { |
iZsh | 6698793 | 2015-08-16 14:42:18 +0200 | [diff] [blame] | 117 | d_bursts_sacch[index] = msg_out; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 118 | d_frame_numbers_sacch[index] = frame_nr; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 119 | |
| 120 | if (index == 3) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 121 | { |
| 122 | //check for a situation where some bursts were lost |
| 123 | //in this situation frame numbers won't be consecutive |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 124 | frames_are_consecutive = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 125 | 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 145 | if (fn_mod13 <= 3) |
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 b3 |
iZsh | 6698793 | 2015-08-16 14:42:18 +0200 | [diff] [blame] | 148 | d_bursts[0][fn_mod13] = msg_out; |
| 149 | d_bursts[2][fn_mod13 + 4] = msg_out; |
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[2][fn_mod13 + 4] = frame_nr; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 154 | } |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 155 | else if (fn_mod13 >= 4 && fn_mod13 <= 7) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 156 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 157 | // add to b1 and b2 |
iZsh | 6698793 | 2015-08-16 14:42:18 +0200 | [diff] [blame] | 158 | d_bursts[0][fn_mod13] = msg_out; |
| 159 | d_bursts[1][fn_mod13 - 4] = msg_out; |
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[0][fn_mod13] = frame_nr; |
| 163 | d_frame_numbers[1][fn_mod13 - 4] = frame_nr; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 164 | } |
| 165 | else if (fn_mod13 >= 8 && fn_mod13 <= 11) |
| 166 | { |
| 167 | // add to b2 and b3 |
iZsh | 6698793 | 2015-08-16 14:42:18 +0200 | [diff] [blame] | 168 | d_bursts[1][fn_mod13 - 4] = msg_out; |
| 169 | d_bursts[2][fn_mod13 - 8] = msg_out; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 170 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 171 | // set framenumber |
| 172 | d_frame_numbers[1][fn_mod13 - 4] = frame_nr; |
| 173 | d_frame_numbers[2][fn_mod13 - 8] = frame_nr; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 174 | } |
| 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 Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 180 | |
| 181 | if (fn_mod13 == 11) |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 182 | { |
| 183 | tch_burst_nr = 1; |
| 184 | } |
| 185 | else if (fn_mod13 == 3) |
| 186 | { |
| 187 | tch_burst_nr = 2; |
| 188 | } |
| 189 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 190 | //check for a situation where some bursts were lost |
| 191 | //in this situation frame numbers won't be consecutive |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 192 | frames_are_consecutive = true; |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 193 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 194 | for(int jj=1; jj<8; jj++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 195 | { |
Roman Khassraf | 4de8e4a | 2015-05-22 10:02:20 +0200 | [diff] [blame] | 196 | 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] | 197 | { |
| 198 | frames_are_consecutive = false; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 199 | // burst 3 has 1 sacch burst in between |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 200 | 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 Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 202 | { |
| 203 | frames_are_consecutive = true; |
| 204 | } |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 205 | } |
| 206 | } |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 207 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 208 | if(frames_are_consecutive) |
| 209 | { |
| 210 | //send bursts to the output |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 211 | for(int jj=0; jj<8; jj++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 212 | { |
Roman Khassraf | 650ce78 | 2015-05-20 12:48:04 +0200 | [diff] [blame] | 213 | 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] | 214 | } |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 215 | d_bursts_stolen[tch_burst_nr] = false; |
| 216 | } |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | } /* namespace gsm */ |
| 222 | } /* namespace gr */ |
| 223 | |