Loading system/gd/hal/hci_hal_host.cc +10 −7 Original line number Diff line number Diff line Loading @@ -24,10 +24,12 @@ #include <sys/types.h> #include <unistd.h> #include <chrono> #include <chrono> // NOLINT #include <csignal> #include <mutex> #include <mutex> // NOLINT #include <queue> #include <utility> #include <vector> #include "common/init_flags.h" #include "hal/hci_hal.h" Loading Loading @@ -71,8 +73,8 @@ constexpr uint16_t HCI_DEV_NONE = 0xffff; struct sockaddr_hci { sa_family_t hci_family; unsigned short hci_dev; unsigned short hci_channel; uint16_t hci_dev; uint16_t hci_channel; }; struct mgmt_pkt { Loading Loading @@ -154,7 +156,7 @@ int waitHciDev(int hci_interface) { struct mgmt_event_read_index* cc; int i; cc = (struct mgmt_event_read_index*)ev.data; cc = reinterpret_cast<struct mgmt_event_read_index*>(ev.data); if (cc->cc_opcode != MGMT_OP_INDEX_LIST) { continue; Loading Loading @@ -388,7 +390,7 @@ private: bool controller_broken_ = false; void write_to_fd(HciPacket packet) { // TODO: replace this with new queue when it's ready // TODO(chromeos-bt-team@): replace this with new queue when it's ready hci_outgoing_queue_.emplace(packet); if (hci_outgoing_queue_.size() == 1) { hci_incoming_thread_.GetReactor()->ModifyRegistration(reactable_, Loading @@ -402,7 +404,8 @@ private: return; } auto packet_to_send = hci_outgoing_queue_.front(); auto bytes_written = write(sock_fd_, (void*)packet_to_send.data(), packet_to_send.size()); auto bytes_written = write(sock_fd_, reinterpret_cast<void*>(packet_to_send.data()), packet_to_send.size()); hci_outgoing_queue_.pop(); if (bytes_written == -1) { log::error("Can't write to socket: {}", strerror(errno)); Loading system/gd/hal/mgmt.cc +3 −3 Original line number Diff line number Diff line Loading @@ -42,8 +42,8 @@ namespace hal { struct sockaddr_hci { sa_family_t hci_family; unsigned short hci_dev; unsigned short hci_channel; uint16_t hci_dev; uint16_t hci_channel; }; constexpr static uint8_t BTPROTO_HCI = 1; Loading Loading @@ -113,7 +113,7 @@ uint16_t Mgmt::get_vs_opcode(uint16_t vendor_specification) { log::error("Failed to call MGMT opcode 0x{:04x}, errno {}", ev.opcode, -errno); close(fd); return ret_opcode; }; } break; } else if (ret < 0) { log::error("msft poll ret {} errno {}", ret, -errno); Loading system/gd/os/chromeos/system_properties.cc +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ #include "os/system_properties.h" #include <mutex> #include <mutex> // NOLINT #include <string> #include <unordered_map> Loading system/gd/os/linux/system_properties.cc +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ #include "os/system_properties.h" #include <mutex> #include <mutex> // NOLINT #include <string> #include <unordered_map> Loading system/stack/btm/btm_sco_hfp_hal_linux.cc +33 −32 Original line number Diff line number Diff line Loading @@ -21,16 +21,15 @@ #include <vector> #include "btm_sco_hfp_hal.h" #include "common/init_flags.h" #include "hci/controller_interface.h" #include "main/shim/entry.h" #include "os/log.h" #include "osi/include/properties.h" #include "stack/btm/btm_sco_hfp_hal.h" #include "stack/include/hcimsgs.h" #include "stack/include/sdpdefs.h" using namespace bluetooth; using bluetooth::legacy::hci::GetInterface; namespace hfp_hal_interface { Loading Loading @@ -116,15 +115,16 @@ void cache_codec_capabilities(struct mgmt_rp_get_codec_capabilities* rp) { } for (const auto& c : cached_codecs) { log::info("Caching HFP codec {}, data path {}, data len {}, pkt_size {}", (uint64_t)c.inner.codec, c.inner.data_path, c.inner.data.size(), c.pkt_size); bluetooth::log::info("Caching HFP codec {}, data path {}, data len {}, pkt_size {}", (uint64_t)c.inner.codec, c.inner.data_path, c.inner.data.size(), c.pkt_size); } } struct sockaddr_hci { sa_family_t hci_family; unsigned short hci_dev; unsigned short hci_channel; uint16_t hci_dev; uint16_t hci_channel; }; constexpr uint8_t BTPROTO_HCI = 1; Loading @@ -134,7 +134,7 @@ constexpr uint16_t HCI_DEV_NONE = 0xffff; int btsocket_open_mgmt(uint16_t hci) { int fd = socket(PF_BLUETOOTH, SOCK_RAW | SOCK_NONBLOCK, BTPROTO_HCI); if (fd < 0) { log::debug("Failed to open BT socket, hci: %u", hci); bluetooth::log::debug("Failed to open BT socket, hci: %u", hci); return -errno; } Loading @@ -146,7 +146,7 @@ int btsocket_open_mgmt(uint16_t hci) { int ret = bind(fd, (struct sockaddr*)&addr, sizeof(addr)); if (ret < 0) { log::debug("Failed to bind BT socket."); bluetooth::log::debug("Failed to bind BT socket."); close(fd); return -errno; } Loading Loading @@ -175,15 +175,15 @@ int mgmt_get_codec_capabilities(int fd, uint16_t hci) { if (ret > 0) { RETRY_ON_INTR(ret = write(fd, &ev, MGMT_PKT_HDR_SIZE + ev.len)); if (ret < 0) { log::debug("Failed to call MGMT_OP_GET_SCO_CODEC_CAPABILITIES: {}", -errno); bluetooth::log::debug("Failed to call MGMT_OP_GET_SCO_CODEC_CAPABILITIES: {}", -errno); return -errno; }; } break; } } while (ret > 0); if (ret <= 0) { log::debug("Failed waiting for mgmt socket to be writable."); bluetooth::log::debug("Failed waiting for mgmt socket to be writable."); return -1; } Loading @@ -198,10 +198,10 @@ int mgmt_get_codec_capabilities(int fd, uint16_t hci) { if (fds[0].revents & POLLIN) { RETRY_ON_INTR(ret = read(fd, &ev, sizeof(ev))); if (ret < 0) { log::debug("Failed to read mgmt socket: {}", -errno); bluetooth::log::debug("Failed to read mgmt socket: {}", -errno); return -errno; } else if (ret == 0) { // unlikely to happen, just a safeguard. log::debug("Failed to read mgmt socket: EOF"); bluetooth::log::debug("Failed to read mgmt socket: EOF"); return -1; } Loading @@ -218,7 +218,7 @@ int mgmt_get_codec_capabilities(int fd, uint16_t hci) { } } } else if (ret == 0) { log::debug("Timeout while waiting for codec capabilities response."); bluetooth::log::debug("Timeout while waiting for codec capabilities response."); ret = -1; } } while (ret > 0); Loading Loading @@ -262,15 +262,15 @@ int mgmt_notify_sco_connection_change(int fd, int hci, RawAddress device, bool i if (ret > 0) { RETRY_ON_INTR(ret = write(fd, &ev, MGMT_PKT_HDR_SIZE + ev.len)); if (ret < 0) { log::error("Failed to call MGMT_OP_NOTIFY_SCO_CONNECTION_CHANGE: {}", -errno); bluetooth::log::error("Failed to call MGMT_OP_NOTIFY_SCO_CONNECTION_CHANGE: {}", -errno); return -errno; }; } break; } } while (ret > 0); if (ret <= 0) { log::debug("Failed waiting for mgmt socket to be writable."); bluetooth::log::debug("Failed waiting for mgmt socket to be writable."); return -1; } Loading @@ -282,15 +282,15 @@ void init() { int hci = bluetooth::common::InitFlags::GetAdapterIndex(); int fd = btsocket_open_mgmt(hci); if (fd < 0) { log::error("Failed to open mgmt channel, error= {}.", fd); bluetooth::log::error("Failed to open mgmt channel, error= {}.", fd); return; } int ret = mgmt_get_codec_capabilities(fd, hci); if (ret) { log::error("Failed to get codec capabilities with error = {}.", ret); bluetooth::log::error("Failed to get codec capabilities with error = {}.", ret); } else { log::info("Successfully queried SCO codec capabilities."); bluetooth::log::info("Successfully queried SCO codec capabilities."); } close(fd); Loading @@ -299,7 +299,7 @@ void init() { // Check if the specified coding format is supported by the adapter. bool is_coding_format_supported(esco_coding_format_t coding_format) { if (coding_format != ESCO_CODING_FORMAT_TRANSPNT && coding_format != ESCO_CODING_FORMAT_MSBC) { log::warn("Unsupported coding format to query: {}", coding_format); bluetooth::log::warn("Unsupported coding format to query: {}", coding_format); return false; } Loading Loading @@ -349,7 +349,7 @@ bool get_offload_enabled() { return offload_supported && offload_enabled; } // Set offload enable/disable bool enable_offload(bool enable) { if (!offload_supported && enable) { log::error("Cannot enable SCO-offload since it is not supported."); bluetooth::log::error("Cannot enable SCO-offload since it is not supported."); return false; } offload_enabled = enable; Loading @@ -376,7 +376,7 @@ void set_codec_datapath(tBTA_AG_UUID_CODEC codec_uuid) { uint8_t codec_id; if (codec_uuid == tBTA_AG_UUID_CODEC::UUID_CODEC_LC3 && get_offload_enabled()) { log::error("Offload path for LC3 is not implemented."); bluetooth::log::error("Offload path for LC3 is not implemented."); return; } Loading @@ -391,20 +391,21 @@ void set_codec_datapath(tBTA_AG_UUID_CODEC codec_uuid) { codec_id = get_offload_enabled() ? codec::LC3 : codec::MSBC_TRANSPARENT; break; default: log::warn("Unsupported codec ({}). Won't set datapath.", bta_ag_uuid_codec_text(codec_uuid)); bluetooth::log::warn("Unsupported codec ({}). Won't set datapath.", bta_ag_uuid_codec_text(codec_uuid)); return; } found = get_single_codec(codec_id, &codec); if (!found) { log::error("Failed to find codec config for codec ({}). Won't set datapath.", bluetooth::log::error("Failed to find codec config for codec ({}). Won't set datapath.", bta_ag_uuid_codec_text(codec_uuid)); return; } log::info("Configuring datapath for codec ({})", bta_ag_uuid_codec_text(codec_uuid)); bluetooth::log::info("Configuring datapath for codec ({})", bta_ag_uuid_codec_text(codec_uuid)); if (codec->codec == codec::MSBC && !get_offload_enabled()) { log::error( bluetooth::log::error( "Tried to configure offload data path for format ({}) with offload " "disabled. Won't set datapath.", bta_ag_uuid_codec_text(codec_uuid)); Loading Loading @@ -445,12 +446,12 @@ void notify_sco_connection_change(RawAddress device, bool is_connected, int code int hci = bluetooth::common::InitFlags::GetAdapterIndex(); int fd = btsocket_open_mgmt(hci); if (fd < 0) { log::error("Failed to open mgmt channel, error= {}.", fd); bluetooth::log::error("Failed to open mgmt channel, error= {}.", fd); return; } if (codec == codec::LC3) { log::error("Offload path for LC3 is not implemented."); bluetooth::log::error("Offload path for LC3 is not implemented."); return; } Loading @@ -469,12 +470,12 @@ void notify_sco_connection_change(RawAddress device, bool is_connected, int code int ret = mgmt_notify_sco_connection_change(fd, hci, device, is_connected, converted_codec); if (ret) { log::error( bluetooth::log::error( "Failed to notify HAL of connection change: hci {}, device {}, " "connected {}, codec {}", hci, device, is_connected, codec); } else { log::info( bluetooth::log::info( "Notified HAL of connection change: hci {}, device {}, connected {}, " "codec {}", hci, device, is_connected, codec); Loading Loading
system/gd/hal/hci_hal_host.cc +10 −7 Original line number Diff line number Diff line Loading @@ -24,10 +24,12 @@ #include <sys/types.h> #include <unistd.h> #include <chrono> #include <chrono> // NOLINT #include <csignal> #include <mutex> #include <mutex> // NOLINT #include <queue> #include <utility> #include <vector> #include "common/init_flags.h" #include "hal/hci_hal.h" Loading Loading @@ -71,8 +73,8 @@ constexpr uint16_t HCI_DEV_NONE = 0xffff; struct sockaddr_hci { sa_family_t hci_family; unsigned short hci_dev; unsigned short hci_channel; uint16_t hci_dev; uint16_t hci_channel; }; struct mgmt_pkt { Loading Loading @@ -154,7 +156,7 @@ int waitHciDev(int hci_interface) { struct mgmt_event_read_index* cc; int i; cc = (struct mgmt_event_read_index*)ev.data; cc = reinterpret_cast<struct mgmt_event_read_index*>(ev.data); if (cc->cc_opcode != MGMT_OP_INDEX_LIST) { continue; Loading Loading @@ -388,7 +390,7 @@ private: bool controller_broken_ = false; void write_to_fd(HciPacket packet) { // TODO: replace this with new queue when it's ready // TODO(chromeos-bt-team@): replace this with new queue when it's ready hci_outgoing_queue_.emplace(packet); if (hci_outgoing_queue_.size() == 1) { hci_incoming_thread_.GetReactor()->ModifyRegistration(reactable_, Loading @@ -402,7 +404,8 @@ private: return; } auto packet_to_send = hci_outgoing_queue_.front(); auto bytes_written = write(sock_fd_, (void*)packet_to_send.data(), packet_to_send.size()); auto bytes_written = write(sock_fd_, reinterpret_cast<void*>(packet_to_send.data()), packet_to_send.size()); hci_outgoing_queue_.pop(); if (bytes_written == -1) { log::error("Can't write to socket: {}", strerror(errno)); Loading
system/gd/hal/mgmt.cc +3 −3 Original line number Diff line number Diff line Loading @@ -42,8 +42,8 @@ namespace hal { struct sockaddr_hci { sa_family_t hci_family; unsigned short hci_dev; unsigned short hci_channel; uint16_t hci_dev; uint16_t hci_channel; }; constexpr static uint8_t BTPROTO_HCI = 1; Loading Loading @@ -113,7 +113,7 @@ uint16_t Mgmt::get_vs_opcode(uint16_t vendor_specification) { log::error("Failed to call MGMT opcode 0x{:04x}, errno {}", ev.opcode, -errno); close(fd); return ret_opcode; }; } break; } else if (ret < 0) { log::error("msft poll ret {} errno {}", ret, -errno); Loading
system/gd/os/chromeos/system_properties.cc +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ #include "os/system_properties.h" #include <mutex> #include <mutex> // NOLINT #include <string> #include <unordered_map> Loading
system/gd/os/linux/system_properties.cc +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ #include "os/system_properties.h" #include <mutex> #include <mutex> // NOLINT #include <string> #include <unordered_map> Loading
system/stack/btm/btm_sco_hfp_hal_linux.cc +33 −32 Original line number Diff line number Diff line Loading @@ -21,16 +21,15 @@ #include <vector> #include "btm_sco_hfp_hal.h" #include "common/init_flags.h" #include "hci/controller_interface.h" #include "main/shim/entry.h" #include "os/log.h" #include "osi/include/properties.h" #include "stack/btm/btm_sco_hfp_hal.h" #include "stack/include/hcimsgs.h" #include "stack/include/sdpdefs.h" using namespace bluetooth; using bluetooth::legacy::hci::GetInterface; namespace hfp_hal_interface { Loading Loading @@ -116,15 +115,16 @@ void cache_codec_capabilities(struct mgmt_rp_get_codec_capabilities* rp) { } for (const auto& c : cached_codecs) { log::info("Caching HFP codec {}, data path {}, data len {}, pkt_size {}", (uint64_t)c.inner.codec, c.inner.data_path, c.inner.data.size(), c.pkt_size); bluetooth::log::info("Caching HFP codec {}, data path {}, data len {}, pkt_size {}", (uint64_t)c.inner.codec, c.inner.data_path, c.inner.data.size(), c.pkt_size); } } struct sockaddr_hci { sa_family_t hci_family; unsigned short hci_dev; unsigned short hci_channel; uint16_t hci_dev; uint16_t hci_channel; }; constexpr uint8_t BTPROTO_HCI = 1; Loading @@ -134,7 +134,7 @@ constexpr uint16_t HCI_DEV_NONE = 0xffff; int btsocket_open_mgmt(uint16_t hci) { int fd = socket(PF_BLUETOOTH, SOCK_RAW | SOCK_NONBLOCK, BTPROTO_HCI); if (fd < 0) { log::debug("Failed to open BT socket, hci: %u", hci); bluetooth::log::debug("Failed to open BT socket, hci: %u", hci); return -errno; } Loading @@ -146,7 +146,7 @@ int btsocket_open_mgmt(uint16_t hci) { int ret = bind(fd, (struct sockaddr*)&addr, sizeof(addr)); if (ret < 0) { log::debug("Failed to bind BT socket."); bluetooth::log::debug("Failed to bind BT socket."); close(fd); return -errno; } Loading Loading @@ -175,15 +175,15 @@ int mgmt_get_codec_capabilities(int fd, uint16_t hci) { if (ret > 0) { RETRY_ON_INTR(ret = write(fd, &ev, MGMT_PKT_HDR_SIZE + ev.len)); if (ret < 0) { log::debug("Failed to call MGMT_OP_GET_SCO_CODEC_CAPABILITIES: {}", -errno); bluetooth::log::debug("Failed to call MGMT_OP_GET_SCO_CODEC_CAPABILITIES: {}", -errno); return -errno; }; } break; } } while (ret > 0); if (ret <= 0) { log::debug("Failed waiting for mgmt socket to be writable."); bluetooth::log::debug("Failed waiting for mgmt socket to be writable."); return -1; } Loading @@ -198,10 +198,10 @@ int mgmt_get_codec_capabilities(int fd, uint16_t hci) { if (fds[0].revents & POLLIN) { RETRY_ON_INTR(ret = read(fd, &ev, sizeof(ev))); if (ret < 0) { log::debug("Failed to read mgmt socket: {}", -errno); bluetooth::log::debug("Failed to read mgmt socket: {}", -errno); return -errno; } else if (ret == 0) { // unlikely to happen, just a safeguard. log::debug("Failed to read mgmt socket: EOF"); bluetooth::log::debug("Failed to read mgmt socket: EOF"); return -1; } Loading @@ -218,7 +218,7 @@ int mgmt_get_codec_capabilities(int fd, uint16_t hci) { } } } else if (ret == 0) { log::debug("Timeout while waiting for codec capabilities response."); bluetooth::log::debug("Timeout while waiting for codec capabilities response."); ret = -1; } } while (ret > 0); Loading Loading @@ -262,15 +262,15 @@ int mgmt_notify_sco_connection_change(int fd, int hci, RawAddress device, bool i if (ret > 0) { RETRY_ON_INTR(ret = write(fd, &ev, MGMT_PKT_HDR_SIZE + ev.len)); if (ret < 0) { log::error("Failed to call MGMT_OP_NOTIFY_SCO_CONNECTION_CHANGE: {}", -errno); bluetooth::log::error("Failed to call MGMT_OP_NOTIFY_SCO_CONNECTION_CHANGE: {}", -errno); return -errno; }; } break; } } while (ret > 0); if (ret <= 0) { log::debug("Failed waiting for mgmt socket to be writable."); bluetooth::log::debug("Failed waiting for mgmt socket to be writable."); return -1; } Loading @@ -282,15 +282,15 @@ void init() { int hci = bluetooth::common::InitFlags::GetAdapterIndex(); int fd = btsocket_open_mgmt(hci); if (fd < 0) { log::error("Failed to open mgmt channel, error= {}.", fd); bluetooth::log::error("Failed to open mgmt channel, error= {}.", fd); return; } int ret = mgmt_get_codec_capabilities(fd, hci); if (ret) { log::error("Failed to get codec capabilities with error = {}.", ret); bluetooth::log::error("Failed to get codec capabilities with error = {}.", ret); } else { log::info("Successfully queried SCO codec capabilities."); bluetooth::log::info("Successfully queried SCO codec capabilities."); } close(fd); Loading @@ -299,7 +299,7 @@ void init() { // Check if the specified coding format is supported by the adapter. bool is_coding_format_supported(esco_coding_format_t coding_format) { if (coding_format != ESCO_CODING_FORMAT_TRANSPNT && coding_format != ESCO_CODING_FORMAT_MSBC) { log::warn("Unsupported coding format to query: {}", coding_format); bluetooth::log::warn("Unsupported coding format to query: {}", coding_format); return false; } Loading Loading @@ -349,7 +349,7 @@ bool get_offload_enabled() { return offload_supported && offload_enabled; } // Set offload enable/disable bool enable_offload(bool enable) { if (!offload_supported && enable) { log::error("Cannot enable SCO-offload since it is not supported."); bluetooth::log::error("Cannot enable SCO-offload since it is not supported."); return false; } offload_enabled = enable; Loading @@ -376,7 +376,7 @@ void set_codec_datapath(tBTA_AG_UUID_CODEC codec_uuid) { uint8_t codec_id; if (codec_uuid == tBTA_AG_UUID_CODEC::UUID_CODEC_LC3 && get_offload_enabled()) { log::error("Offload path for LC3 is not implemented."); bluetooth::log::error("Offload path for LC3 is not implemented."); return; } Loading @@ -391,20 +391,21 @@ void set_codec_datapath(tBTA_AG_UUID_CODEC codec_uuid) { codec_id = get_offload_enabled() ? codec::LC3 : codec::MSBC_TRANSPARENT; break; default: log::warn("Unsupported codec ({}). Won't set datapath.", bta_ag_uuid_codec_text(codec_uuid)); bluetooth::log::warn("Unsupported codec ({}). Won't set datapath.", bta_ag_uuid_codec_text(codec_uuid)); return; } found = get_single_codec(codec_id, &codec); if (!found) { log::error("Failed to find codec config for codec ({}). Won't set datapath.", bluetooth::log::error("Failed to find codec config for codec ({}). Won't set datapath.", bta_ag_uuid_codec_text(codec_uuid)); return; } log::info("Configuring datapath for codec ({})", bta_ag_uuid_codec_text(codec_uuid)); bluetooth::log::info("Configuring datapath for codec ({})", bta_ag_uuid_codec_text(codec_uuid)); if (codec->codec == codec::MSBC && !get_offload_enabled()) { log::error( bluetooth::log::error( "Tried to configure offload data path for format ({}) with offload " "disabled. Won't set datapath.", bta_ag_uuid_codec_text(codec_uuid)); Loading Loading @@ -445,12 +446,12 @@ void notify_sco_connection_change(RawAddress device, bool is_connected, int code int hci = bluetooth::common::InitFlags::GetAdapterIndex(); int fd = btsocket_open_mgmt(hci); if (fd < 0) { log::error("Failed to open mgmt channel, error= {}.", fd); bluetooth::log::error("Failed to open mgmt channel, error= {}.", fd); return; } if (codec == codec::LC3) { log::error("Offload path for LC3 is not implemented."); bluetooth::log::error("Offload path for LC3 is not implemented."); return; } Loading @@ -469,12 +470,12 @@ void notify_sco_connection_change(RawAddress device, bool is_connected, int code int ret = mgmt_notify_sco_connection_change(fd, hci, device, is_connected, converted_codec); if (ret) { log::error( bluetooth::log::error( "Failed to notify HAL of connection change: hci {}, device {}, " "connected {}, codec {}", hci, device, is_connected, codec); } else { log::info( bluetooth::log::info( "Notified HAL of connection change: hci {}, device {}, connected {}, " "codec {}", hci, device, is_connected, codec); Loading