1 /****************************************************************************** 2 * 3 * Copyright (C) 2014 Google, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #pragma once 20 21 #include <hardware/bluetooth.h> 22 #include <stdbool.h> 23 24 typedef struct uuid_string_t uuid_string_t; 25 26 // Creates uuid string structure to hold a well formed UUID 27 // string. Must release resources with |uuid_string_free|. 28 // Returns NULL if no memory. 29 uuid_string_t *uuid_string_new(void); 30 31 // Frees a uuid string structure created from |uuid_string_new|. 32 // |uuid_string| may be NULL. 33 void uuid_string_free(uuid_string_t *uuid_string); 34 35 // Returns a string pointer to the well formed UUID string 36 // entry. |uuid_string| must not be NULL. 37 const char *uuid_string_data(const uuid_string_t *uuid_string); 38 39 // Creates uuid structure from a well formed UUID string 40 // |uuid_string|. The caller takes ownership of the uuid 41 // structure and must release resources with |uuid_free|. 42 // |uuid_string| must not be NULL. 43 // 44 // Returns NULL if |uuid_string| is malformed or no memory. 45 // 46 // A well formed UUID string is structured like this: 47 // "00112233-4455-6677-8899-aabbccddeeff" 48 bt_uuid_t *uuid_new(const char *uuid_string); 49 50 // Frees a uuid structure created from |uuid_new| and friends. 51 // |uuid| may be NULL. 52 void uuid_free(bt_uuid_t *uuid); 53 54 // Returns true if the UUID is all zeros, false otherwise. 55 // |uuid| may not be NULL. 56 bool uuid_is_empty(const bt_uuid_t *uuid); 57 58 // Returns true if the two UUIDs are equal, false otherwise. 59 // |first| and |second| may not be NULL. 60 bool uuid_is_equal(const bt_uuid_t *first, const bt_uuid_t *second); 61 62 // Copies uuid |src| into |dest| and returns a pointer to |dest|. 63 // |src| and |dest| must not be NULL. 64 bt_uuid_t *uuid_copy(bt_uuid_t *dest, const bt_uuid_t *src); 65 66 // Converts contents of |uuid| to a well formed UUID string 67 // |uuid_string| using numbers and lower case letter. |uuid| 68 // and |uuid_string| must not be NULL. 69 void uuid_to_string(const bt_uuid_t *uuid, uuid_string_t *uuid_string); 70 71 // Converts contents of |uuid| to a short uuid if possible. Returns 72 // true if conversion is possible, false otherwise. 73 // |uuid|, |uuid16| and |uuid32| must not be NULL. 74 bool uuid_128_to_16(const bt_uuid_t *uuid, uint16_t *uuid16); 75 bool uuid_128_to_32(const bt_uuid_t *uuid, uint32_t *uuid32); 76