Merge branch 'feature/btdm_gap' into feature/btdm_bluedroid

# Conflicts:
#	examples/07_blufi/components/bluedroid_demos/app_project/SampleClientProject.c
#	examples/07_blufi/components/bluedroid_demos/app_project/SampleServerProject.c
#	examples/07_blufi/components/bluedroid_demos/include/bt_app_common.h
This commit is contained in:
Tian Hao 2016-11-01 14:19:38 +08:00
commit 66b31b89ac
54 changed files with 5515 additions and 471 deletions

View file

@ -0,0 +1,145 @@
/******************************************************************************
*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.
*
******************************************************************************/
/******************************************************************************
*
* This is the public interface file for the BTA SDP I/F
*
******************************************************************************/
#ifndef BTA_SDP_API_H
#define BTA_SDP_API_H
#include "bt_sdp.h"
#include "bt_target.h"
#include "bt_types.h"
#include "bta_api.h"
#include "btm_api.h"
/* status values */
#define BTA_SDP_SUCCESS 0 /* Successful operation. */
#define BTA_SDP_FAILURE 1 /* Generic failure. */
#define BTA_SDP_BUSY 2 /* Temporarily can not handle this request. */
typedef UINT8 tBTA_SDP_STATUS;
/* SDP I/F callback events */
/* events received by tBTA_SDP_DM_CBACK */
#define BTA_SDP_ENABLE_EVT 0 /* SDP service i/f enabled*/
#define BTA_SDP_SEARCH_EVT 1 /* SDP Service started */
#define BTA_SDP_SEARCH_COMP_EVT 2 /* SDP search complete */
#define BTA_SDP_CREATE_RECORD_USER_EVT 3 /* SDP search complete */
#define BTA_SDP_REMOVE_RECORD_USER_EVT 4 /* SDP search complete */
#define BTA_SDP_MAX_EVT 5 /* max number of SDP events */
#define BTA_SDP_MAX_RECORDS 15
typedef UINT16 tBTA_SDP_EVT;
/* data associated with BTA_SDP_DISCOVERY_COMP_EVT */
typedef struct
{
tBTA_SDP_STATUS status;
BD_ADDR remote_addr;
tBT_UUID uuid;
int record_count;
bluetooth_sdp_record records[BTA_SDP_MAX_RECORDS];
} tBTA_SDP_SEARCH_COMP;
typedef union
{
tBTA_SDP_STATUS status; /* BTA_SDP_SEARCH_EVT */
tBTA_SDP_SEARCH_COMP sdp_search_comp; /* BTA_SDP_SEARCH_COMP_EVT */
} tBTA_SDP;
/* SDP DM Interface callback */
typedef void (tBTA_SDP_DM_CBACK)(tBTA_SDP_EVT event, tBTA_SDP *p_data, void * user_data);
/* MCE configuration structure */
typedef struct
{
UINT16 sdp_db_size; /* The size of p_sdp_db */
tSDP_DISCOVERY_DB *p_sdp_db; /* The data buffer to keep SDP database */
} tBTA_SDP_CFG;
#ifdef __cplusplus
extern "C"
{
#endif
/*******************************************************************************
**
** Function BTA_SdpEnable
**
** Description Enable the SDP I/F service. When the enable
** operation is complete the callback function will be
** called with a BTA_SDP_ENABLE_EVT. This function must
** be called before other functions in the MCE API are
** called.
**
** Returns BTA_SDP_SUCCESS if successful.
** BTA_SDP_FAIL if internal failure.
**
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback);
/*******************************************************************************
**
** Function BTA_SdpSearch
**
** Description Start a search for sdp records for a specific BD_ADDR with a
** specific profile uuid.
** When the search operation is completed, the callback function
** will be called with a BTA_SDP_SEARCH_EVT.
** Returns BTA_SDP_SUCCESS if successful.
** BTA_SDP_FAIL if internal failure.
**
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr,tSDP_UUID *uuid);
/*******************************************************************************
**
** Function BTA_SdpCreateRecordByUser
**
** Description This function is used to request a callback to create a SDP
** record. The registered callback will be called with event
** BTA_SDP_CREATE_RECORD_USER_EVT.
**
** Returns BTA_SDP_SUCCESS, if the request is being processed.
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data);
/*******************************************************************************
**
** Function BTA_SdpRemoveRecordByUser
**
** Description This function is used to request a callback to remove a SDP
** record. The registered callback will be called with event
** BTA_SDP_REMOVE_RECORD_USER_EVT.
**
** Returns BTA_SDP_SUCCESS, if the request is being processed.
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data);
#ifdef __cplusplus
}
#endif
#endif /* BTA_SDP_API_H */

View file

@ -0,0 +1,77 @@
/******************************************************************************
*
* Copyright (C) 2014 The Android Open Source Project
* 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.
*
******************************************************************************/
/******************************************************************************
*
* This is the main implementation file for the BTA MCE I/F
*
******************************************************************************/
#include <stdlib.h>
#include "bta_api.h"
#include "bta_sys.h"
#include "bta_sdp_api.h"
#include "bta_sdp_int.h"
/*****************************************************************************
** Constants and types
*****************************************************************************/
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_SDP_CB bta_sdp_cb;
#endif
/* state machine action enumeration list */
#define BTA_SDP_NUM_ACTIONS (BTA_SDP_MAX_INT_EVT & 0x00ff)
/* type for action functions */
typedef void (*tBTA_SDP_ACTION)(tBTA_SDP_MSG *p_data);
/* action function list */
const tBTA_SDP_ACTION bta_sdp_action[] =
{
bta_sdp_enable, /* BTA_SDP_API_ENABLE_EVT */
bta_sdp_search, /* BTA_SDP_API_SEARCH_EVT */
bta_sdp_create_record, /* BTA_SDP_API_CREATE_RECORD_USER_EVT */
bta_sdp_remove_record, /* BTA_SDP_API_REMOVE_RECORD_USER_EVT */
};
/*******************************************************************************
** Function bta_sdp_sm_execute
**
** Description State machine event handling function for SDP search
**
** Returns void
*******************************************************************************/
BOOLEAN bta_sdp_sm_execute(BT_HDR *p_msg)
{
if(p_msg == NULL) return FALSE;
BOOLEAN ret = FALSE;
UINT16 action = (p_msg->event & 0x00ff);
/* execute action functions */
if(action < BTA_SDP_NUM_ACTIONS)
{
(*bta_sdp_action[action])((tBTA_SDP_MSG*)p_msg);
ret = TRUE;
}
return(ret);
}

View file

@ -0,0 +1,568 @@
/******************************************************************************
*
* Copyright (C) 2014 The Android Open Source Project
*
* 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.
*
******************************************************************************/
/******************************************************************************
* This file contains action functions for SDP search.
******************************************************************************/
// #include <hardware/bluetooth.h>
#include "bt_sdp.h"
// #include <arpa/inet.h>
#include "bt_defs.h"
#include <stdlib.h>
#include <string.h>
#include "allocator.h"
#include "bt_types.h"
#include "gki.h"
#include "utl.h"
#include "bta_sys.h"
#include "bta_api.h"
#include "bta_sdp_api.h"
#include "bta_sdp_int.h"
#include "btm_api.h"
#include "btm_int.h"
#include "sdp_api.h"
/*****************************************************************************
** Constants
*****************************************************************************/
static const uint8_t UUID_OBEX_OBJECT_PUSH[] = {0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
static const uint8_t UUID_PBAP_PSE[] = {0x00, 0x00, 0x11, 0x2F, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
static const uint8_t UUID_MAP_MAS[] = {0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
static const uint8_t UUID_MAP_MNS[] = {0x00, 0x00, 0x11, 0x33, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
static const uint8_t UUID_SPP[] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
static const uint8_t UUID_SAP[] = {0x00, 0x00, 0x11, 0x2D, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
// TODO:
// Both the fact that the UUIDs are declared in multiple places, plus the fact
// that there is a mess of UUID comparison and shortening methods will have to
// be fixed.
// The btcore->uuid module should be used for all instances.
#define UUID_MAX_LENGTH 16
#define IS_UUID(u1,u2) !memcmp(u1,u2,UUID_MAX_LENGTH)
static inline tBT_UUID shorten_sdp_uuid(const tBT_UUID* u)
{
static uint8_t bt_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
APPL_TRACE_DEBUG("%s() - uuid len:%d\n", __func__, u->len);
if(u->len != 16)
return *u;
if(memcmp(&u->uu.uuid128[4], &bt_base_uuid[4], 12) != 0)
return *u;
tBT_UUID su;
memset(&su, 0, sizeof(su));
if(u->uu.uuid128[0] == 0 && u->uu.uuid128[1] == 0)
{
su.len = 2;
uint16_t u16;
memcpy(&u16, &u->uu.uuid128[2], sizeof(u16));
su.uu.uuid16 = ntohs(u16);
} else {
su.len = 4;
uint32_t u32;
memcpy(&u32, &u->uu.uuid128[0], sizeof(u32));
su.uu.uuid32 = ntohl(u32);
}
return su;
}
static void bta_create_mns_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
{
tSDP_DISC_ATTR *p_attr;
tSDP_PROTOCOL_ELEM pe;
UINT16 pversion = 0;
record->mns.hdr.type = SDP_TYPE_MAP_MNS;
record->mns.hdr.service_name_length = 0;
record->mns.hdr.service_name = NULL;
record->mns.hdr.rfcomm_channel_number = 0;
record->mns.hdr.l2cap_psm = -1;
record->mns.hdr.profile_version = 0;
record->mns.supported_features = 0x0000001F; //default value if not found
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAP_SUPPORTED_FEATURES)) != NULL)
{
record->mns.supported_features = p_attr->attr_value.v.u32;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
record->mns.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->mns.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_MAP_PROFILE, &pversion))
{
record->mns.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
record->mns.hdr.rfcomm_channel_number = pe.params[0];
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL)
{
record->mns.hdr.l2cap_psm = p_attr->attr_value.v.u16;
}
}
static void bta_create_mas_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
{
tSDP_DISC_ATTR *p_attr;
tSDP_PROTOCOL_ELEM pe;
UINT16 pversion = -1;
record->mas.hdr.type = SDP_TYPE_MAP_MAS;
record->mas.hdr.service_name_length = 0;
record->mas.hdr.service_name = NULL;
record->mas.hdr.rfcomm_channel_number = 0;
record->mas.hdr.l2cap_psm = -1;
record->mas.hdr.profile_version = 0;
record->mas.mas_instance_id = 0;
record->mas.supported_features = 0x0000001F;
record->mas.supported_message_types = 0;
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAS_INSTANCE_ID)) != NULL)
{
record->mas.mas_instance_id = p_attr->attr_value.v.u8;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_MSG_TYPE)) != NULL)
{
record->mas.supported_message_types = p_attr->attr_value.v.u8;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAP_SUPPORTED_FEATURES)) != NULL)
{
record->mas.supported_features = p_attr->attr_value.v.u32;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
record->mas.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->mas.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_MAP_PROFILE, &pversion))
{
record->mas.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
record->mas.hdr.rfcomm_channel_number = pe.params[0];
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL)
{
record->mas.hdr.l2cap_psm = p_attr->attr_value.v.u16;
}
}
static void bta_create_pse_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
{
tSDP_DISC_ATTR *p_attr;
UINT16 pversion;
tSDP_PROTOCOL_ELEM pe;
record->pse.hdr.type = SDP_TYPE_PBAP_PSE;
record->pse.hdr.service_name_length = 0;
record->pse.hdr.service_name = NULL;
record->pse.hdr.rfcomm_channel_number = 0;
record->pse.hdr.l2cap_psm = -1;
record->pse.hdr.profile_version = 0;
record->pse.supported_features = 0x00000003;
record->pse.supported_repositories = 0;
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_REPOSITORIES)) != NULL)
{
record->pse.supported_repositories = p_attr->attr_value.v.u8;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_PBAP_SUPPORTED_FEATURES)) != NULL)
{
record->pse.supported_features = p_attr->attr_value.v.u32;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
record->pse.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->pse.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_PHONE_ACCESS, &pversion))
{
record->pse.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
record->pse.hdr.rfcomm_channel_number = pe.params[0];
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL)
{
record->pse.hdr.l2cap_psm = p_attr->attr_value.v.u16;
}
}
static void bta_create_ops_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
{
tSDP_DISC_ATTR *p_attr, *p_sattr;
tSDP_PROTOCOL_ELEM pe;
UINT16 pversion = -1;
record->ops.hdr.type = SDP_TYPE_OPP_SERVER;
record->ops.hdr.service_name_length = 0;
record->ops.hdr.service_name = NULL;
record->ops.hdr.rfcomm_channel_number = 0;
record->ops.hdr.l2cap_psm = -1;
record->ops.hdr.profile_version = 0;
record->ops.supported_formats_list_len = 0;
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
record->ops.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->ops.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_OBEX_OBJECT_PUSH, &pversion))
{
record->ops.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
record->ops.hdr.rfcomm_channel_number = pe.params[0];
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL)
{
record->ops.hdr.l2cap_psm = p_attr->attr_value.v.u16;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_FORMATS_LIST)) != NULL)
{
/* Safety check - each entry should itself be a sequence */
if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) {
record->ops.supported_formats_list_len = 0;
APPL_TRACE_ERROR("%s() - supported_formats_list - wrong attribute length/type:"
" 0x%02x - expected 0x06", __func__, p_attr->attr_len_type);
} else {
int count = 0;
/* 1 byte for type/length 1 byte for value */
record->ops.supported_formats_list_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type)/2;
/* Extract each value into */
for (p_sattr = p_attr->attr_value.v.p_sub_attr;
p_sattr != NULL; p_sattr = p_sattr->p_next_attr)
{
if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UINT_DESC_TYPE)
&& (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 1))
{
if (count == sizeof(record->ops.supported_formats_list)) {
APPL_TRACE_ERROR("%s() - supported_formats_list - count overflow - "
"too many sub attributes!!\n", __func__);
/* If you hit this, new formats have been added,
* update SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH */
break;
}
record->ops.supported_formats_list[count] = p_sattr->attr_value.v.u8;
count++;
} else {
APPL_TRACE_ERROR("%s() - supported_formats_list - wrong sub attribute "
"length/type: 0x%02x - expected 0x80", __func__,
p_sattr->attr_len_type);
break;
}
}
if (record->ops.supported_formats_list_len != count) {
APPL_TRACE_WARNING("%s() - supported_formats_list - Length of attribute different "
"from the actual number of sub-attributes in the sequence "
"att-length: %d - number of elements: %d\n", __func__,
record->ops.supported_formats_list_len , count);
}
record->ops.supported_formats_list_len = count;
}
}
}
static void bta_create_sap_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
{
tSDP_DISCOVERY_DB *db = p_bta_sdp_cfg->p_sdp_db;
tSDP_DISC_ATTR *p_attr;
tSDP_PROTOCOL_ELEM pe;
UINT16 pversion = -1;
record->sap.hdr.type = SDP_TYPE_MAP_MAS;
record->sap.hdr.service_name_length = 0;
record->sap.hdr.service_name = NULL;
record->sap.hdr.rfcomm_channel_number = 0;
record->sap.hdr.l2cap_psm = -1;
record->sap.hdr.profile_version = 0;
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
record->sap.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->sap.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_SAP, &pversion))
{
record->sap.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
record->sap.hdr.rfcomm_channel_number = pe.params[0];
}
}
static void bta_create_raw_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
{
tSDP_DISC_ATTR *p_attr;
tSDP_PROTOCOL_ELEM pe;
record->hdr.type = SDP_TYPE_RAW;
record->hdr.service_name_length = 0;
record->hdr.service_name = NULL;
record->hdr.rfcomm_channel_number = -1;
record->hdr.l2cap_psm = -1;
record->hdr.profile_version = -1;
/* Try to extract a service name */
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
record->pse.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->pse.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
/* Try to extract an RFCOMM channel */
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
record->pse.hdr.rfcomm_channel_number = pe.params[0];
}
record->hdr.user1_ptr_len = p_bta_sdp_cfg->p_sdp_db->raw_size;
record->hdr.user1_ptr = p_bta_sdp_cfg->p_sdp_db->raw_data;
}
/*******************************************************************************
**
** Function bta_sdp_search_cback
**
** Description Callback from btm after search is completed
**
** Returns void
**
*******************************************************************************/
static void bta_sdp_search_cback(UINT16 result, void * user_data)
{
tSDP_DISC_REC *p_rec = NULL;
tBTA_SDP_SEARCH_COMP evt_data = {0}; // We need to zero-initialize
tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
int count = 0;
tBT_UUID su;
APPL_TRACE_DEBUG("%s() - res: 0x%x\n", __func__, result);
bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_NONE;
if (bta_sdp_cb.p_dm_cback == NULL) return;
bdcpy(evt_data.remote_addr, bta_sdp_cb.remote_addr);
tBT_UUID *uuid = (tBT_UUID*)user_data;
memcpy(&evt_data.uuid, uuid, sizeof(tBT_UUID));
su = shorten_sdp_uuid(uuid);
if (result == SDP_SUCCESS || result == SDP_DB_FULL)
{
do {
p_rec = SDP_FindServiceUUIDInDb(p_bta_sdp_cfg->p_sdp_db, &su, p_rec);
/* generate the matching record data pointer */
if(p_rec != NULL){
status = BTA_SDP_SUCCESS;
if (IS_UUID(UUID_MAP_MAS,uuid->uu.uuid128)) {
APPL_TRACE_DEBUG("%s() - found MAP (MAS) uuid\n", __func__);
bta_create_mas_sdp_record(&evt_data.records[count], p_rec);
} else if (IS_UUID(UUID_MAP_MNS,uuid->uu.uuid128)) {
APPL_TRACE_DEBUG("%s() - found MAP (MNS) uuid\n", __func__);
bta_create_mns_sdp_record(&evt_data.records[count], p_rec);
} else if (IS_UUID(UUID_PBAP_PSE,uuid->uu.uuid128)){
APPL_TRACE_DEBUG("%s() - found PBAP (PSE) uuid\n", __func__);
bta_create_pse_sdp_record(&evt_data.records[count], p_rec);
} else if (IS_UUID(UUID_OBEX_OBJECT_PUSH,uuid->uu.uuid128)){
APPL_TRACE_DEBUG("%s() - found Object Push Server (OPS) uuid\n", __func__);
bta_create_ops_sdp_record(&evt_data.records[count], p_rec);
} else if (IS_UUID(UUID_SAP,uuid->uu.uuid128)) {
APPL_TRACE_DEBUG("%s() - found SAP uuid\n", __func__);
bta_create_sap_sdp_record(&evt_data.records[count], p_rec);
} else {
/* we do not have specific structure for this */
APPL_TRACE_DEBUG("%s() - profile not identified. using raw data\n", __func__);
bta_create_raw_sdp_record(&evt_data.records[count], p_rec);
p_rec = NULL; // Terminate loop
/* For raw, we only extract the first entry, and then return the entire
raw data chunk.
TODO: Find a way to split the raw data into record chunks, and iterate
to extract generic data for each chunk - e.g. rfcomm channel and
service name. */
}
count++;
} else {
APPL_TRACE_DEBUG("%s() - UUID not found\n", __func__);
}
} while (p_rec != NULL && count < BTA_SDP_MAX_RECORDS);
evt_data.record_count = count;
}
evt_data.status = status;
bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP*) &evt_data, (void*)&uuid->uu.uuid128);
osi_free(user_data); // We no longer need the user data to track the search
}
/*******************************************************************************
**
** Function bta_sdp_enable
**
** Description Initializes the SDP I/F
**
** Returns void
**
*******************************************************************************/
void bta_sdp_enable(tBTA_SDP_MSG *p_data)
{
APPL_TRACE_DEBUG("%s in, sdp_active:%d\n", __func__, bta_sdp_cb.sdp_active);
tBTA_SDP_STATUS status = BTA_SDP_SUCCESS;
bta_sdp_cb.p_dm_cback = p_data->enable.p_cback;
bta_sdp_cb.p_dm_cback(BTA_SDP_ENABLE_EVT, (tBTA_SDP *)&status, NULL);
}
/*******************************************************************************
**
** Function bta_sdp_search
**
** Description Discovers all sdp records for an uuid on remote device
**
** Returns void
**
*******************************************************************************/
void bta_sdp_search(tBTA_SDP_MSG *p_data)
{
int x=0;
// TODO: Leaks!!! but needed as user-data pointer
tBT_UUID *bta_sdp_search_uuid = osi_malloc(sizeof(tBT_UUID));
if(p_data == NULL)
{
APPL_TRACE_DEBUG("SDP control block handle is null\n");
return;
}
tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
APPL_TRACE_DEBUG("%s in, sdp_active:%d\n", __func__, bta_sdp_cb.sdp_active);
if (bta_sdp_cb.sdp_active != BTA_SDP_ACTIVE_NONE)
{
/* SDP is still in progress */
status = BTA_SDP_BUSY;
if(bta_sdp_cb.p_dm_cback) {
tBTA_SDP_SEARCH_COMP result = {0};
result.uuid = p_data->get_search.uuid;
bdcpy(result.remote_addr, p_data->get_search.bd_addr);
result.status = status;
bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP *)&result, NULL);
}
return;
}
bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_YES;
bdcpy(bta_sdp_cb.remote_addr, p_data->get_search.bd_addr);
/* set the uuid used in the search */
memcpy(bta_sdp_search_uuid, &(p_data->get_search.uuid),sizeof(tBT_UUID));
/* initialize the search for the uuid */
APPL_TRACE_DEBUG("%s init discovery with UUID(len: %d):\n",
__func__, bta_sdp_search_uuid->len);
for(x = 0; x<bta_sdp_search_uuid->len;x++){
APPL_TRACE_DEBUG("%X",bta_sdp_search_uuid->uu.uuid128[x]);
}
SDP_InitDiscoveryDb (p_bta_sdp_cfg->p_sdp_db, p_bta_sdp_cfg->sdp_db_size, 1,
bta_sdp_search_uuid, 0, NULL);
if (!SDP_ServiceSearchAttributeRequest2(p_data->get_search.bd_addr, p_bta_sdp_cfg->p_sdp_db,
bta_sdp_search_cback, (void*)bta_sdp_search_uuid))
{
bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_NONE;
/* failed to start SDP. report the failure right away */
if (bta_sdp_cb.p_dm_cback) {
tBTA_SDP_SEARCH_COMP result = {0};
result.uuid = p_data->get_search.uuid;
bdcpy(result.remote_addr, p_data->get_search.bd_addr);
result.status = status;
bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP *)&result, NULL);
}
}
/*
else report the result when the cback is called
*/
}
/*******************************************************************************
**
** Function bta_sdp_record
**
** Description Discovers all sdp records for an uuid on remote device
**
** Returns void
**
*******************************************************************************/
void bta_sdp_create_record(tBTA_SDP_MSG *p_data)
{
APPL_TRACE_DEBUG("%s() event: %d\n", __func__, p_data->record.hdr.event);
if (bta_sdp_cb.p_dm_cback)
bta_sdp_cb.p_dm_cback(BTA_SDP_CREATE_RECORD_USER_EVT, NULL, p_data->record.user_data);
}
/*******************************************************************************
**
** Function bta_sdp_create_record
**
** Description Discovers all sdp records for an uuid on remote device
**
** Returns void
**
*******************************************************************************/
void bta_sdp_remove_record(tBTA_SDP_MSG *p_data)
{
APPL_TRACE_DEBUG("%s() event: %d\n", __func__, p_data->record.hdr.event);
if (bta_sdp_cb.p_dm_cback)
bta_sdp_cb.p_dm_cback(BTA_SDP_REMOVE_RECORD_USER_EVT, NULL, p_data->record.user_data);
}

View file

@ -0,0 +1,173 @@
/******************************************************************************
*
* Copyright (C) 2014 The Android Open Source Project
*
* 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.
*
******************************************************************************/
/******************************************************************************
*
* This is the implementation of the API for SDP search subsystem
*
******************************************************************************/
#include "bta_api.h"
#include "bta_sys.h"
#include "bta_sdp_api.h"
#include "bta_sdp_int.h"
#include "gki.h"
#include <string.h>
// #include "port_api.h"
#include "sdp_api.h"
/*****************************************************************************
** Constants
*****************************************************************************/
static const tBTA_SYS_REG bta_sdp_reg =
{
bta_sdp_sm_execute,
NULL
};
/*******************************************************************************
**
** Function BTA_SdpEnable
**
** Description Enable the SDP search I/F service. When the enable
** operation is complete the callback function will be
** called with a BTA_SDP_ENABLE_EVT. This function must
** be called before other functions in the SDP search API are
** called.
**
** Returns BTA_SDP_SUCCESS if successful.
** BTA_SDP_FAIL if internal failure.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
{
tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
tBTA_SDP_API_ENABLE *p_buf;
APPL_TRACE_API(__FUNCTION__);
if(p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP))
{
memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
/* register with BTA system manager */
bta_sys_register(BTA_ID_SDP, &bta_sdp_reg);
if (p_cback &&
(p_buf = (tBTA_SDP_API_ENABLE *) GKI_getbuf(sizeof(tBTA_SDP_API_ENABLE))) != NULL)
{
p_buf->hdr.event = BTA_SDP_API_ENABLE_EVT;
p_buf->p_cback = p_cback;
bta_sys_sendmsg(p_buf);
status = BTA_SDP_SUCCESS;
}
}
return(status);
}
/*******************************************************************************
**
** Function BTA_SdpSearch
**
** Description This function performs service discovery for a specific service
** on given peer device. When the operation is completed
** the tBTA_SDP_DM_CBACK callback function will be called with
** a BTA_SDP_SEARCH_COMPLETE_EVT.
**
** Returns BTA_SDP_SUCCESS, if the request is being processed.
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
{
tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
tBTA_SDP_API_SEARCH *p_msg;
APPL_TRACE_API(__FUNCTION__);
if ((p_msg = (tBTA_SDP_API_SEARCH *)GKI_getbuf(sizeof(tBTA_SDP_API_SEARCH))) != NULL)
{
p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
//p_msg->uuid = uuid;
memcpy(&(p_msg->uuid), uuid, sizeof(tSDP_UUID));
bta_sys_sendmsg(p_msg);
ret = BTA_SDP_SUCCESS;
}
return(ret);
}
/*******************************************************************************
**
** Function BTA_SdpCreateRecordByUser
**
** Description This function is used to request a callback to create a SDP
** record. The registered callback will be called with event
** BTA_SDP_CREATE_RECORD_USER_EVT.
**
** Returns BTA_SDP_SUCCESS, if the request is being processed.
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data)
{
tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
tBTA_SDP_API_RECORD_USER *p_msg;
APPL_TRACE_API(__FUNCTION__);
if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL)
{
p_msg->hdr.event = BTA_SDP_API_CREATE_RECORD_USER_EVT;
p_msg->user_data = user_data;
bta_sys_sendmsg(p_msg);
ret = BTA_SDP_SUCCESS;
}
return(ret);
}
/*******************************************************************************
**
** Function BTA_SdpRemoveRecordByUser
**
** Description This function is used to request a callback to remove a SDP
** record. The registered callback will be called with event
** BTA_SDP_REMOVE_RECORD_USER_EVT.
**
** Returns BTA_SDP_SUCCESS, if the request is being processed.
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data)
{
tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
tBTA_SDP_API_RECORD_USER *p_msg;
APPL_TRACE_API(__FUNCTION__);
if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL)
{
p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
p_msg->user_data = user_data;
bta_sys_sendmsg(p_msg);
ret = BTA_SDP_SUCCESS;
}
return(ret);
}

View file

@ -0,0 +1,40 @@
/******************************************************************************
*
* Copyright (C) 2014 The Android Open Source Project
*
* 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.
*
******************************************************************************/
/******************************************************************************
* This file contains compile-time configurable constants for SDP Search
******************************************************************************/
#include "gki.h"
#include "bta_api.h"
#include "bta_sdp_api.h"
#ifndef BTA_SDP_DB_SIZE
#define BTA_SDP_DB_SIZE 4500
#endif
static UINT8 __attribute__ ((aligned(4))) bta_sdp_db_data[BTA_SDP_DB_SIZE];
/* SDP configuration structure */
const tBTA_SDP_CFG bta_sdp_cfg =
{
BTA_SDP_DB_SIZE,
(tSDP_DISCOVERY_DB *)bta_sdp_db_data /* The data buffer to keep SDP database */
};
tBTA_SDP_CFG *p_bta_sdp_cfg = (tBTA_SDP_CFG *) &bta_sdp_cfg;

View file

@ -0,0 +1,115 @@
/******************************************************************************
*
* Copyright (C) 2014 The Android Open Source Project
* Copyright (C) 2003-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.
*
******************************************************************************/
/******************************************************************************
*
* This is the private interface file for the BTA SDP I/F
*
******************************************************************************/
#ifndef BTA_SDP_INT_H
#define BTA_SDP_INT_H
#include "bta_sys.h"
#include "bta_api.h"
#include "bta_sdp_api.h"
/*****************************************************************************
** Constants
*****************************************************************************/
enum
{
/* these events are handled by the state machine */
BTA_SDP_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_SDP),
BTA_SDP_API_SEARCH_EVT,
BTA_SDP_API_CREATE_RECORD_USER_EVT,
BTA_SDP_API_REMOVE_RECORD_USER_EVT,
BTA_SDP_MAX_INT_EVT
};
enum
{
BTA_SDP_ACTIVE_NONE = 0,
BTA_SDP_ACTIVE_YES /* waiting for SDP result */
};
/* data type for BTA_SDP_API_ENABLE_EVT */
typedef struct
{
BT_HDR hdr;
tBTA_SDP_DM_CBACK *p_cback;
} tBTA_SDP_API_ENABLE;
/* data type for BTA_SDP_API_SEARCH_EVT */
typedef struct
{
BT_HDR hdr;
BD_ADDR bd_addr;
tSDP_UUID uuid;
} tBTA_SDP_API_SEARCH;
/* data type for BTA_SDP_API_SEARCH_EVT */
typedef struct
{
BT_HDR hdr;
void* user_data;
} tBTA_SDP_API_RECORD_USER;
/* union of all data types */
typedef union
{
/* GKI event buffer header */
BT_HDR hdr;
tBTA_SDP_API_ENABLE enable;
tBTA_SDP_API_SEARCH get_search;
tBTA_SDP_API_RECORD_USER record;
} tBTA_SDP_MSG;
/* SDP control block */
typedef struct
{
UINT8 sdp_active; /* see BTA_SDP_SDP_ACT_* */
BD_ADDR remote_addr;
tBTA_SDP_DM_CBACK *p_dm_cback;
} tBTA_SDP_CB;
/* SDP control block */
#if BTA_DYNAMIC_MEMORY == FALSE
extern tBTA_SDP_CB bta_sdp_cb;
#else
extern tBTA_SDP_CB *bta_sdp_cb_ptr;
#define bta_sdp_cb (*bta_sdp_cb_ptr)
#endif
/* config struct */
extern tBTA_SDP_CFG *p_bta_sdp_cfg;
extern BOOLEAN bta_sdp_sm_execute(BT_HDR *p_msg);
extern void bta_sdp_enable (tBTA_SDP_MSG *p_data);
extern void bta_sdp_search (tBTA_SDP_MSG *p_data);
extern void bta_sdp_create_record(tBTA_SDP_MSG *p_data);
extern void bta_sdp_remove_record(tBTA_SDP_MSG *p_data);
#endif /* BTA_SDP_INT_H */

View file

@ -53,6 +53,29 @@ typedef struct {
uint8_t address[6];
} __attribute__ ((__packed__)) bt_bdaddr_t;
/** Bluetooth 128-bit UUID */
typedef struct {
uint8_t uu[16];
} bt_uuid_t;
/** Bluetooth Error Status */
/** We need to build on this */
typedef enum {
BT_STATUS_SUCCESS,
BT_STATUS_FAIL,
BT_STATUS_NOT_READY,
BT_STATUS_NOMEM,
BT_STATUS_BUSY,
BT_STATUS_DONE, /* request already completed */
BT_STATUS_UNSUPPORTED,
BT_STATUS_PARM_INVALID,
BT_STATUS_UNHANDLED,
BT_STATUS_AUTH_FAILURE,
BT_STATUS_RMT_DEV_DOWN,
BT_STATUS_AUTH_REJECTED
} bt_status_t;
#ifndef CPU_LITTLE_ENDIAN
#define CPU_LITTLE_ENDIAN
@ -69,6 +92,7 @@ inline uint32_t swap_byte_32(uint32_t x) {
((x & 0x00ff0000UL) >> 8) |
((x & 0xff000000UL) >> 24));
}
#ifndef ntohs
inline uint16_t ntohs(uint16_t x) {
#ifdef CPU_LITTLE_ENDIAN
@ -77,6 +101,36 @@ inline uint16_t ntohs(uint16_t x) {
return x;
#endif
}
#endif /* #ifndef ntohs */
#ifndef htons
inline uint16_t htons(uint16_t x) {
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_16(x);
#else
return x;
#endif
}
#endif /* #ifndef htons */
#ifndef ntohl
inline uint32_t ntohl(uint32_t x) {
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_32(x);
#else
return x;
#endif
}
#endif /* #ifndef ntohl*/
#ifndef htonl
inline uint32_t htonl(uint32_t x) {
#ifdef CPU_LITTLE_ENDIAN
return swap_byte_32(x);
#else
return x;
#endif
}
#endif /* #ifndef htonl*/
#endif /* _BT_DEFS_H_ */

View file

@ -7,6 +7,8 @@
#include "freertos/queue.h"
#include "freertos/task.h"
#include "bt_defs.h"
#define portBASE_TYPE int
struct bt_task_evt {
@ -17,27 +19,14 @@ struct bt_task_evt {
};
typedef struct bt_task_evt BtTaskEvt_t;
typedef enum {
BT_STATUS_SUCCESS,
BT_STATUS_FAIL,
BT_STATUS_NOT_READY,
BT_STATUS_NOMEM,
BT_STATUS_BUSY,
BT_STATUS_DONE,
BT_STATUS_UNSUPPORTED,
BT_STATUS_PARAM_INVALID,
BT_STATUS_UNHANDLED,
BT_STATUS_AUTH_FAILURE,
BT_STATUS_RMT_DEV_DOWN
} BtStatus_t;
typedef BtStatus_t (* BtTaskCb_t)(void *arg);
typedef bt_status_t (* BtTaskCb_t)(void *arg);
enum {
SIG_PRF_START_UP = 0xfc,
SIG_PRF_WORK = 0xfd,
SIG_PRF_START_UP = 0xfc,
SIG_PRF_WORK = 0xfd,
SIG_BTU_START_UP = 0xfe,
SIG_BTU_WORK = 0xff
SIG_BTU_WORK = 0xff,
SIG_BTIF_WORK = 0xff
};
void btu_task_post(uint32_t sig);

View file

@ -0,0 +1,111 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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_SDP_H__
#define __BT_SDP_H__
#include <stdint.h>
// #include "bluetooth.h"
#include "bt_defs.h"
#define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15
/**
* These events are handled by the state machine
*/
typedef enum {
SDP_TYPE_RAW, // Used to carry raw SDP search data for unknown UUIDs
SDP_TYPE_MAP_MAS, // Message Access Profile - Server
SDP_TYPE_MAP_MNS, // Message Access Profile - Client (Notification Server)
SDP_TYPE_PBAP_PSE, // Phone Book Profile - Server
SDP_TYPE_PBAP_PCE, // Phone Book Profile - Client
SDP_TYPE_OPP_SERVER, // Object Push Profile
SDP_TYPE_SAP_SERVER // SIM Access Profile
} bluetooth_sdp_types;
typedef struct _bluetooth_sdp_hdr {
bluetooth_sdp_types type;
bt_uuid_t uuid;
uint32_t service_name_length;
char *service_name;
int32_t rfcomm_channel_number;
int32_t l2cap_psm;
int32_t profile_version;
} bluetooth_sdp_hdr;
/**
* Some signals need additional pointers, hence we introduce a
* generic way to handle these pointers.
*/
typedef struct _bluetooth_sdp_hdr_overlay {
bluetooth_sdp_types type;
bt_uuid_t uuid;
uint32_t service_name_length;
char *service_name;
int32_t rfcomm_channel_number;
int32_t l2cap_psm;
int32_t profile_version;
// User pointers, only used for some signals - see bluetooth_sdp_ops_record
int user1_ptr_len;
uint8_t *user1_ptr;
int user2_ptr_len;
uint8_t *user2_ptr;
} bluetooth_sdp_hdr_overlay;
typedef struct _bluetooth_sdp_mas_record {
bluetooth_sdp_hdr_overlay hdr;
uint32_t mas_instance_id;
uint32_t supported_features;
uint32_t supported_message_types;
} bluetooth_sdp_mas_record;
typedef struct _bluetooth_sdp_mns_record {
bluetooth_sdp_hdr_overlay hdr;
uint32_t supported_features;
} bluetooth_sdp_mns_record;
typedef struct _bluetooth_sdp_pse_record {
bluetooth_sdp_hdr_overlay hdr;
uint32_t supported_features;
uint32_t supported_repositories;
} bluetooth_sdp_pse_record;
typedef struct _bluetooth_sdp_pce_record {
bluetooth_sdp_hdr_overlay hdr;
} bluetooth_sdp_pce_record;
typedef struct _bluetooth_sdp_ops_record {
bluetooth_sdp_hdr_overlay hdr;
int supported_formats_list_len;
uint8_t supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH];
} bluetooth_sdp_ops_record;
typedef struct _bluetooth_sdp_sap_record {
bluetooth_sdp_hdr_overlay hdr;
} bluetooth_sdp_sap_record;
typedef union {
bluetooth_sdp_hdr_overlay hdr;
bluetooth_sdp_mas_record mas;
bluetooth_sdp_mns_record mns;
bluetooth_sdp_pse_record pse;
bluetooth_sdp_pce_record pce;
bluetooth_sdp_ops_record ops;
bluetooth_sdp_sap_record sap;
} bluetooth_sdp_record;
#endif /* __BT_SDP_H__ */

View file

@ -65,7 +65,7 @@ static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read
*******************************************************************************/
void btm_acl_init (void)
{
BTM_TRACE_DEBUG ("btm_acl_init");
BTM_TRACE_DEBUG ("btm_acl_init\n");
#if 0 /* cleared in btm_init; put back in if called from anywhere else! */
memset (&btm_cb.acl_db, 0, sizeof (btm_cb.acl_db));
memset (btm_cb.btm_scn, 0, BTM_MAX_SCN); /* Initialize the SCN usage to FALSE */
@ -128,7 +128,7 @@ UINT8 btm_handle_to_acl_index (UINT16 hci_handle)
{
tACL_CONN *p = &btm_cb.acl_db[0];
UINT8 xx;
BTM_TRACE_DEBUG ("btm_handle_to_acl_index");
BTM_TRACE_DEBUG ("btm_handle_to_acl_index\n");
for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
{
if ((p->in_use) && (p->hci_handle == hci_handle))
@ -160,7 +160,7 @@ BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_ad
if (p_dev_rec == NULL)
{
BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address");
BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address\n");
return FALSE;
}
@ -182,7 +182,7 @@ BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_ad
break;
default:
BTM_TRACE_ERROR("Unknown active address: %d", p_dev_rec->ble.active_addr_type);
BTM_TRACE_ERROR("Unknown active address: %d\n", p_dev_rec->ble.active_addr_type);
st = FALSE;
break;
}
@ -213,7 +213,7 @@ void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
tACL_CONN *p;
UINT8 xx;
BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d",
BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d\n",
hci_handle,link_role, transport);
/* Ensure we don't have duplicates */
p = btm_bda_to_acl(bda, transport);
@ -224,7 +224,7 @@ void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
#if BLE_INCLUDED == TRUE
p->transport = transport;
#endif
BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x",
BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy);
return;
@ -275,7 +275,7 @@ void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
#if (BLE_INCLUDED == TRUE)
if (p_dev_rec )
{
BTM_TRACE_DEBUG ("device_type=0x%x", p_dev_rec->device_type);
BTM_TRACE_DEBUG ("device_type=0x%x\n", p_dev_rec->device_type);
}
#endif
@ -294,7 +294,7 @@ void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
/* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */
btm_sec_set_peer_sec_caps(p, p_dev_rec);
BTM_TRACE_API("%s: pend:%d", __FUNCTION__, req_pend);
BTM_TRACE_API("%s: pend:%d\n", __FUNCTION__, req_pend);
if (req_pend)
{
/* Request for remaining Security Features (if any) */
@ -350,7 +350,7 @@ void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
void btm_acl_report_role_change (UINT8 hci_status, BD_ADDR bda)
{
tBTM_ROLE_SWITCH_CMPL ref_data;
BTM_TRACE_DEBUG ("btm_acl_report_role_change");
BTM_TRACE_DEBUG ("btm_acl_report_role_change\n");
if (btm_cb.devcb.p_switch_role_cb
&& (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, bda, BD_ADDR_LEN))))
{
@ -380,7 +380,7 @@ void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport)
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
tBTM_SEC_DEV_REC *p_dev_rec=NULL;
#endif
BTM_TRACE_DEBUG ("btm_acl_removed");
BTM_TRACE_DEBUG ("btm_acl_removed\n");
p = btm_bda_to_acl(bda, transport);
if (p != (tACL_CONN *)NULL)
{
@ -411,7 +411,7 @@ void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport)
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d",
BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d\n",
p->hci_handle,
p->transport,
btm_cb.ble_ctr_cb.inq_var.connectable_mode,
@ -420,32 +420,32 @@ void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport)
p_dev_rec = btm_find_dev(bda);
if ( p_dev_rec)
{
BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags);
BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x\n", p_dev_rec->sec_flags);
if (p->transport == BT_TRANSPORT_LE)
{
BTM_TRACE_DEBUG("LE link down");
BTM_TRACE_DEBUG("LE link down\n");
p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0)
{
BTM_TRACE_DEBUG("Not Bonded");
BTM_TRACE_DEBUG("Not Bonded\n");
p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED);
}
else
{
BTM_TRACE_DEBUG("Bonded");
BTM_TRACE_DEBUG("Bonded\n");
}
}
else
{
BTM_TRACE_DEBUG("Bletooth link down");
BTM_TRACE_DEBUG("Bletooth link down\n");
p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED
| BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
}
BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags);
BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x\n", p_dev_rec->sec_flags);
}
else
{
BTM_TRACE_ERROR("Device not found");
BTM_TRACE_ERROR("Device not found\n");
}
#endif
@ -470,12 +470,12 @@ void btm_acl_device_down (void)
{
tACL_CONN *p = &btm_cb.acl_db[0];
UINT16 xx;
BTM_TRACE_DEBUG ("btm_acl_device_down");
BTM_TRACE_DEBUG ("btm_acl_device_down\n");
for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
{
if (p->in_use)
{
BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE ",p->hci_handle );
BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE \n",p->hci_handle );
l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE);
}
}
@ -563,7 +563,7 @@ void btm_acl_update_busy_level (tBTM_BLI_EVENT event)
tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role)
{
tACL_CONN *p;
BTM_TRACE_DEBUG ("BTM_GetRole");
BTM_TRACE_DEBUG ("BTM_GetRole\n");
if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
{
*p_role = BTM_ROLE_UNDEFINED;
@ -606,7 +606,7 @@ tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB
#if (BT_USE_TRACES == TRUE)
BD_ADDR_PTR p_bda;
#endif
BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x",
BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x\n",
remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2],
remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]);
@ -618,7 +618,7 @@ tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB
{
#if (BT_USE_TRACES == TRUE)
p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x",
BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x\n",
p_bda[0], p_bda[1], p_bda[2],
p_bda[3], p_bda[4], p_bda[5]);
#endif
@ -643,7 +643,7 @@ tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB
/* Ignore role switch request if the previous request was not completed */
if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE)
{
BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d",
BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d\n",
p->switch_role_state);
return(BTM_BUSY);
}
@ -727,7 +727,7 @@ void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
tBTM_SEC_DEV_REC *p_dev_rec;
tBTM_BL_ROLE_CHG_DATA evt;
BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d",
BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d\n",
handle, status, encr_enable);
xx = btm_handle_to_acl_index(handle);
/* don't assume that we can never get a bad hci_handle */
@ -782,7 +782,7 @@ void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status;
(*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d\n",
evt.new_role, evt.hci_status, p->switch_role_state);
}
@ -792,10 +792,10 @@ void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
{
if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING)
{
BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!");
BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!\n");
btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
}
BTM_TRACE_ERROR("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d",
BTM_TRACE_ERROR("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d\n",
(UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
}
@ -815,7 +815,7 @@ tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, UINT16 *settings)
{
tACL_CONN *p;
UINT8 *localFeatures = BTM_ReadLocalFeatures();
BTM_TRACE_DEBUG ("BTM_SetLinkPolicy");
BTM_TRACE_DEBUG ("BTM_SetLinkPolicy\n");
/* BTM_TRACE_API ("BTM_SetLinkPolicy: requested settings: 0x%04x", *settings ); */
/* First, check if hold mode is supported */
@ -824,22 +824,22 @@ tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, UINT16 *settings)
if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) )
{
*settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH);
BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)", *settings );
BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)\n", *settings );
}
if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) )
{
*settings &= (~HCI_ENABLE_HOLD_MODE);
BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)", *settings );
BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)\n", *settings );
}
if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) )
{
*settings &= (~HCI_ENABLE_SNIFF_MODE);
BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)", *settings );
BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)\n", *settings );
}
if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) )
{
*settings &= (~HCI_ENABLE_PARK_MODE);
BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)", *settings );
BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)\n", *settings );
}
}
@ -864,29 +864,29 @@ void BTM_SetDefaultLinkPolicy (UINT16 settings)
{
UINT8 *localFeatures = BTM_ReadLocalFeatures();
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x", settings);
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x\n", settings);
if((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)))
{
settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)", settings);
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)\n", settings);
}
if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)))
{
settings &= ~HCI_ENABLE_HOLD_MODE;
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)", settings);
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)\n", settings);
}
if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)))
{
settings &= ~HCI_ENABLE_SNIFF_MODE;
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)", settings);
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)\n", settings);
}
if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)))
{
settings &= ~HCI_ENABLE_PARK_MODE;
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)", settings);
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)\n", settings);
}
BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x", settings);
BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x\n", settings);
btm_cb.btm_def_link_policy = settings;
@ -910,7 +910,7 @@ void btm_read_remote_version_complete (UINT8 *p)
UINT8 status;
UINT16 handle;
int xx;
BTM_TRACE_DEBUG ("btm_read_remote_version_complete");
BTM_TRACE_DEBUG ("btm_read_remote_version_complete\n");
STREAM_TO_UINT8 (status, p);
STREAM_TO_UINT16 (handle, p);
@ -952,7 +952,7 @@ void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages)
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle);
UINT8 page_idx;
BTM_TRACE_DEBUG ("btm_process_remote_ext_features");
BTM_TRACE_DEBUG ("btm_process_remote_ext_features\n");
/* Make sure we have the record to save remote features information */
if (p_dev_rec == NULL)
@ -969,7 +969,7 @@ void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages)
{
if (page_idx > HCI_EXT_FEATURES_PAGE_MAX)
{
BTM_TRACE_ERROR("%s: page=%d unexpected", __FUNCTION__, page_idx);
BTM_TRACE_ERROR("%s: page=%d unexpected\n", __FUNCTION__, page_idx);
break;
}
memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx],
@ -981,7 +981,7 @@ void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages)
/* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */
btm_sec_set_peer_sec_caps(p_acl_cb, p_dev_rec);
BTM_TRACE_API("%s: pend:%d", __FUNCTION__, req_pend);
BTM_TRACE_API("%s: pend:%d\n", __FUNCTION__, req_pend);
if (req_pend)
{
/* Request for remaining Security Features (if any) */
@ -1005,11 +1005,11 @@ void btm_read_remote_features (UINT16 handle)
UINT8 acl_idx;
tACL_CONN *p_acl_cb;
BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d", handle);
BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d\n", handle);
if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
{
BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid", handle);
BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid\n", handle);
return;
}
@ -1034,7 +1034,7 @@ void btm_read_remote_features (UINT16 handle)
*******************************************************************************/
void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number)
{
BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d", handle, page_number);
BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d\n", handle, page_number);
btsnd_hcic_rmt_ext_features(handle, page_number);
}
@ -1057,12 +1057,12 @@ void btm_read_remote_features_complete (UINT8 *p)
UINT16 handle;
UINT8 acl_idx;
BTM_TRACE_DEBUG ("btm_read_remote_features_complete");
BTM_TRACE_DEBUG ("btm_read_remote_features_complete\n");
STREAM_TO_UINT8 (status, p);
if (status != HCI_SUCCESS)
{
BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)", status);
BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)\n", status);
return;
}
@ -1070,7 +1070,7 @@ void btm_read_remote_features_complete (UINT8 *p)
if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
{
BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid", handle);
BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid\n", handle);
return;
}
@ -1086,7 +1086,7 @@ void btm_read_remote_features_complete (UINT8 *p)
/* if the remote controller has extended features and local controller supports
** HCI_Read_Remote_Extended_Features command then start reading these feature starting
** with extended features page 1 */
BTM_TRACE_DEBUG ("Start reading remote extended features");
BTM_TRACE_DEBUG ("Start reading remote extended features\n");
btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1);
return;
}
@ -1116,7 +1116,7 @@ void btm_read_remote_ext_features_complete (UINT8 *p)
UINT16 handle;
UINT8 acl_idx;
BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete");
BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete\n");
++p;
STREAM_TO_UINT16 (handle, p);
@ -1126,7 +1126,7 @@ void btm_read_remote_ext_features_complete (UINT8 *p)
/* Validate parameters */
if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
{
BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid", handle);
BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid\n", handle);
return;
}
@ -1146,13 +1146,13 @@ void btm_read_remote_ext_features_complete (UINT8 *p)
if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX))
{
page_num++;
BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)", page_num);
BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)\n", page_num);
btm_read_remote_ext_features (handle, page_num);
return;
}
/* Reading of remote feature pages is complete */
BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)", page_num);
BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)\n", page_num);
/* Process the pages */
btm_process_remote_ext_features (p_acl_cb, (UINT8) (page_num + 1));
@ -1176,12 +1176,12 @@ void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle)
tACL_CONN *p_acl_cb;
UINT8 acl_idx;
BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d",
BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d\n",
status, handle);
if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
{
BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid", handle);
BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid\n", handle);
return;
}
@ -1207,7 +1207,7 @@ void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle)
void btm_establish_continue (tACL_CONN *p_acl_cb)
{
tBTM_BL_EVENT_DATA evt_data;
BTM_TRACE_DEBUG ("btm_establish_continue");
BTM_TRACE_DEBUG ("btm_establish_continue\n");
#if (!defined(BTM_BYPASS_EXTRA_ACL_SETUP) || BTM_BYPASS_EXTRA_ACL_SETUP == FALSE)
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR)
@ -1255,7 +1255,7 @@ void btm_establish_continue (tACL_CONN *p_acl_cb)
*******************************************************************************/
void BTM_SetDefaultLinkSuperTout (UINT16 timeout)
{
BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout");
BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout\n");
btm_cb.btm_def_link_super_tout = timeout;
}
@ -1272,7 +1272,7 @@ tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, UINT16 *p_timeout)
{
tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout");
BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout\n");
if (p != (tACL_CONN *)NULL)
{
*p_timeout = p->link_super_tout;
@ -1296,7 +1296,7 @@ tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, UINT16 timeout)
{
tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout");
BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout\n");
if (p != (tACL_CONN *)NULL)
{
p->link_super_tout = timeout;
@ -1332,7 +1332,7 @@ BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport)
{
tACL_CONN *p;
BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x",
BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
remote_bda[0], remote_bda[1], remote_bda[2],
remote_bda[3], remote_bda[4], remote_bda[5]);
@ -1382,7 +1382,7 @@ UINT16 BTM_GetNumAclLinks (void)
UINT16 btm_get_acl_disc_reason_code (void)
{
UINT8 res = btm_cb.acl_disc_reason;
BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code");
BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code\n");
return(res);
}
@ -1400,7 +1400,7 @@ UINT16 btm_get_acl_disc_reason_code (void)
UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport)
{
tACL_CONN *p;
BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle");
BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle\n");
p = btm_bda_to_acl(remote_bda, transport);
if (p != (tACL_CONN *)NULL)
{
@ -1426,7 +1426,7 @@ UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport)
void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset)
{
UINT8 xx;
BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt");
BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt\n");
/* Look up the connection by handle and set the current mode */
if ((xx = btm_handle_to_acl_index(hci_handle)) < MAX_L2CAP_LINKS)
btm_cb.acl_db[xx].clock_offset = clock_offset;
@ -1453,7 +1453,7 @@ void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
tBTM_SEC_DEV_REC *p_dev_rec;
tBTM_BL_ROLE_CHG_DATA evt;
BTM_TRACE_DEBUG ("btm_acl_role_changed");
BTM_TRACE_DEBUG ("btm_acl_role_changed\n");
/* Ignore any stray events */
if (p == NULL)
{
@ -1521,7 +1521,7 @@ void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
(*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
}
BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d\n",
p_data->role, p_data->hci_status, p->switch_role_state);
#if BTM_DISC_DURING_RS == TRUE
@ -1530,10 +1530,10 @@ void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
{
if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING)
{
BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!");
BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!\n");
btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
}
BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d",
BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d\n",
(UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
}
@ -1555,7 +1555,7 @@ void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
UINT8 BTM_AllocateSCN(void)
{
UINT8 x;
BTM_TRACE_DEBUG ("BTM_AllocateSCN");
BTM_TRACE_DEBUG ("BTM_AllocateSCN\n");
// stack reserves scn 1 for HFP, HSP we still do the correct way
for (x = 1; x < BTM_MAX_SCN; x++)
@ -1609,7 +1609,7 @@ BOOLEAN BTM_TryAllocateSCN(UINT8 scn)
*******************************************************************************/
BOOLEAN BTM_FreeSCN(UINT8 scn)
{
BTM_TRACE_DEBUG ("BTM_FreeSCN ");
BTM_TRACE_DEBUG ("BTM_FreeSCN \n");
if (scn <= BTM_MAX_SCN)
{
btm_cb.btm_scn[scn-1] = FALSE;
@ -1633,7 +1633,7 @@ BOOLEAN BTM_FreeSCN(UINT8 scn)
tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types)
{
UINT16 temp_pkt_types;
BTM_TRACE_DEBUG ("btm_set_packet_types");
BTM_TRACE_DEBUG ("btm_set_packet_types\n");
/* Save in the ACL control blocks, types that we support */
temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK &
btm_cb.btm_acl_pkt_types_supported);
@ -1645,7 +1645,7 @@ tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types)
/* Exclude packet types not supported by the peer */
btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types);
BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x", temp_pkt_types);
BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x\n", temp_pkt_types);
if (!btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types))
{
@ -1670,7 +1670,7 @@ UINT16 btm_get_max_packet_size (BD_ADDR addr)
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
UINT16 pkt_types = 0;
UINT16 pkt_size = 0;
BTM_TRACE_DEBUG ("btm_get_max_packet_size");
BTM_TRACE_DEBUG ("btm_get_max_packet_size\n");
if (p != NULL)
{
pkt_types = p->pkt_types_mask;
@ -1726,7 +1726,7 @@ tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, UINT8 *lmp_version,
UINT16 *manufacturer, UINT16 *lmp_sub_version)
{
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion");
BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion\n");
if (p == NULL)
return(BTM_UNKNOWN_ADDR);
@ -1752,7 +1752,7 @@ tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, UINT8 *lmp_version,
UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr)
{
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures");
BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures\n");
if (p == NULL)
{
return(NULL);
@ -1772,7 +1772,7 @@ UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr)
UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number)
{
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures");
BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures\n");
if (p == NULL)
{
return(NULL);
@ -1780,7 +1780,7 @@ UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number)
if (page_number > HCI_EXT_FEATURES_PAGE_MAX)
{
BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown", page_number);
BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown\n", page_number);
return NULL;
}
@ -1797,7 +1797,7 @@ UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number)
UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr)
{
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages");
BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages\n");
if (p == NULL)
{
return(0);
@ -1816,7 +1816,7 @@ UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr)
UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr)
{
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures");
BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures\n");
if (p == NULL)
{
return(NULL);
@ -1838,7 +1838,7 @@ UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr)
tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level,
tBTM_BL_EVENT_MASK evt_mask)
{
BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif");
BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif\n");
if (p_level)
*p_level = btm_cb.busy_level;
@ -1867,7 +1867,7 @@ tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb)
{
tACL_CONN *p = &btm_cb.acl_db[0];
BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x",
BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x\n",
bd[0], bd[1], bd[2],
bd[3], bd[4], bd[5]);
@ -1910,7 +1910,7 @@ void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
{
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qossu_cmpl_cb;
tBTM_QOS_SETUP_CMPL qossu;
BTM_TRACE_DEBUG ("btm_qos_setup_complete");
BTM_TRACE_DEBUG ("btm_qos_setup_complete\n");
btu_stop_timer (&btm_cb.devcb.qossu_timer);
btm_cb.devcb.p_qossu_cmpl_cb = NULL;
@ -1929,7 +1929,7 @@ void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
qossu.flow.latency = p_flow->latency;
qossu.flow.delay_variation = p_flow->delay_variation;
}
BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x",
BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x\n",
qossu.flow.delay_variation);
(*p_cb)(&qossu);
}
@ -1955,7 +1955,7 @@ tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
tBT_DEVICE_TYPE dev_type;
tBLE_ADDR_TYPE addr_type;
#endif
BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x",
BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
remote_bda[0], remote_bda[1], remote_bda[2],
remote_bda[3], remote_bda[4], remote_bda[5]);
@ -2006,7 +2006,7 @@ tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
{
tACL_CONN *p;
BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x",
BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
remote_bda[0], remote_bda[1], remote_bda[2],
remote_bda[3], remote_bda[4], remote_bda[5]);
@ -2054,7 +2054,7 @@ tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_C
#define BTM_READ_RSSI_TYPE_CUR 0x00
#define BTM_READ_RSSI_TYPE_MAX 0X01
BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x",
BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
remote_bda[0], remote_bda[1], remote_bda[2],
remote_bda[3], remote_bda[4], remote_bda[5]);
@ -2111,7 +2111,7 @@ void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble)
UINT16 handle;
tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
UINT16 index;
BTM_TRACE_DEBUG ("btm_read_tx_power_complete");
BTM_TRACE_DEBUG ("btm_read_tx_power_complete\n");
btu_stop_timer (&btm_cb.devcb.tx_power_timer);
/* If there was a callback registered for read rssi, call it */
@ -2147,7 +2147,7 @@ void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble)
memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN);
}
#endif
BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x",
BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x\n",
results.tx_power, results.hci_status);
}
else
@ -2174,7 +2174,7 @@ void btm_read_rssi_complete (UINT8 *p)
UINT16 handle;
tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
UINT16 index;
BTM_TRACE_DEBUG ("btm_read_rssi_complete");
BTM_TRACE_DEBUG ("btm_read_rssi_complete\n");
btu_stop_timer (&btm_cb.devcb.rssi_timer);
/* If there was a callback registered for read rssi, call it */
@ -2191,7 +2191,7 @@ void btm_read_rssi_complete (UINT8 *p)
STREAM_TO_UINT16 (handle, p);
STREAM_TO_UINT8 (results.rssi, p);
BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x",
BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x\n",
results.rssi, results.hci_status);
/* Search through the list of active channels for the correct BD Addr */
@ -2228,7 +2228,7 @@ void btm_read_link_quality_complete (UINT8 *p)
UINT16 handle;
tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
UINT16 index;
BTM_TRACE_DEBUG ("btm_read_link_quality_complete");
BTM_TRACE_DEBUG ("btm_read_link_quality_complete\n");
btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
/* If there was a callback registered for read rssi, call it */
@ -2245,7 +2245,7 @@ void btm_read_link_quality_complete (UINT8 *p)
STREAM_TO_UINT16 (handle, p);
STREAM_TO_UINT8 (results.link_quality, p);
BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x",
BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x\n",
results.link_quality, results.hci_status);
/* Search through the list of active channels for the correct BD Addr */
@ -2279,7 +2279,7 @@ tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport)
UINT16 hci_handle = BTM_GetHCIConnHandle(bd_addr, transport);
tBTM_STATUS status = BTM_SUCCESS;
BTM_TRACE_DEBUG ("btm_remove_acl");
BTM_TRACE_DEBUG ("btm_remove_acl\n");
#if BTM_DISC_DURING_RS == TRUE
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
@ -2317,7 +2317,7 @@ tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport)
*******************************************************************************/
UINT8 BTM_SetTraceLevel (UINT8 new_level)
{
BTM_TRACE_DEBUG ("BTM_SetTraceLevel");
BTM_TRACE_DEBUG ("BTM_SetTraceLevel\n");
if (new_level != 0xFF)
btm_cb.trace_level = new_level;
@ -2339,7 +2339,7 @@ void btm_cont_rswitch (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec,
UINT8 hci_status)
{
BOOLEAN sw_ok = TRUE;
BTM_TRACE_DEBUG ("btm_cont_rswitch");
BTM_TRACE_DEBUG ("btm_cont_rswitch\n");
/* Check to see if encryption needs to be turned off if pending
change of link key or role switch */
if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
@ -2397,7 +2397,7 @@ void btm_acl_resubmit_page (void)
BT_HDR *p_buf;
UINT8 *pp;
BD_ADDR bda;
BTM_TRACE_DEBUG ("btm_acl_resubmit_page");
BTM_TRACE_DEBUG ("btm_acl_resubmit_page\n");
/* If there were other page request schedule can start the next one */
if ((p_buf = (BT_HDR *)GKI_dequeue (&btm_cb.page_queue)) != NULL)
{
@ -2428,7 +2428,7 @@ void btm_acl_resubmit_page (void)
void btm_acl_reset_paging (void)
{
BT_HDR *p;
BTM_TRACE_DEBUG ("btm_acl_reset_paging");
BTM_TRACE_DEBUG ("btm_acl_reset_paging\n");
/* If we sent reset we are definitely not paging any more */
while ((p = (BT_HDR *)GKI_dequeue(&btm_cb.page_queue)) != NULL)
GKI_freebuf (p);
@ -2447,7 +2447,7 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
{
tBTM_SEC_DEV_REC *p_dev_rec;
BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x",
BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x\n",
btm_cb.discing, btm_cb.paging,
(bda[0]<<16) + (bda[1]<<8) + bda[2], (bda[3]<<16) + (bda[4] << 8) + bda[5]);
if (btm_cb.discing)
@ -2459,7 +2459,7 @@ void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
{
if (!BTM_ACL_IS_CONNECTED (bda))
{
BTM_TRACE_DEBUG ("connecting_bda: %06x%06x",
BTM_TRACE_DEBUG ("connecting_bda: %06x%06x\n",
(btm_cb.connecting_bda[0]<<16) + (btm_cb.connecting_bda[1]<<8) +
btm_cb.connecting_bda[2],
(btm_cb.connecting_bda[3]<<16) + (btm_cb.connecting_bda[4] << 8) +
@ -2504,7 +2504,7 @@ BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda)
/* Report possible collision to the upper layer. */
if (btm_cb.p_bl_changed_cb)
{
BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x",
BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
evt_data.event = BTM_BL_COLLISION_EVT;

View file

@ -67,7 +67,7 @@ BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name,
int i, j;
BOOLEAN found = FALSE;
BTM_TRACE_API("%s, link key type:%x", __FUNCTION__,key_type);
BTM_TRACE_API("%s, link key type:%x\n", __FUNCTION__,key_type);
p_dev_rec = btm_find_dev (bd_addr);
if (!p_dev_rec)
{
@ -141,7 +141,7 @@ BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name,
if (link_key)
{
BTM_TRACE_EVENT ("BTM_SecAddDevice() BDA: %02x:%02x:%02x:%02x:%02x:%02x",
BTM_TRACE_EVENT ("BTM_SecAddDevice() BDA: %02x:%02x:%02x:%02x:%02x:%02x\n",
bd_addr[0], bd_addr[1], bd_addr[2],
bd_addr[3], bd_addr[4], bd_addr[5]);
p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_KNOWN;
@ -190,7 +190,7 @@ BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr)
if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) ||
BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR))
{
BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active", __func__);
BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active\n", __func__);
return FALSE;
}
@ -243,7 +243,7 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
DEV_CLASS old_cod;
int i_new_entry = BTM_SEC_MAX_DEVICE_RECORDS;
int i_old_entry = BTM_SEC_MAX_DEVICE_RECORDS;
BTM_TRACE_EVENT ("btm_sec_alloc_dev");
BTM_TRACE_EVENT ("btm_sec_alloc_dev\n");
for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++)
{
@ -252,7 +252,7 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
(!memcmp (btm_cb.sec_dev_rec[i].bd_addr, bd_addr, BD_ADDR_LEN)))
{
i_old_entry = i;
BTM_TRACE_EVENT ("btm_sec_alloc_dev old device found");
BTM_TRACE_EVENT ("btm_sec_alloc_dev old device found\n");
break;
}
}
@ -284,7 +284,7 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
/* Retain the old COD for device */
if(i_old_entry != BTM_SEC_MAX_DEVICE_RECORDS) {
BTM_TRACE_EVENT ("btm_sec_alloc_dev restoring cod ");
BTM_TRACE_EVENT ("btm_sec_alloc_dev restoring cod \n");
memcpy (p_dev_rec->dev_class, old_cod, DEV_CLASS_LEN);
}
@ -377,7 +377,7 @@ BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr)
{
if (HCI_SWITCH_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
{
BTM_TRACE_DEBUG("btm_dev_support_switch return TRUE (feature found)");
BTM_TRACE_DEBUG("btm_dev_support_switch return TRUE (feature found)\n");
return (TRUE);
}
@ -394,12 +394,12 @@ BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr)
/* If we don't know peer's capabilities, assume it supports Role-switch */
if (feature_empty)
{
BTM_TRACE_DEBUG("btm_dev_support_switch return TRUE (feature empty)");
BTM_TRACE_DEBUG("btm_dev_support_switch return TRUE (feature empty)\n");
return (TRUE);
}
}
BTM_TRACE_DEBUG("btm_dev_support_switch return FALSE");
BTM_TRACE_DEBUG("btm_dev_support_switch return FALSE\n");
return(FALSE);
}
@ -484,7 +484,7 @@ void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec)
tBTM_SEC_DEV_REC temp_rec = *p_target_rec;
BD_ADDR dummy_bda = {0};
BTM_TRACE_DEBUG("%s", __func__);
BTM_TRACE_DEBUG("%s\n", __func__);
for (uint8_t i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++, p_dev_rec++)
{
@ -539,7 +539,7 @@ void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec)
tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr)
{
tBTM_SEC_DEV_REC *p_dev_rec;
BTM_TRACE_EVENT ("btm_find_or_alloc_dev");
BTM_TRACE_EVENT ("btm_find_or_alloc_dev\n");
if ((p_dev_rec = btm_find_dev (bd_addr)) == NULL)
{

File diff suppressed because it is too large Load diff

View file

@ -44,7 +44,7 @@
#endif
#endif
extern fixed_queue_t *btif_msg_queue;
// extern fixed_queue_t *btif_msg_queue;
// Communication queue from bta thread to bt_workqueue.
fixed_queue_t *btu_bta_msg_queue;

View file

@ -299,7 +299,7 @@ UINT32 SDP_CreateRecord (void)
p_db->record[p_db->num_records].record_handle = handle;
p_db->num_records++;
SDP_TRACE_DEBUG("SDP_CreateRecord ok, num_records:%d", p_db->num_records);
SDP_TRACE_DEBUG("SDP_CreateRecord ok, num_records:%d\n", p_db->num_records);
/* Add the first attribute (the handle) automatically */
UINT32_TO_BE_FIELD (buf, handle);
SDP_AddAttribute (handle, ATTR_ID_SERVICE_RECORD_HDL, UINT_DESC_TYPE,
@ -307,7 +307,7 @@ UINT32 SDP_CreateRecord (void)
return (p_db->record[p_db->num_records - 1].record_handle);
}
else SDP_TRACE_ERROR("SDP_CreateRecord fail, exceed maximum records:%d", SDP_MAX_RECORDS);
else SDP_TRACE_ERROR("SDP_CreateRecord fail, exceed maximum records:%d\n", SDP_MAX_RECORDS);
#endif
return (0);
}
@ -361,7 +361,7 @@ BOOLEAN SDP_DeleteRecord (UINT32 handle)
sdp_cb.server_db.num_records--;
SDP_TRACE_DEBUG("SDP_DeleteRecord ok, num_records:%d", sdp_cb.server_db.num_records);
SDP_TRACE_DEBUG("SDP_DeleteRecord ok, num_records:%d\n", sdp_cb.server_db.num_records);
/* if we're deleting the primary DI record, clear the */
/* value in the control block */
if( sdp_cb.server_db.di_primary_handle == handle )
@ -417,17 +417,17 @@ BOOLEAN SDP_AddAttribute (UINT32 handle, UINT16 attr_id, UINT8 attr_type,
{
sprintf((char *)&num_array[i*2],"%02X",(UINT8)(p_val[i]));
}
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s",
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s\n",
handle,attr_id,attr_type,attr_len,p_val,num_array);
}
else if (attr_type == BOOLEAN_DESC_TYPE)
{
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%d",
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%d\n",
handle,attr_id,attr_type,attr_len,p_val,*p_val);
}
else
{
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s",
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s\n",
handle,attr_id,attr_type,attr_len,p_val,p_val);
}
}
@ -475,7 +475,7 @@ BOOLEAN SDP_AddAttribute (UINT32 handle, UINT16 attr_id, UINT8 attr_type,
/* do truncate only for text string type descriptor */
if (attr_type == TEXT_STR_DESC_TYPE)
{
SDP_TRACE_WARNING("SDP_AddAttribute: attr_len:%d too long. truncate to (%d)",
SDP_TRACE_WARNING("SDP_AddAttribute: attr_len:%d too long. truncate to (%d)\n",
attr_len, SDP_MAX_PAD_LEN - p_rec->free_pad_ptr );
attr_len = SDP_MAX_PAD_LEN - p_rec->free_pad_ptr;
@ -496,7 +496,7 @@ BOOLEAN SDP_AddAttribute (UINT32 handle, UINT16 attr_id, UINT8 attr_type,
else if ((attr_len == 0 && p_attr->len != 0) || /* if truncate to 0 length, simply don't add */
p_val == 0)
{
SDP_TRACE_ERROR("SDP_AddAttribute fail, length exceed maximum: ID %d: attr_len:%d ",
SDP_TRACE_ERROR("SDP_AddAttribute fail, length exceed maximum: ID %d: attr_len:%d \n",
attr_id, attr_len );
p_attr->id = p_attr->type = p_attr->len = 0;
return (FALSE);
@ -536,7 +536,7 @@ BOOLEAN SDP_AddSequence (UINT32 handle, UINT16 attr_id, UINT16 num_elem,
if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
{
SDP_TRACE_ERROR("SDP_AddSequence cannot get a buffer!");
SDP_TRACE_ERROR("SDP_AddSequence cannot get a buffer!\n");
return (FALSE);
}
p = p_buff;
@ -577,12 +577,12 @@ BOOLEAN SDP_AddSequence (UINT32 handle, UINT16 attr_id, UINT16 num_elem,
if(p_head == p_buff)
{
/* the first element exceed the max length */
SDP_TRACE_ERROR ("SDP_AddSequence - too long(attribute is not added)!!");
SDP_TRACE_ERROR ("SDP_AddSequence - too long(attribute is not added)!!\n");
GKI_freebuf(p_buff);
return FALSE;
}
else
SDP_TRACE_ERROR ("SDP_AddSequence - too long, add %d elements of %d", xx, num_elem);
SDP_TRACE_ERROR ("SDP_AddSequence - too long, add %d elements of %d\n", xx, num_elem);
break;
}
}
@ -619,7 +619,7 @@ BOOLEAN SDP_AddUuidSequence (UINT32 handle, UINT16 attr_id, UINT16 num_uuids,
if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
{
SDP_TRACE_ERROR("SDP_AddUuidSequence cannot get a buffer!");
SDP_TRACE_ERROR("SDP_AddUuidSequence cannot get a buffer!\n");
return (FALSE);
}
p = p_buff;
@ -632,7 +632,7 @@ BOOLEAN SDP_AddUuidSequence (UINT32 handle, UINT16 attr_id, UINT16 num_uuids,
if((p - p_buff) > max_len)
{
SDP_TRACE_WARNING ("SDP_AddUuidSequence - too long, add %d uuids of %d", xx, num_uuids);
SDP_TRACE_WARNING ("SDP_AddUuidSequence - too long, add %d uuids of %d\n", xx, num_uuids);
break;
}
}
@ -667,7 +667,7 @@ BOOLEAN SDP_AddProtocolList (UINT32 handle, UINT16 num_elem,
if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
{
SDP_TRACE_ERROR("SDP_AddProtocolList cannot get a buffer!");
SDP_TRACE_ERROR("SDP_AddProtocolList cannot get a buffer!\n");
return (FALSE);
}
@ -706,7 +706,7 @@ BOOLEAN SDP_AddAdditionProtoLists (UINT32 handle, UINT16 num_elem,
if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
{
SDP_TRACE_ERROR("SDP_AddAdditionProtoLists cannot get a buffer!");
SDP_TRACE_ERROR("SDP_AddAdditionProtoLists cannot get a buffer!\n");
return (FALSE);
}
p = p_buff;
@ -755,7 +755,7 @@ BOOLEAN SDP_AddProfileDescriptorList (UINT32 handle, UINT16 profile_uuid,
if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL)
{
SDP_TRACE_ERROR("SDP_AddProfileDescriptorList cannot get a buffer!");
SDP_TRACE_ERROR("SDP_AddProfileDescriptorList cannot get a buffer!\n");
return (FALSE);
}
p = p_buff+2;
@ -804,7 +804,7 @@ BOOLEAN SDP_AddLanguageBaseAttrIDList (UINT32 handle, UINT16 lang,
if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL)
{
SDP_TRACE_ERROR("SDP_AddLanguageBaseAttrIDList cannot get a buffer!");
SDP_TRACE_ERROR("SDP_AddLanguageBaseAttrIDList cannot get a buffer!\n");
return (FALSE);
}
p = p_buff;
@ -853,7 +853,7 @@ BOOLEAN SDP_AddServiceClassIdList (UINT32 handle, UINT16 num_services,
if ((p_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
{
SDP_TRACE_ERROR("SDP_AddServiceClassIdList cannot get a buffer!");
SDP_TRACE_ERROR("SDP_AddServiceClassIdList cannot get a buffer!\n");
return (FALSE);
}
p = p_buff;
@ -899,7 +899,7 @@ BOOLEAN SDP_DeleteAttribute (UINT32 handle, UINT16 attr_id)
{
tSDP_ATTRIBUTE *p_attr = &p_rec->attribute[0];
SDP_TRACE_API("Deleting attr_id 0x%04x for handle 0x%x", attr_id, handle);
SDP_TRACE_API("Deleting attr_id 0x%04x for handle 0x%x\n", attr_id, handle);
/* Found it. Now, find the attribute */
for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++)
{

View file

@ -171,7 +171,7 @@ static void sdp_snd_service_search_req(tCONN_CB *p_ccb, UINT8 cont_len, UINT8 *
p_cmd->len = (UINT16)(p - p_start);
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("sdp_snd_service_search_req cont_len :%d disc_state:%d",cont_len, p_ccb->disc_state);
SDP_TRACE_WARNING("sdp_snd_service_search_req cont_len :%d disc_state:%d\n",cont_len, p_ccb->disc_state);
#endif
@ -228,7 +228,7 @@ void sdp_disc_server_rsp (tCONN_CB *p_ccb, BT_HDR *p_msg)
BOOLEAN invalid_pdu = TRUE;
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("sdp_disc_server_rsp disc_state:%d", p_ccb->disc_state);
SDP_TRACE_WARNING("sdp_disc_server_rsp disc_state:%d\n", p_ccb->disc_state);
#endif
/* stop inactivity timer when we receive a response */
@ -270,7 +270,7 @@ void sdp_disc_server_rsp (tCONN_CB *p_ccb, BT_HDR *p_msg)
if (invalid_pdu)
{
SDP_TRACE_WARNING ("SDP - Unexp. PDU: %d in state: %d", rsp_pdu, p_ccb->disc_state);
SDP_TRACE_WARNING ("SDP - Unexp. PDU: %d in state: %d\n", rsp_pdu, p_ccb->disc_state);
sdp_disconnect (p_ccb, SDP_GENERIC_ERROR);
}
}
@ -300,7 +300,7 @@ static void process_service_search_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
p_ccb->num_handles += cur_handles;
if (p_ccb->num_handles == 0)
{
SDP_TRACE_WARNING ("SDP - Rcvd ServiceSearchRsp, no matches");
SDP_TRACE_WARNING ("SDP - Rcvd ServiceSearchRsp, no matches\n");
sdp_disconnect (p_ccb, SDP_NO_RECS_MATCH);
return;
}
@ -359,9 +359,9 @@ static void sdp_copy_raw_data (tCONN_CB *p_ccb, BOOLEAN offset)
for (i = 0; i < p_ccb->list_len; i++)
{
sprintf((char *)&num_array[i*2],"%02X",(UINT8)(p_ccb->rsp_list[i]));
sprintf((char *)&num_array[i*2],"%02X\n",(UINT8)(p_ccb->rsp_list[i]));
}
SDP_TRACE_WARNING("result :%s",num_array);
SDP_TRACE_WARNING("result :%s\n",num_array);
#endif
if(p_ccb->p_db->raw_data)
@ -380,7 +380,7 @@ static void sdp_copy_raw_data (tCONN_CB *p_ccb, BOOLEAN offset)
cpy_len = list_len;
}
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("list_len :%d cpy_len:%d raw_size:%d raw_used:%d",
SDP_TRACE_WARNING("list_len :%d cpy_len:%d raw_size:%d raw_used:%d\n",
list_len, cpy_len, p_ccb->p_db->raw_size, p_ccb->p_db->raw_used);
#endif
memcpy (&p_ccb->p_db->raw_data[p_ccb->p_db->raw_used], p, cpy_len);
@ -406,14 +406,14 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
BOOLEAN cont_request_needed = FALSE;
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("process_service_attr_rsp raw inc:%d",
SDP_TRACE_WARNING("process_service_attr_rsp raw inc:%d\n",
SDP_RAW_DATA_INCLUDED);
#endif
/* If p_reply is NULL, we were called after the records handles were read */
if (p_reply)
{
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("ID & len: 0x%02x-%02x-%02x-%02x",
SDP_TRACE_WARNING("ID & len: 0x%02x-%02x-%02x-%02x\n",
p_reply[0], p_reply[1], p_reply[2], p_reply[3]);
#endif
/* Skip transaction ID and length */
@ -421,7 +421,7 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
BE_STREAM_TO_UINT16 (list_byte_count, p_reply);
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("list_byte_count:%d", list_byte_count);
SDP_TRACE_WARNING("list_byte_count:%d\n", list_byte_count);
#endif
/* Copy the response to the scratchpad. First, a safety check on the length */
@ -432,7 +432,7 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
}
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("list_len: %d, list_byte_count: %d",
SDP_TRACE_WARNING("list_len: %d, list_byte_count: %d\n",
p_ccb->list_len, list_byte_count);
#endif
if (p_ccb->rsp_list == NULL)
@ -440,7 +440,7 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (SDP_MAX_LIST_BYTE_COUNT);
if (p_ccb->rsp_list == NULL)
{
SDP_TRACE_ERROR ("SDP - no gki buf to save rsp");
SDP_TRACE_ERROR ("SDP - no gki buf to save rsp\n");
sdp_disconnect (p_ccb, SDP_NO_RESOURCES);
return;
}
@ -449,10 +449,10 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
p_ccb->list_len += list_byte_count;
p_reply += list_byte_count;
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("list_len: %d(attr_rsp)", p_ccb->list_len);
SDP_TRACE_WARNING("list_len: %d(attr_rsp)\n", p_ccb->list_len);
/* Check if we need to request a continuation */
SDP_TRACE_WARNING("*p_reply:%d(%d)", *p_reply, SDP_MAX_CONTINUATION_LEN);
SDP_TRACE_WARNING("*p_reply:%d(%d)\n", *p_reply, SDP_MAX_CONTINUATION_LEN);
#endif
if (*p_reply)
{
@ -467,7 +467,7 @@ static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
{
#if (SDP_RAW_DATA_INCLUDED == TRUE)
SDP_TRACE_WARNING("process_service_attr_rsp");
SDP_TRACE_WARNING("process_service_attr_rsp\n");
sdp_copy_raw_data (p_ccb, FALSE);
#endif
@ -566,13 +566,13 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
BOOLEAN cont_request_needed = FALSE;
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("process_service_search_attr_rsp");
SDP_TRACE_WARNING("process_service_search_attr_rsp\n");
#endif
/* If p_reply is NULL, we were called for the initial read */
if (p_reply)
{
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("ID & len: 0x%02x-%02x-%02x-%02x",
SDP_TRACE_WARNING("ID & len: 0x%02x-%02x-%02x-%02x\n",
p_reply[0], p_reply[1], p_reply[2], p_reply[3]);
#endif
/* Skip transaction ID and length */
@ -580,7 +580,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
BE_STREAM_TO_UINT16 (lists_byte_count, p_reply);
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("lists_byte_count:%d", lists_byte_count);
SDP_TRACE_WARNING("lists_byte_count:%d\n", lists_byte_count);
#endif
/* Copy the response to the scratchpad. First, a safety check on the length */
@ -591,7 +591,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
}
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("list_len: %d, list_byte_count: %d",
SDP_TRACE_WARNING("list_len: %d, list_byte_count: %d\n",
p_ccb->list_len, lists_byte_count);
#endif
if (p_ccb->rsp_list == NULL)
@ -599,7 +599,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (SDP_MAX_LIST_BYTE_COUNT);
if (p_ccb->rsp_list == NULL)
{
SDP_TRACE_ERROR ("SDP - no gki buf to save rsp");
SDP_TRACE_ERROR ("SDP - no gki buf to save rsp\n");
sdp_disconnect (p_ccb, SDP_NO_RESOURCES);
return;
}
@ -608,10 +608,10 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
p_ccb->list_len += lists_byte_count;
p_reply += lists_byte_count;
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("list_len: %d(search_attr_rsp)", p_ccb->list_len);
SDP_TRACE_WARNING("list_len: %d(search_attr_rsp)\n", p_ccb->list_len);
/* Check if we need to request a continuation */
SDP_TRACE_WARNING("*p_reply:%d(%d)", *p_reply, SDP_MAX_CONTINUATION_LEN);
SDP_TRACE_WARNING("*p_reply:%d(%d)\n", *p_reply, SDP_MAX_CONTINUATION_LEN);
#endif
if (*p_reply)
{
@ -626,7 +626,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
}
#if (SDP_DEBUG_RAW == TRUE)
SDP_TRACE_WARNING("cont_request_needed:%d", cont_request_needed);
SDP_TRACE_WARNING("cont_request_needed:%d\n", cont_request_needed);
#endif
/* If continuation request (or first time request) */
if ((cont_request_needed) || (!p_reply))
@ -699,7 +699,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
/*******************************************************************/
#if (SDP_RAW_DATA_INCLUDED == TRUE)
SDP_TRACE_WARNING("process_service_search_attr_rsp");
SDP_TRACE_WARNING("process_service_search_attr_rsp\n");
sdp_copy_raw_data (p_ccb, TRUE);
#endif
@ -710,7 +710,7 @@ static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
if ((type >> 3) != DATA_ELE_SEQ_DESC_TYPE)
{
SDP_TRACE_WARNING ("SDP - Wrong type: 0x%02x in attr_rsp", type);
SDP_TRACE_WARNING ("SDP - Wrong type: 0x%02x in attr_rsp\n", type);
return;
}
p = sdpu_get_len_from_type (p, type, &seq_len);
@ -758,14 +758,14 @@ static UINT8 *save_attr_seq (tCONN_CB *p_ccb, UINT8 *p, UINT8 *p_msg_end)
if ((type >> 3) != DATA_ELE_SEQ_DESC_TYPE)
{
SDP_TRACE_WARNING ("SDP - Wrong type: 0x%02x in attr_rsp", type);
SDP_TRACE_WARNING ("SDP - Wrong type: 0x%02x in attr_rsp\n", type);
return (NULL);
}
p = sdpu_get_len_from_type (p, type, &seq_len);
if ((p + seq_len) > p_msg_end)
{
SDP_TRACE_WARNING ("SDP - Bad len in attr_rsp %d", seq_len);
SDP_TRACE_WARNING ("SDP - Bad len in attr_rsp %d\n", seq_len);
return (NULL);
}
@ -773,7 +773,7 @@ static UINT8 *save_attr_seq (tCONN_CB *p_ccb, UINT8 *p, UINT8 *p_msg_end)
p_rec = add_record (p_ccb->p_db, p_ccb->device_address);
if (!p_rec)
{
SDP_TRACE_WARNING ("SDP - DB full add_record");
SDP_TRACE_WARNING ("SDP - DB full add_record\n");
return (NULL);
}
@ -786,7 +786,7 @@ static UINT8 *save_attr_seq (tCONN_CB *p_ccb, UINT8 *p, UINT8 *p_msg_end)
p = sdpu_get_len_from_type (p, type, &attr_len);
if (((type >> 3) != UINT_DESC_TYPE) || (attr_len != 2))
{
SDP_TRACE_WARNING ("SDP - Bad type: 0x%02x or len: %d in attr_rsp", type, attr_len);
SDP_TRACE_WARNING ("SDP - Bad type: 0x%02x or len: %d in attr_rsp\n", type, attr_len);
return (NULL);
}
BE_STREAM_TO_UINT16 (attr_id, p);
@ -796,7 +796,7 @@ static UINT8 *save_attr_seq (tCONN_CB *p_ccb, UINT8 *p, UINT8 *p_msg_end)
if (!p)
{
SDP_TRACE_WARNING ("SDP - DB full add_attr");
SDP_TRACE_WARNING ("SDP - DB full add_attr\n");
return (NULL);
}
}
@ -916,7 +916,7 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
/* SDP_TRACE_DEBUG ("SDP - attr nest level:%d(list)", nest_level); */
if (nest_level >= MAX_NEST_LEVELS)
{
SDP_TRACE_ERROR ("SDP - attr nesting too deep");
SDP_TRACE_ERROR ("SDP - attr nesting too deep\n");
return (p_end);
}
@ -993,7 +993,7 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
}
break;
default:
SDP_TRACE_WARNING ("SDP - bad len in UUID attr: %d", attr_len);
SDP_TRACE_WARNING ("SDP - bad len in UUID attr: %d\n", attr_len);
return (p + attr_len);
}
break;
@ -1009,7 +1009,7 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
/* SDP_TRACE_DEBUG ("SDP - attr nest level:%d", nest_level); */
if (nest_level >= MAX_NEST_LEVELS)
{
SDP_TRACE_ERROR ("SDP - attr nesting too deep");
SDP_TRACE_ERROR ("SDP - attr nesting too deep\n");
return (p_end);
}
if(is_additional_list != 0 || attr_id == ATTR_ID_ADDITION_PROTO_DESC_LISTS)
@ -1038,7 +1038,7 @@ static UINT8 *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
p_attr->attr_value.v.u8 = *p++;
break;
default:
SDP_TRACE_WARNING ("SDP - bad len in boolean attr: %d", attr_len);
SDP_TRACE_WARNING ("SDP - bad len in boolean attr: %d\n", attr_len);
return (p + attr_len);
}
break;

View file

@ -97,7 +97,7 @@ void sdp_init (void)
if (!BTM_SetSecurityLevel (FALSE, SDP_SERVICE_NAME, BTM_SEC_SERVICE_SDP_SERVER,
SDP_SECURITY_LEVEL, SDP_PSM, 0, 0))
{
SDP_TRACE_ERROR ("Security Registration Server failed");
SDP_TRACE_ERROR ("Security Registration Server failed\n");
return;
}
#endif
@ -107,7 +107,7 @@ void sdp_init (void)
if (!BTM_SetSecurityLevel (TRUE, SDP_SERVICE_NAME, BTM_SEC_SERVICE_SDP_SERVER,
SDP_SECURITY_LEVEL, SDP_PSM, 0, 0))
{
SDP_TRACE_ERROR ("Security Registration for Client failed");
SDP_TRACE_ERROR ("Security Registration for Client failed\n");
return;
}
#endif
@ -133,7 +133,7 @@ void sdp_init (void)
/* Now, register with L2CAP */
if (!L2CA_Register (SDP_PSM, &sdp_cb.reg_info))
{
SDP_TRACE_ERROR ("SDP Registration failed");
SDP_TRACE_ERROR ("SDP Registration failed\n");
}
}
@ -193,7 +193,7 @@ static void sdp_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, UIN
if (cfg.fcr_present)
{
SDP_TRACE_DEBUG("sdp_connect_ind: mode %u, txwinsz %u, max_trans %u, rtrans_tout %u, mon_tout %u, mps %u",
SDP_TRACE_DEBUG("sdp_connect_ind: mode %u, txwinsz %u, max_trans %u, rtrans_tout %u, mon_tout %u, mps %u\n",
cfg.fcr.mode, cfg.fcr.tx_win_sz, cfg.fcr.max_transmit,
cfg.fcr.rtrans_tout,cfg.fcr.mon_tout, cfg.fcr.mps);
}
@ -208,7 +208,7 @@ static void sdp_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, UIN
}
}
SDP_TRACE_EVENT ("SDP - Rcvd L2CAP conn ind, sent config req, CID 0x%x", p_ccb->connection_id);
SDP_TRACE_EVENT ("SDP - Rcvd L2CAP conn ind, sent config req, CID 0x%x\n", p_ccb->connection_id);
#else /* No server */
/* Reject the connection */
L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0);
@ -235,7 +235,7 @@ static void sdp_connect_cfm (UINT16 l2cap_cid, UINT16 result)
/* Find CCB based on CID */
if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL)
{
SDP_TRACE_WARNING ("SDP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid);
SDP_TRACE_WARNING ("SDP - Rcvd conn cnf for unknown CID 0x%x\n", l2cap_cid);
return;
}
@ -249,7 +249,7 @@ static void sdp_connect_cfm (UINT16 l2cap_cid, UINT16 result)
if (cfg.fcr_present)
{
SDP_TRACE_DEBUG("sdp_connect_cfm: mode %u, txwinsz %u, max_trans %u, rtrans_tout %u, mon_tout %u, mps %u",
SDP_TRACE_DEBUG("sdp_connect_cfm: mode %u, txwinsz %u, max_trans %u, rtrans_tout %u, mon_tout %u, mps %u\n",
cfg.fcr.mode, cfg.fcr.tx_win_sz, cfg.fcr.max_transmit,
cfg.fcr.rtrans_tout,cfg.fcr.mon_tout, cfg.fcr.mps);
}
@ -263,11 +263,11 @@ static void sdp_connect_cfm (UINT16 l2cap_cid, UINT16 result)
L2CA_ConfigReq (l2cap_cid, &cfg);
}
SDP_TRACE_EVENT ("SDP - got conn cnf, sent cfg req, CID: 0x%x", p_ccb->connection_id);
SDP_TRACE_EVENT ("SDP - got conn cnf, sent cfg req, CID: 0x%x\n", p_ccb->connection_id);
}
else
{
SDP_TRACE_WARNING ("SDP - Rcvd conn cnf with error: 0x%x CID 0x%x", result, p_ccb->connection_id);
SDP_TRACE_WARNING ("SDP - Rcvd conn cnf with error: 0x%x CID 0x%x\n", result, p_ccb->connection_id);
/* Tell the user if he has a callback */
if (p_ccb->p_cb || p_ccb->p_cb2)
@ -312,7 +312,7 @@ static void sdp_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
/* Find CCB based on CID */
if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL)
{
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x%x\n", l2cap_cid);
return;
}
@ -346,7 +346,7 @@ static void sdp_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
{
p_cfg->fcr.tx_win_sz = sdp_cb.l2cap_my_cfg.fcr.tx_win_sz;
p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS;
SDP_TRACE_DEBUG("sdp_config_ind(CONFIG) -> Please try again with SMALLER TX WINDOW");
SDP_TRACE_DEBUG("sdp_config_ind(CONFIG) -> Please try again with SMALLER TX WINDOW\n");
}
/* Reject if locally we want basic and they don't */
@ -355,12 +355,12 @@ static void sdp_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
/* Ask for a new setup */
p_cfg->fcr.mode = L2CAP_FCR_BASIC_MODE;
p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS;
SDP_TRACE_DEBUG("sdp_config_ind(CONFIG) -> Please try again with BASIC mode");
SDP_TRACE_DEBUG("sdp_config_ind(CONFIG) -> Please try again with BASIC mode\n");
}
/* Remain in configure state and give the peer our desired configuration */
if (p_cfg->result != L2CAP_CFG_OK)
{
SDP_TRACE_WARNING ("SDP - Rcvd cfg ind, Unacceptable Parameters sent cfg cfm, CID: 0x%x", l2cap_cid);
SDP_TRACE_WARNING ("SDP - Rcvd cfg ind, Unacceptable Parameters sent cfg cfm, CID: 0x%x\n", l2cap_cid);
L2CA_ConfigRsp (l2cap_cid, p_cfg);
return;
}
@ -371,7 +371,7 @@ static void sdp_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
L2CA_ConfigRsp (l2cap_cid, p_cfg);
SDP_TRACE_EVENT ("SDP - Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid);
SDP_TRACE_EVENT ("SDP - Rcvd cfg ind, sent cfg cfm, CID: 0x%x\n", l2cap_cid);
p_ccb->con_flags |= SDP_FLAGS_HIS_CFG_DONE;
@ -403,12 +403,12 @@ static void sdp_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
{
tCONN_CB *p_ccb;
SDP_TRACE_EVENT ("SDP - Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, p_cfg->result);
SDP_TRACE_EVENT ("SDP - Rcvd cfg cfm, CID: 0x%x Result: %d\n", l2cap_cid, p_cfg->result);
/* Find CCB based on CID */
if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL)
{
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x%x\n", l2cap_cid);
return;
}
@ -464,14 +464,14 @@ static void sdp_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed)
/* Find CCB based on CID */
if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL)
{
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid);
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP disc, unknown CID: 0x%x\n", l2cap_cid);
return;
}
if (ack_needed)
L2CA_DisconnectRsp (l2cap_cid);
SDP_TRACE_EVENT ("SDP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);
SDP_TRACE_EVENT ("SDP - Rcvd L2CAP disc, CID: 0x%x\n", l2cap_cid);
#if SDP_CLIENT_ENABLED == TRUE
/* Tell the user if he has a callback */
if (p_ccb->p_cb)
@ -516,13 +516,13 @@ static void sdp_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg)
}
else
{
SDP_TRACE_WARNING ("SDP - Ignored L2CAP data while in state: %d, CID: 0x%x",
SDP_TRACE_WARNING ("SDP - Ignored L2CAP data while in state: %d, CID: 0x%x\n",
p_ccb->con_state, l2cap_cid);
}
}
else
{
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid);
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP data, unknown CID: 0x%x\n", l2cap_cid);
}
GKI_freebuf (p_msg);
@ -548,11 +548,11 @@ tCONN_CB* sdp_conn_originate (UINT8 *p_bd_addr)
/* Allocate a new CCB. Return if none available. */
if ((p_ccb = sdpu_allocate_ccb()) == NULL)
{
SDP_TRACE_WARNING ("SDP - no spare CCB for orig");
SDP_TRACE_WARNING ("SDP - no spare CCB for orig\n");
return (NULL);
}
SDP_TRACE_EVENT ("SDP - Originate started");
SDP_TRACE_EVENT ("SDP - Originate started\n");
/* We are the originator of this connection */
p_ccb->con_flags |= SDP_FLAGS_IS_ORIG;
@ -574,7 +574,7 @@ tCONN_CB* sdp_conn_originate (UINT8 *p_bd_addr)
}
else
{
SDP_TRACE_WARNING ("SDP - Originate failed");
SDP_TRACE_WARNING ("SDP - Originate failed\n");
sdpu_release_ccb (p_ccb);
return (NULL);
}
@ -592,7 +592,6 @@ tCONN_CB* sdp_conn_originate (UINT8 *p_bd_addr)
void sdp_disconnect (tCONN_CB*p_ccb, UINT16 reason)
{
#if (defined(SDP_BROWSE_PLUS) && SDP_BROWSE_PLUS == TRUE)
/* If we are browsing for multiple UUIDs ... */
if ((p_ccb->con_state == SDP_STATE_CONNECTED)
&& (p_ccb->con_flags & SDP_FLAGS_IS_ORIG)
@ -618,7 +617,7 @@ void sdp_disconnect (tCONN_CB*p_ccb, UINT16 reason)
p_ccb->cur_handle = 0;
SDP_TRACE_EVENT ("SDP - looking for for more, CID: 0x%x",
SDP_TRACE_EVENT ("SDP - looking for for more, CID: 0x%x\n",
p_ccb->connection_id);
sdp_disc_connected (p_ccb);
@ -631,7 +630,7 @@ void sdp_disconnect (tCONN_CB*p_ccb, UINT16 reason)
#endif
SDP_TRACE_EVENT ("SDP - disconnect CID: 0x%x", p_ccb->connection_id);
SDP_TRACE_EVENT ("SDP - disconnect CID: 0x%x\n", p_ccb->connection_id);
/* Check if we have a connection ID */
if (p_ccb->connection_id != 0)
@ -672,12 +671,11 @@ static void sdp_disconnect_cfm (UINT16 l2cap_cid, UINT16 result)
/* Find CCB based on CID */
if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL)
{
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP disc cfm, unknown CID: 0x%x", l2cap_cid);
SDP_TRACE_WARNING ("SDP - Rcvd L2CAP disc cfm, unknown CID: 0x%x\n", l2cap_cid);
return;
}
SDP_TRACE_EVENT ("SDP - Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid);
SDP_TRACE_EVENT ("SDP - Rcvd L2CAP disc cfm, CID: 0x%x, rsn %d\n", l2cap_cid, p_ccb->disconnect_reason);
/* Tell the user if he has a callback */
if (p_ccb->p_cb)
(*p_ccb->p_cb) (p_ccb->disconnect_reason);
@ -702,7 +700,7 @@ static void sdp_disconnect_cfm (UINT16 l2cap_cid, UINT16 result)
*******************************************************************************/
void sdp_conn_timeout (tCONN_CB*p_ccb)
{
SDP_TRACE_EVENT ("SDP - CCB timeout in state: %d CID: 0x%x",
SDP_TRACE_EVENT ("SDP - CCB timeout in state: %d CID: 0x%x\n",
p_ccb->con_state, p_ccb->connection_id);
L2CA_DisconnectReq (p_ccb->connection_id);

View file

@ -152,7 +152,7 @@ void sdp_server_handle_client_req (tCONN_CB *p_ccb, BT_HDR *p_msg)
default:
sdpu_build_n_send_error (p_ccb, trans_num, SDP_INVALID_REQ_SYNTAX, SDP_TEXT_BAD_PDU);
SDP_TRACE_WARNING ("SDP - server got unknown PDU: 0x%x", pdu_id);
SDP_TRACE_WARNING ("SDP - server got unknown PDU: 0x%x\n", pdu_id);
break;
}
}
@ -258,7 +258,7 @@ static void process_service_search (tCONN_CB *p_ccb, UINT16 trans_num,
/* Get a buffer to use to build the response */
if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL)
{
SDP_TRACE_ERROR ("SDP - no buf for search rsp");
SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
return;
}
p_buf->offset = L2CAP_MIN_OFFSET;
@ -373,7 +373,7 @@ static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
p_ccb->rsp_list = (UINT8 *)GKI_getbuf(max_list_len);
if (p_ccb->rsp_list == NULL)
{
SDP_TRACE_ERROR("%s No scratch buf for attr rsp", __func__);
SDP_TRACE_ERROR("%s No scratch buf for attr rsp\n", __func__);
return;
}
@ -415,7 +415,7 @@ static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
if (p_ccb->rsp_list == NULL)
{
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp");
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
return;
}
}
@ -464,7 +464,7 @@ static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
{
if (attr_len >= SDP_MAX_ATTR_LEN)
{
SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d", max_list_len, attr_len);
SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d\n", max_list_len, attr_len);
sdpu_build_n_send_error (p_ccb, trans_num, SDP_NO_RESOURCES, NULL);
return;
}
@ -523,7 +523,7 @@ static void process_service_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
/* Get a buffer to use to build the response */
if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL)
{
SDP_TRACE_ERROR ("SDP - no buf for search rsp");
SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
return;
}
p_buf->offset = L2CAP_MIN_OFFSET;
@ -636,7 +636,7 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
if (p_ccb->rsp_list == NULL)
{
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp");
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
return;
}
@ -678,7 +678,7 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
p_ccb->rsp_list = (UINT8 *)GKI_getbuf (max_list_len);
if (p_ccb->rsp_list == NULL)
{
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp");
SDP_TRACE_ERROR ("SDP - no scratch buf for search rsp\n");
return;
}
}
@ -751,7 +751,7 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
{
if (attr_len >= SDP_MAX_ATTR_LEN)
{
SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d", max_list_len, attr_len);
SDP_TRACE_ERROR("SDP attr too big: max_list_len=%d,attr_len=%d\n", max_list_len, attr_len);
sdpu_build_n_send_error (p_ccb, trans_num, SDP_NO_RESOURCES, NULL);
return;
}
@ -859,7 +859,7 @@ static void process_service_search_attr_req (tCONN_CB *p_ccb, UINT16 trans_num,
/* Get a buffer to use to build the response */
if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL)
{
SDP_TRACE_ERROR ("SDP - no buf for search rsp");
SDP_TRACE_ERROR ("SDP - no buf for search rsp\n");
return;
}
p_buf->offset = L2CAP_MIN_OFFSET;

View file

@ -158,7 +158,7 @@ void sdpu_release_ccb (tCONN_CB *p_ccb)
/* Free the response buffer */
if (p_ccb->rsp_list)
{
SDP_TRACE_DEBUG("releasing SDP rsp_list");
SDP_TRACE_DEBUG("releasing SDP rsp_list\n");
GKI_freebuf(p_ccb->rsp_list);
p_ccb->rsp_list = NULL;
@ -323,13 +323,13 @@ void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_co
BT_HDR *p_buf;
SDP_TRACE_WARNING ("SDP - sdpu_build_n_send_error code: 0x%x CID: 0x%x",
SDP_TRACE_WARNING ("SDP - sdpu_build_n_send_error code: 0x%x CID: 0x%x\n",
error_code, p_ccb->connection_id);
/* Get a buffer to use to build and send the packet to L2CAP */
if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL)
{
SDP_TRACE_ERROR ("SDP - no buf for err msg");
SDP_TRACE_ERROR ("SDP - no buf for err msg\n");
return;
}
p_buf->offset = L2CAP_MIN_OFFSET;
@ -674,7 +674,7 @@ BOOLEAN sdpu_compare_uuid_arrays (UINT8 *p_uuid1, UINT32 len1, UINT8 *p_uuid2, U
if( ((len1 != 2) && (len1 != 4) && (len1 != 16)) ||
((len2 != 2) && (len2 != 4) && (len2 != 16)) )
{
SDP_TRACE_ERROR("%s: invalid length", __func__);
SDP_TRACE_ERROR("%s: invalid length\n", __func__);
return FALSE;
}
@ -1019,7 +1019,7 @@ UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UI
if ((p_attr_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN )) == NULL)
{
SDP_TRACE_ERROR("sdpu_build_partial_attrib_entry cannot get a buffer!");
SDP_TRACE_ERROR("sdpu_build_partial_attrib_entry cannot get a buffer!\n");
return NULL;
}
p_tmp_attr = p_attr_buff;

View file

@ -0,0 +1,35 @@
#include "bt_gap_api.h"
#include "bta_api.h"
#include "bt_trace.h"
esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode)
{
tBTA_DM_DISC disc_mode;
tBTA_DM_CONN conn_mode;
switch(mode) {
case BT_SCAN_MODE_NONE:
disc_mode = BTA_DM_NON_DISC;
conn_mode = BTA_DM_NON_CONN;
break;
case BT_SCAN_MODE_CONNECTABLE:
disc_mode = BTA_DM_NON_DISC;
conn_mode = BTA_DM_CONN;
break;
case BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
disc_mode = BTA_DM_GENERAL_DISC;
conn_mode = BTA_DM_CONN;
break;
default:
// BTIF_TRACE_ERROR("invalid scan mode (0x%x)", mode);
return ESP_ERR_INVALID_ARG;
}
// BTIF_TRACE_EVENT("set property scan mode : %x", mode);
BTA_DmSetVisibility(disc_mode, conn_mode, BTA_DM_IGNORE, BTA_DM_IGNORE);
return ESP_OK;
}

View file

@ -0,0 +1,111 @@
#include "bt_sdp_api.h"
esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback)
{
tBTA_SDP_STATUS status = BTA_SdpEnable((tBTA_SDP_DM_CBACK *)cback);
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
}
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t* uuid)
{
tBTA_SDP_STATUS status = BTA_SdpSearch(bd_addr, (tSDP_UUID *)uuid);
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
}
esp_err_t esp_bt_sdp_create_record_by_user(void *user_data)
{
tBTA_SDP_STATUS status = BTA_SdpCreateRecordByUser(user_data);
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
}
esp_err_t esp_bt_sdp_remove_record_by_user(void *user_data)
{
tBTA_SDP_STATUS status = BTA_SdpRemoveRecordByUser(user_data);
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
}
/**********************************************************************************************/
/**********************************************************************************************/
/* API into SDP for local service database updates */
/* these APIs are indended to be called in callback function in the context of stack task,
* to handle BT_SDP_CREATE_RECORD_USER_EVT and BT_SDP_REMOVE_RECORD_USER_EVT
*/
uint32_t esp_bt_sdp_create_record(void)
{
return SDP_CreateRecord();
}
bool esp_bt_sdp_delete_record(uint32_t handle)
{
return SDP_DeleteRecord(handle);
}
int32_t esp_bt_sdp_read_record(uint32_t handle, uint8_t *data, int32_t *data_len)
{
return SDP_ReadRecord(handle, data, data_len);
}
bool esp_bt_sdp_add_attribute (uint32_t handle, uint16_t attr_id,
uint8_t attr_type, uint32_t attr_len,
uint8_t *p_val)
{
return SDP_AddAttribute(handle, attr_id, attr_type, attr_len, p_val);
}
bool esp_bt_sdp_add_sequence (uint32_t handle, uint16_t attr_id,
uint16_t num_elem, uint8_t type[],
uint8_t len[], uint8_t *p_val[])
{
return SDP_AddSequence(handle, attr_id, num_elem, type, len, p_val);
}
bool esp_bt_sdp_add_uuid_sequence (uint32_t handle, uint16_t attr_id,
uint16_t num_uuids, uint16_t *p_uuids)
{
return SDP_AddUuidSequence(handle, attr_id, num_uuids, p_uuids);
}
bool esp_bt_sdp_add_protocol_list (uint32_t handle, uint16_t num_elem,
sdp_proto_elem_t *p_elem_list)
{
return SDP_AddProtocolList(handle, num_elem, (tSDP_PROTOCOL_ELEM *)p_elem_list);
}
bool esp_bt_sdp_add_addition_protocol_lists(uint32_t handle, uint16_t num_elem,
sdp_proto_list_elem_t *p_proto_list)
{
return SDP_AddAdditionProtoLists(handle, num_elem, (tSDP_PROTO_LIST_ELEM *)p_proto_list);
}
bool esp_bt_sdp_add_profile_dscp_list (uint32_t handle,
uint16_t profile_uuid,
uint16_t version)
{
return SDP_AddProfileDescriptorList(handle, profile_uuid, version);
}
bool esp_bt_sdp_add_lang_base_attr_id_list(uint32_t handle,
uint16_t lang, uint16_t char_enc,
uint16_t base_id)
{
return SDP_AddLanguageBaseAttrIDList(handle, lang, char_enc, base_id);
}
bool esp_bt_sdp_add_service_class_id_list(uint32_t handle,
uint16_t num_services,
uint16_t *p_service_uuids)
{
return SDP_AddServiceClassIdList(handle, num_services, p_service_uuids);
}
bool esp_bt_sdp_delete_attribute(uint32_t handle, uint16_t attr_id)
{
return SDP_DeleteAttribute(handle, attr_id);
}
/**********************************************************************************************/
/**********************************************************************************************/

View file

@ -0,0 +1,13 @@
#ifndef __BT_API_COMMON_H__
#define __BT_API_COMMON_H__
#include <stdint.h>
#include "bt_types.h"
typedef tBT_UUID esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */
typedef BD_ADDR esp_bd_addr_t; /* BD_ADDR in bt_types.h */
#endif /* __BT_API_COMMON_H__ */

View file

@ -0,0 +1,18 @@
#ifndef __BT_GAP_API_H__
#define __BT_GAP_API_H__
#include <stdint.h>
#include "esp_err.h"
#include "bt_api_common.h"
enum {
BT_SCAN_MODE_NONE,
BT_SCAN_MODE_CONNECTABLE,
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
};
typedef uint16_t bt_scan_mode_t;
esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode);
#endif /* __BT_GAP_API_H__ */

View file

@ -0,0 +1,118 @@
#ifndef __BT_SDP_API_H__
#define __BT_SDP_API_H__
#include <stdint.h>
#include "esp_err.h"
#include "bt_api_common.h"
#include "bta_sdp_api.h"
#include "bt_sdp.h"
#define BT_SDP_STAT_SUCCESS BTA_SDP_SUCCESS
#define BT_SDP_STAT_FAILURE BTA_SDP_FAILURE
#define BT_SDP_STAT_BUSY BTA_SDP_BUSY
#define BT_SDP_ENABLE_EVT BTA_SDP_ENABLE_EVT
#define BT_SDP_SEARCH_EVT BTA_SDP_SEARCH_EVT
#define BT_SDP_SEARCH_COMP_EVT BTA_SDP_SEARCH_COMP_EVT
#define BT_SDP_CREATE_RECORD_USER_EVT BTA_SDP_CREATE_RECORD_USER_EVT
#define BT_SDP_REMOVE_RECORD_USER_EVT BTA_SDP_REMOVE_RECORD_USER_EVT
#define BT_SDP_MAX_EVT BTA_SDP_MAX_EVT
#define BT_SDP_MAX_RECORDS BTA_SDP_MAX_RECORDS
typedef tBTA_SDP_STATUS bt_sdp_status_t;
typedef tBTA_SDP_EVT bt_sdp_evt_t;
typedef bluetooth_sdp_record bt_sdp_record_t;
/* tBTA_SEARCH_COMP, bta_sdp_api.h */
typedef struct {
bt_sdp_status_t status;
esp_bd_addr_t remote_addr;
esp_bt_uuid_t uuid;
int record_count;
bt_sdp_record_t records[BT_SDP_MAX_RECORDS];
} bt_sdp_search_comp_t;
/* tBTA_SDP, bta_sdp_api.h */
typedef union
{
bt_sdp_status_t status;
bt_sdp_search_comp_t sdp_search_comp;
} bt_sdp_t;
typedef void (bt_sdp_cb_t)(bt_sdp_evt_t event, bt_sdp_t *p_data, void * user_data);
esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback);
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t* uuid);
esp_err_t esp_bt_sdp_create_record_by_user(void *user_data);
esp_err_t esp_bt_sdp_remove_record_by_user(void *user_data);
/**********************************************************************************************/
/**********************************************************************************************/
/* API into SDP for local service database updates
* these APIs are indended to be called in callback function in the context of stack task,
* to handle BT_SDP_CREATE_RECORD_USER_EVT and BT_SDP_REMOVE_RECORD_USER_EVT
*/
/* This structure is used to add protocol lists and find protocol elements */
#define ESP_BT_SDP_MAX_PROTOCOL_PARAMS SDP_MAX_PROTOCOL_PARAMS // bt_target.h
typedef struct {
uint16_t protocol_uuid;
uint16_t num_params;
uint16_t params[ESP_BT_SDP_MAX_PROTOCOL_PARAMS];
} sdp_proto_elem_t; // tSDP_PROTOCOL_ELEM, sdp_api.h
#define ESP_BT_SDP_MAX_LIST_ELEMS SDP_MAX_LIST_ELEMS // sdp_api.h
typedef struct
{
uint16_t num_elems;
sdp_proto_elem_t list_elem[ESP_BT_SDP_MAX_LIST_ELEMS];
} sdp_proto_list_elem_t; // tSDP_PROTO_LIST_ELEM, sdp_api.h
uint32_t esp_bt_sdp_create_record(void);
bool esp_bt_sdp_delete_record(uint32_t handle);
int32_t esp_bt_sdp_read_record(uint32_t handle, uint8_t *data, int32_t *data_len);
bool esp_bt_sdp_add_attribute (uint32_t handle, uint16_t attr_id,
uint8_t attr_type, uint32_t attr_len,
uint8_t *p_val);
bool esp_bt_sdp_add_sequence (uint32_t handle, uint16_t attr_id,
uint16_t num_elem, uint8_t type[],
uint8_t len[], uint8_t *p_val[]);
bool esp_bt_sdp_add_uuid_sequence (uint32_t handle, uint16_t attr_id,
uint16_t num_uuids, uint16_t *p_uuids);
bool esp_bt_sdp_add_protocol_list (uint32_t handle, uint16_t num_elem,
sdp_proto_elem_t *p_elem_list);
bool esp_bt_sdp_add_addition_protocol_lists(uint32_t handle, uint16_t num_elem,
sdp_proto_list_elem_t *p_proto_list);
bool esp_bt_sdp_add_profile_dscp_list (uint32_t handle,
uint16_t profile_uuid,
uint16_t version);
bool esp_bt_sdp_add_lang_base_attr_id_list(uint32_t handle,
uint16_t lang, uint16_t char_enc,
uint16_t base_id);
bool esp_bt_sdp_add_service_class_id_list(uint32_t handle,
uint16_t num_services,
uint16_t *p_service_uuids);
bool esp_bt_sdp_delete_attribute(uint32_t handle, uint16_t attr_id);
/**********************************************************************************************/
/**********************************************************************************************/
#endif /* __BT_SDP_API_H__ */

View file

@ -27,6 +27,7 @@ COMPONENT_ADD_INCLUDEDIRS := bluedroid/bta/include \
bluedroid/stack/sdp/include \
bluedroid/stack/smp/include \
bluedroid/stack/include \
bluedroid/stack_api/include \
bluedroid/include \
include
@ -41,6 +42,7 @@ COMPONENT_ADD_LDFLAGS := -lbt -L$(abspath lib) \
COMPONENT_SRCDIRS := bluedroid/bta/dm \
bluedroid/bta/gatt \
bluedroid/bta/hh \
bluedroid/bta/sdp \
bluedroid/bta/sys \
bluedroid/bta \
bluedroid/btcore \
@ -61,6 +63,8 @@ COMPONENT_SRCDIRS := bluedroid/bta/dm \
bluedroid/profiles/std/hid \
bluedroid/profiles/std/hid_le \
bluedroid/profiles/std/rfcomm \
bluedroid/profiles/std/sdp \
bluedroid/profiles/std/gap \
bluedroid/profiles/std \
bluedroid/profiles \
bluedroid/stack/btm \
@ -73,6 +77,7 @@ COMPONENT_SRCDIRS := bluedroid/bta/dm \
bluedroid/stack/sdp \
bluedroid/stack/smp \
bluedroid/stack \
bluedroid/stack_api \
bluedroid \
.

View file

@ -28,10 +28,6 @@ static unsigned char BASE_UUID[16] = {
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
typedef struct {
uint8_t uu[16];
} bt_uuid_t;
int uuidType(unsigned char* p_uuid)
{
int i = 0;

View file

@ -166,10 +166,6 @@ tESP_BLE_ADV_DATA wechat_adv_data[ADV_SCAN_IDX_MAX] =
static void SimpleDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data);
#endif
typedef struct {
uint8_t uu[16];
} bt_uuid_t;
int uuidType(unsigned char* p_uuid)
{
int i = 0;

View file

@ -4,23 +4,7 @@
#include <stdint.h>
#include "osi.h"
#include "bt_common_types.h"
/** Bluetooth Error Status */
/** originally defined in bluetooth.h */
typedef enum {
BT_STATUS_SUCCESS,
BT_STATUS_FAIL,
BT_STATUS_NOT_READY,
BT_STATUS_NOMEM,
BT_STATUS_BUSY,
BT_STATUS_DONE,
BT_STATUS_UNSUPPORTED,
BT_STATUS_PARAM_INVALID,
BT_STATUS_UNHANDLED,
BT_STATUS_AUTH_FAILURE,
BT_STATUS_RMT_DEV_DOWN
} bt_status_t;
#include "bt_defs.h"
/* BT APP Events */
#define BT_EVT_APP (0xB000)

View file

@ -0,0 +1,377 @@
/****************************************************************************
*
* This file is for gatt client. It can scan ble device, connect one device,
*
****************************************************************************/
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include "bta_api.h"
#include "bta_gatt_api.h"
#include "controller.h"
#include "bt_trace.h"
#include "btm_api.h"
#include "bt_types.h"
#include "gattc_profile.h"
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
tBTA_GATTC_IF client_if;
BD_ADDR obj_addr;
static unsigned char BASE_UUID[16] = {
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int uuidType(unsigned char* p_uuid)
{
int i = 0;
int match = 0;
int all_zero = 1;
for(i = 0; i != 16; ++i)
{
if (i == 12 || i == 13)
continue;
if (p_uuid[i] == BASE_UUID[i])
++match;
if (p_uuid[i] != 0)
all_zero = 0;
}
if (all_zero)
return 0;
if (match == 12)
return LEN_UUID_32;
if (match == 14)
return LEN_UUID_16;
return LEN_UUID_128;
}
static void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src)
{
char *p_byte = (char*)p_src;
int i = 0;
p_dest->len = uuidType(p_src->uu);
switch (p_dest->len)
{
case LEN_UUID_16:
p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12];
break;
case LEN_UUID_32:
p_dest->uu.uuid32 = (p_src->uu[13] << 8) + p_src->uu[12];
p_dest->uu.uuid32 += (p_src->uu[15] << 24) + (p_src->uu[14] << 16);
break;
case LEN_UUID_128:
for(i = 0; i != 16; ++i)
p_dest->uu.uuid128[i] = p_byte[i];
break;
default:
LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len);
break;
}
}
/*
uint16_t get_uuid16(tBT_UUID* p_uuid)
{
if(p_uuid->len == LEN_UUID_16)
{
return p_uuid->uu.uuid16;
}
else if(p_uuid->len == LEN_UUID_128)
{
UINT16 u16;
UINT8 *p = &p_uuid->uu.uuid128[LEN_UUID_128 - 4];
STREAM_TO_UINT16(u16, p);
return u16;
}
else
{
return (UINT16)p_uuid->uu.uuid32;
}
}
//fill a GATT ID structure
void bta_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID* p_output)
{
p_output->inst_id = inst_id;
p_output->uuid.len = LEN_UUID_16;
p_output->uuid.uu.uuid16 = uuid;
}
//fill a service ID structure with a 16 bits service UUID
void bta_le_fill_16bits_srvc_id(bool is_pri, UINT8 inst_id, UINT16 srvc_uuid, tBTA_GATT_SRVC_ID* p_output)
{
memset((void *)p_output, 0, sizeof(tBTA_GATT_SRVC_ID));
p_output->is_primary = is_pri;
bta_le_fill_16bits_gatt_id(inst_id, srvc_uuid, &p_output->id);
}
//fill a char ID structure with a 16 bits char UUID
void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, tBTA_GATT_ID* p_output)
{
memset((void *)p_output, 0, sizeof(tBTA_GATT_ID));
bta_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output);
}
*/
/*get remote name*/
static bool check_remote_name(tBTA_DM_INQ_RES* result, uint8_t* rmt_name, uint8_t* rmt_name_len)
{
uint8_t *p_rmt_name = NULL;
uint8_t remote_name_len = 0;
if (result->p_eir) {
p_rmt_name = BTM_CheckEirData(result->p_eir,
BTM_EIR_COMPLETE_LOCAL_NAME_TYPE,
&remote_name_len);
if (!p_rmt_name)
p_rmt_name = BTM_CheckEirData(result->p_eir,
BTM_EIR_SHORTENED_LOCAL_NAME_TYPE,
&remote_name_len);
if (p_rmt_name) {
if (remote_name_len > BD_NAME_LEN)
remote_name_len = BD_NAME_LEN;
if (rmt_name && rmt_name_len) {
memcpy(rmt_name, p_rmt_name, remote_name_len);
*(rmt_name + remote_name_len) = 0;
*rmt_name_len = remote_name_len;
}
return true;
}
}
return false;
}
/************************************************************************************
* * Function bta_scan_recult_callback
* *
* * Description scan result.it will be called when device scaned a peer device
* *
* * Return NULL
**************************************************************************************/
static void bta_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data)
{
uint8_t len;
BD_ADDR bd_addr;
char dev_name[32];
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
//char obj_name[] = "Find Me";
char obj_name[] = "SimpleBLEPeripheral";
uint8_t dev_name_len;
switch (event)
{
case BTA_DM_INQ_RES_EVT:
{
LOG_ERROR("scan result: event=%d, "BT_BD_ADDR_STR", device_type=%d\n",
event, BT_BD_ADDR_HEX(p_data->inq_res.bd_addr), p_data->inq_res.device_type);
bdcpy(bd_addr, p_data->inq_res.bd_addr);
if (p_data->inq_res.p_eir)
{
if (BTM_CheckEirData(p_data->inq_res.p_eir, BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &len))
{
p_data->inq_res.remt_name_not_required = TRUE;
}
}
if(check_remote_name(&(p_data->inq_res), dev_name, &dev_name_len))
{
LOG_ERROR("scan device name len=%d, name = %s\n", dev_name_len, dev_name);
}
if(strcmp(dev_name, obj_name) == 0)
{
bdcpy(obj_addr, bd_addr);
LOG_ERROR("find the device, obj_addr="BT_BD_ADDR_STR"\n", BT_BD_ADDR_HEX(obj_addr));
// BTA_GATTC_Open(client_if, obj_addr, true, transport);
}
}
break;
case BTA_DM_INQ_CMPL_EVT:
{
LOG_ERROR("%s-BLE observe complete. Num Resp %d\n", __FUNCTION__, p_data->inq_cmpl.num_resps);
LOG_ERROR("connect the device "BT_BD_ADDR_STR", client_if=%d\n",
BT_BD_ADDR_HEX(obj_addr), client_if);
/* scan complete, start connect*/
BTA_GATTC_Open(client_if, obj_addr, true, transport);
}
break;
default:
LOG_ERROR("%s : unknown event 0x%x", __FUNCTION__, event);
}
}
/************************************************************************************
* * Function bta_scan_param_setup_cback
* *
* * Description set scan param callback.it will be called after setting scan parameter
* *
* * Return NULL
**************************************************************************************/
static void bta_scan_param_setup_cback(tGATT_IF c_client_if, tBTM_STATUS status)
{
client_if = c_client_if;
LOG_ERROR("\nset scan params complete: status=%d, client_if=%d\n", status, client_if);
/*start scan*/
BTA_DmBleObserve(true, 8, bta_scan_result_callback);
}
/************************************************************************************
* * Function bta_gattc_callback
* *
* * Description app register callback
* *
* * Return NULL
**************************************************************************************/
static void bta_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
{
switch (event)
{
case BTA_GATTC_REG_EVT:
{
tBTA_GATT_STATUS status = p_data->reg_oper.status;
client_if = p_data->reg_oper.client_if;
LOG_ERROR("%s:register complete: event=%d, status=%d, client_if=%d\n", __FUNCTION__, event, status, client_if);
UINT8 scan_interval = 0x50;
UINT8 scan_window = 0x30;
tBLE_SCAN_MODE scan_mode = BTM_BLE_SCAN_MODE_ACTI;
bac_register();
/*register complete,set scan parameter*/
BTA_DmSetBleScanParams(client_if, scan_interval, scan_window, scan_mode,
bta_scan_param_setup_cback);
}
break;
/*connect callback*/
case BTA_GATTC_OPEN_EVT:
{
LOG_ERROR("\n%s:device is connected "BT_BD_ADDR_STR", client_if=%d, status=%d, connect_id=%d\n",
__FUNCTION__, BT_BD_ADDR_HEX(p_data->open.remote_bda), p_data->open.client_if,
p_data->open.status, p_data->open.conn_id);
/*return whether the remote device is currently connected*/
int is_connected = BTA_DmGetConnectionState(p_data->open.remote_bda);
LOG_ERROR("is_connected=%d\n",is_connected);
/*get the energy info of the controller*/
/*read battery level*/
int conn_id = p_data->open.conn_id;
/*discover service*/
// BTA_GATTC_ServiceSearchRequest(conn_id, NULL);
}
break;
/*
case BTA_GATTC_SEARCH_RES_EVT:
{
// tBTA_GATTC_SRVC_RES service_result;
LOG_ERROR("find the service,uuid=0x%x, is_primary=%d\n",
get_uuid16(&p_data->srvc_res.service_uuid.id.uuid),
p_data->srvc_res.service_uuid.is_primary);
}
break;
case BTA_GATTC_SEARCH_CMPL_EVT:
{
LOG_ERROR("search service complete, conn_id=%d,status=%d\n", p_data->search_cmpl.conn_id,
p_data->search_cmpl.status);
//get first characteristic of battey service
LOG_ERROR("get first characteristic of battery service\n");
tBTA_GATT_STATUS status;
tBTA_GATT_SRVC_ID battery_srvc_id;
tBTA_GATTC_CHAR_ID out_char_id;
tGATT_CHAR_PROP out_char_prop;
bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_srvc_id);
status = BTA_GATTC_GetFirstChar(p_data->search_cmpl.conn_id, &battery_srvc_id, NULL,
&out_char_id, &out_char_prop);
if(status == 0)
{
LOG_ERROR("the first char:srvc_id=0x%x,char_id=0x%x, property = %d\n",
get_uuid16(&out_char_id.srvc_id.id.uuid), get_uuid16(&out_char_id.char_id.uuid),
out_char_prop);
//read battery level
tBTA_GATTC_CHAR_ID battery_char_id;
bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_char_id.srvc_id);
bta_le_fill_16bits_char_id(0, GATT_UUID_BATTERY_LEVEL, &battery_char_id.char_id);
BTA_GATTC_ReadCharacteristic(p_data->search_cmpl.conn_id, &battery_char_id,
BTA_GATT_AUTH_REQ_NONE);
}
}
break;
case BTA_GATTC_READ_CHAR_EVT:
{
LOG_ERROR("\nread characteristic:connect_id=%d, status=%d\n",
p_data->read.conn_id, p_data->read.status);
LOG_ERROR("srvc_id=0x%x,char_id=0x%x,descr_type=0x%x\n",
get_uuid16(&p_data->read.srvc_id.id.uuid),
get_uuid16(&p_data->read.char_id.uuid),
get_uuid16(&p_data->read.descr_type.uuid));
if(get_uuid16(&p_data->read.descr_type.uuid) != GATT_UUID_CHAR_AGG_FORMAT
&& p_data->read.p_value->unformat.len > 0
&& p_data->read.p_value->unformat.p_value != NULL)
{
LOG_ERROR("read the value: len=%d, value=%d\n", p_data->read.p_value->unformat.len,
*(p_data->read.p_value->unformat.p_value));
}
}
break;
*/
default:
LOG_ERROR("%s:unknown event: %d\n", __FUNCTION__, event);
}
}
/************************************************************************************
* * Function ble_client_appRegister
* *
* * Description app register function
* *
* * Return NULL
**************************************************************************************/
void ble_client_appRegister(void)
{
bt_uuid_t uuid;
tBT_UUID t_uuid;
memcpy(&uuid, BASE_UUID, sizeof(bt_uuid_t));
btif_to_bta_uuid(&t_uuid, &uuid);
LOG_ERROR("register application\n");
BTA_GATTC_AppRegister(&t_uuid, bta_gattc_callback);
/*battery service register*/
// bac_register();
}
void gattc_client_test(void)
{
BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
ble_client_appRegister();
}

View file

@ -0,0 +1,295 @@
/***************************************************************
*
* This file is for gatt server device. It instantiates BATTERY
* sevice. It can be scanned and connected by central device,
* and the client will get the BAS value. It calls the API bta
* layer provides.
*
****************************************************************/
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include "prf_defs.h"
#include "bta_api.h"
#include "bta_gatt_api.h"
#include "controller.h"
#include "gatt_int.h"
#include "bt_trace.h"
#include "btm_api.h"
#include "bt_types.h"
#include "dis_api.h"
#include "bt_app_common.h"
//#include "app_button.h"
#include "button_pro.h"
#include "hid_le_prf.h"
#include "hcimsgs.h"
#include "bt_app_defs.h"
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
tBTA_GATTS_IF server_if;
static unsigned char DIS_UUID[16] = {
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x0a, 0x18, 0x00, 0x00
};
static unsigned char BASE_UUID[16] = {
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
UINT16 ijiazu_uuid = 0xffff;
tBTA_BLE_SERVICE ijiazu_service = {
0x01, //only one service in the ijiazu button profile
false,
&ijiazu_uuid
}; /* 16 bits services */
UINT8 beacon_manu[25] = {0x4c, 0x00,0x02, 0x15, 0xfd, 0xa5, 0x06, 0x93, 0xa4, 0xe2,
0x4f, 0xb1, 0xaf, 0xcf, 0xc6, 0xeb, 0x07, 0x64, 0x78, 0x25,
0x27, 0x32, 0xe6, 0x08, 0xc5};
//UINT8 ijiazu_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31};
UINT8 ijiazu_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31};
tBTA_BLE_MANU p_ijiazu_manu = {sizeof(ijiazu_manu),ijiazu_manu}; /* manufacturer data */
BD_ADDR rand_ijiazu_addr = {0x00,0x02,0x5B,0x00,0x32,0x55};
tESP_BLE_ADV_DATA ijiazu_adv_data[ADV_SCAN_IDX_MAX] =
{
[BLE_ADV_DATA_IDX] = {
.adv_name = "Espressif_008",
{
{0,0},
NULL, //no manufature data to be setting in the ijiazu adervetisiing datas
&ijiazu_service,
NULL, //the 128 bits service uuid set to null(not used)
NULL, //the 32 bits Service UUID set to null(not used)
NULL, //16 bits services Solicitation UUIDs set to null(not used)
NULL, //List of 32 bit Service Solicitation UUIDs set to null(not used)
NULL, //List of 128 bit Service Solicitation UUIDs set to null(not used)
NULL, //proprietary data set to null(not used)
NULL, //service data set not null(no service data to be sent)
0x0200, //device type : generic display
BTA_DM_GENERAL_DISC, // General discoverable.
0xFE //the tx power value,defult value is 0
},
},
[BLE_SCAN_RSP_DATA_IDX] = {
.adv_name = NULL,
{
{0,0},
&p_ijiazu_manu,
NULL,
NULL, //the 128 bits service uuid set to null(not used)
NULL, //the 32 bits Service UUID set to null(not used)
NULL, //16 bits services Solicitation UUIDs set to null(not used)
NULL, //List of 32 bit Service Solicitation UUIDs set to null(not used)
NULL, //List of 128 bit Service Solicitation UUIDs set to null(not used)
NULL, //proprietary data set to null(not used)
NULL, //service data set not null(no service data to be sent)
0x0000, //device type : generic display
0x00, // General discoverable.
0x00}, //the tx power value,defult value is 0
}
};
#if (BUT_PROFILE_CFG)
static void SimpleDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data);
#endif
int uuidType(unsigned char* p_uuid)
{
int i = 0;
int match = 0;
int all_zero = 1;
for(i = 0; i != 16; ++i)
{
if (i == 12 || i == 13)
continue;
if (p_uuid[i] == BASE_UUID[i])
++match;
if (p_uuid[i] != 0)
all_zero = 0;
}
if (all_zero)
return 0;
if (match == 12)
return LEN_UUID_32;
if (match == 14)
return LEN_UUID_16;
return LEN_UUID_128;
}
/*16-bits uuid to the structure of holding any type of UUID*/
void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src)
{
char *p_byte = (char*)p_src;
int i = 0;
p_dest->len = uuidType(p_src->uu);
switch (p_dest->len)
{
case LEN_UUID_16:
p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12];
break;
case LEN_UUID_32:
p_dest->uu.uuid32 = (p_src->uu[13] << 8) + p_src->uu[12];
p_dest->uu.uuid32 += (p_src->uu[15] << 24) + (p_src->uu[14] << 16);
break;
case LEN_UUID_128:
for(i = 0; i != 16; ++i)
p_dest->uu.uuid128[i] = p_byte[i];
break;
default:
LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len);
break;
}
}
/*set advertising config callback*/
static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status)
{
LOG_ERROR("set advertising config:status=%d\n", call_status);
/*dis init*/
/* tDIS_ATTR_MASK dis_attr_mask;
dis_attr_mask = DIS_ATTR_SYS_ID_BIT | DIS_ATTR_MODEL_NUM_BIT | DIS_ATTR_SERIAL_NUM_BIT |
DIS_ATTR_FW_NUM_BIT | DIS_ATTR_HW_NUM_BIT | DIS_ATTR_SW_NUM_BIT | DIS_ATTR_MANU_NAME_BIT |
DIS_ATTR_IEEE_DATA_BIT | DIS_ATTR_PNP_ID_BIT;
DIS_SrInit(dis_attr_mask);
*/
/*instantiate a battery service*/
//bas_register();
/*instantiate the driver for button profile*/
//app_button_init();
#if (BUT_PROFILE_CFG)
/*instantiate a button service*/
button_init(SimpleDataCallBack);
#endif ///BUT_PROFILE_CFG
/*instantiate a hid device service*/
//hidd_le_init();
/*start advetising*/
//BTA_GATTS_Listen(server_if, true, NULL);
}
/*register callback*/
void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data)
{
switch (event)
{
case BTA_GATTS_REG_EVT:
{
tBTA_GATT_STATUS status = p_data->reg_oper.status;
server_if = p_data->reg_oper.server_if;
LOG_ERROR("register complete: event=%d, status=%d, server_if=%d\n",
event, status, server_if);
LOG_ERROR("set advertising parameters\n");
//set the advertising data to the btm layer
ESP_AppBleConfigadvData(&ijiazu_adv_data[BLE_ADV_DATA_IDX],
bta_gatts_set_adv_data_cback);
//set the adversting data to the btm layer
ESP_AppBleSetScanRsp(&ijiazu_adv_data[BLE_SCAN_RSP_DATA_IDX],NULL);
BTA_GATTS_Listen(server_if, true, NULL);
}
break;
/*connect callback*/
case BTA_GATTS_CONNECT_EVT:
{
LOG_ERROR("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n",
BT_BD_ADDR_HEX(p_data->conn.remote_bda), p_data->conn.server_if,
p_data->conn.reason, p_data->conn.conn_id);
/*return whether the remote device is currently connected*/
int is_connected = BTA_DmGetConnectionState(p_data->conn.remote_bda);
LOG_ERROR("is_connected=%d\n",is_connected);
}
break;
default:
LOG_ERROR("unsettled event: %d\n", event);
}
}
#if (BUT_PROFILE_CFG)
#define HEADER_SSID "ssid"
#define HEADER_PASSWD "passwd"
#define HEADER_CONFIRM "confirm"
extern void wifi_set_blue_config(char *ssid, char *passwd);
static char tmp_ssid[33];
static char tmp_passwd[33];
static void SimpleDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data)
{
char *p = NULL;
LOG_ERROR("the data is:%s\n", p_data);
#if 0
switch(event)
{
case RECEIVE_NET_PASSWD_EVT:
LOG_ERROR("Received the network passwork");
break;
case RECEIVE_NET_SSD_EVT:
LOG_ERROR("Received the network SSID");
break;
default:
break;
}
#endif
p = strstr(p_data, HEADER_SSID);
if (p) {
ets_printf("SSID: %s\n", p+strlen(HEADER_SSID)+1);
strcpy(tmp_ssid, p+strlen(HEADER_SSID)+1);
}
p = strstr(p_data, HEADER_PASSWD);
if (p) {
ets_printf("PASSWORD: %s\n", p+strlen(HEADER_PASSWD)+1);
strcpy(tmp_passwd, p+strlen(HEADER_PASSWD)+1);
}
p = strstr(p_data, HEADER_CONFIRM);
if (p) {
ets_printf("CONFIRM\n");
wifi_set_blue_config(tmp_ssid, tmp_passwd);
}
}
#endif ///BUT_PROFILE_CFG
static void ble_server_appRegister(void)
{
bt_uuid_t uuid;
tBT_UUID t_uuid;
memcpy(&uuid, BASE_UUID, sizeof(bt_uuid_t));
//memcpy(&uuid, DIS_UUID, sizeof(bt_uuid_t));
btif_to_bta_uuid(&t_uuid, &uuid);
LOG_ERROR("register gatts application\n");
BTA_GATTS_AppRegister(&t_uuid, bta_gatts_callback);
}
void gatts_server_test(void)
{
BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
ble_server_appRegister();
}

View file

@ -0,0 +1,31 @@
#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_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
void bt_app_task_start_up(void);
#endif /* __BT_APP_COMMON_H__ */

View file

@ -79,7 +79,7 @@ static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_dat
}
static BtStatus_t blufi_dm_upstreams_evt(void *arg)
static bt_status_t blufi_dm_upstreams_evt(void *arg)
{
struct dm_evt *evt = (struct dm_evt *)arg;
@ -130,7 +130,7 @@ void blufi_bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data)
blufi_transfer_context(blufi_dm_upstreams_evt, evt);
}
BtStatus_t blufi_enable(void *arg)
bt_status_t blufi_enable(void *arg)
{
BTM_SetTraceLevel(BT_TRACE_LEVEL_ERROR);

View file

@ -67,7 +67,7 @@ static int blufi_task_post(uint32_t sig, void *par, void *cb, void *arg)
return 0;
}
BtStatus_t blufi_transfer_context(BtTaskCb_t cb, void *arg)
bt_status_t blufi_transfer_context(BtTaskCb_t cb, void *arg)
{
LOG_DEBUG("%s cb %08x, arg %u\n", __func__, cb, arg);

View file

@ -12,7 +12,7 @@ enum BLUFI_SIG {
};
void blufi_init(void);
BtStatus_t blufi_enable(void *arg);
BtStatus_t blufi_transfer_context(BtTaskCb_t cb, void *arg);
bt_status_t blufi_enable(void *arg);
bt_status_t blufi_transfer_context(BtTaskCb_t cb, void *arg);
#endif /* __BT_APP_COMMON_H__ */

11
examples/08_bt_sdp/Makefile Executable file
View file

@ -0,0 +1,11 @@
#
# 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

5
examples/08_bt_sdp/README.rst Executable file
View file

@ -0,0 +1,5 @@
ESP-IDF 08 SDP Server and Client
=======================
Demo of bluetooth SDP server and client

View file

@ -0,0 +1,174 @@
#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);
}
*/

View file

@ -0,0 +1,140 @@
#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();
}
}

View file

@ -0,0 +1,483 @@
/******************************************************************************
*
* 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;
}

View file

@ -0,0 +1,233 @@
/******************************************************************************
*
* 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);
}

View file

@ -0,0 +1,175 @@
/******************************************************************************
*
* 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;
}

View file

@ -0,0 +1,777 @@
/******************************************************************************
*
* 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;
}

View file

@ -0,0 +1,159 @@
/******************************************************************************
*
* 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;
}

View file

@ -0,0 +1,160 @@
#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;
}

View file

@ -0,0 +1,18 @@
#
# 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

View file

@ -0,0 +1,30 @@
#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__ */

View file

@ -0,0 +1,88 @@
/******************************************************************************
*
* 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 */

View file

@ -0,0 +1,122 @@
/******************************************************************************
*
* 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 */

View file

@ -0,0 +1,32 @@
/******************************************************************************
*
* 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

View file

@ -0,0 +1,38 @@
#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__ */

View file

@ -0,0 +1,31 @@
#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__ */

View file

@ -0,0 +1,52 @@
/******************************************************************************
*
* 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 */

View file

@ -0,0 +1,29 @@
/******************************************************************************
*
* 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__*/

View file

@ -0,0 +1,10 @@
#
# 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

View file

@ -0,0 +1,28 @@
#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);
}