// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef CORE_INTERNAL_INJECTED_BLUETOOTH_DEVICE_STORE_H_ #define CORE_INTERNAL_INJECTED_BLUETOOTH_DEVICE_STORE_H_ #include #include #include #include "connections/implementation/pcp.h" #include "internal/platform/bluetooth_adapter.h" #include "internal/platform/byte_array.h" #include "internal/platform/implementation/bluetooth_classic.h" #include "internal/platform/mac_address.h" namespace nearby { namespace connections { // Creates and stores BluetoothDevice objects which have been "injected" (i.e., // passed to Nearby Connections manually by the client instead of through the // normal discovery flow). class InjectedBluetoothDeviceStore { public: InjectedBluetoothDeviceStore(); ~InjectedBluetoothDeviceStore(); // Creates an injected BluetoothDevice given the provided parameters: // |remote_bluetooth_mac_address|: A 6-byte MAC address. // |endpoint_id|: A string of length 4. // |endpoint_info|: A non-empty ByteArray whose length is <=131 bytes. // |service_id_hash|: A ByteArray whose length is 3. // |pcp|: PCP value to be used for the connection to this device. // // If the provided parameters are malformed or of incorrect length, this // function returns an invalid BluetoothDevice. Clients should use // BluetoothDevice::IsValid() with the returned device to verify that the // parameters were successfully processed. // // Note that successfully-injected devices stay valid for the lifetime of the // InjectedBluetoothDeviceStore and are not cleared until this object is // deleted. BluetoothDevice CreateInjectedBluetoothDevice( const ByteArray& remote_bluetooth_mac_address, const std::string& endpoint_id, const ByteArray& endpoint_info, const ByteArray& service_id_hash, Pcp pcp); // Returns true if the provided MAC address(format as "A0:12:34:56:78:90") is // associated with an injected BluetoothDevice. bool IsInjectedDevice(MacAddress mac_address); private: // Devices created by this class. BluetoothDevice objects returned by // CreateInjectedBluetoothDevice() store pointers to underlying // api::BluetoothDevice objects, so this maintains these underlying devices // to ensure that they are not deleted before they are referenced. std::vector> devices_; }; } // namespace connections } // namespace nearby #endif // CORE_INTERNAL_INJECTED_BLUETOOTH_DEVICE_STORE_H_