free5GRAN  V1.0
common_utils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Telecom Paris
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
17 #include <cmath>
18 #include "common_utils.h"
19 
20 
30  /*
31  * Getting MIB informations
32  */
33  // Recovering SFN from BCH payload
34  int sfn_array[10] = {mib_bits[1], mib_bits[2], mib_bits[3], mib_bits[4], mib_bits[5], mib_bits[6],mib_bits[24], mib_bits[25], mib_bits[26], mib_bits[27]};
35  mib_object.sfn = 0;
36  for (int i = 0 ; i < 10; i ++){
37  mib_object.sfn += sfn_array[i] * pow(2, 10 - 1 - i);
38  }
39 
40  int available_scs[2] = {15, 30};
41  // Recovering PDCCH config identifier
42  int pdcch_config_array[8];
43  for (int i = 0 ; i < 8; i ++){
44  pdcch_config_array[i] = mib_bits[13 + i];
45  }
46  mib_object.pdcch_config = 0;
47  for (int i = 0 ; i < 8; i ++){
48  mib_object.pdcch_config += pdcch_config_array[i] * pow(2, 8 - 1 - i);
49  }
50  // Recovering cell barred information
51  mib_object.cell_barred = mib_bits[21];
52  mib_object.scs = available_scs[mib_bits[7]];
53 
54  int k_ssb_array[5] = {mib_bits[29], mib_bits[8], mib_bits[9], mib_bits[10], mib_bits[11]};
55  mib_object.k_ssb = 0;
56  for (int i = 0 ; i < 5; i ++){
57  mib_object.k_ssb += k_ssb_array[i] * pow(2, 5 - 1 - i);
58  }
59  mib_object.dmrs_type_a_position = 2 + mib_bits[12];
60  mib_object.intra_freq_reselection = mib_bits[22];
61 }
62 
63 /*
64  * Scrambling implementation: output = (input + c_seq)[2]
65  */
66 void free5GRAN::utils::common_utils::scramble(int *input_bits, int *c_seq, int *output_bits, int length, int offset) {
76  for (int i = 0; i < length; i ++){
77  output_bits[i] = (input_bits[i] + c_seq[i + offset]) % 2;
78  }
79 }
80 
81 void free5GRAN::utils::common_utils::scramble(double *input_bits, int *c_seq, double *output_bits, int length, int offset) {
91  for (int i = 0; i < length; i ++){
92  output_bits[i] = input_bits[i] * c_seq[i + offset];
93  }
94 }
void scramble(int *input_bits, int *c_seq, int *output_bits, int length, int offset)
void parse_mib(int *mib_bits, free5GRAN::mib &mib_object)