Move functions for packing/unpacking RACH.indication
Changed parameter in unpack function to be inline with other unpack functions. Changed nfapi_p7_allocate call to calloc to avoid dependency to NFAPI_LIB. Added unitary test for RACH.indication( test pack/unpack, free, copy and compare ) Added constant NFAPI_NR_RACH_IND_MAX_PDU to follow constants related to other P7 messages limiting the maximum number of PDUs to use. Removed now unneeded dependency to NFAPI_LIB and NFAPI_USER_LIB
This commit is contained in:
committed by
Robert Schmidt
parent
08ee4cfcc5
commit
bcbf7ab975
@@ -16,8 +16,7 @@ add_library(nr_fapi_p7
|
|||||||
src/nr_fapi_p7_utils.c
|
src/nr_fapi_p7_utils.c
|
||||||
)
|
)
|
||||||
target_include_directories(nr_fapi_p7 PUBLIC inc)
|
target_include_directories(nr_fapi_p7 PUBLIC inc)
|
||||||
# Note: Dependencies with NFAPI_LIB NFAPI_USER_LIB only necessary until last FAPI function is moved into new library, to be removed at a later stage
|
target_link_libraries(nr_fapi_p7 PUBLIC nr_fapi_common)
|
||||||
target_link_libraries(nr_fapi_p7 PUBLIC nr_fapi_common NFAPI_LIB NFAPI_USER_LIB)
|
|
||||||
|
|
||||||
if (OAI_AERIAL)
|
if (OAI_AERIAL)
|
||||||
target_compile_definitions(nr_fapi_p5 PRIVATE ENABLE_AERIAL)
|
target_compile_definitions(nr_fapi_p5 PRIVATE ENABLE_AERIAL)
|
||||||
|
|||||||
@@ -50,5 +50,6 @@ uint8_t pack_nr_uci_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *e
|
|||||||
uint8_t unpack_nr_uci_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, 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 pack_nr_srs_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 unpack_nr_srs_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config);
|
uint8_t unpack_nr_srs_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, 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);
|
||||||
|
uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config);
|
||||||
#endif // OPENAIRINTERFACE_NR_FAPI_P7_H
|
#endif // OPENAIRINTERFACE_NR_FAPI_P7_H
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ uint8_t fapi_nr_p7_message_body_pack(nfapi_nr_p7_message_header_t *header,
|
|||||||
case NFAPI_NR_PHY_MSG_TYPE_SRS_INDICATION:
|
case NFAPI_NR_PHY_MSG_TYPE_SRS_INDICATION:
|
||||||
result = pack_nr_srs_indication(header, ppWritePackedMsg, end, config);
|
result = pack_nr_srs_indication(header, ppWritePackedMsg, end, config);
|
||||||
break;
|
break;
|
||||||
|
case NFAPI_NR_PHY_MSG_TYPE_RACH_INDICATION:
|
||||||
|
result = pack_nr_rach_indication(header, ppWritePackedMsg, end, config);
|
||||||
|
break;
|
||||||
default: {
|
default: {
|
||||||
if (header->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && header->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) {
|
if (header->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && header->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) {
|
||||||
if (config && config->pack_p7_vendor_extension) {
|
if (config && config->pack_p7_vendor_extension) {
|
||||||
@@ -200,6 +203,11 @@ int fapi_nr_p7_message_unpack(void *pMessageBuf,
|
|||||||
result = unpack_nr_srs_indication(&pReadPackedMessage, end, pMessageHeader, config);
|
result = unpack_nr_srs_indication(&pReadPackedMessage, end, pMessageHeader, config);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case NFAPI_NR_PHY_MSG_TYPE_RACH_INDICATION:
|
||||||
|
if (check_nr_fapi_unpack_length(NFAPI_NR_PHY_MSG_TYPE_RACH_INDICATION, unpackedBufLen)) {
|
||||||
|
result = unpack_nr_rach_indication(&pReadPackedMessage, end, pMessageHeader, config);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if (pMessageHeader->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && pMessageHeader->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) {
|
if (pMessageHeader->message_id >= NFAPI_VENDOR_EXT_MSG_MIN && pMessageHeader->message_id <= NFAPI_VENDOR_EXT_MSG_MAX) {
|
||||||
@@ -2321,3 +2329,78 @@ uint8_t unpack_nr_srs_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t pack_nr_rach_indication_body(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
|
||||||
|
{
|
||||||
|
nfapi_nr_prach_indication_pdu_t *value = (nfapi_nr_prach_indication_pdu_t *)tlv;
|
||||||
|
|
||||||
|
if (!(push16(value->phy_cell_id, ppWritePackedMsg, end) && push8(value->symbol_index, ppWritePackedMsg, end)
|
||||||
|
&& push8(value->slot_index, ppWritePackedMsg, end) && push8(value->freq_index, ppWritePackedMsg, end)
|
||||||
|
&& push8(value->avg_rssi, ppWritePackedMsg, end) && push8(value->avg_snr, ppWritePackedMsg, end)
|
||||||
|
&& push8(value->num_preamble, ppWritePackedMsg, end)))
|
||||||
|
return 0;
|
||||||
|
for (int i = 0; i < value->num_preamble; i++) {
|
||||||
|
if (!(push8(value->preamble_list[i].preamble_index, ppWritePackedMsg, end)
|
||||||
|
&& push16(value->preamble_list[i].timing_advance, ppWritePackedMsg, end)
|
||||||
|
&& push32(value->preamble_list[i].preamble_pwr, ppWritePackedMsg, end)))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t pack_nr_rach_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config)
|
||||||
|
{
|
||||||
|
nfapi_nr_rach_indication_t *pNfapiMsg = (nfapi_nr_rach_indication_t *)msg;
|
||||||
|
|
||||||
|
if (!(push16(pNfapiMsg->sfn, ppWritePackedMsg, end) && push16(pNfapiMsg->slot, ppWritePackedMsg, end)
|
||||||
|
&& push8(pNfapiMsg->number_of_pdus, ppWritePackedMsg, end)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < pNfapiMsg->number_of_pdus; i++) {
|
||||||
|
if (!pack_nr_rach_indication_body(&(pNfapiMsg->pdu_list[i]), ppWritePackedMsg, end))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t unpack_nr_rach_indication_body(nfapi_nr_prach_indication_pdu_t *value,
|
||||||
|
uint8_t **ppReadPackedMsg,
|
||||||
|
uint8_t *end,
|
||||||
|
nfapi_p7_codec_config_t *config)
|
||||||
|
{
|
||||||
|
if (!(pull16(ppReadPackedMsg, &value->phy_cell_id, end) && pull8(ppReadPackedMsg, &value->symbol_index, end)
|
||||||
|
&& pull8(ppReadPackedMsg, &value->slot_index, end) && pull8(ppReadPackedMsg, &value->freq_index, end)
|
||||||
|
&& pull8(ppReadPackedMsg, &value->avg_rssi, end) && pull8(ppReadPackedMsg, &value->avg_snr, end)
|
||||||
|
&& pull8(ppReadPackedMsg, &value->num_preamble, end))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < value->num_preamble; i++) {
|
||||||
|
nfapi_nr_prach_indication_preamble_t *preamble = &(value->preamble_list[i]);
|
||||||
|
if (!(pull8(ppReadPackedMsg, &preamble->preamble_index, end) && pull16(ppReadPackedMsg, &preamble->timing_advance, end)
|
||||||
|
&& pull32(ppReadPackedMsg, &preamble->preamble_pwr, end))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config)
|
||||||
|
{
|
||||||
|
nfapi_nr_rach_indication_t *pNfapiMsg = (nfapi_nr_rach_indication_t *)msg;
|
||||||
|
|
||||||
|
if (!(pull16(ppReadPackedMsg, &pNfapiMsg->sfn, end) && pull16(ppReadPackedMsg, &pNfapiMsg->slot, end)
|
||||||
|
&& pull8(ppReadPackedMsg, &pNfapiMsg->number_of_pdus, end))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pNfapiMsg->number_of_pdus > 0) {
|
||||||
|
pNfapiMsg->pdu_list = calloc(pNfapiMsg->number_of_pdus, sizeof(*pNfapiMsg->pdu_list));
|
||||||
|
for (int i = 0; i < pNfapiMsg->number_of_pdus; i++) {
|
||||||
|
if (!unpack_nr_rach_indication_body(&(pNfapiMsg->pdu_list[i]), ppReadPackedMsg, end, config))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1857,6 +1857,7 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
//3.4.11 rach_indication
|
//3.4.11 rach_indication
|
||||||
|
#define NFAPI_NR_RACH_IND_MAX_PDU 100
|
||||||
//table 3-74
|
//table 3-74
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,17 +40,10 @@ 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_ue_release_response(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);
|
|
||||||
|
|
||||||
uint8_t pack_nr_dl_node_sync(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
|
uint8_t pack_nr_dl_node_sync(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
|
||||||
|
|
||||||
uint8_t pack_nr_ul_node_sync(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
|
uint8_t pack_nr_ul_node_sync(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
|
||||||
|
|
||||||
uint8_t pack_nr_timing_info(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
|
uint8_t pack_nr_timing_info(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
|
||||||
|
|
||||||
uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg,
|
|
||||||
uint8_t *end,
|
|
||||||
nfapi_nr_rach_indication_t *msg,
|
|
||||||
nfapi_p7_codec_config_t *config);
|
|
||||||
|
|
||||||
#endif // OPENAIRINTERFACE_NR_NFAPI_P7_H
|
#endif // OPENAIRINTERFACE_NR_NFAPI_P7_H
|
||||||
|
|||||||
@@ -2597,48 +2597,6 @@ int pack_nr_srs_beamforming_report(void *pMessageBuf, void *pPackedBuf, uint32_t
|
|||||||
return (msgEnd - msgHead);
|
return (msgEnd - msgHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
//RACH INDICATION
|
|
||||||
|
|
||||||
static uint8_t pack_nr_rach_indication_body(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
|
|
||||||
{
|
|
||||||
nfapi_nr_prach_indication_pdu_t* value = (nfapi_nr_prach_indication_pdu_t*)tlv;
|
|
||||||
|
|
||||||
if(!(push16(value->phy_cell_id, ppWritePackedMsg, end) &&
|
|
||||||
push8(value->symbol_index, ppWritePackedMsg, end) &&
|
|
||||||
push8(value->slot_index, ppWritePackedMsg, end) &&
|
|
||||||
push8(value->freq_index, ppWritePackedMsg, end) &&
|
|
||||||
push8(value->avg_rssi, ppWritePackedMsg, end) &&
|
|
||||||
push8(value->avg_snr, ppWritePackedMsg, end) &&
|
|
||||||
push8(value->num_preamble, ppWritePackedMsg, end)
|
|
||||||
))
|
|
||||||
return 0;
|
|
||||||
for(int i = 0; i < value->num_preamble; i++)
|
|
||||||
{
|
|
||||||
if(!(push8(value->preamble_list[i].preamble_index, ppWritePackedMsg, end) &&
|
|
||||||
push16(value->preamble_list[i].timing_advance, ppWritePackedMsg, end) &&
|
|
||||||
push32(value->preamble_list[i].preamble_pwr, ppWritePackedMsg, end)
|
|
||||||
))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t pack_nr_rach_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config)
|
|
||||||
{
|
|
||||||
nfapi_nr_rach_indication_t *pNfapiMsg = (nfapi_nr_rach_indication_t *)msg;
|
|
||||||
|
|
||||||
if (!(push16(pNfapiMsg->sfn, ppWritePackedMsg, end) && push16(pNfapiMsg->slot, ppWritePackedMsg, end)
|
|
||||||
&& push8(pNfapiMsg->number_of_pdus, ppWritePackedMsg, end)))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < pNfapiMsg->number_of_pdus; i++) {
|
|
||||||
if (!pack_nr_rach_indication_body(&(pNfapiMsg->pdu_list[i]), ppWritePackedMsg, end))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main pack function - public
|
// Main pack function - public
|
||||||
|
|
||||||
int nfapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packedBufLen, nfapi_p7_codec_config_t *config)
|
int nfapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packedBufLen, nfapi_p7_codec_config_t *config)
|
||||||
@@ -4510,52 +4468,6 @@ int unpack_nr_srs_beamforming_report(void *pMessageBuf, uint32_t messageBufLen,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//NR RACH
|
|
||||||
|
|
||||||
static uint8_t unpack_nr_rach_indication_body(nfapi_nr_prach_indication_pdu_t *value,
|
|
||||||
uint8_t **ppReadPackedMsg,
|
|
||||||
uint8_t *end,
|
|
||||||
nfapi_p7_codec_config_t *config)
|
|
||||||
{
|
|
||||||
if (!(pull16(ppReadPackedMsg, &value->phy_cell_id, end) && pull8(ppReadPackedMsg, &value->symbol_index, end)
|
|
||||||
&& pull8(ppReadPackedMsg, &value->slot_index, end) && pull8(ppReadPackedMsg, &value->freq_index, end)
|
|
||||||
&& pull8(ppReadPackedMsg, &value->avg_rssi, end) && pull8(ppReadPackedMsg, &value->avg_snr, end)
|
|
||||||
&& pull8(ppReadPackedMsg, &value->num_preamble, end))) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < value->num_preamble; i++) {
|
|
||||||
nfapi_nr_prach_indication_preamble_t *preamble = &(value->preamble_list[i]);
|
|
||||||
if (!(pull8(ppReadPackedMsg, &preamble->preamble_index, end) && pull16(ppReadPackedMsg, &preamble->timing_advance, end)
|
|
||||||
&& pull32(ppReadPackedMsg, &preamble->preamble_pwr, end))) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg,
|
|
||||||
uint8_t *end,
|
|
||||||
nfapi_nr_rach_indication_t *msg,
|
|
||||||
nfapi_p7_codec_config_t *config)
|
|
||||||
{
|
|
||||||
nfapi_nr_rach_indication_t *pNfapiMsg = (nfapi_nr_rach_indication_t *)msg;
|
|
||||||
|
|
||||||
if (!(pull16(ppReadPackedMsg, &pNfapiMsg->sfn, end) && pull16(ppReadPackedMsg, &pNfapiMsg->slot, end)
|
|
||||||
&& pull8(ppReadPackedMsg, &pNfapiMsg->number_of_pdus, end))) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pNfapiMsg->number_of_pdus > 0) {
|
|
||||||
pNfapiMsg->pdu_list = nfapi_p7_allocate(sizeof(*pNfapiMsg->pdu_list) * pNfapiMsg->number_of_pdus, config);
|
|
||||||
for (int i = 0; i < pNfapiMsg->number_of_pdus; i++) {
|
|
||||||
if (!unpack_nr_rach_indication_body(&(pNfapiMsg->pdu_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) {
|
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;
|
uint8_t proceed = 1;
|
||||||
nfapi_ue_release_request_t *pNfapiMsg = (nfapi_ue_release_request_t *)msg;
|
nfapi_ue_release_request_t *pNfapiMsg = (nfapi_ue_release_request_t *)msg;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
set(Test_Labels fapi p7)
|
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;uci_indication;srs_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;srs_indication;rach_indication")
|
||||||
foreach (fapi_p7_message IN LISTS _fapi_p7_messages)
|
foreach (fapi_p7_message IN LISTS _fapi_p7_messages)
|
||||||
add_executable(nr_fapi_${fapi_p7_message}_test nr_fapi_${fapi_p7_message}_test.c)
|
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)
|
target_link_libraries(nr_fapi_${fapi_p7_message}_test PUBLIC nr_fapi_p7)
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* 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_rach_indication_PDU(nfapi_nr_prach_indication_pdu_t *pdu)
|
||||||
|
{
|
||||||
|
pdu->phy_cell_id = rand32();
|
||||||
|
pdu->symbol_index = rand8_range(0,13);
|
||||||
|
pdu->slot_index = rand8_range(0,79);
|
||||||
|
pdu->freq_index = rand8_range(0,7);
|
||||||
|
pdu->avg_rssi = rand8();
|
||||||
|
pdu->avg_snr = rand8();
|
||||||
|
pdu->num_preamble = rand8_range(0,63);
|
||||||
|
for (int preamble_idx = 0; preamble_idx < pdu->num_preamble; ++preamble_idx) {
|
||||||
|
nfapi_nr_prach_indication_preamble_t *preamble = &pdu->preamble_list[preamble_idx];
|
||||||
|
preamble->preamble_index = rand8_range(0,63);
|
||||||
|
preamble->timing_advance = rand16_range(0,3846);
|
||||||
|
preamble->preamble_pwr = rand32_range(0, 170000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fill_rach_indication(nfapi_nr_rach_indication_t *msg)
|
||||||
|
{
|
||||||
|
msg->sfn = rand16_range(0, 1023);
|
||||||
|
msg->slot = rand16_range(0, 159);
|
||||||
|
msg->number_of_pdus = rand8_range(1, NFAPI_NR_RACH_IND_MAX_PDU); // Minimum 1 PDUs in order to test at least one
|
||||||
|
msg->pdu_list = calloc_or_fail(msg->number_of_pdus, sizeof(*msg->pdu_list));
|
||||||
|
for (int pdu_idx = 0; pdu_idx < msg->number_of_pdus; ++pdu_idx) {
|
||||||
|
fill_rach_indication_PDU(&msg->pdu_list[pdu_idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_pack_unpack(nfapi_nr_rach_indication_t *req)
|
||||||
|
{
|
||||||
|
size_t message_size = get_rach_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_rach_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_rach_indication(&unpacked_req, req));
|
||||||
|
free_rach_indication(&unpacked_req);
|
||||||
|
free(msg_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_copy(const nfapi_nr_rach_indication_t *msg)
|
||||||
|
{
|
||||||
|
// Test copy function
|
||||||
|
nfapi_nr_rach_indication_t copy = {0};
|
||||||
|
copy_rach_indication(msg, ©);
|
||||||
|
DevAssert(eq_rach_indication(msg, ©));
|
||||||
|
free_rach_indication(©);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int n, char *v[])
|
||||||
|
{
|
||||||
|
fapi_test_init();
|
||||||
|
|
||||||
|
nfapi_nr_rach_indication_t *req = calloc_or_fail(1, sizeof(nfapi_nr_rach_indication_t));
|
||||||
|
req->header.message_id = NFAPI_NR_PHY_MSG_TYPE_RACH_INDICATION;
|
||||||
|
// Get the actual allocated size
|
||||||
|
printf("Allocated size before filling: %zu bytes\n", get_rach_indication_size(req));
|
||||||
|
// Fill TX_DATA request
|
||||||
|
fill_rach_indication(req);
|
||||||
|
printf("Allocated size after filling: %zu bytes\n", get_rach_indication_size(req));
|
||||||
|
// Perform tests
|
||||||
|
test_pack_unpack(req);
|
||||||
|
test_copy(req);
|
||||||
|
// All tests successful!
|
||||||
|
free_rach_indication(req);
|
||||||
|
free(req);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user