Bug 1215525: Update |BluetoothUuid| structure with c'tors and helper methods, r=brsun

This commit is contained in:
Thomas Zimmermann 2015-10-30 14:54:41 +01:00
Родитель 5b8c793b0f
Коммит da8fa8c983
7 изменённых файлов: 172 добавлений и 100 удалений

Просмотреть файл

@ -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<BluetoothMapSmsManager> sMapSmsManager;
static bool sInShutdown = false;

Просмотреть файл

@ -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<BluetoothOppManager> sBluetoothOppManager;
static bool sInShutdown = false;

Просмотреть файл

@ -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[] = {

Просмотреть файл

@ -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

Просмотреть файл

@ -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<BluetoothOppManager> sBluetoothOppManager;
static bool sInShutdown = false;

Просмотреть файл

@ -7,6 +7,7 @@
#ifndef mozilla_dom_bluetooth_BluetoothCommon_h
#define mozilla_dom_bluetooth_BluetoothCommon_h
#include <algorithm>
#include "mozilla/Compiler.h"
#include "mozilla/Observer.h"
#include "nsAutoPtr.h"
@ -504,22 +505,162 @@ struct BluetoothConfigurationParameter {
nsAutoArrayPtr<uint8_t> mValue;
};
/*
* 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 {
uint8_t mUuid[16];
bool operator==(const BluetoothUuid& aOther) const
BluetoothUuid()
: BluetoothUuid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
{ }
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)
{
for (uint8_t i = 0; i < sizeof(mUuid); i++) {
if (mUuid[i] != aOther.mUuid[i]) {
return false;
}
}
return true;
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;
}
bool operator!=(const BluetoothUuid& aOther) const
explicit BluetoothUuid(uint32_t aUuid32)
{
return !(*this == aOther);
SetUuid32(aUuid32);
}
explicit BluetoothUuid(uint16_t aUuid16)
{
SetUuid16(aUuid16);
}
explicit BluetoothUuid(BluetoothServiceClass aServiceClass)
{
SetUuid16(static_cast<uint16_t>(aServiceClass));
}
BluetoothUuid& operator=(const BluetoothUuid& aRhs) = default;
/**
* |Clear| assigns an invalid value (i.e., zero) to the UUID.
*/
void Clear()
{
operator=(BluetoothUuid());
}
/**
* |IsCleared| returns true if the UUID contains a value of
* zero.
*/
bool IsCleared() const
{
return operator==(BluetoothUuid());
}
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<uint8_t>(0xff & (aUuid32 >> 24));
mUuid[1] = static_cast<uint8_t>(0xff & (aUuid32 >> 16));
mUuid[2] = static_cast<uint8_t>(0xff & (aUuid32 >> 8));
mUuid[3] = static_cast<uint8_t>(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<uint32_t>(mUuid[0]) << 24) |
(static_cast<uint32_t>(mUuid[1]) << 16) |
(static_cast<uint32_t>(mUuid[2]) << 8) |
(static_cast<uint32_t>(mUuid[3]));
}
void SetUuid16(uint16_t aUuid16)
{
SetUuid32(aUuid16); // MSB is 0x0000
}
uint16_t GetUuid16() const
{
return (static_cast<uint16_t>(mUuid[2]) << 8) |
(static_cast<uint16_t>(mUuid[3]));
}
};

Просмотреть файл

@ -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: