2015-10-05 13:53:03 +03:00
|
|
|
/** @file
|
|
|
|
* @brief Bluetooth L2CAP handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-06-10 12:10:18 +03:00
|
|
|
* Copyright (c) 2015-2016 Intel Corporation
|
2015-10-05 13:53:03 +03:00
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-10-05 13:53:03 +03:00
|
|
|
*/
|
2018-09-14 10:43:44 -07:00
|
|
|
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_
|
|
|
|
#define ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_
|
2015-10-05 13:53:03 +03:00
|
|
|
|
2016-05-16 19:54:24 +03:00
|
|
|
/**
|
|
|
|
* @brief L2CAP
|
|
|
|
* @defgroup bt_l2cap L2CAP
|
|
|
|
* @ingroup bluetooth
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2019-06-25 12:25:32 -04:00
|
|
|
#include <sys/atomic.h>
|
2016-06-06 19:03:14 +02:00
|
|
|
#include <bluetooth/buf.h>
|
2015-10-05 13:53:03 +03:00
|
|
|
#include <bluetooth/conn.h>
|
2017-02-01 12:49:57 +02:00
|
|
|
#include <bluetooth/hci.h>
|
|
|
|
|
2019-08-12 12:54:12 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-05-03 09:12:49 +02:00
|
|
|
/** L2CAP PDU header size, used for buffer size calculations */
|
2017-02-01 12:49:57 +02:00
|
|
|
#define BT_L2CAP_HDR_SIZE 4
|
|
|
|
|
2021-04-27 10:38:23 +02:00
|
|
|
/** Maximum Transmission Unit (MTU) for an outgoing L2CAP PDU. */
|
|
|
|
#define BT_L2CAP_TX_MTU (CONFIG_BT_L2CAP_TX_MTU)
|
|
|
|
|
|
|
|
/** Maximum Transmission Unit (MTU) for an incoming L2CAP PDU. */
|
|
|
|
#define BT_L2CAP_RX_MTU (CONFIG_BT_BUF_ACL_RX_SIZE - BT_L2CAP_HDR_SIZE)
|
|
|
|
|
2021-05-21 15:36:26 +02:00
|
|
|
/** @brief Helper to calculate needed buffer size for L2CAP PDUs.
|
2021-04-27 10:27:02 +02:00
|
|
|
* Useful for creating buffer pools.
|
2017-02-01 12:49:57 +02:00
|
|
|
*
|
2021-04-27 10:27:02 +02:00
|
|
|
* @param mtu Needed L2CAP PDU MTU.
|
|
|
|
*
|
|
|
|
* @return Needed buffer size to match the requested L2CAP PDU MTU.
|
|
|
|
*/
|
|
|
|
#define BT_L2CAP_BUF_SIZE(mtu) BT_BUF_ACL_SIZE(BT_L2CAP_HDR_SIZE + (mtu))
|
|
|
|
|
|
|
|
/** L2CAP SDU header size, used for buffer size calculations */
|
|
|
|
#define BT_L2CAP_SDU_HDR_SIZE 2
|
|
|
|
|
2021-05-03 09:12:49 +02:00
|
|
|
/** @brief Maximum Transmission Unit for an unsegmented outgoing L2CAP SDU.
|
|
|
|
*
|
|
|
|
* The Maximum Transmission Unit for an outgoing L2CAP SDU when sent without
|
|
|
|
* segmentation, i.e a single L2CAP SDU will fit inside a single L2CAP PDU.
|
|
|
|
*
|
|
|
|
* The MTU for outgoing L2CAP SDUs with segmentation is defined by the
|
|
|
|
* size of the application buffer pool.
|
|
|
|
*/
|
|
|
|
#define BT_L2CAP_SDU_TX_MTU (BT_L2CAP_TX_MTU - BT_L2CAP_SDU_HDR_SIZE)
|
|
|
|
|
|
|
|
/** @brief Maximum Transmission Unit for an unsegmented incoming L2CAP SDU.
|
|
|
|
*
|
|
|
|
* The Maximum Transmission Unit for an incoming L2CAP SDU when sent without
|
|
|
|
* segmentation, i.e a single L2CAP SDU will fit inside a single L2CAP PDU.
|
|
|
|
*
|
|
|
|
* The MTU for incoming L2CAP SDUs with segmentation is defined by the
|
|
|
|
* size of the application buffer pool. The application will have to define
|
|
|
|
* an alloc_buf callback for the channel in order to support receiving
|
|
|
|
* segmented L2CAP SDUs.
|
|
|
|
*/
|
|
|
|
#define BT_L2CAP_SDU_RX_MTU (BT_L2CAP_RX_MTU - BT_L2CAP_SDU_HDR_SIZE)
|
|
|
|
|
2021-04-27 10:27:02 +02:00
|
|
|
/** @def BT_L2CAP_SDU_BUF_SIZE
|
|
|
|
*
|
|
|
|
* @brief Helper to calculate needed buffer size for L2CAP SDUs.
|
|
|
|
* Useful for creating buffer pools.
|
|
|
|
*
|
2021-05-03 09:12:49 +02:00
|
|
|
* @param mtu Required BT_L2CAP_*_SDU.
|
2017-02-01 12:49:57 +02:00
|
|
|
*
|
2021-05-03 09:12:49 +02:00
|
|
|
* @return Needed buffer size to match the requested L2CAP SDU MTU.
|
2017-02-01 12:49:57 +02:00
|
|
|
*/
|
2021-04-27 10:27:02 +02:00
|
|
|
#define BT_L2CAP_SDU_BUF_SIZE(mtu) BT_L2CAP_BUF_SIZE(BT_L2CAP_SDU_HDR_SIZE + (mtu))
|
2015-10-05 13:53:03 +03:00
|
|
|
|
2016-07-11 13:21:41 +03:00
|
|
|
struct bt_l2cap_chan;
|
|
|
|
|
|
|
|
/** @typedef bt_l2cap_chan_destroy_t
|
|
|
|
* @brief Channel destroy callback
|
|
|
|
*
|
|
|
|
* @param chan Channel object.
|
|
|
|
*/
|
|
|
|
typedef void (*bt_l2cap_chan_destroy_t)(struct bt_l2cap_chan *chan);
|
|
|
|
|
2020-03-17 10:32:20 +01:00
|
|
|
/** @brief Life-span states of L2CAP CoC channel.
|
|
|
|
*
|
|
|
|
* Used only by internal APIs dealing with setting channel to proper state
|
|
|
|
* depending on operational context.
|
2016-06-30 17:13:44 +02:00
|
|
|
*/
|
|
|
|
typedef enum bt_l2cap_chan_state {
|
2016-07-15 18:16:58 +02:00
|
|
|
/** Channel disconnected */
|
|
|
|
BT_L2CAP_DISCONNECTED,
|
|
|
|
/** Channel in connecting state */
|
|
|
|
BT_L2CAP_CONNECT,
|
|
|
|
/** Channel in config state, BR/EDR specific */
|
|
|
|
BT_L2CAP_CONFIG,
|
|
|
|
/** Channel ready for upper layer traffic on it */
|
|
|
|
BT_L2CAP_CONNECTED,
|
2016-07-19 10:56:59 +02:00
|
|
|
/** Channel in disconnecting state */
|
|
|
|
BT_L2CAP_DISCONNECT,
|
2019-07-17 15:13:46 +03:00
|
|
|
|
2016-06-30 17:13:44 +02:00
|
|
|
} __packed bt_l2cap_chan_state_t;
|
|
|
|
|
2019-05-22 22:46:25 +03:00
|
|
|
/** @brief Status of L2CAP channel. */
|
|
|
|
typedef enum bt_l2cap_chan_status {
|
|
|
|
/** Channel output status */
|
|
|
|
BT_L2CAP_STATUS_OUT,
|
|
|
|
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Channel shutdown status
|
2019-11-19 15:31:37 +02:00
|
|
|
*
|
|
|
|
* Once this status is notified it means the channel will no longer be
|
|
|
|
* able to transmit or receive data.
|
|
|
|
*/
|
|
|
|
BT_L2CAP_STATUS_SHUTDOWN,
|
|
|
|
|
2020-04-29 16:22:47 -07:00
|
|
|
/** @brief Channel encryption pending status */
|
|
|
|
BT_L2CAP_STATUS_ENCRYPT_PENDING,
|
|
|
|
|
2019-05-22 22:46:25 +03:00
|
|
|
/* Total number of status - must be at the end of the enum */
|
|
|
|
BT_L2CAP_NUM_STATUS,
|
|
|
|
} __packed bt_l2cap_chan_status_t;
|
|
|
|
|
2015-10-05 13:53:03 +03:00
|
|
|
/** @brief L2CAP Channel structure. */
|
|
|
|
struct bt_l2cap_chan {
|
|
|
|
/** Channel connection reference */
|
2016-05-26 14:03:04 +02:00
|
|
|
struct bt_conn *conn;
|
2015-10-05 13:53:03 +03:00
|
|
|
/** Channel operations reference */
|
2019-12-18 12:44:56 +02:00
|
|
|
const struct bt_l2cap_chan_ops *ops;
|
2017-03-21 15:48:03 +02:00
|
|
|
sys_snode_t node;
|
2016-07-11 13:21:41 +03:00
|
|
|
bt_l2cap_chan_destroy_t destroy;
|
2016-07-22 15:17:42 +02:00
|
|
|
/* Response Timeout eXpired (RTX) timer */
|
2021-04-12 13:03:22 +02:00
|
|
|
struct k_work_delayable rtx_work;
|
|
|
|
struct k_work_sync rtx_sync;
|
2019-05-22 22:46:25 +03:00
|
|
|
ATOMIC_DEFINE(status, BT_L2CAP_NUM_STATUS);
|
2018-10-05 15:47:53 +03:00
|
|
|
|
2017-08-09 09:21:11 +03:00
|
|
|
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
|
2016-06-30 17:13:44 +02:00
|
|
|
bt_l2cap_chan_state_t state;
|
2016-11-02 13:20:11 +02:00
|
|
|
/** Remote PSM to be connected */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t psm;
|
2016-07-19 15:07:26 +02:00
|
|
|
/** Helps match request context during CoC */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t ident;
|
2016-07-08 16:30:31 +02:00
|
|
|
bt_security_t required_sec_level;
|
2017-08-09 09:21:11 +03:00
|
|
|
#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
|
2016-05-26 14:03:04 +02:00
|
|
|
};
|
2015-10-05 13:53:03 +03:00
|
|
|
|
2016-05-26 14:03:04 +02:00
|
|
|
/** @brief LE L2CAP Endpoint structure. */
|
|
|
|
struct bt_l2cap_le_endpoint {
|
2021-02-04 11:07:02 +01:00
|
|
|
/** Endpoint Channel Identifier (CID) */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t cid;
|
2016-05-26 14:03:04 +02:00
|
|
|
/** Endpoint Maximum Transmission Unit */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t mtu;
|
2016-05-26 14:03:04 +02:00
|
|
|
/** Endpoint Maximum PDU payload Size */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t mps;
|
2017-01-17 13:26:50 +02:00
|
|
|
/** Endpoint initial credits */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t init_credits;
|
2016-05-26 14:03:04 +02:00
|
|
|
/** Endpoint credits */
|
2019-12-18 13:27:36 -08:00
|
|
|
atomic_t credits;
|
2016-05-26 14:03:04 +02:00
|
|
|
};
|
2015-10-05 13:53:03 +03:00
|
|
|
|
2016-05-26 14:03:04 +02:00
|
|
|
/** @brief LE L2CAP Channel structure. */
|
|
|
|
struct bt_l2cap_le_chan {
|
|
|
|
/** Common L2CAP channel reference object */
|
|
|
|
struct bt_l2cap_chan chan;
|
2021-05-03 09:12:49 +02:00
|
|
|
/** @brief Channel Receiving Endpoint.
|
|
|
|
*
|
|
|
|
* If the application has set an alloc_buf channel callback for the
|
|
|
|
* channel to support receiving segmented L2CAP SDUs the application
|
|
|
|
* should inititalize the MTU of the Receiving Endpoint. Otherwise the
|
|
|
|
* MTU of the receiving endpoint will be initialized to
|
|
|
|
* @ref BT_L2CAP_SDU_RX_MTU by the stack.
|
|
|
|
*/
|
2016-05-26 14:03:04 +02:00
|
|
|
struct bt_l2cap_le_endpoint rx;
|
|
|
|
/** Channel Transmission Endpoint */
|
|
|
|
struct bt_l2cap_le_endpoint tx;
|
2017-03-07 10:20:15 +02:00
|
|
|
/** Channel Transmission queue */
|
|
|
|
struct k_fifo tx_queue;
|
|
|
|
/** Channel Pending Transmission buffer */
|
|
|
|
struct net_buf *tx_buf;
|
2019-11-18 18:29:45 +02:00
|
|
|
/** Channel Transmission work */
|
|
|
|
struct k_work tx_work;
|
2016-05-26 14:03:04 +02:00
|
|
|
/** Segment SDU packet from upper layer */
|
|
|
|
struct net_buf *_sdu;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t _sdu_len;
|
2019-11-26 13:08:24 +02:00
|
|
|
|
|
|
|
struct k_work rx_work;
|
|
|
|
struct k_fifo rx_queue;
|
2016-05-26 14:03:04 +02:00
|
|
|
};
|
2015-11-16 18:18:45 +02:00
|
|
|
|
2016-06-24 12:08:46 +02:00
|
|
|
/** @def BT_L2CAP_LE_CHAN(_ch)
|
|
|
|
* @brief Helper macro getting container object of type bt_l2cap_le_chan
|
|
|
|
* address having the same container chan member address as object in question.
|
|
|
|
*
|
|
|
|
* @param _ch Address of object of bt_l2cap_chan type
|
|
|
|
*
|
|
|
|
* @return Address of in memory bt_l2cap_le_chan object type containing
|
2020-03-17 10:32:20 +01:00
|
|
|
* the address of in question object.
|
2016-06-24 12:08:46 +02:00
|
|
|
*/
|
|
|
|
#define BT_L2CAP_LE_CHAN(_ch) CONTAINER_OF(_ch, struct bt_l2cap_le_chan, chan)
|
|
|
|
|
2016-05-26 14:03:04 +02:00
|
|
|
/** @brief BREDR L2CAP Endpoint structure. */
|
|
|
|
struct bt_l2cap_br_endpoint {
|
2021-02-04 11:07:02 +01:00
|
|
|
/** Endpoint Channel Identifier (CID) */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t cid;
|
2016-05-26 14:03:04 +02:00
|
|
|
/** Endpoint Maximum Transmission Unit */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t mtu;
|
2016-05-26 14:03:04 +02:00
|
|
|
};
|
2015-11-04 14:46:56 +02:00
|
|
|
|
2016-05-26 14:03:04 +02:00
|
|
|
/** @brief BREDR L2CAP Channel structure. */
|
|
|
|
struct bt_l2cap_br_chan {
|
|
|
|
/** Common L2CAP channel reference object */
|
|
|
|
struct bt_l2cap_chan chan;
|
|
|
|
/** Channel Receiving Endpoint */
|
|
|
|
struct bt_l2cap_br_endpoint rx;
|
|
|
|
/** Channel Transmission Endpoint */
|
|
|
|
struct bt_l2cap_br_endpoint tx;
|
2016-09-21 17:09:04 +02:00
|
|
|
/* For internal use only */
|
2016-07-08 18:13:25 +02:00
|
|
|
atomic_t flags[1];
|
2015-10-05 13:53:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief L2CAP Channel operations structure. */
|
|
|
|
struct bt_l2cap_chan_ops {
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Channel connected callback
|
2016-03-07 14:49:55 +02:00
|
|
|
*
|
|
|
|
* If this callback is provided it will be called whenever the
|
|
|
|
* connection completes.
|
2016-02-18 14:11:35 +02:00
|
|
|
*
|
|
|
|
* @param chan The channel that has been connected
|
|
|
|
*/
|
2016-04-25 09:47:41 +03:00
|
|
|
void (*connected)(struct bt_l2cap_chan *chan);
|
2016-02-18 14:11:35 +02:00
|
|
|
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Channel disconnected callback
|
2016-03-07 14:49:55 +02:00
|
|
|
*
|
|
|
|
* If this callback is provided it will be called whenever the
|
|
|
|
* channel is disconnected, including when a connection gets
|
|
|
|
* rejected.
|
2016-02-18 14:11:35 +02:00
|
|
|
*
|
|
|
|
* @param chan The channel that has been Disconnected
|
|
|
|
*/
|
2016-04-25 09:47:41 +03:00
|
|
|
void (*disconnected)(struct bt_l2cap_chan *chan);
|
2016-02-18 14:11:35 +02:00
|
|
|
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Channel encrypt_change callback
|
2016-02-18 14:11:35 +02:00
|
|
|
*
|
|
|
|
* If this callback is provided it will be called whenever the
|
2016-09-13 09:38:10 +02:00
|
|
|
* security level changed (indirectly link encryption done) or
|
|
|
|
* authentication procedure fails. In both cases security initiator
|
|
|
|
* and responder got the final status (HCI status) passed by
|
|
|
|
* related to encryption and authentication events from local host's
|
|
|
|
* controller.
|
2016-02-18 14:11:35 +02:00
|
|
|
*
|
2016-09-13 09:38:10 +02:00
|
|
|
* @param chan The channel which has made encryption status changed.
|
|
|
|
* @param status HCI status of performed security procedure caused
|
|
|
|
* by channel security requirements. The value is populated
|
|
|
|
* by HCI layer and set to 0 when success and to non-zero (reference to
|
|
|
|
* HCI Error Codes) when security/authentication failed.
|
2016-02-18 14:11:35 +02:00
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
void (*encrypt_change)(struct bt_l2cap_chan *chan, uint8_t hci_status);
|
2016-02-18 14:11:35 +02:00
|
|
|
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Channel alloc_buf callback
|
2016-02-18 14:11:35 +02:00
|
|
|
*
|
|
|
|
* If this callback is provided the channel will use it to allocate
|
2020-09-21 11:20:29 -07:00
|
|
|
* buffers to store incoming data. Channels that requires segmentation
|
|
|
|
* must set this callback.
|
2021-05-03 09:12:49 +02:00
|
|
|
* If the application has not set a callback the L2CAP SDU MTU will be
|
|
|
|
* truncated to @ref BT_L2CAP_SDU_RX_MTU.
|
2016-02-18 14:11:35 +02:00
|
|
|
*
|
|
|
|
* @param chan The channel requesting a buffer.
|
|
|
|
*
|
|
|
|
* @return Allocated buffer.
|
|
|
|
*/
|
2016-04-25 09:47:41 +03:00
|
|
|
struct net_buf *(*alloc_buf)(struct bt_l2cap_chan *chan);
|
2015-10-05 13:53:03 +03:00
|
|
|
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Channel recv callback
|
2016-02-18 14:11:35 +02:00
|
|
|
*
|
|
|
|
* @param chan The channel receiving data.
|
|
|
|
* @param buf Buffer containing incoming data.
|
2018-08-22 13:16:14 +03:00
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
2020-03-17 10:32:20 +01:00
|
|
|
* @return -EINPROGRESS in case where user has to confirm once the data
|
|
|
|
* has been processed by calling
|
|
|
|
* @ref bt_l2cap_chan_recv_complete passing back
|
|
|
|
* the buffer received with its original user_data
|
|
|
|
* which contains the number of segments/credits
|
|
|
|
* used by the packet.
|
2016-02-18 14:11:35 +02:00
|
|
|
*/
|
2018-08-22 13:16:14 +03:00
|
|
|
int (*recv)(struct bt_l2cap_chan *chan, struct net_buf *buf);
|
2019-05-21 15:07:43 +03:00
|
|
|
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Channel sent callback
|
2019-05-21 15:07:43 +03:00
|
|
|
*
|
|
|
|
* If this callback is provided it will be called whenever a SDU has
|
|
|
|
* been completely sent.
|
|
|
|
*
|
|
|
|
* @param chan The channel which has sent data.
|
|
|
|
*/
|
|
|
|
void (*sent)(struct bt_l2cap_chan *chan);
|
2019-05-22 22:46:25 +03:00
|
|
|
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Channel status callback
|
2019-05-22 22:46:25 +03:00
|
|
|
*
|
|
|
|
* If this callback is provided it will be called whenever the
|
|
|
|
* channel status changes.
|
|
|
|
*
|
|
|
|
* @param chan The channel which status changed
|
|
|
|
* @param status The channel status
|
|
|
|
*/
|
|
|
|
void (*status)(struct bt_l2cap_chan *chan, atomic_t *status);
|
2020-02-26 16:42:26 -08:00
|
|
|
|
|
|
|
/* @brief Channel released callback
|
|
|
|
*
|
|
|
|
* If this callback is set it is called when the stack has release all
|
|
|
|
* references to the channel object.
|
|
|
|
*/
|
|
|
|
void (*released)(struct bt_l2cap_chan *chan);
|
2015-10-05 13:53:03 +03:00
|
|
|
};
|
|
|
|
|
2015-11-12 13:42:10 +02:00
|
|
|
/** @def BT_L2CAP_CHAN_SEND_RESERVE
|
2021-05-03 09:12:49 +02:00
|
|
|
* @brief Headroom needed for outgoing L2CAP PDUs.
|
2015-11-12 13:42:10 +02:00
|
|
|
*/
|
2021-04-27 10:27:02 +02:00
|
|
|
#define BT_L2CAP_CHAN_SEND_RESERVE (BT_L2CAP_BUF_SIZE(0))
|
2015-10-08 13:45:40 +03:00
|
|
|
|
2021-05-03 09:12:49 +02:00
|
|
|
/** @def BT_L2CAP_SDU_CHAN_SEND_RESERVE
|
|
|
|
* @brief Headroom needed for outgoing L2CAP SDUs.
|
|
|
|
*/
|
|
|
|
#define BT_L2CAP_SDU_CHAN_SEND_RESERVE (BT_L2CAP_SDU_BUF_SIZE(0))
|
|
|
|
|
2015-10-05 13:53:03 +03:00
|
|
|
/** @brief L2CAP Server structure. */
|
|
|
|
struct bt_l2cap_server {
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Server PSM.
|
2018-05-18 07:43:21 +03:00
|
|
|
*
|
2020-04-28 19:47:46 +02:00
|
|
|
* Possible values:
|
2018-05-18 07:43:21 +03:00
|
|
|
* 0 A dynamic value will be auto-allocated when
|
|
|
|
* bt_l2cap_server_register() is called.
|
|
|
|
*
|
|
|
|
* 0x0001-0x007f Standard, Bluetooth SIG-assigned fixed values.
|
|
|
|
*
|
|
|
|
* 0x0080-0x00ff Dynamically allocated. May be pre-set by the
|
|
|
|
* application before server registration (not
|
|
|
|
* recommended however), or auto-allocated by the
|
|
|
|
* stack if the app gave 0 as the value.
|
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t psm;
|
2015-10-05 13:53:03 +03:00
|
|
|
|
2021-02-03 19:01:32 +08:00
|
|
|
/** Required minimum security level */
|
2016-11-01 11:05:35 +02:00
|
|
|
bt_security_t sec_level;
|
|
|
|
|
2020-04-28 19:47:46 +02:00
|
|
|
/** @brief Server accept callback
|
2016-03-07 14:49:55 +02:00
|
|
|
*
|
|
|
|
* This callback is called whenever a new incoming connection requires
|
|
|
|
* authorization.
|
2016-02-18 14:11:35 +02:00
|
|
|
*
|
|
|
|
* @param conn The connection that is requesting authorization
|
|
|
|
* @param chan Pointer to received the allocated channel
|
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
2020-03-17 10:32:20 +01:00
|
|
|
* @return -ENOMEM if no available space for new channel.
|
|
|
|
* @return -EACCES if application did not authorize the connection.
|
|
|
|
* @return -EPERM if encryption key size is too short.
|
2016-02-18 14:11:35 +02:00
|
|
|
*/
|
2015-10-05 13:53:03 +03:00
|
|
|
int (*accept)(struct bt_conn *conn, struct bt_l2cap_chan **chan);
|
|
|
|
|
2017-03-23 15:03:58 +02:00
|
|
|
sys_snode_t node;
|
2015-10-05 13:53:03 +03:00
|
|
|
};
|
|
|
|
|
2015-11-03 13:50:28 +02:00
|
|
|
/** @brief Register L2CAP server.
|
2015-10-05 13:53:03 +03:00
|
|
|
*
|
2016-03-07 14:49:55 +02:00
|
|
|
* Register L2CAP server for a PSM, each new connection is authorized using
|
|
|
|
* the accept() callback which in case of success shall allocate the channel
|
|
|
|
* structure to be used by the new connection.
|
2015-10-05 13:53:03 +03:00
|
|
|
*
|
2018-05-18 07:43:21 +03:00
|
|
|
* For fixed, SIG-assigned PSMs (in the range 0x0001-0x007f) the PSM should
|
|
|
|
* be assigned to server->psm before calling this API. For dynamic PSMs
|
|
|
|
* (in the range 0x0080-0x00ff) server->psm may be pre-set to a given value
|
|
|
|
* (this is however not recommended) or be left as 0, in which case upon
|
|
|
|
* return a newly allocated value will have been assigned to it. For
|
|
|
|
* dynamically allocated values the expectation is that it's exposed through
|
|
|
|
* a GATT service, and that's how L2CAP clients discover how to connect to
|
|
|
|
* the server.
|
|
|
|
*
|
2015-10-05 13:53:03 +03:00
|
|
|
* @param server Server structure.
|
|
|
|
*
|
2015-11-03 13:50:28 +02:00
|
|
|
* @return 0 in case of success or negative value in case of error.
|
2015-10-05 13:53:03 +03:00
|
|
|
*/
|
|
|
|
int bt_l2cap_server_register(struct bt_l2cap_server *server);
|
|
|
|
|
2016-04-25 15:14:24 +02:00
|
|
|
/** @brief Register L2CAP server on BR/EDR oriented connection.
|
|
|
|
*
|
|
|
|
* Register L2CAP server for a PSM, each new connection is authorized using
|
|
|
|
* the accept() callback which in case of success shall allocate the channel
|
|
|
|
* structure to be used by the new connection.
|
|
|
|
*
|
|
|
|
* @param server Server structure.
|
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
|
|
|
*/
|
|
|
|
int bt_l2cap_br_server_register(struct bt_l2cap_server *server);
|
|
|
|
|
2020-02-26 10:29:23 -08:00
|
|
|
/** @brief Connect Enhanced Credit Based L2CAP channels
|
|
|
|
*
|
|
|
|
* Connect up to 5 L2CAP channels by PSM, once the connection is completed
|
|
|
|
* each channel connected() callback will be called. If the connection is
|
|
|
|
* rejected disconnected() callback is called instead.
|
|
|
|
*
|
|
|
|
* @param conn Connection object.
|
|
|
|
* @param chans Array of channel objects.
|
|
|
|
* @param psm Channel PSM to connect to.
|
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
|
|
|
*/
|
|
|
|
int bt_l2cap_ecred_chan_connect(struct bt_conn *conn,
|
2020-05-27 11:26:57 -05:00
|
|
|
struct bt_l2cap_chan **chans, uint16_t psm);
|
2020-02-26 10:29:23 -08:00
|
|
|
|
2015-11-04 14:46:56 +02:00
|
|
|
/** @brief Connect L2CAP channel
|
|
|
|
*
|
2016-03-07 14:49:55 +02:00
|
|
|
* Connect L2CAP channel by PSM, once the connection is completed channel
|
|
|
|
* connected() callback will be called. If the connection is rejected
|
|
|
|
* disconnected() callback is called instead.
|
2016-05-26 14:03:04 +02:00
|
|
|
* Channel object passed (over an address of it) as second parameter shouldn't
|
|
|
|
* be instantiated in application as standalone. Instead of, application should
|
|
|
|
* create transport dedicated L2CAP objects, i.e. type of bt_l2cap_le_chan for
|
|
|
|
* LE and/or type of bt_l2cap_br_chan for BR/EDR. Then pass to this API
|
|
|
|
* the location (address) of bt_l2cap_chan type object which is a member
|
|
|
|
* of both transport dedicated objects.
|
2015-11-04 14:46:56 +02:00
|
|
|
*
|
|
|
|
* @param conn Connection object.
|
|
|
|
* @param chan Channel object.
|
|
|
|
* @param psm Channel PSM to connect to.
|
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
|
|
|
*/
|
|
|
|
int bt_l2cap_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t psm);
|
2015-11-04 14:46:56 +02:00
|
|
|
|
2015-11-06 13:12:44 +02:00
|
|
|
/** @brief Disconnect L2CAP channel
|
|
|
|
*
|
|
|
|
* Disconnect L2CAP channel, if the connection is pending it will be
|
2016-03-07 14:49:55 +02:00
|
|
|
* canceled and as a result the channel disconnected() callback is called.
|
2016-05-26 14:03:04 +02:00
|
|
|
* Regarding to input parameter, to get details see reference description
|
|
|
|
* to bt_l2cap_chan_connect() API above.
|
2015-11-06 13:12:44 +02:00
|
|
|
*
|
|
|
|
* @param chan Channel object.
|
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
|
|
|
*/
|
|
|
|
int bt_l2cap_chan_disconnect(struct bt_l2cap_chan *chan);
|
|
|
|
|
2015-11-12 13:42:10 +02:00
|
|
|
/** @brief Send data to L2CAP channel
|
|
|
|
*
|
2017-06-13 16:06:21 +05:30
|
|
|
* Send data from buffer to the channel. If credits are not available, buf will
|
2017-08-10 08:21:28 -07:00
|
|
|
* be queued and sent as and when credits are received from peer.
|
2016-05-26 14:03:04 +02:00
|
|
|
* Regarding to first input parameter, to get details see reference description
|
|
|
|
* to bt_l2cap_chan_connect() API above.
|
2015-11-12 13:42:10 +02:00
|
|
|
*
|
2021-05-03 09:12:49 +02:00
|
|
|
* When sending L2CAP data over an BR/EDR connection the application is sending
|
|
|
|
* L2CAP PDUs. The application is required to have reserved
|
|
|
|
* @ref BT_L2CAP_CHAN_SEND_RESERVE bytes in the buffer before sending.
|
2021-05-21 15:36:26 +02:00
|
|
|
* The application should use the BT_L2CAP_BUF_SIZE() helper to correctly
|
2021-05-03 09:12:49 +02:00
|
|
|
* size the buffers for the for the outgoing buffer pool.
|
|
|
|
*
|
|
|
|
* When sending L2CAP data over an LE connection the applicatios is sending
|
|
|
|
* L2CAP SDUs. The application can optionally reserve
|
|
|
|
* @ref BT_L2CAP_SDU_CHAN_SEND_RESERVE bytes in the buffer before sending.
|
|
|
|
* By reserving bytes in the buffer the stack can use this buffer as a segment
|
|
|
|
* directly, otherwise it will have to allocate a new segment for the first
|
|
|
|
* segment.
|
|
|
|
* If the application is reserving the bytes it should use the
|
2021-05-21 15:36:26 +02:00
|
|
|
* BT_L2CAP_BUF_SIZE() helper to correctly size the buffers for the for the
|
2021-05-03 09:12:49 +02:00
|
|
|
* outgoing buffer pool.
|
|
|
|
* When segmenting an L2CAP SDU into L2CAP PDUs the stack will first attempt
|
|
|
|
* to allocate buffers from the original buffer pool of the L2CAP SDU before
|
|
|
|
* using the stacks own buffer pool.
|
|
|
|
*
|
2021-03-30 11:00:39 -07:00
|
|
|
* @note Buffer ownership is transferred to the stack in case of success, in
|
|
|
|
* case of an error the caller retains the ownership of the buffer.
|
|
|
|
*
|
2016-01-28 15:52:52 +02:00
|
|
|
* @return Bytes sent in case of success or negative value in case of error.
|
2015-11-12 13:42:10 +02:00
|
|
|
*/
|
|
|
|
int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf);
|
|
|
|
|
2018-08-22 13:16:14 +03:00
|
|
|
/** @brief Complete receiving L2CAP channel data
|
|
|
|
*
|
|
|
|
* Complete the reception of incoming data. This shall only be called if the
|
|
|
|
* channel recv callback has returned -EINPROGRESS to process some incoming
|
|
|
|
* data. The buffer shall contain the original user_data as that is used for
|
|
|
|
* storing the credits/segments used by the packet.
|
|
|
|
*
|
|
|
|
* @param chan Channel object.
|
|
|
|
* @param buf Buffer containing the data.
|
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
|
|
|
*/
|
|
|
|
int bt_l2cap_chan_recv_complete(struct bt_l2cap_chan *chan,
|
|
|
|
struct net_buf *buf);
|
|
|
|
|
2016-01-22 12:38:49 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-16 19:54:24 +03:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2018-09-14 10:43:44 -07:00
|
|
|
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_ */
|