Files
palemoon27/dom/bluetooth/bluedroid/BluetoothDaemonCoreInterface.cpp
T
roytam1 e333860065 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1251090 - Shell functions should check whether an off main thread compilation is for a script or a module r=shu (41b89b1232)
- Bug 1222420 - Make AutoFinishGC into a function r=terrence (a8f535528c)
- Bug 1253094, part 4 - Stop using DebugOnly for class/struct members in js/. r=billm (2c790aa526)
- Bug 1080968 - Don't use constexpr on clang-cl when emulating MSVC 2013 (e9cc2d7c7c)
- Bug 1257496 - Add information about cycle count and GC state to our GC stats r=sfink (6c2250bfba)
- Bug 1256178 - Drop the moz prefix from the MozCSSKeyframeRule and MozCSSKeyframesRule interfaces; r=bzbarsky (894855bce1)
- Bug 1249896 - Part 1: Remove unused AndOrLeft, AndOrRight, RelationalLeft, and RelationalRight. r=jwalden (c4db9dfecf)
- Bug 1249896 - Part 2: Remove unused type member from SIMD Int8x16Defnetc. r=bbouvier (7d3d7a4db1)
- Bug 1249896 - Part 3: Add JS namespace for GenericNaN. r=luke (69acc1f3ec)
- Bug 1249896 - Part 4: Avoid declaring variable between cases in switch. r=luke (28e5f94c24)
- Bug 1249896 - Part 5: Remove unused ReportInvalidTrapResult. r=efaust (caa948acac)
- Bug 1249896 - Part 7: Remove unnecessary static from my_ErrorReporter. r=sfink (7f723e079d)
- Bug 1249896 - Part 8: Remove unreachable code from GetLine. r=jwalden (108c857a1a)
- Bug 1249896 - Part 9: Include shell/jsshell.h in js.cpp. r=sfink (638bfc13c4)
- Bug 1253094, part 3 - Stop using DebugOnly for class/struct members in ipc/. r=billm (ab9e014158)
- Bug 1259737 - Make sure BackgroundImpl.cpp's mBoundThread is not used in release builds. r=froydnj (5c278ab398)
- Bug 1254515 - GonkCameraImage.cpp:16:5: error: class 'mozilla::GonkCameraImage' does not have any field named 'mThread' r=reuben (e5cac8cf5b)
- Bug 1250952: Create a join block in case we're in dead code after the condition; r=luke (1d6b706ae5)
- Bug 1249601 - Implement wasm i64 comparisons. r=sunfish (4927f709db)
- Bug 1250165 - Implement wasm i64 bitwise ops. r=luke (5c25322772)
- Bug 1251225 - Implement wasm i64 binary arithmetic operators. r=sunfish (f478fa8b4b)
- Bug 1251392 - Baldr: Implement PopcntI. r=sunfish (79556e947f)
- Bug 1229985 - remove nsAutoArrayPtr; r=erahm (91c49451ca)
- Bug 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth managers, r=shuang (2c1dc7ca89)
- Bug 1251541: Pass arguments to AVRCP passthrough command as uint8_t, r=shuang (73a094bd26)
- Bug 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth interfaces, r=shuang (371041f093)
- Bug 1249424 - Remove use of nsAutoArrayPtr from librlz. r=gerald (7cbcfea1b0)
- Bug 1249389 - part 0 - use getter_Transfers in TestStartupCache.cpp; r=erahm (ecb8818959)
- Bug 1249389 - part 1 - change NewObjectInputStreamFromBuffer to take a UniquePtr argument; r=erahm (0bdafa20ae)
- Bug 1249389 - part 2 - change NewBufferFromStorageStream's outparam into a UniquePtr; r=erahm (b27a70ce2d)
- Bug 1249389 - part 3 - assert the size of nsZipItemPtr's storage type; r=erahm (7c55da9ea7)
- Bug 1249389 - part 4 - make StartupCache::GetBuffer take a UniquePtr outparam; r=erahm (84b722479b)
- Bug 1249389 - part 5 - use UniquePtr instead of nsAutoArrayPtr in mozilla::scache::CacheEntry; r=erahm (0fd492ea95)
- Bug 1249389 - part 6 - provide UniquePtr overload for nsIStartupCache::GetBuffer; r=erahm (c27231d945)
- Bug 1249389 - followup - fix compilation bustage in gfxFT2FontList.cpp; r=me (a86a1b0399)
- Bug 1249389 - part 7 - clean up calls to GetBuffer in TestStartupCache; r=erahm (98939334b6)
- Bug 1249369 - use UniquePtr instead of nsAutoArrayPtr in MediaPipeline.cpp; r=jesup (7402a75a8a)
- Bug 1238842 - Add error codes to Gecko by following W3C spec. r=brsun (0dd283f6ba)
- Bug 1253217 - Change filename from BluetoothUuid to BluetoothUuidHelper. r=jocelyn (1946bcac26)
- Bug 1241382 - Revise default value of BluetoothAdapter.address and BluetoothDevice.address to empty string, f=wiwang, r=shuang (d9fdb97743)
- Bug 1223722: Transfer arrays of Bluetooth UUIDs in |BluetoothValue|, r=brsun (344af40591)
- Bug 1222956: Use |BluetoothUuid| in |BluetoothDiscoveryHandle|, r=tzimmermann (40512de386)
- Bug 1250694: Use functions to return static const BluetoothAddress and BluetoothUuid; r=tzimmermann (0c4b20066f)
- Bug 1236561 - part 1 - convert easy cases of nsAutoArrayPtr<T> to UniquePtr<T[]> in dom/bluetooth/; r=btian (31ef8b7b50)
- Bug 1236561 - part 2 - remove ObexHeaderSet::GetAuthChallenge; r=btian (f70daddd53)
- Bug 1236561 - part 3 - make BluetoothConfigurationParameter.mValue a UniquePtr; r=btian (a5a0ac988a)
- Bug 1239979: Add |BluetoothSocket::Accept| method, r=btian (ca92a0ab7c)
- Bug 1239979: Store pointer to Bluetooth socket interface in |BluetoothSocket|, r=btian (7c15e75133)
- Bug 1239979: Cleanup |BluetoothSocket|'s internals when connections close, r=btian (b6ac677d2e)
- Bug 1252841: Convert Bluetooth module to |UniquePtr<>|, r=btian (76d9759afd)
- Bug 1232687: Start bluetoothd with HAL service interface, r=shuang (379a68064f)
- Bug 1223729 - HID Connection Implementation, r=jocelyn, sr=mrbkap (0eeddf875e)
- Bug 1232670: Prepare Bluetooth PDU for sending after checking connection status, r=shuang (699ff14d9b)
- Bug 1252841: Convert Bluetooth daemon interfaces to |UniquePtr<>|, r=brsun (797260c6dc)
2024-02-07 15:25:46 +08:00

1359 lines
35 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "BluetoothDaemonCoreInterface.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/unused.h"
BEGIN_BLUETOOTH_NAMESPACE
using namespace mozilla::ipc;
//
// Core module
//
const int BluetoothDaemonCoreModule::MAX_NUM_CLIENTS = 1;
BluetoothCoreNotificationHandler*
BluetoothDaemonCoreModule::sNotificationHandler;
void
BluetoothDaemonCoreModule::SetNotificationHandler(
BluetoothCoreNotificationHandler* aNotificationHandler)
{
sNotificationHandler = aNotificationHandler;
}
void
BluetoothDaemonCoreModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
DaemonSocketPDU& aPDU,
DaemonSocketResultHandler* aRes)
{
static void (BluetoothDaemonCoreModule::* const HandleOp[])(
const DaemonSocketPDUHeader&, DaemonSocketPDU&,
DaemonSocketResultHandler*) = {
[0] = &BluetoothDaemonCoreModule::HandleRsp,
[1] = &BluetoothDaemonCoreModule::HandleNtf
};
MOZ_ASSERT(!NS_IsMainThread());
(this->*(HandleOp[!!(aHeader.mOpcode & 0x80)]))(aHeader, aPDU, aRes);
}
// Commands
//
nsresult
BluetoothDaemonCoreModule::EnableCmd(BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_ENABLE,
0);
nsresult rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::DisableCmd(BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DISABLE,
0);
nsresult rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::GetAdapterPropertiesCmd(
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_ADAPTER_PROPERTIES,
0);
nsresult rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::GetAdapterPropertyCmd(
BluetoothPropertyType aType, BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_ADAPTER_PROPERTY,
0);
nsresult rv = PackPDU(aType, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::SetAdapterPropertyCmd(
const BluetoothProperty& aProperty, BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_ADAPTER_PROPERTY,
0);
nsresult rv = PackPDU(aProperty, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::GetRemoteDevicePropertiesCmd(
const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REMOTE_DEVICE_PROPERTIES,
0);
nsresult rv = PackPDU(aRemoteAddr, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::GetRemoteDevicePropertyCmd(
const BluetoothAddress& aRemoteAddr,
BluetoothPropertyType aType,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REMOTE_DEVICE_PROPERTY,
0);
nsresult rv = PackPDU(aRemoteAddr, aType, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::SetRemoteDevicePropertyCmd(
const BluetoothAddress& aRemoteAddr,
const BluetoothProperty& aProperty,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SET_REMOTE_DEVICE_PROPERTY,
0);
nsresult rv = PackPDU(aRemoteAddr, aProperty, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::GetRemoteServiceRecordCmd(
const BluetoothAddress& aRemoteAddr, const BluetoothUuid& aUuid,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REMOTE_SERVICE_RECORD,
0);
nsresult rv = PackPDU(aRemoteAddr, aUuid, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::GetRemoteServicesCmd(
const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_GET_REMOTE_SERVICES,
0);
nsresult rv = PackPDU(aRemoteAddr, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::StartDiscoveryCmd(BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_START_DISCOVERY,
0);
nsresult rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::CancelDiscoveryCmd(BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CANCEL_DISCOVERY,
0);
nsresult rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::CreateBondCmd(const BluetoothAddress& aBdAddr,
BluetoothTransport aTransport,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CREATE_BOND,
0);
#if ANDROID_VERSION >= 21
nsresult rv = PackPDU(aBdAddr, aTransport, *pdu);
#else
nsresult rv = PackPDU(aBdAddr, *pdu);
#endif
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::RemoveBondCmd(const BluetoothAddress& aBdAddr,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_REMOVE_BOND,
0);
nsresult rv = PackPDU(aBdAddr, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::CancelBondCmd(const BluetoothAddress& aBdAddr,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_CANCEL_BOND,
0);
nsresult rv = PackPDU(aBdAddr, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::PinReplyCmd(const BluetoothAddress& aBdAddr,
bool aAccept,
const BluetoothPinCode& aPinCode,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_PIN_REPLY,
0);
nsresult rv = PackPDU(aBdAddr, aAccept, aPinCode, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::SspReplyCmd(const BluetoothAddress& aBdAddr,
BluetoothSspVariant aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_SSP_REPLY,
0);
nsresult rv = PackPDU(aBdAddr, aVariant, aAccept, aPasskey, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::DutModeConfigureCmd(
bool aEnable, BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DUT_MODE_CONFIGURE,
0);
nsresult rv = PackPDU(aEnable, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::DutModeSendCmd(uint16_t aOpcode,
uint8_t* aBuf, uint8_t aLen,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_DUT_MODE_SEND,
0);
nsresult rv = PackPDU(aOpcode, aLen, PackArray<uint8_t>(aBuf, aLen),
*pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
nsresult
BluetoothDaemonCoreModule::LeTestModeCmd(uint16_t aOpcode,
uint8_t* aBuf, uint8_t aLen,
BluetoothCoreResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
UniquePtr<DaemonSocketPDU> pdu =
MakeUnique<DaemonSocketPDU>(SERVICE_ID, OPCODE_LE_TEST_MODE,
0);
nsresult rv = PackPDU(aOpcode, aLen, PackArray<uint8_t>(aBuf, aLen),
*pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu.get(), aRes);
if (NS_FAILED(rv)) {
return rv;
}
Unused << pdu.release();
return rv;
}
// Responses
//
void
BluetoothDaemonCoreModule::ErrorRsp(const DaemonSocketPDUHeader& aHeader,
DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ErrorRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::OnError, UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::EnableRsp(const DaemonSocketPDUHeader& aHeader,
DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::Enable, UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::DisableRsp(const DaemonSocketPDUHeader& aHeader,
DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::Disable, UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::GetAdapterPropertiesRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::GetAdapterProperties,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::GetAdapterPropertyRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::GetAdapterProperty,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::SetAdapterPropertyRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::SetAdapterProperty,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::GetRemoteDevicePropertiesRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::GetRemoteDeviceProperties,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::GetRemoteDevicePropertyRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::GetRemoteDeviceProperty,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::SetRemoteDevicePropertyRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::SetRemoteDeviceProperty,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::GetRemoteServiceRecordRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::GetRemoteServiceRecord,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::GetRemoteServicesRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::GetRemoteServices,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::StartDiscoveryRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::StartDiscovery,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::CancelDiscoveryRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::CancelDiscovery,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::CreateBondRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::CreateBond,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::RemoveBondRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::RemoveBond,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::CancelBondRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::CancelBond,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::PinReplyRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::PinReply,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::SspReplyRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::SspReply,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::DutModeConfigureRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::DutModeConfigure,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::DutModeSendRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::DutModeSend,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::LeTestModeRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
BluetoothCoreResultHandler* aRes)
{
ResultRunnable::Dispatch(
aRes, &BluetoothCoreResultHandler::LeTestMode,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::HandleRsp(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
DaemonSocketResultHandler* aRes)
{
static void (BluetoothDaemonCoreModule::* const HandleRsp[])(
const DaemonSocketPDUHeader&,
DaemonSocketPDU&,
BluetoothCoreResultHandler*) = {
[OPCODE_ERROR] =
&BluetoothDaemonCoreModule::ErrorRsp,
[OPCODE_ENABLE] =
&BluetoothDaemonCoreModule::EnableRsp,
[OPCODE_DISABLE] =
&BluetoothDaemonCoreModule::DisableRsp,
[OPCODE_GET_ADAPTER_PROPERTIES] =
&BluetoothDaemonCoreModule::GetAdapterPropertiesRsp,
[OPCODE_GET_ADAPTER_PROPERTY] =
&BluetoothDaemonCoreModule::GetAdapterPropertyRsp,
[OPCODE_SET_ADAPTER_PROPERTY] =
&BluetoothDaemonCoreModule::SetAdapterPropertyRsp,
[OPCODE_GET_REMOTE_DEVICE_PROPERTIES] =
&BluetoothDaemonCoreModule::GetRemoteDevicePropertiesRsp,
[OPCODE_GET_REMOTE_DEVICE_PROPERTY] =
&BluetoothDaemonCoreModule::GetRemoteDevicePropertyRsp,
[OPCODE_SET_REMOTE_DEVICE_PROPERTY] =
&BluetoothDaemonCoreModule::SetRemoteDevicePropertyRsp,
[OPCODE_GET_REMOTE_SERVICE_RECORD] =
&BluetoothDaemonCoreModule::GetRemoteServiceRecordRsp,
[OPCODE_GET_REMOTE_SERVICES] =
&BluetoothDaemonCoreModule::GetRemoteServicesRsp,
[OPCODE_START_DISCOVERY] =
&BluetoothDaemonCoreModule::StartDiscoveryRsp,
[OPCODE_CANCEL_DISCOVERY] =
&BluetoothDaemonCoreModule::CancelDiscoveryRsp,
[OPCODE_CREATE_BOND] =
&BluetoothDaemonCoreModule::CreateBondRsp,
[OPCODE_REMOVE_BOND] =
&BluetoothDaemonCoreModule::RemoveBondRsp,
[OPCODE_CANCEL_BOND] =
&BluetoothDaemonCoreModule::CancelBondRsp,
[OPCODE_PIN_REPLY] =
&BluetoothDaemonCoreModule::PinReplyRsp,
[OPCODE_SSP_REPLY] =
&BluetoothDaemonCoreModule::SspReplyRsp,
[OPCODE_DUT_MODE_CONFIGURE] =
&BluetoothDaemonCoreModule::DutModeConfigureRsp,
[OPCODE_DUT_MODE_SEND] =
&BluetoothDaemonCoreModule::DutModeSendRsp,
[OPCODE_LE_TEST_MODE] =
&BluetoothDaemonCoreModule::LeTestModeRsp,
};
MOZ_ASSERT(!NS_IsMainThread());
if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
return;
}
RefPtr<BluetoothCoreResultHandler> res =
static_cast<BluetoothCoreResultHandler*>(aRes);
if (!res) {
return; // Return early if no result handler has been set for response
}
(this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
}
// Notifications
//
class BluetoothDaemonCoreModule::NotificationHandlerWrapper final
{
public:
typedef BluetoothCoreNotificationHandler ObjectType;
static ObjectType* GetInstance()
{
MOZ_ASSERT(NS_IsMainThread());
return sNotificationHandler;
}
};
void
BluetoothDaemonCoreModule::AdapterStateChangedNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
AdapterStateChangedNotification::Dispatch(
&BluetoothCoreNotificationHandler::AdapterStateChangedNotification,
UnpackPDUInitOp(aPDU));
}
// Init operator class for AdapterPropertiesNotification
class BluetoothDaemonCoreModule::AdapterPropertiesInitOp final
: private PDUInitOp
{
public:
AdapterPropertiesInitOp(DaemonSocketPDU& aPDU)
: PDUInitOp(aPDU)
{ }
nsresult
operator () (BluetoothStatus& aArg1, int& aArg2,
UniquePtr<BluetoothProperty[]>& aArg3) const
{
DaemonSocketPDU& pdu = GetPDU();
/* Read status */
nsresult rv = UnpackPDU(pdu, aArg1);
if (NS_FAILED(rv)) {
return rv;
}
/* Read number of properties */
uint8_t numProperties;
rv = UnpackPDU(pdu, numProperties);
if (NS_FAILED(rv)) {
return rv;
}
aArg2 = numProperties;
/* Read properties array */
UnpackArray<BluetoothProperty> properties(aArg3, aArg2);
rv = UnpackPDU(pdu, properties);
if (NS_FAILED(rv)) {
return rv;
}
WarnAboutTrailingData();
return NS_OK;
}
};
void
BluetoothDaemonCoreModule::AdapterPropertiesNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
AdapterPropertiesNotification::Dispatch(
&BluetoothCoreNotificationHandler::AdapterPropertiesNotification,
AdapterPropertiesInitOp(aPDU));
}
// Init operator class for RemoteDevicePropertiesNotification
class BluetoothDaemonCoreModule::RemoteDevicePropertiesInitOp final
: private PDUInitOp
{
public:
RemoteDevicePropertiesInitOp(DaemonSocketPDU& aPDU)
: PDUInitOp(aPDU)
{ }
nsresult
operator () (BluetoothStatus& aArg1, BluetoothAddress& aArg2, int& aArg3,
UniquePtr<BluetoothProperty[]>& aArg4) const
{
DaemonSocketPDU& pdu = GetPDU();
/* Read status */
nsresult rv = UnpackPDU(pdu, aArg1);
if (NS_FAILED(rv)) {
return rv;
}
/* Read address */
rv = UnpackPDU(pdu, aArg2);
if (NS_FAILED(rv)) {
return rv;
}
/* Read number of properties */
uint8_t numProperties;
rv = UnpackPDU(pdu, numProperties);
if (NS_FAILED(rv)) {
return rv;
}
aArg3 = numProperties;
/* Read properties array */
UnpackArray<BluetoothProperty> properties(aArg4, aArg3);
rv = UnpackPDU(pdu, properties);
if (NS_FAILED(rv)) {
return rv;
}
WarnAboutTrailingData();
return NS_OK;
}
};
void
BluetoothDaemonCoreModule::RemoteDevicePropertiesNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
RemoteDevicePropertiesNotification::Dispatch(
&BluetoothCoreNotificationHandler::RemoteDevicePropertiesNotification,
RemoteDevicePropertiesInitOp(aPDU));
}
// Init operator class for DeviceFoundNotification
class BluetoothDaemonCoreModule::DeviceFoundInitOp final
: private PDUInitOp
{
public:
DeviceFoundInitOp(DaemonSocketPDU& aPDU)
: PDUInitOp(aPDU)
{ }
nsresult
operator () (int& aArg1, UniquePtr<BluetoothProperty[]>& aArg2) const
{
DaemonSocketPDU& pdu = GetPDU();
/* Read number of properties */
uint8_t numProperties;
nsresult rv = UnpackPDU(pdu, numProperties);
if (NS_FAILED(rv)) {
return rv;
}
aArg1 = numProperties;
/* Read properties array */
UnpackArray<BluetoothProperty> properties(aArg2, aArg1);
rv = UnpackPDU(pdu, properties);
if (NS_FAILED(rv)) {
return rv;
}
WarnAboutTrailingData();
return NS_OK;
}
};
void
BluetoothDaemonCoreModule::DeviceFoundNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
DeviceFoundNotification::Dispatch(
&BluetoothCoreNotificationHandler::DeviceFoundNotification,
DeviceFoundInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::DiscoveryStateChangedNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
DiscoveryStateChangedNotification::Dispatch(
&BluetoothCoreNotificationHandler::DiscoveryStateChangedNotification,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::PinRequestNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
PinRequestNotification::Dispatch(
&BluetoothCoreNotificationHandler::PinRequestNotification,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::SspRequestNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
SspRequestNotification::Dispatch(
&BluetoothCoreNotificationHandler::SspRequestNotification,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::BondStateChangedNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
BondStateChangedNotification::Dispatch(
&BluetoothCoreNotificationHandler::BondStateChangedNotification,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::AclStateChangedNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
AclStateChangedNotification::Dispatch(
&BluetoothCoreNotificationHandler::AclStateChangedNotification,
UnpackPDUInitOp(aPDU));
}
// Init operator class for DutModeRecvNotification
class BluetoothDaemonCoreModule::DutModeRecvInitOp final
: private PDUInitOp
{
public:
DutModeRecvInitOp(DaemonSocketPDU& aPDU)
: PDUInitOp(aPDU)
{ }
nsresult
operator () (uint16_t& aArg1, UniquePtr<uint8_t[]>& aArg2,
uint8_t& aArg3) const
{
DaemonSocketPDU& pdu = GetPDU();
/* Read opcode */
nsresult rv = UnpackPDU(pdu, aArg1);
if (NS_FAILED(rv)) {
return rv;
}
/* Read length */
rv = UnpackPDU(pdu, aArg3);
if (NS_FAILED(rv)) {
return rv;
}
/* Read data */
rv = UnpackPDU(pdu, UnpackArray<uint8_t>(aArg2, aArg3));
if (NS_FAILED(rv)) {
return rv;
}
WarnAboutTrailingData();
return NS_OK;
}
};
void
BluetoothDaemonCoreModule::DutModeRecvNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
DutModeRecvNotification::Dispatch(
&BluetoothCoreNotificationHandler::DutModeRecvNotification,
DutModeRecvInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::LeTestModeNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU)
{
LeTestModeNotification::Dispatch(
&BluetoothCoreNotificationHandler::LeTestModeNotification,
UnpackPDUInitOp(aPDU));
}
void
BluetoothDaemonCoreModule::HandleNtf(
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
DaemonSocketResultHandler* aRes)
{
static void (BluetoothDaemonCoreModule::* const HandleNtf[])(
const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
[0] = &BluetoothDaemonCoreModule::AdapterStateChangedNtf,
[1] = &BluetoothDaemonCoreModule::AdapterPropertiesNtf,
[2] = &BluetoothDaemonCoreModule::RemoteDevicePropertiesNtf,
[3] = &BluetoothDaemonCoreModule::DeviceFoundNtf,
[4] = &BluetoothDaemonCoreModule::DiscoveryStateChangedNtf,
[5] = &BluetoothDaemonCoreModule::PinRequestNtf,
[6] = &BluetoothDaemonCoreModule::SspRequestNtf,
[7] = &BluetoothDaemonCoreModule::BondStateChangedNtf,
[8] = &BluetoothDaemonCoreModule::AclStateChangedNtf,
[9] = &BluetoothDaemonCoreModule::DutModeRecvNtf,
[10] = &BluetoothDaemonCoreModule::LeTestModeNtf
};
MOZ_ASSERT(!NS_IsMainThread());
uint8_t index = aHeader.mOpcode - 0x81;
if (NS_WARN_IF(!(index < MOZ_ARRAY_LENGTH(HandleNtf))) ||
NS_WARN_IF(!HandleNtf[index])) {
return;
}
(this->*(HandleNtf[index]))(aHeader, aPDU);
}
//
// Core interface
//
BluetoothDaemonCoreInterface::BluetoothDaemonCoreInterface(
BluetoothDaemonCoreModule* aModule)
: mModule(aModule)
{ }
BluetoothDaemonCoreInterface::~BluetoothDaemonCoreInterface()
{ }
void
BluetoothDaemonCoreInterface::SetNotificationHandler(
BluetoothCoreNotificationHandler* aNotificationHandler)
{
MOZ_ASSERT(mModule);
mModule->SetNotificationHandler(aNotificationHandler);
}
/* Enable / Disable */
void
BluetoothDaemonCoreInterface::Enable(BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->EnableCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::Disable(BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->DisableCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Adapter Properties */
void
BluetoothDaemonCoreInterface::GetAdapterProperties(
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->GetAdapterPropertiesCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::GetAdapterProperty(
BluetoothPropertyType aType, BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->GetAdapterPropertyCmd(aType, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::SetAdapterProperty(
const BluetoothProperty& aProperty, BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->SetAdapterPropertyCmd(aProperty, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Remote Device Properties */
void
BluetoothDaemonCoreInterface::GetRemoteDeviceProperties(
const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->GetRemoteDevicePropertiesCmd(aRemoteAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::GetRemoteDeviceProperty(
const BluetoothAddress& aRemoteAddr, BluetoothPropertyType aType,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->GetRemoteDevicePropertyCmd(aRemoteAddr, aType, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::SetRemoteDeviceProperty(
const BluetoothAddress& aRemoteAddr, const BluetoothProperty& aProperty,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->SetRemoteDevicePropertyCmd(aRemoteAddr,
aProperty,
aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Remote Services */
void
BluetoothDaemonCoreInterface::GetRemoteServiceRecord(
const BluetoothAddress& aRemoteAddr, const BluetoothUuid& aUuid,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->GetRemoteServiceRecordCmd(aRemoteAddr, aUuid, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::GetRemoteServices(
const BluetoothAddress& aRemoteAddr, BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->GetRemoteServicesCmd(aRemoteAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Discovery */
void
BluetoothDaemonCoreInterface::StartDiscovery(BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->StartDiscoveryCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::CancelDiscovery(BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->CancelDiscoveryCmd(aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Bonds */
void
BluetoothDaemonCoreInterface::CreateBond(const BluetoothAddress& aBdAddr,
BluetoothTransport aTransport,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->CreateBondCmd(aBdAddr, aTransport, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::RemoveBond(const BluetoothAddress& aBdAddr,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->RemoveBondCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::CancelBond(
const BluetoothAddress& aBdAddr, BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->CancelBondCmd(aBdAddr, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Connection */
void
BluetoothDaemonCoreInterface::GetConnectionState(
const BluetoothAddress& aBdAddr, BluetoothCoreResultHandler* aRes)
{
// NO-OP: no corresponding interface of current BlueZ
}
/* Authentication */
void
BluetoothDaemonCoreInterface::PinReply(const BluetoothAddress& aBdAddr,
bool aAccept,
const BluetoothPinCode& aPinCode,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->PinReplyCmd(aBdAddr, aAccept, aPinCode, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::SspReply(const BluetoothAddress& aBdAddr,
BluetoothSspVariant aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->SspReplyCmd(aBdAddr, aVariant, aAccept, aPasskey,
aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* DUT Mode */
void
BluetoothDaemonCoreInterface::DutModeConfigure(
bool aEnable, BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->DutModeConfigureCmd(aEnable, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
void
BluetoothDaemonCoreInterface::DutModeSend(uint16_t aOpcode,
uint8_t* aBuf,
uint8_t aLen,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->DutModeSendCmd(aOpcode, aBuf, aLen, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* LE Mode */
void
BluetoothDaemonCoreInterface::LeTestMode(uint16_t aOpcode,
uint8_t* aBuf,
uint8_t aLen,
BluetoothCoreResultHandler* aRes)
{
nsresult rv = mModule->LeTestModeCmd(aOpcode, aBuf, aLen, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
/* Energy Information */
void
BluetoothDaemonCoreInterface::ReadEnergyInfo(BluetoothCoreResultHandler* aRes)
{
// NO-OP: no corresponding interface of current BlueZ
}
void
BluetoothDaemonCoreInterface::DispatchError(BluetoothCoreResultHandler* aRes,
BluetoothStatus aStatus)
{
DaemonResultRunnable1<
BluetoothCoreResultHandler, void,
BluetoothStatus, BluetoothStatus>::Dispatch(
aRes, &BluetoothCoreResultHandler::OnError,
ConstantInitOp1<BluetoothStatus>(aStatus));
}
void
BluetoothDaemonCoreInterface::DispatchError(BluetoothCoreResultHandler* aRes,
nsresult aRv)
{
BluetoothStatus status;
if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
status = STATUS_FAIL;
}
DispatchError(aRes, status);
}
END_BLUETOOTH_NAMESPACE