blob: 6ab982e11aebca2c8c0e9b6173c2c666ded36405 [file] [log] [blame]
Roman Khassraf98581a82017-01-11 12:50:38 +01001/* -*- c++ -*- */
2/*
3 * @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004 * @author (C) 2017 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassraf98581a82017-01-11 12:50:38 +01005 * @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 <grgsm/gsmtap.h>
Piotr Krysikeb81b032018-02-27 08:46:17 +010029//#include <unistd.h>
Roman Khassraf98581a82017-01-11 12:50:38 +010030#include <grgsm/endian.h>
31
32#include "collect_system_info_impl.h"
33
34namespace gr {
35 namespace gsm {
36
37 void collect_system_info_impl::process_messages(pmt::pmt_t msg){
38 pmt::pmt_t message_plus_header_blob = pmt::cdr(msg);
39 uint8_t * message_plus_header = (uint8_t *)pmt::blob_data(message_plus_header_blob);
40 gsmtap_hdr * header = (gsmtap_hdr *)message_plus_header;
41 uint8_t * msg_elements = (uint8_t *)(message_plus_header+sizeof(gsmtap_hdr));
42
43 uint8_t chan_type = header->sub_type;
44
45 if (chan_type == GSMTAP_CHANNEL_BCCH && msg_elements[1] == 0x06)
46 {
47 int frame_nr = be32toh(header->frame_number);
48
49 if (msg_elements[2] == 0x19)
50 {
51 d_framenumbers.push_back(frame_nr);
52 d_sit_types.push_back("System Information Type 1");
53 d_sit_data.push_back(get_hex_string(msg_elements));
54 }
55 else if (msg_elements[2] == 0x1a)
56 {
57 d_framenumbers.push_back(frame_nr);
58 d_sit_types.push_back("System Information Type 2");
59 d_sit_data.push_back(get_hex_string(msg_elements));
60 }
61 else if (msg_elements[2] == 0x1b)
62 {
63 d_framenumbers.push_back(frame_nr);
64 d_sit_types.push_back("System Information Type 3");
65 d_sit_data.push_back(get_hex_string(msg_elements));
66 }
67 else if (msg_elements[2] == 0x1c)
68 {
69 d_framenumbers.push_back(frame_nr);
70 d_sit_types.push_back("System Information Type 4");
71 d_sit_data.push_back(get_hex_string(msg_elements));
72 }
73 else if (msg_elements[2] == 0x02)
74 {
75 d_framenumbers.push_back(frame_nr);
76 d_sit_types.push_back("System Information Type 2bis");
77 d_sit_data.push_back(get_hex_string(msg_elements));
78 }
79 else if (msg_elements[2] == 0x03)
80 {
81 d_framenumbers.push_back(frame_nr);
82 d_sit_types.push_back("System Information Type 2ter");
83 d_sit_data.push_back(get_hex_string(msg_elements));
84 }
85 else if (msg_elements[2] == 0x07)
86 {
87 d_framenumbers.push_back(frame_nr);
88 d_sit_types.push_back("System Information Type 2quater");
89 d_sit_data.push_back(get_hex_string(msg_elements));
90 }
91 else if (msg_elements[2] == 0x00)
92 {
93 d_framenumbers.push_back(frame_nr);
94 d_sit_types.push_back("System Information Type 13");
95 d_sit_data.push_back(get_hex_string(msg_elements));
96 }
97 }
Steve Glass263f00d2017-03-02 20:40:22 +100098 else if ((chan_type == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH)
99 || chan_type == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH4)
100 || chan_type == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH8)
101 || chan_type == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_F)
102 || chan_type == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_H))
Roman Khassraf98581a82017-01-11 12:50:38 +0100103 && msg_elements[5] == 0x06)
104 {
105 int frame_nr = be32toh(header->frame_number);
106
107 if (msg_elements[6] == 0x1D)
108 {
109 d_framenumbers.push_back(frame_nr);
110 d_sit_types.push_back("System Information Type 5");
111 d_sit_data.push_back(get_hex_string(msg_elements));
112 }
113 else if (msg_elements[6] == 0x1E)
114 {
115 d_framenumbers.push_back(frame_nr);
116 d_sit_types.push_back("System Information Type 6");
117 d_sit_data.push_back(get_hex_string(msg_elements));
118 }
119 else if (msg_elements[6] == 0x05)
120 {
121 d_framenumbers.push_back(frame_nr);
122 d_sit_types.push_back("System Information Type 5bis");
123 d_sit_data.push_back(get_hex_string(msg_elements));
124 }
125 else if (msg_elements[6] == 0x06)
126 {
127 d_framenumbers.push_back(frame_nr);
128 d_sit_types.push_back("System Information Type 5ter");
129 d_sit_data.push_back(get_hex_string(msg_elements));
130 }
131 }
132 }
133
134 std::vector<int> collect_system_info_impl::get_framenumbers()
135 {
136 return d_framenumbers;
137 }
138
139 std::vector<std::string> collect_system_info_impl::get_system_information_type()
140 {
141 return d_sit_types;
142 }
143
144 std::vector<std::string> collect_system_info_impl::get_data()
145 {
146 return d_sit_data;
147 }
148
149 std::string collect_system_info_impl::get_hex_string(uint8_t * msg_elements)
150 {
151 std::stringstream sstream;
152 for (int i=0; i<23; i++)
153 {
154 sstream << std::setfill ('0') << std::setw(2) << std::hex << static_cast<int>(msg_elements[i]);
155 }
156 return sstream.str();
157 }
158
159 collect_system_info::sptr
160 collect_system_info::make()
161 {
162 return gnuradio::get_initial_sptr
163 (new collect_system_info_impl());
164 }
165
166 /*
167 * The private constructor
168 */
169 collect_system_info_impl::collect_system_info_impl()
170 : gr::block("collect_system_info",
171 gr::io_signature::make(0, 0, 0),
172 gr::io_signature::make(0, 0, 0))
173 {
174 message_port_register_in(pmt::mp("msgs"));
Vadim Yanitskiya1169202021-05-03 19:00:43 +0200175 set_msg_handler(pmt::mp("msgs"), boost::bind(&collect_system_info_impl::process_messages, this, boost::placeholders::_1));
Roman Khassraf98581a82017-01-11 12:50:38 +0100176 }
177
178 /*
179 * Our virtual destructor.
180 */
181 collect_system_info_impl::~collect_system_info_impl()
182 {
183 }
184 } /* namespace gsm */
185} /* namespace gr */