Eric | ac726b1 | 2022-11-28 18:57:58 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | /* -*- c++ -*- */ |
| 3 | /* |
| 4 | * @file |
| 5 | * @author (C) 2009-2017 by Piotr Krysik <ptrkrysik@gmail.com> |
| 6 | * @section LICENSE |
| 7 | * |
| 8 | * Gr-gsm is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 3, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * Gr-gsm is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with gr-gsm; see the file COPYING. If not, write to |
| 20 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 21 | * Boston, MA 02110-1301, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <complex> |
| 25 | |
| 26 | #define gr_complex std::complex<float> |
| 27 | |
| 28 | |
| 29 | #define GSM_SYMBOL_RATE (1625000.0/6.0) //symbols per second |
| 30 | #define GSM_SYMBOL_PERIOD (1.0/GSM_SYMBOL_RATE) //seconds per symbol |
| 31 | |
| 32 | //Burst timing |
| 33 | #define TAIL_BITS 3 |
| 34 | #define GUARD_BITS 8 |
| 35 | #define GUARD_FRACTIONAL 0.25 //fractional part of guard period |
| 36 | #define GUARD_PERIOD GUARD_BITS + GUARD_FRACTIONAL |
| 37 | #define DATA_BITS 57 //size of 1 data block in normal burst |
| 38 | #define STEALING_BIT 1 |
| 39 | #define N_TRAIN_BITS 26 |
| 40 | #define N_SYNC_BITS 64 |
| 41 | #define USEFUL_BITS 142 //(2*(DATA_BITS+STEALING_BIT) + N_TRAIN_BITS ) |
| 42 | #define FCCH_BITS USEFUL_BITS |
| 43 | #define BURST_SIZE (USEFUL_BITS+2*TAIL_BITS) |
| 44 | #define ACCESS_BURST_SIZE 88 |
| 45 | #define PROCESSED_CHUNK BURST_SIZE+2*GUARD_PERIOD |
| 46 | |
| 47 | #define SCH_DATA_LEN 39 |
| 48 | #define TS_BITS (TAIL_BITS+USEFUL_BITS+TAIL_BITS+GUARD_BITS) //a full TS (156 bits) |
| 49 | #define TS_PER_FRAME 8 |
| 50 | #define FRAME_BITS (TS_PER_FRAME * TS_BITS + 2) // 156.25 * 8 |
| 51 | #define FCCH_POS TAIL_BITS |
| 52 | #define SYNC_POS (TAIL_BITS + 39) |
| 53 | #define TRAIN_POS ( TAIL_BITS + (DATA_BITS+STEALING_BIT) + 5) //first 5 bits of a training sequence |
| 54 | //aren't used for channel impulse response estimation |
| 55 | #define TRAIN_BEGINNING 5 |
| 56 | #define SAFETY_MARGIN 6 // |
| 57 | |
| 58 | #define FCCH_HITS_NEEDED (USEFUL_BITS - 4) |
| 59 | #define FCCH_MAX_MISSES 1 |
| 60 | #define FCCH_MAX_FREQ_OFFSET 100 |
| 61 | |
| 62 | #define CHAN_IMP_RESP_LENGTH 5 |
| 63 | |
| 64 | #define MAX_SCH_ERRORS 10 //maximum number of subsequent sch errors after which gsm receiver goes to find_next_fcch state |
| 65 | |
| 66 | typedef enum { empty, fcch_burst, sch_burst, normal_burst, rach_burst, dummy, dummy_or_normal, normal_or_noise } burst_type; |
| 67 | typedef enum { unknown, multiframe_26, multiframe_51 } multiframe_type; |
| 68 | |
| 69 | static const unsigned char SYNC_BITS[] = { |
| 70 | 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, |
| 71 | 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, |
| 72 | 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, |
| 73 | 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1 |
| 74 | }; |
| 75 | |
| 76 | const unsigned FCCH_FRAMES[] = { 0, 10, 20, 30, 40 }; |
| 77 | const unsigned SCH_FRAMES[] = { 1, 11, 21, 31, 41 }; |
| 78 | |
| 79 | const unsigned BCCH_FRAMES[] = { 2, 3, 4, 5 }; //!!the receiver shouldn't care about logical |
| 80 | //!!channels so this will be removed from this header |
| 81 | const unsigned TEST_CCH_FRAMES[] = { 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 44, 45, 46, 47, 48, 49 }; |
| 82 | const unsigned TRAFFIC_CHANNEL_F[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }; |
| 83 | const unsigned TEST51[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 }; |
| 84 | |
| 85 | |
| 86 | #define TSC0 0 |
| 87 | #define TSC1 1 |
| 88 | #define TSC2 2 |
| 89 | #define TSC3 3 |
| 90 | #define TSC4 4 |
| 91 | #define TSC5 5 |
| 92 | #define TSC6 6 |
| 93 | #define TSC7 7 |
| 94 | #define TS_DUMMY 8 |
| 95 | |
| 96 | #define TRAIN_SEQ_NUM 9 |
| 97 | |
| 98 | #define TIMESLOT0 0 |
| 99 | #define TIMESLOT1 1 |
| 100 | #define TIMESLOT2 2 |
| 101 | #define TIMESLOT3 3 |
| 102 | #define TIMESLOT4 4 |
| 103 | #define TIMESLOT5 5 |
| 104 | #define TIMESLOT6 6 |
| 105 | #define TIMESLOT7 7 |
| 106 | |
| 107 | |
| 108 | static const unsigned char train_seq[TRAIN_SEQ_NUM][N_TRAIN_BITS] = { |
| 109 | {0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}, |
| 110 | {0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}, |
| 111 | {0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0}, |
| 112 | {0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0}, |
| 113 | {0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1}, |
| 114 | {0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0}, |
| 115 | {1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1}, |
| 116 | {1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0}, |
| 117 | {0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1} // DUMMY |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | //Dummy burst 0xFB 76 0A 4E 09 10 1F 1C 5C 5C 57 4A 33 39 E9 F1 2F A8 |
| 122 | static const unsigned char dummy_burst[] = { |
| 123 | 0, 0, 0, |
| 124 | 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, |
| 125 | 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, |
| 126 | 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, |
| 127 | 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, |
| 128 | 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, |
| 129 | 0, 1, 1, 1, 1, 1, 0, 0, |
| 130 | |
| 131 | 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, |
| 132 | 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, |
| 133 | 0, 0, 0, 1, 0, 1, |
| 134 | |
| 135 | 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, |
| 136 | 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, |
| 137 | 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, |
| 138 | 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, |
| 139 | 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, |
| 140 | 1, 1, 1, 0, 1, 0, 1, 0, |
| 141 | 0, 0, 0 |
| 142 | }; |