blob: c28e49f798ac45548be1b08007019117d0716884 [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 }
Piotr Krysika0813662017-04-02 17:19:13 +020053 if((msg_elements[3] & 0xFF) == 0x06 && msg_elements[4] == 0x2e)
54 {
55 int frame_nr = be32toh(header->frame_number);
56 d_assignment_commands.push_back(frame_nr);
57 }
Roman Khassrafe5ddab32016-12-04 16:19:40 +010058 }
59
60 std::vector<int> extract_cmc_impl::get_framenumbers()
61 {
62 return d_framenumbers;
63 }
64
65 std::vector<int> extract_cmc_impl::get_a5_versions()
66 {
67 return d_a5_versions;
68 }
Piotr Krysik8f121c12017-03-30 10:55:08 +020069
70 std::vector<int> extract_cmc_impl::get_start_ciphering()
71 {
72 return d_start_ciphering;
73 }
Roman Khassrafe5ddab32016-12-04 16:19:40 +010074
Piotr Krysika0813662017-04-02 17:19:13 +020075 std::vector<int> extract_cmc_impl::get_assignment_commands()
76 {
77 return d_assignment_commands;
78 }
79
Roman Khassrafe5ddab32016-12-04 16:19:40 +010080 extract_cmc::sptr
81 extract_cmc::make()
82 {
83 return gnuradio::get_initial_sptr
84 (new extract_cmc_impl());
85 }
86
87 /*
88 * The private constructor
89 */
90 extract_cmc_impl::extract_cmc_impl()
91 : gr::block("extract_cmc",
92 gr::io_signature::make(0, 0, 0),
93 gr::io_signature::make(0, 0, 0))
94 {
95 message_port_register_in(pmt::mp("msgs"));
96 set_msg_handler(pmt::mp("msgs"), boost::bind(&extract_cmc_impl::process_messages, this, _1));
97 }
98
99 /*
100 * Our virtual destructor.
101 */
102 extract_cmc_impl::~extract_cmc_impl()
103 {
104 }
105 } /* namespace gsm */
106} /* namespace gr */