From 19ce41b8890507fcd09d08e2648bd74fdab73cc6 Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Thu, 11 Jan 2024 11:53:30 +0200 Subject: [PATCH] tests: net: nrf_provisioning: remove header file Remove file coap_client.h located in nrf_provisioning tests folder and use the same header file from Zephyr. Update header file nrf_modem_at.h Signed-off-by: Juha Ylinen --- .../net/lib/nrf_provisioning/CMakeLists.txt | 2 +- .../nrf_provisioning/include/coap_client.h | 134 ---------------- .../nrf_provisioning/include/nrf_modem_at.h | 143 ++++++++++-------- 3 files changed, 82 insertions(+), 197 deletions(-) delete mode 100644 tests/subsys/net/lib/nrf_provisioning/include/coap_client.h diff --git a/tests/subsys/net/lib/nrf_provisioning/CMakeLists.txt b/tests/subsys/net/lib/nrf_provisioning/CMakeLists.txt index f79756dc907..cfa01da5cf7 100644 --- a/tests/subsys/net/lib/nrf_provisioning/CMakeLists.txt +++ b/tests/subsys/net/lib/nrf_provisioning/CMakeLists.txt @@ -45,7 +45,7 @@ elseif(CONFIG_NRF_PROVISIONING_COAP) -DCONFIG_MODEM_INFO_BUFFER_SIZE=128 -DCONFIG_COAP_CLIENT_MAX_REQUESTS=2 ) - cmock_handle(include/coap_client.h) + cmock_handle(${ZEPHYR_BASE}/include/zephyr/net/coap_client.h) cmock_handle(${ZEPHYR_NRF_MODULE_DIR}/subsys/net/lib/nrf_provisioning/include/nrf_provisioning_jwt.h) elseif(CONFIG_NRF_PROVISIONING_HTTP) diff --git a/tests/subsys/net/lib/nrf_provisioning/include/coap_client.h b/tests/subsys/net/lib/nrf_provisioning/include/coap_client.h deleted file mode 100644 index 23801d37918..00000000000 --- a/tests/subsys/net/lib/nrf_provisioning/include/coap_client.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause - */ - -#ifndef ZEPHYR_INCLUDE_NET_COAP_CLIENT_H_ -#define ZEPHYR_INCLUDE_NET_COAP_CLIENT_H_ - -/** @file - * @brief CoAP client API - * - * An API for applications to do CoAP requests - */ - -/** - * @brief CoAP client API - * @defgroup coap_client CoAP client API - * @ingroup networking - * @{ - */ - -#include - - -#define MAX_COAP_MSG_LEN (CONFIG_COAP_CLIENT_MESSAGE_HEADER_SIZE + \ - CONFIG_COAP_CLIENT_MESSAGE_SIZE) - -/** - * @typedef coap_client_response_cb_t - * @brief Callback for CoAP request. - * - * This callback is called for responses to CoAP client requests. - * It is used to indicate errors, response codes from server or to deliver payload. - * Blockwise transfers cause this callback to be called sequentially with increasing payload offset - * and only partial content in buffer pointed by payload parameter. - * - * @param result_code Result code of the response. Negative if there was a failure in send. - * @ref coap_response_code for positive. - * @param offset Payload offset from the beginning of a blockwise transfer. - * @param payload Buffer containing the payload from the response. NULL for empty payload. - * @param len Size of the payload. - * @param last_block Indicates the last block of the response. - * @param user_data User provided context. - */ -typedef void (*coap_client_response_cb_t)(int16_t result_code, - size_t offset, const uint8_t *payload, size_t len, - bool last_block, void *user_data); - -/** - * @brief Representation of a CoAP client request. - */ -struct coap_client_request { - enum coap_method method; /**< Method of the request */ - bool confirmable; /**< CoAP Confirmable/Non-confirmable message */ - const char *path; /**< Path of the requested resource */ - enum coap_content_format fmt; /**< Content format to be used */ - uint8_t *payload; /**< User allocated buffer for send request */ - size_t len; /**< Length of the payload */ - coap_client_response_cb_t cb; /**< Callback when response received */ - struct coap_client_option *options; /**< Extra options to be added to request */ - uint8_t num_options; /**< Number of extra options */ - void *user_data; /**< User provided context */ -}; - -/** - * @brief Representation of extra options for the CoAP client request - */ -struct coap_client_option { - uint16_t code; -#if defined(CONFIG_COAP_EXTENDED_OPTIONS_LEN) - uint16_t len; - uint8_t value[CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE]; -#else - uint8_t len; - uint8_t value[12]; -#endif -}; - -/** @cond INTERNAL_HIDDEN */ -struct coap_client { - int fd; - struct sockaddr address; - socklen_t socklen; - uint8_t send_buf[MAX_COAP_MSG_LEN]; - uint8_t recv_buf[MAX_COAP_MSG_LEN]; - uint8_t request_token[COAP_TOKEN_MAX_LEN]; - int request_tkl; - int offset; - int retry_count; - struct coap_block_context recv_blk_ctx; - struct coap_block_context send_blk_ctx; - struct coap_pending pending; - struct coap_client_request *coap_request; - struct coap_packet request; -}; -/** @endcond */ - -/** - * @brief Initialize the CoAP client. - * - * @param[in] client Client instance. - * @param[in] info Name for the receiving thread of the client. Setting this NULL will result as - * default name of "coap_client". - * - * @return int Zero on success, otherwise a negative error code. - */ -int coap_client_init(struct coap_client *client, const char *info); - -/** - * @brief Send CoAP request - * - * Operation is handled asynchronously using a background thread. - * If the socket isn't connected to a destination address, user must provide a destination address, - * otherwise the address should be set as NULL. - * Once the callback is called with last block set as true, socket can be closed or - * used for another query. - * - * @param client Client instance. - * @param sock Open socket file descriptor. - * @param addr the destination address of the request. - * @param req CoAP request structure - * @param retries How many times to retry or -1 to use default. - * @return zero when operation started successfully or negative error code otherwise. - */ - -int coap_client_req(struct coap_client *client, int sock, const struct sockaddr *addr, - struct coap_client_request *req, int retries); - -/** - * @} - */ - -#endif /* ZEPHYR_INCLUDE_NET_COAP_CLIENT_H_ */ diff --git a/tests/subsys/net/lib/nrf_provisioning/include/nrf_modem_at.h b/tests/subsys/net/lib/nrf_provisioning/include/nrf_modem_at.h index e9b365852ff..d46f4dc2bb4 100644 --- a/tests/subsys/net/lib/nrf_provisioning/include/nrf_modem_at.h +++ b/tests/subsys/net/lib/nrf_provisioning/include/nrf_modem_at.h @@ -38,47 +38,6 @@ extern "C" { */ typedef void (*nrf_modem_at_notif_handler_t)(const char *notif); -/** - * @brief AT response handler prototype. - * - * @note This handler is executed in an interrupt service routine. - * Offload any intensive operations as necessary. - * - * @param resp The AT command response. - */ -typedef void (*nrf_modem_at_resp_handler_t)(const char *resp); - -/** @brief AT filter callback function format - * - * @note This declaration is used for the callback functions - * of AT commands in the nRF SDK. - * - * @param buf Buffer to receive the response into. - * @param len Buffer length. - * @param at_cmd AT command. - * - * @retval 0 On "OK" responses. - * @returns A positive value On "ERROR", "+CME ERROR", and "+CMS ERROR" responses. - * The type of error can be distinguished using @c nrf_modem_at_err_type. - * The error value can be retrieved using @c nrf_modem_at_err. - * @retval -NRF_EPERM The Modem library is not initialized. - * @retval -NRF_EFAULT @c buf or @c fmt are @c NULL. - * @retval -NRF_ENOMEM Not enough shared memory for this request. - * @retval -NRF_E2BIG The response is larger than the supplied buffer @c buf. - */ -typedef int (*nrf_modem_at_cmd_handler_t)(char *buf, size_t len, char *at_cmd); - -/* Struct for AT filter - * Contains string for which the AT commands are compared - * and a function pointer for the function to call on detection. - */ -struct nrf_modem_at_cmd_filter { - const char * const cmd; - const nrf_modem_at_cmd_handler_t callback; - /** Whether filter is paused. */ - bool paused; -}; - /** * @brief Set a handler function for AT notifications. * @@ -107,6 +66,7 @@ int nrf_modem_at_notif_handler_set(nrf_modem_at_notif_handler_t callback); * @retval -NRF_EPERM The Modem library is not initialized. * @retval -NRF_EFAULT @c fmt is @c NULL. * @retval -NRF_EINVAL Bad format @c fmt. + * @retval -NRF_EAGAIN Timed out while waiting for another AT command to complete. * @retval -NRF_ENOMEM Not enough shared memory for this request. * @retval -NRF_ESHUTDOWN If modem was shut down. */ @@ -128,6 +88,7 @@ int nrf_modem_at_printf(const char *fmt, ...); * @retval -NRF_EPERM The Modem library is not initialized. * @retval -NRF_EFAULT @c cmd or @c fmt are @c NULL. * @retval -NRF_EBADMSG No arguments were matched. + * @retval -NRF_EAGAIN Timed out while waiting for another AT command to complete. * @retval -NRF_ENOMEM Not enough shared memory for this request. * @retval -NRF_ESHUTDOWN If the modem was shut down. */ @@ -149,12 +110,23 @@ int nrf_modem_at_scanf(const char *cmd, const char *fmt, ...); * @retval -NRF_EPERM The Modem library is not initialized. * @retval -NRF_EFAULT @c buf or @c fmt are @c NULL. * @retval -NRF_EINVAL Bad format @c fmt, or @c len is zero. + * @retval -NRF_EAGAIN Timed out while waiting for another AT command to complete. * @retval -NRF_ENOMEM Not enough shared memory for this request. * @retval -NRF_E2BIG The response is larger than the supplied buffer @c buf. * @retval -NRF_ESHUTDOWN If the modem was shut down. */ int nrf_modem_at_cmd(void *buf, size_t len, const char *fmt, ...); +/** + * @brief AT response handler prototype. + * + * @note This handler is executed in an interrupt service routine. + * Offload any intensive operations as necessary. + * + * @param resp The AT command response. + */ +typedef void (*nrf_modem_at_resp_handler_t)(const char *resp); + /** * @brief Send a formatted AT command to the modem * and receive the response asynchronously via a callback. @@ -173,12 +145,79 @@ int nrf_modem_at_cmd(void *buf, size_t len, const char *fmt, ...); * @retval -NRF_EPERM The Modem library is not initialized. * @retval -NRF_EFAULT @c callback or @c fmt are @c NULL. * @retval -NRF_EINVAL Bad format @c fmt. - * @retval -NRF_EINPROGRESS An asynchrounous request is already in progress. + * @retval -NRF_EINPROGRESS Another AT command is executing. * @retval -NRF_ENOMEM Not enough shared memory for this request. * @retval -NRF_ESHUTDOWN If the modem was shut down. */ int nrf_modem_at_cmd_async(nrf_modem_at_resp_handler_t callback, const char *fmt, ...); +/** @brief AT command handler prototype. + * + * Implements a custom AT command in the application. + * + * @param buf Buffer to receive the response into. + * @param len Buffer length. + * @param at_cmd AT command. + * + * @retval 0 On "OK" responses. + * @returns A positive value On "ERROR", "+CME ERROR", and "+CMS ERROR" responses. + * The type of error can be distinguished using @c nrf_modem_at_err_type. + * The error value can be retrieved using @c nrf_modem_at_err. + * @retval -NRF_EPERM The Modem library is not initialized. + * @retval -NRF_EFAULT @c buf or @c fmt are @c NULL. + * @retval -NRF_ENOMEM Not enough shared memory for this request. + * @retval -NRF_E2BIG The response is larger than the supplied buffer @c buf. + */ +typedef int (*nrf_modem_at_cmd_custom_handler_t)(char *buf, size_t len, char *at_cmd); + +/** + * @brief Custom AT command. + * + * Application-defined AT command implementation. + */ +struct nrf_modem_at_cmd_custom { + /** The AT command to implement. */ + const char * const cmd; + /** The function implementing the AT command. */ + const nrf_modem_at_cmd_custom_handler_t callback; +}; + +/** + * @brief Set a list of custom AT commands that are implemented in the application. + * + * When a custom AT command list is set, AT commands sent via @c nrf_modem_at_cmd that match any + * AT command in the list, will be redirected to the custom callback function instead + * of being sent to the modem. + * + * @note The custom commands are disabled by passing NULL to the @c custom_commands and + * 0 to the @c len. + * + * @param custom_commands List of custom AT commands. + * @param len Custom AT command list size. + * + * @retval 0 On success. + * @retval -NRF_EINVAL On invalid parameters. + */ +int nrf_modem_at_cmd_custom_set(struct nrf_modem_at_cmd_custom *custom_commands, size_t len); + +/** + * @brief Configure how long to wait for ongoing AT commands to complete when sending AT commands. + * + * AT commands are executed one at a time. While one AT command is being executed, the other + * AT commands wait on a semaphore for the ongoing AT command to complete. + * + * This function configures how long @c nrf_modem_at_printf, @c nrf_modem_at_scanf and + * @c nrf_modem_at_cmd shall wait for ongoing AT commands to complete. + * + * By default, the timeout is infinite. + * + * @param timeout_ms Timeout in milliseconds. Use NRF_MODEM_OS_FOREVER for infinite timeout + * or NRF_MODEM_OS_NO_WAIT for no timeout. + * + * @return int Zero on success, a negative errno otherwise. + */ +int nrf_modem_at_sem_timeout_set(int timeout_ms); + /** * @brief Return the error type represented by the return value of * @c nrf_modem_at_printf and @c nrf_modem_at_cmd. @@ -201,29 +240,9 @@ int nrf_modem_at_err_type(int error); */ int nrf_modem_at_err(int error); -/** - * @brief Set a list of AT commands to be filtered by @c nrf_modem_at_cmd. - * - * When a filter list is set, AT commands sent via @c nrf_modem_at_cmd that match any - * AT command in the filter will be redirected to the filter callback function instead - * of being sent to the modem. - * - * @note The filter is disabled by passing NULL to the @c filters and - * 0 to the @c len. - * - * @param filters AT filter list. - * @param len AT filter list size. - * - * @retval 0 On a success. - * @retval -NRF_EINVAL On invalid parameters. - */ -int nrf_modem_at_cmd_filter_set(struct nrf_modem_at_cmd_filter *filters, - size_t len); - #ifdef __cplusplus } #endif #endif /* NRF_MODEM_AT_H__ */ - /** @} */