diff options
author | Piotr Krysik <pkrysik@elka.pw.edu.pl> | 2018-05-11 11:37:21 +0200 |
---|---|---|
committer | Piotr Krysik <pkrysik@elka.pw.edu.pl> | 2018-05-11 11:37:21 +0200 |
commit | b7cce89e55f3f2084e1aa989a7532ae11f44bdf0 (patch) | |
tree | 2c97aec277f464fd1f76b22eb0be2f609087ddba | |
parent | fd3d883d4e450abb1d4c4e0185ce38d490291dcc (diff) |
Distilled function to generate hopping from cx_channel hopper
-rw-r--r-- | lib/misc_utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/misc_utils/freq_hopping_utils.cc | 69 | ||||
-rw-r--r-- | lib/misc_utils/freq_hopping_utils.h | 36 | ||||
-rw-r--r-- | lib/receiver/cx_channel_hopper_impl.cc | 56 | ||||
-rw-r--r-- | lib/receiver/cx_channel_hopper_impl.h | 2 |
5 files changed, 109 insertions, 55 deletions
diff --git a/lib/misc_utils/CMakeLists.txt b/lib/misc_utils/CMakeLists.txt index 63effe5..a2dc6d8 100644 --- a/lib/misc_utils/CMakeLists.txt +++ b/lib/misc_utils/CMakeLists.txt @@ -35,6 +35,7 @@ add_sources( tmsi_dumper_impl.cc time_spec.cc fn_time.cc + freq_hopping_utils.cc udp_socket.cc burst_to_fn_time_impl.cc ) diff --git a/lib/misc_utils/freq_hopping_utils.cc b/lib/misc_utils/freq_hopping_utils.cc new file mode 100644 index 0000000..15a5acb --- /dev/null +++ b/lib/misc_utils/freq_hopping_utils.cc @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* @file + * @author Piotr Krysik <ptrkrysik@gmail.com> + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +//#include "grgsm/misc_utils/freq_hopping_utils.h" +#include <cmath> + +namespace gr { + namespace gsm { + unsigned char RNTABLE[114] = { + 48, 98, 63, 1, 36, 95, 78, 102, 94, 73, \ + 0, 64, 25, 81, 76, 59, 124, 23, 104, 100, \ + 101, 47, 118, 85, 18, 56, 96, 86, 54, 2, \ + 80, 34, 127, 13, 6, 89, 57, 103, 12, 74, \ + 55, 111, 75, 38, 109, 71, 112, 29, 11, 88, \ + 87, 19, 3, 68, 110, 26, 33, 31, 8, 45, \ + 82, 58, 40, 107, 32, 5, 106, 92, 62, 67, \ + 77, 108, 122, 37, 60, 66, 121, 42, 51, 126, \ + 117, 114, 4, 90, 43, 52, 53, 113, 120, 72, \ + 16, 49, 7, 79, 119, 61, 22, 84, 9, 97, \ + 91, 15, 21, 24, 46, 39, 93, 105, 65, 70, \ + 125, 99, 17, 123 \ + }; + + int calculate_ma_sfh(int maio, int hsn, int n, int fn) + { + int mai = 0; + int s = 0; + int nbin = floor(log2(n) + 1); + int t1 = fn / 1326; + int t2 = fn % 26; + int t3 = fn % 51; + + if (hsn == 0){ + mai = (fn + maio) % n; + } else { + int t1r = t1 % 64; + int m = t2 + RNTABLE[(hsn ^ t1r) + t3]; + int mprim = m % (1 << nbin); + int tprim = t3 % (1 << nbin); + + if (mprim < n){ + s = mprim; + } else { + s = (mprim + tprim) % n; + } + mai = (s + maio) % n; + } + } + } // namespace gsm +} // namespace gr diff --git a/lib/misc_utils/freq_hopping_utils.h b/lib/misc_utils/freq_hopping_utils.h new file mode 100644 index 0000000..df4cba2 --- /dev/null +++ b/lib/misc_utils/freq_hopping_utils.h @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* @file + * @author Piotr Krysik <ptrkrysik@gmail.com> + * @section LICENSE + * + * Gr-gsm is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * Gr-gsm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gr-gsm; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef INCLUDED_FREQ_HOPPING_UTILS_H +#define INCLUDED_FREQ_HOPPING_UTILS_H + +namespace gr { + namespace gsm { + /* + * Slow Frequency Hopping (SFH) MAI calculation based + * on airprobe-hopping by Bogdan Diaconescu. + */ + int calculate_ma_sfh(int maio, int hsn, int n, int fn); + } // namespace gsm +} // namespace gr + +#endif /* INCLUDED_FREQ_HOPPING_UTILS_H */ diff --git a/lib/receiver/cx_channel_hopper_impl.cc b/lib/receiver/cx_channel_hopper_impl.cc index e5be27a..a45737c 100644 --- a/lib/receiver/cx_channel_hopper_impl.cc +++ b/lib/receiver/cx_channel_hopper_impl.cc @@ -29,6 +29,7 @@ #include <grgsm/endian.h> #include <boost/algorithm/clamp.hpp> #include "cx_channel_hopper_impl.h" +#include "../misc_utils/freq_hopping_utils.h" namespace gr { namespace gsm { @@ -83,57 +84,6 @@ namespace gr { } /** - * Random number table used for calculating the - * hopping sequence. Defined in GSM 05.02. - */ - unsigned char RNTABLE[114] = { - 48, 98, 63, 1, 36, 95, 78, 102, 94, 73, \ - 0, 64, 25, 81, 76, 59, 124, 23, 104, 100, \ - 101, 47, 118, 85, 18, 56, 96, 86, 54, 2, \ - 80, 34, 127, 13, 6, 89, 57, 103, 12, 74, \ - 55, 111, 75, 38, 109, 71, 112, 29, 11, 88, \ - 87, 19, 3, 68, 110, 26, 33, 31, 8, 45, \ - 82, 58, 40, 107, 32, 5, 106, 92, 62, 67, \ - 77, 108, 122, 37, 60, 66, 121, 42, 51, 126, \ - 117, 114, 4, 90, 43, 52, 53, 113, 120, 72, \ - 16, 49, 7, 79, 119, 61, 22, 84, 9, 97, \ - 91, 15, 21, 24, 46, 39, 93, 105, 65, 70, \ - 125, 99, 17, 123 \ - }; - - /* - * Slow Frequency Hopping (SFH) MAI calculation based - * on airprobe-hopping by Bogdan Diaconescu. - */ - int cx_channel_hopper_impl::calculate_ma_sfh(int maio, int hsn, int n, int fn) - { - int mai = 0; - int s = 0; - int nbin = floor(log2(n) + 1); - int t1 = fn / 1326; - int t2 = fn % 26; - int t3 = fn % 51; - - if (hsn == 0) - mai = (fn + maio) % n; - else { - int t1r = t1 % 64; - int m = t2 + RNTABLE[(hsn ^ t1r) + t3]; - int mprim = m % (1 << nbin); - int tprim = t3 % (1 << nbin); - - if (mprim < n) - s = mprim; - else - s = (mprim + tprim) % n; - - mai = (s + maio) % n; - } - - return (mai); - } - - /** * Given MA, MAIO, HSN, and FN, decide which frames * to forward to the demapper. */ @@ -147,10 +97,10 @@ namespace gr { //in order to leave only ARFCN number int mai = calculate_ma_sfh(d_maio, d_hsn, d_narfcn, frame_nr); - +/* if(d_ma[mai] == (int)frame_ca) { message_port_pub(pmt::mp("bursts"), msg); - } + }*/ } } /* namespace gsm */ diff --git a/lib/receiver/cx_channel_hopper_impl.h b/lib/receiver/cx_channel_hopper_impl.h index 7ac9bf4..83c4fa2 100644 --- a/lib/receiver/cx_channel_hopper_impl.h +++ b/lib/receiver/cx_channel_hopper_impl.h @@ -28,7 +28,6 @@ namespace gr { namespace gsm { - class cx_channel_hopper_impl : public cx_channel_hopper { private: @@ -37,7 +36,6 @@ namespace gr { int d_hsn; // Hopping Sequence Number int d_narfcn; // Length of d_ma - int calculate_ma_sfh(int maio, int hsn, int n, int fn); void assemble_bursts(pmt::pmt_t msg); public: |