Roman Khassraf | e5ddab3 | 2016-12-04 16:19:40 +0100 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* |
| 3 | * @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 4 | * @author (C) 2016 by Roman Khassraf <rkhassraf@gmail.com> |
Roman Khassraf | e5ddab3 | 2016-12-04 16:19:40 +0100 | [diff] [blame] | 5 | * @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> |
| 29 | #include <unistd.h> |
| 30 | #include <grgsm/endian.h> |
| 31 | |
| 32 | #include "extract_cmc_impl.h" |
| 33 | |
| 34 | namespace 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 | |
| 43 | if((msg_elements[3] & 0xF) == 0x6 && msg_elements[4] == 0x35) |
| 44 | { |
Roman Khassraf | e5ddab3 | 2016-12-04 16:19:40 +0100 | [diff] [blame] | 45 | |
Piotr Krysik | 8f121c1 | 2017-03-30 10:55:08 +0200 | [diff] [blame] | 46 | 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 Khassraf | e5ddab3 | 2016-12-04 16:19:40 +0100 | [diff] [blame] | 50 | 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 Krysik | 8f121c1 | 2017-03-30 10:55:08 +0200 | [diff] [blame] | 64 | |
| 65 | std::vector<int> extract_cmc_impl::get_start_ciphering() |
| 66 | { |
| 67 | return d_start_ciphering; |
| 68 | } |
Roman Khassraf | e5ddab3 | 2016-12-04 16:19:40 +0100 | [diff] [blame] | 69 | |
| 70 | 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 */ |