Commit 3272225e authored by Rúben Soares Silva's avatar Rúben Soares Silva Committed by Robert Schmidt

Move functions for packing/unpacking UCI.indication

Reordered PDU pack/unpack function to follow PDU value order
Changed nfapi_p7_allocate calls to calloc to avoid dependency from FAPI lib to nFAPI lib.
Add unitary test for UCI.indication( test pack/unpack, free, copy and compare )
parent 36821641
......@@ -46,4 +46,6 @@ uint8_t pack_nr_rx_data_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_
uint8_t unpack_nr_rx_data_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config);
uint8_t pack_nr_crc_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t unpack_nr_crc_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config);
uint8_t pack_nr_uci_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t unpack_nr_uci_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config);
#endif // OPENAIRINTERFACE_NR_FAPI_P7_H
......@@ -52,6 +52,9 @@ uint8_t fapi_nr_p7_message_body_pack(nfapi_nr_p7_message_header_t *header,
case NFAPI_NR_PHY_MSG_TYPE_CRC_INDICATION:
result = pack_nr_crc_indication(header, ppWritePackedMsg, end, config);
break;
case NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION:
result = pack_nr_uci_indication(header, ppWritePackedMsg, end, config);
break;
default: {
if (header->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && header->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) {
if (config && config->pack_p7_vendor_extension) {
......@@ -184,6 +187,11 @@ int fapi_nr_p7_message_unpack(void *pMessageBuf,
result = unpack_nr_crc_indication(&pReadPackedMessage, end, pMessageHeader, config);
}
break;
case NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION:
if (check_nr_fapi_unpack_length(NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION, unpackedBufLen)) {
result = unpack_nr_uci_indication(&pReadPackedMessage, end, pMessageHeader, config);
}
break;
default:
if (pMessageHeader->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && pMessageHeader->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) {
......@@ -1750,3 +1758,455 @@ uint8_t unpack_nr_crc_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *
return 1;
}
static uint8_t pack_nr_uci_pusch(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
{
nfapi_nr_uci_pusch_pdu_t *value = (nfapi_nr_uci_pusch_pdu_t *)tlv;
if (!push8(value->pduBitmap, ppWritePackedMsg, end))
return 0;
if (!push32(value->handle, ppWritePackedMsg, end))
return 0;
if (!push16(value->rnti, ppWritePackedMsg, end))
return 0;
if (!push8(value->ul_cqi, ppWritePackedMsg, end))
return 0;
if (!push16(value->timing_advance, ppWritePackedMsg, end))
return 0;
if (!push16(value->rssi, ppWritePackedMsg, end))
return 0;
// Bit 0 not used in PUSCH PDU
if ((value->pduBitmap >> 1) & 0x01) { // HARQ
if (!push8(value->harq.harq_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->harq.harq_bit_len, ppWritePackedMsg, end))
return 0;
const uint16_t harq_len = (value->harq.harq_bit_len / 8) + 1;
if (!pusharray8(value->harq.harq_payload, harq_len, harq_len, ppWritePackedMsg, end))
return 0;
}
if ((value->pduBitmap >> 2) & 0x01) { // CSI-1
if (!push8(value->csi_part1.csi_part1_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->csi_part1.csi_part1_bit_len, ppWritePackedMsg, end))
return 0;
const uint16_t csi_len = value->csi_part1.csi_part1_bit_len / 8 + 1;
if (!pusharray8(value->csi_part1.csi_part1_payload, csi_len, csi_len, ppWritePackedMsg, end))
return 0;
}
if ((value->pduBitmap >> 3) & 0x01) { // CSI-2
if (!push8(value->csi_part2.csi_part2_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->csi_part2.csi_part2_bit_len, ppWritePackedMsg, end))
return 0;
const uint16_t csi_len = value->csi_part2.csi_part2_bit_len / 8 + 1;
if (!pusharray8(value->csi_part2.csi_part2_payload, csi_len, csi_len, ppWritePackedMsg, end))
return 0;
}
return 1;
}
static uint8_t pack_nr_uci_pucch_0_1(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
{
nfapi_nr_uci_pucch_pdu_format_0_1_t *value = (nfapi_nr_uci_pucch_pdu_format_0_1_t *)tlv;
if (!push8(value->pduBitmap, ppWritePackedMsg, end))
return 0;
if (!push32(value->handle, ppWritePackedMsg, end))
return 0;
if (!push16(value->rnti, ppWritePackedMsg, end))
return 0;
if (!push8(value->pucch_format, ppWritePackedMsg, end))
return 0;
if (!push8(value->ul_cqi, ppWritePackedMsg, end))
return 0;
if (!push16(value->timing_advance, ppWritePackedMsg, end))
return 0;
if (!push16(value->rssi, ppWritePackedMsg, end))
return 0;
if (value->pduBitmap & 0x01) { // SR
if (!push8(value->sr.sr_indication, ppWritePackedMsg, end))
return 0;
if (!push8(value->sr.sr_confidence_level, ppWritePackedMsg, end))
return 0;
}
if (((value->pduBitmap >> 1) & 0x01)) { // HARQ
if (!push8(value->harq.num_harq, ppWritePackedMsg, end))
return 0;
if (!push8(value->harq.harq_confidence_level, ppWritePackedMsg, end))
return 0;
for (int i = 0; i < value->harq.num_harq; i++) {
if (!push8(value->harq.harq_list[i].harq_value, ppWritePackedMsg, end))
return 0;
}
}
return 1;
}
static uint8_t pack_nr_uci_pucch_2_3_4(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
{
nfapi_nr_uci_pucch_pdu_format_2_3_4_t *value = (nfapi_nr_uci_pucch_pdu_format_2_3_4_t *)tlv;
if (!push8(value->pduBitmap, ppWritePackedMsg, end))
return 0;
if (!push32(value->handle, ppWritePackedMsg, end))
return 0;
if (!push16(value->rnti, ppWritePackedMsg, end))
return 0;
if (!push8(value->pucch_format, ppWritePackedMsg, end))
return 0;
if (!push8(value->ul_cqi, ppWritePackedMsg, end))
return 0;
if (!push16(value->timing_advance, ppWritePackedMsg, end))
return 0;
if (!push16(value->rssi, ppWritePackedMsg, end))
return 0;
if (value->pduBitmap & 0x01) { // SR
if (!push16(value->sr.sr_bit_len, ppWritePackedMsg, end))
return 0;
const uint16_t sr_len = value->sr.sr_bit_len / 8 + 1;
if (!pusharray8(value->sr.sr_payload, sr_len, sr_len, ppWritePackedMsg, end))
return 0;
}
if ((value->pduBitmap >> 1) & 0x01) { // HARQ
if (!push8(value->harq.harq_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->harq.harq_bit_len, ppWritePackedMsg, end))
return 0;
const uint16_t harq_len = value->harq.harq_bit_len / 8 + 1;
if (!pusharray8(value->harq.harq_payload, harq_len, harq_len, ppWritePackedMsg, end))
return 0;
}
if ((value->pduBitmap >> 2) & 0x01) { // CSI-1
if (!push8(value->csi_part1.csi_part1_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->csi_part1.csi_part1_bit_len, ppWritePackedMsg, end))
return 0;
const uint16_t csi_len = value->csi_part1.csi_part1_bit_len / 8 + 1;
if (!pusharray8(value->csi_part1.csi_part1_payload, csi_len, csi_len, ppWritePackedMsg, end))
return 0;
}
if ((value->pduBitmap >> 3) & 0x01) { // CSI-2
if (!push8(value->csi_part2.csi_part2_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->csi_part2.csi_part2_bit_len, ppWritePackedMsg, end))
return 0;
const uint16_t csi_len = value->csi_part2.csi_part2_bit_len / 8 + 1;
if (!pusharray8(value->csi_part2.csi_part2_payload, csi_len, csi_len, ppWritePackedMsg, end))
return 0;
}
return 1;
}
static uint8_t pack_nr_uci_indication_body(nfapi_nr_uci_t *value, uint8_t **ppWritePackedMsg, uint8_t *end)
{
if (!push16(value->pdu_type, ppWritePackedMsg, end))
return 0;
if (!push16(value->pdu_size, ppWritePackedMsg, end))
return 0;
switch (value->pdu_type) {
case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
if (!pack_nr_uci_pusch(&value->pusch_pdu, ppWritePackedMsg, end)) {
return 0;
}
break;
case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE:
if (!pack_nr_uci_pucch_0_1(&value->pucch_pdu_format_0_1, ppWritePackedMsg, end)) {
return 0;
}
break;
case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE:
if (!pack_nr_uci_pucch_2_3_4(&value->pucch_pdu_format_2_3_4, ppWritePackedMsg, end)) {
return 0;
}
break;
default:
NFAPI_TRACE(NFAPI_TRACE_WARN, "Unexpected UCI.indication PDU type %d\n", value->pdu_type);
return 0;
}
return 1;
}
uint8_t pack_nr_uci_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config)
{
nfapi_nr_uci_indication_t *pNfapiMsg = (nfapi_nr_uci_indication_t *)msg;
if (!push16(pNfapiMsg->sfn, ppWritePackedMsg, end))
return 0;
if (!push16(pNfapiMsg->slot, ppWritePackedMsg, end))
return 0;
if (!push16(pNfapiMsg->num_ucis, ppWritePackedMsg, end))
return 0;
for (int i = 0; i < pNfapiMsg->num_ucis; i++) {
if (!pack_nr_uci_indication_body(&pNfapiMsg->uci_list[i], ppWritePackedMsg, end))
return 0;
}
return 1;
}
static uint8_t unpack_nr_uci_pusch(nfapi_nr_uci_pusch_pdu_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!pull8(ppReadPackedMsg, &value->pduBitmap, end))
return 0;
if (!pull32(ppReadPackedMsg, &value->handle, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->rnti, end))
return 0;
if (!pull8(ppReadPackedMsg, &value->ul_cqi, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->timing_advance, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->rssi, end))
return 0;
// Bit 0 not used in PUSCH PDU
if ((value->pduBitmap >> 1) & 0x01) { // HARQ
if (!pull8(ppReadPackedMsg, &value->harq.harq_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->harq.harq_bit_len, end))
return 0;
const uint16_t harq_len = value->harq.harq_bit_len / 8 + 1;
value->harq.harq_payload = calloc(harq_len, sizeof(*value->harq.harq_payload));
if (value->harq.harq_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->harq.harq_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->harq.harq_payload, harq_len, harq_len, end))
return 0;
}
if ((value->pduBitmap >> 2) & 0x01) { // CSI-1
if (!pull8(ppReadPackedMsg, &value->csi_part1.csi_part1_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->csi_part1.csi_part1_bit_len, end))
return 0;
const uint16_t csi_len = value->csi_part1.csi_part1_bit_len / 8 + 1;
value->csi_part1.csi_part1_payload = calloc(csi_len, sizeof(*value->csi_part1.csi_part1_payload));
if (value->csi_part1.csi_part1_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->csi_part1.csi_part1_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->csi_part1.csi_part1_payload, csi_len, csi_len, end))
return 0;
}
if ((value->pduBitmap >> 3) & 0x01) { // CSI-2
if (!pull8(ppReadPackedMsg, &value->csi_part2.csi_part2_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->csi_part2.csi_part2_bit_len, end))
return 0;
const uint16_t csi_len = value->csi_part2.csi_part2_bit_len / 8 + 1;
value->csi_part2.csi_part2_payload = calloc(csi_len, sizeof(*value->csi_part2.csi_part2_payload));
if (value->csi_part2.csi_part2_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->csi_part2.csi_part2_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->csi_part2.csi_part2_payload, csi_len, csi_len, end))
return 0;
}
return 1;
}
static uint8_t unpack_nr_uci_pucch_0_1(nfapi_nr_uci_pucch_pdu_format_0_1_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!(pull8(ppReadPackedMsg, &value->pduBitmap, end) && pull32(ppReadPackedMsg, &value->handle, end)
&& pull16(ppReadPackedMsg, &value->rnti, end) && pull8(ppReadPackedMsg, &value->pucch_format, end)
&& pull8(ppReadPackedMsg, &value->ul_cqi, end) && pull16(ppReadPackedMsg, &value->timing_advance, end)
&& pull16(ppReadPackedMsg, &value->rssi, end)))
return 0;
if (value->pduBitmap & 0x01) { // SR
if (!(pull8(ppReadPackedMsg, &value->sr.sr_indication, end) && pull8(ppReadPackedMsg, &value->sr.sr_confidence_level, end)))
return 0;
}
if (((value->pduBitmap >> 1) & 0x01)) { // HARQ
if (!(pull8(ppReadPackedMsg, &value->harq.num_harq, end) && pull8(ppReadPackedMsg, &value->harq.harq_confidence_level, end)))
return 0;
if (value->harq.num_harq > 0) {
for (int i = 0; i < value->harq.num_harq; i++) {
if (!pull8(ppReadPackedMsg, &value->harq.harq_list[i].harq_value, end)) {
return 0;
}
}
}
}
return 1;
}
static uint8_t unpack_nr_uci_pucch_2_3_4(nfapi_nr_uci_pucch_pdu_format_2_3_4_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!pull8(ppReadPackedMsg, &value->pduBitmap, end))
return 0;
if (!pull32(ppReadPackedMsg, &value->handle, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->rnti, end))
return 0;
if (!pull8(ppReadPackedMsg, &value->pucch_format, end))
return 0;
if (!pull8(ppReadPackedMsg, &value->ul_cqi, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->timing_advance, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->rssi, end))
return 0;
if (value->pduBitmap & 0x01) { // SR
if (!pull16(ppReadPackedMsg, &value->sr.sr_bit_len, end))
return 0;
const uint16_t sr_len = value->sr.sr_bit_len / 8 + 1;
value->sr.sr_payload = calloc(sr_len, sizeof(*value->sr.sr_payload));
if (value->sr.sr_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->sr.sr_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->sr.sr_payload, sr_len, sr_len, end))
return 0;
}
if ((value->pduBitmap >> 1) & 0x01) { // HARQ
if (!pull8(ppReadPackedMsg, &value->harq.harq_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->harq.harq_bit_len, end))
return 0;
const uint16_t harq_len = value->harq.harq_bit_len / 8 + 1;
value->harq.harq_payload = calloc(harq_len, sizeof(*value->harq.harq_payload));
if (value->harq.harq_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->harq.harq_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->harq.harq_payload, harq_len, harq_len, end))
return 0;
}
if ((value->pduBitmap >> 2) & 0x01) { // CSI-1
if (!pull8(ppReadPackedMsg, &value->csi_part1.csi_part1_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->csi_part1.csi_part1_bit_len, end))
return 0;
const uint16_t csi_len = value->csi_part1.csi_part1_bit_len / 8 + 1;
value->csi_part1.csi_part1_payload = calloc(csi_len, sizeof(*value->csi_part1.csi_part1_payload));
if (value->csi_part1.csi_part1_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->csi_part1.csi_part1_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->csi_part1.csi_part1_payload, csi_len, csi_len, end))
return 0;
}
if ((value->pduBitmap >> 3) & 0x01) { // CSI-2
if (!pull8(ppReadPackedMsg, &value->csi_part2.csi_part2_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->csi_part2.csi_part2_bit_len, end))
return 0;
const uint16_t csi_len = value->csi_part2.csi_part2_bit_len / 8 + 1;
value->csi_part2.csi_part2_payload = calloc(csi_len, sizeof(*value->csi_part2.csi_part2_payload));
if (value->csi_part2.csi_part2_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->csi_part2.csi_part2_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->csi_part2.csi_part2_payload, csi_len, csi_len, end))
return 0;
}
return 1;
}
static uint8_t unpack_nr_uci_indication_body(nfapi_nr_uci_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!pull16(ppReadPackedMsg, &value->pdu_type, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->pdu_size, end))
return 0;
switch (value->pdu_type) {
case NFAPI_NR_UCI_PUSCH_PDU_TYPE: {
nfapi_nr_uci_pusch_pdu_t *uci_pdu = &value->pusch_pdu;
if (!unpack_nr_uci_pusch(uci_pdu, ppReadPackedMsg, end, config))
return 0;
break;
}
case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE: {
nfapi_nr_uci_pucch_pdu_format_0_1_t *uci_pdu = &value->pucch_pdu_format_0_1;
if (!unpack_nr_uci_pucch_0_1(uci_pdu, ppReadPackedMsg, end, config))
return 0;
break;
}
case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE: {
nfapi_nr_uci_pucch_pdu_format_2_3_4_t *uci_pdu = &value->pucch_pdu_format_2_3_4;
if (!unpack_nr_uci_pucch_2_3_4(uci_pdu, ppReadPackedMsg, end, config))
return 0;
break;
}
default:
NFAPI_TRACE(NFAPI_TRACE_WARN, "Unexpected UCI.indication PDU type %d\n", value->pdu_type);
break;
}
return 1;
}
uint8_t unpack_nr_uci_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config)
{
nfapi_nr_uci_indication_t *pNfapiMsg = (nfapi_nr_uci_indication_t *)msg;
if (!pull16(ppReadPackedMsg, &pNfapiMsg->sfn, end))
return 0;
if (!pull16(ppReadPackedMsg, &pNfapiMsg->slot, end))
return 0;
if (!pull16(ppReadPackedMsg, &pNfapiMsg->num_ucis, end))
return 0;
pNfapiMsg->uci_list = calloc(pNfapiMsg->num_ucis, sizeof(*pNfapiMsg->uci_list));
for (int i = 0; i < pNfapiMsg->num_ucis; i++) {
if (!unpack_nr_uci_indication_body(&pNfapiMsg->uci_list[i], ppReadPackedMsg, end, config))
return 0;
}
return 1;
}
......@@ -45,8 +45,6 @@ uint8_t pack_ue_release_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *
uint8_t pack_ue_release_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t pack_nr_uci_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t pack_nr_srs_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t pack_nr_rach_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
......@@ -57,8 +55,6 @@ uint8_t pack_nr_ul_node_sync(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end
uint8_t pack_nr_timing_info(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
uint8_t unpack_nr_uci_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config);
uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_nr_rach_indication_t *msg,
......
......@@ -2639,230 +2639,6 @@ uint8_t pack_nr_rach_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *
return 1;
}
//UCI INDICATION
static uint8_t pack_nr_uci_pucch_0_1(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end) {
nfapi_nr_uci_pucch_pdu_format_0_1_t* value = (nfapi_nr_uci_pucch_pdu_format_0_1_t*)tlv;
if (!push8(value->pduBitmap, ppWritePackedMsg, end))
return 0;
if (!push32(value->handle, ppWritePackedMsg, end))
return 0;
if (!push16(value->rnti, ppWritePackedMsg, end))
return 0;
if (!push8(value->pucch_format, ppWritePackedMsg, end))
return 0;
if (!push8(value->ul_cqi, ppWritePackedMsg, end))
return 0;
if (!push16(value->timing_advance, ppWritePackedMsg, end))
return 0;
if (!push16(value->rssi, ppWritePackedMsg, end))
return 0;
if (value->pduBitmap & 0x01) { //SR
if (!push8(value->sr.sr_indication, ppWritePackedMsg, end))
return 0;
if (!push8(value->sr.sr_confidence_level, ppWritePackedMsg, end))
return 0;
}
if (((value->pduBitmap >> 1) & 0x01)) { //HARQ
if (!push8(value->harq.num_harq, ppWritePackedMsg, end))
return 0;
if (!push8(value->harq.harq_confidence_level, ppWritePackedMsg, end))
return 0;
for (int i = 0; i < value->harq.num_harq; i++)
{
if (!push8(value->harq.harq_list[i].harq_value, ppWritePackedMsg, end))
return 0;
}
}
return 1;
}
static uint8_t pack_nr_uci_pucch_2_3_4(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end) {
nfapi_nr_uci_pucch_pdu_format_2_3_4_t* value = (nfapi_nr_uci_pucch_pdu_format_2_3_4_t*) tlv;
if (!push8(value->pduBitmap, ppWritePackedMsg, end))
return 0;
if (!push32(value->handle, ppWritePackedMsg, end))
return 0;
if (!push16(value->rnti, ppWritePackedMsg, end))
return 0;
if (!push8(value->pucch_format, ppWritePackedMsg, end))
return 0;
if (!push8(value->ul_cqi, ppWritePackedMsg, end))
return 0;
if (!push16(value->timing_advance, ppWritePackedMsg, end))
return 0;
if (!push16(value->rssi, ppWritePackedMsg, end))
return 0;
if (value->pduBitmap & 0x01) { //SR
if (!push16(value->sr.sr_bit_len, ppWritePackedMsg, end))
return 0;
if (!pusharray8(value->sr.sr_payload,
(int)((value->sr.sr_bit_len / 8) + 1),
(int)((value->sr.sr_bit_len / 8) + 1),
ppWritePackedMsg,
end))
return 0;
}
if ((value->pduBitmap >> 1) & 0x01) { //HARQ
if (!push8(value->harq.harq_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->harq.harq_bit_len, ppWritePackedMsg, end))
return 0;
if (!pusharray8(value->harq.harq_payload,
(int)((value->harq.harq_bit_len / 8) + 1),
(int)((value->harq.harq_bit_len / 8) + 1),
ppWritePackedMsg,
end))
return 0;
}
if ((value->pduBitmap >> 2) & 0x01) { //CSI-1
if (!push8(value->csi_part1.csi_part1_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->csi_part1.csi_part1_bit_len, ppWritePackedMsg, end))
return 0;
if (!pusharray8(value->csi_part1.csi_part1_payload,
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
ppWritePackedMsg,
end))
return 0;
}
if ((value->pduBitmap >> 3) & 0x01) { //CSI-2
if (!push8(value->csi_part2.csi_part2_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->csi_part2.csi_part2_bit_len, ppWritePackedMsg, end))
return 0;
if (!pusharray8(value->csi_part2.csi_part2_payload,
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
ppWritePackedMsg,
end))
return 0;
}
return 1;
}
static uint8_t pack_nr_uci_pusch(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
{
nfapi_nr_uci_pusch_pdu_t *value = (nfapi_nr_uci_pusch_pdu_t *)tlv;
if (!push8(value->pduBitmap, ppWritePackedMsg, end))
return 0;
if (!push32(value->handle, ppWritePackedMsg, end))
return 0;
if (!push16(value->rnti, ppWritePackedMsg, end))
return 0;
if (!push8(value->ul_cqi, ppWritePackedMsg, end))
return 0;
if (!push16(value->timing_advance, ppWritePackedMsg, end))
return 0;
if (!push16(value->rssi, ppWritePackedMsg, end))
return 0;
// Bit 0 not used in PUSCH PDU
if ((value->pduBitmap >> 1) & 0x01) { // HARQ
if (!push8(value->harq.harq_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->harq.harq_bit_len, ppWritePackedMsg, end))
return 0;
if (!pusharray8(value->harq.harq_payload,
(int)((value->harq.harq_bit_len / 8) + 1),
(int)((value->harq.harq_bit_len / 8) + 1),
ppWritePackedMsg,
end))
return 0;
}
if ((value->pduBitmap >> 2) & 0x01) { // CSI-1
if (!push8(value->csi_part1.csi_part1_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->csi_part1.csi_part1_bit_len, ppWritePackedMsg, end))
return 0;
if (!pusharray8(value->csi_part1.csi_part1_payload,
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
ppWritePackedMsg,
end))
return 0;
}
if ((value->pduBitmap >> 3) & 0x01) { // CSI-2
if (!push8(value->csi_part2.csi_part2_crc, ppWritePackedMsg, end))
return 0;
if (!push16(value->csi_part2.csi_part2_bit_len, ppWritePackedMsg, end))
return 0;
if (!pusharray8(value->csi_part2.csi_part2_payload,
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
ppWritePackedMsg,
end))
return 0;
}
return 1;
}
static uint8_t pack_nr_uci_indication_body(nfapi_nr_uci_t* value, uint8_t **ppWritePackedMsg, uint8_t *end)
{
if (!push16(value->pdu_type, ppWritePackedMsg, end))
return 0;
if (!push16(value->pdu_size, ppWritePackedMsg, end))
return 0;
switch (value->pdu_type) {
case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
if(!pack_nr_uci_pusch(&value->pusch_pdu, ppWritePackedMsg, end)){
return 0;
}
break;
case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE:
if(!pack_nr_uci_pucch_0_1(&value->pucch_pdu_format_0_1, ppWritePackedMsg, end)){
return 0;
}
break;
case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE:
if(!pack_nr_uci_pucch_2_3_4(&value->pucch_pdu_format_2_3_4, ppWritePackedMsg, end)){
return 0;
}
break;
}
return 1;
}
uint8_t pack_nr_uci_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config)
{
nfapi_nr_uci_indication_t *pNfapiMsg = (nfapi_nr_uci_indication_t *)msg;
if (!push16(pNfapiMsg->sfn, ppWritePackedMsg, end))
return 0;
if (!push16(pNfapiMsg->slot, ppWritePackedMsg, end))
return 0;
if (!push16(pNfapiMsg->num_ucis, ppWritePackedMsg, end))
return 0;
for (int i = 0; i < pNfapiMsg->num_ucis; i++) {
if (!pack_nr_uci_indication_body(&pNfapiMsg->uci_list[i], ppWritePackedMsg, end))
return 0;
}
return 1;
}
// Main pack function - public
int nfapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packedBufLen, nfapi_p7_codec_config_t *config)
......@@ -4776,294 +4552,6 @@ uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg,
return 1;
}
//NR UCI
static uint8_t unpack_nr_uci_pucch_0_1(nfapi_nr_uci_pucch_pdu_format_0_1_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!(pull8(ppReadPackedMsg, &value->pduBitmap, end) && pull32(ppReadPackedMsg, &value->handle, end)
&& pull16(ppReadPackedMsg, &value->rnti, end) && pull8(ppReadPackedMsg, &value->pucch_format, end)
&& pull8(ppReadPackedMsg, &value->ul_cqi, end) && pull16(ppReadPackedMsg, &value->timing_advance, end)
&& pull16(ppReadPackedMsg, &value->rssi, end)))
return 0;
if (value->pduBitmap & 0x01) { // SR
if (!(pull8(ppReadPackedMsg, &value->sr.sr_indication, end) && pull8(ppReadPackedMsg, &value->sr.sr_confidence_level, end)))
return 0;
}
if (((value->pduBitmap >> 1) & 0x01)) { // HARQ
if (!(pull8(ppReadPackedMsg, &value->harq.num_harq, end) && pull8(ppReadPackedMsg, &value->harq.harq_confidence_level, end)))
return 0;
if (value->harq.num_harq > 0) {
for (int i = 0; i < value->harq.num_harq; i++) {
if (!pull8(ppReadPackedMsg, &value->harq.harq_list[i].harq_value, end)) {
return 0;
}
}
}
}
return 1;
}
static uint8_t unpack_nr_uci_pucch_2_3_4(nfapi_nr_uci_pucch_pdu_format_2_3_4_t* value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config) {
if (!pull8(ppReadPackedMsg, &value->pduBitmap, end))
return 0;
if (!pull32(ppReadPackedMsg, &value->handle, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->rnti, end))
return 0;
if (!pull8(ppReadPackedMsg, &value->pucch_format, end))
return 0;
if (!pull8(ppReadPackedMsg, &value->ul_cqi, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->timing_advance, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->rssi, end))
return 0;
if (value->pduBitmap & 0x01) { //SR
if (!pull16(ppReadPackedMsg, &value->sr.sr_bit_len, end))
return 0;
value->sr.sr_payload = nfapi_p7_allocate(sizeof(*value->sr.sr_payload) *
(int)((value->sr.sr_bit_len / 8) + 1),
config);
if (value->sr.sr_payload == NULL)
{
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->sr.sr_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->sr.sr_payload,
(int)((value->sr.sr_bit_len / 8) + 1),
(int)((value->sr.sr_bit_len / 8) + 1),
end))
return 0;
}
if ((value->pduBitmap >> 1) & 0x01) { //HARQ
if (!pull8(ppReadPackedMsg, &value->harq.harq_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->harq.harq_bit_len, end))
return 0;
value->harq.harq_payload = nfapi_p7_allocate(sizeof(*value->harq.harq_payload) *
(int)((value->harq.harq_bit_len / 8) + 1),
config);
if (value->harq.harq_payload == NULL)
{
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->harq.harq_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->harq.harq_payload,
(int)((value->harq.harq_bit_len / 8) + 1),
(int)((value->harq.harq_bit_len / 8) + 1),
end))
return 0;
}
if ((value->pduBitmap >> 2) & 0x01) { //CSI-1
if (!pull8(ppReadPackedMsg, &value->csi_part1.csi_part1_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->csi_part1.csi_part1_bit_len, end))
return 0;
value->csi_part1.csi_part1_payload = nfapi_p7_allocate(sizeof(*value->csi_part1.csi_part1_payload) *
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
config);
if (value->csi_part1.csi_part1_payload == NULL)
{
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->csi_part1.csi_part1_payload\n",
__FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->csi_part1.csi_part1_payload,
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
end))
return 0;
}
if ((value->pduBitmap >> 3) & 0x01) { //CSI-2
if (!pull8(ppReadPackedMsg, &value->csi_part2.csi_part2_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->csi_part2.csi_part2_bit_len, end))
return 0;
value->csi_part2.csi_part2_payload = nfapi_p7_allocate(sizeof(*value->csi_part2.csi_part2_payload) *
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
config);
if (value->csi_part2.csi_part2_payload == NULL)
{
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->csi_part2.csi_part2_payload\n",
__FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg, value->csi_part2.csi_part2_payload,
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
end))
return 0;
}
return 1;
}
static uint8_t unpack_nr_uci_pusch(nfapi_nr_uci_pusch_pdu_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!pull8(ppReadPackedMsg, &value->pduBitmap, end))
return 0;
if (!pull32(ppReadPackedMsg, &value->handle, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->rnti, end))
return 0;
if (!pull8(ppReadPackedMsg, &value->ul_cqi, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->timing_advance, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->rssi, end))
return 0;
// Bit 0 not used in PUSCH PDU
if ((value->pduBitmap >> 1) & 0x01) { // HARQ
if (!pull8(ppReadPackedMsg, &value->harq.harq_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->harq.harq_bit_len, end))
return 0;
value->harq.harq_payload =
nfapi_p7_allocate(sizeof(*value->harq.harq_payload) * (int)((value->harq.harq_bit_len / 8) + 1), config);
if (value->harq.harq_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->harq.harq_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg,
value->harq.harq_payload,
(int)((value->harq.harq_bit_len / 8) + 1),
(int)((value->harq.harq_bit_len / 8) + 1),
end))
return 0;
}
if ((value->pduBitmap >> 2) & 0x01) { // CSI-1
if (!pull8(ppReadPackedMsg, &value->csi_part1.csi_part1_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->csi_part1.csi_part1_bit_len, end))
return 0;
value->csi_part1.csi_part1_payload =
nfapi_p7_allocate(sizeof(*value->csi_part1.csi_part1_payload) * (int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
config);
if (value->csi_part1.csi_part1_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->csi_part1.csi_part1_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg,
value->csi_part1.csi_part1_payload,
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
(int)((value->csi_part1.csi_part1_bit_len / 8) + 1),
end))
return 0;
}
if ((value->pduBitmap >> 3) & 0x01) { // CSI-2
if (!pull8(ppReadPackedMsg, &value->csi_part2.csi_part2_crc, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->csi_part2.csi_part2_bit_len, end))
return 0;
value->csi_part2.csi_part2_payload =
nfapi_p7_allocate(sizeof(*value->csi_part2.csi_part2_payload) * (int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
config);
if (value->csi_part2.csi_part2_payload == NULL) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate value->csi_part2.csi_part2_payload\n", __FUNCTION__);
return 0;
}
if (!pullarray8(ppReadPackedMsg,
value->csi_part2.csi_part2_payload,
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
(int)((value->csi_part2.csi_part2_bit_len / 8) + 1),
end))
return 0;
}
return 1;
}
static uint8_t unpack_nr_uci_indication_body(nfapi_nr_uci_t *value,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config)
{
if (!pull16(ppReadPackedMsg, &value->pdu_type, end))
return 0;
if (!pull16(ppReadPackedMsg, &value->pdu_size, end))
return 0;
switch (value->pdu_type) {
case NFAPI_NR_UCI_PUSCH_PDU_TYPE: {
nfapi_nr_uci_pusch_pdu_t *uci_pdu = &value->pusch_pdu;
if (!unpack_nr_uci_pusch(uci_pdu, ppReadPackedMsg, end, config))
return 0;
break;
}
case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE: {
nfapi_nr_uci_pucch_pdu_format_0_1_t *uci_pdu = &value->pucch_pdu_format_0_1;
if (!unpack_nr_uci_pucch_0_1(uci_pdu, ppReadPackedMsg, end, config))
return 0;
break;
}
case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE: {
nfapi_nr_uci_pucch_pdu_format_2_3_4_t *uci_pdu = &value->pucch_pdu_format_2_3_4;
if (!unpack_nr_uci_pucch_2_3_4(uci_pdu, ppReadPackedMsg, end, config))
return 0;
break;
}
default:
NFAPI_TRACE(NFAPI_TRACE_WARN, "Unexpected pdu type %d\n", value->pdu_type);
break;
}
return 1;
}
uint8_t unpack_nr_uci_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config)
{
nfapi_nr_uci_indication_t *pNfapiMsg = (nfapi_nr_uci_indication_t *)msg;
if (!pull16(ppReadPackedMsg, &pNfapiMsg->sfn, end))
return 0;
if (!pull16(ppReadPackedMsg, &pNfapiMsg->slot, end))
return 0;
if (!pull16(ppReadPackedMsg, &pNfapiMsg->num_ucis, end))
return 0;
pNfapiMsg->uci_list = nfapi_p7_allocate(sizeof(*pNfapiMsg->uci_list) * pNfapiMsg->num_ucis, config);
for (int i = 0; i < pNfapiMsg->num_ucis; i++) {
if (!unpack_nr_uci_indication_body(&pNfapiMsg->uci_list[i], ppReadPackedMsg, end, config))
return 0;
}
return 1;
}
static uint8_t unpack_ue_release_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config) {
uint8_t proceed = 1;
nfapi_ue_release_request_t *pNfapiMsg = (nfapi_ue_release_request_t *)msg;
......
set(Test_Labels fapi p7)
set(_fapi_p7_messages "dci_inversion;dl_tti_request;ul_tti_request;slot_indication;ul_dci_request;tx_data_request;rx_data_indication;crc_indication")
set(_fapi_p7_messages "dci_inversion;dl_tti_request;ul_tti_request;slot_indication;ul_dci_request;tx_data_request;rx_data_indication;crc_indication;uci_indication")
foreach (fapi_p7_message IN LISTS _fapi_p7_messages)
add_executable(nr_fapi_${fapi_p7_message}_test nr_fapi_${fapi_p7_message}_test.c)
target_link_libraries(nr_fapi_${fapi_p7_message}_test PUBLIC nr_fapi_p7)
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "dci_payload_utils.h"
#include "nr_fapi_p7.h"
#include "nr_fapi_p7_utils.h"
static void fill_uci_indication_sr_pdu_0_1(nfapi_nr_sr_pdu_0_1_t *pdu)
{
pdu->sr_indication = rand8_range(0, 1);
pdu->sr_confidence_level = rand8_range(0, 1);
}
static void fill_uci_indication_sr_pdu_2_3_4(nfapi_nr_sr_pdu_2_3_4_t *pdu)
{
pdu->sr_bit_len = rand16_range(1, 8);
pdu->sr_payload = calloc(((pdu->sr_bit_len / 8) + 1), sizeof(*pdu->sr_payload));
for (int i = 0; i < (pdu->sr_bit_len / 8) + 1; ++i) {
pdu->sr_payload[i] = rand8();
}
}
static void fill_uci_indication_harq_pdu_0_1(nfapi_nr_harq_pdu_0_1_t *pdu)
{
pdu->num_harq = rand8_range(1, 2);
pdu->harq_confidence_level = rand8_range(0, 1);
for (int i = 0; i < pdu->num_harq; ++i) {
pdu->harq_list[i].harq_value = rand8_range(0, 2);
}
}
static void fill_uci_indication_harq_pdu_2_3_4(nfapi_nr_harq_pdu_2_3_4_t *pdu)
{
pdu->harq_crc = rand8_range(0, 2);
pdu->harq_bit_len = rand16_range(1, 1706);
pdu->harq_payload = calloc(((pdu->harq_bit_len / 8) + 1), sizeof(*pdu->harq_payload));
for (int i = 0; i < (pdu->harq_bit_len / 8) + 1; ++i) {
pdu->harq_payload[i] = rand8();
}
}
static void fill_uci_indication_csi_part1(nfapi_nr_csi_part1_pdu_t *pdu)
{
pdu->csi_part1_crc = rand8_range(0, 2);
pdu->csi_part1_bit_len = rand16_range(1, 1706);
pdu->csi_part1_payload = calloc(((pdu->csi_part1_bit_len / 8) + 1), sizeof(*pdu->csi_part1_payload));
for (int i = 0; i < (pdu->csi_part1_bit_len / 8) + 1; ++i) {
pdu->csi_part1_payload[i] = rand8();
}
}
static void fill_uci_indication_csi_part2(nfapi_nr_csi_part2_pdu_t *pdu)
{
pdu->csi_part2_crc = rand8_range(0, 2);
pdu->csi_part2_bit_len = rand16_range(1, 1706);
pdu->csi_part2_payload = calloc(((pdu->csi_part2_bit_len / 8) + 1), sizeof(*pdu->csi_part2_payload));
for (int i = 0; i < (pdu->csi_part2_bit_len / 8) + 1; ++i) {
pdu->csi_part2_payload[i] = rand8();
}
}
static void fill_uci_indication_PUSCH(nfapi_nr_uci_pusch_pdu_t *pdu)
{
pdu->pduBitmap = rand8_range(0, 0b1110) & 0b1110; // Bit 0 is always unused
pdu->handle = rand32();
pdu->rnti = rand16_range(1, 65535);
pdu->ul_cqi = rand8();
pdu->timing_advance = rand16_range(0, 63);
pdu->rssi = rand16_range(0, 1280);
// Bit 0 not used in PUSCH PDU
// HARQ
if ((pdu->pduBitmap >> 1) & 0x01) {
fill_uci_indication_harq_pdu_2_3_4(&pdu->harq);
}
// CSI Part 1
if ((pdu->pduBitmap >> 2) & 0x01) {
fill_uci_indication_csi_part1(&pdu->csi_part1);
}
// CSI Part 2
if ((pdu->pduBitmap >> 3) & 0x01) {
fill_uci_indication_csi_part2(&pdu->csi_part2);
}
}
static void fill_uci_indication_PUCCH_0_1(nfapi_nr_uci_pucch_pdu_format_0_1_t *pdu)
{
pdu->pduBitmap = rand8_range(0, 0b11);
pdu->handle = rand32();
pdu->rnti = rand16_range(1, 65535);
pdu->pucch_format = rand8_range(0, 1);
pdu->ul_cqi = rand8();
pdu->timing_advance = rand16_range(0, 63);
pdu->rssi = rand16_range(0, 1280);
// SR
if (pdu->pduBitmap & 0x01) {
fill_uci_indication_sr_pdu_0_1(&pdu->sr);
}
// HARQ
if ((pdu->pduBitmap >> 1) & 0x01) {
fill_uci_indication_harq_pdu_0_1(&pdu->harq);
}
}
static void fill_uci_indication_PUCCH_2_3_4(nfapi_nr_uci_pucch_pdu_format_2_3_4_t *pdu)
{
pdu->pduBitmap = rand8_range(0, 0b1111);
pdu->handle = rand32();
pdu->rnti = rand16_range(1, 65535);
pdu->pucch_format = rand8_range(0, 2);
pdu->ul_cqi = rand8();
pdu->timing_advance = rand16_range(0, 63);
pdu->rssi = rand16_range(0, 1280);
// SR
if (pdu->pduBitmap & 0x01) {
fill_uci_indication_sr_pdu_2_3_4(&pdu->sr);
}
// HARQ
if ((pdu->pduBitmap >> 1) & 0x01) {
fill_uci_indication_harq_pdu_2_3_4(&pdu->harq);
}
// CSI Part 1
if ((pdu->pduBitmap >> 2) & 0x01) {
fill_uci_indication_csi_part1(&pdu->csi_part1);
}
// CSI Part 2
if ((pdu->pduBitmap >> 3) & 0x01) {
fill_uci_indication_csi_part2(&pdu->csi_part2);
}
}
static void fill_uci_indication_UCI(nfapi_nr_uci_t *uci)
{
uci->pdu_type = rand16_range(NFAPI_NR_UCI_PUSCH_PDU_TYPE, NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE);
uci->pdu_size = rand16();
switch (uci->pdu_type) {
case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
fill_uci_indication_PUSCH(&uci->pusch_pdu);
break;
case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE:
fill_uci_indication_PUCCH_0_1(&uci->pucch_pdu_format_0_1);
break;
case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE:
fill_uci_indication_PUCCH_2_3_4(&uci->pucch_pdu_format_2_3_4);
break;
default:
AssertFatal(1 == 0, "Unknown UCI.indication PDU Type %d\n", uci->pdu_type);
break;
}
}
static void fill_uci_indication(nfapi_nr_uci_indication_t *msg)
{
msg->sfn = rand16_range(0, 1023);
msg->slot = rand16_range(0, 159);
msg->num_ucis = rand8_range(1, NFAPI_NR_UCI_IND_MAX_PDU); // Minimum 1 PDUs in order to test at least one
msg->uci_list = calloc_or_fail(msg->num_ucis, sizeof(*msg->uci_list));
for (int crc_idx = 0; crc_idx < msg->num_ucis; ++crc_idx) {
fill_uci_indication_UCI(&msg->uci_list[crc_idx]);
}
}
static void test_pack_unpack(nfapi_nr_uci_indication_t *req)
{
size_t message_size = get_uci_indication_size(req);
uint8_t *msg_buf = calloc_or_fail(message_size, sizeof(uint8_t));
/*uint8_t msg_buf[1024*1024*3];
size_t message_size = sizeof(msg_buf);*/
// first test the packing procedure
int pack_result = fapi_nr_p7_message_pack(req, msg_buf, message_size, NULL);
DevAssert(pack_result >= 0 + NFAPI_HEADER_LENGTH);
// update req message_length value with value calculated in message_pack procedure
req->header.message_length = pack_result; //- NFAPI_HEADER_LENGTH;
// test the unpacking of the header
// copy first NFAPI_HEADER_LENGTH bytes into a new buffer, to simulate SCTP PEEK
fapi_message_header_t header;
uint32_t header_buffer_size = NFAPI_HEADER_LENGTH;
uint8_t header_buffer[header_buffer_size];
for (int idx = 0; idx < header_buffer_size; idx++) {
header_buffer[idx] = msg_buf[idx];
}
uint8_t *pReadPackedMessage = header_buffer;
int unpack_header_result = fapi_nr_message_header_unpack(&pReadPackedMessage, NFAPI_HEADER_LENGTH, &header, sizeof(header), 0);
DevAssert(unpack_header_result >= 0);
DevAssert(header.message_id == req->header.message_id);
DevAssert(header.message_length == req->header.message_length);
// test the unpacking and compare with initial message
nfapi_nr_uci_indication_t unpacked_req = {0};
int unpack_result =
fapi_nr_p7_message_unpack(msg_buf, header.message_length + NFAPI_HEADER_LENGTH, &unpacked_req, sizeof(unpacked_req), 0);
DevAssert(unpack_result >= 0);
DevAssert(eq_uci_indication(&unpacked_req, req));
free_uci_indication(&unpacked_req);
free(msg_buf);
}
static void test_copy(const nfapi_nr_uci_indication_t *msg)
{
// Test copy function
nfapi_nr_uci_indication_t copy = {0};
copy_uci_indication(msg, &copy);
DevAssert(eq_uci_indication(msg, &copy));
free_uci_indication(&copy);
}
int main(int n, char *v[])
{
fapi_test_init();
nfapi_nr_uci_indication_t *req = calloc_or_fail(1, sizeof(nfapi_nr_uci_indication_t));
req->header.message_id = NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION;
// Get the actual allocated size
printf("Allocated size before filling: %zu bytes\n", get_uci_indication_size(req));
// Fill TX_DATA request
fill_uci_indication(req);
printf("Allocated size after filling: %zu bytes\n", get_uci_indication_size(req));
// Perform tests
test_pack_unpack(req);
test_copy(req);
// All tests successful!
free_uci_indication(req);
free(req);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment