#include <base/location.h>
#include <base/logging.h>
#include <base/threading/thread.h>
+#include <log/log.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
btm_sec_rmt_name_request_complete(&bd_addr, p, status);
}
+constexpr uint8_t MIN_KEY_SIZE = 7;
+
+static void read_encryption_key_size_complete_after_encryption_change(
+ uint8_t status, uint16_t handle, uint8_t key_size) {
+ if (status != HCI_SUCCESS) {
+ HCI_TRACE_WARNING("%s: disconnecting, status: 0x%02x", __func__, status);
+ btsnd_hcic_disconnect(handle, HCI_ERR_PEER_USER);
+ return;
+ }
+
+ if (key_size < MIN_KEY_SIZE) {
+ android_errorWriteLog(0x534e4554, "124301137");
+ HCI_TRACE_ERROR(
+ "%s encryption key too short, disconnecting. handle: 0x%02x, key_size: "
+ "%d",
+ __func__, handle, key_size);
+
+ btsnd_hcic_disconnect(handle, HCI_ERR_HOST_REJECT_SECURITY);
+ return;
+ }
+
+ // good key size - succeed
+ btm_acl_encrypt_change(handle, status, 1 /* enable */);
+ btm_sec_encrypt_change(handle, status, 1 /* enable */);
+}
/*******************************************************************************
*
* Function btu_hcif_encryption_change_evt
STREAM_TO_UINT16(handle, p);
STREAM_TO_UINT8(encr_enable, p);
- btm_acl_encrypt_change(handle, status, encr_enable);
- btm_sec_encrypt_change(handle, status, encr_enable);
+ if (status != HCI_SUCCESS || encr_enable == 0 ||
+ BTM_IsBleConnection(handle)) {
+ btm_acl_encrypt_change(handle, status, encr_enable);
+ btm_sec_encrypt_change(handle, status, encr_enable);
+ } else {
+ btsnd_hcic_read_encryption_key_size(
+ handle,
+ base::Bind(&read_encryption_key_size_complete_after_encryption_change));
+ }
}
/*******************************************************************************
* End of Simple Pairing Events
**********************************************/
-/**********************************************
- * BLE Events
- **********************************************/
+static void read_encryption_key_size_complete_after_key_refresh(
+ uint8_t status, uint16_t handle, uint8_t key_size) {
+ if (status != HCI_SUCCESS) {
+ HCI_TRACE_WARNING("%s: disconnecting, status: 0x%02x", __func__, status);
+ btsnd_hcic_disconnect(handle, HCI_ERR_PEER_USER);
+ return;
+ }
+
+ if (key_size < MIN_KEY_SIZE) {
+ android_errorWriteLog(0x534e4554, "124301137");
+ HCI_TRACE_WARNING(
+ "%s encryption key too short, disconnecting. handle: 0x%02x, key_size: "
+ "%d",
+ __func__, handle, key_size);
+
+ btsnd_hcic_disconnect(handle, HCI_ERR_HOST_REJECT_SECURITY);
+ return;
+ }
+
+ btm_sec_encrypt_change(handle, status, 1 /* enc_enable */);
+}
+
static void btu_hcif_encryption_key_refresh_cmpl_evt(uint8_t* p) {
uint8_t status;
- uint8_t enc_enable = 0;
uint16_t handle;
STREAM_TO_UINT8(status, p);
STREAM_TO_UINT16(handle, p);
- if (status == HCI_SUCCESS) enc_enable = 1;
-
- btm_sec_encrypt_change(handle, status, enc_enable);
+ if (status != HCI_SUCCESS || BTM_IsBleConnection(handle)) {
+ btm_sec_encrypt_change(handle, status, (status == HCI_SUCCESS) ? 1 : 0);
+ } else {
+ btsnd_hcic_read_encryption_key_size(
+ handle,
+ base::Bind(&read_encryption_key_size_complete_after_key_refresh));
+ }
}
+/**********************************************
+ * BLE Events
+ **********************************************/
+
static void btu_ble_ll_conn_complete_evt(uint8_t* p, uint16_t evt_len) {
btm_ble_conn_complete(p, evt_len, false);
}
#include "hcidefs.h"
#include "hcimsgs.h"
+#include <base/bind.h>
#include <stddef.h>
#include <string.h>
btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
}
+static void read_encryption_key_size_complete(
+ ReadEncKeySizeCb cb, uint8_t* return_parameters,
+ uint16_t return_parameters_length) {
+ uint8_t status;
+ uint16_t handle;
+ uint8_t key_size;
+ STREAM_TO_UINT8(status, return_parameters);
+ STREAM_TO_UINT16(handle, return_parameters);
+ STREAM_TO_UINT8(key_size, return_parameters);
+
+ std::move(cb).Run(status, handle, key_size);
+}
+
+void btsnd_hcic_read_encryption_key_size(uint16_t handle, ReadEncKeySizeCb cb) {
+ constexpr uint8_t len = 2;
+ uint8_t param[len];
+ memset(param, 0, len);
+
+ uint8_t* p = param;
+ UINT16_TO_STREAM(p, handle);
+
+ btu_hcif_send_cmd_with_cb(
+ FROM_HERE, HCI_READ_ENCR_KEY_SIZE, param, len,
+ base::Bind(&read_encryption_key_size_complete, base::Passed(&cb)));
+}
+
void btsnd_hcic_read_failed_contact_counter(uint16_t handle) {
BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
uint8_t* pp = (uint8_t*)(p + 1);