diff --git a/nfapi/oai_integration/nfapi_pnf.c b/nfapi/oai_integration/nfapi_pnf.c index 21b3e1e90e..b58463a7de 100644 --- a/nfapi/oai_integration/nfapi_pnf.c +++ b/nfapi/oai_integration/nfapi_pnf.c @@ -1747,6 +1747,9 @@ int nr_start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nf p7_config->codec_config.pack_p7_vendor_extension = &pnf_nr_phy_pack_p7_vendor_extension; p7_config->codec_config.unpack_vendor_extension_tlv = &pnf_nr_phy_unpack_vendor_extension_tlv; p7_config->codec_config.pack_vendor_extension_tlv = &pnf_nr_phy_pack_vendor_extention_tlv; + p7_config->unpack_func = &nfapi_nr_p7_message_unpack; + p7_config->hdr_unpack_func = &nfapi_nr_p7_message_header_unpack; + p7_config->pack_func = &nfapi_nr_p7_message_pack; NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] Creating P7 thread %s\n", __FUNCTION__); pthread_t p7_thread; threadCreate(&p7_thread, &pnf_nr_p7_thread_start, p7_config, "pnf_p7_thread", -1, OAI_PRIORITY_RT); @@ -2188,6 +2191,9 @@ void configure_nr_nfapi_pnf(char *vnf_ip_addr, int vnf_p5_port, char *pnf_ip_add config->deallocate_p4_p5_vendor_ext = &pnf_nr_sim_deallocate_p4_p5_vendor_ext; config->codec_config.unpack_p4_p5_vendor_extension = &pnf_nr_sim_unpack_p4_p5_vendor_extension; config->codec_config.pack_p4_p5_vendor_extension = &pnf_nr_sim_pack_p4_p5_vendor_extension; + config->unpack_func = &nfapi_nr_p5_message_unpack; + config->hdr_unpack_func = &nfapi_nr_p5_message_header_unpack; + config->pack_func = &nfapi_nr_p5_message_pack; NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] Creating PNF NFAPI start thread %s\n", __FUNCTION__); pthread_create(&pnf_start_pthread, NULL, &pnf_nr_start_thread, config); pthread_setname_np(pnf_start_pthread, "NFAPI_PNF"); diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h index eb668f3e73..683de59c59 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h @@ -110,11 +110,11 @@ uint8_t pack_nr_p5_message_body(nfapi_nr_p4_p5_message_header_t *header, * \param pUnpackedBuf A pointer to the nfapi_message_header * \param unpackedBufLen The size of nfapi_message_header structure. * \param config A pointer to the nfapi configuration structure - * \return 10 ( size of the unpacked header ) on success, -1 on failure. + * \return true on success, false on failure. * * The function will decode a byte stream pointed to by pMessageBuf into a nfapi p5 header structure pointed to by pUnpackedBuf */ -int nfapi_nr_p5_message_header_unpack(void *pMessageBuf, +bool nfapi_nr_p5_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -126,11 +126,11 @@ int nfapi_nr_p5_message_header_unpack(void *pMessageBuf, * \param pUnpackedBuf A pointer to the nfapi_message_header * \param unpackedBufLen The size of nfapi_message_header structure. * \param config A pointer to the nfapi configuration structure - * \return != -1 means success, -1 means failure. + * \return true on success, false on failure. * * The function will decode a byte stream pointed to by pMessageBuf into a nfapi p5 message structure pointer to by pUnpackedBuf */ -int nfapi_nr_p5_message_unpack(void *pMessageBuf, +bool nfapi_nr_p5_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -154,13 +154,13 @@ int nfapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packe * \param pUnpackedBuf A pointer to the nfapi_message_header * \param unpackedBufLen The size of nfapi_message_header structure. * \param config A pointer to the nfapi configuration structure - * \return 0 means success, -1 means failure. + * \return true on success, false on failure. * * The function will decode a byte stream pointed to by pMessageBuf into a nfapi_p7_message_header structure pointer to by pUnpackedBuf */ -int nfapi_nr_p7_message_header_unpack(void *pMessageBuf, +bool nfapi_nr_p7_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -172,11 +172,11 @@ int nfapi_nr_p7_message_header_unpack(void *pMessageBuf, * \param pUnpackedBuf A pointer to the nfapi_message_header * \param unpackedBufLen The size of nfapi_message_header structure. * \param config A pointer to the nfapi configuration structure - * \return 0 means success, -1 means failure. + * \return true on success, false failure. * * The function will decode a byte stream pointed to by pMessageBuf into a nfapi p7 message structure pointer to by pUnpackedBuf */ -int nfapi_nr_p7_message_unpack(void *pMessageBuf, +bool nfapi_nr_p7_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c index 1aeef4b766..4516302e48 100644 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c @@ -2325,7 +2325,7 @@ int nfapi_p5_message_header_unpack(void *pMessageBuf, return 8; } -int nfapi_nr_p5_message_header_unpack(void *pMessageBuf, +bool nfapi_nr_p5_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -2336,25 +2336,25 @@ int nfapi_nr_p5_message_header_unpack(void *pMessageBuf, if (pMessageBuf == NULL || pUnpackedBuf == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P5 header unpack supplied pointers are null\n"); - return -1; + return false; } uint8_t *end = pMessageBuf + messageBufLen; if (messageBufLen < NFAPI_NR_P5_HEADER_LENGTH || unpackedBufLen < sizeof(nfapi_nr_p4_p5_message_header_t)) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P5 header unpack supplied message buffer is too small %d, %d\n", messageBufLen, unpackedBufLen); - return -1; + return false; } // process the header if (!(pull16(&pReadPackedMessage, &pMessageHeader->phy_id, end) && pull16(&pReadPackedMessage, &pMessageHeader->message_id, end) && pull32(&pReadPackedMessage, &pMessageHeader->message_length, end) && pull16(&pReadPackedMessage, &pMessageHeader->spare, end))) { - return -1; + return false; } - return NFAPI_NR_P5_HEADER_LENGTH; + return true; } -int nfapi_nr_p5_message_unpack(void *pMessageBuf, +bool nfapi_nr_p5_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -2362,11 +2362,11 @@ int nfapi_nr_p5_message_unpack(void *pMessageBuf, { if (pMessageBuf == NULL || pUnpackedBuf == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P5 unpack supplied pointers are null\n"); - return -1; + return false; } if (messageBufLen < NFAPI_NR_P5_HEADER_LENGTH || unpackedBufLen < sizeof(nfapi_nr_p4_p5_message_header_t)) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P5 unpack supplied message buffer is too small %d, %d\n", messageBufLen, unpackedBufLen); - return -1; + return false; } nfapi_nr_p4_p5_message_header_t *pMessageHeader = pUnpackedBuf; @@ -2374,7 +2374,7 @@ int nfapi_nr_p5_message_unpack(void *pMessageBuf, (void)memset(pUnpackedBuf, 0, unpackedBufLen); // process the header if (!nfapi_nr_p5_message_header_unpack(pMessageBuf, messageBufLen, pMessageHeader, unpackedBufLen, config)) { - return -1; + return false; } uint8_t *pReadPackedMessage = pMessageBuf + NFAPI_NR_P5_HEADER_LENGTH; uint8_t *end = (uint8_t *)pMessageBuf + messageBufLen; @@ -2382,7 +2382,7 @@ int nfapi_nr_p5_message_unpack(void *pMessageBuf, if (check_nr_unpack_length(pMessageHeader->message_id, unpackedBufLen) == 0) { // the unpack buffer is not big enough for the struct - return -1; + return false; } // look for the specific message @@ -2476,7 +2476,7 @@ int nfapi_nr_p5_message_unpack(void *pMessageBuf, break; } - return result; + return result == 1; } int nfapi_p5_message_unpack(void *pMessageBuf, diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c index b6e15e294b..c60ed27d07 100644 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c @@ -5930,7 +5930,7 @@ int nfapi_p7_message_header_unpack(void *pMessageBuf, return 0; } -int nfapi_nr_p7_message_header_unpack(void *pMessageBuf, +bool nfapi_nr_p7_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -5941,14 +5941,14 @@ int nfapi_nr_p7_message_header_unpack(void *pMessageBuf, if (pMessageBuf == NULL || pUnpackedBuf == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 header unpack supplied pointers are null\n"); - return -1; + return false; } uint8_t *end = (uint8_t *)pMessageBuf + messageBufLen; if (messageBufLen < NFAPI_NR_P7_HEADER_LENGTH || unpackedBufLen < sizeof(nfapi_nr_p7_message_header_t)) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 header unpack supplied message buffer is too small %d, %d\n", messageBufLen, unpackedBufLen); - return -1; + return false; } // process the header if (!(pull16(&pReadPackedMessage, &pMessageHeader->phy_id, end) && pull16(&pReadPackedMessage, &pMessageHeader->message_id, end) @@ -5956,9 +5956,9 @@ int nfapi_nr_p7_message_header_unpack(void *pMessageBuf, && pull16(&pReadPackedMessage, &pMessageHeader->m_segment_sequence, end) && pull32(&pReadPackedMessage, &pMessageHeader->checksum, end) && pull32(&pReadPackedMessage, &pMessageHeader->transmit_timestamp, end))) - return -1; + return false; - return 0; + return true; } int nfapi_p7_message_unpack(void *pMessageBuf, @@ -6213,7 +6213,7 @@ bool peek_nr_nfapi_p7_sfn_slot(void *pMessageBuf, uint32_t messageBufLen, uint16 return true; } -int nfapi_nr_p7_message_unpack(void *pMessageBuf, +bool nfapi_nr_p7_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -6225,14 +6225,14 @@ int nfapi_nr_p7_message_unpack(void *pMessageBuf, if (pMessageBuf == NULL || pUnpackedBuf == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 unpack supplied pointers are null\n"); - return -1; + return false; } uint8_t *end = (uint8_t *)pMessageBuf + messageBufLen; if (messageBufLen < NFAPI_NR_P7_HEADER_LENGTH || unpackedBufLen < sizeof(nfapi_nr_p7_message_header_t)) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 unpack supplied message buffer is too small %d, %d\n", messageBufLen, unpackedBufLen); - return -1; + return false; } // process the header @@ -6242,11 +6242,11 @@ int nfapi_nr_p7_message_unpack(void *pMessageBuf, && pull32(&pReadPackedMessage, &pMessageHeader->checksum, end) && pull32(&pReadPackedMessage, &pMessageHeader->transmit_timestamp, end))) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 unpack header failed\n"); - return -1; + return false; } if ((uint8_t *)(pMessageBuf + pMessageHeader->message_length) > end) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 unpack message length is greater than the message buffer \n"); - return -1; + return false; } /* @@ -6356,7 +6356,7 @@ int nfapi_nr_p7_message_unpack(void *pMessageBuf, if (result == 0) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 Pack failed to pack message\n"); - return -1; + return false; } - return 0; + return true; } diff --git a/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h b/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h index 7403bd7169..2e4cb8812c 100644 --- a/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h +++ b/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h @@ -319,7 +319,47 @@ typedef struct nfapi_pnf_config */ void (*deallocate_p4_p5_vendor_ext)(void* header); + /*! \brief Encodes an (n)FAPI P5 message to a buffer + * \param pMessageBuf A pointer to a nfapi p5 message structure + * \param messageBufLen The size of the p5 message structure + * \param pPackedBuf A pointer to the buffer that the p5 message will be packed into + * \param packedBufLen The size of the buffer + * \param config A pointer to the nfapi configuration structure + * \return != 0 means success, -1 means failure. + */ + int (*pack_func)(void* pMessageBuf, + uint32_t messageBufLen, + void* pPackedBuf, + uint32_t packedBufLen, + nfapi_p4_p5_codec_config_t* config); + /*! \brief Decodes a (n)FAPI P5 message + * \param pMessageBuf A pointer to an encoded P5 message + * \param messageBufLen The size of the encoded P5 message + * \param pUnpackedBuf A pointer to the nfapi_message_header + * \param unpackedBufLen The size of nfapi_message_header structure. + * \param config A pointer to the nfapi configuration structure + * \return true on success, false on failure. + */ + bool (*unpack_func)(void* pMessageBuf, + uint32_t messageBufLen, + void* pUnpackedBuf, + uint32_t unpackedBufLen, + nfapi_p4_p5_codec_config_t* config); + + /*! \brief Decodes an (n)FAPI P5 message header + * \param pMessageBuf A pointer to an encoded P5 message header + * \param messageBufLen The size of the encoded P5 message header + * \param pUnpackedBuf A pointer to the nfapi_message_header + * \param unpackedBufLen The size of nfapi_message_header structure. + * \param config A pointer to the nfapi configuration structure + * \return true on success, false on failure. + */ + bool (*hdr_unpack_func)(void* pMessageBuf, + uint32_t messageBufLen, + void* pUnpackedBuf, + uint32_t unpackedBufLen, + nfapi_p4_p5_codec_config_t* config); } nfapi_pnf_config_t; @@ -726,7 +766,42 @@ typedef struct nfapi_pnf_p7_config */ void (*deallocate_p7_vendor_ext)(void* header); + /*! A callback to pack a P7 message + * \param pMessageBuf A pointer to a nfapi p7 message structure + * \param pPackedBuf A pointer to the buffer that the p7 message will be packed into + * \param packedBufLen The size of the buffer + * \param config A pointer to the nfapi configuration structure + * \return != -1 means success, -1 means failure. + */ + int (*pack_func)(void* pMessageBuf, void* pPackedBuf, uint32_t packedBufLen, nfapi_p7_codec_config_t* config); + /*! A callback to unpack a P7 message + * \param pMessageBuf A pointer to an encoded P7 message header + * \param messageBufLen The size of the encoded P7 message header + * \param pUnpackedBuf A pointer to the nfapi_message_header + * \param unpackedBufLen The size of nfapi_message_header structure. + * \param config A pointer to the nfapi configuration structure + * \return true success, false on failure. + */ + bool (*unpack_func)(void* pMessageBuf, + uint32_t messageBufLen, + void* pUnpackedBuf, + uint32_t unpackedBufLen, + nfapi_p7_codec_config_t* config); + + /*! \brief Decodes a NFAPI P7 message header + * \param pMessageBuf A pointer to an encoded P5 message header + * \param messageBufLen The size of the encoded P5 message header + * \param pUnpackedBuf A pointer to the nfapi_message_header + * \param unpackedBufLen The size of nfapi_message_header structure. + * \param config A pointer to the nfapi configuration structure + * \return true on success, false on failure. + */ + bool (*hdr_unpack_func)(void* pMessageBuf, + uint32_t messageBufLen, + void* pUnpackedBuf, + uint32_t unpackedBufLen, + nfapi_p7_codec_config_t* config); } nfapi_pnf_p7_config_t; diff --git a/nfapi/open-nFAPI/pnf/src/pnf.c b/nfapi/open-nFAPI/pnf/src/pnf.c index 4cef8e6412..e4438eded7 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf.c +++ b/nfapi/open-nFAPI/pnf/src/pnf.c @@ -95,8 +95,9 @@ void pnf_nr_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen) NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_PARAM.request received\n"); - // unpack the message - if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(nfapi_nr_pnf_param_request_t), &pnf->_public.codec_config) >= 0) + /// The unpack() function pointer is not called here due to the only possibility of entering being on a nFAPI message + const bool result = nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(nfapi_nr_pnf_param_request_t), &pnf->_public.codec_config); + if (result) { if(pnf->_public.state == NFAPI_PNF_IDLE) { @@ -251,8 +252,9 @@ void pnf_nr_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_CONFIG.request received\n"); - // unpack the message - if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0) + /// The unpack() function pointer is not called here due to the only possibility of entering being on a nFAPI message + const bool result = nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config); + if (result) { // ensure correct state if(pnf->_public.state != NFAPI_PNF_RUNNING) @@ -357,8 +359,9 @@ void pnf_nr_handle_pnf_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen) NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_START.request Received\n"); - // unpack the message - if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0) + /// The unpack() function pointer is not called here due to the only possibility of entering being on a nFAPI message + const bool result = nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config); + if (result) { if(pnf->_public.state == NFAPI_PNF_CONFIGURED) { @@ -517,7 +520,8 @@ void pnf_nr_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen) NFAPI_TRACE(NFAPI_TRACE_INFO, "PARAM.request received\n"); // unpack the message - if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0) + const bool result = pnf->_public.unpack_func(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config); + if (result) { if(config->state == NFAPI_PNF_RUNNING) { @@ -662,7 +666,8 @@ void pnf_nr_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen) nfapi_pnf_config_t* config = &(pnf->_public); // unpack the message - if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0) + const bool result = pnf->_public.unpack_func(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config); + if (result) { if(config->state == NFAPI_PNF_RUNNING) { @@ -806,7 +811,8 @@ void pnf_nr_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen) NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() START.request received state:%d\n", __FUNCTION__, config->state); // unpack the message - if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0) + const bool result = pnf->_public.unpack_func(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config); + if (result) { if(config->state == NFAPI_PNF_RUNNING) { @@ -945,7 +951,8 @@ void pnf_nr_handle_stop_request(pnf_t* pnf, void* pRecvMsg, int recvMsgLen) nfapi_pnf_config_t* config = &(pnf->_public); // unpack the message - if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0) { + const bool result = pnf->_public.unpack_func(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config); + if (result) { if (config->state == NFAPI_PNF_RUNNING) { nfapi_pnf_phy_config_t* phy = nfapi_pnf_phy_config_find(config, req.header.phy_id); if (phy) { @@ -1525,12 +1532,8 @@ void pnf_nr_handle_p5_message(pnf_t* pnf, void* pRecvMsg, int recvMsgLen) } // unpack the message header - if (nfapi_nr_p5_message_header_unpack(pRecvMsg, - recvMsgLen, - &messageHeader, - sizeof(nfapi_nr_p4_p5_message_header_t), - &pnf->_public.codec_config) - < 0) { + const bool result = pnf->_public.hdr_unpack_func(pRecvMsg, recvMsgLen, &messageHeader, sizeof(messageHeader), &pnf->_public.codec_config); + if (!result) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n"); return; } @@ -1705,7 +1708,7 @@ void pnf_handle_p5_message(pnf_t* pnf, void *pRecvMsg, int recvMsgLen) int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_nr_p4_p5_message_header_t* msg, uint32_t msg_len) { int packed_len = - nfapi_nr_p5_message_pack(msg, msg_len, pnf->tx_message_buffer, sizeof(pnf->tx_message_buffer), &pnf->_public.codec_config); + pnf->_public.pack_func(msg, msg_len, pnf->tx_message_buffer, sizeof(pnf->tx_message_buffer), &pnf->_public.codec_config); if (packed_len < 0) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "nfapi_nr_p5_message_pack failed (%d)\n", packed_len); @@ -2143,8 +2146,8 @@ int pnf_nr_read_dispatch_message(pnf_t* pnf) } nfapi_nr_p4_p5_message_header_t header; - int unpack_result = nfapi_nr_p5_message_header_unpack(header_buffer, header_buffer_size, &header, sizeof(header), 0); - if (unpack_result < 0) { + const bool result = pnf->_public.hdr_unpack_func(header_buffer, header_buffer_size, &header, sizeof(header), 0); + if (!result) { NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF Failed to unpack p5 message header\n"); return 0; } diff --git a/nfapi/open-nFAPI/pnf/src/pnf_p7.c b/nfapi/open-nFAPI/pnf/src/pnf_p7.c index bdc1634ef5..2235a7c153 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf_p7.c +++ b/nfapi/open-nFAPI/pnf/src/pnf_p7.c @@ -580,7 +580,7 @@ int pnf_nr_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_hea } uint8_t tx_buf[131072]; // four times NFAPI_MAX_PACKED_MESSAGE_SIZE as of this commit - int len = nfapi_nr_p7_message_pack(header, tx_buf, sizeof(tx_buf), &pnf_p7->_public.codec_config); + int len = pnf_p7->_public.pack_func(header, tx_buf, sizeof(tx_buf), &pnf_p7->_public.codec_config); if (len < 0) { if (pthread_mutex_unlock(&(pnf_p7->pack_mutex)) != 0) { @@ -1299,8 +1299,8 @@ void pnf_handle_dl_tti_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7) frame, slot, buffer_index); - - if (nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(*req), &(pnf_p7->_public.codec_config)) != 0) + const bool result = pnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, req, sizeof(*req), &(pnf_p7->_public.codec_config)); + if (!result) NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to unpack request\n"); } else { if (pnf_p7->_public.timing_info_mode_aperiodic) @@ -1432,8 +1432,8 @@ void pnf_handle_ul_tti_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7) frame, slot, buffer_index); - - if (nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(*req), &(pnf_p7->_public.codec_config)) != 0) + const bool result = pnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, req, sizeof(*req), &(pnf_p7->_public.codec_config)); + if (!result) NFAPI_TRACE(NFAPI_TRACE_ERROR, "failed to unpack UL_TTI.request\n"); } else { NFAPI_TRACE(NFAPI_TRACE_NOTE, @@ -1551,8 +1551,8 @@ void pnf_handle_ul_dci_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7) frame, slot, buffer_index); - - if (nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(*req), &pnf_p7->_public.codec_config) != 0) + const bool result = pnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, req, sizeof(*req), &(pnf_p7->_public.codec_config)); + if (!result) NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to unpack request\n"); } else { if (pnf_p7->_public.timing_info_mode_aperiodic) { @@ -1664,8 +1664,8 @@ void pnf_handle_tx_data_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7 frame, slot, buffer_index); - - if (nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(*req), &pnf_p7->_public.codec_config) == 0) { + const bool result = pnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, req, sizeof(*req), &(pnf_p7->_public.codec_config)); + if (result) { for (int i = 0; i < req->Number_of_PDUs; ++i) pnf_p7->nr_stats.dl.bytes += req->pdu_list[i].PDU_length; } else { @@ -2063,7 +2063,8 @@ void pnf_nr_handle_dl_node_sync(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7 } // unpack the message - if (nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &dl_node_sync, sizeof(dl_node_sync), &pnf_p7->_public.codec_config) < 0) + const bool result = pnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &dl_node_sync, sizeof(dl_node_sync), &pnf_p7->_public.codec_config); + if (!result) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__); return; @@ -2182,7 +2183,8 @@ void pnf_nr_dispatch_p7_message(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7 } // unpack the message header - if (nfapi_nr_p7_message_header_unpack(pRecvMsg, recvMsgLen, &header, sizeof(header), &pnf_p7->_public.codec_config) < 0) { + const bool result = pnf_p7->_public.hdr_unpack_func(pRecvMsg, recvMsgLen, &header, sizeof(header), &pnf_p7->_public.codec_config); + if (!result) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n"); return; } @@ -2336,12 +2338,9 @@ void pnf_nr_handle_p7_message(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, } // unpack the message header - if (nfapi_nr_p7_message_header_unpack(pRecvMsg, - recvMsgLen, - &messageHeader, - sizeof(nfapi_nr_p7_message_header_t), - &pnf_p7->_public.codec_config) - < 0) { + const bool result = + pnf_p7->_public.hdr_unpack_func(pRecvMsg, recvMsgLen, &messageHeader, sizeof(messageHeader), &pnf_p7->_public.codec_config); + if (!result) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n"); return; } @@ -2519,7 +2518,7 @@ void pnf_nr_nfapi_p7_read_dispatch_message(pnf_p7_t* pnf_p7, uint32_t now_hr_tim if (recvfrom_result > 0) { // get the segment size nfapi_nr_p7_message_header_t header; - nfapi_nr_p7_message_header_unpack(header_buffer, NFAPI_NR_P7_HEADER_LENGTH, &header, 34, 0); + pnf_p7->_public.hdr_unpack_func(header_buffer, NFAPI_NR_P7_HEADER_LENGTH, &header, 34, 0); // resize the buffer if we have a large segment if (header.message_length > pnf_p7->rx_message_buffer_size) { diff --git a/openair1/SIMULATION/NR_PHY/nr_unitary_common.c b/openair1/SIMULATION/NR_PHY/nr_unitary_common.c index 734a62d994..8a682b02f1 100644 --- a/openair1/SIMULATION/NR_PHY/nr_unitary_common.c +++ b/openair1/SIMULATION/NR_PHY/nr_unitary_common.c @@ -119,13 +119,13 @@ int nfapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packe { return 0; } -int nfapi_nr_p7_message_unpack(void *pMessageBuf, +bool nfapi_nr_p7_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, nfapi_p7_codec_config_t *config) { - return 0; + return false; } int nfapi_p7_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index e13ddac506..de5ae571ca 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -853,12 +853,11 @@ static void enqueue_nr_nfapi_msg(void *buffer, ssize_t len, nfapi_p7_message_hea case NFAPI_NR_PHY_MSG_TYPE_DL_TTI_REQUEST: { nfapi_nr_dl_tti_request_t *dl_tti_request = malloc16(sizeof(*dl_tti_request)); - if (nfapi_nr_p7_message_unpack(buffer, len, dl_tti_request, - sizeof(*dl_tti_request), NULL) < 0) - { - LOG_E(NR_PHY, "Message dl_tti_request failed to unpack\n"); - break; - } + const bool result = nfapi_nr_p7_message_unpack(buffer, len, dl_tti_request, sizeof(*dl_tti_request), NULL); + if (!result) { + LOG_E(NR_PHY, "Message dl_tti_request failed to unpack\n"); + break; + } LOG_D(NR_PHY, "Received an NFAPI_NR_PHY_MSG_TYPE_DL_TTI_REQUEST message in sfn/slot %d %d. \n", dl_tti_request->SFN, dl_tti_request->Slot); @@ -877,12 +876,11 @@ static void enqueue_nr_nfapi_msg(void *buffer, ssize_t len, nfapi_p7_message_hea case NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST: { nfapi_nr_tx_data_request_t *tx_data_request = malloc16(sizeof(*tx_data_request)); - if (nfapi_nr_p7_message_unpack(buffer, len, tx_data_request, - sizeof(*tx_data_request), NULL) < 0) - { - LOG_E(NR_PHY, "Message tx_data_request failed to unpack\n"); - break; - } + const bool result = nfapi_nr_p7_message_unpack(buffer, len, tx_data_request, sizeof(*tx_data_request), NULL); + if (!result) { + LOG_E(NR_PHY, "Message tx_data_request failed to unpack\n"); + break; + } LOG_D(NR_PHY, "Received an NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST message in SFN/slot %d %d. \n", tx_data_request->SFN, tx_data_request->Slot); if (!put_queue(&nr_tx_req_queue, tx_data_request)) @@ -897,12 +895,11 @@ static void enqueue_nr_nfapi_msg(void *buffer, ssize_t len, nfapi_p7_message_hea case NFAPI_NR_PHY_MSG_TYPE_UL_DCI_REQUEST: { nfapi_nr_ul_dci_request_t *ul_dci_request = malloc16(sizeof(*ul_dci_request)); - if (nfapi_nr_p7_message_unpack(buffer, len, ul_dci_request, - sizeof(*ul_dci_request), NULL) < 0) - { - LOG_E(NR_PHY, "Message ul_dci_request failed to unpack\n"); - break; - } + const bool result = nfapi_nr_p7_message_unpack(buffer, len, ul_dci_request, sizeof(*ul_dci_request), NULL); + if (!result) { + LOG_E(NR_PHY, "Message ul_dci_request failed to unpack\n"); + break; + } LOG_D(NR_PHY, "Received an NFAPI_NR_PHY_MSG_TYPE_UL_DCI_REQUEST message in SFN/slot %d %d. \n", ul_dci_request->SFN, ul_dci_request->Slot); if (!put_queue(&nr_ul_dci_req_queue, ul_dci_request)) @@ -917,12 +914,11 @@ static void enqueue_nr_nfapi_msg(void *buffer, ssize_t len, nfapi_p7_message_hea case NFAPI_NR_PHY_MSG_TYPE_UL_TTI_REQUEST: { nfapi_nr_ul_tti_request_t *ul_tti_request = malloc16(sizeof(*ul_tti_request)); - if (nfapi_nr_p7_message_unpack(buffer, len, ul_tti_request, - sizeof(*ul_tti_request), NULL) < 0) - { - LOG_E(NR_PHY, "Message ul_tti_request failed to unpack\n"); - break; - } + const bool result = nfapi_nr_p7_message_unpack(buffer, len, ul_tti_request, sizeof(*ul_tti_request), NULL); + if (!result) { + LOG_E(NR_PHY, "Message ul_tti_request failed to unpack\n"); + break; + } /* We are filtering UL_TTI_REQs below. We only care about UL_TTI_REQs that will trigger sending a ul_harq (CRC/RX pair). This UL_TTI_REQ will have NFAPI_NR_UL_CONFIG_PUSCH_PDU_TYPE. If we have not yet completed the CBRA/ diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c index 2216fb5a75..39b8f426ce 100644 --- a/openair2/RRC/LTE/rrc_UE.c +++ b/openair2/RRC/LTE/rrc_UE.c @@ -6582,15 +6582,11 @@ void process_nr_nsa_msg(nsa_msg_t *msg, int msg_len) } nfapi_nr_dl_tti_request_t dl_tti_request; - int unpack_len = nfapi_nr_p7_message_unpack((void *)msg_buffer, - msg_len, - &dl_tti_request, - sizeof(nfapi_nr_dl_tti_request_t), - NULL); - if (unpack_len < 0) - { - LOG_E(RRC, "%s: SSB PDU unpack failed \n", __FUNCTION__); - break; + const bool result = + nfapi_nr_p7_message_unpack((void *)msg_buffer, msg_len, &dl_tti_request, sizeof(nfapi_nr_dl_tti_request_t), NULL); + if (!result) { + LOG_E(RRC, "%s: SSB PDU unpack failed \n", __FUNCTION__); + break; } int num_pdus = dl_tti_request.dl_tti_request_body.nPDUs; if (num_pdus <= 0)