--- /dev/null
+// 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 <string.h>
+
+#include "esp_bt_main.h"
+#include "esp_gap_bt_api.h"
+#include "bt_trace.h"
+#include "btc_manage.h"
+#include "btc_gap_bt.h"
+
+esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode)
+{
+ btc_msg_t msg;
+ btc_gap_bt_args_t arg;
+
+ if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
+ return ESP_ERR_INVALID_STATE;
+ }
+
+ msg.sig = BTC_SIG_API_CALL;
+ msg.pid = BTC_PID_GAP_BT;
+ msg.act = BTC_GAP_BT_ACT_SET_SCAN_MODE;
+ arg.scan_mode.mode = mode;
+
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
+
/// Discoverability and Connectability mode
typedef enum {
- BT_SCAN_MODE_NONE = 0, /*!< Neither discoverable nor connectable */
- BT_SCAN_MODE_CONNECTABLE, /*!< Connectable but not discoverable */
- BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE /*!< both discoverable and connectaable */
-} bt_scan_mode_t;
+ ESP_BT_SCAN_MODE_NONE = 0, /*!< Neither discoverable nor connectable */
+ ESP_BT_SCAN_MODE_CONNECTABLE, /*!< Connectable but not discoverable */
+ ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE /*!< both discoverable and connectaable */
+} esp_bt_scan_mode_t;
/**
* @brief Set discoverability and connectability mode for legacy bluetooth
* - ESP_OK : Succeed
* - ESP_ERR_INVALID_ARG: if argument invalid
*/
-esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode);
+esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode);
/**
{
if (BTA_EnableBluetooth(btc_sec_callback) != BTA_SUCCESS) {
future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_FAIL);
- }
+ }
}
static void btc_disable_bluetooth(void)
{
if (BTA_DisableBluetooth() != BTA_SUCCESS) {
future_ready(*btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE), FUTURE_FAIL);
- }
+ }
}
void btc_init_callback(void)
#include "btc_gatts.h"
#include "btc_gattc.h"
#include "btc_gap_ble.h"
+#include "btc_gap_bt.h"
#include "btc_blufi_prf.h"
#include "bta_gatt_api.h"
[BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler },
[BTC_PID_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
- [BTC_PID_GAP_BT] = {NULL, NULL}, // {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
+ [BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
[BTC_PID_SDP] = {NULL, NULL},
[BTC_PID_BLE_HID] = {NULL, NULL},
[BTC_PID_BT_HID] = {NULL, NULL},
// limitations under the License.
#include "esp_gap_bt_api.h"
+#include "btc_gap_bt.h"
#include "bta_api.h"
#include "bt_trace.h"
#include <string.h>
-esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode)
+void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
+{
+ switch (msg->act) {
+ default:
+ // LOG_ERROR("Unhandled deep copy %d\n", msg->act);
+ break;
+ }
+}
+
+static void btc_gap_bt_arg_deep_free(btc_msg_t *msg)
+{
+ LOG_DEBUG("%s \n", __func__);
+ switch (msg->act) {
+ default:
+ // LOG_DEBUG("Unhandled deep free %d\n", msg->act);
+ break;
+ }
+}
+
+static void btc_bt_set_scan_mode(esp_bt_scan_mode_t mode)
{
tBTA_DM_DISC disc_mode;
tBTA_DM_CONN conn_mode;
switch (mode) {
- case BT_SCAN_MODE_NONE:
+ case ESP_BT_SCAN_MODE_NONE:
disc_mode = BTA_DM_NON_DISC;
conn_mode = BTA_DM_NON_CONN;
break;
- case BT_SCAN_MODE_CONNECTABLE:
+ case ESP_BT_SCAN_MODE_CONNECTABLE:
disc_mode = BTA_DM_NON_DISC;
conn_mode = BTA_DM_CONN;
break;
- case BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
+ case ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
disc_mode = BTA_DM_GENERAL_DISC;
conn_mode = BTA_DM_CONN;
break;
default:
- // BTIF_TRACE_ERROR("invalid scan mode (0x%x)", mode);
- return ESP_ERR_INVALID_ARG;
+ LOG_WARN("invalid scan mode (0x%x)", mode);
+ return;
}
- // BTIF_TRACE_EVENT("set property scan mode : %x", mode);
BTA_DmSetVisibility(disc_mode, conn_mode, BTA_DM_IGNORE, BTA_DM_IGNORE);
+ return;
+}
- return ESP_OK;
+void btc_gap_bt_call_handler(btc_msg_t *msg)
+{
+ btc_gap_bt_args_t *arg = (btc_gap_bt_args_t *)msg->arg;
+ LOG_DEBUG("%s act %d\n", __func__, msg->act);
+ switch (msg->act) {
+ case BTC_GAP_BT_ACT_SET_SCAN_MODE: {
+ btc_bt_set_scan_mode(arg->scan_mode.mode);
+ break;
+ }
+ default:
+ break;
+ }
+ btc_gap_bt_arg_deep_free(msg);
}
+/* to be fixed */
esp_err_t esp_bt_gap_set_device_name(const char *name)
{
if (name == NULL || *name == '\0') {
#ifndef __BTC_GAP_BT_H__
#define __BTC_GAP_BT_H__
+#include "esp_bt_defs.h"
+#include "esp_gap_bt_api.h"
+#include "btc_task.h"
+typedef enum {
+ BTC_GAP_BT_ACT_SET_SCAN_MODE = 0
+} btc_gap_bt_act_t;
+/* btc_gap_bt_args_t */
+typedef union {
+ // BTC_GAP_BT_ACT_SET_SCAN_MODE,
+ struct scan_mode_args {
+ esp_bt_scan_mode_t mode;
+ } scan_mode;
+} btc_gap_bt_args_t;
+void btc_gap_bt_call_handler(btc_msg_t *msg);
+void btc_gap_bt_cb_handler(btc_msg_t *msg);
-#define /* __BTC_GAP_BT_H__ */
+void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
+
+#endif /* __BTC_GAP_BT_H__ */
esp_avrc_ct_init();
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
- esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
+ esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
break;
}
case ESP_A2D_CONNECTION_STATE_EVT: {