device: Set disconnect timer to zero for fast disconnection
[platform/upstream/bluez.git] / monitor / packet.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  *
4  *  BlueZ - Bluetooth protocol stack for Linux
5  *
6  *  Copyright (C) 2011-2014  Intel Corporation
7  *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
8  *
9  *
10  */
11
12 #include <stdint.h>
13 #include <stdbool.h>
14 #include <sys/time.h>
15 #include <sys/socket.h>
16
17 #define PACKET_FILTER_SHOW_INDEX        (1 << 0)
18 #define PACKET_FILTER_SHOW_DATE         (1 << 1)
19 #define PACKET_FILTER_SHOW_TIME         (1 << 2)
20 #define PACKET_FILTER_SHOW_TIME_OFFSET  (1 << 3)
21 #define PACKET_FILTER_SHOW_ACL_DATA     (1 << 4)
22 #define PACKET_FILTER_SHOW_SCO_DATA     (1 << 5)
23 #define PACKET_FILTER_SHOW_A2DP_STREAM  (1 << 6)
24 #define PACKET_FILTER_SHOW_MGMT_SOCKET  (1 << 7)
25 #define PACKET_FILTER_SHOW_ISO_DATA     (1 << 8)
26 #define TV_MSEC(_tv) (long long)((_tv).tv_sec * 1000 + (_tv).tv_usec / 1000)
27
28 struct packet_latency {
29         struct timeval total;
30         struct timeval min;
31         struct timeval max;
32         struct timeval med;
33 };
34
35 struct packet_frame {
36         struct timeval tv;
37         size_t num;
38         size_t len;
39 };
40
41 struct packet_conn_data {
42         uint16_t index;
43         uint8_t  src[6];
44         uint16_t handle;
45         uint16_t link;
46         uint8_t  type;
47         uint8_t  dst[6];
48         uint8_t  dst_type;
49         struct queue *tx_q;
50         struct queue *chan_q;
51         struct packet_latency tx_l;
52         void     *data;
53         void     (*destroy)(void *data);
54 };
55
56 struct packet_conn_data *packet_get_conn_data(uint16_t handle);
57 void packet_latency_add(struct packet_latency *latency, struct timeval *delta);
58
59 bool packet_has_filter(unsigned long filter);
60 void packet_set_filter(unsigned long filter);
61 void packet_add_filter(unsigned long filter);
62 void packet_del_filter(unsigned long filter);
63
64 void packet_set_priority(const char *priority);
65 void packet_select_index(uint16_t index);
66 void packet_set_fallback_manufacturer(uint16_t manufacturer);
67 void packet_set_msft_evt_prefix(const uint8_t *prefix, uint8_t len);
68
69 void packet_hexdump(const unsigned char *buf, uint16_t len);
70 void packet_print_error(const char *label, uint8_t error);
71 void packet_print_version(const char *label, uint8_t version,
72                                 const char *sublabel, uint16_t subversion);
73 void packet_print_company(const char *label, uint16_t company);
74 void packet_print_addr(const char *label, const void *data, uint8_t type);
75 void packet_print_handle(uint16_t handle);
76 void packet_print_rssi(const char *label, int8_t rssi);
77 void packet_print_ad(const void *data, uint8_t size);
78 void packet_print_features_lmp(const uint8_t *features, uint8_t page);
79 void packet_print_features_ll(const uint8_t *features);
80 void packet_print_features_msft(const uint8_t *features);
81 void packet_print_channel_map_lmp(const uint8_t *map);
82 void packet_print_channel_map_ll(const uint8_t *map);
83 void packet_print_io_capability(uint8_t capability);
84 void packet_print_io_authentication(uint8_t authentication);
85 void packet_print_codec_id(const char *label, uint8_t codec);
86
87 #define LTV_DEC(_type, _func) \
88 { \
89         .type = _type, \
90         .func = _func, \
91 }
92
93 struct packet_ltv_decoder {
94         uint8_t  type;
95         void (*func)(const uint8_t *data, uint8_t len);
96 };
97
98 void packet_print_ltv(const char *label, const uint8_t *data, uint8_t len,
99                         struct packet_ltv_decoder *decoder, size_t num);
100
101 void packet_control(struct timeval *tv, struct ucred *cred,
102                                         uint16_t index, uint16_t opcode,
103                                         const void *data, uint16_t size);
104 void packet_monitor(struct timeval *tv, struct ucred *cred,
105                                         uint16_t index, uint16_t opcode,
106                                         const void *data, uint16_t size);
107 void packet_simulator(struct timeval *tv, uint16_t frequency,
108                                         const void *data, uint16_t size);
109
110 void packet_new_index(struct timeval *tv, uint16_t index, const char *label,
111                                 uint8_t type, uint8_t bus, const char *name);
112 void packet_del_index(struct timeval *tv, uint16_t index, const char *label);
113 void packet_open_index(struct timeval *tv, uint16_t index, const char *label);
114 void packet_close_index(struct timeval *tv, uint16_t index, const char *label);
115 void packet_index_info(struct timeval *tv, uint16_t index, const char *label,
116                                                         uint16_t manufacturer);
117 void packet_vendor_diag(struct timeval *tv, uint16_t index,
118                                         uint16_t manufacturer,
119                                         const void *data, uint16_t size);
120 void packet_system_note(struct timeval *tv, struct ucred *cred,
121                                         uint16_t index, const void *message);
122 void packet_user_logging(struct timeval *tv, struct ucred *cred,
123                                         uint16_t index, uint8_t priority,
124                                         const char *ident, const void *data,
125                                         uint16_t size);
126
127 void packet_hci_command(struct timeval *tv, struct ucred *cred, uint16_t index,
128                                         const void *data, uint16_t size);
129 void packet_hci_event(struct timeval *tv, struct ucred *cred, uint16_t index,
130                                         const void *data, uint16_t size);
131 void packet_hci_acldata(struct timeval *tv, struct ucred *cred, uint16_t index,
132                                 bool in, const void *data, uint16_t size);
133 void packet_hci_scodata(struct timeval *tv, struct ucred *cred, uint16_t index,
134                                 bool in, const void *data, uint16_t size);
135 void packet_hci_isodata(struct timeval *tv, struct ucred *cred, uint16_t index,
136                                 bool in, const void *data, uint16_t size);
137
138 void packet_ctrl_open(struct timeval *tv, struct ucred *cred, uint16_t index,
139                                         const void *data, uint16_t size);
140 void packet_ctrl_close(struct timeval *tv, struct ucred *cred, uint16_t index,
141                                         const void *data, uint16_t size);
142 void packet_ctrl_command(struct timeval *tv, struct ucred *cred, uint16_t index,
143                                         const void *data, uint16_t size);
144 void packet_ctrl_event(struct timeval *tv, struct ucred *cred, uint16_t index,
145                                         const void *data, uint16_t size);
146
147 void packet_todo(void);
148
149 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
150 void print_le_set_adv_parameters_cmd(const void *data, uint8_t size);
151 void print_le_set_random_address_cmd(const void *data, uint8_t size);
152 void print_le_set_adv_data_cmd(const void *data, uint8_t size);
153 void print_le_set_scan_rsp_data_cmd(const void *data, uint8_t size);
154 void print_le_set_adv_enable_cmd(const void *data, uint8_t size);
155 #endif