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