Loading system/internal_include/bt_target.h +0 −5 Original line number Diff line number Diff line Loading @@ -389,11 +389,6 @@ #define BTM_MAX_PM_RECORDS 2 #endif /* This is set to show debug trace messages for the power manager. */ #ifndef BTM_PM_DEBUG #define BTM_PM_DEBUG FALSE #endif /* If the user does not respond to security process requests within this many * seconds, a negative response would be sent automatically. * 30 is LMP response timeout value */ Loading system/main/shim/hci_layer.cc +32 −18 Original line number Diff line number Diff line Loading @@ -19,12 +19,10 @@ #include "hci/hci_layer.h" #include <base/bind.h> #include <frameworks/base/core/proto/android/bluetooth/hci/enums.pb.h> #include <algorithm> #include <cstdint> #include "btcore/include/module.h" #include "hci/hci_packets.h" #include "hci/include/packet_fragmenter.h" #include "main/shim/hci_layer.h" Loading Loading @@ -202,7 +200,7 @@ std::unique_ptr<bluetooth::packet::RawBuilder> MakeUniquePacket( BT_HDR* WrapPacketAndCopy( uint16_t event, bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian>* data) { size_t packet_size = data->size() + BT_HDR_SIZE; size_t packet_size = data->size() + kBtHdrSize; BT_HDR* packet = reinterpret_cast<BT_HDR*>(osi_malloc(packet_size)); packet->offset = 0; packet->len = data->size(); Loading @@ -228,25 +226,39 @@ static void set_data_cb( void OnTransmitPacketCommandComplete(command_complete_cb complete_callback, void* context, bluetooth::hci::CommandCompleteView view) { LOG_DEBUG("Received cmd complete for %s", bluetooth::hci::OpCodeText(view.GetCommandOpCode()).c_str()); std::vector<const uint8_t> data(view.begin(), view.end()); BT_HDR* response = static_cast<BT_HDR*>(osi_calloc(data.size() + kBtHdrSize)); std::copy(data.begin(), data.end(), response->data); response->len = data.size(); BT_HDR* response = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_EVT, &view); complete_callback(response, context); } void OnTransmitPacketStatus(command_status_cb status_callback, void* context, bluetooth::hci::CommandStatusView view) { std::vector<const uint8_t> data(view.begin(), view.end()); class OsiObject { public: OsiObject(void* ptr) : ptr_(ptr) {} ~OsiObject() { if (ptr_ != nullptr) { osi_free(ptr_); } } void* Release() { void* ptr = ptr_; ptr_ = nullptr; return ptr; } BT_HDR* response = static_cast<BT_HDR*>(osi_calloc(data.size() + kBtHdrSize)); std::copy(data.begin(), data.end(), response->data); response->len = data.size(); private: void* ptr_; }; void OnTransmitPacketStatus(command_status_cb status_callback, void* context, std::unique_ptr<OsiObject> command, bluetooth::hci::CommandStatusView view) { LOG_DEBUG("Received cmd status %s for %s", bluetooth::hci::ErrorCodeText(view.GetStatus()).c_str(), bluetooth::hci::OpCodeText(view.GetCommandOpCode()).c_str()); uint8_t status = static_cast<uint8_t>(view.GetStatus()); status_callback(status, response, context); status_callback(status, static_cast<BT_HDR*>(command->Release()), context); } using bluetooth::common::BindOnce; Loading Loading @@ -276,15 +288,17 @@ static void transmit_command(BT_HDR* command, LOG_INFO("Sending command %s", bluetooth::hci::OpCodeText(op_code).c_str()); if (IsCommandStatusOpcode(op_code)) { auto command_unique = std::make_unique<OsiObject>(command); bluetooth::shim::GetHciLayer()->EnqueueCommand( std::move(packet), bluetooth::shim::GetGdShimHandler()->BindOnce( OnTransmitPacketStatus, status_callback, context)); std::move(packet), bluetooth::shim::GetGdShimHandler()->BindOnce( OnTransmitPacketStatus, status_callback, context, std::move(command_unique))); } else { bluetooth::shim::GetHciLayer()->EnqueueCommand( std::move(packet), bluetooth::shim::GetGdShimHandler()->BindOnce( OnTransmitPacketCommandComplete, complete_callback, context)); osi_free(command); } } Loading system/stack/acl/btm_acl.cc +3 −7 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ #define LOG_TAG "btm_acl" #include <cstdint> #include "bta/include/bta_dm_acl.h" #include "bta/sys/bta_sys.h" #include "btif/include/btif_acl.h" Loading Loading @@ -381,9 +382,7 @@ void btm_acl_created(const RawAddress& bda, uint16_t hci_handle, tBTM_PM_MCB* p_db = &btm_cb.acl_cb_.pm_mode_db[xx]; /* per ACL link */ memset(p_db, 0, sizeof(tBTM_PM_MCB)); p_db->state = BTM_PM_ST_ACTIVE; #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_sm_alloc ind:%d st:%d", xx, p_db->state); #endif // BTM_PM_DEBUG LOG_VERBOSE("btm_pm_sm_alloc ind:%d st:%d", xx, p_db->state); /* if BR/EDR do something more */ if (transport == BT_TRANSPORT_BR_EDR) { Loading Loading @@ -2601,10 +2600,7 @@ int btm_pm_find_acl_ind(const RawAddress& remote_bda) { for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) { if (p->in_use && p->remote_addr == remote_bda && p->transport == BT_TRANSPORT_BR_EDR) { #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_find_acl_ind ind:%d, st:%d", xx, btm_cb.pm_mode_db[xx].state); #endif // BTM_PM_DEBUG LOG_VERBOSE("btm_pm_find_acl_ind ind:%d", xx); break; } } Loading system/stack/acl/btm_pm.cc +54 −82 Original line number Diff line number Diff line Loading @@ -76,19 +76,6 @@ const uint8_t static const char* mode_to_string(const tBTM_PM_MODE mode); #if (BTM_PM_DEBUG == TRUE) const char* btm_pm_state_str[] = {"pm_active_state", "pm_hold_state", "pm_sniff_state", "pm_park_state", "pm_pend_state"}; const char* btm_pm_event_str[] = {"pm_set_mode_event", "pm_hci_sts_event", "pm_mod_chg_event", "pm_update_event"}; const char* btm_pm_action_str[] = {"pm_set_mode_action", "pm_update_db_action", "pm_mod_chg_action", "pm_hci_sts_action", "pm_update_action"}; #endif // BTM_PM_DEBUG /*****************************************************************************/ /* P U B L I C F U N C T I O N S */ /*****************************************************************************/ Loading Loading @@ -144,39 +131,35 @@ tBTM_STATUS BTM_PmRegister(uint8_t mask, uint8_t* p_pm_id, ******************************************************************************/ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda, const tBTM_PM_PWR_MD* p_mode) { int acl_ind; tBTM_PM_MCB* p_cb = nullptr; /* per ACL link */ tBTM_PM_MODE mode; int temp_pm_id; if (pm_id >= BTM_MAX_PM_RECORDS) { pm_id = BTM_PM_SET_ONLY_ID; } if (!p_mode) { LOG(ERROR) << __func__ << ": pm_id " << unsigned(pm_id) << " p_mode is null for " << remote_bda; LOG_ERROR("pm_id: %u, p_mode is null for %s", unsigned(pm_id), remote_bda.ToString().c_str()); return BTM_ILLEGAL_VALUE; } VLOG(2) << __func__ << " pm_id " << pm_id << " BDA: " << remote_bda << " mode:" << std::to_string(p_mode->mode); /* take out the force bit */ mode = p_mode->mode & ~BTM_PM_MD_FORCE; tBTM_PM_MODE mode = p_mode->mode & ~BTM_PM_MD_FORCE; acl_ind = btm_pm_find_acl_ind(remote_bda); if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR); int acl_ind = btm_pm_find_acl_ind(remote_bda); if (acl_ind == MAX_L2CAP_LINKS) { LOG_ERROR("addr %s is unknown", remote_bda.ToString().c_str()); return (BTM_UNKNOWN_ADDR); } p_cb = &(btm_cb.acl_cb_.pm_mode_db[acl_ind]); // per ACL link tBTM_PM_MCB* p_cb = &(btm_cb.acl_cb_.pm_mode_db[acl_ind]); if (mode != BTM_PM_MD_ACTIVE) { const controller_t* controller = controller_get_interface(); if ((mode == BTM_PM_MD_HOLD && !controller->supports_hold_mode()) || (mode == BTM_PM_MD_SNIFF && !controller->supports_sniff_mode()) || (mode == BTM_PM_MD_PARK && !controller->supports_park_mode())) { LOG(ERROR) << __func__ << ": pm_id " << unsigned(pm_id) << " mode " << unsigned(mode) << " is not supported for " << remote_bda; LOG_ERROR("pm_id %u mode %u is not supported for %s", pm_id, mode, remote_bda.ToString().c_str()); return BTM_MODE_UNSUPPORTED; } } Loading @@ -189,14 +172,13 @@ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda, (p_mode->min <= p_cb->interval)) || ((p_mode->mode & BTM_PM_MD_FORCE) == 0 && (p_mode->max >= p_cb->interval))) { VLOG(1) << __func__ << " already in requested mode " << std::to_string(p_mode->mode) << ", interval " << p_cb->interval << " max " << p_mode->max << " min " << p_mode->min; LOG_DEBUG("already in requested mode %d, interval: %d, max: %d, min: %d", p_mode->mode, p_cb->interval, p_mode->max, p_mode->min); return BTM_SUCCESS; } } temp_pm_id = pm_id; int temp_pm_id = pm_id; if (pm_id == BTM_PM_SET_ONLY_ID) { temp_pm_id = BTM_MAX_PM_RECORDS; } Loading @@ -206,32 +188,31 @@ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda, (btm_cb.pm_reg_db[pm_id].mask & BTM_PM_REG_SET)) || ((pm_id == BTM_PM_SET_ONLY_ID) && (btm_cb.acl_cb_.pm_pend_link != MAX_L2CAP_LINKS))) { #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("BTM_SetPowerMode: Saving cmd acl_ind %d temp_pm_id %d", acl_ind, temp_pm_id); #endif // BTM_PM_DEBUG LOG_VERBOSE("saving cmd acl_ind %d temp_pm_id %d", acl_ind, temp_pm_id); /* Make sure mask is set to BTM_PM_REG_SET */ btm_cb.pm_reg_db[temp_pm_id].mask |= BTM_PM_REG_SET; *(&p_cb->req_mode[temp_pm_id]) = *p_mode; p_cb->chg_ind = true; } #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm state:0x%x, pm_pend_link: %d", p_cb->state, btm_cb.acl_cb_.pm_pend_link); #endif // BTM_PM_DEBUG /* if mode == hold or pending, return */ if ((p_cb->state == BTM_PM_STS_HOLD) || (p_cb->state == BTM_PM_STS_PENDING) || (btm_cb.acl_cb_.pm_pend_link != MAX_L2CAP_LINKS)) { LOG_DEBUG("storing pm setup, state: %d, pm_pending_link: %d", p_cb->state, btm_cb.acl_cb_.pm_pend_link); /* command pending */ if (acl_ind != btm_cb.acl_cb_.pm_pend_link) { /* set the stored mask */ p_cb->state |= BTM_PM_STORED_MASK; BTM_TRACE_DEBUG("%s: btm_pm state stored:%d", __func__, acl_ind); LOG_DEBUG("btm_pm state stored: %d", acl_ind); } return BTM_CMD_STORED; } LOG_DEBUG("pm_id: %d, bda: %s, mode: %d, state: %d, pending_link: %d", pm_id, remote_bda.ToString().c_str(), p_mode->mode, p_cb->state, btm_cb.acl_cb_.pm_pend_link); return internal_.btm_pm_snd_md_req(pm_id, acl_ind, p_mode); } Loading Loading @@ -260,7 +241,10 @@ bool BTM_ReadPowerMode(const RawAddress& remote_bda, tBTM_PM_MODE* p_mode) { return false; } int acl_ind = btm_pm_find_acl_ind(remote_bda); if (acl_ind == MAX_L2CAP_LINKS) return false; if (acl_ind == MAX_L2CAP_LINKS) { LOG_WARN("unknown bda: %s", remote_bda.ToString().c_str()); return false; } *p_mode = btm_cb.acl_cb_.pm_mode_db[acl_ind].state; return true; Loading Loading @@ -291,7 +275,10 @@ tBTM_STATUS btm_read_power_mode_state(const RawAddress& remote_bda, tBTM_PM_STATE* pmState) { int acl_ind = btm_pm_find_acl_ind(remote_bda); if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR); if (acl_ind == MAX_L2CAP_LINKS) { LOG_WARN("unknown bda: %s", remote_bda.ToString().c_str()); return BTM_UNKNOWN_ADDR; } *pmState = btm_cb.acl_cb_.pm_mode_db[acl_ind].state; return BTM_SUCCESS; Loading Loading @@ -330,6 +317,7 @@ tBTM_STATUS BTM_SetSsrParams(const RawAddress& remote_bda, uint16_t max_lat, max_lat, min_rmt_to, min_loc_to); return BTM_SUCCESS; } LOG_DEBUG("pm_mode_db state: %d", btm_cb.acl_cb_.pm_mode_db[acl_ind].state); p_cb = &btm_cb.acl_cb_.pm_mode_db[acl_ind]; p_cb->max_lat = max_lat; p_cb->min_rmt_to = min_rmt_to; Loading Loading @@ -371,6 +359,7 @@ void btm_pm_reset(void) { } /* no command pending */ btm_cb.acl_cb_.pm_pend_link = MAX_L2CAP_LINKS; LOG_DEBUG("reset pm"); } /******************************************************************************* Loading Loading @@ -520,9 +509,7 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind, mode = btm_pm_get_set_mode(pm_id, p_cb, p_mode, &md_res); md_res.mode = mode; #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_snd_md_req link_ind:%d, mode: %d", link_ind, mode); #endif // BTM_PM_DEBUG LOG_DEBUG("link_ind: %d, mode: %d", link_ind, mode); if (p_cb->state == mode) { /* already in the resulting mode */ Loading Loading @@ -554,13 +541,10 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind, /* send the appropriate HCI command */ btm_cb.pm_pend_id = pm_id; #if (BTM_PM_DEBUG == TRUE) 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("switching from %s(0x%x) to %s(0x%x), link_ind: %d", mode_to_string(p_cb->state), p_cb->state, mode_to_string(md_res.mode), md_res.mode, link_ind); BTM_TRACE_DEBUG("%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: switch (p_cb->state) { Loading Loading @@ -604,9 +588,7 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind, if (btm_cb.acl_cb_.pm_pend_link == MAX_L2CAP_LINKS) { /* the command was not sent */ #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("pm_pend_link: %d", btm_cb.acl_cb_.pm_pend_link); #endif // BTM_PM_DEBUG LOG_ERROR("pm_pending_link maxed out"); return (BTM_NO_RESOURCES); } Loading @@ -626,21 +608,18 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind, * ******************************************************************************/ void btm_pm_proc_cmd_status(uint8_t status) { tBTM_PM_MCB* p_cb; tBTM_PM_STATUS pm_status; if (btm_cb.acl_cb_.pm_pend_link >= MAX_L2CAP_LINKS) return; p_cb = &btm_cb.acl_cb_.pm_mode_db[btm_cb.acl_cb_.pm_pend_link]; if (btm_cb.acl_cb_.pm_pend_link >= MAX_L2CAP_LINKS) { LOG_ERROR("pending_link: %d", btm_cb.acl_cb_.pm_pend_link); return; } tBTM_PM_MCB* p_cb = &btm_cb.acl_cb_.pm_mode_db[btm_cb.acl_cb_.pm_pend_link]; tBTM_PM_STATUS pm_status; if (status == HCI_SUCCESS) { p_cb->state = BTM_PM_ST_PENDING; pm_status = BTM_PM_STS_PENDING; #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_proc_cmd_status new state:0x%x", p_cb->state); #endif // BTM_PM_DEBUG } else /* the command was not successfull. Stay in the same state */ { } else { // the command was not successful. Stay in the same state pm_status = BTM_PM_STS_ERROR; } Loading @@ -653,11 +632,8 @@ void btm_pm_proc_cmd_status(uint8_t status) { } /* no pending cmd now */ #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG( "btm_pm_proc_cmd_status state:0x%x, pm_pend_link: %d(new: %d)", p_cb->state, btm_cb.acl_cb_.pm_pend_link, MAX_L2CAP_LINKS); #endif // BTM_PM_DEBUG LOG_DEBUG("state: %d, pend_link: %d", p_cb->state, btm_cb.acl_cb_.pm_pend_link); btm_cb.acl_cb_.pm_pend_link = MAX_L2CAP_LINKS; /******************************************************************************* Loading Loading @@ -717,8 +693,8 @@ void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle, p_cb->state = mode; p_cb->interval = interval; BTM_TRACE_DEBUG("%s switched from %s to %s.", __func__, mode_to_string(old_state), mode_to_string(p_cb->state)); LOG_DEBUG("switched from [%s] to [%s].", mode_to_string(old_state), mode_to_string(p_cb->state)); if ((p_cb->state == BTM_PM_ST_ACTIVE) || (p_cb->state == BTM_PM_ST_SNIFF)) { l2c_OnHciModeChangeSendPendingPackets(bd_addr); Loading @@ -734,16 +710,12 @@ void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle, /* new request has been made. - post a message to BTU task */ if (old_state & BTM_PM_STORED_MASK) { #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_proc_mode_change: Sending stored req:%d", xx); #endif // BTM_PM_DEBUG LOG_VERBOSE("Sending stored req: %d", xx); internal_.btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, xx, NULL); } else { for (zz = 0; zz < MAX_L2CAP_LINKS; zz++) { if (btm_cb.acl_cb_.pm_mode_db[zz].chg_ind) { #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_proc_mode_change: Sending PM req :%d", zz); #endif // BTM_PM_DEBUG LOG_VERBOSE("Sending PM req :%d", zz); internal_.btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, zz, NULL); break; } Loading Loading
system/internal_include/bt_target.h +0 −5 Original line number Diff line number Diff line Loading @@ -389,11 +389,6 @@ #define BTM_MAX_PM_RECORDS 2 #endif /* This is set to show debug trace messages for the power manager. */ #ifndef BTM_PM_DEBUG #define BTM_PM_DEBUG FALSE #endif /* If the user does not respond to security process requests within this many * seconds, a negative response would be sent automatically. * 30 is LMP response timeout value */ Loading
system/main/shim/hci_layer.cc +32 −18 Original line number Diff line number Diff line Loading @@ -19,12 +19,10 @@ #include "hci/hci_layer.h" #include <base/bind.h> #include <frameworks/base/core/proto/android/bluetooth/hci/enums.pb.h> #include <algorithm> #include <cstdint> #include "btcore/include/module.h" #include "hci/hci_packets.h" #include "hci/include/packet_fragmenter.h" #include "main/shim/hci_layer.h" Loading Loading @@ -202,7 +200,7 @@ std::unique_ptr<bluetooth::packet::RawBuilder> MakeUniquePacket( BT_HDR* WrapPacketAndCopy( uint16_t event, bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian>* data) { size_t packet_size = data->size() + BT_HDR_SIZE; size_t packet_size = data->size() + kBtHdrSize; BT_HDR* packet = reinterpret_cast<BT_HDR*>(osi_malloc(packet_size)); packet->offset = 0; packet->len = data->size(); Loading @@ -228,25 +226,39 @@ static void set_data_cb( void OnTransmitPacketCommandComplete(command_complete_cb complete_callback, void* context, bluetooth::hci::CommandCompleteView view) { LOG_DEBUG("Received cmd complete for %s", bluetooth::hci::OpCodeText(view.GetCommandOpCode()).c_str()); std::vector<const uint8_t> data(view.begin(), view.end()); BT_HDR* response = static_cast<BT_HDR*>(osi_calloc(data.size() + kBtHdrSize)); std::copy(data.begin(), data.end(), response->data); response->len = data.size(); BT_HDR* response = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_EVT, &view); complete_callback(response, context); } void OnTransmitPacketStatus(command_status_cb status_callback, void* context, bluetooth::hci::CommandStatusView view) { std::vector<const uint8_t> data(view.begin(), view.end()); class OsiObject { public: OsiObject(void* ptr) : ptr_(ptr) {} ~OsiObject() { if (ptr_ != nullptr) { osi_free(ptr_); } } void* Release() { void* ptr = ptr_; ptr_ = nullptr; return ptr; } BT_HDR* response = static_cast<BT_HDR*>(osi_calloc(data.size() + kBtHdrSize)); std::copy(data.begin(), data.end(), response->data); response->len = data.size(); private: void* ptr_; }; void OnTransmitPacketStatus(command_status_cb status_callback, void* context, std::unique_ptr<OsiObject> command, bluetooth::hci::CommandStatusView view) { LOG_DEBUG("Received cmd status %s for %s", bluetooth::hci::ErrorCodeText(view.GetStatus()).c_str(), bluetooth::hci::OpCodeText(view.GetCommandOpCode()).c_str()); uint8_t status = static_cast<uint8_t>(view.GetStatus()); status_callback(status, response, context); status_callback(status, static_cast<BT_HDR*>(command->Release()), context); } using bluetooth::common::BindOnce; Loading Loading @@ -276,15 +288,17 @@ static void transmit_command(BT_HDR* command, LOG_INFO("Sending command %s", bluetooth::hci::OpCodeText(op_code).c_str()); if (IsCommandStatusOpcode(op_code)) { auto command_unique = std::make_unique<OsiObject>(command); bluetooth::shim::GetHciLayer()->EnqueueCommand( std::move(packet), bluetooth::shim::GetGdShimHandler()->BindOnce( OnTransmitPacketStatus, status_callback, context)); std::move(packet), bluetooth::shim::GetGdShimHandler()->BindOnce( OnTransmitPacketStatus, status_callback, context, std::move(command_unique))); } else { bluetooth::shim::GetHciLayer()->EnqueueCommand( std::move(packet), bluetooth::shim::GetGdShimHandler()->BindOnce( OnTransmitPacketCommandComplete, complete_callback, context)); osi_free(command); } } Loading
system/stack/acl/btm_acl.cc +3 −7 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ #define LOG_TAG "btm_acl" #include <cstdint> #include "bta/include/bta_dm_acl.h" #include "bta/sys/bta_sys.h" #include "btif/include/btif_acl.h" Loading Loading @@ -381,9 +382,7 @@ void btm_acl_created(const RawAddress& bda, uint16_t hci_handle, tBTM_PM_MCB* p_db = &btm_cb.acl_cb_.pm_mode_db[xx]; /* per ACL link */ memset(p_db, 0, sizeof(tBTM_PM_MCB)); p_db->state = BTM_PM_ST_ACTIVE; #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_sm_alloc ind:%d st:%d", xx, p_db->state); #endif // BTM_PM_DEBUG LOG_VERBOSE("btm_pm_sm_alloc ind:%d st:%d", xx, p_db->state); /* if BR/EDR do something more */ if (transport == BT_TRANSPORT_BR_EDR) { Loading Loading @@ -2601,10 +2600,7 @@ int btm_pm_find_acl_ind(const RawAddress& remote_bda) { for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) { if (p->in_use && p->remote_addr == remote_bda && p->transport == BT_TRANSPORT_BR_EDR) { #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_find_acl_ind ind:%d, st:%d", xx, btm_cb.pm_mode_db[xx].state); #endif // BTM_PM_DEBUG LOG_VERBOSE("btm_pm_find_acl_ind ind:%d", xx); break; } } Loading
system/stack/acl/btm_pm.cc +54 −82 Original line number Diff line number Diff line Loading @@ -76,19 +76,6 @@ const uint8_t static const char* mode_to_string(const tBTM_PM_MODE mode); #if (BTM_PM_DEBUG == TRUE) const char* btm_pm_state_str[] = {"pm_active_state", "pm_hold_state", "pm_sniff_state", "pm_park_state", "pm_pend_state"}; const char* btm_pm_event_str[] = {"pm_set_mode_event", "pm_hci_sts_event", "pm_mod_chg_event", "pm_update_event"}; const char* btm_pm_action_str[] = {"pm_set_mode_action", "pm_update_db_action", "pm_mod_chg_action", "pm_hci_sts_action", "pm_update_action"}; #endif // BTM_PM_DEBUG /*****************************************************************************/ /* P U B L I C F U N C T I O N S */ /*****************************************************************************/ Loading Loading @@ -144,39 +131,35 @@ tBTM_STATUS BTM_PmRegister(uint8_t mask, uint8_t* p_pm_id, ******************************************************************************/ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda, const tBTM_PM_PWR_MD* p_mode) { int acl_ind; tBTM_PM_MCB* p_cb = nullptr; /* per ACL link */ tBTM_PM_MODE mode; int temp_pm_id; if (pm_id >= BTM_MAX_PM_RECORDS) { pm_id = BTM_PM_SET_ONLY_ID; } if (!p_mode) { LOG(ERROR) << __func__ << ": pm_id " << unsigned(pm_id) << " p_mode is null for " << remote_bda; LOG_ERROR("pm_id: %u, p_mode is null for %s", unsigned(pm_id), remote_bda.ToString().c_str()); return BTM_ILLEGAL_VALUE; } VLOG(2) << __func__ << " pm_id " << pm_id << " BDA: " << remote_bda << " mode:" << std::to_string(p_mode->mode); /* take out the force bit */ mode = p_mode->mode & ~BTM_PM_MD_FORCE; tBTM_PM_MODE mode = p_mode->mode & ~BTM_PM_MD_FORCE; acl_ind = btm_pm_find_acl_ind(remote_bda); if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR); int acl_ind = btm_pm_find_acl_ind(remote_bda); if (acl_ind == MAX_L2CAP_LINKS) { LOG_ERROR("addr %s is unknown", remote_bda.ToString().c_str()); return (BTM_UNKNOWN_ADDR); } p_cb = &(btm_cb.acl_cb_.pm_mode_db[acl_ind]); // per ACL link tBTM_PM_MCB* p_cb = &(btm_cb.acl_cb_.pm_mode_db[acl_ind]); if (mode != BTM_PM_MD_ACTIVE) { const controller_t* controller = controller_get_interface(); if ((mode == BTM_PM_MD_HOLD && !controller->supports_hold_mode()) || (mode == BTM_PM_MD_SNIFF && !controller->supports_sniff_mode()) || (mode == BTM_PM_MD_PARK && !controller->supports_park_mode())) { LOG(ERROR) << __func__ << ": pm_id " << unsigned(pm_id) << " mode " << unsigned(mode) << " is not supported for " << remote_bda; LOG_ERROR("pm_id %u mode %u is not supported for %s", pm_id, mode, remote_bda.ToString().c_str()); return BTM_MODE_UNSUPPORTED; } } Loading @@ -189,14 +172,13 @@ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda, (p_mode->min <= p_cb->interval)) || ((p_mode->mode & BTM_PM_MD_FORCE) == 0 && (p_mode->max >= p_cb->interval))) { VLOG(1) << __func__ << " already in requested mode " << std::to_string(p_mode->mode) << ", interval " << p_cb->interval << " max " << p_mode->max << " min " << p_mode->min; LOG_DEBUG("already in requested mode %d, interval: %d, max: %d, min: %d", p_mode->mode, p_cb->interval, p_mode->max, p_mode->min); return BTM_SUCCESS; } } temp_pm_id = pm_id; int temp_pm_id = pm_id; if (pm_id == BTM_PM_SET_ONLY_ID) { temp_pm_id = BTM_MAX_PM_RECORDS; } Loading @@ -206,32 +188,31 @@ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda, (btm_cb.pm_reg_db[pm_id].mask & BTM_PM_REG_SET)) || ((pm_id == BTM_PM_SET_ONLY_ID) && (btm_cb.acl_cb_.pm_pend_link != MAX_L2CAP_LINKS))) { #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("BTM_SetPowerMode: Saving cmd acl_ind %d temp_pm_id %d", acl_ind, temp_pm_id); #endif // BTM_PM_DEBUG LOG_VERBOSE("saving cmd acl_ind %d temp_pm_id %d", acl_ind, temp_pm_id); /* Make sure mask is set to BTM_PM_REG_SET */ btm_cb.pm_reg_db[temp_pm_id].mask |= BTM_PM_REG_SET; *(&p_cb->req_mode[temp_pm_id]) = *p_mode; p_cb->chg_ind = true; } #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm state:0x%x, pm_pend_link: %d", p_cb->state, btm_cb.acl_cb_.pm_pend_link); #endif // BTM_PM_DEBUG /* if mode == hold or pending, return */ if ((p_cb->state == BTM_PM_STS_HOLD) || (p_cb->state == BTM_PM_STS_PENDING) || (btm_cb.acl_cb_.pm_pend_link != MAX_L2CAP_LINKS)) { LOG_DEBUG("storing pm setup, state: %d, pm_pending_link: %d", p_cb->state, btm_cb.acl_cb_.pm_pend_link); /* command pending */ if (acl_ind != btm_cb.acl_cb_.pm_pend_link) { /* set the stored mask */ p_cb->state |= BTM_PM_STORED_MASK; BTM_TRACE_DEBUG("%s: btm_pm state stored:%d", __func__, acl_ind); LOG_DEBUG("btm_pm state stored: %d", acl_ind); } return BTM_CMD_STORED; } LOG_DEBUG("pm_id: %d, bda: %s, mode: %d, state: %d, pending_link: %d", pm_id, remote_bda.ToString().c_str(), p_mode->mode, p_cb->state, btm_cb.acl_cb_.pm_pend_link); return internal_.btm_pm_snd_md_req(pm_id, acl_ind, p_mode); } Loading Loading @@ -260,7 +241,10 @@ bool BTM_ReadPowerMode(const RawAddress& remote_bda, tBTM_PM_MODE* p_mode) { return false; } int acl_ind = btm_pm_find_acl_ind(remote_bda); if (acl_ind == MAX_L2CAP_LINKS) return false; if (acl_ind == MAX_L2CAP_LINKS) { LOG_WARN("unknown bda: %s", remote_bda.ToString().c_str()); return false; } *p_mode = btm_cb.acl_cb_.pm_mode_db[acl_ind].state; return true; Loading Loading @@ -291,7 +275,10 @@ tBTM_STATUS btm_read_power_mode_state(const RawAddress& remote_bda, tBTM_PM_STATE* pmState) { int acl_ind = btm_pm_find_acl_ind(remote_bda); if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR); if (acl_ind == MAX_L2CAP_LINKS) { LOG_WARN("unknown bda: %s", remote_bda.ToString().c_str()); return BTM_UNKNOWN_ADDR; } *pmState = btm_cb.acl_cb_.pm_mode_db[acl_ind].state; return BTM_SUCCESS; Loading Loading @@ -330,6 +317,7 @@ tBTM_STATUS BTM_SetSsrParams(const RawAddress& remote_bda, uint16_t max_lat, max_lat, min_rmt_to, min_loc_to); return BTM_SUCCESS; } LOG_DEBUG("pm_mode_db state: %d", btm_cb.acl_cb_.pm_mode_db[acl_ind].state); p_cb = &btm_cb.acl_cb_.pm_mode_db[acl_ind]; p_cb->max_lat = max_lat; p_cb->min_rmt_to = min_rmt_to; Loading Loading @@ -371,6 +359,7 @@ void btm_pm_reset(void) { } /* no command pending */ btm_cb.acl_cb_.pm_pend_link = MAX_L2CAP_LINKS; LOG_DEBUG("reset pm"); } /******************************************************************************* Loading Loading @@ -520,9 +509,7 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind, mode = btm_pm_get_set_mode(pm_id, p_cb, p_mode, &md_res); md_res.mode = mode; #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_snd_md_req link_ind:%d, mode: %d", link_ind, mode); #endif // BTM_PM_DEBUG LOG_DEBUG("link_ind: %d, mode: %d", link_ind, mode); if (p_cb->state == mode) { /* already in the resulting mode */ Loading Loading @@ -554,13 +541,10 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind, /* send the appropriate HCI command */ btm_cb.pm_pend_id = pm_id; #if (BTM_PM_DEBUG == TRUE) 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("switching from %s(0x%x) to %s(0x%x), link_ind: %d", mode_to_string(p_cb->state), p_cb->state, mode_to_string(md_res.mode), md_res.mode, link_ind); BTM_TRACE_DEBUG("%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: switch (p_cb->state) { Loading Loading @@ -604,9 +588,7 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind, if (btm_cb.acl_cb_.pm_pend_link == MAX_L2CAP_LINKS) { /* the command was not sent */ #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("pm_pend_link: %d", btm_cb.acl_cb_.pm_pend_link); #endif // BTM_PM_DEBUG LOG_ERROR("pm_pending_link maxed out"); return (BTM_NO_RESOURCES); } Loading @@ -626,21 +608,18 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind, * ******************************************************************************/ void btm_pm_proc_cmd_status(uint8_t status) { tBTM_PM_MCB* p_cb; tBTM_PM_STATUS pm_status; if (btm_cb.acl_cb_.pm_pend_link >= MAX_L2CAP_LINKS) return; p_cb = &btm_cb.acl_cb_.pm_mode_db[btm_cb.acl_cb_.pm_pend_link]; if (btm_cb.acl_cb_.pm_pend_link >= MAX_L2CAP_LINKS) { LOG_ERROR("pending_link: %d", btm_cb.acl_cb_.pm_pend_link); return; } tBTM_PM_MCB* p_cb = &btm_cb.acl_cb_.pm_mode_db[btm_cb.acl_cb_.pm_pend_link]; tBTM_PM_STATUS pm_status; if (status == HCI_SUCCESS) { p_cb->state = BTM_PM_ST_PENDING; pm_status = BTM_PM_STS_PENDING; #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_proc_cmd_status new state:0x%x", p_cb->state); #endif // BTM_PM_DEBUG } else /* the command was not successfull. Stay in the same state */ { } else { // the command was not successful. Stay in the same state pm_status = BTM_PM_STS_ERROR; } Loading @@ -653,11 +632,8 @@ void btm_pm_proc_cmd_status(uint8_t status) { } /* no pending cmd now */ #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG( "btm_pm_proc_cmd_status state:0x%x, pm_pend_link: %d(new: %d)", p_cb->state, btm_cb.acl_cb_.pm_pend_link, MAX_L2CAP_LINKS); #endif // BTM_PM_DEBUG LOG_DEBUG("state: %d, pend_link: %d", p_cb->state, btm_cb.acl_cb_.pm_pend_link); btm_cb.acl_cb_.pm_pend_link = MAX_L2CAP_LINKS; /******************************************************************************* Loading Loading @@ -717,8 +693,8 @@ void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle, p_cb->state = mode; p_cb->interval = interval; BTM_TRACE_DEBUG("%s switched from %s to %s.", __func__, mode_to_string(old_state), mode_to_string(p_cb->state)); LOG_DEBUG("switched from [%s] to [%s].", mode_to_string(old_state), mode_to_string(p_cb->state)); if ((p_cb->state == BTM_PM_ST_ACTIVE) || (p_cb->state == BTM_PM_ST_SNIFF)) { l2c_OnHciModeChangeSendPendingPackets(bd_addr); Loading @@ -734,16 +710,12 @@ void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle, /* new request has been made. - post a message to BTU task */ if (old_state & BTM_PM_STORED_MASK) { #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_proc_mode_change: Sending stored req:%d", xx); #endif // BTM_PM_DEBUG LOG_VERBOSE("Sending stored req: %d", xx); internal_.btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, xx, NULL); } else { for (zz = 0; zz < MAX_L2CAP_LINKS; zz++) { if (btm_cb.acl_cb_.pm_mode_db[zz].chg_ind) { #if (BTM_PM_DEBUG == TRUE) BTM_TRACE_DEBUG("btm_pm_proc_mode_change: Sending PM req :%d", zz); #endif // BTM_PM_DEBUG LOG_VERBOSE("Sending PM req :%d", zz); internal_.btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, zz, NULL); break; } Loading