2015-01-29 16:15:09 -08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
|
|
|
* Copyright 2013-2014 The libLTE Developers. See the
|
|
|
|
* COPYRIGHT file at the top-level directory of this distribution.
|
|
|
|
*
|
|
|
|
* \section LICENSE
|
|
|
|
*
|
|
|
|
* This file is part of the libLTE library.
|
|
|
|
*
|
|
|
|
* libLTE is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* libLTE 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 Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* A copy of the GNU Lesser General Public License can be found in
|
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "liblte/phy/phch/uci.h"
|
|
|
|
#include "liblte/phy/phch/harq.h"
|
2015-02-09 02:32:47 -08:00
|
|
|
#include "liblte/phy/fec/convcoder.h"
|
|
|
|
#include "liblte/phy/fec/crc.h"
|
|
|
|
#include "liblte/phy/fec/rm_conv.h"
|
2015-01-29 16:15:09 -08:00
|
|
|
#include "liblte/phy/common/phy_common.h"
|
|
|
|
#include "liblte/phy/utils/vector.h"
|
2015-02-09 02:32:47 -08:00
|
|
|
#include "liblte/phy/utils/debug.h"
|
2015-01-29 16:15:09 -08:00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, 0, 0, 1, 1 },
|
|
|
|
{1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1 },
|
|
|
|
{1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1 },
|
|
|
|
{1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0 },
|
|
|
|
{1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1 },
|
|
|
|
{1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0 },
|
|
|
|
{1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0 },
|
|
|
|
{1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 },
|
|
|
|
{1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
|
|
|
|
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
|
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
|
|
|
};
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2015-02-09 02:32:47 -08:00
|
|
|
int uci_cqi_init(uci_cqi_t *q) {
|
|
|
|
if (crc_init(&q->crc, LTE_CRC8, 8)) {
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
}
|
|
|
|
return LIBLTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uci_cqi_free(uci_cqi_t *q) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t Q_prime_cqi(uint32_t O, float beta, uint32_t Q_prime_ri, harq_t *harq_process) {
|
|
|
|
uint32_t M_sc = harq_process->prb_alloc.slot[0].nof_prb * RE_X_RB;
|
|
|
|
|
|
|
|
uint32_t K = harq_process->cb_segm.C1*harq_process->cb_segm.K1 +
|
|
|
|
harq_process->cb_segm.C2*harq_process->cb_segm.K2;
|
2015-02-10 07:49:11 -08:00
|
|
|
|
|
|
|
uint32_t Q_prime = 0;
|
|
|
|
if (K > 0) {
|
|
|
|
uint32_t M_sc_init = harq_process->nof_prb_pusch_init * RE_X_RB;
|
|
|
|
uint32_t L = (O<11)?0:8;
|
|
|
|
uint32_t x = (uint32_t) ceilf((float) (O+L)*M_sc_init*harq_process->N_symb_ul*beta/K);
|
2015-02-09 02:32:47 -08:00
|
|
|
|
2015-02-10 07:49:11 -08:00
|
|
|
Q_prime = MIN(x, M_sc * harq_process->N_symb_ul - Q_prime_ri);
|
|
|
|
} else {
|
|
|
|
Q_prime = 12*harq_process->prb_alloc.slot[0].nof_prb*RE_X_RB - Q_prime_ri;
|
|
|
|
}
|
2015-02-09 02:32:47 -08:00
|
|
|
|
|
|
|
return Q_prime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Encode UCI CQI/PMI for payloads equal or lower to 11 bits (Sec 5.2.2.6.4)
|
|
|
|
*/
|
|
|
|
int encode_cqi_short(uci_cqi_t *q, uint8_t *data, uint32_t nof_bits, uint8_t *q_bits, uint32_t Q)
|
2015-01-29 16:15:09 -08:00
|
|
|
{
|
2015-02-09 02:32:47 -08:00
|
|
|
if (nof_bits < MAX_CQI_LEN &&
|
|
|
|
q != NULL &&
|
|
|
|
data != NULL &&
|
|
|
|
q_bits != NULL)
|
|
|
|
{
|
|
|
|
for (int i=0;i<32;i++) {
|
|
|
|
q->encoded_cqi[i] = 0;
|
|
|
|
for (int n=0;n<nof_bits;n++) {
|
|
|
|
q->encoded_cqi[i] += (data[n] * M_basis_seq[i][n]) % 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0;i<Q;i++) {
|
|
|
|
q_bits[i] = q->encoded_cqi[i%32];
|
|
|
|
}
|
|
|
|
return LIBLTE_SUCCESS;
|
|
|
|
} else {
|
|
|
|
return LIBLTE_ERROR_INVALID_INPUTS;
|
|
|
|
}
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
2015-02-09 02:32:47 -08:00
|
|
|
/* Encode UCI CQI/PMI for payloads greater than 11 bits (go through CRC, conv coder and rate match)
|
|
|
|
*/
|
|
|
|
int encode_cqi_long(uci_cqi_t *q, uint8_t *data, uint32_t nof_bits, uint8_t *q_bits, uint32_t Q)
|
|
|
|
{
|
|
|
|
convcoder_t encoder;
|
|
|
|
|
|
|
|
if (nof_bits + 8 < MAX_CQI_LEN &&
|
|
|
|
q != NULL &&
|
|
|
|
data != NULL &&
|
|
|
|
q_bits != NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
int poly[3] = { 0x6D, 0x4F, 0x57 };
|
|
|
|
encoder.K = 7;
|
|
|
|
encoder.R = 3;
|
|
|
|
encoder.tail_biting = true;
|
|
|
|
memcpy(encoder.poly, poly, 3 * sizeof(int));
|
|
|
|
|
|
|
|
memcpy(q->tmp_cqi, data, sizeof(uint8_t) * nof_bits);
|
|
|
|
crc_attach(&q->crc, q->tmp_cqi, nof_bits);
|
|
|
|
|
|
|
|
convcoder_encode(&encoder, q->tmp_cqi, q->encoded_cqi, nof_bits + 8);
|
|
|
|
|
|
|
|
DEBUG("CConv output: ", 0);
|
|
|
|
|
|
|
|
if (VERBOSE_ISDEBUG()) {
|
|
|
|
vec_fprint_b(stdout, q->encoded_cqi, 3 * (nof_bits + 8));
|
|
|
|
}
|
|
|
|
|
|
|
|
rm_conv_tx(q->encoded_cqi, 3 * (nof_bits + 8), q_bits, Q);
|
|
|
|
|
|
|
|
return LIBLTE_SUCCESS;
|
|
|
|
} else {
|
|
|
|
return LIBLTE_ERROR_INVALID_INPUTS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Encode UCI CQI/PMI as described in 5.2.2.6 of 36.212
|
|
|
|
*/
|
|
|
|
int uci_encode_cqi(uci_cqi_t *q, uint8_t *cqi_data, uint32_t cqi_len, float beta, uint32_t Q_prime_ri,
|
|
|
|
harq_t *harq_process, uint8_t *q_bits)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t Q_prime = Q_prime_cqi(cqi_len, beta, Q_prime_ri, harq_process);
|
|
|
|
uint32_t Q_m = lte_mod_bits_x_symbol(harq_process->mcs.mod);
|
|
|
|
|
|
|
|
int ret = LIBLTE_ERROR;
|
|
|
|
if (cqi_len <= 11) {
|
|
|
|
ret = encode_cqi_short(q, cqi_data, cqi_len, q_bits, Q_prime*Q_m);
|
|
|
|
} else {
|
|
|
|
ret = encode_cqi_long(q, cqi_data, cqi_len, q_bits, Q_prime*Q_m);
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
return (int) Q_prime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-10 07:49:11 -08:00
|
|
|
static uint32_t Q_prime_ri_ack(uint32_t O, uint32_t O_cqi, float beta, harq_t *harq_process) {
|
2015-01-29 16:15:09 -08:00
|
|
|
uint32_t M_sc = harq_process->prb_alloc.slot[0].nof_prb * RE_X_RB;
|
|
|
|
|
|
|
|
uint32_t K = harq_process->cb_segm.C1*harq_process->cb_segm.K1 +
|
|
|
|
harq_process->cb_segm.C2*harq_process->cb_segm.K2;
|
2015-02-10 07:49:11 -08:00
|
|
|
|
|
|
|
// If not carrying UL-SCH, get Q_prime according to 5.2.4.1
|
|
|
|
if (K == 0) {
|
|
|
|
K = O_cqi+8;
|
|
|
|
}
|
|
|
|
|
2015-01-29 16:15:09 -08:00
|
|
|
uint32_t M_sc_init = harq_process->nof_prb_pusch_init * RE_X_RB;
|
|
|
|
|
|
|
|
uint32_t x = (uint32_t) ceilf((float) O*M_sc_init*harq_process->N_symb_ul*beta/K);
|
|
|
|
|
|
|
|
uint32_t Q_prime = MIN(x, 4*M_sc);
|
|
|
|
|
|
|
|
return Q_prime;
|
|
|
|
}
|
|
|
|
|
2015-02-09 02:32:47 -08:00
|
|
|
/* Encode UCI RI and HARQ bits as described in 5.2.2.6 of 36.212
|
2015-01-29 16:15:09 -08:00
|
|
|
* Currently only supporting 1-bit RI or 1-bit HARQ
|
|
|
|
*/
|
2015-02-10 07:49:11 -08:00
|
|
|
int uci_encode_ri_ack(uint8_t data, uint32_t O_cqi, float beta, harq_t *harq_process, uint8_t *q_bits)
|
2015-01-29 16:15:09 -08:00
|
|
|
{
|
2015-02-09 02:32:47 -08:00
|
|
|
uint32_t Q_m = lte_mod_bits_x_symbol(harq_process->mcs.mod);
|
2015-01-29 16:15:09 -08:00
|
|
|
|
|
|
|
q_bits[0] = data;
|
|
|
|
q_bits[1] = 2;
|
2015-02-09 02:32:47 -08:00
|
|
|
for (uint32_t i=2;i<Q_m;i++) {
|
2015-01-29 16:15:09 -08:00
|
|
|
q_bits[i] = 3;
|
|
|
|
}
|
|
|
|
|
2015-02-10 07:49:11 -08:00
|
|
|
uint32_t Qprime = Q_prime_ri_ack(1, O_cqi, beta, harq_process);
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2015-02-09 02:32:47 -08:00
|
|
|
for (uint32_t i=1;i<Qprime;i++) {
|
2015-01-29 16:15:09 -08:00
|
|
|
memcpy(&q_bits[i*Q_m], q_bits, Q_m*sizeof(uint8_t));
|
|
|
|
}
|
|
|
|
|
2015-02-09 02:32:47 -08:00
|
|
|
return (int) Qprime;
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|