Bluetooth: Add support for Encrypt Change HCI event

There will be various scenarios where we need to know what the current
encryption mode for a connection is.

Change-Id: I9836ffe51bfb6ebfc09497c7c716bd13a4064305
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-05-21 21:00:50 +03:00 committed by Anas Nashif
commit 62c82f0c97
3 changed files with 34 additions and 0 deletions

View file

@ -264,6 +264,13 @@ struct bt_hci_evt_disconn_complete {
uint8_t reason;
} PACK_STRUCT;
#define BT_HCI_EVT_ENCRYPT_CHANGE 0x08
struct bt_hci_evt_encrypt_change {
uint8_t status;
uint16_t handle;
uint8_t encrypt;
} PACK_STRUCT;
#define BT_HCI_EVT_CMD_COMPLETE 0x0e
struct hci_evt_cmd_complete {
uint8_t ncmd;

View file

@ -80,6 +80,8 @@ struct bt_conn {
uint8_t dst[6];
uint8_t dst_type;
uint8_t encrypt;
uint16_t rx_len;
struct bt_buf *rx;

View file

@ -293,6 +293,28 @@ static void hci_disconn_complete(struct bt_buf *buf)
}
}
static void hci_encrypt_change(struct bt_buf *buf)
{
struct bt_hci_evt_encrypt_change *evt = (void *)buf->data;
uint16_t handle = sys_le16_to_cpu(evt->handle);
struct bt_conn *conn;
BT_DBG("status %u handle %u encrypt 0x%02x\n", evt->status, handle,
evt->encrypt);
if (evt->status) {
return;
}
conn = bt_conn_lookup(handle);
if (!conn) {
BT_ERR("Unable to look up conn with handle %u\n", handle);
return;
}
conn->encrypt = evt->encrypt;
}
static void hci_reset_complete(struct bt_buf *buf)
{
uint8_t status = buf->data[0];
@ -544,6 +566,9 @@ static void hci_event(struct bt_buf *buf)
case BT_HCI_EVT_DISCONN_COMPLETE:
hci_disconn_complete(buf);
break;
case BT_HCI_EVT_ENCRYPT_CHANGE:
hci_encrypt_change(buf);
break;
case BT_HCI_EVT_CMD_COMPLETE:
hci_cmd_complete(buf);
break;