2014-03-03 11:09:26 -08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* Copyright 2013-2015 The srsLTE Developers. See the
|
2014-03-03 11:09:26 -08:00
|
|
|
* COPYRIGHT file at the top-level directory of this distribution.
|
|
|
|
*
|
|
|
|
* \section LICENSE
|
2014-01-28 03:41:17 -08:00
|
|
|
*
|
2015-03-20 05:01:08 -07:00
|
|
|
* This file is part of the srsLTE library.
|
2014-01-28 03:41:17 -08:00
|
|
|
*
|
2015-03-20 05:01:08 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2015-05-08 08:05:40 -07:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2014-03-03 11:09:26 -08:00
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-03-20 05:01:08 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2014-01-28 03:41:17 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-05-08 08:05:40 -07:00
|
|
|
* GNU Affero General Public License for more details.
|
2014-01-28 03:41:17 -08:00
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
2014-03-03 11:09:26 -08:00
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
2014-01-28 03:41:17 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-03-03 11:09:26 -08:00
|
|
|
#include <assert.h>
|
2015-08-06 17:56:45 -07:00
|
|
|
#include "srslte/utils/vector.h"
|
2015-03-18 05:31:13 -07:00
|
|
|
#include "srslte/scrambling/scrambling.h"
|
2014-01-28 03:41:17 -08:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
void srslte_scrambling_f(srslte_sequence_t *s, float *data) {
|
|
|
|
srslte_scrambling_f_offset(s, data, 0, s->len);
|
2014-01-28 03:41:17 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
void srslte_scrambling_f_offset(srslte_sequence_t *s, float *data, int offset, int len) {
|
2014-07-10 05:43:18 -07:00
|
|
|
int i;
|
2014-06-17 02:11:41 -07:00
|
|
|
assert (len + offset <= s->len);
|
2014-03-03 11:09:26 -08:00
|
|
|
|
2014-06-17 02:11:41 -07:00
|
|
|
for (i = 0; i < len; i++) {
|
2015-08-06 17:56:45 -07:00
|
|
|
data[i] = data[i] * (1-2*s->c[i + offset]);
|
2014-06-17 02:11:41 -07:00
|
|
|
}
|
2014-01-28 03:41:17 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
void srslte_scrambling_c(srslte_sequence_t *s, cf_t *data) {
|
|
|
|
srslte_scrambling_c_offset(s, data, 0, s->len);
|
2014-03-27 09:31:25 -07:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
void srslte_scrambling_c_offset(srslte_sequence_t *s, cf_t *data, int offset, int len) {
|
2014-06-17 02:11:41 -07:00
|
|
|
int i;
|
|
|
|
assert (len + offset <= s->len);
|
2014-03-27 09:31:25 -07:00
|
|
|
|
2014-06-17 02:11:41 -07:00
|
|
|
for (i = 0; i < len; i++) {
|
2014-06-17 07:32:19 -07:00
|
|
|
data[i] = data[i] * (1 - 2 * s->c[i + offset]);
|
2014-06-17 02:11:41 -07:00
|
|
|
}
|
2014-03-27 09:31:25 -07:00
|
|
|
}
|
|
|
|
|
2015-09-18 06:46:27 -07:00
|
|
|
void scrambling_b(uint8_t *c, uint8_t *data, int offset, int len) {
|
2014-06-17 02:11:41 -07:00
|
|
|
int i;
|
2015-08-06 17:56:45 -07:00
|
|
|
// Do XOR on a word basis
|
2015-09-05 02:51:19 -07:00
|
|
|
|
2015-08-06 17:56:45 -07:00
|
|
|
if (!(len%8)) {
|
|
|
|
uint64_t *x = (uint64_t*) data;
|
2015-09-18 06:46:27 -07:00
|
|
|
uint64_t *y = (uint64_t*) &c[offset];
|
2015-08-06 17:56:45 -07:00
|
|
|
for (int i=0;i<len/8;i++) {
|
|
|
|
x[i] = (x[i] ^ y[i]);
|
|
|
|
}
|
|
|
|
} else if (!(len%4)) {
|
|
|
|
uint32_t *x = (uint32_t*) data;
|
2015-09-18 06:46:27 -07:00
|
|
|
uint32_t *y = (uint32_t*) &c[offset];
|
2015-09-05 02:51:19 -07:00
|
|
|
for (int i=0;i<len/4;i++) {
|
2015-08-06 17:56:45 -07:00
|
|
|
x[i] = (x[i] ^ y[i]);
|
|
|
|
}
|
|
|
|
} else if (!(len%2)) {
|
|
|
|
uint16_t *x = (uint16_t*) data;
|
2015-09-18 06:46:27 -07:00
|
|
|
uint16_t *y = (uint16_t*) &c[offset];
|
2015-09-05 02:51:19 -07:00
|
|
|
for (int i=0;i<len/2;i++) {
|
2015-08-06 17:56:45 -07:00
|
|
|
x[i] = (x[i] ^ y[i]);
|
|
|
|
}
|
2015-09-05 02:51:19 -07:00
|
|
|
} else {
|
2015-08-06 17:56:45 -07:00
|
|
|
for (i = 0; i < len; i++) {
|
2015-09-18 06:46:27 -07:00
|
|
|
data[i] = (data[i] ^ c[i + offset]);
|
2015-08-06 17:56:45 -07:00
|
|
|
}
|
2014-06-17 02:11:41 -07:00
|
|
|
}
|
2014-03-03 11:09:26 -08:00
|
|
|
}
|
|
|
|
|
2015-09-18 06:46:27 -07:00
|
|
|
void srslte_scrambling_b(srslte_sequence_t *s, uint8_t *data) {
|
|
|
|
scrambling_b(s->c, data, 0, s->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void srslte_scrambling_b_offset(srslte_sequence_t *s, uint8_t *data, int offset, int len) {
|
|
|
|
scrambling_b(s->c, data, offset, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void srslte_scrambling_bytes(srslte_sequence_t *s, uint8_t *data) {
|
2015-09-18 15:17:19 -07:00
|
|
|
scrambling_b(s->c_bytes, data, 0, s->len/8);
|
2015-09-18 06:46:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void srslte_scrambling_bytes_offset(srslte_sequence_t *s, uint8_t *data, int offset, int len) {
|
2015-09-18 15:17:19 -07:00
|
|
|
scrambling_b(s->c_bytes, data, offset, len/8);
|
2015-09-18 06:46:27 -07:00
|
|
|
}
|