Line data Source code
1 1 : /* 2 : * Copyright (c) 2019 Nordic Semiconductor ASA 3 : * 4 : * SPDX-License-Identifier: Apache-2.0 5 : */ 6 : 7 : /** @file 8 : * @brief Shell transport for the mcumgr SMP protocol. 9 : */ 10 : 11 : #ifndef ZEPHYR_INCLUDE_MGMT_SMP_SHELL_H_ 12 : #define ZEPHYR_INCLUDE_MGMT_SMP_SHELL_H_ 13 : 14 : #include <zephyr/types.h> 15 : 16 : #ifdef __cplusplus 17 : extern "C" { 18 : #endif 19 : 20 0 : #define SMP_SHELL_RX_BUF_SIZE 127 21 : 22 : /** @brief Data used by SMP shell */ 23 1 : struct smp_shell_data { 24 0 : struct net_buf_pool *buf_pool; 25 0 : struct k_fifo buf_ready; 26 0 : struct net_buf *buf; 27 0 : atomic_t esc_state; 28 : }; 29 : 30 : /** 31 : * @brief Attempt to process received bytes as part of an SMP frame. 32 : * 33 : * Called to scan buffer from the beginning and consume all bytes that are 34 : * part of SMP frame until frame or buffer ends. 35 : * 36 : * @param data SMP shell transfer data. 37 : * @param bytes Buffer with bytes to process 38 : * @param size Number of bytes to process 39 : * 40 : * @return number of bytes consumed by the SMP 41 : */ 42 1 : size_t smp_shell_rx_bytes(struct smp_shell_data *data, const uint8_t *bytes, 43 : size_t size); 44 : 45 : /** 46 : * @brief Processes SMP data and executes command if full frame was received. 47 : * 48 : * This function should be called from thread context. 49 : * 50 : * @param data SMP shell transfer data. 51 : */ 52 1 : void smp_shell_process(struct smp_shell_data *data); 53 : 54 : /** 55 : * @brief Initializes SMP transport over shell. 56 : * 57 : * This function should be called before feeding SMP transport with received 58 : * data. 59 : * 60 : * @return 0 on success 61 : */ 62 1 : int smp_shell_init(void); 63 : 64 : #ifdef __cplusplus 65 : } 66 : #endif 67 : 68 : #endif