From db554581079863974af8e1289646f5deea6fc044 Mon Sep 17 00:00:00 2001 From: Marie Janssen Date: Fri, 26 Jun 2015 14:53:46 -0700 Subject: [PATCH] build: Update osi log functions, use consistently Update the LOG_* functions to take a tag argument which makes them more consistent with the Android Log.*(TAG, s) common syntax and removes some #define-dependency with osi/include/log.h. Also update to never use Android log functions directly. Also contains minor cleanup of some header includes. Bug: 21569831 Change-Id: If07385cafbea062232ecdbc7c673f908d5ef8921 --- audio_a2dp_hw/audio_a2dp_hw.c | 12 +++--- bta/av/bta_av_act.c | 9 ++-- bta/av/bta_av_main.c | 10 +++-- bta/dm/bta_dm_act.c | 25 +++++------ bta/gatt/bta_gattc_act.c | 20 ++++----- bta/gatt/bta_gattc_cache.c | 17 ++++---- bta/hh/bta_hh_api.c | 4 +- bta/hh/bta_hh_le.c | 15 ++++--- bta/sys/bta_sys_main.c | 21 ++++----- btcore/src/counter.c | 36 ++++++++-------- btcore/src/module.c | 14 +++--- btif/include/btif_common.h | 8 +--- btif/include/btif_sock_util.h | 2 +- btif/src/bluetooth.c | 14 +++--- btif/src/btif_config.c | 25 ++++++----- btif/src/btif_config_transcode.cpp | 6 +-- btif/src/btif_core.c | 15 +++---- btif/src/btif_dm.c | 42 +++++++++--------- btif/src/btif_gatt_client.c | 35 ++++++++------- btif/src/btif_gatt_server.c | 28 ++++++------ btif/src/btif_gatt_test.c | 61 +++++++++++++------------- btif/src/btif_gatt_util.c | 22 +++++----- btif/src/btif_hh.c | 23 +++++----- btif/src/btif_hl.c | 2 +- btif/src/btif_media_task.c | 67 ++++++++++++++--------------- btif/src/btif_pan.c | 53 +++++++++++------------ btif/src/btif_profile_queue.c | 9 ++-- btif/src/btif_sock.c | 23 +++++----- btif/src/btif_sock_l2cap.c | 50 +++++++++++----------- btif/src/btif_sock_rfc.c | 55 ++++++++++++------------ btif/src/btif_sock_sco.c | 29 +++++++------ btif/src/btif_sock_util.c | 27 +++--------- btif/src/btif_storage.c | 27 ++++++------ btif/src/stack_manager.c | 36 ++++++++-------- hci/src/btsnoop.c | 10 ++--- hci/src/btsnoop_net.c | 14 +++--- hci/src/hci_audio.c | 2 +- hci/src/hci_hal_h4.c | 34 +++++++-------- hci/src/hci_hal_mct.c | 34 +++++++-------- hci/src/hci_inject.c | 16 +++---- hci/src/hci_layer.c | 87 +++++++++++++++++++------------------- hci/src/hci_packet_parser.c | 10 ++--- hci/src/low_power_manager.c | 23 +++++----- hci/src/packet_fragmenter.c | 17 ++++---- hci/src/vendor.c | 18 ++++---- main/bte_conf.c | 30 ++++++------- main/bte_logmsg.c | 47 +++++++------------- main/bte_main.c | 31 +++++++------- main/stack_config.c | 9 ++-- osi/include/log.h | 13 +++--- osi/src/alarm.c | 26 ++++++------ osi/src/allocation_tracker.c | 2 +- osi/src/array.c | 4 +- osi/src/buffer.c | 4 +- osi/src/config.c | 16 +++---- osi/src/data_dispatcher.c | 8 ++-- osi/src/eager_reader.c | 18 ++++---- osi/src/future.c | 6 +-- osi/src/reactor.c | 18 ++++---- osi/src/semaphore.c | 12 +++--- osi/src/socket.c | 16 +++---- osi/src/thread.c | 6 +-- service/a2dp_source.cpp | 4 +- service/core_stack.cpp | 20 ++++----- service/gatt_server.cpp | 32 +++++++------- service/host.cpp | 14 +++--- service/main.cpp | 6 +-- stack/btm/btm_ble.c | 4 +- stack/btm/btm_ble_gap.c | 4 +- stack/btm/btm_pm.c | 4 +- stack/btm/btm_sec.c | 10 ++--- stack/btu/btu_hcif.c | 4 +- stack/btu/btu_init.c | 2 +- stack/btu/btu_task.c | 14 +++--- stack/l2cap/l2c_api.c | 4 +- stack/l2cap/l2c_main.c | 10 +++-- stack/l2cap/l2cap_client.c | 36 ++++++++-------- stack/rfcomm/port_api.c | 10 +++-- stack/srvc/srvc_dis.c | 2 +- utils/src/bt_utils.c | 6 +-- 80 files changed, 769 insertions(+), 790 deletions(-) diff --git a/audio_a2dp_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c index 7f5cea4ca..1e0b289b7 100644 --- a/audio_a2dp_hw/audio_a2dp_hw.c +++ b/audio_a2dp_hw/audio_a2dp_hw.c @@ -42,8 +42,6 @@ #include #include -#define LOG_TAG "bt_a2dp_hw" - #include "audio_a2dp_hw.h" #include "bt_utils.h" #include "osi/include/log.h" @@ -58,10 +56,12 @@ #define CASE_RETURN_STR(const) case const: return #const; -#define FNLOG() LOG_VERBOSE("%s", __FUNCTION__); -#define DEBUG(fmt, ...) LOG_VERBOSE("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) -#define INFO(fmt, ...) LOG_INFO("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) -#define ERROR(fmt, ...) LOG_ERROR("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) +#define LOG_TAG "bt_a2dp_hw" + +#define FNLOG() LOG_VERBOSE(LOG_TAG, "%s", __FUNCTION__); +#define DEBUG(fmt, ...) LOG_VERBOSE(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__) +#define INFO(fmt, ...) LOG_INFO(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__) +#define ERROR(fmt, ...) LOG_ERROR(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__) #define ASSERTC(cond, msg, val) if (!(cond)) {ERROR("### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);} diff --git a/bta/av/bta_av_act.c b/bta/av/bta_av_act.c index 5d7588ea2..6816d8bbd 100644 --- a/bta/av/bta_av_act.c +++ b/bta/av/bta_av_act.c @@ -24,16 +24,19 @@ ******************************************************************************/ #include "bt_target.h" + #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE) #include + +#include "avdt_api.h" #include "bta_av_api.h" #include "bta_av_int.h" -#include "avdt_api.h" -#include "utl.h" #include "l2c_api.h" #include "osi/include/list.h" #include "osi/include/osi.h" +#include "utl.h" + #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) #include "bta_ar_api.h" #endif @@ -505,7 +508,7 @@ void bta_av_rc_opened(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) p_scb->rc_handle = p_data->rc_conn_chg.handle; APPL_TRACE_DEBUG("bta_av_rc_opened shdl:%d, srch %d", i + 1, p_scb->rc_handle); shdl = i+1; - LOG_INFO("%s allow incoming AVRCP connections:%d", __func__, p_scb->use_rc); + LOG_INFO(LOG_TAG, "%s allow incoming AVRCP connections:%d", __func__, p_scb->use_rc); bta_sys_stop_timer(&p_scb->timer); disc = p_scb->hndl; break; diff --git a/bta/av/bta_av_main.c b/bta/av/bta_av_main.c index 3552911fe..e7dd55177 100644 --- a/bta/av/bta_av_main.c +++ b/bta/av/bta_av_main.c @@ -29,11 +29,12 @@ #include "osi/include/log.h" #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE) +#include "bta_av_co.h" #include "bta_av_int.h" -#include "utl.h" #include "l2c_api.h" #include "l2cdefs.h" -#include "bta_av_co.h" +#include "utl.h" + #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) #include "bta_ar_api.h" #endif @@ -42,9 +43,12 @@ ** Constants and types *****************************************************************************/ +#define LOG_TAG "bta_av" + /* AVDTP protocol timeout values */ #define BTIF_AVK_SERVICE_NAME "Advanced Audio Sink" + #ifndef BTA_AV_RET_TOUT #define BTA_AV_RET_TOUT 4 #endif @@ -1106,7 +1110,7 @@ BOOLEAN bta_av_link_role_ok(tBTA_AV_SCB *p_scb, UINT8 bits) if (BTM_GetRole(p_scb->peer_addr, &role) == BTM_SUCCESS) { - LOG_INFO("%s hndl:x%x role:%d conn_audio:x%x bits:%d features:x%x", + LOG_INFO(LOG_TAG, "%s hndl:x%x role:%d conn_audio:x%x bits:%d features:x%x", __func__, p_scb->hndl, role, bta_av_cb.conn_audio, bits, bta_av_cb.features); if (BTM_ROLE_MASTER != role && (A2D_BitsSet(bta_av_cb.conn_audio) > bits || (bta_av_cb.features & BTA_AV_FEAT_MASTER))) diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c index 2f94a0e29..d1160ee43 100644 --- a/bta/dm/bta_dm_act.c +++ b/bta/dm/bta_dm_act.c @@ -23,30 +23,31 @@ * ******************************************************************************/ +#include + #include "bt_target.h" #include "bt_types.h" -#include "gki.h" -#include "bta_sys.h" #include "bta_api.h" -#include "bta_dm_int.h" #include "bta_dm_co.h" +#include "bta_dm_int.h" +#include "bta_sys.h" #include "btm_api.h" #include "btm_int.h" #include "btu.h" -#include "sdp_api.h" -#include "l2c_api.h" -#include "utl.h" #include "gap_api.h" /* For GAP_BleReadPeerPrefConnParams */ -#include - -#define LOG_TAG "bt_bta_dm" +#include "gki.h" +#include "l2c_api.h" #include "osi/include/log.h" #include "osi/include/osi.h" +#include "sdp_api.h" +#include "utl.h" #if (GAP_INCLUDED == TRUE) #include "gap_api.h" #endif +#define LOG_TAG "bt_bta_dm" + static void bta_dm_inq_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir); static void bta_dm_inq_cmpl_cb (void * p_result); static void bta_dm_service_search_remname_cback (BD_ADDR bd_addr, DEV_CLASS dc, BD_NAME bd_name); @@ -2093,7 +2094,7 @@ static void bta_dm_find_services ( BD_ADDR bd_addr) /* try to search all services by search based on L2CAP UUID */ if(bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK ) { - LOG_INFO("%s services_to_search=%08x", __func__, bta_dm_search_cb.services_to_search); + LOG_INFO(LOG_TAG, "%s services_to_search=%08x", __func__, bta_dm_search_cb.services_to_search); if (bta_dm_search_cb.services_to_search & BTA_RES_SERVICE_MASK) { uuid.uu.uuid16 = bta_service_id_to_uuid_lkup_tbl[0]; @@ -2147,7 +2148,7 @@ static void bta_dm_find_services ( BD_ADDR bd_addr) memcpy(&uuid, &bta_dm_search_cb.uuid, sizeof(tSDP_UUID)); } - LOG_INFO("%s search UUID = %04x", __func__, uuid.uu.uuid16); + LOG_INFO(LOG_TAG, "%s search UUID = %04x", __func__, uuid.uu.uuid16); SDP_InitDiscoveryDb (bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, &uuid, 0, NULL); memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); @@ -5443,7 +5444,7 @@ static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id) APPL_TRACE_ERROR("%s out of room to accomodate more service ids ble_raw_size = %d ble_raw_used = %d", __FUNCTION__,bta_dm_search_cb.ble_raw_size, bta_dm_search_cb.ble_raw_used ); } - LOG_INFO("%s service_id_uuid_len=%d ", __func__, service_id.uuid.len); + LOG_INFO(LOG_TAG, "%s service_id_uuid_len=%d ", __func__, service_id.uuid.len); if ( bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) { diff --git a/bta/gatt/bta_gattc_act.c b/bta/gatt/bta_gattc_act.c index b07c47bc7..b47b4e199 100755 --- a/bta/gatt/bta_gattc_act.c +++ b/bta/gatt/bta_gattc_act.c @@ -22,26 +22,24 @@ * machine. * ******************************************************************************/ -#define LOG_TAG "bt_bta_gattc" -#include "bt_target.h" +#include -#include "utl.h" -#include "gki.h" -#include "bta_sys.h" +#include "bt_target.h" #include "bta_gattc_int.h" +#include "bta_sys.h" +#include "btif/include/btif_debug_conn.h" +#include "gki.h" #include "l2c_api.h" +#include "osi/include/log.h" +#include "utl.h" #if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE) #include "bta_hh_int.h" #endif -#include "btif/include/btif_debug_conn.h" - -#include - -#include "osi/include/log.h" +#define LOG_TAG "bt_bta_gattc" #if BTA_GATT_INCLUDED && BLE_INCLUDED == TRUE @@ -2319,7 +2317,7 @@ void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg) /* if listen to all */ else { - LOG_DEBUG("Listen For All now"); + LOG_DEBUG(LOG_TAG, "Listen For All now"); /* go through all connected device and send callback for all connected slave connection */ bta_gattc_process_listen_all(p_msg->api_listen.client_if); diff --git a/bta/gatt/bta_gattc_cache.c b/bta/gatt/bta_gattc_cache.c index cd68cbcd3..908a1651b 100644 --- a/bta/gatt/bta_gattc_cache.c +++ b/bta/gatt/bta_gattc_cache.c @@ -28,23 +28,24 @@ #if defined(BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE) #include -#include "utl.h" -#include "gki.h" -#include "bta_sys.h" -#include "sdp_api.h" -#include "sdpdefs.h" + #include "bta_gattc_int.h" +#include "bta_sys.h" #include "btm_api.h" #include "btm_ble_api.h" - -#define LOG_TAG "bt_bta_gattc" +#include "gki.h" #include "osi/include/log.h" +#include "sdp_api.h" +#include "sdpdefs.h" +#include "utl.h" static void bta_gattc_char_dscpt_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb); static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb); #define BTA_GATT_SDP_DB_SIZE 4096 +#define LOG_TAG "bt_bta_gattc" + /***************************************************************************** ** Constants *****************************************************************************/ @@ -601,7 +602,7 @@ static void bta_gattc_explore_srvc(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb) } } /* no service found at all, the end of server discovery*/ - LOG_WARN("%s no more services found", __func__); + LOG_WARN(LOG_TAG, "%s no more services found", __func__); #if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE) bta_gattc_display_cache_server(p_srvc_cb->p_srvc_cache); diff --git a/bta/hh/bta_hh_api.c b/bta/hh/bta_hh_api.c index 1fdbc2928..0df20f369 100644 --- a/bta/hh/bta_hh_api.c +++ b/bta/hh/bta_hh_api.c @@ -26,9 +26,9 @@ #if defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE) +#include #include #include -#include #include "bta_hh_api.h" #include "bta_hh_int.h" @@ -68,7 +68,7 @@ void BTA_HhEnable(tBTA_SEC sec_mask, tBTA_HH_CBACK *p_cback) /* register with BTA system manager */ bta_sys_register(BTA_ID_HH, &bta_hh_reg); - LOG_INFO("%s sec_mask:0x%x p_cback:%p", __func__, sec_mask, p_cback); + LOG_INFO(LOG_TAG, "%s sec_mask:0x%x p_cback:%p", __func__, sec_mask, p_cback); p_buf = (tBTA_HH_API_ENABLE *)GKI_getbuf((UINT16)sizeof(tBTA_HH_API_ENABLE)); if (p_buf != NULL) diff --git a/bta/hh/bta_hh_le.c b/bta/hh/bta_hh_le.c index fee2cda85..dd77cd7d5 100644 --- a/bta/hh/bta_hh_le.c +++ b/bta/hh/bta_hh_le.c @@ -21,18 +21,19 @@ #if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE) -#include "bta_api.h" #include + +#include "bta_api.h" +#include "bta_gatt_api.h" +#include "bta_hh_co.h" #include "btm_api.h" #include "btm_ble_api.h" -#include "bta_hh_co.h" -#include "bta_gatt_api.h" -#include "srvc_api.h" #include "btm_int.h" +#include "osi/include/log.h" +#include "srvc_api.h" #include "utl.h" #define LOG_TAG "bt_bta_hh" -#include "osi/include/log.h" #ifndef BTA_HH_LE_RECONN #define BTA_HH_LE_RECONN TRUE @@ -629,7 +630,7 @@ tBTA_HH_STATUS bta_hh_le_read_char_dscrpt(tBTA_HH_DEV_CB *p_cb, UINT16 srvc_uuid else { #if BTA_HH_DEBUG == TRUE - LOG_WARN("%s No descriptor exists: %s(0x%04x)", __func__, + LOG_WARN(LOG_TAG, "%s No descriptor exists: %s(0x%04x)", __func__, bta_hh_uuid_to_str(char_descp_uuid), char_descp_uuid); #endif } @@ -1142,7 +1143,7 @@ void bta_hh_le_expl_rpt(tBTA_HH_DEV_CB *p_dev_cb, } while (1); - LOG_INFO("%s all BLE reports searched", __func__); + LOG_INFO(LOG_TAG, "%s all BLE reports searched", __func__); bta_hh_le_read_rpt_ref_descr(p_dev_cb, &p_dev_cb->hid_srvc[p_dev_cb->cur_srvc_index].report[0]); diff --git a/bta/sys/bta_sys_main.c b/bta/sys/bta_sys_main.c index f05ddac52..4c4f984be 100644 --- a/bta/sys/bta_sys_main.c +++ b/bta/sys/bta_sys_main.c @@ -21,29 +21,30 @@ * This is the main implementation file for the BTA system manager. * ******************************************************************************/ -#define LOG_TAG "bt_bta_sys_main" #include #include #include -#include "osi/include/alarm.h" -#include "btm_api.h" #include "bta_api.h" #include "bta_sys.h" #include "bta_sys_int.h" - -#include "osi/include/fixed_queue.h" +#include "btm_api.h" #include "gki.h" -#include "osi/include/hash_map.h" -#include "osi/include/osi.h" +#include "osi/include/alarm.h" +#include "osi/include/fixed_queue.h" #include "osi/include/hash_functions.h" +#include "osi/include/hash_map.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "osi/include/thread.h" +#include "utl.h" + #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) #include "bta_ar_api.h" #endif -#include "utl.h" + +#define LOG_TAG "bt_bta_sys_main" /* system manager control block definition */ #if BTA_DYNAMIC_MEMORY == FALSE @@ -630,7 +631,7 @@ void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms) { alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_ERROR("%s unable to create alarm.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create alarm.", __func__); return; } @@ -653,7 +654,7 @@ void bta_sys_stop_timer(TIMER_LIST_ENT *p_tle) { alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_DEBUG("%s expected alarm was not in bta alarm hash map.", __func__); + LOG_DEBUG(LOG_TAG, "%s expected alarm was not in bta alarm hash map.", __func__); return; } alarm_cancel(alarm); diff --git a/btcore/src/counter.c b/btcore/src/counter.c index 89f967d34..13272cbbf 100644 --- a/btcore/src/counter.c +++ b/btcore/src/counter.c @@ -26,15 +26,15 @@ #include #include +#include "btcore/include/counter.h" +#include "btcore/include/module.h" #include "osi/include/allocator.h" #include "osi/include/atomic.h" -#include "btcore/include/counter.h" +#include "osi/include/hash_functions.h" #include "osi/include/hash_map.h" #include "osi/include/list.h" -#include "btcore/include/module.h" -#include "osi/include/osi.h" -#include "osi/include/hash_functions.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "osi/include/socket.h" #include "osi/include/thread.h" @@ -125,12 +125,12 @@ static future_t *counter_init(void) { hash_map_counter_ = hash_map_new(COUNTER_NUM_BUCKETS, hash_function_string, NULL, hash_element_free_, NULL); if (hash_map_counter_ == NULL) { - LOG_ERROR("%s unable to allocate resources", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate resources", __func__); return future_new_immediate(FUTURE_FAIL); } if (!counter_socket_open()) { - LOG_ERROR("%s unable to open counter port", __func__); + LOG_ERROR(LOG_TAG, "%s unable to open counter port", __func__); return future_new_immediate(FUTURE_FAIL); } return future_new_immediate(FUTURE_SUCCESS); @@ -223,13 +223,13 @@ static counter_t *name_to_counter_(const char *name) { counter = counter_new_(0); if (!counter) { - LOG_ERROR("%s unable to create new counter name:%s", __func__, name); + LOG_ERROR(LOG_TAG, "%s unable to create new counter name:%s", __func__, name); goto exit; } hash_element_t *element = hash_element_new_(); if (!element) { - LOG_ERROR("%s unable to create counter element name:%s", __func__, name); + LOG_ERROR(LOG_TAG, "%s unable to create counter element name:%s", __func__, name); counter_free_(counter); counter = NULL; goto exit; @@ -238,7 +238,7 @@ static counter_t *name_to_counter_(const char *name) { element->key = name; element->val = counter; if (!hash_map_set(hash_map_counter_, name, counter)) { - LOG_ERROR("%s unable to set new counter into hash map name:%s", __func__, name); + LOG_ERROR(LOG_TAG, "%s unable to set new counter into hash map name:%s", __func__, name); hash_element_free_(element); counter_free_(counter); counter = NULL; @@ -265,28 +265,28 @@ static bool counter_socket_open(void) { clients_ = list_new(client_free); if (!clients_) { - LOG_ERROR("%s unable to create counter clients list", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create counter clients list", __func__); goto error; } thread_ = thread_new("counter_socket"); if (!thread_) { - LOG_ERROR("%s unable to create counter thread", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create counter thread", __func__); goto error; } listen_socket_ = socket_new(); if (!listen_socket_) { - LOG_ERROR("%s unable to create listen socket", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create listen socket", __func__); goto error; } if (!socket_listen(listen_socket_, LISTEN_PORT)) { - LOG_ERROR("%s unable to setup listen socket", __func__); + LOG_ERROR(LOG_TAG, "%s unable to setup listen socket", __func__); goto error; } - LOG_INFO("%s opened counter server socket", __func__); + LOG_INFO(LOG_TAG, "%s opened counter server socket", __func__); socket_register(listen_socket_, thread_get_reactor(thread_), NULL, accept_ready, NULL); return true; @@ -304,7 +304,7 @@ static void counter_socket_close(void) { thread_ = NULL; clients_ = NULL; - LOG_INFO("%s closed counter server socket", __func__); + LOG_INFO(LOG_TAG, "%s closed counter server socket", __func__); } static bool monitor_counter_iter_cb(const char *name, counter_data_t val, void *context) { @@ -326,14 +326,14 @@ static void accept_ready(socket_t *socket, UNUSED_ATTR void *context) { assert(socket != NULL); assert(socket == listen_socket_); - LOG_INFO("%s accepted OSI monitor socket", __func__); + LOG_INFO(LOG_TAG, "%s accepted OSI monitor socket", __func__); socket = socket_accept(socket); if (!socket) return; client_t *client = (client_t *)osi_calloc(sizeof(client_t)); if (!client) { - LOG_ERROR("%s unable to allocate memory for client", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for client", __func__); socket_free(socket); return; } @@ -341,7 +341,7 @@ static void accept_ready(socket_t *socket, UNUSED_ATTR void *context) { client->socket = socket; if (!list_append(clients_, client)) { - LOG_ERROR("%s unable to add client to list", __func__); + LOG_ERROR(LOG_TAG, "%s unable to add client to list", __func__); client_free(client); return; } diff --git a/btcore/src/module.c b/btcore/src/module.c index 745a36893..341bc824d 100644 --- a/btcore/src/module.c +++ b/btcore/src/module.c @@ -23,12 +23,12 @@ #include #include -#include "osi/include/allocator.h" -#include "osi/include/hash_map.h" #include "btcore/include/module.h" -#include "osi/include/osi.h" +#include "osi/include/allocator.h" #include "osi/include/hash_functions.h" +#include "osi/include/hash_map.h" #include "osi/include/log.h" +#include "osi/include/osi.h" typedef enum { MODULE_STATE_NONE = 0, @@ -79,7 +79,7 @@ bool module_init(const module_t *module) { assert(get_module_state(module) == MODULE_STATE_NONE); if (!call_lifecycle_function(module->init)) { - LOG_ERROR("%s failed to initialize \"%s\"", __func__, module->name); + LOG_ERROR(LOG_TAG, "%s failed to initialize \"%s\"", __func__, module->name); return false; } @@ -96,7 +96,7 @@ bool module_start_up(const module_t *module) { assert(get_module_state(module) == MODULE_STATE_INITIALIZED || module->init == NULL); if (!call_lifecycle_function(module->start_up)) { - LOG_ERROR("%s failed to start up \"%s\"", __func__, module->name); + LOG_ERROR(LOG_TAG, "%s failed to start up \"%s\"", __func__, module->name); return false; } @@ -115,7 +115,7 @@ void module_shut_down(const module_t *module) { return; if (!call_lifecycle_function(module->shut_down)) - LOG_ERROR("%s found \"%s\" reported failure during shutdown. Continuing anyway.", __func__, module->name); + LOG_ERROR(LOG_TAG, "%s found \"%s\" reported failure during shutdown. Continuing anyway.", __func__, module->name); set_module_state(module, MODULE_STATE_INITIALIZED); } @@ -131,7 +131,7 @@ void module_clean_up(const module_t *module) { return; if (!call_lifecycle_function(module->clean_up)) - LOG_ERROR("%s found \"%s\" reported failure during cleanup. Continuing anyway.", __func__, module->name); + LOG_ERROR(LOG_TAG, "%s found \"%s\" reported failure during cleanup. Continuing anyway.", __func__, module->name); set_module_state(module, MODULE_STATE_NONE); } diff --git a/btif/include/btif_common.h b/btif/include/btif_common.h index 2c4276d92..0833f7858 100644 --- a/btif/include/btif_common.h +++ b/btif/include/btif_common.h @@ -21,23 +21,19 @@ #define BTIF_COMMON_H #include + #include #include "bt_types.h" #include "bta_api.h" #include "osi.h" - -#ifndef LOG_TAG -#error "LOG_TAG not defined, please add in .c file prior to including bt_common.h" -#endif - #include "osi/include/log.h" /******************************************************************************* ** Constants & Macros ********************************************************************************/ -#define ASSERTC(cond, msg, val) if (!(cond)) { LOG_ERROR( \ +#define ASSERTC(cond, msg, val) if (!(cond)) { LOG_ERROR(LOG_TAG, \ "### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);} /* Calculate start of event enumeration; id is top 8 bits of event */ diff --git a/btif/include/btif_sock_util.h b/btif/include/btif_sock_util.h index eff18d2d3..eb915f960 100644 --- a/btif/include/btif_sock_util.h +++ b/btif/include/btif_sock_util.h @@ -27,7 +27,7 @@ #ifndef BTIF_SOCK_UTIL_H #define BTIF_SOCK_UTIL_H -#include "osi/include/log.h" +#include void dump_bin(const char* title, const char* data, int size); diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c index 015da3810..6312aceea 100644 --- a/btif/src/bluetooth.c +++ b/btif/src/bluetooth.c @@ -119,7 +119,7 @@ static bool interface_ready(void) { *****************************************************************************/ static int init(bt_callbacks_t *callbacks) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); if (interface_ready()) return BT_STATUS_DONE; @@ -143,7 +143,7 @@ static int init(bt_callbacks_t *callbacks) { } static int enable(void) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); if (!interface_ready()) return BT_STATUS_NOT_READY; @@ -325,7 +325,7 @@ static void dump(int fd) static const void* get_profile_interface (const char *profile_id) { - LOG_INFO("get_profile_interface %s", profile_id); + LOG_INFO(LOG_TAG, "get_profile_interface %s", profile_id); /* sanity check */ if (interface_ready() == FALSE) @@ -375,7 +375,7 @@ static const void* get_profile_interface (const char *profile_id) int dut_mode_configure(uint8_t enable) { - LOG_INFO("dut_mode_configure"); + LOG_INFO(LOG_TAG, "dut_mode_configure"); /* sanity check */ if (interface_ready() == FALSE) @@ -386,7 +386,7 @@ int dut_mode_configure(uint8_t enable) int dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) { - LOG_INFO("dut_mode_send"); + LOG_INFO(LOG_TAG, "dut_mode_send"); /* sanity check */ if (interface_ready() == FALSE) @@ -398,7 +398,7 @@ int dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) #if BLE_INCLUDED == TRUE int le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { - LOG_INFO("le_test_mode"); + LOG_INFO(LOG_TAG, "le_test_mode"); /* sanity check */ if (interface_ready() == FALSE) @@ -410,7 +410,7 @@ int le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) int config_hci_snoop_log(uint8_t enable) { - LOG_INFO("config_hci_snoop_log"); + LOG_INFO(LOG_TAG, "config_hci_snoop_log"); if (!interface_ready()) return BT_STATUS_NOT_READY; diff --git a/btif/src/btif_config.c b/btif/src/btif_config.c index f47b37fbb..260b87d5d 100644 --- a/btif/src/btif_config.c +++ b/btif/src/btif_config.c @@ -16,8 +16,6 @@ * ******************************************************************************/ -#define LOG_TAG "bt_btif_config" - #include #include #include @@ -25,19 +23,20 @@ #include #include -#include "osi/include/alarm.h" -#include "osi/include/allocator.h" +#include "bt_types.h" #include "btcore/include/bdaddr.h" +#include "btcore/include/module.h" #include "btif_config.h" #include "btif_config_transcode.h" #include "btif_util.h" +#include "osi/include/alarm.h" +#include "osi/include/allocator.h" #include "osi/include/compat.h" #include "osi/include/config.h" -#include "btcore/include/module.h" -#include "osi/include/osi.h" #include "osi/include/log.h" +#include "osi/include/osi.h" -#include "bt_types.h" +#define LOG_TAG "bt_btif_config" static const char *CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf"; static const char *LEGACY_CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.xml"; @@ -61,7 +60,7 @@ bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type) if (!btif_config_get_int(bd_addr_str, "DevType", p_device_type)) return FALSE; - LOG_DEBUG("%s: Device [%s] type %d", __FUNCTION__, bd_addr_str, *p_device_type); + LOG_DEBUG(LOG_TAG, "%s: Device [%s] type %d", __FUNCTION__, bd_addr_str, *p_device_type); return TRUE; } @@ -79,7 +78,7 @@ bool btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type) if (!btif_config_get_int(bd_addr_str, "AddrType", p_addr_type)) return FALSE; - LOG_DEBUG("%s: Device [%s] address type %d", __FUNCTION__, bd_addr_str, *p_addr_type); + LOG_DEBUG(LOG_TAG, "%s: Device [%s] address type %d", __FUNCTION__, bd_addr_str, *p_addr_type); return TRUE; } @@ -93,13 +92,13 @@ static future_t *init(void) { pthread_mutex_init(&lock, NULL); config = config_new(CONFIG_FILE_PATH); if (!config) { - LOG_WARN("%s unable to load config file; attempting to transcode legacy file.", __func__); + LOG_WARN(LOG_TAG, "%s unable to load config file; attempting to transcode legacy file.", __func__); config = btif_config_transcode(LEGACY_CONFIG_FILE_PATH); if (!config) { - LOG_WARN("%s unable to transcode legacy file, starting unconfigured.", __func__); + LOG_WARN(LOG_TAG, "%s unable to transcode legacy file, starting unconfigured.", __func__); config = config_new_empty(); if (!config) { - LOG_ERROR("%s unable to allocate a config object.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate a config object.", __func__); goto error; } } @@ -113,7 +112,7 @@ static future_t *init(void) { // write back to disk. alarm_timer = alarm_new(); if (!alarm_timer) { - LOG_ERROR("%s unable to create alarm.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create alarm.", __func__); goto error; } diff --git a/btif/src/btif_config_transcode.cpp b/btif/src/btif_config_transcode.cpp index fb38a4a4f..c402a48c8 100644 --- a/btif/src/btif_config_transcode.cpp +++ b/btif/src/btif_config_transcode.cpp @@ -31,19 +31,19 @@ extern "C" config_t *btif_config_transcode(const char *xml_filename) { XMLDocument document; int error = document.LoadFile(xml_filename); if (error != XML_SUCCESS) { - LOG_ERROR("%s unable to load XML file '%s': %d", __func__, xml_filename, error); + LOG_ERROR(LOG_TAG, "%s unable to load XML file '%s': %d", __func__, xml_filename, error); return NULL; } XMLElement *rootElement = document.RootElement(); if (!rootElement) { - LOG_ERROR("%s unable to find root element; assuming corrupted config file.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to find root element; assuming corrupted config file.", __func__); return NULL; } config_t *config = config_new_empty(); if (!config) { - LOG_ERROR("%s unable to allocate config object.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate config object.", __func__); return NULL; } diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c index 995066289..dcf981efe 100644 --- a/btif/src/btif_core.c +++ b/btif/src/btif_core.c @@ -45,9 +45,6 @@ #include #endif /* !defined(OS_GENERIC) */ -#define LOG_TAG "bt_btif_core" -#include "btcore/include/bdaddr.h" - #include "bdaddr.h" #include "bt_utils.h" #include "bta_api.h" @@ -55,21 +52,21 @@ #include "btif_api.h" #include "btif_av.h" #include "btif_config.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 "device/include/controller.h" +#include "gki.h" #include "osi/include/fixed_queue.h" #include "osi/include/future.h" -#include "gki.h" -#include "osi/include/osi.h" #include "osi/include/log.h" -#include "stack_manager.h" +#include "osi/include/osi.h" #include "osi/include/thread.h" +#include "stack_manager.h" /************************************************************************************ ** Constants & Macros @@ -79,6 +76,8 @@ #define BTE_DID_CONF_FILE "/etc/bluetooth/bt_did.conf" #endif +#define LOG_TAG "bt_btif_core" + /************************************************************************************ ** Local type definitions ************************************************************************************/ @@ -453,7 +452,7 @@ bt_status_t btif_init_bluetooth() { bt_jni_workqueue_thread = thread_new(BT_JNI_WORKQUEUE_NAME); if (bt_jni_workqueue_thread == NULL) { - LOG_ERROR("%s Unable to create thread %s", __func__, BT_JNI_WORKQUEUE_NAME); + LOG_ERROR(LOG_TAG, "%s Unable to create thread %s", __func__, BT_JNI_WORKQUEUE_NAME); goto error_exit; } diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c index e88e774cc..4607ef8a5 100644 --- a/btif/src/btif_dm.c +++ b/btif/src/btif_dm.c @@ -25,8 +25,6 @@ * ***********************************************************************************/ -#define LOG_TAG "bt_btif_dm" - #include #include #include @@ -46,23 +44,23 @@ #include #endif /* !defined(OS_GENERIC) */ -#include "gki.h" -#include "btu.h" -#include "btcore/include/bdaddr.h" +#include "bdaddr.h" #include "bta_api.h" +#include "bta_gatt_api.h" #include "btif_api.h" -#include "btif_util.h" +#include "btif_config.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 "include/stack_config.h" - -#include "osi/include/log.h" +#include "btif_storage.h" +#include "btif_util.h" +#include "btu.h" +#include "gki.h" #include "osi/include/allocator.h" +#include "osi/include/log.h" +#include "stack_config.h" + +#define LOG_TAG "bt_btif_dm" /****************************************************************************** ** Device specific workarounds @@ -422,7 +420,7 @@ BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod) sizeof(uint32_t), &remote_cod); if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS) { - LOG_INFO("%s remote_cod = 0x%08x cod = 0x%08x", __func__, remote_cod, cod); + LOG_INFO(LOG_TAG, "%s remote_cod = 0x%08x cod = 0x%08x", __func__, remote_cod, cod); if ((remote_cod & 0x7ff) == cod) return TRUE; } @@ -569,7 +567,7 @@ static void btif_update_remote_version_property(bt_bdaddr_t *p_bd) btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)p_bd, &lmp_ver, &mfct_set, &lmp_subver); - LOG_DEBUG("remote version info [%s]: %x, %x, %x", bdaddr_to_string(p_bd, bdstr, sizeof(bdstr)), + LOG_DEBUG(LOG_TAG, "remote version info [%s]: %x, %x, %x", bdaddr_to_string(p_bd, bdstr, sizeof(bdstr)), lmp_ver, mfct_set, lmp_subver); if (btm_status == BTM_SUCCESS) @@ -1030,7 +1028,7 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req) cod = devclass2uint(p_ssp_cfm_req->dev_class); if (cod == 0) { - LOG_DEBUG("%s cod is 0, set as unclassified", __func__); + LOG_DEBUG(LOG_TAG, "%s cod is 0, set as unclassified", __func__); cod = COD_UNCLASSIFIED; } @@ -1065,7 +1063,7 @@ static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif) cod = devclass2uint(p_ssp_key_notif->dev_class); if (cod == 0) { - LOG_DEBUG("%s cod is 0, set as unclassified", __func__); + LOG_DEBUG(LOG_TAG, "%s cod is 0, set as unclassified", __func__); cod = COD_UNCLASSIFIED; } @@ -1135,14 +1133,14 @@ static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr, COD_HID_MAJOR)) { - LOG_WARN("%s:skip SDP", __FUNCTION__); + LOG_WARN(LOG_TAG, "%s:skip SDP", __FUNCTION__); skip_sdp = TRUE; } if(!pairing_cb.is_local_initiated && skip_sdp) { bond_state_changed(status, &bd_addr, state); - LOG_WARN("%s: Incoming HID Connection",__FUNCTION__); + LOG_WARN(LOG_TAG, "%s: Incoming HID Connection",__FUNCTION__); bt_property_t prop; bt_bdaddr_t bd_addr; bt_uuid_t uuid; @@ -1325,7 +1323,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) cod = devclass2uint (p_search_data->inq_res.dev_class); if (cod == 0) { - LOG_DEBUG("%s cod is 0, set as unclassified", __func__); + LOG_DEBUG(LOG_TAG, "%s cod is 0, set as unclassified", __func__); cod = COD_UNCLASSIFIED; } @@ -1483,7 +1481,7 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) { char temp[256]; uuid_to_string_legacy((bt_uuid_t*)(p_data->disc_res.p_uuid_list + (i*MAX_UUID_SIZE)), temp); - LOG_INFO("%s index:%d uuid:%s", __func__, i, temp); + LOG_INFO(LOG_TAG, "%s index:%d uuid:%s", __func__, i, temp); } } @@ -1550,7 +1548,7 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) } uuid_to_string_legacy(&uuid, temp); - LOG_INFO("%s uuid:%s", __func__, temp); + LOG_INFO(LOG_TAG, "%s uuid:%s", __func__, temp); bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr); prop.type = BT_PROPERTY_UUIDS; diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c index aaacbcc21..3ba95de0e 100644 --- a/btif/src/btif_gatt_client.c +++ b/btif/src/btif_gatt_client.c @@ -31,26 +31,23 @@ #include #include -#define LOG_TAG "bt_btif_gattc" - #include "btcore/include/bdaddr.h" #include "btif_common.h" #include "btif_util.h" #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) -#include "btif_gatt_multi_adv_util.h" #include + #include "bta_api.h" #include "bta_gatt_api.h" -#include "btif_storage.h" #include "btif_config.h" - +#include "btif_dm.h" #include "btif_gatt.h" +#include "btif_gatt_multi_adv_util.h" #include "btif_gatt_util.h" -#include "btif_dm.h" #include "btif_storage.h" - +#include "btif_storage.h" #include "osi/include/log.h" #include "vendor_api.h" @@ -58,12 +55,14 @@ ** Constants & Macros ********************************************************************************/ +#define LOG_TAG "bt_btif_gattc" + #define CHECK_BTGATT_INIT() if (bt_gatt_callbacks == NULL)\ {\ - LOG_WARN("%s: BTGATT not initialized", __FUNCTION__);\ + LOG_WARN(LOG_TAG, "%s: BTGATT not initialized", __FUNCTION__);\ return BT_STATUS_NOT_READY;\ } else {\ - LOG_VERBOSE("%s", __FUNCTION__);\ + LOG_VERBOSE(LOG_TAG, "%s", __FUNCTION__);\ } #define BLE_RESOLVE_ADDR_MSB 0x40 /* bit7, bit6 is 01 to be resolvable random */ @@ -401,7 +400,7 @@ static void btif_gattc_add_remote_bdaddr (BD_ADDR p_bda, uint8_t addr_type) memcpy(p_dev_cb->remote_dev[i].bd_addr.address, p_bda, BD_ADDR_LEN); p_dev_cb->addr_type = addr_type; p_dev_cb->remote_dev[i].in_use = TRUE; - LOG_VERBOSE("%s device added idx=%d", __FUNCTION__, i ); + LOG_VERBOSE(LOG_TAG, "%s device added idx=%d", __FUNCTION__, i ); break; } } @@ -412,7 +411,7 @@ static void btif_gattc_add_remote_bdaddr (BD_ADDR p_bda, uint8_t addr_type) memcpy(p_dev_cb->remote_dev[i].bd_addr.address, p_bda, BD_ADDR_LEN); p_dev_cb->addr_type = addr_type; p_dev_cb->remote_dev[i].in_use = TRUE; - LOG_VERBOSE("%s device overwrite idx=%d", __FUNCTION__, i ); + LOG_VERBOSE(LOG_TAG, "%s device overwrite idx=%d", __FUNCTION__, i ); p_dev_cb->next_storage_idx++; if (p_dev_cb->next_storage_idx >= BTIF_GATT_MAX_OBSERVED_DEV) p_dev_cb->next_storage_idx = 0; @@ -453,7 +452,7 @@ static void btif_gattc_update_properties ( btif_gattc_cb_t *p_btif_cb ) memcpy(bdname.name, p_eir_remote_name, remote_name_len); bdname.name[remote_name_len]='\0'; - LOG_DEBUG("%s BLE device name=%s len=%d dev_type=%d", __FUNCTION__, bdname.name, + LOG_DEBUG(LOG_TAG, "%s BLE device name=%s len=%d dev_type=%d", __FUNCTION__, bdname.name, remote_name_len, p_btif_cb->device_type ); btif_dm_update_ble_remote_properties( p_btif_cb->bd_addr.address, bdname.name, p_btif_cb->device_type); @@ -464,7 +463,7 @@ static void btif_gattc_update_properties ( btif_gattc_cb_t *p_btif_cb ) static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) { - LOG_VERBOSE("%s: Event %d", __FUNCTION__, event); + LOG_VERBOSE(LOG_TAG, "%s: Event %d", __FUNCTION__, event); tBTA_GATTC *p_data = (tBTA_GATTC*) p_param; switch (event) @@ -606,7 +605,7 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) } case BTA_GATTC_ACL_EVT: - LOG_DEBUG("BTA_GATTC_ACL_EVT: status = %d", p_data->status); + LOG_DEBUG(LOG_TAG, "BTA_GATTC_ACL_EVT: status = %d", p_data->status); /* Ignore for now */ break; @@ -845,7 +844,7 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) } default: - LOG_ERROR("%s: Unhandled event (%d)!", __FUNCTION__, event); + LOG_ERROR(LOG_TAG, "%s: Unhandled event (%d)!", __FUNCTION__, event); break; } @@ -1160,7 +1159,7 @@ static void btgattc_handle_event(uint16_t event, char* p_param) btif_gattc_cb_t* p_cb = (btif_gattc_cb_t*) p_param; if (!p_cb) return; - LOG_VERBOSE("%s: Event %d", __FUNCTION__, event); + LOG_VERBOSE(LOG_TAG, "%s: Event %d", __FUNCTION__, event); switch (event) { @@ -1553,7 +1552,7 @@ static void btgattc_handle_event(uint16_t event, char* p_param) } default: - LOG_ERROR("%s: Unknown filter type (%d)!", __FUNCTION__, p_cb->action); + LOG_ERROR(LOG_TAG, "%s: Unknown filter type (%d)!", __FUNCTION__, p_cb->action); break; } break; @@ -1756,7 +1755,7 @@ static void btgattc_handle_event(uint16_t event, char* p_param) } default: - LOG_ERROR("%s: Unknown event (%d)!", __FUNCTION__, event); + LOG_ERROR(LOG_TAG, "%s: Unknown event (%d)!", __FUNCTION__, event); break; } diff --git a/btif/src/btif_gatt_server.c b/btif/src/btif_gatt_server.c index 489869a71..077623862 100644 --- a/btif/src/btif_gatt_server.c +++ b/btif/src/btif_gatt_server.c @@ -25,41 +25,41 @@ * ***********************************************************************************/ -#include -#include #include #include #include #include -#define LOG_TAG "bt_btif_gatt" +#include +#include #include "btif_common.h" #include "btif_util.h" #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) -#include "gki.h" #include "bta_api.h" #include "bta_gatt_api.h" -#include "btif_dm.h" -#include "btif_storage.h" #include "btif_config.h" - +#include "btif_dm.h" #include "btif_gatt.h" #include "btif_gatt_util.h" +#include "btif_storage.h" +#include "gki.h" #include "osi/include/log.h" /************************************************************************************ ** Constants & Macros ************************************************************************************/ +#define LOG_TAG "bt_btif_gatt" + #define CHECK_BTGATT_INIT() if (bt_gatt_callbacks == NULL)\ {\ - LOG_WARN("%s: BTGATT not initialized", __FUNCTION__);\ + LOG_WARN(LOG_TAG, "%s: BTGATT not initialized", __FUNCTION__);\ return BT_STATUS_NOT_READY;\ } else {\ - LOG_VERBOSE("%s", __FUNCTION__);\ + LOG_VERBOSE(LOG_TAG, "%s", __FUNCTION__);\ } @@ -169,7 +169,7 @@ static void btapp_gatts_free_req_data(UINT16 event, tBTA_GATTS *p_data) static void btapp_gatts_handle_cback(uint16_t event, char* p_param) { - LOG_VERBOSE("%s: Event %d", __FUNCTION__, event); + LOG_VERBOSE(LOG_TAG, "%s: Event %d", __FUNCTION__, event); tBTA_GATTS *p_data = (tBTA_GATTS*)p_param; switch (event) @@ -344,11 +344,11 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param) case BTA_GATTS_OPEN_EVT: case BTA_GATTS_CANCEL_OPEN_EVT: case BTA_GATTS_CLOSE_EVT: - LOG_DEBUG("%s: Empty event (%d)!", __FUNCTION__, event); + LOG_DEBUG(LOG_TAG, "%s: Empty event (%d)!", __FUNCTION__, event); break; default: - LOG_ERROR("%s: Unhandled event (%d)!", __FUNCTION__, event); + LOG_ERROR(LOG_TAG, "%s: Unhandled event (%d)!", __FUNCTION__, event); break; } @@ -368,7 +368,7 @@ static void btgatts_handle_event(uint16_t event, char* p_param) btif_gatts_cb_t* p_cb = (btif_gatts_cb_t*)p_param; if (!p_cb) return; - LOG_VERBOSE("%s: Event %d", __FUNCTION__, event); + LOG_VERBOSE(LOG_TAG, "%s: Event %d", __FUNCTION__, event); switch (event) { @@ -508,7 +508,7 @@ static void btgatts_handle_event(uint16_t event, char* p_param) } default: - LOG_ERROR("%s: Unknown event (%d)!", __FUNCTION__, event); + LOG_ERROR(LOG_TAG, "%s: Unknown event (%d)!", __FUNCTION__, event); break; } } diff --git a/btif/src/btif_gatt_test.c b/btif/src/btif_gatt_test.c index 4ccf5b04d..f38e52ab0 100644 --- a/btif/src/btif_gatt_test.c +++ b/btif/src/btif_gatt_test.c @@ -17,14 +17,13 @@ ******************************************************************************/ -#include -#include #include #include #include #include -#define LOG_TAG "bt_btif_gatt" +#include +#include #include "btif_common.h" #include "btif_util.h" @@ -33,16 +32,16 @@ #include "bta_api.h" #include "bta_gatt_api.h" -#include "btif_storage.h" #include "bte_appl.h" - +#include "btif_dm.h" #include "btif_gatt.h" #include "btif_gatt_util.h" -#include "btif_dm.h" - +#include "btif_storage.h" #include "gatt_api.h" #include "osi/include/log.h" +#define LOG_TAG "bt_btif_gatt" + /******************************************************************************* * Typedefs & Macros *******************************************************************************/ @@ -108,14 +107,14 @@ static void btif_test_connect_cback(tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_i UNUSED(reason); UNUSED (transport); - LOG_DEBUG("%s: conn_id=%d, connected=%d", __FUNCTION__, conn_id, connected); + LOG_DEBUG(LOG_TAG, "%s: conn_id=%d, connected=%d", __FUNCTION__, conn_id, connected); test_cb.conn_id = connected ? conn_id : 0; } static void btif_test_command_complete_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data) { - LOG_DEBUG ("%s: op_code=0x%02x, conn_id=0x%x. status=0x%x", + LOG_DEBUG(LOG_TAG, "%s: op_code=0x%02x, conn_id=0x%x. status=0x%x", __FUNCTION__, op, conn_id, status); switch (op) @@ -132,7 +131,7 @@ static void btif_test_command_complete_cback(UINT16 conn_id, tGATTC_OPTYPE op, break; default: - LOG_DEBUG ("%s: Unknown op_code (0x%02x)", __FUNCTION__, op); + LOG_DEBUG(LOG_TAG, "%s: Unknown op_code (0x%02x)", __FUNCTION__, op); break; } } @@ -144,50 +143,50 @@ static void btif_test_discovery_result_cback(UINT16 conn_id, tGATT_DISC_TYPE dis char str_buf[50]; UNUSED(conn_id); - LOG_DEBUG("------ GATT Discovery result %-22s -------", disc_name[disc_type]); - LOG_DEBUG(" Attribute handle: 0x%04x (%d)", p_data->handle, p_data->handle); + LOG_DEBUG(LOG_TAG, "------ GATT Discovery result %-22s -------", disc_name[disc_type]); + LOG_DEBUG(LOG_TAG, " Attribute handle: 0x%04x (%d)", p_data->handle, p_data->handle); if (disc_type != GATT_DISC_CHAR_DSCPT) { - LOG_DEBUG(" Attribute type: %s", format_uuid(p_data->type, str_buf)); + LOG_DEBUG(LOG_TAG, " Attribute type: %s", format_uuid(p_data->type, str_buf)); } switch (disc_type) { case GATT_DISC_SRVC_ALL: - LOG_DEBUG(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", + LOG_DEBUG(LOG_TAG, " Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", p_data->handle, p_data->value.group_value.e_handle, p_data->handle, p_data->value.group_value.e_handle); - LOG_DEBUG(" Service UUID: %s", + LOG_DEBUG(LOG_TAG, " Service UUID: %s", format_uuid(p_data->value.group_value.service_type, str_buf)); break; case GATT_DISC_SRVC_BY_UUID: - LOG_DEBUG(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", + LOG_DEBUG(LOG_TAG, " Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", p_data->handle, p_data->value.handle, p_data->handle, p_data->value.handle); break; case GATT_DISC_INC_SRVC: - LOG_DEBUG(" Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", + LOG_DEBUG(LOG_TAG, " Handle range: 0x%04x ~ 0x%04x (%d ~ %d)", p_data->value.incl_service.s_handle, p_data->value.incl_service.e_handle, p_data->value.incl_service.s_handle, p_data->value.incl_service.e_handle); - LOG_DEBUG(" Service UUID: %s", + LOG_DEBUG(LOG_TAG, " Service UUID: %s", format_uuid(p_data->value.incl_service.service_type, str_buf)); break; case GATT_DISC_CHAR: - LOG_DEBUG(" Properties: 0x%02x", + LOG_DEBUG(LOG_TAG, " Properties: 0x%02x", p_data->value.dclr_value.char_prop); - LOG_DEBUG(" Characteristic UUID: %s", + LOG_DEBUG(LOG_TAG, " Characteristic UUID: %s", format_uuid(p_data->value.dclr_value.char_uuid, str_buf)); break; case GATT_DISC_CHAR_DSCPT: - LOG_DEBUG(" Descriptor UUID: %s", format_uuid(p_data->type, str_buf)); + LOG_DEBUG(LOG_TAG, " Descriptor UUID: %s", format_uuid(p_data->type, str_buf)); break; } - LOG_DEBUG("-----------------------------------------------------------"); + LOG_DEBUG(LOG_TAG, "-----------------------------------------------------------"); } static void btif_test_discovery_complete_cback(UINT16 conn_id, @@ -196,7 +195,7 @@ static void btif_test_discovery_complete_cback(UINT16 conn_id, { UNUSED(conn_id); UNUSED(disc_type); - LOG_DEBUG("%s: status=%d", __FUNCTION__, status); + LOG_DEBUG(LOG_TAG, "%s: status=%d", __FUNCTION__, status); } static tGATT_CBACK btif_test_callbacks = @@ -219,7 +218,7 @@ bt_status_t btif_gattc_test_command_impl(uint16_t command, btgatt_test_params_t* switch(command) { case 0x01: /* Enable */ { - LOG_DEBUG("%s: ENABLE - enable=%d", __FUNCTION__, params->u1); + LOG_DEBUG(LOG_TAG, "%s: ENABLE - enable=%d", __FUNCTION__, params->u1); if (params->u1) { tBT_UUID app_uuid = {LEN_UUID_128,{0xAE}}; @@ -234,7 +233,7 @@ bt_status_t btif_gattc_test_command_impl(uint16_t command, btgatt_test_params_t* case 0x02: /* Connect */ { - LOG_DEBUG("%s: CONNECT - device=%02x:%02x:%02x:%02x:%02x:%02x (dev_type=%d, addr_type=%d)", + LOG_DEBUG(LOG_TAG, "%s: CONNECT - device=%02x:%02x:%02x:%02x:%02x:%02x (dev_type=%d, addr_type=%d)", __FUNCTION__, params->bda1->address[0], params->bda1->address[1], params->bda1->address[2], params->bda1->address[3], @@ -246,14 +245,14 @@ bt_status_t btif_gattc_test_command_impl(uint16_t command, btgatt_test_params_t* if ( !GATT_Connect(test_cb.gatt_if, params->bda1->address, TRUE, BT_TRANSPORT_LE) ) { - LOG_ERROR("%s: GATT_Connect failed!", __FUNCTION__); + LOG_ERROR(LOG_TAG, "%s: GATT_Connect failed!", __FUNCTION__); } break; } case 0x03: /* Disconnect */ { - LOG_DEBUG("%s: DISCONNECT - conn_id=%d", __FUNCTION__, test_cb.conn_id); + LOG_DEBUG(LOG_TAG, "%s: DISCONNECT - conn_id=%d", __FUNCTION__, test_cb.conn_id); GATT_Disconnect(test_cb.conn_id); break; } @@ -266,7 +265,7 @@ bt_status_t btif_gattc_test_command_impl(uint16_t command, btgatt_test_params_t* if (params->u1 >= GATT_DISC_MAX) { - LOG_ERROR("%s: DISCOVER - Invalid type (%d)!", __FUNCTION__, params->u1); + LOG_ERROR(LOG_TAG, "%s: DISCOVER - Invalid type (%d)!", __FUNCTION__, params->u1); return 0; } @@ -274,7 +273,7 @@ bt_status_t btif_gattc_test_command_impl(uint16_t command, btgatt_test_params_t* param.e_handle = params->u3; btif_to_bta_uuid(¶m.service, params->uuid1); - LOG_DEBUG("%s: DISCOVER (%s), conn_id=%d, uuid=%s, handles=0x%04x-0x%04x", + LOG_DEBUG(LOG_TAG, "%s: DISCOVER (%s), conn_id=%d, uuid=%s, handles=0x%04x-0x%04x", __FUNCTION__, disc_name[params->u1], test_cb.conn_id, format_uuid(param.service, buf), params->u2, params->u3); GATTC_Discover(test_cb.conn_id, params->u1, ¶m); @@ -282,7 +281,7 @@ bt_status_t btif_gattc_test_command_impl(uint16_t command, btgatt_test_params_t* } case 0xF0: /* Pairing configuration */ - LOG_DEBUG("%s: Setting pairing config auth=%d, iocaps=%d, keys=%d/%d/%d", + LOG_DEBUG(LOG_TAG, "%s: Setting pairing config auth=%d, iocaps=%d, keys=%d/%d/%d", __FUNCTION__, params->u1, params->u2, params->u3, params->u4, params->u5); @@ -294,7 +293,7 @@ bt_status_t btif_gattc_test_command_impl(uint16_t command, btgatt_test_params_t* break; default: - LOG_ERROR("%s: UNKNOWN TEST COMMAND 0x%02x", __FUNCTION__, command); + LOG_ERROR(LOG_TAG, "%s: UNKNOWN TEST COMMAND 0x%02x", __FUNCTION__, command); break; } return 0; diff --git a/btif/src/btif_gatt_util.c b/btif/src/btif_gatt_util.c index c3efbefff..35e70bae8 100644 --- a/btif/src/btif_gatt_util.c +++ b/btif/src/btif_gatt_util.c @@ -16,29 +16,29 @@ * ******************************************************************************/ -#include -#include #include #include #include #include -#define LOG_TAG "bt_btif_gatt" +#include +#include -#include "btcore/include/bdaddr.h" +#include "bdaddr.h" #include "bta_api.h" #include "bta_gatt_api.h" #include "bta_jv_api.h" -#include "btif_storage.h" -#include "btif_config.h" - #include "btif_common.h" +#include "btif_config.h" #include "btif_dm.h" -#include "btif_util.h" #include "btif_gatt.h" #include "btif_gatt_util.h" +#include "btif_storage.h" +#include "btif_util.h" #include "gki.h" +#define LOG_TAG "bt_btif_gatt" + #if BTA_GATT_INCLUDED == TRUE #define GATTC_READ_VALUE_TYPE_VALUE 0x0000 /* Attribute value itself */ @@ -103,7 +103,7 @@ void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src) break; default: - LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len); + LOG_ERROR(LOG_TAG, "%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len); break; } } @@ -193,7 +193,7 @@ void bta_to_btif_uuid(bt_uuid_t *p_dest, tBT_UUID *p_src) break; default: - LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_src->len); + LOG_ERROR(LOG_TAG, "%s: Unknown UUID length %d!", __FUNCTION__, p_src->len); break; } } @@ -258,7 +258,7 @@ uint16_t set_read_value(btgatt_read_params_t *p_dest, tBTA_GATTC_READ *p_src) default: if (( p_src->status == BTA_GATT_OK ) &&(p_src->p_value != NULL)) { - LOG_INFO("%s unformat.len = %d ", __FUNCTION__, p_src->p_value->unformat.len); + LOG_INFO(LOG_TAG, "%s unformat.len = %d ", __FUNCTION__, p_src->p_value->unformat.len); p_dest->value.len = p_src->p_value->unformat.len; if ( p_src->p_value->unformat.len > 0 && p_src->p_value->unformat.p_value != NULL ) { diff --git a/btif/src/btif_hh.c b/btif/src/btif_hh.c index 7ba3c8f94..96980a3e4 100644 --- a/btif/src/btif_hh.c +++ b/btif/src/btif_hh.c @@ -24,27 +24,28 @@ * * ***********************************************************************************/ -#include -#include + #include #include #include #include #include -#define LOG_TAG "bt_btif_hh" +#include +#include #include "bta_api.h" #include "bta_hh_api.h" -#include "btif_storage.h" - #include "btif_common.h" -#include "btif_util.h" #include "btif_hh.h" +#include "btif_storage.h" +#include "btif_util.h" #include "gki.h" #include "l2c_api.h" #include "osi/include/log.h" +#define LOG_TAG "bt_btif_hh" + #define BTIF_HH_APP_ID_MI 0x01 #define BTIF_HH_APP_ID_KB 0x02 @@ -502,7 +503,7 @@ void btif_hh_remove_device(bt_bdaddr_t bd_addr) btif_hh_device_t *p_dev; btif_hh_added_device_t *p_added_dev; - LOG_INFO("%s: bda = %02x:%02x:%02x:%02x:%02x:%02x", __FUNCTION__, + LOG_INFO(LOG_TAG, "%s: bda = %02x:%02x:%02x:%02x:%02x:%02x", __FUNCTION__, bd_addr.address[0], bd_addr.address[1], bd_addr.address[2], bd_addr.address[3], bd_addr.address[4], bd_addr.address[5]); for (i = 0; i < BTIF_HH_MAX_ADDED_DEV; i++) { @@ -935,7 +936,7 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) return; } if (p_dev->fd < 0) { - LOG_ERROR("BTA_HH_GET_DSCP_EVT: Error, failed to find the uhid driver..."); + LOG_ERROR(LOG_TAG, "BTA_HH_GET_DSCP_EVT: Error, failed to find the uhid driver..."); return; } { @@ -1077,7 +1078,7 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) break; case BTA_HH_API_ERR_EVT : - LOG_INFO("BTA_HH API_ERR"); + LOG_INFO(LOG_TAG, "BTA_HH API_ERR"); break; @@ -1370,7 +1371,7 @@ static bt_status_t set_info (bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info ) dscp_info.descriptor.dsc_list = (UINT8 *) GKI_getbuf(dscp_info.descriptor.dl_len); if (dscp_info.descriptor.dsc_list == NULL) { - LOG_ERROR("%s: Failed to allocate DSCP for CB", __FUNCTION__); + LOG_ERROR(LOG_TAG, "%s: Failed to allocate DSCP for CB", __FUNCTION__); return BT_STATUS_FAIL; } memcpy(dscp_info.descriptor.dsc_list, &(hid_info.dsc_list), hid_info.dl_len); @@ -1564,7 +1565,7 @@ static bt_status_t set_report (bt_bdaddr_t *bd_addr, bthh_report_type_t reportTy memset(hexbuf, 0, len); //TODO hex_bytes_filled = ascii_2_hex(report, len, hexbuf); - LOG_INFO("Hex bytes filled, hex value: %d", hex_bytes_filled); + LOG_INFO(LOG_TAG, "Hex bytes filled, hex value: %d", hex_bytes_filled); if (hex_bytes_filled) { BT_HDR* p_buf = create_pbuf(hex_bytes_filled, hexbuf); if (p_buf == NULL) { diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c index 43d4a8123..2d24aae51 100644 --- a/btif/src/btif_hl.c +++ b/btif/src/btif_hl.c @@ -5017,7 +5017,7 @@ void btif_hl_soc_thread_init(void){ BTIF_TRACE_DEBUG("%s", __FUNCTION__); soc_queue = list_new(NULL); if (soc_queue == NULL) - LOG_ERROR("%s unable to allocate resources for thread", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate resources for thread", __func__); select_thread_id = create_thread(btif_hl_select_thread, NULL); } /******************************************************************************* diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c index 80b6df1ba..16fd6556b 100644 --- a/btif/src/btif_media_task.c +++ b/btif/src/btif_media_task.c @@ -26,40 +26,42 @@ ** ******************************************************************************/ -#define LOG_TAG "bt_btif_media" - #include -#include -#include -#include -#include +#include +#include #include -#include #include #include +#include +#include +#include #include -#include +#include +#include -#include "bt_target.h" -#include "osi/include/fixed_queue.h" -#include "gki.h" -#include "bta_api.h" -#include "btu.h" -#include "bta_sys.h" -#include "bta_sys_int.h" +#include -#include "bta_av_api.h" #include "a2d_api.h" -#include "a2d_sbc.h" #include "a2d_int.h" -#include "bta_av_sbc.h" +#include "a2d_sbc.h" +#include "audio_a2dp_hw.h" +#include "bt_target.h" +#include "bta_api.h" +#include "bta_av_api.h" #include "bta_av_ci.h" -#include "l2c_api.h" - +#include "bta_av_sbc.h" +#include "bta_sys.h" +#include "bta_sys_int.h" +#include "btif_av.h" #include "btif_av_co.h" #include "btif_media.h" - +#include "btif_sm.h" +#include "btif_util.h" +#include "btu.h" +#include "gki.h" +#include "l2c_api.h" #include "osi/include/alarm.h" +#include "osi/include/fixed_queue.h" #include "osi/include/log.h" #include "osi/include/thread.h" @@ -67,17 +69,12 @@ #include "sbc_encoder.h" #endif -#include -#include "audio_a2dp_hw.h" -#include "btif_av.h" -#include "btif_sm.h" -#include "btif_util.h" #if (BTA_AV_SINK_INCLUDED == TRUE) #include "oi_codec_sbc.h" #include "oi_status.h" #endif -#include "stdio.h" -#include + +#define LOG_TAG "bt_btif_media" #if (BTA_AV_SINK_INCLUDED == TRUE) OI_CODEC_SBC_DECODER_CONTEXT context; @@ -1170,7 +1167,7 @@ static void btif_media_task_aa_handle_uipc_rx_rdy(void) btif_media_aa_prep_2_send(0xFF); /* send it */ - LOG_VERBOSE("btif_media_task_aa_handle_uipc_rx_rdy calls bta_av_ci_src_data_ready"); + LOG_VERBOSE(LOG_TAG, "btif_media_task_aa_handle_uipc_rx_rdy calls bta_av_ci_src_data_ready"); bta_av_ci_src_data_ready(BTA_AV_CHNL_AUDIO); } #endif @@ -1241,7 +1238,7 @@ static void btif_media_flush_q(BUFFER_Q *p_q) static void btif_media_thread_handle_cmd(fixed_queue_t *queue, UNUSED_ATTR void *context) { BT_HDR *p_msg = (BT_HDR *)fixed_queue_dequeue(queue); - LOG_VERBOSE("btif_media_thread_handle_cmd : %d %s", p_msg->event, + LOG_VERBOSE(LOG_TAG, "btif_media_thread_handle_cmd : %d %s", p_msg->event, dump_media_event(p_msg->event)); switch (p_msg->event) @@ -1286,7 +1283,7 @@ static void btif_media_thread_handle_cmd(fixed_queue_t *queue, UNUSED_ATTR void APPL_TRACE_ERROR("ERROR in %s unknown event %d", __func__, p_msg->event); } GKI_freebuf(p_msg); - LOG_VERBOSE("%s: %s DONE", __func__, dump_media_event(p_msg->event)); + LOG_VERBOSE(LOG_TAG, "%s: %s DONE", __func__, dump_media_event(p_msg->event)); } #if (BTA_AV_SINK_INCLUDED == TRUE) @@ -1915,7 +1912,7 @@ static void btif_media_task_aa_handle_start_decoding(void) { btif_media_cb.decode_alarm = alarm_new(); if (!btif_media_cb.decode_alarm) { - LOG_ERROR("%s unable to allocate decode alarm.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate decode alarm.", __func__); return; } @@ -2131,7 +2128,7 @@ static void btif_media_task_aa_start_tx(void) btif_media_cb.media_alarm = alarm_new(); if (!btif_media_cb.media_alarm) { - LOG_ERROR("%s unable to allocate media alarm.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate media alarm.", __func__); return; } @@ -2208,7 +2205,7 @@ static UINT8 btif_get_num_aa_frame(void) } btif_media_cb.media_feeding_state.pcm.counter -= result*pcm_bytes_per_frame; - LOG_VERBOSE("WRITE %d FRAMES", result); + LOG_VERBOSE(LOG_TAG, "WRITE %d FRAMES", result); } break; @@ -2607,7 +2604,7 @@ static void btif_media_send_aa_frame(void) } /* send it */ - LOG_VERBOSE("btif_media_send_aa_frame : send %d frames", nb_frame_2_send); + LOG_VERBOSE(LOG_TAG, "btif_media_send_aa_frame : send %d frames", nb_frame_2_send); bta_av_ci_src_data_ready(BTA_AV_CHNL_AUDIO); } diff --git a/btif/src/btif_pan.c b/btif/src/btif_pan.c index 256568c0b..ad477358b 100644 --- a/btif/src/btif_pan.c +++ b/btif/src/btif_pan.c @@ -24,45 +24,46 @@ * * ***********************************************************************************/ -#include -#include #include -#include -#include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include #include -#include -#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include #include -#define LOG_TAG "bt_btif_pan" -#include "btif_common.h" -#include "btif_util.h" -#include "btm_api.h" -#include "btcore/include/bdaddr.h" -#include "device/include/controller.h" +#include +#include #include "bta_api.h" #include "bta_pan_api.h" +#include "btcore/include/bdaddr.h" +#include "btif_common.h" +#include "btif_pan_internal.h" #include "btif_sock_thread.h" #include "btif_sock_util.h" -#include "btif_pan_internal.h" +#include "btif_util.h" +#include "btm_api.h" +#include "device/include/controller.h" #include "gki.h" -#include "osi/include/osi.h" #include "osi/include/log.h" +#include "osi/include/osi.h" + +#define LOG_TAG "bt_btif_pan" #define FORWARD_IGNORE 1 #define FORWARD_SUCCESS 0 @@ -446,7 +447,7 @@ int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, UINT16 prot memcpy(packet, ð_hdr, sizeof(tETH_HDR)); if (len > TAP_MAX_PKT_WRITE_LEN) { - LOG_ERROR("btpan_tap_send eth packet size:%d is exceeded limit!", len); + LOG_ERROR(LOG_TAG, "btpan_tap_send eth packet size:%d is exceeded limit!", len); return -1; } memcpy(packet + sizeof(tETH_HDR), buf, len); @@ -608,7 +609,7 @@ static void bta_pan_callback_transfer(UINT16 event, char *p_param) bt_status_t status; btpan_conn_t *conn = btpan_find_conn_handle(p_data->open.handle); - LOG_VERBOSE("%s pan connection open status: %d", __func__, p_data->open.status); + LOG_VERBOSE(LOG_TAG, "%s pan connection open status: %d", __func__, p_data->open.status); if (p_data->open.status == BTA_PAN_SUCCESS) { state = BTPAN_STATE_CONNECTED; @@ -632,7 +633,7 @@ static void bta_pan_callback_transfer(UINT16 event, char *p_param) { btpan_conn_t* conn = btpan_find_conn_handle(p_data->close.handle); - LOG_INFO("%s: event = BTA_PAN_CLOSE_EVT handle %d", __FUNCTION__, p_data->close.handle); + LOG_INFO(LOG_TAG, "%s: event = BTA_PAN_CLOSE_EVT handle %d", __FUNCTION__, p_data->close.handle); if (conn && conn->handle >= 0) { diff --git a/btif/src/btif_profile_queue.c b/btif/src/btif_profile_queue.c index 86025efc6..66aeefdf9 100644 --- a/btif/src/btif_profile_queue.c +++ b/btif/src/btif_profile_queue.c @@ -26,17 +26,18 @@ #include #include + #include -#include -#define LOG_TAG "bt_btif_queue" #include "btif_common.h" #include "btif_profile_queue.h" #include "gki.h" -#include "osi/include/list.h" #include "osi/include/allocator.h" +#include "osi/include/list.h" #include "stack_manager.h" +#define LOG_TAG "bt_btif_queue" + /******************************************************************************* ** Local type definitions *******************************************************************************/ @@ -76,7 +77,7 @@ static void queue_int_add(connect_node_t *p_param) { for (const list_node_t *node = list_begin(connect_queue); node != list_end(connect_queue); node = list_next(node)) { if (((connect_node_t *)list_node(node))->uuid == p_param->uuid) { - LOG_INFO("%s dropping duplicate connect request for uuid: %04x", __func__, p_param->uuid); + LOG_INFO(LOG_TAG, "%s dropping duplicate connect request for uuid: %04x", __func__, p_param->uuid); return; } } diff --git a/btif/src/btif_sock.c b/btif/src/btif_sock.c index c441eebce..346e2d60c 100644 --- a/btif/src/btif_sock.c +++ b/btif/src/btif_sock.c @@ -16,22 +16,23 @@ * ******************************************************************************/ -#define LOG_TAG "bt_btif_sock" - #include + #include #include #include "bta_api.h" #include "btif_common.h" +#include "btif_sock_l2cap.h" #include "btif_sock_rfc.h" #include "btif_sock_sco.h" -#include "btif_sock_thread.h" -#include "btif_sock_l2cap.h" #include "btif_sock_sdp.h" +#include "btif_sock_thread.h" #include "btif_util.h" #include "osi/include/thread.h" +#define LOG_TAG "bt_btif_sock" + static bt_status_t btsock_listen(btsock_type_t type, const char *service_name, const uint8_t *uuid, int channel, int *sock_fd, int flags); static bt_status_t btsock_connect(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t *uuid, int channel, int *sock_fd, int flags); @@ -58,32 +59,32 @@ bt_status_t btif_sock_init(void) { btsock_thread_init(); thread_handle = btsock_thread_create(btsock_signaled, NULL); if (thread_handle == -1) { - LOG_ERROR("%s unable to create btsock_thread.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create btsock_thread.", __func__); goto error; } bt_status_t status = btsock_rfc_init(thread_handle); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s error initializing RFCOMM sockets: %d", __func__, status); + LOG_ERROR(LOG_TAG, "%s error initializing RFCOMM sockets: %d", __func__, status); goto error; } status = btsock_l2cap_init(thread_handle); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s error initializing L2CAP sockets: %d", __func__, status); + LOG_ERROR(LOG_TAG, "%s error initializing L2CAP sockets: %d", __func__, status); goto error; } thread = thread_new("btif_sock"); if (!thread) { - LOG_ERROR("%s error creating new thread.", __func__); + LOG_ERROR(LOG_TAG, "%s error creating new thread.", __func__); btsock_rfc_cleanup(); goto error; } status = btsock_sco_init(thread); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s error initializing SCO sockets: %d", __func__, status); + LOG_ERROR(LOG_TAG, "%s error initializing SCO sockets: %d", __func__, status); btsock_rfc_cleanup(); goto error; } @@ -136,7 +137,7 @@ static bt_status_t btsock_listen(btsock_type_t type, const char *service_name, c break; default: - LOG_ERROR("%s unknown/unsupported socket type: %d", __func__, type); + LOG_ERROR(LOG_TAG, "%s unknown/unsupported socket type: %d", __func__, type); status = BT_STATUS_UNSUPPORTED; break; } @@ -165,7 +166,7 @@ static bt_status_t btsock_connect(const bt_bdaddr_t *bd_addr, btsock_type_t type break; default: - LOG_ERROR("%s unknown/unsupported socket type: %d", __func__, type); + LOG_ERROR(LOG_TAG, "%s unknown/unsupported socket type: %d", __func__, type); status = BT_STATUS_UNSUPPORTED; break; } diff --git a/btif/src/btif_sock_l2cap.c b/btif/src/btif_sock_l2cap.c index 97cb37f48..d2895fd2b 100644 --- a/btif/src/btif_sock_l2cap.c +++ b/btif/src/btif_sock_l2cap.c @@ -15,41 +15,41 @@ * limitations under the License. */ -#include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +#include +#include + +#include +#include #define LOG_TAG "BTIF_SOCK" #include "osi/include/allocator.h" -#include "btif_common.h" -#include "btif_util.h" +#include "osi/include/log.h" +#include "bt_target.h" #include "bta_api.h" -#include "btif_sock_thread.h" +#include "bta_jv_api.h" +#include "bta_jv_co.h" +#include "btif_common.h" +#include "btif_sock_l2cap.h" #include "btif_sock_sdp.h" +#include "btif_sock_thread.h" #include "btif_sock_util.h" -#include "btif_sock_l2cap.h" -#include "l2cdefs.h" - -#include "bt_target.h" -#include "gki.h" -#include "hcimsgs.h" -#include "sdp_api.h" -#include "btu.h" +#include "btif_util.h" #include "btm_api.h" #include "btm_int.h" -#include "bta_jv_api.h" -#include "bta_jv_co.h" -#include "port_api.h" +#include "btu.h" +#include "gki.h" +#include "hcimsgs.h" #include "l2c_api.h" +#include "l2cdefs.h" +#include "port_api.h" +#include "sdp_api.h" -#include -#include #define asrt(s) if (!(s)) APPL_TRACE_ERROR("## %s assert %s failed at line:%d ##",__FUNCTION__, \ #s, __LINE__) @@ -82,7 +82,7 @@ typedef struct l2cap_socket { unsigned connected :1; //is connected? unsigned outgoing_congest :1; //should we hold? unsigned server_psm_sent :1; //The server shall only send PSM once. -}l2cap_socket; +} l2cap_socket; static bt_status_t btSock_start_l2cap_server_l(l2cap_socket *sock); @@ -182,12 +182,12 @@ static char packet_put_tail_l(l2cap_socket *sock, const void *data, uint32_t len struct packet *p = packet_alloc((const uint8_t*)data, len); if (sock->bytes_buffered >= L2CAP_MAX_RX_BUFFER) { - ALOGE("packet_put_tail_l: buffer overflow"); + LOG_ERROR(LOG_TAG, "packet_put_tail_l: buffer overflow"); return FALSE; } if (!p) { - ALOGE("packet_put_tail_l: unable to allocate packet..."); + LOG_ERROR(LOG_TAG, "packet_put_tail_l: unable to allocate packet..."); return FALSE; } diff --git a/btif/src/btif_sock_rfc.c b/btif/src/btif_sock_rfc.c index 8e74880a8..2723038e0 100644 --- a/btif/src/btif_sock_rfc.c +++ b/btif/src/btif_sock_rfc.c @@ -16,13 +16,9 @@ * ******************************************************************************/ -#define LOG_TAG "bt_btif_sock_rfcomm" - #include #include #include -#include -#include #include #include #include @@ -30,19 +26,17 @@ #include #include -#include "bta_api.h" +#include +#include + #include "bt_target.h" +#include "bta_api.h" #include "bta_jv_api.h" #include "bta_jv_co.h" #include "btif_common.h" #include "btif_sock_sdp.h" #include "btif_sock_thread.h" #include "btif_sock_util.h" -/* The JV interface can have only one user, hence we need to call a few - * L2CAP functions from this file. */ -#include "btif_sock_l2cap.h" - - #include "btif_util.h" #include "btm_api.h" #include "btm_int.h" @@ -51,11 +45,18 @@ #include "hcimsgs.h" #include "osi/include/compat.h" #include "osi/include/list.h" -#include "osi/include/osi.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "port_api.h" #include "sdp_api.h" +/* The JV interface can have only one user, hence we need to call a few + * L2CAP functions from this file. */ +#include "btif_sock_l2cap.h" + +#define LOG_TAG "bt_btif_sock_rfcomm" + + #define MAX_RFC_CHANNEL 30 // Maximum number of RFCOMM channels (1-30 inclusive). #define MAX_RFC_SESSION 7 // Maximum number of devices we can have an RFCOMM connection with. @@ -148,7 +149,7 @@ static rfc_slot_t *find_rfc_slot_by_id(uint32_t id) { if (rfc_slots[i].id == id) return &rfc_slots[i]; - LOG_ERROR("%s unable to find RFCOMM slot id: %d", __func__, id); + LOG_ERROR(LOG_TAG, "%s unable to find RFCOMM slot id: %d", __func__, id); return NULL; } @@ -180,13 +181,13 @@ static rfc_slot_t *alloc_rfc_slot(const bt_bdaddr_t *addr, const char *name, con rfc_slot_t *slot = find_free_slot(); if (!slot) { - LOG_ERROR("%s unable to find free RFCOMM slot.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to find free RFCOMM slot.", __func__); return NULL; } int fds[2] = { INVALID_FD, INVALID_FD }; if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) == -1) { - LOG_ERROR("%s error creating socketpair: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s error creating socketpair: %s", __func__, strerror(errno)); return NULL; } @@ -223,7 +224,7 @@ static rfc_slot_t *alloc_rfc_slot(const bt_bdaddr_t *addr, const char *name, con static rfc_slot_t *create_srv_accept_rfc_slot(rfc_slot_t *srv_rs, const bt_bdaddr_t *addr, int open_handle, int new_listen_handle) { rfc_slot_t *accept_rs = alloc_rfc_slot(addr, srv_rs->service_name, srv_rs->service_uuid, srv_rs->scn, 0, false); if (!accept_rs) { - LOG_ERROR("%s unable to allocate RFCOMM slot.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate RFCOMM slot.", __func__); return NULL; } @@ -280,7 +281,7 @@ bt_status_t btsock_rfc_listen(const char *service_name, const uint8_t *service_u rfc_slot_t *slot = alloc_rfc_slot(NULL, service_name, service_uuid, channel, flags, true); if (!slot) { - LOG_ERROR("%s unable to allocate RFCOMM slot.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate RFCOMM slot.", __func__); goto out; } APPL_TRACE_DEBUG("BTA_JvGetChannelId: service_name: %s - channel: %d", service_name, channel); @@ -319,20 +320,20 @@ bt_status_t btsock_rfc_connect(const bt_bdaddr_t *bd_addr, const uint8_t *servic rfc_slot_t *slot = alloc_rfc_slot(bd_addr, NULL, service_uuid, channel, flags, false); if (!slot) { - LOG_ERROR("%s unable to allocate RFCOMM slot.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate RFCOMM slot.", __func__); goto out; } if (is_uuid_empty(service_uuid)) { tBTA_JV_STATUS ret = BTA_JvRfcommConnect(slot->security, slot->role, slot->scn, slot->addr.address, rfcomm_cback, (void *)(uintptr_t)slot->id); if (ret != BTA_JV_SUCCESS) { - LOG_ERROR("%s unable to initiate RFCOMM connection: %d", __func__, ret); + LOG_ERROR(LOG_TAG, "%s unable to initiate RFCOMM connection: %d", __func__, ret); cleanup_rfc_slot(slot); goto out; } if (!send_app_scn(slot)) { - LOG_ERROR("%s unable to send channel number.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to send channel number.", __func__); cleanup_rfc_slot(slot); goto out; } @@ -511,7 +512,7 @@ static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN *p_open, uint32_t id) { if (send_app_connect_signal(slot->fd, &slot->addr, slot->scn, 0, -1)) slot->f.connected = true; else - LOG_ERROR("%s unable to send connect completion signal to caller.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to send connect completion signal to caller.", __func__); out:; pthread_mutex_unlock(&slot_lock); @@ -592,7 +593,7 @@ static void *rfcomm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) { break; default: - LOG_ERROR("%s unhandled event %d, slot id: %zi", __func__, event, (uintptr_t)user_data); + LOG_ERROR(LOG_TAG, "%s unhandled event %d, slot id: %zi", __func__, event, (uintptr_t)user_data); break; } return new_user_data; @@ -679,7 +680,7 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) { } } else if (slot) { // TODO(sharvil): this is really a logic error and we should probably assert. - LOG_ERROR("%s SDP response returned but RFCOMM slot %d did not request SDP record.", __func__, id); + LOG_ERROR(LOG_TAG, "%s SDP response returned but RFCOMM slot %d did not request SDP record.", __func__, id); } } else if (slot) { cleanup_rfc_slot(slot); @@ -722,7 +723,7 @@ static sent_status_t send_data_to_app(int fd, BT_HDR *p_buf) { if (sent == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) return SENT_NONE; - LOG_ERROR("%s error writing RFCOMM data back to app: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s error writing RFCOMM data back to app: %s", __func__, strerror(errno)); return SENT_FAILED; } @@ -786,7 +787,7 @@ void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t user_id) { pthread_mutex_unlock(&slot_lock); BTA_JvRfcommWrite(slot->rfc_handle, slot->id); } else { - LOG_ERROR("%s socket signaled for read while disconnected, slot: %d, channel: %d", __func__, slot->id, slot->scn); + LOG_ERROR(LOG_TAG, "%s socket signaled for read while disconnected, slot: %d, channel: %d", __func__, slot->id, slot->scn); need_close = true; } } @@ -794,7 +795,7 @@ void btsock_rfc_signaled(UNUSED_ATTR int fd, int flags, uint32_t user_id) { if (flags & SOCK_THREAD_FD_WR) { // App is ready to receive more data, tell stack to enable data flow. if (!slot->f.connected || !flush_incoming_que_on_wr_signal(slot)) { - LOG_ERROR("%s socket signaled for write while disconnected (or write failure), slot: %d, channel: %d", __func__, slot->id, slot->scn); + LOG_ERROR(LOG_TAG, "%s socket signaled for write while disconnected (or write failure), slot: %d, channel: %d", __func__, slot->id, slot->scn); need_close = true; } } @@ -859,7 +860,7 @@ int bta_co_rfc_data_outgoing_size(void *user_data, int *size) { if (ioctl(slot->fd, FIONREAD, size) == 0) { ret = true; } else { - LOG_ERROR("%s unable to determine bytes remaining to be read on fd %d: %s", __func__, slot->fd, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to determine bytes remaining to be read on fd %d: %s", __func__, slot->fd, strerror(errno)); cleanup_rfc_slot(slot); } @@ -881,7 +882,7 @@ int bta_co_rfc_data_outgoing(void *user_data, uint8_t *buf, uint16_t size) { if(received == size) { ret = true; } else { - LOG_ERROR("%s error receiving RFCOMM data from app: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s error receiving RFCOMM data from app: %s", __func__, strerror(errno)); cleanup_rfc_slot(slot); } diff --git a/btif/src/btif_sock_sco.c b/btif/src/btif_sock_sco.c index e9bff91f1..28d6e33bf 100644 --- a/btif/src/btif_sock_sco.c +++ b/btif/src/btif_sock_sco.c @@ -16,18 +16,17 @@ * ******************************************************************************/ -#define LOG_TAG "bt_btif_sock_sco" - #include #include -#include -#include #include #include #include #include #include +#include +#include + #include "btif_common.h" #include "osi/include/allocator.h" #include "osi/include/list.h" @@ -36,6 +35,8 @@ #include "osi/include/socket.h" #include "osi/include/thread.h" +#define LOG_TAG "bt_btif_sock_sco" + // This module provides a socket abstraction for SCO connections to a higher // layer. It returns file descriptors representing two types of sockets: // listening (server) and connected (client) sockets. No SCO data is @@ -143,25 +144,25 @@ static sco_socket_t *sco_socket_establish_locked(bool is_listening, const bt_bda sco_socket_t *sco_socket = NULL; if (socketpair(AF_LOCAL, SOCK_STREAM, 0, pair) == -1) { - LOG_ERROR("%s unable to allocate socket pair: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to allocate socket pair: %s", __func__, strerror(errno)); goto error; } sco_socket = sco_socket_new(); if (!sco_socket) { - LOG_ERROR("%s unable to allocate new SCO socket.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate new SCO socket.", __func__); goto error; } tBTM_STATUS status = BTM_CreateSco((uint8_t *)bd_addr, !is_listening, sco_parameters.packet_types, &sco_socket->sco_handle, connect_completed_cb, disconnect_completed_cb); if (status != BTM_CMD_STARTED) { - LOG_ERROR("%s unable to create SCO socket: %d", __func__, status); + LOG_ERROR(LOG_TAG, "%s unable to create SCO socket: %d", __func__, status); goto error; } socket_t *socket = socket_new_from_fd(pair[1]); if (!socket) { - LOG_ERROR("%s unable to allocate socket from file descriptor %d.", __func__, pair[1]); + LOG_ERROR(LOG_TAG, "%s unable to allocate socket from file descriptor %d.", __func__, pair[1]); goto error; } @@ -225,18 +226,18 @@ static void connection_request_cb(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA *data) int client_fd = INVALID_FD; if (!sco_socket) { - LOG_ERROR("%s unable to find sco_socket for handle: %hu", __func__, conn_data->sco_inx); + LOG_ERROR(LOG_TAG, "%s unable to find sco_socket for handle: %hu", __func__, conn_data->sco_inx); goto error; } if (sco_socket != listen_sco_socket) { - LOG_ERROR("%s received connection request on non-listening socket handle: %hu", __func__, conn_data->sco_inx); + LOG_ERROR(LOG_TAG, "%s received connection request on non-listening socket handle: %hu", __func__, conn_data->sco_inx); goto error; } sco_socket_t *new_sco_socket = sco_socket_establish_locked(true, NULL, &client_fd); if (!new_sco_socket) { - LOG_ERROR("%s unable to allocate new sco_socket.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate new sco_socket.", __func__); goto error; } @@ -252,7 +253,7 @@ static void connection_request_cb(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA *data) connect_signal.status = 0; if (socket_write_and_transfer_fd(sco_socket->socket, &connect_signal, sizeof(connect_signal), client_fd) != sizeof(connect_signal)) { - LOG_ERROR("%s unable to send new file descriptor to listening socket.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to send new file descriptor to listening socket.", __func__); goto error; } @@ -275,7 +276,7 @@ static void connect_completed_cb(uint16_t sco_handle) { sco_socket_t *sco_socket = sco_socket_find_locked(sco_handle); if (!sco_socket) { - LOG_ERROR("%s SCO socket not found on connect for handle: %hu", __func__, sco_handle); + LOG_ERROR(LOG_TAG, "%s SCO socket not found on connect for handle: %hu", __func__, sco_handle); goto out; } @@ -298,7 +299,7 @@ static void disconnect_completed_cb(uint16_t sco_handle) { sco_socket_t *sco_socket = sco_socket_find_locked(sco_handle); if (!sco_socket) { - LOG_ERROR("%s SCO socket not found on disconnect for handle: %hu", __func__, sco_handle); + LOG_ERROR(LOG_TAG, "%s SCO socket not found on disconnect for handle: %hu", __func__, sco_handle); goto out; } diff --git a/btif/src/btif_sock_util.c b/btif/src/btif_sock_util.c index e4c10c473..b99713115 100644 --- a/btif/src/btif_sock_util.c +++ b/btif/src/btif_sock_util.c @@ -16,15 +16,8 @@ * ******************************************************************************/ +#include "btif_sock_util.h" -/************************************************************************************ - * - * Filename: btif_hf.c - * - * Description: Handsfree Profile Bluetooth Interface - * - * - ***********************************************************************************/ #include #include #include @@ -158,14 +151,6 @@ int sock_send_fd(int sock_fd, const uint8_t* buf, int len, int send_fd) return ret_len; } -// TODO(armansito): I'm not sure why the osi log macros aren't being used here, -// but for now just redefine PRINT for non-Android platforms. -#if defined(OS_GENERIC) -#define PRINT(s) fprintf(stderr, "%s\n", s) -#else // !defined(OS_GENERIC) -#define PRINT(s) __android_log_write(ANDROID_LOG_DEBUG, NULL, s) -#endif // defined(OS_GENERIC) - static const char* hex_table = "0123456789abcdef"; static inline void byte2hex(const char* data, char** str) { @@ -190,7 +175,7 @@ void dump_bin(const char* title, const char* data, int size) char *line; int i, j, addr; const int width = 16; - LOG_DEBUG("%s, size:%d, dump started {", title, size); + LOG_DEBUG(LOG_TAG, "%s, size:%d, dump started {", title, size); if(size <= 0) return; //write offset @@ -207,7 +192,7 @@ void dump_bin(const char* title, const char* data, int size) *line++ = ' '; } *line = 0; - PRINT(line_buff); + LOG_DEBUG(LOG_TAG, "%s", line_buff); for(i = 0; i < size / width; i++) { @@ -228,7 +213,7 @@ void dump_bin(const char* title, const char* data, int size) //wirte the end of line *line = 0; //output the line - PRINT(line_buff); + LOG_DEBUG(LOG_TAG, "%s", line_buff); } //last line of left over if any int leftover = size % width; @@ -256,8 +241,8 @@ void dump_bin(const char* title, const char* data, int size) //write the end of line *line = 0; //output the line - PRINT(line_buff); + LOG_DEBUG(LOG_TAG, "%s", line_buff); } - LOG_DEBUG("%s, size:%d, dump ended }", title, size); + LOG_DEBUG(LOG_TAG, "%s, size:%d, dump ended }", title, size); } diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c index 95d61d87e..25d084de8 100644 --- a/btif/src/btif_storage.c +++ b/btif/src/btif_storage.c @@ -27,35 +27,36 @@ * * */ + +#include #include +#include #include -#include #include -#include -#include - +#include #include -#include "btif_config.h" -#define LOG_TAG "bt_btif_storage" +#include "bta_hh_api.h" +#include "btcore/include/bdaddr.h" #include "btif_api.h" +#include "btif_config.h" +#include "btif_hh.h" #include "btif_storage.h" #include "btif_util.h" -#include "btcore/include/bdaddr.h" +#include "gki.h" #include "osi/include/allocator.h" #include "osi/include/compat.h" #include "osi/include/config.h" -#include "gki.h" -#include "osi/include/osi.h" -#include "bta_hh_api.h" -#include "btif_hh.h" #include "osi/include/log.h" +#include "osi/include/osi.h" /************************************************************************************ ** Constants & Macros ************************************************************************************/ +#define LOG_TAG "bt_btif_storage" + #define BTIF_STORAGE_PATH_BLUEDROID "/data/misc/bluedroid" //#define BTIF_STORAGE_PATH_ADAPTER_INFO "adapter_info" @@ -640,7 +641,7 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t *property) uint32_t i; tBTA_SERVICE_MASK service_mask = btif_get_enabled_services_mask(); - LOG_INFO("%s service_mask:0x%x", __FUNCTION__, service_mask); + LOG_INFO(LOG_TAG, "%s service_mask:0x%x", __FUNCTION__, service_mask); for (i=0; i < BTA_MAX_SERVICE_ID; i++) { /* This should eventually become a function when more services are enabled */ @@ -1503,7 +1504,7 @@ bt_status_t btif_storage_load_autopair_device_list() { config_t *config = config_new(BTIF_AUTO_PAIR_CONF_FILE); if (!config) { - LOG_ERROR("%s failed to open auto pair blacklist conf file '%s'.", __func__, BTIF_AUTO_PAIR_CONF_FILE); + LOG_ERROR(LOG_TAG, "%s failed to open auto pair blacklist conf file '%s'.", __func__, BTIF_AUTO_PAIR_CONF_FILE); return BT_STATUS_FAIL; } diff --git a/btif/src/stack_manager.c b/btif/src/stack_manager.c index 817e46f55..fcd373c4e 100644 --- a/btif/src/stack_manager.c +++ b/btif/src/stack_manager.c @@ -16,26 +16,26 @@ * ******************************************************************************/ -#define LOG_TAG "bt_stack_manager" - #include +#include "btcore/include/module.h" +#include "btcore/include/osi_module.h" #include "btif_api.h" #include "btif_common.h" #include "device/include/controller.h" -#include "btcore/include/module.h" -#include "btcore/include/osi_module.h" -#include "osi/include/osi.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "osi/include/semaphore.h" -#include "stack_manager.h" #include "osi/include/thread.h" +#include "stack_manager.h" // Temp includes #include "btif_config.h" #include "btif_profile_queue.h" #include "bt_utils.h" +#define LOG_TAG "bt_stack_manager" + static thread_t *management_thread; // If initialized, any of the bluetooth API functions can be called. @@ -108,7 +108,7 @@ static void event_init_stack(void *context) { static void ensure_stack_is_initialized(void) { if (!stack_is_initialized) { - LOG_WARN("%s found the stack was uninitialized. Initializing now.", __func__); + LOG_WARN(LOG_TAG, "%s found the stack was uninitialized. Initializing now.", __func__); // No semaphore needed since we are calling it directly event_init_stack(NULL); } @@ -117,13 +117,13 @@ static void ensure_stack_is_initialized(void) { // Synchronous function to start up the stack static void event_start_up_stack(UNUSED_ATTR void *context) { if (stack_is_running) { - LOG_DEBUG("%s stack already brought up.", __func__); + LOG_DEBUG(LOG_TAG, "%s stack already brought up.", __func__); return; } ensure_stack_is_initialized(); - LOG_DEBUG("%s is bringing up the stack.", __func__); + LOG_DEBUG(LOG_TAG, "%s is bringing up the stack.", __func__); hack_future = future_new(); // Include this for now to put btif config into a shutdown-able state @@ -137,18 +137,18 @@ static void event_start_up_stack(UNUSED_ATTR void *context) { } stack_is_running = true; - LOG_DEBUG("%s finished", __func__); + LOG_DEBUG(LOG_TAG, "%s finished", __func__); btif_thread_post(event_signal_stack_up, NULL); } // Synchronous function to shut down the stack static void event_shut_down_stack(UNUSED_ATTR void *context) { if (!stack_is_running) { - LOG_DEBUG("%s stack is already brought down.", __func__); + LOG_DEBUG(LOG_TAG, "%s stack is already brought down.", __func__); return; } - LOG_DEBUG("%s is bringing down the stack.", __func__); + LOG_DEBUG(LOG_TAG, "%s is bringing down the stack.", __func__); hack_future = future_new(); stack_is_running = false; @@ -158,13 +158,13 @@ static void event_shut_down_stack(UNUSED_ATTR void *context) { future_await(hack_future); module_shut_down(get_module(CONTROLLER_MODULE)); // Doesn't do any work, just puts it in a restartable state - LOG_DEBUG("%s finished.", __func__); + LOG_DEBUG(LOG_TAG, "%s finished.", __func__); btif_thread_post(event_signal_stack_down, NULL); } static void ensure_stack_is_not_running(void) { if (stack_is_running) { - LOG_WARN("%s found the stack was still running. Bringing it down now.", __func__); + LOG_WARN(LOG_TAG, "%s found the stack was still running. Bringing it down now.", __func__); event_shut_down_stack(NULL); } } @@ -172,13 +172,13 @@ static void ensure_stack_is_not_running(void) { // Synchronous function to clean up the stack static void event_clean_up_stack(UNUSED_ATTR void *context) { if (!stack_is_initialized) { - LOG_DEBUG("%s found the stack already in a clean state.", __func__); + LOG_DEBUG(LOG_TAG, "%s found the stack already in a clean state.", __func__); return; } ensure_stack_is_not_running(); - LOG_DEBUG("%s is cleaning up the stack.", __func__); + LOG_DEBUG(LOG_TAG, "%s is cleaning up the stack.", __func__); hack_future = future_new(); stack_is_initialized = false; @@ -189,7 +189,7 @@ static void event_clean_up_stack(UNUSED_ATTR void *context) { future_await(hack_future); module_clean_up(get_module(OSI_MODULE)); module_management_stop(); - LOG_DEBUG("%s finished.", __func__); + LOG_DEBUG(LOG_TAG, "%s finished.", __func__); } static void event_signal_stack_up(UNUSED_ATTR void *context) { @@ -209,7 +209,7 @@ static void ensure_manager_initialized(void) { management_thread = thread_new("stack_manager"); if (!management_thread) { - LOG_ERROR("%s unable to create stack management thread.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create stack management thread.", __func__); return; } } diff --git a/hci/src/btsnoop.c b/hci/src/btsnoop.c index b768f7068..f1dcab8d4 100644 --- a/hci/src/btsnoop.c +++ b/hci/src/btsnoop.c @@ -16,8 +16,6 @@ * ******************************************************************************/ -#define LOG_TAG "bt_snoop" - #include #include #include @@ -32,13 +30,15 @@ #include #include +#include "bt_types.h" #include "hci/include/btsnoop.h" #include "hci/include/btsnoop_mem.h" -#include "bt_types.h" #include "hci_layer.h" #include "osi/include/log.h" #include "stack_config.h" +#define LOG_TAG "bt_snoop" + typedef enum { kCommandPacket = 1, kAclPacket = 2, @@ -155,12 +155,12 @@ static void update_logging() { char last_log_path[PATH_MAX]; snprintf(last_log_path, PATH_MAX, "%s.last", log_path); if (!rename(log_path, last_log_path) && errno != ENOENT) - LOG_ERROR("%s unable to rename '%s' to '%s': %s", __func__, log_path, last_log_path, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to rename '%s' to '%s': %s", __func__, log_path, last_log_path, strerror(errno)); } logfile_fd = open(log_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); if (logfile_fd == INVALID_FD) { - LOG_ERROR("%s unable to open '%s': %s", __func__, log_path, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to open '%s': %s", __func__, log_path, strerror(errno)); is_logging = false; return; } diff --git a/hci/src/btsnoop_net.c b/hci/src/btsnoop_net.c index 173638d82..bd0448b6a 100644 --- a/hci/src/btsnoop_net.c +++ b/hci/src/btsnoop_net.c @@ -48,9 +48,9 @@ static int client_socket_ = -1; void btsnoop_net_open() { listen_thread_valid_ = (pthread_create(&listen_thread_, NULL, listen_fn_, NULL) == 0); if (!listen_thread_valid_) { - LOG_ERROR("%s pthread_create failed: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s pthread_create failed: %s", __func__, strerror(errno)); } else { - LOG_DEBUG("initialized"); + LOG_DEBUG(LOG_TAG, "initialized"); } } @@ -79,13 +79,13 @@ static void *listen_fn_(UNUSED_ATTR void *context) { listen_socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (listen_socket_ == -1) { - LOG_ERROR("%s socket creation failed: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s socket creation failed: %s", __func__, strerror(errno)); goto cleanup; } int enable = 1; if (setsockopt(listen_socket_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) == -1) { - LOG_ERROR("%s unable to set SO_REUSEADDR: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to set SO_REUSEADDR: %s", __func__, strerror(errno)); goto cleanup; } @@ -94,12 +94,12 @@ static void *listen_fn_(UNUSED_ATTR void *context) { addr.sin_addr.s_addr = htonl(LOCALHOST_); addr.sin_port = htons(LISTEN_PORT_); if (bind(listen_socket_, (struct sockaddr *)&addr, sizeof(addr)) == -1) { - LOG_ERROR("%s unable to bind listen socket: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to bind listen socket: %s", __func__, strerror(errno)); goto cleanup; } if (listen(listen_socket_, 10) == -1) { - LOG_ERROR("%s unable to listen: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to listen: %s", __func__, strerror(errno)); goto cleanup; } @@ -109,7 +109,7 @@ static void *listen_fn_(UNUSED_ATTR void *context) { if (errno == EINVAL || errno == EBADF) { break; } - LOG_WARN("%s error accepting socket: %s", __func__, strerror(errno)); + LOG_WARN(LOG_TAG, "%s error accepting socket: %s", __func__, strerror(errno)); continue; } diff --git a/hci/src/hci_audio.c b/hci/src/hci_audio.c index 63def165b..e81898271 100644 --- a/hci/src/hci_audio.c +++ b/hci/src/hci_audio.c @@ -27,7 +27,7 @@ void set_audio_state(uint16_t handle, sco_codec_t codec, sco_state_t state) { - LOG_INFO("%s handle:%d codec:0x%x state:%d", __func__, handle, codec, state); + LOG_INFO(LOG_TAG, "%s handle:%d codec:0x%x state:%d", __func__, handle, codec, state); bt_vendor_op_audio_state_t audio_state; diff --git a/hci/src/hci_hal_h4.c b/hci/src/hci_hal_h4.c index fd3ad8346..89bcb08d4 100644 --- a/hci/src/hci_hal_h4.c +++ b/hci/src/hci_hal_h4.c @@ -16,20 +16,20 @@ * ******************************************************************************/ -#define LOG_TAG "bt_hci_h4" - #include #include #include #include -#include "osi/include/eager_reader.h" #include "hci_hal.h" -#include "osi/include/osi.h" +#include "osi/include/eager_reader.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "osi/include/reactor.h" #include "vendor.h" +#define LOG_TAG "bt_hci_h4" + #define HCI_HAL_SERIAL_BUFFER_SIZE 1026 // Our interface and modules we import @@ -58,26 +58,26 @@ static bool hal_init(const hci_hal_callbacks_t *upper_callbacks, thread_t *upper } static bool hal_open() { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); // TODO(zachoverflow): close if already open / or don't reopen (maybe at the hci layer level) int fd_array[CH_MAX]; int number_of_ports = vendor->send_command(VENDOR_OPEN_USERIAL, &fd_array); if (number_of_ports != 1) { - LOG_ERROR("%s opened the wrong number of ports: got %d, expected 1.", __func__, number_of_ports); + LOG_ERROR(LOG_TAG, "%s opened the wrong number of ports: got %d, expected 1.", __func__, number_of_ports); goto error; } uart_fd = fd_array[0]; if (uart_fd == INVALID_FD) { - LOG_ERROR("%s unable to open the uart serial port.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to open the uart serial port.", __func__); goto error; } uart_stream = eager_reader_new(uart_fd, &allocator_malloc, HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX, "hci_single_channel"); if (!uart_stream) { - LOG_ERROR("%s unable to create eager reader for the uart serial port.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create eager reader for the uart serial port.", __func__); goto error; } @@ -92,7 +92,7 @@ error: } static void hal_close() { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); eager_reader_free(uart_stream); vendor->send_command(VENDOR_CLOSE_USERIAL, NULL); @@ -101,13 +101,13 @@ static void hal_close() { static size_t read_data(serial_data_type_t type, uint8_t *buffer, size_t max_size, bool block) { if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) { - LOG_ERROR("%s invalid data type: %d", __func__, type); + LOG_ERROR(LOG_TAG, "%s invalid data type: %d", __func__, type); return 0; } else if (!stream_has_interpretation) { - LOG_ERROR("%s with no valid stream intepretation.", __func__); + LOG_ERROR(LOG_TAG, "%s with no valid stream intepretation.", __func__); return 0; } else if (current_data_type != type) { - LOG_ERROR("%s with different type than existing interpretation.", __func__); + LOG_ERROR(LOG_TAG, "%s with different type than existing interpretation.", __func__); return 0; } @@ -116,9 +116,9 @@ static size_t read_data(serial_data_type_t type, uint8_t *buffer, size_t max_siz static void packet_finished(serial_data_type_t type) { if (!stream_has_interpretation) - LOG_ERROR("%s with no existing stream interpretation.", __func__); + LOG_ERROR(LOG_TAG, "%s with no existing stream interpretation.", __func__); else if (current_data_type != type) - LOG_ERROR("%s with different type than existing interpretation.", __func__); + LOG_ERROR(LOG_TAG, "%s with different type than existing interpretation.", __func__); stream_has_interpretation = false; } @@ -128,7 +128,7 @@ static uint16_t transmit_data(serial_data_type_t type, uint8_t *data, uint16_t l assert(length > 0); if (type < DATA_TYPE_COMMAND || type > DATA_TYPE_SCO) { - LOG_ERROR("%s invalid data type: %d", __func__, type); + LOG_ERROR(LOG_TAG, "%s invalid data type: %d", __func__, type); return 0; } @@ -143,7 +143,7 @@ static uint16_t transmit_data(serial_data_type_t type, uint8_t *data, uint16_t l ssize_t ret = write(uart_fd, data + transmitted_length, length); switch (ret) { case -1: - LOG_ERROR("In %s, error writing to the uart serial port: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "In %s, error writing to the uart serial port: %s", __func__, strerror(errno)); goto done; case 0: // If we wrote nothing, don't loop more because we @@ -177,7 +177,7 @@ static void event_uart_has_bytes(eager_reader_t *reader, UNUSED_ATTR void *conte uint8_t type_byte; eager_reader_read(reader, &type_byte, 1, true); if (type_byte < DATA_TYPE_ACL || type_byte > DATA_TYPE_EVENT) { - LOG_ERROR("[h4] Unknown HCI message type. Dropping this byte 0x%x, min %x, max %x", type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT); + LOG_ERROR(LOG_TAG, "[h4] Unknown HCI message type. Dropping this byte 0x%x, min %x, max %x", type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT); return; } diff --git a/hci/src/hci_hal_mct.c b/hci/src/hci_hal_mct.c index 25fa53acb..0f5b230b1 100644 --- a/hci/src/hci_hal_mct.c +++ b/hci/src/hci_hal_mct.c @@ -16,21 +16,21 @@ * ******************************************************************************/ -#define LOG_TAG "bt_hci_mct" - #include #include #include #include #include "bt_vendor_lib.h" -#include "osi/include/eager_reader.h" #include "hci_hal.h" -#include "osi/include/osi.h" +#include "osi/include/eager_reader.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "osi/include/reactor.h" #include "vendor.h" +#define LOG_TAG "bt_hci_mct" + #define HCI_HAL_SERIAL_BUFFER_SIZE 1026 // Our interface and modules we import @@ -60,48 +60,48 @@ static bool hal_init(const hci_hal_callbacks_t *upper_callbacks, thread_t *upper } static bool hal_open() { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); // TODO(zachoverflow): close if already open / or don't reopen (maybe at the hci layer level) int number_of_ports = vendor->send_command(VENDOR_OPEN_USERIAL, &uart_fds); if (number_of_ports != 2 && number_of_ports != 4) { - LOG_ERROR("%s opened the wrong number of ports: got %d, expected 2 or 4.", __func__, number_of_ports); + LOG_ERROR(LOG_TAG, "%s opened the wrong number of ports: got %d, expected 2 or 4.", __func__, number_of_ports); goto error; } - LOG_INFO("%s got uart fds: CMD=%d, EVT=%d, ACL_OUT=%d, ACL_IN=%d", + LOG_INFO(LOG_TAG, "%s got uart fds: CMD=%d, EVT=%d, ACL_OUT=%d, ACL_IN=%d", __func__, uart_fds[CH_CMD], uart_fds[CH_EVT], uart_fds[CH_ACL_OUT], uart_fds[CH_ACL_IN]); if (uart_fds[CH_CMD] == INVALID_FD) { - LOG_ERROR("%s unable to open the command uart serial port.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to open the command uart serial port.", __func__); goto error; } if (uart_fds[CH_EVT] == INVALID_FD) { - LOG_ERROR("%s unable to open the event uart serial port.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to open the event uart serial port.", __func__); goto error; } if (uart_fds[CH_ACL_OUT] == INVALID_FD) { - LOG_ERROR("%s unable to open the acl-out uart serial port.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to open the acl-out uart serial port.", __func__); goto error; } if (uart_fds[CH_ACL_IN] == INVALID_FD) { - LOG_ERROR("%s unable to open the acl-in uart serial port.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to open the acl-in uart serial port.", __func__); goto error; } event_stream = eager_reader_new(uart_fds[CH_EVT], &allocator_malloc, HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX, "hci_mct"); if (!event_stream) { - LOG_ERROR("%s unable to create eager reader for the event uart serial port.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create eager reader for the event uart serial port.", __func__); goto error; } acl_stream = eager_reader_new(uart_fds[CH_ACL_IN], &allocator_malloc, HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX, "hci_mct"); if (!event_stream) { - LOG_ERROR("%s unable to create eager reader for the acl-in uart serial port.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create eager reader for the acl-in uart serial port.", __func__); goto error; } @@ -116,7 +116,7 @@ error:; } static void hal_close() { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); eager_reader_free(event_stream); eager_reader_free(acl_stream); @@ -133,7 +133,7 @@ static size_t read_data(serial_data_type_t type, uint8_t *buffer, size_t max_siz return eager_reader_read(event_stream, buffer, max_size, block); } - LOG_ERROR("%s invalid data type: %d", __func__, type); + LOG_ERROR(LOG_TAG, "%s invalid data type: %d", __func__, type); return 0; } @@ -148,7 +148,7 @@ static uint16_t transmit_data(serial_data_type_t type, uint8_t *data, uint16_t l return transmit_data_on(uart_fds[CH_CMD], data, length); } - LOG_ERROR("%s invalid data type: %d", __func__, type); + LOG_ERROR(LOG_TAG, "%s invalid data type: %d", __func__, type); return 0; } @@ -163,7 +163,7 @@ static uint16_t transmit_data_on(int fd, uint8_t *data, uint16_t length) { ssize_t ret = write(fd, data + transmitted_length, length); switch (ret) { case -1: - LOG_ERROR("In %s, error writing to the serial port with fd %d: %s", __func__, fd, strerror(errno)); + LOG_ERROR(LOG_TAG, "In %s, error writing to the serial port with fd %d: %s", __func__, fd, strerror(errno)); return transmitted_length; case 0: // If we wrote nothing, don't loop more because we diff --git a/hci/src/hci_inject.c b/hci/src/hci_inject.c index 169295bbe..7bf6ebb5d 100644 --- a/hci/src/hci_inject.c +++ b/hci/src/hci_inject.c @@ -16,23 +16,23 @@ * ******************************************************************************/ -#define LOG_TAG "bt_hci_inject" - #include #include #include -#include "osi/include/allocator.h" #include "bt_types.h" #include "buffer_allocator.h" #include "hci_inject.h" #include "hci_layer.h" +#include "osi/include/allocator.h" #include "osi/include/list.h" -#include "osi/include/osi.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "osi/include/socket.h" #include "osi/include/thread.h" +#define LOG_TAG "bt_hci_inject" + typedef enum { HCI_PACKET_COMMAND = 1, HCI_PACKET_ACL_DATA = 2, @@ -110,7 +110,7 @@ static int hci_packet_to_event(hci_packet_t packet) { case HCI_PACKET_SCO_DATA: return MSG_STACK_TO_HC_HCI_SCO; default: - LOG_ERROR("%s unsupported packet type: %d", __func__, packet); + LOG_ERROR(LOG_TAG, "%s unsupported packet type: %d", __func__, packet); return -1; } } @@ -125,7 +125,7 @@ static void accept_ready(socket_t *socket, UNUSED_ATTR void *context) { client_t *client = (client_t *)osi_calloc(sizeof(client_t)); if (!client) { - LOG_ERROR("%s unable to allocate memory for client.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for client.", __func__); socket_free(socket); return; } @@ -133,7 +133,7 @@ static void accept_ready(socket_t *socket, UNUSED_ATTR void *context) { client->socket = socket; if (!list_append(clients, client)) { - LOG_ERROR("%s unable to add client to list.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to add client to list.", __func__); client_free(client); return; } @@ -176,7 +176,7 @@ static void read_ready(UNUSED_ATTR socket_t *socket, void *context) { memcpy(buf->data, buffer + 3, packet_len); hci->transmit_downward(buf->event, buf); } else { - LOG_ERROR("%s dropping injected packet of length %zu", __func__, packet_len); + LOG_ERROR(LOG_TAG, "%s dropping injected packet of length %zu", __func__, packet_len); } size_t remainder = client->buffer_size - frame_len; diff --git a/hci/src/hci_layer.c b/hci/src/hci_layer.c index 62e3ad631..cdbb93949 100644 --- a/hci/src/hci_layer.c +++ b/hci/src/hci_layer.c @@ -16,11 +16,8 @@ * ******************************************************************************/ -#define LOG_TAG "bt_hci" - #include #include -#include #include #include #include @@ -33,26 +30,28 @@ #include #endif // !defined(OS_GENERIC) -#include "buffer_allocator.h" +#include "btcore/include/module.h" #include "btsnoop.h" -#include "osi/include/fixed_queue.h" -#include "osi/include/future.h" -#include "hcidefs.h" -#include "hcimsgs.h" +#include "buffer_allocator.h" #include "hci_hal.h" -#include "hci_internals.h" #include "hci_inject.h" +#include "hci_internals.h" #include "hci_layer.h" -#include "osi/include/list.h" +#include "hcidefs.h" +#include "hcimsgs.h" #include "low_power_manager.h" -#include "btcore/include/module.h" +#include "osi/include/fixed_queue.h" +#include "osi/include/future.h" +#include "osi/include/list.h" +#include "osi/include/log.h" #include "osi/include/non_repeating_timer.h" #include "osi/include/osi.h" -#include "osi/include/log.h" -#include "packet_fragmenter.h" #include "osi/include/reactor.h" +#include "packet_fragmenter.h" #include "vendor.h" +#define LOG_TAG "bt_hci" + // TODO(zachoverflow): remove this hack extern #include bt_bdaddr_t btif_local_bd_addr; @@ -173,7 +172,7 @@ static waiting_command_t *get_waiting_command(command_opcode_t opcode); // Module lifecycle functions static future_t *start_up(void) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); // The host is only allowed to send at most one command initially, // as per the Bluetooth spec, Volume 2, Part E, 4.4 (Command Flow Control) @@ -199,7 +198,7 @@ static future_t *start_up(void) { startup_timer = non_repeating_timer_new(startup_timeout_ms, startup_timer_expired, NULL); if (!startup_timer) { - LOG_ERROR("%s unable to create startup timer.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create startup timer.", __func__); goto error; } @@ -208,37 +207,37 @@ static future_t *start_up(void) { epilog_timer = non_repeating_timer_new(EPILOG_TIMEOUT_MS, epilog_timer_expired, NULL); if (!epilog_timer) { - LOG_ERROR("%s unable to create epilog timer.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create epilog timer.", __func__); goto error; } command_response_timer = non_repeating_timer_new(COMMAND_PENDING_TIMEOUT, command_timed_out, NULL); if (!command_response_timer) { - LOG_ERROR("%s unable to create command response timer.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create command response timer.", __func__); goto error; } command_queue = fixed_queue_new(SIZE_MAX); if (!command_queue) { - LOG_ERROR("%s unable to create pending command queue.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create pending command queue.", __func__); goto error; } packet_queue = fixed_queue_new(SIZE_MAX); if (!packet_queue) { - LOG_ERROR("%s unable to create pending packet queue.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create pending packet queue.", __func__); goto error; } thread = thread_new("hci_thread"); if (!thread) { - LOG_ERROR("%s unable to create thread.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create thread.", __func__); goto error; } commands_pending_response = list_new(NULL); if (!commands_pending_response) { - LOG_ERROR("%s unable to create list for commands pending response.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create list for commands pending response.", __func__); goto error; } @@ -263,7 +262,7 @@ static future_t *start_up(void) { int power_state = BT_VND_PWR_OFF; #if (defined (BT_CLEAN_TURN_ON_DISABLED) && BT_CLEAN_TURN_ON_DISABLED == TRUE) - LOG_WARN("%s not turning off the chip before turning on.", __func__); + LOG_WARN(LOG_TAG, "%s not turning off the chip before turning on.", __func__); // So apparently this hack was needed in the past because a Wingray kernel driver // didn't handle power off commands in a powered off state correctly. @@ -278,7 +277,7 @@ static future_t *start_up(void) { vendor->send_command(VENDOR_CHIP_POWER_CONTROL, &power_state); startup_future = future_new(); - LOG_DEBUG("%s starting async portion", __func__); + LOG_DEBUG(LOG_TAG, "%s starting async portion", __func__); thread_post(thread, event_finish_startup, NULL); return startup_future; error:; @@ -287,7 +286,7 @@ error:; } static future_t *shut_down() { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); hci_inject->close(); @@ -347,7 +346,7 @@ EXPORT_SYMBOL const module_t hci_module = { // Interface functions static void do_postload() { - LOG_DEBUG("%s posting postload work item", __func__); + LOG_DEBUG(LOG_TAG, "%s posting postload work item", __func__); thread_post(thread, event_postload, NULL); } @@ -362,7 +361,7 @@ static void transmit_command( void *context) { waiting_command_t *wait_entry = osi_calloc(sizeof(waiting_command_t)); if (!wait_entry) { - LOG_ERROR("%s couldn't allocate space for wait entry.", __func__); + LOG_ERROR(LOG_TAG, "%s couldn't allocate space for wait entry.", __func__); return; } @@ -403,7 +402,7 @@ static void transmit_downward(data_dispatcher_type_t type, void *data) { if (type == MSG_STACK_TO_HC_HCI_CMD) { // TODO(zachoverflow): eliminate this call transmit_command((BT_HDR *)data, NULL, NULL, NULL); - LOG_WARN("%s legacy transmit of command. Use transmit_command instead.", __func__); + LOG_WARN(LOG_TAG, "%s legacy transmit of command. Use transmit_command instead.", __func__); } else { fixed_queue_enqueue(packet_queue, data); } @@ -412,13 +411,13 @@ static void transmit_downward(data_dispatcher_type_t type, void *data) { // Start up functions static void event_finish_startup(UNUSED_ATTR void *context) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); hal->open(); vendor->send_async_command(VENDOR_CONFIGURE_FIRMWARE, NULL); } static void firmware_config_callback(UNUSED_ATTR bool success) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); firmware_is_configured = true; non_repeating_timer_cancel(startup_timer); @@ -427,7 +426,7 @@ static void firmware_config_callback(UNUSED_ATTR bool success) { } static void startup_timer_expired(UNUSED_ATTR void *context) { - LOG_ERROR("%s", __func__); + LOG_ERROR(LOG_TAG, "%s", __func__); future_ready(startup_future, FUTURE_FAIL); startup_future = NULL; } @@ -435,7 +434,7 @@ static void startup_timer_expired(UNUSED_ATTR void *context) { // Postload functions static void event_postload(UNUSED_ATTR void *context) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); if(vendor->send_async_command(VENDOR_CONFIGURE_SCO, NULL) == -1) { // If couldn't configure sco, we won't get the sco configuration callback // so go pretend to do it now @@ -445,7 +444,7 @@ static void event_postload(UNUSED_ATTR void *context) { } static void sco_config_callback(UNUSED_ATTR bool success) { - LOG_INFO("%s postload finished.", __func__); + LOG_INFO(LOG_TAG, "%s postload finished.", __func__); } // Epilog functions @@ -455,12 +454,12 @@ static void event_epilog(UNUSED_ATTR void *context) { } static void epilog_finished_callback(UNUSED_ATTR bool success) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); thread_stop(thread); } static void epilog_timer_expired(UNUSED_ATTR void *context) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); thread_stop(thread); } @@ -521,17 +520,17 @@ static void command_timed_out(UNUSED_ATTR void *context) { pthread_mutex_lock(&commands_pending_response_lock); if (list_is_empty(commands_pending_response)) { - LOG_ERROR("%s with no commands pending response", __func__); + LOG_ERROR(LOG_TAG, "%s with no commands pending response", __func__); } else { waiting_command_t *wait_entry = list_front(commands_pending_response); pthread_mutex_unlock(&commands_pending_response_lock); // We shouldn't try to recover the stack from this command timeout. // If it's caused by a software bug, fix it. If it's a hardware bug, fix it. - LOG_ERROR("%s hci layer timeout waiting for response to a command. opcode: 0x%x", __func__, wait_entry->opcode); + LOG_ERROR(LOG_TAG, "%s hci layer timeout waiting for response to a command. opcode: 0x%x", __func__, wait_entry->opcode); } - LOG_ERROR("%s restarting the bluetooth process.", __func__); + LOG_ERROR(LOG_TAG, "%s restarting the bluetooth process.", __func__); usleep(10000); kill(getpid(), SIGKILL); } @@ -566,7 +565,7 @@ static void hal_says_data_ready(serial_data_type_t type) { incoming->buffer = (BT_HDR *)buffer_allocator->alloc(buffer_size); if (!incoming->buffer) { - LOG_ERROR("%s error getting buffer for incoming packet of type %d and size %zd", __func__, type, buffer_size); + LOG_ERROR(LOG_TAG, "%s error getting buffer for incoming packet of type %d and size %zd", __func__, type, buffer_size); // Can't read any more of this current packet, so jump out incoming->state = incoming->bytes_remaining == 0 ? BRAND_NEW : IGNORE; break; @@ -606,7 +605,7 @@ static void hal_says_data_ready(serial_data_type_t type) { break; case FINISHED: - LOG_ERROR("%s the state machine should not have been left in the finished state.", __func__); + LOG_ERROR(LOG_TAG, "%s the state machine should not have been left in the finished state.", __func__); break; } @@ -660,7 +659,7 @@ static bool filter_incoming_event(BT_HDR *packet) { wait_entry = get_waiting_command(opcode); if (!wait_entry) - LOG_WARN("%s command complete event with no matching command. opcode: 0x%x.", __func__, opcode); + LOG_WARN(LOG_TAG, "%s command complete event with no matching command. opcode: 0x%x.", __func__, opcode); else if (wait_entry->complete_callback) wait_entry->complete_callback(packet, wait_entry->context); else if (wait_entry->complete_future) @@ -677,7 +676,7 @@ static bool filter_incoming_event(BT_HDR *packet) { wait_entry = get_waiting_command(opcode); if (!wait_entry) - LOG_WARN("%s command status event with no matching command. opcode: 0x%x", __func__, opcode); + LOG_WARN(LOG_TAG, "%s command status event with no matching command. opcode: 0x%x", __func__, opcode); else if (wait_entry->status_callback) wait_entry->status_callback(status, wait_entry->command, wait_entry->context); @@ -714,7 +713,7 @@ static void dispatch_reassembled(BT_HDR *packet) { if (upwards_data_queue) { fixed_queue_enqueue(upwards_data_queue, packet); } else { - LOG_ERROR("%s had no queue to place upwards data packet in. Dropping it on the floor.", __func__); + LOG_ERROR(LOG_TAG, "%s had no queue to place upwards data packet in. Dropping it on the floor.", __func__); buffer_allocator->free(packet); } } @@ -730,7 +729,7 @@ static serial_data_type_t event_to_data_type(uint16_t event) { else if (event == MSG_STACK_TO_HC_HCI_CMD) return DATA_TYPE_COMMAND; else - LOG_ERROR("%s invalid event type, could not translate 0x%x", __func__, event); + LOG_ERROR(LOG_TAG, "%s invalid event type, could not translate 0x%x", __func__, event); return 0; } @@ -765,7 +764,7 @@ static void init_layer_interface() { // there's only one instance of the hci interface. interface.event_dispatcher = data_dispatcher_new("hci_layer"); if (!interface.event_dispatcher) { - LOG_ERROR("%s could not create upward dispatcher.", __func__); + LOG_ERROR(LOG_TAG, "%s could not create upward dispatcher.", __func__); return; } diff --git a/hci/src/hci_packet_parser.c b/hci/src/hci_packet_parser.c index b9f4080cd..2e2f2a591 100644 --- a/hci/src/hci_packet_parser.c +++ b/hci/src/hci_packet_parser.c @@ -16,17 +16,17 @@ * ******************************************************************************/ -#define LOG_TAG "bt_hci" +#include "hci_packet_parser.h" #include #include "buffer_allocator.h" -#include "bt_types.h" -#include "hcimsgs.h" #include "hci_layer.h" -#include "hci_packet_parser.h" +#include "hcimsgs.h" #include "osi/include/log.h" +#define LOG_TAG "bt_hci" + static const command_opcode_t NO_OPCODE_CHECKING = 0; static const allocator_t *buffer_allocator; @@ -109,7 +109,7 @@ static void parse_read_local_extended_features_response( assert(*page_number_ptr < feature_pages_count); STREAM_TO_ARRAY(feature_pages[*page_number_ptr].as_array, stream, (int)sizeof(bt_device_features_t)); } else { - LOG_ERROR("%s() - WARNING: READING EXTENDED FEATURES FAILED. " + LOG_ERROR(LOG_TAG, "%s() - WARNING: READING EXTENDED FEATURES FAILED. " "THIS MAY INDICATE A FIRMWARE/CONTROLLER ISSUE.", __func__); } diff --git a/hci/src/low_power_manager.c b/hci/src/low_power_manager.c index 9435e4fe1..5cbece754 100644 --- a/hci/src/low_power_manager.c +++ b/hci/src/low_power_manager.c @@ -16,18 +16,19 @@ * ******************************************************************************/ -#define LOG_TAG "bt_low_power_manager" +#include "low_power_manager.h" #include #include #include "osi/include/alarm.h" -#include "low_power_manager.h" -#include "osi/include/osi.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "osi/include/thread.h" #include "vendor.h" +#define LOG_TAG "bt_low_power_manager" + typedef enum { LPM_DISABLED = 0, LPM_ENABLED, @@ -83,7 +84,7 @@ static void init(thread_t *post_thread) { idle_alarm = alarm_new(); if (!idle_alarm) { - LOG_ERROR("%s could not create idle alarm.", __func__); + LOG_ERROR(LOG_TAG, "%s could not create idle alarm.", __func__); } reset_state(); @@ -97,7 +98,7 @@ static void cleanup() { static void post_command(low_power_command_t command) { if (command > LPM_WAKE_DEASSERT) { - LOG_ERROR("%s unknown low power command %d", __func__, command); + LOG_ERROR(LOG_TAG, "%s unknown low power command %d", __func__, command); return; } @@ -132,18 +133,18 @@ static void transmit_done() { static void enable(bool enable) { if (state == LPM_DISABLING) { if (enable) - LOG_ERROR("%s still processing prior disable request, cannot enable.", __func__); + LOG_ERROR(LOG_TAG, "%s still processing prior disable request, cannot enable.", __func__); else - LOG_WARN("%s still processing prior disable request, ignoring new request to disable.", __func__); + LOG_WARN(LOG_TAG, "%s still processing prior disable request, ignoring new request to disable.", __func__); } else if (state == LPM_ENABLING) { if (enable) - LOG_ERROR("%s still processing prior enable request, ignoring new request to enable.", __func__); + LOG_ERROR(LOG_TAG, "%s still processing prior enable request, ignoring new request to enable.", __func__); else - LOG_WARN("%s still processing prior enable request, cannot disable.", __func__); + LOG_WARN(LOG_TAG, "%s still processing prior enable request, cannot disable.", __func__); } else if (state == LPM_ENABLED && enable) { - LOG_INFO("%s already enabled.", __func__); + LOG_INFO(LOG_TAG, "%s already enabled.", __func__); } else if (state == LPM_DISABLED && !enable) { - LOG_INFO("%s already disabled.", __func__); + LOG_INFO(LOG_TAG, "%s already disabled.", __func__); } else { uint8_t command = enable ? BT_VND_LPM_ENABLE : BT_VND_LPM_DISABLE; state = enable ? LPM_ENABLING : LPM_DISABLING; diff --git a/hci/src/packet_fragmenter.c b/hci/src/packet_fragmenter.c index de6366809..be554e468 100644 --- a/hci/src/packet_fragmenter.c +++ b/hci/src/packet_fragmenter.c @@ -16,20 +16,21 @@ * ******************************************************************************/ -#define LOG_TAG "bt_hci_packet_fragmenter" +#include "packet_fragmenter.h" #include #include #include "buffer_allocator.h" #include "device/include/controller.h" -#include "osi/include/hash_map.h" #include "hci_internals.h" #include "hci_layer.h" -#include "packet_fragmenter.h" -#include "osi/include/osi.h" #include "osi/include/hash_functions.h" +#include "osi/include/hash_map.h" #include "osi/include/log.h" +#include "osi/include/osi.h" + +#define LOG_TAG "bt_hci_packet_fragmenter" #define APPLY_CONTINUATION_FLAG(handle) (((handle) & 0xCFFF) | 0x1000) #define APPLY_START_FLAG(handle) (((handle) & 0xCFFF) | 0x2000) @@ -139,7 +140,7 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) { if (boundary_flag == START_PACKET_BOUNDARY) { if (partial_packet) { - LOG_WARN("%s found unfinished packet for handle with start packet. Dropping old.", __func__); + LOG_WARN(LOG_TAG, "%s found unfinished packet for handle with start packet. Dropping old.", __func__); hash_map_erase(partial_packets, (void *)(uintptr_t)handle); buffer_allocator->free(partial_packet); @@ -148,7 +149,7 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) { uint16_t full_length = l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE; if (full_length <= packet->len) { if (full_length < packet->len) - LOG_WARN("%s found l2cap full length %d less than the hci length %d.", __func__, l2cap_length, packet->len); + LOG_WARN(LOG_TAG, "%s found l2cap full length %d less than the hci length %d.", __func__, l2cap_length, packet->len); callbacks->reassembled(packet); return; @@ -171,7 +172,7 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) { buffer_allocator->free(packet); } else { if (!partial_packet) { - LOG_WARN("%s got continuation for unknown packet. Dropping it.", __func__); + LOG_WARN(LOG_TAG, "%s got continuation for unknown packet. Dropping it.", __func__); buffer_allocator->free(packet); return; } @@ -179,7 +180,7 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) { packet->offset = HCI_ACL_PREAMBLE_SIZE; uint16_t projected_offset = partial_packet->offset + (packet->len - HCI_ACL_PREAMBLE_SIZE); if (projected_offset > partial_packet->len) { // len stores the expected length - LOG_WARN("%s got packet which would exceed expected length of %d. Truncating.", __func__, partial_packet->len); + LOG_WARN(LOG_TAG, "%s got packet which would exceed expected length of %d. Truncating.", __func__, partial_packet->len); packet->len = partial_packet->len - partial_packet->offset; projected_offset = partial_packet->len; } diff --git a/hci/src/vendor.c b/hci/src/vendor.c index 2e220e4a7..e0a0b7fc5 100644 --- a/hci/src/vendor.c +++ b/hci/src/vendor.c @@ -51,21 +51,21 @@ static bool vendor_open( lib_handle = dlopen(VENDOR_LIBRARY_NAME, RTLD_NOW); if (!lib_handle) { - LOG_ERROR("%s unable to open %s: %s", __func__, VENDOR_LIBRARY_NAME, dlerror()); + LOG_ERROR(LOG_TAG, "%s unable to open %s: %s", __func__, VENDOR_LIBRARY_NAME, dlerror()); goto error; } lib_interface = (bt_vendor_interface_t *)dlsym(lib_handle, VENDOR_LIBRARY_SYMBOL_NAME); if (!lib_interface) { - LOG_ERROR("%s unable to find symbol %s in %s: %s", __func__, VENDOR_LIBRARY_SYMBOL_NAME, VENDOR_LIBRARY_NAME, dlerror()); + LOG_ERROR(LOG_TAG, "%s unable to find symbol %s in %s: %s", __func__, VENDOR_LIBRARY_SYMBOL_NAME, VENDOR_LIBRARY_NAME, dlerror()); goto error; } - LOG_INFO("alloc value %p", lib_callbacks.alloc); + LOG_INFO(LOG_TAG, "alloc value %p", lib_callbacks.alloc); int status = lib_interface->init(&lib_callbacks, (unsigned char *)local_bdaddr); if (status) { - LOG_ERROR("%s unable to initialize vendor library: %d", __func__, status); + LOG_ERROR(LOG_TAG, "%s unable to initialize vendor library: %d", __func__, status); goto error; } @@ -109,7 +109,7 @@ static void set_callback(vendor_async_opcode_t opcode, vendor_cb callback) { // Called back from vendor library when the firmware configuration // completes. static void firmware_config_cb(bt_vendor_op_result_t result) { - LOG_INFO("firmware callback"); + LOG_INFO(LOG_TAG, "firmware callback"); vendor_cb callback = callbacks[VENDOR_CONFIGURE_FIRMWARE]; assert(callback != NULL); callback(result == BT_VND_OP_RESULT_SUCCESS); @@ -119,7 +119,7 @@ static void firmware_config_cb(bt_vendor_op_result_t result) { // SCO configuration request. This should only happen during the // postload process. static void sco_config_cb(bt_vendor_op_result_t result) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); vendor_cb callback = callbacks[VENDOR_CONFIGURE_SCO]; assert(callback != NULL); callback(result == BT_VND_OP_RESULT_SUCCESS); @@ -128,7 +128,7 @@ static void sco_config_cb(bt_vendor_op_result_t result) { // Called back from vendor library to indicate status of previous // LPM enable/disable request. static void low_power_mode_cb(bt_vendor_op_result_t result) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); vendor_cb callback = callbacks[VENDOR_SET_LPM_MODE]; assert(callback != NULL); callback(result == BT_VND_OP_RESULT_SUCCESS); @@ -149,7 +149,7 @@ static void sco_audiostate_cb(bt_vendor_op_result_t result) { uint8_t status = (result == BT_VND_OP_RESULT_SUCCESS) ? 0 : 1; - LOG_INFO("sco_audiostate_cb(status: %d)",status); + LOG_INFO(LOG_TAG, "sco_audiostate_cb(status: %d)",status); } // Called by vendor library when it needs an HCI buffer. @@ -180,7 +180,7 @@ static uint8_t transmit_cb(UNUSED_ATTR uint16_t opcode, void *buffer, tINT_CMD_C // completed. It is safe to call vendor_interface->cleanup() after // this callback has been received. static void epilog_cb(bt_vendor_op_result_t result) { - LOG_INFO("%s", __func__); + LOG_INFO(LOG_TAG, "%s", __func__); vendor_cb callback = callbacks[VENDOR_DO_EPILOG]; assert(callback != NULL); callback(result == BT_VND_OP_RESULT_SUCCESS); diff --git a/main/bte_conf.c b/main/bte_conf.c index 2bf61dac3..ff4691e1c 100644 --- a/main/bte_conf.c +++ b/main/bte_conf.c @@ -33,11 +33,11 @@ void bte_load_ble_conf(const char* path) { assert(path != NULL); - LOG_INFO("%s attempt to load ble stack conf from %s", __func__, path); + LOG_INFO(LOG_TAG, "%s attempt to load ble stack conf from %s", __func__, path); config_t *config = config_new(path); if (!config) { - LOG_INFO("%s file >%s< not found", __func__, path); + LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path); return; } @@ -45,7 +45,7 @@ void bte_load_ble_conf(const char* path) if(*ble_adv_tx_power) { sscanf(ble_adv_tx_power, "%d,%d,%d,%d,%d", btm_ble_tx_power, btm_ble_tx_power + 1, btm_ble_tx_power + 2, btm_ble_tx_power + 3, btm_ble_tx_power + 4); - LOG_INFO("loaded btm_ble_tx_power: %d, %d, %d, %d, %d", (char)btm_ble_tx_power[0], (char)btm_ble_tx_power[1], + LOG_INFO(LOG_TAG, "loaded btm_ble_tx_power: %d, %d, %d, %d, %d", (char)btm_ble_tx_power[0], (char)btm_ble_tx_power[1], btm_ble_tx_power[2], btm_ble_tx_power[3], btm_ble_tx_power[4]); } config_free(config); @@ -59,7 +59,7 @@ void bte_load_did_conf(const char *p_path) { config_t *config = config_new(p_path); if (!config) { - LOG_ERROR("%s unable to load DID config '%s'.", __func__, p_path); + LOG_ERROR(LOG_TAG, "%s unable to load DID config '%s'.", __func__, p_path); return; } @@ -68,7 +68,7 @@ void bte_load_did_conf(const char *p_path) { snprintf(section_name, sizeof(section_name), "DID%d", i); if (!config_has_section(config, section_name)) { - LOG_DEBUG("%s no section named %s.", __func__, section_name); + LOG_DEBUG(LOG_TAG, "%s no section named %s.", __func__, section_name); break; } @@ -84,23 +84,23 @@ void bte_load_did_conf(const char *p_path) { if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG && record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) { - LOG_ERROR("%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i); + LOG_ERROR(LOG_TAG, "%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i); continue; } - LOG_DEBUG("Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary")); - LOG_DEBUG(" vendorId = %04x", record.vendor); - LOG_DEBUG(" vendorIdSource = %04x", record.vendor_id_source); - LOG_DEBUG(" product = %04x", record.product); - LOG_DEBUG(" version = %04x", record.version); - LOG_DEBUG(" clientExecutableURL = %s", record.client_executable_url); - LOG_DEBUG(" serviceDescription = %s", record.service_description); - LOG_DEBUG(" documentationURL = %s", record.documentation_url); + LOG_DEBUG(LOG_TAG, "Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary")); + LOG_DEBUG(LOG_TAG, " vendorId = %04x", record.vendor); + LOG_DEBUG(LOG_TAG, " vendorIdSource = %04x", record.vendor_id_source); + LOG_DEBUG(LOG_TAG, " product = %04x", record.product); + LOG_DEBUG(LOG_TAG, " version = %04x", record.version); + LOG_DEBUG(LOG_TAG, " clientExecutableURL = %s", record.client_executable_url); + LOG_DEBUG(LOG_TAG, " serviceDescription = %s", record.service_description); + LOG_DEBUG(LOG_TAG, " documentationURL = %s", record.documentation_url); uint32_t record_handle; tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle); if (status != BTA_SUCCESS) { - LOG_ERROR("%s unable to set device ID record %d: error %d.", __func__, i, status); + LOG_ERROR(LOG_TAG, "%s unable to set device ID record %d: error %d.", __func__, i, status); } } diff --git a/main/bte_logmsg.c b/main/bte_logmsg.c index e302cbe01..26444f685 100644 --- a/main/bte_logmsg.c +++ b/main/bte_logmsg.c @@ -24,20 +24,21 @@ #include #include -#include "bte.h" +#include "avrc_api.h" #include "bta_api.h" +#include "bte.h" +#include "btm_api.h" #include "btu.h" -#include "osi/include/config.h" +#include "gap_api.h" #include "gki.h" #include "l2c_api.h" +#include "osi/include/config.h" +#include "osi/include/log.h" #include "osi/include/log.h" +#include "port_api.h" +#include "sdp_api.h" #include "stack_config.h" -#include "port_api.h" -#if (AVDT_INCLUDED==TRUE) -#include "avdt_api.h" -#endif -#include "avrc_api.h" #if (AVDT_INCLUDED==TRUE) #include "avdt_api.h" #endif @@ -47,31 +48,15 @@ #if (BNEP_INCLUDED==TRUE) #include "bnep_api.h" #endif -#include "btm_api.h" -#include "gap_api.h" #if (PAN_INCLUDED==TRUE) #include "pan_api.h" #endif -#include "sdp_api.h" - #if (BLE_INCLUDED==TRUE) #include "gatt_api.h" #include "smp_api.h" #endif -// TODO(armansito): Work-around until we figure out a way to generate logs in a -// platform-independent manner. -#if defined(OS_GENERIC) -#define LOGI0(t,s) fprintf(stderr, "%s\n", s) -#define LOGD0(t,s) fprintf(stderr, "%s\n", s) -#define LOGW0(t,s) fprintf(stderr, "%s\n", s) -#define LOGE0(t,s) fprintf(stderr, "%s\n", s) -#else // !defined(OS_GENERIC) -#define LOGI0(t,s) __android_log_write(ANDROID_LOG_INFO, t, s) -#define LOGD0(t,s) __android_log_write(ANDROID_LOG_DEBUG, t, s) -#define LOGW0(t,s) __android_log_write(ANDROID_LOG_WARN, t, s) -#define LOGE0(t,s) __android_log_write(ANDROID_LOG_ERROR, t, s) -#endif // defined(OS_GENERIC) +#define LOG_TAG "bte_logmsg" #ifndef DEFAULT_CONF_TRACE_LEVEL #define DEFAULT_CONF_TRACE_LEVEL BT_TRACE_LEVEL_WARNING @@ -193,20 +178,20 @@ void LogMsg(uint32_t trace_set_mask, const char *fmt_str, ...) { switch ( TRACE_GET_TYPE(trace_set_mask) ) { case TRACE_TYPE_ERROR: - LOGE0(bt_layer_tags[trace_layer], buffer); + LOG_ERROR(bt_layer_tags[trace_layer], "%s", buffer); break; case TRACE_TYPE_WARNING: - LOGW0(bt_layer_tags[trace_layer], buffer); + LOG_WARN(bt_layer_tags[trace_layer], "%s", buffer); break; case TRACE_TYPE_API: case TRACE_TYPE_EVENT: - LOGI0(bt_layer_tags[trace_layer], buffer); + LOG_INFO(bt_layer_tags[trace_layer], "%s", buffer); break; case TRACE_TYPE_DEBUG: - LOGD0(bt_layer_tags[trace_layer], buffer); + LOG_DEBUG(bt_layer_tags[trace_layer], "%s", buffer); break; default: - LOGE0(bt_layer_tags[trace_layer], buffer); /* we should never get this */ + LOG_ERROR(bt_layer_tags[trace_layer], "%s", buffer); /* we should never get this */ break; } } @@ -237,7 +222,7 @@ static void load_levels_from_config(const config_t *config) { assert(config != NULL); for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) { - LOG_INFO("BTE_InitTraceLevels -- %s", functions->trc_name); + LOG_INFO(LOG_TAG, "BTE_InitTraceLevels -- %s", functions->trc_name); int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1); if (value != -1) functions->trace_level = value; @@ -250,7 +235,7 @@ static void load_levels_from_config(const config_t *config) { static future_t *init(void) { const stack_config_t *stack_config = stack_config_get_interface(); if (!stack_config->get_trace_config_enabled()) { - LOG_INFO("[bttrc] using compile default trace settings"); + LOG_INFO(LOG_TAG, "using compile default trace settings"); return NULL; } diff --git a/main/bte_main.c b/main/bte_main.c index 4f6c1b030..43dcf8b8c 100644 --- a/main/bte_main.c +++ b/main/bte_main.c @@ -24,41 +24,42 @@ * ******************************************************************************/ -#define LOG_TAG "bt_main" - #include #include -#include #include #include #include #include -#include "osi/include/alarm.h" -#include "bta_api.h" +#include + #include "bt_hci_bdroid.h" -#include "bte.h" -#include "btif_common.h" -#include "btu.h" -#include "btsnoop.h" #include "bt_utils.h" +#include "bta_api.h" #include "btcore/include/counter.h" #include "btcore/include/module.h" +#include "bte.h" +#include "btif_common.h" +#include "btsnoop.h" +#include "btu.h" +#include "gki.h" +#include "hci_layer.h" +#include "osi/include/alarm.h" #include "osi/include/fixed_queue.h" #include "osi/include/future.h" -#include "gki.h" #include "osi/include/hash_functions.h" #include "osi/include/hash_map.h" -#include "hci_layer.h" -#include "osi/include/osi.h" #include "osi/include/log.h" -#include "stack_config.h" +#include "osi/include/osi.h" #include "osi/include/thread.h" +#include "stack_config.h" /******************************************************************************* ** Constants & Macros *******************************************************************************/ +#define LOG_TAG "bt_main" + /* Run-time configuration file for BLE*/ #ifndef BTE_BLE_STACK_CONF_FILE #define BTE_BLE_STACK_CONF_FILE "/etc/bluetooth/ble_stack.conf" @@ -99,11 +100,11 @@ void bte_main_boot_entry(void) hci = hci_layer_get_interface(); if (!hci) - LOG_ERROR("%s could not get hci layer interface.", __func__); + LOG_ERROR(LOG_TAG, "%s could not get hci layer interface.", __func__); btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); if (btu_hci_msg_queue == NULL) { - LOG_ERROR("%s unable to allocate hci message queue.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate hci message queue.", __func__); return; } diff --git a/main/stack_config.c b/main/stack_config.c index 06e15d114..979a1ec75 100644 --- a/main/stack_config.c +++ b/main/stack_config.c @@ -16,14 +16,15 @@ * ******************************************************************************/ -#define LOG_TAG "bt_stack_config" +#include "stack_config.h" #include #include "osi/include/future.h" -#include "stack_config.h" #include "osi/include/log.h" +#define LOG_TAG "bt_stack_config" + const char *BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName"; const char *BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput"; const char *BTSNOOP_SHOULD_SAVE_LAST_KEY = "BtSnoopSaveLog"; @@ -37,11 +38,11 @@ static future_t *init() { const char *path = "/etc/bluetooth/bt_stack.conf"; assert(path != NULL); - LOG_INFO("%s attempt to load stack conf from %s", __func__, path); + LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path); config = config_new(path); if (!config) { - LOG_INFO("%s file >%s< not found", __func__, path); + LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path); return future_new_immediate(FUTURE_FAIL); } diff --git a/osi/include/log.h b/osi/include/log.h index 4493ee913..21817c181 100644 --- a/osi/include/log.h +++ b/osi/include/log.h @@ -27,7 +27,7 @@ /* syslog didn't work well here since we would be redefining LOG_DEBUG. */ #include -#define LOGWRAPPER(fmt, args...) fprintf(stderr, fmt "\n", ## args) +#define LOGWRAPPER(tag, fmt, args...) fprintf(stderr, "%s: " fmt "\n", tag, ## args) #define LOG_VERBOSE(...) LOGWRAPPER(__VA_ARGS__) #define LOG_DEBUG(...) LOGWRAPPER(__VA_ARGS__) @@ -39,11 +39,10 @@ #include -#define LOG_VERBOSE(...) ALOGV(__VA_ARGS__) -#define LOG_DEBUG(...) ALOGD(__VA_ARGS__) -#define LOG_INFO(...) ALOGI(__VA_ARGS__) -#define LOG_WARN(...) ALOGW(__VA_ARGS__) -#define LOG_ERROR(...) ALOGE(__VA_ARGS__) - +#define LOG_VERBOSE(tag, fmt, args...) ALOG(LOG_VERBOSE, tag, fmt, ## args) +#define LOG_DEBUG(tag, fmt, args...) ALOG(LOG_DEBUG, tag, fmt, ## args ) +#define LOG_INFO(tag, fmt, args...) ALOG(LOG_INFO, tag, fmt, ## args) +#define LOG_WARN(tag, fmt, args...) ALOG(LOG_WARN, tag, fmt, ## args) +#define LOG_ERROR(tag, fmt, args...) ALOG(LOG_ERROR, tag, fmt, ## args) #endif /* defined(OS_GENERIC) */ diff --git a/osi/src/alarm.c b/osi/src/alarm.c index 513916775..32b18b248 100644 --- a/osi/src/alarm.c +++ b/osi/src/alarm.c @@ -92,7 +92,7 @@ alarm_t *alarm_new(void) { alarm_t *ret = osi_calloc(sizeof(alarm_t)); if (!ret) { - LOG_ERROR("%s unable to allocate memory for alarm.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for alarm.", __func__); goto error; } @@ -100,13 +100,13 @@ alarm_t *alarm_new(void) { // within the callback function of the alarm. int error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); if (error) { - LOG_ERROR("%s unable to create a recursive mutex: %s", __func__, strerror(error)); + LOG_ERROR(LOG_TAG, "%s unable to create a recursive mutex: %s", __func__, strerror(error)); goto error; } error = pthread_mutex_init(&ret->callback_lock, &attr); if (error) { - LOG_ERROR("%s unable to initialize mutex: %s", __func__, strerror(error)); + LOG_ERROR(LOG_TAG, "%s unable to initialize mutex: %s", __func__, strerror(error)); goto error; } @@ -204,7 +204,7 @@ static bool lazy_initialize(void) { alarms = list_new(NULL); if (!alarms) { - LOG_ERROR("%s unable to allocate alarm list.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate alarm list.", __func__); return false; } @@ -213,20 +213,20 @@ static bool lazy_initialize(void) { sigevent.sigev_notify = SIGEV_THREAD; sigevent.sigev_notify_function = (void (*)(union sigval))timer_callback; if (timer_create(CLOCK_ID, &sigevent, &timer) == -1) { - LOG_ERROR("%s unable to create timer: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to create timer: %s", __func__, strerror(errno)); return false; } alarm_expired = semaphore_new(0); if (!alarm_expired) { - LOG_ERROR("%s unable to create alarm expired semaphore", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create alarm expired semaphore", __func__); return false; } callback_thread_active = true; callback_thread = thread_new("alarm_callbacks"); if (!callback_thread) { - LOG_ERROR("%s unable to create alarm callback thread.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create alarm callback thread.", __func__); return false; } @@ -239,7 +239,7 @@ static period_ms_t now(void) { struct timespec ts; if (clock_gettime(CLOCK_ID, &ts) == -1) { - LOG_ERROR("%s unable to get current time: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to get current time: %s", __func__, strerror(errno)); return 0; } @@ -294,7 +294,7 @@ static void reschedule_root_alarm(void) { if (!timer_set) { int status = bt_os_callouts->acquire_wake_lock(WAKE_LOCK_ID); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s unable to acquire wake lock: %d", __func__, status); + LOG_ERROR(LOG_TAG, "%s unable to acquire wake lock: %d", __func__, status); goto done; } } @@ -303,7 +303,7 @@ static void reschedule_root_alarm(void) { wakeup_time.it_value.tv_nsec = (next->deadline % 1000) * 1000000LL; } else { if (!bt_os_callouts->set_wake_alarm(next_expiration, true, timer_callback, NULL)) - LOG_ERROR("%s unable to set wake alarm for %" PRId64 "ms.", __func__, next_expiration); + LOG_ERROR(LOG_TAG, "%s unable to set wake alarm for %" PRId64 "ms.", __func__, next_expiration); } done: @@ -313,7 +313,7 @@ done: } if (timer_settime(timer, TIMER_ABSTIME, &wakeup_time, NULL) == -1) - LOG_ERROR("%s unable to set timer: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to set timer: %s", __func__, strerror(errno)); // If next expiration was in the past (e.g. short timer that got context switched) // then the timer might have diarmed itself. Detect this case and work around it @@ -328,7 +328,7 @@ done: struct itimerspec time_to_expire; timer_gettime(timer, &time_to_expire); if (time_to_expire.it_value.tv_sec == 0 && time_to_expire.it_value.tv_nsec == 0) { - LOG_ERROR("%s alarm expiration too close for posix timers, switching to guns", __func__); + LOG_ERROR(LOG_TAG, "%s alarm expiration too close for posix timers, switching to guns", __func__); semaphore_post(alarm_expired); } } @@ -384,5 +384,5 @@ static void callback_dispatch(UNUSED_ATTR void *context) { pthread_mutex_unlock(&alarm->callback_lock); } - LOG_DEBUG("%s Callback thread exited", __func__); + LOG_DEBUG(LOG_TAG, "%s Callback thread exited", __func__); } diff --git a/osi/src/allocation_tracker.c b/osi/src/allocation_tracker.c index 761e58d3a..67fe8f70c 100644 --- a/osi/src/allocation_tracker.c +++ b/osi/src/allocation_tracker.c @@ -180,7 +180,7 @@ static bool allocation_entry_freed_checker(hash_map_entry_t *entry, void *contex allocation_t *allocation = (allocation_t *)entry->data; if (!allocation->freed) { *((size_t *)context) += allocation->size; // Report back the unfreed byte count - LOG_ERROR("%s found unfreed allocation. address: 0x%zx size: %zd bytes", __func__, (uintptr_t)allocation->ptr, allocation->size); + LOG_ERROR(LOG_TAG, "%s found unfreed allocation. address: 0x%zx size: %zd bytes", __func__, (uintptr_t)allocation->ptr, allocation->size); } return true; diff --git a/osi/src/array.c b/osi/src/array.c index c2ef1bc75..f8e11e812 100644 --- a/osi/src/array.c +++ b/osi/src/array.c @@ -43,7 +43,7 @@ array_t *array_new(size_t element_size) { array_t *array = osi_calloc(sizeof(array_t) + element_size * INTERNAL_ELEMENTS); if (!array) { - LOG_ERROR("%s unable to allocate memory for array with elements of size %zu.", __func__, element_size); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for array with elements of size %zu.", __func__, element_size); return NULL; } @@ -87,7 +87,7 @@ bool array_append_ptr(array_t *array, void *data) { assert(data != NULL); if (array->length == array->capacity && !grow(array)) { - LOG_ERROR("%s unable to grow array past current capacity of %zu elements of size %zu.", __func__, array->capacity, array->element_size); + LOG_ERROR(LOG_TAG, "%s unable to grow array past current capacity of %zu elements of size %zu.", __func__, array->capacity, array->element_size); return false; } diff --git a/osi/src/buffer.c b/osi/src/buffer.c index ebf51aa53..4d6bcf0f4 100644 --- a/osi/src/buffer.c +++ b/osi/src/buffer.c @@ -37,7 +37,7 @@ buffer_t *buffer_new(size_t size) { buffer_t *buffer = osi_calloc(sizeof(buffer_t) + size); if (!buffer) { - LOG_ERROR("%s unable to allocate buffer of %zu bytes.", __func__, size); + LOG_ERROR(LOG_TAG, "%s unable to allocate buffer of %zu bytes.", __func__, size); return NULL; } @@ -60,7 +60,7 @@ buffer_t *buffer_new_slice(const buffer_t *buf, size_t slice_size) { buffer_t *ret = osi_calloc(sizeof(buffer_t)); if (!ret) { - LOG_ERROR("%s unable to allocate new buffer for slice of length %zu.", __func__, slice_size); + LOG_ERROR(LOG_TAG, "%s unable to allocate new buffer for slice of length %zu.", __func__, slice_size); return NULL; } diff --git a/osi/src/config.c b/osi/src/config.c index c6b73dc91..7af398f69 100644 --- a/osi/src/config.c +++ b/osi/src/config.c @@ -61,13 +61,13 @@ static entry_t *entry_find(const config_t *config, const char *section, const ch config_t *config_new_empty(void) { config_t *config = osi_calloc(sizeof(config_t)); if (!config) { - LOG_ERROR("%s unable to allocate memory for config_t.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for config_t.", __func__); goto error; } config->sections = list_new(section_free); if (!config->sections) { - LOG_ERROR("%s unable to allocate list for sections.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate list for sections.", __func__); goto error; } @@ -87,7 +87,7 @@ config_t *config_new(const char *filename) { FILE *fp = fopen(filename, "rt"); if (!fp) { - LOG_ERROR("%s unable to open file '%s': %s", __func__, filename, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to open file '%s': %s", __func__, filename, strerror(errno)); config_free(config); return NULL; } @@ -253,7 +253,7 @@ bool config_save(const config_t *config, const char *filename) { char *temp_filename = osi_calloc(strlen(filename) + 5); if (!temp_filename) { - LOG_ERROR("%s unable to allocate memory for filename.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for filename.", __func__); return false; } @@ -262,7 +262,7 @@ bool config_save(const config_t *config, const char *filename) { FILE *fp = fopen(temp_filename, "wt"); if (!fp) { - LOG_ERROR("%s unable to write file '%s': %s", __func__, temp_filename, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to write file '%s': %s", __func__, temp_filename, strerror(errno)); goto error; } @@ -284,7 +284,7 @@ bool config_save(const config_t *config, const char *filename) { fclose(fp); if (rename(temp_filename, filename) == -1) { - LOG_ERROR("%s unable to commit file '%s': %s", __func__, filename, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to commit file '%s': %s", __func__, filename, strerror(errno)); goto error; } @@ -332,7 +332,7 @@ static void config_parse(FILE *fp, config_t *config) { if (*line_ptr == '[') { size_t len = strlen(line_ptr); if (line_ptr[len - 1] != ']') { - LOG_DEBUG("%s unterminated section name on line %d.", __func__, line_num); + LOG_DEBUG(LOG_TAG, "%s unterminated section name on line %d.", __func__, line_num); continue; } strncpy(section, line_ptr + 1, len - 2); @@ -340,7 +340,7 @@ static void config_parse(FILE *fp, config_t *config) { } else { char *split = strchr(line_ptr, '='); if (!split) { - LOG_DEBUG("%s no key/value separator found on line %d.", __func__, line_num); + LOG_DEBUG(LOG_TAG, "%s no key/value separator found on line %d.", __func__, line_num); continue; } diff --git a/osi/src/data_dispatcher.c b/osi/src/data_dispatcher.c index 31867371e..59265fa34 100644 --- a/osi/src/data_dispatcher.c +++ b/osi/src/data_dispatcher.c @@ -40,19 +40,19 @@ data_dispatcher_t *data_dispatcher_new(const char *name) { data_dispatcher_t *ret = osi_calloc(sizeof(data_dispatcher_t)); if (!ret) { - LOG_ERROR("%s unable to allocate memory for new data dispatcher.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for new data dispatcher.", __func__); goto error; } ret->dispatch_table = hash_map_new(DEFAULT_TABLE_BUCKETS, hash_function_naive, NULL, NULL, NULL); if (!ret->dispatch_table) { - LOG_ERROR("%s unable to create dispatch table.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create dispatch table.", __func__); goto error; } ret->name = osi_strdup(name); if (!ret->name) { - LOG_ERROR("%s unable to duplicate provided name.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to duplicate provided name.", __func__); goto error; } @@ -100,7 +100,7 @@ bool data_dispatcher_dispatch(data_dispatcher_t *dispatcher, data_dispatcher_typ if (queue) fixed_queue_enqueue(queue, data); else - LOG_WARN("%s has no handler for type (%zd) in data dispatcher named: %s", __func__, type, dispatcher->name); + LOG_WARN(LOG_TAG, "%s has no handler for type (%zd) in data dispatcher named: %s", __func__, type, dispatcher->name); return queue != NULL; } diff --git a/osi/src/eager_reader.c b/osi/src/eager_reader.c index 6f6fe86b4..250f39428 100644 --- a/osi/src/eager_reader.c +++ b/osi/src/eager_reader.c @@ -79,7 +79,7 @@ eager_reader_t *eager_reader_new( eager_reader_t *ret = osi_calloc(sizeof(eager_reader_t)); if (!ret) { - LOG_ERROR("%s unable to allocate memory for new eager_reader.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for new eager_reader.", __func__); goto error; } @@ -88,7 +88,7 @@ eager_reader_t *eager_reader_new( ret->bytes_available_fd = eventfd(0, 0); if (ret->bytes_available_fd == INVALID_FD) { - LOG_ERROR("%s unable to create output reading semaphore.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create output reading semaphore.", __func__); goto error; } @@ -96,13 +96,13 @@ eager_reader_t *eager_reader_new( ret->buffers = fixed_queue_new(max_buffer_count); if (!ret->buffers) { - LOG_ERROR("%s unable to create buffers queue.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create buffers queue.", __func__); goto error; } ret->inbound_read_thread = thread_new(thread_name); if (!ret->inbound_read_thread) { - LOG_ERROR("%s unable to make reading thread.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to make reading thread.", __func__); goto error; } @@ -179,7 +179,7 @@ size_t eager_reader_read(eager_reader_t *reader, uint8_t *buffer, size_t max_siz // Find out how many bytes we have available in our various buffers. eventfd_t bytes_available; if (eventfd_read(reader->bytes_available_fd, &bytes_available) == -1) { - LOG_ERROR("%s unable to read semaphore for output data.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to read semaphore for output data.", __func__); return 0; } @@ -207,7 +207,7 @@ size_t eager_reader_read(eager_reader_t *reader, uint8_t *buffer, size_t max_siz bytes_available -= bytes_consumed; if (eventfd_write(reader->bytes_available_fd, bytes_available) == -1) { - LOG_ERROR("%s unable to write back bytes available for output data.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to write back bytes available for output data.", __func__); } return bytes_consumed; @@ -234,7 +234,7 @@ static void inbound_data_waiting(void *context) { data_buffer_t *buffer = (data_buffer_t *)reader->allocator->alloc(reader->buffer_size + sizeof(data_buffer_t)); if (!buffer) { - LOG_ERROR("%s couldn't aquire memory for inbound data buffer.", __func__); + LOG_ERROR(LOG_TAG, "%s couldn't aquire memory for inbound data buffer.", __func__); return; } @@ -252,9 +252,9 @@ static void inbound_data_waiting(void *context) { eventfd_write(reader->bytes_available_fd, bytes_read); } else { if (bytes_read == 0) - LOG_WARN("%s fd said bytes existed, but none were found.", __func__); + LOG_WARN(LOG_TAG, "%s fd said bytes existed, but none were found.", __func__); else - LOG_WARN("%s unable to read from file descriptor: %s", __func__, strerror(errno)); + LOG_WARN(LOG_TAG, "%s unable to read from file descriptor: %s", __func__, strerror(errno)); reader->allocator->free(buffer); } diff --git a/osi/src/future.c b/osi/src/future.c index be140ad1e..3e02462aa 100644 --- a/osi/src/future.c +++ b/osi/src/future.c @@ -37,13 +37,13 @@ static void future_free(future_t *future); future_t *future_new(void) { future_t *ret = osi_calloc(sizeof(future_t)); if (!ret) { - LOG_ERROR("%s unable to allocate memory for return value.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for return value.", __func__); goto error; } ret->semaphore = semaphore_new(0); if (!ret->semaphore) { - LOG_ERROR("%s unable to allocate memory for the semaphore.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for the semaphore.", __func__); goto error; } @@ -57,7 +57,7 @@ error:; future_t *future_new_immediate(void *value) { future_t *ret = osi_calloc(sizeof(future_t)); if (!ret) { - LOG_ERROR("%s unable to allocate memory for return value.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for return value.", __func__); goto error; } diff --git a/osi/src/reactor.c b/osi/src/reactor.c index 68b09840a..f213a4078 100644 --- a/osi/src/reactor.c +++ b/osi/src/reactor.c @@ -71,20 +71,20 @@ reactor_t *reactor_new(void) { ret->epoll_fd = epoll_create(MAX_EVENTS); if (ret->epoll_fd == INVALID_FD) { - LOG_ERROR("%s unable to create epoll instance: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to create epoll instance: %s", __func__, strerror(errno)); goto error; } ret->event_fd = eventfd(0, 0); if (ret->event_fd == INVALID_FD) { - LOG_ERROR("%s unable to create eventfd: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to create eventfd: %s", __func__, strerror(errno)); goto error; } pthread_mutex_init(&ret->list_lock, NULL); ret->invalidation_list = list_new(NULL); if (!ret->invalidation_list) { - LOG_ERROR("%s unable to allocate object invalidation list.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate object invalidation list.", __func__); goto error; } @@ -93,7 +93,7 @@ reactor_t *reactor_new(void) { event.events = EPOLLIN; event.data.ptr = NULL; if (epoll_ctl(ret->epoll_fd, EPOLL_CTL_ADD, ret->event_fd, &event) == -1) { - LOG_ERROR("%s unable to register eventfd with epoll set: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to register eventfd with epoll set: %s", __func__, strerror(errno)); goto error; } @@ -139,7 +139,7 @@ reactor_object_t *reactor_register(reactor_t *reactor, reactor_object_t *object = (reactor_object_t *)osi_calloc(sizeof(reactor_object_t)); if (!object) { - LOG_ERROR("%s unable to allocate reactor object: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to allocate reactor object: %s", __func__, strerror(errno)); return NULL; } @@ -159,7 +159,7 @@ reactor_object_t *reactor_register(reactor_t *reactor, event.data.ptr = object; if (epoll_ctl(reactor->epoll_fd, EPOLL_CTL_ADD, fd, &event) == -1) { - LOG_ERROR("%s unable to register fd %d to epoll set: %s", __func__, fd, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to register fd %d to epoll set: %s", __func__, fd, strerror(errno)); pthread_mutex_destroy(&object->lock); osi_free(object); return NULL; @@ -182,7 +182,7 @@ bool reactor_change_registration(reactor_object_t *object, event.data.ptr = object; if (epoll_ctl(object->reactor->epoll_fd, EPOLL_CTL_MOD, object->fd, &event) == -1) { - LOG_ERROR("%s unable to modify interest set for fd %d: %s", __func__, object->fd, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to modify interest set for fd %d: %s", __func__, object->fd, strerror(errno)); return false; } @@ -200,7 +200,7 @@ void reactor_unregister(reactor_object_t *obj) { reactor_t *reactor = obj->reactor; if (epoll_ctl(reactor->epoll_fd, EPOLL_CTL_DEL, obj->fd, NULL) == -1) - LOG_ERROR("%s unable to unregister fd %d from epoll set: %s", __func__, obj->fd, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to unregister fd %d from epoll set: %s", __func__, obj->fd, strerror(errno)); if (reactor->is_running && pthread_equal(pthread_self(), reactor->run_thread)) { reactor->object_removed = true; @@ -246,7 +246,7 @@ static reactor_status_t run_reactor(reactor_t *reactor, int iterations) { } while (ret == -1 && errno == EINTR); if (ret == -1) { - LOG_ERROR("%s error in epoll_wait: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s error in epoll_wait: %s", __func__, strerror(errno)); reactor->is_running = false; return REACTOR_STATUS_ERROR; } diff --git a/osi/src/semaphore.c b/osi/src/semaphore.c index c9b117d83..5ea2f05d2 100644 --- a/osi/src/semaphore.c +++ b/osi/src/semaphore.c @@ -44,7 +44,7 @@ semaphore_t *semaphore_new(unsigned int value) { if (ret) { ret->fd = eventfd(value, EFD_SEMAPHORE); if (ret->fd == INVALID_FD) { - LOG_ERROR("%s unable to allocate semaphore: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to allocate semaphore: %s", __func__, strerror(errno)); osi_free(ret); ret = NULL; } @@ -67,7 +67,7 @@ void semaphore_wait(semaphore_t *semaphore) { uint64_t value; if (eventfd_read(semaphore->fd, &value) == -1) - LOG_ERROR("%s unable to wait on semaphore: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to wait on semaphore: %s", __func__, strerror(errno)); } bool semaphore_try_wait(semaphore_t *semaphore) { @@ -76,11 +76,11 @@ bool semaphore_try_wait(semaphore_t *semaphore) { int flags = fcntl(semaphore->fd, F_GETFL); if (flags == -1) { - LOG_ERROR("%s unable to get flags for semaphore fd: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to get flags for semaphore fd: %s", __func__, strerror(errno)); return false; } if (fcntl(semaphore->fd, F_SETFL, flags | O_NONBLOCK) == -1) { - LOG_ERROR("%s unable to set O_NONBLOCK for semaphore fd: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to set O_NONBLOCK for semaphore fd: %s", __func__, strerror(errno)); return false; } @@ -89,7 +89,7 @@ bool semaphore_try_wait(semaphore_t *semaphore) { return false; if (fcntl(semaphore->fd, F_SETFL, flags) == -1) - LOG_ERROR("%s unable to resetore flags for semaphore fd: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to resetore flags for semaphore fd: %s", __func__, strerror(errno)); return true; } @@ -98,7 +98,7 @@ void semaphore_post(semaphore_t *semaphore) { assert(semaphore->fd != INVALID_FD); if (eventfd_write(semaphore->fd, 1ULL) == -1) - LOG_ERROR("%s unable to post to semaphore: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to post to semaphore: %s", __func__, strerror(errno)); } int semaphore_get_fd(const semaphore_t *semaphore) { diff --git a/osi/src/socket.c b/osi/src/socket.c index 8841d5605..fa6286882 100644 --- a/osi/src/socket.c +++ b/osi/src/socket.c @@ -48,19 +48,19 @@ static void internal_write_ready(void *context); socket_t *socket_new(void) { socket_t *ret = (socket_t *)osi_calloc(sizeof(socket_t)); if (!ret) { - LOG_ERROR("%s unable to allocate memory for socket.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for socket.", __func__); goto error; } ret->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ret->fd == INVALID_FD) { - LOG_ERROR("%s unable to create socket: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to create socket: %s", __func__, strerror(errno)); goto error; } int enable = 1; if (setsockopt(ret->fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) == -1) { - LOG_ERROR("%s unable to set SO_REUSEADDR: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to set SO_REUSEADDR: %s", __func__, strerror(errno)); goto error; } @@ -78,7 +78,7 @@ socket_t *socket_new_from_fd(int fd) { socket_t *ret = (socket_t *)osi_calloc(sizeof(socket_t)); if (!ret) { - LOG_ERROR("%s unable to allocate memory for socket.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for socket.", __func__); return NULL; } @@ -103,12 +103,12 @@ bool socket_listen(const socket_t *socket, port_t port) { addr.sin_addr.s_addr = 0; addr.sin_port = htons(port); if (bind(socket->fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { - LOG_ERROR("%s unable to bind socket to port %u: %s", __func__, port, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to bind socket to port %u: %s", __func__, port, strerror(errno)); return false; } if (listen(socket->fd, 10) == -1) { - LOG_ERROR("%s unable to listen on port %u: %s", __func__, port, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to listen on port %u: %s", __func__, port, strerror(errno)); return false; } @@ -120,14 +120,14 @@ socket_t *socket_accept(const socket_t *socket) { int fd = accept(socket->fd, NULL, NULL); if (fd == INVALID_FD) { - LOG_ERROR("%s unable to accept socket: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to accept socket: %s", __func__, strerror(errno)); return NULL; } socket_t *ret = (socket_t *)osi_calloc(sizeof(socket_t)); if (!ret) { close(fd); - LOG_ERROR("%s unable to allocate memory for socket.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for socket.", __func__); return NULL; } diff --git a/osi/src/thread.c b/osi/src/thread.c index c6c89792a..2747e3046 100644 --- a/osi/src/thread.c +++ b/osi/src/thread.c @@ -140,7 +140,7 @@ bool thread_post(thread_t *thread, thread_fn func, void *context) { // or when the item is removed from the queue for dispatch. work_item_t *item = (work_item_t *)osi_malloc(sizeof(work_item_t)); if (!item) { - LOG_ERROR("%s unable to allocate memory: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory: %s", __func__, strerror(errno)); return false; } item->func = func; @@ -178,7 +178,7 @@ static void *run_thread(void *start_arg) { assert(thread != NULL); if (prctl(PR_SET_NAME, (unsigned long)thread->name) == -1) { - LOG_ERROR("%s unable to set thread name: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s unable to set thread name: %s", __func__, strerror(errno)); start->error = errno; semaphore_post(start->start_sem); return NULL; @@ -207,7 +207,7 @@ static void *run_thread(void *start_arg) { } if (count > fixed_queue_capacity(thread->work_queue)) - LOG_DEBUG("%s growing event queue on shutdown.", __func__); + LOG_DEBUG(LOG_TAG, "%s growing event queue on shutdown.", __func__); return NULL; } diff --git a/service/a2dp_source.cpp b/service/a2dp_source.cpp index 6cde92ae7..e8ff8a911 100644 --- a/service/a2dp_source.cpp +++ b/service/a2dp_source.cpp @@ -58,7 +58,7 @@ int A2dpSource::Start() { // Get the interface to the a2dp source profile. const void *interface = bt_->GetInterface(BT_PROFILE_ADVANCED_AUDIO_ID); if (!interface) { - LOG_ERROR("Error getting audio source interface"); + LOG_ERROR(LOG_TAG, "Error getting audio source interface"); return -1; } @@ -66,7 +66,7 @@ int A2dpSource::Start() { bt_status_t btstat = av_->init(&av_callbacks); if (btstat != BT_STATUS_SUCCESS && btstat != BT_STATUS_DONE) { - LOG_ERROR("Failed to initialize audio source interface: %s %d", + LOG_ERROR(LOG_TAG, "Failed to initialize audio source interface: %s %d", BtStatusText(btstat), btstat); return -1; } diff --git a/service/core_stack.cpp b/service/core_stack.cpp index d40d64bd5..2b8c64be8 100644 --- a/service/core_stack.cpp +++ b/service/core_stack.cpp @@ -91,7 +91,7 @@ void GenericDevicePropertiesCallback(bt_status_t status, int num_properties, bt_property_t *properties) { if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s: %s", __func__, BtStatusText(status)); + LOG_ERROR(LOG_TAG, "%s: %s", __func__, BtStatusText(status)); return; } @@ -133,7 +133,7 @@ void GenericDevicePropertiesCallback(bt_status_t status, void AclStateChangedCallback(bt_status_t status, bt_bdaddr_t *remote_bd_addr, bt_acl_state_t state) { if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("%s: %s", __func__, BtStatusText(status)); + LOG_ERROR(LOG_TAG, "%s: %s", __func__, BtStatusText(status)); return; } @@ -187,7 +187,7 @@ bool CoreStack::Initialize() { const hw_module_t *module; int status = hw_get_module(BT_HARDWARE_MODULE_ID, &module); if (status) { - LOG_ERROR("Error getting bluetooth module"); + LOG_ERROR(LOG_TAG, "Error getting bluetooth module"); return false; } @@ -195,7 +195,7 @@ bool CoreStack::Initialize() { hw_device_t *device; status = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device); if (status) { - LOG_ERROR("Error opening bluetooth module"); + LOG_ERROR(LOG_TAG, "Error opening bluetooth module"); return false; } @@ -206,19 +206,19 @@ bool CoreStack::Initialize() { // Bind module callbacks to local handlers. status = hal_->init(&bt_callbacks); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("Error binding callbacks"); + LOG_ERROR(LOG_TAG, "Error binding callbacks"); return false; } status = hal_->set_os_callouts(&callouts); if (status != BT_STATUS_SUCCESS) { - LOG_ERROR("Error binding OS callbacks"); + LOG_ERROR(LOG_TAG, "Error binding OS callbacks"); return false; } status = hal_->enable(); if (status) { - LOG_ERROR("Enable failed: %d", status); + LOG_ERROR(LOG_TAG, "Enable failed: %d", status); return false; } @@ -240,7 +240,7 @@ bool CoreStack::SetAdapterName(const std::string &name) { int status = hal_->set_adapter_property(&prop); if (status) { - LOG_ERROR("%s: prop change failed: %d", __func__, status); + LOG_ERROR(LOG_TAG, "%s: prop change failed: %d", __func__, status); return false; } @@ -259,7 +259,7 @@ bool CoreStack::SetClassicDiscoverable() { int status = hal_->set_adapter_property(&disc); if (status) { - LOG_ERROR("Prop change failed: %d", status); + LOG_ERROR(LOG_TAG, "Prop change failed: %d", status); return false; } @@ -272,7 +272,7 @@ const void *CoreStack::GetInterface(const char *profile) { // Get the interface to the GATT profile. const void *interface = hal_->get_profile_interface(profile); if (!interface) { - LOG_ERROR("Error getting %s interface", profile); + LOG_ERROR(LOG_TAG, "Error getting %s interface", profile); return nullptr; } return interface; diff --git a/service/gatt_server.cpp b/service/gatt_server.cpp index 54e407ec9..03b31f66a 100644 --- a/service/gatt_server.cpp +++ b/service/gatt_server.cpp @@ -204,7 +204,7 @@ void RequestWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, int status = write(internal->pipefd[kPipeWriteEnd], attr_uuid.data(), attr_uuid.size()); if (-1 == status) - LOG_ERROR("%s: write failed: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s: write failed: %s", __func__, strerror(errno)); } else { // This is a multi-frame characteristic write. // Wait for an 'RequestExecWriteCallback' to notify completion. @@ -237,7 +237,7 @@ void RequestExecWriteCallback(int conn_id, int trans_id, bt_bdaddr_t *bda, internal->last_write.GetFullBigEndian(); int status = write(internal->pipefd[kPipeWriteEnd], uuid.data(), uuid.size()); if (-1 == status) - LOG_ERROR("%s: write failed: %s", __func__, strerror(errno)); + LOG_ERROR(LOG_TAG, "%s: write failed: %s", __func__, strerror(errno)); } void ConnectionCallback(int conn_id, int server_if, int connected, @@ -289,7 +289,7 @@ void ServiceStartedCallback(int status, int server_if, int srvc_handle) { bt_status_t btstat = internal->gatt->client->register_client(&client_id); if (btstat != BT_STATUS_SUCCESS) { - LOG_ERROR("%s: Failed to register client", __func__); + LOG_ERROR(LOG_TAG, "%s: Failed to register client", __func__); } } @@ -309,7 +309,7 @@ void RegisterClientCallback(int status, int client_if, bt_uuid_t *app_uuid) { 0, nullptr, /* no service data */ 0, nullptr /* no service id yet */); if (btstat != BT_STATUS_SUCCESS) { - LOG_ERROR("Failed to set advertising data"); + LOG_ERROR(LOG_TAG, "Failed to set advertising data"); return; } @@ -317,7 +317,7 @@ void RegisterClientCallback(int status, int client_if, bt_uuid_t *app_uuid) { // This calls back to ListenCallback. btstat = internal->gatt->client->listen(client_if, true); if (btstat != BT_STATUS_SUCCESS) { - LOG_ERROR("Failed to start listening"); + LOG_ERROR(LOG_TAG, "Failed to start listening"); } } @@ -444,19 +444,19 @@ int ServerInternals::Initialize(CoreStack *bt) { gatt = reinterpret_cast( bt->GetInterface(BT_PROFILE_GATT_ID)); if (!gatt) { - LOG_ERROR("Error getting GATT interface"); + LOG_ERROR(LOG_TAG, "Error getting GATT interface"); return -1; } bt_status_t btstat = gatt->init(&gatt_callbacks); if (btstat != BT_STATUS_SUCCESS) { - LOG_ERROR("Failed to initialize gatt interface"); + LOG_ERROR(LOG_TAG, "Failed to initialize gatt interface"); return -1; } int status = pipe(pipefd); if (status == -1) { - LOG_ERROR("pipe creation failed: %s", strerror(errno)); + LOG_ERROR(LOG_TAG, "pipe creation failed: %s", strerror(errno)); return -1; } @@ -484,7 +484,7 @@ Server::~Server() {} bool Server::Initialize(const Uuid &service_id, int *gatt_pipe, CoreStack *bt) { internal_.reset(new ServerInternals); if (!internal_) { - LOG_ERROR("Error creating internals"); + LOG_ERROR(LOG_TAG, "Error creating internals"); return false; } internal = internal_.get(); @@ -492,7 +492,7 @@ bool Server::Initialize(const Uuid &service_id, int *gatt_pipe, CoreStack *bt) { std::unique_lock lock(internal_->lock); int status = internal_->Initialize(bt); if (status) { - LOG_ERROR("Error initializing internals"); + LOG_ERROR(LOG_TAG, "Error initializing internals"); return false; } @@ -500,14 +500,14 @@ bool Server::Initialize(const Uuid &service_id, int *gatt_pipe, CoreStack *bt) { bt_status_t btstat = internal_->gatt->server->register_server(&uuid); if (btstat != BT_STATUS_SUCCESS) { - LOG_ERROR("Failed to register server"); + LOG_ERROR(LOG_TAG, "Failed to register server"); return false; } internal_->api_synchronize.wait(lock); // TODO(icoolidge): Better error handling. if (internal_->server_if == 0) { - LOG_ERROR("Initialization of server failed"); + LOG_ERROR(LOG_TAG, "Initialization of server failed"); return false; } @@ -541,7 +541,7 @@ bool Server::SetAdvertisement(const std::vector &ids, reinterpret_cast(mutable_service_data.data()), id_data.size(), reinterpret_cast(id_data.data())); if (btstat != BT_STATUS_SUCCESS) { - LOG_ERROR("Failed to set advertising data"); + LOG_ERROR(LOG_TAG, "Failed to set advertising data"); return false; } return true; @@ -572,7 +572,7 @@ bool Server::SetScanResponse(const std::vector &ids, reinterpret_cast(mutable_service_data.data()), id_data.size(), reinterpret_cast(id_data.data())); if (btstat != BT_STATUS_SUCCESS) { - LOG_ERROR("Failed to set scan response data"); + LOG_ERROR(LOG_TAG, "Failed to set scan response data"); return false; } return true; @@ -649,7 +649,7 @@ bool Server::Stop() { bool Server::ScanEnable() { bt_status_t btstat = internal_->gatt->client->scan(true); if (btstat) { - LOG_ERROR("Enable scan failed: %d", btstat); + LOG_ERROR(LOG_TAG, "Enable scan failed: %d", btstat); return false; } return true; @@ -658,7 +658,7 @@ bool Server::ScanEnable() { bool Server::ScanDisable() { bt_status_t btstat = internal_->gatt->client->scan(false); if (btstat) { - LOG_ERROR("Disable scan failed: %d", btstat); + LOG_ERROR(LOG_TAG, "Disable scan failed: %d", btstat); return false; } return true; diff --git a/service/host.cpp b/service/host.cpp index fb38f1802..a2db15bdf 100644 --- a/service/host.cpp +++ b/service/host.cpp @@ -80,7 +80,7 @@ bool Host::EventLoop() { int status = TEMP_FAILURE_RETRY(ppoll(pfds_.data(), pfds_.size(), nullptr, nullptr)); if (status < 1) { - LOG_ERROR("ppoll error"); + LOG_ERROR(LOG_TAG, "ppoll error"); return false; } @@ -110,7 +110,7 @@ bool Host::OnCreateService(const std::string& service_uuid) { bool status = gatt_servers_[service_uuid]->Initialize(Uuid(service_uuid), &gattfd, bt_); if (!status) { - LOG_ERROR("Failed to initialize bluetooth"); + LOG_ERROR(LOG_TAG, "Failed to initialize bluetooth"); return false; } pfds_.resize(kPossibleFds); @@ -229,7 +229,7 @@ bool Host::OnMessage() { std::string ipc_msg; int size = recv(pfds_[kFdIpc].fd, &ipc_msg[0], 0, MSG_PEEK | MSG_TRUNC); if (-1 == size) { - LOG_ERROR("Error reading datagram size: %s", strerror(errno)); + LOG_ERROR(LOG_TAG, "Error reading datagram size: %s", strerror(errno)); return false; } else if (0 == size) { LOG_INFO("%s:%d: Connection closed", __func__, __LINE__); @@ -239,7 +239,7 @@ bool Host::OnMessage() { ipc_msg.resize(size); size = read(pfds_[kFdIpc].fd, &ipc_msg[0], ipc_msg.size()); if (-1 == size) { - LOG_ERROR("Error reading IPC: %s", strerror(errno)); + LOG_ERROR(LOG_TAG, "Error reading IPC: %s", strerror(errno)); return false; } else if (0 == size) { LOG_INFO("%s:%d: Connection closed", __func__, __LINE__); @@ -276,7 +276,7 @@ bool Host::OnMessage() { break; } - LOG_ERROR("Malformed IPC message: %s", ipc_msg.c_str()); + LOG_ERROR(LOG_TAG, "Malformed IPC message: %s", ipc_msg.c_str()); return false; } @@ -284,7 +284,7 @@ bool Host::OnGattWrite() { Uuid::Uuid128Bit id; int r = read(pfds_[kFdGatt].fd, id.data(), id.size()); if (r != id.size()) { - LOG_ERROR("Error reading GATT attribute ID"); + LOG_ERROR(LOG_TAG, "Error reading GATT attribute ID"); return false; } @@ -303,7 +303,7 @@ bool Host::OnGattWrite() { r = write(pfds_[kFdIpc].fd, transmit.data(), transmit.size()); if (-1 == r) { - LOG_ERROR("Error replying to IPC: %s", strerror(errno)); + LOG_ERROR(LOG_TAG, "Error replying to IPC: %s", strerror(errno)); return false; } diff --git a/service/main.cpp b/service/main.cpp index c1668be51..529b9ac99 100644 --- a/service/main.cpp +++ b/service/main.cpp @@ -44,13 +44,13 @@ int main() { int server_socket = osi_android_get_control_socket(kSocketFromInit); if (server_socket == -1) { - LOG_ERROR("failed to get socket from init"); + LOG_ERROR(LOG_TAG, "failed to get socket from init"); return EXIT_FAILURE; } status = listen(server_socket, SOMAXCONN); if (status == -1) { - LOG_ERROR("listen failed: %s", strerror(errno)); + LOG_ERROR(LOG_TAG, "listen failed: %s", strerror(errno)); return EXIT_FAILURE; } @@ -61,7 +61,7 @@ int main() { while (true) { int client_socket = accept4(server_socket, nullptr, nullptr, SOCK_NONBLOCK); if (status == -1) { - LOG_ERROR("accept failed: %s", strerror(errno)); + LOG_ERROR(LOG_TAG, "accept failed: %s", strerror(errno)); return EXIT_FAILURE; } diff --git a/stack/btm/btm_ble.c b/stack/btm/btm_ble.c index 0101b97a1..b450df161 100644 --- a/stack/btm/btm_ble.c +++ b/stack/btm/btm_ble.c @@ -1650,7 +1650,7 @@ static void btm_ble_resolve_random_addr_on_conn_cmpl(void * p_rec, void *p_data) if (match_rec) { - LOG_INFO("%s matched and resolved random address", __func__); + LOG_INFO(LOG_TAG, "%s matched and resolved random address", __func__); match = TRUE; match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); @@ -1658,7 +1658,7 @@ static void btm_ble_resolve_random_addr_on_conn_cmpl(void * p_rec, void *p_data) } else { - LOG_INFO("%s unable to match and resolve random address", __func__); + LOG_INFO(LOG_TAG, "%s unable to match and resolve random address", __func__); } btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match); diff --git a/stack/btm/btm_ble_gap.c b/stack/btm/btm_ble_gap.c index 153b5985f..41be717e4 100644 --- a/stack/btm/btm_ble_gap.c +++ b/stack/btm/btm_ble_gap.c @@ -1662,7 +1662,7 @@ void btm_ble_set_adv_flag(UINT16 connect_mode, UINT16 disc_mode) btm_ble_update_dmt_flag_bits (&flag, connect_mode, disc_mode); - LOG_DEBUG("disc_mode %04x", disc_mode); + LOG_DEBUG(LOG_TAG, "disc_mode %04x", disc_mode); /* update discoverable flag */ if (disc_mode & BTM_BLE_LIMITED_DISCOVERABLE) { @@ -2748,7 +2748,7 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt if ((result = btm_ble_is_discoverable(bda, evt_type, p)) == 0) { - LOG_WARN("%s device is no longer discoverable so discarding advertising packet pkt", + LOG_WARN(LOG_TAG, "%s device is no longer discoverable so discarding advertising packet pkt", __func__); return; } diff --git a/stack/btm/btm_pm.c b/stack/btm/btm_pm.c index b22b5de68..e3588ebe7 100644 --- a/stack/btm/btm_pm.c +++ b/stack/btm/btm_pm.c @@ -624,7 +624,7 @@ static tBTM_STATUS btm_pm_snd_md_req(UINT8 pm_id, int link_ind, tBTM_PM_PWR_MD * BTM_TRACE_DEBUG("btm_pm_snd_md_req state:0x%x, link_ind: %d", p_cb->state, link_ind); #endif // BTM_PM_DEBUG - LOG_DEBUG("%s switching from %s to %s.", __func__, mode_to_string(p_cb->state), mode_to_string(md_res.mode)); + LOG_DEBUG(LOG_TAG, "%s switching from %s to %s.", __func__, mode_to_string(p_cb->state), mode_to_string(md_res.mode)); switch(md_res.mode) { case BTM_PM_MD_ACTIVE: @@ -802,7 +802,7 @@ void btm_pm_proc_mode_change (UINT8 hci_status, UINT16 hci_handle, UINT8 mode, U p_cb->state = mode; p_cb->interval = interval; - LOG_DEBUG("%s switched from %s to %s.", __func__, mode_to_string(old_state), mode_to_string(p_cb->state)); + LOG_DEBUG(LOG_TAG, "%s switched from %s to %s.", __func__, mode_to_string(old_state), mode_to_string(p_cb->state)); if ((p_lcb = l2cu_find_lcb_by_bd_addr(p->remote_addr, BT_TRANSPORT_BR_EDR)) != NULL) { diff --git a/stack/btm/btm_sec.c b/stack/btm/btm_sec.c index 126007f6b..50e80b286 100644 --- a/stack/btm/btm_sec.c +++ b/stack/btm/btm_sec.c @@ -215,7 +215,7 @@ BOOLEAN BTM_SecRegister(tBTM_APPL_INFO *p_cb_info) BTM_TRACE_EVENT("%s application registered", __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(LOG_TAG, "%s p_cb_info->p_le_callback == 0x%p", __func__, p_cb_info->p_le_callback); if (p_cb_info->p_le_callback) { #if SMP_INCLUDED == TRUE @@ -230,13 +230,13 @@ BOOLEAN BTM_SecRegister(tBTM_APPL_INFO *p_cb_info) } else { - LOG_WARN("%s p_cb_info->p_le_callback == NULL", __func__); + LOG_WARN(LOG_TAG, "%s p_cb_info->p_le_callback == NULL", __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(LOG_TAG, "%s btm_cb.api.p_le_callback = 0x%p ", __func__, btm_cb.api.p_le_callback); #endif BTM_TRACE_EVENT("%s application registered", __func__); return(TRUE); @@ -2391,7 +2391,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(LOG_TAG, "%s peer should have initiated security process by now (SM4 to SM4)", __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); @@ -4704,7 +4704,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(LOG_TAG, "%s clearing pending flag handle:%d reason:%d", __func__, handle, reason); p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ #endif diff --git a/stack/btu/btu_hcif.c b/stack/btu/btu_hcif.c index 700577271..163687a69 100644 --- a/stack/btu/btu_hcif.c +++ b/stack/btu/btu_hcif.c @@ -200,11 +200,11 @@ void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg) btu_hcif_qos_setup_comp_evt (p); break; case HCI_COMMAND_COMPLETE_EVT: - LOG_ERROR("%s should not have received a command complete event. " + LOG_ERROR(LOG_TAG, "%s should not have received a command complete event. " "Someone didn't go through the hci transmit_command function.", __func__); break; case HCI_COMMAND_STATUS_EVT: - LOG_ERROR("%s should not have received a command status event. " + LOG_ERROR(LOG_TAG, "%s should not have received a command status event. " "Someone didn't go through the hci transmit_command function.", __func__); break; case HCI_HARDWARE_ERROR_EVT: diff --git a/stack/btu/btu_init.c b/stack/btu/btu_init.c index 0888cb57e..cb7ad50d9 100644 --- a/stack/btu/btu_init.c +++ b/stack/btu/btu_init.c @@ -198,7 +198,7 @@ void BTU_StartUp(void) return; error_exit:; - LOG_ERROR("%s Unable to allocate resources for bt_workqueue", __func__); + LOG_ERROR(LOG_TAG, "%s Unable to allocate resources for bt_workqueue", __func__); BTU_ShutDown(); } diff --git a/stack/btu/btu_task.c b/stack/btu/btu_task.c index 41170f020..982f5dfe7 100644 --- a/stack/btu/btu_task.c +++ b/stack/btu/btu_task.c @@ -261,7 +261,7 @@ void btu_task_start_up(UNUSED_ATTR void *context) { BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API, "btu_task pending for preload complete event"); - LOG_INFO("Bluetooth chip preload is complete"); + LOG_INFO(LOG_TAG, "Bluetooth chip preload is complete"); BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API, "btu_task received preload complete event"); @@ -462,7 +462,7 @@ void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) { alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_ERROR("%s Unable to create alarm", __func__); + LOG_ERROR(LOG_TAG, "%s Unable to create alarm", __func__); return; } alarm_cancel(alarm); @@ -493,7 +493,7 @@ void btu_stop_timer(TIMER_LIST_ENT *p_tle) { // Get the alarm for the timer list entry. alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_WARN("%s Unable to find expected alarm in hashmap", __func__); + LOG_WARN(LOG_TAG, "%s Unable to find expected alarm in hashmap", __func__); return; } alarm_cancel(alarm); @@ -542,7 +542,7 @@ void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ti alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_ERROR("%s Unable to create alarm", __func__); + LOG_ERROR(LOG_TAG, "%s Unable to create alarm", __func__); return; } alarm_cancel(alarm); @@ -573,7 +573,7 @@ void btu_stop_quick_timer(TIMER_LIST_ENT *p_tle) { // Get the alarm for the timer list entry. alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_WARN("%s Unable to find expected alarm in hashmap", __func__); + LOG_WARN(LOG_TAG, "%s Unable to find expected alarm in hashmap", __func__); return; } alarm_cancel(alarm); @@ -604,7 +604,7 @@ void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_ERROR("%s Unable to create alarm", __func__); + LOG_ERROR(LOG_TAG, "%s Unable to create alarm", __func__); return; } alarm_cancel(alarm); @@ -626,7 +626,7 @@ void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle) { // Get the alarm for the timer list entry. alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle); if (alarm == NULL) { - LOG_WARN("%s Unable to find expected alarm in hashmap", __func__); + LOG_WARN(LOG_TAG, "%s Unable to find expected alarm in hashmap", __func__); return; } alarm_cancel(alarm); diff --git a/stack/l2cap/l2c_api.c b/stack/l2cap/l2c_api.c index e7dbf36e2..3c95af7ee 100644 --- a/stack/l2cap/l2c_api.c +++ b/stack/l2cap/l2c_api.c @@ -347,7 +347,7 @@ bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *cal tL2C_CCB *channel_control_block = l2cu_find_ccb_by_cid(NULL, local_cid); if (!channel_control_block) { - LOG_ERROR("%s no channel control block found for L2CAP LCID=0x%04x.", __func__, local_cid); + LOG_ERROR(LOG_TAG, "%s no channel control block found for L2CAP LCID=0x%04x.", __func__, local_cid); return false; } @@ -359,7 +359,7 @@ bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *cal if (!channel_control_block->should_free_rcb) { registration_control_block = (tL2C_RCB *)osi_calloc(sizeof(tL2C_RCB)); if (!registration_control_block) { - LOG_ERROR("%s unable to allocate registration control block.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate registration control block.", __func__); return false; } diff --git a/stack/l2cap/l2c_main.c b/stack/l2cap/l2c_main.c index fcc53d5b1..03e154199 100644 --- a/stack/l2cap/l2c_main.c +++ b/stack/l2cap/l2c_main.c @@ -22,15 +22,15 @@ * ******************************************************************************/ +#include #include #include -#include -#include "device/include/controller.h" -#include "btcore/include/counter.h" #include "bt_target.h" +#include "btcore/include/counter.h" #include "btm_int.h" #include "btu.h" +#include "device/include/controller.h" #include "gki.h" #include "hcimsgs.h" #include "l2c_api.h" @@ -38,6 +38,8 @@ #include "l2cdefs.h" #include "osi/include/log.h" +#define LOG_TAG "l2c_main" + /********************************************************************************/ /* L O C A L F U N C T I O N P R O T O T Y P E S */ /********************************************************************************/ @@ -903,7 +905,7 @@ void l2c_init (void) l2cb.rcv_pending_q = list_new(NULL); if (l2cb.rcv_pending_q == NULL) - LOG_ERROR("%s unable to allocate memory for link layer control block", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate memory for link layer control block", __func__); } void l2c_free(void) { diff --git a/stack/l2cap/l2cap_client.c b/stack/l2cap/l2cap_client.c index 95b8e0131..0b2f0edbb 100644 --- a/stack/l2cap/l2cap_client.c +++ b/stack/l2cap/l2cap_client.c @@ -92,14 +92,14 @@ l2cap_client_t *l2cap_client_new(const l2cap_client_callbacks_t *callbacks, void if (!l2cap_clients) { l2cap_clients = list_new(NULL); if (!l2cap_clients) { - LOG_ERROR("%s unable to allocate space for L2CAP client list.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate space for L2CAP client list.", __func__); return NULL; } } l2cap_client_t *ret = (l2cap_client_t *)osi_calloc(sizeof(l2cap_client_t)); if (!ret) { - LOG_ERROR("%s unable to allocate L2CAP client.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate L2CAP client.", __func__); goto error; } @@ -109,7 +109,7 @@ l2cap_client_t *l2cap_client_new(const l2cap_client_callbacks_t *callbacks, void ret->remote_mtu = L2CAP_MTU_DEFAULT; ret->outbound_fragments = list_new(NULL); if (!ret) { - LOG_ERROR("%s unable to allocate outbound L2CAP fragment list.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to allocate outbound L2CAP fragment list.", __func__); goto error; } @@ -144,7 +144,7 @@ bool l2cap_client_connect(l2cap_client_t *client, const bt_bdaddr_t *remote_bdad client->local_channel_id = L2CA_ConnectReq(psm, (uint8_t *)remote_bdaddr); if (!client->local_channel_id) { - LOG_ERROR("%s unable to create L2CAP connection.", __func__); + LOG_ERROR(LOG_TAG, "%s unable to create L2CAP connection.", __func__); return false; } @@ -156,7 +156,7 @@ void l2cap_client_disconnect(l2cap_client_t *client) { assert(client != NULL); if (client->local_channel_id && !L2CA_DisconnectReq(client->local_channel_id)) - LOG_ERROR("%s unable to send disconnect message for LCID 0x%04x.", __func__, client->local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to send disconnect message for LCID 0x%04x.", __func__, client->local_channel_id); client->local_channel_id = 0; client->remote_mtu = L2CAP_MTU_DEFAULT; @@ -194,12 +194,12 @@ static void connect_completed_cb(uint16_t local_channel_id, uint16_t error_code) l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client for LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client for LCID 0x%04x.", __func__, local_channel_id); return; } if (error_code != L2CAP_CONN_OK) { - LOG_ERROR("%s error connecting L2CAP channel: %d.", __func__, error_code); + LOG_ERROR(LOG_TAG, "%s error connecting L2CAP channel: %d.", __func__, error_code); client->callbacks.disconnected(client, client->context); return; } @@ -207,7 +207,7 @@ static void connect_completed_cb(uint16_t local_channel_id, uint16_t error_code) // Use default L2CAP parameters. tL2CAP_CFG_INFO desired_parameters = { 0 }; if (!L2CA_ConfigReq(local_channel_id, &desired_parameters)) { - LOG_ERROR("%s error sending L2CAP config parameters.", __func__); + LOG_ERROR(LOG_TAG, "%s error sending L2CAP config parameters.", __func__); client->callbacks.disconnected(client, client->context); } } @@ -217,7 +217,7 @@ static void config_request_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *reques l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); return; } @@ -245,7 +245,7 @@ static void config_request_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *reques } if (!L2CA_ConfigRsp(local_channel_id, &response)) { - LOG_ERROR("%s unable to send config response for LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to send config response for LCID 0x%04x.", __func__, local_channel_id); l2cap_client_disconnect(client); return; } @@ -260,7 +260,7 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); return; } @@ -271,7 +271,7 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego case L2CAP_CFG_UNACCEPTABLE_PARAMS: // TODO: see if we can renegotiate parameters instead of dropping the connection. - LOG_WARN("%s dropping L2CAP connection due to unacceptable config parameters.", __func__); + LOG_WARN(LOG_TAG, "%s dropping L2CAP connection due to unacceptable config parameters.", __func__); l2cap_client_disconnect(client); break; @@ -284,7 +284,7 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego // Failure, no further parameter negotiation possible. default: - LOG_WARN("%s L2CAP parameter negotiation failed with error code %d.", __func__, negotiated_parameters->result); + LOG_WARN(LOG_TAG, "%s L2CAP parameter negotiation failed with error code %d.", __func__, negotiated_parameters->result); l2cap_client_disconnect(client); break; } @@ -293,7 +293,7 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego static void disconnect_request_cb(uint16_t local_channel_id, bool ack_required) { l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client with LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client with LCID 0x%04x.", __func__, local_channel_id); return; } @@ -312,7 +312,7 @@ static void disconnect_completed_cb(uint16_t local_channel_id, UNUSED_ATTR uint1 l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client with LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client with LCID 0x%04x.", __func__, local_channel_id); return; } @@ -327,7 +327,7 @@ static void congestion_cb(uint16_t local_channel_id, bool is_congested) { l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); return; } @@ -348,7 +348,7 @@ static void read_ready_cb(uint16_t local_channel_id, BT_HDR *packet) { l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR(LOG_TAG, "%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); return; } @@ -412,7 +412,7 @@ static void dispatch_fragments(l2cap_client_t *client) { return; case L2CAP_DW_FAILED: - LOG_ERROR("%s error writing data to L2CAP connection LCID 0x%04x; disconnecting.", __func__, client->local_channel_id); + LOG_ERROR(LOG_TAG, "%s error writing data to L2CAP connection LCID 0x%04x; disconnecting.", __func__, client->local_channel_id); l2cap_client_disconnect(client); return; diff --git a/stack/rfcomm/port_api.c b/stack/rfcomm/port_api.c index 73ced16ea..75c3de6a8 100644 --- a/stack/rfcomm/port_api.c +++ b/stack/rfcomm/port_api.c @@ -39,10 +39,12 @@ /* duration of break in 200ms units */ #define PORT_BREAK_DURATION 1 -#define info(fmt, ...) LOG_INFO ("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) -#define debug(fmt, ...) LOG_DEBUG ("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) -#define error(fmt, ...) LOG_ERROR ("## ERROR : %s: " fmt "##",__FUNCTION__, ## __VA_ARGS__) -#define asrt(s) if(!(s)) LOG_ERROR ("## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) +#define LOG_TAG "port_api" + +#define info(fmt, ...) LOG_INFO(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__) +#define debug(fmt, ...) LOG_DEBUG(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__) +#define error(fmt, ...) LOG_ERROR(LOG_TAG, "## ERROR : %s: " fmt "##",__FUNCTION__, ## __VA_ARGS__) +#define asrt(s) if(!(s)) LOG_ERROR(LOG_TAG, "## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) /* Mapping from PORT_* result codes to human readable strings. */ static const char *result_code_strings[] = { diff --git a/stack/srvc/srvc_dis.c b/stack/srvc/srvc_dis.c index 4a1e1bbf6..788051ed1 100644 --- a/stack/srvc/srvc_dis.c +++ b/stack/srvc/srvc_dis.c @@ -210,7 +210,7 @@ static void dis_gatt_c_read_dis_value_cmpl(UINT16 conn_id) if (dis_cb.p_read_dis_cback && p_clcb) { - LOG_INFO("%s conn_id:%d attr_mask = 0x%04x", __func__, conn_id, + LOG_INFO(LOG_TAG, "%s conn_id:%d attr_mask = 0x%04x", __func__, conn_id, p_clcb->dis_value.attr_mask); (*dis_cb.p_read_dis_cback)(p_clcb->bda, &p_clcb->dis_value); diff --git a/utils/src/bt_utils.c b/utils/src/bt_utils.c index 2420716e1..d2962c9d7 100644 --- a/utils/src/bt_utils.c +++ b/utils/src/bt_utils.c @@ -148,7 +148,7 @@ void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) { pthread_mutex_unlock(&gIdxLock); if (rc) { - LOG_WARN("failed to change sched policy, tid %d, err: %d", tid, errno); + LOG_WARN(LOG_TAG, "failed to change sched policy, tid %d, err: %d", tid, errno); } // always use urgent priority for HCI worker thread until we can adjust @@ -159,7 +159,7 @@ void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task) { priority = ANDROID_PRIORITY_URGENT_AUDIO; if (setpriority(PRIO_PROCESS, tid, priority) < 0) { - LOG_WARN("failed to change priority tid: %d to %d", tid, priority); + LOG_WARN(LOG_TAG, "failed to change priority tid: %d to %d", tid, priority); } } @@ -186,7 +186,7 @@ void adjust_priority_a2dp(int start) { { if (setpriority(PRIO_PROCESS, tid, priority) < 0) { - LOG_WARN("failed to change priority tid: %d to %d", tid, priority); + LOG_WARN(LOG_TAG, "failed to change priority tid: %d to %d", tid, priority); } } } -- 2.11.0