Part 1
요약·해설
BLE UUID와 ordered fragmentation, UART 127-byte 제한, initial/partial/final marker, Base64 용량 계산과 CRC16 범위를 다룹니다.
Write · Notification
Base64 framing
CRC16 0x1021
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
C9521EDC0E64A958D3ACF79876AAF2E0BB150CA8FDECEAD8B1C4508645DADB09
.. _mcumgr_smp_transport_specification:
SMP Transport Specification
###########################
The documents specifies information needed for implementing server and client
side SMP transports.
.. _mcumgr_smp_transport_ble:
BLE (Bluetooth Low Energy)
**************************
MCUmgr Clients need to use following BLE Characteristics, when implementing
SMP client:
- **Service UUID**: `8D53DC1D-1DB7-4CD3-868B-8A527460AA84`
- **Characteristic UUID**: `DA2E7828-FBCE-4E01-AE9E-261174997C48`
All SMP communication utilizes a single GATT characteristic. An SMP request is
sent via a GATT Write Without Response command. An SMP response is sent in the form
of a GATT Notification
If an SMP request or response is too large to fit in a single GATT command, the
sender fragments it across several packets. No additional framing is
introduced when a request or response is fragmented; the payload is simply
split among several packets. Since GATT guarantees ordered delivery of
packets, the SMP header in the first fragment contains sufficient information
for reassembly.
.. _mcumgr_smp_transport_uart:
UART/serial and console
***********************
SMP protocol specification by MCUmgr subsystem of Zephyr uses basic framing
of data to allow multiplexing of UART channel. Multiplexing requires
prefixing each frame with two byte marker and terminating it with newline.
Currently MCUmgr imposes a 127 byte limit on frame size, although there
are no real protocol constraints that require that limit.
The limit includes the prefix and the newline character, so the allowed payload
size is actually 124 bytes.
Although no such transport exists in Zephyr, it is possible to implement
MCUmgr client/server over UART transport that does not have framing at all,
or uses hardware serial port control, or other means of framing.
Frame fragmenting
=================
SMP protocol over serial is fragmented into MTU size frames; each
frame consists of two byte start marker, body and terminating newline
character.
There are four types of types of frames: initial, partial, partial-final
and initial-final; each frame type differs by start marker and/or body
contents.
Frame formats
-------------
Initial frame requires to be followed by optional sequence of partial
frames and finally by partial-final frame.
Body is always Base64 encoded, so the body size, here described as
MTU - 3, is able to actually carry N = (MTU - 3) / 4 * 3 bytes
of raw data.
Body of initial frame is preceded by two byte total packet length,
encoded in Big Endian, and equals size of a raw body plus two bytes,
size of CRC16; this means that actual body size allowed into an
initial frame is N - 2.
If a body size is smaller than N - 4, than it is possible to carry
entire body with preceding length and following it CRC in a single
frame, here called initial-final; for the description of initial-final
frame look below.
Initial frame format:
.. table::
:align: center
+---------------+---------------+---------------------------+
| Content | Size | Description |
+===============+===============+===========================+
| 0x06 0x09 | 2 bytes | Frame start marker |
+---------------+---------------+---------------------------+
| <base64-i> | no more than | Base64 encoded body |
| | MTU - 3 bytes | |
+---------------+---------------+---------------------------+
| 0x0a | 1 byte | Frame termination |
+---------------+---------------+---------------------------+
``<base64-i>`` is Base64 encoded body of format:
.. table::
:align: center
+---------------+---------------+---------------------------+
| Content | Size | Description |
+===============+===============+===========================+
| total length | 2 bytes | Big endian 16-bit value |
| | | representing total length |
| | | of body + 2 bytes for |
| | | CRC16; note that size of |
| | | total length field is not |
| | | added to total length |
| | | value. |
+---------------+---------------+---------------------------+
| body | no more than | Raw body data fragment |
| | MTU - 5 | |
+---------------+---------------+---------------------------+
Initial-final frame format is similar to initial frame format,
but differs by ``<base64-i>`` definition.
``<base64-i>`` of initial-final frame, is Base64 encoded data taking
form:
.. table::
:align: center
+---------------+---------------+---------------------------+
| Content | Size | Description |
+===============+===============+===========================+
| total length | 2 bytes | Big endian 16-bit value |
| | | representing total length |
| | | of body + 2 bytes for |
| | | CRC16; note that size of |
| | | total length field is not |
| | | added to total length |
| | | value. |
+---------------+---------------+---------------------------+
| body | no more than | Raw body data fragment |
| | MTU - 7 | |
+---------------+---------------+---------------------------+
| crc16 | 2 bytes | CRC16 of entire packet |
| | | body, preceding length |
| | | not included. |
+---------------+---------------+---------------------------+
Partial frame is continuation after previous initial or other partial
frame. Partial frame takes form:
.. table::
:align: center
+---------------+---------------+---------------------------+
| Content | Size | Description |
+===============+===============+===========================+
| 0x04 0x14 | 2 bytes | Frame start marker |
+---------------+---------------+---------------------------+
| <base64-i> | no more than | Base64 encoded body |
| | MTU - 3 bytes | |
+---------------+---------------+---------------------------+
| 0x0a | 1 byte | Frame termination |
+---------------+---------------+---------------------------+
The ``<base64-i>`` of partial frame is Base64 encoding of data,
taking form:
.. table::
:align: center
+---------------+---------------+---------------------------+
| Content | Size | Description |
+===============+===============+===========================+
| body | no more than | Raw body data fragment |
| | MTU - 3 | |
+---------------+---------------+---------------------------+
The ``<base64-i>`` of partial-final frame is Base64 encoding of data,
taking form:
.. table::
:align: center
+---------------+---------------+---------------------------+
| Content | Size | Description |
+===============+===============+===========================+
| body | no more than | Raw body data fragment |
| | MTU - 3 | |
+---------------+---------------+---------------------------+
| crc16 | 2 bytes | CRC16 of entire packet |
| | | body, preceding length |
| | | not included. |
+---------------+---------------+---------------------------+
CRC Details
-----------
The CRC16 included in final type frames is calculated over only
raw data and does not include packet length.
CRC16 polynomial is 0x1021 and initial value is 0.
API Reference
*************
.. doxygengroup:: mcumgr_transport_smp
Part 3
한국어 전문 번역
이 문서는 SMP transport의 server와 client를 구현할 때 필요한 wire-level 정보를 설명합니다.
BLE (Bluetooth Low Energy)
MCUmgr client에서 SMP를 구현할 때 다음 BLE characteristic을 사용해야 합니다.
- Service UUID:
8D53DC1D-1DB7-4CD3-868B-8A527460AA84 - Characteristic UUID:
DA2E7828-FBCE-4E01-AE9E-261174997C48
모든 SMP communication은 GATT characteristic 하나를 사용합니다. SMP request는 GATT Write Without Response command로 보내고, SMP response는 GATT Notification으로 보냅니다.
Request나 response가 GATT command 하나에 들어가지 않을 만큼 크면 sender가 여러 packet으로 나눕니다. Fragmentation을 위한 별도 framing은 추가하지 않고 payload를 packet 여러 개로 단순 분할합니다. GATT가 packet의 순서 전달을 보장하므로 첫 fragment의 SMP header에 있는 Data Length만으로 전체 frame을 reassembly할 수 있습니다.
UART/serial 및 console
Zephyr MCUmgr subsystem의 SMP protocol은 UART channel을 multiplex할 수 있도록 기본 framing을 사용합니다. 각 frame 앞에는 2-byte marker를 붙이고 끝에는 newline을 붙입니다. 현재 MCUmgr의 frame size 제한은 127 byte이지만 protocol 자체가 요구하는 제한은 아닙니다. 이 제한에는 prefix와 newline도 포함되므로 실제 허용 payload size는 124 byte입니다.
Zephyr에는 그런 transport가 들어 있지 않지만, framing을 전혀 쓰지 않거나 hardware serial port control 또는 다른 framing 방법을 사용하는 UART 기반 MCUmgr client/server를 구현하는 것도 가능합니다.
Frame fragmentation
Serial의 SMP packet은 MTU 크기 frame으로 나뉩니다. 각 frame은 2-byte start marker, body, 마지막 newline으로 구성됩니다.
Frame type은 initial, partial, partial-final, initial-final의 네 가지입니다. Type마다 start marker 또는 body 내용이 다릅니다.
Frame format
Initial frame 뒤에는 0개 이상의 partial frame이 올 수 있고, 마지막에는 partial-final frame이 와야 합니다. Body는 항상 Base64로 encode합니다. 따라서 여기서 MTU - 3으로 표현한 body 공간은 실제 raw data N = (MTU - 3) / 4 * 3 byte를 운반할 수 있습니다.
Initial frame의 body 앞에는 2-byte total packet length가 Big Endian으로 들어갑니다. 이 값은 raw body size에 CRC16 2 byte를 더한 값이며 length field 자체의 2 byte는 포함하지 않습니다. 따라서 initial frame에 넣을 수 있는 실제 body size는 N - 2입니다.
Body size가 N - 4보다 작으면 앞의 length와 뒤의 CRC를 한 frame에 함께 넣을 수 있습니다. 이것이 initial-final frame입니다.
Initial frame format은 다음과 같습니다.
| Content | Size | Description |
|---|---|---|
| 0x06 0x09 | 2 bytes | Frame start marker |
| <base64-i> | MTU - 3 bytes 이하 | Base64 encoded body |
| 0x0a | 1 byte | Frame termination |
Initial frame의 <base64-i>는 다음 body를 Base64로 encode한 값입니다.
| Content | Size | Description |
|---|---|---|
| total length | 2 bytes | Body length + CRC16 2 byte를 나타내는 Big-endian 16-bit value입니다. Total length field 자체의 크기는 이 값에 더하지 않습니다. |
| body | MTU - 5 이하 | Raw body data fragment |
Initial-final frame format은 initial frame과 비슷하지만 <base64-i> 정의가 다릅니다. Initial-final frame의 Base64 input은 다음과 같습니다.
| Content | Size | Description |
|---|---|---|
| total length | 2 bytes | Body length + CRC16 2 byte를 나타내는 Big-endian 16-bit value입니다. Total length field 자체의 크기는 이 값에 더하지 않습니다. |
| body | MTU - 7 이하 | Raw body data fragment |
| crc16 | 2 bytes | 전체 packet body의 CRC16입니다. 앞의 length는 계산에 포함하지 않습니다. |
Partial frame은 initial frame 또는 다른 partial frame 뒤에 오는 continuation입니다. 형식은 다음과 같습니다.
| Content | Size | Description |
|---|---|---|
| 0x04 0x14 | 2 bytes | Frame start marker |
| <base64-i> | MTU - 3 bytes 이하 | Base64 encoded body |
| 0x0a | 1 byte | Frame termination |
Partial frame의 <base64-i>는 다음 data를 Base64로 encode한 값입니다.
| Content | Size | Description |
|---|---|---|
| body | MTU - 3 이하 | Raw body data fragment |
Partial-final frame의 <base64-i>는 다음 data를 Base64로 encode한 값입니다.
| Content | Size | Description |
|---|---|---|
| body | MTU - 3 이하 | Raw body data fragment |
| crc16 | 2 bytes | 전체 packet body의 CRC16입니다. 앞의 length는 계산에 포함하지 않습니다. |
CRC 상세
Final type frame에 들어가는 CRC16은 raw data만 대상으로 계산하며 packet length는 포함하지 않습니다. CRC16 polynomial은 0x1021, initial value는 0입니다.
API Reference
관련 Zephyr API는 mcumgr_transport_smp Doxygen group에 정의돼 있습니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.