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/kernel.h>
15 #include <zephyr/types.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #define SMP_SHELL_RX_BUF_SIZE	127
22 
23 /** @brief Data used by SMP shell */
24 struct smp_shell_data {
25 	struct net_buf_pool *buf_pool;
26 	struct k_fifo buf_ready;
27 	struct net_buf *buf;
28 	atomic_t esc_state;
29 };
30 
31 /**
32  * @brief Attempt to process received bytes as part of an SMP frame.
33  *
34  * Called to scan buffer from the beginning and consume all bytes that are
35  * part of SMP frame until frame or buffer ends.
36  *
37  * @param data SMP shell transfer data.
38  * @param bytes Buffer with bytes to process
39  * @param size Number of bytes to process
40  *
41  * @return number of bytes consumed by the SMP
42  */
43 size_t smp_shell_rx_bytes(struct smp_shell_data *data, const uint8_t *bytes,
44 			  size_t size);
45 
46 /**
47  * @brief Processes SMP data and executes command if full frame was received.
48  *
49  * This function should be called from thread context.
50  *
51  * @param data SMP shell transfer data.
52  */
53 void smp_shell_process(struct smp_shell_data *data);
54 
55 /**
56  * @brief Initializes SMP transport over shell.
57  *
58  * This function should be called before feeding SMP transport with received
59  * data.
60  *
61  * @return 0 on success
62  */
63 int smp_shell_init(void);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif
70