]> granicus.if.org Git - esp-idf/commitdiff
component/bt: fix adv stop event bug and add attribute table create
authorisland <island@espressif.com>
Sun, 7 May 2017 12:01:45 +0000 (20:01 +0800)
committerisland <island@espressif.com>
Mon, 8 May 2017 07:44:36 +0000 (15:44 +0800)
error

- Fix bug that advertising stop event produced while calling start_adv function
- Modify gatt server adv data and scan rsp data raw setting
- add create attribute table error msg
- Delete redundant printf in previous commits

12 files changed:
components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c
components/bt/bluedroid/btif/bta_dm_co.c
components/bt/bluedroid/main/bte_main.c
components/bt/bluedroid/stack/btm/btm_ble.c
components/bt/bluedroid/stack/btm/btm_ble_gap.c
components/bt/bluedroid/stack/btu/btu_hcif.c
components/bt/bluedroid/stack/gatt/gatt_attr.c
components/bt/bluedroid/stack/hcic/hciblecmds.c
components/bt/bluedroid/stack/l2cap/l2c_api.c
components/bt/bluedroid/stack/l2cap/l2c_ble.c
examples/bluetooth/gatt_server/main/gatts_demo.c
examples/bluetooth/gatt_server_service_table/main/gatts_table_creat_demo.c

index 7ca73435564c6b98a158ec141482bbfeebae27ee..7f63ad2cb6c6cf73bede958577b182737a154f52 100644 (file)
@@ -208,6 +208,19 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
     uint16_t uuid = 0;
     future_t *future_p;
     esp_ble_gatts_cb_param_t param;
+    param.add_attr_tab.status = ESP_GATT_OK;
+    param.add_attr_tab.num_handle = max_nb_attr;
+
+    // To add a large attribute table, need to enlarge BTC_TASK_QUEUE_NUM
+    if (max_nb_attr > BTC_TASK_QUEUE_NUM){
+        param.add_attr_tab.status = ESP_GATT_NO_RESOURCES;
+    }
+
+    if (param.add_attr_tab.status != ESP_GATT_OK){
+        btc_gatts_cb_to_app(ESP_GATTS_CREAT_ATTR_TAB_EVT, gatts_if, &param);
+        return;
+    }
+
 
     //set the attribute table create service flag to true
     btc_creat_tab_env.is_tab_creat_svc = true;
@@ -354,8 +367,6 @@ static void btc_gatts_act_create_attr_tab(esp_gatts_attr_db_t *gatts_attr_db,
         
     }
 
-    param.add_attr_tab.status = ESP_GATT_OK;
-    param.add_attr_tab.num_handle = max_nb_attr;
     param.add_attr_tab.handles = btc_creat_tab_env.handles;
     memcpy(&param.add_attr_tab.svc_uuid, &btc_creat_tab_env.svc_uuid, sizeof(esp_bt_uuid_t));
 
index 3c45d65ffe58bf9886a5180048f6c8cca9d0526a..d14123e823531dd9d3dc3993662343a5a0c724cb 100644 (file)
@@ -90,7 +90,7 @@ void bta_dm_co_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_o
 #endif
     btif_dm_proc_io_req(bd_addr, p_io_cap, p_oob_data, p_auth_req, is_orig);
 #else
-    LOG_ERROR("bta_dm_co_io_req: func not ported\n");
+    BTIF_TRACE_DEBUG("bta_dm_co_io_req: func not ported\n");
 #endif /* #if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE) */
     BTIF_TRACE_DEBUG("bta_dm_co_io_req *p_oob_data = %d", *p_oob_data);
     BTIF_TRACE_DEBUG("bta_dm_co_io_req *p_io_cap = %d", *p_io_cap);
@@ -119,7 +119,7 @@ void bta_dm_co_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
 #if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE)
     btif_dm_proc_io_rsp(bd_addr, io_cap, oob_data, auth_req);
 #else
-    LOG_ERROR("bta_dm_co_io_rsp: func not ported\n");
+    BTIF_TRACE_DEBUG("bta_dm_co_io_rsp: func not ported\n");
 #endif /* #if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE) */
 }
 
@@ -165,7 +165,7 @@ void bta_dm_co_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
     btif_dm_proc_loc_oob(valid, c, r);
 #endif
 #else
-    LOG_ERROR("bta_dm_co_loc_oob: func not ported\n");
+    BTIF_TRACE_DEBUG("bta_dm_co_loc_oob: func not ported\n");
 #endif /* #if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE) */
 }
 
@@ -192,7 +192,7 @@ void bta_dm_co_rmt_oob(BD_ADDR bd_addr)
 #if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE)
     result = btif_dm_proc_rmt_oob(bd_addr, p_c, p_r);
 #else
-    LOG_ERROR("bta_dm_rmt_oob: func not ported\n");
+    BTIF_TRACE_DEBUG("bta_dm_rmt_oob: func not ported\n");
 #endif /* #if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE) */
 #endif
 
@@ -370,9 +370,9 @@ void bta_dm_co_le_io_key_req(BD_ADDR bd_addr, UINT8 *p_max_key_size,
 {
     UNUSED(bd_addr);
 #if (SMP_INCLUDED == TRUE)
-    BTIF_TRACE_ERROR("##################################");
-    BTIF_TRACE_ERROR("bta_dm_co_le_io_key_req: only setting max size to 16");
-    BTIF_TRACE_ERROR("##################################");
+    BTIF_TRACE_DEBUG("##################################");
+    BTIF_TRACE_DEBUG("bta_dm_co_le_io_key_req: only setting max size to 16");
+    BTIF_TRACE_DEBUG("##################################");
     *p_max_key_size = 16;
     *p_init_key = *p_resp_key =
                       (BTA_LE_KEY_PENC | BTA_LE_KEY_PID | BTA_LE_KEY_PCSRK | BTA_LE_KEY_LENC | BTA_LE_KEY_LID | BTA_LE_KEY_LCSRK);
@@ -403,7 +403,7 @@ void bta_dm_co_ble_load_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OC
 #endif  ///defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE
 #if (SMP_INCLUDED == TRUE)
     btc_dm_get_ble_local_keys( p_key_mask, er, p_id_keys);
-    LOG_WARN("bta_dm_co_ble_load_local_keys: func not ported\n");
+    BTIF_TRACE_DEBUG("bta_dm_co_ble_load_local_keys: func not ported\n");
 #endif  ///SMP_INCLUDED == TRUE
 }
 
index 6221983688031ec3596e51b74fb455e75c8587b0..957580f0c1dea80d4dd3c72d77bf3871f864bad2 100644 (file)
@@ -201,7 +201,6 @@ static void bte_main_enable(void)
     }
 
     //Now Test Case Not Supported BTU
-    LOG_ERROR("Startup BTU\n");
     BTU_StartUp();
 }
 
index b7a47a5ed767f3bcd7e50bbb2aba362ed39fbca3..c2854708907bea9e897dba617ee785bca3420cf9 100644 (file)
@@ -1720,7 +1720,7 @@ void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len, BOOLEAN enhanced)
     STREAM_TO_UINT8    (role, p);
     STREAM_TO_UINT8    (bda_type, p);
     STREAM_TO_BDADDR   (bda, p);
-    BTM_TRACE_ERROR("status = %d, handle = %d, role = %d, bda_type = %d",status,handle,role,bda_type);
+    BTM_TRACE_DEBUG("status = %d, handle = %d, role = %d, bda_type = %d",status,handle,role,bda_type);
     if (status == 0) {
 #if (BLE_PRIVACY_SPT == TRUE )
         peer_addr_type = bda_type;
index 23daef539b3891998a11e43e593cb56af6ce0fe8..dfa3b068d47c70b61ad8b3f388b01c1ba4558f5f 100644 (file)
@@ -1352,7 +1352,7 @@ tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p
     p_cb_data->p_pad = p;
 
     if (mask != 0) {
-        BTM_TRACE_ERROR("Partial data write into ADV");
+        BTM_TRACE_DEBUG("Partial data write into ADV");
     }
 
     p_cb_data->data_mask &= ~mask;
index b0bca897e599d6659a00f8fac846f1bc3261dbdc..d39008e848f5464632c2d61474bd33f5e658a607 100644 (file)
@@ -326,7 +326,7 @@ void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg)
     case HCI_BLE_EVENT:
         STREAM_TO_UINT8  (ble_sub_code, p);
 
-        HCI_TRACE_ERROR("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code,  ble_sub_code);
+        HCI_TRACE_DEBUG("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code,  ble_sub_code);
 
         switch (ble_sub_code) {
         case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */
index 4d7a895edb00fb3810c1ccaaecdf8fd77cbeef72..fcd7db527ac5d04de81e573e68109e3fe16f1ad4 100644 (file)
@@ -296,7 +296,7 @@ void gatt_profile_db_init (void)
     GATT_StartIf(gatt_cb.gatt_if);
 
     service_handle = GATTS_CreateService (gatt_cb.gatt_if , &uuid, 0, GATTP_MAX_ATTR_NUM, TRUE);
-    GATT_TRACE_ERROR ("GATTS_CreateService:  handle of service handle%x", service_handle);
+    GATT_TRACE_DEBUG ("GATTS_CreateService:  handle of service handle%x", service_handle);
        
     /* add Service Changed characteristic
     */
index 3222ea5d71570f5d3d026506c051accf24a148c0..2c970f9b43edaf8ad25f110ca484bedde6579e38 100644 (file)
@@ -86,7 +86,6 @@ BOOLEAN btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max,
 {
     BT_HDR *p;
     UINT8 *pp;
-    HCI_TRACE_ERROR("####################adv_type = %d",adv_type);
     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS)) == NULL) {
         return (FALSE);
     }
index 1d2c1b047b21e16bc8d7f7b23415ed6530ee0817..3b3f18701c7bc7cef37fc4acd446c425286485a1 100644 (file)
@@ -1315,7 +1315,7 @@ UINT8 L2CA_GetChnlFcrMode (UINT16 lcid)
 *******************************************************************************/
 BOOLEAN  L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg)
 {
-    L2CAP_TRACE_ERROR ("L2CA_RegisterFixedChannel()  CID: 0x%04x, %p", fixed_cid,p_freg);
+    L2CAP_TRACE_DEBUG ("L2CA_RegisterFixedChannel()  CID: 0x%04x, %p", fixed_cid,p_freg);
     if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL) ) {
         L2CAP_TRACE_ERROR ("L2CA_RegisterFixedChannel()  Invalid CID: 0x%04x", fixed_cid);
 
index acdbd4fc868233abea5985dedddfac50cccc1b01..bb3a4c5866d45af3a4869546204661e81fa8c8d0 100644 (file)
@@ -767,7 +767,7 @@ void l2c_link_processs_ble_num_bufs (UINT16 num_lm_ble_bufs)
         num_lm_ble_bufs = L2C_DEF_NUM_BLE_BUF_SHARED;
         l2cb.num_lm_acl_bufs -= L2C_DEF_NUM_BLE_BUF_SHARED;
     }
-    L2CAP_TRACE_ERROR("#####################################num_lm_ble_bufs = %d",num_lm_ble_bufs);
+    L2CAP_TRACE_DEBUG("#####################################num_lm_ble_bufs = %d",num_lm_ble_bufs);
     l2cb.num_lm_ble_bufs = l2cb.controller_le_xmit_window = num_lm_ble_bufs;
 }
 
index 1715b65fc2d3f443eebb7ac1fa70e5769dfd14dc..f36206b798ee06bae4d4a4dcee41e0eb9df239bc 100644 (file)
@@ -63,12 +63,12 @@ esp_attr_value_t gatts_demo_char1_val =
 
 #ifdef CONFIG_SET_RAW_ADV_DATA
 static uint8_t raw_adv_data[] = {
-        0x02, 0x01, 0x06, 0x0f, 0x09, 0x45, 0x53, 0x50, 0x5f, 0x47, 0x41, 0x54, 0x54, 0x53, 0x5f, 0x44,
-        0x45, 0x4d, 0x4f, 0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd
+        0x02, 0x01, 0x06,
+        0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd
 };
 static uint8_t raw_scan_rsp_data[] = {
-        0x02, 0x01, 0x06, 0x0f, 0x09, 0x45, 0x53, 0x50, 0x5f, 0x47, 0x41, 0x54, 0x54, 0x53, 0x5f, 0x44,
-        0x45, 0x4d, 0x4f, 0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd
+        0x0f, 0x09, 0x45, 0x53, 0x50, 0x5f, 0x47, 0x41, 0x54, 0x54, 0x53, 0x5f, 0x44,
+        0x45, 0x4d, 0x4f
 };
 #else
 static uint8_t test_service_uuid128[32] = {
@@ -156,6 +156,7 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
         if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
             ESP_LOGE(GATTS_TAG, "Advertising start failed\n");
         }
+        break;
     case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
         if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
             ESP_LOGE(GATTS_TAG, "Advertising stop failed\n");
index c23bd6383cff8cdf4801e35821b0d51ac1c0e045..5cfe563b016d5861bd8ea548ffe3cb5604ba10b9 100644 (file)
@@ -263,16 +263,21 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
        case ESP_GATTS_CONGEST_EVT:
                break;
     case ESP_GATTS_CREAT_ATTR_TAB_EVT:{
-               ESP_LOGE(GATTS_TABLE_TAG, "The number handle =%x\n",param->add_attr_tab.num_handle);
-               if(param->add_attr_tab.num_handle == HRS_IDX_NB){                       
-                       memcpy(heart_rate_handle_table, param->add_attr_tab.handles, 
-                                       sizeof(heart_rate_handle_table));
-                       esp_ble_gatts_start_service(heart_rate_handle_table[HRS_IDX_SVC]);
-               }
+        ESP_LOGI(GATTS_TABLE_TAG, "The number handle =%x\n",param->add_attr_tab.num_handle);
+        if (param->add_attr_tab.status != ESP_GATT_OK){
+            ESP_LOGE(GATTS_TABLE_TAG, "Create attribute table failed, error code=0x%x", param->add_attr_tab.status);
+        }
+        else if (param->add_attr_tab.num_handle != HRS_IDX_NB){
+            ESP_LOGE(GATTS_TABLE_TAG, "Create attribute table abnormally, num_handle (%d) \
+                    doesn't equal to HRS_IDX_NB(%d)", param->add_attr_tab.num_handle, HRS_IDX_NB);
+        }
+        else {
+            memcpy(heart_rate_handle_table, param->add_attr_tab.handles, sizeof(heart_rate_handle_table));
+            esp_ble_gatts_start_service(heart_rate_handle_table[HRS_IDX_SVC]);
+        }
+        break;
+                                      }
 
-               break;
-       }
-               
     default:
         break;
     }