Bug 1146355: Support Bluetooth v1 and v2 in backend interfaces, r=joliu

There are some minor differences between backends in Bluetooth v1 and
v2. Some of the types have been added, removed or renamed. This patch
prepares the HAL and daemon backend interfaces to support both variants.
This commit is contained in:
Thomas Zimmermann 2015-04-09 15:57:41 +02:00
parent 23bade5cc7
commit ef3a83f42f
4 changed files with 153 additions and 0 deletions

View File

@ -508,6 +508,29 @@ public:
return rv;
}
#ifdef MOZ_B2G_BT_API_V2
nsresult SspReplyCmd(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes)
{
MOZ_ASSERT(NS_IsMainThread());
nsAutoPtr<BluetoothDaemonPDU> pdu(new BluetoothDaemonPDU(0x01, 0x11, 0));
nsresult rv = PackPDU(
PackConversion<nsAString, BluetoothAddress>(aBdAddr),
aVariant, aAccept, aPasskey, *pdu);
if (NS_FAILED(rv)) {
return rv;
}
rv = Send(pdu, aRes);
if (NS_FAILED(rv)) {
return rv;
}
unused << pdu.forget();
return rv;
}
#else
nsresult SspReplyCmd(const nsAString& aBdAddr, const nsAString& aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes)
@ -530,6 +553,7 @@ public:
unused << pdu.forget();
return rv;
}
#endif
nsresult DutModeConfigureCmd(bool aEnable, BluetoothResultHandler* aRes)
{
@ -2404,6 +2428,20 @@ BluetoothDaemonInterface::PinReply(const nsAString& aBdAddr, bool aAccept,
}
}
#ifdef MOZ_B2G_BT_API_V2
void
BluetoothDaemonInterface::SspReply(const nsAString& aBdAddr,
BluetoothSspVariant aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes)
{
nsresult rv = static_cast<BluetoothDaemonCoreModule*>
(mProtocol)->SspReplyCmd(aBdAddr, aVariant, aAccept, aPasskey, aRes);
if (NS_FAILED(rv)) {
DispatchError(aRes, rv);
}
}
#else
void
BluetoothDaemonInterface::SspReply(const nsAString& aBdAddr,
const nsAString& aVariant,
@ -2416,6 +2454,7 @@ BluetoothDaemonInterface::SspReply(const nsAString& aBdAddr,
DispatchError(aRes, rv);
}
}
#endif
/* DUT Mode */
@ -2537,4 +2576,14 @@ BluetoothDaemonInterface::GetBluetoothAvrcpInterface()
return mAvrcpInterface;
}
#ifdef MOZ_B2G_BT_API_V2
BluetoothGattInterface*
BluetoothDaemonInterface::GetBluetoothGattInterface()
{
return nullptr;
}
#else
// TODO: Support GATT
#endif
END_BLUETOOTH_NAMESPACE

View File

@ -89,9 +89,15 @@ public:
const nsAString& aPinCode,
BluetoothResultHandler* aRes);
#ifdef MOZ_B2G_BT_API_V2
void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes);
#else
void SspReply(const nsAString& aBdAddr, const nsAString& aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes);
#endif
/* DUT Mode */
@ -115,6 +121,12 @@ public:
BluetoothA2dpInterface* GetBluetoothA2dpInterface() override;
BluetoothAvrcpInterface* GetBluetoothAvrcpInterface() override;
#ifdef MOZ_B2G_BT_API_V2
BluetoothGattInterface* GetBluetoothGattInterface() override;
#else
// TODO: Support GATT
#endif
protected:
enum Channel {
LISTEN_SOCKET,

View File

@ -8,6 +8,11 @@
#include "BluetoothHALHelpers.h"
#include "BluetoothA2dpHALInterface.h"
#include "BluetoothAvrcpHALInterface.h"
#ifdef MOZ_B2G_BT_API_V2
#include "BluetoothGattHALInterface.h"
#else
// TODO: Support GATT
#endif
#include "BluetoothHandsfreeHALInterface.h"
#include "BluetoothSocketHALInterface.h"
@ -63,6 +68,23 @@ struct interface_traits<BluetoothAvrcpHALInterface>
};
#endif
#ifdef MOZ_B2G_BT_API_V2
#if ANDROID_VERSION >= 19
template<>
struct interface_traits<BluetoothGattHALInterface>
{
typedef const btgatt_interface_t const_interface_type;
static const char* profile_id()
{
return BT_PROFILE_GATT_ID;
}
};
#endif
#else
// TODO: Support GATT
#endif
typedef
BluetoothHALInterfaceRunnable0<BluetoothResultHandler, void>
BluetoothHALResultRunnable;
@ -861,6 +883,33 @@ BluetoothHALInterface::PinReply(const nsAString& aBdAddr, bool aAccept,
}
}
#ifdef MOZ_B2G_BT_API_V2
void
BluetoothHALInterface::SspReply(const nsAString& aBdAddr,
BluetoothSspVariant aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes)
{
int status;
bt_bdaddr_t bdAddr;
bt_ssp_variant_t variant;
uint8_t accept;
if (NS_SUCCEEDED(Convert(aBdAddr, bdAddr)) &&
NS_SUCCEEDED(Convert(aVariant, variant)) &&
NS_SUCCEEDED(Convert(aAccept, accept))) {
status = mInterface->ssp_reply(&bdAddr, variant, accept, aPasskey);
} else {
status = BT_STATUS_PARM_INVALID;
}
if (aRes) {
DispatchBluetoothHALResult(aRes,
&BluetoothResultHandler::SspReply,
ConvertDefault(status, STATUS_FAIL));
}
}
#else
void
BluetoothHALInterface::SspReply(const nsAString& aBdAddr,
const nsAString& aVariant,
@ -886,6 +935,7 @@ BluetoothHALInterface::SspReply(const nsAString& aBdAddr,
ConvertDefault(status, STATUS_FAIL));
}
}
#endif
/* DUT Mode */
@ -998,6 +1048,26 @@ BluetoothHALInterface::CreateProfileInterface<BluetoothAvrcpHALInterface>()
}
#endif
#ifdef MOZ_B2G_BT_API_V2
#if ANDROID_VERSION < 19
/*
* Versions that we don't support GATT will call this function
* to create an GATT interface. All interface methods will fail with
* the error constant STATUS_UNSUPPORTED.
*/
template <>
BluetoothGattHALInterface*
BluetoothHALInterface::CreateProfileInterface<BluetoothGattHALInterface>()
{
BT_WARNING("Bluetooth profile 'gatt' is not supported");
return new BluetoothGattHALInterface();
}
#endif
#else
// TODO: Support GATT
#endif
template <class T>
T*
BluetoothHALInterface::GetProfileInterface()
@ -1037,4 +1107,14 @@ BluetoothHALInterface::GetBluetoothAvrcpInterface()
return GetProfileInterface<BluetoothAvrcpHALInterface>();
}
#ifdef MOZ_B2G_BT_API_V2
BluetoothGattInterface*
BluetoothHALInterface::GetBluetoothGattInterface()
{
return GetProfileInterface<BluetoothGattHALInterface>();
}
#else
// TODO: Support GATT
#endif
END_BLUETOOTH_NAMESPACE

View File

@ -75,9 +75,15 @@ public:
const nsAString& aPinCode,
BluetoothResultHandler* aRes);
#ifdef MOZ_B2G_BT_API_V2
void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes);
#else
void SspReply(const nsAString& aBdAddr, const nsAString& aVariant,
bool aAccept, uint32_t aPasskey,
BluetoothResultHandler* aRes);
#endif
/* DUT Mode */
@ -101,6 +107,12 @@ public:
BluetoothA2dpInterface* GetBluetoothA2dpInterface();
BluetoothAvrcpInterface* GetBluetoothAvrcpInterface();
#ifdef MOZ_B2G_BT_API_V2
BluetoothGattInterface* GetBluetoothGattInterface();
#else
// TODO: Support GATT
#endif
protected:
BluetoothHALInterface(const bt_interface_t* aInterface);
~BluetoothHALInterface();