dlsch_scrambling.c 3.98 KB
Newer Older
1
/*******************************************************************************
ghaddab's avatar
ghaddab committed
2
3
    OpenAirInterface 
    Copyright(c) 1999 - 2014 Eurecom
4

ghaddab's avatar
ghaddab committed
5
6
7
8
    OpenAirInterface 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 of the License, or
    (at your option) any later version.
9
10


ghaddab's avatar
ghaddab committed
11
12
13
14
    OpenAirInterface 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.
15

ghaddab's avatar
ghaddab committed
16
17
18
19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is 
   included in this distribution in the file called "COPYING". If not, 
   see <http://www.gnu.org/licenses/>.
20
21

  Contact Information
ghaddab's avatar
ghaddab committed
22
23
24
25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
  
ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

ghaddab's avatar
ghaddab committed
28
 *******************************************************************************/
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

/*! \file PHY/LTE_TRANSPORT/dlsch_scrambling.c
* \brief Routines for the scrambling procedure of the PDSCH physical channel from 36-211, V8.6 2009-03
* \author R. Knopp
* \date 2011
* \version 0.1
* \company Eurecom
* \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr
* \note
* \warning
*/

//#define DEBUG_SCRAMBLING 1

#include "PHY/defs.h"
#include "PHY/CODING/extern.h"
#include "PHY/CODING/lte_interleaver_inline.h"
#include "defs.h"
#include "extern.h"
#include "PHY/extern.h"
49
50
#include "UTIL/LOG/vcd_signal_dumper.h"

51
52
53
54
void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
		      int mbsfn_flag,
		      LTE_eNB_DLSCH_t *dlsch,
		      int G,
gauthier's avatar
gauthier committed
55
56
		      uint8_t q,
		      uint8_t Ns) {
57
58

  int i,j,k=0;
gauthier's avatar
gauthier committed
59
60
61
  //  uint8_t reset;
  uint32_t x1, x2, s=0;
  uint8_t *e=dlsch->e;
62

63
64
  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_SCRAMBLING, VCD_FUNCTION_IN);

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  //  reset = 1;
  // x1 is set in lte_gold_generic
  if (mbsfn_flag == 0) {
    x2 = (dlsch->rnti<<14) + (q<<13) + ((Ns>>1)<<9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.3.1
  }
  else {
    x2 = ((Ns>>1)<<9) + frame_parms->Nid_cell_mbsfn; //this is c_init in 36.211 Sec 6.3.1
  }
#ifdef DEBUG_SCRAMBLING
  printf("scrambling: rnti %x, q %d, Ns %d, Nid_cell %d, length %d\n",dlsch->rnti,q,Ns,frame_parms->Nid_cell, G);  
#endif
  s = lte_gold_generic(&x1, &x2, 1);
  for (i=0; i<(1+(G>>5)); i++) {
 
    for (j=0;j<32;j++,k++) {
#ifdef DEBUG_SCRAMBLING
      printf("scrambling %d : %d => ",k,e[k]);
#endif
      e[k] = (e[k]&1) ^ ((s>>j)&1);
#ifdef DEBUG_SCRAMBLING
      printf("%d\n",e[k]);
#endif
    }
   s = lte_gold_generic(&x1, &x2, 0);
  }

91
92
  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_SCRAMBLING, VCD_FUNCTION_OUT);

93
94
95
96
97
98
99
}


void dlsch_unscrambling(LTE_DL_FRAME_PARMS *frame_parms,
			int mbsfn_flag,
			LTE_UE_DLSCH_t *dlsch,
			int G,
gauthier's avatar
gauthier committed
100
101
102
			int16_t* llr,
			uint8_t q,
			uint8_t Ns) {
103
104

  int i,j,k=0;
gauthier's avatar
gauthier committed
105
106
  //  uint8_t reset;
  uint32_t x1, x2, s=0;
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  
  //  reset = 1;
  // x1 is set in first call to lte_gold_generic

  if (mbsfn_flag == 0)
    x2 = (dlsch->rnti<<14) + (q<<13) + ((Ns>>1)<<9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.3.1
  else
    x2 = ((Ns>>1)<<9) + frame_parms->Nid_cell_mbsfn; //this is c_init in 36.211 Sec 6.3.1
#ifdef DEBUG_SCRAMBLING
  printf("unscrambling: rnti %x, q %d, Ns %d, Nid_cell %d length %d\n",dlsch->rnti,q,Ns,frame_parms->Nid_cell,G);
#endif
  s = lte_gold_generic(&x1, &x2, 1);
  for (i=0; i<(1+(G>>5)); i++) {
    for (j=0;j<32;j++,k++) {
#ifdef DEBUG_SCRAMBLING
      printf("unscrambling %d : %d => ",k,llr[k]);
#endif
      llr[k] = ((2*((s>>j)&1))-1)*llr[k];
#ifdef DEBUG_SCRAMBLING
      printf("%d\n",llr[k]);
#endif
    }
    s = lte_gold_generic(&x1, &x2, 0);
  }
}