bluetooth_util.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2018 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. #ifndef CHROMECAST_DEVICE_BLUETOOTH_BLUETOOTH_UTIL_H_
  5. #define CHROMECAST_DEVICE_BLUETOOTH_BLUETOOTH_UTIL_H_
  6. #include <string>
  7. #include "chromecast/public/bluetooth/bluetooth_types.h"
  8. namespace chromecast {
  9. namespace bluetooth {
  10. namespace util {
  11. // https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
  12. // BASE_UUID 00000000-0000-1000-8000-00805F9B34FB
  13. extern const bluetooth_v2_shlib::Uuid kUuidBase;
  14. // Format |addr| into the canonical text representation of a 48 bit mac address
  15. // (1a:2b:3c:4e:5f:60). Hex digits are lower case.
  16. std::string AddrToString(const bluetooth_v2_shlib::Addr& addr);
  17. // Get the last byte of |addr| as a hex string. This is used for logging since
  18. // full address is PII.
  19. std::string AddrLastByteString(const bluetooth_v2_shlib::Addr& addr);
  20. // Parse |str| as the canonical text representation of a 48 bit mac
  21. // address (1a:2b:3c:4e:5f:60). Hex digits may be either upper or lower case.
  22. //
  23. // Returns true iff |str| is a valid mac address.
  24. bool ParseAddr(const std::string& str, bluetooth_v2_shlib::Addr* addr);
  25. // Format |uuid| as the canonical big endian text format (with lowercase hex
  26. // digits).
  27. // 123e4567-e89b-12d3-a456-426655440000
  28. std::string UuidToString(const bluetooth_v2_shlib::Uuid& uuid);
  29. // Parses UUIDs of the following formats:
  30. // Canonical big endian: 123e4567-e89b-12d3-a456-426655440000
  31. // Bluetooth SIG 16-bit UUID: FEA0
  32. // Big endian no dashes: 123e4567e89b12d3a456426655440000
  33. //
  34. // Hex digits may be either upper or lower case.
  35. // Returns true iff |str| is a UUID.
  36. bool ParseUuid(const std::string& str, bluetooth_v2_shlib::Uuid* uuid);
  37. // Return full UUID object corresponding to 16 bit uuid.
  38. bluetooth_v2_shlib::Uuid UuidFromInt16(uint16_t uuid);
  39. // Return full UUID object corresponding to 32 bit uuid.
  40. bluetooth_v2_shlib::Uuid UuidFromInt32(uint32_t uuid);
  41. } // namespace util
  42. } // namespace bluetooth
  43. } // namespace chromecast
  44. #endif // CHROMECAST_DEVICE_BLUETOOTH_BLUETOOTH_UTIL_H_