13cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati/****************************************************************************** 23cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * 33cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * Copyright (C) 2014 Google, Inc. 43cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * 53cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * Licensed under the Apache License, Version 2.0 (the "License"); 63cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * you may not use this file except in compliance with the License. 73cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * You may obtain a copy of the License at: 83cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * 93cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * http://www.apache.org/licenses/LICENSE-2.0 103cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * 113cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * Unless required by applicable law or agreed to in writing, software 123cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * distributed under the License is distributed on an "AS IS" BASIS, 133cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 143cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * See the License for the specific language governing permissions and 153cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * limitations under the License. 163cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati * 173cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati ******************************************************************************/ 183cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati 193cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati#pragma once 203cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati 215c26224e2cffbd79aa6b2a803eac6f6352129bd7Chris Manton#include <hardware/bluetooth.h> 2297c544445c8b0d9d67de3652d7249a151e199ad7Chris Manton#include <stdint.h> 235c26224e2cffbd79aa6b2a803eac6f6352129bd7Chris Manton#include <stdlib.h> 243cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati 2597c544445c8b0d9d67de3652d7249a151e199ad7Chris Manton#include "btcore/include/device_class.h" 2697c544445c8b0d9d67de3652d7249a151e199ad7Chris Manton 273252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// Copies an array of consecutive properties of |count| to a newly 283252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// allocated array. |properties| must not be NULL. 29911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_copy_array(const bt_property_t* properties, 30911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson size_t count); 313252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton 323252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// Copies |src| to |dest|. Returns the value of |dest|. 333252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// |src| and |dest| must not be NULL. 34911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_copy(bt_property_t* dest, const bt_property_t* src); 3597c544445c8b0d9d67de3652d7249a151e199ad7Chris Manton 363252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// Returns true if the value of the two properties |p1| and |p2| are equal. 373252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// |p1| and |p2| must not be NULL. 38911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_equals(const bt_property_t* p1, const bt_property_t* p2); 393252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton 403252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// Property resource allocations. Caller is expected to free |property| 413252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// using |property_free| or |property_free_array|. 423252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// Parameter must not be NULL. A copy of the parameter is made and 433252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// stored in the property. 44911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_new_addr(const bt_bdaddr_t* addr); 45911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_new_device_class(const bt_device_class_t* dc); 46911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_new_device_type(bt_device_type_t device_type); 47911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_new_discovery_timeout(const uint32_t timeout); 48911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_new_name(const char* name); 49911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_new_rssi(const int8_t rssi); 50911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_new_scan_mode(bt_scan_mode_t scan_mode); 51911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_property_t* property_new_uuids(const bt_uuid_t* uuid, size_t count); 523cf59ef3b216adffbe7e49297e6e3e8c56c4e9a0Sharvil Nanavati 533252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// Property resource frees both property and value. 54911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonvoid property_free(bt_property_t* property); 55911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonvoid property_free_array(bt_property_t* properties, size_t count); 563252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton 573252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// Value check convenience methods. The contents of the property are 583252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// checked for the respective validity and returns true, false otherwise. 593252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// |property| must not be NULL. 60911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_is_addr(const bt_property_t* property); 61911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_is_device_class(const bt_property_t* property); 62911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_is_device_type(const bt_property_t* property); 63911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_is_discovery_timeout(const bt_property_t* property); 64911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_is_name(const bt_property_t* property); 65911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_is_rssi(const bt_property_t* property); 66911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_is_scan_mode(const bt_property_t* property); 67911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbool property_is_uuids(const bt_property_t* property); 683252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton 693252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// Value conversion convenience methods. The contents of the property are 703252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton// properly typed and returned to the caller. |property| must not be NULL. 71911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonconst bt_bdaddr_t* property_as_addr(const bt_property_t* property); 72911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonconst bt_device_class_t* property_as_device_class( 73911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson const bt_property_t* property); 74911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_device_type_t property_as_device_type(const bt_property_t* property); 75911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonuint32_t property_as_discovery_timeout(const bt_property_t* property); 76911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonconst bt_bdname_t* property_as_name(const bt_property_t* property); 77911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonint8_t property_as_rssi(const bt_property_t* property); 78911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_scan_mode_t property_as_scan_mode(const bt_property_t* property); 79911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonconst bt_uuid_t* property_as_uuids(const bt_property_t* property, 80911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson size_t* count); 81