Bluetooth: Add convenience defines for ACL handles

These make the code more readable when it comes to encoding and
decoding ACL handle values.

Change-Id: Ibd1972d6001c6c0c55428300f839b288dff1ce52
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-11-03 13:42:44 +02:00 committed by Anas Nashif
commit db946d8bae
3 changed files with 13 additions and 7 deletions

View file

@ -73,7 +73,13 @@ struct bt_hci_evt_hdr {
uint8_t len;
} __packed;
#define BT_ACL_START_NO_FLUSH 0x00
#define BT_ACL_CONT 0x01
#define BT_ACL_START 0x02
#define bt_acl_handle(h) ((h) & 0x0fff)
#define bt_acl_flags(h) ((h) >> 12)
#define bt_acl_handle_pack(h, f) ((h) | ((f) << 12))
struct bt_hci_acl_hdr {
uint16_t handle;

View file

@ -234,8 +234,7 @@ void bt_conn_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
/* Check packet boundary flags */
switch (flags) {
case 0x02:
/* First packet */
case BT_ACL_START:
hdr = (void *)buf->data;
len = sys_le16_to_cpu(hdr->len);
@ -254,8 +253,7 @@ void bt_conn_recv(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
}
break;
case 0x01:
/* Continuation */
case BT_ACL_CONT:
if (!conn->rx_len) {
BT_ERR("Unexpected L2CAP continuation\n");
bt_conn_reset_rx_state(conn);
@ -332,7 +330,8 @@ void bt_conn_send(struct bt_conn *conn, struct net_buf *buf)
len = min(remaining, bt_dev.le_mtu);
hdr = net_buf_push(buf, sizeof(*hdr));
hdr->handle = sys_cpu_to_le16(conn->handle);
hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn->handle,
BT_ACL_START_NO_FLUSH));
hdr->len = sys_cpu_to_le16(len);
buf->len -= remaining - len;
@ -351,7 +350,8 @@ void bt_conn_send(struct bt_conn *conn, struct net_buf *buf)
ptr += len;
hdr = net_buf_push(buf, sizeof(*hdr));
hdr->handle = sys_cpu_to_le16(conn->handle | (1 << 12));
hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn->handle,
BT_ACL_CONT));
hdr->len = sys_cpu_to_le16(len);
nano_fifo_put(&frags, buf);

View file

@ -316,7 +316,7 @@ static void hci_acl(struct net_buf *buf)
BT_DBG("buf %p\n", buf);
handle = sys_le16_to_cpu(hdr->handle);
flags = (handle >> 12);
flags = bt_acl_flags(handle);
acl(buf)->handle = bt_acl_handle(handle);