From: zhiweijian Date: Thu, 25 Jan 2018 09:34:10 +0000 (+0800) Subject: Component/bt: modify set mtu call handler X-Git-Tag: v3.1-beta1~425^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b06ea40f66a3fff54ab5912fce77ba154ba9085a;p=esp-idf Component/bt: modify set mtu call handler --- diff --git a/components/bt/bluedroid/api/esp_gatt_common_api.c b/components/bt/bluedroid/api/esp_gatt_common_api.c index 6d795c1c08..1146750c7c 100644 --- a/components/bt/bluedroid/api/esp_gatt_common_api.c +++ b/components/bt/bluedroid/api/esp_gatt_common_api.c @@ -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 diff --git a/components/bt/bluedroid/btc/core/btc_main.c b/components/bt/bluedroid/btc/core/btc_main.c index f37801e699..cb5975be1f 100644 --- a/components/bt/bluedroid/btc/core/btc_main.c +++ b/components/bt/bluedroid/btc/core/btc_main.c @@ -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; diff --git a/components/bt/bluedroid/btc/core/btc_task.c b/components/bt/bluedroid/btc/core/btc_task.c index 2a11472964..004b67f16b 100644 --- a/components/bt/bluedroid/btc/core/btc_task.c +++ b/components/bt/bluedroid/btc/core/btc_task.c @@ -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 */ }; diff --git a/components/bt/bluedroid/btc/include/btc_main.h b/components/bt/bluedroid/btc/include/btc_main.h index 523e1bb982..b95ae0bbec 100644 --- a/components/bt/bluedroid/btc/include/btc_main.h +++ b/components/bt/bluedroid/btc/include/btc_main.h @@ -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__ */ diff --git a/components/bt/bluedroid/btc/include/btc_task.h b/components/bt/bluedroid/btc/include/btc_task.h index f19c266991..16388c685b 100644 --- a/components/bt/bluedroid/btc/include/btc_task.h +++ b/components/bt/bluedroid/btc/include/btc_task.h @@ -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 index 0000000000..af34c7108f --- /dev/null +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_common.c @@ -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 index 0000000000..41b0fee54e --- /dev/null +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gatt_common.h @@ -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__ */