summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-27 22:22:22 +0000
committerbryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-27 22:22:22 +0000
commit98ae4a3d3ca74c8de31122951d54709b57faff08 (patch)
tree4346fb444da4448154cd0de40aceca9edd743167
parent66a7c0cd84eb5303ba95f4be9f633b31b1cf4722 (diff)
downloadchromium_src-98ae4a3d3ca74c8de31122951d54709b57faff08.zip
chromium_src-98ae4a3d3ca74c8de31122951d54709b57faff08.tar.gz
chromium_src-98ae4a3d3ca74c8de31122951d54709b57faff08.tar.bz2
Fix the semantics of str2ba.
This was originally written to correspond to strtoba, which places the pairs of bytes in the wrong order for calls to connect(). TEST=updated unit test BUG=none Review URL: http://codereview.chromium.org/10253013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134373 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/bluetooth/bluetooth_utils.cc2
-rw-r--r--chrome/browser/chromeos/bluetooth/bluetooth_utils.h2
-rw-r--r--chrome/browser/chromeos/bluetooth/bluetooth_utils_unittest.cc12
3 files changed, 9 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc b/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc
index 8ee0ab9..608845f 100644
--- a/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc
@@ -32,7 +32,7 @@ bool str2ba(const std::string& in_address, bdaddr_t* out_address) {
if (base::HexStringToBytes(numbers_only, &address_bytes)) {
if (address_bytes.size() == 6) {
for (int i = 0; i < 6; ++i) {
- out_address->b[i] = address_bytes[i];
+ out_address->b[5 - i] = address_bytes[i];
}
return true;
}
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_utils.h b/chrome/browser/chromeos/bluetooth/bluetooth_utils.h
index 2174037..09d0648 100644
--- a/chrome/browser/chromeos/bluetooth/bluetooth_utils.h
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_utils.h
@@ -16,6 +16,8 @@ namespace bluetooth_utils {
// Converts a bluetooth address in the format "B0:D0:9C:0F:3A:2D" into a
// bdaddr_t struct. Returns true on success, false on failure. The contents
// of |out_address| are zeroed on failure.
+// Note that the order is reversed upon conversion. For example,
+// "B0:D0:9C:0F:3A:2D" -> {"0x2d", "0x3a", "0x0f", "0x9c", "0xd0", "0xb0"}
bool str2ba(const std::string& in_address, bdaddr_t* out_address);
} // namespace bluetooth_utils
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_utils_unittest.cc b/chrome/browser/chromeos/bluetooth/bluetooth_utils_unittest.cc
index 4c04035..65c203e 100644
--- a/chrome/browser/chromeos/bluetooth/bluetooth_utils_unittest.cc
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_utils_unittest.cc
@@ -14,12 +14,12 @@ TEST(BluetoothUtilsTest, str2ba) {
bdaddr_t bluetooth_address;
EXPECT_TRUE(bluetooth_utils::str2ba("01:02:03:0A:10:A0", &bluetooth_address));
- EXPECT_EQ(1, bluetooth_address.b[0]);
- EXPECT_EQ(2, bluetooth_address.b[1]);
- EXPECT_EQ(3, bluetooth_address.b[2]);
- EXPECT_EQ(10, bluetooth_address.b[3]);
- EXPECT_EQ(16, bluetooth_address.b[4]);
- EXPECT_EQ(160, bluetooth_address.b[5]);
+ EXPECT_EQ(1, bluetooth_address.b[5]);
+ EXPECT_EQ(2, bluetooth_address.b[4]);
+ EXPECT_EQ(3, bluetooth_address.b[3]);
+ EXPECT_EQ(10, bluetooth_address.b[2]);
+ EXPECT_EQ(16, bluetooth_address.b[1]);
+ EXPECT_EQ(160, bluetooth_address.b[0]);
EXPECT_FALSE(bluetooth_utils::str2ba("obviously wrong", &bluetooth_address));
EXPECT_FALSE(bluetooth_utils::str2ba("00:00", &bluetooth_address));