From bf62dfad700e5ff297153c0fee2fce7816778551 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lichwa Date: Fri, 18 Mar 2016 14:19:35 +0100 Subject: [PATCH] Bluetooth: BR/EDR: Initiate encryption on link Adds method to start encrypting the link by local controller. Encryption implies successful authentication to be done before. > HCI Event: Auth Complete (0x06) plen 3 Status: Success (0x00) Handle: 11 < HCI Command: Set Connection Encryption (0x01|0x0013) plen 3 Handle: 11 Encryption: Enabled (0x01) > HCI Event: Command Status (0x0f) plen 4 Set Connection Encryption (0x01|0x0013) ncmd 1 Status: Success (0x00) > HCI Event: Encryption Change (0x08) plen 4 Status: Success (0x00) Handle: 11 Encryption: Enabled with E0 (0x01) Change-Id: I3bbfc6ca77a6fd088582ab45f14d7c122aec7f05 Signed-off-by: Arkadiusz Lichwa --- include/bluetooth/hci.h | 6 ++++++ net/bluetooth/hci_core.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/bluetooth/hci.h b/include/bluetooth/hci.h index 4089fb68286..0393ac7805e 100644 --- a/include/bluetooth/hci.h +++ b/include/bluetooth/hci.h @@ -262,6 +262,12 @@ struct bt_hci_cp_auth_requested { uint16_t handle; } __packed; +#define BT_HCI_OP_SET_CONN_ENCRYPT BT_OP(BT_OGF_LINK_CTRL, 0x0013) +struct bt_hci_cp_set_conn_encrypt { + uint16_t handle; + uint8_t encrypt; +} __packed; + #define BT_HCI_OP_REMOTE_NAME_REQUEST BT_OP(BT_OGF_LINK_CTRL, 0x0019) struct bt_hci_cp_remote_name_request { bt_addr_t bdaddr; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index d1ac6a0e825..085ce913928 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1708,6 +1708,26 @@ check_names: discovery_results_count = 0; } +static void link_encr(const uint16_t handle) +{ + struct bt_hci_cp_set_conn_encrypt *encr; + struct net_buf *buf; + + BT_DBG(""); + + buf = bt_hci_cmd_create(BT_HCI_OP_SET_CONN_ENCRYPT, sizeof(*encr)); + if (!buf) { + BT_ERR("Out of command buffers"); + return; + } + + encr = net_buf_add(buf, sizeof(*encr)); + encr->handle = sys_cpu_to_le16(handle); + encr->encrypt = 0x01; + + bt_hci_cmd_send_sync(BT_HCI_OP_SET_CONN_ENCRYPT, buf, NULL); +} + static void auth_complete(struct net_buf *buf) { struct bt_hci_evt_auth_complete *evt = (void *)buf->data; @@ -1732,6 +1752,8 @@ static void auth_complete(struct net_buf *buf) /* Reset required security level to current operational */ conn->required_sec_level = conn->sec_level; + } else { + link_encr(handle); } bt_conn_unref(conn);