mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-09-13 12:41:57 +00:00
Refactor and simplify the bluetooth buffer configurations to improve the easy of configurations and eliminate invalid ones. By moving configurations out of host and controller specific configurations and into a common one it becomes easier to configure the host and controller separately as the same configurations can be used as would be for a combined build. All HCI configurations are now given exluding the matching HCI header, which eases the configuration as the application don't have to know the different header sizes. The BT_RX_BUF_LEN is split into ACL and Event, as well as the suprising use of Command size. BT_L2CAP_RX_MTU is removed as the stack does not support reassembling of HCI ACL data to larger L2CAP PDUs. The application will have to set ACL RX size and account for the L2CAP PDU header itself. BT_EATT_RX_MTU was removed as it is only used for setting a different default value for another option which leads to the stuck kconfig symbol problem. The configurations can be updated according to the table below: ** New configuration | ** Old configuration All configurations BT_BUF_ACL_RX_SIZE | BT_L2CAP_RX_MTU + 4 BT_BUF_ACL_RX_SIZE | BT_RX_BUF_LEN - 4 BT_BUF_EVT_RX_SIZE | BT_RX_BUF_LEN - 2 BT_BUF_CMD_TX_SIZE | BT_RX_BUF_LEN - 3 BT_BUF_CMD_TX_COUNT | BT_HCI_CMD_COUNT BT_BUF_EVT_RX_COUNT | BT_RX_BUF_COUNT BT_BUF_ACL_RX_COUNT | BT_RX_BUF_COUNT BT_BUF_ACL_RX_COUNT | BT_ACL_RX_COUNT BT_BUF_EVT_DISCARDABLE_SIZE | BT_DISCARDABLE_BUF_SIZE - 2 BT_BUF_EVT_DISCARDABLE_COUNT | BT_DISCARDABLE_BUF_COUNT Controller-build BT_BUF_ACL_TX_SIZE | BT_CTLR_TX_BUFFERS_SIZE BT_BUF_ACL_TX_COUNT | BT_CTLR_TX_BUFFER HCI-bridge BT_BUF_ACL_TX_SIZE | BT_HCI_ACL_DATA_SIZE BT_BUF_ACL_TX_COUNT | 6 Fixed invalid configurations setting either BT_L2CAP_RX_MTU or BT_CTLR_DATA_LENGTH_MAX larger than BT_RX_BUF_LEN could lead to buffer overruns. Fix advertising report max data length calculation. This always used the BT_DISCARDABLE_BUF_SIZE macro but this feature can be turned off and advertising reports will be allocated from the RX buffer in that case. Also controller-build does not have this buffer (in hci_raw.c). Also the wrong HCI header was used in the calculation, HCI event header should have been used instead of HCI ACL header. Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
136 lines
3.2 KiB
C
136 lines
3.2 KiB
C
/** @file
|
|
* @brief Bluetooth HCI RAW channel handling
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2016 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_HCI_RAW_H_
|
|
#define ZEPHYR_INCLUDE_BLUETOOTH_HCI_RAW_H_
|
|
|
|
/**
|
|
* @brief HCI RAW channel
|
|
* @defgroup hci_raw HCI RAW channel
|
|
* @ingroup bluetooth
|
|
* @{
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/** @brief Send packet to the Bluetooth controller
|
|
*
|
|
* Send packet to the Bluetooth controller. Caller needs to
|
|
* implement netbuf pool.
|
|
*
|
|
* @param buf netbuf packet to be send
|
|
*
|
|
* @return Zero on success or (negative) error code otherwise.
|
|
*/
|
|
int bt_send(struct net_buf *buf);
|
|
|
|
enum {
|
|
/** Passthrough mode
|
|
*
|
|
* While in this mode the buffers are passed as is between the stack
|
|
* and the driver.
|
|
*/
|
|
BT_HCI_RAW_MODE_PASSTHROUGH = 0x00,
|
|
|
|
/** H:4 mode
|
|
*
|
|
* While in this mode H:4 headers will added into the buffers
|
|
* according to the buffer type when coming from the stack and will be
|
|
* removed and used to set the buffer type.
|
|
*/
|
|
BT_HCI_RAW_MODE_H4 = 0x01,
|
|
};
|
|
|
|
/** @brief Set Bluetooth RAW channel mode
|
|
*
|
|
* Set access mode of Bluetooth RAW channel.
|
|
*
|
|
* @param mode Access mode.
|
|
*
|
|
* @return Zero on success or (negative) error code otherwise.
|
|
*/
|
|
int bt_hci_raw_set_mode(uint8_t mode);
|
|
|
|
/** @brief Get Bluetooth RAW channel mode
|
|
*
|
|
* Get access mode of Bluetooth RAW channel.
|
|
*
|
|
* @return Access mode.
|
|
*/
|
|
uint8_t bt_hci_raw_get_mode(void);
|
|
|
|
#define BT_HCI_ERR_EXT_HANDLED 0xff
|
|
|
|
/** Helper macro to define a command extension
|
|
*
|
|
* @param _op Opcode of the command.
|
|
* @param _min_len Minimal length of the command.
|
|
* @param _func Handler function to be called.
|
|
*/
|
|
#define BT_HCI_RAW_CMD_EXT(_op, _min_len, _func) \
|
|
{ \
|
|
.op = _op, \
|
|
.min_len = _min_len, \
|
|
.func = _func, \
|
|
}
|
|
|
|
struct bt_hci_raw_cmd_ext {
|
|
/** Opcode of the command */
|
|
uint16_t op;
|
|
|
|
/** Minimal length of the command */
|
|
size_t min_len;
|
|
|
|
/** Handler function.
|
|
*
|
|
* Handler function to be called when a command is intercepted.
|
|
*
|
|
* @param buf Buffer containing the command.
|
|
*
|
|
* @return HCI Status code or BT_HCI_ERR_EXT_HANDLED if command has
|
|
* been handled already and a response has been sent as oppose to
|
|
* BT_HCI_ERR_SUCCESS which just indicates that the command can be
|
|
* sent to the controller to be processed.
|
|
*/
|
|
uint8_t (*func)(struct net_buf *buf);
|
|
};
|
|
|
|
/** @brief Register Bluetooth RAW command extension table
|
|
*
|
|
* Register Bluetooth RAW channel command extension table, opcodes in this
|
|
* table are intercepted to sent to the handler function.
|
|
*
|
|
* @param cmds Pointer to the command extension table.
|
|
* @param size Size of the command extension table.
|
|
*/
|
|
void bt_hci_raw_cmd_ext_register(struct bt_hci_raw_cmd_ext *cmds, size_t size);
|
|
|
|
/** @brief Enable Bluetooth RAW channel:
|
|
*
|
|
* Enable Bluetooth RAW HCI channel.
|
|
*
|
|
* @param rx_queue netbuf queue where HCI packets received from the Bluetooth
|
|
* controller are to be queued. The queue is defined in the caller while
|
|
* the available buffers pools are handled in the stack.
|
|
*
|
|
* @return Zero on success or (negative) error code otherwise.
|
|
*/
|
|
int bt_enable_raw(struct k_fifo *rx_queue);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_HCI_RAW_H_ */
|