blob: dc0fba7897ecd4cff0b755e4979654dea7eeda6f [file] [log] [blame]
Piotr Krysik23444832017-11-29 16:39:22 +01001/* -*- 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>
David Holm17852162018-09-16 13:13:52 +020028#include <grgsm/endian.h>
Piotr Krysik23444832017-11-29 16:39:22 +010029#include <grgsm/gsmtap.h>
30#include <grgsm/gsm_constants.h>
31#include "gen_test_ab_impl.h"
32
33namespace gr {
34 namespace gsm {
35
36 static uint8_t rach_synch_seq[] = {
37 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
38 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0 ,
39 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0,
40 };
41
Piotr Krysike3f34d92017-11-30 12:50:37 +010042 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, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 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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
46// ,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 Krysik23444832017-11-29 16:39:22 +010047 gen_test_ab::sptr
48 gen_test_ab::make()
49 {
50 return gnuradio::get_initial_sptr
51 (new gen_test_ab_impl());
52 }
53
54 /*
55 * The private constructor
56 */
57 gen_test_ab_impl::gen_test_ab_impl()
58 : gr::block("gen_test_ab",
59 gr::io_signature::make(0, 0, 0),
60 gr::io_signature::make(0, 0, 0))
61 {
62 message_port_register_in(pmt::intern("bursts_in"));
63 message_port_register_out(pmt::intern("bursts_out"));
64
Vadim Yanitskiya1169202021-05-03 19:00:43 +020065 set_msg_handler(pmt::intern("bursts_in"), boost::bind(&gen_test_ab_impl::generate_ab, this, boost::placeholders::_1));
Piotr Krysik23444832017-11-29 16:39:22 +010066 }
67
68 /*
69 * Our virtual destructor.
70 */
71 gen_test_ab_impl::~gen_test_ab_impl()
72 {
73 }
74
75 void gen_test_ab_impl::generate_ab(pmt::pmt_t burst)
76 {
77 uint8_t buf[sizeof(gsmtap_hdr) + 148];
78 struct gsmtap_hdr *tap_header = (struct gsmtap_hdr *) buf;
79 uint8_t *access_burst = buf + sizeof(gsmtap_hdr);
80
81// memset(access_burst, 0, 8); /* TB */
82// memcpy(access_burst + 8, rach_synch_seq, 41); /* sync seq */
83// memcpy(access_burst + 49, AB, 36); /* payload */
84// memset(access_burst + 85, 0, 63); /* TB + GP */
85
86 memcpy(access_burst, AB, 148);
87
88 gsmtap_hdr * header = (gsmtap_hdr *)(pmt::blob_data(pmt::cdr(burst)));
89 uint32_t frame_nr = be32toh(header->frame_number);
90 frame_nr = (frame_nr+51)% (26*51*2048);
91
92 tap_header->version = GSMTAP_VERSION;
93 tap_header->hdr_len = sizeof(gsmtap_hdr) / 4;
94 tap_header->type = GSMTAP_TYPE_UM_BURST;
95 tap_header->sub_type = GSMTAP_BURST_ACCESS;
96 tap_header->frame_number = htobe32(frame_nr);
97 tap_header->timeslot = header->timeslot;
98 tap_header->arfcn = 0;
99
100 pmt::pmt_t blob = pmt::make_blob(buf, sizeof(gsmtap_hdr) + BURST_SIZE);
101 pmt::pmt_t pdu_header = pmt::make_dict();
102
103 pmt::pmt_t new_msg = pmt::cons(pdu_header, blob);
104 message_port_pub(pmt::intern("bursts_out"), new_msg);
105 }
106 } /* namespace gsm */
107} /* namespace gr */
108