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 #include <stddef.h>
24 
25 // Note: the string representation of a bdaddr is expected to have the format
26 // xx:xx:xx:xx:xx:xx
27 // where each 'x' is a hex digit. The API presented in this header will accept
28 // both uppercase and lowercase digits but will only ever produce lowercase
29 // digits.
30 
31 typedef char bdstr_t[sizeof("xx:xx:xx:xx:xx:xx")];
32 
33 // Returns true if |addr| is the empty address (00:00:00:00:00:00).
34 // |addr| may not be NULL.
35 bool bdaddr_is_empty(const bt_bdaddr_t* addr);
36 
37 // Returns true if |first| and |second| refer to the same address. Neither
38 // may be NULL.
39 bool bdaddr_equals(const bt_bdaddr_t* first, const bt_bdaddr_t* second);
40 
41 // Returns destination bdaddr |dest| after copying |src| to |dest|.
42 // |dest| and |src| must not be NULL.
43 bt_bdaddr_t* bdaddr_copy(bt_bdaddr_t* dest, const bt_bdaddr_t* src);
44 
45 // Makes a string representation of |addr| and places it into |string|. |size|
46 // refers to the size of |string|'s buffer and must be >= 18. On success, this
47 // function returns |string|, otherwise it returns NULL. Neither |addr| nor
48 // |string| may be NULL.
49 const char* bdaddr_to_string(const bt_bdaddr_t* addr, char* string,
50                              size_t size);
51 
52 // Returns true if |string| represents a Bluetooth address. |string| may not be
53 // NULL.
54 bool string_is_bdaddr(const char* string);
55 
56 // Converts |string| to bt_bdaddr_t and places it in |addr|. If |string| does
57 // not represent a Bluetooth address, |addr| is not modified and this function
58 // returns false. Otherwise, it returns true. Neither |string| nor |addr| may be
59 // NULL.
60 bool string_to_bdaddr(const char* string, bt_bdaddr_t* addr);
61