From 01d7d59785a32412a729007114bebcd2f6206ea3 Mon Sep 17 00:00:00 2001 From: Jamin Liu Date: Thu, 2 Apr 2015 02:28:00 -0400 Subject: [PATCH] Bug 1141899 - If Bluetooth CoD of remote device is unclear, add common profile managers to profile list. r=shuang --- dom/bluetooth/BluetoothProfileController.cpp | 10 ++++++++++ dom/bluetooth/BluetoothProfileController.h | 11 +++++++++++ dom/bluetooth2/BluetoothProfileController.cpp | 10 ++++++++++ dom/bluetooth2/BluetoothProfileController.h | 11 +++++++++++ 4 files changed, 42 insertions(+) diff --git a/dom/bluetooth/BluetoothProfileController.cpp b/dom/bluetooth/BluetoothProfileController.cpp index 4fb1e8215602..53b858a00ded 100644 --- a/dom/bluetooth/BluetoothProfileController.cpp +++ b/dom/bluetooth/BluetoothProfileController.cpp @@ -176,6 +176,16 @@ BluetoothProfileController::SetupProfiles(bool aAssignServiceClass) bool isRemoteControl = IS_REMOTE_CONTROL(mTarget.cod); bool isKeyboard = IS_KEYBOARD(mTarget.cod); bool isPointingDevice = IS_POINTING_DEVICE(mTarget.cod); + bool isInvalid = IS_INVALID_COD(mTarget.cod); + + // The value of CoD is invalid. Since the device didn't declare its class of + // device properly, we assume the device may support all of these profiles. + if (isInvalid) { + AddProfile(BluetoothHfpManager::Get()); + AddProfile(BluetoothA2dpManager::Get()); + AddProfile(BluetoothHidManager::Get()); + return; + } NS_ENSURE_TRUE_VOID(hasAudio || hasRendering || isPeripheral); diff --git a/dom/bluetooth/BluetoothProfileController.h b/dom/bluetooth/BluetoothProfileController.h index 5cdbe1bbf559..72a6a076b003 100644 --- a/dom/bluetooth/BluetoothProfileController.h +++ b/dom/bluetooth/BluetoothProfileController.h @@ -53,6 +53,17 @@ BEGIN_BLUETOOTH_NAMESPACE // Pointing device: sub-field of minor device class (Bit 7) #define IS_POINTING_DEVICE(cod) ((GET_MINOR_DEVICE_CLASS(cod) & 0x20) >> 5) +/** + * Check whether the value of CoD is invalid. (i.e. Bit 31 ~ Bit 24 != 0x0) + * + * According to Bluetooth core spec v4.1. Vol 2, Sec. 7.3, the data length of + * CoD (class of device) is 3 bytes. The two least significant bits are used to + * indicate 'format type'. The following 22 bits are used to indicate category + * of service class and device type. The remaining 8 bits (Bit 31 ~ Bit 24) + * should be unassigned bits, since BlueDroid uses uint32_t to store CoD. + */ +#define IS_INVALID_COD(cod) (cod >> 24) + class BluetoothProfileManagerBase; class BluetoothReplyRunnable; typedef void (*BluetoothProfileControllerCallback)(); diff --git a/dom/bluetooth2/BluetoothProfileController.cpp b/dom/bluetooth2/BluetoothProfileController.cpp index a939a653908b..72ba1b09262b 100644 --- a/dom/bluetooth2/BluetoothProfileController.cpp +++ b/dom/bluetooth2/BluetoothProfileController.cpp @@ -173,6 +173,16 @@ BluetoothProfileController::SetupProfiles(bool aAssignServiceClass) bool isRemoteControl = IS_REMOTE_CONTROL(mTarget.cod); bool isKeyboard = IS_KEYBOARD(mTarget.cod); bool isPointingDevice = IS_POINTING_DEVICE(mTarget.cod); + bool isInvalid = IS_INVALID_COD(mTarget.cod); + + // The value of CoD is invalid. Since the device didn't declare its class of + // device properly, we assume the device may support all of these profiles. + if (isInvalid) { + AddProfile(BluetoothHfpManager::Get()); + AddProfile(BluetoothA2dpManager::Get()); + AddProfile(BluetoothHidManager::Get()); + return; + } NS_ENSURE_TRUE_VOID(hasAudio || hasRendering || isPeripheral); diff --git a/dom/bluetooth2/BluetoothProfileController.h b/dom/bluetooth2/BluetoothProfileController.h index e4b12840a8a7..39b47d6a799e 100644 --- a/dom/bluetooth2/BluetoothProfileController.h +++ b/dom/bluetooth2/BluetoothProfileController.h @@ -53,6 +53,17 @@ BEGIN_BLUETOOTH_NAMESPACE // Pointing device: sub-field of minor device class (Bit 7) #define IS_POINTING_DEVICE(cod) ((GET_MINOR_DEVICE_CLASS(cod) & 0x20) >> 5) +/** + * Check whether the value of CoD is invalid. (i.e. Bit 31 ~ Bit 24 != 0x0) + * + * According to Bluetooth core spec v4.1. Vol 2, Sec. 7.3, the data length of + * CoD (class of device) is 3 bytes. The two least significant bits are used to + * indicate 'format type'. The following 22 bits are used to indicate category + * of service class and device type. The remaining 8 bits (Bit 31 ~ Bit 24) + * should be unassigned bits, since BlueDroid uses uint32_t to store CoD. + */ +#define IS_INVALID_COD(cod) (cod >> 24) + class BluetoothProfileManagerBase; class BluetoothReplyRunnable; typedef void (*BluetoothProfileControllerCallback)();