Piotr Krysik | 2344483 | 2017-11-29 16:39:22 +0100 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* @file |
| 3 | * @author Piotr Krysik <ptrkrysik@gmail.com> |
| 4 | * @section LICENSE |
| 5 | * |
| 6 | * Gr-gsm is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * Gr-gsm is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with gr-gsm; see the file COPYING. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include "config.h" |
| 25 | #endif |
| 26 | |
| 27 | #include <gnuradio/io_signature.h> |
| 28 | #include <grgsm/gsmtap.h> |
| 29 | #include <grgsm/gsm_constants.h> |
| 30 | #include "gen_test_ab_impl.h" |
| 31 | |
| 32 | namespace gr { |
| 33 | namespace gsm { |
| 34 | |
| 35 | static uint8_t rach_synch_seq[] = { |
| 36 | 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, |
| 37 | 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0 , |
| 38 | 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, |
| 39 | }; |
| 40 | |
Piotr Krysik | e3f34d9 | 2017-11-30 12:50:37 +0100 | [diff] [blame] | 41 | static uint8_t AB[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 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:50:37 +0100 | [diff] [blame] | 44 | // static uint8_t AB[] = {1,1,1,1,1,1,1,1,1,0,1,1,0,1,0,0,1,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,0,1,0,1,0,1,1,1,0,0,0,0,1,1,1,0,0,1,0,0,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,0,0,1,0,1,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 |
| 45 | // ,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; |
Piotr Krysik | 2344483 | 2017-11-29 16:39:22 +0100 | [diff] [blame] | 46 | gen_test_ab::sptr |
| 47 | gen_test_ab::make() |
| 48 | { |
| 49 | return gnuradio::get_initial_sptr |
| 50 | (new gen_test_ab_impl()); |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * The private constructor |
| 55 | */ |
| 56 | gen_test_ab_impl::gen_test_ab_impl() |
| 57 | : gr::block("gen_test_ab", |
| 58 | gr::io_signature::make(0, 0, 0), |
| 59 | gr::io_signature::make(0, 0, 0)) |
| 60 | { |
| 61 | message_port_register_in(pmt::intern("bursts_in")); |
| 62 | message_port_register_out(pmt::intern("bursts_out")); |
| 63 | |
| 64 | set_msg_handler(pmt::intern("bursts_in"), boost::bind(&gen_test_ab_impl::generate_ab, this, _1)); |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Our virtual destructor. |
| 69 | */ |
| 70 | gen_test_ab_impl::~gen_test_ab_impl() |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | void gen_test_ab_impl::generate_ab(pmt::pmt_t burst) |
| 75 | { |
| 76 | uint8_t buf[sizeof(gsmtap_hdr) + 148]; |
| 77 | struct gsmtap_hdr *tap_header = (struct gsmtap_hdr *) buf; |
| 78 | uint8_t *access_burst = buf + sizeof(gsmtap_hdr); |
| 79 | |
| 80 | // memset(access_burst, 0, 8); /* TB */ |
| 81 | // memcpy(access_burst + 8, rach_synch_seq, 41); /* sync seq */ |
| 82 | // memcpy(access_burst + 49, AB, 36); /* payload */ |
| 83 | // memset(access_burst + 85, 0, 63); /* TB + GP */ |
| 84 | |
| 85 | memcpy(access_burst, AB, 148); |
| 86 | |
| 87 | gsmtap_hdr * header = (gsmtap_hdr *)(pmt::blob_data(pmt::cdr(burst))); |
| 88 | uint32_t frame_nr = be32toh(header->frame_number); |
| 89 | frame_nr = (frame_nr+51)% (26*51*2048); |
| 90 | |
| 91 | tap_header->version = GSMTAP_VERSION; |
| 92 | tap_header->hdr_len = sizeof(gsmtap_hdr) / 4; |
| 93 | tap_header->type = GSMTAP_TYPE_UM_BURST; |
| 94 | tap_header->sub_type = GSMTAP_BURST_ACCESS; |
| 95 | tap_header->frame_number = htobe32(frame_nr); |
| 96 | tap_header->timeslot = header->timeslot; |
| 97 | tap_header->arfcn = 0; |
| 98 | |
| 99 | pmt::pmt_t blob = pmt::make_blob(buf, sizeof(gsmtap_hdr) + BURST_SIZE); |
| 100 | pmt::pmt_t pdu_header = pmt::make_dict(); |
| 101 | |
| 102 | pmt::pmt_t new_msg = pmt::cons(pdu_header, blob); |
| 103 | message_port_pub(pmt::intern("bursts_out"), new_msg); |
| 104 | } |
| 105 | } /* namespace gsm */ |
| 106 | } /* namespace gr */ |
| 107 | |