Advertisement

OS服务——SMP协议规范——SMP协议规范

阅读量:

本摘要总结了mcumgr库中使用的简单管理协议(SMP)及其相关机制:
SMP协议:作为mcumgr库的核心机制,用于将请求传递给设备并接收响应。
信封结构:每个帧由头(包括数据长度字段)和数据组成;支持碎片化传输时可重组目的。
操作代码:包含4个操作码(0-3),分别表示读取请求/读取响应/写入请求/写入响应。
管理组ID:分为预定义和自定义组(如默认/操作系统管理组),通常CBOR编码。
最小响应:所有请求均应返回CBOR目录结构的最小响应;若对方无SMP服务或设备无应答则允许缺少。
状态/错误代码:包括10种可能的状态码(如无误、超时等),由Zephyr用MGMTERR前缀扩展支持。
应用支持:当前仅限于Zephyr官方文档中列出的支持范围内的管理小组与操作码。

SMP协议规范

该协议旨在简明扼要地阐述SMP的基本功能。其中,在该模块中通过...的形式实现了资源数据与设备间的高效交互。

SMP是一个应用程序层协议。底层传输层不在本文档的范围内。

框架:信封

每个帧由前导部分以及后续数据构成。当传输层协议支持碎片化时,报告头中的'数据长度'字段可用于重组目的。该编码方案标记为'大编码'(即网络编码),其中各字段均包含多于一个字节,并采用如下格式:

3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
Res OP Flags Data Length
Group ID Sequence Num Command ID
Data …

注意:

最初提出的规范规定

该系统支持可选的数据输入,在数据长度为零的情况下则不再存在。各组别或个体的数据编码将依据其group/ID目标来确定。

其中,字段的含义为:

Field Description
Res This is reserved, not-used field and should be always set to 0.
OP Operation code
Flags Reserved for flags; there are no flags defined yet, the field should be set to 0
Data Length Length of the Data field
Group ID Management Group ID’s
Sequence Num This is a frame sequence number. The number is increased by one with each request frame. The Sequence Num of a response should match the one in the request.
Command ID This is a command, within Group.
Data This is data payload of the Data Length size. It is optional as Data Length may be set to zero, which means that no data follows the header.

注意:

数据的内容取决于OP、组ID和命令ID的值。

注意:

Res字段可能会被Zephyr重新用于协议版本。

操作代码

操作代码决定了相关信息是要传输至设备还是由设备发起请求,并且需要检查数据包中是否有来自SMP服务器的发包请求或者来自该服务器的数据包响应。

已定义了以下操作代码。

Decimal ID Operation
0 read request
1 read response
2 write request
3 write response

管理组ID

SMP 协议包含预先配置的标准群组,并提供给用户自定义群组的机会。表格列举了常见的群组

Decimal ID Group description
0 Default/OS Management Group
1 Application/software image management group
2 Statistics management
3 Application/system configuration (currently not used by Zephyr)
4 Application/system log management (currently not used by Zephyr)
5 Run-time tests (unused by Zephyr)
6 Split image management (unused by Zephyr)
7 Test crashing application (unused by Zephyr)
8 File management
9 Shell management
63 Zephyr specific basic commands group
64 This is the base group for defining an application specific management groups.

上述组的有效载荷通常为CBOR编码方案。其中64及以上范围内的各组参数值由应用程序开发者根据需求自行设定;同时在本文文档中并未对这些参数值的具体取值进行明确的规定。

最小响应

不论您发出何种指令,在请求的另一端存在SMP客户端的情况下,请务必返回包含头信息以及CBOR映射容器的响应数据包。仅在没有任何SMP服务可用或者设备未能有效响应时才允许缺少响应数据包。

最小响应SMP数据

最小的响应是CBOR目录:

复制代码
    {
    (str)"rc" : (int)
    }

这里

“rc” Status/error codes in responses

响应中的状态/错误代码

Decimal ID Meaning
0 No error, OK.
1 Unknown error.
2 Not enough memory; this error is reported when there is not enough memory to complete response.
3 Invalid value; a request contains an invalid value.
4 Timeout; the operation for some reason could not be completed in assumed time.
5 No entry; the error means that request frame has been missing some information that is required to perform action. It may also mean that requested information is not available.
6 Bad state; the error means that application or device is in a state that would not allow it to perform or complete a requested action.
7 Response too long; this error is issued when buffer assigned for gathering response is not big enough.
8 Not supported; usually issued when requested Group ID or Command ID is not supported by application.
9 Corrupted payload received.
10 Device is busy with processing previous SMP request and may not process incoming one. Client should re-try later.
256 This is base error number of user defined error codes.

Zephyr依赖于位于头文件subsys/mgmt/mcumgr/lib/mgmt/include/mgmt/mgmt.h中的MGMT_ERR_前缀定义来实现相关的功能。

由Zephyr支持的管理小组的规范

  • 操作系统相关的默认配置设置
    • 应用软件的镜像及安装包管理
    • 数据统计与分析功能模块
    • 文件存储与访问权限配置
    • 脚本执行与命令行参数配置

全部评论 (0)

还没有任何评论哟~