From 9a96187655b68c872e251523398c175f8731b6e4 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Thu, 2 Nov 2017 17:49:48 +0800 Subject: [PATCH] Component/bt: modify some log --- components/bt/bluedroid/bta/dm/bta_dm_act.c | 2 ++ components/bt/bluedroid/stack/smp/smp_cmac.c | 4 +-- .../main/example_ble_sec_gattc_demo.c | 33 +++++++++++++++++++ .../main/example_ble_sec_gatts_demo.c | 16 +++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index e599f00697..2d08011f4f 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4101,6 +4101,8 @@ void bta_dm_set_encryption (tBTA_DM_MSG *p_data) == BTM_CMD_STARTED) { bta_dm_cb.device_list.peer_device[i].p_encrypt_cback = p_data->set_encryption.p_callback; } + }else{ + APPL_TRACE_ERROR("%s, not find peer_bdaddr or peer_bdaddr connection state error", __func__); } } #endif ///SMP_INCLUDED == TRUE diff --git a/components/bt/bluedroid/stack/smp/smp_cmac.c b/components/bt/bluedroid/stack/smp/smp_cmac.c index 0eedb9a98b..e284b678f2 100644 --- a/components/bt/bluedroid/stack/smp/smp_cmac.c +++ b/components/bt/bluedroid/stack/smp/smp_cmac.c @@ -186,7 +186,7 @@ static void cmac_prepare_last_block (BT_OCTET16 k1, BT_OCTET16 k2) /* last block is a complete block set flag to 1 */ flag = ((cmac_cb.len % BT_OCTET16_LEN) == 0 && cmac_cb.len != 0) ? TRUE : FALSE; - SMP_TRACE_WARNING("flag = %d round = %d", flag, cmac_cb.round); + SMP_TRACE_DEBUG("flag = %d round = %d", flag, cmac_cb.round); if ( flag ) { /* last block is complete block */ @@ -291,7 +291,7 @@ BOOLEAN aes_cipher_msg_auth_code(BT_OCTET16 key, UINT8 *input, UINT16 length, } len = n * BT_OCTET16_LEN; - SMP_TRACE_WARNING("AES128_CMAC started, allocate buffer size = %d", len); + SMP_TRACE_DEBUG("AES128_CMAC started, allocate buffer size = %d", len); /* allocate a memory space of multiple of 16 bytes to hold text */ if ((cmac_cb.text = (UINT8 *)osi_malloc(len)) != NULL) { cmac_cb.round = n; diff --git a/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c b/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c index 7838dd89dd..463dfc8492 100644 --- a/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c +++ b/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c @@ -344,6 +344,22 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par } ESP_LOGI(GATTC_TAG, "Scan start success"); break; + case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */ + //esp_ble_passkey_reply(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, true, 0x00); + ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT"); + break; + case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */ + ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_OOB_REQ_EVT"); + break; + case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */ + ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT"); + break; + case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */ + ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_LOCAL_ER_EVT"); + break; + case ESP_GAP_BLE_NC_REQ_EVT: + ESP_LOGI(GATTC_TAG, "ESP_GAP_BLE_NC_REQ_EVT"); + break; case ESP_GAP_BLE_SEC_REQ_EVT: /* send the positive(true) security response to the peer device to accept the security request. If not accept the security request, should sent the security response with negative(false) accept value*/ @@ -495,10 +511,27 @@ void app_main() if (ret){ ESP_LOGE(GATTC_TAG, "%s gattc app register error, error code = %x\n", __func__, ret); } + ret = esp_ble_gatt_set_local_mtu(200); if (ret){ ESP_LOGE(GATTC_TAG, "set local MTU failed, error code = %x", ret); } + /* set the security iocap & auth_req & key size & init key response key parameters to the stack*/ + esp_ble_auth_req_t auth_req = ESP_LE_AUTH_BOND; //bonding with peer device after authentication + esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE; //set the IO capability to No output No input + uint8_t key_size = 16; //the key size should be 7~16 bytes + uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK; + uint8_t rsp_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK; + esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t)); + esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t)); + esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t)); + /* If your BLE device act as a Slave, the init_key means you hope which types of key of the master should distribut to you, + and the response key means which key you can distribut to the Master; + If your BLE device act as a master, the response key means you hope which types of key of the slave should distribut to you, + and the init key means which key you can distribut to the slave. */ + esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t)); + esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t)); + } diff --git a/examples/bluetooth/gatt_security_server/main/example_ble_sec_gatts_demo.c b/examples/bluetooth/gatt_security_server/main/example_ble_sec_gatts_demo.c index ce85c23aec..3a71974d49 100644 --- a/examples/bluetooth/gatt_security_server/main/example_ble_sec_gatts_demo.c +++ b/examples/bluetooth/gatt_security_server/main/example_ble_sec_gatts_demo.c @@ -287,6 +287,22 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param } ESP_LOGI(GATTS_TABLE_TAG, "advertising start success"); break; + case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */ + ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT"); + //esp_ble_passkey_reply(heart_rate_profile_tab[HEART_PROFILE_APP_IDX].remote_bda, true, 0x00); + break; + case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */ + ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_OOB_REQ_EVT"); + break; + case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */ + ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT"); + break; + case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */ + ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_LOCAL_ER_EVT"); + break; + case ESP_GAP_BLE_NC_REQ_EVT: + ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_NC_REQ_EVT"); + break; case ESP_GAP_BLE_SEC_REQ_EVT: /* send the positive(true) security response to the peer device to accept the security request. If not accept the security request, should sent the security response with negative(false) accept value*/