Skip to content

Commit a7e40b3

Browse files
de-nordiccarlescufi
authored andcommitted
mgmt/mcumgr: Drop zephyr_ prefix from functions
The MCUMgr library is now part of Zephyr, so there is no point to prefix SMP functions with Zephyr. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 44be5c9 commit a7e40b3

File tree

12 files changed

+158
-92
lines changed

12 files changed

+158
-92
lines changed

include/zephyr/mgmt/mcumgr/smp.h

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@
1313
extern "C" {
1414
#endif
1515

16+
struct smp_transport;
1617
struct zephyr_smp_transport;
1718
struct net_buf;
1819

19-
/** @typedef zephyr_smp_transport_out_fn
20-
* @brief SMP transmit function for Zephyr.
20+
/** @typedef smp_transport_out_fn
21+
* @brief SMP transmit callback for transport
2122
*
2223
* The supplied net_buf is always consumed, regardless of return code.
2324
*
2425
* @param nb The net_buf to transmit.
2526
*
2627
* @return 0 on success, MGMT_ERR_[...] code on failure.
2728
*/
29+
typedef int (*smp_transport_out_fn)(struct net_buf *nb);
30+
/* use smp_transport_out_fn instead */
2831
typedef int zephyr_smp_transport_out_fn(struct net_buf *nb);
2932

30-
/** @typedef zephyr_smp_transport_get_mtu_fn
31-
* @brief SMP MTU query function for Zephyr.
33+
/** @typedef smp_transport_get_mtu_fn
34+
* @brief SMP MTU query callback for transport
3235
*
3336
* The supplied net_buf should contain a request received from the peer whose
3437
* MTU is being queried. This function takes a net_buf parameter because some
@@ -40,10 +43,12 @@ typedef int zephyr_smp_transport_out_fn(struct net_buf *nb);
4043
* @return The transport's MTU;
4144
* 0 if transmission is currently not possible.
4245
*/
46+
typedef uint16_t (*smp_transport_get_mtu_fn)(const struct net_buf *nb);
47+
/* use smp_transport_get_mtu_fn instead */
4348
typedef uint16_t zephyr_smp_transport_get_mtu_fn(const struct net_buf *nb);
4449

45-
/** @typedef zephyr_smp_transport_ud_copy_fn
46-
* @brief SMP copy buffer user_data function for Zephyr.
50+
/** @typedef smp_transport_ud_copy_fn
51+
* @brief SMP copy user_data callback
4752
*
4853
* The supplied src net_buf should contain a user_data that cannot be copied
4954
* using regular memcpy function (e.g., the BLE transport net_buf user_data
@@ -55,34 +60,61 @@ typedef uint16_t zephyr_smp_transport_get_mtu_fn(const struct net_buf *nb);
5560
*
5661
* @return 0 on success, MGMT_ERR_[...] code on failure.
5762
*/
63+
typedef int (*smp_transport_ud_copy_fn)(struct net_buf *dst,
64+
const struct net_buf *src);
65+
/* use smp_transport_ud_copy_fn instead */
5866
typedef int zephyr_smp_transport_ud_copy_fn(struct net_buf *dst,
5967
const struct net_buf *src);
6068

61-
/** @typedef zephyr_smp_transport_ud_free_fn
62-
* @brief SMP free buffer user_data function for Zephyr.
69+
/** @typedef smp_transport_ud_free_fn
70+
* @brief SMP free user_data callback
6371
*
6472
* This function frees net_buf user data, because some transports store
6573
* connection-specific information in the net_buf user data (e.g., the BLE
6674
* transport stores the connection reference that has to be decreased).
6775
*
6876
* @param ud Contains a user_data pointer to be freed.
6977
*/
78+
typedef void (*smp_transport_ud_free_fn)(void *ud);
79+
/* use smp_transport_ud_free_fn instead */
7080
typedef void zephyr_smp_transport_ud_free_fn(void *ud);
7181

7282
/**
73-
* @brief Provides Zephyr-specific functionality for sending SMP responses.
83+
* @brief SMP transport object for sending SMP responses.
7484
*/
85+
struct smp_transport {
86+
/* Must be the first member. */
87+
struct k_work zst_work;
88+
89+
/* FIFO containing incoming requests to be processed. */
90+
struct k_fifo zst_fifo;
91+
92+
smp_transport_out_fn zst_output;
93+
smp_transport_get_mtu_fn zst_get_mtu;
94+
smp_transport_ud_copy_fn zst_ud_copy;
95+
smp_transport_ud_free_fn zst_ud_free;
96+
97+
#ifdef CONFIG_MCUMGR_SMP_REASSEMBLY
98+
/* Packet reassembly internal data, API access only */
99+
struct {
100+
struct net_buf *current; /* net_buf used for reassembly */
101+
uint16_t expected; /* expected bytes to come */
102+
} __reassembly;
103+
#endif
104+
};
105+
106+
/* Deprecated, use smp_transport instead */
75107
struct zephyr_smp_transport {
76108
/* Must be the first member. */
77109
struct k_work zst_work;
78110

79111
/* FIFO containing incoming requests to be processed. */
80112
struct k_fifo zst_fifo;
81113

82-
zephyr_smp_transport_out_fn *zst_output;
83-
zephyr_smp_transport_get_mtu_fn *zst_get_mtu;
84-
zephyr_smp_transport_ud_copy_fn *zst_ud_copy;
85-
zephyr_smp_transport_ud_free_fn *zst_ud_free;
114+
smp_transport_out_fn zst_output;
115+
smp_transport_get_mtu_fn zst_get_mtu;
116+
smp_transport_ud_copy_fn zst_ud_copy;
117+
smp_transport_ud_free_fn zst_ud_free;
86118

87119
#ifdef CONFIG_MCUMGR_SMP_REASSEMBLY
88120
/* Packet reassembly internal data, API access only */
@@ -102,11 +134,25 @@ struct zephyr_smp_transport {
102134
* @param ud_copy_func The transport buffer user_data copy function.
103135
* @param ud_free_func The transport buffer user_data free function.
104136
*/
105-
void zephyr_smp_transport_init(struct zephyr_smp_transport *zst,
137+
void smp_transport_init(struct smp_transport *zst,
138+
smp_transport_out_fn output_func,
139+
smp_transport_get_mtu_fn get_mtu_func,
140+
smp_transport_ud_copy_fn ud_copy_func,
141+
smp_transport_ud_free_fn ud_free_func);
142+
143+
static inline
144+
void zephyr_smp_transport_init(struct zephyr_smp_transport *smpt,
106145
zephyr_smp_transport_out_fn *output_func,
107146
zephyr_smp_transport_get_mtu_fn *get_mtu_func,
108147
zephyr_smp_transport_ud_copy_fn *ud_copy_func,
109-
zephyr_smp_transport_ud_free_fn *ud_free_func);
148+
zephyr_smp_transport_ud_free_fn *ud_free_func)
149+
{
150+
smp_transport_init((struct smp_transport *)smpt,
151+
(smp_transport_out_fn)output_func,
152+
(smp_transport_get_mtu_fn)get_mtu_func,
153+
(smp_transport_ud_copy_fn)ud_copy_func,
154+
(smp_transport_ud_free_fn)ud_free_func);
155+
}
110156

111157
#ifdef __cplusplus
112158
}

subsys/mgmt/mcumgr/lib/smp/include/smp/smp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct mgmt_hdr;
3838
* @brief Decodes, encodes, and transmits SMP packets.
3939
*/
4040
struct smp_streamer {
41-
struct zephyr_smp_transport *smpt;
41+
struct smp_transport *smpt;
4242
struct cbor_nb_reader *reader;
4343
struct cbor_nb_writer *writer;
4444
};

subsys/mgmt/mcumgr/lib/smp/src/smp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ smp_on_err(struct smp_streamer *streamer, const struct mgmt_hdr *req_hdr,
233233
}
234234

235235
/* Free any extra buffers. */
236-
zephyr_smp_free_buf(req, streamer->smpt);
237-
zephyr_smp_free_buf(rsp, streamer->smpt);
236+
smp_free_buf(req, streamer->smpt);
237+
smp_free_buf(rsp, streamer->smpt);
238238
}
239239

240240
/**
@@ -290,7 +290,7 @@ smp_process_request_packet(struct smp_streamer *streamer, void *vreq)
290290
break;
291291
}
292292

293-
rsp = zephyr_smp_alloc_rsp(req, streamer->smpt);
293+
rsp = smp_alloc_rsp(req, streamer->smpt);
294294
if (rsp == NULL) {
295295
rc = MGMT_ERR_ENOMEM;
296296
break;
@@ -332,8 +332,8 @@ smp_process_request_packet(struct smp_streamer *streamer, void *vreq)
332332
return rc;
333333
}
334334

335-
zephyr_smp_free_buf(req, streamer->smpt);
336-
zephyr_smp_free_buf(rsp, streamer->smpt);
335+
smp_free_buf(req, streamer->smpt);
336+
smp_free_buf(rsp, streamer->smpt);
337337

338338
return rc;
339339
}

subsys/mgmt/mcumgr/smp.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ static const struct k_work_queue_config smp_work_queue_config = {
4545
* @return Newly-allocated buffer on success
4646
* NULL on failure.
4747
*/
48-
void *zephyr_smp_alloc_rsp(const void *req, void *arg)
48+
void *smp_alloc_rsp(const void *req, void *arg)
4949
{
5050
const struct net_buf *req_nb;
5151
struct net_buf *rsp_nb;
52-
struct zephyr_smp_transport *zst = arg;
52+
struct smp_transport *zst = arg;
5353

5454
req_nb = req;
5555

@@ -69,9 +69,9 @@ void *zephyr_smp_alloc_rsp(const void *req, void *arg)
6969
return rsp_nb;
7070
}
7171

72-
void zephyr_smp_free_buf(void *buf, void *arg)
72+
void smp_free_buf(void *buf, void *arg)
7373
{
74-
struct zephyr_smp_transport *zst = arg;
74+
struct smp_transport *zst = arg;
7575

7676
if (!buf) {
7777
return;
@@ -88,7 +88,7 @@ void zephyr_smp_free_buf(void *buf, void *arg)
8888
* Processes a single SMP packet and sends the corresponding response(s).
8989
*/
9090
static int
91-
zephyr_smp_process_packet(struct zephyr_smp_transport *zst,
91+
smp_process_packet(struct smp_transport *zst,
9292
struct net_buf *nb)
9393
{
9494
struct cbor_nb_reader reader;
@@ -110,37 +110,37 @@ zephyr_smp_process_packet(struct zephyr_smp_transport *zst,
110110
* Processes all received SNP request packets.
111111
*/
112112
static void
113-
zephyr_smp_handle_reqs(struct k_work *work)
113+
smp_handle_reqs(struct k_work *work)
114114
{
115-
struct zephyr_smp_transport *zst;
115+
struct smp_transport *zst;
116116
struct net_buf *nb;
117117

118118
zst = (void *)work;
119119

120120
while ((nb = net_buf_get(&zst->zst_fifo, K_NO_WAIT)) != NULL) {
121-
zephyr_smp_process_packet(zst, nb);
121+
smp_process_packet(zst, nb);
122122
}
123123
}
124124

125125
void
126-
zephyr_smp_transport_init(struct zephyr_smp_transport *zst,
127-
zephyr_smp_transport_out_fn *output_func,
128-
zephyr_smp_transport_get_mtu_fn *get_mtu_func,
129-
zephyr_smp_transport_ud_copy_fn *ud_copy_func,
130-
zephyr_smp_transport_ud_free_fn *ud_free_func)
126+
smp_transport_init(struct smp_transport *zst,
127+
smp_transport_out_fn output_func,
128+
smp_transport_get_mtu_fn get_mtu_func,
129+
smp_transport_ud_copy_fn ud_copy_func,
130+
smp_transport_ud_free_fn ud_free_func)
131131
{
132-
*zst = (struct zephyr_smp_transport) {
132+
*zst = (struct smp_transport) {
133133
.zst_output = output_func,
134134
.zst_get_mtu = get_mtu_func,
135135
.zst_ud_copy = ud_copy_func,
136136
.zst_ud_free = ud_free_func,
137137
};
138138

139139
#ifdef CONFIG_MCUMGR_SMP_REASSEMBLY
140-
zephyr_smp_reassembly_init(zst);
140+
smp_reassembly_init(zst);
141141
#endif
142142

143-
k_work_init(&zst->zst_work, zephyr_smp_handle_reqs);
143+
k_work_init(&zst->zst_work, smp_handle_reqs);
144144
k_fifo_init(&zst->zst_fifo);
145145
}
146146

@@ -154,13 +154,13 @@ zephyr_smp_transport_init(struct zephyr_smp_transport *zst,
154154
* @param nb The request packet to process.
155155
*/
156156
WEAK void
157-
zephyr_smp_rx_req(struct zephyr_smp_transport *zst, struct net_buf *nb)
157+
smp_rx_req(struct smp_transport *zst, struct net_buf *nb)
158158
{
159159
net_buf_put(&zst->zst_fifo, nb);
160160
k_work_submit_to_queue(&smp_work_queue, &zst->zst_work);
161161
}
162162

163-
static int zephyr_smp_init(const struct device *dev)
163+
static int smp_init(const struct device *dev)
164164
{
165165
k_work_queue_init(&smp_work_queue);
166166

@@ -171,4 +171,4 @@ static int zephyr_smp_init(const struct device *dev)
171171
return 0;
172172
}
173173

174-
SYS_INIT(zephyr_smp_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
174+
SYS_INIT(smp_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

subsys/mgmt/mcumgr/smp_internal.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
extern "C" {
1313
#endif
1414

15+
struct smp_transport;
1516
struct zephyr_smp_transport;
1617
struct net_buf;
1718

@@ -24,7 +25,13 @@ struct net_buf;
2425
* response(s).
2526
* @param nb The request packet to process.
2627
*/
27-
void zephyr_smp_rx_req(struct zephyr_smp_transport *zst, struct net_buf *nb);
28+
void smp_rx_req(struct smp_transport *zst, struct net_buf *nb);
29+
30+
static inline
31+
void zephyr_smp_rx_req(struct zephyr_smp_transport *smpt, struct net_buf *nb)
32+
{
33+
smp_rx_req((struct smp_transport *)smpt, nb);
34+
}
2835

2936
/**
3037
* @brief Allocates a response buffer.
@@ -37,15 +44,28 @@ void zephyr_smp_rx_req(struct zephyr_smp_transport *zst, struct net_buf *nb);
3744
* @return Newly-allocated buffer on success
3845
* NULL on failure.
3946
*/
40-
void *zephyr_smp_alloc_rsp(const void *req, void *arg);
47+
void *smp_alloc_rsp(const void *req, void *arg);
48+
49+
static inline
50+
void *zephyr_smp_alloc_rsp(const void *req, void *arg)
51+
{
52+
return smp_alloc_rsp(req, arg);
53+
}
54+
4155

4256
/**
4357
* @brief Frees an allocated buffer.
4458
*
4559
* @param buf The buffer to free.
4660
* @param arg The streamer providing the callback.
4761
*/
48-
void zephyr_smp_free_buf(void *buf, void *arg);
62+
void smp_free_buf(void *buf, void *arg);
63+
64+
static inline
65+
void zephyr_smp_free_buf(void *buf, void *arg)
66+
{
67+
smp_free_buf(buf, arg);
68+
}
4969

5070
#ifdef __cplusplus
5171
}

0 commit comments

Comments
 (0)