2019-01-27 01:57:27 +08:00
|
|
|
.. _bt_l2cap:
|
|
|
|
|
|
|
|
Logical Link Control and Adaptation Protocol (L2CAP)
|
|
|
|
####################################################
|
|
|
|
|
2019-04-08 16:26:44 +08:00
|
|
|
L2CAP layer enables connection-oriented channels which can be enable with the
|
|
|
|
configuration option: :option:`CONFIG_BT_L2CAP_DYNAMIC_CHANNEL`. This channels
|
|
|
|
support segmentation and reassembly transparently, they also support credit
|
|
|
|
based flow control making it suitable for data streams.
|
|
|
|
|
2020-08-21 01:29:47 +08:00
|
|
|
Channels instances are represented by the :c:struct:`bt_l2cap_chan` struct which
|
|
|
|
contains the callbacks in the :c:struct:`bt_l2cap_chan_ops` struct to inform
|
2019-04-08 16:26:44 +08:00
|
|
|
when the channel has been connected, disconnected or when the encryption has
|
|
|
|
changed.
|
|
|
|
In addition to that it also contains the ``recv`` callback which is called
|
|
|
|
whenever an incoming data has been received. Data received this way can be
|
|
|
|
marked as processed by returning 0 or using
|
2020-08-24 22:35:45 +08:00
|
|
|
:c:func:`bt_l2cap_chan_recv_complete` API if processing is asynchronous.
|
2019-04-08 16:26:44 +08:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
The ``recv`` callback is called directly from RX Thread thus it is not
|
2019-04-08 16:28:45 +08:00
|
|
|
recommended to block for long periods of time.
|
2019-04-08 16:26:44 +08:00
|
|
|
|
2020-08-24 22:35:45 +08:00
|
|
|
For sending data the :c:func:`bt_l2cap_chan_send` API can be used noting that
|
2019-04-08 16:26:44 +08:00
|
|
|
it may block if no credits are available, and resuming as soon as more credits
|
|
|
|
are available.
|
|
|
|
|
2020-08-24 22:35:45 +08:00
|
|
|
Servers can be registered using :c:func:`bt_l2cap_server_register` API passing
|
2020-08-21 01:29:47 +08:00
|
|
|
the :c:struct:`bt_l2cap_server` struct which informs what ``psm`` it should
|
2019-04-08 16:26:44 +08:00
|
|
|
listen to, the required security level ``sec_level``, and the callback
|
|
|
|
``accept`` which is called to authorize incoming connection requests and
|
|
|
|
allocate channel instances.
|
|
|
|
|
2020-08-24 22:35:45 +08:00
|
|
|
Client channels can be initiated with use of :c:func:`bt_l2cap_chan_connect`
|
|
|
|
API and can be disconnected with the :c:func:`bt_l2cap_chan_disconnect` API.
|
2019-04-08 16:26:44 +08:00
|
|
|
Note that the later can also disconnect channel instances created by servers.
|
|
|
|
|
2019-01-27 01:57:27 +08:00
|
|
|
API Reference
|
|
|
|
*************
|
|
|
|
|
|
|
|
.. doxygengroup:: bt_l2cap
|
|
|
|
:project: Zephyr
|
2020-04-28 23:46:48 +08:00
|
|
|
:members:
|