|
|
|
@ -25,7 +25,6 @@
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
@ -59,12 +58,12 @@ void dci_free(dci_t *q) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dci_candidate_fprint(FILE *f, dci_candidate_t *q) {
|
|
|
|
|
fprintf(f, "L: %d, nCCE: %d, RNTI: 0x%x, nBits: %d\n",
|
|
|
|
|
q->L, q->ncce, q->rnti, q->nof_bits);
|
|
|
|
|
fprintf(f, "L: %d, nCCE: %d, RNTI: 0x%x, nBits: %d\n", q->L, q->ncce, q->rnti,
|
|
|
|
|
q->nof_bits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dci_msg_candidate_set(dci_msg_t *msg, int L, int nCCE, unsigned short rnti) {
|
|
|
|
|
if (L >= 0 && L <=3) {
|
|
|
|
|
if (L >= 0 && L <= 3) {
|
|
|
|
|
msg->location.L = (unsigned char) L;
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(stderr, "Invalid L %d\n", L);
|
|
|
|
@ -81,14 +80,14 @@ int dci_msg_candidate_set(dci_msg_t *msg, int L, int nCCE, unsigned short rnti)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int riv_nbits(int nof_prb) {
|
|
|
|
|
return (int) ceilf(log2f((float) nof_prb*((float) nof_prb+1)/2));
|
|
|
|
|
return (int) ceilf(log2f((float) nof_prb * ((float) nof_prb + 1) / 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int ambiguous_sizes[10] = {12, 14, 16, 20, 24, 26, 32, 40, 44, 56};
|
|
|
|
|
const int ambiguous_sizes[10] = { 12, 14, 16, 20, 24, 26, 32, 40, 44, 56 };
|
|
|
|
|
|
|
|
|
|
bool is_ambiguous_size(int size) {
|
|
|
|
|
int i;
|
|
|
|
|
for (i=0;i<10;i++) {
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
|
if (size == ambiguous_sizes[i]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -96,20 +95,17 @@ bool is_ambiguous_size(int size) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************
|
|
|
|
|
* PAYLOAD sizeof functions
|
|
|
|
|
* ********************************/
|
|
|
|
|
int dci_format0_sizeof_(int nof_prb) {
|
|
|
|
|
return 1+1+riv_nbits(nof_prb)+5+1+2+3+1;
|
|
|
|
|
return 1 + 1 + riv_nbits(nof_prb) + 5 + 1 + 2 + 3 + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int dci_format1A_sizeof(int nof_prb) {
|
|
|
|
|
int n;
|
|
|
|
|
n = 1+1+riv_nbits(nof_prb)+5+3+1+2+2;
|
|
|
|
|
while(n < dci_format0_sizeof_(nof_prb)) {
|
|
|
|
|
n = 1 + 1 + riv_nbits(nof_prb) + 5 + 3 + 1 + 2 + 2;
|
|
|
|
|
while (n < dci_format0_sizeof_(nof_prb)) {
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
if (is_ambiguous_size(n)) {
|
|
|
|
@ -118,7 +114,6 @@ int dci_format1A_sizeof(int nof_prb) {
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int dci_format0_sizeof(int nof_prb) {
|
|
|
|
|
int n = dci_format0_sizeof_(nof_prb);
|
|
|
|
|
while (n < dci_format1A_sizeof(nof_prb)) {
|
|
|
|
@ -129,12 +124,12 @@ int dci_format0_sizeof(int nof_prb) {
|
|
|
|
|
|
|
|
|
|
int dci_format1_sizeof(int nof_prb) {
|
|
|
|
|
|
|
|
|
|
int n = (int) ceilf((float) nof_prb/ra_type0_P(nof_prb))+5+3+1+2+2;
|
|
|
|
|
int n = (int) ceilf((float) nof_prb / ra_type0_P(nof_prb)) + 5 + 3 + 1 + 2
|
|
|
|
|
+ 2;
|
|
|
|
|
if (nof_prb > 10) {
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
while(n == dci_format0_sizeof(nof_prb)
|
|
|
|
|
|| n == dci_format1A_sizeof(nof_prb)
|
|
|
|
|
while (n == dci_format0_sizeof(nof_prb) || n == dci_format1A_sizeof(nof_prb)
|
|
|
|
|
|| is_ambiguous_size(n)) {
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
@ -144,7 +139,7 @@ int dci_format1_sizeof(int nof_prb) {
|
|
|
|
|
int dci_format1C_sizeof(int nof_prb) {
|
|
|
|
|
int n_vrb_dl_gap1 = ra_type2_n_vrb_dl(nof_prb, true);
|
|
|
|
|
int n_step = ra_type2_n_rb_step(nof_prb);
|
|
|
|
|
int n = + riv_nbits((int) n_vrb_dl_gap1/n_step) + 5;
|
|
|
|
|
int n = +riv_nbits((int) n_vrb_dl_gap1 / n_step) + 5;
|
|
|
|
|
if (nof_prb >= 50) {
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
@ -152,7 +147,7 @@ int dci_format1C_sizeof(int nof_prb) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dci_format_sizeof(dci_format_t format, int nof_prb) {
|
|
|
|
|
switch(format) {
|
|
|
|
|
switch (format) {
|
|
|
|
|
case Format0:
|
|
|
|
|
return dci_format0_sizeof(nof_prb);
|
|
|
|
|
case Format1:
|
|
|
|
@ -166,13 +161,10 @@ int dci_format_sizeof(dci_format_t format, int nof_prb) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************
|
|
|
|
|
* DCI Resource Allocation functions
|
|
|
|
|
* ********************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Packs DCI format 0 data to a sequence of bits and store them in msg according
|
|
|
|
|
* to 36.212 5.3.3.1.1
|
|
|
|
|
*
|
|
|
|
@ -203,7 +195,8 @@ int dci_format0_pack(ra_pusch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
/* pack RIV according to 8.1 of 36.213 */
|
|
|
|
|
uint32_t riv;
|
|
|
|
|
if (data->type2_alloc.L_crb) {
|
|
|
|
|
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start, nof_prb);
|
|
|
|
|
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start,
|
|
|
|
|
nof_prb);
|
|
|
|
|
} else {
|
|
|
|
|
riv = data->type2_alloc.riv;
|
|
|
|
|
}
|
|
|
|
@ -222,7 +215,8 @@ int dci_format0_pack(ra_pusch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
} else {
|
|
|
|
|
if (data->mcs.tbs) {
|
|
|
|
|
if (data->mcs.tbs) {
|
|
|
|
|
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs, ra_nprb_ul(data, nof_prb));
|
|
|
|
|
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs,
|
|
|
|
|
ra_nprb_ul(data, nof_prb));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mcs = ra_mcs_to_table_idx(&data->mcs);
|
|
|
|
@ -248,7 +242,7 @@ int dci_format0_pack(ra_pusch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
|
|
|
|
|
// Padding with zeros
|
|
|
|
|
int n = dci_format0_sizeof(nof_prb);
|
|
|
|
|
while (y-msg->data < n) {
|
|
|
|
|
while (y - msg->data < n) {
|
|
|
|
|
*y++ = 0;
|
|
|
|
|
}
|
|
|
|
|
msg->location.nof_bits = (y - msg->data);
|
|
|
|
@ -271,7 +265,8 @@ int dci_format0_unpack(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (*y++ != 0) {
|
|
|
|
|
fprintf(stderr, "Invalid format differentiation field value. This is Format1A\n");
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid format differentiation field value. This is Format1A\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (*y++ == 0) {
|
|
|
|
@ -283,31 +278,33 @@ int dci_format0_unpack(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
|
|
|
|
|
data->freq_hop_fl = *y++;
|
|
|
|
|
} else {
|
|
|
|
|
n_ul_hop = 2; // Table 8.4-1 of 36.213
|
|
|
|
|
data->freq_hop_fl = y[0]<<1 | y[1];
|
|
|
|
|
data->freq_hop_fl = y[0] << 1 | y[1];
|
|
|
|
|
y += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* unpack RIV according to 8.1 of 36.213 */
|
|
|
|
|
uint32_t riv = bit_unpack(&y, riv_nbits(nof_prb) - n_ul_hop);
|
|
|
|
|
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, nof_prb, nof_prb);
|
|
|
|
|
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start,
|
|
|
|
|
nof_prb, nof_prb);
|
|
|
|
|
bit_pack(riv, &y, riv_nbits(nof_prb) - n_ul_hop);
|
|
|
|
|
data->type2_alloc.riv = riv;
|
|
|
|
|
|
|
|
|
|
/* unpack MCS according to 8.6 of 36.213 */
|
|
|
|
|
uint32_t mcs = bit_unpack(&y, 5);
|
|
|
|
|
|
|
|
|
|
data->ndi = *y++?true:false;
|
|
|
|
|
data->ndi = *y++ ? true : false;
|
|
|
|
|
|
|
|
|
|
// TCP and DM RS commands not implemented
|
|
|
|
|
y+= 5;
|
|
|
|
|
y += 5;
|
|
|
|
|
|
|
|
|
|
// CQI request
|
|
|
|
|
data->cqi_request = *y++?true:false;
|
|
|
|
|
data->cqi_request = *y++ ? true : false;
|
|
|
|
|
|
|
|
|
|
// 8.6.2 First paragraph
|
|
|
|
|
if (mcs <= 28) {
|
|
|
|
|
ra_mcs_from_idx_ul(mcs, &data->mcs);
|
|
|
|
|
data->mcs.tbs = ra_tbs_from_idx(data->mcs.tbs_idx, ra_nprb_ul(data, nof_prb));
|
|
|
|
|
data->mcs.tbs = ra_tbs_from_idx(data->mcs.tbs_idx,
|
|
|
|
|
ra_nprb_ul(data, nof_prb));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 8.6.1 and 8.6.2 36.213 second paragraph
|
|
|
|
@ -340,18 +337,20 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
|
|
|
|
|
/* Resource allocation: type0 or type 1 */
|
|
|
|
|
int P = ra_type0_P(nof_prb);
|
|
|
|
|
int alloc_size = (int) ceilf((float) nof_prb/P);
|
|
|
|
|
switch(data->alloc_type) {
|
|
|
|
|
int alloc_size = (int) ceilf((float) nof_prb / P);
|
|
|
|
|
switch (data->alloc_type) {
|
|
|
|
|
case alloc_type0:
|
|
|
|
|
bit_pack(data->type0_alloc.rbg_bitmask, &y, alloc_size);
|
|
|
|
|
break;
|
|
|
|
|
case alloc_type1:
|
|
|
|
|
bit_pack(data->type1_alloc.rbg_subset, &y, (int) ceilf(log2f(P)));
|
|
|
|
|
*y++ = data->type1_alloc.shift?1:0;
|
|
|
|
|
bit_pack(data->type1_alloc.vrb_bitmask, &y, alloc_size - (int) ceilf(log2f(P)) - 1);
|
|
|
|
|
*y++ = data->type1_alloc.shift ? 1 : 0;
|
|
|
|
|
bit_pack(data->type1_alloc.vrb_bitmask, &y,
|
|
|
|
|
alloc_size - (int) ceilf(log2f(P)) - 1);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "Format 1 accepts type0 or type1 resource allocation only\n");
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Format 1 accepts type0 or type1 resource allocation only\n");
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -361,7 +360,8 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
mcs = data->mcs.mcs_idx;
|
|
|
|
|
} else {
|
|
|
|
|
if (data->mcs.tbs) {
|
|
|
|
|
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs, ra_nprb_dl(data, nof_prb));
|
|
|
|
|
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs,
|
|
|
|
|
ra_nprb_dl(data, nof_prb));
|
|
|
|
|
}
|
|
|
|
|
mcs = ra_mcs_to_table_idx(&data->mcs);
|
|
|
|
|
}
|
|
|
|
@ -381,7 +381,7 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
|
|
|
|
|
// Padding with zeros
|
|
|
|
|
int n = dci_format1_sizeof(nof_prb);
|
|
|
|
|
while (y-msg->data < n) {
|
|
|
|
|
while (y - msg->data < n) {
|
|
|
|
|
*y++ = 0;
|
|
|
|
|
}
|
|
|
|
|
msg->location.nof_bits = (y - msg->data);
|
|
|
|
@ -408,18 +408,20 @@ int dci_format1_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
|
|
|
|
|
|
|
|
|
|
/* Resource allocation: type0 or type 1 */
|
|
|
|
|
int P = ra_type0_P(nof_prb);
|
|
|
|
|
int alloc_size = (int) ceilf((float) nof_prb/P);
|
|
|
|
|
switch(data->alloc_type) {
|
|
|
|
|
int alloc_size = (int) ceilf((float) nof_prb / P);
|
|
|
|
|
switch (data->alloc_type) {
|
|
|
|
|
case alloc_type0:
|
|
|
|
|
data->type0_alloc.rbg_bitmask = bit_unpack(&y, alloc_size);
|
|
|
|
|
break;
|
|
|
|
|
case alloc_type1:
|
|
|
|
|
data->type1_alloc.rbg_subset = bit_unpack(&y, (int) ceilf(log2f(P)));
|
|
|
|
|
data->type1_alloc.shift = *y++?true:false;
|
|
|
|
|
data->type1_alloc.vrb_bitmask = bit_unpack(&y, alloc_size - (int) ceilf(log2f(P)) - 1);
|
|
|
|
|
data->type1_alloc.shift = *y++ ? true : false;
|
|
|
|
|
data->type1_alloc.vrb_bitmask = bit_unpack(&y,
|
|
|
|
|
alloc_size - (int) ceilf(log2f(P)) - 1);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "Format 1 accepts type0 or type1 resource allocation only\n");
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Format 1 accepts type0 or type1 resource allocation only\n");
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -432,23 +434,22 @@ int dci_format1_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
|
|
|
|
|
/* harq process number */
|
|
|
|
|
data->harq_process = bit_unpack(&y, 3);
|
|
|
|
|
|
|
|
|
|
data->ndi = *y++?true:false;
|
|
|
|
|
data->ndi = *y++ ? true : false;
|
|
|
|
|
|
|
|
|
|
// rv version
|
|
|
|
|
data->rv_idx = bit_unpack(&y, 2);
|
|
|
|
|
|
|
|
|
|
// TPC not implemented
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Packs DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3
|
|
|
|
|
*
|
|
|
|
|
* TODO: RA procedure initiated by PDCCH, TPC commands
|
|
|
|
|
*/
|
|
|
|
|
int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_is_crnti) {
|
|
|
|
|
int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb,
|
|
|
|
|
bool crc_is_crnti) {
|
|
|
|
|
|
|
|
|
|
/* pack bits */
|
|
|
|
|
char *y = msg->data;
|
|
|
|
@ -464,7 +465,8 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
|
|
|
|
|
|
|
|
|
|
if (data->type2_alloc.mode == t2_loc) {
|
|
|
|
|
if (data->type2_alloc.L_crb > nof_prb) {
|
|
|
|
|
fprintf(stderr, "L_CRB=%d can not exceed system BW for localized type2\n", data->type2_alloc.L_crb);
|
|
|
|
|
fprintf(stderr, "L_CRB=%d can not exceed system BW for localized type2\n",
|
|
|
|
|
data->type2_alloc.L_crb);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -472,17 +474,20 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
|
|
|
|
|
if (crc_is_crnti && nof_prb > 50) {
|
|
|
|
|
n_vrb_dl = 16;
|
|
|
|
|
} else {
|
|
|
|
|
n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap==t2_ng1);
|
|
|
|
|
n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
|
|
|
|
|
}
|
|
|
|
|
if (data->type2_alloc.L_crb > n_vrb_dl) {
|
|
|
|
|
fprintf(stderr, "L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n", data->type2_alloc.L_crb, n_vrb_dl);
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n",
|
|
|
|
|
data->type2_alloc.L_crb, n_vrb_dl);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* pack RIV according to 7.1.6.3 of 36.213 */
|
|
|
|
|
uint32_t riv;
|
|
|
|
|
if (data->type2_alloc.L_crb) {
|
|
|
|
|
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start, nof_prb);
|
|
|
|
|
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start,
|
|
|
|
|
nof_prb);
|
|
|
|
|
} else {
|
|
|
|
|
riv = data->type2_alloc.riv;
|
|
|
|
|
}
|
|
|
|
@ -491,7 +496,7 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
|
|
|
|
|
nb_gap = 1;
|
|
|
|
|
*y++ = data->type2_alloc.n_gap;
|
|
|
|
|
}
|
|
|
|
|
bit_pack(riv, &y, riv_nbits(nof_prb)-nb_gap);
|
|
|
|
|
bit_pack(riv, &y, riv_nbits(nof_prb) - nb_gap);
|
|
|
|
|
|
|
|
|
|
// in format1A, MCS = TBS according to 7.1.7.2 of 36.213
|
|
|
|
|
uint32_t mcs;
|
|
|
|
@ -504,7 +509,7 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
|
|
|
|
|
if (!crc_is_crnti) {
|
|
|
|
|
n_prb = ra_nprb_dl(data, nof_prb);
|
|
|
|
|
} else {
|
|
|
|
|
n_prb = data->type2_alloc.n_prb1a==nprb1a_2?2:3;
|
|
|
|
|
n_prb = data->type2_alloc.n_prb1a == nprb1a_2 ? 2 : 3;
|
|
|
|
|
}
|
|
|
|
|
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs, n_prb);
|
|
|
|
|
}
|
|
|
|
@ -534,7 +539,7 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
|
|
|
|
|
|
|
|
|
|
// Padding with zeros
|
|
|
|
|
int n = dci_format1A_sizeof(nof_prb);
|
|
|
|
|
while (y-msg->data < n) {
|
|
|
|
|
while (y - msg->data < n) {
|
|
|
|
|
*y++ = 0;
|
|
|
|
|
}
|
|
|
|
|
msg->location.nof_bits = (y - msg->data);
|
|
|
|
@ -545,7 +550,8 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
|
|
|
|
|
/* Unpacks DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc_is_crnti) {
|
|
|
|
|
int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb,
|
|
|
|
|
bool crc_is_crnti) {
|
|
|
|
|
|
|
|
|
|
/* pack bits */
|
|
|
|
|
char *y = msg->data;
|
|
|
|
@ -557,7 +563,8 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*y++ != 1) {
|
|
|
|
|
fprintf(stderr, "Invalid format differentiation field value. This is Format0\n");
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid format differentiation field value. This is Format0\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -580,7 +587,8 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
|
|
|
|
|
nof_vrb = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
|
|
|
|
|
}
|
|
|
|
|
uint32_t riv = bit_unpack(&y, riv_nbits(nof_prb) - nb_gap);
|
|
|
|
|
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, nof_prb, nof_vrb);
|
|
|
|
|
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start,
|
|
|
|
|
nof_prb, nof_vrb);
|
|
|
|
|
data->type2_alloc.riv = riv;
|
|
|
|
|
|
|
|
|
|
// unpack MCS
|
|
|
|
@ -610,7 +618,7 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
|
|
|
|
|
if (crc_is_crnti) {
|
|
|
|
|
n_prb = ra_nprb_dl(data, nof_prb);
|
|
|
|
|
} else {
|
|
|
|
|
n_prb = data->type2_alloc.n_prb1a==nprb1a_2?2:3;
|
|
|
|
|
n_prb = data->type2_alloc.n_prb1a == nprb1a_2 ? 2 : 3;
|
|
|
|
|
}
|
|
|
|
|
data->mcs.tbs = ra_tbs_from_idx(data->mcs.tbs_idx, n_prb);
|
|
|
|
|
data->mcs.mod = QPSK;
|
|
|
|
@ -627,7 +635,8 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
char *y = msg->data;
|
|
|
|
|
|
|
|
|
|
if (data->alloc_type != alloc_type2 || data->type2_alloc.mode != t2_dist) {
|
|
|
|
|
fprintf(stderr, "Format 1C accepts distributed type2 resource allocation only\n");
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Format 1C accepts distributed type2 resource allocation only\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -635,11 +644,12 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
*y++ = data->type2_alloc.n_gap;
|
|
|
|
|
}
|
|
|
|
|
int n_step = ra_type2_n_rb_step(nof_prb);
|
|
|
|
|
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap==t2_ng1);
|
|
|
|
|
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
|
|
|
|
|
|
|
|
|
|
if (data->type2_alloc.L_crb > ((int) n_vrb_dl/n_step)*n_step) {
|
|
|
|
|
fprintf(stderr, "L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n", data->type2_alloc.L_crb,
|
|
|
|
|
((int) n_vrb_dl/n_step)*n_step);
|
|
|
|
|
if (data->type2_alloc.L_crb > ((int) n_vrb_dl / n_step) * n_step) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n",
|
|
|
|
|
data->type2_alloc.L_crb, ((int) n_vrb_dl / n_step) * n_step);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (data->type2_alloc.L_crb % n_step) {
|
|
|
|
@ -650,8 +660,8 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
fprintf(stderr, "RB_start must be multiple of n_step\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
int L_p = data->type2_alloc.L_crb/n_step;
|
|
|
|
|
int RB_p = data->type2_alloc.RB_start/n_step;
|
|
|
|
|
int L_p = data->type2_alloc.L_crb / n_step;
|
|
|
|
|
int RB_p = data->type2_alloc.RB_start / n_step;
|
|
|
|
|
int n_vrb_p = (int) n_vrb_dl / n_step;
|
|
|
|
|
|
|
|
|
|
uint32_t riv;
|
|
|
|
@ -660,7 +670,7 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
|
|
|
|
|
} else {
|
|
|
|
|
riv = data->type2_alloc.riv;
|
|
|
|
|
}
|
|
|
|
|
bit_pack(riv, &y, riv_nbits((int) n_vrb_dl/n_step));
|
|
|
|
|
bit_pack(riv, &y, riv_nbits((int) n_vrb_dl / n_step));
|
|
|
|
|
|
|
|
|
|
// in format1C, MCS = TBS according to 7.1.7.2 of 36.213
|
|
|
|
|
uint32_t mcs;
|
|
|
|
@ -695,9 +705,9 @@ int dci_format1Cs_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
|
|
|
|
|
data->type2_alloc.n_gap = *y++;
|
|
|
|
|
}
|
|
|
|
|
int n_step = ra_type2_n_rb_step(nof_prb);
|
|
|
|
|
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap==t2_ng1);
|
|
|
|
|
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
|
|
|
|
|
|
|
|
|
|
uint32_t riv = bit_unpack(&y, riv_nbits((int) n_vrb_dl/n_step));
|
|
|
|
|
uint32_t riv = bit_unpack(&y, riv_nbits((int) n_vrb_dl / n_step));
|
|
|
|
|
int n_vrb_p = (int) n_vrb_dl / n_step;
|
|
|
|
|
|
|
|
|
|
ra_type2_from_riv(riv, &L_p, &RB_p, n_vrb_p, n_vrb_p);
|
|
|
|
@ -715,8 +725,9 @@ int dci_format1Cs_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format, int nof_prb, bool crc_is_crnti) {
|
|
|
|
|
switch(format) {
|
|
|
|
|
int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format,
|
|
|
|
|
int nof_prb, bool crc_is_crnti) {
|
|
|
|
|
switch (format) {
|
|
|
|
|
case Format1:
|
|
|
|
|
return dci_format1_pack(data, msg, nof_prb);
|
|
|
|
|
case Format1A:
|
|
|
|
@ -724,12 +735,14 @@ int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format, in
|
|
|
|
|
case Format1C:
|
|
|
|
|
return dci_format1Cs_pack(data, msg, nof_prb);
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "Invalid DCI format %s for PDSCH resource allocation\n", dci_format_string(format));
|
|
|
|
|
fprintf(stderr, "Invalid DCI format %s for PDSCH resource allocation\n",
|
|
|
|
|
dci_format_string(format));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dci_msg_unpack_pdsch(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc_is_crnti) {
|
|
|
|
|
int dci_msg_unpack_pdsch(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb,
|
|
|
|
|
bool crc_is_crnti) {
|
|
|
|
|
if (msg->location.nof_bits == dci_format_sizeof(Format1, nof_prb)) {
|
|
|
|
|
return dci_format1_unpack(msg, data, nof_prb);
|
|
|
|
|
} else if (msg->location.nof_bits == dci_format_sizeof(Format1A, nof_prb)) {
|
|
|
|
@ -750,7 +763,7 @@ int dci_msg_unpack_pusch(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* dci_format_string(dci_format_t format) {
|
|
|
|
|
switch(format) {
|
|
|
|
|
switch (format) {
|
|
|
|
|
case Format0:
|
|
|
|
|
return "Format0";
|
|
|
|
|
case Format1:
|
|
|
|
@ -765,26 +778,28 @@ char* dci_format_string(dci_format_t format) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dci_msg_type_fprint(FILE *f, dci_msg_type_t type) {
|
|
|
|
|
switch(type.type) {
|
|
|
|
|
switch (type.type) {
|
|
|
|
|
case PUSCH_SCHED:
|
|
|
|
|
fprintf(f,"%s PUSCH Scheduling\n", dci_format_string(type.format));
|
|
|
|
|
fprintf(f, "%s PUSCH Scheduling\n", dci_format_string(type.format));
|
|
|
|
|
break;
|
|
|
|
|
case PDSCH_SCHED:
|
|
|
|
|
fprintf(f,"%s PDSCH Scheduling\n", dci_format_string(type.format));
|
|
|
|
|
fprintf(f, "%s PDSCH Scheduling\n", dci_format_string(type.format));
|
|
|
|
|
break;
|
|
|
|
|
case RA_PROC_PDCCH:
|
|
|
|
|
fprintf(f,"%s Random access initiated by PDCCH\n", dci_format_string(type.format));
|
|
|
|
|
fprintf(f, "%s Random access initiated by PDCCH\n",
|
|
|
|
|
dci_format_string(type.format));
|
|
|
|
|
break;
|
|
|
|
|
case MCCH_CHANGE:
|
|
|
|
|
fprintf(f,"%s MCCH change notification\n", dci_format_string(type.format));
|
|
|
|
|
fprintf(f, "%s MCCH change notification\n", dci_format_string(type.format));
|
|
|
|
|
break;
|
|
|
|
|
case TPC_COMMAND:
|
|
|
|
|
fprintf(f,"%s TPC command\n", dci_format_string(type.format));
|
|
|
|
|
fprintf(f, "%s TPC command\n", dci_format_string(type.format));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, int nof_prb, unsigned short crnti) {
|
|
|
|
|
int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, int nof_prb,
|
|
|
|
|
unsigned short crnti) {
|
|
|
|
|
if (msg->location.nof_bits == dci_format_sizeof(Format0, nof_prb)
|
|
|
|
|
&& !msg->data[0]) {
|
|
|
|
|
type->type = PUSCH_SCHED;
|
|
|
|
|