From e6acc32df6ad5e24b2237f46952febd871dd2cbe Mon Sep 17 00:00:00 2001 From: Yulong Date: Fri, 2 Jun 2017 01:09:23 -0400 Subject: [PATCH] component/bt: rebase the btdm_updata_param_bug_#9626 to the new master. - Added the error code for the time out status. --- .../bt/bluedroid/api/include/esp_bt_defs.h | 4 ++ .../bluedroid/api/include/esp_gap_ble_api.h | 14 ++++ components/bt/bluedroid/bta/dm/bta_dm_act.c | 7 ++ components/bt/bluedroid/bta/dm/bta_dm_api.c | 4 +- components/bt/bluedroid/bta/dm/bta_dm_int.h | 1 + .../bt/bluedroid/bta/gatt/bta_gatts_act.c | 6 +- components/bt/bluedroid/bta/include/bta_api.h | 6 +- .../btc/profile/std/gap/btc_gap_ble.c | 64 ++++++++++++++++- components/bt/bluedroid/include/bt_defs.h | 4 ++ components/bt/bluedroid/stack/btu/btu_hcif.c | 10 ++- components/bt/bluedroid/stack/btu/btu_task.c | 1 + .../bt/bluedroid/stack/include/btm_api.h | 11 +++ .../bt/bluedroid/stack/include/btm_int.h | 2 +- components/bt/bluedroid/stack/include/btu.h | 2 + .../bluedroid/stack/l2cap/include/l2c_int.h | 11 ++- components/bt/bluedroid/stack/l2cap/l2c_ble.c | 70 +++++++++++++++++-- .../bt/bluedroid/stack/l2cap/l2c_main.c | 5 ++ .../bt/bluedroid/stack/l2cap/l2c_utils.c | 1 + components/bt/bluedroid/stack/smp/smp_l2c.c | 2 +- .../bluetooth/gatt_server/main/gatts_demo.c | 20 +++++- 20 files changed, 223 insertions(+), 22 deletions(-) diff --git a/components/bt/bluedroid/api/include/esp_bt_defs.h b/components/bt/bluedroid/api/include/esp_bt_defs.h index 2b82ec9ca2..1aa58f6e12 100644 --- a/components/bt/bluedroid/api/include/esp_bt_defs.h +++ b/components/bt/bluedroid/api/include/esp_bt_defs.h @@ -38,6 +38,10 @@ typedef enum { ESP_BT_STATUS_RMT_DEV_DOWN = 10, /* relate to BT_STATUS_RMT_DEV_DOWN in bt_def.h */ ESP_BT_STATUS_AUTH_REJECTED, /* relate to BT_STATUS_AUTH_REJECTED in bt_def.h */ ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR, /* relate to BT_STATUS_INVALID_STATIC_RAND_ADDR in bt_def.h */ + ESP_BT_STATUS_PENDING, /* relate to BT_STATUS_PENDING in bt_def.h */ + ESP_BT_STATUS_UNACCEPT_CONN_INTERVAL, /* relate to BT_UNACCEPT_CONN_INTERVAL in bt_def.h */ + ESP_BT_STATUS_PARAM_OUT_OF_RANGE, /* relate to BT_PARAM_OUT_OF_RANGE in bt_def.h */ + ESP_BT_STATUS_TIMEOUT, /* relate to BT_STATUS_TIMEOUT in bt_def.h */ } esp_bt_status_t; diff --git a/components/bt/bluedroid/api/include/esp_gap_ble_api.h b/components/bt/bluedroid/api/include/esp_gap_ble_api.h index c0d2209197..abd3057d8d 100644 --- a/components/bt/bluedroid/api/include/esp_gap_ble_api.h +++ b/components/bt/bluedroid/api/include/esp_gap_ble_api.h @@ -91,6 +91,7 @@ typedef enum { ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT, /*!< When stop adv complete, the event comes */ ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, /*!< When stop scan complete, the event comes */ ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, /*!< When set the static rand address complete, the event comes */ + ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, /*!< When update connection parameters complete, the event comes */ } esp_gap_ble_cb_event_t; /// Advertising data maximum length @@ -508,6 +509,19 @@ typedef union { struct ble_set_rand_cmpl_evt_param { esp_bt_status_t status; /*!< Indicate set static rand address operation success status */ } set_rand_addr_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT */ + /** + * @brief ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT + */ + struct ble_update_conn_params_evt_param { + esp_bt_status_t status; /*!< Indicate update connection parameters success status */ + esp_bd_addr_t bda; /*!< Bluetooth device address */ + uint16_t min_int; /*!< Min connection interval */ + uint16_t max_int; /*!< Max connection interval */ + uint16_t latency; /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */ + uint16_t conn_int; /*!< Current connection interval */ + uint16_t timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80. + Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec */ + }update_conn_params; /*!< Event parameter of ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT */ } esp_ble_gap_cb_param_t; /** diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index a3e5cf3d43..3625317942 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4514,6 +4514,13 @@ void bta_dm_ble_set_conn_scan_params (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_update_conn_params (tBTA_DM_MSG *p_data) { + tACL_CONN *p_acl_cb = btm_bda_to_acl(p_data->ble_update_conn_params.bd_addr, BT_TRANSPORT_LE); + if (p_acl_cb == NULL) { + APPL_TRACE_ERROR("%s error: Invalid connection bd_addr.", __func__); + return; + } else { + p_acl_cb->update_conn_param_cb = p_data->ble_update_conn_params.update_conn_param_cb; + } if (!L2CA_UpdateBleConnParams(p_data->ble_update_conn_params.bd_addr, p_data->ble_update_conn_params.min_int, p_data->ble_update_conn_params.max_int, diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 0ae3af50a1..bf6a9e5d76 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -1991,7 +1991,7 @@ void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cb ** *******************************************************************************/ void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int, - UINT16 latency, UINT16 timeout) + UINT16 latency, UINT16 timeout, tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb) { tBTA_DM_API_UPDATE_CONN_PARAM *p_msg; @@ -2004,7 +2004,7 @@ void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max p_msg->max_int = max_int; p_msg->latency = latency; p_msg->timeout = timeout; - + p_msg->update_conn_param_cb = update_conn_param_cb; bta_sys_sendmsg(p_msg); } } diff --git a/components/bt/bluedroid/bta/dm/bta_dm_int.h b/components/bt/bluedroid/bta/dm/bta_dm_int.h index adb5fc033d..1e6cfe3435 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/bta_dm_int.h @@ -637,6 +637,7 @@ typedef struct { UINT16 max_int; UINT16 latency; UINT16 timeout; + tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb; } tBTA_DM_API_UPDATE_CONN_PARAM; #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE diff --git a/components/bt/bluedroid/bta/gatt/bta_gatts_act.c b/components/bt/bluedroid/bta/gatt/bta_gatts_act.c index 6d75b864a0..65cec00e6a 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gatts_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gatts_act.c @@ -503,7 +503,7 @@ void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg) { tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; - UINT16 attr_id = 0; + UINT16 service_id = p_srvc_cb->service_id; tBTA_GATTS cb_data; tBTA_GATT_STATUS gatts_status; gatts_status = GATTS_SetAttributeValue(p_msg->api_add_char_descr.hdr.layer_specific, @@ -511,8 +511,8 @@ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_ p_msg->api_set_val.value); cb_data.attr_val.server_if = p_rcb->gatt_if; - cb_data.attr_val.service_id = p_msg->api_set_val.hdr.layer_specific; - cb_data.attr_val.attr_id = attr_id; + cb_data.attr_val.service_id = service_id; + cb_data.attr_val.attr_id = p_msg->api_set_val.hdr.layer_specific; cb_data.attr_val.status = gatts_status; if (p_rcb->p_cback) { diff --git a/components/bt/bluedroid/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index 0c6baa92d5..d68263b8c0 100644 --- a/components/bt/bluedroid/bta/include/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta_api.h @@ -718,6 +718,10 @@ typedef UINT8 tBTA_DM_BLE_CONN_TYPE; typedef BOOLEAN (tBTA_DM_BLE_SEL_CBACK)(BD_ADDR random_bda, UINT8 *p_remote_name); +typedef tBTM_LE_UPDATE_CONN_PRAMS tBTA_LE_UPDATE_CONN_PRAMS; +typedef tBTM_UPDATE_CONN_PARAM_CBACK tBTA_UPDATE_CONN_PARAM_CBACK; + + /* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */ typedef struct { BD_ADDR bd_addr; /* peer address */ @@ -2202,7 +2206,7 @@ extern void BTA_BleDisableAdvInstance(UINT8 inst_id); ** *******************************************************************************/ extern void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, - UINT16 max_int, UINT16 latency, UINT16 timeout); + UINT16 max_int, UINT16 latency, UINT16 timeout, tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb); /******************************************************************************* ** diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 027e8d4acd..a743bccc25 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -105,6 +105,33 @@ static void btc_cleanup_adv_data(tBTA_BLE_ADV_DATA *bta_adv_data) } +static esp_bt_status_t btc_hci_to_esp_status(uint8_t hci_status) +{ + esp_bt_status_t esp_status = ESP_BT_STATUS_FAIL; + switch(hci_status) { + case HCI_SUCCESS: + esp_status = ESP_BT_STATUS_SUCCESS; + break; + case HCI_ERR_HOST_TIMEOUT: + esp_status = ESP_BT_STATUS_TIMEOUT; + break; + case HCI_ERR_ILLEGAL_COMMAND: + esp_status = ESP_BT_STATUS_PENDING; + break; + case HCI_ERR_UNACCEPT_CONN_INTERVAL: + esp_status = ESP_BT_STATUS_UNACCEPT_CONN_INTERVAL; + break; + case HCI_ERR_PARAM_OUT_OF_RANGE: + esp_status = ESP_BT_STATUS_PARAM_OUT_OF_RANGE; + break; + default: + esp_status = ESP_BT_STATUS_FAIL; + break; + } + + return esp_status; +} + static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DATA *bta_adv_data, uint32_t *data_mask) { uint32_t mask; @@ -570,6 +597,31 @@ static void btc_stop_scan_callback(tBTA_STATUS status) } } +void btc_update_conn_param_callback (UINT8 status, BD_ADDR bd_addr, + tBTM_LE_UPDATE_CONN_PRAMS *update_conn_params) +{ + esp_ble_gap_cb_param_t param; + bt_status_t ret; + btc_msg_t msg; + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_GAP_BLE; + msg.act = ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT; + param.update_conn_params.status = btc_hci_to_esp_status(status); + param.update_conn_params.min_int = update_conn_params->min_conn_int; + param.update_conn_params.max_int = update_conn_params->max_conn_int; + param.update_conn_params.conn_int = update_conn_params->conn_int; + param.update_conn_params.latency = update_conn_params->slave_latency; + param.update_conn_params.timeout = update_conn_params->supervision_tout; + memcpy(param.update_conn_params.bda, bd_addr, sizeof(esp_bd_addr_t)); + ret = btc_transfer_context(&msg, ¶m, + sizeof(esp_ble_gap_cb_param_t), NULL); + + if (ret != BT_STATUS_SUCCESS) { + LOG_ERROR("%s btc_transfer_context failed\n", __func__); + } +} + + #if (SMP_INCLUDED == TRUE) static void btc_set_encryption_callback(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_STATUS enc_status) { @@ -607,7 +659,8 @@ static void btc_ble_stop_advertising(tBTA_START_STOP_ADV_CMPL_CBACK *stop_adv_cb } static void btc_ble_update_conn_params(BD_ADDR bd_addr, uint16_t min_int, - uint16_t max_int, uint16_t latency, uint16_t timeout) + uint16_t max_int, uint16_t latency, uint16_t timeout, + tBTA_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb) { if (min_int > max_int) { min_int = max_int; @@ -618,7 +671,7 @@ static void btc_ble_update_conn_params(BD_ADDR bd_addr, uint16_t min_int, } BTA_DmBleUpdateConnectionParams(bd_addr, min_int, max_int, - latency, timeout); + latency, timeout, update_conn_param_cb); } static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_length) @@ -733,6 +786,10 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg) break; case ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT: btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, param); + break; + case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: + btc_gap_ble_cb_to_app(ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, param); + break; default: break; @@ -883,7 +940,8 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) arg->conn_update_params.conn_params.min_int, arg->conn_update_params.conn_params.max_int, arg->conn_update_params.conn_params.latency, - arg->conn_update_params.conn_params.timeout); + arg->conn_update_params.conn_params.timeout, + btc_update_conn_param_callback); break; case BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN: btc_ble_set_pkt_data_len(arg->set_pkt_data_len.remote_device, arg->set_pkt_data_len.tx_data_length); diff --git a/components/bt/bluedroid/include/bt_defs.h b/components/bt/bluedroid/include/bt_defs.h index 428f771a9b..5d0dd3d9c0 100644 --- a/components/bt/bluedroid/include/bt_defs.h +++ b/components/bt/bluedroid/include/bt_defs.h @@ -90,6 +90,10 @@ typedef enum { BT_STATUS_RMT_DEV_DOWN, BT_STATUS_AUTH_REJECTED, BT_STATUS_INVALID_STATIC_RAND_ADDR, + BT_STATUS_PENDING, + BT_STATUS_UNACCEPT_CONN_INTERVAL, + BT_STATUS_PARAM_OUT_OF_RANGE, + BT_STATUS_TIMEOUT, } bt_status_t; #ifndef CPU_LITTLE_ENDIAN diff --git a/components/bt/bluedroid/stack/btu/btu_hcif.c b/components/bt/bluedroid/stack/btu/btu_hcif.c index d39008e848..9f28928075 100644 --- a/components/bt/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/bluedroid/stack/btu/btu_hcif.c @@ -1747,11 +1747,15 @@ static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len) /* We can enable the update request if the result is a success. */ /* extract the HCI handle first */ UINT8 status; - UINT16 handle; - + UINT16 handle, conn_interval, conn_latency, conn_timeout; STREAM_TO_UINT8 (status, p); STREAM_TO_UINT16 (handle, p); - l2cble_process_conn_update_evt(handle, status); + STREAM_TO_UINT16 (conn_interval, p); + STREAM_TO_UINT16 (conn_latency, p); + STREAM_TO_UINT16 (conn_timeout, p); + + l2cble_process_conn_update_evt(handle, status, conn_interval, + conn_latency, conn_timeout); } static void btu_ble_read_remote_feat_evt (UINT8 *p) diff --git a/components/bt/bluedroid/stack/btu/btu_task.c b/components/bt/bluedroid/stack/btu/btu_task.c index feaa50faf8..9e02627de2 100644 --- a/components/bt/bluedroid/stack/btu/btu_task.c +++ b/components/bt/bluedroid/stack/btu/btu_task.c @@ -418,6 +418,7 @@ static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle) case BTU_TTYPE_L2CAP_HOLD: case BTU_TTYPE_L2CAP_INFO: case BTU_TTYPE_L2CAP_FCR_ACK: + case BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS: l2c_process_timeout (p_tle); break; #if (defined(SDP_INCLUDED) && SDP_INCLUDED == TRUE) diff --git a/components/bt/bluedroid/stack/include/btm_api.h b/components/bt/bluedroid/stack/include/btm_api.h index af0d8df21f..86bcf0245e 100644 --- a/components/bt/bluedroid/stack/include/btm_api.h +++ b/components/bt/bluedroid/stack/include/btm_api.h @@ -129,6 +129,14 @@ enum { typedef UINT8 tBTM_DEV_STATUS; +typedef struct { + UINT16 min_conn_int; + UINT16 max_conn_int; + UINT16 conn_int; + UINT16 slave_latency; + UINT16 supervision_tout; +}tBTM_LE_UPDATE_CONN_PRAMS; + typedef void (tBTM_DEV_STATUS_CB) (tBTM_DEV_STATUS status); @@ -156,6 +164,9 @@ typedef void (tBTM_VSC_CMPL_CB) (tBTM_VSC_CMPL *p1); */ typedef UINT8 (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc); +typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM_LE_UPDATE_CONN_PRAMS *update_conn_params); + + /***************************************************************************** ** DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device *****************************************************************************/ diff --git a/components/bt/bluedroid/stack/include/btm_int.h b/components/bt/bluedroid/stack/include/btm_int.h index c732edd1ae..ca409ced8c 100644 --- a/components/bt/bluedroid/stack/include/btm_int.h +++ b/components/bt/bluedroid/stack/include/btm_int.h @@ -115,7 +115,7 @@ UINT8 conn_addr_type; /* local device address type for this co BD_ADDR active_remote_addr; /* remote address used on this connection */ UINT8 active_remote_addr_type; /* local device address type for this connection */ BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */ - +tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb; #endif } tACL_CONN; diff --git a/components/bt/bluedroid/stack/include/btu.h b/components/bt/bluedroid/stack/include/btu.h index d82d96d79e..2427dd2f51 100644 --- a/components/bt/bluedroid/stack/include/btu.h +++ b/components/bt/bluedroid/stack/include/btu.h @@ -143,6 +143,8 @@ typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr); /* eL2CAP Info Request and other proto cmds timer */ #define BTU_TTYPE_L2CAP_FCR_ACK 78 #define BTU_TTYPE_L2CAP_INFO 79 +/* L2CAP update connection parameters timer */ +#define BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS 80 #define BTU_TTYPE_MCA_CCB_RSP 98 diff --git a/components/bt/bluedroid/stack/l2cap/include/l2c_int.h b/components/bt/bluedroid/stack/l2cap/include/l2c_int.h index 56fdd0c943..b88659172d 100644 --- a/components/bt/bluedroid/stack/l2cap/include/l2c_int.h +++ b/components/bt/bluedroid/stack/l2cap/include/l2c_int.h @@ -53,9 +53,10 @@ #define L2CAP_DELAY_CHECK_SM4 2 /* 2 seconds */ #define L2CAP_WAIT_INFO_RSP_TOUT 3 /* 3 seconds */ #define L2CAP_WAIT_UNPARK_TOUT 2 /* 2 seconds */ -#define L2CAP_LINK_INFO_RESP_TOUT 2 /* 2 seconds */ +#define L2CAP_LINK_INFO_RESP_TOUT 2 /* 2 seconds */ +#define L2CAP_UPDATE_CONN_PARAM_TOUT 6 /* 6 seconds */ #define L2CAP_BLE_LINK_CONNECT_TOUT 30 /* 30 seconds */ -#define L2CAP_BLE_CONN_PARAM_UPD_TOUT 30 /* 30 seconds */ +#define L2CAP_BLE_CONN_PARAM_UPD_TOUT 30 /* 30 seconds */ /* quick timer uses millisecond unit */ #define L2CAP_DEFAULT_RETRANS_TOUT 2000 /* 2000 milliseconds */ @@ -353,6 +354,7 @@ typedef struct t_l2c_linkcb { tL2C_CCB *p_pending_ccb; /* ccb of waiting channel during link disconnect */ TIMER_LIST_ENT info_timer_entry; /* Timer entry for info resp timeout evt */ + TIMER_LIST_ENT upda_con_timer; /* Timer entry for update connection parametr */ BD_ADDR remote_bd_addr; /* The BD address of the remote */ UINT8 link_role; /* Master or slave */ @@ -404,6 +406,7 @@ typedef struct t_l2c_linkcb { UINT16 min_interval; /* parameters as requested by peripheral */ UINT16 max_interval; + UINT16 conn_int; UINT16 latency; UINT16 timeout; @@ -728,7 +731,8 @@ extern void l2cble_conn_comp (UINT16 handle, UINT8 role, BD_ADDR bda, tBLE_ADDR_ extern BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb); extern void l2cble_notify_le_connection (BD_ADDR bda); extern void l2c_ble_link_adjust_allocation (void); -extern void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status); +extern void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_interval, + UINT16 conn_latency, UINT16 conn_timeout); #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) extern void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, UINT16 int_max, @@ -738,6 +742,7 @@ extern void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, U extern void l2cble_update_data_length(tL2C_LCB *p_lcb); extern void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, UINT16 fix_cid, UINT16 tx_mtu); +extern void l2c_send_update_conn_params_cb(tL2C_LCB *p_lcb, UINT8 status); extern void l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len, UINT16 rx_data_len); diff --git a/components/bt/bluedroid/stack/l2cap/l2c_ble.c b/components/bt/bluedroid/stack/l2cap/l2c_ble.c index bb3a4c5866..a50efc8ed2 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_ble.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_ble.c @@ -463,8 +463,16 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb) { UINT16 min_conn_int, max_conn_int, slave_latency, supervision_tout; tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE); + UINT8 status; + btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT); if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) { + if (p_acl_cb != NULL && p_acl_cb->update_conn_param_cb != NULL) { + status = HCI_ERR_ILLEGAL_COMMAND; + L2CAP_TRACE_ERROR("%s, staus = %x", __func__, status); + btu_stop_timer(&p_lcb->upda_con_timer); + l2c_send_update_conn_params_cb(p_lcb, status); + } return; } @@ -495,6 +503,12 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb) } p_lcb->conn_update_mask &= ~L2C_BLE_NOT_DEFAULT_PARAM; p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; + } else { + status = HCI_ERR_ILLEGAL_COMMAND; + L2CAP_TRACE_DEBUG("%s, staus = %x", __func__, status); + btu_stop_timer(&p_lcb->upda_con_timer); + l2c_send_update_conn_params_cb(p_lcb, status); + return; } } else { /* application allows to do update, if we were delaying one do it now */ @@ -515,6 +529,12 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb) } p_lcb->conn_update_mask &= ~L2C_BLE_NEW_CONN_PARAM; p_lcb->conn_update_mask |= L2C_BLE_NOT_DEFAULT_PARAM; + } else { + status = HCI_ERR_ILLEGAL_COMMAND; + L2CAP_TRACE_DEBUG("%s, staus = %x", __func__, status); + btu_stop_timer(&p_lcb->upda_con_timer); + l2c_send_update_conn_params_cb(p_lcb, status); + return; } } } @@ -529,7 +549,8 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb) ** Returns void ** *******************************************************************************/ -void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status) +void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_interval, + UINT16 conn_latency, UINT16 conn_timeout) { tL2C_LCB *p_lcb; @@ -542,6 +563,7 @@ void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status) return; } + tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE); p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING; if (status != HCI_SUCCESS) { @@ -550,6 +572,13 @@ void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status) l2cble_start_conn_update(p_lcb); + btu_stop_timer (&p_lcb->timer_entry); + btu_stop_timer (&p_lcb->upda_con_timer); + + if (p_acl_cb->update_conn_param_cb != NULL) { + l2c_send_update_conn_params_cb(p_lcb, status); + } + L2CAP_TRACE_DEBUG("l2cble_process_conn_update_evt: conn_update_mask=%d", p_lcb->conn_update_mask); } /******************************************************************************* @@ -608,8 +637,11 @@ void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len) latency > BTM_BLE_CONN_LATENCY_MAX || /*(timeout >= max_interval && latency > (timeout * 10/(max_interval * 1.25) - 1)) ||*/ timeout < BTM_BLE_CONN_SUP_TOUT_MIN || timeout > BTM_BLE_CONN_SUP_TOUT_MAX || + timeout <= ((1 + latency)*BTM_BLE_CONN_INT_MAX*2) || max_interval < min_interval) { l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_UNACCEPTABLE_PARAMS, id); + UINT8 status = HCI_ERR_PARAM_OUT_OF_RANGE; + l2c_send_update_conn_params_cb(p_lcb, status); } else { l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_OK, id); @@ -627,10 +659,16 @@ void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len) } break; - case L2CAP_CMD_BLE_UPDATE_RSP: - p += 2; + case L2CAP_CMD_BLE_UPDATE_RSP: { + UINT16 result = 0; + STREAM_TO_UINT16(result, p); //result = 0 connection param accepted, result = 1 connection param rejected. + UINT8 status = (result == 0) ? HCI_SUCCESS : HCI_ERR_PARAM_OUT_OF_RANGE; + if (status != HCI_SUCCESS) { + btu_stop_timer(&p_lcb->upda_con_timer); + l2c_send_update_conn_params_cb(p_lcb, status); + } break; - + } default: L2CAP_TRACE_WARNING ("L2CAP - LE - unknown cmd code: %d", cmd_code); l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); @@ -1026,4 +1064,28 @@ void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, UINT16 fix_cid, l2cble_update_data_length(p_lcb); } + +/******************************************************************************* +** +** Function l2c_send_update_conn_params_cb +** +** Description This function send the update connection parameter callback to the uplayer. +** +** Returns void +** +*******************************************************************************/ +void l2c_send_update_conn_params_cb(tL2C_LCB *p_lcb, UINT8 status) +{ + tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE); + if (p_acl_cb != NULL && p_acl_cb->update_conn_param_cb != NULL) { + tBTM_LE_UPDATE_CONN_PRAMS update_param; + update_param.max_conn_int = p_lcb->max_interval; + update_param.min_conn_int = p_lcb->min_interval; + update_param.conn_int = p_lcb->conn_int; + update_param.slave_latency = p_lcb->latency; + update_param.supervision_tout = p_lcb->timeout; + (p_acl_cb->update_conn_param_cb)(status, p_acl_cb->active_remote_addr, &update_param); + } +} + #endif /* (BLE_INCLUDED == TRUE) */ diff --git a/components/bt/bluedroid/stack/l2cap/l2c_main.c b/components/bt/bluedroid/stack/l2cap/l2c_main.c index 3c5e4d1495..3ed8a0d002 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_main.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_main.c @@ -894,6 +894,11 @@ void l2c_process_timeout (TIMER_LIST_ENT *p_tle) case BTU_TTYPE_L2CAP_INFO: l2c_info_timeout((tL2C_LCB *)p_tle->param); break; + case BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS: { + UINT8 status = HCI_ERR_HOST_TIMEOUT; + l2c_send_update_conn_params_cb((tL2C_LCB *)p_tle->param, status); + break; + } } } diff --git a/components/bt/bluedroid/stack/l2cap/l2c_utils.c b/components/bt/bluedroid/stack/l2cap/l2c_utils.c index eb5490bd29..042387964d 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_utils.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_utils.c @@ -65,6 +65,7 @@ tL2C_LCB *l2cu_allocate_lcb (BD_ADDR p_bd_addr, BOOLEAN is_bonding, tBT_TRANSPOR p_lcb->link_flush_tout = 0xFFFF; p_lcb->timer_entry.param = (TIMER_PARAM_TYPE)p_lcb; p_lcb->info_timer_entry.param = (TIMER_PARAM_TYPE)p_lcb; + p_lcb->upda_con_timer.param = (TIMER_PARAM_TYPE)p_lcb; p_lcb->idle_timeout = l2cb.idle_timeout; p_lcb->id = 1; /* spec does not allow '0' */ p_lcb->is_bonding = is_bonding; diff --git a/components/bt/bluedroid/stack/smp/smp_l2c.c b/components/bt/bluedroid/stack/smp/smp_l2c.c index 007c9ccb7b..452b84edcd 100644 --- a/components/bt/bluedroid/stack/smp/smp_l2c.c +++ b/components/bt/bluedroid/stack/smp/smp_l2c.c @@ -239,7 +239,7 @@ static void smp_br_connect_callback(UINT16 channel, BD_ADDR bd_addr, BOOLEAN con SMP_TRACE_EVENT ("%s", __func__); if (transport != BT_TRANSPORT_BR_EDR) { - SMP_TRACE_WARNING("%s is called on unexpected transport %d\n", + SMP_TRACE_EVENT ("%s is called on unexpected transport %d\n", __func__, transport); return; } diff --git a/examples/bluetooth/gatt_server/main/gatts_demo.c b/examples/bluetooth/gatt_server/main/gatts_demo.c index 8bcbde7a03..2fa1f65da0 100644 --- a/examples/bluetooth/gatt_server/main/gatts_demo.c +++ b/examples/bluetooth/gatt_server/main/gatts_demo.c @@ -178,6 +178,15 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param ESP_LOGI(GATTS_TAG, "Stop adv successfully\n"); } break; + case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: + ESP_LOGI(GATTS_TAG, "update connetion params status = %d, min_int = %x, max_int = %x,\ + conn_int = %d,latency = %d, timeout = %d", param->update_conn_params.status, + param->update_conn_params.min_int, + param->update_conn_params.max_int, + param->update_conn_params.conn_int, + param->update_conn_params.latency, + param->update_conn_params.timeout); + break; default: break; } @@ -333,14 +342,23 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i break; case ESP_GATTS_STOP_EVT: break; - case ESP_GATTS_CONNECT_EVT: + case ESP_GATTS_CONNECT_EVT: { + esp_ble_conn_update_params_t conn_params = {0}; + memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t)); + conn_params.latency = 0; + conn_params.max_int = 0x50; // max_int = 0x50*1.25ms = 100ms + conn_params.min_int = 0x30; // min_int = 0x30*1.25ms = 60ms + 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\n", 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); 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); break; + } case ESP_GATTS_DISCONNECT_EVT: esp_ble_gap_start_advertising(&test_adv_params); break; -- 2.40.0