From 1f0b0286aa21c3c6439b76830ae2334b12ae8185 Mon Sep 17 00:00:00 2001 From: intel Date: Tue, 7 May 2024 21:46:24 +0530 Subject: [PATCH] Add Blutooth Hci interface down option Everytime before launching android user has to manually do "sudo hciconfig hci0 down" when BT Card is passthrough. Added 'bluetooth' section with 'hci_down' flag in the vm-manager. If set to 'true', will bring down the BT hci interface. Tests done: 1. Build vm-manager binary 2. Add BT USB Pci address in the [passthrough] 3. Add hci_down=true in [bluetooth] 4. Launch Android and check BT on success 5. Validated on RPL NUC with AX211 Tracked-On: OAM-116593 Signed-off-by: Gowtham Anandha Babu Signed-off-by: Aman Bhadouria --- docs/fields.md | 3 +++ src/guest/config_parser.cc | 1 + src/guest/config_parser.h | 3 +++ src/guest/vm_builder_qemu.cc | 13 +++++++++++++ src/guest/vm_builder_qemu.h | 1 + 5 files changed, 21 insertions(+) diff --git a/docs/fields.md b/docs/fields.md index f831d70c..d3d4043b 100644 --- a/docs/fields.md +++ b/docs/fields.md @@ -169,3 +169,6 @@ Requirements - cmd: Set extra command. - service: Set extra services, use `:` split different services. - pwr_ctrl_multios: If set to "true", will create qmp socket in /tmp/ folder for suspend/hibernate feature. Setting to "false" will not create the sockeet. + +### [bluetooth] +- hci_down: If set to 'true', will bring down Bluetooth Hci Interface. Make sure BT USB Pci address is added in `[passthrough]`. diff --git a/src/guest/config_parser.cc b/src/guest/config_parser.cc index d2b04c84..20ac8a14 100644 --- a/src/guest/config_parser.cc +++ b/src/guest/config_parser.cc @@ -41,6 +41,7 @@ map> kConfigMap = { { kGroupRpmb, { kRpmbBinPath, kRpmbDataDir } }, { kGroupAaf, { kAafPath, kAafSuspend, kAafAudioType }}, { kGroupPciPt, { kPciPtDev }}, + { kGroupbluetooth, { kHciDown }}, { kGroupAudio, { kDisableEmul } }, { kGroupMed, { kMedBattery, kMedThermal, kMedCamera } }, { kGroupService, { kServTimeKeep, kServPmCtrl, kServVinput } }, diff --git a/src/guest/config_parser.h b/src/guest/config_parser.h index 947bc423..4ee11735 100644 --- a/src/guest/config_parser.h +++ b/src/guest/config_parser.h @@ -28,6 +28,7 @@ constexpr char kGroupVtpm[] = "vtpm"; constexpr char kGroupRpmb[] = "rpmb"; constexpr char kGroupAaf[] = "aaf"; constexpr char kGroupPciPt[] = "passthrough"; +constexpr char kGroupbluetooth[] = "bluetooth"; constexpr char kGroupAudio[] = "audio"; constexpr char kGroupMed[] = "mediation"; constexpr char kGroupService[] = "guest_control"; @@ -78,6 +79,8 @@ constexpr char kAafAudioType[] = "audio_type"; constexpr char kPciPtDev[] = "passthrough_pci"; +constexpr char kHciDown[] = "hci_down"; + constexpr char kDisableEmul[] = "disable_emulation"; constexpr char kMedBattery[] = "battery_med"; diff --git a/src/guest/vm_builder_qemu.cc b/src/guest/vm_builder_qemu.cc index 6dbea7cd..2b32b3a1 100644 --- a/src/guest/vm_builder_qemu.cc +++ b/src/guest/vm_builder_qemu.cc @@ -300,6 +300,18 @@ bool VmBuilderQemu::SetupSriov(void) { return true; } +void VmBuilderQemu::BringDownBtHciIntf() { + std::string hci_status = cfg_.GetValue(kGroupbluetooth, kHciDown); + boost::trim(hci_status); + if (hci_status == "true") { + LOG(info) << "Shutting down Hci Interface!!!\n"; + int result = boost::process::system("sudo hciconfig hci0 down"); + if (result != 0) { + LOG(warning) << "Failed to execute command: sudo hciconfig hci0 down"; + } + } +} + void VmBuilderQemu::BuildExtraGuestPmCtrlCmd(void) { std::string ex_cmd = cfg_.GetValue(kGroupExtra, kExtraPwrCtrlMultiOS); if (ex_cmd == "true") { @@ -413,6 +425,7 @@ void VmBuilderQemu::BuildPtPciDevicesCmd(void) { std::vector vec; boost::split(vec, pt_pci, boost::is_any_of(","), boost::token_compress_on); + BringDownBtHciIntf(); // Bring down blutooth hci interface before passthrough for (auto it=vec.begin(); it != vec.end(); ++it) { boost::trim(*it); if (PassthroughOnePciDev(it->c_str(), kPciPassthrough)) { diff --git a/src/guest/vm_builder_qemu.h b/src/guest/vm_builder_qemu.h index 6e2b7133..8ccb0912 100644 --- a/src/guest/vm_builder_qemu.h +++ b/src/guest/vm_builder_qemu.h @@ -57,6 +57,7 @@ class VmBuilderQemu : public VmBuilder { void BuildVcpuCmd(void); bool BuildFirmwareCmd(void); void BuildVdiskCmd(void); + void BringDownBtHciIntf(); void BuildPtPciDevicesCmd(void); void BuildGuestTimeKeepCmd(void); void BuildGuestPmCtrlCmd(void);