Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
smp.h File Reference

SMP - Simple Management Protocol. More...

#include <zephyr/net_buf.h>
#include <zephyr/mgmt/mcumgr/transport/smp.h>
#include <zcbor_common.h>

Go to the source code of this file.

Data Structures

struct  cbor_nb_reader
 
struct  cbor_nb_writer
 
struct  smp_streamer
 Decodes, encodes, and transmits SMP packets. More...
 

Enumerations

enum  smp_mcumgr_version_t { SMP_MCUMGR_VERSION_1 = 0 , SMP_MCUMGR_VERSION_2 }
 SMP MCUmgr protocol version, part of the SMP header. More...
 

Functions

struct net_bufsmp_packet_alloc (void)
 Allocates a net_buf for holding an mcumgr request or response.
 
void smp_packet_free (struct net_buf *nb)
 Frees an mcumgr net_buf.
 
int smp_process_request_packet (struct smp_streamer *streamer, void *req)
 Processes a single SMP request packet and sends all corresponding responses.
 
bool smp_add_cmd_err (zcbor_state_t *zse, uint16_t group, uint16_t ret)
 Appends an "err" response.
 
bool smp_add_cmd_ret (zcbor_state_t *zse, uint16_t group, uint16_t ret)
 

Detailed Description

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.

Enumeration Type Documentation

◆ smp_mcumgr_version_t

SMP MCUmgr protocol version, part of the SMP header.

Enumerator
SMP_MCUMGR_VERSION_1 

Version 1: the original protocol.

SMP_MCUMGR_VERSION_2 

Version 2: adds more detailed error reporting capabilities.

Function Documentation

◆ smp_add_cmd_err()

bool smp_add_cmd_err ( zcbor_state_t * zse,
uint16_t group,
uint16_t ret )

Appends an "err" response.

This appends an err response to a pending outgoing response which contains a result code for a specific group. Note that error codes are specific to the command group they are emitted from).

Parameters
zseThe zcbor encoder to use.
groupThe group which emitted the error.
retThe command result code to add.
Returns
true on success, false on failure (memory error).

◆ smp_add_cmd_ret()

bool smp_add_cmd_ret ( zcbor_state_t * zse,
uint16_t group,
uint16_t ret )
inline
Deprecated
Deprecated after Zephyr 3.4, use smp_add_cmd_err() instead

◆ smp_packet_alloc()

struct net_buf * smp_packet_alloc ( void )

Allocates a net_buf for holding an mcumgr request or response.

Returns
A newly-allocated buffer net_buf on success; NULL on failure.

◆ smp_packet_free()

void smp_packet_free ( struct net_buf * nb)

Frees an mcumgr net_buf.

Parameters
nbThe net_buf to free.

◆ smp_process_request_packet()

int smp_process_request_packet ( struct smp_streamer * streamer,
void * req )

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.

Parameters
streamerThe streamer providing the required SMP callbacks.
reqThe request packet to process.
Returns
0 on success, mcumgr_err_t code on failure.