Commit bf94b886 authored by keybuk@chromium.org's avatar keybuk@chromium.org

Bluetooth: add support for Bluetooth-assigned Device ID

The Bluetooth SIG also assigned Vendor IDs used in the Device ID
specification, in fact, Chromebooks use a Bluetooth SIG-assigned
Device ID rather than a USB IF-assigned one.

These take the format bluetooth:vXXXXpYYYYdZZZZ; handle this case
in addition to the usb:vXXXXpYYYYdZZZZ case.

BUG=350159
TEST=device_unittests

Review URL: https://codereview.chromium.org/189663003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255603 0039d316-1c4b-4281-b951-d872f2087c98
parent a15932ae
...@@ -3094,4 +3094,54 @@ TEST_F(BluetoothChromeOSTest, RemovePairingDelegateDuringPairing) { ...@@ -3094,4 +3094,54 @@ TEST_F(BluetoothChromeOSTest, RemovePairingDelegateDuringPairing) {
EXPECT_FALSE(device->IsPaired()); EXPECT_FALSE(device->IsPaired());
} }
TEST_F(BluetoothChromeOSTest, DeviceId) {
GetAdapter();
// Use the built-in paired device for this test, grab its Properties
// structure so we can adjust the underlying modalias property.
BluetoothDevice* device = adapter_->GetDevice(
FakeBluetoothDeviceClient::kPairedDeviceAddress);
FakeBluetoothDeviceClient::Properties* properties =
fake_bluetooth_device_client_->GetProperties(
dbus::ObjectPath(FakeBluetoothDeviceClient::kPairedDevicePath));
ASSERT_TRUE(device != NULL);
ASSERT_TRUE(properties != NULL);
// Valid USB IF-assigned identifier.
ASSERT_EQ("usb:v05ACp030Dd0306", properties->modalias.value());
EXPECT_EQ(0x05ac, device->GetVendorID());
EXPECT_EQ(0x030d, device->GetProductID());
EXPECT_EQ(0x0306, device->GetDeviceID());
// Valid Bluetooth SIG-assigned identifier.
properties->modalias.ReplaceValue("bluetooth:v00E0p2400d0400");
EXPECT_EQ(0x00e0, device->GetVendorID());
EXPECT_EQ(0x2400, device->GetProductID());
EXPECT_EQ(0x0400, device->GetDeviceID());
// Invalid USB IF-assigned identifier.
properties->modalias.ReplaceValue("usb:x00E0p2400d0400");
EXPECT_EQ(0, device->GetVendorID());
EXPECT_EQ(0, device->GetProductID());
EXPECT_EQ(0, device->GetDeviceID());
// Invalid Bluetooth SIG-assigned identifier.
properties->modalias.ReplaceValue("bluetooth:x00E0p2400d0400");
EXPECT_EQ(0, device->GetVendorID());
EXPECT_EQ(0, device->GetProductID());
EXPECT_EQ(0, device->GetDeviceID());
// Unknown vendor specification identifier.
properties->modalias.ReplaceValue("chrome:v00E0p2400d0400");
EXPECT_EQ(0, device->GetVendorID());
EXPECT_EQ(0, device->GetProductID());
EXPECT_EQ(0, device->GetDeviceID());
}
} // namespace chromeos } // namespace chromeos
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "device/bluetooth/bluetooth_device_chromeos.h" #include "device/bluetooth/bluetooth_device_chromeos.h"
#include <stdio.h>
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
...@@ -49,25 +51,18 @@ void ParseModalias(const dbus::ObjectPath& object_path, ...@@ -49,25 +51,18 @@ void ParseModalias(const dbus::ObjectPath& object_path,
DCHECK(properties); DCHECK(properties);
std::string modalias = properties->modalias.value(); std::string modalias = properties->modalias.value();
if (StartsWithASCII(modalias, "usb:", false) && modalias.length() == 19) { int vendor_value, product_value, device_value;
// usb:vXXXXpXXXXdXXXX
if (modalias[4] == 'v' && vendor_id != NULL) { if (sscanf(modalias.c_str(), "bluetooth:v%04xp%04xd%04x",
uint64 component = 0; &vendor_value, &product_value, &device_value) == 3 ||
base::HexStringToUInt64(modalias.substr(5, 4), &component); sscanf(modalias.c_str(), "usb:v%04xp%04xd%04x",
*vendor_id = component; &vendor_value, &product_value, &device_value) == 3) {
} if (vendor_id != NULL)
*vendor_id = vendor_value;
if (modalias[9] == 'p' && product_id != NULL) { if (product_id != NULL)
uint64 component = 0; *product_id = product_value;
base::HexStringToUInt64(modalias.substr(10, 4), &component); if (device_id != NULL)
*product_id = component; *device_id = device_value;
}
if (modalias[14] == 'd' && device_id != NULL) {
uint64 component = 0;
base::HexStringToUInt64(modalias.substr(15, 4), &component);
*device_id = component;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment