diff --git a/components/bt/bluedroid/include/bt_sdp.h b/components/bt/bluedroid/include/bt_sdp.h deleted file mode 100755 index 64d757b7f..000000000 --- a/components/bt/bluedroid/include/bt_sdp.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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 "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; - - -/** 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 { - /** Set to sizeof(btsdp_callbacks_t) */ - size_t size; - btsdp_search_callback sdp_search_cb; -} btsdp_callbacks_t; - -#endif /* __BT_SDP_H__ */ diff --git a/components/bt/bluedroid/profiles/core/btif_dm.c b/components/bt/bluedroid/profiles/core/btif_dm.c index 558414508..64424052c 100755 --- a/components/bt/bluedroid/profiles/core/btif_dm.c +++ b/components/bt/bluedroid/profiles/core/btif_dm.c @@ -108,14 +108,14 @@ static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC *dm_sec) bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id, BOOLEAN b_enable) { - BTIF_TRACE_DEBUG("%s service_id: %d", __FUNCTION__, service_id); + 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", __FUNCTION__); + BTIF_TRACE_ERROR("%s: Unknown service being enabled\n", __FUNCTION__); return BT_STATUS_FAIL; } return BT_STATUS_SUCCESS; @@ -205,7 +205,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param) case BTA_DM_ROLE_CHG_EVT: default: - BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)", event ); + BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)\n", event ); break; } @@ -229,5 +229,5 @@ void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data) (void*)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy); /* catch any failed context transfers */ - ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status); + ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed\n", status); } diff --git a/components/bt/bluedroid/profiles/core/stack_manager.c b/components/bt/bluedroid/profiles/core/stack_manager.c index c2d2d847b..f12145cab 100644 --- a/components/bt/bluedroid/profiles/core/stack_manager.c +++ b/components/bt/bluedroid/profiles/core/stack_manager.c @@ -26,7 +26,6 @@ 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_initialized(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); @@ -62,7 +61,7 @@ static bt_status_t event_start_up_stack(void) return BT_STATUS_DONE; } - LOG_DEBUG("%s is bringing up the stack.", __func__); + LOG_DEBUG("%s is bringing up the stack.\n", __func__); hack_future = future_new(); btif_enable_bluetooth(); @@ -74,7 +73,7 @@ static bt_status_t event_start_up_stack(void) } stack_is_running = true; - LOG_DEBUG("%s finished", __func__); + LOG_DEBUG("%s finished\n", __func__); btif_transfer_context(event_signal_stack_up, 0, NULL, 0, NULL); return BT_STATUS_SUCCESS; } @@ -82,11 +81,11 @@ static bt_status_t event_start_up_stack(void) static bt_status_t event_shut_down_stack(void) { if (!stack_is_running) { - LOG_DEBUG("%s stack is already brought down.", __func__); + LOG_DEBUG("%s stack is already brought down.\n", __func__); return BT_STATUS_DONE; } - LOG_DEBUG("%s is bringing down the stack.", __func__); + LOG_DEBUG("%s is bringing down the stack.\n", __func__); hack_future = future_new(); stack_is_running = false; @@ -94,7 +93,7 @@ static bt_status_t event_shut_down_stack(void) future_await(hack_future); - LOG_DEBUG("%s finished.", __func__); + LOG_DEBUG("%s finished.\n", __func__); btif_transfer_context(event_signal_stack_down, 0, NULL, 0, NULL); return BT_STATUS_SUCCESS; } @@ -102,7 +101,7 @@ static bt_status_t event_shut_down_stack(void) static bt_status_t event_clean_up_stack(void) { if (!stack_is_initialized) { - LOG_DEBUG("%s found the stack already in a clean state.", __func__); + LOG_DEBUG("%s found the stack already in a clean state.\n", __func__); return BT_STATUS_DONE; } @@ -110,7 +109,7 @@ static bt_status_t event_clean_up_stack(void) event_shut_down_stack(); } - LOG_DEBUG("%s is cleaning up the stack.", __func__); + LOG_DEBUG("%s is cleaning up the stack.\n", __func__); stack_is_initialized = false; diff --git a/components/bt/bluedroid/profiles/std/include/bt_sdp.h b/components/bt/bluedroid/profiles/std/include/bt_sdp.h index 0a7a6618f..efa3116bf 100755 --- a/components/bt/bluedroid/profiles/std/include/bt_sdp.h +++ b/components/bt/bluedroid/profiles/std/include/bt_sdp.h @@ -113,8 +113,6 @@ typedef union { 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 { - /** Set to sizeof(btsdp_callbacks_t) */ - size_t size; btsdp_search_callback sdp_search_cb; } btsdp_callbacks_t; diff --git a/components/bt/bluedroid/profiles/std/sdp/btif_sdp.c b/components/bt/bluedroid/profiles/std/sdp/btif_sdp.c index 58d042c97..f5c6ae482 100755 --- a/components/bt/bluedroid/profiles/std/sdp/btif_sdp.c +++ b/components/bt/bluedroid/profiles/std/sdp/btif_sdp.c @@ -63,7 +63,7 @@ static void btif_sdp_search_comp_evt(UINT16 event, char *p_param) { tBTA_SDP_SEARCH_COMP *evt_data = (tBTA_SDP_SEARCH_COMP*) p_param; bt_bdaddr_t addr; - BTIF_TRACE_DEBUG("%s: event = %d", __FUNCTION__, event); + BTIF_TRACE_DEBUG("%s: event = %d\n", __FUNCTION__, event); if (event != BTA_SDP_SEARCH_COMP_EVT) return; @@ -123,7 +123,7 @@ static void sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP *p_data, void *user_data) bt_status_t API_BT_SdpInit(btsdp_callbacks_t *callbacks) { - BTIF_TRACE_DEBUG("Sdp Search %s", __FUNCTION__); + BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__); bt_sdp_callbacks = callbacks; sdp_server_init(); @@ -135,7 +135,7 @@ bt_status_t API_BT_SdpInit(btsdp_callbacks_t *callbacks) bt_status_t API_BT_SdpDeinit(void) { - BTIF_TRACE_DEBUG("Sdp Search %s", __FUNCTION__); + BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__); bt_sdp_callbacks = NULL; sdp_server_cleanup(); @@ -168,7 +168,7 @@ bt_status_t API_BT_SdpSearch(bt_bdaddr_t *bd_addr, const uint8_t* uuid) *******************************************************************************/ bt_status_t btif_sdp_execute_service(BOOLEAN b_enable) { - BTIF_TRACE_DEBUG("%s enable:%d", __FUNCTION__, b_enable); + BTIF_TRACE_DEBUG("%s enable:%d\n", __FUNCTION__, b_enable); if (b_enable) { diff --git a/components/bt/bluedroid/profiles/std/sdp/btif_sdp_server.c b/components/bt/bluedroid/profiles/std/sdp/btif_sdp_server.c index e87a331d0..f62b34577 100755 --- a/components/bt/bluedroid/profiles/std/sdp/btif_sdp_server.c +++ b/components/bt/bluedroid/profiles/std/sdp/btif_sdp_server.c @@ -99,7 +99,7 @@ static void init_sdp_slots() bt_status_t sdp_server_init() { - BTIF_TRACE_DEBUG("Sdp Server %s", __FUNCTION__); + BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__); pthread_mutex_init(&sdp_lock, NULL); init_sdp_slots(); return BT_STATUS_SUCCESS; @@ -107,7 +107,7 @@ bt_status_t sdp_server_init() void sdp_server_cleanup() { - BTIF_TRACE_DEBUG("Sdp Server %s", __FUNCTION__); + BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__); pthread_mutex_lock(&sdp_lock); int i; for(i = 0; i < MAX_SDP_SLOTS; i++) @@ -206,7 +206,7 @@ static int alloc_sdp_slot(bluetooth_sdp_record* in_record) { } pthread_mutex_unlock(&sdp_lock); if(i >= MAX_SDP_SLOTS) { - APPL_TRACE_ERROR("%s() failed - no more free slots!", __func__); + 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; @@ -218,7 +218,7 @@ 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", __func__, id); + APPL_TRACE_ERROR("%s() failed - id %d is invalid\n", __func__, id); return handle; } pthread_mutex_lock(&sdp_lock); @@ -248,7 +248,7 @@ static int free_sdp_slot(int id) { 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", __func__, id); + APPL_TRACE_ERROR("%s() failed - id %d is invalid\n", __func__, id); return NULL; } pthread_mutex_lock(&sdp_lock); @@ -260,8 +260,8 @@ static const sdp_slot_t* start_create_sdp(int id) { } pthread_mutex_unlock(&sdp_lock); if(sdp_slot == NULL) { - APPL_TRACE_ERROR("%s() failed - state for id %d is " - "sdp_slots[id].state = %d expected %d", __func__, + 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; @@ -271,14 +271,14 @@ 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", __FUNCTION__, id, handle); + BTIF_TRACE_DEBUG("%s() id=%d to handle=0x%08x\n", __FUNCTION__, id, handle); } bt_status_t API_BT_SdpCreateRecord(bluetooth_sdp_record *record, int* record_handle) { int handle; handle = alloc_sdp_slot(record); - BTIF_TRACE_DEBUG("%s() handle = 0x%08x", __FUNCTION__, handle); + BTIF_TRACE_DEBUG("%s() handle = 0x%08x\n", __FUNCTION__, handle); if(handle < 0) return BT_STATUS_FAIL; @@ -295,7 +295,7 @@ bt_status_t API_BT_SdpRemoveRecord(int record_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", + BTIF_TRACE_DEBUG("Sdp Server %s id=%d to handle=0x%08x\n", __FUNCTION__, record_handle, handle); /* Pass the actual record handle */ @@ -303,7 +303,7 @@ bt_status_t API_BT_SdpRemoveRecord(int record_handle) { BTA_SdpRemoveRecordByUser((void*) handle); return BT_STATUS_SUCCESS; } - BTIF_TRACE_DEBUG("Sdp Server %s - record already removed - or never created", __FUNCTION__); + BTIF_TRACE_DEBUG("Sdp Server %s - record already removed - or never created\n", __FUNCTION__); return BT_STATUS_FAIL; } @@ -320,7 +320,7 @@ void on_create_record_event(int id) { * 3) Update state on completion * 4) What to do at fail? * */ - BTIF_TRACE_DEBUG("Sdp Server %s", __FUNCTION__); + 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) { @@ -345,7 +345,7 @@ void on_create_record_event(int id) { case SDP_TYPE_PBAP_PCE: // break; not yet supported default: - BTIF_TRACE_DEBUG("Record type %d is not supported",record->hdr.type); + BTIF_TRACE_DEBUG("Record type %d is not supported\n",record->hdr.type); break; } if(handle != -1) { @@ -355,14 +355,14 @@ void on_create_record_event(int id) { } void on_remove_record_event(int handle) { - BTIF_TRACE_DEBUG("Sdp Server %s", __FUNCTION__); + 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", handle); + BTIF_TRACE_ERROR(" Unable to remove handle 0x%08x\n", handle); } } } @@ -383,16 +383,16 @@ static int add_maps_sdp(const bluetooth_sdp_mas_record* rec) UINT8 temp[4]; UINT8* p_temp = temp; - APPL_TRACE_DEBUG("%s(): MASID = 0x%02x, scn 0x%02x, psm = 0x%04x\n service name %s", __func__, + 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", + APPL_TRACE_DEBUG(" msg_types: 0x%02x, feature_bits: 0x%08x\n", rec->supported_message_types, rec->supported_features); if ((sdp_handle = SDP_CreateRecord()) == 0) { - APPL_TRACE_ERROR("%s() - Unable to register MAPS Service", __func__); + APPL_TRACE_ERROR("%s() - Unable to register MAPS Service\n", __func__); return sdp_handle; } @@ -450,12 +450,12 @@ static int add_maps_sdp(const bluetooth_sdp_mas_record* rec) { SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - APPL_TRACE_ERROR("%s() FAILED", __func__); + 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)", __func__, sdp_handle); + APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle); } return sdp_handle; } @@ -472,14 +472,14 @@ static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec) UINT8 temp[4]; UINT8* p_temp = temp; - APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s", __func__, + 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", rec->supported_features); + APPL_TRACE_DEBUG(" feature_bits: 0x%08x\n", rec->supported_features); if ((sdp_handle = SDP_CreateRecord()) == 0) { - APPL_TRACE_ERROR("%s(): Unable to register MAP Notification Service", __func__); + APPL_TRACE_ERROR("%s(): Unable to register MAP Notification Service\n", __func__); return sdp_handle; } @@ -529,12 +529,12 @@ static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec) { SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - APPL_TRACE_ERROR("%s() FAILED", __func__); + 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)", __func__, sdp_handle); + APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle); } return sdp_handle; } @@ -551,15 +551,15 @@ static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec) UINT8 temp[4]; UINT8* p_temp = temp; - APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s", __func__, + 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", + APPL_TRACE_DEBUG(" supported_repositories: 0x%08x, feature_bits: 0x%08x\n", rec->supported_repositories, rec->supported_features); if ((sdp_handle = SDP_CreateRecord()) == 0) { - APPL_TRACE_ERROR("%s(): Unable to register PBAP Server Service", __func__); + APPL_TRACE_ERROR("%s(): Unable to register PBAP Server Service\n", __func__); return sdp_handle; } @@ -613,12 +613,12 @@ static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec) { SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - APPL_TRACE_ERROR("%s() FAILED", __func__); + 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)", __func__, sdp_handle); + APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle); } return sdp_handle; } @@ -641,15 +641,15 @@ static int add_opps_sdp(const bluetooth_sdp_ops_record* rec) tBTA_UTL_COD cod; int i,j; - APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s", __func__, + 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", + APPL_TRACE_DEBUG(" supported formats count: %d\n", rec->supported_formats_list_len); if ((sdp_handle = SDP_CreateRecord()) == 0) { - APPL_TRACE_ERROR("%s(): Unable to register Object Push Server Service", __func__); + APPL_TRACE_ERROR("%s(): Unable to register Object Push Server Service\n", __func__); return sdp_handle; } @@ -705,7 +705,7 @@ static int add_opps_sdp(const bluetooth_sdp_ops_record* rec) { SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - APPL_TRACE_ERROR("%s() FAILED", __func__); + APPL_TRACE_ERROR("%s() FAILED\n", __func__); } else { @@ -714,7 +714,7 @@ static int add_opps_sdp(const bluetooth_sdp_ops_record* rec) 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)", __func__, sdp_handle); + APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle); } return sdp_handle; } @@ -728,12 +728,12 @@ static int add_saps_sdp(const bluetooth_sdp_sap_record* rec) BOOLEAN status = TRUE; UINT32 sdp_handle = 0; - APPL_TRACE_DEBUG("%s(): scn 0x%02x, service name %s", __func__, + APPL_TRACE_DEBUG("%s(): scn 0x%02x, service name %s\n", __func__, rec->hdr.rfcomm_channel_number, rec->hdr.service_name); if ((sdp_handle = SDP_CreateRecord()) == 0) { - APPL_TRACE_ERROR("%s(): Unable to register SAPS Service", __func__); + APPL_TRACE_ERROR("%s(): Unable to register SAPS Service\n", __func__); return sdp_handle; } @@ -771,12 +771,12 @@ static int add_saps_sdp(const bluetooth_sdp_sap_record* rec) { SDP_DeleteRecord(sdp_handle); sdp_handle = 0; - APPL_TRACE_ERROR("%s(): FAILED deleting record", __func__); + 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)", __func__, sdp_handle); + APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle); } return sdp_handle; } diff --git a/components/bt/component.mk b/components/bt/component.mk index 2683703d9..6f83a16fd 100644 --- a/components/bt/component.mk +++ b/components/bt/component.mk @@ -61,6 +61,7 @@ COMPONENT_SRCDIRS := bluedroid/bta/dm \ 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 \ diff --git a/examples/08_bt_sdp_server/Makefile b/examples/08_bt_sdp_server/Makefile new file mode 100755 index 000000000..1e91bbb89 --- /dev/null +++ b/examples/08_bt_sdp_server/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_server/README.rst b/examples/08_bt_sdp_server/README.rst new file mode 100755 index 000000000..cc91b26fc --- /dev/null +++ b/examples/08_bt_sdp_server/README.rst @@ -0,0 +1,5 @@ +ESP-IDF 08 SDP Server +======================= + +SDP Server demo for legacy bluetooth; Test can be conducted via such tool as sdptool. + diff --git a/examples/08_bt_sdp_server/components/bluedroid_demos/app_core/bt_app_core.c b/examples/08_bt_sdp_server/components/bluedroid_demos/app_core/bt_app_core.c new file mode 100755 index 000000000..e20c3b39c --- /dev/null +++ b/examples/08_bt_sdp_server/components/bluedroid_demos/app_core/bt_app_core.c @@ -0,0 +1,175 @@ +#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 "prf_defs.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_server/components/bluedroid_demos/app_project/SampleSdpServer.c b/examples/08_bt_sdp_server/components/bluedroid_demos/app_project/SampleSdpServer.c new file mode 100644 index 000000000..af003e225 --- /dev/null +++ b/examples/08_bt_sdp_server/components/bluedroid_demos/app_project/SampleSdpServer.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include + + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#include "bt_app_common.h" +#include "bt_stack_manager.h" +#include "bt_sdp.h" +#include "bt_gap.h" + +/* bta_api.h should not be included as BTA APIs should not be used by APP */ +#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 bt_callbacks_t bt_callbacks = { + bt_stack_state_changed +}; + +static btsdp_callbacks_t btsdp_callbacks = { + NULL +}; + +static void bt_app_stack_evt(UINT16 event, char *p_param) +{ + // tBT_APP_EVT_DATA *p_data = (tBT_APP_EVT_DATA *)p_param; + switch (event) { + case BT_APP_EVT_STACK_ON: { + // todo: BTM & BTA APIs should not be called in application task + char *dev_name = "flash"; + BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG); + BTA_DmSetDeviceName(dev_name); + + API_BT_GapSetScanMode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); + + API_BT_SdpInit(&btsdp_callbacks); + // todo: SdpInit should have callback function indicating the end of execution + // to avoid using vTaskDelay. + vTaskDelay(1000 / portTICK_PERIOD_MS); + int handle = bt_sdp_add_record(); + + vTaskDelay(20000/portTICK_PERIOD_MS); + API_BT_SdpRemoveRecord(handle); + + vTaskDelay(20000/portTICK_PERIOD_MS); + bt_sdp_add_record(); + + } + 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 = "SAP_SVR"; + sap_svr.hdr.service_name_length = 7; + sap_svr.hdr.profile_version = 1; + + API_BT_SdpCreateRecord((bluetooth_sdp_record *)(&sap_svr), &handle); + return handle; +} + +void app_main_entry(void) +{ + bt_status_t stat; + stat = API_BTDM_InitStack(&bt_callbacks); + if (stat == BT_STATUS_SUCCESS) { + API_BTDM_EnableStack(); + } +} diff --git a/examples/08_bt_sdp_server/components/bluedroid_demos/component.mk b/examples/08_bt_sdp_server/components/bluedroid_demos/component.mk new file mode 100755 index 000000000..84150bddc --- /dev/null +++ b/examples/08_bt_sdp_server/components/bluedroid_demos/component.mk @@ -0,0 +1,17 @@ +# +# 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 + +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_server/components/bluedroid_demos/include/bt_app_common.h b/examples/08_bt_sdp_server/components/bluedroid_demos/include/bt_app_common.h new file mode 100755 index 000000000..501bfccc9 --- /dev/null +++ b/examples/08_bt_sdp_server/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_server/main/component.mk b/examples/08_bt_sdp_server/main/component.mk new file mode 100755 index 000000000..24356f23e --- /dev/null +++ b/examples/08_bt_sdp_server/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_server/main/demo_main.c b/examples/08_bt_sdp_server/main/demo_main.c new file mode 100755 index 000000000..ad8243a1f --- /dev/null +++ b/examples/08_bt_sdp_server/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); +}