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