// limitations under the License.
#include <string.h>
-
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "bt_trace.h"
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;
+ arg.set_scan_mode.mode = mode;
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
+esp_err_t esp_bt_gap_set_device_name(const char *name)
+{
+ btc_msg_t msg;
+ btc_gap_bt_args_t arg;
+
+ if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
+ return ESP_ERR_INVALID_STATE;
+ }
+
+ if (strlen(name) > ESP_BT_GAP_DEVICE_NAME_MAX) {
+ return ESP_ERR_INVALID_ARG;
+ }
+
+ msg.sig = BTC_SIG_API_CALL;
+ msg.pid = BTC_PID_GAP_BT;
+ msg.act = BTC_GAP_BT_ACT_SET_DEV_NAME;
+ strcpy(arg.set_dev_name.device_name, name);
+
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
extern "C" {
#endif
+#define ESP_BT_GAP_DEVICE_NAME_MAX (32)
+
/// Discoverability and Connectability mode
typedef enum {
ESP_BT_SCAN_MODE_NONE = 0, /*!< Neither discoverable nor connectable */
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include "btc_dm.h"
+#include "btc_main.h"
+#include "bt_trace.h"
+#include "bt_target.h"
+#include "btif_storage.h" // TODO: replace with "btc"
+
+extern void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl); // todo: replace with "btc_xx"
+
+static void btc_dm_sec_arg_deep_free(btc_msg_t *msg)
+{
+ btc_dm_sec_args_t *arg = (btc_dm_sec_args_t *)(msg->arg);
+ if (msg->act == BTA_DM_BLE_KEY_EVT) {
+ osi_free(arg->sec.ble_key.p_key_value);
+ }
+}
+
+void btc_dm_sec_arg_deep_copy(btc_msg_t *msg, void *dst, void *src)
+{
+ tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC *)dst;
+ tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC *)src;
+
+ if (!src_dm_sec) {
+ return;
+ }
+
+ assert(dst_dm_sec);
+ memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
+
+ if (msg->act == BTA_DM_BLE_KEY_EVT) {
+ dst_dm_sec->ble_key.p_key_value = osi_malloc(sizeof(tBTM_LE_KEY_VALUE));
+ assert(src_dm_sec->ble_key.p_key_value);
+ assert(dst_dm_sec->ble_key.p_key_value);
+ memcpy(dst_dm_sec->ble_key.p_key_value, src_dm_sec->ble_key.p_key_value, sizeof(tBTM_LE_KEY_VALUE));
+ }
+}
+
+
+/*******************************************************************************
+**
+** Function btc_dm_evt
+**
+** Description Switches context from BTE to BTC for all DM events
+**
+** Returns void
+**
+*******************************************************************************/
+
+void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data)
+{
+ btc_msg_t msg;
+
+ msg.sig = BTC_SIG_API_CB;
+ msg.pid = BTC_PID_DM_SEC;
+ msg.act = event;
+
+ btc_transfer_context(&msg, (btc_dm_sec_args_t *)data, sizeof(btc_dm_sec_args_t), btc_dm_sec_arg_deep_copy);
+}
+
+static void btc_enable_bluetooth_evt(tBTA_STATUS status)
+{
+ if (status == BTA_SUCCESS) {
+ future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_SUCCESS);
+ } else {
+ future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_FAIL);
+ }
+}
+
+static void btc_disable_bluetooth_evt(void)
+{
+ LOG_DEBUG("%s", __FUNCTION__);
+
+ future_ready(*btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE), FUTURE_SUCCESS);
+}
+
+void btc_dm_sec_cb_handler(btc_msg_t *msg)
+{
+ btc_dm_sec_args_t *arg = (btc_dm_sec_args_t *)(msg->arg);
+ tBTA_DM_SEC *p_data = &(arg->sec);
+ // tBTA_SERVICE_MASK service_mask;
+ LOG_DEBUG("btif_dm_upstreams_cback ev: %d\n", msg->act);
+
+ switch (msg->act) {
+ case BTA_DM_ENABLE_EVT:
+#if KARL_NOT_IGNORE
+ /* for each of the enabled services in the mask, trigger the profile
+ * enable */
+ service_mask = btif_get_enabled_services_mask();
+ for (int i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
+ if (service_mask &
+ (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
+ btif_in_execute_service_request(i, TRUE);
+ }
+ }
+ btif_enable_bluetooth_evt(p_data->enable.status);
+#endif /* KARL_NOT_IGNORE */
+ btif_storage_load_bonded_devices();
+ btc_enable_bluetooth_evt(p_data->enable.status);
+ break;
+ case BTA_DM_DISABLE_EVT:
+#if KARL_NOT_IGNORE
+ /* for each of the enabled services in the mask, trigger the profile
+ * disable */
+ service_mask = btif_get_enabled_services_mask();
+ for (int i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
+ if (service_mask &
+ (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
+ btif_in_execute_service_request(i, FALSE);
+ }
+ }
+ btif_disable_bluetooth_evt();
+#endif /* KARL_NOT_IGNORE */
+ btc_disable_bluetooth_evt();
+ break;
+ case BTA_DM_PIN_REQ_EVT:
+ break;
+ case BTA_DM_AUTH_CMPL_EVT:
+ btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
+ break;
+ case BTA_DM_BOND_CANCEL_CMPL_EVT:
+ case BTA_DM_SP_CFM_REQ_EVT:
+ case BTA_DM_SP_KEY_NOTIF_EVT:
+
+ case BTA_DM_DEV_UNPAIRED_EVT:
+ case BTA_DM_BUSY_LEVEL_EVT:
+ case BTA_DM_LINK_UP_EVT:
+ case BTA_DM_LINK_DOWN_EVT:
+ case BTA_DM_HW_ERROR_EVT:
+
+#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
+ case BTA_DM_BLE_KEY_EVT:
+ case BTA_DM_BLE_SEC_REQ_EVT:
+ case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
+ case BTA_DM_BLE_PASSKEY_REQ_EVT:
+ case BTA_DM_BLE_NC_REQ_EVT:
+ case BTA_DM_BLE_OOB_REQ_EVT:
+ case BTA_DM_BLE_LOCAL_IR_EVT:
+ case BTA_DM_BLE_LOCAL_ER_EVT:
+ case BTA_DM_BLE_AUTH_CMPL_EVT:
+ case BTA_DM_LE_FEATURES_READ:
+ case BTA_DM_ENER_INFO_READ:
+#endif
+
+ case BTA_DM_AUTHORIZE_EVT:
+ case BTA_DM_SIG_STRENGTH_EVT:
+ case BTA_DM_SP_RMT_OOB_EVT:
+ case BTA_DM_SP_KEYPRESS_EVT:
+ case BTA_DM_ROLE_CHG_EVT:
+
+ default:
+ LOG_WARN( "btc_dm_sec_cback : unhandled event (%d)\n", msg->act );
+ break;
+ }
+
+ btc_dm_sec_arg_deep_free(msg);
+}
#include "btc_task.h"
#include "btc_main.h"
+#include "btc_dm.h"
#include "future.h"
#include "esp_err.h"
#include "btif_config.h"
static void btc_enable_bluetooth(void)
{
- if (BTA_EnableBluetooth(btc_sec_callback) != BTA_SUCCESS) {
+ if (BTA_EnableBluetooth(btc_dm_sec_evt) != BTA_SUCCESS) {
future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_FAIL);
}
}
#include "btc_gap_ble.h"
#include "btc_gap_bt.h"
#include "btc_blufi_prf.h"
+#include "btc_dm.h"
#include "bta_gatt_api.h"
[BTC_PID_SPP] = {NULL, NULL},
[BTC_PID_SPPLIKE] = {NULL, NULL},
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
+ [BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler }
};
/*****************************************************************************
--- /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.
+
+#ifndef __BTC_DM_H__
+#define __BTC_DM_H__
+
+#include "btc_task.h"
+#include "esp_bt_defs.h"
+#include "bta_api.h"
+
+typedef enum {
+ BTC_DM_SEC_ACT
+} btc_dm_sec_act_t;
+
+/* btc_dm_args_t */
+typedef union {
+ //BTC_DM_SEC_ACT
+ tBTA_DM_SEC sec;
+} btc_dm_sec_args_t;
+
+// void btc_dm_call_handler(btc_msg_t *msg);
+void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data);
+void btc_dm_sec_cb_handler(btc_msg_t *msg);
+void btc_dm_sec_arg_deep_copy(btc_msg_t *msg, void *dst, void *src);
+
+#endif /* __BTC_DM_H__ */
BTC_PID_SPP,
BTC_PID_SPPLIKE,
BTC_PID_BLUFI,
+ BTC_PID_DM_SEC,
BTC_PID_NUM,
} btc_pid_t; //btc profile id
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);
+ btc_bt_set_scan_mode(arg->set_scan_mode.mode);
+ break;
+ }
+ case BTC_GAP_BT_ACT_SET_DEV_NAME: {
+ BTA_DmSetDeviceName(arg->set_dev_name.device_name);
break;
}
default:
btc_gap_bt_arg_deep_free(msg);
}
-/* to be fixed */
-esp_err_t esp_bt_gap_set_device_name(const char *name)
+void btc_gap_bt_cb_handler(btc_msg_t *msg)
{
- if (name == NULL || *name == '\0') {
- return ESP_ERR_INVALID_ARG;
- }
- #define ESP_GAP_DEVICE_NAME_MAX (32)
- char dev_name[ESP_GAP_DEVICE_NAME_MAX+1];
- strncpy(dev_name, name, ESP_GAP_DEVICE_NAME_MAX);
- dev_name[ESP_GAP_DEVICE_NAME_MAX] = '\0';
- BTA_DmSetDeviceName(dev_name);
- return ESP_OK;
+ // todo
}
#include "btc_task.h"
typedef enum {
- BTC_GAP_BT_ACT_SET_SCAN_MODE = 0
+ BTC_GAP_BT_ACT_SET_SCAN_MODE = 0,
+ BTC_GAP_BT_ACT_SET_DEV_NAME
} btc_gap_bt_act_t;
-/* btc_gap_bt_args_t */
+/* btc_bt_gap_args_t */
typedef union {
- // BTC_GAP_BT_ACT_SET_SCAN_MODE,
- struct scan_mode_args {
+ // BTC_BT_GAP_ACT_SET_SCAN_MODE,
+ struct set_bt_scan_mode_args {
esp_bt_scan_mode_t mode;
- } scan_mode;
+ } set_scan_mode;
+
+ // BTC_BT_GAP_ACT_SET_DEV_NAME
+ struct set_bt_dev_name_args {
+ char device_name[ESP_BT_GAP_DEVICE_NAME_MAX + 1];
+ } set_dev_name;
} btc_gap_bt_args_t;
void btc_gap_bt_call_handler(btc_msg_t *msg);
** Returns void
**
*******************************************************************************/
-static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
+// static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
+void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
{
/* Save link key, if not temporary */
bt_bdaddr_t bd_addr;
// #include "EspAudioCom.h"
#include "bt_app_common.h"
-#include "esp_bt_stack_manager.h"
+#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_a2dp_api.h"
#include "esp_avrc_api.h"
switch (event) {
case BT_APP_EVT_STACK_ON: {
char *dev_name = "ESP_SPEAKER";
+
esp_bt_gap_set_device_name(dev_name);
- esp_a2d_register_callback(&bt_app_a2d_cb);
- esp_a2d_register_data_callback(bt_app_a2d_data_cb);
+ // esp_a2d_register_callback(&bt_app_a2d_cb);
+ // esp_a2d_register_data_callback(bt_app_a2d_data_cb);
- esp_a2d_sink_init();
+ // esp_a2d_sink_init();
- esp_avrc_ct_init();
- esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
+ // esp_avrc_ct_init();
+ // esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
break;
void app_main_entry(void)
{
esp_err_t init, enable;
- init = esp_bt_init_stack();
+ // init = esp_bt_init_stack();
+ init = esp_bluedroid_init();
if (init != ESP_OK) {
return;
}
- enable = esp_bt_enable_stack();
+ // enable = esp_bt_enable_stack();
+ enable = esp_bluedroid_enable();
if (enable != ESP_OK) {
return;
}