diff --git a/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp b/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp index ee8ce30a9b2b..5ea0aeb805c9 100644 --- a/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp @@ -38,34 +38,22 @@ using namespace mozilla::ipc; namespace { // UUID of Map Mas - static const BluetoothUuid kMapMas = { - { - 0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - } - }; + static const BluetoothUuid kMapMas(MAP_MAS); + // UUID of Map Mns - static const BluetoothUuid kMapMns = { - { - 0x00, 0x00, 0x11, 0x33, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - } - }; + static const BluetoothUuid kMapMns(MAP_MNS); + // UUID used in Map OBEX MAS target header - static const BluetoothUuid kMapMasObexTarget = { - { - 0xBB, 0x58, 0x2B, 0x40, 0x42, 0x0C, 0x11, 0xDB, - 0xB0, 0xDE, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66 - } - }; + static const BluetoothUuid kMapMasObexTarget(0xBB, 0x58, 0x2B, 0x40, + 0x42, 0x0C, 0x11, 0xDB, + 0xB0, 0xDE, 0x08, 0x00, + 0x20, 0x0C, 0x9A, 0x66); // UUID used in Map OBEX MNS target header - static const BluetoothUuid kMapMnsObexTarget = { - { - 0xBB, 0x58, 0x2B, 0x41, 0x42, 0x0C, 0x11, 0xDB, - 0xB0, 0xDE, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66 - } - }; + static const BluetoothUuid kMapMnsObexTarget(0xBB, 0x58, 0x2B, 0x41, + 0x42, 0x0C, 0x11, 0xDB, + 0xB0, 0xDE, 0x08, 0x00, + 0x20, 0x0C, 0x9A, 0x66); StaticRefPtr sMapSmsManager; static bool sInShutdown = false; diff --git a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp index 7a8a93827219..d19a6d77efc6 100644 --- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp @@ -60,12 +60,7 @@ namespace { static const double kSdpUpdatingTimeoutMs = 3000.0; // UUID of OBEX Object Push - static const BluetoothUuid kObexObjectPush = { - { - 0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - } - }; + static const BluetoothUuid kObexObjectPush(OBJECT_PUSH); StaticRefPtr sBluetoothOppManager; static bool sInShutdown = false; diff --git a/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp b/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp index 183160edd1da..534684313a28 100644 --- a/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp @@ -31,20 +31,13 @@ using namespace mozilla::ipc; namespace { // UUID of PBAP PSE - static const BluetoothUuid kPbapPSE = { - { - 0x00, 0x00, 0x11, 0x2F, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - } - }; + static const BluetoothUuid kPbapPSE(PBAP_PSE); // UUID used in PBAP OBEX target header - static const BluetoothUuid kPbapObexTarget = { - { - 0x79, 0x61, 0x35, 0xF0, 0xF0, 0xC5, 0x11, 0xD8, - 0x09, 0x66, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66 - } - }; + static const BluetoothUuid kPbapObexTarget(0x79, 0x61, 0x35, 0xF0, + 0xF0, 0xC5, 0x11, 0xD8, + 0x09, 0x66, 0x08, 0x00, + 0x20, 0x0C, 0x9A, 0x66); // App parameters to pull phonebook static const AppParameterTag sPhonebookTags[] = { diff --git a/dom/bluetooth/bluez/BluetoothHfpManager.cpp b/dom/bluetooth/bluez/BluetoothHfpManager.cpp index 0324e32bf899..c4a10f65fe97 100644 --- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp @@ -82,28 +82,13 @@ namespace { static const char kHfpCrlf[] = "\xd\xa"; // UUID of Handsfree Audio Gateway - static const BluetoothUuid kHandsfreeAG = { - { - 0x00, 0x00, 0x11, 0x1F, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - } - }; + static const BluetoothUuid kHandsfreeAG(HANDSFREE_AG); // UUID of Headset Audio Gateway - static const BluetoothUuid kHeadsetAG = { - { - 0x00, 0x00, 0x11, 0x12, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - } - }; + static const BluetoothUuid kHeadsetAG(HEADSET_AG); // Unknown service UUID (for SCO socket) - static const BluetoothUuid kUnknownService = { - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - } - }; + static const BluetoothUuid kUnknownService(BluetoothServiceClass::UNKNOWN); #ifdef MOZ_B2G_RIL // Sending ringtone related diff --git a/dom/bluetooth/bluez/BluetoothOppManager.cpp b/dom/bluetooth/bluez/BluetoothOppManager.cpp index 8c36d3df9f13..a0b2fa58a2d5 100644 --- a/dom/bluetooth/bluez/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluez/BluetoothOppManager.cpp @@ -62,12 +62,7 @@ namespace { static const double kSdpUpdatingTimeoutMs = 3000.0; // UUID of OBEX Object Push - static const BluetoothUuid kObexObjectPush = { - { - 0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB - } - }; + static const BluetoothUuid kObexObjectPush(OBJECT_PUSH); StaticRefPtr sBluetoothOppManager; static bool sInShutdown = false; diff --git a/dom/bluetooth/common/BluetoothCommon.cpp b/dom/bluetooth/common/BluetoothCommon.cpp index 6fbd19d09f10..256418245bc1 100644 --- a/dom/bluetooth/common/BluetoothCommon.cpp +++ b/dom/bluetooth/common/BluetoothCommon.cpp @@ -21,4 +21,13 @@ const BluetoothAddress BluetoothAddress::ALL(0xff, 0xff, 0xff, const BluetoothAddress BluetoothAddress::LOCAL(0x00, 0x00, 0x00, 0xff, 0xff, 0xff); +// +// |BluetoothUuid| +// + +const BluetoothUuid BluetoothUuid::ZERO(0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00); + END_BLUETOOTH_NAMESPACE diff --git a/dom/bluetooth/common/BluetoothCommon.h b/dom/bluetooth/common/BluetoothCommon.h index bef383c45cd5..f7ff42fbe3a4 100644 --- a/dom/bluetooth/common/BluetoothCommon.h +++ b/dom/bluetooth/common/BluetoothCommon.h @@ -7,6 +7,7 @@ #ifndef mozilla_dom_bluetooth_BluetoothCommon_h #define mozilla_dom_bluetooth_BluetoothCommon_h +#include #include "mozilla/Compiler.h" #include "mozilla/Observer.h" #include "nsAutoPtr.h" @@ -504,22 +505,165 @@ struct BluetoothConfigurationParameter { nsAutoArrayPtr mValue; }; -struct BluetoothUuid { +/* + * Service classes and Profile Identifiers + * + * Supported Bluetooth services for v1 are listed as below. + * + * The value of each service class is defined in "AssignedNumbers/Service + * Discovery Protocol (SDP)/Service classes and Profile Identifiers" in the + * Bluetooth Core Specification. + */ +enum BluetoothServiceClass { + UNKNOWN = 0x0000, + OBJECT_PUSH = 0x1105, + HEADSET = 0x1108, + A2DP_SINK = 0x110b, + AVRCP_TARGET = 0x110c, + A2DP = 0x110d, + AVRCP = 0x110e, + AVRCP_CONTROLLER = 0x110f, + HEADSET_AG = 0x1112, + HANDSFREE = 0x111e, + HANDSFREE_AG = 0x111f, + HID = 0x1124, + PBAP_PCE = 0x112e, + PBAP_PSE = 0x112f, + MAP_MAS = 0x1132, + MAP_MNS = 0x1133 +}; + +struct BluetoothUuid final { + + static const BluetoothUuid ZERO; + uint8_t mUuid[16]; - bool operator==(const BluetoothUuid& aOther) const + BluetoothUuid() { - for (uint8_t i = 0; i < sizeof(mUuid); i++) { - if (mUuid[i] != aOther.mUuid[i]) { - return false; - } - } - return true; + Clear(); // assign ZERO } - bool operator!=(const BluetoothUuid& aOther) const + MOZ_IMPLICIT BluetoothUuid(const BluetoothUuid&) = default; + + BluetoothUuid(uint8_t aUuid0, uint8_t aUuid1, + uint8_t aUuid2, uint8_t aUuid3, + uint8_t aUuid4, uint8_t aUuid5, + uint8_t aUuid6, uint8_t aUuid7, + uint8_t aUuid8, uint8_t aUuid9, + uint8_t aUuid10, uint8_t aUuid11, + uint8_t aUuid12, uint8_t aUuid13, + uint8_t aUuid14, uint8_t aUuid15) { - return !(*this == aOther); + mUuid[0] = aUuid0; + mUuid[1] = aUuid1; + mUuid[2] = aUuid2; + mUuid[3] = aUuid3; + mUuid[4] = aUuid4; + mUuid[5] = aUuid5; + mUuid[6] = aUuid6; + mUuid[7] = aUuid7; + mUuid[8] = aUuid8; + mUuid[9] = aUuid9; + mUuid[10] = aUuid10; + mUuid[11] = aUuid11; + mUuid[12] = aUuid12; + mUuid[13] = aUuid13; + mUuid[14] = aUuid14; + mUuid[15] = aUuid15; + } + + explicit BluetoothUuid(uint32_t aUuid32) + { + SetUuid32(aUuid32); + } + + explicit BluetoothUuid(uint16_t aUuid16) + { + SetUuid16(aUuid16); + } + + explicit BluetoothUuid(BluetoothServiceClass aServiceClass) + { + SetUuid16(static_cast(aServiceClass)); + } + + BluetoothUuid& operator=(const BluetoothUuid& aRhs) = default; + + /** + * |Clear| assigns an invalid value (i.e., ZERO) to the UUID. + */ + void Clear() + { + operator=(ZERO); + } + + /** + * |IsCleared| returns true if the UUID contains a value of + * zero (i.e., ZERO). + */ + bool IsCleared() const + { + return operator==(ZERO); + } + + bool operator==(const BluetoothUuid& aRhs) const + { + return std::equal(aRhs.mUuid, + aRhs.mUuid + MOZ_ARRAY_LENGTH(aRhs.mUuid), mUuid); + } + + bool operator!=(const BluetoothUuid& aRhs) const + { + return !operator==(aRhs); + } + + /* + * Getter-setter methods for short UUIDS. The first 4 bytes in the + * UUID are represented by the short notation UUID32, and bytes 3 + * and 4 (indices 2 and 3) are represented by UUID16. The rest of + * the UUID is filled with the SDP base UUID. + * + * Below are helpers for accessing these values. + */ + + void SetUuid32(uint32_t aUuid32) + { + mUuid[0] = static_cast(0xff & (aUuid32 >> 24)); + mUuid[1] = static_cast(0xff & (aUuid32 >> 16)); + mUuid[2] = static_cast(0xff & (aUuid32 >> 8)); + mUuid[3] = static_cast(0xff & (aUuid32)); + mUuid[4] = 0x00; + mUuid[5] = 0x00; + mUuid[6] = 0x10; + mUuid[7] = 0x00; + mUuid[8] = 0x80; + mUuid[9] = 0x00; + mUuid[10] = 0x00; + mUuid[11] = 0x80; + mUuid[12] = 0x5f; + mUuid[13] = 0x9b; + mUuid[14] = 0x34; + mUuid[15] = 0xfb; + } + + uint32_t GetUuid32() const + { + return (static_cast(mUuid[0]) << 24) | + (static_cast(mUuid[1]) << 16) | + (static_cast(mUuid[2]) << 8) | + (static_cast(mUuid[3])); + } + + void SetUuid16(uint16_t aUuid16) + { + SetUuid32(aUuid16); // MSB is 0x0000 + } + + uint16_t GetUuid16() const + { + return (static_cast(mUuid[2]) << 8) | + (static_cast(mUuid[3])); } }; diff --git a/dom/bluetooth/common/BluetoothUuid.h b/dom/bluetooth/common/BluetoothUuid.h index 35bcfbe1535a..ea8c0a54f3fd 100644 --- a/dom/bluetooth/common/BluetoothUuid.h +++ b/dom/bluetooth/common/BluetoothUuid.h @@ -13,31 +13,6 @@ BEGIN_BLUETOOTH_NAMESPACE class BluetoothProfileManagerBase; -/* - * Service classes and Profile Identifiers - * - * Supported Bluetooth services for v1 are listed as below. - * - * The value of each service class is defined in "AssignedNumbers/Service - * Discovery Protocol (SDP)/Service classes and Profile Identifiers" in the - * Bluetooth Core Specification. - */ -enum BluetoothServiceClass -{ - A2DP = 0x110D, - A2DP_SINK = 0x110B, - AVRCP = 0x110E, - AVRCP_TARGET = 0x110C, - AVRCP_CONTROLLER = 0x110F, - HANDSFREE = 0x111E, - HANDSFREE_AG = 0x111F, - HEADSET = 0x1108, - HEADSET_AG = 0x1112, - HID = 0x1124, - OBJECT_PUSH = 0x1105, - UNKNOWN = 0x0000 -}; - class BluetoothUuidHelper { public: