diff options
author | bryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-23 18:42:53 +0000 |
---|---|---|
committer | bryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-23 18:42:53 +0000 |
commit | 5c8589ac12643f2fb25d1a99716da10761efcaf8 (patch) | |
tree | 153a0819c8fea3b5da433bd13dc2c9a98614c9cf /chrome/browser/chromeos/bluetooth/bluetooth_utils.cc | |
parent | 77e07b84f56ef033bb2a1dc6a6578b393868517a (diff) | |
download | chromium_src-5c8589ac12643f2fb25d1a99716da10761efcaf8.zip chromium_src-5c8589ac12643f2fb25d1a99716da10761efcaf8.tar.gz chromium_src-5c8589ac12643f2fb25d1a99716da10761efcaf8.tar.bz2 |
Add support for creating bluetooth RFCOMM sockets.
BUG=119473
TEST=added some unittests
Review URL: http://codereview.chromium.org/10007008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/bluetooth/bluetooth_utils.cc')
-rw-r--r-- | chrome/browser/chromeos/bluetooth/bluetooth_utils.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc b/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc new file mode 100644 index 0000000..8ee0ab9 --- /dev/null +++ b/chrome/browser/chromeos/bluetooth/bluetooth_utils.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" + +#include <vector> + +#include <bluetooth/bluetooth.h> + +#include "base/logging.h" +#include "base/string_number_conversions.h" + +namespace chromeos { +namespace bluetooth_utils { + +bool str2ba(const std::string& in_address, bdaddr_t* out_address) { + if (!out_address) + return false; + + memset(out_address, 0, sizeof(*out_address)); + + if (in_address.size() != 17) + return false; + + std::string numbers_only; + for (int i = 0; i < 6; ++i) { + numbers_only += in_address.substr(i * 3, 2); + } + + std::vector<uint8> address_bytes; + 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]; + } + return true; + } + } + + return false; +} + +} // namespace bluetooth_utils +} // namespace chromeos |