diff --git a/srslte/examples/pdsch_enodeb.c b/srslte/examples/pdsch_enodeb.c index a551d8e31..f1c4a1211 100644 --- a/srslte/examples/pdsch_enodeb.c +++ b/srslte/examples/pdsch_enodeb.c @@ -422,7 +422,7 @@ void *net_thread_fnc(void *arg) { while (rpm >= nbytes) { // wait for packet to be transmitted sem_wait(&net_sem); - srslte_bit_pack_vector(&data_unpacked[wpm], data, nbytes*8); + srslte_bit_unpack_vector(&data_unpacked[wpm], data, nbytes*8); INFO("Sent %d/%d bytes ready\n", nbytes, rpm); rpm -= nbytes; wpm += nbytes; @@ -590,7 +590,7 @@ int main(int argc, char **argv) { } if (net_port > 0 && net_packet_ready) { if (null_file_sink) { - srslte_bit_unpack_vector(data, data_tmp, pdsch_cfg.grant.mcs.tbs); + srslte_bit_pack_vector(data, data_tmp, pdsch_cfg.grant.mcs.tbs); if (srslte_netsink_write(&net_sink, data_tmp, 1+(pdsch_cfg.grant.mcs.tbs-1)/8) < 0) { fprintf(stderr, "Error sending data through UDP socket\n"); } diff --git a/srslte/examples/prach_ue.c b/srslte/examples/prach_ue.c index 80ac8533e..db37631b4 100644 --- a/srslte/examples/prach_ue.c +++ b/srslte/examples/prach_ue.c @@ -264,20 +264,20 @@ int rar_unpack(uint8_t *buffer, rar_msg_t *msg) msg->hdr_type = *ptr++; if(msg->hdr_type == rar_header_type_bi) { ptr += 2; - msg->BI = srslte_bit_unpack(&ptr, 4); + msg->BI = srslte_bit_pack(&ptr, 4); ret = SRSLTE_SUCCESS; } else if (msg->hdr_type == rar_header_type_rapid) { - msg->RAPID = srslte_bit_unpack(&ptr, 6); + msg->RAPID = srslte_bit_pack(&ptr, 6); ptr++; - msg->timing_adv_cmd = srslte_bit_unpack(&ptr, 11); + msg->timing_adv_cmd = srslte_bit_pack(&ptr, 11); msg->hopping_flag = *ptr++; - msg->rba = srslte_bit_unpack(&ptr, 10); - msg->mcs = srslte_bit_unpack(&ptr, 4); - msg->tpc_command = (rar_tpc_command_t) srslte_bit_unpack(&ptr, 3); + msg->rba = srslte_bit_pack(&ptr, 10); + msg->mcs = srslte_bit_pack(&ptr, 4); + msg->tpc_command = (rar_tpc_command_t) srslte_bit_pack(&ptr, 3); msg->ul_delay = *ptr++; msg->csi_req = *ptr++; - msg->temp_c_rnti = srslte_bit_unpack(&ptr, 16); + msg->temp_c_rnti = srslte_bit_pack(&ptr, 16); ret = SRSLTE_SUCCESS; } } @@ -504,7 +504,7 @@ cell.nof_ports = 1; srslte_ue_sync_get_last_timestamp(&ue_sync, &uhd_time); - srslte_bit_pack_vector((uint8_t*) conn_request_msg, data, ra_grant.mcs.tbs); + srslte_bit_unpack_vector((uint8_t*) conn_request_msg, data, ra_grant.mcs.tbs); uint32_t n_ta = srslte_N_ta_new_rar(rar_msg.timing_adv_cmd); printf("ta: %d, n_ta: %d\n", rar_msg.timing_adv_cmd, n_ta); diff --git a/srslte/include/srslte/utils/bit.h b/srslte/include/srslte/utils/bit.h index 78341da73..dc5193a23 100644 --- a/srslte/include/srslte/utils/bit.h +++ b/srslte/include/srslte/utils/bit.h @@ -41,25 +41,25 @@ #include "srslte/config.h" -SRSLTE_API void srslte_bit_pack_vector(uint8_t *srslte_bit_unpacked, +SRSLTE_API void srslte_bit_unpack_vector(uint8_t *srslte_bit_packed, uint8_t *bits_packed, int nof_bits); -SRSLTE_API void srslte_bit_unpack_vector(uint8_t *bits_packed, - uint8_t *srslte_bit_unpacked, +SRSLTE_API void srslte_bit_pack_vector(uint8_t *bits_packed, + uint8_t *srslte_bit_packed, int nof_bits); -SRSLTE_API uint32_t srslte_bit_unpack(uint8_t **bits, +SRSLTE_API uint32_t srslte_bit_pack(uint8_t **bits, int nof_bits); -SRSLTE_API uint64_t srslte_bit_unpack_l(uint8_t **bits, +SRSLTE_API uint64_t srslte_bit_pack_l(uint8_t **bits, int nof_bits); -SRSLTE_API void srslte_bit_pack_l(uint64_t value, +SRSLTE_API void srslte_bit_unpack_l(uint64_t value, uint8_t **bits, int nof_bits); -SRSLTE_API void srslte_bit_pack(uint32_t value, +SRSLTE_API void srslte_bit_unpack(uint32_t value, uint8_t **bits, int nof_bits); diff --git a/srslte/lib/fec/src/crc.c b/srslte/lib/fec/src/crc.c index 3b3d4881e..b2935b279 100644 --- a/srslte/lib/fec/src/crc.c +++ b/srslte/lib/fec/src/crc.c @@ -136,7 +136,7 @@ uint32_t srslte_crc_checksum(srslte_crc_t *h, uint8_t *data, int len) { byte |= ((uint8_t) *(pter + k)) << (7 - k); } } else { - byte = (uint8_t) (srslte_bit_unpack(&pter, 8) & 0xFF); + byte = (uint8_t) (srslte_bit_pack(&pter, 8) & 0xFF); } crc = crctable(h, byte); } @@ -185,7 +185,7 @@ uint32_t srslte_crc_attach(srslte_crc_t *h, uint8_t *data, int len) { // Add CRC uint8_t *ptr = &data[len]; - srslte_bit_pack(checksum, &ptr, h->order); + srslte_bit_unpack(checksum, &ptr, h->order); return checksum; } diff --git a/srslte/lib/fec/src/turbocoder.c b/srslte/lib/fec/src/turbocoder.c index 03d28bba1..443b7345d 100644 --- a/srslte/lib/fec/src/turbocoder.c +++ b/srslte/lib/fec/src/turbocoder.c @@ -265,7 +265,7 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, uint8_t *input, uint8_t *output, ui k++; } - srslte_bit_unpack_vector(tail, &output[2*(long_cb/8)], TOTALTAIL); + srslte_bit_pack_vector(tail, &output[2*(long_cb/8)], TOTALTAIL); return 2*long_cb+TOTALTAIL; } diff --git a/srslte/lib/fec/test/turbocoder_test.c b/srslte/lib/fec/test/turbocoder_test.c index 12e1858a9..e890e0b47 100644 --- a/srslte/lib/fec/test/turbocoder_test.c +++ b/srslte/lib/fec/test/turbocoder_test.c @@ -90,7 +90,7 @@ int main(int argc, char **argv) { input_bytes[i] = rand()%256; } - srslte_bit_pack_vector(input_bytes, input_bits, long_cb); + srslte_bit_unpack_vector(input_bytes, input_bits, long_cb); if (SRSLTE_VERBOSE_ISINFO()) { printf("Input bits:\n"); @@ -102,7 +102,7 @@ int main(int argc, char **argv) { srslte_tcod_encode(&tcod, input_bits, output_bits, long_cb); srslte_tcod_encode_lut(&tcod, input_bytes, output_bytes, long_cb); - srslte_bit_pack_vector(output_bytes, output_bits2, 2*long_cb+12); + srslte_bit_unpack_vector(output_bytes, output_bits2, 2*long_cb+12); /* de-Interleace bits for comparison */ for (int i=0;inbits_x_symbol) { - idx = srslte_bit_unpack(&b_ptr,q->nbits_x_symbol); + idx = srslte_bit_pack(&b_ptr,q->nbits_x_symbol); if (idx < q->nsymbols) { symbols[j] = q->symbol_table[idx]; } else { diff --git a/srslte/lib/phch/src/cqi.c b/srslte/lib/phch/src/cqi.c index b4a24582f..61d0060f3 100644 --- a/srslte/lib/phch/src/cqi.c +++ b/srslte/lib/phch/src/cqi.c @@ -44,8 +44,8 @@ int srslte_cqi_hl_subband_pack(srslte_cqi_hl_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS]) { uint8_t *body_ptr = buff; - srslte_bit_pack(msg->wideband_cqi, &body_ptr, 4); - srslte_bit_pack(msg->subband_diff_cqi, &body_ptr, 2*msg->N); + srslte_bit_unpack(msg->wideband_cqi, &body_ptr, 4); + srslte_bit_unpack(msg->subband_diff_cqi, &body_ptr, 2*msg->N); return 4+2*msg->N; } @@ -53,9 +53,9 @@ int srslte_cqi_hl_subband_pack(srslte_cqi_hl_subband_t *msg, uint8_t buff[SRSLTE int srslte_cqi_ue_subband_pack(srslte_cqi_ue_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS]) { uint8_t *body_ptr = buff; - srslte_bit_pack(msg->wideband_cqi, &body_ptr, 4); - srslte_bit_pack(msg->subband_diff_cqi, &body_ptr, 2); - srslte_bit_pack(msg->subband_diff_cqi, &body_ptr, msg->L); + srslte_bit_unpack(msg->wideband_cqi, &body_ptr, 4); + srslte_bit_unpack(msg->subband_diff_cqi, &body_ptr, 2); + srslte_bit_unpack(msg->subband_diff_cqi, &body_ptr, msg->L); return 4+2+msg->L; } @@ -63,15 +63,15 @@ int srslte_cqi_ue_subband_pack(srslte_cqi_ue_subband_t *msg, uint8_t buff[SRSLTE int srslte_cqi_format2_wideband_pack(srslte_cqi_format2_wideband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS]) { uint8_t *body_ptr = buff; - srslte_bit_pack(msg->wideband_cqi, &body_ptr, 4); + srslte_bit_unpack(msg->wideband_cqi, &body_ptr, 4); return 4; } int srslte_cqi_format2_subband_pack(srslte_cqi_format2_subband_t *msg, uint8_t buff[SRSLTE_CQI_MAX_BITS]) { uint8_t *body_ptr = buff; - srslte_bit_pack(msg->subband_cqi, &body_ptr, 4); - srslte_bit_pack(msg->subband_label, &body_ptr, msg->subband_label_2_bits?2:1); + srslte_bit_unpack(msg->subband_cqi, &body_ptr, 4); + srslte_bit_unpack(msg->subband_label, &body_ptr, msg->subband_label_2_bits?2:1); return 4+msg->subband_label_2_bits?2:1; } diff --git a/srslte/lib/phch/src/dci.c b/srslte/lib/phch/src/dci.c index 9d9a75085..7f9870f63 100644 --- a/srslte/lib/phch/src/dci.c +++ b/srslte/lib/phch/src/dci.c @@ -141,12 +141,12 @@ int srslte_dci_rar_to_ul_grant(srslte_dci_rar_grant_t *rar, uint32_t nof_prb, void srslte_dci_rar_grant_unpack(srslte_dci_rar_grant_t *rar, uint8_t grant[SRSLTE_RAR_GRANT_LEN]) { uint8_t *grant_ptr = grant; - rar->hopping_flag = srslte_bit_unpack(&grant_ptr, 1)?true:false; - rar->rba = srslte_bit_unpack(&grant_ptr, 10); - rar->trunc_mcs = srslte_bit_unpack(&grant_ptr, 4); - rar->tpc_pusch = srslte_bit_unpack(&grant_ptr, 3); - rar->ul_delay = srslte_bit_unpack(&grant_ptr, 1)?true:false; - rar->cqi_request = srslte_bit_unpack(&grant_ptr, 1)?true:false; + rar->hopping_flag = srslte_bit_pack(&grant_ptr, 1)?true:false; + rar->rba = srslte_bit_pack(&grant_ptr, 10); + rar->trunc_mcs = srslte_bit_pack(&grant_ptr, 4); + rar->tpc_pusch = srslte_bit_pack(&grant_ptr, 3); + rar->ul_delay = srslte_bit_pack(&grant_ptr, 1)?true:false; + rar->cqi_request = srslte_bit_pack(&grant_ptr, 1)?true:false; } void srslte_dci_rar_grant_fprint(FILE *stream, srslte_dci_rar_grant_t *rar) { @@ -341,10 +341,10 @@ int dci_format0_pack(srslte_ra_ul_dci_t *data, srslte_dci_msg_t *msg, uint32_t n riv = data->type2_alloc.riv; } - srslte_bit_pack(riv, &y, riv_nbits(nof_prb) - n_ul_hop); + srslte_bit_unpack(riv, &y, riv_nbits(nof_prb) - n_ul_hop); /* pack MCS according to 8.6.1 of 36.213 */ - srslte_bit_pack(data->mcs_idx, &y, 5); + srslte_bit_unpack(data->mcs_idx, &y, 5); *y++ = data->ndi; @@ -402,21 +402,21 @@ int dci_format0_unpack(srslte_dci_msg_t *msg, srslte_ra_ul_dci_t *data, uint32_t } } /* unpack RIV according to 8.1 of 36.213 */ - uint32_t riv = srslte_bit_unpack(&y, riv_nbits(nof_prb) - n_ul_hop); + uint32_t riv = srslte_bit_pack(&y, riv_nbits(nof_prb) - n_ul_hop); srslte_ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, nof_prb, nof_prb); data->type2_alloc.riv = riv; /* unpack MCS according to 8.6 of 36.213 */ - data->mcs_idx = srslte_bit_unpack(&y, 5); + data->mcs_idx = srslte_bit_pack(&y, 5); data->ndi = *y++ ? true : false; // TPC command for scheduled PUSCH - data->tpc_pusch = srslte_bit_unpack(&y, 2); + data->tpc_pusch = srslte_bit_pack(&y, 2); // Cyclic shift for DMRS - data->n_dmrs = srslte_bit_unpack(&y, 3); + data->n_dmrs = srslte_bit_pack(&y, 3); // CQI request data->cqi_request = *y++ ? true : false; @@ -444,12 +444,12 @@ int dci_format1_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t n uint32_t alloc_size = (uint32_t) ceilf((float) nof_prb / P); switch (data->alloc_type) { case SRSLTE_RA_ALLOC_TYPE0: - srslte_bit_pack((uint32_t) data->type0_alloc.rbg_bitmask, &y, alloc_size); + srslte_bit_unpack((uint32_t) data->type0_alloc.rbg_bitmask, &y, alloc_size); break; case SRSLTE_RA_ALLOC_TYPE1: - srslte_bit_pack((uint32_t) data->type1_alloc.rbg_subset, &y, (int) ceilf(log2f(P))); + srslte_bit_unpack((uint32_t) data->type1_alloc.rbg_subset, &y, (int) ceilf(log2f(P))); *y++ = data->type1_alloc.shift ? 1 : 0; - srslte_bit_pack((uint32_t) data->type1_alloc.vrb_bitmask, &y, + srslte_bit_unpack((uint32_t) data->type1_alloc.vrb_bitmask, &y, alloc_size - (int) ceilf(log2f(P)) - 1); break; default: @@ -459,15 +459,15 @@ int dci_format1_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t n } /* pack MCS */ - srslte_bit_pack(data->mcs_idx, &y, 5); + srslte_bit_unpack(data->mcs_idx, &y, 5); /* harq process number */ - srslte_bit_pack(data->harq_process, &y, 3); + srslte_bit_unpack(data->harq_process, &y, 3); *y++ = data->ndi; // rv version - srslte_bit_pack(data->rv_idx, &y, 2); + srslte_bit_unpack(data->rv_idx, &y, 2); // TPC not implemented *y++ = 0; @@ -505,12 +505,12 @@ int dci_format1_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32_t uint32_t alloc_size = (uint32_t) ceilf((float) nof_prb / P); switch (data->alloc_type) { case SRSLTE_RA_ALLOC_TYPE0: - data->type0_alloc.rbg_bitmask = srslte_bit_unpack(&y, alloc_size); + data->type0_alloc.rbg_bitmask = srslte_bit_pack(&y, alloc_size); break; case SRSLTE_RA_ALLOC_TYPE1: - data->type1_alloc.rbg_subset = srslte_bit_unpack(&y, (int) ceilf(log2f(P))); + data->type1_alloc.rbg_subset = srslte_bit_pack(&y, (int) ceilf(log2f(P))); data->type1_alloc.shift = *y++ ? true : false; - data->type1_alloc.vrb_bitmask = srslte_bit_unpack(&y, + data->type1_alloc.vrb_bitmask = srslte_bit_pack(&y, alloc_size - (int) ceilf(log2f(P)) - 1); break; default: @@ -519,14 +519,14 @@ int dci_format1_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32_t } /* unpack MCS according to 7.1.7 of 36.213 */ - data->mcs_idx = srslte_bit_unpack(&y, 5); + data->mcs_idx = srslte_bit_pack(&y, 5); /* harq process number */ - data->harq_process = srslte_bit_unpack(&y, 3); + data->harq_process = srslte_bit_pack(&y, 3); data->ndi = *y++ ? true : false; // rv version - data->rv_idx = srslte_bit_unpack(&y, 2); + data->rv_idx = srslte_bit_pack(&y, 2); // TPC not implemented @@ -588,12 +588,12 @@ int dci_format1As_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t nb_gap = 1; *y++ = data->type2_alloc.n_gap; } - srslte_bit_pack(riv, &y, riv_nbits(nof_prb) - nb_gap); + srslte_bit_unpack(riv, &y, riv_nbits(nof_prb) - nb_gap); // in format1A, MCS = TBS according to 7.1.7.2 of 36.213 - srslte_bit_pack(data->mcs_idx, &y, 5); + srslte_bit_unpack(data->mcs_idx, &y, 5); - srslte_bit_pack(data->harq_process, &y, 3); + srslte_bit_unpack(data->harq_process, &y, 3); if (!crc_is_crnti && nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) { *y++ = data->type2_alloc.n_gap; @@ -602,7 +602,7 @@ int dci_format1As_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t } // rv version - srslte_bit_pack(data->rv_idx, &y, 2); + srslte_bit_unpack(data->rv_idx, &y, 2); if (crc_is_crnti) { // TPC not implemented @@ -661,15 +661,15 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32 } else { nof_vrb = srslte_ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == SRSLTE_RA_TYPE2_NG1); } - uint32_t riv = srslte_bit_unpack(&y, riv_nbits(nof_prb) - nb_gap); + uint32_t riv = srslte_bit_pack(&y, riv_nbits(nof_prb) - nb_gap); srslte_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 - data->mcs_idx = srslte_bit_unpack(&y, 5); + data->mcs_idx = srslte_bit_pack(&y, 5); - data->harq_process = srslte_bit_unpack(&y, 3); + data->harq_process = srslte_bit_pack(&y, 3); if (!crc_is_crnti) { if (nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) { @@ -682,7 +682,7 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32 } // rv version - data->rv_idx = srslte_bit_unpack(&y, 2); + data->rv_idx = srslte_bit_pack(&y, 2); if (crc_is_crnti) { // TPC not implemented @@ -741,10 +741,10 @@ int dci_format1Cs_pack(srslte_ra_dl_dci_t *data, srslte_dci_msg_t *msg, uint32_t } else { riv = data->type2_alloc.riv; } - srslte_bit_pack(riv, &y, riv_nbits((int) n_vrb_dl / n_step)); + srslte_bit_unpack(riv, &y, riv_nbits((int) n_vrb_dl / n_step)); // in format1C, MCS = TBS according to 7.1.7.2 of 36.213 - srslte_bit_pack(data->mcs_idx, &y, 5); + srslte_bit_unpack(data->mcs_idx, &y, 5); msg->nof_bits = (y - msg->data); @@ -769,7 +769,7 @@ int dci_format1Cs_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32 uint32_t n_step = srslte_ra_type2_n_rb_step(nof_prb); uint32_t n_vrb_dl = srslte_ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == SRSLTE_RA_TYPE2_NG1); - uint32_t riv = srslte_bit_unpack(&y, riv_nbits((int) n_vrb_dl / n_step)); + uint32_t riv = srslte_bit_pack(&y, riv_nbits((int) n_vrb_dl / n_step)); uint32_t n_vrb_p = (uint32_t) n_vrb_dl / n_step; srslte_ra_type2_from_riv(riv, &L_p, &RB_p, n_vrb_p, n_vrb_p); @@ -777,7 +777,7 @@ int dci_format1Cs_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32 data->type2_alloc.RB_start = RB_p * n_step; data->type2_alloc.riv = riv; - data->mcs_idx = srslte_bit_unpack(&y, 5); + data->mcs_idx = srslte_bit_pack(&y, 5); data->dci_format = SRSLTE_RA_DCI_FORMAT1C; diff --git a/srslte/lib/phch/src/pbch.c b/srslte/lib/phch/src/pbch.c index 2c7c0180f..b0683773f 100644 --- a/srslte/lib/phch/src/pbch.c +++ b/srslte/lib/phch/src/pbch.c @@ -261,7 +261,7 @@ void srslte_pbch_free(srslte_pbch_t *q) { void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) { int phich_res; - cell->bw_idx = srslte_bit_unpack(&msg, 3); + cell->bw_idx = srslte_bit_pack(&msg, 3); switch (cell->bw_idx) { case 0: cell->nof_prb = 6; @@ -280,7 +280,7 @@ void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) { } msg++; - phich_res = srslte_bit_unpack(&msg, 2); + phich_res = srslte_bit_pack(&msg, 2); switch (phich_res) { case 0: cell->phich_resources = SRSLTE_PHICH_SRSLTE_PHICH_R_1_6; @@ -296,7 +296,7 @@ void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) { break; } if (sfn) { - *sfn = srslte_bit_unpack(&msg, 8) << 2; + *sfn = srslte_bit_pack(&msg, 8) << 2; } } @@ -315,7 +315,7 @@ void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg) { } else { bw = 1 + cell->nof_prb / 25; } - srslte_bit_pack(bw, &msg, 3); + srslte_bit_unpack(bw, &msg, 3); *msg = cell->phich_length == SRSLTE_PHICH_EXT; msg++; @@ -334,8 +334,8 @@ void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg) { phich_res = 3; break; } - srslte_bit_pack(phich_res, &msg, 2); - srslte_bit_pack(sfn >> 2, &msg, 8); + srslte_bit_unpack(phich_res, &msg, 2); + srslte_bit_unpack(sfn >> 2, &msg, 8); } void srslte_pbch_decode_reset(srslte_pbch_t *q) { diff --git a/srslte/lib/phch/src/pdcch.c b/srslte/lib/phch/src/pdcch.c index 054761f97..01f7c2185 100644 --- a/srslte/lib/phch/src/pdcch.c +++ b/srslte/lib/phch/src/pdcch.c @@ -296,7 +296,7 @@ static int dci_decode(srslte_pdcch_t *q, float *e, uint8_t *data, uint32_t E, ui } x = &data[nof_bits]; - p_bits = (uint16_t) srslte_bit_unpack(&x, 16); + p_bits = (uint16_t) srslte_bit_pack(&x, 16); crc_res = ((uint16_t) srslte_crc_checksum(&q->crc, data, nof_bits) & 0xffff); DEBUG("p_bits: 0x%x, crc_checksum: 0x%x, crc_rem: 0x%x\n", p_bits, crc_res, p_bits ^ crc_res); @@ -444,7 +444,7 @@ static void crc_set_mask_rnti(uint8_t *crc, uint16_t rnti) { DEBUG("Mask CRC with RNTI 0x%x\n", rnti); - srslte_bit_pack(rnti, &r, 16); + srslte_bit_unpack(rnti, &r, 16); for (i = 0; i < 16; i++) { crc[i] = (crc[i] + mask[i]) % 2; } diff --git a/srslte/lib/phch/src/sch.c b/srslte/lib/phch/src/sch.c index 43ab320d3..a50a0a61f 100644 --- a/srslte/lib/phch/src/sch.c +++ b/srslte/lib/phch/src/sch.c @@ -260,7 +260,7 @@ static int encode_tb(srslte_sch_t *q, } /* pack bits to temporal buffer for encoding */ - srslte_bit_pack_vector(q->cb_in, q->cb_temp, cb_len); + srslte_bit_unpack_vector(q->cb_in, q->cb_temp, cb_len); /* Set the filler bits to */ for (int j = 0; j < F; j++) { diff --git a/srslte/lib/phch/test/dci_unpacking.c b/srslte/lib/phch/test/dci_unpacking.c index 3c0f4ebc3..dbca82298 100644 --- a/srslte/lib/phch/test/dci_unpacking.c +++ b/srslte/lib/phch/test/dci_unpacking.c @@ -67,9 +67,9 @@ int main(int argc, char **argv) { for (i = 0; i < nwords; i++) { x = strtoul(argv[i + 3], NULL, 16); if (len - rlen < 32) { - srslte_bit_pack(x, &y, len - rlen); + srslte_bit_unpack(x, &y, len - rlen); } else { - srslte_bit_pack(x, &y, 32); + srslte_bit_unpack(x, &y, 32); } } diff --git a/srslte/lib/phch/test/dlsch_encode_test_mex.c b/srslte/lib/phch/test/dlsch_encode_test_mex.c index 7e4cd3a2c..1ad44b34d 100644 --- a/srslte/lib/phch/test/dlsch_encode_test_mex.c +++ b/srslte/lib/phch/test/dlsch_encode_test_mex.c @@ -69,7 +69,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) return; } uint8_t *trblkin = srslte_vec_malloc(cfg.grant.mcs.tbs/8); - srslte_bit_unpack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs); + srslte_bit_pack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs); free(trblkin_bits); if (mexutils_read_uint32_struct(PUSCHCFG, "RV", &cfg.rv)) { diff --git a/srslte/lib/phch/test/pdsch_test_mex.c b/srslte/lib/phch/test/pdsch_test_mex.c index 55527b634..d22a8b79c 100644 --- a/srslte/lib/phch/test/pdsch_test_mex.c +++ b/srslte/lib/phch/test/pdsch_test_mex.c @@ -217,7 +217,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) free(data_bytes); uint8_t *data = malloc(grant.mcs.tbs); - srslte_bit_pack_vector(data_bytes, data, grant.mcs.tbs); + srslte_bit_unpack_vector(data_bytes, data, grant.mcs.tbs); if (nlhs >= 1) { plhs[0] = mxCreateLogicalScalar(r == 0); diff --git a/srslte/lib/phch/test/pusch_encode_test_mex.c b/srslte/lib/phch/test/pusch_encode_test_mex.c index 1e7c28cf4..a3e7b8a80 100644 --- a/srslte/lib/phch/test/pusch_encode_test_mex.c +++ b/srslte/lib/phch/test/pusch_encode_test_mex.c @@ -128,7 +128,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) grant.mcs.tbs = mexutils_read_uint8(TRBLKIN, &trblkin_bits); uint8_t *trblkin = srslte_vec_malloc(grant.mcs.tbs/8); - srslte_bit_unpack_vector(trblkin_bits, trblkin, grant.mcs.tbs); + srslte_bit_pack_vector(trblkin_bits, trblkin, grant.mcs.tbs); free(trblkin_bits); grant.M_sc = grant.L_prb*SRSLTE_NRE; diff --git a/srslte/lib/phch/test/ulsch_encode_test_mex.c b/srslte/lib/phch/test/ulsch_encode_test_mex.c index fc383b1d1..c6ae04088 100644 --- a/srslte/lib/phch/test/ulsch_encode_test_mex.c +++ b/srslte/lib/phch/test/ulsch_encode_test_mex.c @@ -78,7 +78,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) cfg.grant.mcs.tbs = mexutils_read_uint8(TRBLKIN, &trblkin_bits); uint8_t *trblkin = srslte_vec_malloc(cfg.grant.mcs.tbs/8); - srslte_bit_unpack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs); + srslte_bit_pack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs); free(trblkin_bits); diff --git a/srslte/lib/utils/src/bit.c b/srslte/lib/utils/src/bit.c index b229e7779..b0b25ff8a 100644 --- a/srslte/lib/utils/src/bit.c +++ b/srslte/lib/utils/src/bit.c @@ -31,19 +31,19 @@ #include "srslte/utils/bit.h" -void srslte_bit_pack_vector(uint8_t *bits_unpacked, uint8_t *bits_packed, int nof_bits) +void srslte_bit_unpack_vector(uint8_t *bits_unpacked, uint8_t *bits_packed, int nof_bits) { uint32_t i, nbytes; nbytes = nof_bits/8; for (i=0;i