diff --git a/components/bt/bluedroid/bta/include/bta_sdp_api.h b/components/bt/bluedroid/bta/include/bta_sdp_api.h new file mode 100755 index 0000000000..11a7edc9f8 --- /dev/null +++ b/components/bt/bluedroid/bta/include/bta_sdp_api.h @@ -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 */ diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp.c b/components/bt/bluedroid/bta/sdp/bta_sdp.c new file mode 100755 index 0000000000..88a68a5f9a --- /dev/null +++ b/components/bt/bluedroid/bta/sdp/bta_sdp.c @@ -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 + +#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); +} diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp_act.c b/components/bt/bluedroid/bta/sdp/bta_sdp_act.c new file mode 100755 index 0000000000..ee337343c7 --- /dev/null +++ b/components/bt/bluedroid/bta/sdp/bta_sdp_act.c @@ -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 +#include "bt_sdp.h" +// #include +#include "bt_defs.h" +#include +#include + +#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; xlen;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); +} diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp_api.c b/components/bt/bluedroid/bta/sdp/bta_sdp_api.c new file mode 100755 index 0000000000..e6a640f70d --- /dev/null +++ b/components/bt/bluedroid/bta/sdp/bta_sdp_api.c @@ -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 +// #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); +} + + diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c b/components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c new file mode 100755 index 0000000000..eef2511a53 --- /dev/null +++ b/components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c @@ -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; diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp_int.h b/components/bt/bluedroid/bta/sdp/bta_sdp_int.h new file mode 100755 index 0000000000..4f3f6a53d4 --- /dev/null +++ b/components/bt/bluedroid/bta/sdp/bta_sdp_int.h @@ -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 */ diff --git a/components/bt/bluedroid/include/bt_defs.h b/components/bt/bluedroid/include/bt_defs.h index 96071af100..4cfbfab8fd 100755 --- a/components/bt/bluedroid/include/bt_defs.h +++ b/components/bt/bluedroid/include/bt_defs.h @@ -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_ */ diff --git a/components/bt/bluedroid/osi/include/thread.h b/components/bt/bluedroid/osi/include/thread.h index 091784b6ca..80d8551c7b 100644 --- a/components/bt/bluedroid/osi/include/thread.h +++ b/components/bt/bluedroid/osi/include/thread.h @@ -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); diff --git a/components/bt/bluedroid/profiles/std/include/bt_sdp.h b/components/bt/bluedroid/profiles/std/include/bt_sdp.h new file mode 100755 index 0000000000..da7f7744d3 --- /dev/null +++ b/components/bt/bluedroid/profiles/std/include/bt_sdp.h @@ -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 +// #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__ */ diff --git a/components/bt/bluedroid/stack/btm/btm_acl.c b/components/bt/bluedroid/stack/btm/btm_acl.c index 575e560a26..05055a09e8 100755 --- a/components/bt/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/bluedroid/stack/btm/btm_acl.c @@ -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; diff --git a/components/bt/bluedroid/stack/btm/btm_dev.c b/components/bt/bluedroid/stack/btm/btm_dev.c index f7e27ee9d5..8ca65741ae 100755 --- a/components/bt/bluedroid/stack/btm/btm_dev.c +++ b/components/bt/bluedroid/stack/btm/btm_dev.c @@ -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) { diff --git a/components/bt/bluedroid/stack/btm/btm_sec.c b/components/bt/bluedroid/stack/btm/btm_sec.c index 4ba8f2847b..1b32a8cb36 100755 --- a/components/bt/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/bluedroid/stack/btm/btm_sec.c @@ -233,14 +233,14 @@ BOOLEAN BTM_SecRegister(tBTM_APPL_INFO *p_cb_info) BT_OCTET16 temp_value = {0}; #endif - BTM_TRACE_EVENT("%s application registered", __func__); + BTM_TRACE_EVENT("%s application registered\n", __func__); #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE - LOG_INFO("%s p_cb_info->p_le_callback == 0x%p", __func__, p_cb_info->p_le_callback); + LOG_INFO("%s p_cb_info->p_le_callback == 0x%p\n", __func__, p_cb_info->p_le_callback); if (p_cb_info->p_le_callback) { #if SMP_INCLUDED == TRUE - BTM_TRACE_EVENT("%s SMP_Register( btm_proc_smp_cback )", __func__); + BTM_TRACE_EVENT("%s SMP_Register( btm_proc_smp_cback )\n", __func__); SMP_Register(btm_proc_smp_cback); #endif /* if no IR is loaded, need to regenerate all the keys */ @@ -251,15 +251,15 @@ BOOLEAN BTM_SecRegister(tBTM_APPL_INFO *p_cb_info) } else { - LOG_WARN("%s p_cb_info->p_le_callback == NULL", __func__); + LOG_WARN("%s p_cb_info->p_le_callback == NULL\n", __func__); } #endif btm_cb.api = *p_cb_info; #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE - LOG_INFO("%s btm_cb.api.p_le_callback = 0x%p ", __func__, btm_cb.api.p_le_callback); + LOG_INFO("%s btm_cb.api.p_le_callback = 0x%p\n", __func__, btm_cb.api.p_le_callback); #endif - BTM_TRACE_EVENT("%s application registered", __func__); + BTM_TRACE_EVENT("%s application registered\n", __func__); return(TRUE); } @@ -378,7 +378,7 @@ BOOLEAN BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, UINT8 * p_sec_flags, return(TRUE); } - BTM_TRACE_ERROR ("BTM_GetSecurityFlags false"); + BTM_TRACE_ERROR ("BTM_GetSecurityFlags false\n"); return(FALSE); } @@ -393,7 +393,7 @@ BOOLEAN BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr, UINT8 * p_sec_flags, *******************************************************************************/ void BTM_SetPinType (UINT8 pin_type, PIN_CODE pin_code, UINT8 pin_code_len) { - BTM_TRACE_API ("BTM_SetPinType: pin type %d [variable-0, fixed-1], code %s, length %d", + BTM_TRACE_API ("BTM_SetPinType: pin type %d [variable-0, fixed-1], code %s, length %d\n", pin_type, (char *) pin_code, pin_code_len); /* If device is not up security mode will be set as a part of startup */ @@ -424,7 +424,7 @@ void BTM_SetPinType (UINT8 pin_type, PIN_CODE pin_code, UINT8 pin_code_len) *******************************************************************************/ void BTM_SetPairableMode (BOOLEAN allow_pairing, BOOLEAN connect_only_paired) { - BTM_TRACE_API ("BTM_SetPairableMode() allow_pairing: %u connect_only_paired: %u", allow_pairing, connect_only_paired); + BTM_TRACE_API ("BTM_SetPairableMode() allow_pairing: %u connect_only_paired: %u\n", allow_pairing, connect_only_paired); btm_cb.pairing_disabled = !allow_pairing; btm_cb.connect_only_paired = connect_only_paired; @@ -447,7 +447,7 @@ void BTM_SetPairableMode (BOOLEAN allow_pairing, BOOLEAN connect_only_paired) *******************************************************************************/ void BTM_SetSecureConnectionsOnly (BOOLEAN secure_connections_only_mode) { - BTM_TRACE_API("%s: Mode : %u", __FUNCTION__, + BTM_TRACE_API("%s: Mode : %u\n", __FUNCTION__, secure_connections_only_mode); btm_cb.devcb.secure_connections_only = secure_connections_only_mode; @@ -542,7 +542,7 @@ static BOOLEAN btm_sec_set_security_level (CONNECTION_TYPE conn_type, char *p_na is_originator = conn_type; #endif - BTM_TRACE_API("%s : sec: 0x%x", __func__, sec_level); + BTM_TRACE_API("%s : sec: 0x%x\n", __func__, sec_level); /* See if the record can be reused (same service name, psm, mx_proto_id, service_id, and mx_chan_id), or obtain the next unused record */ @@ -584,7 +584,7 @@ static BOOLEAN btm_sec_set_security_level (CONNECTION_TYPE conn_type, char *p_na if (!record_allocated) { - BTM_TRACE_WARNING("BTM_SEC_REG: Out of Service Records (%d)", BTM_SEC_MAX_SERVICE_RECORDS); + BTM_TRACE_WARNING("BTM_SEC_REG: Out of Service Records (%d)\n", BTM_SEC_MAX_SERVICE_RECORDS); return(record_allocated); } @@ -699,24 +699,24 @@ static BOOLEAN btm_sec_set_security_level (CONNECTION_TYPE conn_type, char *p_na p_srec->security_flags |= (UINT16)(sec_level | BTM_SEC_IN_USE); } - BTM_TRACE_API("BTM_SEC_REG[%d]: id %d, conn_type 0x%x, psm 0x%04x, proto_id %d, chan_id %d", + BTM_TRACE_API("BTM_SEC_REG[%d]: id %d, conn_type 0x%x, psm 0x%04x, proto_id %d, chan_id %d\n", index, service_id, conn_type, psm, mx_proto_id, mx_chan_id); - BTM_TRACE_API(" : security_flags: 0x%04x, ucd_security_flags: 0x%04x", + BTM_TRACE_API(" : security_flags: 0x%04x, ucd_security_flags: 0x%04x\n", p_srec->security_flags, p_srec->ucd_security_flags); #if BTM_SEC_SERVICE_NAME_LEN > 0 - BTM_TRACE_API(" : service name [%s] (up to %d chars saved)", + BTM_TRACE_API(" : service name [%s] (up to %d chars saved)\n", p_name, BTM_SEC_SERVICE_NAME_LEN); #endif #else p_srec->security_flags |= (UINT16)(sec_level | BTM_SEC_IN_USE); - BTM_TRACE_API("BTM_SEC_REG[%d]: id %d, is_orig %d, psm 0x%04x, proto_id %d, chan_id %d", + BTM_TRACE_API("BTM_SEC_REG[%d]: id %d, is_orig %d, psm 0x%04x, proto_id %d, chan_id %d\n", index, service_id, is_originator, psm, mx_proto_id, mx_chan_id); #if BTM_SEC_SERVICE_NAME_LEN > 0 - BTM_TRACE_API(" : sec: 0x%x, service name [%s] (up to %d chars saved)", + BTM_TRACE_API(" : sec: 0x%x, service name [%s] (up to %d chars saved)\n", p_srec->security_flags, p_name, BTM_SEC_SERVICE_NAME_LEN); #endif #endif @@ -755,7 +755,7 @@ UINT8 BTM_SecClrService (UINT8 service_id) if ((p_srec->security_flags & BTM_SEC_IN_USE) && (p_srec->psm != BT_PSM_SDP) && (!service_id || (service_id == p_srec->service_id))) { - BTM_TRACE_API("BTM_SEC_CLR[%d]: id %d", i, service_id); + BTM_TRACE_API("BTM_SEC_CLR[%d]: id %d\n", i, service_id); p_srec->security_flags = 0; #if (L2CAP_UCD_INCLUDED == TRUE) p_srec->ucd_security_flags = 0; @@ -794,12 +794,12 @@ UINT8 btm_sec_clr_service_by_psm (UINT16 psm) /* Delete services with specified name (if in use and not SDP) */ if ((p_srec->security_flags & BTM_SEC_IN_USE) && (p_srec->psm == psm) ) { - BTM_TRACE_API("BTM_SEC_CLR[%d]: id %d ", i, p_srec->service_id); + BTM_TRACE_API("BTM_SEC_CLR[%d]: id %d\n", i, p_srec->service_id); p_srec->security_flags = 0; num_freed++; } } - BTM_TRACE_API("btm_sec_clr_service_by_psm psm:0x%x num_freed:%d", psm, num_freed); + BTM_TRACE_API("btm_sec_clr_service_by_psm psm:0x%x num_freed:%d\n", psm, num_freed); return(num_freed); } @@ -822,14 +822,14 @@ void btm_sec_clr_temp_auth_service (BD_ADDR bda) if ((p_dev_rec = btm_find_dev (bda)) == NULL) { - BTM_TRACE_WARNING ("btm_sec_clr_temp_auth_service() - no dev CB"); + BTM_TRACE_WARNING ("btm_sec_clr_temp_auth_service() - no dev CB\n"); return; } /* Reset the temporary authorized flag so that next time (untrusted) service is accessed autorization will take place */ if (p_dev_rec->last_author_service_id != BTM_SEC_NO_LAST_SERVICE_ID && p_dev_rec->p_cur_service) { - BTM_TRACE_DEBUG ("btm_sec_clr_auth_service_by_psm [clearing device: %02x:%02x:%02x:%02x:%02x:%02x]", + BTM_TRACE_DEBUG ("btm_sec_clr_auth_service_by_psm [clearing device: %02x:%02x:%02x:%02x:%02x:%02x]\n", bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); p_dev_rec->last_author_service_id = BTM_SEC_NO_LAST_SERVICE_ID; @@ -854,25 +854,25 @@ void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin, { tBTM_SEC_DEV_REC *p_dev_rec; - BTM_TRACE_API ("BTM_PINCodeReply(): PairState: %s PairFlags: 0x%02x PinLen:%d Result:%d", + BTM_TRACE_API ("BTM_PINCodeReply(): PairState: %s PairFlags: 0x%02x PinLen:%d Result:%d\n", btm_pair_state_descr(btm_cb.pairing_state), btm_cb.pairing_flags, pin_len, res); /* If timeout already expired or has been canceled, ignore the reply */ if (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_PIN) { - BTM_TRACE_WARNING ("BTM_PINCodeReply() - Wrong State: %d", btm_cb.pairing_state); + BTM_TRACE_WARNING ("BTM_PINCodeReply() - Wrong State: %d\n", btm_cb.pairing_state); return; } if (memcmp (bd_addr, btm_cb.pairing_bda, BD_ADDR_LEN) != 0) { - BTM_TRACE_ERROR ("BTM_PINCodeReply() - Wrong BD Addr"); + BTM_TRACE_ERROR ("BTM_PINCodeReply() - Wrong BD Addr\n"); return; } if ((p_dev_rec = btm_find_dev (bd_addr)) == NULL) { - BTM_TRACE_ERROR ("BTM_PINCodeReply() - no dev CB"); + BTM_TRACE_ERROR ("BTM_PINCodeReply() - no dev CB\n"); return; } @@ -927,7 +927,7 @@ void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin, /* before originating */ if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) { - BTM_TRACE_WARNING ("BTM_PINCodeReply(): waiting HCI_Connection_Complete after rejected incoming connection"); + BTM_TRACE_WARNING ("BTM_PINCodeReply(): waiting HCI_Connection_Complete after rejected incoming connection\n"); /* we change state little bit early so btm_sec_connected() will originate connection */ /* when existing ACL link is down completely */ btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ); @@ -935,7 +935,7 @@ void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin, /* if we already accepted incoming connection from pairing device */ else if (p_dev_rec->sm4 & BTM_SM4_CONN_PEND) { - BTM_TRACE_WARNING ("BTM_PINCodeReply(): link is connecting so wait pin code request from peer"); + BTM_TRACE_WARNING ("BTM_PINCodeReply(): link is connecting so wait pin code request from peer\n"); btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ); } else if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) @@ -954,7 +954,7 @@ void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin, btm_cb.acl_disc_reason = HCI_SUCCESS; #ifdef PORCHE_PAIRING_CONFLICT - BTM_TRACE_EVENT("BTM_PINCodeReply(): Saving pin_len: %d btm_cb.pin_code_len: %d", pin_len, btm_cb.pin_code_len); + BTM_TRACE_EVENT("BTM_PINCodeReply(): Saving pin_len: %d btm_cb.pin_code_len: %d\n", pin_len, btm_cb.pin_code_len); /* if this was not pre-fetched, save the PIN */ if (btm_cb.pin_code_len == 0) memcpy (btm_cb.pin_code, p_pin, pin_len); @@ -984,16 +984,16 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, UINT8 *p_features; UINT8 ii; tACL_CONN *p= btm_bda_to_acl(bd_addr, transport); - BTM_TRACE_API ("btm_sec_bond_by_transport BDA: %02x:%02x:%02x:%02x:%02x:%02x", + BTM_TRACE_API ("btm_sec_bond_by_transport 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]); - BTM_TRACE_DEBUG("btm_sec_bond_by_transport: Transport used %d" , transport); + BTM_TRACE_DEBUG("btm_sec_bond_by_transport: Transport used %d\n" , transport); /* Other security process is in progress */ if (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) { - BTM_TRACE_ERROR ("BTM_SecBond: already busy in state: %s", btm_pair_state_descr(btm_cb.pairing_state)); + BTM_TRACE_ERROR ("BTM_SecBond: already busy in state: %s\n", btm_pair_state_descr(btm_cb.pairing_state)); return(BTM_WRONG_MODE); } @@ -1002,7 +1002,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, return(BTM_NO_RESOURCES); } - BTM_TRACE_DEBUG ("before update sec_flags=0x%x", p_dev_rec->sec_flags); + BTM_TRACE_DEBUG ("before update sec_flags=0x%x\n", p_dev_rec->sec_flags); /* Finished if connection is active and already paired */ if ( ((p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE) && transport == BT_TRANSPORT_BR_EDR @@ -1014,7 +1014,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, ) { - BTM_TRACE_WARNING("BTM_SecBond -> Already Paired"); + BTM_TRACE_WARNING("BTM_SecBond -> Already Paired\n"); return(BTM_SUCCESS); } @@ -1062,7 +1062,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, | BTM_SEC_ROLE_SWITCHED | BTM_SEC_LINK_KEY_AUTHED); - BTM_TRACE_DEBUG ("after update sec_flags=0x%x", p_dev_rec->sec_flags); + BTM_TRACE_DEBUG ("after update sec_flags=0x%x\n", p_dev_rec->sec_flags); if (!controller_get_interface()->supports_simple_pairing()) { /* The special case when we authenticate keyboard. Set pin type to fixed */ @@ -1080,13 +1080,13 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, for (ii = 0; ii <= HCI_EXT_FEATURES_PAGE_MAX; ii++) { p_features = p_dev_rec->features[ii]; - BTM_TRACE_EVENT(" remote_features page[%1d] = %02x-%02x-%02x-%02x", + BTM_TRACE_EVENT(" remote_features page[%1d] = %02x-%02x-%02x-%02x\n", ii, p_features[0], p_features[1], p_features[2], p_features[3]); - BTM_TRACE_EVENT(" %02x-%02x-%02x-%02x", + BTM_TRACE_EVENT(" %02x-%02x-%02x-%02x\n", p_features[4], p_features[5], p_features[6], p_features[7]); } - BTM_TRACE_EVENT ("BTM_SecBond: Remote sm4: 0x%x HCI Handle: 0x%04x", p_dev_rec->sm4, p_dev_rec->hci_handle); + BTM_TRACE_EVENT ("BTM_SecBond: Remote sm4: 0x%x HCI Handle: 0x%04x\n", p_dev_rec->sm4, p_dev_rec->hci_handle); #if BTM_SEC_FORCE_RNR_FOR_DBOND == TRUE p_dev_rec->sec_flags &= ~BTM_SEC_NAME_KNOWN; @@ -1105,7 +1105,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, return(BTM_CMD_STARTED); } - BTM_TRACE_DEBUG ("sec mode: %d sm4:x%x", btm_cb.security_mode, p_dev_rec->sm4); + BTM_TRACE_DEBUG ("sec mode: %d sm4:x%x\n", btm_cb.security_mode, p_dev_rec->sm4); if (!controller_get_interface()->supports_simple_pairing() || (p_dev_rec->sm4 == BTM_SM4_KNOWN)) { @@ -1131,7 +1131,7 @@ tBTM_STATUS btm_sec_bond_by_transport (BD_ADDR bd_addr, tBT_TRANSPORT transport, /* We are accepting connection request from peer */ btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ); } - BTM_TRACE_DEBUG ("State:%s sm4: 0x%x sec_state:%d", + BTM_TRACE_DEBUG ("State:%s sm4: 0x%x sec_state:%d\n", btm_pair_state_descr (btm_cb.pairing_state), p_dev_rec->sm4, p_dev_rec->sec_state); return BTM_CMD_STARTED; } @@ -1220,7 +1220,7 @@ tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr) { tBTM_SEC_DEV_REC *p_dev_rec; - BTM_TRACE_API ("BTM_SecBondCancel() State: %s flags:0x%x", + BTM_TRACE_API ("BTM_SecBondCancel() State: %s flags:0x%x\n", btm_pair_state_descr (btm_cb.pairing_state), btm_cb.pairing_flags); if (((p_dev_rec = btm_find_dev (bd_addr)) == NULL) @@ -1232,7 +1232,7 @@ tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr) { if (p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) { - BTM_TRACE_DEBUG ("Cancel LE pairing"); + BTM_TRACE_DEBUG ("Cancel LE pairing\n"); if (SMP_PairCancel(bd_addr)) { return BTM_CMD_STARTED; @@ -1242,7 +1242,7 @@ tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr) } #endif - BTM_TRACE_DEBUG ("hci_handle:0x%x sec_state:%d", p_dev_rec->hci_handle, p_dev_rec->sec_state ); + BTM_TRACE_DEBUG ("hci_handle:0x%x sec_state:%d\n", p_dev_rec->hci_handle, p_dev_rec->sec_state ); if (BTM_PAIR_STATE_WAIT_LOCAL_PIN == btm_cb.pairing_state && BTM_PAIR_FLAGS_WE_STARTED_DD & btm_cb.pairing_flags) { @@ -1386,7 +1386,7 @@ tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_SE ) { /* Connection should be up and runnning */ - BTM_TRACE_WARNING ("Security Manager: BTM_SetEncryption not connected"); + BTM_TRACE_WARNING ("Security Manager: BTM_SetEncryption not connected\n"); if (p_callback) (*p_callback) (bd_addr, transport, p_ref_data, BTM_WRONG_MODE); @@ -1402,7 +1402,7 @@ tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_SE #endif ) { - BTM_TRACE_EVENT ("Security Manager: BTM_SetEncryption already encrypted"); + BTM_TRACE_EVENT ("Security Manager: BTM_SetEncryption already encrypted\n"); if (p_callback) (*p_callback) (bd_addr, transport, p_ref_data, BTM_SUCCESS); @@ -1413,7 +1413,7 @@ tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_SE /* enqueue security request if security is active */ if (p_dev_rec->p_callback || (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE)) { - BTM_TRACE_WARNING ("Security Manager: BTM_SetEncryption busy, enqueue request"); + BTM_TRACE_WARNING ("Security Manager: BTM_SetEncryption busy, enqueue request\n"); if (btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data)) { @@ -1432,7 +1432,7 @@ tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_SE p_dev_rec->security_required |= (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_IN_ENCRYPT); p_dev_rec->is_originator = FALSE; - BTM_TRACE_API ("Security Manager: BTM_SetEncryption Handle:%d State:%d Flags:0x%x Required:0x%x", + BTM_TRACE_API ("Security Manager: BTM_SetEncryption Handle:%d State:%d Flags:0x%x Required:0x%x\n", p_dev_rec->hci_handle, p_dev_rec->sec_state, p_dev_rec->sec_flags, p_dev_rec->security_required); @@ -1447,7 +1447,7 @@ tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_SE else { rc = BTM_WRONG_MODE; - BTM_TRACE_WARNING("%s: cannot call btm_ble_set_encryption, p is NULL", __FUNCTION__); + BTM_TRACE_WARNING("%s: cannot call btm_ble_set_encryption, p is NULL\n", __FUNCTION__); } } else @@ -1474,7 +1474,7 @@ static tBTM_STATUS btm_sec_send_hci_disconnect (tBTM_SEC_DEV_REC *p_dev_rec, UIN UINT8 old_state = p_dev_rec->sec_state; tBTM_STATUS status = BTM_CMD_STARTED; - BTM_TRACE_EVENT ("btm_sec_send_hci_disconnect: handle:0x%x, reason=0x%x", + BTM_TRACE_EVENT ("btm_sec_send_hci_disconnect: handle:0x%x, reason=0x%x\n", conn_handle, reason); /* send HCI_Disconnect on a transport only once */ @@ -1509,7 +1509,7 @@ static tBTM_STATUS btm_sec_send_hci_disconnect (tBTM_SEC_DEV_REC *p_dev_rec, UIN /* If a role switch is in progress, delay the HCI Disconnect to avoid controller problem */ if (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING && p_dev_rec->hci_handle == conn_handle) { - BTM_TRACE_DEBUG("RS in progress - Set DISC Pending flag in btm_sec_send_hci_disconnect to delay disconnect"); + BTM_TRACE_DEBUG("RS in progress - Set DISC Pending flag in btm_sec_send_hci_disconnect to delay disconnect\n"); p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING; status = BTM_SUCCESS; } @@ -1586,7 +1586,7 @@ void BTM_ConfirmReqReply(tBTM_STATUS res, BD_ADDR bd_addr) #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) void BTM_PasskeyReqReply(tBTM_STATUS res, BD_ADDR bd_addr, UINT32 passkey) { - BTM_TRACE_API ("BTM_PasskeyReqReply: State: %s res:%d", + BTM_TRACE_API ("BTM_PasskeyReqReply: State: %s res:%d\n", btm_pair_state_descr(btm_cb.pairing_state), res); if ( (btm_cb.pairing_state == BTM_PAIR_STATE_IDLE) @@ -1675,7 +1675,7 @@ void BTM_SendKeypressNotif(BD_ADDR bd_addr, tBTM_SP_KEY_TYPE type) *******************************************************************************/ void BTM_IoCapRsp(BD_ADDR bd_addr, tBTM_IO_CAP io_cap, tBTM_OOB_DATA oob, tBTM_AUTH_REQ auth_req) { - BTM_TRACE_EVENT ("BTM_IoCapRsp: state: %s oob: %d io_cap: %d", + BTM_TRACE_EVENT ("BTM_IoCapRsp: state: %s oob: %d io_cap: %d\n", btm_pair_state_descr(btm_cb.pairing_state), oob, io_cap); if ( (btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS) @@ -1726,7 +1726,7 @@ tBTM_STATUS BTM_ReadLocalOobData(void) *******************************************************************************/ void BTM_RemoteOobDataReply(tBTM_STATUS res, BD_ADDR bd_addr, BT_OCTET16 c, BT_OCTET16 r) { - BTM_TRACE_EVENT ("%s() - State: %s res: %d", __func__, + BTM_TRACE_EVENT ("%s() - State: %s res: %d\n", __func__, btm_pair_state_descr(btm_cb.pairing_state), res); /* If timeout already expired or has been canceled, ignore the reply */ @@ -1880,7 +1880,7 @@ BOOLEAN BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr) if ((p_dev_rec = btm_find_dev(bd_addr)) == NULL) { - BTM_TRACE_WARNING("%s: unknown BDA: %08x%04x", __FUNCTION__, + BTM_TRACE_WARNING("%s: unknown BDA: %08x%04x\n", __FUNCTION__, (bd_addr[0]<<24) + (bd_addr[1]<<16) + (bd_addr[2]<<8) + bd_addr[3], (bd_addr[4]<< 8) + bd_addr[5]); return FALSE; @@ -1987,7 +1987,7 @@ void BTM_SetOutService(BD_ADDR bd_addr, UINT8 service_id, UINT32 mx_chan_id) && (p_serv_rec->service_id == service_id) && (p_serv_rec->orig_mx_chan_id == mx_chan_id)) { - BTM_TRACE_API("BTM_SetOutService p_out_serv id %d, psm 0x%04x, proto_id %d, chan_id %d", + BTM_TRACE_API("BTM_SetOutService p_out_serv id %d, psm 0x%04x, proto_id %d, chan_id %d\n", p_serv_rec->service_id, p_serv_rec->psm, p_serv_rec->mx_proto_id, p_serv_rec->orig_mx_chan_id); btm_cb.p_out_serv = p_serv_rec; if (p_dev_rec) @@ -2020,13 +2020,13 @@ static BOOLEAN btm_sec_is_upgrade_possible(tBTM_SEC_DEV_REC *p_dev_rec, BOOLEAN is_possible = FALSE; if(p_dev_rec->p_cur_service) { - BTM_TRACE_DEBUG ("%s() id: %d, link_key_typet: %d, rmt_io_caps: %d, chk flags: 0x%x, flags: 0x%x", + BTM_TRACE_DEBUG ("%s() id: %d, link_key_typet: %d, rmt_io_caps: %d, chk flags: 0x%x, flags: 0x%x\n", __func__, p_dev_rec->p_cur_service->service_id, p_dev_rec->link_key_type, p_dev_rec->rmt_io_caps, mtm_check, p_dev_rec->p_cur_service->security_flags); } else { - BTM_TRACE_DEBUG ("%s() link_key_typet: %d, rmt_io_caps: %d, chk flags: 0x%x", + BTM_TRACE_DEBUG ("%s() link_key_typet: %d, rmt_io_caps: %d, chk flags: 0x%x\n", __func__, p_dev_rec->link_key_type, p_dev_rec->rmt_io_caps, mtm_check); } /* Already have a link key to the connected peer. Is the link key secure enough? @@ -2048,7 +2048,7 @@ static BOOLEAN btm_sec_is_upgrade_possible(tBTM_SEC_DEV_REC *p_dev_rec, BOOLEAN is_possible = TRUE; } } - BTM_TRACE_DEBUG ("%s() is_possible: %d sec_flags: 0x%x", __func__, is_possible, p_dev_rec->sec_flags); + BTM_TRACE_DEBUG ("%s() is_possible: %d sec_flags: 0x%x\n", __func__, is_possible, p_dev_rec->sec_flags); return is_possible; } @@ -2065,7 +2065,7 @@ static BOOLEAN btm_sec_is_upgrade_possible(tBTM_SEC_DEV_REC *p_dev_rec, BOOLEAN static void btm_sec_check_upgrade(tBTM_SEC_DEV_REC *p_dev_rec, BOOLEAN is_originator) { - BTM_TRACE_DEBUG ("%s()", __func__); + BTM_TRACE_DEBUG ("%s()\n", __func__); /* Only check if link key already exists */ if (!(p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) @@ -2073,7 +2073,7 @@ static void btm_sec_check_upgrade(tBTM_SEC_DEV_REC *p_dev_rec, BOOLEAN is_origi if (btm_sec_is_upgrade_possible (p_dev_rec, is_originator) == TRUE) { - BTM_TRACE_DEBUG ("need upgrade!! sec_flags:0x%x", p_dev_rec->sec_flags); + BTM_TRACE_DEBUG ("need upgrade!! sec_flags:0x%x\n", p_dev_rec->sec_flags); /* upgrade is possible: check if the application wants the upgrade. * If the application is configured to use a global MITM flag, * it probably would not want to upgrade the link key based on the security level database */ @@ -2083,7 +2083,7 @@ static void btm_sec_check_upgrade(tBTM_SEC_DEV_REC *p_dev_rec, BOOLEAN is_origi if (btm_cb.api.p_sp_callback) (*btm_cb.api.p_sp_callback) (BTM_SP_UPGRADE_EVT, (tBTM_SP_EVT_DATA *)&evt_data); - BTM_TRACE_DEBUG ("evt_data.upgrade:0x%x", evt_data.upgrade); + BTM_TRACE_DEBUG ("evt_data.upgrade:0x%x\n", evt_data.upgrade); if (evt_data.upgrade) { /* if the application confirms the upgrade, set the upgrade bit */ @@ -2092,7 +2092,7 @@ static void btm_sec_check_upgrade(tBTM_SEC_DEV_REC *p_dev_rec, BOOLEAN is_origi /* Clear the link key known to go through authentication/pairing again */ p_dev_rec->sec_flags &= ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED); p_dev_rec->sec_flags &= ~BTM_SEC_AUTHENTICATED; - BTM_TRACE_DEBUG ("sec_flags:0x%x", p_dev_rec->sec_flags); + BTM_TRACE_DEBUG ("sec_flags:0x%x\n", p_dev_rec->sec_flags); } } } @@ -2145,11 +2145,11 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle else is_originator = FALSE; - BTM_TRACE_DEBUG ("%s() conn_type: 0x%x, 0x%x", __func__, conn_type, p_ref_data); + BTM_TRACE_DEBUG ("%s() conn_type: 0x%x, 0x%x\n", __func__, conn_type, p_ref_data); #else is_originator = conn_type; - BTM_TRACE_DEBUG ("%s() is_originator:%d, 0x%x", __func__, is_originator, p_ref_data); + BTM_TRACE_DEBUG ("%s() is_originator:%d, 0x%x\n", __func__, is_originator, p_ref_data); #endif /* Find or get oldest record */ @@ -2163,7 +2163,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle /* If there is no application registered with this PSM do not allow connection */ if (!p_serv_rec) { - BTM_TRACE_WARNING ("%s() PSM: %d no application registerd", __func__, psm); + BTM_TRACE_WARNING ("%s() PSM: %d no application registerd\n", __func__, psm); (*p_callback) (bd_addr, transport, p_ref_data, BTM_MODE_UNSUPPORTED); return(BTM_MODE_UNSUPPORTED); } @@ -2242,7 +2242,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle } } - BTM_TRACE_DEBUG("%s: security_required 0x%04x, is_originator 0x%02x, psm 0x%04x", + BTM_TRACE_DEBUG("%s: security_required 0x%04x, is_originator 0x%02x, psm 0x%04x\n", __FUNCTION__, security_required, is_originator, psm); if ((!is_originator) && (security_required & BTM_SEC_MODE4_LEVEL4)) @@ -2251,8 +2251,8 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle /* acceptor receives L2CAP Channel Connect Request for Secure Connections Only service */ if (!(local_supports_sc) || !(p_dev_rec->remote_supports_secure_connections)) { - BTM_TRACE_DEBUG("%s: SC only service, local_support_for_sc %d", - "rmt_support_for_sc : %d -> fail pairing", __FUNCTION__, + BTM_TRACE_DEBUG("%s: SC only service, local_support_for_sc %d\n", + "rmt_support_for_sc : %d -> fail pairing\n", __FUNCTION__, local_supports_sc, p_dev_rec->remote_supports_secure_connections); if (p_callback) @@ -2267,9 +2267,9 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle /* we will process one after another */ if ( (p_dev_rec->p_callback) || (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) ) { - BTM_TRACE_EVENT ("%s() - busy - PSM:%d delayed state: %s mode:%d, sm4:0x%x", __func__, + BTM_TRACE_EVENT ("%s() - busy - PSM:%d delayed state: %s mode:%d, sm4:0x%x\n", __func__, psm, btm_pair_state_descr(btm_cb.pairing_state), btm_cb.security_mode, p_dev_rec->sm4); - BTM_TRACE_EVENT ("security_flags:x%x, sec_flags:x%x", security_required, p_dev_rec->sec_flags); + BTM_TRACE_EVENT ("security_flags:x%x, sec_flags:x%x\n", security_required, p_dev_rec->sec_flags); rc = BTM_CMD_STARTED; if ((btm_cb.security_mode == BTM_SEC_MODE_UNDEFINED || btm_cb.security_mode == BTM_SEC_MODE_NONE || @@ -2352,7 +2352,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle else if (!(BTM_SM4_KNOWN & p_dev_rec->sm4)) { /* the remote features are not known yet */ - BTM_TRACE_DEBUG("%s: (%s) remote features unknown!!sec_flags:0x%02x", __FUNCTION__, + BTM_TRACE_DEBUG("%s: (%s) remote features unknown!!sec_flags:0x%02x\n", __FUNCTION__, (is_originator) ? "initiator" : "acceptor", p_dev_rec->sec_flags); p_dev_rec->sm4 |= BTM_SM4_REQ_PEND; @@ -2360,7 +2360,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle } } - BTM_TRACE_DEBUG ("%s() sm4:0x%x, sec_flags:0x%x, security_required:0x%x chk:%d", __func__, + BTM_TRACE_DEBUG ("%s() sm4:0x%x, sec_flags:0x%x, security_required:0x%x chk:%d\n", __func__, p_dev_rec->sm4, p_dev_rec->sec_flags, security_required, chk_acp_auth_done); old_security_required = p_dev_rec->security_required; @@ -2385,10 +2385,10 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle if ((btm_sec_find_next_serv (p_serv_rec)) != NULL) #endif { - BTM_TRACE_DEBUG ("no next_serv sm4:0x%x, chk:%d", p_dev_rec->sm4, chk_acp_auth_done); + BTM_TRACE_DEBUG ("no next_serv sm4:0x%x, chk:%d\n", p_dev_rec->sm4, chk_acp_auth_done); if (!BTM_SEC_IS_SM4(p_dev_rec->sm4)) { - BTM_TRACE_EVENT ("Security Manager: l2cap_access_req PSM:%d postponed for multiplexer", psm); + BTM_TRACE_EVENT ("Security Manager: l2cap_access_req PSM:%d postponed for multiplexer\n", psm); /* pre-Lisbon: restore the old settings */ p_dev_rec->security_required = old_security_required; p_dev_rec->is_originator = old_is_originator; @@ -2409,7 +2409,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle btm_cb.security_mode == BTM_SEC_MODE_LINK) || !BTM_SEC_IS_SM4(p_dev_rec->sm4)) && (psm >= 0x1001)) { - BTM_TRACE_EVENT ("dynamic PSM:0x%x in legacy mode - postponed for upper layer", psm); + BTM_TRACE_EVENT ("dynamic PSM:0x%x in legacy mode - postponed for upper layer\n", psm); /* restore the old settings */ p_dev_rec->security_required = old_security_required; p_dev_rec->is_originator = old_is_originator; @@ -2421,7 +2421,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle if (chk_acp_auth_done) { - BTM_TRACE_DEBUG ("(SM4 to SM4) btm_sec_l2cap_access_req rspd. authenticated: x%x, enc: x%x", + BTM_TRACE_DEBUG ("(SM4 to SM4) btm_sec_l2cap_access_req rspd. authenticated: x%x, enc: x%x\n", (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED), (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED)); /* SM4, but we do not know for sure which level of security we need. * as long as we have a link key, it's OK */ @@ -2433,7 +2433,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle 2046 may report HCI_Encryption_Change and L2C Connection Request out of sequence because of data path issues. Delay this disconnect a little bit */ - LOG_INFO("%s peer should have initiated security process by now (SM4 to SM4)", __func__); + LOG_INFO("%s peer should have initiated security process by now (SM4 to SM4)\n", __func__); p_dev_rec->p_callback = p_callback; p_dev_rec->sec_state = BTM_SEC_STATE_DELAY_FOR_ENC; (*p_callback) (bd_addr, transport, p_ref_data, rc); @@ -2476,7 +2476,7 @@ tBTM_STATUS btm_sec_l2cap_access_req (BD_ADDR bd_addr, UINT16 psm, UINT16 handle } } - BTM_TRACE_EVENT ("%s() PSM:%d Handle:%d State:%d Flags: 0x%x Required: 0x%x Service ID:%d", + BTM_TRACE_EVENT ("%s() PSM:%d Handle:%d State:%d Flags: 0x%x Required: 0x%x Service ID:%d\n", __func__, psm, handle, p_dev_rec->sec_state, p_dev_rec->sec_flags, p_dev_rec->security_required, p_dev_rec->p_cur_service->service_id); @@ -2522,7 +2522,7 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o UINT16 security_required; BOOLEAN transport = FALSE;/* should check PSM range in LE connection oriented L2CAP connection */ - BTM_TRACE_DEBUG ("%s() is_originator: %d", __func__, is_originator); + BTM_TRACE_DEBUG ("%s() is_originator: %d\n", __func__, is_originator); /* Find or get oldest record */ p_dev_rec = btm_find_or_alloc_dev (bd_addr); @@ -2535,7 +2535,7 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o if (p_callback) (*p_callback) (bd_addr, transport, p_ref_data, BTM_MODE_UNSUPPORTED); - BTM_TRACE_ERROR ("Security Manager: MX service not found PSM:%d Proto:%d SCN:%d", + BTM_TRACE_ERROR ("Security Manager: MX service not found PSM:%d Proto:%d SCN:%d\n", psm, mx_proto_id, mx_chan_id); return BTM_NO_RESOURCES; } @@ -2554,7 +2554,7 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o /* we will process one after another */ if ( (p_dev_rec->p_callback) || (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) ) { - BTM_TRACE_EVENT ("%s() service PSM:%d Proto:%d SCN:%d delayed state: %s", __func__, + BTM_TRACE_EVENT ("%s() service PSM:%d Proto:%d SCN:%d delayed state: %s\n", __func__, psm, mx_proto_id, mx_chan_id, btm_pair_state_descr(btm_cb.pairing_state)); rc = BTM_CMD_STARTED; @@ -2604,13 +2604,13 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o if (rc == BTM_SUCCESS) { - BTM_TRACE_EVENT("%s: allow to bypass, checking authorization", __FUNCTION__); + BTM_TRACE_EVENT("%s: allow to bypass, checking authorization\n", __FUNCTION__); /* the security in BTM_SEC_IN_FLAGS is fullfilled so far, check the requirements in */ /* btm_sec_execute_procedure */ if ((is_originator && (p_serv_rec->security_flags & BTM_SEC_OUT_AUTHORIZE)) || (!is_originator && (p_serv_rec->security_flags & BTM_SEC_IN_AUTHORIZE))) { - BTM_TRACE_EVENT("%s: still need authorization", __FUNCTION__); + BTM_TRACE_EVENT("%s: still need authorization\n", __FUNCTION__); rc = BTM_CMD_STARTED; } } @@ -2619,12 +2619,12 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o /* the new security request */ if (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE) { - BTM_TRACE_EVENT("%s: There is a pending security procedure", __FUNCTION__); + BTM_TRACE_EVENT("%s: There is a pending security procedure\n", __FUNCTION__); rc = BTM_CMD_STARTED; } if (rc == BTM_CMD_STARTED) { - BTM_TRACE_EVENT("%s: call btm_sec_queue_mx_request", __FUNCTION__); + BTM_TRACE_EVENT("%s: call btm_sec_queue_mx_request\n", __FUNCTION__); btm_sec_queue_mx_request (bd_addr, psm, is_originator, mx_proto_id, mx_chan_id, p_callback, p_ref_data); } @@ -2637,7 +2637,7 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o } } - BTM_TRACE_EVENT("%s: return with rc = 0x%02x in delayed state %s", __FUNCTION__, rc, + BTM_TRACE_EVENT("%s: return with rc = 0x%02x in delayed state %s\n", __FUNCTION__, rc, btm_pair_state_descr(btm_cb.pairing_state)); return rc; } @@ -2650,8 +2650,8 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o /* Secure Connections Only service */ if (!(local_supports_sc) || !(p_dev_rec->remote_supports_secure_connections)) { - BTM_TRACE_DEBUG("%s: SC only service,local_support_for_sc %d,", - "remote_support_for_sc %d: fail pairing",__FUNCTION__, + BTM_TRACE_DEBUG("%s: SC only service,local_support_for_sc %d,\n", + "remote_support_for_sc %d: fail pairing\n",__FUNCTION__, local_supports_sc, p_dev_rec->remote_supports_secure_connections); if (p_callback) @@ -2682,7 +2682,7 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o p_dev_rec->sec_flags &= ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED | BTM_SEC_AUTHENTICATED); - BTM_TRACE_DEBUG("%s: sec_flags:0x%x", __FUNCTION__, p_dev_rec->sec_flags); + BTM_TRACE_DEBUG("%s: sec_flags:0x%x\n", __FUNCTION__, p_dev_rec->sec_flags); } else { @@ -2702,7 +2702,7 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o /* scn, we need to request user's permission again. */ p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED); - BTM_TRACE_EVENT ("%s() proto_id:%d chan_id:%d State:%d Flags:0x%x Required:0x%x Service ID:%d", + BTM_TRACE_EVENT ("%s() proto_id:%d chan_id:%d State:%d Flags:0x%x Required:0x%x Service ID:%d\n", __func__, mx_proto_id, mx_chan_id, p_dev_rec->sec_state, p_dev_rec->sec_flags, p_dev_rec->security_required, p_dev_rec->p_cur_service->service_id); @@ -2735,7 +2735,7 @@ void btm_sec_conn_req (UINT8 *bda, UINT8 *dc) /* Some device may request a connection before we are done with the HCI_Reset sequence */ if (!controller_get_interface()->get_is_ready()) { - BTM_TRACE_EVENT ("Security Manager: connect request when device not ready"); + BTM_TRACE_EVENT ("Security Manager: connect request when device not ready\n"); btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); return; } @@ -2747,7 +2747,7 @@ void btm_sec_conn_req (UINT8 *bda, UINT8 *dc) { if (!p_dev_rec || !(p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)) { - BTM_TRACE_EVENT ("Security Manager: connect request from non-paired device"); + BTM_TRACE_EVENT ("Security Manager: connect request from non-paired device\n"); btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); return; } @@ -2759,7 +2759,7 @@ void btm_sec_conn_req (UINT8 *bda, UINT8 *dc) { if (!p_dev_rec) { - BTM_TRACE_EVENT ("Security Manager: connect request from not paired device"); + BTM_TRACE_EVENT ("Security Manager: connect request from not paired device\n"); btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); return; } @@ -2770,7 +2770,7 @@ void btm_sec_conn_req (UINT8 *bda, UINT8 *dc) &&(btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) &&(!memcmp (btm_cb.pairing_bda, bda, BD_ADDR_LEN))) { - BTM_TRACE_EVENT ("Security Manager: reject connect request from bonding device"); + BTM_TRACE_EVENT ("Security Manager: reject connect request from bonding device\n"); /* incoming connection from bonding device is rejected */ btm_cb.pairing_flags |= BTM_PAIR_FLAGS_REJECTED_CONNECT; @@ -2849,7 +2849,7 @@ void btm_create_conn_cancel_complete (UINT8 *p) UINT8 status; STREAM_TO_UINT8 (status, p); - BTM_TRACE_EVENT ("btm_create_conn_cancel_complete(): in State: %s status:%d", + BTM_TRACE_EVENT ("btm_create_conn_cancel_complete(): in State: %s status:%d\n", btm_pair_state_descr(btm_cb.pairing_state), status); /* if the create conn cancel cmd was issued by the bond cancel, @@ -2906,7 +2906,7 @@ void btm_sec_check_pending_reqs (void) { if (p_e->psm != 0) { - BTM_TRACE_EVENT("%s PSM:0x%04x Is_Orig:%u mx_proto_id:%u mx_chan_id:%u", + BTM_TRACE_EVENT("%s PSM:0x%04x Is_Orig:%u mx_proto_id:%u mx_chan_id:%u\n", __FUNCTION__, p_e->psm, p_e->is_orig, p_e->mx_proto_id, p_e->mx_chan_id); @@ -2954,7 +2954,7 @@ void btm_sec_init (UINT8 sec_mode) *******************************************************************************/ void btm_sec_device_down (void) { - BTM_TRACE_EVENT ("%s() State: %s", __func__, btm_pair_state_descr(btm_cb.pairing_state)); + BTM_TRACE_EVENT ("%s() State: %s\n", __func__, btm_pair_state_descr(btm_cb.pairing_state)); btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); } @@ -2974,7 +2974,7 @@ void btm_sec_dev_reset (void) /* set the default IO capabilities */ btm_cb.devcb.loc_io_caps = BTM_LOCAL_IO_CAPS; /* add mx service to use no security */ - BTM_SetSecurityLevel(FALSE, "RFC_MUX", BTM_SEC_SERVICE_RFC_MUX, + BTM_SetSecurityLevel(FALSE, "RFC_MUX\n", BTM_SEC_SERVICE_RFC_MUX, BTM_SEC_NONE, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, 0); } else @@ -2982,7 +2982,7 @@ void btm_sec_dev_reset (void) btm_cb.security_mode = BTM_SEC_MODE_SERVICE; } - BTM_TRACE_DEBUG ("btm_sec_dev_reset sec mode: %d", btm_cb.security_mode); + BTM_TRACE_DEBUG ("btm_sec_dev_reset sec mode: %d\n", btm_cb.security_mode); } /******************************************************************************* @@ -3027,14 +3027,14 @@ static tBTM_STATUS btm_sec_dd_create_conn (tBTM_SEC_DEV_REC *p_dev_rec) tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR); if (p_lcb && (p_lcb->link_state == LST_CONNECTED || p_lcb->link_state == LST_CONNECTING)) { - BTM_TRACE_WARNING("%s Connection already exists", __func__); + BTM_TRACE_WARNING("%s Connection already exists\n", __func__); return BTM_CMD_STARTED; } /* Make sure an L2cap link control block is available */ if (!p_lcb && (p_lcb = l2cu_allocate_lcb (p_dev_rec->bd_addr, TRUE, BT_TRANSPORT_BR_EDR)) == NULL) { - BTM_TRACE_WARNING ("Security Manager: failed allocate LCB [%02x%02x%02x%02x%02x%02x]", + BTM_TRACE_WARNING ("Security Manager: failed allocate LCB [%02x%02x%02x%02x%02x%02x]\n", p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); @@ -3046,7 +3046,7 @@ static tBTM_STATUS btm_sec_dd_create_conn (tBTM_SEC_DEV_REC *p_dev_rec) if (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == FALSE) { - BTM_TRACE_WARNING ("Security Manager: failed create [%02x%02x%02x%02x%02x%02x]", + BTM_TRACE_WARNING ("Security Manager: failed create [%02x%02x%02x%02x%02x%02x]\n", p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); @@ -3056,7 +3056,7 @@ static tBTM_STATUS btm_sec_dd_create_conn (tBTM_SEC_DEV_REC *p_dev_rec) btm_acl_update_busy_level (BTM_BLI_PAGE_EVT); - BTM_TRACE_DEBUG ("Security Manager: btm_sec_dd_create_conn [%02x%02x%02x%02x%02x%02x]", + BTM_TRACE_DEBUG ("Security Manager: btm_sec_dd_create_conn [%02x%02x%02x%02x%02x%02x]\n", p_dev_rec->bd_addr[0], p_dev_rec->bd_addr[1], p_dev_rec->bd_addr[2], p_dev_rec->bd_addr[3], p_dev_rec->bd_addr[4], p_dev_rec->bd_addr[5]); @@ -3082,7 +3082,7 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT DEV_CLASS dev_class; UINT8 old_sec_state; - BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete"); + BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete\n"); if (((p_bd_addr == NULL) && !BTM_ACL_IS_CONNECTED(btm_cb.connecting_bda)) || ((p_bd_addr != NULL) && !BTM_ACL_IS_CONNECTED(p_bd_addr))) { @@ -3120,13 +3120,13 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT if (p_dev_rec) { - BTM_TRACE_EVENT ("Security Manager: rmt_name_complete PairState: %s RemName: %s status: %d State:%d p_dev_rec: 0x%08x ", + BTM_TRACE_EVENT ("Security Manager: rmt_name_complete PairState: %s RemName: %s status: %d State:%d p_dev_rec: 0x%08x \n", btm_pair_state_descr (btm_cb.pairing_state), p_bd_name, status, p_dev_rec->sec_state, p_dev_rec); } else { - BTM_TRACE_EVENT ("Security Manager: rmt_name_complete PairState: %s RemName: %s status: %d", + BTM_TRACE_EVENT ("Security Manager: rmt_name_complete PairState: %s RemName: %s status: %d\n", btm_pair_state_descr (btm_cb.pairing_state), p_bd_name, status); } @@ -3139,7 +3139,7 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT { BCM_STRNCPY_S ((char *)p_dev_rec->sec_bd_name, sizeof (p_dev_rec->sec_bd_name), (char *)p_bd_name, BTM_MAX_REM_BD_NAME_LEN); p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; - BTM_TRACE_EVENT ("setting BTM_SEC_NAME_KNOWN sec_flags:0x%x", p_dev_rec->sec_flags); + BTM_TRACE_EVENT ("setting BTM_SEC_NAME_KNOWN sec_flags:0x%x\n", p_dev_rec->sec_flags); } else { @@ -3178,13 +3178,13 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT if ( (btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_LOCAL_PIN) && p_bd_addr && (memcmp (btm_cb.pairing_bda, p_bd_addr, BD_ADDR_LEN) == 0) ) { - BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete() delayed pin now being requested flags:0x%x, (p_pin_callback=0x%p)", btm_cb.pairing_flags, btm_cb.api.p_pin_callback); + BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete() delayed pin now being requested flags:0x%x, (p_pin_callback=0x%p)\n", btm_cb.pairing_flags, btm_cb.api.p_pin_callback); if (((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) == 0) && ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PIN_REQD) == 0) && btm_cb.api.p_pin_callback) { - BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete() calling pin_callback"); + BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete() calling pin_callback\n"); btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; (*btm_cb.api.p_pin_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, p_bd_name, (p_dev_rec->p_cur_service==NULL) ? FALSE @@ -3201,7 +3201,7 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT { if (p_bd_addr && memcmp (btm_cb.pairing_bda, p_bd_addr, BD_ADDR_LEN) == 0) { - BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete() continue bonding sm4: 0x%04x, status:0x%x", p_dev_rec->sm4, status); + BTM_TRACE_EVENT ("btm_sec_rmt_name_request_complete() continue bonding sm4: 0x%04x, status:0x%x\n", p_dev_rec->sm4, status); if(btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_CANCEL_DD) { btm_sec_bond_cancel_complete(); @@ -3223,7 +3223,7 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT { /* set the KNOWN flag only if BTM_PAIR_FLAGS_REJECTED_CONNECT is not set.*/ /* If it is set, there may be a race condition */ - BTM_TRACE_DEBUG ("btm_sec_rmt_name_request_complete IS_SM4_UNKNOWN Flags:0x%04x", + BTM_TRACE_DEBUG ("btm_sec_rmt_name_request_complete IS_SM4_UNKNOWN Flags:0x%04x\n", btm_cb.pairing_flags); if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) == 0) { @@ -3231,7 +3231,7 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT } } - BTM_TRACE_DEBUG("%s, SM4 Value: %x, Legacy:%d,IS SM4:%d, Unknown:%d",__FUNCTION__, + BTM_TRACE_DEBUG("%s, SM4 Value: %x, Legacy:%d,IS SM4:%d, Unknown:%d\n",__FUNCTION__, p_dev_rec->sm4, BTM_SEC_IS_SM4_LEGACY(p_dev_rec->sm4), BTM_SEC_IS_SM4(p_dev_rec->sm4),BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)); @@ -3244,12 +3244,12 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT /* before originating */ if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT) { - BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete: waiting HCI_Connection_Complete after rejecting connection"); + BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete: waiting HCI_Connection_Complete after rejecting connection\n"); } /* Both we and the peer are 2.1 - continue to create connection */ else if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) { - BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete: failed to start connection"); + BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete: failed to start connection\n"); btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); @@ -3262,7 +3262,7 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT } else { - BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete: wrong BDA, retry with pairing BDA"); + BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete: wrong BDA, retry with pairing BDA\n"); BTM_ReadRemoteDeviceName (btm_cb.pairing_bda, NULL, BT_TRANSPORT_BR_EDR); return; @@ -3296,7 +3296,7 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT if ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) && (p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) { - BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete (none/ce)"); + BTM_TRACE_WARNING ("btm_sec_rmt_name_request_complete (none/ce)\n"); p_dev_rec->security_required &= ~(BTM_SEC_OUT_AUTHENTICATE); l2cu_start_post_bond_timer(p_dev_rec->hci_handle); return; @@ -3314,7 +3314,7 @@ void btm_sec_rmt_name_request_complete (UINT8 *p_bd_addr, UINT8 *p_bd_name, UINT if (p_dev_rec->sm4 & BTM_SM4_REQ_PEND) { - BTM_TRACE_EVENT ("waiting for remote features!!"); + BTM_TRACE_EVENT ("waiting for remote features!!\n"); return; } @@ -3348,7 +3348,7 @@ void btm_sec_rmt_host_support_feat_evt (UINT8 *p) STREAM_TO_BDADDR (bd_addr, p); p_dev_rec = btm_find_or_alloc_dev (bd_addr); - BTM_TRACE_EVENT ("btm_sec_rmt_host_support_feat_evt sm4: 0x%x p[0]: 0x%x", p_dev_rec->sm4, p[0]); + BTM_TRACE_EVENT ("btm_sec_rmt_host_support_feat_evt sm4: 0x%x p[0]: 0x%x\n", p_dev_rec->sm4, p[0]); if (BTM_SEC_IS_SM4_UNKNOWN(p_dev_rec->sm4)) { @@ -3358,7 +3358,7 @@ void btm_sec_rmt_host_support_feat_evt (UINT8 *p) { p_dev_rec->sm4 = BTM_SM4_TRUE; } - BTM_TRACE_EVENT ("btm_sec_rmt_host_support_feat_evt sm4: 0x%x features[0]: 0x%x", p_dev_rec->sm4, features[0]); + BTM_TRACE_EVENT ("btm_sec_rmt_host_support_feat_evt sm4: 0x%x features[0]: 0x%x\n", p_dev_rec->sm4, features[0]); } } @@ -3390,17 +3390,17 @@ void btm_io_capabilities_req (UINT8 *p) evt_data.oob_data = BTM_OOB_NONE; evt_data.auth_req = BTM_DEFAULT_AUTH_REQ; - BTM_TRACE_EVENT("%s: State: %s", __FUNCTION__, btm_pair_state_descr(btm_cb.pairing_state)); + BTM_TRACE_EVENT("%s: State: %s\n", __FUNCTION__, btm_pair_state_descr(btm_cb.pairing_state)); p_dev_rec = btm_find_or_alloc_dev (evt_data.bd_addr); - BTM_TRACE_DEBUG("%s:Security mode: %d, Num Read Remote Feat pages: %d", __FUNCTION__, + BTM_TRACE_DEBUG("%s:Security mode: %d, Num Read Remote Feat pages: %d\n", __FUNCTION__, btm_cb.security_mode, p_dev_rec->num_read_pages); if ((btm_cb.security_mode == BTM_SEC_MODE_SC) && (p_dev_rec->num_read_pages == 0)) { - BTM_TRACE_EVENT("%s: Device security mode is SC only.", - "To continue need to know remote features.", __FUNCTION__); + BTM_TRACE_EVENT("%s: Device security mode is SC only.\n", + "To continue need to know remote features.\n", __FUNCTION__); p_dev_rec->remote_features_needed = TRUE; return; @@ -3408,13 +3408,13 @@ void btm_io_capabilities_req (UINT8 *p) p_dev_rec->sm4 |= BTM_SM4_TRUE; - BTM_TRACE_EVENT("%s: State: %s Flags: 0x%04x p_cur_service: 0x%08x", + BTM_TRACE_EVENT("%s: State: %s Flags: 0x%04x p_cur_service: 0x%08x\n", __FUNCTION__, btm_pair_state_descr(btm_cb.pairing_state), btm_cb.pairing_flags, p_dev_rec->p_cur_service); if (p_dev_rec->p_cur_service) { - BTM_TRACE_EVENT("%s: cur_service psm: 0x%04x, security_flags: 0x%04x", + BTM_TRACE_EVENT("%s: cur_service psm: 0x%04x, security_flags: 0x%04x\n", __FUNCTION__, p_dev_rec->p_cur_service->psm, p_dev_rec->p_cur_service->security_flags); } @@ -3454,7 +3454,7 @@ void btm_io_capabilities_req (UINT8 *p) /* any other state is unexpected */ default: err_code = HCI_ERR_HOST_BUSY_PAIRING; - BTM_TRACE_ERROR("%s: Unexpected Pairing state received %d", __FUNCTION__, + BTM_TRACE_ERROR("%s: Unexpected Pairing state received %d\n", __FUNCTION__, btm_cb.pairing_state); break; } @@ -3462,7 +3462,7 @@ void btm_io_capabilities_req (UINT8 *p) if (btm_cb.pairing_disabled) { /* pairing is not allowed */ - BTM_TRACE_DEBUG("%s: Pairing is not allowed -> fail pairing.", __FUNCTION__); + BTM_TRACE_DEBUG("%s: Pairing is not allowed -> fail pairing.\n", __FUNCTION__); err_code = HCI_ERR_PAIRING_NOT_ALLOWED; } else if (btm_cb.security_mode == BTM_SEC_MODE_SC) @@ -3471,8 +3471,8 @@ void btm_io_capabilities_req (UINT8 *p) /* device in Secure Connections Only mode */ if (!(local_supports_sc) || !(p_dev_rec->remote_supports_secure_connections)) { - BTM_TRACE_DEBUG("%s: SC only service, local_support_for_sc %d,", - " remote_support_for_sc 0x%02x -> fail pairing", __FUNCTION__, + BTM_TRACE_DEBUG("%s: SC only service, local_support_for_sc %d,\n", + " remote_support_for_sc 0x%02x -> fail pairing\n", __FUNCTION__, local_supports_sc, p_dev_rec->remote_supports_secure_connections); err_code = HCI_ERR_PAIRING_NOT_ALLOWED; @@ -3555,7 +3555,7 @@ False-positive: False-positive: evt_data.bd_addr is set at the beginning with: /* At this moment we know that both sides are SC capable, device in */ /* SC only mode requires MITM for any service so let's set MITM bit */ evt_data.auth_req |= BTM_AUTH_YN_BIT; - BTM_TRACE_DEBUG("%s: for device in \"SC only\" mode set auth_req to 0x%02x", + BTM_TRACE_DEBUG("%s: for device in \"SC only\" mode set auth_req to 0x%02x\n", __FUNCTION__, evt_data.auth_req); } @@ -3659,7 +3659,7 @@ void btm_proc_sp_req_evt (tBTM_SP_EVT event, UINT8 *p) /* All events start with bd_addr */ STREAM_TO_BDADDR (p_bda, p); - BTM_TRACE_EVENT ("btm_proc_sp_req_evt() BDA: %08x%04x event: 0x%x, State: %s", + BTM_TRACE_EVENT ("btm_proc_sp_req_evt() BDA: %08x%04x event: 0x%x, State: %s\n", (p_bda[0]<<24) + (p_bda[1]<<16) + (p_bda[2]<<8) + p_bda[3], (p_bda[4] << 8) + p_bda[5], event, btm_pair_state_descr(btm_cb.pairing_state)); @@ -3694,7 +3694,7 @@ void btm_proc_sp_req_evt (tBTM_SP_EVT event, UINT8 *p) evt_data.cfm_req.just_works = FALSE; } #endif - BTM_TRACE_DEBUG ("btm_proc_sp_req_evt() just_works:%d, io loc:%d, rmt:%d, auth loc:%d, rmt:%d", + BTM_TRACE_DEBUG ("btm_proc_sp_req_evt() just_works:%d, io loc:%d, rmt:%d, auth loc:%d, rmt:%d\n", evt_data.cfm_req.just_works, btm_cb.devcb.loc_io_caps, p_dev_rec->rmt_io_caps, btm_cb.devcb.loc_auth_req, p_dev_rec->rmt_auth_req); @@ -3708,7 +3708,7 @@ void btm_proc_sp_req_evt (tBTM_SP_EVT event, UINT8 *p) /* Passkey notification (other side is a keyboard) */ STREAM_TO_UINT32 (evt_data.key_notif.passkey, p); - BTM_TRACE_DEBUG ("BTM_SP_KEY_NOTIF_EVT: passkey: %u", evt_data.key_notif.passkey); + BTM_TRACE_DEBUG ("BTM_SP_KEY_NOTIF_EVT: passkey: %u\n", evt_data.key_notif.passkey); btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); break; @@ -3738,7 +3738,7 @@ void btm_proc_sp_req_evt (tBTM_SP_EVT event, UINT8 *p) if (event == BTM_SP_CFM_REQ_EVT) { - BTM_TRACE_DEBUG ("calling BTM_ConfirmReqReply with status: %d", status); + BTM_TRACE_DEBUG ("calling BTM_ConfirmReqReply with status: %d\n", status); BTM_ConfirmReqReply (status, p_bda); } #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) @@ -3827,13 +3827,13 @@ void btm_simple_pair_complete (UINT8 *p) if ((p_dev_rec = btm_find_dev (evt_data.bd_addr)) == NULL) { - BTM_TRACE_ERROR ("btm_simple_pair_complete() with unknown BDA: %08x%04x", + BTM_TRACE_ERROR ("btm_simple_pair_complete() with unknown BDA: %08x%04x\n", (evt_data.bd_addr[0]<<24) + (evt_data.bd_addr[1]<<16) + (evt_data.bd_addr[2]<<8) + evt_data.bd_addr[3], (evt_data.bd_addr[4] << 8) + evt_data.bd_addr[5]); return; } - BTM_TRACE_EVENT ("btm_simple_pair_complete() Pair State: %s Status:%d sec_state: %u", + BTM_TRACE_EVENT ("btm_simple_pair_complete() Pair State: %s Status:%d sec_state: %u\n", btm_pair_state_descr(btm_cb.pairing_state), status, p_dev_rec->sec_state); evt_data.status = BTM_ERR_PROCESSING; @@ -3908,7 +3908,7 @@ void btm_rem_oob_req (UINT8 *p) STREAM_TO_BDADDR (p_bda, p); - BTM_TRACE_EVENT ("btm_rem_oob_req() BDA: %02x:%02x:%02x:%02x:%02x:%02x", + BTM_TRACE_EVENT ("btm_rem_oob_req() BDA: %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]); if ( (NULL != (p_dev_rec = btm_find_dev (p_bda))) && @@ -3947,7 +3947,7 @@ void btm_read_local_oob_complete (UINT8 *p) tBTM_SP_LOC_OOB evt_data; UINT8 status = *p++; - BTM_TRACE_EVENT ("btm_read_local_oob_complete:%d", status); + BTM_TRACE_EVENT ("btm_read_local_oob_complete:%d\n", status); if (status == HCI_SUCCESS) { evt_data.status = BTM_SUCCESS; @@ -3991,7 +3991,7 @@ static void btm_sec_auth_collision (UINT16 handle) if (p_dev_rec != NULL) { - BTM_TRACE_DEBUG ("btm_sec_auth_collision: state %d (retrying in a moment...)", p_dev_rec->sec_state); + BTM_TRACE_DEBUG ("btm_sec_auth_collision: state %d (retrying in a moment...)\n", p_dev_rec->sec_state); /* We will restart authentication after timeout */ if (p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING || p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING) p_dev_rec->sec_state = 0; @@ -4025,7 +4025,7 @@ void btm_sec_auth_complete (UINT16 handle, UINT8 status) #if (BT_USE_TRACES == TRUE) if (p_dev_rec) { - BTM_TRACE_EVENT ("Security Manager: auth_complete PairState: %s handle:%u status:%d dev->sec_state: %u Bda:%08x, RName:%s", + BTM_TRACE_EVENT ("Security Manager: auth_complete PairState: %s handle:%u status:%d dev->sec_state: %u Bda:%08x, RName:%s\n", btm_pair_state_descr (btm_cb.pairing_state), handle, status, p_dev_rec->sec_state, @@ -4034,7 +4034,7 @@ void btm_sec_auth_complete (UINT16 handle, UINT8 status) } else { - BTM_TRACE_EVENT ("Security Manager: auth_complete PairState: %s handle:%u status:%d", + BTM_TRACE_EVENT ("Security Manager: auth_complete PairState: %s handle:%u status:%d\n", btm_pair_state_descr (btm_cb.pairing_state), handle, status); } @@ -4128,7 +4128,7 @@ void btm_sec_auth_complete (UINT16 handle, UINT8 status) } else { - BTM_TRACE_DEBUG ("TRYING TO DECIDE IF CAN USE SMP_BR_CHNL"); + BTM_TRACE_DEBUG ("TRYING TO DECIDE IF CAN USE SMP_BR_CHNL\n"); if (p_dev_rec->new_encryption_key_is_p256 && (btm_sec_use_smp_br_chnl(p_dev_rec)) /* no LE keys are available, do deriving */ && (!(p_dev_rec->sec_flags &BTM_SEC_LE_LINK_KEY_KNOWN) || @@ -4136,7 +4136,7 @@ void btm_sec_auth_complete (UINT16 handle, UINT8 status) (!(p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)))) { - BTM_TRACE_DEBUG ("link encrypted afer dedic bonding can use SMP_BR_CHNL"); + BTM_TRACE_DEBUG ("link encrypted afer dedic bonding can use SMP_BR_CHNL\n"); if (btm_sec_is_master(p_dev_rec)) { @@ -4161,7 +4161,7 @@ void btm_sec_auth_complete (UINT16 handle, UINT8 status) { /* not retried yet. set the retry bit */ p_dev_rec->sm4 |= BTM_SM4_RETRY; - BTM_TRACE_DEBUG ("Collision retry sm4:x%x sec_flags:0x%x", p_dev_rec->sm4, p_dev_rec->sec_flags); + BTM_TRACE_DEBUG ("Collision retry sm4:x%x sec_flags:0x%x\n", p_dev_rec->sm4, p_dev_rec->sec_flags); } /* this retry for missing key is for Lisbon or later only. * Legacy device do not need this. the controller will drive the retry automatically */ @@ -4170,7 +4170,7 @@ void btm_sec_auth_complete (UINT16 handle, UINT8 status) /* not retried yet. set the retry bit */ p_dev_rec->sm4 |= BTM_SM4_RETRY; p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_KNOWN; - BTM_TRACE_DEBUG ("Retry for missing key sm4:x%x sec_flags:0x%x", p_dev_rec->sm4, p_dev_rec->sec_flags); + BTM_TRACE_DEBUG ("Retry for missing key sm4:x%x sec_flags:0x%x\n", p_dev_rec->sm4, p_dev_rec->sec_flags); /* With BRCM controller, we do not need to delete the stored link key in controller. If the stack may sit on top of other controller, we may need this @@ -4228,9 +4228,9 @@ void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable) tACL_CONN *p_acl = NULL; UINT8 acl_idx = btm_handle_to_acl_index(handle); #endif - BTM_TRACE_EVENT ("Security Manager: encrypt_change status:%d State:%d, encr_enable = %d", + BTM_TRACE_EVENT ("Security Manager: encrypt_change status:%d State:%d, encr_enable = %d\n", status, (p_dev_rec) ? p_dev_rec->sec_state : 0, encr_enable); - BTM_TRACE_DEBUG ("before update p_dev_rec->sec_flags=0x%x", (p_dev_rec) ? p_dev_rec->sec_flags : 0 ); + BTM_TRACE_DEBUG ("before update p_dev_rec->sec_flags=0x%x\n", (p_dev_rec) ? p_dev_rec->sec_flags : 0 ); /* For transaction collision we need to wait and repeat. There is no need */ /* for random timeout because only slave should receive the result */ @@ -4271,7 +4271,7 @@ void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable) p_dev_rec->sec_flags &= ~BTM_SEC_LE_ENCRYPTED; } - 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 ); #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE if (acl_idx != MAX_L2CAP_LINKS) @@ -4297,7 +4297,7 @@ void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable) p_dev_rec->enc_key_size = 16; } - BTM_TRACE_DEBUG ("in %s new_encr_key_256 is %d", + BTM_TRACE_DEBUG ("in %s new_encr_key_256 is %d\n", __func__, p_dev_rec->new_encryption_key_is_p256); if ((status == HCI_SUCCESS) && encr_enable && (p_dev_rec->hci_handle == handle)) @@ -4317,11 +4317,11 @@ void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable) if (p_dev_rec->no_smp_on_br) { - BTM_TRACE_DEBUG ("%s NO SM over BR/EDR", __func__); + BTM_TRACE_DEBUG ("%s NO SM over BR/EDR\n", __func__); } else { - BTM_TRACE_DEBUG ("%s start SM over BR/EDR", __func__); + BTM_TRACE_DEBUG ("%s start SM over BR/EDR\n", __func__); SMP_BR_PairWith(p_dev_rec->bd_addr); } } @@ -4340,7 +4340,7 @@ void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable) else /* BTM_LKEY_TYPE_AUTH_COMB_P_256 */ p_dev_rec->link_key_type = BTM_LKEY_TYPE_AUTH_COMB; - BTM_TRACE_DEBUG("updated link key type to %d", p_dev_rec->link_key_type); + BTM_TRACE_DEBUG("updated link key type to %d\n", p_dev_rec->link_key_type); btm_send_link_key_notif(p_dev_rec); } } @@ -4391,13 +4391,13 @@ static void btm_sec_connect_after_reject_timeout (TIMER_LIST_ENT *p_tle) tBTM_SEC_DEV_REC *p_dev_rec = btm_cb.p_collided_dev_rec; UNUSED(p_tle); - BTM_TRACE_EVENT ("btm_sec_connect_after_reject_timeout()"); + BTM_TRACE_EVENT ("btm_sec_connect_after_reject_timeout()\n"); btm_cb.sec_collision_tle.param = 0; btm_cb.p_collided_dev_rec = 0; if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED) { - BTM_TRACE_WARNING ("Security Manager: btm_sec_connect_after_reject_timeout: failed to start connection"); + BTM_TRACE_WARNING ("Security Manager: btm_sec_connect_after_reject_timeout: failed to start connection\n"); btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); @@ -4432,14 +4432,14 @@ void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode) #if (BT_USE_TRACES == TRUE) if (p_dev_rec) { - BTM_TRACE_EVENT ("Security Manager: btm_sec_connected in state: %s handle:%d status:%d enc_mode:%d bda:%x RName:%s", + BTM_TRACE_EVENT ("Security Manager: btm_sec_connected in state: %s handle:%d status:%d enc_mode:%d bda:%x RName:%s\n", btm_pair_state_descr(btm_cb.pairing_state), handle, status, enc_mode, (bda[2]<<24)+(bda[3]<<16)+(bda[4]<<8)+bda[5], p_dev_rec->sec_bd_name); } else { - BTM_TRACE_EVENT ("Security Manager: btm_sec_connected in state: %s handle:%d status:%d enc_mode:%d bda:%x ", + BTM_TRACE_EVENT ("Security Manager: btm_sec_connected in state: %s handle:%d status:%d enc_mode:%d bda:%x \n", btm_pair_state_descr(btm_cb.pairing_state), handle, status, enc_mode, (bda[2]<<24)+(bda[3]<<16)+(bda[4]<<8)+bda[5]); } @@ -4485,7 +4485,7 @@ void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode) /* Motorola S9 disconnects without asking pin code */ if ((status != HCI_SUCCESS)&&(btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ)) { - BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: incoming connection failed without asking PIN"); + BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: incoming connection failed without asking PIN\n"); p_dev_rec->sm4 &= ~BTM_SM4_CONN_PEND; if (p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) @@ -4533,7 +4533,7 @@ void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode) if ((status == HCI_ERR_HOST_REJECT_DEVICE) &&(btm_cb.pairing_flags & BTM_PAIR_FLAGS_REJECTED_CONNECT)) { - BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: HCI_Conn_Comp Flags:0x%04x, sm4: 0x%x", + BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: HCI_Conn_Comp Flags:0x%04x, sm4: 0x%x\n", btm_cb.pairing_flags, p_dev_rec->sm4); btm_cb.pairing_flags &= ~BTM_PAIR_FLAGS_REJECTED_CONNECT; @@ -4560,7 +4560,7 @@ void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode) /* wait for incoming connection without resetting pairing state */ else if (status == HCI_ERR_CONNECTION_EXISTS) { - BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: Wait for incoming connection"); + BTM_TRACE_WARNING ("Security Manager: btm_sec_connected: Wait for incoming connection\n"); return; } @@ -4578,7 +4578,7 @@ void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode) { p_dev_rec->security_required &= ~BTM_SEC_OUT_AUTHENTICATE; p_dev_rec->sec_flags &= ~((BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED) << bit_shift); - BTM_TRACE_DEBUG ("security_required:%x ", p_dev_rec->security_required ); + BTM_TRACE_DEBUG ("security_required:%x \n", p_dev_rec->security_required ); btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); @@ -4715,7 +4715,7 @@ void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode) /* After connection is established we perform security if we do not know */ /* the name, or if we are originator because some procedure can have */ /* been scheduled while connection was down */ - BTM_TRACE_DEBUG ("is_originator:%d ", p_dev_rec->is_originator); + BTM_TRACE_DEBUG ("is_originator:%d \n", p_dev_rec->is_originator); if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) || p_dev_rec->is_originator) { if ((res = btm_sec_execute_procedure (p_dev_rec)) != BTM_CMD_STARTED) @@ -4788,7 +4788,7 @@ void btm_sec_disconnected (UINT16 handle, UINT8 reason) p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ #if BTM_DISC_DURING_RS == TRUE - LOG_INFO("%s clearing pending flag handle:%d reason:%d", __func__, handle, reason); + LOG_INFO("%s clearing pending flag handle:%d reason:%d\n", __func__, handle, reason); p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ #endif @@ -4797,10 +4797,10 @@ void btm_sec_disconnected (UINT16 handle, UINT8 reason) uint8_t *bd_addr = (uint8_t *)p_dev_rec->bd_addr; BTM_TRACE_EVENT("%s sec_req:x%x state:%s reason:%d bd_addr:%02x:%02x:%02x:%02x:%02x:%02x" - " remote_name:%s", __func__, p_dev_rec->security_required, btm_pair_state_descr(btm_cb.pairing_state), + " remote_name:%s\n", __func__, p_dev_rec->security_required, btm_pair_state_descr(btm_cb.pairing_state), reason, bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5], p_dev_rec->sec_bd_name); - BTM_TRACE_EVENT("%s before update sec_flags=0x%x", __func__, p_dev_rec->sec_flags); + BTM_TRACE_EVENT("%s before update sec_flags=0x%x\n", __func__, p_dev_rec->sec_flags); /* If we are in the process of bonding we need to tell client that auth failed */ if ( (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) @@ -4866,7 +4866,7 @@ void btm_sec_disconnected (UINT16 handle, UINT8 reason) (*p_callback) (p_dev_rec->bd_addr, transport, p_dev_rec->p_ref_data, BTM_ERR_PROCESSING); } - BTM_TRACE_EVENT("%s after update sec_flags=0x%x", __func__, p_dev_rec->sec_flags); + BTM_TRACE_EVENT("%s after update sec_flags=0x%x\n", __func__, p_dev_rec->sec_flags); } /******************************************************************************* @@ -4885,7 +4885,7 @@ void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_t BOOLEAN we_are_bonding = FALSE; BOOLEAN ltk_derived_lk = FALSE; - BTM_TRACE_EVENT ("btm_sec_link_key_notification() BDA:%04x%08x, TYPE: %d", + BTM_TRACE_EVENT ("btm_sec_link_key_notification() BDA:%04x%08x, TYPE: %d\n", (p_bda[0]<<8)+p_bda[1], (p_bda[2]<<24)+(p_bda[3]<<16)+(p_bda[4]<<8)+p_bda[5], key_type); @@ -4933,7 +4933,7 @@ void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_t { if (btm_cb.api.p_link_key_callback) { - BTM_TRACE_DEBUG ("%s() Save LTK derived LK (key_type = %d)", + BTM_TRACE_DEBUG ("%s() Save LTK derived LK (key_type = %d)\n", __FUNCTION__, p_dev_rec->link_key_type); (*btm_cb.api.p_link_key_callback) (p_bda, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, @@ -4946,7 +4946,7 @@ void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_t (p_dev_rec->link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256)) { p_dev_rec->new_encryption_key_is_p256 = TRUE; - BTM_TRACE_DEBUG ("%s set new_encr_key_256 to %d", + BTM_TRACE_DEBUG ("%s set new_encr_key_256 to %d\n", __func__, p_dev_rec->new_encryption_key_is_p256); } } @@ -4957,7 +4957,7 @@ void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_t && ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) != BTM_COD_MAJOR_PERIPHERAL)) && !ltk_derived_lk) { - BTM_TRACE_EVENT ("btm_sec_link_key_notification() Delayed BDA: %08x%04x Type:%d", + BTM_TRACE_EVENT ("btm_sec_link_key_notification() Delayed BDA: %08x%04x Type:%d\n", (p_bda[0]<<24) + (p_bda[1]<<16) + (p_bda[2]<<8) + p_bda[3], (p_bda[4] << 8) + p_bda[5], key_type); @@ -4970,7 +4970,7 @@ void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_t btm_inq_rmt_name_failed(); } - BTM_TRACE_EVENT ("rmt_io_caps:%d, sec_flags:x%x, dev_class[1]:x%02x", p_dev_rec->rmt_io_caps, p_dev_rec->sec_flags, p_dev_rec->dev_class[1]) + BTM_TRACE_EVENT ("rmt_io_caps:%d, sec_flags:x%x, dev_class[1]:x%02x\n", p_dev_rec->rmt_io_caps, p_dev_rec->sec_flags, p_dev_rec->dev_class[1]) return; } @@ -4996,7 +4996,7 @@ void btm_sec_link_key_notification (UINT8 *p_bda, UINT8 *p_link_key, UINT8 key_t if (ltk_derived_lk) { BTM_TRACE_DEBUG ("btm_sec_link_key_notification() LTK derived LK is saved already" - " (key_type = %d)", p_dev_rec->link_key_type); + " (key_type = %d)\n", p_dev_rec->link_key_type); } else { @@ -5021,7 +5021,7 @@ void btm_sec_link_key_request (UINT8 *p_bda) { tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_bda); - BTM_TRACE_EVENT ("btm_sec_link_key_request() BDA: %02x:%02x:%02x:%02x:%02x:%02x", + BTM_TRACE_EVENT ("btm_sec_link_key_request() BDA: %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]); if( (btm_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ) && @@ -5029,7 +5029,7 @@ void btm_sec_link_key_request (UINT8 *p_bda) (memcmp (btm_cb.p_collided_dev_rec->bd_addr, p_bda, BD_ADDR_LEN) == 0) ) { BTM_TRACE_EVENT ("btm_sec_link_key_request() rejecting link key req " - "State: %d START_TIMEOUT : %d", + "State: %d START_TIMEOUT : %d\n", btm_cb.pairing_state, btm_cb.collision_start_time); btsnd_hcic_link_key_neg_reply (p_bda); return; @@ -5077,7 +5077,7 @@ static void btm_sec_pairing_timeout (TIMER_LIST_ENT *p_tle) */ p_dev_rec = btm_find_dev (p_cb->pairing_bda); - BTM_TRACE_EVENT ("btm_sec_pairing_timeout() State: %s Flags: %u", + BTM_TRACE_EVENT ("btm_sec_pairing_timeout() State: %s Flags: %u\n", btm_pair_state_descr(p_cb->pairing_state), p_cb->pairing_flags); switch (p_cb->pairing_state) @@ -5140,7 +5140,7 @@ static void btm_sec_pairing_timeout (TIMER_LIST_ENT *p_tle) * now it's time to tear down the ACL link*/ if (p_dev_rec == NULL) { - BTM_TRACE_ERROR ("btm_sec_pairing_timeout() BTM_PAIR_STATE_WAIT_DISCONNECT unknown BDA: %08x%04x", + BTM_TRACE_ERROR ("btm_sec_pairing_timeout() BTM_PAIR_STATE_WAIT_DISCONNECT unknown BDA: %08x%04x\n", (p_cb->pairing_bda[0]<<24) + (p_cb->pairing_bda[1]<<16) + (p_cb->pairing_bda[2]<<8) + p_cb->pairing_bda[3], (p_cb->pairing_bda[4] << 8) + p_cb->pairing_bda[5]); break; @@ -5170,7 +5170,7 @@ static void btm_sec_pairing_timeout (TIMER_LIST_ENT *p_tle) break; default: - BTM_TRACE_WARNING ("btm_sec_pairing_timeout() not processed state: %s", btm_pair_state_descr(btm_cb.pairing_state)); + BTM_TRACE_WARNING ("btm_sec_pairing_timeout() not processed state: %s\n", btm_pair_state_descr(btm_cb.pairing_state)); btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE); break; } @@ -5194,7 +5194,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda) UINT8 default_pin_code_len = 4; PIN_CODE default_pin_code = {0x30, 0x30, 0x30, 0x30}; #endif - BTM_TRACE_EVENT ("btm_sec_pin_code_request() State: %s, BDA:%04x%08x", + BTM_TRACE_EVENT ("btm_sec_pin_code_request() State: %s, BDA:%04x%08x\n", btm_pair_state_descr(btm_cb.pairing_state), (p_bda[0]<<8)+p_bda[1], (p_bda[2]<<24)+(p_bda[3]<<16)+(p_bda[4]<<8)+p_bda[5] ); @@ -5219,12 +5219,12 @@ void btm_sec_pin_code_request (UINT8 *p_bda) else if ((btm_cb.pairing_state != BTM_PAIR_STATE_WAIT_PIN_REQ) || memcmp (p_bda, btm_cb.pairing_bda, BD_ADDR_LEN) != 0) { - BTM_TRACE_WARNING ("btm_sec_pin_code_request() rejected - state: %s", + BTM_TRACE_WARNING ("btm_sec_pin_code_request() rejected - state: %s\n", btm_pair_state_descr(btm_cb.pairing_state)); #ifdef PORCHE_PAIRING_CONFLICT /* reply pin code again due to counter in_rand when local initiates pairing */ - BTM_TRACE_EVENT ("btm_sec_pin_code_request from remote dev. for local initiated pairing"); + BTM_TRACE_EVENT ("btm_sec_pin_code_request from remote dev. for local initiated pairing\n"); if(! btm_cb.pin_code_len_saved) { btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); @@ -5257,7 +5257,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda) if (!p_cb->pairing_disabled && (p_cb->cfg.pin_type == HCI_PIN_TYPE_FIXED)) { - BTM_TRACE_EVENT ("btm_sec_pin_code_request fixed pin replying"); + BTM_TRACE_EVENT ("btm_sec_pin_code_request fixed pin replying\n"); btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); btsnd_hcic_pin_code_req_reply (p_bda, p_cb->cfg.pin_code_len, p_cb->cfg.pin_code); return; @@ -5271,7 +5271,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda) /* We could have started connection after asking user for the PIN code */ if (btm_cb.pin_code_len != 0) { - BTM_TRACE_EVENT ("btm_sec_pin_code_request bonding sending reply"); + BTM_TRACE_EVENT ("btm_sec_pin_code_request bonding sending reply\n"); btsnd_hcic_pin_code_req_reply (p_bda, btm_cb.pin_code_len, p_cb->pin_code); #ifdef PORCHE_PAIRING_CONFLICT @@ -5300,7 +5300,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda) && ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) == BTM_COD_MAJOR_PERIPHERAL) && (p_dev_rec->dev_class[2] & BTM_COD_MINOR_KEYBOARD)) ) { - BTM_TRACE_WARNING("btm_sec_pin_code_request(): Pairing disabled:%d; PIN callback:%x, Dev Rec:%x!", + BTM_TRACE_WARNING("btm_sec_pin_code_request(): Pairing disabled:%d; PIN callback:%x, Dev Rec:%x!\n", p_cb->pairing_disabled, p_cb->api.p_pin_callback, p_dev_rec); btsnd_hcic_pin_code_neg_reply (p_bda); @@ -5321,7 +5321,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda) /* Also cannot send remote name request while paging, i.e. connection is not completed */ if (p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) { - BTM_TRACE_EVENT ("btm_sec_pin_code_request going for callback"); + BTM_TRACE_EVENT ("btm_sec_pin_code_request going for callback\n"); btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; if (p_cb->api.p_pin_callback) { @@ -5333,7 +5333,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda) } else { - BTM_TRACE_EVENT ("btm_sec_pin_code_request going for remote name"); + BTM_TRACE_EVENT ("btm_sec_pin_code_request going for remote name\n"); /* We received PIN code request for the device with unknown name */ /* it is not user friendly just to ask for the PIN without name */ @@ -5345,7 +5345,7 @@ void btm_sec_pin_code_request (UINT8 *p_bda) p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; p_dev_rec->sec_bd_name[0] = 'f'; p_dev_rec->sec_bd_name[1] = '0'; - BTM_TRACE_ERROR ("can not send rmt_name_req?? fake a name and call callback"); + BTM_TRACE_ERROR ("can not send rmt_name_req?? fake a name and call callback\n"); btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; if (p_cb->api.p_pin_callback) @@ -5407,7 +5407,7 @@ void btm_sec_update_clock_offset (UINT16 handle, UINT16 clock_offset) *******************************************************************************/ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) { - BTM_TRACE_EVENT ("btm_sec_execute_procedure: Required:0x%x Flags:0x%x State:%d", + BTM_TRACE_EVENT ("btm_sec_execute_procedure: Required:0x%x Flags:0x%x State:%d\n", p_dev_rec->security_required, p_dev_rec->sec_flags, p_dev_rec->sec_state); /* There is a chance that we are getting name. Wait until done. */ @@ -5418,7 +5418,7 @@ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) && (p_dev_rec->hci_handle != BTM_SEC_INVALID_HANDLE)) { - BTM_TRACE_EVENT ("Security Manager: Start get name"); + BTM_TRACE_EVENT ("Security Manager: Start get name\n"); if (!btm_sec_start_get_name (p_dev_rec)) { return(BTM_NO_RESOURCES); @@ -5449,7 +5449,7 @@ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) return(BTM_FAILED_ON_SECURITY); #endif - BTM_TRACE_EVENT ("Security Manager: Start authentication"); + BTM_TRACE_EVENT ("Security Manager: Start authentication\n"); /* * If we do have a link-key, but we end up here because we need an @@ -5490,7 +5490,7 @@ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) return(BTM_FAILED_ON_SECURITY); #endif - BTM_TRACE_EVENT ("Security Manager: Start encryption"); + BTM_TRACE_EVENT ("Security Manager: Start encryption\n"); if (!btm_sec_start_encryption (p_dev_rec)) { @@ -5503,7 +5503,7 @@ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) (p_dev_rec->link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256)) { BTM_TRACE_EVENT("%s: Security Manager: SC only service, but link key type is 0x%02x -", - "security failure", __FUNCTION__, p_dev_rec->link_key_type); + "security failure\n", __FUNCTION__, p_dev_rec->link_key_type); return (BTM_FAILED_ON_SECURITY); } @@ -5513,7 +5513,7 @@ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) && (( p_dev_rec->is_originator && (p_dev_rec->security_required & BTM_SEC_OUT_AUTHORIZE)) || (!p_dev_rec->is_originator && (p_dev_rec->security_required & BTM_SEC_IN_AUTHORIZE)))) { - BTM_TRACE_EVENT ("service id:%d, is trusted:%d", + BTM_TRACE_EVENT ("service id:%d, is trusted:%d\n", p_dev_rec->p_cur_service->service_id, (BTM_SEC_IS_SERVICE_TRUSTED(p_dev_rec->trusted_mask, p_dev_rec->p_cur_service->service_id))); @@ -5522,7 +5522,7 @@ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) (BTM_SEC_IS_SERVICE_TRUSTED(p_dev_rec->trusted_mask, p_dev_rec->p_cur_service->service_id) == FALSE)) { - BTM_TRACE_EVENT ("Security Manager: Start authorization"); + BTM_TRACE_EVENT ("Security Manager: Start authorization\n"); return(btm_sec_start_authorization (p_dev_rec)); } } @@ -5534,8 +5534,8 @@ static tBTM_STATUS btm_sec_execute_procedure (tBTM_SEC_DEV_REC *p_dev_rec) BTM_SEC_FORCE_MASTER | BTM_SEC_ATTEMPT_MASTER | BTM_SEC_FORCE_SLAVE | BTM_SEC_ATTEMPT_SLAVE); - BTM_TRACE_EVENT ("Security Manager: trusted:0x%04x%04x", p_dev_rec->trusted_mask[1], p_dev_rec->trusted_mask[0]); - BTM_TRACE_EVENT ("Security Manager: access granted"); + BTM_TRACE_EVENT ("Security Manager: trusted:0x%04x%04x\n", p_dev_rec->trusted_mask[1], p_dev_rec->trusted_mask[0]); + BTM_TRACE_EVENT ("Security Manager: access granted\n"); return(BTM_SUCCESS); } @@ -5652,7 +5652,7 @@ static UINT8 btm_sec_start_authorization (tBTM_SEC_DEV_REC *p_dev_rec) else /* Already authorized once for this L2CAP bringup */ { - BTM_TRACE_DEBUG ("btm_sec_start_authorization: (Ignoring extra Authorization prompt for service %d)", service_id); + BTM_TRACE_DEBUG ("btm_sec_start_authorization: (Ignoring extra Authorization prompt for service %d)\n", service_id); return (BTM_SUCCESS); } @@ -5783,7 +5783,7 @@ static tBTM_SEC_SERV_REC *btm_sec_find_mx_serv (UINT8 is_originator, UINT16 psm, tBTM_SEC_SERV_REC *p_serv_rec = &btm_cb.sec_serv_rec[0]; int i; - BTM_TRACE_DEBUG ("%s()", __func__); + BTM_TRACE_DEBUG ("%s()\n", __func__); if (is_originator && p_out_serv && p_out_serv->psm == psm && p_out_serv->mx_proto_id == mx_proto_id && p_out_serv->orig_mx_chan_id == mx_chan_id) @@ -5823,7 +5823,7 @@ static void btm_sec_collision_timeout (TIMER_LIST_ENT *p_tle) { UNUSED(p_tle); - BTM_TRACE_EVENT ("%s()", __func__); + BTM_TRACE_EVENT ("%s()\n", __func__); btm_cb.sec_collision_tle.param = 0; tBTM_STATUS status = btm_sec_execute_procedure (btm_cb.p_collided_dev_rec); @@ -5889,7 +5889,7 @@ static void btm_restore_mode(void) if (btm_cb.security_mode_changed) { btm_cb.security_mode_changed = FALSE; - BTM_TRACE_DEBUG("%s() Auth enable -> %d", __func__, (btm_cb.security_mode == BTM_SEC_MODE_LINK)); + BTM_TRACE_DEBUG("%s() Auth enable -> %d\n", __func__, (btm_cb.security_mode == BTM_SEC_MODE_LINK)); btsnd_hcic_write_auth_enable ((UINT8)(btm_cb.security_mode == BTM_SEC_MODE_LINK)); } @@ -5935,8 +5935,8 @@ static void btm_sec_change_pairing_state (tBTM_PAIRING_STATE new_state) { tBTM_PAIRING_STATE old_state = btm_cb.pairing_state; - BTM_TRACE_EVENT ("%s() Old: %s", __func__, btm_pair_state_descr(btm_cb.pairing_state)); - BTM_TRACE_EVENT ("%s() New: %s pairing_flags:0x%x", __func__, + BTM_TRACE_EVENT ("%s() Old: %s\n", __func__, btm_pair_state_descr(btm_cb.pairing_state)); + BTM_TRACE_EVENT ("%s() New: %s pairing_flags:0x%x\n\n", __func__, btm_pair_state_descr(new_state), btm_cb.pairing_flags); btm_cb.pairing_state = new_state; @@ -5998,7 +5998,7 @@ static char *btm_pair_state_descr (tBTM_PAIRING_STATE state) return("???"); #else - sprintf(btm_cb.state_temp_buffer,"%hhu",state); + sprintf(btm_cb.state_temp_buffer,"%d",state); return(btm_cb.state_temp_buffer); #endif @@ -6059,7 +6059,7 @@ static BOOLEAN btm_sec_queue_mx_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN memcpy (p_e->bd_addr, bd_addr, BD_ADDR_LEN); - BTM_TRACE_EVENT ("%s() PSM: 0x%04x Is_Orig: %u mx_proto_id: %u mx_chan_id: %u", + BTM_TRACE_EVENT ("%s() PSM: 0x%04x Is_Orig: %u mx_proto_id: %u mx_chan_id: %u\n", __func__, psm, is_orig, mx_proto_id, mx_chan_id); GKI_enqueue (&btm_cb.sec_pending_q, p_e); @@ -6079,7 +6079,7 @@ static BOOLEAN btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec) if ((major == BTM_COD_MAJOR_AUDIO) && ((minor == BTM_COD_MINOR_CONFM_HANDSFREE) || (minor == BTM_COD_MINOR_CAR_AUDIO)) ) { - BTM_TRACE_EVENT ("%s() Skipping pre-fetch PIN for carkit COD Major: 0x%02x Minor: 0x%02x", + BTM_TRACE_EVENT ("%s() Skipping pre-fetch PIN for carkit COD Major: 0x%02x Minor: 0x%02x\n", __func__, major, minor); if (btm_cb.security_mode_changed == FALSE) @@ -6105,7 +6105,7 @@ static BOOLEAN btm_sec_check_prefetch_pin (tBTM_SEC_DEV_REC *p_dev_rec) /* pin was not supplied - pre-fetch pin code now */ if (btm_cb.api.p_pin_callback && ((btm_cb.pairing_flags & BTM_PAIR_FLAGS_PIN_REQD) == 0)) { - BTM_TRACE_DEBUG("%s() PIN code callback called", __func__); + BTM_TRACE_DEBUG("%s() PIN code callback called\n", __func__); if (btm_bda_to_acl(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR) == NULL) btm_cb.pairing_flags |= BTM_PAIR_FLAGS_PIN_REQD; (btm_cb.api.p_pin_callback) (p_dev_rec->bd_addr, p_dev_rec->dev_class, @@ -6140,7 +6140,7 @@ void btm_sec_auth_payload_tout (UINT8 *p, UINT16 hci_evt_len) handle = HCID_GET_HANDLE (handle); /* Will be exposed to upper layers in the future if/when determined necessary */ - BTM_TRACE_ERROR ("%s on handle 0x%02x", __func__, handle); + BTM_TRACE_ERROR ("%s on handle 0x%02x\n", __func__, handle); } /******************************************************************************* @@ -6202,13 +6202,13 @@ void btm_sec_set_peer_sec_caps(tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec) p_dev_rec->remote_supports_secure_connections = FALSE; } - BTM_TRACE_API("%s: sm4: 0x%02x, rmt_support_for_secure_connections %d", __FUNCTION__, + BTM_TRACE_API("%s: sm4: 0x%02x, rmt_support_for_secure_connections %d\n", __FUNCTION__, p_dev_rec->sm4, p_dev_rec->remote_supports_secure_connections); if (p_dev_rec->remote_features_needed) { - BTM_TRACE_EVENT("%s: Now device in SC Only mode, waiting for peer remote features!", + BTM_TRACE_EVENT("%s: Now device in SC Only mode, waiting for peer remote features!\n", __FUNCTION__); p_rem_bd_addr = (UINT8*) rem_bd_addr; BDADDR_TO_STREAM(p_rem_bd_addr, p_dev_rec->bd_addr); @@ -6264,7 +6264,7 @@ static BOOLEAN btm_sec_is_serv_level0(UINT16 psm) { if (psm == BT_PSM_SDP) { - BTM_TRACE_DEBUG("%s: PSM: 0x%04x -> mode 4 level 0 service", __FUNCTION__, psm); + BTM_TRACE_DEBUG("%s: PSM: 0x%04x -> mode 4 level 0 service\n", __FUNCTION__, psm); return TRUE; } return FALSE; @@ -6348,7 +6348,7 @@ static UINT16 btm_sec_set_serv_level4_flags(UINT16 cur_security, BOOLEAN is_orig void btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC *p_dev_rec) { - BTM_TRACE_DEBUG ("%s() Clearing BLE Keys", __func__); + BTM_TRACE_DEBUG ("%s() Clearing BLE Keys\n", __func__); #if (SMP_INCLUDED== TRUE) p_dev_rec->ble.key_type = BTM_LE_KEY_NONE; memset (&p_dev_rec->ble.keys, 0, sizeof(tBTM_SEC_BLE_KEYS)); @@ -6384,7 +6384,7 @@ BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda) { is_bonded = TRUE; } - BTM_TRACE_DEBUG ("%s() is_bonded=%d", __func__, is_bonded); + BTM_TRACE_DEBUG ("%s() is_bonded=%d\n", __func__, is_bonded); return(is_bonded); } @@ -6427,7 +6427,7 @@ BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_D int i; if (start_idx >= BTM_SEC_MAX_DEVICE_RECORDS) { - BTM_TRACE_DEBUG ("LE bonded device not found"); + BTM_TRACE_DEBUG ("LE bonded device not found\n"); return found; } @@ -6441,7 +6441,7 @@ BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_D break; } } - BTM_TRACE_DEBUG ("%s() found=%d", __func__, found); + BTM_TRACE_DEBUG ("%s() found=%d\n", __func__, found); #endif return(found); } @@ -6465,7 +6465,7 @@ static BOOLEAN btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC *p_dev_rec) UINT32 ext_feat; UINT8 chnl_mask[L2CAP_FIXED_CHNL_ARRAY_SIZE]; - BTM_TRACE_DEBUG ("%s() link_key_type = 0x%x", __func__, + BTM_TRACE_DEBUG ("%s() link_key_type = 0x%x\n", __func__, p_dev_rec->link_key_type); if ((p_dev_rec->link_key_type != BTM_LKEY_TYPE_UNAUTH_COMB_P_256) && diff --git a/components/bt/bluedroid/stack/btu/btu_init.c b/components/bt/bluedroid/stack/btu/btu_init.c index cd0af18ad8..9ac18a86a8 100755 --- a/components/bt/bluedroid/stack/btu/btu_init.c +++ b/components/bt/bluedroid/stack/btu/btu_init.c @@ -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; diff --git a/components/bt/bluedroid/stack/sdp/sdp_db.c b/components/bt/bluedroid/stack/sdp/sdp_db.c index ea8fa87563..8eb680dcd4 100755 --- a/components/bt/bluedroid/stack/sdp/sdp_db.c +++ b/components/bt/bluedroid/stack/sdp/sdp_db.c @@ -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++) { diff --git a/components/bt/bluedroid/stack/sdp/sdp_discovery.c b/components/bt/bluedroid/stack/sdp/sdp_discovery.c index 646a62dd3d..8e17a28b1f 100755 --- a/components/bt/bluedroid/stack/sdp/sdp_discovery.c +++ b/components/bt/bluedroid/stack/sdp/sdp_discovery.c @@ -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; diff --git a/components/bt/bluedroid/stack/sdp/sdp_main.c b/components/bt/bluedroid/stack/sdp/sdp_main.c index ba3c763e4b..b500f106c7 100755 --- a/components/bt/bluedroid/stack/sdp/sdp_main.c +++ b/components/bt/bluedroid/stack/sdp/sdp_main.c @@ -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); diff --git a/components/bt/bluedroid/stack/sdp/sdp_server.c b/components/bt/bluedroid/stack/sdp/sdp_server.c index 333b3e68ab..53cb525108 100755 --- a/components/bt/bluedroid/stack/sdp/sdp_server.c +++ b/components/bt/bluedroid/stack/sdp/sdp_server.c @@ -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; diff --git a/components/bt/bluedroid/stack/sdp/sdp_utils.c b/components/bt/bluedroid/stack/sdp/sdp_utils.c index 6e3130b53d..90bf58e005 100755 --- a/components/bt/bluedroid/stack/sdp/sdp_utils.c +++ b/components/bt/bluedroid/stack/sdp/sdp_utils.c @@ -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; diff --git a/components/bt/bluedroid/stack_api/bt_gap_api.c b/components/bt/bluedroid/stack_api/bt_gap_api.c new file mode 100644 index 0000000000..47ab0730bb --- /dev/null +++ b/components/bt/bluedroid/stack_api/bt_gap_api.c @@ -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; +} diff --git a/components/bt/bluedroid/stack_api/bt_sdp_api.c b/components/bt/bluedroid/stack_api/bt_sdp_api.c new file mode 100644 index 0000000000..6cee6650d3 --- /dev/null +++ b/components/bt/bluedroid/stack_api/bt_sdp_api.c @@ -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); +} + +/**********************************************************************************************/ +/**********************************************************************************************/ diff --git a/components/bt/bluedroid/stack_api/include/bt_api_common.h b/components/bt/bluedroid/stack_api/include/bt_api_common.h new file mode 100644 index 0000000000..7c4859db24 --- /dev/null +++ b/components/bt/bluedroid/stack_api/include/bt_api_common.h @@ -0,0 +1,13 @@ +#ifndef __BT_API_COMMON_H__ +#define __BT_API_COMMON_H__ + +#include + +#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__ */ diff --git a/components/bt/bluedroid/stack_api/include/bt_gap_api.h b/components/bt/bluedroid/stack_api/include/bt_gap_api.h new file mode 100644 index 0000000000..ac74996f5c --- /dev/null +++ b/components/bt/bluedroid/stack_api/include/bt_gap_api.h @@ -0,0 +1,18 @@ +#ifndef __BT_GAP_API_H__ +#define __BT_GAP_API_H__ + +#include + +#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__ */ diff --git a/components/bt/bluedroid/stack_api/include/bt_sdp_api.h b/components/bt/bluedroid/stack_api/include/bt_sdp_api.h new file mode 100644 index 0000000000..a4b8f2d2a9 --- /dev/null +++ b/components/bt/bluedroid/stack_api/include/bt_sdp_api.h @@ -0,0 +1,118 @@ +#ifndef __BT_SDP_API_H__ +#define __BT_SDP_API_H__ + +#include +#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__ */ diff --git a/components/bt/component.mk b/components/bt/component.mk index 4316eaf474..1926f857d5 100644 --- a/components/bt/component.mk +++ b/components/bt/component.mk @@ -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 \ . diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c index 639e732606..be179f501f 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c @@ -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; diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index d5c0264bee..3f4483409c 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -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; diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_common.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_common.h index 80e85f2905..d0eb314bb1 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_common.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_common.h @@ -4,23 +4,7 @@ #include #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) diff --git a/examples/07_blufi/components/bluedroid_demos/app_project/SampleClientProject.c b/examples/07_blufi/components/bluedroid_demos/app_project/SampleClientProject.c new file mode 100644 index 0000000000..be179f501f --- /dev/null +++ b/examples/07_blufi/components/bluedroid_demos/app_project/SampleClientProject.c @@ -0,0 +1,377 @@ +/**************************************************************************** +* +* This file is for gatt client. It can scan ble device, connect one device, +* +****************************************************************************/ + +#include +#include +#include +#include + +#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(); +} diff --git a/examples/07_blufi/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/07_blufi/components/bluedroid_demos/app_project/SampleServerProject.c new file mode 100644 index 0000000000..8ed96b04c4 --- /dev/null +++ b/examples/07_blufi/components/bluedroid_demos/app_project/SampleServerProject.c @@ -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 +#include +#include +#include + +#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(); +} diff --git a/examples/07_blufi/components/bluedroid_demos/include/bt_app_common.h b/examples/07_blufi/components/bluedroid_demos/include/bt_app_common.h new file mode 100644 index 0000000000..d0eb314bb1 --- /dev/null +++ b/examples/07_blufi/components/bluedroid_demos/include/bt_app_common.h @@ -0,0 +1,31 @@ +#ifndef __BT_APP_COMMON_H__ +#define __BT_APP_COMMON_H__ + +#include +#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__ */ diff --git a/examples/07_blufi/components/blufi/blufi.c b/examples/07_blufi/components/blufi/blufi.c index 5b6884134f..65ccd40302 100644 --- a/examples/07_blufi/components/blufi/blufi.c +++ b/examples/07_blufi/components/blufi/blufi.c @@ -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); diff --git a/examples/07_blufi/components/blufi/blufi_task.c b/examples/07_blufi/components/blufi/blufi_task.c index 77ce1d6d43..daa60db6ec 100644 --- a/examples/07_blufi/components/blufi/blufi_task.c +++ b/examples/07_blufi/components/blufi/blufi_task.c @@ -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); diff --git a/examples/07_blufi/components/blufi/include/blufi.h b/examples/07_blufi/components/blufi/include/blufi.h index 8cb2733408..61a1c1c242 100644 --- a/examples/07_blufi/components/blufi/include/blufi.h +++ b/examples/07_blufi/components/blufi/include/blufi.h @@ -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__ */ diff --git a/examples/08_bt_sdp/Makefile b/examples/08_bt_sdp/Makefile new file mode 100755 index 0000000000..1e91bbb891 --- /dev/null +++ b/examples/08_bt_sdp/Makefile @@ -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 + diff --git a/examples/08_bt_sdp/README.rst b/examples/08_bt_sdp/README.rst new file mode 100755 index 0000000000..c55040a510 --- /dev/null +++ b/examples/08_bt_sdp/README.rst @@ -0,0 +1,5 @@ +ESP-IDF 08 SDP Server and Client +======================= + +Demo of bluetooth SDP server and client + diff --git a/examples/08_bt_sdp/components/bluedroid_demos/app_core/bt_app_core.c b/examples/08_bt_sdp/components/bluedroid_demos/app_core/bt_app_core.c new file mode 100755 index 0000000000..220c01d31a --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/app_core/bt_app_core.c @@ -0,0 +1,174 @@ +#include +#include +#include + +#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); +} +*/ diff --git a/examples/08_bt_sdp/components/bluedroid_demos/app_project/SampleBtSdp.c b/examples/08_bt_sdp/components/bluedroid_demos/app_project/SampleBtSdp.c new file mode 100644 index 0000000000..3587ba6d4e --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/app_project/SampleBtSdp.c @@ -0,0 +1,140 @@ +#include +#include +#include +#include + + +#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(); + } +} + diff --git a/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_core.c b/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_core.c new file mode 100755 index 0000000000..97dc8baf79 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_core.c @@ -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 +// #include +// #include +// #include +// #include +#include +#include +// #include +// #include + +#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< +// #include +#include +#include +#include +// #include +// #include + +// #include + +// #include +#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); +} diff --git a/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_sdp.c b/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_sdp.c new file mode 100755 index 0000000000..d77f61869a --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_sdp.c @@ -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 +#include + +#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; +} + diff --git a/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_sdp_server.c b/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_sdp_server.c new file mode 100755 index 0000000000..ebb3f8422f --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_sdp_server.c @@ -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 +#include +#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; ihdr.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; ihdr.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; +} + diff --git a/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_util.c b/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_util.c new file mode 100755 index 0000000000..b64e7fdeb2 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/btif/btif_util.c @@ -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 +// #include +// #include +// #include +#include +#include +#include +#include + + +#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; +} + diff --git a/examples/08_bt_sdp/components/bluedroid_demos/btif/stack_manager.c b/examples/08_bt_sdp/components/bluedroid_demos/btif/stack_manager.c new file mode 100644 index 0000000000..37843cdea2 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/btif/stack_manager.c @@ -0,0 +1,160 @@ +#include +#include +#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; +} diff --git a/examples/08_bt_sdp/components/bluedroid_demos/component.mk b/examples/08_bt_sdp/components/bluedroid_demos/component.mk new file mode 100755 index 0000000000..98cb290800 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/component.mk @@ -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 diff --git a/examples/08_bt_sdp/components/bluedroid_demos/include/bt_app_common.h b/examples/08_bt_sdp/components/bluedroid_demos/include/bt_app_common.h new file mode 100755 index 0000000000..501bfccc97 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/include/bt_app_common.h @@ -0,0 +1,30 @@ +#ifndef __BT_APP_COMMON_H__ +#define __BT_APP_COMMON_H__ + +#include +#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__ */ diff --git a/examples/08_bt_sdp/components/bluedroid_demos/include/btif_api.h b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_api.h new file mode 100755 index 0000000000..753fec100d --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_api.h @@ -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 */ diff --git a/examples/08_bt_sdp/components/bluedroid_demos/include/btif_common.h b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_common.h new file mode 100755 index 0000000000..ca6168c52b --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_common.h @@ -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 +// #include + +#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 */ diff --git a/examples/08_bt_sdp/components/bluedroid_demos/include/btif_dm.h b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_dm.h new file mode 100755 index 0000000000..58f535c30b --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_dm.h @@ -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 diff --git a/examples/08_bt_sdp/components/bluedroid_demos/include/btif_sdp.h b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_sdp.h new file mode 100644 index 0000000000..e345ef03f2 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_sdp.h @@ -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__ */ diff --git a/examples/08_bt_sdp/components/bluedroid_demos/include/btif_stack_manager.h b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_stack_manager.h new file mode 100644 index 0000000000..a780fded25 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_stack_manager.h @@ -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__ */ diff --git a/examples/08_bt_sdp/components/bluedroid_demos/include/btif_util.h b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_util.h new file mode 100755 index 0000000000..8c5e035fc7 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/include/btif_util.h @@ -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 +// #include +#include +// #include + +#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 */ diff --git a/examples/08_bt_sdp/components/bluedroid_demos/include/stack_manager.h b/examples/08_bt_sdp/components/bluedroid_demos/include/stack_manager.h new file mode 100755 index 0000000000..466cdca122 --- /dev/null +++ b/examples/08_bt_sdp/components/bluedroid_demos/include/stack_manager.h @@ -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 +#include "future.h" + +bool stack_manager_is_stack_running(void); + +future_t *stack_manager_get_hack_future(void); + +#endif /* __STACK_MANAGER_H__*/ diff --git a/examples/08_bt_sdp/main/component.mk b/examples/08_bt_sdp/main/component.mk new file mode 100755 index 0000000000..24356f23ed --- /dev/null +++ b/examples/08_bt_sdp/main/component.mk @@ -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 diff --git a/examples/08_bt_sdp/main/demo_main.c b/examples/08_bt_sdp/main/demo_main.c new file mode 100755 index 0000000000..ad8243a1fc --- /dev/null +++ b/examples/08_bt_sdp/main/demo_main.c @@ -0,0 +1,28 @@ +#include +#include +#include +#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); +}