emulator: sync with upstream
[platform/upstream/bluez.git] / emulator / hciemu.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2012-2014  Intel Corporation. All rights reserved.
6  *
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <stdbool.h>
25 #include <stdint.h>
26
27 struct hciemu;
28
29 enum hciemu_type {
30         HCIEMU_TYPE_BREDRLE,
31         HCIEMU_TYPE_BREDR,
32         HCIEMU_TYPE_LE,
33         HCIEMU_TYPE_LEGACY,
34 };
35
36 enum hciemu_hook_type {
37         HCIEMU_HOOK_PRE_CMD,
38         HCIEMU_HOOK_POST_CMD,
39         HCIEMU_HOOK_PRE_EVT,
40         HCIEMU_HOOK_POST_EVT,
41 };
42
43 struct hciemu *hciemu_new(enum hciemu_type type);
44
45 struct hciemu *hciemu_ref(struct hciemu *hciemu);
46 void hciemu_unref(struct hciemu *hciemu);
47
48 struct bthost *hciemu_client_get_host(struct hciemu *hciemu);
49
50 const char *hciemu_get_address(struct hciemu *hciemu);
51 uint8_t *hciemu_get_features(struct hciemu *hciemu);
52
53 const uint8_t *hciemu_get_master_bdaddr(struct hciemu *hciemu);
54 const uint8_t *hciemu_get_client_bdaddr(struct hciemu *hciemu);
55
56 uint8_t hciemu_get_master_scan_enable(struct hciemu *hciemu);
57
58 uint8_t hciemu_get_master_le_scan_enable(struct hciemu *hciemu);
59
60 void hciemu_set_master_le_states(struct hciemu *hciemu,
61                                                 const uint8_t *le_states);
62
63 typedef void (*hciemu_command_func_t)(uint16_t opcode, const void *data,
64                                                 uint8_t len, void *user_data);
65
66 typedef bool (*hciemu_hook_func_t)(const void *data, uint16_t len,
67                                                         void *user_data);
68
69 bool hciemu_add_master_post_command_hook(struct hciemu *hciemu,
70                         hciemu_command_func_t function, void *user_data);
71
72 bool hciemu_clear_master_post_command_hooks(struct hciemu *hciemu);
73
74 int hciemu_add_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
75                                 uint16_t opcode, hciemu_hook_func_t function,
76                                 void *user_data);
77
78 bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type,
79                                                         uint16_t opcode);