connectivity/bluetooth/api/mesh/access.html · connectivity/bluetooth/api/mesh/access.rst 공식 원문 ↗

Zephyr 3.7.0 · Connectivity · Bluetooth Mesh

Bluetooth Mesh Access layer

Application behavior를 element와 model로 구성하고 key·address·publication·persistent data를 관리합니다.

Official pathconnectivity/bluetooth/api/mesh/access.html
Source fileconnectivity/bluetooth/api/mesh/access.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

Opcode·AppKey·subscription, extension tree, Composition Data 6개 page와 random response delay를 설명합니다.

Structure

Element · model

Routing

AppKey · subscription

State

Publication · storage

Composition

Pages 0 · 1 · 2 · mirrors

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 2C174F962A0984FACD28749A7714D157A37D3663B3D230DFCE98A2EBEEC3C84C
.. _bluetooth_mesh_access:

Access layer
############

The access layer is the application's interface to the Bluetooth Mesh network.
The access layer provides mechanisms for compartmentalizing the node behavior
into elements and models, which are implemented by the application.

Mesh models
***********

The functionality of a mesh node is represented by models. A model implements
a single behavior the node supports, like being a light, a sensor or a
thermostat. The mesh models are grouped into *elements*. Each element is
assigned its own unicast address, and may only contain one of each type of
model. Conventionally, each element represents a single aspect of the mesh
node behavior. For instance, a node that contains a sensor, two lights and a
power outlet would spread this functionality across four elements, with each
element instantiating all the models required for a single aspect of the
supported behavior.

The node's element and model structure is specified in the node composition
data, which is passed to :c:func:`bt_mesh_init` during initialization. The
Bluetooth SIG have defined a set of foundation models (see
:ref:`bluetooth_mesh_models`) and a set of models for implementing common
behavior in the `Bluetooth Mesh Model Specification
<https://www.bluetooth.com/specifications/mesh-specifications/>`_. All models
not specified by the Bluetooth SIG are vendor models, and must be tied to a
Company ID.

Mesh models have several parameters that can be configured either through
initialization of the mesh stack or with the
:ref:`bluetooth_mesh_models_cfg_srv`:

Opcode list
===========

The opcode list contains all message opcodes the model can receive, as well as
the minimum acceptable payload length and the callback to pass them to. Models
can support any number of opcodes, but each opcode can only be listed by one
model in each element.

The full opcode list must be passed to the model structure in the composition
data, and cannot be changed at runtime. The end of the opcode list is
determined by the special :c:macro:`BT_MESH_MODEL_OP_END` entry. This entry
must always be present in the opcode list, unless the list is empty. In that
case, :c:macro:`BT_MESH_MODEL_NO_OPS` should be used in place of a proper
opcode list definition.

AppKey list
===========

The AppKey list contains all the application keys the model can receive
messages on. Only messages encrypted with application keys in the AppKey list
will be passed to the model.

The maximum number of supported application keys each model can hold is
configured with the :kconfig:option:`CONFIG_BT_MESH_MODEL_KEY_COUNT` configuration
option. The contents of the AppKey list is managed by the
:ref:`bluetooth_mesh_models_cfg_srv`.

Subscription list
=================

A model will process all messages addressed to the unicast address of their
element (given that the utilized application key is present in the AppKey
list). Additionally, the model will process packets addressed to any group or
virtual address in its subscription list. This allows nodes to address
multiple nodes throughout the mesh network with a single message.

The maximum number of supported addresses in the Subscription list each model
can hold is configured with the :kconfig:option:`CONFIG_BT_MESH_MODEL_GROUP_COUNT`
configuration option. The contents of the subscription list is managed by the
:ref:`bluetooth_mesh_models_cfg_srv`.

Model publication
=================

The models may send messages in two ways:

* By specifying a set of message parameters in a :c:struct:`bt_mesh_msg_ctx`,
  and calling :c:func:`bt_mesh_model_send`.
* By setting up a :c:struct:`bt_mesh_model_pub` structure and calling
  :c:func:`bt_mesh_model_publish`.

When publishing messages with :c:func:`bt_mesh_model_publish`, the model
will use the publication parameters configured by the
:ref:`bluetooth_mesh_models_cfg_srv`. This is the recommended way to send
unprompted model messages, as it passes the responsibility of selecting
message parameters to the network administrator, which likely knows more about
the mesh network than the individual nodes will.

To support publishing with the publication parameters, the model must allocate
a packet buffer for publishing, and pass it to
:c:member:`bt_mesh_model_pub.msg`. The Config Server may also set up period
publication for the publication message. To support this, the model must
populate the :c:member:`bt_mesh_model_pub.update` callback. The
:c:member:`bt_mesh_model_pub.update` callback will be called right before the
message is published, allowing the model to change the payload to reflect its
current state.

By setting :c:member:`bt_mesh_model_pub.retr_update` to 1, the model can
configure the :c:member:`bt_mesh_model_pub.update` callback to be triggered
on every retransmission. This can, for example, be used by models that make
use of a Delay parameter, which can be adjusted for every retransmission.
The :c:func:`bt_mesh_model_pub_is_retransmission` function can be
used to differentiate a first publication and a retransmission.
The :c:macro:`BT_MESH_PUB_MSG_TOTAL` and :c:macro:`BT_MESH_PUB_MSG_NUM` macros
can be used to return total number of transmissions and the retransmission
number within one publication interval.

Extended models
===============

The Bluetooth Mesh specification allows the mesh models to extend each other.
When a model extends another, it inherits that model's functionality, and
extension can be used to construct complex models out of simple ones,
leveraging the existing model functionality to avoid defining new opcodes.
Models may extend any number of models, from any element. When one model
extends another in the same element, the two models will share subscription
lists. The mesh stack implements this by merging the subscription lists of the
two models into one, combining the number of subscriptions the models can have
in total. Models may extend models that extend others, creating an "extension
tree". All models in an extension tree share a single subscription list per
element it spans.

Model extensions are done by calling :c:func:`bt_mesh_model_extend` during
initialization. A model can only be extended by one other model, and
extensions cannot be circular. Note that binding of node states and other
relationships between the models must be defined by the model implementations.

The model extension concept adds some overhead in the access layer packet
processing, and must be explicitly enabled with
:kconfig:option:`CONFIG_BT_MESH_MODEL_EXTENSIONS` to have any effect.

Model data storage
==================

Mesh models may have data associated with each model instance that needs to be
stored persistently. The access API provides a mechanism for storing this
data, leveraging the internal model instance encoding scheme. Models can store
one user defined data entry per instance by calling
:c:func:`bt_mesh_model_data_store`. To be able to read out the data the
next time the device reboots, the model's
:c:member:`bt_mesh_model_cb.settings_set` callback must be populated. This
callback gets called when model specific data is found in the persistent
storage. The model can retrieve the data by calling the ``read_cb`` passed as
a parameter to the callback. See the :ref:`settings_api` module documentation for
details.

When model data changes frequently, storing it on every change may lead to
increased wear of flash. To reduce the wear, the model can postpone storing of
data by calling :c:func:`bt_mesh_model_data_store_schedule`. The stack will
schedule a work item with delay defined by the
:kconfig:option:`CONFIG_BT_MESH_STORE_TIMEOUT` option. When the work item is
running, the stack will call the :c:member:`bt_mesh_model_cb.pending_store`
callback for every model that has requested storing of data. The model can
then call :c:func:`bt_mesh_model_data_store` to store the data.

If :kconfig:option:`CONFIG_BT_MESH_SETTINGS_WORKQ` is enabled, the
:c:member:`bt_mesh_model_cb.pending_store` callback is called from a dedicated
thread. This allows the stack to process other incoming and outgoing messages
while model data is being stored. It is recommended to use this option and the
:c:func:`bt_mesh_model_data_store_schedule` function when large amount of data
needs to be stored.

Composition Data
================

The Composition Data provides information about a mesh device.
A device's Composition Data holds information about the elements on the
device, the models that it supports, and other features. The Composition
Data is split into different pages, where each page contains specific feature
information about the device. In order to access this information, the user
may use the :ref:`bluetooth_mesh_models_cfg_srv` model or, if supported,
the :ref:`bluetooth_mesh_lcd_srv` model.

Composition Data Page 0
-----------------------

Composition Data Page 0 provides the fundamental information about a device, and
is mandatory for all mesh devices. It contains the element and model composition,
the supported features, and manufacturer information.

Composition Data Page 1
-----------------------

Composition Data Page 1 provides information about the relationships between models,
and is mandatory for all mesh devices. A model may extend and/or correspond to one
or more models. A model can extend another model by calling :c:func:`bt_mesh_model_extend`,
or correspond to another model by calling :c:func:`bt_mesh_model_correspond`.
:kconfig:option:`CONFIG_BT_MESH_MODEL_EXTENSION_LIST_SIZE` specifies how many model
relations can be stored in the composition on a device, and this number should reflect the
number of :c:func:`bt_mesh_model_extend` and :c:func:`bt_mesh_model_correspond` calls.

Composition Data Page 2
-----------------------

Composition Data Page 2 provides information for supported mesh profiles. Mesh profile
specifications define product requirements for devices that want to support a specific
Bluetooth SIG defined profile. Currently supported profiles can be found in section
3.12 in `Bluetooth SIG Assigned Numbers
<https://www.bluetooth.com/specifications/assigned-numbers/uri-scheme-name-string-mapping/>`_.
Composition Data Page 2 is only mandatory for devices that claim support for one or more
mesh profile(s).

Composition Data Pages 128, 129 and 130
---------------------------------------

Composition Data Pages 128, 129 and 130 mirror Composition Data Pages 0, 1 and 2 respectively.
They are used to represent the new content of the mirrored pages when the Composition Data will
change after a firmware update. See :ref:`bluetooth_mesh_dfu_srv_comp_data_and_models_metadata`
for details.

Delayable messages
==================

The delayable message functionality is enabled with Kconfig option
:kconfig:option:`CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG`.
This is an optional functionality that implements specification recommendations for
messages that are transmitted by a model in a response to a received message, also called
response messages.

Response messages should be sent with the following random delays:

* Between 20 and 50 milliseconds if the received message was sent
  to a unicast address
* Between 20 and 500 milliseconds if the received message was sent
  to a group or virtual address

The delayable message functionality is triggered if the :c:member:`bt_mesh_msg_ctx.rnd_delay`
flag is set.
The delayable message functionality stores messages in the local memory while they are
waiting for the random delay expiration.

If the transport layer doesn't have sufficient memory to send a message at the moment
the random delay expires, the message is postponed for another 10 milliseconds.
If the transport layer cannot send a message for any other reason, the delayable message
functionality raises the :c:member:`bt_mesh_send_cb.start` callback with a transport layer
error code.

If the delayable message functionality cannot find enough free memory to store an incoming
message, it will send messages with delay close to expiration to free memory.

When the mesh stack is suspended or reset, messages not yet sent are removed and
the :c:member:`bt_mesh_send_cb.start` callback is raised with an error code.

.. note::
   When a model sends several messages in a row, it may happen that the messages are not sent in
   the order they were passed to the access layer. This is because some messages can be delayed
   for a longer time than the others.

   Disable the randomization by setting the :c:member:`bt_mesh_msg_ctx.rnd_delay` to ``false``,
   when a set of messages originated by the same model needs to be sent in a certain order.

Delayable publications
======================

The delayable publication functionality implements the specification recommendations for message
publication delays in the following cases:

* Between 20 to 500 milliseconds when the Bluetooth Mesh stack starts or when the publication is
  triggered by the :c:func:`bt_mesh_model_publish` function
* Between 20 to 50 milliseconds for periodically published messages

This feature is optional and enabled with the :kconfig:option:`CONFIG_BT_MESH_DELAYABLE_PUBLICATION`
Kconfig option. When enabled, each model can enable or disable the delayable publication by setting
the :c:member:`bt_mesh_model_pub.delayable` bit field to ``1`` or ``0`` correspondingly. This bit
field can be changed at any time.

API reference
*************

.. doxygengroup:: bt_mesh_access

Part 3

한국어 전문 번역

Bluetooth Mesh Access layer

Access layer는 application이 Bluetooth Mesh network와 만나는 interface입니다. Application이 구현한 element와 model로 node의 behavior를 구획화하는 mechanism을 제공합니다.

Mesh model

Mesh node 기능은 model로 표현합니다. Model 하나는 light, sensor, thermostat처럼 node가 지원하는 behavior 하나를 구현합니다. Model은 element로 묶이고 각 element에는 고유 unicast address가 있으며 같은 type의 model을 하나씩만 포함할 수 있습니다.

관례적으로 element 하나는 node behavior의 한 측면을 나타냅니다. Sensor 하나, light 두 개와 power outlet 하나가 있는 node라면 네 element로 나누고 각 element는 해당 측면에 필요한 model을 모두 instance화합니다.

Element·model 구조는 node Composition Data에 정의해 초기화 때 bt_mesh_init에 전달합니다. Bluetooth SIG는 foundation model과 공통 behavior model을 표준화했습니다. SIG가 지정하지 않은 model은 vendor model이며 Company ID와 결합해야 합니다.

Model parameter는 mesh stack 초기화 또는 Configuration Server를 통해 구성합니다.

Opcode list

Model이 받을 수 있는 모든 message opcode, 허용하는 최소 payload length와 처리 callback을 담습니다. Model은 opcode를 제한 없이 지원할 수 있지만 한 element 안에서 같은 opcode는 model 하나에만 등록할 수 있습니다.

전체 opcode list는 Composition Data의 model structure에 넣고 runtime에는 바꿀 수 없습니다. 빈 list가 아니라면 끝에 반드시 BT_MESH_MODEL_OP_END가 있어야 합니다. Opcode가 전혀 없으면 일반 list 대신 BT_MESH_MODEL_NO_OPS를 사용합니다.

AppKey list

Model이 message를 받을 수 있는 application key 목록입니다. List에 있는 AppKey로 암호화한 message만 model에 전달됩니다. Model별 최대 key 수는 CONFIG_BT_MESH_MODEL_KEY_COUNT로 정하며 실제 list는 Configuration Server가 관리합니다.

Subscription list

Model은 AppKey 조건을 만족하는 한 자신의 element unicast address로 온 message를 모두 처리합니다. Subscription list에 등록된 group·virtual address로 온 packet도 처리하므로 message 하나로 network의 여러 node를 addressing할 수 있습니다.

Model별 최대 subscription address 수는 CONFIG_BT_MESH_MODEL_GROUP_COUNT로 정하고 list 내용은 Configuration Server가 관리합니다.

Model publication

  • bt_mesh_msg_ctx에 message parameter를 직접 지정하고 bt_mesh_model_send 호출
  • bt_mesh_model_pub을 설정하고 bt_mesh_model_publish 호출

bt_mesh_model_publish는 Configuration Server가 구성한 publication parameter를 사용합니다. Network를 개별 node보다 잘 아는 administrator가 parameter를 선택하므로 자발적인 model message에는 이 방식을 권장합니다.

Publication parameter를 쓰려면 model이 packet buffer를 할당해 bt_mesh_model_pub.msg에 둡니다. Config Server가 periodic publication을 설정할 수 있으므로 model은 필요하면 bt_mesh_model_pub.update callback을 채웁니다. Callback은 publish 직전에 호출되어 현재 상태를 payload에 반영할 수 있습니다.

bt_mesh_model_pub.retr_update를 1로 두면 retransmission마다 update callback을 호출합니다. Delay parameter처럼 재전송마다 값을 조정할 때 유용합니다. bt_mesh_model_pub_is_retransmission으로 최초 publication과 retransmission을 구분하고, BT_MESH_PUB_MSG_TOTAL·BT_MESH_PUB_MSG_NUM으로 한 publication interval의 총 transmission 수와 현재 retransmission 번호를 얻습니다.

Extended model

Model은 다른 model을 extend해 기능을 상속할 수 있습니다. 단순 model을 결합해 새 opcode 없이 복잡한 model을 만듭니다. 어느 element의 model이든 여러 개 extend할 수 있습니다.

같은 element 안의 두 model이 extension 관계면 subscription list를 merge해 공유하며 두 model이 사용할 수 있는 총 subscription 수가 합쳐집니다. Extension을 연쇄해 tree를 만들 수 있고 tree의 모든 model은 걸쳐 있는 각 element마다 subscription list 하나를 공유합니다.

초기화 중 bt_mesh_model_extend를 호출합니다. Model 하나는 다른 model 하나에 의해서만 extend될 수 있고 순환 extension은 허용하지 않습니다. Node state binding 같은 model 간 다른 관계는 각 model 구현이 정의해야 합니다.

Extension은 Access layer packet 처리 overhead가 있어 CONFIG_BT_MESH_MODEL_EXTENSIONS를 명시적으로 활성화해야 동작합니다.

Model data storage

Model instance마다 persistent data 하나를 bt_mesh_model_data_store로 저장할 수 있습니다. 다음 boot에서 읽으려면 bt_mesh_model_cb.settings_set callback을 구현합니다. Persistent storage에서 해당 model data를 찾으면 callback을 호출하고 전달된 read_cb로 내용을 읽습니다.

자주 바뀌는 data를 매번 저장하면 flash wear가 늘어납니다. bt_mesh_model_data_store_schedule은 CONFIG_BT_MESH_STORE_TIMEOUT만큼 지연한 work item을 예약합니다. Work가 실행되면 저장을 요청한 각 model의 bt_mesh_model_cb.pending_store를 호출하고 model이 최종 data store를 수행합니다.

CONFIG_BT_MESH_SETTINGS_WORKQ를 켜면 pending_store callback을 전용 thread에서 실행해 저장 중에도 incoming·outgoing message를 처리합니다. 많은 data를 저장할 때 이 option과 scheduled store 사용을 권장합니다.

Composition Data

Composition Data는 mesh device의 element, 지원 model과 feature 정보를 담습니다. Feature별 page로 나뉘며 Configuration Server 또는 지원되는 경우 Large Composition Data Server로 읽습니다.

Page 0

모든 mesh device에 필수입니다. Element·model composition, 지원 feature와 manufacturer 정보를 담는 기본 page입니다.

Page 1

모든 mesh device에 필수이며 model 간 extension·correspondence 관계를 담습니다. bt_mesh_model_extend 또는 bt_mesh_model_correspond로 관계를 등록합니다. CONFIG_BT_MESH_MODEL_EXTENSION_LIST_SIZE는 composition에 저장할 relation 수이며 두 function의 실제 호출 수를 반영해야 합니다.

Page 2

지원하는 mesh profile 정보를 담습니다. Bluetooth SIG profile 지원을 주장하는 device에만 필수이며 profile별 product requirement를 나타냅니다.

Page 128·129·130

각각 Page 0·1·2를 mirror합니다. Firmware update 뒤 Composition Data가 바뀔 때 새 content를 나타내는 용도입니다.

Delayable message

CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG로 활성화하는 optional 기능이며 model이 받은 message에 응답하는 response message의 specification 권장 random delay를 구현합니다.

  • Received message가 unicast address 대상: 20~50 ms
  • Group 또는 virtual address 대상: 20~500 ms

bt_mesh_msg_ctx.rnd_delay flag가 설정되면 message를 local memory에 보관했다가 random delay 만료 후 보냅니다. 만료 시 transport memory가 부족하면 10 ms 더 미룹니다. 다른 이유로 보낼 수 없으면 bt_mesh_send_cb.start를 transport error code와 함께 호출합니다.

Incoming message를 저장할 free memory가 부족하면 만료가 가까운 대기 message를 먼저 보내 공간을 확보합니다. Mesh stack suspend 또는 reset 때 아직 보내지 않은 message를 제거하고 start callback에 error를 전달합니다.

Delayable publication

Publication delay 권장사항을 구현합니다. Stack 시작 또는 bt_mesh_model_publish가 trigger한 publication은 20~500 ms, periodic publication은 20~50 ms 지연합니다.

Optional CONFIG_BT_MESH_DELAYABLE_PUBLICATION으로 활성화합니다. 활성화 후 각 model은 bt_mesh_model_pub.delayable bit를 1 또는 0으로 설정해 runtime에도 개별 enable·disable할 수 있습니다.

API Reference

공식 bt_mesh_access Doxygen group이 element, model, publication, message context와 storage API를 생성합니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.