]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: modify set mtu call handler
authorzhiweijian <zhiweijian@espressif.com>
Thu, 25 Jan 2018 09:34:10 +0000 (17:34 +0800)
committerzhiweijian <zhiweijian@espressif.com>
Wed, 31 Jan 2018 03:28:05 +0000 (11:28 +0800)
components/bt/bluedroid/api/esp_gatt_common_api.c
components/bt/bluedroid/btc/core/btc_main.c
components/bt/bluedroid/btc/core/btc_task.c
components/bt/bluedroid/btc/include/btc_main.h
components/bt/bluedroid/btc/include/btc_task.h
components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_common.c [new file with mode: 0644]
components/bt/bluedroid/btc/profile/std/include/btc_gatt_common.h [new file with mode: 0644]

index 6d795c1c08e716cd7bd6912f0d2311ed77e6aa85..1146750c7c8e608edc873339366cda4211b2a778 100644 (file)
@@ -16,7 +16,7 @@
 #include "esp_gatt_common_api.h"
 #include "esp_bt_main.h"
 #include "esp_gatt_defs.h"
-#include "btc_main.h"
+#include "btc_gatt_common.h"
 
 /**
  * @brief           This function is called to set local MTU,
@@ -32,7 +32,7 @@
 esp_err_t esp_ble_gatt_set_local_mtu (uint16_t mtu)
 {
     btc_msg_t msg;
-    btc_ble_main_args_t arg;
+    btc_ble_gatt_com_args_t arg;
 
     ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
 
@@ -41,9 +41,9 @@ esp_err_t esp_ble_gatt_set_local_mtu (uint16_t mtu)
     }
 
     msg.sig = BTC_SIG_API_CALL;
-    msg.pid = BTC_PID_MAIN_INIT;
+    msg.pid = BTC_PID_GATT_COMMON;
     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);
+    return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatt_com_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
 }
\ No newline at end of file
index f37801e699edfc0db6024c5d6972f1f66781a2bc..cb5975be1f8178bc056fa8f9b35719b845b4e593 100644 (file)
@@ -20,7 +20,6 @@
 #include "btc_config.h"
 #include "alarm.h"
 #include "btc_ble_storage.h"
-#include "bta_gatt_common.h"
 #include "btc_gap_ble.h"
 #include "bta_gattc_int.h"
 #include "bta_gatts_int.h"
@@ -88,11 +87,6 @@ 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);
@@ -110,12 +104,6 @@ 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 2a1147296435cdb6b99186adef0f4f6c38630d7c..004b67f16b51d3bd780bbce49f5a121e14a72f23 100644 (file)
@@ -24,6 +24,7 @@
 #include "btc_dev.h"
 #include "btc_gatts.h"
 #include "btc_gattc.h"
+#include "btc_gatt_common.h"
 #include "btc_gap_ble.h"
 #include "btc_blufi_prf.h"
 #include "btc_dm.h"
@@ -48,33 +49,36 @@ static xTaskHandle  xBtcTaskHandle = NULL;
 static xQueueHandle xBtcQueue = 0;
 
 static btc_func_t profile_tab[BTC_PID_NUM] = {
-    [BTC_PID_MAIN_INIT] = {btc_main_call_handler,       NULL                    },
-    [BTC_PID_DEV]       = {btc_dev_call_handler,        NULL                    },
+    [BTC_PID_MAIN_INIT]   = {btc_main_call_handler,       NULL                    },
+    [BTC_PID_DEV]         = {btc_dev_call_handler,        NULL                    },
 #if (GATTS_INCLUDED == TRUE)
-    [BTC_PID_GATTS]     = {btc_gatts_call_handler,      btc_gatts_cb_handler    },
+    [BTC_PID_GATTS]       = {btc_gatts_call_handler,      btc_gatts_cb_handler    },
 #endif  ///GATTS_INCLUDED == TRUE
 #if (GATTC_INCLUDED == TRUE)
-    [BTC_PID_GATTC]     = {btc_gattc_call_handler,      btc_gattc_cb_handler    },
+    [BTC_PID_GATTC]       = {btc_gattc_call_handler,      btc_gattc_cb_handler    },
 #endif  ///GATTC_INCLUDED == TRUE
-    [BTC_PID_GAP_BLE]   = {btc_gap_ble_call_handler,    btc_gap_ble_cb_handler  },
-    [BTC_PID_BLE_HID]   = {NULL, NULL},
-    [BTC_PID_SPPLIKE]   = {NULL, NULL},
+#if (GATTS_INCLUDED == TRUE || GATTC_INCLUDED == TRUE)
+    [BTC_PID_GATT_COMMON] = {btc_gatt_com_call_handler,   NULL                    },
+#endif //GATTC_INCLUDED == TRUE || GATTS_INCLUDED == TRUE
+    [BTC_PID_GAP_BLE]     = {btc_gap_ble_call_handler,    btc_gap_ble_cb_handler  },
+    [BTC_PID_BLE_HID]     = {NULL, NULL},
+    [BTC_PID_SPPLIKE]     = {NULL, NULL},
 #if (GATTS_INCLUDED == TRUE)
-    [BTC_PID_BLUFI]     = {btc_blufi_call_handler,      btc_blufi_cb_handler    },
+    [BTC_PID_BLUFI]       = {btc_blufi_call_handler,      btc_blufi_cb_handler    },
 #endif  ///GATTS_INCLUDED == TRUE
-    [BTC_PID_DM_SEC]    = {NULL,                        btc_dm_sec_cb_handler   },
-    [BTC_PID_ALARM]     = {btc_alarm_handler,           NULL                    },
+    [BTC_PID_DM_SEC]      = {NULL,                        btc_dm_sec_cb_handler   },
+    [BTC_PID_ALARM]       = {btc_alarm_handler,           NULL                    },
 #if CONFIG_CLASSIC_BT_ENABLED
 #if (BTC_GAP_BT_INCLUDED == TRUE)
-    [BTC_PID_GAP_BT]    = {btc_gap_bt_call_handler,     NULL                    },
+    [BTC_PID_GAP_BT]      = {btc_gap_bt_call_handler,     NULL                    },
 #endif /* (BTC_GAP_BT_INCLUDED == TRUE) */
-    [BTC_PID_PRF_QUE]   = {btc_profile_queue_handler,   NULL                    },
+    [BTC_PID_PRF_QUE]     = {btc_profile_queue_handler,   NULL                    },
 #if BTC_AV_INCLUDED
-    [BTC_PID_A2DP]      = {btc_a2dp_call_handler,       btc_a2dp_cb_handler     },
-    [BTC_PID_AVRC]      = {btc_avrc_call_handler,       NULL                    },
+    [BTC_PID_A2DP]        = {btc_a2dp_call_handler,       btc_a2dp_cb_handler     },
+    [BTC_PID_AVRC]        = {btc_avrc_call_handler,       NULL                    },
 #endif /* #if BTC_AV_INCLUDED */
 #if CONFIG_BT_SPP_ENABLED
-    [BTC_PID_SPP]       = {btc_spp_call_handler,        btc_spp_cb_handler      },
+    [BTC_PID_SPP]         = {btc_spp_call_handler,        btc_spp_cb_handler      },
 #endif /* #if CONFIG_BT_SPP_ENABLED */
 #endif /* #if CONFIG_CLASSIC_BT_ENABLED */
 };
index 523e1bb982993fb8264f1898be82ea90636b221b..b95ae0bbec205f63215e7d318d5c1346a3aa146f 100644 (file)
@@ -26,7 +26,6 @@ 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 {
@@ -61,13 +60,5 @@ 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 f19c266991a7932a5dc59dc8c1b13f51a6b442c0..16388c685bbd4579f2ed925c6fb4b1c51c964d33 100644 (file)
@@ -41,6 +41,7 @@ typedef enum {
 #if (GATTC_INCLUDED == TRUE)
     BTC_PID_GATTC,
 #endif  ///GATTC_INCLUDED == TRUE
+    BTC_PID_GATT_COMMON,
     BTC_PID_GAP_BLE,
     BTC_PID_BLE_HID,
     BTC_PID_SPPLIKE,
diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_common.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_common.c
new file mode 100644 (file)
index 0000000..af34c71
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright 2015-2016 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 "btc_task.h"
+#include "btc_main.h"
+#include "btc_dm.h"
+#include "future.h"
+#include "esp_err.h"
+#include "btc_config.h"
+#include "alarm.h"
+#include "btc_ble_storage.h"
+#include "btc_gatt_common.h"
+#include "bta_gatt_common.h"
+
+
+static void btc_set_local_mtu(uint16_t mtu)
+{
+    BTA_GATT_SetLocalMTU(mtu);
+}
+
+void btc_gatt_com_call_handler(btc_msg_t *msg)
+{
+    LOG_DEBUG("%s act %d\n", __func__, msg->act);
+    switch (msg->act) {
+    case BTC_GATT_ACT_SET_LOCAL_MTU:
+    {
+        btc_ble_gatt_com_args_t *arg = (btc_ble_gatt_com_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;
+    }
+}
+
diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gatt_common.h b/components/bt/bluedroid/btc/profile/std/include/btc_gatt_common.h
new file mode 100644 (file)
index 0000000..41b0fee
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2015-2016 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.
+
+#ifndef __BTC_GATT_COMMON_H__
+#define __BTC_GATT_COMMON_H__
+
+#include "future.h"
+#include "bt_types.h"
+#include "bta_api.h"
+#include "btc_main.h"
+#include "btc_task.h"
+
+typedef enum {
+    BTC_GATT_ACT_SET_LOCAL_MTU = 0,
+} btc_gatt_com_act_t;
+
+/* btc_ble_gattc_args_t */
+typedef union {
+    //BTC_GATT_ACT_SET_LOCAL_MTU,
+    struct set_mtu_arg {
+        uint16_t mtu;
+    } set_mtu;
+} btc_ble_gatt_com_args_t;
+
+void btc_gatt_com_call_handler(btc_msg_t *msg);
+#endif /* __BTC_GATT_COMMON_H__ */