blob: a45737c6f3c61739d1be4fee16aef7c19064e941 [file] [log] [blame]
rpp4f0f3b52015-06-10 10:23:30 +02001/* -*- c++ -*- */
2/* @file
Piotr Krysika6268a52017-08-23 16:02:19 +02003 * @author (C) 2015 by Pieter Robyns <pieter.robyns@uhasselt.be>
rpp4f0f3b52015-06-10 10:23:30 +02004 * @section LICENSE
Martin Jesper Low Madsenf3105d92015-06-24 13:33:56 +02005 *
rpp4f0f3b52015-06-10 10:23:30 +02006 * 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.
Martin Jesper Low Madsenf3105d92015-06-24 13:33:56 +020010 *
rpp4f0f3b52015-06-10 10:23:30 +020011 * 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.
Martin Jesper Low Madsenf3105d92015-06-24 13:33:56 +020015 *
rpp4f0f3b52015-06-10 10:23:30 +020016 * 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.
Martin Jesper Low Madsenf3105d92015-06-24 13:33:56 +020020 *
rpp4f0f3b52015-06-10 10:23:30 +020021 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
rpp267214a2015-06-10 11:49:55 +020028#include <grgsm/gsmtap.h>
Martin Jesper Low Madsenf3105d92015-06-24 13:33:56 +020029#include <grgsm/endian.h>
rpp11b549e2015-06-11 10:25:19 +020030#include <boost/algorithm/clamp.hpp>
rpp4f0f3b52015-06-10 10:23:30 +020031#include "cx_channel_hopper_impl.h"
Piotr Krysikb7cce892018-05-11 11:37:21 +020032#include "../misc_utils/freq_hopping_utils.h"
rpp4f0f3b52015-06-10 10:23:30 +020033
34namespace gr {
35 namespace gsm {
36
37 cx_channel_hopper::sptr
rpp267214a2015-06-10 11:49:55 +020038 cx_channel_hopper::make(const std::vector<int> &ma, int maio, int hsn)
rpp4f0f3b52015-06-10 10:23:30 +020039 {
rpp267214a2015-06-10 11:49:55 +020040 return gnuradio::get_initial_sptr
41 (new cx_channel_hopper_impl(ma, maio, hsn));
rpp4f0f3b52015-06-10 10:23:30 +020042 }
43
44 /*
45 * The private constructor
46 */
rpp267214a2015-06-10 11:49:55 +020047 cx_channel_hopper_impl::cx_channel_hopper_impl(const std::vector<int> &ma, int maio, int hsn)
48 : gr::block("cx_channel_hopper",
49 gr::io_signature::make(0, 0, 0),
50 gr::io_signature::make(0, 0, 0)),
51 d_ma(ma),
52 d_maio(maio),
53 d_hsn(hsn)
rpp4f0f3b52015-06-10 10:23:30 +020054 {
rpp267214a2015-06-10 11:49:55 +020055 d_narfcn = ma.size();
rpp4f0f3b52015-06-10 10:23:30 +020056
rpp11b549e2015-06-11 10:25:19 +020057 // Check user input for GSM 05.02, p16 compliance
58 if(d_narfcn < 1 || d_narfcn > 64) {
59 std::cerr << "warning: clamping number of RFCNs in the MA (" << d_narfcn << "), which should be 1 <= N <= 64." << std::endl;
60 d_narfcn = boost::algorithm::clamp(d_narfcn, 1, 64);
61 d_ma.resize(d_narfcn);
62 }
63
64 if(d_maio < 0 || d_maio >= d_narfcn) {
65 std::cerr << "warning: clamping MAIO (" << d_maio << "), which should be 0 <= MAIO < N." << std::endl;
66 d_maio = boost::algorithm::clamp(d_maio, 0, d_narfcn - 1);
67 }
68
69 if(d_hsn < 0 || d_hsn > 63) {
70 std::cerr << "warning: clamping HSN (" << d_hsn << "), which should be 0 <= HSN < 64." << std::endl;
71 d_hsn = boost::algorithm::clamp(d_hsn, 0, 63);
72 }
73
rpp267214a2015-06-10 11:49:55 +020074 message_port_register_in(pmt::mp("CX"));
75 set_msg_handler(pmt::mp("CX"), boost::bind(&cx_channel_hopper_impl::assemble_bursts, this, _1));
76 message_port_register_out(pmt::mp("bursts"));
rpp4f0f3b52015-06-10 10:23:30 +020077 }
78
79 /*
80 * Our virtual destructor.
81 */
82 cx_channel_hopper_impl::~cx_channel_hopper_impl()
83 {
84 }
85
rpp267214a2015-06-10 11:49:55 +020086 /**
rpp267214a2015-06-10 11:49:55 +020087 * Given MA, MAIO, HSN, and FN, decide which frames
88 * to forward to the demapper.
89 */
90 void cx_channel_hopper_impl::assemble_bursts(pmt::pmt_t msg)
91 {
92 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
93 gsmtap_hdr *header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
94
95 uint32_t frame_nr = be32toh(header->frame_number);
Piotr Krysik938cda42016-07-14 11:44:45 +020096 uint16_t frame_ca = be16toh(header->arfcn) & 0x3FFF; //change highest bits to '0'
97 //in order to leave only ARFCN number
Your Namea7976a32016-07-12 17:23:13 +043098
rpp267214a2015-06-10 11:49:55 +020099 int mai = calculate_ma_sfh(d_maio, d_hsn, d_narfcn, frame_nr);
Piotr Krysikb7cce892018-05-11 11:37:21 +0200100/*
rpp11b549e2015-06-11 10:25:19 +0200101 if(d_ma[mai] == (int)frame_ca) {
rpp267214a2015-06-10 11:49:55 +0200102 message_port_pub(pmt::mp("bursts"), msg);
Piotr Krysikb7cce892018-05-11 11:37:21 +0200103 }*/
rpp267214a2015-06-10 11:49:55 +0200104 }
105
rpp4f0f3b52015-06-10 10:23:30 +0200106 } /* namespace gsm */
107} /* namespace gr */