| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" | 5 #include "device/bluetooth/bluetooth_utils.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #if defined(OS_CHROMEOS) |
| 9 #include <bluetooth/bluetooth.h> | 10 #include <bluetooth/bluetooth.h> |
| 11 #endif |
| 10 | 12 |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 static const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb"; | 18 static const char* kCommonUuidPostfix = "-0000-1000-8000-00805f9b34fb"; |
| 17 static const char* kCommonUuidPrefix = "0000"; | 19 static const char* kCommonUuidPrefix = "0000"; |
| 18 static const int kUuidSize = 36; | 20 static const int kUuidSize = 36; |
| 19 } // namespace | 21 } // namespace |
| 20 | 22 |
| 21 namespace chromeos { | 23 namespace device { |
| 22 namespace bluetooth_utils { | 24 namespace bluetooth_utils { |
| 23 | 25 |
| 26 #if defined(OS_CHROMEOS) |
| 24 bool str2ba(const std::string& in_address, bdaddr_t* out_address) { | 27 bool str2ba(const std::string& in_address, bdaddr_t* out_address) { |
| 25 if (!out_address) | 28 if (!out_address) |
| 26 return false; | 29 return false; |
| 27 | 30 |
| 28 memset(out_address, 0, sizeof(*out_address)); | 31 memset(out_address, 0, sizeof(*out_address)); |
| 29 | 32 |
| 30 if (in_address.size() != 17) | 33 if (in_address.size() != 17) |
| 31 return false; | 34 return false; |
| 32 | 35 |
| 33 std::string numbers_only; | 36 std::string numbers_only; |
| 34 for (int i = 0; i < 6; ++i) { | 37 for (int i = 0; i < 6; ++i) { |
| 35 numbers_only += in_address.substr(i * 3, 2); | 38 numbers_only += in_address.substr(i * 3, 2); |
| 36 } | 39 } |
| 37 | 40 |
| 38 std::vector<uint8> address_bytes; | 41 std::vector<uint8> address_bytes; |
| 39 if (base::HexStringToBytes(numbers_only, &address_bytes)) { | 42 if (base::HexStringToBytes(numbers_only, &address_bytes)) { |
| 40 if (address_bytes.size() == 6) { | 43 if (address_bytes.size() == 6) { |
| 41 for (int i = 0; i < 6; ++i) { | 44 for (int i = 0; i < 6; ++i) { |
| 42 out_address->b[5 - i] = address_bytes[i]; | 45 out_address->b[5 - i] = address_bytes[i]; |
| 43 } | 46 } |
| 44 return true; | 47 return true; |
| 45 } | 48 } |
| 46 } | 49 } |
| 47 | 50 |
| 48 return false; | 51 return false; |
| 49 } | 52 } |
| 53 #endif |
| 50 | 54 |
| 51 std::string CanonicalUuid(std::string uuid) { | 55 std::string CanonicalUuid(std::string uuid) { |
| 52 if (uuid.empty()) | 56 if (uuid.empty()) |
| 53 return ""; | 57 return ""; |
| 54 | 58 |
| 55 if (uuid.size() < 11 && uuid.find("0x") == 0) | 59 if (uuid.size() < 11 && uuid.find("0x") == 0) |
| 56 uuid = uuid.substr(2); | 60 uuid = uuid.substr(2); |
| 57 | 61 |
| 58 if (!(uuid.size() == 4 || uuid.size() == 8 || uuid.size() == 36)) | 62 if (!(uuid.size() == 4 || uuid.size() == 8 || uuid.size() == 36)) |
| 59 return ""; | 63 return ""; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 78 } else { | 82 } else { |
| 79 if (!IsHexDigit(uuid[i])) | 83 if (!IsHexDigit(uuid[i])) |
| 80 return ""; | 84 return ""; |
| 81 uuid_result[i] = tolower(uuid[i]); | 85 uuid_result[i] = tolower(uuid[i]); |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 return uuid_result; | 88 return uuid_result; |
| 85 } | 89 } |
| 86 | 90 |
| 87 } // namespace bluetooth_utils | 91 } // namespace bluetooth_utils |
| 88 } // namespace chromeos | 92 } // namespace device |
| OLD | NEW |