ble_scan_parser_impl.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 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 SERVICES_DATA_DECODER_BLE_SCAN_PARSER_IMPL_H_
  5. #define SERVICES_DATA_DECODER_BLE_SCAN_PARSER_IMPL_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/containers/span.h"
  10. #include "device/bluetooth/public/mojom/uuid.mojom.h"
  11. #include "services/data_decoder/public/mojom/ble_scan_parser.mojom.h"
  12. namespace data_decoder {
  13. enum class UuidFormat {
  14. // The UUID is the third and fourth bytes of a UUID with this pattern:
  15. // 0000____-0000-1000-8000-00805F9B34FB
  16. kFormat16Bit,
  17. // The UUID is the first four bytes of a UUID with this pattern:
  18. // ________-0000-1000-8000-00805F9B34FB
  19. kFormat32Bit,
  20. // The UUID is a standard UUID
  21. kFormat128Bit,
  22. kFormatInvalid
  23. };
  24. class BleScanParserImpl : public mojom::BleScanParser {
  25. public:
  26. BleScanParserImpl();
  27. BleScanParserImpl(const BleScanParserImpl&) = delete;
  28. BleScanParserImpl& operator=(const BleScanParserImpl&) = delete;
  29. ~BleScanParserImpl() override;
  30. // mojom::BleScanParser:
  31. void Parse(const std::vector<uint8_t>& advertisement_data,
  32. ParseCallback callback) override;
  33. static mojom::ScanRecordPtr ParseBleScan(
  34. base::span<const uint8_t> advertisement_data);
  35. static std::string ParseUuid(base::span<const uint8_t> bytes,
  36. UuidFormat format);
  37. static bool ParseServiceUuids(
  38. base::span<const uint8_t> bytes,
  39. UuidFormat format,
  40. std::vector<device::BluetoothUUID>* service_uuids);
  41. };
  42. } // namespace data_decoder
  43. #endif // SERVICES_DATA_DECODER_BLE_SCAN_PARSER_IMPL_H_