]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: add set local MTU API
authorzhiweijian <zhiweijian@espressif.com>
Thu, 24 Aug 2017 11:54:41 +0000 (19:54 +0800)
committerzhiweijian <zhiweijian@espressif.com>
Fri, 1 Sep 2017 13:55:28 +0000 (21:55 +0800)
- add esp_ble_gatt_set_local_mtu( ) API
- modify esp_ble_gattc_config_mtu(esp_gatt_if_t gattc_if, uint16_t conn_id)
- modify  gattc demo

24 files changed:
components/bt/bluedroid/api/esp_gatt_common_api.c [new file with mode: 0644]
components/bt/bluedroid/api/esp_gattc_api.c
components/bt/bluedroid/api/include/esp_gatt_common_api.h [new file with mode: 0644]
components/bt/bluedroid/api/include/esp_gattc_api.h
components/bt/bluedroid/bta/dm/bta_dm_main.c
components/bt/bluedroid/bta/gatt/bta_gatt_common.c [new file with mode: 0644]
components/bt/bluedroid/bta/gatt/bta_gattc_act.c
components/bt/bluedroid/bta/gatt/bta_gattc_api.c
components/bt/bluedroid/bta/include/bta_gatt_api.h
components/bt/bluedroid/bta/include/bta_gatt_common.h [new file with mode: 0644]
components/bt/bluedroid/bta/include/bta_gattc_int.h
components/bt/bluedroid/btc/core/btc_main.c
components/bt/bluedroid/btc/include/btc_main.h
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c
components/bt/bluedroid/btc/profile/std/include/btc_gattc.h
components/bt/bluedroid/stack/gatt/gatt_api.c
components/bt/bluedroid/stack/gatt/gatt_main.c
components/bt/bluedroid/stack/gatt/gatt_sr.c
components/bt/bluedroid/stack/gatt/include/gatt_int.h
components/bt/bluedroid/stack/include/gatt_api.h
examples/bluetooth/gatt_client/main/gattc_demo.c
examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c
examples/bluetooth/gatt_server/main/gatts_demo.c
examples/bluetooth/gattc_multi_connect/main/gattc_multi_connect.c

diff --git a/components/bt/bluedroid/api/esp_gatt_common_api.c b/components/bt/bluedroid/api/esp_gatt_common_api.c
new file mode 100644 (file)
index 0000000..e184325
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <string.h>
+#include "esp_gatt_common_api.h"
+#include "esp_bt_main.h"
+#include "esp_gatt_defs.h"
+#include "btc_main.h"
+
+/**
+ * @brief           This function is called to set local MTU,
+ *                  the function is called before BLE connection.
+ *
+ * @param[in]       mtu: the size of MTU.
+ *
+ * @return
+ *                  - ESP_OK: success
+ *                  - other: failed
+ *
+ */
+esp_err_t esp_ble_gatt_set_local_mtu (uint16_t mtu)
+{
+    btc_msg_t msg;
+    btc_ble_main_args_t arg;
+
+    ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
+
+    if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
+        return ESP_GATT_ILLEGAL_PARAMETER;
+    }
+
+    msg.sig = BTC_SIG_API_CALL;
+    msg.pid = BTC_PID_MAIN_INIT;
+    msg.act = BTC_GATT_ACT_SET_LOCAL_MTU;
+    arg.set_mtu.mtu = mtu;
+
+    return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_main_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
\ No newline at end of file
index b58c408f80b7309c45e616ff048ccb1a6f220c4f..75970ad3f121c26e740a6b927056abb595d9f43f 100644 (file)
@@ -99,22 +99,17 @@ esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id)
     return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
 }
 
-esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu)
+esp_err_t esp_ble_gattc_send_mtu_req (esp_gatt_if_t gattc_if, uint16_t conn_id)
 {
     btc_msg_t msg;
     btc_ble_gattc_args_t arg;
 
     ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
-    
-    if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
-        return ESP_GATT_ILLEGAL_PARAMETER;
-    }
 
     msg.sig = BTC_SIG_API_CALL;
     msg.pid = BTC_PID_GATTC;
     msg.act = BTC_GATTC_ACT_CFG_MTU;
     arg.cfg_mtu.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
-    arg.cfg_mtu.mtu = mtu;
 
     return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
 }
diff --git a/components/bt/bluedroid/api/include/esp_gatt_common_api.h b/components/bt/bluedroid/api/include/esp_gatt_common_api.h
new file mode 100644 (file)
index 0000000..33bc112
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "esp_err.h"
+#include "esp_bt_defs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Maximum Transmission Unit used in GATT
+#define ESP_GATT_DEF_BLE_MTU_SIZE   23   /* relate to GATT_DEF_BLE_MTU_SIZE in gatt_api.h */
+
+// Maximum Transmission Unit allowed in GATT
+#define ESP_GATT_MAX_MTU_SIZE       517  /* relate to GATT_MAX_MTU_SIZE in gatt_api.h */
+
+/**
+ * @brief           This function is called to set local MTU,
+ *                  the function is called before BLE connection.
+ *
+ * @param[in]       mtu: the size of MTU.
+ *
+ * @return
+ *                  - ESP_OK: success
+ *                  - other: failed
+ *
+ */
+extern esp_err_t esp_ble_gatt_set_local_mtu (uint16_t mtu);
+
+#ifdef __cplusplus
+}
+#endif
index f28736e3bcee1fdebd2db79b2986c11b34a41ecb..b950d438f087f0733e58d90a8e9f1ae0e5c68a2f 100644 (file)
@@ -68,11 +68,6 @@ typedef enum {
     ESP_GATTC_DISCONNECT_EVT          = 41,       /*!< When the ble physical connection disconnected, the event comes */
 } esp_gattc_cb_event_t;
 
-/// Maximum Transmission Unit used in GATT
-#define ESP_GATT_DEF_BLE_MTU_SIZE   23
-
-/// Maximum Transmission Unit allowed in GATT
-#define ESP_GATT_MAX_MTU_SIZE       517
 
 /**
  * @brief Gatt client callback parameters union
@@ -355,18 +350,19 @@ esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id);
 
 /**
  * @brief           Configure the MTU size in the GATT channel. This can be done
- *                  only once per connection.
+ *                  only once per connection. Before using, use esp_ble_gatt_set_local_mtu()
+ *                  to configure the local MTU size.
+ *
  *
  * @param[in]       gattc_if: Gatt client access interface.
  * @param[in]       conn_id: connection ID.
- * @param[in]       mtu: desired MTU size to use.
  *
  * @return
  *                  - ESP_OK: success
  *                  - other: failed
  *
  */
-esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu);
+esp_err_t esp_ble_gattc_send_mtu_req (esp_gatt_if_t gattc_if, uint16_t conn_id);
 
 
 /**
index 3d0b84ee65004789295443f289df490d81101583..2f01c248f56f5666ba0a3d3b1701e09564e26ef2 100644 (file)
@@ -53,7 +53,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
     bta_dm_set_visibility,                  /* 3  BTA_DM_API_SET_VISIBILITY_EVT */
     bta_dm_acl_change,                      /* 8  BTA_DM_ACL_CHANGE_EVT */
     bta_dm_add_device,                      /* 9  BTA_DM_API_ADD_DEVICE_EVT */
-    bta_dm_close_acl,                       /* 10  BTA_DM_API_ADD_DEVICE_EVT */
+    bta_dm_close_acl,                       /* 10  BTA_DM_API_REMOVE_ACL_EVT */
 #if (SMP_INCLUDED == TRUE)
     /* security API events */
     bta_dm_bond,                            /* 11  BTA_DM_API_BOND_EVT */
diff --git a/components/bt/bluedroid/bta/gatt/bta_gatt_common.c b/components/bt/bluedroid/bta/gatt/bta_gatt_common.c
new file mode 100644 (file)
index 0000000..3e4a0f7
--- /dev/null
@@ -0,0 +1,30 @@
+/******************************************************************************
+* Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains the action functions for gatts and gattc.
+ *
+ *
+ ******************************************************************************/
+
+#include "bta_gatt_common.h"
+#include "gatt_int.h"
+
+void BTA_GATT_SetLocalMTU(uint16_t mtu)
+{
+    gatt_set_local_mtu(mtu);
+}
\ No newline at end of file
index c8283936a08b229f6ac541c6f5e1d599444cfa66..2738b52ad0e1e2bba2d08617aa2d781d9fc82e5c 100644 (file)
@@ -901,7 +901,7 @@ void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
     tBTA_GATT_STATUS    status;
 
     if (bta_gattc_enqueue(p_clcb, p_data)) {
-        status = GATTC_ConfigureMTU (p_clcb->bta_conn_id, p_data->api_mtu.mtu);
+        status = GATTC_ConfigureMTU (p_clcb->bta_conn_id);
 
         /* if failed, return callback here */
         if (status != GATT_SUCCESS && status != GATT_CMD_STARTED) {
index bca1c080d798aeda4315dcd3b73bd56d764110bf..eaaf77cccfb1e43342e4129f8f8c932d81e4fb0b 100644 (file)
@@ -228,7 +228,7 @@ void BTA_GATTC_Close(UINT16 conn_id)
 ** Returns          void
 **
 *******************************************************************************/
-void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu)
+void BTA_GATTC_ConfigureMTU (UINT16 conn_id)
 {
     tBTA_GATTC_API_CFG_MTU  *p_buf;
 
@@ -236,8 +236,6 @@ void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu)
         p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT;
         p_buf->hdr.layer_specific = conn_id;
 
-        p_buf->mtu = mtu;
-
         bta_sys_sendmsg(p_buf);
     }
     return;
index e6dc5e8dbfcc9afe009685d3b18d966b1d7ab541..4b4945aa5e0e382a2eabdaf7b7e207064fd3afc5 100644 (file)
@@ -1157,12 +1157,12 @@ extern void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start);
 **                  only once per connection.
 **
 ** Parameters       conn_id: connection ID.
-**                  mtu: desired MTU size to use.
+**
 **
 ** Returns          void
 **
 *******************************************************************************/
-extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu);
+extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id);
 
 /*******************************************************************************
 **  BTA GATT Server API
diff --git a/components/bt/bluedroid/bta/include/bta_gatt_common.h b/components/bt/bluedroid/bta/include/bta_gatt_common.h
new file mode 100644 (file)
index 0000000..f6bc884
--- /dev/null
@@ -0,0 +1,36 @@
+/******************************************************************************
+* Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains the action functions for gatts and gattc.
+ *
+ *
+ ******************************************************************************/
+
+#include "bt_types.h"
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+extern void BTA_GATT_SetLocalMTU(uint16_t mtu);
+
+#ifdef __cplusplus
+}
+#endif
index 3b71438e81f3d4b5b8dbcce7fdb4e3f6d784a5af..6ea09ef8c1e5a8a4f8c06de0b278cfb62ef9c929 100644 (file)
@@ -184,7 +184,6 @@ typedef struct {
 
 typedef struct {
     BT_HDR              hdr;
-    UINT16              mtu;
 } tBTA_GATTC_API_CFG_MTU;
 
 typedef struct {
index 87892b8468ae19081a949794716bc77b481dcf6f..2317074c8e7194122fec9bfa7332f447d1fb6ee8 100644 (file)
@@ -20,6 +20,7 @@
 #include "btc_config.h"
 #include "alarm.h"
 #include "btc_ble_storage.h"
+#include "bta_gatt_common.h"
 
 static future_t *main_future[BTC_MAIN_FUTURE_NUM];
 
@@ -73,6 +74,11 @@ static void btc_deinit_bluetooth(void)
     future_ready(*btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE), FUTURE_SUCCESS);
 }
 
+static void btc_set_local_mtu(uint16_t mtu)
+{
+    BTA_GATT_SetLocalMTU(mtu);
+}
+
 void btc_main_call_handler(btc_msg_t *msg)
 {
     LOG_DEBUG("%s act %d\n", __func__, msg->act);
@@ -90,6 +96,12 @@ void btc_main_call_handler(btc_msg_t *msg)
     case BTC_MAIN_ACT_DISABLE:
         btc_disable_bluetooth();
         break;
+    case BTC_GATT_ACT_SET_LOCAL_MTU:
+    {
+        btc_ble_main_args_t *arg = (btc_ble_main_args_t *)(msg->arg);
+        btc_set_local_mtu(arg->set_mtu.mtu);
+        break;
+    }
     default:
         LOG_ERROR("%s UNKNOWN ACT %d\n", __func__, msg->act);
         break;
index b95ae0bbec205f63215e7d318d5c1346a3aa146f..523e1bb982993fb8264f1898be82ea90636b221b 100644 (file)
@@ -26,6 +26,7 @@ typedef enum {
     BTC_MAIN_ACT_DEINIT,
     BTC_MAIN_ACT_ENABLE,
     BTC_MAIN_ACT_DISABLE,
+    BTC_GATT_ACT_SET_LOCAL_MTU,
 } btc_main_act_t;
 
 typedef enum {
@@ -60,5 +61,13 @@ bt_status_t btc_init_bluetooth(future_t *future);
 void btc_deinit_bluetooth(future_t *future);
 #endif
 
+/* btc_ble_gattc_args_t */
+typedef union {
+    //BTC_GATT_ACT_SET_LOCAL_MTU,
+    struct set_mtu_arg {
+        uint16_t mtu;
+    } set_mtu;
+} btc_ble_main_args_t;
+
 void btc_main_call_handler(btc_msg_t *msg);
 #endif /* __BTC_BT_MAIN_H__ */
index 62d6ed4e0bde1a90af7913e103f10cd949e93eb7..67098e8bf6cc00bf0f5d71fb6e254a32e6a06873 100644 (file)
@@ -181,7 +181,7 @@ static void btc_gattc_close(btc_ble_gattc_args_t *arg)
 
 static void btc_gattc_cfg_mtu(btc_ble_gattc_args_t *arg)
 {
-    BTA_GATTC_ConfigureMTU (arg->cfg_mtu.conn_id, arg->cfg_mtu.mtu);
+    BTA_GATTC_ConfigureMTU (arg->cfg_mtu.conn_id);
 }
 
 static void btc_gattc_search_service(btc_ble_gattc_args_t *arg)
index 1374dc0a721a91458831eff616a101592a3b6c43..d1e0e9680d7aecb9732f87c2554eda599ce9f777 100644 (file)
@@ -68,7 +68,6 @@ typedef union {
     //BTC_GATTC_ACT_CFG_MTU,
     struct cfg_mtu_arg {
         uint16_t conn_id;
-        uint16_t mtu;
     } cfg_mtu;
     //BTC_GATTC_ACT_SEARCH_SERVICE,
     struct search_srvc_arg {
index f8fffc2e62c26b88861be35a3550e741e9432b55..1c9c6df0224f89f44209c6b509db28b95100c270 100644 (file)
@@ -791,7 +791,7 @@ tGATT_STATUS GATTS_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 *
 ** Returns          GATT_SUCCESS if command started successfully.
 **
 *******************************************************************************/
-tGATT_STATUS GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu)
+tGATT_STATUS GATTC_ConfigureMTU (UINT16 conn_id)
 {
     UINT8           ret = GATT_NO_RESOURCES;
     tGATT_IF        gatt_if = GATT_GET_GATT_IF(conn_id);
@@ -800,6 +800,7 @@ tGATT_STATUS GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu)
     tGATT_REG       *p_reg = gatt_get_regcb(gatt_if);
 
     tGATT_CLCB    *p_clcb;
+    uint16_t  mtu = gatt_get_local_mtu();
 
     GATT_TRACE_API ("GATTC_ConfigureMTU conn_id=%d mtu=%d", conn_id, mtu );
 
index bb226ba52d813d0f6af50f2e53a5320625d25e82..5ebd2ec0b532e620a73fee05d75110369c275abc 100644 (file)
@@ -79,6 +79,8 @@ static const tL2CAP_APPL_INFO dyn_info = {
 tGATT_CB  gatt_cb;
 #endif
 
+tGATT_DEFAULT gatt_default;
+
 /*******************************************************************************
 **
 ** Function         gatt_init
@@ -136,7 +138,8 @@ void gatt_init (void)
 #if (GATTS_INCLUDED == TRUE)
     gatt_profile_db_init();
 #endif  ///GATTS_INCLUDED == TRUE
-
+    //init local MTU size
+    gatt_default.local_mtu = GATT_MAX_MTU_SIZE;
 }
 
 
@@ -596,7 +599,7 @@ static void gatt_l2cif_connect_ind_cback (BD_ADDR  bd_addr, UINT16 lcid, UINT16
         /* Send L2CAP config req */
         memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO));
         cfg.mtu_present = TRUE;
-        cfg.mtu = GATT_MAX_MTU_SIZE;
+        cfg.mtu = gatt_default.local_mtu;
 
         L2CA_ConfigReq(lcid, &cfg);
     }
@@ -632,7 +635,7 @@ static void gatt_l2cif_connect_cfm_cback(UINT16 lcid, UINT16 result)
                 /* Send L2CAP config req */
                 memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO));
                 cfg.mtu_present = TRUE;
-                cfg.mtu = GATT_MAX_MTU_SIZE;
+                cfg.mtu = gatt_default.local_mtu;
                 L2CA_ConfigReq(lcid, &cfg);
             }
             /* else initiating connection failure */
@@ -1169,4 +1172,14 @@ tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB *p_tcb)
     return ch_state;
 }
 
+uint16_t gatt_get_local_mtu(void)
+{
+    return gatt_default.local_mtu;
+}
+
+void gatt_set_local_mtu(uint16_t mtu)
+{
+    gatt_default.local_mtu = mtu;
+}
+
 #endif /* BLE_INCLUDED */
index cf6055e8c153d68630144c7adb3f4a5911500899..08591334f46f0a42f3471dab828097b484f3605c 100644 (file)
@@ -941,14 +941,12 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data)
         /* mtu must be greater than default MTU which is 23/48 */
         if (mtu < GATT_DEF_BLE_MTU_SIZE) {
             p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE;
-        } else if (mtu > GATT_MAX_MTU_SIZE) {
-            p_tcb->payload_size = GATT_MAX_MTU_SIZE;
+        } else if (mtu > gatt_default.local_mtu) {
+            p_tcb->payload_size = gatt_default.local_mtu;
         } else {
             p_tcb->payload_size = mtu;
         }
 
-        GATT_TRACE_ERROR("MTU request PDU with MTU size %d\n", p_tcb->payload_size);
-
         l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size);
 
         if ((p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_MTU, (tGATT_SR_MSG *) &p_tcb->payload_size)) != NULL) {
index eee0d2858b01033915a889af5ed17d2df2ce8270..9d836597a21d2341bba68d05d0ab222ab27ef02d 100644 (file)
@@ -537,6 +537,9 @@ typedef struct {
 
 } tGATT_CB;
 
+typedef struct{
+    UINT16 local_mtu;
+} tGATT_DEFAULT;
 
 #define GATT_SIZE_OF_SRV_CHG_HNDL_RANGE 4
 
@@ -544,6 +547,8 @@ typedef struct {
 extern "C" {
 #endif
 
+extern tGATT_DEFAULT gatt_default;
+
 /* Global GATT data */
 #if GATT_DYNAMIC_MEMORY == FALSE
 extern tGATT_CB  gatt_cb;
@@ -741,4 +746,6 @@ extern void gatts_update_srv_list_elem(UINT8 i_sreg, UINT16 handle, BOOLEAN is_p
 extern tBT_UUID *gatts_get_service_uuid (tGATT_SVC_DB *p_db);
 
 extern void gatt_reset_bgdev_list(void);
+extern uint16_t gatt_get_local_mtu(void);
+extern void gatt_set_local_mtu(uint16_t mtu);
 #endif
index 76d8c4659a55c79644c3518484568b41c795f25e..946e5fee470eb2d6aaef882035ed89c4f5594f43 100644 (file)
@@ -943,7 +943,7 @@ tGATT_STATUS GATTS_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 *
 ** Returns          GATT_SUCCESS if command started successfully.
 **
 *******************************************************************************/
-extern tGATT_STATUS GATTC_ConfigureMTU (UINT16 conn_id, UINT16  mtu);
+extern tGATT_STATUS GATTC_ConfigureMTU (UINT16 conn_id);
 
 /*******************************************************************************
 **
index dc83d7f10697c5ca50ed5b52a5e60129ac70a4c0..76b809ede6832827ea87f21ef6b26389ae5b3826 100644 (file)
@@ -36,6 +36,7 @@
 #include "esp_gattc_api.h"
 #include "esp_gatt_defs.h"
 #include "esp_bt_main.h"
+#include "esp_gatt_common_api.h"
 
 #define GATTC_TAG "GATTC_DEMO"
 #define REMOTE_SERVICE_UUID        0x00FF
@@ -117,7 +118,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
             ESP_LOGE(GATTC_TAG, "set scan params error, error code = %x", scan_ret);
         }
         break;
-    case ESP_GATTC_CONNECT_EVT:
+    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", conn_id, gattc_if, p_data->connect.status);
         conn_id = p_data->connect.conn_id;
@@ -125,11 +126,12 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
         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:");
         esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
-        esp_err_t mtu_ret = esp_ble_gattc_config_mtu (gattc_if, conn_id, 200);
+        esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, conn_id);
         if (mtu_ret){
             ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
         }
         break;
+    }
     case ESP_GATTC_OPEN_EVT:
         if (param->open.status != ESP_GATT_OK){
             ESP_LOGE(GATTC_TAG, "open failed, status %d", p_data->open.status);
@@ -404,6 +406,10 @@ void app_main()
     if (ret){
         ESP_LOGE(GATTC_TAG, "%s gattc app register failed, error code = %x\n", __func__, ret);
     }
+    esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
+    if (local_mtu_ret){
+        ESP_LOGE(GATTC_TAG, "set local  MTU failed, error code = %x", local_mtu_ret);
+    }
 
 }
 
index aa2ce9dfe5d230a2b97d6e675be58dd0700e9319..2964602c962d3ae67a2c77ee14b24448d3beb004 100644 (file)
@@ -35,6 +35,7 @@
 #include "esp_gattc_api.h"
 #include "esp_gatt_defs.h"
 #include "esp_bt_main.h"
+#include "esp_gatt_common_api.h"
 
 #define GATTC_TAG             "SEC_GATTC_DEMO"
 #define REMOTE_SERVICE_UUID   0x1809
@@ -164,7 +165,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
         memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
         ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
         esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t));
-        esp_err_t mtu_ret = esp_ble_gattc_config_mtu (gattc_if, conn_id, 200);
+        esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, conn_id);
         if (mtu_ret){
             ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
         }
@@ -455,6 +456,10 @@ 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);
+    }
 
 }
 
index 2782c026d004266a4aef412d6e44358b2f218c41..edbe74394726c29e812d5beac6bcde0724ff0d3a 100644 (file)
@@ -38,6 +38,7 @@
 #include "esp_bt_defs.h"
 #include "esp_bt_main.h"
 #include "esp_bt_main.h"
+#include "esp_gatt_common_api.h"
 
 #include "sdkconfig.h"
 
@@ -722,6 +723,10 @@ void app_main()
         ESP_LOGE(GATTS_TAG, "gatts app register error, error code = %x", ret);
         return;
     }
+    esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
+    if (local_mtu_ret){
+        ESP_LOGE(GATTS_TAG, "set local  MTU failed, error code = %x", local_mtu_ret);
+    }
 
     return;
 }
index cc6a2db6941e391c897153145037e20d8d7fbff5..adeb070f544cc8fa07a068346ab72d424c4365ca 100644 (file)
@@ -39,6 +39,7 @@
 #include "esp_gattc_api.h"
 #include "esp_gatt_defs.h"
 #include "esp_bt_main.h"
+#include "esp_gatt_common_api.h"
 
 #define GATTC_TAG "GATTC_MULTIPLE_DEMO"
 #define REMOTE_SERVICE_UUID        0x00FF
@@ -166,7 +167,7 @@ static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
         ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", p_data->open.conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
         ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
         esp_log_buffer_hex(GATTC_TAG, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
-        esp_err_t mtu_ret = esp_ble_gattc_config_mtu (gattc_if, p_data->open.conn_id, 200);
+        esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, p_data->open.conn_id);
         if (mtu_ret){
             ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
         }
@@ -306,7 +307,7 @@ static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
         ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", p_data->open.conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
         ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
         esp_log_buffer_hex(GATTC_TAG, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
-        esp_err_t mtu_ret = esp_ble_gattc_config_mtu (gattc_if, p_data->open.conn_id, 200);
+        esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, p_data->open.conn_id);
         if (mtu_ret){
             ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
         }
@@ -439,7 +440,7 @@ static void gattc_profile_c_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
         ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", p_data->open.conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
         ESP_LOGI(GATTC_TAG, "REMOTE BDA:");
         esp_log_buffer_hex(GATTC_TAG, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
-        esp_err_t mtu_ret = esp_ble_gattc_config_mtu (gattc_if, p_data->open.conn_id, 200);
+        esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, p_data->open.conn_id);
         if (mtu_ret){
             ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret);
         }
@@ -748,6 +749,11 @@ void app_main()
         ESP_LOGE(GATTC_TAG, "gattc app register error, error code = %x", ret);
         return;
     }
+    ret = esp_ble_gatt_set_local_mtu(200);
+    if (ret){
+        ESP_LOGE(GATTC_TAG, "set local  MTU failed, error code = %x", ret);
+    }
+
 
 }