Просмотр исходного кода

component/bt: Fix some hid bugs

1. Property of HID Information is Read
2. Property of HID Control Point is WriteWithoutResponse
baohongde 7 лет назад
Родитель
Сommit
7ff84d94aa
1 измененных файлов с 34 добавлено и 34 удалено
  1. 34 34
      examples/bluetooth/ble_hid_device_demo/main/hid_device_le_prf.c

+ 34 - 34
examples/bluetooth/ble_hid_device_demo/main/hid_device_le_prf.c

@@ -230,7 +230,7 @@ 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 };
 
-static uint8_t hidReportRefVendorOut[HID_REPORT_REF_LEN] = 
+static uint8_t hidReportRefVendorOut[HID_REPORT_REF_LEN] =
              {HID_RPT_ID_VENDOR_OUT, HID_REPORT_TYPE_OUTPUT};
 
 // HID Report Reference characteristic descriptor, Feature
@@ -271,7 +271,7 @@ static const uint16_t hid_report_ref_descr_uuid = ESP_GATT_UUID_RPT_REF_DESCR;
 ///the propoty definition
 static const uint8_t char_prop_notify = ESP_GATT_CHAR_PROP_BIT_NOTIFY;
 static const uint8_t char_prop_read = ESP_GATT_CHAR_PROP_BIT_READ;
-static const uint8_t char_prop_write = ESP_GATT_CHAR_PROP_BIT_WRITE;
+static const uint8_t char_prop_write_nr = ESP_GATT_CHAR_PROP_BIT_WRITE_NR;
 static const uint8_t char_prop_read_write = ESP_GATT_CHAR_PROP_BIT_WRITE|ESP_GATT_CHAR_PROP_BIT_READ;
 static const uint8_t char_prop_read_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_NOTIFY;
 static const uint8_t char_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_WRITE|ESP_GATT_CHAR_PROP_BIT_NOTIFY;
@@ -294,7 +294,7 @@ static const esp_gatts_attr_db_t bas_att_db[BAS_IDX_NB] =
     // Battary level Characteristic Declaration
     [BAS_IDX_BATT_LVL_CHAR]    = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
                                                    CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_notify}},
-      
+
     // Battary level Characteristic Value
     [BAS_IDX_BATT_LVL_VAL]             	= {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&bat_lev_uuid, ESP_GATT_PERM_READ,
                                                                 sizeof(uint8_t),sizeof(uint8_t), &battary_lev}},
@@ -313,8 +313,8 @@ static const esp_gatts_attr_db_t bas_att_db[BAS_IDX_NB] =
 static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
 {
             // HID Service Declaration
-    [HIDD_LE_IDX_SVC]                       = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, 
-                                                             ESP_GATT_PERM_READ_ENCRYPTED, sizeof(uint16_t), sizeof(hid_le_svc), 
+    [HIDD_LE_IDX_SVC]                       = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid,
+                                                             ESP_GATT_PERM_READ_ENCRYPTED, sizeof(uint16_t), sizeof(hid_le_svc),
                                                             (uint8_t *)&hid_le_svc}},
 
     // HID Service Declaration
@@ -327,7 +327,7 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
     [HIDD_LE_IDX_HID_INFO_CHAR]     = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid,
                                                             ESP_GATT_PERM_READ,
                                                             CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE,
-                                                            (uint8_t *)&char_prop_read_write}},
+                                                            (uint8_t *)&char_prop_read}},
     // HID Information Characteristic Value
     [HIDD_LE_IDX_HID_INFO_VAL]       = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&hid_info_char_uuid,
                                                             ESP_GATT_PERM_READ,
@@ -338,7 +338,7 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
     [HIDD_LE_IDX_HID_CTNL_PT_CHAR]  = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid,
                                                               ESP_GATT_PERM_READ,
                                                               CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE,
-                                                              (uint8_t *)&char_prop_write}},
+                                                              (uint8_t *)&char_prop_write_nr}},
     // HID Control Point Characteristic Value
     [HIDD_LE_IDX_HID_CTNL_PT_VAL]    = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&hid_control_point_uuid,
                                                              ESP_GATT_PERM_WRITE,
@@ -372,22 +372,22 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
                                                                         (ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE),
                                                                         sizeof(uint8_t), sizeof(hidProtocolMode),
                                                                         (uint8_t *)&hidProtocolMode}},
-    
+
     [HIDD_LE_IDX_REPORT_MOUSE_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,
                                                                          (uint8_t *)&char_prop_read_notify}},
-    
+
     [HIDD_LE_IDX_REPORT_MOUSE_IN_VAL]        = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&hid_report_uuid,
                                                                        ESP_GATT_PERM_READ,
                                                                        HIDD_LE_REPORT_MAX_LEN, 0,
                                                                        NULL}},
-    
+
     [HIDD_LE_IDX_REPORT_MOUSE_IN_CCC]        = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid,
                                                                       (ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE),
                                                                       sizeof(uint16_t), 0,
                                                                       NULL}},
-    
+
     [HIDD_LE_IDX_REPORT_MOUSE_REP_REF]       = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&hid_report_ref_descr_uuid,
                                                                        ESP_GATT_PERM_READ,
                                                                        sizeof(hidReportRefMouseIn), sizeof(hidReportRefMouseIn),
@@ -461,7 +461,7 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
                                                                        ESP_GATT_PERM_READ,
                                                                        sizeof(hidReportRefCCIn), sizeof(hidReportRefCCIn),
                                                                        hidReportRefCCIn}},
-    
+
     // Boot Keyboard Input Report Characteristic Declaration
     [HIDD_LE_IDX_BOOT_KB_IN_REPORT_CHAR] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid,
                                                                         ESP_GATT_PERM_READ,
@@ -524,7 +524,7 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] =
 
 static void hid_add_id_tbl(void);
 
-void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, 
+void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
 									esp_ble_gatts_cb_param_t *param)
 {
     switch(event) {
@@ -543,14 +543,14 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
                  if(hidd_le_env.hidd_cb != NULL) {
                     (hidd_le_env.hidd_cb)(ESP_BAT_EVENT_REG, &hidd_param);
                 }
-                
+
             }
-           
+
             break;
         }
         case ESP_GATTS_CONF_EVT: {
             break;
-        }    
+        }
         case ESP_GATTS_CREATE_EVT:
             break;
         case ESP_GATTS_CONNECT_EVT: {
@@ -587,18 +587,18 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
             break;
         }
         case ESP_GATTS_CREAT_ATTR_TAB_EVT: {
-            if (param->add_attr_tab.num_handle == BAS_IDX_NB && 
+            if (param->add_attr_tab.num_handle == BAS_IDX_NB &&
                 param->add_attr_tab.svc_uuid.uuid.uuid16 == ESP_GATT_UUID_BATTERY_SERVICE_SVC &&
                 param->add_attr_tab.status == ESP_GATT_OK) {
                 incl_svc.start_hdl = param->add_attr_tab.handles[BAS_IDX_SVC];
                 incl_svc.end_hdl = incl_svc.start_hdl + BAS_IDX_NB -1;
-                ESP_LOGE(HID_LE_PRF_TAG, "%s(), start added the hid service to the stack database. incl_handle = %d", 
+                ESP_LOGE(HID_LE_PRF_TAG, "%s(), start added the hid service to the stack database. incl_handle = %d",
                            __func__, incl_svc.start_hdl);
                 esp_ble_gatts_create_attr_tab(hidd_le_gatt_db, gatts_if, HIDD_LE_IDX_NB, 0);
             }
-            if (param->add_attr_tab.num_handle == HIDD_LE_IDX_NB && 
+            if (param->add_attr_tab.num_handle == HIDD_LE_IDX_NB &&
                 param->add_attr_tab.status == ESP_GATT_OK) {
-                memcpy(hidd_le_env.hidd_inst.att_tbl, param->add_attr_tab.handles, 
+                memcpy(hidd_le_env.hidd_inst.att_tbl, param->add_attr_tab.handles,
                             HIDD_LE_IDX_NB*sizeof(uint16_t));
                 ESP_LOGE(HID_LE_PRF_TAG, "hid svc handle = %x",hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_SVC]);
                 hid_add_id_tbl();
@@ -608,7 +608,7 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
             }
             break;
          }
-        
+
         default:
             break;
     }
@@ -619,12 +619,12 @@ void hidd_le_create_service(esp_gatt_if_t gatts_if)
     /* Here should added the battery service first, because the hid service should include the battery service.
        After finish to added the battery service then can added the hid service. */
     esp_ble_gatts_create_attr_tab(bas_att_db, gatts_if, BAS_IDX_NB, 0);
-   
+
 }
 
 void hidd_le_init(void)
-{ 
-    
+{
+
     // Reset the hid device target environment
     memset(&hidd_le_env, 0, sizeof(hidd_le_env_t));
 }
@@ -655,7 +655,7 @@ bool hidd_clcb_dealloc (uint16_t conn_id)
             memset(p_clcb, 0, sizeof(hidd_clcb_t));
             return true;
     }
-    
+
     return false;
 }
 
@@ -669,7 +669,7 @@ esp_err_t hidd_register_cb(void)
 void hidd_set_attr_value(uint16_t handle, uint16_t val_len, const uint8_t *value)
 {
     hidd_inst_t *hidd_inst = &hidd_le_env.hidd_inst;
-    if(hidd_inst->att_tbl[HIDD_LE_IDX_HID_INFO_VAL] <= handle && 
+    if(hidd_inst->att_tbl[HIDD_LE_IDX_HID_INFO_VAL] <= handle &&
         hidd_inst->att_tbl[HIDD_LE_IDX_REPORT_REP_REF] >= handle) {
         esp_ble_gatts_set_attr_value(handle, val_len, value);
     } else {
@@ -681,7 +681,7 @@ void hidd_set_attr_value(uint16_t handle, uint16_t val_len, const uint8_t *value
 void hidd_get_attr_value(uint16_t handle, uint16_t *length, uint8_t **value)
 {
     hidd_inst_t *hidd_inst = &hidd_le_env.hidd_inst;
-    if(hidd_inst->att_tbl[HIDD_LE_IDX_HID_INFO_VAL] <= handle && 
+    if(hidd_inst->att_tbl[HIDD_LE_IDX_HID_INFO_VAL] <= handle &&
         hidd_inst->att_tbl[HIDD_LE_IDX_REPORT_REP_REF] >= handle){
         esp_ble_gatts_get_attr_value(handle, length, (const uint8_t **)value);
     } else {
@@ -699,28 +699,28 @@ static void hid_add_id_tbl(void)
       hid_rpt_map[0].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_MOUSE_IN_VAL];
       hid_rpt_map[0].cccdHandle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_MOUSE_IN_VAL];
       hid_rpt_map[0].mode = HID_PROTOCOL_MODE_REPORT;
-     
+
       // Key input report
       hid_rpt_map[1].id = hidReportRefKeyIn[0];
       hid_rpt_map[1].type = hidReportRefKeyIn[1];
       hid_rpt_map[1].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_KEY_IN_VAL];
       hid_rpt_map[1].cccdHandle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_KEY_IN_CCC];
       hid_rpt_map[1].mode = HID_PROTOCOL_MODE_REPORT;
-     
+
       // Consumer Control input report
       hid_rpt_map[2].id = hidReportRefCCIn[0];
       hid_rpt_map[2].type = hidReportRefCCIn[1];
       hid_rpt_map[2].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_CC_IN_VAL];
       hid_rpt_map[2].cccdHandle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_CC_IN_CCC];
       hid_rpt_map[2].mode = HID_PROTOCOL_MODE_REPORT;
-     
+
       // LED output report
       hid_rpt_map[3].id = hidReportRefLedOut[0];
       hid_rpt_map[3].type = hidReportRefLedOut[1];
       hid_rpt_map[3].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_LED_OUT_VAL];
       hid_rpt_map[3].cccdHandle = 0;
       hid_rpt_map[3].mode = HID_PROTOCOL_MODE_REPORT;
-     
+
       // Boot keyboard input report
       // Use same ID and type as key input report
       hid_rpt_map[4].id = hidReportRefKeyIn[0];
@@ -728,7 +728,7 @@ static void hid_add_id_tbl(void)
       hid_rpt_map[4].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_BOOT_KB_IN_REPORT_VAL];
       hid_rpt_map[4].cccdHandle = 0;
       hid_rpt_map[4].mode = HID_PROTOCOL_MODE_BOOT;
-     
+
       // Boot keyboard output report
       // Use same ID and type as LED output report
       hid_rpt_map[5].id = hidReportRefLedOut[0];
@@ -736,7 +736,7 @@ static void hid_add_id_tbl(void)
       hid_rpt_map[5].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_BOOT_KB_OUT_REPORT_VAL];
       hid_rpt_map[5].cccdHandle = 0;
       hid_rpt_map[5].mode = HID_PROTOCOL_MODE_BOOT;
-     
+
       // Boot mouse input report
       // Use same ID and type as mouse input report
       hid_rpt_map[6].id = hidReportRefMouseIn[0];
@@ -744,7 +744,7 @@ static void hid_add_id_tbl(void)
       hid_rpt_map[6].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_BOOT_MOUSE_IN_REPORT_VAL];
       hid_rpt_map[6].cccdHandle = 0;
       hid_rpt_map[6].mode = HID_PROTOCOL_MODE_BOOT;
-     
+
       // Feature report
       hid_rpt_map[7].id = hidReportRefFeature[0];
       hid_rpt_map[7].type = hidReportRefFeature[1];