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