mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
component/bt : remove sdp demo and add default sdkconfig of bt demos
1. remove sdp demo. 2. add sdkconfig.default for bt demos
This commit is contained in:
parent
6010ea713f
commit
a8dd1dfcf2
@ -9,3 +9,10 @@ COMPONENT_ADD_INCLUDEDIRS := components/include
|
|||||||
|
|
||||||
include $(IDF_PATH)/make/project.mk
|
include $(IDF_PATH)/make/project.mk
|
||||||
|
|
||||||
|
# Copy some defaults into the sdkconfig by default
|
||||||
|
# so BT stack is enabled
|
||||||
|
sdkconfig: sdkconfig.defaults
|
||||||
|
$(Q) cp $< $@
|
||||||
|
|
||||||
|
menuconfig: sdkconfig
|
||||||
|
defconfig: sdkconfig
|
||||||
|
14
examples/12_blufi/sdkconfig.defaults
Normal file
14
examples/12_blufi/sdkconfig.defaults
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Override some defaults so BT stack is enabled
|
||||||
|
# in this example
|
||||||
|
|
||||||
|
#
|
||||||
|
# BT config
|
||||||
|
#
|
||||||
|
CONFIG_BT_ENABLED=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# ESP32-specific config
|
||||||
|
#
|
||||||
|
CONFIG_ESP32_ENABLE_STACK_BT=y
|
||||||
|
# CONFIG_ESP32_ENABLE_STACK_NONE is not set
|
||||||
|
CONFIG_MEMMAP_BT=y
|
@ -1,11 +0,0 @@
|
|||||||
#
|
|
||||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
|
||||||
# project subdirectory.
|
|
||||||
#
|
|
||||||
|
|
||||||
PROJECT_NAME := bluedroid_demos
|
|
||||||
|
|
||||||
COMPONENT_ADD_INCLUDEDIRS := components/include
|
|
||||||
|
|
||||||
include $(IDF_PATH)/make/project.mk
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
ESP-IDF 08 SDP Server and Client
|
|
||||||
=======================
|
|
||||||
|
|
||||||
Demo of bluetooth SDP server and client
|
|
||||||
|
|
@ -1,188 +0,0 @@
|
|||||||
// 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 <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "fixed_queue.h"
|
|
||||||
#include "gki.h"
|
|
||||||
#include "bt_defs.h"
|
|
||||||
#include "bt_trace.h"
|
|
||||||
#include "bt_types.h"
|
|
||||||
#include "allocator.h"
|
|
||||||
|
|
||||||
#include "bta_api.h"
|
|
||||||
#include "bta_gatt_api.h"
|
|
||||||
#include "bt_app_common.h"
|
|
||||||
|
|
||||||
#include "controller.h"
|
|
||||||
#include "thread.h"
|
|
||||||
#include "bt_app_common.h"
|
|
||||||
|
|
||||||
static fixed_queue_t *bt_app_msg_queue;
|
|
||||||
|
|
||||||
xQueueHandle xBtAppQueue;
|
|
||||||
xTaskHandle xBtAppTaskHandle;
|
|
||||||
|
|
||||||
static void bt_app_context_switched(void *p_msg);
|
|
||||||
static void bt_app_send_msg(void *p_msg);
|
|
||||||
static void bt_app_task_handler(void *arg);
|
|
||||||
static void bta_app_msg_ready(fixed_queue_t *queue);
|
|
||||||
static void bt_app_task_shut_down(void);
|
|
||||||
|
|
||||||
|
|
||||||
extern void app_main_entry(void);
|
|
||||||
|
|
||||||
static void bt_app_task_handler(void *arg)
|
|
||||||
{
|
|
||||||
app_main_entry();
|
|
||||||
TaskEvt_t *e;
|
|
||||||
for (;;) {
|
|
||||||
if (pdTRUE == xQueueReceive(xBtAppQueue, &e, (portTickType)portMAX_DELAY)) {
|
|
||||||
if (e->sig == 0xff) {
|
|
||||||
fixed_queue_process(bt_app_msg_queue);
|
|
||||||
}
|
|
||||||
osi_free(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bt_app_task_post(void)
|
|
||||||
{
|
|
||||||
TaskEvt_t *evt = (TaskEvt_t *)osi_malloc(sizeof(TaskEvt_t));
|
|
||||||
if (evt == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
evt->sig = 0xff;
|
|
||||||
evt->par = 0;
|
|
||||||
|
|
||||||
if (xQueueSend(xBtAppQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
|
|
||||||
ets_printf("btdm_post failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bta_app_msg_ready(fixed_queue_t *queue) {
|
|
||||||
BT_HDR *p_msg;
|
|
||||||
while (!fixed_queue_is_empty(queue)) {
|
|
||||||
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
|
|
||||||
LOG_ERROR("bta_app_msg_ready, evt: %d\n", p_msg->event);
|
|
||||||
switch (p_msg->event) {
|
|
||||||
case BT_EVT_APP_CONTEXT_SWITCH:
|
|
||||||
bt_app_context_switched(p_msg);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG_ERROR("unhandled BT_APP event (%d)\n", p_msg->event & BT_EVT_MASK);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
GKI_freebuf(p_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bt_app_context_switched(void *p_msg)
|
|
||||||
{
|
|
||||||
tBTAPP_CONTEXT_SWITCH_CBACK *p = (tBTAPP_CONTEXT_SWITCH_CBACK *) p_msg;
|
|
||||||
|
|
||||||
if (p->p_cb)
|
|
||||||
p->p_cb(p->event, p->p_param);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bt_app_send_msg(void *p_msg)
|
|
||||||
{
|
|
||||||
if (bt_app_msg_queue) {
|
|
||||||
fixed_queue_enqueue(bt_app_msg_queue, p_msg);
|
|
||||||
bt_app_task_post();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback)
|
|
||||||
{
|
|
||||||
tBTAPP_CONTEXT_SWITCH_CBACK *p_msg;
|
|
||||||
|
|
||||||
LOG_ERROR("btapp_transfer_context evt %d, len %d\n", event, param_len);
|
|
||||||
|
|
||||||
/* allocate and send message that will be executed in btif context */
|
|
||||||
if ((p_msg = (tBTAPP_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTAPP_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
|
|
||||||
{
|
|
||||||
p_msg->hdr.event = BT_EVT_APP_CONTEXT_SWITCH; /* internal event */
|
|
||||||
p_msg->p_cb = p_cback;
|
|
||||||
|
|
||||||
p_msg->event = event; /* callback event */
|
|
||||||
|
|
||||||
/* check if caller has provided a copy callback to do the deep copy */
|
|
||||||
if (p_copy_cback)
|
|
||||||
{
|
|
||||||
p_copy_cback(event, p_msg->p_param, p_params);
|
|
||||||
}
|
|
||||||
else if (p_params)
|
|
||||||
{
|
|
||||||
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_app_send_msg(p_msg);
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* let caller deal with a failed allocation */
|
|
||||||
return BT_STATUS_NOMEM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bt_app_task_start_up(void)
|
|
||||||
{
|
|
||||||
bt_app_msg_queue = fixed_queue_new(SIZE_MAX);
|
|
||||||
if (bt_app_msg_queue == NULL)
|
|
||||||
goto error_exit;
|
|
||||||
//ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler);
|
|
||||||
|
|
||||||
xBtAppQueue = xQueueCreate(3, sizeof(void *));
|
|
||||||
xTaskCreate(bt_app_task_handler, "BtaApp1T", 8192, NULL, configMAX_PRIORITIES - 3, xBtAppTaskHandle);
|
|
||||||
|
|
||||||
fixed_queue_register_dequeue(bt_app_msg_queue, bta_app_msg_ready);
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
error_exit:
|
|
||||||
LOG_ERROR("%s Unable to allocate resources for bt_app\n", __func__);
|
|
||||||
bt_app_task_shut_down();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bt_app_task_shut_down(void)
|
|
||||||
{
|
|
||||||
fixed_queue_unregister_dequeue(bt_app_msg_queue);
|
|
||||||
fixed_queue_free(bt_app_msg_queue, NULL);
|
|
||||||
bt_app_msg_queue = NULL;
|
|
||||||
|
|
||||||
vTaskDelete(xBtAppTaskHandle);
|
|
||||||
vQueueDelete(xBtAppQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
static void bt_app_upstreams_evt(UINT16 event, char *p_param)
|
|
||||||
{
|
|
||||||
tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
|
|
||||||
switch (event) {
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bt_stack_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data)
|
|
||||||
{
|
|
||||||
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
|
|
||||||
bt_app_transfer_context(bt_app_upstreams_evt, (uint16_t)event,
|
|
||||||
(void *)p_data, sizeof(tBTA_DM_SEC), NULL);
|
|
||||||
}
|
|
||||||
*/
|
|
@ -1,154 +0,0 @@
|
|||||||
// 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 <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
|
|
||||||
#include "bt_app_common.h"
|
|
||||||
#include "btif_stack_manager.h"
|
|
||||||
#include "btif_sdp.h"
|
|
||||||
#include "bt_gap_api.h"
|
|
||||||
|
|
||||||
#include "bta_api.h"
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BT_APP_EVT_STACK_ON,
|
|
||||||
BT_APP_EVT_STACK_OFF,
|
|
||||||
BT_APP_EVT
|
|
||||||
} tBT_APP_EVT;
|
|
||||||
|
|
||||||
typedef union {
|
|
||||||
uint32_t dummy;
|
|
||||||
} tBT_APP_EVT_DATA;
|
|
||||||
|
|
||||||
static void bt_stack_state_changed(bt_state_t state);
|
|
||||||
static int bt_sdp_add_record(void);
|
|
||||||
static void bt_sdp_search_complete(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
|
|
||||||
|
|
||||||
// static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}};
|
|
||||||
static bt_bdaddr_t peer_bd_addr = {{0xfc, 0x3f, 0x7c, 0xf1, 0x2c, 0x78}};
|
|
||||||
|
|
||||||
/* root browse
|
|
||||||
static const uint8_t target_uuid[16] = { 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x10, 0x00,
|
|
||||||
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* UUID_MAP_MAS */
|
|
||||||
static const uint8_t target_uuid[] = {0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00,
|
|
||||||
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
|
|
||||||
|
|
||||||
/* UUID AUDIO Source */
|
|
||||||
/*
|
|
||||||
static const uint8_t target_uuid[] = {0x00, 0x00, 0x11, 0x0A, 0x00, 0x00, 0x10, 0x00,
|
|
||||||
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
|
|
||||||
*/
|
|
||||||
|
|
||||||
static bt_callbacks_t bt_callbacks = {
|
|
||||||
bt_stack_state_changed
|
|
||||||
};
|
|
||||||
|
|
||||||
static btsdp_callbacks_t btsdp_callbacks = {
|
|
||||||
bt_sdp_search_complete
|
|
||||||
};
|
|
||||||
|
|
||||||
static void bt_app_stack_evt(UINT16 event, char *p_param)
|
|
||||||
{
|
|
||||||
switch (event) {
|
|
||||||
case BT_APP_EVT_STACK_ON: {
|
|
||||||
char *dev_name = "SDP_SERVER_CLIENT";
|
|
||||||
BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
|
|
||||||
BTA_DmSetDeviceName(dev_name);
|
|
||||||
|
|
||||||
esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
|
||||||
BTIF_SdpInit(&btsdp_callbacks);
|
|
||||||
|
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
||||||
bt_sdp_add_record();
|
|
||||||
|
|
||||||
vTaskDelay(20000/portTICK_PERIOD_MS);
|
|
||||||
BTIF_SdpSearch(&peer_bd_addr, target_uuid);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data)
|
|
||||||
{
|
|
||||||
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
|
|
||||||
bt_app_transfer_context(bt_app_stack_evt, (uint16_t)event,
|
|
||||||
(void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bt_stack_state_changed(bt_state_t state)
|
|
||||||
{
|
|
||||||
if (state == BT_STATE_ON) {
|
|
||||||
bt_stack_evt(BT_APP_EVT_STACK_ON, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int bt_sdp_add_record(void)
|
|
||||||
{
|
|
||||||
int handle;
|
|
||||||
bluetooth_sdp_sap_record sap_svr;
|
|
||||||
memset (&sap_svr, 0, sizeof(bluetooth_sdp_sap_record));
|
|
||||||
|
|
||||||
sap_svr.hdr.type = SDP_TYPE_SAP_SERVER;
|
|
||||||
sap_svr.hdr.rfcomm_channel_number = 2;
|
|
||||||
sap_svr.hdr.service_name = "SIM ACCESS";
|
|
||||||
sap_svr.hdr.service_name_length = 10;
|
|
||||||
sap_svr.hdr.profile_version = 0x0100;
|
|
||||||
|
|
||||||
BTIF_SdpCreateRecord((bluetooth_sdp_record *)(&sap_svr), &handle);
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bt_sdp_search_complete(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records)
|
|
||||||
{
|
|
||||||
uint8_t *addr = bd_addr->address;
|
|
||||||
bluetooth_sdp_hdr_overlay *p = &records->mas.hdr;
|
|
||||||
LOG_ERROR("sdp search cmpl: st %d, bd_addr: %02x:%02x:%02x:%02x:%02x:%02x, records %d\n",
|
|
||||||
status, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], num_records);
|
|
||||||
if (p->service_name_length > 0) {
|
|
||||||
LOG_ERROR("service name: %s\n", p->service_name);
|
|
||||||
}
|
|
||||||
LOG_ERROR("rfc_chl_num %d, l2cap_psm %d, version %02x\n",
|
|
||||||
p->rfcomm_channel_number, p->l2cap_psm, p->profile_version);
|
|
||||||
#if 0
|
|
||||||
uint8_t *addr = bd_addr->address;
|
|
||||||
bluetooth_sdp_hdr_overlay *p = &records->hdr;
|
|
||||||
LOG_ERROR("sdp search cmpl: st %d, bd_addr: %02x:%02x:%02x:%02x:%02x:%02x, records %d, len:%d\n",
|
|
||||||
status, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], num_records, p->user1_ptr_len);
|
|
||||||
if (p->service_name_length > 0) {
|
|
||||||
LOG_ERROR("service name: %s\n", p->service_name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_main_entry(void)
|
|
||||||
{
|
|
||||||
bt_status_t stat;
|
|
||||||
stat = BTIF_InitStack(&bt_callbacks);
|
|
||||||
if (stat == BT_STATUS_SUCCESS) {
|
|
||||||
BTIF_EnableStack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,483 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2014 The Android Open Source Project
|
|
||||||
* Copyright (C) 2009-2012 Broadcom Corporation
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
*
|
|
||||||
* Filename: btif_core.c
|
|
||||||
*
|
|
||||||
* Description: Contains core functionality related to interfacing between
|
|
||||||
* Bluetooth HAL and BTE core stack.
|
|
||||||
*
|
|
||||||
***********************************************************************************/
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
// #include <cutils/properties.h>
|
|
||||||
// #include <dirent.h>
|
|
||||||
// #include <fcntl.h>
|
|
||||||
// #include <hardware/bluetooth.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
// #include <sys/stat.h>
|
|
||||||
// #include <sys/types.h>
|
|
||||||
|
|
||||||
#define LOG_TAG "bt_btif_core"
|
|
||||||
// #include "btcore/include/bdaddr.h"
|
|
||||||
|
|
||||||
#include "bdaddr.h"
|
|
||||||
// #include "bt_utils.h"
|
|
||||||
#include "bta_api.h"
|
|
||||||
#include "bte.h"
|
|
||||||
#include "btif_api.h"
|
|
||||||
// #include "btif_av.h"
|
|
||||||
// #include "btif_config.h"
|
|
||||||
// #include "btif_pan.h"
|
|
||||||
// #include "btif_profile_queue.h"
|
|
||||||
// #include "btif_config.h"
|
|
||||||
// #include "btif_sock.h"
|
|
||||||
// #include "btif_storage.h"
|
|
||||||
#include "btif_util.h"
|
|
||||||
#include "btu.h"
|
|
||||||
#include "controller.h"
|
|
||||||
#include "fixed_queue.h"
|
|
||||||
#include "future.h"
|
|
||||||
#include "gki.h"
|
|
||||||
#include "osi.h"
|
|
||||||
// #include "osi/include/log.h"
|
|
||||||
#include "stack_manager.h"
|
|
||||||
#include "thread.h"
|
|
||||||
#include "btif_common.h"
|
|
||||||
#include "btif_dm.h"
|
|
||||||
/************************************************************************************
|
|
||||||
** Constants & Macros
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Local type definitions
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Static variables
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
static tBTA_SERVICE_MASK btif_enabled_services = 0;
|
|
||||||
|
|
||||||
static fixed_queue_t *btif_msg_queue = NULL;
|
|
||||||
static xTaskHandle xBtifTaskHandle = NULL;
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Static functions
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/* sends message to btif task */
|
|
||||||
static void btif_sendmsg(void *p_msg);
|
|
||||||
static void btif_thread_post(uint32_t sig);
|
|
||||||
/************************************************************************************
|
|
||||||
** Externs
|
|
||||||
************************************************************************************/
|
|
||||||
static fixed_queue_t *xBtifQueue = NULL;
|
|
||||||
|
|
||||||
/** TODO: Move these to _common.h */
|
|
||||||
void bte_main_boot_entry(void *);
|
|
||||||
void bte_main_disable(void);
|
|
||||||
void bte_main_shutdown(void);
|
|
||||||
void btif_dm_execute_service_request(UINT16 event, char *p_param);
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_context_switched
|
|
||||||
**
|
|
||||||
** Description Callback used to execute transferred context callback
|
|
||||||
**
|
|
||||||
** p_msg : message to be executed in btif context
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
static void btif_context_switched(void *p_msg)
|
|
||||||
{
|
|
||||||
|
|
||||||
BTIF_TRACE_VERBOSE("btif_context_switched");
|
|
||||||
|
|
||||||
tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg;
|
|
||||||
|
|
||||||
/* each callback knows how to parse the data */
|
|
||||||
if (p->p_cb)
|
|
||||||
p->p_cb(p->event, p->p_param);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_transfer_context
|
|
||||||
**
|
|
||||||
** Description This function switches context to btif task
|
|
||||||
**
|
|
||||||
** p_cback : callback used to process message in btif context
|
|
||||||
** event : event id of message
|
|
||||||
** p_params : parameter area passed to callback (copied)
|
|
||||||
** param_len : length of parameter area
|
|
||||||
** p_copy_cback : If set this function will be invoked for deep copy
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTIF_COPY_CBACK *p_copy_cback)
|
|
||||||
{
|
|
||||||
tBTIF_CONTEXT_SWITCH_CBACK *p_msg;
|
|
||||||
|
|
||||||
BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
|
|
||||||
|
|
||||||
/* allocate and send message that will be executed in btif context */
|
|
||||||
if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
|
|
||||||
{
|
|
||||||
p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
|
|
||||||
p_msg->p_cb = p_cback;
|
|
||||||
|
|
||||||
p_msg->event = event; /* callback event */
|
|
||||||
|
|
||||||
/* check if caller has provided a copy callback to do the deep copy */
|
|
||||||
if (p_copy_cback)
|
|
||||||
{
|
|
||||||
p_copy_cback(event, p_msg->p_param, p_params);
|
|
||||||
}
|
|
||||||
else if (p_params)
|
|
||||||
{
|
|
||||||
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
|
|
||||||
}
|
|
||||||
|
|
||||||
btif_sendmsg(p_msg);
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* let caller deal with a failed allocation */
|
|
||||||
return BT_STATUS_NOMEM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int btif_is_enabled(void)
|
|
||||||
{
|
|
||||||
return (stack_manager_is_stack_running());
|
|
||||||
}
|
|
||||||
|
|
||||||
void btif_init_ok(void) {
|
|
||||||
BTIF_TRACE_DEBUG("btif_task: received trigger stack init event");
|
|
||||||
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_enable_bluetooth_evt
|
|
||||||
**
|
|
||||||
** Description Event indicating bluetooth enable is completed
|
|
||||||
** Notifies HAL user with updated adapter state
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
void btif_enable_bluetooth_evt(tBTA_STATUS status)
|
|
||||||
{
|
|
||||||
if (status == BTA_SUCCESS) {
|
|
||||||
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
|
|
||||||
} else {
|
|
||||||
future_ready(stack_manager_get_hack_future(), FUTURE_FAIL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_disable_bluetooth_evt
|
|
||||||
**
|
|
||||||
** Description Event notifying BT disable is now complete.
|
|
||||||
** Terminates main stack tasks and notifies HAL
|
|
||||||
** user with updated BT state.
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
void btif_disable_bluetooth_evt(void)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("%s", __FUNCTION__);
|
|
||||||
|
|
||||||
/* callback to HAL */
|
|
||||||
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_task
|
|
||||||
**
|
|
||||||
** Description BTIF task handler managing all messages being passed
|
|
||||||
** Bluetooth HAL and BTA.
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
static void bt_jni_msg_ready(fixed_queue_t *queue) {
|
|
||||||
BT_HDR *p_msg;
|
|
||||||
while (!fixed_queue_is_empty(queue)) {
|
|
||||||
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
|
|
||||||
BTIF_TRACE_VERBOSE("btif task fetched event %x", p_msg->event);
|
|
||||||
switch (p_msg->event) {
|
|
||||||
case BT_EVT_CONTEXT_SWITCH_EVT:
|
|
||||||
btif_context_switched(p_msg);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
BTIF_TRACE_ERROR("unhandled btif event (%d)", p_msg->event & BT_EVT_MASK); break;
|
|
||||||
}
|
|
||||||
GKI_freebuf(p_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_sendmsg
|
|
||||||
**
|
|
||||||
** Description Sends msg to BTIF task
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
void btif_sendmsg(void *p_msg)
|
|
||||||
{
|
|
||||||
fixed_queue_enqueue(btif_msg_queue, p_msg);
|
|
||||||
btif_thread_post(SIG_BTIF_WORK);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void btif_thread_post(uint32_t sig) {
|
|
||||||
TaskEvt_t *evt = (TaskEvt_t *)osi_malloc(sizeof(TaskEvt_t));
|
|
||||||
if (evt == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
evt->sig = sig;
|
|
||||||
evt->par = 0;
|
|
||||||
|
|
||||||
if (xQueueSend(xBtifQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
|
|
||||||
ets_printf("xBtifQueue failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_task_thread_handler
|
|
||||||
**
|
|
||||||
** Description Process BTif Task Thread.
|
|
||||||
******************************************************************************/
|
|
||||||
void btif_task_thread_handler(void *arg)
|
|
||||||
{
|
|
||||||
TaskEvt_t *e;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (pdTRUE == xQueueReceive(xBtifQueue, &e, (portTickType)portMAX_DELAY)) {
|
|
||||||
|
|
||||||
if (e->sig == SIG_BTIF_WORK) {
|
|
||||||
fixed_queue_process(btif_msg_queue);
|
|
||||||
}
|
|
||||||
osi_free(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_init_bluetooth
|
|
||||||
**
|
|
||||||
** Description Creates BTIF task and prepares BT scheduler for startup
|
|
||||||
**
|
|
||||||
** Returns bt_status_t
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_init_bluetooth(void) {
|
|
||||||
bte_main_boot_entry(btif_init_ok);
|
|
||||||
|
|
||||||
btif_msg_queue = fixed_queue_new(SIZE_MAX);
|
|
||||||
if (btif_msg_queue == NULL) {
|
|
||||||
goto error_exit;
|
|
||||||
}
|
|
||||||
xBtifQueue = xQueueCreate(60, sizeof(void *));
|
|
||||||
xTaskCreate(btif_task_thread_handler, "BtifT", 8192, NULL, configMAX_PRIORITIES - 1, &xBtifTaskHandle);
|
|
||||||
fixed_queue_register_dequeue(btif_msg_queue, bt_jni_msg_ready);
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
|
|
||||||
error_exit:;
|
|
||||||
btif_shutdown_bluetooth();
|
|
||||||
|
|
||||||
return BT_STATUS_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_enable_bluetooth
|
|
||||||
**
|
|
||||||
** Description Inititates shutdown of Bluetooth system.
|
|
||||||
** Any active links will be dropped and device entering
|
|
||||||
** non connectable/discoverable mode
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_enable_bluetooth(void)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("BTIF ENABLE BLUETOOTH");
|
|
||||||
|
|
||||||
BTA_EnableBluetooth(bte_dm_evt);
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_disable_bluetooth
|
|
||||||
**
|
|
||||||
** Description Inititates shutdown of Bluetooth system.
|
|
||||||
** Any active links will be dropped and device entering
|
|
||||||
** non connectable/discoverable mode
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_disable_bluetooth(void)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("BTIF DISABLE BLUETOOTH");
|
|
||||||
|
|
||||||
// btif_dm_on_disable();
|
|
||||||
/* cleanup rfcomm & l2cap api */
|
|
||||||
// btif_sock_cleanup();
|
|
||||||
// btif_pan_cleanup();
|
|
||||||
BTA_DisableBluetooth();
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_shutdown_bluetooth
|
|
||||||
**
|
|
||||||
** Description Finalizes BT scheduler shutdown and terminates BTIF
|
|
||||||
** task.
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
bt_status_t btif_shutdown_bluetooth(void)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("%s", __FUNCTION__);
|
|
||||||
|
|
||||||
fixed_queue_unregister_dequeue(btif_msg_queue);
|
|
||||||
fixed_queue_free(btif_msg_queue, NULL);
|
|
||||||
btif_msg_queue = NULL;
|
|
||||||
|
|
||||||
vTaskDelete(xBtifTaskHandle);
|
|
||||||
xBtifTaskHandle = NULL;
|
|
||||||
|
|
||||||
vQueueDelete(xBtifQueue);
|
|
||||||
xBtifQueue = NULL;
|
|
||||||
|
|
||||||
bte_main_shutdown();
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_get_enabled_services_mask
|
|
||||||
**
|
|
||||||
** Description Fetches currently enabled services
|
|
||||||
**
|
|
||||||
** Returns tBTA_SERVICE_MASK
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
tBTA_SERVICE_MASK btif_get_enabled_services_mask(void)
|
|
||||||
{
|
|
||||||
return btif_enabled_services;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_enable_service
|
|
||||||
**
|
|
||||||
** Description Enables the service 'service_ID' to the service_mask.
|
|
||||||
** Upon BT enable, BTIF core shall invoke the BTA APIs to
|
|
||||||
** enable the profiles
|
|
||||||
**
|
|
||||||
** Returns bt_status_t
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id)
|
|
||||||
{
|
|
||||||
tBTA_SERVICE_ID *p_id = &service_id;
|
|
||||||
|
|
||||||
/* If BT is enabled, we need to switch to BTIF context and trigger the
|
|
||||||
* enable for that profile
|
|
||||||
*
|
|
||||||
* Otherwise, we just set the flag. On BT_Enable, the DM will trigger
|
|
||||||
* enable for the profiles that have been enabled */
|
|
||||||
|
|
||||||
btif_enabled_services |= (1 << service_id);
|
|
||||||
|
|
||||||
BTIF_TRACE_DEBUG("%s: current services:0x%x", __FUNCTION__, btif_enabled_services);
|
|
||||||
|
|
||||||
if (btif_is_enabled()) {
|
|
||||||
btif_transfer_context(btif_dm_execute_service_request,
|
|
||||||
BTIF_DM_ENABLE_SERVICE,
|
|
||||||
(char*)p_id, sizeof(tBTA_SERVICE_ID), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_disable_service
|
|
||||||
**
|
|
||||||
** Description Disables the service 'service_ID' to the service_mask.
|
|
||||||
** Upon BT disable, BTIF core shall invoke the BTA APIs to
|
|
||||||
** disable the profiles
|
|
||||||
**
|
|
||||||
** Returns bt_status_t
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id)
|
|
||||||
{
|
|
||||||
tBTA_SERVICE_ID *p_id = &service_id;
|
|
||||||
|
|
||||||
/* If BT is enabled, we need to switch to BTIF context and trigger the
|
|
||||||
* disable for that profile so that the appropriate uuid_property_changed will
|
|
||||||
* be triggerred. Otherwise, we just need to clear the service_id in the mask
|
|
||||||
*/
|
|
||||||
|
|
||||||
btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1<<service_id));
|
|
||||||
|
|
||||||
BTIF_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services);
|
|
||||||
|
|
||||||
if (btif_is_enabled()) {
|
|
||||||
btif_transfer_context(btif_dm_execute_service_request,
|
|
||||||
BTIF_DM_DISABLE_SERVICE,
|
|
||||||
(char*)p_id, sizeof(tBTA_SERVICE_ID), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
@ -1,233 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009-2012 Broadcom Corporation
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
*
|
|
||||||
* Filename: btif_dm.c
|
|
||||||
*
|
|
||||||
* Description: Contains Device Management (DM) related functionality
|
|
||||||
*
|
|
||||||
*
|
|
||||||
***********************************************************************************/
|
|
||||||
|
|
||||||
#define LOG_TAG "bt_btif_dm"
|
|
||||||
|
|
||||||
// #include <assert.h>
|
|
||||||
// #include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
// #include <sys/types.h>
|
|
||||||
// #include <unistd.h>
|
|
||||||
|
|
||||||
// #include <hardware/bluetooth.h>
|
|
||||||
|
|
||||||
// #include <cutils/properties.h>
|
|
||||||
#include "gki.h"
|
|
||||||
#include "btu.h"
|
|
||||||
// #include "btcore/include/bdaddr.h"
|
|
||||||
#include "bta_api.h"
|
|
||||||
#include "btif_api.h"
|
|
||||||
#include "btif_util.h"
|
|
||||||
#include "btif_dm.h"
|
|
||||||
// #include "btif_storage.h"
|
|
||||||
// #include "btif_hh.h"
|
|
||||||
// #include "btif_config.h"
|
|
||||||
// #include "btif_sdp.h"
|
|
||||||
// #include "bta_gatt_api.h"
|
|
||||||
// #include "device/include/interop.h"
|
|
||||||
// #include "include/stack_config.h"
|
|
||||||
// #include "osi/include/log.h"
|
|
||||||
#include "allocator.h"
|
|
||||||
#include "btm_int.h"
|
|
||||||
#include "bt_defs.h"
|
|
||||||
#include "future.h"
|
|
||||||
#include "stack_manager.h"
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
** Constants & Macros
|
|
||||||
******************************************************************************/
|
|
||||||
#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Static variables
|
|
||||||
************************************************************************************/
|
|
||||||
/******************************************************************************
|
|
||||||
** Static functions
|
|
||||||
******************************************************************************/
|
|
||||||
/******************************************************************************
|
|
||||||
** Externs
|
|
||||||
******************************************************************************/
|
|
||||||
extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
** Functions
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
static void btif_dm_data_copy(uint16_t event, char *dst, char *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 (event == 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC *dm_sec)
|
|
||||||
{
|
|
||||||
if (event == BTA_DM_BLE_KEY_EVT) {
|
|
||||||
osi_free(dm_sec->ble_key.p_key_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
|
|
||||||
BOOLEAN b_enable)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("%s service_id: %d\n", __FUNCTION__, service_id);
|
|
||||||
/* Check the service_ID and invoke the profile's BT state changed API */
|
|
||||||
switch (service_id) {
|
|
||||||
case BTA_SDP_SERVICE_ID:
|
|
||||||
btif_sdp_execute_service(b_enable);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
BTIF_TRACE_ERROR("%s: Unknown service being enabled\n", __FUNCTION__);
|
|
||||||
return BT_STATUS_FAIL;
|
|
||||||
}
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void btif_dm_execute_service_request(UINT16 event, char *p_param)
|
|
||||||
{
|
|
||||||
BOOLEAN b_enable = FALSE;
|
|
||||||
if (event == BTIF_DM_ENABLE_SERVICE) {
|
|
||||||
b_enable = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_dm_upstreams_cback
|
|
||||||
**
|
|
||||||
** Description Executes UPSTREAMS events in btif context
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
|
|
||||||
{
|
|
||||||
tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
|
|
||||||
tBTA_SERVICE_MASK service_mask;
|
|
||||||
uint32_t i;
|
|
||||||
BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %d\n", event);
|
|
||||||
|
|
||||||
switch (event) {
|
|
||||||
case BTA_DM_ENABLE_EVT:
|
|
||||||
/* for each of the enabled services in the mask, trigger the profile
|
|
||||||
* enable */
|
|
||||||
service_mask = btif_get_enabled_services_mask();
|
|
||||||
for (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);
|
|
||||||
break;
|
|
||||||
case BTA_DM_DISABLE_EVT:
|
|
||||||
/* for each of the enabled services in the mask, trigger the profile
|
|
||||||
* disable */
|
|
||||||
service_mask = btif_get_enabled_services_mask();
|
|
||||||
for (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();
|
|
||||||
break;
|
|
||||||
case BTA_DM_PIN_REQ_EVT:
|
|
||||||
case BTA_DM_AUTH_CMPL_EVT:
|
|
||||||
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:
|
|
||||||
BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)\n", event );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
btif_dm_data_free(event, p_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function bte_dm_evt
|
|
||||||
**
|
|
||||||
** Description Switches context from BTE to BTIF for all DM events
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
|
|
||||||
{
|
|
||||||
/* switch context to btif task context (copy full union size for convenience) */
|
|
||||||
bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
|
|
||||||
(void*)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
|
|
||||||
|
|
||||||
/* catch any failed context transfers */
|
|
||||||
ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed\n", status);
|
|
||||||
}
|
|
@ -1,175 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2014 Samsung System LSI
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
*
|
|
||||||
* Filename: btif_sdp.c
|
|
||||||
* Description: SDP Bluetooth Interface.
|
|
||||||
* Implements the generic message handling and search functionality.
|
|
||||||
* References btif_sdp_server.c for SDP record creation.
|
|
||||||
*
|
|
||||||
***********************************************************************************/
|
|
||||||
|
|
||||||
#include "btif_sdp.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define LOG_TAG "BTIF_SDP"
|
|
||||||
#include "btif_common.h"
|
|
||||||
#include "btif_util.h"
|
|
||||||
#include "bta_api.h"
|
|
||||||
|
|
||||||
#include "bt_sdp_api.h"
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
** Functions implemented in sdp_server.c
|
|
||||||
******************************************************************************/
|
|
||||||
bt_status_t sdp_server_init();
|
|
||||||
void sdp_server_cleanup();
|
|
||||||
void on_create_record_event(int handle);
|
|
||||||
void on_remove_record_event(int handle);
|
|
||||||
|
|
||||||
// Utility functions:
|
|
||||||
int get_sdp_records_size(bluetooth_sdp_record* in_record, int count);
|
|
||||||
void copy_sdp_records(bluetooth_sdp_record* in_records,
|
|
||||||
bluetooth_sdp_record* out_records, int count);
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
** Static variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
static btsdp_callbacks_t *bt_sdp_callbacks = NULL;
|
|
||||||
|
|
||||||
static void btif_sdp_search_comp_evt(UINT16 event, char *p_param)
|
|
||||||
{
|
|
||||||
bt_sdp_search_comp_t *evt_data = (bt_sdp_search_comp_t *) p_param;
|
|
||||||
bt_bdaddr_t addr;
|
|
||||||
BTIF_TRACE_DEBUG("%s: event = %d\n", __FUNCTION__, event);
|
|
||||||
|
|
||||||
if (event != BT_SDP_SEARCH_COMP_EVT)
|
|
||||||
return;
|
|
||||||
|
|
||||||
bdcpy(addr.address, evt_data->remote_addr);
|
|
||||||
|
|
||||||
HAL_CBACK(bt_sdp_callbacks, sdp_search_cb, evt_data->status,
|
|
||||||
&addr, (uint8_t*)(evt_data->uuid.uu.uuid128),
|
|
||||||
evt_data->record_count, evt_data->records);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sdp_search_comp_copy_cb(UINT16 event, char *p_dest, char *p_src)
|
|
||||||
{
|
|
||||||
bt_sdp_search_comp_t *p_dest_data = (bt_sdp_search_comp_t *) p_dest;
|
|
||||||
bt_sdp_search_comp_t *p_src_data = (bt_sdp_search_comp_t *) p_src;
|
|
||||||
if (!p_src)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event != BT_SDP_SEARCH_COMP_EVT)
|
|
||||||
return;
|
|
||||||
|
|
||||||
memcpy(p_dest_data, p_src_data, sizeof(bt_sdp_search_comp_t));
|
|
||||||
|
|
||||||
copy_sdp_records(p_src_data->records, p_dest_data->records, p_src_data->record_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void sdp_dm_cback(bt_sdp_evt_t event, bt_sdp_t *p_data, void * user_data)
|
|
||||||
{
|
|
||||||
switch (event)
|
|
||||||
{
|
|
||||||
case BT_SDP_SEARCH_COMP_EVT:
|
|
||||||
{
|
|
||||||
int size = sizeof(bt_sdp_t);
|
|
||||||
size += get_sdp_records_size(p_data->sdp_search_comp.records,
|
|
||||||
p_data->sdp_search_comp.record_count);
|
|
||||||
|
|
||||||
BTIF_TRACE_DEBUG("%s: stat %d, record_cnt = %d\n", __FUNCTION__, p_data->sdp_search_comp.status, p_data->sdp_search_comp.record_count);
|
|
||||||
/* need to deep copy the record content */
|
|
||||||
btif_transfer_context(btif_sdp_search_comp_evt, event,
|
|
||||||
(char*)p_data, size, sdp_search_comp_copy_cb);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BT_SDP_CREATE_RECORD_USER_EVT:
|
|
||||||
{
|
|
||||||
on_create_record_event((int)user_data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BT_SDP_REMOVE_RECORD_USER_EVT:
|
|
||||||
{
|
|
||||||
on_remove_record_event((int)user_data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpInit(btsdp_callbacks_t *callbacks)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__);
|
|
||||||
|
|
||||||
bt_sdp_callbacks = callbacks;
|
|
||||||
sdp_server_init();
|
|
||||||
|
|
||||||
btif_enable_service(BTA_SDP_SERVICE_ID);
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpDeinit(void)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__);
|
|
||||||
|
|
||||||
bt_sdp_callbacks = NULL;
|
|
||||||
sdp_server_cleanup();
|
|
||||||
btif_disable_service(BTA_SDP_SERVICE_ID);
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpSearch(bt_bdaddr_t *bd_addr, const uint8_t* uuid)
|
|
||||||
{
|
|
||||||
esp_bt_uuid_t sdp_uuid;
|
|
||||||
sdp_uuid.len = 16;
|
|
||||||
memcpy(sdp_uuid.uu.uuid128, uuid, sizeof(sdp_uuid.uu.uuid128));
|
|
||||||
|
|
||||||
esp_bt_sdp_search(bd_addr->address, &sdp_uuid);
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_sdp_execute_service
|
|
||||||
**
|
|
||||||
** Description Initializes/Shuts down the service
|
|
||||||
**
|
|
||||||
** Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_sdp_execute_service(BOOLEAN b_enable)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("%s enable:%d\n", __FUNCTION__, b_enable);
|
|
||||||
|
|
||||||
if (b_enable) {
|
|
||||||
esp_bt_sdp_enable(sdp_dm_cback);
|
|
||||||
} else {
|
|
||||||
/* This is called on BT disable so no need to extra cleanup */
|
|
||||||
}
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
@ -1,777 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2014 Samsung System LSI
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
*
|
|
||||||
* Filename: btif_sdp_server.c
|
|
||||||
* Description: SDP server Bluetooth Interface to create and remove SDP records.
|
|
||||||
* To be used in combination with the RFCOMM/L2CAP(LE) sockets.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
***********************************************************************************/
|
|
||||||
|
|
||||||
#include "btif_sdp.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#define LOG_TAG "BTIF_SDP_SERVER"
|
|
||||||
#include "allocator.h"
|
|
||||||
#include "btif_common.h"
|
|
||||||
#include "bta_sys.h"
|
|
||||||
#include "utl.h"
|
|
||||||
#include "bt_sdp_api.h"
|
|
||||||
|
|
||||||
static pthread_mutex_t sdp_lock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The need for a state variable have been reduced to two states.
|
|
||||||
* The remaining state control is handled by program flow
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
SDP_RECORD_FREE = 0,
|
|
||||||
SDP_RECORD_ALLOCED,
|
|
||||||
} sdp_state_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
sdp_state_t state;
|
|
||||||
int sdp_handle;
|
|
||||||
bluetooth_sdp_record* record_data;
|
|
||||||
} sdp_slot_t;
|
|
||||||
|
|
||||||
#define MAX_SDP_SLOTS 128
|
|
||||||
static sdp_slot_t sdp_slots[MAX_SDP_SLOTS];
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* LOCAL Functions
|
|
||||||
*****************************************************************************/
|
|
||||||
static int add_maps_sdp(const bluetooth_sdp_mas_record* rec);
|
|
||||||
static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec);
|
|
||||||
static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec);
|
|
||||||
static int add_opps_sdp(const bluetooth_sdp_ops_record* rec);
|
|
||||||
static int add_saps_sdp(const bluetooth_sdp_sap_record* rec);
|
|
||||||
bt_status_t remove_sdp_record(int record_id);
|
|
||||||
static int free_sdp_slot(int id);
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* WARNING: Functions below are not called in BTU context.
|
|
||||||
* Introduced to make it possible to create SDP records from JAVA with both a
|
|
||||||
* RFCOMM channel and a L2CAP PSM.
|
|
||||||
* Overall architecture:
|
|
||||||
* 1) JAVA calls createRecord() which returns a pseudo ID which at a later
|
|
||||||
* point will be linked to a specific SDP handle.
|
|
||||||
* 2) createRecord() requests the BTU task(thread) to call a callback in SDP
|
|
||||||
* which creates the actual record, and updates the ID<->SDPHandle map
|
|
||||||
* based on the ID beeing passed to BTA as user_data.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
static void init_sdp_slots()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
memset(sdp_slots, 0, sizeof(sdp_slot_t)*MAX_SDP_SLOTS);
|
|
||||||
/* if SDP_RECORD_FREE is zero - no need to set the value */
|
|
||||||
if(SDP_RECORD_FREE != 0) {
|
|
||||||
for(i = 0; i < MAX_SDP_SLOTS; i++)
|
|
||||||
{
|
|
||||||
sdp_slots[i].state = SDP_RECORD_FREE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t sdp_server_init()
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
|
|
||||||
pthread_mutex_init(&sdp_lock, NULL);
|
|
||||||
init_sdp_slots();
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sdp_server_cleanup()
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < MAX_SDP_SLOTS; i++)
|
|
||||||
{
|
|
||||||
/*remove_sdp_record(i); we cannot send messages to the other threads, since they might
|
|
||||||
* have been shut down already. Just do local cleanup.
|
|
||||||
*/
|
|
||||||
free_sdp_slot(i);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
pthread_mutex_destroy(&sdp_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_sdp_records_size(bluetooth_sdp_record* in_record, int count) {
|
|
||||||
bluetooth_sdp_record* record = in_record;
|
|
||||||
int records_size = 0;
|
|
||||||
int i;
|
|
||||||
for(i=0; i<count; i++) {
|
|
||||||
record = &in_record[i];
|
|
||||||
records_size += sizeof(bluetooth_sdp_record);
|
|
||||||
records_size += record->hdr.service_name_length;
|
|
||||||
if(record->hdr.service_name_length > 0){
|
|
||||||
records_size++; /* + '\0' termination of string */
|
|
||||||
}
|
|
||||||
records_size += record->hdr.user1_ptr_len;
|
|
||||||
records_size += record->hdr.user2_ptr_len;
|
|
||||||
}
|
|
||||||
return records_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Deep copy all content of in_records into out_records.
|
|
||||||
* out_records must point to a chunk of memory large enough to contain all
|
|
||||||
* the data. Use getSdpRecordsSize() to calculate the needed size. */
|
|
||||||
void copy_sdp_records(bluetooth_sdp_record* in_records,
|
|
||||||
bluetooth_sdp_record* out_records, int count) {
|
|
||||||
int i;
|
|
||||||
bluetooth_sdp_record* in_record;
|
|
||||||
bluetooth_sdp_record* out_record;
|
|
||||||
char* free_ptr = (char*)(&out_records[count]); /* set pointer to after the last entry */
|
|
||||||
|
|
||||||
for(i=0; i<count; i++) {
|
|
||||||
in_record = &in_records[i];
|
|
||||||
out_record = &out_records[i];
|
|
||||||
*out_record = *in_record;
|
|
||||||
|
|
||||||
if(in_record->hdr.service_name == NULL || in_record->hdr.service_name_length == 0) {
|
|
||||||
out_record->hdr.service_name = NULL;
|
|
||||||
out_record->hdr.service_name_length = 0;
|
|
||||||
} else {
|
|
||||||
out_record->hdr.service_name = free_ptr; // Update service_name pointer
|
|
||||||
// Copy string
|
|
||||||
memcpy(free_ptr, in_record->hdr.service_name, in_record->hdr.service_name_length);
|
|
||||||
free_ptr += in_record->hdr.service_name_length;
|
|
||||||
*(free_ptr) = '\0'; // Set '\0' termination of string
|
|
||||||
free_ptr++;
|
|
||||||
}
|
|
||||||
if(in_record->hdr.user1_ptr != NULL) {
|
|
||||||
out_record->hdr.user1_ptr = (UINT8*)free_ptr; // Update pointer
|
|
||||||
memcpy(free_ptr, in_record->hdr.user1_ptr, in_record->hdr.user1_ptr_len); // Copy content
|
|
||||||
free_ptr += in_record->hdr.user1_ptr_len;
|
|
||||||
}
|
|
||||||
if(in_record->hdr.user2_ptr != NULL) {
|
|
||||||
out_record->hdr.user2_ptr = (UINT8*)free_ptr; // Update pointer
|
|
||||||
memcpy(free_ptr, in_record->hdr.user2_ptr, in_record->hdr.user2_ptr_len); // Copy content
|
|
||||||
free_ptr += in_record->hdr.user2_ptr_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reserve a slot in sdp_slots, copy data and set a reference to the copy.
|
|
||||||
* The record_data will contain both the record and any data pointed to by
|
|
||||||
* the record.
|
|
||||||
* Currently this covers:
|
|
||||||
* service_name string,
|
|
||||||
* user1_ptr and
|
|
||||||
* user2_ptr. */
|
|
||||||
static int alloc_sdp_slot(bluetooth_sdp_record* in_record) {
|
|
||||||
int i;
|
|
||||||
int record_size = get_sdp_records_size(in_record, 1);
|
|
||||||
bluetooth_sdp_record* record = osi_malloc(record_size);
|
|
||||||
|
|
||||||
copy_sdp_records(in_record, record, 1);
|
|
||||||
|
|
||||||
/* We are optimists here, and preallocate the record.
|
|
||||||
* This is to reduce the time we hold the sdp_lock. */
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
for(i = 0; i < MAX_SDP_SLOTS; i++)
|
|
||||||
{
|
|
||||||
if(sdp_slots[i].state == SDP_RECORD_FREE) {
|
|
||||||
sdp_slots[i].state = SDP_RECORD_ALLOCED;
|
|
||||||
sdp_slots[i].record_data = record;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
if(i >= MAX_SDP_SLOTS) {
|
|
||||||
APPL_TRACE_ERROR("%s() failed - no more free slots!\n", __func__);
|
|
||||||
/* Rearly the optimist is too optimistic, and cleanup is needed...*/
|
|
||||||
osi_free(record);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int free_sdp_slot(int id) {
|
|
||||||
int handle = -1;
|
|
||||||
bluetooth_sdp_record* record = NULL;
|
|
||||||
if(id >= MAX_SDP_SLOTS) {
|
|
||||||
APPL_TRACE_ERROR("%s() failed - id %d is invalid\n", __func__, id);
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
handle = sdp_slots[id].sdp_handle;
|
|
||||||
sdp_slots[id].sdp_handle = 0;
|
|
||||||
if(sdp_slots[id].state != SDP_RECORD_FREE)
|
|
||||||
{
|
|
||||||
/* safe a copy of the pointer, and free after unlock() */
|
|
||||||
record = sdp_slots[id].record_data;
|
|
||||||
}
|
|
||||||
sdp_slots[id].state = SDP_RECORD_FREE;
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
|
|
||||||
if(record != NULL) {
|
|
||||||
osi_free(record);
|
|
||||||
} else {
|
|
||||||
// Record have already been freed
|
|
||||||
handle = -1;
|
|
||||||
}
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Use this to get a reference to a SDP slot AND change the state to
|
|
||||||
* SDP_RECORD_CREATE_INITIATED.
|
|
||||||
*/
|
|
||||||
static const sdp_slot_t* start_create_sdp(int id) {
|
|
||||||
sdp_slot_t* sdp_slot;
|
|
||||||
if(id >= MAX_SDP_SLOTS) {
|
|
||||||
APPL_TRACE_ERROR("%s() failed - id %d is invalid\n", __func__, id);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
if(sdp_slots[id].state == SDP_RECORD_ALLOCED) {
|
|
||||||
sdp_slot = &(sdp_slots[id]);
|
|
||||||
} else {
|
|
||||||
/* The record have been removed before this event occurred - e.g. deinit */
|
|
||||||
sdp_slot = NULL;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
if(sdp_slot == NULL) {
|
|
||||||
APPL_TRACE_ERROR("%s() failed - state for id %d is \n"
|
|
||||||
"sdp_slots[id].state = %d expected %d\n", __func__,
|
|
||||||
id, sdp_slots[id].state, SDP_RECORD_ALLOCED);
|
|
||||||
}
|
|
||||||
return sdp_slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_sdp_handle(int id, int handle) {
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
sdp_slots[id].sdp_handle = handle;
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
BTIF_TRACE_DEBUG("%s() id=%d to handle=0x%08x\n", __FUNCTION__, id, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpCreateRecord(bluetooth_sdp_record *record, int* record_handle) {
|
|
||||||
int handle;
|
|
||||||
|
|
||||||
handle = alloc_sdp_slot(record);
|
|
||||||
BTIF_TRACE_DEBUG("%s() handle = 0x%08x\n", __FUNCTION__, handle);
|
|
||||||
|
|
||||||
if(handle < 0)
|
|
||||||
return BT_STATUS_FAIL;
|
|
||||||
|
|
||||||
esp_bt_sdp_create_record_by_user((void*) handle);
|
|
||||||
|
|
||||||
*record_handle = handle;
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpRemoveRecord(int record_handle) {
|
|
||||||
int handle;
|
|
||||||
|
|
||||||
/* Get the Record handle, and free the slot */
|
|
||||||
handle = free_sdp_slot(record_handle);
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s id=%d to handle=0x%08x\n",
|
|
||||||
__FUNCTION__, record_handle, handle);
|
|
||||||
|
|
||||||
/* Pass the actual record handle */
|
|
||||||
if(handle > 0) {
|
|
||||||
esp_bt_sdp_remove_record_by_user((void *)handle);
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s - record already removed - or never created\n", __FUNCTION__);
|
|
||||||
return BT_STATUS_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* CALLBACK FUNCTIONS
|
|
||||||
* Called in BTA context to create/remove SDP records.
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
void on_create_record_event(int id) {
|
|
||||||
/*
|
|
||||||
* 1) Fetch the record pointer, and change its state?
|
|
||||||
* 2) switch on the type to create the correct record
|
|
||||||
* 3) Update state on completion
|
|
||||||
* 4) What to do at fail?
|
|
||||||
* */
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
|
|
||||||
const sdp_slot_t* sdp_slot = start_create_sdp(id);
|
|
||||||
/* In the case we are shutting down, sdp_slot is NULL */
|
|
||||||
if(sdp_slot != NULL) {
|
|
||||||
bluetooth_sdp_record* record = sdp_slot->record_data;
|
|
||||||
int handle = -1;
|
|
||||||
switch(record->hdr.type) {
|
|
||||||
case SDP_TYPE_MAP_MAS:
|
|
||||||
handle = add_maps_sdp(&record->mas);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_MAP_MNS:
|
|
||||||
handle = add_mapc_sdp(&record->mns);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_PBAP_PSE:
|
|
||||||
handle = add_pbaps_sdp(&record->pse);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_OPP_SERVER:
|
|
||||||
handle = add_opps_sdp(&record->ops);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_SAP_SERVER:
|
|
||||||
handle = add_saps_sdp(&record->sap);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_PBAP_PCE:
|
|
||||||
// break; not yet supported
|
|
||||||
default:
|
|
||||||
BTIF_TRACE_DEBUG("Record type %d is not supported\n",record->hdr.type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(handle != -1) {
|
|
||||||
set_sdp_handle(id, handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_remove_record_event(int handle) {
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
|
|
||||||
|
|
||||||
// User data carries the actual SDP handle, not the ID.
|
|
||||||
if(handle != -1 && handle != 0) {
|
|
||||||
BOOLEAN result;
|
|
||||||
result = SDP_DeleteRecord( handle );
|
|
||||||
if(result == FALSE) {
|
|
||||||
BTIF_TRACE_ERROR(" Unable to remove handle 0x%08x\n", handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****
|
|
||||||
* Below the actual functions accessing BTA context data - hence only call from BTA context!
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Create a MAP MAS SDP record based on information stored in a bluetooth_sdp_mas_record */
|
|
||||||
static int add_maps_sdp(const bluetooth_sdp_mas_record* rec)
|
|
||||||
{
|
|
||||||
|
|
||||||
sdp_proto_elem_t protoList[3];
|
|
||||||
UINT16 service = UUID_SERVCLASS_MESSAGE_ACCESS;
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
UINT8 temp[4];
|
|
||||||
UINT8* p_temp = temp;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): MASID = 0x%02x, scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
|
|
||||||
rec->mas_instance_id, rec->hdr.rfcomm_channel_number,
|
|
||||||
rec->hdr.l2cap_psm, rec->hdr.service_name);
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG(" msg_types: 0x%02x, feature_bits: 0x%08x\n",
|
|
||||||
rec->supported_message_types, rec->supported_features);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s() - Unable to register MAPS Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add service class */
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
|
|
||||||
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
|
|
||||||
|
|
||||||
/* add protocol list, including RFCOMM scn */
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
|
|
||||||
protoList[2].num_params = 0;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
|
|
||||||
|
|
||||||
/* Add a name entry */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
/* Add in the Bluetooth Profile Descriptor List */
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_MAP_PROFILE,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
/* Add MAS instance ID */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAS_INSTANCE_ID, UINT_DESC_TYPE,
|
|
||||||
(UINT32)1, (UINT8*)&rec->mas_instance_id);
|
|
||||||
|
|
||||||
/* Add supported message types */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_SUPPORTED_MSG_TYPE, UINT_DESC_TYPE,
|
|
||||||
(UINT32)1, (UINT8*)&rec->supported_message_types);
|
|
||||||
|
|
||||||
/* Add supported feature */
|
|
||||||
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAP_SUPPORTED_FEATURES,
|
|
||||||
UINT_DESC_TYPE, (UINT32)4, temp);
|
|
||||||
|
|
||||||
/* Add the L2CAP PSM if present */
|
|
||||||
if(rec->hdr.l2cap_psm != -1) {
|
|
||||||
p_temp = temp;// The macro modifies p_temp, hence rewind.
|
|
||||||
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
|
|
||||||
UINT_DESC_TYPE, (UINT32)2, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the service browseable */
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Create a MAP MNS SDP record based on information stored in a bluetooth_sdp_mns_record */
|
|
||||||
static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec)
|
|
||||||
{
|
|
||||||
|
|
||||||
sdp_proto_elem_t protoList [3];
|
|
||||||
UINT16 service = UUID_SERVCLASS_MESSAGE_NOTIFICATION;
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
UINT8 temp[4];
|
|
||||||
UINT8* p_temp = temp;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
|
|
||||||
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG(" feature_bits: 0x%08x\n", rec->supported_features);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s(): Unable to register MAP Notification Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add service class */
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
|
|
||||||
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
|
|
||||||
|
|
||||||
/* add protocol list, including RFCOMM scn */
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
|
|
||||||
protoList[2].num_params = 0;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
|
|
||||||
|
|
||||||
/* Add a name entry */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
/* Add in the Bluetooth Profile Descriptor List */
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_MAP_PROFILE,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
/* Add supported feature */
|
|
||||||
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAP_SUPPORTED_FEATURES,
|
|
||||||
UINT_DESC_TYPE, (UINT32)4, temp);
|
|
||||||
|
|
||||||
/* Add the L2CAP PSM if present */
|
|
||||||
if(rec->hdr.l2cap_psm != -1) {
|
|
||||||
p_temp = temp;// The macro modifies p_temp, hence rewind.
|
|
||||||
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
|
|
||||||
UINT_DESC_TYPE, (UINT32)2, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the service browseable */
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a PBAP Server SDP record based on information stored in a bluetooth_sdp_pse_record */
|
|
||||||
static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec)
|
|
||||||
{
|
|
||||||
|
|
||||||
sdp_proto_elem_t protoList [3];
|
|
||||||
UINT16 service = UUID_SERVCLASS_PBAP_PSE;
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
UINT8 temp[4];
|
|
||||||
UINT8* p_temp = temp;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
|
|
||||||
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG(" supported_repositories: 0x%08x, feature_bits: 0x%08x\n",
|
|
||||||
rec->supported_repositories, rec->supported_features);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s(): Unable to register PBAP Server Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add service class */
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
|
|
||||||
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
|
|
||||||
|
|
||||||
/* add protocol list, including RFCOMM scn */
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
|
|
||||||
protoList[2].num_params = 0;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
|
|
||||||
|
|
||||||
/* Add a name entry */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
/* Add in the Bluetooth Profile Descriptor List */
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_PHONE_ACCESS,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
/* Add supported repositories 1 byte */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_SUPPORTED_REPOSITORIES,
|
|
||||||
UINT_DESC_TYPE, (UINT32)1, (UINT8*)&rec->supported_repositories);
|
|
||||||
|
|
||||||
/* Add supported feature 4 bytes*/
|
|
||||||
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_PBAP_SUPPORTED_FEATURES,
|
|
||||||
UINT_DESC_TYPE, (UINT32)4, temp);
|
|
||||||
|
|
||||||
/* Add the L2CAP PSM if present */
|
|
||||||
if(rec->hdr.l2cap_psm != -1) {
|
|
||||||
p_temp = temp;// The macro modifies p_temp, hence rewind.
|
|
||||||
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
|
|
||||||
UINT_DESC_TYPE, (UINT32)2, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the service browseable */
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Create a OPP Server SDP record based on information stored in a bluetooth_sdp_ops_record */
|
|
||||||
static int add_opps_sdp(const bluetooth_sdp_ops_record* rec)
|
|
||||||
{
|
|
||||||
|
|
||||||
sdp_proto_elem_t protoList [3];
|
|
||||||
UINT16 service = UUID_SERVCLASS_OBEX_OBJECT_PUSH;
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
UINT8 type_len[rec->supported_formats_list_len];
|
|
||||||
UINT8 desc_type[rec->supported_formats_list_len];
|
|
||||||
UINT8 *type_value[rec->supported_formats_list_len];
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
UINT8 temp[4];
|
|
||||||
UINT8* p_temp = temp;
|
|
||||||
tBTA_UTL_COD cod;
|
|
||||||
int i,j;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
|
|
||||||
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG(" supported formats count: %d\n",
|
|
||||||
rec->supported_formats_list_len);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s(): Unable to register Object Push Server Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add service class */
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
|
|
||||||
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
|
|
||||||
|
|
||||||
/* add protocol list, including RFCOMM scn */
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
|
|
||||||
protoList[2].num_params = 0;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
|
|
||||||
|
|
||||||
/* Add a name entry */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
/* Add in the Bluetooth Profile Descriptor List */
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_OBEX_OBJECT_PUSH,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
/* add sequence for supported types */
|
|
||||||
for (i = 0, j = 0; i < rec->supported_formats_list_len; i++)
|
|
||||||
{
|
|
||||||
type_value[j] = (UINT8 *) &rec->supported_formats_list[i];
|
|
||||||
desc_type[j] = UINT_DESC_TYPE;
|
|
||||||
type_len[j++] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
status &= esp_bt_sdp_add_sequence(sdp_handle, (UINT16) ATTR_ID_SUPPORTED_FORMATS_LIST,
|
|
||||||
(UINT8) rec->supported_formats_list_len, desc_type, type_len, type_value);
|
|
||||||
|
|
||||||
/* Add the L2CAP PSM if present */
|
|
||||||
if(rec->hdr.l2cap_psm != -1) {
|
|
||||||
p_temp = temp;// The macro modifies p_temp, hence rewind.
|
|
||||||
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
|
|
||||||
UINT_DESC_TYPE, (UINT32)2, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the service browseable */
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* set class of device */
|
|
||||||
cod.service = BTM_COD_SERVICE_OBJ_TRANSFER;
|
|
||||||
utl_set_device_class(&cod, BTA_UTL_SET_COD_SERVICE_CLASS);
|
|
||||||
|
|
||||||
bta_sys_add_uuid(service); /* UUID_SERVCLASS_OBEX_OBJECT_PUSH */
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a Sim Access Profile SDP record based on information stored in a bluetooth_sdp_sap_record.
|
|
||||||
static int add_saps_sdp(const bluetooth_sdp_sap_record* rec)
|
|
||||||
{
|
|
||||||
sdp_proto_elem_t protoList [2];
|
|
||||||
UINT16 services[2];
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): scn 0x%02x, service name %s\n", __func__,
|
|
||||||
rec->hdr.rfcomm_channel_number, rec->hdr.service_name);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s(): Unable to register SAPS Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
services[0] = UUID_SERVCLASS_SAP;
|
|
||||||
services[1] = UUID_SERVCLASS_GENERIC_TELEPHONY;
|
|
||||||
|
|
||||||
// add service class
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 2, services);
|
|
||||||
memset(protoList, 0, 2 * sizeof(sdp_proto_elem_t));
|
|
||||||
|
|
||||||
// add protocol list, including RFCOMM scn
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 2, protoList);
|
|
||||||
|
|
||||||
// Add a name entry
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
// Add in the Bluetooth Profile Descriptor List
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_SAP,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
// Make the service browseable
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s(): FAILED deleting record\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bta_sys_add_uuid(UUID_SERVCLASS_SAP);
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
@ -1,159 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014 The Android Open Source Project
|
|
||||||
* Copyright (C) 2009-2012 Broadcom Corporation
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
*
|
|
||||||
* Filename: btif_util.c
|
|
||||||
*
|
|
||||||
* Description: Miscellaneous helper functions
|
|
||||||
*
|
|
||||||
*
|
|
||||||
***********************************************************************************/
|
|
||||||
|
|
||||||
// #include <hardware/bluetooth.h>
|
|
||||||
// #include <hardware/bt_hf.h>
|
|
||||||
// #include <hardware/bt_av.h>
|
|
||||||
// #include <netinet/in.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define LOG_TAG "bt_btif_util"
|
|
||||||
// #include "btif_common.h"
|
|
||||||
// #include "bta_api.h"
|
|
||||||
// #include "gki.h"
|
|
||||||
// #include "btu.h"
|
|
||||||
// #include "bte.h"
|
|
||||||
// #include "btif_dm.h"
|
|
||||||
#include "btif_util.h"
|
|
||||||
// #include "bta_ag_api.h"
|
|
||||||
// #include "bta_av_api.h"
|
|
||||||
// #include "bta_hh_api.h"
|
|
||||||
// #include "bta_hf_client_api.h"
|
|
||||||
// #include "avrc_defs.h"
|
|
||||||
#include "bt_defs.h"
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Constants & Macros
|
|
||||||
************************************************************************************/
|
|
||||||
#define ISDIGIT(a) ((a>='0') && (a<='9'))
|
|
||||||
#define ISXDIGIT(a) (((a>='0') && (a<='9'))||((a>='A') && (a<='F'))||((a>='a') && (a<='f')))
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Local type definitions
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Static variables
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Static functions
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Externs
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Functions
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
** Logging helper functions
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
UINT32 devclass2uint(DEV_CLASS dev_class)
|
|
||||||
{
|
|
||||||
UINT32 cod = 0;
|
|
||||||
|
|
||||||
if(dev_class != NULL)
|
|
||||||
{
|
|
||||||
/* if COD is 0, irrespective of the device type set it to Unclassified device */
|
|
||||||
cod = (dev_class[2]) | (dev_class[1] << 8) | (dev_class[0] << 16);
|
|
||||||
}
|
|
||||||
return cod;
|
|
||||||
}
|
|
||||||
void uint2devclass(UINT32 cod, DEV_CLASS dev_class)
|
|
||||||
{
|
|
||||||
dev_class[2] = (UINT8)cod;
|
|
||||||
dev_class[1] = (UINT8)(cod >> 8);
|
|
||||||
dev_class[0] = (UINT8)(cod >> 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const UINT8 sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
|
||||||
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
|
|
||||||
|
|
||||||
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128)
|
|
||||||
{
|
|
||||||
uint16_t uuid16_bo;
|
|
||||||
memset(uuid128, 0, sizeof(bt_uuid_t));
|
|
||||||
|
|
||||||
memcpy(uuid128->uu, sdp_base_uuid, MAX_UUID_SIZE);
|
|
||||||
uuid16_bo = ntohs(uuid16);
|
|
||||||
memcpy(uuid128->uu + 2, &uuid16_bo, sizeof(uint16_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
void string_to_uuid(char *str, bt_uuid_t *p_uuid)
|
|
||||||
{
|
|
||||||
uint32_t uuid0, uuid4;
|
|
||||||
uint16_t uuid1, uuid2, uuid3, uuid5;
|
|
||||||
|
|
||||||
sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
|
|
||||||
&uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
|
|
||||||
|
|
||||||
uuid0 = htonl(uuid0);
|
|
||||||
uuid1 = htons(uuid1);
|
|
||||||
uuid2 = htons(uuid2);
|
|
||||||
uuid3 = htons(uuid3);
|
|
||||||
uuid4 = htonl(uuid4);
|
|
||||||
uuid5 = htons(uuid5);
|
|
||||||
|
|
||||||
memcpy(&(p_uuid->uu[0]), &uuid0, 4);
|
|
||||||
memcpy(&(p_uuid->uu[4]), &uuid1, 2);
|
|
||||||
memcpy(&(p_uuid->uu[6]), &uuid2, 2);
|
|
||||||
memcpy(&(p_uuid->uu[8]), &uuid3, 2);
|
|
||||||
memcpy(&(p_uuid->uu[10]), &uuid4, 4);
|
|
||||||
memcpy(&(p_uuid->uu[14]), &uuid5, 2);
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str)
|
|
||||||
{
|
|
||||||
uint32_t uuid0, uuid4;
|
|
||||||
uint16_t uuid1, uuid2, uuid3, uuid5;
|
|
||||||
|
|
||||||
memcpy(&uuid0, &(p_uuid->uu[0]), 4);
|
|
||||||
memcpy(&uuid1, &(p_uuid->uu[4]), 2);
|
|
||||||
memcpy(&uuid2, &(p_uuid->uu[6]), 2);
|
|
||||||
memcpy(&uuid3, &(p_uuid->uu[8]), 2);
|
|
||||||
memcpy(&uuid4, &(p_uuid->uu[10]), 4);
|
|
||||||
memcpy(&uuid5, &(p_uuid->uu[14]), 2);
|
|
||||||
|
|
||||||
sprintf((char *)str, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
|
|
||||||
ntohl(uuid0), ntohs(uuid1),
|
|
||||||
ntohs(uuid2), ntohs(uuid3),
|
|
||||||
ntohl(uuid4), ntohs(uuid5));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
@ -1,160 +0,0 @@
|
|||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "btif_stack_manager.h"
|
|
||||||
#include "stack_manager.h"
|
|
||||||
#include "bt_defs.h"
|
|
||||||
#include "bt_trace.h"
|
|
||||||
#include "future.h"
|
|
||||||
#include "btif_common.h"
|
|
||||||
#include "btif_api.h"
|
|
||||||
#include "btif_dm.h"
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
** Constants & Macros
|
|
||||||
************************************************************************************/
|
|
||||||
/************************************************************************************
|
|
||||||
** Local type definitions
|
|
||||||
************************************************************************************/
|
|
||||||
/************************************************************************************
|
|
||||||
** Static variables
|
|
||||||
************************************************************************************/
|
|
||||||
static bool stack_is_initialized = false;
|
|
||||||
static bool stack_is_running = false;
|
|
||||||
static bt_callbacks_t *bt_hal_cbacks = NULL;
|
|
||||||
static future_t *hack_future = NULL;
|
|
||||||
|
|
||||||
static bt_status_t event_init_stack(bt_callbacks_t *cb);
|
|
||||||
static bt_status_t event_start_up_stack(void);
|
|
||||||
static bt_status_t event_shut_down_stack(void);
|
|
||||||
static bt_status_t event_clean_up_stack(void);
|
|
||||||
static void event_signal_stack_up(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
|
|
||||||
static void event_signal_stack_down(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
|
|
||||||
|
|
||||||
static bt_status_t event_init_stack(bt_callbacks_t *cb)
|
|
||||||
{
|
|
||||||
bt_status_t ret;
|
|
||||||
if (!stack_is_initialized) {
|
|
||||||
hack_future = future_new();
|
|
||||||
ret = btif_init_bluetooth();
|
|
||||||
if (future_await(hack_future) != FUTURE_SUCCESS) {
|
|
||||||
return BT_STATUS_FAIL;
|
|
||||||
}
|
|
||||||
if (ret == BT_STATUS_SUCCESS) {
|
|
||||||
bt_hal_cbacks = cb;
|
|
||||||
stack_is_initialized = true;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return BT_STATUS_DONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bt_status_t event_start_up_stack(void)
|
|
||||||
{
|
|
||||||
if (!stack_is_initialized) {
|
|
||||||
LOG_DEBUG("%s stack not initialized yet.\n", __func__);
|
|
||||||
return BT_STATUS_NOT_READY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stack_is_running) {
|
|
||||||
LOG_DEBUG("%s stack already brought up.\n", __func__);
|
|
||||||
return BT_STATUS_DONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_DEBUG("%s is bringing up the stack.\n", __func__);
|
|
||||||
hack_future = future_new();
|
|
||||||
|
|
||||||
btif_enable_bluetooth();
|
|
||||||
|
|
||||||
if (future_await(hack_future) != FUTURE_SUCCESS) {
|
|
||||||
stack_is_running = true; // So stack shutdown actually happens
|
|
||||||
event_shut_down_stack();
|
|
||||||
return BT_STATUS_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
stack_is_running = true;
|
|
||||||
LOG_DEBUG("%s finished\n", __func__);
|
|
||||||
btif_transfer_context(event_signal_stack_up, 0, NULL, 0, NULL);
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bt_status_t event_shut_down_stack(void)
|
|
||||||
{
|
|
||||||
if (!stack_is_running) {
|
|
||||||
LOG_DEBUG("%s stack is already brought down.\n", __func__);
|
|
||||||
return BT_STATUS_DONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_DEBUG("%s is bringing down the stack.\n", __func__);
|
|
||||||
hack_future = future_new();
|
|
||||||
stack_is_running = false;
|
|
||||||
|
|
||||||
btif_disable_bluetooth();
|
|
||||||
|
|
||||||
future_await(hack_future);
|
|
||||||
|
|
||||||
LOG_DEBUG("%s finished.\n", __func__);
|
|
||||||
btif_transfer_context(event_signal_stack_down, 0, NULL, 0, NULL);
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bt_status_t event_clean_up_stack(void)
|
|
||||||
{
|
|
||||||
if (!stack_is_initialized) {
|
|
||||||
LOG_DEBUG("%s found the stack already in a clean state.\n", __func__);
|
|
||||||
return BT_STATUS_DONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stack_is_running) {
|
|
||||||
event_shut_down_stack();
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_DEBUG("%s is cleaning up the stack.\n", __func__);
|
|
||||||
|
|
||||||
stack_is_initialized = false;
|
|
||||||
|
|
||||||
btif_shutdown_bluetooth();
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void event_signal_stack_up(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param)
|
|
||||||
{
|
|
||||||
HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void event_signal_stack_down(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param)
|
|
||||||
{
|
|
||||||
HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_InitStack(bt_callbacks_t *cb)
|
|
||||||
{
|
|
||||||
return event_init_stack(cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_EnableStack(void)
|
|
||||||
{
|
|
||||||
return event_start_up_stack();
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_DisableStack(void)
|
|
||||||
{
|
|
||||||
return event_shut_down_stack();
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_CleanUpStack(void)
|
|
||||||
{
|
|
||||||
return event_clean_up_stack();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool stack_manager_is_stack_running(void)
|
|
||||||
{
|
|
||||||
return stack_is_running;
|
|
||||||
}
|
|
||||||
|
|
||||||
future_t *stack_manager_get_hack_future(void)
|
|
||||||
{
|
|
||||||
return hack_future;
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#
|
|
||||||
# Main Makefile. This is basically the same as a component makefile.
|
|
||||||
#
|
|
||||||
# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default,
|
|
||||||
# this will take the sources in the src/ directory, compile them and link them into
|
|
||||||
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
|
|
||||||
# please read the ESP-IDF documents if you need to do this.
|
|
||||||
#
|
|
||||||
|
|
||||||
COMPONENT_SRCDIRS := \
|
|
||||||
app_core \
|
|
||||||
app_project \
|
|
||||||
btif
|
|
||||||
|
|
||||||
CFLAGS += -Wno-error=unused-label -Wno-error=return-type -Wno-error=missing-braces -Wno-error=pointer-sign -Wno-error=parentheses -I./include
|
|
||||||
|
|
||||||
|
|
||||||
include $(IDF_PATH)/make/component_common.mk
|
|
@ -1,44 +0,0 @@
|
|||||||
// 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 __BT_APP_COMMON_H__
|
|
||||||
#define __BT_APP_COMMON_H__
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "osi.h"
|
|
||||||
#include "bt_common_types.h"
|
|
||||||
#include "bt_defs.h"
|
|
||||||
|
|
||||||
/* BT APP Events */
|
|
||||||
#define BT_EVT_APP (0xB000)
|
|
||||||
#define BT_EVT_APP_CONTEXT_SWITCH (0x0001 | BT_EVT_APP)
|
|
||||||
|
|
||||||
typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param);
|
|
||||||
typedef void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
BT_HDR hdr;
|
|
||||||
tBTAPP_CBACK* p_cb; /* context switch callback */
|
|
||||||
|
|
||||||
/* parameters passed to callback */
|
|
||||||
UINT16 event; /* message event id */
|
|
||||||
char p_param[0]; /* parameter area needs to be last */
|
|
||||||
} tBTAPP_CONTEXT_SWITCH_CBACK;
|
|
||||||
|
|
||||||
bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback);
|
|
||||||
|
|
||||||
void bt_app_task_start_up(void);
|
|
||||||
|
|
||||||
#endif /* __BT_APP_COMMON_H__ */
|
|
@ -1,88 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009-2012 Broadcom Corporation
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
*
|
|
||||||
* Filename: btif_api.h
|
|
||||||
*
|
|
||||||
* Description: Main API header file for all BTIF functions accessed
|
|
||||||
* from main bluetooth HAL. All HAL extensions will not
|
|
||||||
* require headerfiles as they would be accessed through
|
|
||||||
* callout/callins.
|
|
||||||
*
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef BTIF_API_H
|
|
||||||
#define BTIF_API_H
|
|
||||||
|
|
||||||
#include "btif_common.h"
|
|
||||||
#include "btif_dm.h"
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
** BTIF CORE API
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_init_bluetooth
|
|
||||||
**
|
|
||||||
** Description Creates BTIF task and prepares BT scheduler for startup
|
|
||||||
**
|
|
||||||
** Returns bt_status_t
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_init_bluetooth(void);
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_enable_bluetooth
|
|
||||||
**
|
|
||||||
** Description Performs chip power on and kickstarts OS scheduler
|
|
||||||
**
|
|
||||||
** Returns bt_status_t
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_enable_bluetooth(void);
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_disable_bluetooth
|
|
||||||
**
|
|
||||||
** Description Inititates shutdown of Bluetooth system.
|
|
||||||
** Any active links will be dropped and device entering
|
|
||||||
** non connectable/discoverable mode
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_disable_bluetooth(void);
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_shutdown_bluetooth
|
|
||||||
**
|
|
||||||
** Description Finalizes BT scheduler shutdown and terminates BTIF
|
|
||||||
** task.
|
|
||||||
**
|
|
||||||
**
|
|
||||||
** Returns void
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_shutdown_bluetooth(void);
|
|
||||||
|
|
||||||
#endif /* BTIF_API_H */
|
|
@ -1,122 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014 The Android Open Source Project
|
|
||||||
* Copyright (C) 2009-2012 Broadcom Corporation
|
|
||||||
*
|
|
||||||
* 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 BTIF_COMMON_H
|
|
||||||
#define BTIF_COMMON_H
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
// #include <hardware/bluetooth.h>
|
|
||||||
|
|
||||||
#include "bt_types.h"
|
|
||||||
#include "bta_api.h"
|
|
||||||
#include "osi.h"
|
|
||||||
|
|
||||||
// #include "osi/include/log.h"
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
** Constants & Macros
|
|
||||||
********************************************************************************/
|
|
||||||
#define ASSERTC(cond, msg, val) if (!(cond)) { LOG_ERROR( \
|
|
||||||
"### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);}
|
|
||||||
|
|
||||||
/* Calculate start of event enumeration; id is top 8 bits of event */
|
|
||||||
#define BTIF_SIG_START(id) ((id) << 8)
|
|
||||||
|
|
||||||
/* For upstream the MSB bit is always SET */
|
|
||||||
#define BTIF_SIG_CB_BIT (0x8000)
|
|
||||||
#define BTIF_SIG_CB_START(id) (((id) << 8) | BTIF_SIG_CB_BIT)
|
|
||||||
|
|
||||||
/* BTIF sub-systems */
|
|
||||||
#define BTIF_CORE 0
|
|
||||||
#define BTIF_DM 1
|
|
||||||
// #define BTIF_HFP 2
|
|
||||||
// #define BTIF_AV 3
|
|
||||||
// #define BTIF_PAN 4
|
|
||||||
// #define BTIF_HF_CLIENT 5
|
|
||||||
|
|
||||||
#define HAL_CBACK(P_CB, P_CBACK, ...)\
|
|
||||||
if (P_CB && P_CB->P_CBACK) { \
|
|
||||||
BTIF_TRACE_API("HAL %s->%s", #P_CB, #P_CBACK); \
|
|
||||||
P_CB->P_CBACK(__VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
else { \
|
|
||||||
ASSERTC(0, "Callback is NULL", 0); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BTIF events for requests that require context switch to btif task
|
|
||||||
* on downstreams path
|
|
||||||
*/
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
|
|
||||||
/* add here */
|
|
||||||
|
|
||||||
BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM),
|
|
||||||
BTIF_DM_ENABLE_SERVICE,
|
|
||||||
BTIF_DM_DISABLE_SERVICE,
|
|
||||||
/* add here */
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
** Type definitions for callback functions
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
typedef void (tBTIF_CBACK) (UINT16 event, char *p_param);
|
|
||||||
typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
** Type definitions and return values
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
/* this type handles all btif context switches between BTU and HAL */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
BT_HDR hdr;
|
|
||||||
tBTIF_CBACK* p_cb; /* context switch callback */
|
|
||||||
|
|
||||||
/* parameters passed to callback */
|
|
||||||
UINT16 event; /* message event id */
|
|
||||||
char p_param[0]; /* parameter area needs to be last */
|
|
||||||
} tBTIF_CONTEXT_SWITCH_CBACK;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
** Functions
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params,
|
|
||||||
int param_len, tBTIF_COPY_CBACK *p_copy_cback);
|
|
||||||
tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
|
|
||||||
bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
|
|
||||||
bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
|
|
||||||
int btif_is_enabled(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BTIF_Events
|
|
||||||
*/
|
|
||||||
void btif_enable_bluetooth_evt(tBTA_STATUS status);
|
|
||||||
void btif_disable_bluetooth_evt(void);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* BTIF_COMMON_H */
|
|
@ -1,32 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009-2012 Broadcom Corporation
|
|
||||||
*
|
|
||||||
* 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 BTIF_DM_H
|
|
||||||
#define BTIF_DM_H
|
|
||||||
|
|
||||||
#include "bta_api.h"
|
|
||||||
/************************************************************************************
|
|
||||||
** Functions
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BTIF callback to switch context from bte to btif
|
|
||||||
*/
|
|
||||||
void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,38 +0,0 @@
|
|||||||
#ifndef __BTIF_SDP_H__
|
|
||||||
#define __BTIF_SDP_H__
|
|
||||||
|
|
||||||
#include "bt_sdp.h"
|
|
||||||
|
|
||||||
/** Callback for SDP search */
|
|
||||||
typedef void (*btsdp_search_callback)(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
btsdp_search_callback sdp_search_cb;
|
|
||||||
} btsdp_callbacks_t;
|
|
||||||
|
|
||||||
/** Register BT SDP search callbacks */
|
|
||||||
bt_status_t BTIF_SdpInit(btsdp_callbacks_t *callbacks);
|
|
||||||
|
|
||||||
/** Unregister BT SDP */
|
|
||||||
bt_status_t BTIF_SdpDeinit(void);
|
|
||||||
|
|
||||||
/** Search for SDP records with specific uuid on remote device */
|
|
||||||
bt_status_t BTIF_SdpSearch(bt_bdaddr_t *bd_addr, const uint8_t* uuid);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use listen in the socket interface to create rfcomm and/or l2cap PSM channels,
|
|
||||||
* (without UUID and service_name and set the BTSOCK_FLAG_NO_SDP flag in flags).
|
|
||||||
* Then use createSdpRecord to create the SDP record associated with the rfcomm/l2cap channels.
|
|
||||||
*
|
|
||||||
* Returns a handle to the SDP record, which can be parsed to remove_sdp_record.
|
|
||||||
*
|
|
||||||
* record (in) The SDP record to create
|
|
||||||
* record_handle (out)The corresponding record handle will be written to this pointer.
|
|
||||||
*/
|
|
||||||
bt_status_t BTIF_SdpCreateRecord(bluetooth_sdp_record *record, int* record_handle);
|
|
||||||
|
|
||||||
/** Remove a SDP record created by BTIF_SdpCreateRecord */
|
|
||||||
bt_status_t BTIF_SdpRemoveRecord(int record_handle);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __BTIF_SDP_H__ */
|
|
@ -1,31 +0,0 @@
|
|||||||
#ifndef __BTIF_STACK_MANAGER_H__
|
|
||||||
#define __BTIF_STACK_MANAGER_H__
|
|
||||||
|
|
||||||
#include "bt_defs.h"
|
|
||||||
|
|
||||||
/** Bluetooth Adapter State */
|
|
||||||
typedef enum {
|
|
||||||
BT_STATE_OFF,
|
|
||||||
BT_STATE_ON
|
|
||||||
} bt_state_t;
|
|
||||||
|
|
||||||
/** Bluetooth Interface callbacks */
|
|
||||||
|
|
||||||
/** Bluetooth Enable/Disable Callback. */
|
|
||||||
typedef void (*adapter_state_changed_callback)(bt_state_t state);
|
|
||||||
|
|
||||||
|
|
||||||
/** Bluetooth Device callback structure. */
|
|
||||||
typedef struct {
|
|
||||||
adapter_state_changed_callback adapter_state_changed_cb;
|
|
||||||
} bt_callbacks_t;
|
|
||||||
|
|
||||||
bt_status_t BTIF_InitStack(bt_callbacks_t *cb);
|
|
||||||
|
|
||||||
bt_status_t BTIF_EnableStack(void);
|
|
||||||
|
|
||||||
bt_status_t BTIF_DisableStack(void);
|
|
||||||
|
|
||||||
bt_status_t BTIF_CleanUpStack(void);
|
|
||||||
|
|
||||||
#endif /* __BTIF_STACK_MANAGER_H__ */
|
|
@ -1,52 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014 The Android Open Source Project
|
|
||||||
* Copyright (C) 2009-2012 Broadcom Corporation
|
|
||||||
*
|
|
||||||
* 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 BTIF_UTIL_H
|
|
||||||
#define BTIF_UTIL_H
|
|
||||||
|
|
||||||
// #include <hardware/bluetooth.h>
|
|
||||||
// #include <hardware/bt_hf.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
// #include <sys/time.h>
|
|
||||||
|
|
||||||
#include "bt_types.h"
|
|
||||||
// #include "bt_utils.h"
|
|
||||||
#include "bt_defs.h"
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
** Constants & Macros
|
|
||||||
********************************************************************************/
|
|
||||||
/*******************************************************************************
|
|
||||||
** Type definitions for callback functions
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
typedef char bdstr_t[18];
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
** Functions
|
|
||||||
********************************************************************************/
|
|
||||||
UINT32 devclass2uint(DEV_CLASS dev_class);
|
|
||||||
void uint2devclass(UINT32 dev, DEV_CLASS dev_class);
|
|
||||||
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128);
|
|
||||||
|
|
||||||
void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
|
|
||||||
void string_to_uuid(char *str, bt_uuid_t *p_uuid);
|
|
||||||
|
|
||||||
#endif /* BTIF_UTIL_H */
|
|
@ -1,29 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2014 Google, Inc.
|
|
||||||
*
|
|
||||||
* 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 __STACK_MANAGER_H__
|
|
||||||
#define __STACK_MANAGER_H__
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "future.h"
|
|
||||||
|
|
||||||
bool stack_manager_is_stack_running(void);
|
|
||||||
|
|
||||||
future_t *stack_manager_get_hack_future(void);
|
|
||||||
|
|
||||||
#endif /* __STACK_MANAGER_H__*/
|
|
@ -1,10 +0,0 @@
|
|||||||
#
|
|
||||||
# Main Makefile. This is basically the same as a component makefile.
|
|
||||||
#
|
|
||||||
# This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default,
|
|
||||||
# this will take the sources in the src/ directory, compile them and link them into
|
|
||||||
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
|
|
||||||
# please read the ESP-IDF documents if you need to do this.
|
|
||||||
#
|
|
||||||
|
|
||||||
include $(IDF_PATH)/make/component_common.mk
|
|
@ -1,42 +0,0 @@
|
|||||||
// 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 <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "bt.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "string.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern void bte_main_boot_entry(void *);
|
|
||||||
extern void bt_app_task_start_up(void);
|
|
||||||
extern void bt_app_core_start(void);
|
|
||||||
|
|
||||||
void pingTask(void *pvParameters)
|
|
||||||
{
|
|
||||||
while (1) {
|
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
||||||
printf("ping\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_main()
|
|
||||||
{
|
|
||||||
bt_controller_init();
|
|
||||||
xTaskCreatePinnedToCore(&pingTask, "pingTask", 2048, NULL, 5, NULL, 0);
|
|
||||||
bt_app_task_start_up();
|
|
||||||
// bte_main_boot_entry(bt_app_core_start);
|
|
||||||
}
|
|
@ -9,3 +9,10 @@ COMPONENT_ADD_INCLUDEDIRS := components/include
|
|||||||
|
|
||||||
include $(IDF_PATH)/make/project.mk
|
include $(IDF_PATH)/make/project.mk
|
||||||
|
|
||||||
|
# Copy some defaults into the sdkconfig by default
|
||||||
|
# so BT stack is enabled
|
||||||
|
sdkconfig: sdkconfig.defaults
|
||||||
|
$(Q) cp $< $@
|
||||||
|
|
||||||
|
menuconfig: sdkconfig
|
||||||
|
defconfig: sdkconfig
|
||||||
|
14
examples/14_gatt_server/sdkconfig.defaults
Normal file
14
examples/14_gatt_server/sdkconfig.defaults
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Override some defaults so BT stack is enabled
|
||||||
|
# in this example
|
||||||
|
|
||||||
|
#
|
||||||
|
# BT config
|
||||||
|
#
|
||||||
|
CONFIG_BT_ENABLED=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# ESP32-specific config
|
||||||
|
#
|
||||||
|
CONFIG_ESP32_ENABLE_STACK_BT=y
|
||||||
|
# CONFIG_ESP32_ENABLE_STACK_NONE is not set
|
||||||
|
CONFIG_MEMMAP_BT=y
|
@ -9,3 +9,10 @@ COMPONENT_ADD_INCLUDEDIRS := components/include
|
|||||||
|
|
||||||
include $(IDF_PATH)/make/project.mk
|
include $(IDF_PATH)/make/project.mk
|
||||||
|
|
||||||
|
# Copy some defaults into the sdkconfig by default
|
||||||
|
# so BT stack is enabled
|
||||||
|
sdkconfig: sdkconfig.defaults
|
||||||
|
$(Q) cp $< $@
|
||||||
|
|
||||||
|
menuconfig: sdkconfig
|
||||||
|
defconfig: sdkconfig
|
||||||
|
14
examples/15_gatt_client/sdkconfig.defaults
Normal file
14
examples/15_gatt_client/sdkconfig.defaults
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Override some defaults so BT stack is enabled
|
||||||
|
# in this example
|
||||||
|
|
||||||
|
#
|
||||||
|
# BT config
|
||||||
|
#
|
||||||
|
CONFIG_BT_ENABLED=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# ESP32-specific config
|
||||||
|
#
|
||||||
|
CONFIG_ESP32_ENABLE_STACK_BT=y
|
||||||
|
# CONFIG_ESP32_ENABLE_STACK_NONE is not set
|
||||||
|
CONFIG_MEMMAP_BT=y
|
Loading…
x
Reference in New Issue
Block a user