]> granicus.if.org Git - esp-idf/commitdiff
component/bt: rebase the btdm_updata_param_bug_#9626 to the new master.
authorYulong <huangyulong@espressif.com>
Fri, 2 Jun 2017 05:09:23 +0000 (01:09 -0400)
committerYulong <huangyulong@espressif.com>
Tue, 6 Jun 2017 09:51:31 +0000 (05:51 -0400)
- Added the error code for the time out status.

20 files changed:
components/bt/bluedroid/api/include/esp_bt_defs.h
components/bt/bluedroid/api/include/esp_gap_ble_api.h
components/bt/bluedroid/bta/dm/bta_dm_act.c
components/bt/bluedroid/bta/dm/bta_dm_api.c
components/bt/bluedroid/bta/dm/bta_dm_int.h
components/bt/bluedroid/bta/gatt/bta_gatts_act.c
components/bt/bluedroid/bta/include/bta_api.h
components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
components/bt/bluedroid/include/bt_defs.h
components/bt/bluedroid/stack/btu/btu_hcif.c
components/bt/bluedroid/stack/btu/btu_task.c
components/bt/bluedroid/stack/include/btm_api.h
components/bt/bluedroid/stack/include/btm_int.h
components/bt/bluedroid/stack/include/btu.h
components/bt/bluedroid/stack/l2cap/include/l2c_int.h
components/bt/bluedroid/stack/l2cap/l2c_ble.c
components/bt/bluedroid/stack/l2cap/l2c_main.c
components/bt/bluedroid/stack/l2cap/l2c_utils.c
components/bt/bluedroid/stack/smp/smp_l2c.c
examples/bluetooth/gatt_server/main/gatts_demo.c

index 2b82ec9ca2300a43ddafc370a381199731077573..1aa58f6e1261c837ecc0843d30855900e74a5585 100644 (file)
@@ -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;
 
 
index c0d22091979ba7a4dae3ed2fa1efb353b83537a5..abd3057d8d7817a5d4f9f83e31e0640ace498094 100644 (file)
@@ -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;
 
 /**
index a3e5cf3d43210632bb0c921c561828684e54a0b4..362531794271a8172403e8b5c9eb34894940a655 100644 (file)
@@ -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,
index 0ae3af50a1171c9bbab6872c51f88639c665a535..bf6a9e5d76c2fd4ef4453f20275338e13eecdb06 100644 (file)
@@ -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);
     }
 }
index adb5fc033d59be1b54bf4112f693c21d069a131c..1e6cfe34356d55b8ef04ac7fecc74f882ccc0989 100644 (file)
@@ -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
index 6d75b864a0882ab664908220f1d3c404232d7404..65cec00e6a4b56cb9ab6abce993d71675715191f 100644 (file)
@@ -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) {
index 0c6baa92d51633771c1566418c576ed856b464e6..d68263b8c0ce015f0edd622d317d89048f421330 100644 (file)
@@ -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);
 
 /*******************************************************************************
 **
index 027e8d4acdb5dc49ab9e38a83639e248c6cd29dc..a743bccc2567c7eeadc6af8ca50ca08307520239 100644 (file)
@@ -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, &param,
+                               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);
index 428f771a9b201fdf1a0ee7c58316b7a3f611b369..5d0dd3d9c02d222f94abb2aa9b50d72975005523 100644 (file)
@@ -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
index d39008e848f5464632c2d61474bd33f5e658a607..9f289280751552ce1569867d1bf9835ccd610c3c 100644 (file)
@@ -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)
index feaa50faf8cfcca6ae4d67bc0e4c47b7e72409ef..9e02627de260b8043fe2a778b264322d83666090 100644 (file)
@@ -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)
index af0d8df21fff3b29a218bcb42fc097f5958c599d..86bcf0245e385c5c9077112841c10175a0a1b7b9 100644 (file)
@@ -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
 *****************************************************************************/
index c732edd1aeba5e0cfd9f03d356c3b370ca355220..ca409ced8cc266eafa282b93f6e20deee66bdbdb 100644 (file)
@@ -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;
index d82d96d79e28ca3169d6624a423ef11e2540b0fa..2427dd2f5179b116fe3f597e08e4927b568f1e97 100644 (file)
@@ -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
 
index 56fdd0c943be50b981ee64f88d01e88861752926..b88659172dc73dff4bb1bcb714ac83de2dc792c7 100644 (file)
 #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);
 
index bb3a4c5866d45af3a4869546204661e81fa8c8d0..a50efc8ed2ddc3d2cc4d86c80d74845841ce9a6b 100644 (file)
@@ -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) */
index 3c5e4d1495fd2a14ddeb95ce2b9f9ee863c9aee9..3ed8a0d002bdcb854adb0db72afa151806dd0927 100644 (file)
@@ -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;
+    }
     }
 }
 
index eb5490bd2985870651a00c183fb87387e3fbb4d2..042387964db1592ca2821d75953768075d362558 100644 (file)
@@ -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;
index 007c9ccb7b685d39c5c3fea73ad37140184ac600..452b84edcd839e2ed3b979706bba976ae591b0d3 100644 (file)
@@ -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;
     }
index 8bcbde7a03d9b6425a3dabcda2bc49aa1f7571f1..2fa1f65da0741adb8cb3b7d70119d39f1417c0ef 100644 (file)
@@ -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;