Example #1
0
void srslte_scrambling_b_offset(srslte_sequence_t *s, uint8_t *data, int offset, int len) {
  if (offset%8) {
    // Do not load words if offset is not word-aligned
    scrambling_b(&s->c[offset], data, len);
  } else {
    scrambling_b_word(&s->c[offset], data, len);      
  }
}
Example #2
0
void srslte_scrambling_bytes(srslte_sequence_t *s, uint8_t *data, int len) {
  scrambling_b_word(s->c_bytes, data, len/8);  
  // Scramble last bits
  if (len%8) {
    uint8_t tmp_bits[8];
    srslte_bit_unpack_vector(&data[len/8], tmp_bits, len%8);
    scrambling_b(&s->c[8*(len/8)], tmp_bits, len%8);
    srslte_bit_pack_vector(tmp_bits, &data[len/8], len%8);
  }    
}
Example #3
0
void scrambling_b_word(uint8_t *c, uint8_t *data, int len) {
  // Do XOR every 64 bits 
  // FIXME: Use 32-bit in 32-bit machines
  uint64_t *x = (uint64_t*) data; 
  uint64_t *y = (uint64_t*) c;
  for (int i=0;i<len/8;i++) {
    x[i] = (x[i] ^ y[i]);
  }
  
  // Do XOR every 8 bits
  scrambling_b(&c[8*(len/8)], &data[8*(len/8)], len%8);
}
Example #4
0
int main(int argc, char **argv) {
  int i;
  sequence_t seq;
  char *input_b, *scrambled_b;
  float *input_f, *scrambled_f;

  parse_args(argc, argv);

  if (init_sequence(&seq, sequence_name) == -1) {
    fprintf(stderr, "Error initiating sequence %s\n", sequence_name);
    exit(-1);
  }

  if (!do_floats) {
    input_b = malloc(sizeof(char) * seq.len);
    if (!input_b) {
      perror("malloc");
      exit(-1);
    }
    scrambled_b = malloc(sizeof(char) * seq.len);
    if (!scrambled_b) {
      perror("malloc");
      exit(-1);
    }

    for (i=0;i<seq.len;i++) {
      input_b[i] = rand()%2;
      scrambled_b[i] = input_b[i];
    }

    scrambling_b(&seq, scrambled_b);
    scrambling_b(&seq, scrambled_b);

    for (i=0;i<seq.len;i++) {
      if (scrambled_b[i] != input_b[i]) {
        printf("Error in %d\n", i);
        exit(-1);
      }
    }
    free(input_b);
    free(scrambled_b);
  } else {
    input_f = malloc(sizeof(float) * seq.len);
    if (!input_f) {
      perror("malloc");
      exit(-1);
    }
    scrambled_f = malloc(sizeof(float) * seq.len);
    if (!scrambled_f) {
      perror("malloc");
      exit(-1);
    }

    for (i=0;i<seq.len;i++) {
      input_f[i] = 100*(rand()/RAND_MAX);
      scrambled_f[i] = input_f[i];
    }

    scrambling_f(&seq, scrambled_f);
    scrambling_f(&seq, scrambled_f);

    for (i=0;i<seq.len;i++) {
      if (scrambled_f[i] != input_f[i]) {
        printf("Error in %d\n", i);
        exit(-1);
      }
    }

    free(input_f);
    free(scrambled_f);
  }
  printf("Ok\n");
  sequence_free(&seq);
  exit(0);
}