Bluetooth: Add skeleton for handling disconnect complete events
This patch adds a simple event handler for the LE Disconnection Complete HCI event. An extra thing the handler needs to do is to re-enable advertising if necessary, since it will have been implicitly disabled by the controller upon a connection event. Change-Id: Ie6f2eecb8c1d7de16fea24c8fd1533545f41baa5 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
64b6f11450
commit
58c5689531
2 changed files with 29 additions and 0 deletions
|
@ -163,6 +163,13 @@ struct bt_hci_cp_le_set_adv_enable {
|
|||
|
||||
/* Event definitions */
|
||||
|
||||
#define BT_HCI_EVT_DISCONN_COMPLETE 0x05
|
||||
struct bt_hci_evt_disconn_complete {
|
||||
uint8_t status;
|
||||
uint16_t handle;
|
||||
uint8_t reason;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#define BT_HCI_EVT_CMD_COMPLETE 0x0e
|
||||
struct hci_evt_cmd_complete {
|
||||
uint8_t ncmd;
|
||||
|
|
|
@ -203,6 +203,25 @@ static void hci_acl(struct bt_buf *buf)
|
|||
|
||||
/* HCI event processing */
|
||||
|
||||
static void hci_disconn_complete(struct bt_buf *buf)
|
||||
{
|
||||
struct bt_hci_evt_disconn_complete *evt = (void *)buf->data;
|
||||
uint16_t handle = bt_acl_handle(sys_le16_to_cpu(evt->handle));
|
||||
|
||||
BT_DBG("status %u handle %u reason %u\n", evt->status, handle,
|
||||
evt->reason);
|
||||
|
||||
if (dev.adv_enable) {
|
||||
struct bt_buf *buf;
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
|
||||
if (buf) {
|
||||
memcpy(bt_buf_add(buf, 1), &dev.adv_enable, 1);
|
||||
bt_hci_cmd_send(BT_HCI_OP_LE_SET_ADV_ENABLE, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void hci_reset_complete(struct bt_buf *buf)
|
||||
{
|
||||
uint8_t status = buf->data[0];
|
||||
|
@ -428,6 +447,9 @@ static void hci_event(struct bt_buf *buf)
|
|||
bt_buf_pull(buf, sizeof(*hdr));
|
||||
|
||||
switch (hdr->evt) {
|
||||
case BT_HCI_EVT_DISCONN_COMPLETE:
|
||||
hci_disconn_complete(buf);
|
||||
break;
|
||||
case BT_HCI_EVT_CMD_COMPLETE:
|
||||
hci_cmd_complete(buf);
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue