Line data Source code
1 1 : /* 2 : * Copyright Runtime.io 2018. All rights reserved. 3 : * Copyright Laird Connectivity 2021-2022. All rights reserved. 4 : * 5 : * SPDX-License-Identifier: Apache-2.0 6 : */ 7 : 8 : /** @file 9 : * @brief Dummy transport for the mcumgr SMP protocol for unit testing. 10 : */ 11 : #ifndef ZEPHYR_INCLUDE_MGMT_MCUMGR_TRANSPORT_DUMMY_H_ 12 : #define ZEPHYR_INCLUDE_MGMT_MCUMGR_TRANSPORT_DUMMY_H_ 13 : 14 : #include <zephyr/kernel.h> 15 : #include <zephyr/net_buf.h> 16 : #include <zephyr/mgmt/mcumgr/mgmt/mgmt.h> 17 : #include <zephyr/mgmt/mcumgr/transport/serial.h> 18 : 19 : #ifdef __cplusplus 20 : extern "C" { 21 : #endif 22 : 23 : /** 24 : * @brief Clears internal dummy SMP state and resets semaphore 25 : */ 26 1 : void smp_dummy_clear_state(void); 27 : 28 : /** 29 : * @brief Adds SMPC data to the internal buffer to be processed 30 : * 31 : * @param data Input data buffer 32 : * @param data_size Size of data (in bytes) 33 : */ 34 1 : void dummy_mcumgr_add_data(uint8_t *data, uint16_t data_size); 35 : 36 : /** 37 : * @brief Processes a single line (fragment) coming from the mcumgr response to 38 : * be used in tests 39 : * 40 : * @retval net buffer of processed data 41 : */ 42 1 : struct net_buf *smp_dummy_get_outgoing(void); 43 : 44 : /** 45 : * @brief Waits for a period of time for outgoing SMPC data to be ready and 46 : * returns either when a full message is ready or when the timeout has 47 : * elapsed. 48 : * 49 : * @param wait_time_s Time to wait for data (in seconds) 50 : * 51 : * @retval true on message received successfully, false on timeout 52 : */ 53 1 : bool smp_dummy_wait_for_data(uint32_t wait_time_s); 54 : 55 : /** 56 : * @brief Calls dummy_mcumgr_add_data with the internal SMPC receive buffer. 57 : */ 58 1 : void smp_dummy_add_data(void); 59 : 60 : /** 61 : * @brief Gets current send buffer position 62 : * 63 : * @retval Current send buffer position (in bytes) 64 : */ 65 1 : uint16_t smp_dummy_get_send_pos(void); 66 : 67 : /** 68 : * @brief Gets current receive buffer position 69 : * 70 : * @retval Current receive buffer position (in bytes) 71 : */ 72 1 : uint16_t smp_dummy_get_receive_pos(void); 73 : 74 : /** 75 : * @brief Converts input data to go out through the internal SMPC buffer. 76 : * 77 : * @param data Input data buffer 78 : * @param len Size of data (in bytes) 79 : * 80 : * @retval 0 on success, negative on error. 81 : */ 82 1 : int smp_dummy_tx_pkt(const uint8_t *data, int len); 83 : 84 : /** 85 : * @brief Enabled the dummy SMP module (will process sent/received data) 86 : */ 87 1 : void smp_dummy_enable(void); 88 : 89 : /** 90 : * @brief Disables the dummy SMP module (will not process sent/received data) 91 : */ 92 1 : void smp_dummy_disable(void); 93 : 94 : /** 95 : * @brief Returns status on if the dummy SMP system is active 96 : * 97 : * @retval true if dummy SMP is enabled, false otherwise 98 : */ 99 1 : bool smp_dummy_get_status(void); 100 : 101 : #ifdef __cplusplus 102 : } 103 : #endif 104 : 105 : #endif /* ZEPHYR_INCLUDE_MGMT_MCUMGR_TRANSPORT_DUMMY_H_ */