Disable IPSP feature
[platform/upstream/bluez.git] / emulator / btdev.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2011-2012  Intel Corporation
6  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
7  *
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public
11  *  License as published by the Free Software Foundation; either
12  *  version 2.1 of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24
25 #include <stdint.h>
26 #include <stdbool.h>
27
28 #define BTDEV_RESPONSE_DEFAULT          0
29 #define BTDEV_RESPONSE_COMMAND_STATUS   1
30 #define BTDEV_RESPONSE_COMMAND_COMPLETE 2
31
32 typedef struct btdev_callback * btdev_callback;
33
34 void btdev_command_response(btdev_callback callback, uint8_t response,
35                                 uint8_t status, const void *data, uint8_t len);
36
37 #define btdev_command_default(callback) \
38                 btdev_command_response(callback, \
39                         BTDEV_RESPONSE_DEFAULT, 0x00, NULL, 0);
40
41 #define btdev_command_status(callback, status) \
42                 btdev_command_response(callback, \
43                         BTDEV_RESPONSE_COMMAND_STATUS, status, NULL, 0);
44
45 #define btdev_command_complete(callback, data, len) \
46                  btdev_command_response(callback, \
47                         BTDEV_RESPONSE_COMMAND_COMPLETE, 0x00, data, len);
48
49
50 typedef void (*btdev_command_func) (uint16_t opcode,
51                                 const void *data, uint8_t len,
52                                 btdev_callback callback, void *user_data);
53
54 typedef void (*btdev_send_func) (const struct iovec *iov, int iovlen,
55                                                         void *user_data);
56
57 typedef bool (*btdev_hook_func) (const void *data, uint16_t len,
58                                                         void *user_data);
59
60 enum btdev_type {
61         BTDEV_TYPE_BREDRLE,
62         BTDEV_TYPE_BREDR,
63         BTDEV_TYPE_LE,
64         BTDEV_TYPE_AMP,
65 };
66
67 enum btdev_hook_type {
68         BTDEV_HOOK_PRE_CMD,
69         BTDEV_HOOK_POST_CMD,
70         BTDEV_HOOK_PRE_EVT,
71         BTDEV_HOOK_POST_EVT,
72 };
73
74 struct btdev;
75
76 struct btdev *btdev_create(enum btdev_type type, uint16_t id);
77 void btdev_destroy(struct btdev *btdev);
78
79 const uint8_t *btdev_get_bdaddr(struct btdev *btdev);
80 uint8_t *btdev_get_features(struct btdev *btdev);
81
82 void btdev_set_command_handler(struct btdev *btdev, btdev_command_func handler,
83                                                         void *user_data);
84
85 void btdev_set_send_handler(struct btdev *btdev, btdev_send_func handler,
86                                                         void *user_data);
87
88 void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len);
89
90 int btdev_add_hook(struct btdev *btdev, enum btdev_hook_type type,
91                                 uint16_t opcode, btdev_hook_func handler,
92                                 void *user_data);
93
94 bool btdev_del_hook(struct btdev *btdev, enum btdev_hook_type type,
95                                                         uint16_t opcode);