help
This option can be close when the app not used the ble security connect.
+ config SMP_SLAVE_CON_PARAMS_UPD_ENABLE
+ bool "Slave enable connection parameters update during pairing"
+ depends on BLE_SMP_ENABLE
+ default n
+ help
+ In order to reduce the pairing time, slave actively initiates connection parameters update during pairing.
+
config BT_STACK_NO_LOG
bool "Disable BT debug logs (minimize bin size)"
depends on BLUEDROID_ENABLED
#define BLE_PRIVACY_SPT FALSE
#endif /* CONFIG_SMP_ENABLE */
+#ifdef CONFIG_SMP_SLAVE_CON_PARAMS_UPD_ENABLE
+#if(CONFIG_SMP_SLAVE_CON_PARAMS_UPD_ENABLE)
+#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE TRUE
+#else
+#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE
+#endif
+#else
+#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE
+#endif
+
#if (CONFIG_BT_ACL_CONNECTIONS)
#define MAX_ACL_CONNECTIONS CONFIG_BT_ACL_CONNECTIONS
#define GATT_MAX_PHY_CHANNEL CONFIG_BT_ACL_CONNECTIONS
break;
}
}
-
+#if (SMP_SLAVE_CON_PARAMS_UPD_ENABLE == TRUE)
// already have encrypted information, do not need to update connection parameters
if(link_role == BTM_ROLE_SLAVE && (p_rec->ble.key_type & BTM_LE_KEY_PENC)) {
p_rec->ble.skip_update_conn_param = true;
} else {
p_rec->ble.skip_update_conn_param = false;
}
+#endif
if (SMP_Pair(bd_addr) == SMP_STARTED) {
cmd = BTM_CMD_STARTED;
p_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING;
#if SMP_INCLUDED == TRUE
tBTM_LE_KEY_TYPE key_type; /* bit mask of valid key types in record */
tBTM_SEC_BLE_KEYS keys; /* LE device security info in slave rode */
+#if (SMP_SLAVE_CON_PARAMS_UPD_ENABLE == TRUE)
bool skip_update_conn_param; /* skip update connection paraams or not*/
+#endif
UINT16 auth_mode; /* Authentication mode */
#endif
#if (BLE_PRIVACY_SPT == TRUE)
*******************************************************************************/
void smp_fast_conn_param(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
- tBTM_SEC_DEV_REC *p_rec = btm_find_dev (p_cb->pairing_bda);
- if(p_rec && p_rec->ble.skip_update_conn_param) {
- //do nothing
- return;
+ if(p_cb->role == BTM_ROLE_MASTER) {
+ L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, FALSE);
+ }
+#if (SMP_SLAVE_CON_PARAMS_UPD_ENABLE == TRUE)
+ else {
+ tBTM_SEC_DEV_REC *p_rec = btm_find_dev (p_cb->pairing_bda);
+ if(p_rec && p_rec->ble.skip_update_conn_param) {
+ //do nothing
+ return;
+ }
+ /* Disable L2CAP connection parameter updates while bonding since
+ some peripherals are not able to revert to fast connection parameters
+ during the start of service discovery. Connection paramter updates
+ get enabled again once service discovery completes. */
+ L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, FALSE);
}
- /* Disable L2CAP connection parameter updates while bonding since
- some peripherals are not able to revert to fast connection parameters
- during the start of service discovery. Connection paramter updates
- get enabled again once service discovery completes. */
- L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, FALSE);
+#endif
}
/*******************************************************************************
memcpy (pairing_bda, p_cb->pairing_bda, BD_ADDR_LEN);
+#if (SMP_SLAVE_CON_PARAMS_UPD_ENABLE == TRUE)
if (p_cb->role == HCI_ROLE_SLAVE) {
if(p_rec && p_rec->ble.skip_update_conn_param) {
//clear flag
L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, TRUE);
}
}
+#endif
smp_reset_control_value(p_cb);
if (p_callback) {
*
*/
+/**
+ * Note:
+ * 1. Win10 does not support vendor report , So SUPPORT_REPORT_VENDOR is always set to FALSE, it defines in hidd_le_prf_int.h
+ * 2. Update connection parameters are not allowed during iPhone HID encryption, slave turns
+ * off the ability to automatically update connection parameters during encryption.
+ * 3. After our HID device is connected, the iPhones write 1 to the Report Characteristic Configuration Descriptor,
+ * even if the HID encryption is not completed. This should actually be written 1 after the HID encryption is completed.
+ * we modify the permissions of the Report Characteristic Configuration Descriptor to `ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE_ENCRYPTED`.
+ * if you got `GATT_INSUF_ENCRYPTION` error, please ignore.
+ */
+
#define HID_DEMO_TAG "HID_DEMO"
//init the gpio pin
gpio_demo_init();
- xTaskCreate(&hid_demo_task, "hid_task", 2048, NULL, 5, NULL);
+ xTaskCreate(&hid_demo_task, "hid_task", 2048, NULL, 5, NULL);
}
0x81, 0x00, // Input (Data, Ary, Abs)
0xC0, // End Collection
0x81, 0x03, // Input (Const, Var, Abs)
- 0xC0, // End Collection
+ 0xC0, // End Collectionq
+
+#if (SUPPORT_REPORT_VENDOR == true)
0x06, 0xFF, 0xFF, // Usage Page(Vendor defined)
0x09, 0xA5, // Usage(Vendor Defined)
0xA1, 0x01, // Collection(Application)
0x95, 0x7F, // Report Count = 127 Btyes
0x91, 0x02, // Output(Data, Variable, Absolute)
0xC0, // End Collection
+#endif
+
};
/// Battery Service Attributes Indexes
static uint8_t hidReportRefLedOut[HID_REPORT_REF_LEN] =
{ HID_RPT_ID_LED_OUT, HID_REPORT_TYPE_OUTPUT };
+#if (SUPPORT_REPORT_VENDOR == true)
+
static uint8_t hidReportRefVendorOut[HID_REPORT_REF_LEN] =
{HID_RPT_ID_VENDOR_OUT, HID_REPORT_TYPE_OUTPUT};
+#endif
// HID Report Reference characteristic descriptor, Feature
static uint8_t hidReportRefFeature[HID_REPORT_REF_LEN] =
ESP_GATT_PERM_READ,
sizeof(hidReportRefLedOut), sizeof(hidReportRefLedOut),
hidReportRefLedOut}},
+#if (SUPPORT_REPORT_VENDOR == true)
// Report Characteristic Declaration
[HIDD_LE_IDX_REPORT_VENDOR_OUT_CHAR] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid,
ESP_GATT_PERM_READ,
ESP_GATT_PERM_READ,
sizeof(hidReportRefVendorOut), sizeof(hidReportRefVendorOut),
hidReportRefVendorOut}},
-
- // Report Characteristic Declaration
+#endif
+ // Report Characteristic Declaration
[HIDD_LE_IDX_REPORT_CC_IN_CHAR] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid,
ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE,
NULL}},
// Report KEY INPUT Characteristic - Client Characteristic Configuration Descriptor
[HIDD_LE_IDX_REPORT_CC_IN_CCC] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid,
- (ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE),
+ (ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE_ENCRYPTED),
sizeof(uint16_t), 0,
NULL}},
// Report Characteristic - Report Reference Descriptor
{
switch(event) {
case ESP_GATTS_REG_EVT: {
+ esp_ble_gap_config_local_icon (ESP_BLE_APPEARANCE_GENERIC_HID);
esp_hidd_cb_param_t hidd_param;
hidd_param.init_finish.state = param->reg.status;
if(param->reg.app_id == HIDD_APP_ID) {
case ESP_GATTS_CLOSE_EVT:
break;
case ESP_GATTS_WRITE_EVT: {
+#if (SUPPORT_REPORT_VENDOR == true)
esp_hidd_cb_param_t cb_param = {0};
if (param->write.handle == hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_VENDOR_OUT_VAL] &&
hidd_le_env.hidd_cb != NULL) {
cb_param.vendor_write.data = param->write.value;
(hidd_le_env.hidd_cb)(ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT, &cb_param);
}
+#endif
break;
}
case ESP_GATTS_CREAT_ATTR_TAB_EVT: {
#ifndef __HID_DEVICE_LE_PRF__
#define __HID_DEVICE_LE_PRF__
+#include <stdbool.h>
#include "esp_gatts_api.h"
#include "esp_gatt_defs.h"
#include "esp_hidd_prf_api.h"
#include "esp_gap_ble_api.h"
#include "hid_dev.h"
+#define SUPPORT_REPORT_VENDOR false
//HID BLE profile log tag
#define HID_LE_PRF_TAG "HID_LE_PRF"
HIDD_LE_IDX_REPORT_LED_OUT_VAL,
HIDD_LE_IDX_REPORT_LED_OUT_REP_REF,
+#if (SUPPORT_REPORT_VENDOR == true)
/// Report Vendor
HIDD_LE_IDX_REPORT_VENDOR_OUT_CHAR,
HIDD_LE_IDX_REPORT_VENDOR_OUT_VAL,
HIDD_LE_IDX_REPORT_VENDOR_OUT_REP_REF,
-
+#endif
HIDD_LE_IDX_REPORT_CC_IN_CHAR,
HIDD_LE_IDX_REPORT_CC_IN_VAL,
HIDD_LE_IDX_REPORT_CC_IN_CCC,