diff --git a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h index 3997a643a5b20301aae21eb8548f11f0062b243f..c5f86f5537865dc064d62a8f3b3af3b22f9c5748 100644 --- a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h +++ b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h @@ -44,4 +44,6 @@ uint8_t pack_nr_config_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t * uint8_t unpack_nr_config_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config); uint8_t pack_nr_start_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config); uint8_t unpack_nr_start_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config); +uint8_t pack_nr_start_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config); +uint8_t unpack_nr_start_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config); #endif // OPENAIRINTERFACE_NR_FAPI_P5_H diff --git a/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c b/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c index 4a2f8691f447f4f65bf29d28abc68e27f8370e1b..a3c5a4b543495adee4bda125364ffddc59f6c66f 100644 --- a/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c +++ b/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c @@ -1644,3 +1644,17 @@ uint8_t unpack_nr_start_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *m nfapi_nr_start_request_scf_t *pNfapiMsg = (nfapi_nr_start_request_scf_t *)msg; return unpack_nr_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension)); } + +uint8_t pack_nr_start_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) +{ + nfapi_nr_start_response_scf_t *pNfapiMsg = (nfapi_nr_start_response_scf_t *)msg; + return (push8(pNfapiMsg->error_code, ppWritePackedMsg, end) + && pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config)); +} + +uint8_t unpack_nr_start_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config) +{ + nfapi_nr_start_response_scf_t *pNfapiMsg = (nfapi_nr_start_response_scf_t *)msg; + return (pull8(ppReadPackedMsg, (uint8_t *)&pNfapiMsg->error_code, end) + && unpack_nr_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension))); +} diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h index 576399c3ed5cd63418385a9131d35ead7a4b923f..7aac6a91a21a76f743ed1a42dc53d599fa14f95d 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h @@ -4121,10 +4121,6 @@ int pack_nr_srs_beamforming_report(void *pMessageBuf, void *pPackedBuf, uint32_t */ int unpack_nr_srs_beamforming_report(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen); -uint8_t pack_nr_start_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config); - -uint8_t unpack_nr_start_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config); - uint8_t pack_nr_stop_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config); uint8_t unpack_nr_stop_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config); diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c index 30d9bbbc37e54300f0a65ab323c21dbf9cea7b7a..0349c6de951de08fc2f72c15b82791acfad27392 100644 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c @@ -1157,13 +1157,6 @@ static uint8_t pack_start_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t return pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config); } -uint8_t pack_nr_start_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) -{ - nfapi_nr_start_response_scf_t *pNfapiMsg = (nfapi_nr_start_response_scf_t *)msg; - return (push32(pNfapiMsg->error_code, ppWritePackedMsg, end) - && pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config)); -} - static uint8_t pack_start_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) { nfapi_start_response_t *pNfapiMsg = (nfapi_start_response_t *)msg; return ( push32(pNfapiMsg->error_code, ppWritePackedMsg, end ) && @@ -2101,12 +2094,6 @@ static uint8_t unpack_start_request(uint8_t **ppReadPackedMsg, uint8_t *end, voi return unpack_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension)); } -uint8_t unpack_nr_start_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config) -{ - nfapi_nr_start_response_scf_t *pNfapiMsg = (nfapi_nr_start_response_scf_t *)msg; - return (pull8(ppReadPackedMsg, (uint8_t *)&pNfapiMsg->error_code, end) - && unpack_nr_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension))); -} static uint8_t unpack_start_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config) { nfapi_start_response_t *pNfapiMsg = (nfapi_start_response_t *)msg; return ( pull32(ppReadPackedMsg, &pNfapiMsg->error_code, end) && diff --git a/nfapi/tests/p5/CMakeLists.txt b/nfapi/tests/p5/CMakeLists.txt index 5ada568d47b6e5e21dfa051e13995d5254f4332a..da7e2b6741bdb1e614ce2edc8313afaa410c735f 100644 --- a/nfapi/tests/p5/CMakeLists.txt +++ b/nfapi/tests/p5/CMakeLists.txt @@ -1,5 +1,5 @@ set(Test_Labels fapi p5) -set(_fapi_p5_messages "param_request;param_response;config_request;config_response;start_request") +set(_fapi_p5_messages "param_request;param_response;config_request;config_response;start_request;start_response") foreach (fapi_p5_message IN LISTS _fapi_p5_messages) add_executable(nr_fapi_${fapi_p5_message}_test nr_fapi_${fapi_p5_message}_test.c) diff --git a/nfapi/tests/p5/nr_fapi_start_response_test.c b/nfapi/tests/p5/nr_fapi_start_response_test.c new file mode 100644 index 0000000000000000000000000000000000000000..32ef894981d9fc6ff477413cbec8dd5f8e64e43b --- /dev/null +++ b/nfapi/tests/p5/nr_fapi_start_response_test.c @@ -0,0 +1,88 @@ +/* + * 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 + */ +/*! \file nfapi/tests/p5/nr_fapi_start_response_test.c + * \brief + * \author Ruben S. Silva + * \date 2024 + * \version 0.1 + * \company OpenAirInterface Software Alliance + * \email: contact@openairinterface.org, rsilva@allbesmart.pt + * \note + * \warning + */ +#include "nfapi/tests/nr_fapi_test.h" +#include "nr_fapi_p5_utils.h" + +void test_pack_unpack(nfapi_nr_start_response_scf_t *req) +{ + uint8_t msg_buf[65535]; + uint16_t msg_len = sizeof(req); + // first test the packing procedure + int pack_result = fapi_nr_p5_message_pack(req, msg_len, msg_buf, sizeof(msg_buf), NULL); + // START.response message body length is 1 + DevAssert(pack_result == 1 + 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_p5_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_start_response_scf_t unpacked_req = {0}; + int unpack_result = + fapi_nr_p5_message_unpack(msg_buf, header.message_length + NFAPI_HEADER_LENGTH, &unpacked_req, sizeof(unpacked_req), NULL); + DevAssert(unpack_result >= 0); + DevAssert(eq_start_response(&unpacked_req, req)); + free_start_response(&unpacked_req); +} + +void test_copy(const nfapi_nr_start_response_scf_t *msg) +{ + // Test copy function + nfapi_nr_start_response_scf_t copy = {0}; + copy_start_response(msg, ©); + DevAssert(eq_start_response(msg, ©)); + free_start_response(©); +} + +int main(int n, char *v[]) +{ + fapi_test_init(); + + nfapi_nr_start_response_scf_t req = {.header.message_id = NFAPI_NR_PHY_MSG_TYPE_START_RESPONSE}; + // Fill the message with randomized data + req.error_code = rand8_range(0x00, 0x01); + // Perform tests + test_pack_unpack(&req); + test_copy(&req); + // All tests successful! + free_start_response(&req); + return 0; +}