xref: /openbmc/linux/include/net/bluetooth/hci_core.h (revision ad3f7986)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds    BlueZ - Bluetooth protocol stack for Linux
32d0a0346SRon Shaffer    Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
40fe8c8d0SIulia Tanasescu    Copyright 2023 NXP
51da177e4SLinus Torvalds 
61da177e4SLinus Torvalds    Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds    This program is free software; you can redistribute it and/or modify
91da177e4SLinus Torvalds    it under the terms of the GNU General Public License version 2 as
101da177e4SLinus Torvalds    published by the Free Software Foundation;
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
131da177e4SLinus Torvalds    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
141da177e4SLinus Torvalds    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
151da177e4SLinus Torvalds    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
161da177e4SLinus Torvalds    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
171da177e4SLinus Torvalds    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
181da177e4SLinus Torvalds    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
191da177e4SLinus Torvalds    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
221da177e4SLinus Torvalds    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
231da177e4SLinus Torvalds    SOFTWARE IS DISCLAIMED.
241da177e4SLinus Torvalds */
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #ifndef __HCI_CORE_H
271da177e4SLinus Torvalds #define __HCI_CORE_H
281da177e4SLinus Torvalds 
29e5e1e7fdSMiao-chen Chou #include <linux/idr.h>
306d5d2ee6SHeiner Kallweit #include <linux/leds.h>
31b2d09103SIngo Molnar #include <linux/rculist.h>
32b2d09103SIngo Molnar 
331da177e4SLinus Torvalds #include <net/bluetooth/hci.h>
346a98e383SMarcel Holtmann #include <net/bluetooth/hci_sync.h>
35f49daa81SMarcel Holtmann #include <net/bluetooth/hci_sock.h>
369695ef87SAbhishek Pandit-Subedi #include <net/bluetooth/coredump.h>
371da177e4SLinus Torvalds 
385e59b791SLuiz Augusto von Dentz /* HCI priority */
395e59b791SLuiz Augusto von Dentz #define HCI_PRIO_MAX	7
405e59b791SLuiz Augusto von Dentz 
41103a2f32SItay Iellin /* HCI maximum id value */
42103a2f32SItay Iellin #define HCI_MAX_ID 10000
43103a2f32SItay Iellin 
441da177e4SLinus Torvalds /* HCI Core structures */
451da177e4SLinus Torvalds struct inquiry_data {
461da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
471da177e4SLinus Torvalds 	__u8		pscan_rep_mode;
481da177e4SLinus Torvalds 	__u8		pscan_period_mode;
491da177e4SLinus Torvalds 	__u8		pscan_mode;
501da177e4SLinus Torvalds 	__u8		dev_class[3];
511ebb9252SMarcel Holtmann 	__le16		clock_offset;
521da177e4SLinus Torvalds 	__s8		rssi;
5341a96212SMarcel Holtmann 	__u8		ssp_mode;
541da177e4SLinus Torvalds };
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds struct inquiry_entry {
57561aafbcSJohan Hedberg 	struct list_head	all;		/* inq_cache.all */
58561aafbcSJohan Hedberg 	struct list_head	list;		/* unknown or resolve */
59561aafbcSJohan Hedberg 	enum {
60561aafbcSJohan Hedberg 		NAME_NOT_KNOWN,
61561aafbcSJohan Hedberg 		NAME_NEEDED,
62561aafbcSJohan Hedberg 		NAME_PENDING,
63561aafbcSJohan Hedberg 		NAME_KNOWN,
64561aafbcSJohan Hedberg 	} name_state;
651da177e4SLinus Torvalds 	__u32			timestamp;
661da177e4SLinus Torvalds 	struct inquiry_data	data;
671da177e4SLinus Torvalds };
681da177e4SLinus Torvalds 
6930883512SJohan Hedberg struct discovery_state {
704aab14e5SAndre Guedes 	int			type;
71ff9ef578SJohan Hedberg 	enum {
72ff9ef578SJohan Hedberg 		DISCOVERY_STOPPED,
73ff9ef578SJohan Hedberg 		DISCOVERY_STARTING,
74343f935bSAndre Guedes 		DISCOVERY_FINDING,
7530dc78e1SJohan Hedberg 		DISCOVERY_RESOLVING,
76ff9ef578SJohan Hedberg 		DISCOVERY_STOPPING,
77ff9ef578SJohan Hedberg 	} state;
78561aafbcSJohan Hedberg 	struct list_head	all;	/* All devices found during inquiry */
79561aafbcSJohan Hedberg 	struct list_head	unknown;	/* Name state not known */
80561aafbcSJohan Hedberg 	struct list_head	resolve;	/* Name needs to be resolved */
811da177e4SLinus Torvalds 	__u32			timestamp;
82b9a6328fSJohan Hedberg 	bdaddr_t		last_adv_addr;
83b9a6328fSJohan Hedberg 	u8			last_adv_addr_type;
84ff5cd29fSJohan Hedberg 	s8			last_adv_rssi;
85c70a7e4cSMarcel Holtmann 	u32			last_adv_flags;
86db08722fSLuiz Augusto von Dentz 	u8			last_adv_data[HCI_MAX_EXT_AD_LENGTH];
87b9a6328fSJohan Hedberg 	u8			last_adv_data_len;
88da25cf6aSMarcel Holtmann 	bool			report_invalid_rssi;
8982f8b651SJakub Pawlowski 	bool			result_filtering;
9078b781caSJohan Hedberg 	bool			limited;
9137eab042SJakub Pawlowski 	s8			rssi;
9237eab042SJakub Pawlowski 	u16			uuid_count;
9337eab042SJakub Pawlowski 	u8			(*uuids)[16];
942d28cfe7SJakub Pawlowski 	unsigned long		scan_start;
952d28cfe7SJakub Pawlowski 	unsigned long		scan_duration;
96dbf6811aSArchie Pusaka 	unsigned long		name_resolve_timeout;
971da177e4SLinus Torvalds };
981da177e4SLinus Torvalds 
999952d90eSAbhishek Pandit-Subedi #define SUSPEND_NOTIFIER_TIMEOUT	msecs_to_jiffies(2000) /* 2 seconds */
1009952d90eSAbhishek Pandit-Subedi 
1019952d90eSAbhishek Pandit-Subedi enum suspend_tasks {
1024867bd00SAbhishek Pandit-Subedi 	SUSPEND_PAUSE_DISCOVERY,
1034867bd00SAbhishek Pandit-Subedi 	SUSPEND_UNPAUSE_DISCOVERY,
1044867bd00SAbhishek Pandit-Subedi 
1054867bd00SAbhishek Pandit-Subedi 	SUSPEND_PAUSE_ADVERTISING,
1064867bd00SAbhishek Pandit-Subedi 	SUSPEND_UNPAUSE_ADVERTISING,
1074867bd00SAbhishek Pandit-Subedi 
1084f40afc6SAbhishek Pandit-Subedi 	SUSPEND_SCAN_DISABLE,
1094f40afc6SAbhishek Pandit-Subedi 	SUSPEND_SCAN_ENABLE,
1104f40afc6SAbhishek Pandit-Subedi 	SUSPEND_DISCONNECTING,
1114f40afc6SAbhishek Pandit-Subedi 
1129952d90eSAbhishek Pandit-Subedi 	SUSPEND_POWERING_DOWN,
1139952d90eSAbhishek Pandit-Subedi 
1149952d90eSAbhishek Pandit-Subedi 	SUSPEND_PREPARE_NOTIFIER,
115bf6a4e30SHoward Chung 
116bf6a4e30SHoward Chung 	SUSPEND_SET_ADV_FILTER,
1179952d90eSAbhishek Pandit-Subedi 	__SUSPEND_NUM_TASKS
1189952d90eSAbhishek Pandit-Subedi };
1199952d90eSAbhishek Pandit-Subedi 
1209952d90eSAbhishek Pandit-Subedi enum suspended_state {
1219952d90eSAbhishek Pandit-Subedi 	BT_RUNNING = 0,
1224f40afc6SAbhishek Pandit-Subedi 	BT_SUSPEND_DISCONNECT,
1230d2c9825SAbhishek Pandit-Subedi 	BT_SUSPEND_CONFIGURE_WAKE,
1249952d90eSAbhishek Pandit-Subedi };
1259952d90eSAbhishek Pandit-Subedi 
1261da177e4SLinus Torvalds struct hci_conn_hash {
1271da177e4SLinus Torvalds 	struct list_head list;
1281da177e4SLinus Torvalds 	unsigned int     acl_num;
129bd1eb66bSAndrei Emeltchenko 	unsigned int     amp_num;
1301da177e4SLinus Torvalds 	unsigned int     sco_num;
13126afbd82SLuiz Augusto von Dentz 	unsigned int     iso_num;
132fcd89c09SVille Tervo 	unsigned int     le_num;
13339bc74caSArchie Pusaka 	unsigned int     le_num_peripheral;
1341da177e4SLinus Torvalds };
1351da177e4SLinus Torvalds 
136f0358568SJohan Hedberg struct bdaddr_list {
137f0358568SJohan Hedberg 	struct list_head list;
138f0358568SJohan Hedberg 	bdaddr_t bdaddr;
139b9ee0a78SMarcel Holtmann 	u8 bdaddr_type;
140f0358568SJohan Hedberg };
1412aeb9a1aSJohan Hedberg 
1428961987fSKiran K struct codec_list {
1438961987fSKiran K 	struct list_head list;
1448961987fSKiran K 	u8	id;
1458961987fSKiran K 	__u16	cid;
1468961987fSKiran K 	__u16	vid;
1478961987fSKiran K 	u8	transport;
1488961987fSKiran K 	u8	num_caps;
1498961987fSKiran K 	u32	len;
1508961987fSKiran K 	struct hci_codec_caps caps[];
1518961987fSKiran K };
1528961987fSKiran K 
153b950aa88SAnkit Navik struct bdaddr_list_with_irk {
154b950aa88SAnkit Navik 	struct list_head list;
155b950aa88SAnkit Navik 	bdaddr_t bdaddr;
156b950aa88SAnkit Navik 	u8 bdaddr_type;
157b950aa88SAnkit Navik 	u8 peer_irk[16];
158b950aa88SAnkit Navik 	u8 local_irk[16];
159b950aa88SAnkit Navik };
160b950aa88SAnkit Navik 
161e1cff700SLinus Torvalds /* Bitmask of connection flags */
162fe92ee64SLuiz Augusto von Dentz enum hci_conn_flags {
163e1cff700SLinus Torvalds 	HCI_CONN_FLAG_REMOTE_WAKEUP = 1,
164e1cff700SLinus Torvalds 	HCI_CONN_FLAG_DEVICE_PRIVACY = 2,
165fe92ee64SLuiz Augusto von Dentz };
166e1cff700SLinus Torvalds typedef u8 hci_conn_flags_t;
167fe92ee64SLuiz Augusto von Dentz 
1688baaa403SAbhishek Pandit-Subedi struct bdaddr_list_with_flags {
1698baaa403SAbhishek Pandit-Subedi 	struct list_head list;
1708baaa403SAbhishek Pandit-Subedi 	bdaddr_t bdaddr;
1718baaa403SAbhishek Pandit-Subedi 	u8 bdaddr_type;
172e1cff700SLinus Torvalds 	hci_conn_flags_t flags;
1738baaa403SAbhishek Pandit-Subedi };
1748baaa403SAbhishek Pandit-Subedi 
1752aeb9a1aSJohan Hedberg struct bt_uuid {
1762aeb9a1aSJohan Hedberg 	struct list_head list;
1772aeb9a1aSJohan Hedberg 	u8 uuid[16];
17883be8ecaSJohan Hedberg 	u8 size;
1791aff6f09SJohan Hedberg 	u8 svc_hint;
1802aeb9a1aSJohan Hedberg };
1812aeb9a1aSJohan Hedberg 
182600a8749SAlain Michaud struct blocked_key {
183600a8749SAlain Michaud 	struct list_head list;
184600a8749SAlain Michaud 	struct rcu_head rcu;
185600a8749SAlain Michaud 	u8 type;
186600a8749SAlain Michaud 	u8 val[16];
187600a8749SAlain Michaud };
188600a8749SAlain Michaud 
1897ee4ea36SMarcel Holtmann struct smp_csrk {
1907ee4ea36SMarcel Holtmann 	bdaddr_t bdaddr;
1917ee4ea36SMarcel Holtmann 	u8 bdaddr_type;
192865f1f43SXiao Yao 	u8 link_type;
1934cd3928aSJohan Hedberg 	u8 type;
1947ee4ea36SMarcel Holtmann 	u8 val[16];
1957ee4ea36SMarcel Holtmann };
1967ee4ea36SMarcel Holtmann 
197b899efafSVinicius Costa Gomes struct smp_ltk {
198b899efafSVinicius Costa Gomes 	struct list_head list;
199970d0f1bSJohan Hedberg 	struct rcu_head rcu;
200b899efafSVinicius Costa Gomes 	bdaddr_t bdaddr;
201b899efafSVinicius Costa Gomes 	u8 bdaddr_type;
202865f1f43SXiao Yao 	u8 link_type;
203b899efafSVinicius Costa Gomes 	u8 authenticated;
204b899efafSVinicius Costa Gomes 	u8 type;
205b899efafSVinicius Costa Gomes 	u8 enc_size;
206b899efafSVinicius Costa Gomes 	__le16 ediv;
207fe39c7b2SMarcel Holtmann 	__le64 rand;
208b899efafSVinicius Costa Gomes 	u8 val[16];
20903c515d7SMarcel Holtmann };
210b899efafSVinicius Costa Gomes 
211970c4e46SJohan Hedberg struct smp_irk {
212970c4e46SJohan Hedberg 	struct list_head list;
213adae20cbSJohan Hedberg 	struct rcu_head rcu;
214970c4e46SJohan Hedberg 	bdaddr_t rpa;
215970c4e46SJohan Hedberg 	bdaddr_t bdaddr;
216970c4e46SJohan Hedberg 	u8 addr_type;
217865f1f43SXiao Yao 	u8 link_type;
218970c4e46SJohan Hedberg 	u8 val[16];
219970c4e46SJohan Hedberg };
220970c4e46SJohan Hedberg 
22155ed8ca1SJohan Hedberg struct link_key {
22255ed8ca1SJohan Hedberg 	struct list_head list;
2230378b597SJohan Hedberg 	struct rcu_head rcu;
22455ed8ca1SJohan Hedberg 	bdaddr_t bdaddr;
225865f1f43SXiao Yao 	u8 bdaddr_type;
226865f1f43SXiao Yao 	u8 link_type;
22755ed8ca1SJohan Hedberg 	u8 type;
2289b3b4460SAndrei Emeltchenko 	u8 val[HCI_LINK_KEY_SIZE];
22955ed8ca1SJohan Hedberg 	u8 pin_len;
23055ed8ca1SJohan Hedberg };
23155ed8ca1SJohan Hedberg 
2322763eda6SSzymon Janc struct oob_data {
2332763eda6SSzymon Janc 	struct list_head list;
2342763eda6SSzymon Janc 	bdaddr_t bdaddr;
2356928a924SJohan Hedberg 	u8 bdaddr_type;
236f7697b16SMarcel Holtmann 	u8 present;
237519ca9d0SMarcel Holtmann 	u8 hash192[16];
23838da1703SJohan Hedberg 	u8 rand192[16];
239519ca9d0SMarcel Holtmann 	u8 hash256[16];
24038da1703SJohan Hedberg 	u8 rand256[16];
2412763eda6SSzymon Janc };
2422763eda6SSzymon Janc 
243203fea01SArman Uguray struct adv_info {
244d2609b34SFlorian Grandel 	struct list_head list;
24510279313SLuiz Augusto von Dentz 	bool	enabled;
246fffd38bcSFlorian Grandel 	bool	pending;
247eca0ae4aSLuiz Augusto von Dentz 	bool	periodic;
248b338d917SBrian Gix 	__u8	mesh;
249203fea01SArman Uguray 	__u8	instance;
250203fea01SArman Uguray 	__u32	flags;
251912098a6SArman Uguray 	__u16	timeout;
2525d900e46SFlorian Grandel 	__u16	remaining_time;
253d2609b34SFlorian Grandel 	__u16	duration;
254203fea01SArman Uguray 	__u16	adv_data_len;
255c9ed0a70SLuiz Augusto von Dentz 	__u8	adv_data[HCI_MAX_EXT_AD_LENGTH];
25634a718bcSLuiz Augusto von Dentz 	bool	adv_data_changed;
257203fea01SArman Uguray 	__u16	scan_rsp_len;
258c9ed0a70SLuiz Augusto von Dentz 	__u8	scan_rsp_data[HCI_MAX_EXT_AD_LENGTH];
25934a718bcSLuiz Augusto von Dentz 	bool	scan_rsp_changed;
260eca0ae4aSLuiz Augusto von Dentz 	__u16	per_adv_data_len;
261eca0ae4aSLuiz Augusto von Dentz 	__u8	per_adv_data[HCI_MAX_PER_AD_LENGTH];
262de181e88SJaganath Kanakkassery 	__s8	tx_power;
2639bf9f4b6SDaniel Winkler 	__u32   min_interval;
2649bf9f4b6SDaniel Winkler 	__u32   max_interval;
265a73c046aSJaganath Kanakkassery 	bdaddr_t	random_addr;
266a73c046aSJaganath Kanakkassery 	bool 		rpa_expired;
267a73c046aSJaganath Kanakkassery 	struct delayed_work	rpa_expired_cb;
268203fea01SArman Uguray };
269203fea01SArman Uguray 
270db25be66SFlorian Grandel #define HCI_MAX_ADV_INSTANCES		5
271d2609b34SFlorian Grandel #define HCI_DEFAULT_ADV_DURATION	2
272d2609b34SFlorian Grandel 
27312410572SDaniel Winkler #define HCI_ADV_TX_POWER_NO_PREFERENCE 0x7F
27412410572SDaniel Winkler 
27534a718bcSLuiz Augusto von Dentz #define DATA_CMP(_d1, _l1, _d2, _l2) \
27634a718bcSLuiz Augusto von Dentz 	(_l1 == _l2 ? memcmp(_d1, _d2, _l1) : _l1 - _l2)
27734a718bcSLuiz Augusto von Dentz 
27834a718bcSLuiz Augusto von Dentz #define ADV_DATA_CMP(_adv, _data, _len) \
27934a718bcSLuiz Augusto von Dentz 	DATA_CMP((_adv)->adv_data, (_adv)->adv_data_len, _data, _len)
28034a718bcSLuiz Augusto von Dentz 
28134a718bcSLuiz Augusto von Dentz #define SCAN_RSP_CMP(_adv, _data, _len) \
28234a718bcSLuiz Augusto von Dentz 	DATA_CMP((_adv)->scan_rsp_data, (_adv)->scan_rsp_len, _data, _len)
28334a718bcSLuiz Augusto von Dentz 
2843368aa35SManish Mandlik struct monitored_device {
2853368aa35SManish Mandlik 	struct list_head list;
2863368aa35SManish Mandlik 
2873368aa35SManish Mandlik 	bdaddr_t bdaddr;
2883368aa35SManish Mandlik 	__u8     addr_type;
2893368aa35SManish Mandlik 	__u16    handle;
2903368aa35SManish Mandlik 	bool     notified;
2913368aa35SManish Mandlik };
2923368aa35SManish Mandlik 
293e5e1e7fdSMiao-chen Chou struct adv_pattern {
294e5e1e7fdSMiao-chen Chou 	struct list_head list;
295e5e1e7fdSMiao-chen Chou 	__u8 ad_type;
296e5e1e7fdSMiao-chen Chou 	__u8 offset;
297e5e1e7fdSMiao-chen Chou 	__u8 length;
298db08722fSLuiz Augusto von Dentz 	__u8 value[HCI_MAX_EXT_AD_LENGTH];
299e5e1e7fdSMiao-chen Chou };
300e5e1e7fdSMiao-chen Chou 
301b4a221eaSArchie Pusaka struct adv_rssi_thresholds {
302b4a221eaSArchie Pusaka 	__s8 low_threshold;
303b4a221eaSArchie Pusaka 	__s8 high_threshold;
304b4a221eaSArchie Pusaka 	__u16 low_threshold_timeout;
305b4a221eaSArchie Pusaka 	__u16 high_threshold_timeout;
306b4a221eaSArchie Pusaka 	__u8 sampling_period;
307b4a221eaSArchie Pusaka };
308b4a221eaSArchie Pusaka 
309e5e1e7fdSMiao-chen Chou struct adv_monitor {
310e5e1e7fdSMiao-chen Chou 	struct list_head patterns;
311b4a221eaSArchie Pusaka 	struct adv_rssi_thresholds rssi;
312e5e1e7fdSMiao-chen Chou 	__u16		handle;
313a2a4dedfSArchie Pusaka 
314a2a4dedfSArchie Pusaka 	enum {
315a2a4dedfSArchie Pusaka 		ADV_MONITOR_STATE_NOT_REGISTERED,
316a2a4dedfSArchie Pusaka 		ADV_MONITOR_STATE_REGISTERED,
317a2a4dedfSArchie Pusaka 		ADV_MONITOR_STATE_OFFLOADED
318a2a4dedfSArchie Pusaka 	} state;
319e5e1e7fdSMiao-chen Chou };
320e5e1e7fdSMiao-chen Chou 
321e5e1e7fdSMiao-chen Chou #define HCI_MIN_ADV_MONITOR_HANDLE		1
322e5e1e7fdSMiao-chen Chou #define HCI_MAX_ADV_MONITOR_NUM_HANDLES		32
323e5e1e7fdSMiao-chen Chou #define HCI_MAX_ADV_MONITOR_NUM_PATTERNS	16
324a2a4dedfSArchie Pusaka #define HCI_ADV_MONITOR_EXT_NONE		1
325a2a4dedfSArchie Pusaka #define HCI_ADV_MONITOR_EXT_MSFT		2
326e5e1e7fdSMiao-chen Chou 
327490c5babSJohan Hedberg #define HCI_MAX_SHORT_NAME_LENGTH	10
328490c5babSJohan Hedberg 
329d5ebaa7cSSoenke Huster #define HCI_CONN_HANDLE_MAX		0x0eff
3309f78191cSLuiz Augusto von Dentz #define HCI_CONN_HANDLE_UNSET(_handle)	(_handle > HCI_CONN_HANDLE_MAX)
331d5ebaa7cSSoenke Huster 
332d5bb334aSMarcel Holtmann /* Min encryption key size to match with SMP */
333d5bb334aSMarcel Holtmann #define HCI_MIN_ENC_KEY_SIZE		7
334d5bb334aSMarcel Holtmann 
335d6bfd59cSJohan Hedberg /* Default LE RPA expiry time, 15 minutes */
336d6bfd59cSJohan Hedberg #define HCI_DEFAULT_RPA_TIMEOUT		(15 * 60)
337d6bfd59cSJohan Hedberg 
33831ad1691SAndrzej Kaczmarek /* Default min/max age of connection information (1s/3s) */
33931ad1691SAndrzej Kaczmarek #define DEFAULT_CONN_INFO_MIN_AGE	1000
34031ad1691SAndrzej Kaczmarek #define DEFAULT_CONN_INFO_MAX_AGE	3000
341302975cbSSpoorthi Ravishankar Koppad /* Default authenticated payload timeout 30s */
342302975cbSSpoorthi Ravishankar Koppad #define DEFAULT_AUTH_PAYLOAD_TIMEOUT   0x0bb8
34331ad1691SAndrzej Kaczmarek 
344903e4541SAndrei Emeltchenko struct amp_assoc {
345903e4541SAndrei Emeltchenko 	__u16	len;
346903e4541SAndrei Emeltchenko 	__u16	offset;
34793c284eeSAndrei Emeltchenko 	__u16	rem_len;
34893c284eeSAndrei Emeltchenko 	__u16	len_so_far;
349903e4541SAndrei Emeltchenko 	__u8	data[HCI_MAX_AMP_ASSOC_SIZE];
350903e4541SAndrei Emeltchenko };
351903e4541SAndrei Emeltchenko 
352d2c5d77fSJohan Hedberg #define HCI_MAX_PAGES	3
353cad718edSJohan Hedberg 
3541da177e4SLinus Torvalds struct hci_dev {
3551da177e4SLinus Torvalds 	struct list_head list;
35609fd0de5SGustavo F. Padovan 	struct mutex	lock;
3571da177e4SLinus Torvalds 
35884cb0143SZiyang Xuan 	struct ida	unset_handle_ida;
35984cb0143SZiyang Xuan 
360dcda1657SLuiz Augusto von Dentz 	const char	*name;
3611da177e4SLinus Torvalds 	unsigned long	flags;
3621da177e4SLinus Torvalds 	__u16		id;
363c13854ceSMarcel Holtmann 	__u8		bus;
364943da25dSMarcel Holtmann 	__u8		dev_type;
3651da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
366e30d3f5fSMarcel Holtmann 	bdaddr_t	setup_addr;
36724c457e2SMarcel Holtmann 	bdaddr_t	public_addr;
3687a4cd51dSMarcel Holtmann 	bdaddr_t	random_addr;
369d13eafceSMarcel Holtmann 	bdaddr_t	static_addr;
37056ed2cb8SJohan Hedberg 	__u8		adv_addr_type;
3711f6c6378SJohan Hedberg 	__u8		dev_name[HCI_MAX_NAME_LENGTH];
372490c5babSJohan Hedberg 	__u8		short_name[HCI_MAX_SHORT_NAME_LENGTH];
37380a1e1dbSJohan Hedberg 	__u8		eir[HCI_MAX_EIR_LENGTH];
374c4960ecfSMichał Narajowski 	__u16		appearance;
375a9de9248SMarcel Holtmann 	__u8		dev_class[3];
3761aff6f09SJohan Hedberg 	__u8		major_class;
3771aff6f09SJohan Hedberg 	__u8		minor_class;
378d2c5d77fSJohan Hedberg 	__u8		max_page;
379cad718edSJohan Hedberg 	__u8		features[HCI_MAX_PAGES][8];
38060e77321SJohan Hedberg 	__u8		le_features[8];
3813d4f9c00SArchie Pusaka 	__u8		le_accept_list_size;
382cfdb0c2dSAnkit Navik 	__u8		le_resolv_list_size;
3836b49bcb4SJaganath Kanakkassery 	__u8		le_num_of_adv_sets;
3849b008c04SJohan Hedberg 	__u8		le_states[8];
385b338d917SBrian Gix 	__u8		mesh_ad_types[16];
386b338d917SBrian Gix 	__u8		mesh_send_ref;
387a9de9248SMarcel Holtmann 	__u8		commands[64];
3881143e5a6SMarcel Holtmann 	__u8		hci_ver;
3891143e5a6SMarcel Holtmann 	__u16		hci_rev;
390d5859e22SJohan Hedberg 	__u8		lmp_ver;
3911143e5a6SMarcel Holtmann 	__u16		manufacturer;
3927d69230cSAndrei Emeltchenko 	__u16		lmp_subver;
3931da177e4SLinus Torvalds 	__u16		voice_setting;
394b4cb9fb2SMarcel Holtmann 	__u8		num_iac;
395e88422bcSLuiz Augusto von Dentz 	__u16		stored_max_keys;
396e88422bcSLuiz Augusto von Dentz 	__u16		stored_num_keys;
39717fa4b9dSJohan Hedberg 	__u8		io_capability;
39891c4e9b1SMarcel Holtmann 	__s8		inq_tx_power;
39900bce3fbSAlain Michaud 	__u8		err_data_reporting;
400f332ec66SJohan Hedberg 	__u16		page_scan_interval;
401f332ec66SJohan Hedberg 	__u16		page_scan_window;
402f332ec66SJohan Hedberg 	__u8		page_scan_type;
4033f959d46SMarcel Holtmann 	__u8		le_adv_channel_map;
404628531c9SGeorg Lukas 	__u16		le_adv_min_interval;
405628531c9SGeorg Lukas 	__u16		le_adv_max_interval;
406533553f8SMarcel Holtmann 	__u8		le_scan_type;
407bef64738SMarcel Holtmann 	__u16		le_scan_interval;
408bef64738SMarcel Holtmann 	__u16		le_scan_window;
40910873f99SAlain Michaud 	__u16		le_scan_int_suspend;
41010873f99SAlain Michaud 	__u16		le_scan_window_suspend;
41110873f99SAlain Michaud 	__u16		le_scan_int_discovery;
41210873f99SAlain Michaud 	__u16		le_scan_window_discovery;
41310873f99SAlain Michaud 	__u16		le_scan_int_adv_monitor;
41410873f99SAlain Michaud 	__u16		le_scan_window_adv_monitor;
41510873f99SAlain Michaud 	__u16		le_scan_int_connect;
41610873f99SAlain Michaud 	__u16		le_scan_window_connect;
4174e70c7e7SMarcel Holtmann 	__u16		le_conn_min_interval;
4184e70c7e7SMarcel Holtmann 	__u16		le_conn_max_interval;
41904fb7d90SMarcel Holtmann 	__u16		le_conn_latency;
42004fb7d90SMarcel Holtmann 	__u16		le_supv_timeout;
421a8e1bfaaSMarcel Holtmann 	__u16		le_def_tx_len;
422a8e1bfaaSMarcel Holtmann 	__u16		le_def_tx_time;
423a8e1bfaaSMarcel Holtmann 	__u16		le_max_tx_len;
424a8e1bfaaSMarcel Holtmann 	__u16		le_max_tx_time;
425a8e1bfaaSMarcel Holtmann 	__u16		le_max_rx_len;
426a8e1bfaaSMarcel Holtmann 	__u16		le_max_rx_time;
42730d65e08SMatias Karhumaa 	__u8		le_max_key_size;
42830d65e08SMatias Karhumaa 	__u8		le_min_key_size;
429b9a7a61eSLukasz Rymanowski 	__u16		discov_interleaved_timeout;
43031ad1691SAndrzej Kaczmarek 	__u16		conn_info_min_age;
43131ad1691SAndrzej Kaczmarek 	__u16		conn_info_max_age;
432302975cbSSpoorthi Ravishankar Koppad 	__u16		auth_payload_timeout;
43358a96fc3SMarcel Holtmann 	__u8		min_enc_key_size;
434a4790360SMarcel Holtmann 	__u8		max_enc_key_size;
435a4790360SMarcel Holtmann 	__u8		pairing_opts;
43606f5b778SMarcel Holtmann 	__u8		ssp_debug_mode;
437c7741d16SMarcel Holtmann 	__u8		hw_error_code;
43833f35721SJohan Hedberg 	__u32		clock;
439c4f1f408SHoward Chung 	__u16		advmon_allowlist_duration;
440c4f1f408SHoward Chung 	__u16		advmon_no_filter_duration;
44180af16a3SHoward Chung 	__u8		enable_advmon_interleave_scan;
442f332ec66SJohan Hedberg 
4432b9be137SMarcel Holtmann 	__u16		devid_source;
4442b9be137SMarcel Holtmann 	__u16		devid_vendor;
4452b9be137SMarcel Holtmann 	__u16		devid_product;
4462b9be137SMarcel Holtmann 	__u16		devid_version;
4471da177e4SLinus Torvalds 
44810873f99SAlain Michaud 	__u8		def_page_scan_type;
44910873f99SAlain Michaud 	__u16		def_page_scan_int;
45010873f99SAlain Michaud 	__u16		def_page_scan_window;
45110873f99SAlain Michaud 	__u8		def_inq_scan_type;
45210873f99SAlain Michaud 	__u16		def_inq_scan_int;
45310873f99SAlain Michaud 	__u16		def_inq_scan_window;
45410873f99SAlain Michaud 	__u16		def_br_lsto;
45510873f99SAlain Michaud 	__u16		def_page_timeout;
45610873f99SAlain Michaud 	__u16		def_multi_adv_rotation_duration;
45749b020c1SAlain Michaud 	__u16		def_le_autoconnect_timeout;
4587c395ea5SDaniel Winkler 	__s8		min_le_tx_power;
4597c395ea5SDaniel Winkler 	__s8		max_le_tx_power;
46010873f99SAlain Michaud 
4611da177e4SLinus Torvalds 	__u16		pkt_type;
4625b7f9909SMarcel Holtmann 	__u16		esco_type;
4631da177e4SLinus Torvalds 	__u16		link_policy;
4641da177e4SLinus Torvalds 	__u16		link_mode;
4651da177e4SLinus Torvalds 
46604837f64SMarcel Holtmann 	__u32		idle_timeout;
46704837f64SMarcel Holtmann 	__u16		sniff_min_interval;
46804837f64SMarcel Holtmann 	__u16		sniff_max_interval;
46904837f64SMarcel Holtmann 
470928abaa7SAndrei Emeltchenko 	__u8		amp_status;
471928abaa7SAndrei Emeltchenko 	__u32		amp_total_bw;
472928abaa7SAndrei Emeltchenko 	__u32		amp_max_bw;
473928abaa7SAndrei Emeltchenko 	__u32		amp_min_latency;
474928abaa7SAndrei Emeltchenko 	__u32		amp_max_pdu;
475928abaa7SAndrei Emeltchenko 	__u8		amp_type;
476928abaa7SAndrei Emeltchenko 	__u16		amp_pal_cap;
477928abaa7SAndrei Emeltchenko 	__u16		amp_assoc_size;
478928abaa7SAndrei Emeltchenko 	__u32		amp_max_flush_to;
479928abaa7SAndrei Emeltchenko 	__u32		amp_be_flush_to;
480928abaa7SAndrei Emeltchenko 
481903e4541SAndrei Emeltchenko 	struct amp_assoc	loc_assoc;
482903e4541SAndrei Emeltchenko 
4831e89cffbSAndrei Emeltchenko 	__u8		flow_ctl_mode;
4841e89cffbSAndrei Emeltchenko 
4859f61656aSJohan Hedberg 	unsigned int	auto_accept_delay;
4869f61656aSJohan Hedberg 
4871da177e4SLinus Torvalds 	unsigned long	quirks;
4881da177e4SLinus Torvalds 
4891da177e4SLinus Torvalds 	atomic_t	cmd_cnt;
4901da177e4SLinus Torvalds 	unsigned int	acl_cnt;
4911da177e4SLinus Torvalds 	unsigned int	sco_cnt;
4926ed58ec5SVille Tervo 	unsigned int	le_cnt;
49326afbd82SLuiz Augusto von Dentz 	unsigned int	iso_cnt;
4941da177e4SLinus Torvalds 
4951da177e4SLinus Torvalds 	unsigned int	acl_mtu;
4961da177e4SLinus Torvalds 	unsigned int	sco_mtu;
4976ed58ec5SVille Tervo 	unsigned int	le_mtu;
49826afbd82SLuiz Augusto von Dentz 	unsigned int	iso_mtu;
4991da177e4SLinus Torvalds 	unsigned int	acl_pkts;
5001da177e4SLinus Torvalds 	unsigned int	sco_pkts;
5016ed58ec5SVille Tervo 	unsigned int	le_pkts;
50226afbd82SLuiz Augusto von Dentz 	unsigned int	iso_pkts;
5031da177e4SLinus Torvalds 
504350ee4cfSAndrei Emeltchenko 	__u16		block_len;
505350ee4cfSAndrei Emeltchenko 	__u16		block_mtu;
506350ee4cfSAndrei Emeltchenko 	__u16		num_blocks;
507350ee4cfSAndrei Emeltchenko 	__u16		block_cnt;
508350ee4cfSAndrei Emeltchenko 
5091da177e4SLinus Torvalds 	unsigned long	acl_last_tx;
5101da177e4SLinus Torvalds 	unsigned long	sco_last_tx;
5116ed58ec5SVille Tervo 	unsigned long	le_last_tx;
5121da177e4SLinus Torvalds 
5136decb5b4SJaganath Kanakkassery 	__u8		le_tx_def_phys;
5146decb5b4SJaganath Kanakkassery 	__u8		le_rx_def_phys;
5156decb5b4SJaganath Kanakkassery 
516f48fd9c8SMarcel Holtmann 	struct workqueue_struct	*workqueue;
5176ead1bbcSJohan Hedberg 	struct workqueue_struct	*req_workqueue;
518f48fd9c8SMarcel Holtmann 
519ab81cbf9SJohan Hedberg 	struct work_struct	power_on;
5203243553fSJohan Hedberg 	struct delayed_work	power_off;
521c7741d16SMarcel Holtmann 	struct work_struct	error_reset;
5226a98e383SMarcel Holtmann 	struct work_struct	cmd_sync_work;
5236a98e383SMarcel Holtmann 	struct list_head	cmd_sync_work_list;
5246a98e383SMarcel Holtmann 	struct mutex		cmd_sync_work_lock;
5251857c199SZhengping Jiang 	struct mutex		unregister_lock;
526744451c1SBenjamin Berg 	struct work_struct	cmd_sync_cancel_work;
527b338d917SBrian Gix 	struct work_struct	reenable_adv_work;
528ab81cbf9SJohan Hedberg 
52916ab91abSJohan Hedberg 	__u16			discov_timeout;
53016ab91abSJohan Hedberg 	struct delayed_work	discov_off;
53116ab91abSJohan Hedberg 
5327d78525dSJohan Hedberg 	struct delayed_work	service_cache;
5337d78525dSJohan Hedberg 
53465cc2b49SMarcel Holtmann 	struct delayed_work	cmd_timer;
535de75cd0dSManish Mandlik 	struct delayed_work	ncmd_timer;
536b78752ccSMarcel Holtmann 
537b78752ccSMarcel Holtmann 	struct work_struct	rx_work;
538c347b765SGustavo F. Padovan 	struct work_struct	cmd_work;
5393eff45eaSGustavo F. Padovan 	struct work_struct	tx_work;
5401da177e4SLinus Torvalds 
5417c1fbed2SJohan Hedberg 	struct delayed_work	le_scan_disable;
5427c1fbed2SJohan Hedberg 	struct delayed_work	le_scan_restart;
5432e93e53bSJohan Hedberg 
5441da177e4SLinus Torvalds 	struct sk_buff_head	rx_q;
5451da177e4SLinus Torvalds 	struct sk_buff_head	raw_q;
5461da177e4SLinus Torvalds 	struct sk_buff_head	cmd_q;
5471da177e4SLinus Torvalds 
5481da177e4SLinus Torvalds 	struct sk_buff		*sent_cmd;
549dfe6d5c3SLuiz Augusto von Dentz 	struct sk_buff		*recv_event;
5501da177e4SLinus Torvalds 
551a6a67efdSThomas Gleixner 	struct mutex		req_lock;
5521da177e4SLinus Torvalds 	wait_queue_head_t	req_wait_q;
5531da177e4SLinus Torvalds 	__u32			req_status;
5541da177e4SLinus Torvalds 	__u32			req_result;
555f60cb305SJohan Hedberg 	struct sk_buff		*req_skb;
5562af7aa66SLuiz Augusto von Dentz 	struct sk_buff		*req_rsp;
557a5040efaSJohan Hedberg 
55870db83c4SJohan Hedberg 	void			*smp_data;
559ef8efe4bSJohan Hedberg 	void			*smp_bredr_data;
5602e58ef3eSJohan Hedberg 
56130883512SJohan Hedberg 	struct discovery_state	discovery;
5629952d90eSAbhishek Pandit-Subedi 
5634867bd00SAbhishek Pandit-Subedi 	int			discovery_old_state;
5644867bd00SAbhishek Pandit-Subedi 	bool			discovery_paused;
5654867bd00SAbhishek Pandit-Subedi 	int			advertising_old_state;
5664867bd00SAbhishek Pandit-Subedi 	bool			advertising_paused;
5674867bd00SAbhishek Pandit-Subedi 
5689952d90eSAbhishek Pandit-Subedi 	struct notifier_block	suspend_notifier;
5699952d90eSAbhishek Pandit-Subedi 	enum suspended_state	suspend_state_next;
5709952d90eSAbhishek Pandit-Subedi 	enum suspended_state	suspend_state;
5714f40afc6SAbhishek Pandit-Subedi 	bool			scanning_paused;
5724f40afc6SAbhishek Pandit-Subedi 	bool			suspended;
5732f20216cSAbhishek Pandit-Subedi 	u8			wake_reason;
5742f20216cSAbhishek Pandit-Subedi 	bdaddr_t		wake_addr;
5752f20216cSAbhishek Pandit-Subedi 	u8			wake_addr_type;
5769952d90eSAbhishek Pandit-Subedi 
5771da177e4SLinus Torvalds 	struct hci_conn_hash	conn_hash;
5785c136e90SAndre Guedes 
579b338d917SBrian Gix 	struct list_head	mesh_pending;
5805c136e90SAndre Guedes 	struct list_head	mgmt_pending;
5813d4f9c00SArchie Pusaka 	struct list_head	reject_list;
5823d4f9c00SArchie Pusaka 	struct list_head	accept_list;
5832aeb9a1aSJohan Hedberg 	struct list_head	uuids;
58455ed8ca1SJohan Hedberg 	struct list_head	link_keys;
585b899efafSVinicius Costa Gomes 	struct list_head	long_term_keys;
586970c4e46SJohan Hedberg 	struct list_head	identity_resolving_keys;
5872763eda6SSzymon Janc 	struct list_head	remote_oob_data;
5883d4f9c00SArchie Pusaka 	struct list_head	le_accept_list;
589cfdb0c2dSAnkit Navik 	struct list_head	le_resolv_list;
59015819a70SAndre Guedes 	struct list_head	le_conn_params;
59177a77a30SAndre Guedes 	struct list_head	pend_le_conns;
59266f8455aSJohan Hedberg 	struct list_head	pend_le_reports;
593600a8749SAlain Michaud 	struct list_head	blocked_keys;
5948961987fSKiran K 	struct list_head	local_codecs;
5952763eda6SSzymon Janc 
5961da177e4SLinus Torvalds 	struct hci_dev_stats	stat;
5971da177e4SLinus Torvalds 
5981da177e4SLinus Torvalds 	atomic_t		promisc;
5991da177e4SLinus Torvalds 
6005177a838SMarcel Holtmann 	const char		*hw_info;
6015177a838SMarcel Holtmann 	const char		*fw_info;
602ca325f69SMarcel Holtmann 	struct dentry		*debugfs;
603ca325f69SMarcel Holtmann 
6049695ef87SAbhishek Pandit-Subedi 	struct hci_devcoredump	dump;
6059695ef87SAbhishek Pandit-Subedi 
606a91f2e39SMarcel Holtmann 	struct device		dev;
6071da177e4SLinus Torvalds 
608611b30f7SMarcel Holtmann 	struct rfkill		*rfkill;
609611b30f7SMarcel Holtmann 
610eacb44dfSMarcel Holtmann 	DECLARE_BITMAP(dev_flags, __HCI_NUM_FLAGS);
611e1cff700SLinus Torvalds 	hci_conn_flags_t	conn_flags;
612d23264a8SAndre Guedes 
6138fa19098SJohan Hedberg 	__s8			adv_tx_power;
614c9ed0a70SLuiz Augusto von Dentz 	__u8			adv_data[HCI_MAX_EXT_AD_LENGTH];
6153f0f524bSJohan Hedberg 	__u8			adv_data_len;
616c9ed0a70SLuiz Augusto von Dentz 	__u8			scan_rsp_data[HCI_MAX_EXT_AD_LENGTH];
617f8e808bdSMarcel Holtmann 	__u8			scan_rsp_data_len;
618eca0ae4aSLuiz Augusto von Dentz 	__u8			per_adv_data[HCI_MAX_PER_AD_LENGTH];
619eca0ae4aSLuiz Augusto von Dentz 	__u8			per_adv_data_len;
6208fa19098SJohan Hedberg 
621d2609b34SFlorian Grandel 	struct list_head	adv_instances;
622d2609b34SFlorian Grandel 	unsigned int		adv_instance_cnt;
623d2609b34SFlorian Grandel 	__u8			cur_adv_instance;
6245d900e46SFlorian Grandel 	__u16			adv_instance_timeout;
6255d900e46SFlorian Grandel 	struct delayed_work	adv_instance_expire;
626203fea01SArman Uguray 
627e5e1e7fdSMiao-chen Chou 	struct idr		adv_monitors_idr;
628e5e1e7fdSMiao-chen Chou 	unsigned int		adv_monitors_cnt;
629e5e1e7fdSMiao-chen Chou 
630863efaf2SJohan Hedberg 	__u8			irk[16];
631d6bfd59cSJohan Hedberg 	__u32			rpa_timeout;
632d6bfd59cSJohan Hedberg 	struct delayed_work	rpa_expired;
6332b5224dcSMarcel Holtmann 	bdaddr_t		rpa;
634863efaf2SJohan Hedberg 
635b338d917SBrian Gix 	struct delayed_work	mesh_send_done;
636b338d917SBrian Gix 
637c4f1f408SHoward Chung 	enum {
638c4f1f408SHoward Chung 		INTERLEAVE_SCAN_NONE,
639c4f1f408SHoward Chung 		INTERLEAVE_SCAN_NO_FILTER,
640c4f1f408SHoward Chung 		INTERLEAVE_SCAN_ALLOWLIST
641c4f1f408SHoward Chung 	} interleave_scan_state;
642c4f1f408SHoward Chung 
643c4f1f408SHoward Chung 	struct delayed_work	interleave_scan;
644c4f1f408SHoward Chung 
6453368aa35SManish Mandlik 	struct list_head	monitored_devices;
6468d7f1677SManish Mandlik 	bool			advmon_pend_notify;
6473368aa35SManish Mandlik 
64853f863a6SMarcel Holtmann #if IS_ENABLED(CONFIG_BT_LEDS)
6496d5d2ee6SHeiner Kallweit 	struct led_trigger	*power_led;
65053f863a6SMarcel Holtmann #endif
6516d5d2ee6SHeiner Kallweit 
652145373cbSMiao-chen Chou #if IS_ENABLED(CONFIG_BT_MSFTEXT)
653145373cbSMiao-chen Chou 	__u16			msft_opcode;
654145373cbSMiao-chen Chou 	void			*msft_data;
655a61d6718SMarcel Holtmann 	bool			msft_curve_validity;
656145373cbSMiao-chen Chou #endif
657145373cbSMiao-chen Chou 
658f67743f9SMarcel Holtmann #if IS_ENABLED(CONFIG_BT_AOSPEXT)
659f67743f9SMarcel Holtmann 	bool			aosp_capable;
660749a6c59SJoseph Hwang 	bool			aosp_quality_report;
661f67743f9SMarcel Holtmann #endif
662f67743f9SMarcel Holtmann 
6631da177e4SLinus Torvalds 	int (*open)(struct hci_dev *hdev);
6641da177e4SLinus Torvalds 	int (*close)(struct hci_dev *hdev);
6651da177e4SLinus Torvalds 	int (*flush)(struct hci_dev *hdev);
666f41c70c4SMarcel Holtmann 	int (*setup)(struct hci_dev *hdev);
667a44fecbdSTedd Ho-Jeong An 	int (*shutdown)(struct hci_dev *hdev);
6687bd8f09fSMarcel Holtmann 	int (*send)(struct hci_dev *hdev, struct sk_buff *skb);
6691da177e4SLinus Torvalds 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
670c7741d16SMarcel Holtmann 	void (*hw_error)(struct hci_dev *hdev, u8 code);
67198a63aafSMarcel Holtmann 	int (*post_init)(struct hci_dev *hdev);
6724b4113d6SMarcel Holtmann 	int (*set_diag)(struct hci_dev *hdev, bool enable);
67324c457e2SMarcel Holtmann 	int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
674e2bef384SRajat Jain 	void (*cmd_timeout)(struct hci_dev *hdev);
675c9209b26SArchie Pusaka 	void (*reset)(struct hci_dev *hdev);
6764539ca67SLuiz Augusto von Dentz 	bool (*wakeup)(struct hci_dev *hdev);
677ae7d925bSJoseph Hwang 	int (*set_quality_report)(struct hci_dev *hdev, bool enable);
678248733e8SKiran K 	int (*get_data_path_id)(struct hci_dev *hdev, __u8 *data_path);
6799798fbdeSKiran K 	int (*get_codec_config_data)(struct hci_dev *hdev, __u8 type,
6809798fbdeSKiran K 				     struct bt_codec *codec, __u8 *vnd_len,
6819798fbdeSKiran K 				     __u8 **vnd_data);
6821da177e4SLinus Torvalds };
6831da177e4SLinus Torvalds 
68453502d69SAndrei Emeltchenko #define HCI_PHY_HANDLE(handle)	(handle & 0xff)
68553502d69SAndrei Emeltchenko 
68676b13996SManish Mandlik enum conn_reasons {
68776b13996SManish Mandlik 	CONN_REASON_PAIR_DEVICE,
68876b13996SManish Mandlik 	CONN_REASON_L2CAP_CHAN,
68976b13996SManish Mandlik 	CONN_REASON_SCO_CONNECT,
69026afbd82SLuiz Augusto von Dentz 	CONN_REASON_ISO_CONNECT,
69176b13996SManish Mandlik };
69276b13996SManish Mandlik 
6931da177e4SLinus Torvalds struct hci_conn {
6941da177e4SLinus Torvalds 	struct list_head list;
6951da177e4SLinus Torvalds 
6961da177e4SLinus Torvalds 	atomic_t	refcnt;
6971da177e4SLinus Torvalds 
6981da177e4SLinus Torvalds 	bdaddr_t	dst;
69929b7988aSAndre Guedes 	__u8		dst_type;
700662e8820SMarcel Holtmann 	bdaddr_t	src;
701e7c4096eSMarcel Holtmann 	__u8		src_type;
702cb1d68f7SJohan Hedberg 	bdaddr_t	init_addr;
703cb1d68f7SJohan Hedberg 	__u8		init_addr_type;
704cb1d68f7SJohan Hedberg 	bdaddr_t	resp_addr;
705cb1d68f7SJohan Hedberg 	__u8		resp_addr_type;
7067087c4f6SLuiz Augusto von Dentz 	__u8		adv_instance;
7071da177e4SLinus Torvalds 	__u16		handle;
708eca0ae4aSLuiz Augusto von Dentz 	__u16		sync_handle;
7091da177e4SLinus Torvalds 	__u16		state;
710ad3f7986SSungwoo Kim 	__u16		mtu;
71104837f64SMarcel Holtmann 	__u8		mode;
7121da177e4SLinus Torvalds 	__u8		type;
71340bef302SJohan Hedberg 	__u8		role;
714a0c808b3SJohan Hedberg 	bool		out;
7154c67bc74SMarcel Holtmann 	__u8		attempt;
7161da177e4SLinus Torvalds 	__u8		dev_class[3];
717cad718edSJohan Hedberg 	__u8		features[HCI_MAX_PAGES][8];
718a8746417SMarcel Holtmann 	__u16		pkt_type;
71904837f64SMarcel Holtmann 	__u16		link_policy;
72013d39315SWaldemar Rymarkiewicz 	__u8		key_type;
72140be492fSMarcel Holtmann 	__u8		auth_type;
7228c1b2355SMarcel Holtmann 	__u8		sec_level;
723765c2a96SJohan Hedberg 	__u8		pending_sec_level;
724980e1a53SJohan Hedberg 	__u8		pin_length;
725726b4ffcSVinicius Costa Gomes 	__u8		enc_key_size;
72617fa4b9dSJohan Hedberg 	__u8		io_capability;
72792a25256SJohan Hedberg 	__u32		passkey_notify;
72892a25256SJohan Hedberg 	__u8		passkey_entered;
729052b30b0SMarcel Holtmann 	__u16		disc_timeout;
73009ae260bSJohan Hedberg 	__u16		conn_timeout;
73110c62ddcSFrédéric Dalleau 	__u16		setting;
732302975cbSSpoorthi Ravishankar Koppad 	__u16		auth_payload_timeout;
7331e406eefSAndre Guedes 	__u16		le_conn_min_interval;
7341e406eefSAndre Guedes 	__u16		le_conn_max_interval;
735e04fde60SMarcel Holtmann 	__u16		le_conn_interval;
736e04fde60SMarcel Holtmann 	__u16		le_conn_latency;
737e04fde60SMarcel Holtmann 	__u16		le_supv_timeout;
738db08722fSLuiz Augusto von Dentz 	__u8		le_adv_data[HCI_MAX_EXT_AD_LENGTH];
739fd45ada9SAlfonso Acosta 	__u8		le_adv_data_len;
740eca0ae4aSLuiz Augusto von Dentz 	__u8		le_per_adv_data[HCI_MAX_PER_AD_LENGTH];
741eca0ae4aSLuiz Augusto von Dentz 	__u8		le_per_adv_data_len;
7421efd927dSLuiz Augusto von Dentz 	__u8		le_tx_phy;
7431efd927dSLuiz Augusto von Dentz 	__u8		le_rx_phy;
7445ae76a94SAndrzej Kaczmarek 	__s8		rssi;
7455a134faeSAndrzej Kaczmarek 	__s8		tx_power;
746d0455ed9SAndrzej Kaczmarek 	__s8		max_tx_power;
74726afbd82SLuiz Augusto von Dentz 	struct bt_iso_qos iso_qos;
74851a8efd7SJohan Hedberg 	unsigned long	flags;
7491da177e4SLinus Torvalds 
75076b13996SManish Mandlik 	enum conn_reasons conn_reason;
751a13f316eSLuiz Augusto von Dentz 	__u8		abort_reason;
75276b13996SManish Mandlik 
75333f35721SJohan Hedberg 	__u32		clock;
75433f35721SJohan Hedberg 	__u16		clock_accuracy;
75533f35721SJohan Hedberg 
756dd983808SAndrzej Kaczmarek 	unsigned long	conn_info_timestamp;
757dd983808SAndrzej Kaczmarek 
75803b555e1SJohan Hedberg 	__u8		remote_cap;
75903b555e1SJohan Hedberg 	__u8		remote_auth;
7603161ae1cSAndrei Emeltchenko 	__u8		remote_id;
76103b555e1SJohan Hedberg 
7621da177e4SLinus Torvalds 	unsigned int	sent;
7631da177e4SLinus Torvalds 
7641da177e4SLinus Torvalds 	struct sk_buff_head data_q;
7652c33c06aSGustavo F. Padovan 	struct list_head chan_list;
7661da177e4SLinus Torvalds 
76719c40e3bSGustavo F. Padovan 	struct delayed_work disc_work;
7687bc18d9dSJohan Hedberg 	struct delayed_work auto_accept_work;
769a74a84f6SJohan Hedberg 	struct delayed_work idle_work;
7709489eca4SJohan Hedberg 	struct delayed_work le_conn_timeout;
7711da177e4SLinus Torvalds 
772b219e3acSMarcel Holtmann 	struct device	dev;
77323b9ceb7SMarcel Holtmann 	struct dentry	*debugfs;
774b219e3acSMarcel Holtmann 
7751da177e4SLinus Torvalds 	struct hci_dev	*hdev;
7761da177e4SLinus Torvalds 	void		*l2cap_data;
7771da177e4SLinus Torvalds 	void		*sco_data;
77826afbd82SLuiz Augusto von Dentz 	void		*iso_data;
7799740e49dSAndrei Emeltchenko 	struct amp_mgr	*amp_mgr;
7801da177e4SLinus Torvalds 
78106149746SLuiz Augusto von Dentz 	struct list_head link_list;
78206149746SLuiz Augusto von Dentz 	struct hci_conn	*parent;
78306149746SLuiz Augusto von Dentz 	struct hci_link *link;
78406149746SLuiz Augusto von Dentz 
785b2af264aSKiran K 	struct bt_codec codec;
786e9a416b5SJohan Hedberg 
787e9a416b5SJohan Hedberg 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
788e9a416b5SJohan Hedberg 	void (*security_cfm_cb)	(struct hci_conn *conn, u8 status);
789e9a416b5SJohan Hedberg 	void (*disconn_cfm_cb)	(struct hci_conn *conn, u8 reason);
79026afbd82SLuiz Augusto von Dentz 
79126afbd82SLuiz Augusto von Dentz 	void (*cleanup)(struct hci_conn *conn);
7921da177e4SLinus Torvalds };
7931da177e4SLinus Torvalds 
79406149746SLuiz Augusto von Dentz struct hci_link {
79506149746SLuiz Augusto von Dentz 	struct list_head list;
79606149746SLuiz Augusto von Dentz 	struct hci_conn *conn;
79706149746SLuiz Augusto von Dentz };
79806149746SLuiz Augusto von Dentz 
79973d80debSLuiz Augusto von Dentz struct hci_chan {
80073d80debSLuiz Augusto von Dentz 	struct list_head list;
80142c4e53eSAndrei Emeltchenko 	__u16 handle;
80273d80debSLuiz Augusto von Dentz 	struct hci_conn *conn;
80373d80debSLuiz Augusto von Dentz 	struct sk_buff_head data_q;
80473d80debSLuiz Augusto von Dentz 	unsigned int	sent;
805168df8e5SMat Martineau 	__u8		state;
8065c4c8c95SArchie Pusaka 	bool		amp;
80773d80debSLuiz Augusto von Dentz };
80873d80debSLuiz Augusto von Dentz 
80915819a70SAndre Guedes struct hci_conn_params {
81015819a70SAndre Guedes 	struct list_head list;
81193450c75SJohan Hedberg 	struct list_head action;
81215819a70SAndre Guedes 
81315819a70SAndre Guedes 	bdaddr_t addr;
81415819a70SAndre Guedes 	u8 addr_type;
81515819a70SAndre Guedes 
81615819a70SAndre Guedes 	u16 conn_min_interval;
81715819a70SAndre Guedes 	u16 conn_max_interval;
818f044eb05SMarcel Holtmann 	u16 conn_latency;
819f044eb05SMarcel Holtmann 	u16 supervision_timeout;
8209fcb18efSAndre Guedes 
8219fcb18efSAndre Guedes 	enum {
8229fcb18efSAndre Guedes 		HCI_AUTO_CONN_DISABLED,
823a3451d27SJohan Hedberg 		HCI_AUTO_CONN_REPORT,
8244b9e7e75SMarcel Holtmann 		HCI_AUTO_CONN_DIRECT,
8259fcb18efSAndre Guedes 		HCI_AUTO_CONN_ALWAYS,
8269fcb18efSAndre Guedes 		HCI_AUTO_CONN_LINK_LOSS,
827158e9218SJakub Pawlowski 		HCI_AUTO_CONN_EXPLICIT,
8289fcb18efSAndre Guedes 	} auto_connect;
829f161dd41SJohan Hedberg 
830f161dd41SJohan Hedberg 	struct hci_conn *conn;
831158e9218SJakub Pawlowski 	bool explicit_connect;
832195ef75eSPauli Virtanen 	/* Accessed without hdev->lock: */
833e1cff700SLinus Torvalds 	hci_conn_flags_t flags;
834853b70b5SLuiz Augusto von Dentz 	u8  privacy_mode;
83515819a70SAndre Guedes };
83615819a70SAndre Guedes 
8371da177e4SLinus Torvalds extern struct list_head hci_dev_list;
8381da177e4SLinus Torvalds extern struct list_head hci_cb_list;
8391da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock;
840fba7ecf0SJohan Hedberg extern struct mutex hci_cb_list_lock;
8411da177e4SLinus Torvalds 
842eacb44dfSMarcel Holtmann #define hci_dev_set_flag(hdev, nr)             set_bit((nr), (hdev)->dev_flags)
843eacb44dfSMarcel Holtmann #define hci_dev_clear_flag(hdev, nr)           clear_bit((nr), (hdev)->dev_flags)
844eacb44dfSMarcel Holtmann #define hci_dev_change_flag(hdev, nr)          change_bit((nr), (hdev)->dev_flags)
845eacb44dfSMarcel Holtmann #define hci_dev_test_flag(hdev, nr)            test_bit((nr), (hdev)->dev_flags)
846eacb44dfSMarcel Holtmann #define hci_dev_test_and_set_flag(hdev, nr)    test_and_set_bit((nr), (hdev)->dev_flags)
847eacb44dfSMarcel Holtmann #define hci_dev_test_and_clear_flag(hdev, nr)  test_and_clear_bit((nr), (hdev)->dev_flags)
848eacb44dfSMarcel Holtmann #define hci_dev_test_and_change_flag(hdev, nr) test_and_change_bit((nr), (hdev)->dev_flags)
849d7a5a11dSMarcel Holtmann 
850eacb44dfSMarcel Holtmann #define hci_dev_clear_volatile_flags(hdev)			\
851eacb44dfSMarcel Holtmann 	do {							\
852eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LE_SCAN);		\
853eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LE_ADV);		\
8542eb71a3aSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);\
855eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ);	\
856ae7d925bSJoseph Hwang 		hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);	\
857eacb44dfSMarcel Holtmann 	} while (0)
858516018a9SMarcel Holtmann 
8594fc9857aSLuiz Augusto von Dentz #define hci_dev_le_state_simultaneous(hdev) \
8604fc9857aSLuiz Augusto von Dentz 	(test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && \
8614fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[4] & 0x08) &&	/* Central */ \
8624fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[4] & 0x40) &&	/* Peripheral */ \
8634fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[3] & 0x10))	/* Simultaneous */
8644fc9857aSLuiz Augusto von Dentz 
865686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */
866e74e58f8SJoe Perches int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
867e74e58f8SJoe Perches int l2cap_disconn_ind(struct hci_conn *hcon);
8689b4c3336SArron Wang void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
869686ebf28SUlisses Furquim 
870ff50e8afSArron Wang #if IS_ENABLED(CONFIG_BT_BREDR)
871e74e58f8SJoe Perches int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
8729b4c3336SArron Wang void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
873ff50e8afSArron Wang #else
874ff50e8afSArron Wang static inline int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
875ff50e8afSArron Wang 				  __u8 *flags)
876ff50e8afSArron Wang {
877ff50e8afSArron Wang 	return 0;
878ff50e8afSArron Wang }
879ff50e8afSArron Wang 
880ff50e8afSArron Wang static inline void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb)
881ff50e8afSArron Wang {
882ff50e8afSArron Wang }
883ff50e8afSArron Wang #endif
884686ebf28SUlisses Furquim 
885ccf74f23SLuiz Augusto von Dentz #if IS_ENABLED(CONFIG_BT_LE)
886ccf74f23SLuiz Augusto von Dentz int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
887ccf74f23SLuiz Augusto von Dentz void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
888ccf74f23SLuiz Augusto von Dentz #else
889ccf74f23SLuiz Augusto von Dentz static inline int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
890ccf74f23SLuiz Augusto von Dentz 				  __u8 *flags)
891ccf74f23SLuiz Augusto von Dentz {
892ccf74f23SLuiz Augusto von Dentz 	return 0;
893ccf74f23SLuiz Augusto von Dentz }
894ccf74f23SLuiz Augusto von Dentz static inline void iso_recv(struct hci_conn *hcon, struct sk_buff *skb,
895ccf74f23SLuiz Augusto von Dentz 			    u16 flags)
896ccf74f23SLuiz Augusto von Dentz {
897ccf74f23SLuiz Augusto von Dentz }
898ccf74f23SLuiz Augusto von Dentz #endif
899ccf74f23SLuiz Augusto von Dentz 
9001da177e4SLinus Torvalds /* ----- Inquiry cache ----- */
90170f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX   (HZ*30)   /* 30 seconds */
90270f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX   (HZ*60)   /* 60 seconds */
9031da177e4SLinus Torvalds 
90430883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev)
9051da177e4SLinus Torvalds {
906ff9ef578SJohan Hedberg 	hdev->discovery.state = DISCOVERY_STOPPED;
90730883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.all);
90830883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.unknown);
90930883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.resolve);
910da25cf6aSMarcel Holtmann 	hdev->discovery.report_invalid_rssi = true;
91137eab042SJakub Pawlowski 	hdev->discovery.rssi = HCI_RSSI_INVALID;
9121da177e4SLinus Torvalds }
9131da177e4SLinus Torvalds 
9140256325eSMarcel Holtmann static inline void hci_discovery_filter_clear(struct hci_dev *hdev)
9150256325eSMarcel Holtmann {
91682f8b651SJakub Pawlowski 	hdev->discovery.result_filtering = false;
917da25cf6aSMarcel Holtmann 	hdev->discovery.report_invalid_rssi = true;
9180256325eSMarcel Holtmann 	hdev->discovery.rssi = HCI_RSSI_INVALID;
9190256325eSMarcel Holtmann 	hdev->discovery.uuid_count = 0;
9200256325eSMarcel Holtmann 	kfree(hdev->discovery.uuids);
9210256325eSMarcel Holtmann 	hdev->discovery.uuids = NULL;
9222d28cfe7SJakub Pawlowski 	hdev->discovery.scan_start = 0;
9232d28cfe7SJakub Pawlowski 	hdev->discovery.scan_duration = 0;
9240256325eSMarcel Holtmann }
9250256325eSMarcel Holtmann 
92630dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev);
92730dc78e1SJohan Hedberg 
928ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state);
929ff9ef578SJohan Hedberg 
9301da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev)
9311da177e4SLinus Torvalds {
93230883512SJohan Hedberg 	return list_empty(&hdev->discovery.all);
9331da177e4SLinus Torvalds }
9341da177e4SLinus Torvalds 
9351da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev)
9361da177e4SLinus Torvalds {
93730883512SJohan Hedberg 	struct discovery_state *c = &hdev->discovery;
9381da177e4SLinus Torvalds 	return jiffies - c->timestamp;
9391da177e4SLinus Torvalds }
9401da177e4SLinus Torvalds 
9411da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e)
9421da177e4SLinus Torvalds {
9431da177e4SLinus Torvalds 	return jiffies - e->timestamp;
9441da177e4SLinus Torvalds }
9451da177e4SLinus Torvalds 
9465a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
9475a9d0a3fSWaldemar Rymarkiewicz 					       bdaddr_t *bdaddr);
948561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
949561aafbcSJohan Hedberg 						       bdaddr_t *bdaddr);
95030dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
95130dc78e1SJohan Hedberg 						       bdaddr_t *bdaddr,
95230dc78e1SJohan Hedberg 						       int state);
953a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
954a3d4e20aSJohan Hedberg 				      struct inquiry_entry *ie);
955af58925cSMarcel Holtmann u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
956af58925cSMarcel Holtmann 			     bool name_known);
9571f9b9a5dSAndre Guedes void hci_inquiry_cache_flush(struct hci_dev *hdev);
9581da177e4SLinus Torvalds 
9591da177e4SLinus Torvalds /* ----- HCI Connections ----- */
9601da177e4SLinus Torvalds enum {
9611da177e4SLinus Torvalds 	HCI_CONN_AUTH_PEND,
9621da177e4SLinus Torvalds 	HCI_CONN_ENCRYPT_PEND,
96304837f64SMarcel Holtmann 	HCI_CONN_RSWITCH_PEND,
96404837f64SMarcel Holtmann 	HCI_CONN_MODE_CHANGE_PEND,
965e73439d8SMarcel Holtmann 	HCI_CONN_SCO_SETUP_PEND,
966b644ba33SJohan Hedberg 	HCI_CONN_MGMT_CONNECTED,
96758a681efSJohan Hedberg 	HCI_CONN_SSP_ENABLED,
968eb9a8f3fSMarcel Holtmann 	HCI_CONN_SC_ENABLED,
969abf76badSMarcel Holtmann 	HCI_CONN_AES_CCM,
97058a681efSJohan Hedberg 	HCI_CONN_POWER_SAVE,
971af6a9c32SJohan Hedberg 	HCI_CONN_FLUSH_KEY,
9724dae2798SJohan Hedberg 	HCI_CONN_ENCRYPT,
9734dae2798SJohan Hedberg 	HCI_CONN_AUTH,
9744dae2798SJohan Hedberg 	HCI_CONN_SECURE,
9754dae2798SJohan Hedberg 	HCI_CONN_FIPS,
976fe59a05fSJohan Hedberg 	HCI_CONN_STK_ENCRYPT,
977977f8fceSJohan Hedberg 	HCI_CONN_AUTH_INITIATOR,
978f94b665dSJohan Hedberg 	HCI_CONN_DROP,
979b62e7220SLuiz Augusto von Dentz 	HCI_CONN_CANCEL,
98089cbb063SAlfonso Acosta 	HCI_CONN_PARAM_REMOVAL_PEND,
981fe8bc5acSJohan Hedberg 	HCI_CONN_NEW_LINK_KEY,
982158e9218SJakub Pawlowski 	HCI_CONN_SCANNING,
983160b9251SSzymon Janc 	HCI_CONN_AUTH_FAILURE,
984eca0ae4aSLuiz Augusto von Dentz 	HCI_CONN_PER_ADV,
985a0bfde16SIulia Tanasescu 	HCI_CONN_BIG_CREATED,
9867f74563eSPauli Virtanen 	HCI_CONN_CREATE_CIS,
987f777d882SIulia Tanasescu 	HCI_CONN_BIG_SYNC,
988f777d882SIulia Tanasescu 	HCI_CONN_BIG_SYNC_FAILED,
989fbdc4bc4SIulia Tanasescu 	HCI_CONN_PA_SYNC,
990fbdc4bc4SIulia Tanasescu 	HCI_CONN_PA_SYNC_FAILED,
9911da177e4SLinus Torvalds };
9921da177e4SLinus Torvalds 
993aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
994aa64a8b5SJohan Hedberg {
995aa64a8b5SJohan Hedberg 	struct hci_dev *hdev = conn->hdev;
996d7a5a11dSMarcel Holtmann 	return hci_dev_test_flag(hdev, HCI_SSP_ENABLED) &&
997c3c7ea65SGustavo Padovan 	       test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
998aa64a8b5SJohan Hedberg }
999aa64a8b5SJohan Hedberg 
1000eb9a8f3fSMarcel Holtmann static inline bool hci_conn_sc_enabled(struct hci_conn *conn)
1001eb9a8f3fSMarcel Holtmann {
1002eb9a8f3fSMarcel Holtmann 	struct hci_dev *hdev = conn->hdev;
1003d7a5a11dSMarcel Holtmann 	return hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
1004eb9a8f3fSMarcel Holtmann 	       test_bit(HCI_CONN_SC_ENABLED, &conn->flags);
1005eb9a8f3fSMarcel Holtmann }
1006eb9a8f3fSMarcel Holtmann 
10071da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
10081da177e4SLinus Torvalds {
10091da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
1010d4b20f0bSLuiz Augusto von Dentz 	list_add_tail_rcu(&c->list, &h->list);
1011fcd89c09SVille Tervo 	switch (c->type) {
1012fcd89c09SVille Tervo 	case ACL_LINK:
10131da177e4SLinus Torvalds 		h->acl_num++;
1014fcd89c09SVille Tervo 		break;
1015bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1016bd1eb66bSAndrei Emeltchenko 		h->amp_num++;
1017bd1eb66bSAndrei Emeltchenko 		break;
1018fcd89c09SVille Tervo 	case LE_LINK:
1019fcd89c09SVille Tervo 		h->le_num++;
1020f8218dc6SJohan Hedberg 		if (c->role == HCI_ROLE_SLAVE)
102139bc74caSArchie Pusaka 			h->le_num_peripheral++;
1022fcd89c09SVille Tervo 		break;
1023fcd89c09SVille Tervo 	case SCO_LINK:
1024fcd89c09SVille Tervo 	case ESCO_LINK:
10251da177e4SLinus Torvalds 		h->sco_num++;
1026fcd89c09SVille Tervo 		break;
102726afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
102826afbd82SLuiz Augusto von Dentz 		h->iso_num++;
102926afbd82SLuiz Augusto von Dentz 		break;
1030fcd89c09SVille Tervo 	}
10311da177e4SLinus Torvalds }
10321da177e4SLinus Torvalds 
10331da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
10341da177e4SLinus Torvalds {
10351da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
1036bf4c6325SGustavo F. Padovan 
1037bf4c6325SGustavo F. Padovan 	list_del_rcu(&c->list);
1038bf4c6325SGustavo F. Padovan 	synchronize_rcu();
1039bf4c6325SGustavo F. Padovan 
1040fcd89c09SVille Tervo 	switch (c->type) {
1041fcd89c09SVille Tervo 	case ACL_LINK:
10421da177e4SLinus Torvalds 		h->acl_num--;
1043fcd89c09SVille Tervo 		break;
1044bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1045bd1eb66bSAndrei Emeltchenko 		h->amp_num--;
1046bd1eb66bSAndrei Emeltchenko 		break;
1047fcd89c09SVille Tervo 	case LE_LINK:
1048fcd89c09SVille Tervo 		h->le_num--;
1049f8218dc6SJohan Hedberg 		if (c->role == HCI_ROLE_SLAVE)
105039bc74caSArchie Pusaka 			h->le_num_peripheral--;
1051fcd89c09SVille Tervo 		break;
1052fcd89c09SVille Tervo 	case SCO_LINK:
1053fcd89c09SVille Tervo 	case ESCO_LINK:
10541da177e4SLinus Torvalds 		h->sco_num--;
1055fcd89c09SVille Tervo 		break;
105626afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
105726afbd82SLuiz Augusto von Dentz 		h->iso_num--;
105826afbd82SLuiz Augusto von Dentz 		break;
1059fcd89c09SVille Tervo 	}
10601da177e4SLinus Torvalds }
10611da177e4SLinus Torvalds 
106252087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
106352087a79SLuiz Augusto von Dentz {
106452087a79SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
106552087a79SLuiz Augusto von Dentz 	switch (type) {
106652087a79SLuiz Augusto von Dentz 	case ACL_LINK:
106752087a79SLuiz Augusto von Dentz 		return h->acl_num;
1068bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1069bd1eb66bSAndrei Emeltchenko 		return h->amp_num;
107052087a79SLuiz Augusto von Dentz 	case LE_LINK:
107152087a79SLuiz Augusto von Dentz 		return h->le_num;
107252087a79SLuiz Augusto von Dentz 	case SCO_LINK:
107352087a79SLuiz Augusto von Dentz 	case ESCO_LINK:
107452087a79SLuiz Augusto von Dentz 		return h->sco_num;
107526afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
107626afbd82SLuiz Augusto von Dentz 		return h->iso_num;
107752087a79SLuiz Augusto von Dentz 	default:
107852087a79SLuiz Augusto von Dentz 		return 0;
107952087a79SLuiz Augusto von Dentz 	}
108052087a79SLuiz Augusto von Dentz }
108152087a79SLuiz Augusto von Dentz 
1082f4f07505SJohan Hedberg static inline unsigned int hci_conn_count(struct hci_dev *hdev)
1083f4f07505SJohan Hedberg {
1084f4f07505SJohan Hedberg 	struct hci_conn_hash *c = &hdev->conn_hash;
1085f4f07505SJohan Hedberg 
108626afbd82SLuiz Augusto von Dentz 	return c->acl_num + c->amp_num + c->sco_num + c->le_num + c->iso_num;
1087f4f07505SJohan Hedberg }
1088f4f07505SJohan Hedberg 
1089845472e8SMarcel Holtmann static inline __u8 hci_conn_lookup_type(struct hci_dev *hdev, __u16 handle)
1090845472e8SMarcel Holtmann {
1091845472e8SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
1092845472e8SMarcel Holtmann 	struct hci_conn *c;
1093845472e8SMarcel Holtmann 	__u8 type = INVALID_LINK;
1094845472e8SMarcel Holtmann 
1095845472e8SMarcel Holtmann 	rcu_read_lock();
1096845472e8SMarcel Holtmann 
1097845472e8SMarcel Holtmann 	list_for_each_entry_rcu(c, &h->list, list) {
1098845472e8SMarcel Holtmann 		if (c->handle == handle) {
1099845472e8SMarcel Holtmann 			type = c->type;
1100845472e8SMarcel Holtmann 			break;
1101845472e8SMarcel Holtmann 		}
1102845472e8SMarcel Holtmann 	}
1103845472e8SMarcel Holtmann 
1104845472e8SMarcel Holtmann 	rcu_read_unlock();
1105845472e8SMarcel Holtmann 
1106845472e8SMarcel Holtmann 	return type;
1107845472e8SMarcel Holtmann }
1108845472e8SMarcel Holtmann 
1109eca0ae4aSLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_bis(struct hci_dev *hdev,
11106a42e9bfSIulia Tanasescu 							bdaddr_t *ba, __u8 bis)
1111eca0ae4aSLuiz Augusto von Dentz {
1112eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1113eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn  *c;
1114eca0ae4aSLuiz Augusto von Dentz 
1115eca0ae4aSLuiz Augusto von Dentz 	rcu_read_lock();
1116eca0ae4aSLuiz Augusto von Dentz 
1117eca0ae4aSLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1118eca0ae4aSLuiz Augusto von Dentz 		if (bacmp(&c->dst, ba) || c->type != ISO_LINK)
1119eca0ae4aSLuiz Augusto von Dentz 			continue;
1120eca0ae4aSLuiz Augusto von Dentz 
11216a42e9bfSIulia Tanasescu 		if (c->iso_qos.bcast.bis == bis) {
1122eca0ae4aSLuiz Augusto von Dentz 			rcu_read_unlock();
1123eca0ae4aSLuiz Augusto von Dentz 			return c;
1124eca0ae4aSLuiz Augusto von Dentz 		}
1125eca0ae4aSLuiz Augusto von Dentz 	}
1126eca0ae4aSLuiz Augusto von Dentz 	rcu_read_unlock();
1127eca0ae4aSLuiz Augusto von Dentz 
1128eca0ae4aSLuiz Augusto von Dentz 	return NULL;
1129eca0ae4aSLuiz Augusto von Dentz }
1130eca0ae4aSLuiz Augusto von Dentz 
1131a0bfde16SIulia Tanasescu static inline struct hci_conn *
1132a0bfde16SIulia Tanasescu hci_conn_hash_lookup_per_adv_bis(struct hci_dev *hdev,
1133a0bfde16SIulia Tanasescu 				 bdaddr_t *ba,
1134a0bfde16SIulia Tanasescu 				 __u8 big, __u8 bis)
1135a0bfde16SIulia Tanasescu {
1136a0bfde16SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1137a0bfde16SIulia Tanasescu 	struct hci_conn  *c;
1138a0bfde16SIulia Tanasescu 
1139a0bfde16SIulia Tanasescu 	rcu_read_lock();
1140a0bfde16SIulia Tanasescu 
1141a0bfde16SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1142a0bfde16SIulia Tanasescu 		if (bacmp(&c->dst, ba) || c->type != ISO_LINK ||
1143a0bfde16SIulia Tanasescu 			!test_bit(HCI_CONN_PER_ADV, &c->flags))
1144a0bfde16SIulia Tanasescu 			continue;
1145a0bfde16SIulia Tanasescu 
1146a0bfde16SIulia Tanasescu 		if (c->iso_qos.bcast.big == big &&
1147a0bfde16SIulia Tanasescu 		    c->iso_qos.bcast.bis == bis) {
1148a0bfde16SIulia Tanasescu 			rcu_read_unlock();
1149a0bfde16SIulia Tanasescu 			return c;
1150a0bfde16SIulia Tanasescu 		}
1151a0bfde16SIulia Tanasescu 	}
1152a0bfde16SIulia Tanasescu 	rcu_read_unlock();
1153a0bfde16SIulia Tanasescu 
1154a0bfde16SIulia Tanasescu 	return NULL;
1155a0bfde16SIulia Tanasescu }
1156a0bfde16SIulia Tanasescu 
11571da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
11581da177e4SLinus Torvalds 								__u16 handle)
11591da177e4SLinus Torvalds {
11601da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
11611da177e4SLinus Torvalds 	struct hci_conn  *c;
11621da177e4SLinus Torvalds 
1163bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1164bf4c6325SGustavo F. Padovan 
1165bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1166bf4c6325SGustavo F. Padovan 		if (c->handle == handle) {
1167bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
11681da177e4SLinus Torvalds 			return c;
11691da177e4SLinus Torvalds 		}
1170bf4c6325SGustavo F. Padovan 	}
1171bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1172bf4c6325SGustavo F. Padovan 
11731da177e4SLinus Torvalds 	return NULL;
11741da177e4SLinus Torvalds }
11751da177e4SLinus Torvalds 
11761da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
11771da177e4SLinus Torvalds 							__u8 type, bdaddr_t *ba)
11781da177e4SLinus Torvalds {
11791da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
11801da177e4SLinus Torvalds 	struct hci_conn  *c;
11811da177e4SLinus Torvalds 
1182bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1183bf4c6325SGustavo F. Padovan 
1184bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1185bf4c6325SGustavo F. Padovan 		if (c->type == type && !bacmp(&c->dst, ba)) {
1186bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
11871da177e4SLinus Torvalds 			return c;
11881da177e4SLinus Torvalds 		}
1189bf4c6325SGustavo F. Padovan 	}
1190bf4c6325SGustavo F. Padovan 
1191bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1192bf4c6325SGustavo F. Padovan 
11931da177e4SLinus Torvalds 	return NULL;
11941da177e4SLinus Torvalds }
11951da177e4SLinus Torvalds 
11961b51c7b6SJohan Hedberg static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev,
11971b51c7b6SJohan Hedberg 						       bdaddr_t *ba,
11981b51c7b6SJohan Hedberg 						       __u8 ba_type)
11991b51c7b6SJohan Hedberg {
12001b51c7b6SJohan Hedberg 	struct hci_conn_hash *h = &hdev->conn_hash;
12011b51c7b6SJohan Hedberg 	struct hci_conn  *c;
12021b51c7b6SJohan Hedberg 
12031b51c7b6SJohan Hedberg 	rcu_read_lock();
12041b51c7b6SJohan Hedberg 
12051b51c7b6SJohan Hedberg 	list_for_each_entry_rcu(c, &h->list, list) {
12061b51c7b6SJohan Hedberg 		if (c->type != LE_LINK)
12071b51c7b6SJohan Hedberg 		       continue;
12081b51c7b6SJohan Hedberg 
12091b51c7b6SJohan Hedberg 		if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) {
12101b51c7b6SJohan Hedberg 			rcu_read_unlock();
12111b51c7b6SJohan Hedberg 			return c;
12121b51c7b6SJohan Hedberg 		}
12131b51c7b6SJohan Hedberg 	}
12141b51c7b6SJohan Hedberg 
12151b51c7b6SJohan Hedberg 	rcu_read_unlock();
12161b51c7b6SJohan Hedberg 
12171b51c7b6SJohan Hedberg 	return NULL;
12181b51c7b6SJohan Hedberg }
12191b51c7b6SJohan Hedberg 
122026afbd82SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
122126afbd82SLuiz Augusto von Dentz 							bdaddr_t *ba,
1222c14516faSLuiz Augusto von Dentz 							__u8 ba_type,
1223c14516faSLuiz Augusto von Dentz 							__u8 cig,
1224c14516faSLuiz Augusto von Dentz 							__u8 id)
122526afbd82SLuiz Augusto von Dentz {
122626afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
122726afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
122826afbd82SLuiz Augusto von Dentz 
122926afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
123026afbd82SLuiz Augusto von Dentz 
123126afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1232b5793de3SPauli Virtanen 		if (c->type != ISO_LINK || !bacmp(&c->dst, BDADDR_ANY))
123326afbd82SLuiz Augusto von Dentz 			continue;
123426afbd82SLuiz Augusto von Dentz 
1235c14516faSLuiz Augusto von Dentz 		/* Match CIG ID if set */
1236a07a95bcSLuiz Augusto von Dentz 		if (cig != c->iso_qos.ucast.cig)
1237c14516faSLuiz Augusto von Dentz 			continue;
1238c14516faSLuiz Augusto von Dentz 
1239c14516faSLuiz Augusto von Dentz 		/* Match CIS ID if set */
1240a07a95bcSLuiz Augusto von Dentz 		if (id != c->iso_qos.ucast.cis)
1241c14516faSLuiz Augusto von Dentz 			continue;
1242c14516faSLuiz Augusto von Dentz 
124371e95884SPauli Virtanen 		/* Match destination address if set */
124471e95884SPauli Virtanen 		if (!ba || (ba_type == c->dst_type && !bacmp(&c->dst, ba))) {
124526afbd82SLuiz Augusto von Dentz 			rcu_read_unlock();
124626afbd82SLuiz Augusto von Dentz 			return c;
124726afbd82SLuiz Augusto von Dentz 		}
124826afbd82SLuiz Augusto von Dentz 	}
124926afbd82SLuiz Augusto von Dentz 
125026afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
125126afbd82SLuiz Augusto von Dentz 
125226afbd82SLuiz Augusto von Dentz 	return NULL;
125326afbd82SLuiz Augusto von Dentz }
125426afbd82SLuiz Augusto von Dentz 
125526afbd82SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_cig(struct hci_dev *hdev,
125626afbd82SLuiz Augusto von Dentz 							__u8 handle)
125726afbd82SLuiz Augusto von Dentz {
125826afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
125926afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
126026afbd82SLuiz Augusto von Dentz 
126126afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
126226afbd82SLuiz Augusto von Dentz 
126326afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1264b5793de3SPauli Virtanen 		if (c->type != ISO_LINK || !bacmp(&c->dst, BDADDR_ANY))
126526afbd82SLuiz Augusto von Dentz 			continue;
126626afbd82SLuiz Augusto von Dentz 
12670fe8c8d0SIulia Tanasescu 		if (handle == c->iso_qos.ucast.cig) {
126826afbd82SLuiz Augusto von Dentz 			rcu_read_unlock();
126926afbd82SLuiz Augusto von Dentz 			return c;
127026afbd82SLuiz Augusto von Dentz 		}
127126afbd82SLuiz Augusto von Dentz 	}
127226afbd82SLuiz Augusto von Dentz 
127326afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
127426afbd82SLuiz Augusto von Dentz 
127526afbd82SLuiz Augusto von Dentz 	return NULL;
127626afbd82SLuiz Augusto von Dentz }
127726afbd82SLuiz Augusto von Dentz 
1278eca0ae4aSLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,
1279eca0ae4aSLuiz Augusto von Dentz 							__u8 handle)
1280eca0ae4aSLuiz Augusto von Dentz {
1281eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1282eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn  *c;
1283eca0ae4aSLuiz Augusto von Dentz 
1284eca0ae4aSLuiz Augusto von Dentz 	rcu_read_lock();
1285eca0ae4aSLuiz Augusto von Dentz 
1286eca0ae4aSLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1287eca0ae4aSLuiz Augusto von Dentz 		if (bacmp(&c->dst, BDADDR_ANY) || c->type != ISO_LINK)
1288eca0ae4aSLuiz Augusto von Dentz 			continue;
1289eca0ae4aSLuiz Augusto von Dentz 
12900fe8c8d0SIulia Tanasescu 		if (handle == c->iso_qos.bcast.big) {
1291eca0ae4aSLuiz Augusto von Dentz 			rcu_read_unlock();
1292eca0ae4aSLuiz Augusto von Dentz 			return c;
1293eca0ae4aSLuiz Augusto von Dentz 		}
1294eca0ae4aSLuiz Augusto von Dentz 	}
1295eca0ae4aSLuiz Augusto von Dentz 
1296eca0ae4aSLuiz Augusto von Dentz 	rcu_read_unlock();
1297eca0ae4aSLuiz Augusto von Dentz 
1298eca0ae4aSLuiz Augusto von Dentz 	return NULL;
1299eca0ae4aSLuiz Augusto von Dentz }
1300eca0ae4aSLuiz Augusto von Dentz 
1301f777d882SIulia Tanasescu static inline struct hci_conn *hci_conn_hash_lookup_big_any_dst(struct hci_dev *hdev,
1302f777d882SIulia Tanasescu 							__u8 handle)
1303f777d882SIulia Tanasescu {
1304f777d882SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1305f777d882SIulia Tanasescu 	struct hci_conn  *c;
1306f777d882SIulia Tanasescu 
1307f777d882SIulia Tanasescu 	rcu_read_lock();
1308f777d882SIulia Tanasescu 
1309f777d882SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1310f777d882SIulia Tanasescu 		if (c->type != ISO_LINK)
1311f777d882SIulia Tanasescu 			continue;
1312f777d882SIulia Tanasescu 
1313fbdc4bc4SIulia Tanasescu 		if (handle != BT_ISO_QOS_BIG_UNSET && handle == c->iso_qos.bcast.big) {
1314f777d882SIulia Tanasescu 			rcu_read_unlock();
1315f777d882SIulia Tanasescu 			return c;
1316f777d882SIulia Tanasescu 		}
1317f777d882SIulia Tanasescu 	}
1318f777d882SIulia Tanasescu 
1319f777d882SIulia Tanasescu 	rcu_read_unlock();
1320f777d882SIulia Tanasescu 
1321f777d882SIulia Tanasescu 	return NULL;
1322f777d882SIulia Tanasescu }
1323f777d882SIulia Tanasescu 
1324fbdc4bc4SIulia Tanasescu static inline struct hci_conn *
132523417475SIulia Tanasescu hci_conn_hash_lookup_pa_sync_big_handle(struct hci_dev *hdev, __u8 big)
1326fbdc4bc4SIulia Tanasescu {
1327fbdc4bc4SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1328fbdc4bc4SIulia Tanasescu 	struct hci_conn  *c;
1329fbdc4bc4SIulia Tanasescu 
1330fbdc4bc4SIulia Tanasescu 	rcu_read_lock();
1331fbdc4bc4SIulia Tanasescu 
1332fbdc4bc4SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1333fbdc4bc4SIulia Tanasescu 		if (c->type != ISO_LINK ||
1334fbdc4bc4SIulia Tanasescu 			!test_bit(HCI_CONN_PA_SYNC, &c->flags))
1335fbdc4bc4SIulia Tanasescu 			continue;
1336fbdc4bc4SIulia Tanasescu 
1337fbdc4bc4SIulia Tanasescu 		if (c->iso_qos.bcast.big == big) {
1338fbdc4bc4SIulia Tanasescu 			rcu_read_unlock();
1339fbdc4bc4SIulia Tanasescu 			return c;
1340fbdc4bc4SIulia Tanasescu 		}
1341fbdc4bc4SIulia Tanasescu 	}
1342fbdc4bc4SIulia Tanasescu 	rcu_read_unlock();
1343fbdc4bc4SIulia Tanasescu 
1344fbdc4bc4SIulia Tanasescu 	return NULL;
1345fbdc4bc4SIulia Tanasescu }
1346fbdc4bc4SIulia Tanasescu 
134723417475SIulia Tanasescu static inline struct hci_conn *
134823417475SIulia Tanasescu hci_conn_hash_lookup_pa_sync_handle(struct hci_dev *hdev, __u16 sync_handle)
134923417475SIulia Tanasescu {
135023417475SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
135123417475SIulia Tanasescu 	struct hci_conn  *c;
135223417475SIulia Tanasescu 
135323417475SIulia Tanasescu 	rcu_read_lock();
135423417475SIulia Tanasescu 
135523417475SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
135623417475SIulia Tanasescu 		if (c->type != ISO_LINK ||
135723417475SIulia Tanasescu 			!test_bit(HCI_CONN_PA_SYNC, &c->flags))
135823417475SIulia Tanasescu 			continue;
135923417475SIulia Tanasescu 
136023417475SIulia Tanasescu 		if (c->sync_handle == sync_handle) {
136123417475SIulia Tanasescu 			rcu_read_unlock();
136223417475SIulia Tanasescu 			return c;
136323417475SIulia Tanasescu 		}
136423417475SIulia Tanasescu 	}
136523417475SIulia Tanasescu 	rcu_read_unlock();
136623417475SIulia Tanasescu 
136723417475SIulia Tanasescu 	return NULL;
136823417475SIulia Tanasescu }
136923417475SIulia Tanasescu 
13704c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
13714c67bc74SMarcel Holtmann 							__u8 type, __u16 state)
13724c67bc74SMarcel Holtmann {
13734c67bc74SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
13744c67bc74SMarcel Holtmann 	struct hci_conn  *c;
13754c67bc74SMarcel Holtmann 
1376bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1377bf4c6325SGustavo F. Padovan 
1378bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1379bf4c6325SGustavo F. Padovan 		if (c->type == type && c->state == state) {
1380bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
13814c67bc74SMarcel Holtmann 			return c;
13824c67bc74SMarcel Holtmann 		}
1383bf4c6325SGustavo F. Padovan 	}
1384bf4c6325SGustavo F. Padovan 
1385bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1386bf4c6325SGustavo F. Padovan 
13874c67bc74SMarcel Holtmann 	return NULL;
13884c67bc74SMarcel Holtmann }
13894c67bc74SMarcel Holtmann 
139026afbd82SLuiz Augusto von Dentz typedef void (*hci_conn_func_t)(struct hci_conn *conn, void *data);
139126afbd82SLuiz Augusto von Dentz static inline void hci_conn_hash_list_state(struct hci_dev *hdev,
139226afbd82SLuiz Augusto von Dentz 					    hci_conn_func_t func, __u8 type,
139326afbd82SLuiz Augusto von Dentz 					    __u16 state, void *data)
139426afbd82SLuiz Augusto von Dentz {
139526afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
139626afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
139726afbd82SLuiz Augusto von Dentz 
139826afbd82SLuiz Augusto von Dentz 	if (!func)
139926afbd82SLuiz Augusto von Dentz 		return;
140026afbd82SLuiz Augusto von Dentz 
140126afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
140226afbd82SLuiz Augusto von Dentz 
140326afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
140426afbd82SLuiz Augusto von Dentz 		if (c->type == type && c->state == state)
140526afbd82SLuiz Augusto von Dentz 			func(c, data);
140626afbd82SLuiz Augusto von Dentz 	}
140726afbd82SLuiz Augusto von Dentz 
140826afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
140926afbd82SLuiz Augusto von Dentz }
141026afbd82SLuiz Augusto von Dentz 
1411e7d9ab73SJakub Pawlowski static inline struct hci_conn *hci_lookup_le_connect(struct hci_dev *hdev)
1412e7d9ab73SJakub Pawlowski {
1413e7d9ab73SJakub Pawlowski 	struct hci_conn_hash *h = &hdev->conn_hash;
1414e7d9ab73SJakub Pawlowski 	struct hci_conn  *c;
1415e7d9ab73SJakub Pawlowski 
1416e7d9ab73SJakub Pawlowski 	rcu_read_lock();
1417e7d9ab73SJakub Pawlowski 
1418e7d9ab73SJakub Pawlowski 	list_for_each_entry_rcu(c, &h->list, list) {
1419e7d9ab73SJakub Pawlowski 		if (c->type == LE_LINK && c->state == BT_CONNECT &&
1420e7d9ab73SJakub Pawlowski 		    !test_bit(HCI_CONN_SCANNING, &c->flags)) {
1421e7d9ab73SJakub Pawlowski 			rcu_read_unlock();
1422e7d9ab73SJakub Pawlowski 			return c;
1423e7d9ab73SJakub Pawlowski 		}
1424e7d9ab73SJakub Pawlowski 	}
1425e7d9ab73SJakub Pawlowski 
1426e7d9ab73SJakub Pawlowski 	rcu_read_unlock();
1427e7d9ab73SJakub Pawlowski 
1428e7d9ab73SJakub Pawlowski 	return NULL;
1429e7d9ab73SJakub Pawlowski }
1430e7d9ab73SJakub Pawlowski 
1431f8867016SLuiz Augusto von Dentz /* Returns true if an le connection is in the scanning state */
1432f8867016SLuiz Augusto von Dentz static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev)
1433f8867016SLuiz Augusto von Dentz {
1434f8867016SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1435f8867016SLuiz Augusto von Dentz 	struct hci_conn  *c;
1436f8867016SLuiz Augusto von Dentz 
1437f8867016SLuiz Augusto von Dentz 	rcu_read_lock();
1438f8867016SLuiz Augusto von Dentz 
1439f8867016SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1440f8867016SLuiz Augusto von Dentz 		if (c->type == LE_LINK && c->state == BT_CONNECT &&
1441f8867016SLuiz Augusto von Dentz 		    test_bit(HCI_CONN_SCANNING, &c->flags)) {
1442f8867016SLuiz Augusto von Dentz 			rcu_read_unlock();
1443f8867016SLuiz Augusto von Dentz 			return true;
1444f8867016SLuiz Augusto von Dentz 		}
1445f8867016SLuiz Augusto von Dentz 	}
1446f8867016SLuiz Augusto von Dentz 
1447f8867016SLuiz Augusto von Dentz 	rcu_read_unlock();
1448f8867016SLuiz Augusto von Dentz 
1449f8867016SLuiz Augusto von Dentz 	return false;
1450f8867016SLuiz Augusto von Dentz }
1451f8867016SLuiz Augusto von Dentz 
1452e3b679d5SJohan Hedberg int hci_disconnect(struct hci_conn *conn, __u8 reason);
14532dea632fSFrédéric Dalleau bool hci_setup_sync(struct hci_conn *conn, __u16 handle);
1454e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status);
145526afbd82SLuiz Augusto von Dentz bool hci_iso_setup_path(struct hci_conn *conn);
14567f74563eSPauli Virtanen int hci_le_create_cis_pending(struct hci_dev *hdev);
14577f74563eSPauli Virtanen int hci_conn_check_create_cis(struct hci_conn *conn);
14581da177e4SLinus Torvalds 
1459a5c4e309SJohan Hedberg struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
146084cb0143SZiyang Xuan 			      u8 role, u16 handle);
146184cb0143SZiyang Xuan struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
146284cb0143SZiyang Xuan 				    bdaddr_t *dst, u8 role);
1463a2ac591cSRuihan Li void hci_conn_del(struct hci_conn *conn);
14641da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev);
1465a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev);
14661da177e4SLinus Torvalds 
146773d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn);
14689472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan);
14692c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn);
147042c4e53eSAndrei Emeltchenko struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
147173d80debSLuiz Augusto von Dentz 
1472f75113a2SJakub Pawlowski struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
1473f75113a2SJakub Pawlowski 				     u8 dst_type, u8 sec_level,
147476b13996SManish Mandlik 				     u16 conn_timeout,
147576b13996SManish Mandlik 				     enum conn_reasons conn_reason);
147604a6c589SAndre Guedes struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1477d850bf08SLuiz Augusto von Dentz 				u8 dst_type, bool dst_resolved, u8 sec_level,
14788e8b92eeSLuiz Augusto von Dentz 				u16 conn_timeout, u8 role);
147904a6c589SAndre Guedes struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
148076b13996SManish Mandlik 				 u8 sec_level, u8 auth_type,
148176b13996SManish Mandlik 				 enum conn_reasons conn_reason);
148210c62ddcSFrédéric Dalleau struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1483b2af264aSKiran K 				 __u16 setting, struct bt_codec *codec);
148426afbd82SLuiz Augusto von Dentz struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
148526afbd82SLuiz Augusto von Dentz 			      __u8 dst_type, struct bt_iso_qos *qos);
1486a0bfde16SIulia Tanasescu struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst,
1487a0bfde16SIulia Tanasescu 			      struct bt_iso_qos *qos,
1488a0bfde16SIulia Tanasescu 			      __u8 base_len, __u8 *base);
148926afbd82SLuiz Augusto von Dentz struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
149026afbd82SLuiz Augusto von Dentz 				 __u8 dst_type, struct bt_iso_qos *qos);
1491eca0ae4aSLuiz Augusto von Dentz struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
1492eca0ae4aSLuiz Augusto von Dentz 				 __u8 dst_type, struct bt_iso_qos *qos,
1493eca0ae4aSLuiz Augusto von Dentz 				 __u8 data_len, __u8 *data);
1494eca0ae4aSLuiz Augusto von Dentz int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type,
14950fe8c8d0SIulia Tanasescu 		       __u8 sid, struct bt_iso_qos *qos);
1496fbdc4bc4SIulia Tanasescu int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
1497fbdc4bc4SIulia Tanasescu 			   struct bt_iso_qos *qos,
1498eca0ae4aSLuiz Augusto von Dentz 			   __u16 sync_handle, __u8 num_bis, __u8 bis[]);
1499e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn);
1500b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
1501e7cafc45SJohan Hedberg int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type,
1502e7cafc45SJohan Hedberg 		      bool initiator);
15038c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
15041da177e4SLinus Torvalds 
150514b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
15061da177e4SLinus Torvalds 
15079b3628d7SLuiz Augusto von Dentz void hci_conn_failed(struct hci_conn *conn, u8 status);
150816e3b642SLuiz Augusto von Dentz u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle);
150906c053fbSAndre Guedes 
15108d12356fSDavid Herrmann /*
15118d12356fSDavid Herrmann  * hci_conn_get() and hci_conn_put() are used to control the life-time of an
15128d12356fSDavid Herrmann  * "hci_conn" object. They do not guarantee that the hci_conn object is running,
15138d12356fSDavid Herrmann  * working or anything else. They just guarantee that the object is available
15148d12356fSDavid Herrmann  * and can be dereferenced. So you can use its locks, local variables and any
15158d12356fSDavid Herrmann  * other constant data.
15168d12356fSDavid Herrmann  * Before accessing runtime data, you _must_ lock the object and then check that
15178d12356fSDavid Herrmann  * it is still running. As soon as you release the locks, the connection might
15188d12356fSDavid Herrmann  * get dropped, though.
15198d12356fSDavid Herrmann  *
15208d12356fSDavid Herrmann  * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control
15218d12356fSDavid Herrmann  * how long the underlying connection is held. So every channel that runs on the
15228d12356fSDavid Herrmann  * hci_conn object calls this to prevent the connection from disappearing. As
15238d12356fSDavid Herrmann  * long as you hold a device, you must also guarantee that you have a valid
15248d12356fSDavid Herrmann  * reference to the device via hci_conn_get() (or the initial reference from
15258d12356fSDavid Herrmann  * hci_conn_add()).
15268d12356fSDavid Herrmann  * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't
15278d12356fSDavid Herrmann  * break because nobody cares for that. But this means, we cannot use
15288d12356fSDavid Herrmann  * _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
15298d12356fSDavid Herrmann  */
15308d12356fSDavid Herrmann 
153151bb8457SJohan Hedberg static inline struct hci_conn *hci_conn_get(struct hci_conn *conn)
15328d12356fSDavid Herrmann {
15338d12356fSDavid Herrmann 	get_device(&conn->dev);
153451bb8457SJohan Hedberg 	return conn;
15358d12356fSDavid Herrmann }
15368d12356fSDavid Herrmann 
15378d12356fSDavid Herrmann static inline void hci_conn_put(struct hci_conn *conn)
15388d12356fSDavid Herrmann {
15398d12356fSDavid Herrmann 	put_device(&conn->dev);
15408d12356fSDavid Herrmann }
15418d12356fSDavid Herrmann 
154206149746SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hold(struct hci_conn *conn)
15431da177e4SLinus Torvalds {
154471becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
154538b3fef1SAndrei Emeltchenko 
15461da177e4SLinus Torvalds 	atomic_inc(&conn->refcnt);
15472f304d1eSAndre Guedes 	cancel_delayed_work(&conn->disc_work);
154806149746SLuiz Augusto von Dentz 
154906149746SLuiz Augusto von Dentz 	return conn;
15501da177e4SLinus Torvalds }
15511da177e4SLinus Torvalds 
155276a68ba0SDavid Herrmann static inline void hci_conn_drop(struct hci_conn *conn)
15531da177e4SLinus Torvalds {
155471becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
155538b3fef1SAndrei Emeltchenko 
15561da177e4SLinus Torvalds 	if (atomic_dec_and_test(&conn->refcnt)) {
155704837f64SMarcel Holtmann 		unsigned long timeo;
1558716e4ab5SAndrei Emeltchenko 
1559716e4ab5SAndrei Emeltchenko 		switch (conn->type) {
1560716e4ab5SAndrei Emeltchenko 		case ACL_LINK:
1561716e4ab5SAndrei Emeltchenko 		case LE_LINK:
1562a74a84f6SJohan Hedberg 			cancel_delayed_work(&conn->idle_work);
15636ac59344SMarcel Holtmann 			if (conn->state == BT_CONNECTED) {
15645f246e89SAndrei Emeltchenko 				timeo = conn->disc_timeout;
156504837f64SMarcel Holtmann 				if (!conn->out)
1566052b30b0SMarcel Holtmann 					timeo *= 2;
15675a9d0a3fSWaldemar Rymarkiewicz 			} else {
1568eb78d7e5SJohan Hedberg 				timeo = 0;
15695a9d0a3fSWaldemar Rymarkiewicz 			}
1570716e4ab5SAndrei Emeltchenko 			break;
1571716e4ab5SAndrei Emeltchenko 
1572716e4ab5SAndrei Emeltchenko 		case AMP_LINK:
1573716e4ab5SAndrei Emeltchenko 			timeo = conn->disc_timeout;
1574716e4ab5SAndrei Emeltchenko 			break;
1575716e4ab5SAndrei Emeltchenko 
1576716e4ab5SAndrei Emeltchenko 		default:
1577eb78d7e5SJohan Hedberg 			timeo = 0;
1578716e4ab5SAndrei Emeltchenko 			break;
15795a9d0a3fSWaldemar Rymarkiewicz 		}
1580716e4ab5SAndrei Emeltchenko 
15812f304d1eSAndre Guedes 		cancel_delayed_work(&conn->disc_work);
158219c40e3bSGustavo F. Padovan 		queue_delayed_work(conn->hdev->workqueue,
15831931782bSVinicius Costa Gomes 				   &conn->disc_work, timeo);
15841da177e4SLinus Torvalds 	}
15851da177e4SLinus Torvalds }
15861da177e4SLinus Torvalds 
15871da177e4SLinus Torvalds /* ----- HCI Devices ----- */
1588dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d)
15891da177e4SLinus Torvalds {
1590376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
15912c935bc5SPeter Zijlstra 	       kref_read(&d->dev.kobj.kref));
1592376261aeSAndrei Emeltchenko 
15934c724c71SDavid Herrmann 	put_device(&d->dev);
1594010666a1SDavid Herrmann }
15951da177e4SLinus Torvalds 
1596dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
15971da177e4SLinus Torvalds {
1598376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
15992c935bc5SPeter Zijlstra 	       kref_read(&d->dev.kobj.kref));
1600376261aeSAndrei Emeltchenko 
16014c724c71SDavid Herrmann 	get_device(&d->dev);
16021da177e4SLinus Torvalds 	return d;
16031da177e4SLinus Torvalds }
16041da177e4SLinus Torvalds 
160509fd0de5SGustavo F. Padovan #define hci_dev_lock(d)		mutex_lock(&d->lock)
160609fd0de5SGustavo F. Padovan #define hci_dev_unlock(d)	mutex_unlock(&d->lock)
16071da177e4SLinus Torvalds 
1608aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev)
16093dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev)
1610aa2b86d7SDavid Herrmann 
1611155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev)
1612155961e8SDavid Herrmann {
1613155961e8SDavid Herrmann 	return dev_get_drvdata(&hdev->dev);
1614155961e8SDavid Herrmann }
1615155961e8SDavid Herrmann 
1616155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
1617155961e8SDavid Herrmann {
1618155961e8SDavid Herrmann 	dev_set_drvdata(&hdev->dev, data);
1619155961e8SDavid Herrmann }
1620155961e8SDavid Herrmann 
16216ec56613STedd Ho-Jeong An static inline void *hci_get_priv(struct hci_dev *hdev)
16226ec56613STedd Ho-Jeong An {
16236ec56613STedd Ho-Jeong An 	return (char *)hdev + sizeof(*hdev);
16246ec56613STedd Ho-Jeong An }
16256ec56613STedd Ho-Jeong An 
16261da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index);
162739385cb5SJohan Hedberg struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type);
16281da177e4SLinus Torvalds 
16296ec56613STedd Ho-Jeong An struct hci_dev *hci_alloc_dev_priv(int sizeof_priv);
16306ec56613STedd Ho-Jeong An 
16316ec56613STedd Ho-Jeong An static inline struct hci_dev *hci_alloc_dev(void)
16326ec56613STedd Ho-Jeong An {
16336ec56613STedd Ho-Jeong An 	return hci_alloc_dev_priv(0);
16346ec56613STedd Ho-Jeong An }
16356ec56613STedd Ho-Jeong An 
16361da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev);
16371da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev);
163859735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev);
163958ce6d5bSTetsuo Handa void hci_release_dev(struct hci_dev *hdev);
1640359ee4f8SAbhishek Pandit-Subedi int hci_register_suspend_notifier(struct hci_dev *hdev);
1641359ee4f8SAbhishek Pandit-Subedi int hci_unregister_suspend_notifier(struct hci_dev *hdev);
16421da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev);
16431da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev);
164475e0569fSMarcel Holtmann int hci_reset_dev(struct hci_dev *hdev);
1645f962fe32SMarcel Holtmann int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
1646f962fe32SMarcel Holtmann int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb);
16471aabbbceSNicolas Iooss __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...);
16481aabbbceSNicolas Iooss __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...);
1649145373cbSMiao-chen Chou 
1650145373cbSMiao-chen Chou static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
1651145373cbSMiao-chen Chou {
1652145373cbSMiao-chen Chou #if IS_ENABLED(CONFIG_BT_MSFTEXT)
1653145373cbSMiao-chen Chou 	hdev->msft_opcode = opcode;
1654145373cbSMiao-chen Chou #endif
1655145373cbSMiao-chen Chou }
1656145373cbSMiao-chen Chou 
1657f67743f9SMarcel Holtmann static inline void hci_set_aosp_capable(struct hci_dev *hdev)
1658f67743f9SMarcel Holtmann {
1659f67743f9SMarcel Holtmann #if IS_ENABLED(CONFIG_BT_AOSPEXT)
1660f67743f9SMarcel Holtmann 	hdev->aosp_capable = true;
1661f67743f9SMarcel Holtmann #endif
1662f67743f9SMarcel Holtmann }
1663f67743f9SMarcel Holtmann 
16649695ef87SAbhishek Pandit-Subedi static inline void hci_devcd_setup(struct hci_dev *hdev)
16659695ef87SAbhishek Pandit-Subedi {
16669695ef87SAbhishek Pandit-Subedi #ifdef CONFIG_DEV_COREDUMP
16679695ef87SAbhishek Pandit-Subedi 	INIT_WORK(&hdev->dump.dump_rx, hci_devcd_rx);
16689695ef87SAbhishek Pandit-Subedi 	INIT_DELAYED_WORK(&hdev->dump.dump_timeout, hci_devcd_timeout);
16699695ef87SAbhishek Pandit-Subedi 	skb_queue_head_init(&hdev->dump.dump_q);
16709695ef87SAbhishek Pandit-Subedi #endif
16719695ef87SAbhishek Pandit-Subedi }
16729695ef87SAbhishek Pandit-Subedi 
16731da177e4SLinus Torvalds int hci_dev_open(__u16 dev);
16741da177e4SLinus Torvalds int hci_dev_close(__u16 dev);
16756b3cc1dbSSimon Fels int hci_dev_do_close(struct hci_dev *hdev);
16761da177e4SLinus Torvalds int hci_dev_reset(__u16 dev);
16771da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev);
16781da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg);
16791da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg);
16801da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg);
16811da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg);
16821da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
168340be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
16841da177e4SLinus Torvalds int hci_inquiry(void __user *arg);
16851da177e4SLinus Torvalds 
1686dcc36c16SJohan Hedberg struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list,
1687b9ee0a78SMarcel Holtmann 					   bdaddr_t *bdaddr, u8 type);
1688b950aa88SAnkit Navik struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk(
1689b950aa88SAnkit Navik 				    struct list_head *list, bdaddr_t *bdaddr,
1690b950aa88SAnkit Navik 				    u8 type);
16918baaa403SAbhishek Pandit-Subedi struct bdaddr_list_with_flags *
16928baaa403SAbhishek Pandit-Subedi hci_bdaddr_list_lookup_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16938baaa403SAbhishek Pandit-Subedi 				  u8 type);
1694dcc36c16SJohan Hedberg int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1695b950aa88SAnkit Navik int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1696b950aa88SAnkit Navik 				 u8 type, u8 *peer_irk, u8 *local_irk);
16978baaa403SAbhishek Pandit-Subedi int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16988baaa403SAbhishek Pandit-Subedi 				   u8 type, u32 flags);
1699dcc36c16SJohan Hedberg int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1700b950aa88SAnkit Navik int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1701b950aa88SAnkit Navik 				 u8 type);
17028baaa403SAbhishek Pandit-Subedi int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr,
17038baaa403SAbhishek Pandit-Subedi 				   u8 type);
1704dcc36c16SJohan Hedberg void hci_bdaddr_list_clear(struct list_head *list);
1705d2ab0ac1SMarcel Holtmann 
170615819a70SAndre Guedes struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
170715819a70SAndre Guedes 					       bdaddr_t *addr, u8 addr_type);
170851d167c0SMarcel Holtmann struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
170951d167c0SMarcel Holtmann 					    bdaddr_t *addr, u8 addr_type);
171015819a70SAndre Guedes void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
171155af49a8SJohan Hedberg void hci_conn_params_clear_disabled(struct hci_dev *hdev);
1712195ef75eSPauli Virtanen void hci_conn_params_free(struct hci_conn_params *param);
171315819a70SAndre Guedes 
1714195ef75eSPauli Virtanen void hci_pend_le_list_del_init(struct hci_conn_params *param);
1715195ef75eSPauli Virtanen void hci_pend_le_list_add(struct hci_conn_params *param,
1716195ef75eSPauli Virtanen 			  struct list_head *list);
1717501f8827SJohan Hedberg struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
1718501f8827SJohan Hedberg 						  bdaddr_t *addr,
1719501f8827SJohan Hedberg 						  u8 addr_type);
172077a77a30SAndre Guedes 
172135f7498aSJohan Hedberg void hci_uuids_clear(struct hci_dev *hdev);
17222aeb9a1aSJohan Hedberg 
172335f7498aSJohan Hedberg void hci_link_keys_clear(struct hci_dev *hdev);
172455ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
1725567fa2aaSJohan Hedberg struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
17267652ff6aSJohan Hedberg 				  bdaddr_t *bdaddr, u8 *val, u8 type,
17277652ff6aSJohan Hedberg 				  u8 pin_len, bool *persistent);
1728ca9142b8SJohan Hedberg struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
172935d70271SJohan Hedberg 			    u8 addr_type, u8 type, u8 authenticated,
1730fe39c7b2SMarcel Holtmann 			    u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand);
1731f3a73d97SJohan Hedberg struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1732e804d25dSJohan Hedberg 			     u8 addr_type, u8 role);
1733e0b2b27eSJohan Hedberg int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type);
173435f7498aSJohan Hedberg void hci_smp_ltks_clear(struct hci_dev *hdev);
173555ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
173655ed8ca1SJohan Hedberg 
1737970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa);
1738970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1739970c4e46SJohan Hedberg 				     u8 addr_type);
1740ca9142b8SJohan Hedberg struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1741ca9142b8SJohan Hedberg 			    u8 addr_type, u8 val[16], bdaddr_t *rpa);
1742a7ec7338SJohan Hedberg void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
1743600a8749SAlain Michaud bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]);
1744600a8749SAlain Michaud void hci_blocked_keys_clear(struct hci_dev *hdev);
1745970c4e46SJohan Hedberg void hci_smp_irks_clear(struct hci_dev *hdev);
1746970c4e46SJohan Hedberg 
174755e76b38SJohan Hedberg bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
174855e76b38SJohan Hedberg 
174935f7498aSJohan Hedberg void hci_remote_oob_data_clear(struct hci_dev *hdev);
17502763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
17516928a924SJohan Hedberg 					  bdaddr_t *bdaddr, u8 bdaddr_type);
17520798872eSMarcel Holtmann int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
17536928a924SJohan Hedberg 			    u8 bdaddr_type, u8 *hash192, u8 *rand192,
175438da1703SJohan Hedberg 			    u8 *hash256, u8 *rand256);
17556928a924SJohan Hedberg int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
17566928a924SJohan Hedberg 			       u8 bdaddr_type);
17572763eda6SSzymon Janc 
1758d2609b34SFlorian Grandel void hci_adv_instances_clear(struct hci_dev *hdev);
1759d2609b34SFlorian Grandel struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance);
1760d2609b34SFlorian Grandel struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance);
1761eca0ae4aSLuiz Augusto von Dentz struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance,
1762eca0ae4aSLuiz Augusto von Dentz 				      u32 flags, u16 adv_data_len, u8 *adv_data,
1763d2609b34SFlorian Grandel 				      u16 scan_rsp_len, u8 *scan_rsp_data,
17649bf9f4b6SDaniel Winkler 				      u16 timeout, u16 duration, s8 tx_power,
1765b338d917SBrian Gix 				      u32 min_interval, u32 max_interval,
1766b338d917SBrian Gix 				      u8 mesh_handle);
1767eca0ae4aSLuiz Augusto von Dentz struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance,
1768eca0ae4aSLuiz Augusto von Dentz 				      u32 flags, u8 data_len, u8 *data,
1769eca0ae4aSLuiz Augusto von Dentz 				      u32 min_interval, u32 max_interval);
177031aab5c2SDaniel Winkler int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance,
177131aab5c2SDaniel Winkler 			 u16 adv_data_len, u8 *adv_data,
177231aab5c2SDaniel Winkler 			 u16 scan_rsp_len, u8 *scan_rsp_data);
1773d2609b34SFlorian Grandel int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance);
1774a73c046aSJaganath Kanakkassery void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);
177501ce70b0SLuiz Augusto von Dentz u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance);
177601ce70b0SLuiz Augusto von Dentz bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance);
1777d2609b34SFlorian Grandel 
1778e5e1e7fdSMiao-chen Chou void hci_adv_monitors_clear(struct hci_dev *hdev);
177966bd095aSArchie Pusaka void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
1780b747a836SManish Mandlik int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
17817cf5c297SManish Mandlik int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle);
17827cf5c297SManish Mandlik int hci_remove_all_adv_monitor(struct hci_dev *hdev);
17838208f5a9SMiao-chen Chou bool hci_is_adv_monitoring(struct hci_dev *hdev);
1784a2a4dedfSArchie Pusaka int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev);
1785e5e1e7fdSMiao-chen Chou 
17861da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
17871da177e4SLinus Torvalds 
17880ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev);
1789a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn);
1790b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn);
1791b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn);
17921da177e4SLinus Torvalds 
17936935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
1794294d749bSKiran K #define GET_HCIDEV_DEV(hdev) ((hdev)->dev.parent)
17951da177e4SLinus Torvalds 
17961da177e4SLinus Torvalds /* ----- LMP capabilities ----- */
1797cad718edSJohan Hedberg #define lmp_encrypt_capable(dev)   ((dev)->features[0][0] & LMP_ENCRYPT)
1798cad718edSJohan Hedberg #define lmp_rswitch_capable(dev)   ((dev)->features[0][0] & LMP_RSWITCH)
1799cad718edSJohan Hedberg #define lmp_hold_capable(dev)      ((dev)->features[0][0] & LMP_HOLD)
1800cad718edSJohan Hedberg #define lmp_sniff_capable(dev)     ((dev)->features[0][0] & LMP_SNIFF)
1801cad718edSJohan Hedberg #define lmp_park_capable(dev)      ((dev)->features[0][1] & LMP_PARK)
1802cad718edSJohan Hedberg #define lmp_inq_rssi_capable(dev)  ((dev)->features[0][3] & LMP_RSSI_INQ)
1803cad718edSJohan Hedberg #define lmp_esco_capable(dev)      ((dev)->features[0][3] & LMP_ESCO)
1804cad718edSJohan Hedberg #define lmp_bredr_capable(dev)     (!((dev)->features[0][4] & LMP_NO_BREDR))
1805cad718edSJohan Hedberg #define lmp_le_capable(dev)        ((dev)->features[0][4] & LMP_LE)
1806cad718edSJohan Hedberg #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR)
1807cad718edSJohan Hedberg #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC)
18088b1c324cSYu Liu #define lmp_esco_2m_capable(dev)   ((dev)->features[0][5] & LMP_EDR_ESCO_2M)
1809cad718edSJohan Hedberg #define lmp_ext_inq_capable(dev)   ((dev)->features[0][6] & LMP_EXT_INQ)
1810cad718edSJohan Hedberg #define lmp_le_br_capable(dev)     (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR))
1811cad718edSJohan Hedberg #define lmp_ssp_capable(dev)       ((dev)->features[0][6] & LMP_SIMPLE_PAIR)
1812cad718edSJohan Hedberg #define lmp_no_flush_capable(dev)  ((dev)->features[0][6] & LMP_NO_FLUSH)
1813cad718edSJohan Hedberg #define lmp_lsto_capable(dev)      ((dev)->features[0][7] & LMP_LSTO)
1814cad718edSJohan Hedberg #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR)
1815cad718edSJohan Hedberg #define lmp_ext_feat_capable(dev)  ((dev)->features[0][7] & LMP_EXTFEATURES)
181607a5c61eSFrédéric Dalleau #define lmp_transp_capable(dev)    ((dev)->features[0][2] & LMP_TRANSPARENT)
18175075b972SJaganath Kanakkassery #define lmp_edr_2m_capable(dev)    ((dev)->features[0][3] & LMP_EDR_2M)
18185075b972SJaganath Kanakkassery #define lmp_edr_3m_capable(dev)    ((dev)->features[0][3] & LMP_EDR_3M)
18195075b972SJaganath Kanakkassery #define lmp_edr_3slot_capable(dev) ((dev)->features[0][4] & LMP_EDR_3SLOT)
18205075b972SJaganath Kanakkassery #define lmp_edr_5slot_capable(dev) ((dev)->features[0][5] & LMP_EDR_5SLOT)
18211da177e4SLinus Torvalds 
1822eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */
18236397729bSArchie Pusaka #define lmp_cpb_central_capable(dev) ((dev)->features[2][0] & LMP_CPB_CENTRAL)
18246397729bSArchie Pusaka #define lmp_cpb_peripheral_capable(dev) ((dev)->features[2][0] & LMP_CPB_PERIPHERAL)
182553b834d2SMarcel Holtmann #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN)
182653b834d2SMarcel Holtmann #define lmp_sync_scan_capable(dev)  ((dev)->features[2][0] & LMP_SYNC_SCAN)
1827d5991585SMarcel Holtmann #define lmp_sc_capable(dev)         ((dev)->features[2][1] & LMP_SC)
1828d5991585SMarcel Holtmann #define lmp_ping_capable(dev)       ((dev)->features[2][1] & LMP_PING)
182953b834d2SMarcel Holtmann 
183053b834d2SMarcel Holtmann /* ----- Host capabilities ----- */
1831cad718edSJohan Hedberg #define lmp_host_ssp_capable(dev)  ((dev)->features[1][0] & LMP_HOST_SSP)
1832d5991585SMarcel Holtmann #define lmp_host_sc_capable(dev)   ((dev)->features[1][0] & LMP_HOST_SC)
1833cad718edSJohan Hedberg #define lmp_host_le_capable(dev)   (!!((dev)->features[1][0] & LMP_HOST_LE))
1834cad718edSJohan Hedberg #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
1835eead27daSAndre Guedes 
1836d7a5a11dSMarcel Holtmann #define hdev_is_powered(dev)   (test_bit(HCI_UP, &(dev)->flags) && \
1837d7a5a11dSMarcel Holtmann 				!hci_dev_test_flag(dev, HCI_AUTO_OFF))
183805b3c3e7SMarcel Holtmann #define bredr_sc_enabled(dev)  (lmp_sc_capable(dev) && \
1839d7a5a11dSMarcel Holtmann 				hci_dev_test_flag(dev, HCI_SC_ENABLED))
1840c45074d6SLuiz Augusto von Dentz #define rpa_valid(dev)         (bacmp(&dev->rpa, BDADDR_ANY) && \
1841c45074d6SLuiz Augusto von Dentz 				!hci_dev_test_flag(dev, HCI_RPA_EXPIRED))
1842c45074d6SLuiz Augusto von Dentz #define adv_rpa_valid(adv)     (bacmp(&adv->random_addr, BDADDR_ANY) && \
1843c45074d6SLuiz Augusto von Dentz 				!adv->rpa_expired)
1844432df05eSJohan Hedberg 
184545bdd86eSJaganath Kanakkassery #define scan_1m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_1M) || \
184645bdd86eSJaganath Kanakkassery 		      ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_1M))
184745bdd86eSJaganath Kanakkassery 
1848288c9022SLuiz Augusto von Dentz #define le_2m_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_2M))
1849288c9022SLuiz Augusto von Dentz 
185045bdd86eSJaganath Kanakkassery #define scan_2m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_2M) || \
185145bdd86eSJaganath Kanakkassery 		      ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_2M))
185245bdd86eSJaganath Kanakkassery 
1853253f3399SLuiz Augusto von Dentz #define le_coded_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_CODED) && \
1854253f3399SLuiz Augusto von Dentz 			       !test_bit(HCI_QUIRK_BROKEN_LE_CODED, \
1855253f3399SLuiz Augusto von Dentz 					 &(dev)->quirks))
1856288c9022SLuiz Augusto von Dentz 
185745bdd86eSJaganath Kanakkassery #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \
185845bdd86eSJaganath Kanakkassery 			 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED))
185945bdd86eSJaganath Kanakkassery 
1860ad383c2cSLuiz Augusto von Dentz #define ll_privacy_capable(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
1861ad383c2cSLuiz Augusto von Dentz 
1862e1d57235SMarcel Holtmann /* Use LL Privacy based address resolution if supported */
1863ad383c2cSLuiz Augusto von Dentz #define use_ll_privacy(dev) (ll_privacy_capable(dev) && \
1864ad383c2cSLuiz Augusto von Dentz 			     hci_dev_test_flag(dev, HCI_ENABLE_LL_PRIVACY))
1865e1d57235SMarcel Holtmann 
18666126ffabSLuiz Augusto von Dentz #define privacy_mode_capable(dev) (use_ll_privacy(dev) && \
18676126ffabSLuiz Augusto von Dentz 				   (hdev->commands[39] & 0x04))
18686126ffabSLuiz Augusto von Dentz 
186962e3a7cbSLuiz Augusto von Dentz #define read_key_size_capable(dev) \
187062e3a7cbSLuiz Augusto von Dentz 	((dev)->commands[20] & 0x10 && \
187162e3a7cbSLuiz Augusto von Dentz 	 !test_bit(HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE, &hdev->quirks))
187262e3a7cbSLuiz Augusto von Dentz 
187305abad85SLuiz Augusto von Dentz /* Use enhanced synchronous connection if command is supported and its quirk
187405abad85SLuiz Augusto von Dentz  * has not been set.
187505abad85SLuiz Augusto von Dentz  */
187605abad85SLuiz Augusto von Dentz #define enhanced_sync_conn_capable(dev) \
187705abad85SLuiz Augusto von Dentz 	(((dev)->commands[29] & 0x08) && \
187805abad85SLuiz Augusto von Dentz 	 !test_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &(dev)->quirks))
1879b2af264aSKiran K 
1880a2344b9eSJaganath Kanakkassery /* Use ext scanning if set ext scan param and ext scan enable is supported */
1881a2344b9eSJaganath Kanakkassery #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \
1882392fca35SSven Peter 			   ((dev)->commands[37] & 0x40) && \
1883392fca35SSven Peter 			   !test_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &(dev)->quirks))
1884392fca35SSven Peter 
18854d94f95dSJaganath Kanakkassery /* Use ext create connection if command is supported */
18864d94f95dSJaganath Kanakkassery #define use_ext_conn(dev) ((dev)->commands[37] & 0x80)
1887a2344b9eSJaganath Kanakkassery 
18886b49bcb4SJaganath Kanakkassery /* Extended advertising support */
18896b49bcb4SJaganath Kanakkassery #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
18906b49bcb4SJaganath Kanakkassery 
1891112b5090SLuiz Augusto von Dentz /* Maximum advertising length */
1892112b5090SLuiz Augusto von Dentz #define max_adv_len(dev) \
1893112b5090SLuiz Augusto von Dentz 	(ext_adv_capable(dev) ? HCI_MAX_EXT_AD_LENGTH : HCI_MAX_AD_LENGTH)
1894112b5090SLuiz Augusto von Dentz 
1895a56a1138SLuiz Augusto von Dentz /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1789:
1896a56a1138SLuiz Augusto von Dentz  *
1897a56a1138SLuiz Augusto von Dentz  * C24: Mandatory if the LE Controller supports Connection State and either
1898a56a1138SLuiz Augusto von Dentz  * LE Feature (LL Privacy) or LE Feature (Extended Advertising) is supported
1899a56a1138SLuiz Augusto von Dentz  */
1900a56a1138SLuiz Augusto von Dentz #define use_enhanced_conn_complete(dev) (ll_privacy_capable(dev) || \
1901a56a1138SLuiz Augusto von Dentz 					 ext_adv_capable(dev))
1902a56a1138SLuiz Augusto von Dentz 
1903eca0ae4aSLuiz Augusto von Dentz /* Periodic advertising support */
1904eca0ae4aSLuiz Augusto von Dentz #define per_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_PERIODIC_ADV))
1905eca0ae4aSLuiz Augusto von Dentz 
1906eca0ae4aSLuiz Augusto von Dentz /* CIS Master/Slave and BIS support */
1907eca0ae4aSLuiz Augusto von Dentz #define iso_capable(dev) (cis_capable(dev) || bis_capable(dev))
190826afbd82SLuiz Augusto von Dentz #define cis_capable(dev) \
190926afbd82SLuiz Augusto von Dentz 	(cis_central_capable(dev) || cis_peripheral_capable(dev))
191026afbd82SLuiz Augusto von Dentz #define cis_central_capable(dev) \
191126afbd82SLuiz Augusto von Dentz 	((dev)->le_features[3] & HCI_LE_CIS_CENTRAL)
191226afbd82SLuiz Augusto von Dentz #define cis_peripheral_capable(dev) \
191326afbd82SLuiz Augusto von Dentz 	((dev)->le_features[3] & HCI_LE_CIS_PERIPHERAL)
1914eca0ae4aSLuiz Augusto von Dentz #define bis_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_BROADCASTER)
1915ae753361SClaudia Draghicescu #define sync_recv_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_SYNC_RECEIVER)
191626afbd82SLuiz Augusto von Dentz 
1917ffcb0a44SSven Peter #define mws_transport_config_capable(dev) (((dev)->commands[30] & 0x08) && \
1918ffcb0a44SSven Peter 	(!test_bit(HCI_QUIRK_BROKEN_MWS_TRANSPORT_CONFIG, &(dev)->quirks)))
1919ffcb0a44SSven Peter 
19201da177e4SLinus Torvalds /* ----- HCI protocols ----- */
192120714bfeSFrédéric Dalleau #define HCI_PROTO_DEFER             0x01
192220714bfeSFrédéric Dalleau 
19235a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
192420714bfeSFrédéric Dalleau 					__u8 type, __u8 *flags)
19251da177e4SLinus Torvalds {
1926686ebf28SUlisses Furquim 	switch (type) {
1927686ebf28SUlisses Furquim 	case ACL_LINK:
1928686ebf28SUlisses Furquim 		return l2cap_connect_ind(hdev, bdaddr);
19291da177e4SLinus Torvalds 
1930686ebf28SUlisses Furquim 	case SCO_LINK:
1931686ebf28SUlisses Furquim 	case ESCO_LINK:
193220714bfeSFrédéric Dalleau 		return sco_connect_ind(hdev, bdaddr, flags);
19331da177e4SLinus Torvalds 
193426afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
1935ccf74f23SLuiz Augusto von Dentz 		return iso_connect_ind(hdev, bdaddr, flags);
193626afbd82SLuiz Augusto von Dentz 
1937686ebf28SUlisses Furquim 	default:
1938686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", type);
1939686ebf28SUlisses Furquim 		return -EINVAL;
1940686ebf28SUlisses Furquim 	}
19411da177e4SLinus Torvalds }
19421da177e4SLinus Torvalds 
19432950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn)
19442950f21aSMarcel Holtmann {
1945686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
1946686ebf28SUlisses Furquim 		return HCI_ERROR_REMOTE_USER_TERM;
19472950f21aSMarcel Holtmann 
1948686ebf28SUlisses Furquim 	return l2cap_disconn_ind(conn);
19492950f21aSMarcel Holtmann }
19502950f21aSMarcel Holtmann 
19511da177e4SLinus Torvalds /* ----- HCI callbacks ----- */
19521da177e4SLinus Torvalds struct hci_cb {
19531da177e4SLinus Torvalds 	struct list_head list;
19541da177e4SLinus Torvalds 
19551da177e4SLinus Torvalds 	char *name;
19561da177e4SLinus Torvalds 
1957539c496dSJohan Hedberg 	void (*connect_cfm)	(struct hci_conn *conn, __u8 status);
19583a6d576bSJohan Hedberg 	void (*disconn_cfm)	(struct hci_conn *conn, __u8 status);
19595a9d0a3fSWaldemar Rymarkiewicz 	void (*security_cfm)	(struct hci_conn *conn, __u8 status,
19605a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt);
19611da177e4SLinus Torvalds 	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
19621da177e4SLinus Torvalds 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
19631da177e4SLinus Torvalds };
19641da177e4SLinus Torvalds 
1965539c496dSJohan Hedberg static inline void hci_connect_cfm(struct hci_conn *conn, __u8 status)
1966539c496dSJohan Hedberg {
1967539c496dSJohan Hedberg 	struct hci_cb *cb;
1968539c496dSJohan Hedberg 
1969539c496dSJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
1970539c496dSJohan Hedberg 	list_for_each_entry(cb, &hci_cb_list, list) {
1971539c496dSJohan Hedberg 		if (cb->connect_cfm)
1972539c496dSJohan Hedberg 			cb->connect_cfm(conn, status);
1973539c496dSJohan Hedberg 	}
1974539c496dSJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
1975539c496dSJohan Hedberg 
1976539c496dSJohan Hedberg 	if (conn->connect_cfm_cb)
1977539c496dSJohan Hedberg 		conn->connect_cfm_cb(conn, status);
1978539c496dSJohan Hedberg }
1979539c496dSJohan Hedberg 
19803a6d576bSJohan Hedberg static inline void hci_disconn_cfm(struct hci_conn *conn, __u8 reason)
19813a6d576bSJohan Hedberg {
19823a6d576bSJohan Hedberg 	struct hci_cb *cb;
19833a6d576bSJohan Hedberg 
19843a6d576bSJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
19853a6d576bSJohan Hedberg 	list_for_each_entry(cb, &hci_cb_list, list) {
19863a6d576bSJohan Hedberg 		if (cb->disconn_cfm)
19873a6d576bSJohan Hedberg 			cb->disconn_cfm(conn, reason);
19883a6d576bSJohan Hedberg 	}
19893a6d576bSJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
19903a6d576bSJohan Hedberg 
19913a6d576bSJohan Hedberg 	if (conn->disconn_cfm_cb)
19923a6d576bSJohan Hedberg 		conn->disconn_cfm_cb(conn, reason);
19933a6d576bSJohan Hedberg }
19943a6d576bSJohan Hedberg 
19951da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
19961da177e4SLinus Torvalds {
1997711584eaSDenis Kirjanov 	struct hci_cb *cb;
19988c1b2355SMarcel Holtmann 	__u8 encrypt;
19991da177e4SLinus Torvalds 
200051a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
20018c1b2355SMarcel Holtmann 		return;
20028c1b2355SMarcel Holtmann 
20034dae2798SJohan Hedberg 	encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
20048c1b2355SMarcel Holtmann 
2005fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2006711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20078c1b2355SMarcel Holtmann 		if (cb->security_cfm)
20088c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
20091da177e4SLinus Torvalds 	}
2010fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
2011354fe804SJohan Hedberg 
2012354fe804SJohan Hedberg 	if (conn->security_cfm_cb)
2013354fe804SJohan Hedberg 		conn->security_cfm_cb(conn, status);
20141da177e4SLinus Torvalds }
20151da177e4SLinus Torvalds 
20163ca44c16SLuiz Augusto von Dentz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status)
20171da177e4SLinus Torvalds {
2018711584eaSDenis Kirjanov 	struct hci_cb *cb;
20193ca44c16SLuiz Augusto von Dentz 	__u8 encrypt;
20203ca44c16SLuiz Augusto von Dentz 
20213ca44c16SLuiz Augusto von Dentz 	if (conn->state == BT_CONFIG) {
2022339ddaa6SPatrick Steinhardt 		if (!status)
20233ca44c16SLuiz Augusto von Dentz 			conn->state = BT_CONNECTED;
20243ca44c16SLuiz Augusto von Dentz 
20253ca44c16SLuiz Augusto von Dentz 		hci_connect_cfm(conn, status);
20263ca44c16SLuiz Augusto von Dentz 		hci_conn_drop(conn);
20273ca44c16SLuiz Augusto von Dentz 		return;
20283ca44c16SLuiz Augusto von Dentz 	}
20293ca44c16SLuiz Augusto von Dentz 
20303ca44c16SLuiz Augusto von Dentz 	if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
20313ca44c16SLuiz Augusto von Dentz 		encrypt = 0x00;
20323ca44c16SLuiz Augusto von Dentz 	else if (test_bit(HCI_CONN_AES_CCM, &conn->flags))
20333ca44c16SLuiz Augusto von Dentz 		encrypt = 0x02;
20343ca44c16SLuiz Augusto von Dentz 	else
20353ca44c16SLuiz Augusto von Dentz 		encrypt = 0x01;
20361da177e4SLinus Torvalds 
20378746f135SLuiz Augusto von Dentz 	if (!status) {
2038435fef20SMarcel Holtmann 		if (conn->sec_level == BT_SECURITY_SDP)
2039435fef20SMarcel Holtmann 			conn->sec_level = BT_SECURITY_LOW;
2040435fef20SMarcel Holtmann 
204188167aedSVinicius Costa Gomes 		if (conn->pending_sec_level > conn->sec_level)
204288167aedSVinicius Costa Gomes 			conn->sec_level = conn->pending_sec_level;
20438746f135SLuiz Augusto von Dentz 	}
204488167aedSVinicius Costa Gomes 
2045fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2046711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20478c1b2355SMarcel Holtmann 		if (cb->security_cfm)
20488c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
20491da177e4SLinus Torvalds 	}
2050fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
2051354fe804SJohan Hedberg 
2052354fe804SJohan Hedberg 	if (conn->security_cfm_cb)
2053354fe804SJohan Hedberg 		conn->security_cfm_cb(conn, status);
20541da177e4SLinus Torvalds }
20551da177e4SLinus Torvalds 
20561da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
20571da177e4SLinus Torvalds {
2058711584eaSDenis Kirjanov 	struct hci_cb *cb;
20591da177e4SLinus Torvalds 
2060fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2061711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20621da177e4SLinus Torvalds 		if (cb->key_change_cfm)
20631da177e4SLinus Torvalds 			cb->key_change_cfm(conn, status);
20641da177e4SLinus Torvalds 	}
2065fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
20661da177e4SLinus Torvalds }
20671da177e4SLinus Torvalds 
20685a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
20695a9d0a3fSWaldemar Rymarkiewicz 								__u8 role)
20701da177e4SLinus Torvalds {
2071711584eaSDenis Kirjanov 	struct hci_cb *cb;
20721da177e4SLinus Torvalds 
2073fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2074711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20751da177e4SLinus Torvalds 		if (cb->role_switch_cfm)
20761da177e4SLinus Torvalds 			cb->role_switch_cfm(conn, status, role);
20771da177e4SLinus Torvalds 	}
2078fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
20791da177e4SLinus Torvalds }
20801da177e4SLinus Torvalds 
2081301cb2d8SJohan Hedberg static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
2082301cb2d8SJohan Hedberg {
2083dbbfa2abSAndre Guedes 	if (addr_type != ADDR_LE_DEV_RANDOM)
2084301cb2d8SJohan Hedberg 		return false;
2085301cb2d8SJohan Hedberg 
2086301cb2d8SJohan Hedberg 	if ((bdaddr->b[5] & 0xc0) == 0x40)
2087301cb2d8SJohan Hedberg 	       return true;
2088301cb2d8SJohan Hedberg 
2089301cb2d8SJohan Hedberg 	return false;
2090301cb2d8SJohan Hedberg }
2091301cb2d8SJohan Hedberg 
2092c46245b3SJohan Hedberg static inline bool hci_is_identity_address(bdaddr_t *addr, u8 addr_type)
2093c46245b3SJohan Hedberg {
2094c46245b3SJohan Hedberg 	if (addr_type == ADDR_LE_DEV_PUBLIC)
2095c46245b3SJohan Hedberg 		return true;
2096c46245b3SJohan Hedberg 
2097c46245b3SJohan Hedberg 	/* Check for Random Static address type */
2098c46245b3SJohan Hedberg 	if ((addr->b[5] & 0xc0) == 0xc0)
2099c46245b3SJohan Hedberg 		return true;
2100c46245b3SJohan Hedberg 
2101c46245b3SJohan Hedberg 	return false;
2102c46245b3SJohan Hedberg }
2103c46245b3SJohan Hedberg 
21042426f3a5SJohan Hedberg static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
21052426f3a5SJohan Hedberg 					  bdaddr_t *bdaddr, u8 addr_type)
21062426f3a5SJohan Hedberg {
21072426f3a5SJohan Hedberg 	if (!hci_bdaddr_is_rpa(bdaddr, addr_type))
21082426f3a5SJohan Hedberg 		return NULL;
21092426f3a5SJohan Hedberg 
21102426f3a5SJohan Hedberg 	return hci_find_irk_by_rpa(hdev, bdaddr);
21112426f3a5SJohan Hedberg }
21122426f3a5SJohan Hedberg 
2113d4905f24SAndre Guedes static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
2114d4905f24SAndre Guedes 					u16 to_multiplier)
2115d4905f24SAndre Guedes {
2116d4905f24SAndre Guedes 	u16 max_latency;
2117d4905f24SAndre Guedes 
2118d4905f24SAndre Guedes 	if (min > max || min < 6 || max > 3200)
2119d4905f24SAndre Guedes 		return -EINVAL;
2120d4905f24SAndre Guedes 
2121d4905f24SAndre Guedes 	if (to_multiplier < 10 || to_multiplier > 3200)
2122d4905f24SAndre Guedes 		return -EINVAL;
2123d4905f24SAndre Guedes 
2124d4905f24SAndre Guedes 	if (max >= to_multiplier * 8)
2125d4905f24SAndre Guedes 		return -EINVAL;
2126d4905f24SAndre Guedes 
21278757825bSSeungyoun Ju 	max_latency = (to_multiplier * 4 / max) - 1;
2128d4905f24SAndre Guedes 	if (latency > 499 || latency > max_latency)
2129d4905f24SAndre Guedes 		return -EINVAL;
2130d4905f24SAndre Guedes 
2131d4905f24SAndre Guedes 	return 0;
2132d4905f24SAndre Guedes }
2133d4905f24SAndre Guedes 
21341da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb);
21351da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb);
21361da177e4SLinus Torvalds 
2137d6ee6ad7SLoic Poulain int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen,
2138d6ee6ad7SLoic Poulain 		   const void *param);
213975e84b7cSJohan Hedberg 
214007dc93ddSJohan Hedberg int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
214107dc93ddSJohan Hedberg 		 const void *param);
214273d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
21430d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
214426afbd82SLuiz Augusto von Dentz void hci_send_iso(struct hci_conn *conn, struct sk_buff *skb);
21451da177e4SLinus Torvalds 
2146a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
2147dfe6d5c3SLuiz Augusto von Dentz void *hci_recv_event_data(struct hci_dev *hdev, __u8 event);
21481da177e4SLinus Torvalds 
2149eab2404bSLuiz Augusto von Dentz u32 hci_conn_get_phy(struct hci_conn *conn);
2150eab2404bSLuiz Augusto von Dentz 
21511da177e4SLinus Torvalds /* ----- HCI Sockets ----- */
2152470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
21537129069eSJohan Hedberg void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
2154c08b1a1dSMarcel Holtmann 			 int flag, struct sock *skip_sk);
2155cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
215638ceaa00SMarcel Holtmann void hci_send_monitor_ctrl_event(struct hci_dev *hdev, u16 event,
215738ceaa00SMarcel Holtmann 				 void *data, u16 data_len, ktime_t tstamp,
215838ceaa00SMarcel Holtmann 				 int flag, struct sock *skip_sk);
21591da177e4SLinus Torvalds 
2160040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event);
2161040030efSMarcel Holtmann 
2162a958452aSMarcel Holtmann #define HCI_MGMT_VAR_LEN	BIT(0)
2163a958452aSMarcel Holtmann #define HCI_MGMT_NO_HDEV	BIT(1)
2164a958452aSMarcel Holtmann #define HCI_MGMT_UNTRUSTED	BIT(2)
2165a958452aSMarcel Holtmann #define HCI_MGMT_UNCONFIGURED	BIT(3)
2166d5cc6626SMarcel Holtmann #define HCI_MGMT_HDEV_OPTIONAL	BIT(4)
2167b9a245fbSJohan Hedberg 
2168801c1e8dSJohan Hedberg struct hci_mgmt_handler {
2169801c1e8dSJohan Hedberg 	int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
2170801c1e8dSJohan Hedberg 		     u16 data_len);
2171801c1e8dSJohan Hedberg 	size_t data_len;
2172b9a245fbSJohan Hedberg 	unsigned long flags;
2173801c1e8dSJohan Hedberg };
2174801c1e8dSJohan Hedberg 
2175801c1e8dSJohan Hedberg struct hci_mgmt_chan {
2176801c1e8dSJohan Hedberg 	struct list_head list;
2177801c1e8dSJohan Hedberg 	unsigned short channel;
2178801c1e8dSJohan Hedberg 	size_t handler_count;
2179801c1e8dSJohan Hedberg 	const struct hci_mgmt_handler *handlers;
218088b94ce9SJohan Hedberg 	void (*hdev_init) (struct sock *sk, struct hci_dev *hdev);
2181801c1e8dSJohan Hedberg };
2182801c1e8dSJohan Hedberg 
2183801c1e8dSJohan Hedberg int hci_mgmt_chan_register(struct hci_mgmt_chan *c);
2184801c1e8dSJohan Hedberg void hci_mgmt_chan_unregister(struct hci_mgmt_chan *c);
2185801c1e8dSJohan Hedberg 
21860381101fSJohan Hedberg /* Management interface */
2187591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR		(BIT(BDADDR_BREDR))
2188591f47f3SAndre Guedes #define DISCOV_TYPE_LE			(BIT(BDADDR_LE_PUBLIC) | \
2189591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
2190591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED		(BIT(BDADDR_BREDR) | \
2191591f47f3SAndre Guedes 					 BIT(BDADDR_LE_PUBLIC) | \
2192591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
2193f39799f5SAndre Guedes 
21940d8cc935SAndre Guedes /* These LE scan and inquiry parameters were chosen according to LE General
21950d8cc935SAndre Guedes  * Discovery Procedure specification.
21960d8cc935SAndre Guedes  */
21970d8cc935SAndre Guedes #define DISCOV_LE_SCAN_WIN		0x12
21980d8cc935SAndre Guedes #define DISCOV_LE_SCAN_INT		0x12
21993d5a76f0SLukasz Rymanowski #define DISCOV_LE_TIMEOUT		10240	/* msec */
2200ae55f598SLukasz Rymanowski #define DISCOV_INTERLEAVED_TIMEOUT	5120	/* msec */
22010d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_INQUIRY_LEN	0x04
22020d8cc935SAndre Guedes #define DISCOV_BREDR_INQUIRY_LEN	0x08
22034b0e0cedSJakub Pawlowski #define DISCOV_LE_RESTART_DELAY		msecs_to_jiffies(200)	/* msec */
2204cfa15ccaSMarcel Holtmann #define DISCOV_LE_FAST_ADV_INT_MIN	0x00A0	/* 100 msec */
2205cfa15ccaSMarcel Holtmann #define DISCOV_LE_FAST_ADV_INT_MAX	0x00F0	/* 150 msec */
2206eca0ae4aSLuiz Augusto von Dentz #define DISCOV_LE_PER_ADV_INT_MIN	0x00A0	/* 200 msec */
2207eca0ae4aSLuiz Augusto von Dentz #define DISCOV_LE_PER_ADV_INT_MAX	0x00A0	/* 200 msec */
2208b338d917SBrian Gix #define DISCOV_LE_ADV_MESH_MIN		0x00A0  /* 100 msec */
2209b338d917SBrian Gix #define DISCOV_LE_ADV_MESH_MAX		0x00A0  /* 100 msec */
2210b338d917SBrian Gix #define INTERVAL_TO_MS(x)		(((x) * 10) / 0x10)
22110d8cc935SAndre Guedes 
2212dbf6811aSArchie Pusaka #define NAME_RESOLVE_DURATION		msecs_to_jiffies(10240)	/* 10.24 sec */
2213dbf6811aSArchie Pusaka 
221403c979c4SMarcel Holtmann void mgmt_fill_version_info(void *ver);
221591a668b0SJohan Hedberg int mgmt_new_settings(struct hci_dev *hdev);
2216bf6b56dbSMarcel Holtmann void mgmt_index_added(struct hci_dev *hdev);
2217bf6b56dbSMarcel Holtmann void mgmt_index_removed(struct hci_dev *hdev);
22183eec705eSMarcel Holtmann void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
22192ff13894SJohan Hedberg void mgmt_power_on(struct hci_dev *hdev, int err);
22202ff13894SJohan Hedberg void __mgmt_power_off(struct hci_dev *hdev);
2221dc4a5ee2SMarcel Holtmann void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
2222745c0ce3SVishal Agarwal 		       bool persistent);
222348ec92faSAlfonso Acosta void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
22241c6ed31bSYu Liu 			   u8 *name, u8 name_len);
22259b80ec5eSMarcel Holtmann void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
222612d4a3b2SJohan Hedberg 			      u8 link_type, u8 addr_type, u8 reason,
222712d4a3b2SJohan Hedberg 			      bool mgmt_connected);
22287892924cSMarcel Holtmann void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
222988c3df13SJohan Hedberg 			    u8 link_type, u8 addr_type, u8 status);
2230445608d0SMarcel Holtmann void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
223148264f06SJohan Hedberg 			 u8 addr_type, u8 status);
2232ce0e4a0dSMarcel Holtmann void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
2233e669cf80SMarcel Holtmann void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2234c35938b2SSzymon Janc 				  u8 status);
22353eb38528SMarcel Holtmann void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2236744cf19eSJohan Hedberg 				      u8 status);
2237744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
223839adbffeSJohan Hedberg 			      u8 link_type, u8 addr_type, u32 value,
2239272d90dfSJohan Hedberg 			      u8 confirm_hint);
2240744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2241272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
2242272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2243272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
2244272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
2245272d90dfSJohan Hedberg 			      u8 link_type, u8 addr_type);
2246604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2247272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
2248272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2249272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
225092a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
225192a25256SJohan Hedberg 			     u8 link_type, u8 addr_type, u32 passkey,
225292a25256SJohan Hedberg 			     u8 entered);
2253e1e930f5SJohan Hedberg void mgmt_auth_failed(struct hci_conn *conn, u8 status);
2254464996aeSMarcel Holtmann void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
22554e1b0245SMarcel Holtmann void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
22567f9a903cSMarcel Holtmann 				    u8 status);
22577667da34SMarcel Holtmann void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
2258e68f072bSJohan Hedberg void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status);
22592154d3f4SJohan Hedberg void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status);
2260901801b9SMarcel Holtmann void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2261af58925cSMarcel Holtmann 		       u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
2262b338d917SBrian Gix 		       u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len,
2263b338d917SBrian Gix 		       u64 instant);
22649cf12aeeSMarcel Holtmann void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2265b644ba33SJohan Hedberg 		      u8 addr_type, s8 rssi, u8 *name, u8 name_len);
22662f1e063bSMarcel Holtmann void mgmt_discovering(struct hci_dev *hdev, u8 discovering);
2267346ce5b7SAbhishek Pandit-Subedi void mgmt_suspending(struct hci_dev *hdev, u8 state);
2268346ce5b7SAbhishek Pandit-Subedi void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr,
2269346ce5b7SAbhishek Pandit-Subedi 		   u8 addr_type);
227084c61d92SJohan Hedberg bool mgmt_powering_down(struct hci_dev *hdev);
227153ac6ab6SMarcel Holtmann void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent);
2272cad20c27SJohan Hedberg void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent);
227353ac6ab6SMarcel Holtmann void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
227453ac6ab6SMarcel Holtmann 		   bool persistent);
2275ffb5a827SAndre Guedes void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
2276f4869e2aSJohan Hedberg 			 u8 bdaddr_type, u8 store_hint, u16 min_interval,
2277f4869e2aSJohan Hedberg 			 u16 max_interval, u16 latency, u16 timeout);
2278f4a407beSJohan Hedberg void mgmt_smp_complete(struct hci_conn *conn, bool complete);
2279f2252570SJohan Hedberg bool mgmt_get_connectable(struct hci_dev *hdev);
2280f2252570SJohan Hedberg u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev);
2281f2252570SJohan Hedberg void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev,
2282f2252570SJohan Hedberg 			    u8 instance);
2283f2252570SJohan Hedberg void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev,
2284f2252570SJohan Hedberg 			      u8 instance);
228566bd095aSArchie Pusaka void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle);
2286b7c23df8SJaganath Kanakkassery int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip);
22878d7f1677SManish Mandlik void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle,
22888d7f1677SManish Mandlik 				  bdaddr_t *bdaddr, u8 addr_type);
2289346af67bSVinicius Costa Gomes 
22901a942de0SBrian Gix int hci_abort_conn(struct hci_conn *conn, u8 reason);
22917d6ca693SJohan Hedberg u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
22927d6ca693SJohan Hedberg 		      u16 to_multiplier);
2293fe39c7b2SMarcel Holtmann void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
22948b76ce34SJohan Hedberg 		      __u8 ltk[16], __u8 key_size);
22952519a1fcSAndre Guedes 
2296a1f4c318SJohan Hedberg void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
2297a1f4c318SJohan Hedberg 			       u8 *bdaddr_type);
2298ebd3a747SJohan Hedberg 
22995d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_MASK       0x0003
23005d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_CVSD       0x0000
23015d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_TRANSP     0x0003
23025d4d62f6SFrédéric Dalleau 
23038961987fSKiran K #define LOCAL_CODEC_ACL_MASK	BIT(0)
23048961987fSKiran K #define LOCAL_CODEC_SCO_MASK	BIT(1)
23058961987fSKiran K 
23068961987fSKiran K #define TRANSPORT_TYPE_MAX	0x04
23078961987fSKiran K 
23081da177e4SLinus Torvalds #endif /* __HCI_CORE_H */
2309