Lines Matching +full:header +full:- +full:payload

2  * Copyright (c) 2018-2021 mcumgr authors
3 * Copyright (c) 2022-2023 Nordic Semiconductor ASA
5 * SPDX-License-Identifier: Apache-2.0
8 /** SMP - Simple Management Protocol. */
34 * @param err Group-specific error code
54 cnr->nb = nb; in cbor_nb_reader_init()
55 zcbor_new_decode_state(cnr->zs, ARRAY_SIZE(cnr->zs), nb->data, in cbor_nb_reader_init()
56 nb->len, 1, NULL, 0); in cbor_nb_reader_init()
62 cnw->nb = nb; in cbor_nb_writer_init()
63 cnw->nb->len = sizeof(struct smp_hdr); in cbor_nb_writer_init()
64 zcbor_new_encode_state(cnw->zs, ARRAY_SIZE(cnw->zs), nb->data + sizeof(struct smp_hdr), in cbor_nb_writer_init()
85 .nh_op = smp_rsp_op(req_hdr->nh_op), in smp_make_rsp_hdr()
86 .nh_group = sys_cpu_to_be16(req_hdr->nh_group), in smp_make_rsp_hdr()
87 .nh_seq = req_hdr->nh_seq, in smp_make_rsp_hdr()
88 .nh_id = req_hdr->nh_id, in smp_make_rsp_hdr()
89 .nh_version = (req_hdr->nh_version > SMP_MCUMGR_VERSION_2 ? SMP_MCUMGR_VERSION_2 : in smp_make_rsp_hdr()
90 req_hdr->nh_version), in smp_make_rsp_hdr()
96 if (nb->len < sizeof(*dst_hdr)) { in smp_read_hdr()
100 memcpy(dst_hdr, nb->data, sizeof(*dst_hdr)); in smp_read_hdr()
101 dst_hdr->nh_len = sys_be16_to_cpu(dst_hdr->nh_len); in smp_read_hdr()
102 dst_hdr->nh_group = sys_be16_to_cpu(dst_hdr->nh_group); in smp_read_hdr()
109 memcpy(streamer->writer->nb->data, src_hdr, sizeof(*src_hdr)); in smp_write_hdr()
117 struct cbor_nb_writer *nbw = streamer->writer; in smp_build_err_rsp()
118 zcbor_state_t *zsp = nbw->zs; in smp_build_err_rsp()
140 zsp->payload_mut - nbw->nb->data - MGMT_HDR_SIZE); in smp_build_err_rsp()
141 nbw->nb->len = zsp->payload_mut - nbw->nb->data; in smp_build_err_rsp()
148 * Processes a single SMP request and generates a response payload (i.e.,
149 * everything after the management header). On success, the response payload
155 * @param req_hdr The management header belonging to the incoming request (host-byte order).
172 group = mgmt_find_group(req_hdr->nh_group); in smp_handle_single_payload()
177 handler = mgmt_get_handler(group, req_hdr->nh_id); in smp_handle_single_payload()
182 switch (req_hdr->nh_op) { in smp_handle_single_payload()
184 handler_fn = handler->mh_read; in smp_handle_single_payload()
188 handler_fn = handler->mh_write; in smp_handle_single_payload()
199 if (!group->custom_payload) { in smp_handle_single_payload()
201 ok = zcbor_map_start_encode(cbuf->writer->zs, in smp_handle_single_payload()
214 cmd_recv.group = req_hdr->nh_group; in smp_handle_single_payload()
215 cmd_recv.id = req_hdr->nh_id; in smp_handle_single_payload()
216 cmd_recv.op = req_hdr->nh_op; in smp_handle_single_payload()
229 ok = smp_add_cmd_err(cbuf->writer->zs, err_group, in smp_handle_single_payload()
245 if (!group->custom_payload) { in smp_handle_single_payload()
247 /* End response payload. */ in smp_handle_single_payload()
248 if (!zcbor_map_end_encode(cbuf->writer->zs, in smp_handle_single_payload()
265 * header and payload). On success, the response is written using the supplied
270 * @param req_hdr The management header belonging to the incoming request (host-byte order).
278 struct cbor_nb_writer *nbw = streamer->writer; in smp_handle_single_req()
279 zcbor_state_t *zsp = nbw->zs; in smp_handle_single_req()
283 nbw->error_group = 0; in smp_handle_single_req()
284 nbw->error_ret = 0; in smp_handle_single_req()
286 if (req_hdr->nh_version == SMP_MCUMGR_VERSION_1) { in smp_handle_single_req()
293 if (req_hdr->nh_version > SMP_MCUMGR_VERSION_2) { in smp_handle_single_req()
297 /* Process the request and write the response payload. */ in smp_handle_single_req()
306 if (nbw->error_ret != 0 && req_hdr->nh_version == 0) { in smp_handle_single_req()
307 rc = smp_translate_error_code(nbw->error_group, nbw->error_ret); in smp_handle_single_req()
314 zsp->payload_mut - nbw->nb->data - MGMT_HDR_SIZE); in smp_handle_single_req()
315 nbw->nb->len = zsp->payload_mut - nbw->nb->data; in smp_handle_single_req()
326 * @param req_hdr The header of the request which elicited the error.
347 cbor_nb_writer_init(streamer->writer, rsp); in smp_on_err()
352 streamer->smpt->functions.output(rsp); in smp_on_err()
357 smp_free_buf(req, streamer->smpt); in smp_on_err()
358 smp_free_buf(rsp, streamer->smpt); in smp_on_err()
377 * MGMT_ERR_ECORRUPT if buffer starts with non SMP data header or there
378 * is not enough bytes to process header, or other MGMT_ERR_[...] code on
399 while (req->len > 0) { in smp_process_request_packet()
403 /* Read the management header and strip it from the request. */ in smp_process_request_packet()
414 if (req->len < req_hdr.nh_len) { in smp_process_request_packet()
420 rsp = smp_alloc_rsp(req, streamer->smpt); in smp_process_request_packet()
426 cbor_nb_reader_init(streamer->reader, req); in smp_process_request_packet()
427 cbor_nb_writer_init(streamer->writer, rsp); in smp_process_request_packet()
429 /* Process the request payload and build the response. */ in smp_process_request_packet()
437 rc = streamer->smpt->functions.output(rsp); in smp_process_request_packet()
487 smp_free_buf(req, streamer->smpt); in smp_process_request_packet()
488 smp_free_buf(rsp, streamer->smpt); in smp_process_request_packet()
501 container->error_group = group; in smp_add_cmd_err()
502 container->error_ret = ret; in smp_add_cmd_err()