]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: fix iOS and win10 compatibility error for HID
authorzhiweijian <zhiweijian@espressif.com>
Thu, 28 Feb 2019 12:39:12 +0000 (20:39 +0800)
committerzhiweijian <zhiweijian@espressif.com>
Thu, 28 Feb 2019 12:39:12 +0000 (20:39 +0800)
components/bt/Kconfig
components/bt/bluedroid/common/include/common/bt_target.h
components/bt/bluedroid/stack/btm/btm_ble.c
components/bt/bluedroid/stack/btm/include/btm_int.h
components/bt/bluedroid/stack/smp/smp_act.c
components/bt/bluedroid/stack/smp/smp_utils.c
examples/bluetooth/ble_hid_device_demo/main/ble_hidd_demo_main.c
examples/bluetooth/ble_hid_device_demo/main/hid_device_le_prf.c
examples/bluetooth/ble_hid_device_demo/main/hidd_le_prf_int.h

index 4551a47f88148ca574739a2be5235a9711393f2e..d0152d6ff802e500e15f77584d0fd3c489e7b86c 100644 (file)
@@ -428,6 +428,13 @@ menu Bluetooth
         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
index e2b5f8538a480ed900640c536deca9dd0b4ac5a7..997295bb419377b251230dbf9933ca68bbcd8420 100644 (file)
 #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
index 0a5ad832c9cb003a6c20a386f0bf965d833d12ed..5e4c9ee71ceeb8b89c86b3f1051fa5576ef05a44 100644 (file)
@@ -1468,13 +1468,14 @@ tBTM_STATUS btm_ble_set_encryption (BD_ADDR bd_addr, void *p_ref_data, UINT8 lin
                 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;
index 490d9afe42f53f7015fd5f85f44abe8da456a98e..47ddfd3449b3885b9d1fb5953931ffdb8698e93c 100644 (file)
@@ -488,7 +488,9 @@ typedef struct {
 #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)
index 63b9cb10e5fc540728109bd7a7235741618545c1..dcd3495f254dbd3aecae1c0fb6ff61ebaff655a6 100644 (file)
@@ -1478,16 +1478,23 @@ void smp_idle_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 *******************************************************************************/
 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
 }
 
 /*******************************************************************************
index 79a8b1dd59ebd674989067309d428629bdeec6ab..19c2cde99bfd7463797fcb0e8874887844365fe9 100644 (file)
@@ -996,6 +996,7 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb)
 
     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
@@ -1004,6 +1005,7 @@ void smp_proc_pairing_cmpl(tSMP_CB *p_cb)
             L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, TRUE);
         }
     }
+#endif
     smp_reset_control_value(p_cb);
 
     if (p_callback) {
index 39316b7e673778e791b5bbd7473f9b005580bd10..ae7e0cac92b59741214f6319e2afc16cd26fe132 100644 (file)
  *
  */
 
+/** 
+ * 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"
 
 
@@ -324,7 +335,7 @@ void app_main()
 
     //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);
 
 }
 
index 8d112fad875928e162a19ceb03015c2058935998..8041e7b5e617b1f7f44434980942a1d8cceb6cf0 100644 (file)
@@ -168,7 +168,9 @@ static const uint8_t hidReportMap[] = {
     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)
@@ -179,6 +181,8 @@ static const uint8_t hidReportMap[] = {
     0x95, 0x7F,   // Report Count = 127 Btyes
     0x91, 0x02,   // Output(Data, Variable, Absolute)
     0xC0,         // End Collection
+#endif
+
 };
 
 /// Battery Service Attributes Indexes
@@ -239,8 +243,11 @@ static uint8_t hidReportRefKeyIn[HID_REPORT_REF_LEN] =
 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] =
@@ -436,6 +443,7 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
                                                                        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,
@@ -449,8 +457,8 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
                                                                        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,
@@ -462,7 +470,7 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
                                                                        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
@@ -538,6 +546,7 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
 {
     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) {
@@ -584,6 +593,7 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
         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) {
@@ -593,6 +603,7 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
                 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: {
index 4482be55ae6a51caac7377b540c172b446407263..89e7cc20dfa5a4199b68dbe1df2d52d1d3e923e9 100644 (file)
 
 #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"
 
@@ -141,11 +143,12 @@ enum {
     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,