blob: 04b0afc6501dad898c13e1e40a7ab83796208e0a [file] [log] [blame]
Roman Khassrafe5ddab32016-12-04 16:19:40 +01001/* -*- c++ -*- */
2/*
3 * @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004 * @author (C) 2016 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassrafe5ddab32016-12-04 16:19:40 +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 Khassrafe5ddab32016-12-04 16:19:40 +010030#include <grgsm/endian.h>
31
32#include "extract_cmc_impl.h"
33
34namespace gr {
35 namespace gsm {
36 void extract_cmc_impl::process_messages(pmt::pmt_t msg)
37 {
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
Piotr Krysika0813662017-04-02 17:19:13 +020043 if((msg_elements[3] & 0xFF) == 0x06 && msg_elements[4] == 0x35)
Roman Khassrafe5ddab32016-12-04 16:19:40 +010044 {
Roman Khassrafe5ddab32016-12-04 16:19:40 +010045
Piotr Krysik8f121c12017-03-30 10:55:08 +020046 int frame_nr = be32toh(header->frame_number);
47 int a5_version = ((msg_elements[5] & 0xE) >> 1) + 1; //10.5.2.9 Cipher Mode Setting
48 int start_ciphering = ((msg_elements[5] & 0x1));
49 d_start_ciphering.push_back(start_ciphering);
Roman Khassrafe5ddab32016-12-04 16:19:40 +010050 d_framenumbers.push_back(frame_nr);
51 d_a5_versions.push_back(a5_version);
52 }
53 }
54
55 std::vector<int> extract_cmc_impl::get_framenumbers()
56 {
57 return d_framenumbers;
58 }
59
60 std::vector<int> extract_cmc_impl::get_a5_versions()
61 {
62 return d_a5_versions;
63 }
Piotr Krysik8f121c12017-03-30 10:55:08 +020064
65 std::vector<int> extract_cmc_impl::get_start_ciphering()
66 {
67 return d_start_ciphering;
68 }
Roman Khassrafe5ddab32016-12-04 16:19:40 +010069
Roman Khassrafe5ddab32016-12-04 16:19:40 +010070 extract_cmc::sptr
71 extract_cmc::make()
72 {
73 return gnuradio::get_initial_sptr
74 (new extract_cmc_impl());
75 }
76
77 /*
78 * The private constructor
79 */
80 extract_cmc_impl::extract_cmc_impl()
81 : gr::block("extract_cmc",
82 gr::io_signature::make(0, 0, 0),
83 gr::io_signature::make(0, 0, 0))
84 {
85 message_port_register_in(pmt::mp("msgs"));
86 set_msg_handler(pmt::mp("msgs"), boost::bind(&extract_cmc_impl::process_messages, this, _1));
87 }
88
89 /*
90 * Our virtual destructor.
91 */
92 extract_cmc_impl::~extract_cmc_impl()
93 {
94 }
95 } /* namespace gsm */
96} /* namespace gr */