M module-bluetooth/Bluetooth/BluetoothWorker.cpp => module-bluetooth/Bluetooth/BluetoothWorker.cpp +4 -3
@@ 153,9 153,6 @@ auto BluetoothWorker::handleCommand(QueueHandle_t queue) -> bool
initDevicesList();
controller->turnOn();
break;
- case bluetooth::Command::PowerOff:
- controller->turnOff();
- break;
case bluetooth::Command::Unpair: {
controller->processCommand(command);
auto device = std::get<Devicei>(command.getData());
@@ 164,6 161,10 @@ auto BluetoothWorker::handleCommand(QueueHandle_t queue) -> bool
} break;
case bluetooth::Command::None:
break;
+ case bluetooth::Command::PowerOff:
+ controller->processCommand(command);
+ controller->turnOff();
+ break;
default:
controller->processCommand(command);
break;
M module-bluetooth/Bluetooth/CommandHandler.cpp => module-bluetooth/Bluetooth/CommandHandler.cpp +1 -0
@@ 63,6 63,7 @@ namespace bluetooth
case bluetooth::Command::DisconnectAudio:
return disconnectAudioConnection();
case bluetooth::Command::PowerOff:
+ profileManager->deInit();
return Error::Success;
case bluetooth::Command::None:
return Error::Success;
M module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp => module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp +19 -4
@@ 32,7 32,11 @@ namespace bluetooth
A2DP::A2DP() : pimpl(std::make_unique<A2DPImpl>(A2DPImpl()))
{}
- A2DP::~A2DP() = default;
+ A2DP::~A2DP()
+ {
+ pimpl->disconnect();
+ pimpl->deInit();
+ }
A2DP::A2DP(A2DP &other) : pimpl(new A2DPImpl(*other.pimpl))
{}
@@ 148,7 152,6 @@ namespace bluetooth
// Create A2DP Source service record and register it with SDP.
sdpSourceServiceBuffer.fill(0);
- constexpr uint32_t a2dpSdpRecordHandle = 0x10001;
a2dp_source_create_sdp_record(
sdpSourceServiceBuffer.data(), a2dpSdpRecordHandle, AVDTP_SOURCE_FEATURE_MASK_PLAYER, nullptr, nullptr);
if (const auto status = sdp_register_service(sdpSourceServiceBuffer.data()); status != ERROR_CODE_SUCCESS) {
@@ 161,7 164,6 @@ namespace bluetooth
#ifdef AVRCP_BROWSING_ENABLED
supported_features |= AVRCP_FEATURE_MASK_BROWSING;
#endif
- constexpr uint32_t avrcpServiceSdpRecordHandle = 0x10002;
avrcp_target_create_sdp_record(
AVRCP::sdpTargetServiceBuffer.data(), avrcpServiceSdpRecordHandle, supportedFeatures, nullptr, nullptr);
if (const auto status = sdp_register_service(AVRCP::sdpTargetServiceBuffer.data());
@@ 172,7 174,6 @@ namespace bluetooth
// setup AVRCP Controller
AVRCP::sdpControllerServiceBuffer.fill(0);
uint16_t controllerSupportedFeatures = AVRCP_FEATURE_MASK_CATEGORY_PLAYER_OR_RECORDER;
- constexpr uint32_t avrcpControllerSdpRecordHandle = 0x10003;
avrcp_controller_create_sdp_record(AVRCP::sdpControllerServiceBuffer.data(),
avrcpControllerSdpRecordHandle,
controllerSupportedFeatures,
@@ 299,6 300,7 @@ namespace bluetooth
a2dp_subevent_signaling_connection_established_get_bd_addr(packet, address);
cid = a2dp_subevent_signaling_connection_established_get_a2dp_cid(packet);
status = a2dp_subevent_signaling_connection_established_get_status(packet);
+
if (status != ERROR_CODE_SUCCESS) {
LOG_INFO("A2DP Source: Connection failed, status 0x%02x, cid 0x%02x, a2dp_cid 0x%02x \n",
status,
@@ 320,6 322,9 @@ namespace bluetooth
isConnected = true;
auto &busProxy = const_cast<sys::Service *>(ownerService)->bus;
device.deviceState = DeviceState::ConnectedAudio;
+ // handle proper device matching when connection was initiated by remote device
+ a2dp_subevent_signaling_connection_established_get_bd_addr(packet, device.address);
+
busProxy.sendUnicast(std::make_shared<message::bluetooth::ConnectResult>(device, true),
service::name::bluetooth);
break;
@@ 601,5 606,15 @@ namespace bluetooth
{
A2DP::A2DPImpl::audioDevice = std::move(newAudioDevice);
}
+ void A2DP::A2DPImpl::deInit()
+ {
+ LOG_DEBUG("[A2DP] deinit");
+
+ sdp_unregister_service(a2dpSdpRecordHandle);
+ sdp_unregister_service(avrcpControllerSdpRecordHandle);
+ sdp_unregister_service(avrcpServiceSdpRecordHandle);
+
+ audioDevice.reset();
+ }
} // namespace bluetooth
M module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DPImpl.hpp => module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DPImpl.hpp +4 -0
@@ 50,9 50,13 @@ namespace bluetooth
static bool isConnected;
static std::shared_ptr<BluetoothAudioDevice> audioDevice;
static Devicei device;
+ static constexpr uint32_t a2dpSdpRecordHandle = 0x10001;
+ static constexpr uint32_t avrcpServiceSdpRecordHandle = 0x10002;
+ static constexpr uint32_t avrcpControllerSdpRecordHandle = 0x10003;
public:
auto init() -> Error::Code;
+ void deInit();
void connect();
void disconnect();
void start();
M module-bluetooth/Bluetooth/interface/profiles/HFP/HFP.cpp => module-bluetooth/Bluetooth/interface/profiles/HFP/HFP.cpp +15 -3
@@ 129,7 129,11 @@ namespace bluetooth
return pimpl->callStarted(num);
}
- HFP::~HFP() = default;
+ HFP::~HFP()
+ {
+ pimpl->disconnect();
+ pimpl->deInit();
+ }
hci_con_handle_t HFP::HFPImpl::scoHandle = HCI_CON_HANDLE_INVALID;
hci_con_handle_t HFP::HFPImpl::aclHandle = HCI_CON_HANDLE_INVALID;
@@ 364,7 368,6 @@ namespace bluetooth
Profile::initSdp();
serviceBuffer.fill(0);
- constexpr std::uint32_t hspSdpRecordHandle = 0x10004;
uint16_t supported_features = (1 << HFP_AGSF_ESCO_S4) | /* (1 << HFP_AGSF_HF_INDICATORS) | */
(1 << HFP_AGSF_CODEC_NEGOTIATION) | (1 << HFP_AGSF_EXTENDED_ERROR_RESULT_CODES) |
(1 << HFP_AGSF_ENHANCED_CALL_CONTROL) | (1 << HFP_AGSF_ENHANCED_CALL_STATUS) |
@@ 373,7 376,7 @@ namespace bluetooth
int wide_band_speech = 0;
constexpr std::uint8_t abilityToRejectCall = 1;
hfp_ag_create_sdp_record(serviceBuffer.data(),
- hspSdpRecordHandle,
+ hfpSdpRecordHandle,
rfcommChannelNr,
agServiceName.data(),
abilityToRejectCall,
@@ 533,5 536,14 @@ namespace bluetooth
hfp_ag_set_roaming_status(enabled);
return Error::Success;
}
+ void HFP::HFPImpl::deInit() noexcept
+ {
+ LOG_DEBUG("[HFP] deinit");
+ sdp_unregister_service(hfpSdpRecordHandle);
+
+ cellularInterface.reset();
+ audioInterface.reset();
+ sco.reset();
+ }
} // namespace bluetooth
M module-bluetooth/Bluetooth/interface/profiles/HFP/HFPImpl.hpp => module-bluetooth/Bluetooth/interface/profiles/HFP/HFPImpl.hpp +2 -0
@@ 26,6 26,7 @@ namespace bluetooth
public:
static void packetHandler(uint8_t packetType, uint16_t channel, uint8_t *event, uint16_t eventSize);
auto init() -> Error::Code;
+ void deInit() noexcept;
void startRinging() const noexcept;
void stopRinging() const noexcept;
void initializeCall() const noexcept;
@@ 68,6 69,7 @@ namespace bluetooth
static const char *call_hold_services[5];
[[maybe_unused]] static int hf_indicators_nr;
[[maybe_unused]] static hfp_generic_status_indicator_t hf_indicators[2];
+ static constexpr std::uint32_t hfpSdpRecordHandle = 0x10004;
static std::shared_ptr<CVSDAudioDevice> audioDevice;
static Devicei device;
static CallStatus currentCallStatus;
M module-bluetooth/Bluetooth/interface/profiles/ProfileManager.cpp => module-bluetooth/Bluetooth/interface/profiles/ProfileManager.cpp +13 -0
@@ 167,5 167,18 @@ namespace bluetooth
LOG_ERROR("No profile, returning!");
return Error::NotReady;
}
+ void ProfileManager::deInit()
+ {
+ for (auto &[profileName, ptr] : profilesList) {
+ if (ptr != nullptr) {
+ ptr.reset();
+ }
+ }
+ callProfilePtr = nullptr;
+ musicProfilePtr = nullptr;
+ initialized = false;
+
+ LOG_DEBUG("ProfileManager deinit done");
+ }
} // namespace bluetooth
M module-bluetooth/Bluetooth/interface/profiles/ProfileManager.hpp => module-bluetooth/Bluetooth/interface/profiles/ProfileManager.hpp +1 -0
@@ 32,6 32,7 @@ namespace bluetooth
explicit ProfileManager(sys::Service *ownerService);
auto init() -> Error::Code;
+ void deInit();
auto connect(const Devicei &device) -> Error::Code;
auto disconnect() -> Error::Code;
auto start() -> Error::Code;