From 481e4365872f65f83494e92dbc1deb0510bfb9f2 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Mon, 16 Oct 2017 16:27:38 +0800 Subject: [PATCH] Component/bt: modify close event and disconnection event params - modify close event params - modify disconnection event params - modify connect event params --- components/bt/bluedroid/api/include/esp_gattc_api.h | 3 +-- components/bt/bluedroid/api/include/esp_gatts_api.h | 3 +-- components/bt/bluedroid/bta/gatt/bta_gattc_act.c | 5 ++--- components/bt/bluedroid/bta/gatt/bta_gattc_utils.c | 8 +++----- components/bt/bluedroid/bta/include/bta_gatt_api.h | 3 +-- components/bt/bluedroid/bta/include/bta_gattc_int.h | 5 ++--- .../bt/bluedroid/btc/profile/std/gatt/btc_gattc.c | 3 +-- .../bt/bluedroid/btc/profile/std/gatt/btc_gatts.c | 3 +-- .../bluetooth/ble_spp_client/main/spp_client_demo.c | 8 ++------ examples/bluetooth/gatt_client/main/gattc_demo.c | 5 ++--- .../main/example_ble_sec_gattc_demo.c | 2 +- examples/bluetooth/gatt_server/main/gatts_demo.c | 10 ++++------ 12 files changed, 21 insertions(+), 37 deletions(-) diff --git a/components/bt/bluedroid/api/include/esp_gattc_api.h b/components/bt/bluedroid/api/include/esp_gattc_api.h index b72466b82..6a6aa579c 100644 --- a/components/bt/bluedroid/api/include/esp_gattc_api.h +++ b/components/bt/bluedroid/api/include/esp_gattc_api.h @@ -201,7 +201,6 @@ typedef union { * @brief ESP_GATTC_CONNECT_EVT */ struct gattc_connect_evt_param { - esp_gatt_status_t status; /*!< Operation status */ uint16_t conn_id; /*!< Connection id */ esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ } connect; /*!< Gatt client callback param of ESP_GATTC_CONNECT_EVT */ @@ -210,7 +209,7 @@ typedef union { * @brief ESP_GATTC_DISCONNECT_EVT */ struct gattc_disconnect_evt_param { - esp_gatt_status_t status; /*!< Operation status */ + esp_gatt_conn_reason_t reason; /*!< disconnection reason */ uint16_t conn_id; /*!< Connection id */ esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ } disconnect; /*!< Gatt client callback param of ESP_GATTC_DISCONNECT_EVT */ diff --git a/components/bt/bluedroid/api/include/esp_gatts_api.h b/components/bt/bluedroid/api/include/esp_gatts_api.h index d964ac9b9..87869bb6f 100644 --- a/components/bt/bluedroid/api/include/esp_gatts_api.h +++ b/components/bt/bluedroid/api/include/esp_gatts_api.h @@ -193,7 +193,6 @@ typedef union { struct gatts_connect_evt_param { uint16_t conn_id; /*!< Connection id */ esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ - bool is_connected; /*!< Indicate it is connected or not */ } connect; /*!< Gatt server callback param of ESP_GATTS_CONNECT_EVT */ /** @@ -202,7 +201,7 @@ typedef union { struct gatts_disconnect_evt_param { uint16_t conn_id; /*!< Connection id */ esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ - bool is_connected; /*!< Indicate it is connected or not */ + esp_gatt_conn_reason_t reason; /*!< Indicate the reason of disconnection */ } disconnect; /*!< Gatt server callback param of ESP_GATTS_DISCONNECT_EVT */ /** diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index 25814059b..1a9306001 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -711,7 +711,6 @@ void bta_gattc_conncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data) { if (p_rcb) { bta_gattc_send_connect_cback(p_rcb, - BTA_GATT_OK, p_data->int_conn.remote_bda, p_data->int_conn.hdr.layer_specific); @@ -730,7 +729,7 @@ void bta_gattc_disconncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data) { if (p_rcb) { bta_gattc_send_disconnect_cback(p_rcb, - BTA_GATT_OK, + p_data->int_conn.reason, p_data->int_conn.remote_bda, p_data->int_conn.hdr.layer_specific); @@ -793,7 +792,7 @@ void bta_gattc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT) { cb_data.close.status = GATT_Disconnect(p_data->hdr.layer_specific); } else if (p_data->hdr.event == BTA_GATTC_INT_DISCONN_EVT) { - cb_data.close.status = p_data->int_conn.reason; + cb_data.close.status = BTA_GATT_OK; cb_data.close.reason = p_data->int_conn.reason; } diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c index dfa685f67..864a85fe8 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c @@ -653,15 +653,13 @@ void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status ** Returns ** *******************************************************************************/ -void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status, - BD_ADDR remote_bda, UINT16 conn_id) +void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id) { tBTA_GATTC cb_data; if (p_clreg->p_cback) { memset(&cb_data, 0, sizeof(tBTA_GATTC)); - cb_data.connect.status = status; cb_data.connect.client_if = p_clreg->client_if; cb_data.connect.conn_id = conn_id; bdcpy(cb_data.connect.remote_bda, remote_bda); @@ -679,7 +677,7 @@ void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS sta ** Returns ** *******************************************************************************/ -void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status, +void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REASON reason, BD_ADDR remote_bda, UINT16 conn_id) { tBTA_GATTC cb_data; @@ -687,7 +685,7 @@ void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS if (p_clreg->p_cback) { memset(&cb_data, 0, sizeof(tBTA_GATTC)); - cb_data.disconnect.status = status; + cb_data.disconnect.reason = reason; cb_data.disconnect.client_if = p_clreg->client_if; cb_data.disconnect.conn_id = conn_id; bdcpy(cb_data.disconnect.remote_bda, remote_bda); diff --git a/components/bt/bluedroid/bta/include/bta_gatt_api.h b/components/bt/bluedroid/bta/include/bta_gatt_api.h index 35fb42d71..6c17368f5 100644 --- a/components/bt/bluedroid/bta/include/bta_gatt_api.h +++ b/components/bt/bluedroid/bta/include/bta_gatt_api.h @@ -367,14 +367,13 @@ typedef struct { } tBTA_GATTC_ENC_CMPL_CB; typedef struct { - tBTA_GATT_STATUS status; UINT16 conn_id; tBTA_GATTC_IF client_if; BD_ADDR remote_bda; } tBTA_GATTC_CONNECT; typedef struct { - tBTA_GATT_STATUS status; + tGATT_DISCONN_REASON reason; UINT16 conn_id; tBTA_GATTC_IF client_if; BD_ADDR remote_bda; diff --git a/components/bt/bluedroid/bta/include/bta_gattc_int.h b/components/bt/bluedroid/bta/include/bta_gattc_int.h index 3a1e71915..f54c0fbee 100644 --- a/components/bt/bluedroid/bta/include/bta_gattc_int.h +++ b/components/bt/bluedroid/bta/include/bta_gattc_int.h @@ -438,9 +438,8 @@ extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB * extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data); extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status, BD_ADDR remote_bda, UINT16 conn_id, tBTA_TRANSPORT transport, UINT16 mtu); -extern void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status, - BD_ADDR remote_bda, UINT16 conn_id); -extern void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status, +extern void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id); +extern void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REASON reason, BD_ADDR remote_bda, UINT16 conn_id); extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); extern void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c index d3149bf85..5b33f0f77 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c @@ -858,7 +858,6 @@ void btc_gattc_cb_handler(btc_msg_t *msg) tBTA_GATTC_CONNECT *connect = &arg->connect; gattc_if = connect->client_if; - param.connect.status = connect->status; param.connect.conn_id = BTC_GATT_GET_CONN_ID(connect->conn_id); memcpy(param.connect.remote_bda, connect->remote_bda, sizeof(esp_bd_addr_t)); btc_gattc_cb_to_app(ESP_GATTC_CONNECT_EVT, gattc_if, ¶m); @@ -879,7 +878,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg) tBTA_GATTC_DISCONNECT *disconnect = &arg->disconnect; gattc_if = disconnect->client_if; - param.disconnect.status = disconnect->status; + param.disconnect.reason = disconnect->reason; param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(disconnect->conn_id); memcpy(param.disconnect.remote_bda, disconnect->remote_bda, sizeof(esp_bd_addr_t)); btc_gattc_cb_to_app(ESP_GATTC_DISCONNECT_EVT, gattc_if, ¶m); diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c index df2d74212..75c53b893 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c @@ -849,7 +849,6 @@ void btc_gatts_cb_handler(btc_msg_t *msg) case BTA_GATTS_CONNECT_EVT: gatts_if = p_data->conn.server_if; param.connect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id); - param.connect.is_connected = true; memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN); btc_gatts_cb_to_app(ESP_GATTS_CONNECT_EVT, gatts_if, ¶m); @@ -857,7 +856,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg) case BTA_GATTS_DISCONNECT_EVT: gatts_if = p_data->conn.server_if; param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id); - param.disconnect.is_connected = false; + param.disconnect.reason = p_data->conn.reason; memcpy(param.disconnect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN); btc_gatts_cb_to_app(ESP_GATTS_DISCONNECT_EVT, gatts_if, ¶m); diff --git a/examples/bluetooth/ble_spp_client/main/spp_client_demo.c b/examples/bluetooth/ble_spp_client/main/spp_client_demo.c index 7b570eaf4..9eadc13b7 100644 --- a/examples/bluetooth/ble_spp_client/main/spp_client_demo.c +++ b/examples/bluetooth/ble_spp_client/main/spp_client_demo.c @@ -698,21 +698,17 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ esp_ble_gap_set_scan_params(&ble_scan_params); break; case ESP_GATTC_CONNECT_EVT: - if(p_data->connect.status != ESP_GATT_OK){ - ESP_LOGI(GATTC_TAG, "connect fail, status = %d", p_data->connect.status); - break; - } spp_gattc_if = gattc_if; is_connect = true; spp_conn_id = p_data->connect.conn_id; memcpy(gl_profile_tab[PROFILE_APP_ID].remote_bda, p_data->connect.remote_bda, sizeof(esp_bd_addr_t)); - ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT: conn_id=%d, gatt_if = %d, status =%d", spp_conn_id, gattc_if, p_data->connect.status); + ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT: conn_id=%d, gatt_if = %d", spp_conn_id, gattc_if); ESP_LOGI(GATTC_TAG, "REMOTE BDA:"); esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_APP_ID].remote_bda, sizeof(esp_bd_addr_t)); esp_ble_gattc_search_service(gattc_if, spp_conn_id, NULL); break; case ESP_GATTC_DISCONNECT_EVT: - ESP_LOGI(GATTC_TAG, "disconnect , status = %d", p_data->disconnect.status); + ESP_LOGI(GATTC_TAG, "disconnect"); free_gattc_srv_db(); esp_ble_gap_start_scanning(0xffff); break; diff --git a/examples/bluetooth/gatt_client/main/gattc_demo.c b/examples/bluetooth/gatt_client/main/gattc_demo.c index 14290c2d8..a2be74da5 100644 --- a/examples/bluetooth/gatt_client/main/gattc_demo.c +++ b/examples/bluetooth/gatt_client/main/gattc_demo.c @@ -112,8 +112,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ } break; case ESP_GATTC_CONNECT_EVT:{ - //p_data->connect.status always be ESP_GATT_OK - ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT conn_id %d, if %d, status %d", p_data->connect.conn_id, gattc_if, p_data->connect.status); + ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT conn_id %d, if %d", p_data->connect.conn_id, gattc_if); gl_profile_tab[PROFILE_A_APP_ID].conn_id = p_data->connect.conn_id; memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->connect.remote_bda, sizeof(esp_bd_addr_t)); ESP_LOGI(GATTC_TAG, "REMOTE BDA:"); @@ -296,7 +295,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ case ESP_GATTC_DISCONNECT_EVT: connect = false; get_server = false; - ESP_LOGI(GATTC_TAG, "ESP_GATTC_DISCONNECT_EVT, status = %d", p_data->disconnect.status); + ESP_LOGI(GATTC_TAG, "ESP_GATTC_DISCONNECT_EVT, reason = %d", p_data->disconnect.reason); break; default: break; 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 6ae360e65..7838dd89d 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 @@ -306,7 +306,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ ESP_LOGI(GATTC_TAG, "Write char success "); break; case ESP_GATTC_DISCONNECT_EVT: - ESP_LOGI(GATTC_TAG, "ESP_GATTC_DISCONNECT_EVT, status = %d", p_data->disconnect.status); + ESP_LOGI(GATTC_TAG, "ESP_GATTC_DISCONNECT_EVT, reason = %d", p_data->disconnect.reason); connect = false; get_service = false; break; diff --git a/examples/bluetooth/gatt_server/main/gatts_demo.c b/examples/bluetooth/gatt_server/main/gatts_demo.c index a60d567c8..885702e9f 100644 --- a/examples/bluetooth/gatt_server/main/gatts_demo.c +++ b/examples/bluetooth/gatt_server/main/gatts_demo.c @@ -478,11 +478,10 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i conn_params.max_int = 0x20; // max_int = 0x20*1.25ms = 40ms conn_params.min_int = 0x10; // min_int = 0x10*1.25ms = 20ms conn_params.timeout = 400; // timeout = 400*10ms = 4000ms - ESP_LOGI(GATTS_TAG, "ESP_GATTS_CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d", + ESP_LOGI(GATTS_TAG, "ESP_GATTS_CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:", param->connect.conn_id, param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2], - param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5], - param->connect.is_connected); + param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5]); gl_profile_tab[PROFILE_A_APP_ID].conn_id = param->connect.conn_id; //start sent the update connection parameters to the peer device. esp_ble_gap_update_conn_params(&conn_params); @@ -624,11 +623,10 @@ static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_i case ESP_GATTS_STOP_EVT: break; case ESP_GATTS_CONNECT_EVT: - ESP_LOGI(GATTS_TAG, "CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d", + ESP_LOGI(GATTS_TAG, "CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:", param->connect.conn_id, param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2], - param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5], - param->connect.is_connected); + param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5]); gl_profile_tab[PROFILE_B_APP_ID].conn_id = param->connect.conn_id; break; case ESP_GATTS_DISCONNECT_EVT: