OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include <bluetooth/bluetooth.h> |
| 10 |
| 11 #include "base/logging.h" |
| 12 #include "base/string_number_conversions.h" |
| 13 |
| 14 namespace chromeos { |
| 15 namespace bluetooth_utils { |
| 16 |
| 17 bool str2ba(const std::string& in_address, bdaddr_t* out_address) { |
| 18 if (!out_address) |
| 19 return false; |
| 20 |
| 21 memset(out_address, 0, sizeof(*out_address)); |
| 22 |
| 23 if (in_address.size() != 17) |
| 24 return false; |
| 25 |
| 26 std::string numbers_only; |
| 27 for (int i = 0; i < 6; ++i) { |
| 28 numbers_only += in_address.substr(i * 3, 2); |
| 29 } |
| 30 |
| 31 std::vector<uint8> address_bytes; |
| 32 if (base::HexStringToBytes(numbers_only, &address_bytes)) { |
| 33 if (address_bytes.size() == 6) { |
| 34 for (int i = 0; i < 6; ++i) { |
| 35 out_address->b[i] = address_bytes[i]; |
| 36 } |
| 37 return true; |
| 38 } |
| 39 } |
| 40 |
| 41 return false; |
| 42 } |
| 43 |
| 44 } // namespace bluetooth_utils |
| 45 } // namespace chromeos |
OLD | NEW |