Skip to content

Commit 1950ce6

Browse files
committed
smp - The built-in transfer encoding.
Simple management protocol.
1 parent 612dc4f commit 1950ce6

File tree

4 files changed

+517
-0
lines changed

4 files changed

+517
-0
lines changed

smp/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
target_include_directories(MCUMGR INTERFACE
2+
include
3+
)
4+
5+
zephyr_library_sources(
6+
smp/src/smp.c
7+
)

smp/include/smp/smp.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/**
21+
* @file
22+
* @brief SMP - Simple Management Protocol.
23+
*
24+
* SMP is a basic protocol that sits on top of the mgmt layer. SMP requests
25+
* and responses have the following format:
26+
*
27+
* [Offset 0]: Mgmt header
28+
* [Offset 8]: CBOR map of command-specific key-value pairs.
29+
*
30+
* SMP request packets may contain multiple concatenated requests. Each
31+
* request must start at an offset that is a multiple of 4, so padding should
32+
* be inserted between requests as necessary. Requests are processed
33+
* sequentially from the start of the packet to the end. Each response is sent
34+
* individually in its own packet. If a request elicits an error response,
35+
* processing of the packet is aborted.
36+
*/
37+
38+
#ifndef H_SMP_
39+
#define H_SMP_
40+
41+
#include "mgmt/mgmt.h"
42+
43+
#ifdef __cplusplus
44+
extern "C" {
45+
#endif
46+
47+
struct smp_streamer;
48+
struct mgmt_hdr;
49+
50+
/** @typedef smp_tx_rsp_fn
51+
* @brief Transmits an SMP response packet.
52+
*
53+
* @param ss The streamer to transmit via.
54+
* @param buf Buffer containing the response packet.
55+
* @param arg Optional streamer argument.
56+
*
57+
* @return 0 on success, MGMT_ERR_[...] code on failure.
58+
*/
59+
typedef int smp_tx_rsp_fn(struct smp_streamer *ss, void *buf, void *arg);
60+
61+
/**
62+
* @brief Decodes, encodes, and transmits SMP packets.
63+
*/
64+
struct smp_streamer {
65+
struct mgmt_streamer mgmt_stmr;
66+
smp_tx_rsp_fn *tx_rsp_cb;
67+
};
68+
69+
/**
70+
* @brief Processes a single SMP request packet and sends all corresponding
71+
* responses.
72+
*
73+
* Processes all SMP requests in an incoming packet. Requests are processed
74+
* sequentially from the start of the packet to the end. Each response is sent
75+
* individually in its own packet. If a request elicits an error response,
76+
* processing of the packet is aborted. This function consumes the supplied
77+
* request buffer regardless of the outcome.
78+
*
79+
* @param streamer The streamer providing the required SMP
80+
* callbacks.
81+
* @param req The request packet to process.
82+
*
83+
* @return 0 on success, MGMT_ERR_[...] code on failure.
84+
*/
85+
int smp_process_request_packet(struct smp_streamer *streamer, void *req);
86+
87+
#ifdef __cplusplus
88+
}
89+
#endif
90+
91+
#endif /* H_SMP_ */

smp/pkg.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
pkg.name: smp
21+
pkg.description: Server-side simple management protocol (SMP) functionality.
22+
pkg.author: "Apache Mynewt <[email protected]>"
23+
pkg.homepage: "http://mynewt.apache.org/"
24+
pkg.keywords:
25+
26+
pkg.deps:
27+
- '@apache-mynewt-core/encoding/cborattr'
28+
- '@apache-mynewt-core/kernel/os'
29+
- '@apache-mynewt-core/util/mem'
30+
- '@mynewt-mcumgr/mgmt'
31+
- '@mynewt-mcumgr/smp'
32+
33+
pkg.deps.NEWTMGR_BLE_HOST:
34+
- '@apache-mynewt-core/mgmt/newtmgr/transport/ble'
35+
36+
pkg.apis:
37+
- newtmgr
38+
39+
pkg.init:
40+
smp_pkg_init: 500

0 commit comments

Comments
 (0)