|
| 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_ */ |
0 commit comments