Bluetooth: Add convenience macros for common header sizes
The C pre-processor doesn't allow using sizeof() in comparisons such as "#if FOO < sizeof(bar)". To make it possible to use such comparisons where the sizes of headers are involved, introduce helper macros for the headers instead of always having to hard-code magic numbers into the code. Change-Id: Iaf654cb4aaa49e83360901f5b01225ba4b952854 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
bbf389aae6
commit
be139268b3
3 changed files with 21 additions and 6 deletions
|
@ -133,6 +133,7 @@ struct bt_hci_evt_hdr {
|
||||||
uint8_t evt;
|
uint8_t evt;
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
#define BT_HCI_EVT_HDR_SIZE 2
|
||||||
|
|
||||||
#define BT_ACL_START_NO_FLUSH 0x00
|
#define BT_ACL_START_NO_FLUSH 0x00
|
||||||
#define BT_ACL_CONT 0x01
|
#define BT_ACL_CONT 0x01
|
||||||
|
@ -146,11 +147,13 @@ struct bt_hci_acl_hdr {
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
#define BT_HCI_ACL_HDR_SIZE 4
|
||||||
|
|
||||||
struct bt_hci_cmd_hdr {
|
struct bt_hci_cmd_hdr {
|
||||||
uint16_t opcode;
|
uint16_t opcode;
|
||||||
uint8_t param_len;
|
uint8_t param_len;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
#define BT_HCI_CMD_HDR_SIZE 3
|
||||||
|
|
||||||
/* Supported Commands */
|
/* Supported Commands */
|
||||||
#define BT_CMD_TEST(cmd, octet, bit) (cmd[octet] & BIT(bit))
|
#define BT_CMD_TEST(cmd, octet, bit) (cmd[octet] & BIT(bit))
|
||||||
|
|
|
@ -24,6 +24,23 @@ extern "C" {
|
||||||
#include <atomic.h>
|
#include <atomic.h>
|
||||||
#include <bluetooth/buf.h>
|
#include <bluetooth/buf.h>
|
||||||
#include <bluetooth/conn.h>
|
#include <bluetooth/conn.h>
|
||||||
|
#include <bluetooth/hci.h>
|
||||||
|
|
||||||
|
/* L2CAP header size, used for buffer size calculations */
|
||||||
|
#define BT_L2CAP_HDR_SIZE 4
|
||||||
|
|
||||||
|
/** @def BT_L2CAP_BUF_SIZE
|
||||||
|
*
|
||||||
|
* Helper to calculate needed outgoing buffer size, useful e.g. for
|
||||||
|
* creating buffer pools.
|
||||||
|
*
|
||||||
|
* @param mtu Needed L2CAP MTU.
|
||||||
|
*
|
||||||
|
* @return Needed buffer size to match the requested L2CAP MTU.
|
||||||
|
*/
|
||||||
|
#define BT_L2CAP_BUF_SIZE(mtu) (CONFIG_BLUETOOTH_HCI_SEND_RESERVE + \
|
||||||
|
BT_HCI_ACL_HDR_SIZE + BT_L2CAP_HDR_SIZE + \
|
||||||
|
(mtu))
|
||||||
|
|
||||||
struct bt_l2cap_chan;
|
struct bt_l2cap_chan;
|
||||||
|
|
||||||
|
|
|
@ -192,13 +192,8 @@ struct bt_l2cap_le_credits {
|
||||||
|
|
||||||
#define BT_L2CAP_SDU_HDR_LEN 2
|
#define BT_L2CAP_SDU_HDR_LEN 2
|
||||||
|
|
||||||
/* Helper to calculate needed outgoing buffer size */
|
|
||||||
#define BT_L2CAP_BUF_SIZE(mtu) (CONFIG_BLUETOOTH_HCI_SEND_RESERVE + \
|
|
||||||
sizeof(struct bt_hci_acl_hdr) + \
|
|
||||||
sizeof(struct bt_l2cap_hdr) + (mtu))
|
|
||||||
|
|
||||||
#define BT_L2CAP_RX_MTU (CONFIG_BLUETOOTH_RX_BUF_LEN - \
|
#define BT_L2CAP_RX_MTU (CONFIG_BLUETOOTH_RX_BUF_LEN - \
|
||||||
4 /* HCI ACL header */ - 4 /* L2CAP header */)
|
BT_HCI_ACL_HDR_SIZE - BT_L2CAP_HDR_SIZE)
|
||||||
|
|
||||||
struct bt_l2cap_fixed_chan {
|
struct bt_l2cap_fixed_chan {
|
||||||
uint16_t cid;
|
uint16_t cid;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue